From bffb4fb72f61b2080acf9af911a5001b8a91104a Mon Sep 17 00:00:00 2001 From: darren siepka Date: Thu, 11 May 2017 00:08:24 +0100 Subject: [PATCH] r command bug fixes and further multiprocessor can and serial3 support --- reference/speeduino.ini | 4 + speeduino/cancomms.h | 3 +- speeduino/cancomms.ino | 166 +++++++++++++++++++++++++++++++++++----- 3 files changed, 151 insertions(+), 22 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 100fde1a..40af77e1 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -722,6 +722,10 @@ page = 10 defaultValue = boostMinDuty,0 defaultValue = boostMaxDuty,100 defaultValue = sparkDur, 1.0 + defaultValue = speeduino_tsCanId, 0 + defaultValue = true_address, 0 + defaultValue = realtime_base_address, 0 + defaultValue = obd_address, 0 ;Default pins defaultValue = fanPin, 0 diff --git a/speeduino/cancomms.h b/speeduino/cancomms.h index c3ff62f3..d5dafcc2 100644 --- a/speeduino/cancomms.h +++ b/speeduino/cancomms.h @@ -3,7 +3,7 @@ //These are the page numbers that the Tuner Studio serial protocol uses to transverse the different map and config pages. #define veMapPage 1 - +uint8_t currentcanCommand; uint8_t currentCanPage = 1;//Not the same as the speeduino config page numbers uint8_t nCanretry = 0; //no of retrys uint8_t cancmdfail = 0; //command fail yes/no @@ -14,6 +14,5 @@ uint8_t Glow, Ghigh; void canCommand();//This is the heart of the Command Line Interpeter. All that needed to be done was to make it human readable. void sendCancommand(uint8_t cmdtype , uint16_t canadddress, uint8_t candata1, uint8_t candata2, uint16_t paramgroup); -void testCanComm(); #endif // CANCOMMS_H diff --git a/speeduino/cancomms.ino b/speeduino/cancomms.ino index 87caa81b..18ad551a 100644 --- a/speeduino/cancomms.ino +++ b/speeduino/cancomms.ino @@ -15,11 +15,18 @@ sendcancommand is called when a comman d is to be sent via serial3 to the Can in //#include "globals.h" //#include "storage.h" -#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) - void canCommand() { - switch (Serial3.read()) +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + currentcanCommand = Serial3.read(); +#elif defined(CORE_STM32) + currentcanCommand = Serial2.read(); +#elif defined(CORE_TEENSY) + currentcanCommand = Serial2.read(); +#else return; +#endif + + switch (currentcanCommand) { case 'A': // sends the bytes of realtime values sendValues(0, packetSize,3); //send values to serial3 @@ -27,14 +34,32 @@ void canCommand() case 'G': // this is the reply command sent by the Can interface //uint8_t Gdata; +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) while (Serial3.available() == 0) { } cancmdfail = Serial3.read(); +#elif defined(CORE_STM32) + while (Serial2.available() == 0) { } + cancmdfail = Serial2.read(); +#elif defined(CORE_TEENSY) + while (Serial2.available() == 0) { } + cancmdfail = Serial2.read(); +#else return; +#endif if (cancmdfail != 0) { for (byte Gx = 0; Gx < 8; Gx++) //read all 8 bytes of data { +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) while (Serial3.available() == 0) { } Gdata[Gx] = Serial3.read(); +#elif defined(CORE_STM32) + while (Serial2.available() == 0) { } + Gdata[Gx] = Serial2.read(); +#elif defined(CORE_TEENSY) + while (Serial2.available() == 0) { } + Gdata[Gx] = Serial2.read(); +#else return; +#endif } Glow = Gdata[(configPage10.caninput_param_start_byte[currentStatus.current_caninchannel])]; @@ -68,61 +93,129 @@ void canCommand() case 'L': uint8_t Llength; +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) while (Serial3.available() == 0) { } canlisten = Serial3.read(); +#elif defined(CORE_STM32) + while (Serial2.available() == 0) { } + canlisten = Serial2.read(); +#elif defined(CORE_TEENSY) + while (Serial2.available() == 0) { } + canlisten = Serial2.read(); +#else return; +#endif if (canlisten == 0) { //command request failed and/or data/device was not available break; } +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) while (Serial3.available() == 0) { } Llength= Serial3.read(); // next the number of bytes expected value +#elif defined(CORE_STM32) + while (Serial2.available() == 0) { } + Llength= Serial2.read(); // next the number of bytes expected value +#elif defined(CORE_TEENSY) + while (Serial2.available() == 0) { } + Llength= Serial2.read(); // next the number of bytes expected value +#else return; +#endif for (uint8_t Lcount = 0; Lcount > 8) ); +#elif defined(CORE_STM32) + Serial2.print("R"); //send "R" to request data from the parmagroup whos value is sent next + Serial2.write( lowByte(paramgroup) ); //send lsb first + Serial2.write( lowByte(paramgroup >> 8) ); +#elif defined(CORE_TEENSY) + Serial2.print("R"); //send "R" to request data from the parmagroup whos value is sent next + Serial2.write( lowByte(paramgroup) ); //send lsb first + Serial2.write( lowByte(paramgroup >> 8) ); +#else return; +#endif break; case 3: //send to truecan send routine +#if defined(CORE_STM32) + +#elif defined(CORE_TEENSY) +#else return; +#endif break; } } -#else -//Dummy functions for those that can't do Serial3 -void canCommand() { return; } -void sendCancommand(uint8_t cmdtype, uint16_t canaddress, uint8_t candata1, uint8_t candata2, uint16_t paramgroup) { return; } - -#endif