/* Speeduino - Simple engine management for the Arduino Mega 2560 platform Copyright (C) Josh Stewart A full copy of the license may be found in the projects root directory can_comms was originally contributed by Darren Siepka */ /* secondserial_command is called when a command is received from the secondary serial port It parses the command and calls the relevant function. can_command is called when a command is received by the onboard/attached canbus module It parses the command and calls the relevant function. sendcancommand is called when a command is to be sent either to serial3 ,to the external Can interface, or to the onboard/attached can interface */ #include "globals.h" #include "comms_secondary.h" #include "comms_CAN.h" #include "maths.h" #include "errors.h" #include "utilities.h" #include "comms_legacy.h" #include "logger.h" #include "page_crc.h" #include BOARD_H uint8_t currentSecondaryCommand; SECONDARY_SERIAL_T* pSecondarySerial; void secondserial_Command(void) { #if defined(secondarySerial_AVAILABLE) if ( serialSecondaryStatusFlag == SERIAL_INACTIVE ) { currentSecondaryCommand = secondarySerial.read(); } switch (currentSecondaryCommand) { case 'A': // sends a fixed 75 bytes of data. Used by Real Dash (Among others) if(configPage9.secondarySerialProtocol == SECONDARY_SERIAL_PROTO_GENERIC_FIXED) { sendValues(0, CAN_PACKET_SIZE, 0x31, secondarySerial, serialSecondaryStatusFlag, &getLegacySecondarySerialLogEntry); } // Send values using the legacy fixed byte order else { sendValues(0, CAN_PACKET_SIZE, 0x31, secondarySerial, serialSecondaryStatusFlag); } //send values to serial3 using the order in the ini file break; case 'b': // New EEPROM burn command to only burn a single page at a time legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag); break; case 'B': // AS above but for the serial compatibility mode. BIT_SET(currentStatus.status4, BIT_STATUS4_COMMS_COMPAT); //Force the compat mode legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag); break; case 'd': // Send a CRC32 hash of a given page legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag); break; case 'G': // this is the reply command sent by the Can interface serialSecondaryStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY; byte destcaninchannel; if (secondarySerial.available() >= 9) { serialSecondaryStatusFlag = SERIAL_INACTIVE; uint8_t cmdSuccessful = secondarySerial.read(); //0 == fail, 1 == good. destcaninchannel = secondarySerial.read(); // the input channel that requested the data value if (cmdSuccessful != 0) { // read all 8 bytes of data. uint8_t Gdata[9]; uint8_t Glow, Ghigh; for (byte Gx = 0; Gx < 8; Gx++) // first two are the can address the data is from. next two are the can address the data is for.then next 1 or two bytes of data { Gdata[Gx] = secondarySerial.read(); } Glow = Gdata[(configPage9.caninput_source_start_byte[destcaninchannel]&7)]; if ((BIT_CHECK(configPage9.caninput_source_num_bytes,destcaninchannel) > 0)) //if true then num bytes is 2 { if ((configPage9.caninput_source_start_byte[destcaninchannel]&7) < 8) //you can't have a 2 byte value starting at byte 7(8 on the list) { Ghigh = Gdata[((configPage9.caninput_source_start_byte[destcaninchannel]&7)+1)]; } else { Ghigh = 0; } } else { Ghigh = 0; } currentStatus.canin[destcaninchannel] = (Ghigh<<8) | Glow; } else{} //continue as command request failed and/or data/device was not available } break; case 'k': //placeholder for new can interface (toucan etc) commands break; case 'L': { //uint8_t Llength; while (secondarySerial.available() == 0) { } uint8_t canListen = secondarySerial.read(); if (canListen == 0) { //command request failed and/or data/device was not available break; } while (secondarySerial.available() == 0) { } /* Unclear what the below is trying to achieve. Commenting out for now to avoid compiler warnings for unused variables Llength = secondarySerial.read(); // next the number of bytes expected value uint8_t Lbuffer[8]; //8 byte buffer to store incoming can data for (uint8_t Lcount = 0; Lcount