From dd14a9447adcfbb81ef19eb355cc192ef6f2100a Mon Sep 17 00:00:00 2001 From: Timur Iskhodzhanov Date: Sat, 13 Aug 2022 21:52:00 -0700 Subject: [PATCH] Make the baud rate of the CAN bus car-specific. --- RaceChronoDiyBleDevice.ino | 1 - config.h | 10 ++++++++-- configs/ft86_gen1.h | 4 +++- configs/ft86_gen2.h | 4 +++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/RaceChronoDiyBleDevice.ino b/RaceChronoDiyBleDevice.ino index 95a8e83..f1ba8de 100644 --- a/RaceChronoDiyBleDevice.ino +++ b/RaceChronoDiyBleDevice.ino @@ -17,7 +17,6 @@ const int IRQ_PIN = 9; const long QUARTZ_CLOCK_FREQUENCY = 16 * 1E6; // 16 MHz. const uint32_t SPI_FREQUENCY = 10 * 1E6; // 10 MHz. -const long BAUD_RATE = 500 * 1E3; // 500k. bool isCanBusReaderActive = false; long lastCanMessageReceivedMs; diff --git a/config.h b/config.h index 33cf7a6..b73aac5 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #if !defined(RACECHRONO_BIY_BLE_DEVICE_CONFIG_H) #define RACECHRONO_BIY_BLE_DEVICE_CONFIG_H -// Change the value +// Change the value to customize the name of your device. #define DEVICE_NAME "BLE CAN device demo" // We use RaceChronoPidMap to keep track of stuff for each CAN ID. @@ -11,13 +11,19 @@ const uint8_t DEFAULT_UPDATE_RATE_DIVIDER = 10; // You need to pick one of the provided configurations below, or define your own -// configuration. Your configuration should define the following two functions: +// configuration. Your configuration should define the following constant and +// function: + +// Defines the baud rate to use for the CAN bus. For example, 500k baud rate +// should be written as 500 * 1e3. +extern const long BAUD_RATE; // 500k. // Returns an "update rate divider for a given CAN ID. // If the value is N, only every Nth message received from the CAN bus will be // communicated to RaceChrono via BLE. uint8_t getUpdateRateDivider(uint32_t can_id); + // Here are some configurations you can pick from by uncommenting one of the // following lines: //#include "configs/ft86_gen1.h" diff --git a/configs/ft86_gen1.h b/configs/ft86_gen1.h index dfdc89c..de895c4 100644 --- a/configs/ft86_gen1.h +++ b/configs/ft86_gen1.h @@ -2,7 +2,9 @@ // (2013-2020 model years). #if !defined(RACECHRONO_BIY_BLE_DEVICE_FT86_GEN1_H) -#define RACECHRONO_BIY_BLE_DEVICE_FT86_GEN1_H) +#define RACECHRONO_BIY_BLE_DEVICE_FT86_GEN1_H + +const long BAUD_RATE = 500 * 1e3; // 500k. uint8_t getUpdateRateDivider(uint32_t can_id) { switch (can_id) { diff --git a/configs/ft86_gen2.h b/configs/ft86_gen2.h index d928782..f93a81c 100644 --- a/configs/ft86_gen2.h +++ b/configs/ft86_gen2.h @@ -2,7 +2,9 @@ // (2022+ model years). #if !defined(RACECHRONO_BIY_BLE_DEVICE_FT86_GEN2_H) -#define RACECHRONO_BIY_BLE_DEVICE_FT86_GEN2_H) +#define RACECHRONO_BIY_BLE_DEVICE_FT86_GEN2_H + +const long BAUD_RATE = 500 * 1e3; // 500k. uint8_t getUpdateRateDivider(uint32_t can_id) { // This is sent over the CAN bus 50 times per second and includes brake