From 17f0d273f4cd04b4c981df8b2d268ac74c5f294b Mon Sep 17 00:00:00 2001 From: latonita Date: Wed, 18 Nov 2015 14:35:45 +0300 Subject: [PATCH] Default can speed setting --- arduino-canbus-monitor.ino | 20 ++++++++++++-------- can-232.cpp | 17 +++++++++++------ can-232.h | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/arduino-canbus-monitor.ino b/arduino-canbus-monitor.ino index 74bd097..b9e30c0 100644 --- a/arduino-canbus-monitor.ino +++ b/arduino-canbus-monitor.ino @@ -17,6 +17,16 @@ #include "SoftwareSerial.h" +void setup() { + Serial.begin(LW232_DEFAULT_BAUD_RATE); // default COM baud rate is 115200. + Can232::init(CAN_125KBPS); // set default rate you need here + // CAN_10KBPS, CAN_20KBPS, CAN_50KBPS, CAN_100KBPS, CAN_125KBPS, CAN_250KBPS, CAN_500KBPS, CAN_500KBPS, CAN_1000KBPS, CAN_83K3BPS + + + // optional custom packet filter to reduce number of messages comingh through to canhacker + // Can232::setFilter(myCustomAddressFilter); +} + INT8U myCustomAddressFilter(INT32U addr) { INT8U ret = LW232_FILTER_SKIP; //LW232_FILTER_PROCESS or LW232_FILTER_SKIP switch(addr) { @@ -24,7 +34,7 @@ INT8U myCustomAddressFilter(INT32U addr) { // case 0x1C8: //lights // case 0x2C0: // pedals case 0x3d0: // sound vol, treb.. - ret = LW232_FILTER_PROCESS; + ret = LW232_FILTER_PROCESS; // case 0x000: // ? // case 0x003: //shifter // case 0x015: // dor open close affects this as well @@ -39,15 +49,9 @@ INT8U myCustomAddressFilter(INT32U addr) { // ret = 0; } - return ret; + return ret; } -void setup() { - Serial.begin(LW232_DEFAULT_BAUD_RATE); - - Can232::init(); - //Can232::setFilter(myCustomAddressFilter); // optional -} void loop() { Can232::loop(); } diff --git a/can-232.cpp b/can-232.cpp index 54be67e..7a58650 100644 --- a/can-232.cpp +++ b/can-232.cpp @@ -49,12 +49,17 @@ Can232* const & Can232::instance() { } void Can232::init() { - dbg_begin(LW232_DEFAULT_BAUD_RATE); // logging through software serial - dbg1("CAN ASCII. Welcome to debug"); - + dbg_begin(LW232_DEFAULT_BAUD_RATE); // logging through software serial + dbg1("CAN ASCII. Welcome to debug"); + instance()->initFunc(); } +void Can232::init(INT8U defaultCanSpeed) { + init(); + instance()->lw232CanSpeedSelection = defaultCanSpeed; +} + void Can232::setFilter(INT8U (*userFunc)(INT32U)) { instance()->setFilterFunc(userFunc); } @@ -71,10 +76,10 @@ void Can232::initFunc() { inputString.reserve(200); // lw232AutoStart = true; //todo: read from eeprom // lw232AutoPoll = false; //todo: read from eeprom - // lw232TimeStamp = //read from eeprom - // lw232Message[0] = 'Z'; lw232Message[1] = '1'; exec(); + // lw232TimeStamp = //read from eeprom + // lw232Message[0] = 'Z'; lw232Message[1] = '1'; exec(); // if (lw232AutoStart) { - lw232Message[0] = 'O'; exec(); + lw232Message[0] = 'O'; exec(); // } } diff --git a/can-232.h b/can-232.h index 8752d56..b5d6852 100644 --- a/can-232.h +++ b/can-232.h @@ -152,6 +152,7 @@ class Can232 { public: static void init(); + static void init(INT8U defaultCanSpeed); static void setFilter(INT8U (*userFunc)(INT32U)); static void loop(); static void serialEvent();