From 57bfc3634820b73d1df0058ee71ca45f764db968 Mon Sep 17 00:00:00 2001 From: Autohome2 Date: Mon, 13 Jan 2020 02:16:12 +0000 Subject: [PATCH] fix for serial0 and serial3 errors (#301) * fix to serial0 and serial3 when offset is 0 uses wrong command * fix to serial0 and serial3 when offset is 0 uses wrong command * fix hex num --- speeduino/cancomms.ino | 33 +++++++++++++++++---------------- speeduino/comms.ino | 13 +++++++------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/speeduino/cancomms.ino b/speeduino/cancomms.ino index e7fe3baf..d3fc1b91 100644 --- a/speeduino/cancomms.ino +++ b/speeduino/cancomms.ino @@ -23,7 +23,7 @@ void canCommand() switch (currentcanCommand) { case 'A': // sends the bytes of realtime values from the OLD CAN list - sendcanValues(0, CAN_PACKET_SIZE, 0x30, 1); //send values to serial3 + sendcanValues(0, CAN_PACKET_SIZE, 0x31, 1); //send values to serial3 break; case 'G': // this is the reply command sent by the Can interface @@ -87,7 +87,7 @@ void canCommand() break; case 'n': // sends the bytes of realtime values from the NEW CAN list - sendcanValues(0, NEW_CAN_PACKET_SIZE, 0x31, 1); //send values to serial3 + sendcanValues(0, NEW_CAN_PACKET_SIZE, 0x32, 1); //send values to serial3 break; case 'r': //New format for the optimised OutputChannels @@ -144,20 +144,21 @@ void sendcanValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portTy //CAN serial #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)|| defined(CORE_STM32) || defined (CORE_TEENSY) //ATmega2561 does not have Serial3 - if (offset == 0) - { - if (cmd == 0x30) {CANSerial.write("A");} // confirm command type - else - { - CANSerial.write("n"); // confirm command type - CANSerial.write(NEW_CAN_PACKET_SIZE); // send the packet size the receiving device should expect. - } - } - else - { - CANSerial.write("r"); //confirm cmd type - CANSerial.write(cmd); - } + if (cmd == 0x30) + { + CANSerial.write("r"); //confirm cmd type + CANSerial.write(cmd); + } + else if (cmd == 0x31) + { + CANSerial.write("A"); // confirm command type + } + else if (cmd == 0x32) + { + CANSerial.write("n"); // confirm command type + CANSerial.write(cmd); // send command type , 0x32 (dec50) is ascii '0' + CANSerial.write(NEW_CAN_PACKET_SIZE); // send the packet size the receiving device should expect. + } #endif currentStatus.spark ^= (-currentStatus.hasSync ^ currentStatus.spark) & (1U << BIT_SPARK_SYNC); //Set the sync bit of the Spark variable to match the hasSync variable diff --git a/speeduino/comms.ino b/speeduino/comms.ino index 3e83c66b..a0fd835b 100644 --- a/speeduino/comms.ino +++ b/speeduino/comms.ino @@ -39,7 +39,7 @@ void command() break; case 'A': // send x bytes of realtime values - sendValues(0, LOG_ENTRY_SIZE, 0x30, 0); //send values to serial0 + sendValues(0, LOG_ENTRY_SIZE, 0x31, 0); //send values to serial0 break; @@ -501,14 +501,15 @@ void sendValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portNum) { //CAN serial #if defined(USE_SERIAL3) - if (offset == 0) - { - CANSerial.write("A"); //confirm cmd type - } - else + if (cmd == 30) { CANSerial.write("r"); //confirm cmd type CANSerial.write(cmd); + + } + else if (cmd == 31) + { + CANSerial.write("A"); //confirm cmd type } #endif }