Skip to content

Commit

Permalink
use CanData struct from cereal
Browse files Browse the repository at this point in the history
  • Loading branch information
MankaranSingh committed Aug 20, 2023
1 parent 6eb4994 commit ea0d275
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 45 deletions.
13 changes: 10 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cereal_dir = Dir('.')

python_path = sysconfig.get_paths()['include']
cpppath = [
"can",
'#',
'/usr/lib/include',
python_path
]
Expand Down Expand Up @@ -41,7 +41,7 @@ env = Environment(
LDFLAGS=ldflags_asan,
LINKFLAGS=ldflags_asan,
LIBPATH=[
"can/",
"#opendbc/can/",
],
CFLAGS="-std=gnu11",
CXXFLAGS=["-std=c++1z"],
Expand All @@ -53,6 +53,11 @@ env = Environment(
common = ''
Export('env', 'zmq', 'arch', 'common')

cereal = [File('#cereal/libcereal.a')]
messaging = [File('#cereal/libmessaging.a')]
Export('cereal', 'messaging')


envCython = env.Clone()
envCython["CPPPATH"] += [np.get_include()]
envCython["CCFLAGS"] += ["-Wno-#warnings", "-Wno-shadow", "-Wno-deprecated-declarations"]
Expand All @@ -72,4 +77,6 @@ envCython["LIBS"] = python_libs

Export('envCython')

SConscript(['can/SConscript'])

SConscript(['cereal/SConscript'])
SConscript(['opendbc/can/SConscript'])
10 changes: 1 addition & 9 deletions can/SConscript
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
Import('env', 'envCython')
Import('env', 'envCython', 'cereal', 'common')

import os

# Build Capnp Definitions
msg_capnp = env.Command(
target=['msg.capnp.c++', 'msg.capnp.h'],
source=["msg.capnp"],
action='capnp compile -oc++ $SOURCE'
)

common = ''
envDBC = env.Clone()
dbc_file_path = '-DDBC_FILE_PATH=\'"%s"\'' % (envDBC.Dir("..").abspath)
envDBC['CXXFLAGS'] += [dbc_file_path]
Expand Down
2 changes: 1 addition & 1 deletion can/common.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common.h"
#include "opendbc/can/common.h"


unsigned int honda_checksum(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d) {
Expand Down
6 changes: 3 additions & 3 deletions can/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <capnp/serialize.h>

#ifndef DYNAMIC_CAPNP
#include "msg.capnp.h"
#include "cereal/gen/cpp/log.capnp.h"
#endif

#include "common_dbc.h"
#include "opendbc/can/common_dbc.h"

#define INFO printf
#define WARN printf
Expand Down Expand Up @@ -81,7 +81,7 @@ class CANParser {
#ifndef DYNAMIC_CAPNP
void update_string(const std::string &data, bool sendcan);
void update_strings(const std::vector<std::string> &data, std::vector<SignalValue> &vals, bool sendcan);
void UpdateCans(uint64_t sec, const capnp::List<CanData>::Reader& cans);
void UpdateCans(uint64_t sec, const capnp::List<cereal::CanData>::Reader& cans);
#endif
void UpdateCans(uint64_t sec, const capnp::DynamicStruct::Reader& cans);
void UpdateValid(uint64_t sec);
Expand Down
4 changes: 2 additions & 2 deletions can/dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <cstring>
#include <clocale>

#include "common.h"
#include "common_dbc.h"
#include "opendbc/can/common.h"
#include "opendbc/can/common_dbc.h"

std::regex bo_regexp(R"(^BO_ (\w+) (\w+) *: (\w+) (\w+))");
std::regex sg_regexp(R"(^SG_ (\w+) : (\d+)\|(\d+)@(\d+)([\+|\-]) \(([0-9.+\-eE]+),([0-9.+\-eE]+)\) \[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] \"(.*)\" (.*))");
Expand Down
18 changes: 0 additions & 18 deletions can/msg.capnp

This file was deleted.

2 changes: 1 addition & 1 deletion can/packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdexcept>
#include <utility>

#include "common.h"
#include "opendbc/can/common.h"


void set_value(std::vector<uint8_t> &msg, const Signal &sig, int64_t ival) {
Expand Down
11 changes: 5 additions & 6 deletions can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#include <sys/stat.h>
#include <sys/mman.h>

#include "common.h"
#include "msg.capnp.h"

#include "cereal/logger/logger.h"
#include "opendbc/can/common.h"

int64_t get_raw_value(const std::vector<uint8_t> &msg, const Signal &sig) {
int64_t ret = 0;
Expand Down Expand Up @@ -172,7 +171,7 @@ void CANParser::update_string(const std::string &data, bool sendcan) {

// extract the messages
capnp::FlatArrayMessageReader cmsg(aligned_buf.slice(0, buf_size));
Event::Reader event = cmsg.getRoot<Event>();
cereal::Event::Reader event = cmsg.getRoot<cereal::Event>();

if (first_sec == 0) {
first_sec = event.getLogMonoTime();
Expand All @@ -196,7 +195,7 @@ void CANParser::update_strings(const std::vector<std::string> &data, std::vector
query_latest(vals, current_sec);
}

void CANParser::UpdateCans(uint64_t sec, const capnp::List<CanData>::Reader& cans) {
void CANParser::UpdateCans(uint64_t sec, const capnp::List<cereal::CanData>::Reader& cans) {
//DEBUG("got %d messages\n", cans.size());

bool bus_empty = true;
Expand Down Expand Up @@ -242,7 +241,7 @@ void CANParser::UpdateCans(uint64_t sec, const capnp::List<CanData>::Reader& can
#endif

void CANParser::UpdateCans(uint64_t sec, const capnp::DynamicStruct::Reader& cmsg) {
// assume message struct is `CanData` and parse
// assume message struct is `cereal::CanData` and parse
assert(cmsg.has("address") && cmsg.has("src") && cmsg.has("dat") && cmsg.has("busTime"));

if (cmsg.get("src").as<uint8_t>() != bus) {
Expand Down
4 changes: 2 additions & 2 deletions can/tests/test_packer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import unittest
import random

from cereal import log
import cereal.messaging as messaging
from opendbc.can.parser import CANParser
from opendbc.can.packer import CANPacker
from opendbc.can.tests import TEST_DBC


# Python implementation so we don't have to depend on boardd
def can_list_to_can_capnp(can_msgs, msgtype='can', logMonoTime=None):
dat = log.Event.new_message()
dat = messaging.new_message()
dat.init(msgtype, len(can_msgs))

if logMonoTime is not None:
Expand Down

0 comments on commit ea0d275

Please sign in to comment.