From c131f9db57ba92bdf69481757203a6ac72fac986 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 19 Dec 2020 15:05:40 -0800 Subject: [PATCH] small ubloxd cleanup --- release/files_common | 1 - selfdrive/locationd/SConscript | 13 +++---------- selfdrive/locationd/ublox_msg.cc | 17 ++++------------- selfdrive/locationd/ublox_msg.h | 1 + selfdrive/locationd/ubloxd.cc | 23 ++--------------------- selfdrive/locationd/ubloxd_main.cc | 1 - selfdrive/locationd/ubloxd_test.cc | 16 ++++------------ 7 files changed, 14 insertions(+), 58 deletions(-) diff --git a/release/files_common b/release/files_common index 3b4fba19..57c1964e 100644 --- a/release/files_common +++ b/release/files_common @@ -286,7 +286,6 @@ selfdrive/locationd/.gitignore selfdrive/locationd/SConscript selfdrive/locationd/ubloxd.cc selfdrive/locationd/ubloxd_main.cc -selfdrive/locationd/ubloxd_test.cc selfdrive/locationd/ublox_msg.cc selfdrive/locationd/ublox_msg.h diff --git a/selfdrive/locationd/SConscript b/selfdrive/locationd/SConscript index 59516574..43e5d1fe 100644 --- a/selfdrive/locationd/SConscript +++ b/selfdrive/locationd/SConscript @@ -2,14 +2,7 @@ Import('env', 'common', 'cereal', 'messaging') loc_libs = [cereal, messaging, 'zmq', common, 'capnp', 'kj', 'pthread'] -env.Program("ubloxd", [ - "ubloxd.cc", - "ublox_msg.cc", - "ubloxd_main.cc"], - LIBS=loc_libs) +env.Program("ubloxd", ["ubloxd.cc", "ublox_msg.cc", "ubloxd_main.cc"], LIBS=loc_libs) -env.Program("ubloxd_test", [ - "ubloxd_test.cc", - "ublox_msg.cc", - "ubloxd_main.cc"], - LIBS=loc_libs) +if GetOption("test"): + env.Program("ubloxd_test", ["ubloxd_test.cc", "ublox_msg.cc", "ubloxd_main.cc"], LIBS=loc_libs) diff --git a/selfdrive/locationd/ublox_msg.cc b/selfdrive/locationd/ublox_msg.cc index 8e7656f4..596bbaf8 100644 --- a/selfdrive/locationd/ublox_msg.cc +++ b/selfdrive/locationd/ublox_msg.cc @@ -1,20 +1,11 @@ #include #include -#include #include -#include -#include -#include -#include -#include #include #include #include -#include -#include "common/params.h" #include "common/swaglog.h" -#include "common/timing.h" #include "ublox_msg.h" @@ -173,8 +164,7 @@ inline bool UbloxMsgParser::valid_cheksum() { inline bool UbloxMsgParser::valid() { return bytes_in_parse_buf >= UBLOX_HEADER_SIZE + UBLOX_CHECKSUM_SIZE && - needed_bytes() == 0 && - valid_cheksum(); + needed_bytes() == 0 && valid_cheksum(); } inline bool UbloxMsgParser::valid_so_far() { @@ -186,8 +176,9 @@ inline bool UbloxMsgParser::valid_so_far() { //LOGD("PREAMBLE2 invalid, %02X.", msg_parse_buf[1]); return false; } - if(needed_bytes() == 0 && !valid()) + if(needed_bytes() == 0 && !valid()) { return false; + } return true; } @@ -221,7 +212,7 @@ kj::Array UbloxMsgParser::gen_solution() { } inline bool bit_to_bool(uint8_t val, int shifts) { - return (val & (1 << shifts)) ? true : false; + return (bool)(val & (1 << shifts)); } kj::Array UbloxMsgParser::gen_raw() { diff --git a/selfdrive/locationd/ublox_msg.h b/selfdrive/locationd/ublox_msg.h index 4bb103bb..63eaaab8 100644 --- a/selfdrive/locationd/ublox_msg.h +++ b/selfdrive/locationd/ublox_msg.h @@ -68,6 +68,7 @@ typedef struct __attribute__((packed)) { int8_t trkStat; int8_t reserved3; } rxm_raw_msg_extra; + // RXM_SFRBX typedef struct __attribute__((packed)) { int8_t gnssId; diff --git a/selfdrive/locationd/ubloxd.cc b/selfdrive/locationd/ubloxd.cc index 4ffc010f..5fdcebba 100644 --- a/selfdrive/locationd/ubloxd.cc +++ b/selfdrive/locationd/ubloxd.cc @@ -1,29 +1,11 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "messaging.hpp" -#include "common/params.h" -#include "common/swaglog.h" -#include "common/timing.h" - #include "ublox_msg.h" -const long ZMQ_POLL_TIMEOUT = 1000; // In miliseconds - Message * poll_ubloxraw_msg(Poller * poller) { - auto p = poller->poll(ZMQ_POLL_TIMEOUT); + auto p = poller->poll(1000); if (p.size()) { return p[0]->receive(); @@ -32,11 +14,10 @@ Message * poll_ubloxraw_msg(Poller * poller) { } } - int send_gps_event(PubSocket *s, const void *buf, size_t len) { return s->send((char*)buf, len); } int main() { return ubloxd_main(poll_ubloxraw_msg, send_gps_event); -} +} \ No newline at end of file diff --git a/selfdrive/locationd/ubloxd_main.cc b/selfdrive/locationd/ubloxd_main.cc index ad895f8d..54cfb279 100644 --- a/selfdrive/locationd/ubloxd_main.cc +++ b/selfdrive/locationd/ubloxd_main.cc @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/selfdrive/locationd/ubloxd_test.cc b/selfdrive/locationd/ubloxd_test.cc index d1118e4d..07a0f19e 100644 --- a/selfdrive/locationd/ubloxd_test.cc +++ b/selfdrive/locationd/ubloxd_test.cc @@ -1,16 +1,4 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include "messaging.hpp" @@ -75,19 +63,23 @@ int main(int argc, char** argv) { printf("Format: ubloxd_test stream_file_path save_prefix\n"); return 0; } + // Parse 11360 msgs, generate 9452 events data = (uint8_t *)read_file(argv[1], &len); if(data == NULL) { LOGE("Read file %s failed\n", argv[1]); return -1; } + prefix = argv[2]; ubloxd_main(poll_ubloxraw_msg, send_gps_event); free(data); printf("Generated %d cereal events\n", save_idx); + if(save_idx != 9452) { printf("Event count error: %d\n", save_idx); return -1; } + return 0; }