Further cleanup work on secondary comms. Slight RAM free up.
This commit is contained in:
parent
60c53b8887
commit
484e3916e3
|
@ -189,7 +189,7 @@
|
|||
***********************************************************************************************************
|
||||
* CAN / Second serial
|
||||
*/
|
||||
Uart CANSerial (&sercom3, 0, 1, SERCOM_RX_PAD_1, UART_TX_PAD_0);
|
||||
Uart secondarySerial (&sercom3, 0, 1, SERCOM_RX_PAD_1, UART_TX_PAD_0);
|
||||
|
||||
#endif //CORE_SAMD21
|
||||
#endif //SAMD21_H
|
||||
|
|
|
@ -219,9 +219,9 @@
|
|||
* CAN / Second serial
|
||||
*/
|
||||
#if defined(STM32GENERIC) // STM32GENERIC core
|
||||
SerialUART &CANSerial = Serial2;
|
||||
SerialUART &secondarySerial = Serial2;
|
||||
#else //libmaple core aka STM32DUINO
|
||||
HardwareSerial &CANSerial = Serial2;
|
||||
HardwareSerial &secondarySerial = Serial2;
|
||||
#endif
|
||||
|
||||
#endif //CORE_STM32
|
||||
|
|
|
@ -334,7 +334,6 @@ void ignitionSchedule8Interrupt(HardwareTimer*);
|
|||
*/
|
||||
#if HAL_CAN_MODULE_ENABLED
|
||||
#define NATIVE_CAN_AVAILABLE
|
||||
//HardwareSerial CANSerial(PD6, PD5);
|
||||
#include <src/STM32_CAN/STM32_CAN.h>
|
||||
//This activates CAN1 interface on STM32, but it's named as Can0, because that's how Teensy implementation is done
|
||||
extern STM32_CAN Can0;
|
||||
|
|
|
@ -8,7 +8,7 @@ A full copy of the license may be found in the projects root directory
|
|||
*/
|
||||
#include "globals.h"
|
||||
#include "comms.h"
|
||||
#include "cancomms.h"
|
||||
#include "comms_secondary.h"
|
||||
#include "storage.h"
|
||||
#include "maths.h"
|
||||
#include "utilities.h"
|
||||
|
|
|
@ -8,7 +8,7 @@ A full copy of the license may be found in the projects root directory
|
|||
*/
|
||||
#include "globals.h"
|
||||
#include "comms_legacy.h"
|
||||
#include "cancomms.h"
|
||||
#include "comms_secondary.h"
|
||||
#include "storage.h"
|
||||
#include "maths.h"
|
||||
#include "utilities.h"
|
||||
|
@ -659,7 +659,7 @@ void legacySerialHandler(byte cmd, Stream &targetPort, SerialStatus &targetStatu
|
|||
* This will "live" information from @ref currentStatus struct.
|
||||
* @param offset - Start field number
|
||||
* @param packetLength - Length of actual message (after possible ack/confirm headers)
|
||||
* @param cmd - ??? - Will be used as some kind of ack on CANSerial
|
||||
* @param cmd - ??? - Will be used as some kind of ack on secondarySerial
|
||||
* @param targetPort - The HardwareSerial device that will be transmitted to
|
||||
* @param targetStatusFlag - The status flag that will be set to indicate the status of the transmission
|
||||
* E.g. tuning sw command 'A' (Send all values) will send data from field number 0, LOG_ENTRY_SIZE fields.
|
||||
|
@ -667,26 +667,26 @@ void legacySerialHandler(byte cmd, Stream &targetPort, SerialStatus &targetStatu
|
|||
*/
|
||||
void sendValues(uint16_t offset, uint16_t packetLength, byte cmd, Stream &targetPort, SerialStatus &targetStatusFlag)
|
||||
{
|
||||
#if defined(CANSerial_AVAILABLE)
|
||||
if (&targetPort == &CANSerial)
|
||||
#if defined(secondarySerial_AVAILABLE)
|
||||
if (&targetPort == &secondarySerial)
|
||||
{
|
||||
//CAN serial
|
||||
if( (configPage9.secondarySerialProtocol == SECONDARY_SERIAL_PROTO_GENERIC) || (configPage9.secondarySerialProtocol == SECONDARY_SERIAL_PROTO_REALDASH))
|
||||
{
|
||||
if (cmd == 0x30)
|
||||
{
|
||||
CANSerial.write("r"); //confirm cmd type
|
||||
CANSerial.write(cmd);
|
||||
secondarySerial.write("r"); //confirm cmd type
|
||||
secondarySerial.write(cmd);
|
||||
}
|
||||
else if (cmd == 0x31)
|
||||
{
|
||||
CANSerial.write("A"); // confirm command type
|
||||
secondarySerial.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.
|
||||
secondarySerial.write("n"); // confirm command type
|
||||
secondarySerial.write(cmd); // send command type , 0x32 (dec50) is ascii '0'
|
||||
secondarySerial.write(NEW_CAN_PACKET_SIZE); // send the packet size the receiving device should expect.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef CANCOMMS_H
|
||||
#define CANCOMMS_H
|
||||
#ifndef COMMS_SECONDARY_H
|
||||
#define COMMS_SECONDARY_H
|
||||
|
||||
#define NEW_CAN_PACKET_SIZE 123
|
||||
#define CAN_PACKET_SIZE 75
|
||||
|
@ -10,21 +10,21 @@
|
|||
#define SECONDARY_SERIAL_PROTO_REALDASH 3
|
||||
|
||||
#if ( defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) )
|
||||
#define CANSerial_AVAILABLE
|
||||
extern HardwareSerial &CANSerial;
|
||||
#define secondarySerial_AVAILABLE
|
||||
extern HardwareSerial &secondarySerial;
|
||||
#elif defined(CORE_STM32)
|
||||
#define CANSerial_AVAILABLE
|
||||
#define secondarySerial_AVAILABLE
|
||||
#ifndef HAVE_HWSERIAL2 //Hack to get the code to compile on BlackPills
|
||||
#define Serial2 Serial1
|
||||
#endif
|
||||
#if defined(STM32GENERIC) // STM32GENERIC core
|
||||
extern SerialUART &CANSerial;
|
||||
extern SerialUART &secondarySerial;
|
||||
#else //libmaple core aka STM32DUINO
|
||||
extern HardwareSerial &CANSerial;
|
||||
extern HardwareSerial &secondarySerial;
|
||||
#endif
|
||||
#elif defined(CORE_TEENSY)
|
||||
#define CANSerial_AVAILABLE
|
||||
extern HardwareSerial &CANSerial;
|
||||
#define secondarySerial_AVAILABLE
|
||||
extern HardwareSerial &secondarySerial;
|
||||
#endif
|
||||
|
||||
void secondserial_Command(void);//This is the heart of the Command Line Interpreter. All that needed to be done was to make it human readable.
|
||||
|
@ -33,4 +33,4 @@ void sendCancommand(uint8_t cmdtype , uint16_t canadddress, uint8_t candata1, ui
|
|||
void obd_response(uint8_t therequestedPID , uint8_t therequestedPIDlow, uint8_t therequestedPIDhigh);
|
||||
void readAuxCanBus();
|
||||
|
||||
#endif // CANCOMMS_H
|
||||
#endif // COMMS_SECONDARY_H
|
|
@ -16,7 +16,7 @@ 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 "cancomms.h"
|
||||
#include "comms_secondary.h"
|
||||
#include "maths.h"
|
||||
#include "errors.h"
|
||||
#include "utilities.h"
|
||||
|
@ -25,68 +25,64 @@ sendcancommand is called when a command is to be sent either to serial3
|
|||
#include "page_crc.h"
|
||||
|
||||
uint8_t currentSecondaryCommand;
|
||||
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
|
||||
uint8_t canlisten = 0;
|
||||
uint8_t Lbuffer[8]; //8 byte buffer to store incoming can data
|
||||
uint8_t Gdata[9];
|
||||
uint8_t Glow, Ghigh;
|
||||
|
||||
#if ( defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) )
|
||||
HardwareSerial &CANSerial = Serial3;
|
||||
HardwareSerial &secondarySerial = Serial3;
|
||||
#elif defined(CORE_STM32)
|
||||
#ifndef HAVE_HWSERIAL2 //Hack to get the code to compile on BlackPills
|
||||
#define Serial2 Serial1
|
||||
#endif
|
||||
#if defined(STM32GENERIC) // STM32GENERIC core
|
||||
SerialUART &CANSerial = Serial2;
|
||||
SerialUART &secondarySerial = Serial2;
|
||||
#else //libmaple core aka STM32DUINO
|
||||
HardwareSerial &CANSerial = Serial2;
|
||||
HardwareSerial &secondarySerial = Serial2;
|
||||
#endif
|
||||
#elif defined(CORE_TEENSY)
|
||||
HardwareSerial &CANSerial = Serial2;
|
||||
HardwareSerial &secondarySerial = Serial2;
|
||||
#endif
|
||||
|
||||
void secondserial_Command(void)
|
||||
{
|
||||
#if defined(CANSerial_AVAILABLE)
|
||||
if ( serialSecondaryStatusFlag == SERIAL_INACTIVE ) { currentSecondaryCommand = CANSerial.read(); }
|
||||
#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)
|
||||
//sendcanValues(0, CAN_PACKET_SIZE, 0x31, 1); //send values to serial3
|
||||
sendValues(0, CAN_PACKET_SIZE, 0x31, CANSerial, serialSecondaryStatusFlag); //send values to serial3
|
||||
sendValues(0, CAN_PACKET_SIZE, 0x31, secondarySerial, serialSecondaryStatusFlag); //send values to serial3
|
||||
break;
|
||||
|
||||
case 'b': // New EEPROM burn command to only burn a single page at a time
|
||||
legacySerialHandler(currentSecondaryCommand, CANSerial, serialSecondaryStatusFlag);
|
||||
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, CANSerial, serialSecondaryStatusFlag);
|
||||
legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag);
|
||||
break;
|
||||
|
||||
case 'd': // Send a CRC32 hash of a given page
|
||||
legacySerialHandler(currentSecondaryCommand, CANSerial, serialSecondaryStatusFlag);
|
||||
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 (CANSerial.available() >= 9)
|
||||
if (secondarySerial.available() >= 9)
|
||||
{
|
||||
serialSecondaryStatusFlag = SERIAL_INACTIVE;
|
||||
cancmdfail = CANSerial.read(); //0 == fail, 1 == good.
|
||||
destcaninchannel = CANSerial.read(); // the input channel that requested the data value
|
||||
if (cancmdfail != 0)
|
||||
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] = CANSerial.read();
|
||||
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
|
||||
|
@ -115,50 +111,56 @@ void secondserial_Command(void)
|
|||
break;
|
||||
|
||||
case 'L':
|
||||
uint8_t Llength;
|
||||
while (CANSerial.available() == 0) { }
|
||||
canlisten = CANSerial.read();
|
||||
{
|
||||
//uint8_t Llength;
|
||||
while (secondarySerial.available() == 0) { }
|
||||
uint8_t canListen = secondarySerial.read();
|
||||
|
||||
if (canlisten == 0)
|
||||
if (canListen == 0)
|
||||
{
|
||||
//command request failed and/or data/device was not available
|
||||
break;
|
||||
}
|
||||
|
||||
while (CANSerial.available() == 0) { }
|
||||
Llength= CANSerial.read(); // next the number of bytes expected value
|
||||
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 <Llength ;Lcount++)
|
||||
{
|
||||
while (CANSerial.available() == 0){}
|
||||
while (secondarySerial.available() == 0){}
|
||||
// receive all x bytes into "Lbuffer"
|
||||
Lbuffer[Lcount] = CANSerial.read();
|
||||
Lbuffer[Lcount] = secondarySerial.read();
|
||||
}
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
case 'n': // sends the bytes of realtime values from the NEW CAN list
|
||||
sendValues(0, NEW_CAN_PACKET_SIZE, 0x32, CANSerial, serialSecondaryStatusFlag); //send values to serial3
|
||||
sendValues(0, NEW_CAN_PACKET_SIZE, 0x32, secondarySerial, serialSecondaryStatusFlag); //send values to serial3
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
legacySerialHandler(currentSecondaryCommand, CANSerial, serialSecondaryStatusFlag);
|
||||
legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag);
|
||||
break;
|
||||
|
||||
case 'Q': // send code version
|
||||
legacySerialHandler(currentSecondaryCommand, CANSerial, serialSecondaryStatusFlag);
|
||||
legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag);
|
||||
break;
|
||||
|
||||
case 'r': //New format for the optimised OutputChannels over CAN
|
||||
legacySerialHandler(currentSecondaryCommand, CANSerial, serialSecondaryStatusFlag);
|
||||
legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag);
|
||||
break;
|
||||
|
||||
case 's': // send the "a" stream code version
|
||||
CANSerial.print(F("Speeduino csx02019.8"));
|
||||
secondarySerial.print(F("Speeduino csx02019.8"));
|
||||
break;
|
||||
|
||||
case 'S': // send code version
|
||||
if(configPage9.secondarySerialProtocol == SECONDARY_SERIAL_PROTO_MSDROID) { legacySerialHandler('Q', CANSerial, serialSecondaryStatusFlag); } //Note 'Q', this is a workaround for msDroid
|
||||
else { legacySerialHandler(currentSecondaryCommand, CANSerial, serialSecondaryStatusFlag); }
|
||||
if(configPage9.secondarySerialProtocol == SECONDARY_SERIAL_PROTO_MSDROID) { legacySerialHandler('Q', secondarySerial, serialSecondaryStatusFlag); } //Note 'Q', this is a workaround for msDroid
|
||||
else { legacySerialHandler(currentSecondaryCommand, secondarySerial, serialSecondaryStatusFlag); }
|
||||
|
||||
break;
|
||||
|
||||
|
@ -217,26 +219,26 @@ void can_Command(void)
|
|||
// this routine sends a request(either "0" for a "G" , "1" for a "L" , "2" for a "R" to the Can interface or "3" sends the request via the actual local canbus
|
||||
void sendCancommand(uint8_t cmdtype, uint16_t canaddress, uint8_t candata1, uint8_t candata2, uint16_t sourcecanAddress)
|
||||
{
|
||||
#if defined(CANSerial_AVAILABLE)
|
||||
#if defined(secondarySerial_AVAILABLE)
|
||||
switch (cmdtype)
|
||||
{
|
||||
case 0:
|
||||
CANSerial.print("G");
|
||||
CANSerial.write(canaddress); //tscanid of speeduino device
|
||||
CANSerial.write(candata1); // table id
|
||||
CANSerial.write(candata2); //table memory offset
|
||||
secondarySerial.print("G");
|
||||
secondarySerial.write(canaddress); //tscanid of speeduino device
|
||||
secondarySerial.write(candata1); // table id
|
||||
secondarySerial.write(candata2); //table memory offset
|
||||
break;
|
||||
|
||||
case 1: //send request to listen for a can message
|
||||
CANSerial.print("L");
|
||||
CANSerial.write(canaddress); //11 bit canaddress of device to listen for
|
||||
secondarySerial.print("L");
|
||||
secondarySerial.write(canaddress); //11 bit canaddress of device to listen for
|
||||
break;
|
||||
|
||||
case 2: // requests via serial3
|
||||
CANSerial.print("R"); //send "R" to request data from the sourcecanAddress whose value is sent next
|
||||
CANSerial.write(candata1); //the currentStatus.current_caninchannel
|
||||
CANSerial.write(lowByte(sourcecanAddress) ); //send lsb first
|
||||
CANSerial.write(highByte(sourcecanAddress) );
|
||||
secondarySerial.print("R"); //send "R" to request data from the sourcecanAddress whose value is sent next
|
||||
secondarySerial.write(candata1); //the currentStatus.current_caninchannel
|
||||
secondarySerial.write(lowByte(sourcecanAddress) ); //send lsb first
|
||||
secondarySerial.write(highByte(sourcecanAddress) );
|
||||
break;
|
||||
|
||||
case 3:
|
|
@ -7,7 +7,7 @@
|
|||
#include "updates.h"
|
||||
#include "speeduino.h"
|
||||
#include "timers.h"
|
||||
#include "cancomms.h"
|
||||
#include "comms_secondary.h"
|
||||
#include "utilities.h"
|
||||
#include "scheduledIO.h"
|
||||
#include "scheduler.h"
|
||||
|
@ -116,8 +116,8 @@ void initialiseAll(void)
|
|||
|
||||
Serial.begin(115200);
|
||||
BIT_SET(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS); //Flag legacy comms as being allowed on startip
|
||||
#if defined(CANSerial_AVAILABLE)
|
||||
if (configPage9.enable_secondarySerial == 1) { CANSerial.begin(115200); }
|
||||
#if defined(secondarySerial_AVAILABLE)
|
||||
if (configPage9.enable_secondarySerial == 1) { secondarySerial.begin(115200); }
|
||||
#endif
|
||||
|
||||
//Repoint the 2D table structs to the config pages that were just loaded
|
||||
|
|
|
@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "scheduler.h"
|
||||
#include "comms.h"
|
||||
#include "comms_legacy.h"
|
||||
#include "cancomms.h"
|
||||
#include "comms_secondary.h"
|
||||
#include "maths.h"
|
||||
#include "corrections.h"
|
||||
#include "timers.h"
|
||||
|
@ -108,13 +108,13 @@ void loop(void)
|
|||
}
|
||||
|
||||
//Check for any CAN comms requiring action
|
||||
#if defined(CANSerial_AVAILABLE)
|
||||
#if defined(secondarySerial_AVAILABLE)
|
||||
//if can or secondary serial interface is enabled then check for requests.
|
||||
if (configPage9.enable_secondarySerial == 1) //secondary serial interface enabled
|
||||
{
|
||||
if ( ((mainLoopCount & 31) == 1) or (CANSerial.available() > SERIAL_BUFFER_THRESHOLD) )
|
||||
if ( ((mainLoopCount & 31) == 1) or (secondarySerial.available() > SERIAL_BUFFER_THRESHOLD) )
|
||||
{
|
||||
if (CANSerial.available() > 0) { secondserial_Command(); }
|
||||
if (secondarySerial.available() > 0) { secondserial_Command(); }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -311,7 +311,7 @@ void loop(void)
|
|||
if (configPage9.enable_secondarySerial == 1) // megas only support can via secondary serial
|
||||
{
|
||||
sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage9.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100));
|
||||
//send an R command for data from caninput_source_address[currentStatus.current_caninchannel] from CANSERIAL
|
||||
//send an R command for data from caninput_source_address[currentStatus.current_caninchannel] from secondarySerial
|
||||
}
|
||||
}
|
||||
else if (((configPage9.caninput_sel[currentStatus.current_caninchannel]&12) == 4)
|
||||
|
|
Loading…
Reference in New Issue