Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into build_message_loo…
Browse files Browse the repository at this point in the history
…kup_table_in_dbc
  • Loading branch information
sshane committed Jun 6, 2024
2 parents 7255286 + f58bc33 commit 99bf552
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ repos:
args:
- --error-exitcode=1
- --language=c++
- --inline-suppr
- --force
- --quiet
- -j4
Expand Down
1 change: 1 addition & 0 deletions can/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "cereal/gen/cpp/log.capnp.h"
#endif

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

#define INFO printf
Expand Down
27 changes: 27 additions & 0 deletions can/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#ifdef SWAGLOG
// cppcheck-suppress preprocessorErrorDirective
#include SWAGLOG
#else

#define CLOUDLOG_DEBUG 10
#define CLOUDLOG_INFO 20
#define CLOUDLOG_WARNING 30
#define CLOUDLOG_ERROR 40
#define CLOUDLOG_CRITICAL 50

#define cloudlog(lvl, fmt, ...) printf(fmt "\n", ## __VA_ARGS__)
#define cloudlog_rl(burst, millis, lvl, fmt, ...) printf(fmt "\n", ##__VA_ARGS__)

#define LOGD(fmt, ...) cloudlog(CLOUDLOG_DEBUG, fmt, ## __VA_ARGS__)
#define LOG(fmt, ...) cloudlog(CLOUDLOG_INFO, fmt, ## __VA_ARGS__)
#define LOGW(fmt, ...) cloudlog(CLOUDLOG_WARNING, fmt, ## __VA_ARGS__)
#define LOGE(fmt, ...) cloudlog(CLOUDLOG_ERROR, fmt, ## __VA_ARGS__)

#define LOGD_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_DEBUG, fmt, ## __VA_ARGS__)
#define LOG_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_INFO, fmt, ## __VA_ARGS__)
#define LOGW_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_WARNING, fmt, ## __VA_ARGS__)
#define LOGE_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_ERROR, fmt, ## __VA_ARGS__)

#endif
4 changes: 2 additions & 2 deletions can/packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ std::vector<uint8_t> CANPacker::pack(uint32_t address, const std::vector<SignalP
}
set_value(ret, sig, ival);

counter_set = counter_set || (sigval.name == "COUNTER");
if (counter_set) {
if (sigval.name == "COUNTER") {
counters[address] = sigval.value;
counter_set = true;
}
}

Expand Down
7 changes: 3 additions & 4 deletions can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <sys/stat.h>
#include <sys/mman.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) {
Expand Down Expand Up @@ -65,7 +64,7 @@ bool MessageState::parse(uint64_t nanos, const std::vector<uint8_t> &dat) {

// only update values if both checksum and counter are valid
if (checksum_failed || counter_failed) {
LOGE("0x%X message checks failed, checksum failed %d, counter failed %d", address, checksum_failed, counter_failed);
LOGE_100("0x%X message checks failed, checksum failed %d, counter failed %d", address, checksum_failed, counter_failed);
return false;
}

Expand Down Expand Up @@ -279,9 +278,9 @@ void CANParser::UpdateValid(uint64_t nanos) {
if (state.check_threshold > 0 && (missing || timed_out)) {
if (show_missing && !bus_timeout) {
if (missing) {
LOGE("0x%X '%s' NOT SEEN", state.address, state.name.c_str());
LOGE_100("0x%X '%s' NOT SEEN", state.address, state.name.c_str());
} else if (timed_out) {
LOGE("0x%X '%s' TIMED OUT", state.address, state.name.c_str());
LOGE_100("0x%X '%s' TIMED OUT", state.address, state.name.c_str());
}
}
_valid = false;
Expand Down
13 changes: 13 additions & 0 deletions can/tests/test_packer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def test_packer_counter(self):
cnt = random.randint(0, 255)
msg = packer.make_can_msg("CAN_FD_MESSAGE", 0, {
"COUNTER": cnt,
"SIGNED": 0
})
dat = can_list_to_can_capnp([msg, ])
parser.update_strings([dat])
Expand Down Expand Up @@ -381,6 +382,18 @@ def test_disallow_duplicate_messages(self):
with self.assertRaises(RuntimeError):
CANParser("toyota_nodsu_pt_generated", [("ACC_CONTROL", 10), ("ACC_CONTROL", 10)])

def test_allow_undefined_msgs(self):
# TODO: we should throw an exception for these, but we need good
# discovery tests in openpilot first
packer = CANPacker("toyota_nodsu_pt_generated")

self.assertEqual(packer.make_can_msg("ACC_CONTROL", 0, {"UNKNOWN_SIGNAL": 0}),
[835, 0, b'\x00\x00\x00\x00\x00\x00\x00N', 0])
self.assertEqual(packer.make_can_msg("UNKNOWN_MESSAGE", 0, {"UNKNOWN_SIGNAL": 0}),
[0, 0, b'', 0])
self.assertEqual(packer.make_can_msg(0, 0, {"UNKNOWN_SIGNAL": 0}),
[0, 0, b'', 0])


if __name__ == "__main__":
unittest.main()

0 comments on commit 99bf552

Please sign in to comment.