diff --git a/README.md b/README.md
index 564287562b4bfa..edcbbeeaa7f988 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
[![](https://i.imgur.com/UetIFyH.jpg)](#)
-Welcome to openpilot
+Welcome to openpilot SPECIFICALLY FOR THE CHEVY BOLT (NO PASSTHROUGH)
======
[openpilot](http://github.com/commaai/openpilot) is an open source driver assistance system. Currently, it performs the functions of Adaptive Cruise Control (ACC) and Automated Lane Centering (ALC) for selected Honda, Toyota, Acura, Lexus, Chevrolet, Hyundai, Kia, Subaru, Volkswagen. It's about on par with Tesla Autopilot and GM Super Cruise, and better than [all other manufacturers](http://www.thedrive.com/tech/5707/the-war-for-autonomous-driving-part-iii-us-vs-germany-vs-japan).
@@ -63,6 +63,7 @@ Supported Cars
| Buick3 | Regal 20186 | Adaptive Cruise | Yes | Yes | 0mph | 7mph |
| Chevrolet3 | Malibu 20176 | Adaptive Cruise | Yes | Yes | 0mph | 7mph |
| Chevrolet3 | Volt 2017-186 | Adaptive Cruise | Yes | Yes | 0mph | 7mph |
+| Chevrolet3 | Bolt 2019 | Driver Confidence II | Yes | No | 0mph | 7mph |
| Cadillac3 | ATS 2018 | Adaptive Cruise | Yes | Yes | 0mph | 7mph |
| Chrysler | Pacifica 2017-187 | Adaptive Cruise | Yes | Stock | 0mph | 9mph |
| Chrysler | Pacifica Hybrid 2017-187| Adaptive Cruise | Yes | Stock | 0mph | 9mph |
diff --git a/models/driving_model.dlc b/models/driving_model.dlc
index e04f9f93a1a0fa..8526838a473549 100644
Binary files a/models/driving_model.dlc and b/models/driving_model.dlc differ
diff --git a/opendbc/gm_global_a_powertrain.dbc b/opendbc/gm_global_a_powertrain.dbc
index 2e3bd7c85dd435..25dbe40bc5acfc 100644
--- a/opendbc/gm_global_a_powertrain.dbc
+++ b/opendbc/gm_global_a_powertrain.dbc
@@ -209,6 +209,12 @@ BO_ 1912 PSCM_778: 8 K43_PSCM
BO_ 1930 ASCM_78A: 7 K124_ASCM
+BO_ 800 FCABrakingCmd: 6 XXX
+ SG_ RollingCounter : 5|2@0+ (1,0) [0|3] "" XXX
+ SG_ Checksum : 27|20@0+ (1,0) [0|2047] "" XXX
+ SG_ BrakeCmdActive : 3|1@1+ (1,0) [0|1] "" XXX
+ SG_ BrakingForce : 2|7@0+ (1,0) [0|7] "" XXX
+
BO_TX_BU_ 384 : K124_ASCM,NEO;
BO_TX_BU_ 880 : NEO,K124_ASCM;
BO_TX_BU_ 1033 : K124_ASCM,NEO;
diff --git a/panda/VERSION b/panda/VERSION
index 4279ff22f4fa77..25120d3de063a4 100644
--- a/panda/VERSION
+++ b/panda/VERSION
@@ -1 +1 @@
-v1.5.9
\ No newline at end of file
+v1.5.33
\ No newline at end of file
diff --git a/panda/board/boards/common.h b/panda/board/boards/common.h
index e33b2a2f0426c4..98ac89e2ed371f 100644
--- a/panda/board/boards/common.h
+++ b/panda/board/boards/common.h
@@ -62,7 +62,9 @@ void peripherals_init(void){
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; // gmlan_alt and IR PWM
//RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
//RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
+ RCC->APB1ENR |= RCC_APB1ENR_TIM7EN;
RCC->APB1ENR |= RCC_APB1ENR_PWREN; // for RTC config
+ //RCC->APB1ENR |= RCC_APB1ENR_TIM12EN;
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
//RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
diff --git a/panda/board/drivers/can.h b/panda/board/drivers/can.h
index c9bf2d25436b35..209a62c1502ce0 100644
--- a/panda/board/drivers/can.h
+++ b/panda/board/drivers/can.h
@@ -363,6 +363,8 @@ void ignition_can_hook(CAN_FIFOMailBox_TypeDef *to_push) {
ignition_can = (GET_BYTE(to_push, 2) & 0x2) != 0;
}
}
+ //TODO: remove this - for testing only
+ //ignition_can = true;
}
// CAN receive handlers
@@ -420,6 +422,26 @@ void CAN3_TX_IRQHandler(void) { process_can(2); }
void CAN3_RX0_IRQHandler(void) { can_rx(2); }
void CAN3_SCE_IRQHandler(void) { can_sce(CAN3); }
+
+void pump_send(pump_hook hook) {
+ uint8_t bus_number = 0U;
+ if (hook == NULL) return;
+ CAN_FIFOMailBox_TypeDef *to_push = hook();
+ if (to_push != NULL) {
+ if (bus_number < BUS_MAX) {
+ // add CAN packet to send queuesend
+ // bus number isn't passed through
+ to_push->RDTR &= 0xF;
+ if ((bus_number == 3U) && (can_num_lookup[3] == 0xFFU)) {
+ gmlan_send_errs += bitbang_gmlan(to_push) ? 0U : 1U;
+ } else {
+ can_fwd_errs += can_push(can_queues[bus_number], to_push) ? 0U : 1U;
+ process_can(CAN_NUM_FROM_BUS_NUM(bus_number));
+ }
+ }
+ }
+}
+
void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) {
if (safety_tx_hook(to_push) != 0) {
if (bus_number < BUS_MAX) {
diff --git a/panda/board/main.c b/panda/board/main.c
index 3bcae876e203d0..97c8333b460955 100644
--- a/panda/board/main.c
+++ b/panda/board/main.c
@@ -630,6 +630,28 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
// ***************************** main code *****************************
+// *pump_hook message_pump_hook;
+
+// void enable_message_pump(uint32_t divider, *pump_hook hook) {
+// //Timer for LKAS pump
+// message_pump_hook = hook;
+// timer_init(TIM7, divider);
+// NVIC_EnableIRQ(TIM7_IRQn);
+// }
+
+// void update_message_pump_rate(uint32_t divider) {
+// //TODO: test if this works
+// TIM7->PSC = divider-1;
+// }
+
+// void disable_message_pump() {
+// NVIC_DisableIRQ(TIM7_IRQn);
+// pump_hook = null;
+// }
+
+
+
+
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
void __initialize_hardware_early(void) {
early();
@@ -646,6 +668,20 @@ uint64_t tcnt = 0;
#define EON_HEARTBEAT_IGNITION_CNT_ON 5U
#define EON_HEARTBEAT_IGNITION_CNT_OFF 2U
+
+
+
+void TIM7_IRQHandler(void) {
+ //TODO: This needs to check for ignition and stop itself?
+ if (TIM7->SR != 0) {
+ if (message_pump_hook != NULL) {
+ pump_send(message_pump_hook);
+ }
+ }
+ TIM7->SR = 0;
+}
+
+
// called once per second
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
void TIM1_BRK_TIM9_IRQHandler(void) {
@@ -760,6 +796,7 @@ int main(void) {
TIM2->EGR = TIM_EGR_UG;
// use TIM2->CNT to read
+
// default to silent mode to prevent issues with Ford
// hardcode a specific safety mode if you want to force the panda to be in a specific mode
int err = safety_set_mode(SAFETY_NOOUTPUT, 0);
@@ -790,6 +827,10 @@ int main(void) {
timer_init(TIM9, 1464);
NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
+ // //Timer for LKAS pump
+ // timer_init(TIM7, 15);
+ // NVIC_EnableIRQ(TIM7_IRQn);
+
#ifdef DEBUG
puts("DEBUG ENABLED\n");
#endif
diff --git a/panda/board/main_declarations.h b/panda/board/main_declarations.h
index 8929e9ac0e0cd9..a06067a470d2d3 100644
--- a/panda/board/main_declarations.h
+++ b/panda/board/main_declarations.h
@@ -6,6 +6,10 @@ typedef struct board board;
typedef struct harness_configuration harness_configuration;
void can_flip_buses(uint8_t bus1, uint8_t bus2);
void can_set_obd(uint8_t harness_orientation, bool obd);
+// void enable_message_pump(uint32_t divider, *pump_hook hook);
+// void update_message_pump_rate(uint32_t divider);
+// void disable_message_pump(void);
+
// ********************* Globals **********************
uint8_t hw_type = 0;
diff --git a/panda/board/obj/panda.bin.signed b/panda/board/obj/panda.bin.signed
deleted file mode 100644
index 7fa3f83e559081..00000000000000
Binary files a/panda/board/obj/panda.bin.signed and /dev/null differ
diff --git a/panda/board/safety.h b/panda/board/safety.h
index c68eda2c4a4864..857af5b666432e 100644
--- a/panda/board/safety.h
+++ b/panda/board/safety.h
@@ -55,6 +55,29 @@ int safety_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
return current_hooks->fwd(bus_num, to_fwd);
}
+pump_hook message_pump_hook;
+
+void enable_message_pump(uint32_t divider, pump_hook hook) {
+ //Timer for LKAS pump
+ //todo: some kind of locking?
+ message_pump_active = true;
+ message_pump_hook = hook;
+ timer_init(TIM7, divider);
+ NVIC_EnableIRQ(TIM7_IRQn);
+}
+
+void update_message_pump_rate(uint32_t divider) {
+ //TODO: test if this works
+ TIM7->PSC = divider-1;
+}
+
+void disable_message_pump() {
+ NVIC_DisableIRQ(TIM7_IRQn);
+ message_pump_hook = NULL;
+ message_pump_active = false;
+}
+
+
typedef struct {
uint16_t id;
const safety_hooks *hooks;
@@ -94,6 +117,10 @@ int safety_set_mode(uint16_t mode, int16_t param) {
if ((set_status == 0) && (current_hooks->init != NULL)) {
current_hooks->init(param);
}
+ if (mode == SAFETY_NOOUTPUT) {
+ puts("Disabling message pump due to SAFETY_NOOUTPUT");
+ disable_message_pump();
+ }
return set_status;
}
diff --git a/panda/board/safety/safety_gm.h b/panda/board/safety/safety_gm.h
index 452f70953df640..545ceb49a253b2 100644
--- a/panda/board/safety/safety_gm.h
+++ b/panda/board/safety/safety_gm.h
@@ -8,7 +8,17 @@
// brake rising edge
// brake > 0mph
-const int GM_MAX_STEER = 300;
+typedef struct {
+ uint32_t current_ts;
+ CAN_FIFOMailBox_TypeDef current_frame;
+ uint32_t stock_ts;
+ CAN_FIFOMailBox_TypeDef stock_frame;
+ uint32_t op_ts;
+ CAN_FIFOMailBox_TypeDef op_frame;
+ uint32_t rolling_counter;
+} gm_dual_buffer;
+
+const int GM_MAX_STEER = 550;
const int GM_MAX_RT_DELTA = 128; // max delta torque allowed for real time checks
const uint32_t GM_RT_INTERVAL = 250000; // 250ms between real time checks
const int GM_MAX_RATE_UP = 7;
@@ -29,6 +39,54 @@ int gm_desired_torque_last = 0;
uint32_t gm_ts_last = 0;
struct sample_t gm_torque_driver; // last few driver torques measured
+static void gm_init_lkas_pump(void);
+
+
+volatile gm_dual_buffer gm_lkas_buffer;
+
+// CAN_FIFOMailBox_TypeDef gm_current_lkas;
+// volatile uint32_t gm_current_lkas_ts = 0;
+// volatile CAN_FIFOMailBox_TypeDef gm_stock_lkas;
+// volatile bool gm_have_stock_lkas = false;
+// volatile uint32_t gm_stock_lkas_ts = 0;
+// volatile CAN_FIFOMailBox_TypeDef gm_op_lkas;
+// volatile bool gm_have_op_lkas = false;
+// volatile uint32_t gm_op_lkas_ts = 0;
+// volatile int gm_lkas_rolling_counter = 0;
+volatile bool gm_ffc_detected = false;
+
+static void gm_apply_buffer(volatile gm_dual_buffer *buffer, bool stock) {
+ if (stock) {
+ buffer->current_frame.RIR = buffer->stock_frame.RIR | 1;
+ buffer->current_frame.RDTR = buffer->stock_frame.RDTR;
+ buffer->current_frame.RDLR = buffer->stock_frame.RDLR;
+ buffer->current_frame.RDHR = buffer->stock_frame.RDHR;
+ buffer->current_ts = buffer->stock_ts;
+ } else {
+ buffer->current_frame.RIR = buffer->op_frame.RIR;
+ buffer->current_frame.RDTR = buffer->op_frame.RDTR;
+ buffer->current_frame.RDLR = buffer->op_frame.RDLR;
+ buffer->current_frame.RDHR = buffer->op_frame.RDHR;
+ buffer->current_ts = buffer->op_ts;
+ }
+}
+
+static void gm_set_stock_lkas(CAN_FIFOMailBox_TypeDef *to_send) {
+ gm_lkas_buffer.stock_frame.RIR = to_send->RIR;
+ gm_lkas_buffer.stock_frame.RDTR = to_send->RDTR;
+ gm_lkas_buffer.stock_frame.RDLR = to_send->RDLR;
+ gm_lkas_buffer.stock_frame.RDHR = to_send->RDHR;
+ gm_lkas_buffer.stock_ts = TIM2->CNT;
+}
+
+static void gm_set_op_lkas(CAN_FIFOMailBox_TypeDef *to_send) {
+ gm_lkas_buffer.op_frame.RIR = to_send->RIR;
+ gm_lkas_buffer.op_frame.RDTR = to_send->RDTR;
+ gm_lkas_buffer.op_frame.RDLR = to_send->RDLR;
+ gm_lkas_buffer.op_frame.RDHR = to_send->RDHR;
+ gm_lkas_buffer.op_ts = TIM2->CNT;
+}
+
static void gm_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
int bus_number = GET_BUS(to_push);
int addr = GET_ADDR(to_push);
@@ -142,6 +200,13 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
// LKA STEER: safety check
if (addr == 384) {
+ uint32_t vals[4];
+ vals[0] = 0x00000000U;
+ vals[1] = 0x10000fffU;
+ vals[2] = 0x20000ffeU;
+ vals[3] = 0x30000ffdU;
+ int rolling_counter = GET_BYTE(to_send, 0) >> 4;
+
int desired_torque = ((GET_BYTE(to_send, 0) & 0x7U) << 8) + GET_BYTE(to_send, 1);
uint32_t ts = TIM2->CNT;
bool violation = 0;
@@ -149,6 +214,7 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
if (current_controls_allowed) {
+
// *** global torque limit check ***
violation |= max_limit_check(desired_torque, GM_MAX_STEER, -GM_MAX_STEER);
@@ -184,8 +250,13 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
}
if (violation) {
- tx = 0;
+ //Replace payload with appropriate zero value for expected rolling counter
+ to_send->RDLR = vals[rolling_counter];
+ //tx = 0;
}
+ tx = 0;
+ gm_set_op_lkas(to_send);
+ gm_init_lkas_pump();
}
// PARK ASSIST STEER: unlimited torque, no thanks
@@ -213,16 +284,119 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
return tx;
}
+
+
+
static void gm_init(int16_t param) {
UNUSED(param);
controls_allowed = 0;
+ gm_lkas_buffer.current_ts = 0;
+ gm_lkas_buffer.op_ts = 0;
+ gm_lkas_buffer.stock_ts = 0;
+}
+
+
+static int gm_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
+ return -1;
+ int bus_fwd = -1;
+ if (bus_num == 0) {
+ bus_fwd = 1; // Camera is on CAN2
+ }
+ if (bus_num == 1) {
+ int addr = GET_ADDR(to_fwd);
+ if (addr != 384) return 0;
+ gm_set_stock_lkas(to_fwd);
+ gm_ffc_detected = true;
+ gm_init_lkas_pump();
+ }
+
+ // fallback to do not forward
+ return bus_fwd;
}
+static CAN_FIFOMailBox_TypeDef * gm_pump_hook(void) {
+ volatile int pedal_pressed = (volatile int)gm_gas_prev || ((volatile int)gm_brake_prev && (volatile int)gm_moving);
+ volatile bool current_controls_allowed = (volatile bool)controls_allowed && !(volatile int)pedal_pressed;
+
+ if (!gm_ffc_detected) {
+ //If we haven't seen lkas messages from CAN2, there is no passthrough, just use OP
+ if (gm_lkas_buffer.op_ts == 0) return NULL;
+ //puts("using OP lkas\n");
+ gm_apply_buffer(&gm_lkas_buffer, false);
+ //In OP only mode we need to send zero if controls are not allowed
+ if (!current_controls_allowed) {
+ gm_lkas_buffer.current_frame.RDLR = 0U;
+ gm_lkas_buffer.current_frame.RDHR = 0U;
+ }
+ }
+ else
+ {
+ if (!current_controls_allowed) {
+ if (gm_lkas_buffer.stock_ts == 0) return NULL;
+ //puts("using stock lkas\n");
+ gm_apply_buffer(&gm_lkas_buffer, true);
+ } else {
+ if (gm_lkas_buffer.op_ts == 0) return NULL;
+ //puts("using OP lkas\n");
+ gm_apply_buffer(&gm_lkas_buffer, false);
+ }
+ }
+
+ // If the timestamp of the last message is more than 40ms old, fallback to zero
+ // If it is more than 1 second, disable message pump
+ uint32_t ts = TIM2->CNT;
+ uint32_t ts_elapsed = get_ts_elapsed(ts, gm_lkas_buffer.current_ts);
+
+
+
+ if (ts_elapsed > 1000000u) {
+ puts("Disabling message pump due to stale buffer\n");
+ disable_message_pump();
+ } else if (ts_elapsed > 40000u) {
+ puts("Zeroing frame due to stale buffer: ");
+ puth(ts_elapsed);
+ puts("\n");
+ gm_lkas_buffer.current_frame.RDLR = 0U;
+ gm_lkas_buffer.current_frame.RDHR = 0U;
+ }
+
+ gm_lkas_buffer.rolling_counter = (gm_lkas_buffer.rolling_counter + 1) % 4;
+
+ //update the rolling counter
+ gm_lkas_buffer.current_frame.RDLR = (0xFFFFFFCF & gm_lkas_buffer.current_frame.RDLR) | (gm_lkas_buffer.rolling_counter << 4);
+
+ // Recalculate checksum - Thanks Andrew C
+
+ // Replacement rolling counter
+ uint32_t newidx = gm_lkas_buffer.rolling_counter;
+
+ // Pull out LKA Steering CMD data and swap endianness (not including rolling counter)
+ uint32_t dataswap = ((gm_lkas_buffer.current_frame.RDLR << 8) & 0x0F00U) | ((gm_lkas_buffer.current_frame.RDLR >> 8) &0xFFU);
+
+ // Compute Checksum
+ uint32_t checksum = (0x1000 - dataswap - newidx) & 0x0fff;
+
+ //Swap endianness of checksum back to what GM expects
+ uint32_t checksumswap = (checksum >> 8) | ((checksum << 8) & 0xFF00U);
+
+ // Merge the rewritten checksum back into the BxCAN frame RDLR
+ gm_lkas_buffer.current_frame.RDLR &= 0x0000FFFF;
+ gm_lkas_buffer.current_frame.RDLR |= (checksumswap << 16);
+
+ return (CAN_FIFOMailBox_TypeDef*)&gm_lkas_buffer.current_frame;
+}
+
+static void gm_init_lkas_pump() {
+ if (message_pump_active) return;
+ puts("Starting message pump\n");
+ enable_message_pump(15, gm_pump_hook);
+}
+
const safety_hooks gm_hooks = {
.init = gm_init,
.rx = gm_rx_hook,
.tx = gm_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
- .fwd = default_fwd_hook,
+ .fwd = gm_fwd_hook,
};
diff --git a/panda/board/safety_declarations.h b/panda/board/safety_declarations.h
index efa6a4e2b8744c..35489bd6eb8593 100644
--- a/panda/board/safety_declarations.h
+++ b/panda/board/safety_declarations.h
@@ -31,6 +31,12 @@ typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
typedef int (*tx_hook)(CAN_FIFOMailBox_TypeDef *to_send);
typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len);
typedef int (*fwd_hook)(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd);
+typedef CAN_FIFOMailBox_TypeDef * (*pump_hook)(void);
+
+void enable_message_pump(uint32_t divider, pump_hook hook);
+void update_message_pump_rate(uint32_t divider);
+void disable_message_pump(void);
+
typedef struct {
safety_hook_init init;
@@ -48,5 +54,7 @@ int gas_interceptor_prev = 0;
// This is set by USB command 0xdf
bool long_controls_allowed = 1;
+bool message_pump_active = false;
+
// avg between 2 tracks
#define GET_INTERCEPTOR(msg) (((GET_BYTE((msg), 0) << 8) + GET_BYTE((msg), 1) + ((GET_BYTE((msg), 2) << 8) + GET_BYTE((msg), 3)) / 2 ) / 2)
diff --git a/selfdrive/can/common.h b/selfdrive/can/common.h
index 2ec25075859ef5..a496c3918b91ad 100644
--- a/selfdrive/can/common.h
+++ b/selfdrive/can/common.h
@@ -1,17 +1,13 @@
-#ifndef SELFDRIVE_CAN_COMMON_H
-#define SELFDRIVE_CAN_COMMON_H
+#pragma once
-#include
-#include
-#include
-#include
#include
+#include
+#include "common_dbc.h"
#include
#include "cereal/gen/cpp/log.capnp.h"
#define MAX_BAD_COUNTER 5
-#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
// Helper functions
unsigned int honda_checksum(unsigned int address, uint64_t d, int l);
@@ -22,74 +18,6 @@ unsigned int pedal_checksum(uint64_t d, int l);
uint64_t read_u64_be(const uint8_t* v);
uint64_t read_u64_le(const uint8_t* v);
-struct SignalPackValue {
- const char* name;
- double value;
-};
-
-struct SignalParseOptions {
- uint32_t address;
- const char* name;
- double default_value;
-};
-
-struct MessageParseOptions {
- uint32_t address;
- int check_frequency;
-};
-
-struct SignalValue {
- uint32_t address;
- uint16_t ts;
- const char* name;
- double value;
-};
-
-
-enum SignalType {
- DEFAULT,
- HONDA_CHECKSUM,
- HONDA_COUNTER,
- TOYOTA_CHECKSUM,
- PEDAL_CHECKSUM,
- PEDAL_COUNTER,
- VOLKSWAGEN_CHECKSUM,
- VOLKSWAGEN_COUNTER,
-};
-
-struct Signal {
- const char* name;
- int b1, b2, bo;
- bool is_signed;
- double factor, offset;
- bool is_little_endian;
- SignalType type;
-};
-
-struct Msg {
- const char* name;
- uint32_t address;
- unsigned int size;
- size_t num_sigs;
- const Signal *sigs;
-};
-
-struct Val {
- const char* name;
- uint32_t address;
- const char* def_val;
- const Signal *sigs;
-};
-
-struct DBC {
- const char* name;
- size_t num_msgs;
- const Msg *msgs;
- const Val *vals;
- size_t num_vals;
-};
-
-
class MessageState {
public:
uint32_t address;
@@ -129,17 +57,3 @@ class CANParser {
std::vector query_latest();
};
-
-
-
-
-const DBC* dbc_lookup(const std::string& dbc_name);
-
-void dbc_register(const DBC* dbc);
-
-#define dbc_init(dbc) \
-static void __attribute__((constructor)) do_dbc_init_ ## dbc(void) { \
- dbc_register(&dbc); \
-}
-
-#endif
diff --git a/selfdrive/can/common.pxd b/selfdrive/can/common.pxd
index 54c6e444fdfcd8..d26f8da46f6057 100644
--- a/selfdrive/can/common.pxd
+++ b/selfdrive/can/common.pxd
@@ -17,7 +17,9 @@ cdef extern from "common.h":
HONDA_COUNTER,
TOYOTA_CHECKSUM,
PEDAL_CHECKSUM,
- PEDAL_COUNTER
+ PEDAL_COUNTER,
+ VOLKSWAGEN_CHECKSUM,
+ VOLKSWAGEN_COUNTER
cdef struct Signal:
const char* name
diff --git a/selfdrive/can/common_dbc.h b/selfdrive/can/common_dbc.h
new file mode 100644
index 00000000000000..ae6f443ec90cd3
--- /dev/null
+++ b/selfdrive/can/common_dbc.h
@@ -0,0 +1,82 @@
+#pragma once
+
+#include
+#include
+#include
+
+#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
+
+struct SignalPackValue {
+ const char* name;
+ double value;
+};
+
+struct SignalParseOptions {
+ uint32_t address;
+ const char* name;
+ double default_value;
+};
+
+struct MessageParseOptions {
+ uint32_t address;
+ int check_frequency;
+};
+
+struct SignalValue {
+ uint32_t address;
+ uint16_t ts;
+ const char* name;
+ double value;
+};
+
+enum SignalType {
+ DEFAULT,
+ HONDA_CHECKSUM,
+ HONDA_COUNTER,
+ TOYOTA_CHECKSUM,
+ PEDAL_CHECKSUM,
+ PEDAL_COUNTER,
+ VOLKSWAGEN_CHECKSUM,
+ VOLKSWAGEN_COUNTER,
+};
+
+struct Signal {
+ const char* name;
+ int b1, b2, bo;
+ bool is_signed;
+ double factor, offset;
+ bool is_little_endian;
+ SignalType type;
+};
+
+struct Msg {
+ const char* name;
+ uint32_t address;
+ unsigned int size;
+ size_t num_sigs;
+ const Signal *sigs;
+};
+
+struct Val {
+ const char* name;
+ uint32_t address;
+ const char* def_val;
+ const Signal *sigs;
+};
+
+struct DBC {
+ const char* name;
+ size_t num_msgs;
+ const Msg *msgs;
+ const Val *vals;
+ size_t num_vals;
+};
+
+const DBC* dbc_lookup(const std::string& dbc_name);
+
+void dbc_register(const DBC* dbc);
+
+#define dbc_init(dbc) \
+static void __attribute__((constructor)) do_dbc_init_ ## dbc(void) { \
+ dbc_register(&dbc); \
+}
diff --git a/selfdrive/can/dbc.cc b/selfdrive/can/dbc.cc
index 95d5e4d791394a..6587de7fe0163a 100644
--- a/selfdrive/can/dbc.cc
+++ b/selfdrive/can/dbc.cc
@@ -1,7 +1,6 @@
-#include
#include
-#include "common.h"
+#include "common_dbc.h"
namespace {
diff --git a/selfdrive/can/dbc_template.cc b/selfdrive/can/dbc_template.cc
index 52351aef2ff79a..f9540fcee9af16 100644
--- a/selfdrive/can/dbc_template.cc
+++ b/selfdrive/can/dbc_template.cc
@@ -1,6 +1,4 @@
-#include
-
-#include "common.h"
+#include "common_dbc.h"
namespace {
@@ -27,7 +25,7 @@ const Signal sigs_{{address}}[] = {
.type = SignalType::HONDA_COUNTER,
{% elif checksum_type == "toyota" and sig.name == "CHECKSUM" %}
.type = SignalType::TOYOTA_CHECKSUM,
- {% elif checksum_type == "volkswagen" and sig.name == "CHECKSUM" %}
+ {% elif checksum_type == "volkswagen" and sig.name == "CHECKSUM" %}
.type = SignalType::VOLKSWAGEN_CHECKSUM,
{% elif checksum_type == "volkswagen" and sig.name == "COUNTER" %}
.type = SignalType::VOLKSWAGEN_COUNTER,
diff --git a/selfdrive/can/packer.cc b/selfdrive/can/packer.cc
index f6da562a7a5910..c658e56731f3f3 100644
--- a/selfdrive/can/packer.cc
+++ b/selfdrive/can/packer.cc
@@ -1,6 +1,4 @@
#include
-#include
-#include
#include
#include
#include