r command bug fixes and further multiprocessor can and serial3 support
This commit is contained in:
parent
49a23d9a33
commit
bffb4fb72f
|
@ -722,6 +722,10 @@ page = 10
|
||||||
defaultValue = boostMinDuty,0
|
defaultValue = boostMinDuty,0
|
||||||
defaultValue = boostMaxDuty,100
|
defaultValue = boostMaxDuty,100
|
||||||
defaultValue = sparkDur, 1.0
|
defaultValue = sparkDur, 1.0
|
||||||
|
defaultValue = speeduino_tsCanId, 0
|
||||||
|
defaultValue = true_address, 0
|
||||||
|
defaultValue = realtime_base_address, 0
|
||||||
|
defaultValue = obd_address, 0
|
||||||
|
|
||||||
;Default pins
|
;Default pins
|
||||||
defaultValue = fanPin, 0
|
defaultValue = fanPin, 0
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//These are the page numbers that the Tuner Studio serial protocol uses to transverse the different map and config pages.
|
//These are the page numbers that the Tuner Studio serial protocol uses to transverse the different map and config pages.
|
||||||
#define veMapPage 1
|
#define veMapPage 1
|
||||||
|
|
||||||
|
uint8_t currentcanCommand;
|
||||||
uint8_t currentCanPage = 1;//Not the same as the speeduino config page numbers
|
uint8_t currentCanPage = 1;//Not the same as the speeduino config page numbers
|
||||||
uint8_t nCanretry = 0; //no of retrys
|
uint8_t nCanretry = 0; //no of retrys
|
||||||
uint8_t cancmdfail = 0; //command fail yes/no
|
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 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 sendCancommand(uint8_t cmdtype , uint16_t canadddress, uint8_t candata1, uint8_t candata2, uint16_t paramgroup);
|
||||||
void testCanComm();
|
|
||||||
|
|
||||||
#endif // CANCOMMS_H
|
#endif // CANCOMMS_H
|
||||||
|
|
|
@ -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 "globals.h"
|
||||||
//#include "storage.h"
|
//#include "storage.h"
|
||||||
|
|
||||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
|
|
||||||
|
|
||||||
void canCommand()
|
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
|
case 'A': // sends the bytes of realtime values
|
||||||
sendValues(0, packetSize,3); //send values to serial3
|
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
|
case 'G': // this is the reply command sent by the Can interface
|
||||||
//uint8_t Gdata;
|
//uint8_t Gdata;
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
while (Serial3.available() == 0) { }
|
while (Serial3.available() == 0) { }
|
||||||
cancmdfail = Serial3.read();
|
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)
|
if (cancmdfail != 0)
|
||||||
{
|
{
|
||||||
for (byte Gx = 0; Gx < 8; Gx++) //read all 8 bytes of data
|
for (byte Gx = 0; Gx < 8; Gx++) //read all 8 bytes of data
|
||||||
{
|
{
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
while (Serial3.available() == 0) { }
|
while (Serial3.available() == 0) { }
|
||||||
Gdata[Gx] = Serial3.read();
|
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])];
|
Glow = Gdata[(configPage10.caninput_param_start_byte[currentStatus.current_caninchannel])];
|
||||||
|
@ -68,61 +93,129 @@ void canCommand()
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
uint8_t Llength;
|
uint8_t Llength;
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
while (Serial3.available() == 0) { }
|
while (Serial3.available() == 0) { }
|
||||||
canlisten = Serial3.read();
|
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)
|
if (canlisten == 0)
|
||||||
{
|
{
|
||||||
//command request failed and/or data/device was not available
|
//command request failed and/or data/device was not available
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
while (Serial3.available() == 0) { }
|
while (Serial3.available() == 0) { }
|
||||||
Llength= Serial3.read(); // next the number of bytes expected value
|
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 <Llength ;Lcount++)
|
for (uint8_t Lcount = 0; Lcount <Llength ;Lcount++)
|
||||||
{
|
{
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
while (Serial3.available() == 0){}
|
while (Serial3.available() == 0){}
|
||||||
// receive all x bytes into "Lbuffer"
|
// receive all x bytes into "Lbuffer"
|
||||||
Lbuffer[Lcount] = Serial3.read();
|
Lbuffer[Lcount] = Serial3.read();
|
||||||
|
#elif defined(CORE_STM32)
|
||||||
|
while (Serial2.available() == 0){}
|
||||||
|
// receive all x bytes into "Lbuffer"
|
||||||
|
Lbuffer[Lcount] = Serial2.read();
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
while (Serial2.available() == 0){}
|
||||||
|
// receive all x bytes into "Lbuffer"
|
||||||
|
Lbuffer[Lcount] = Serial2.read();
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r': //New format for the optimised OutputChannels
|
case 'r': //New format for the optimised OutputChannels
|
||||||
// cmdPending = true;
|
|
||||||
byte cmd;
|
byte cmd;
|
||||||
if (Serial.available() < 6) { return; }
|
byte tsCanId_sent;
|
||||||
Serial.read(); //Read the $tsCanId
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||||
cmd = Serial.read();
|
if (Serial3.available() < 6) { return; }
|
||||||
|
tsCanId_sent = Serial3.read(); //Read the $tsCanId
|
||||||
|
cmd = Serial3.read();
|
||||||
|
#elif defined(CORE_STM32)
|
||||||
|
if (Serial2.available() < 6) { return; }
|
||||||
|
tsCanId_sent = Serial2.read(); //Read the $tsCanId
|
||||||
|
cmd = Serial2.read();
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
if (Serial2.available() < 6) { return; }
|
||||||
|
tsCanId_sent = Serial2.read(); //Read the $tsCanId
|
||||||
|
cmd = Serial2.read();
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
uint16_t offset, length;
|
uint16_t offset, length;
|
||||||
if(cmd == 0x30) //Send output channels command 0x30 is 48dec
|
if(cmd == 0x30) //Send output channels command 0x30 is 48dec
|
||||||
{
|
{
|
||||||
byte tmp;
|
byte tmp;
|
||||||
tmp = Serial.read();
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||||
offset = word(Serial.read(), tmp);
|
tmp = Serial3.read();
|
||||||
tmp = Serial.read();
|
offset = word(Serial3.read(), tmp);
|
||||||
length = word(Serial.read(), tmp);
|
tmp = Serial3.read();
|
||||||
|
length = word(Serial3.read(), tmp);
|
||||||
|
#elif defined(CORE_STM32)
|
||||||
|
tmp = Serial2.read();
|
||||||
|
offset = word(Serial2.read(), tmp);
|
||||||
|
tmp = Serial2.read();
|
||||||
|
length = word(Serial2.read(), tmp);
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
tmp = Serial2.read();
|
||||||
|
offset = word(Serial2.read(), tmp);
|
||||||
|
tmp = Serial2.read();
|
||||||
|
length = word(Serial2.read(), tmp);
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
sendValues(offset, length, 3);
|
sendValues(offset, length, 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//No other r/ commands should be called
|
//No other r/ commands should be called
|
||||||
}
|
}
|
||||||
cmdPending = false;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'S': // send code version
|
case 'S': // send code version
|
||||||
for (unsigned int sig = 0; sig < sizeof(displaySignature) - 1; sig++){
|
for (unsigned int sig = 0; sig < sizeof(displaySignature) - 1; sig++){
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||||
Serial3.write(displaySignature[sig]);
|
Serial3.write(displaySignature[sig]);
|
||||||
|
#elif defined(CORE_STM32)
|
||||||
|
Serial2.write(displaySignature[sig]);
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
Serial2.write(displaySignature[sig]);
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//Serial3.print("speeduino 201609-dev");
|
//Serial3.print("speeduino 201609-dev");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Q': // send code version
|
case 'Q': // send code version
|
||||||
for (unsigned int revn = 0; revn < sizeof( TSfirmwareVersion) - 1; revn++){
|
for (unsigned int revn = 0; revn < sizeof( TSfirmwareVersion) - 1; revn++){
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||||
Serial3.write( TSfirmwareVersion[revn]);
|
Serial3.write( TSfirmwareVersion[revn]);
|
||||||
|
#elif defined(CORE_STM32)
|
||||||
|
Serial2.write( TSfirmwareVersion[revn]);
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
Serial2.write( TSfirmwareVersion[revn]);
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//Serial3.print("speeduino 201609-dev");
|
//Serial3.print("speeduino 201609-dev");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'Z': //dev use
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -134,32 +227,65 @@ void sendCancommand(uint8_t cmdtype, uint16_t canaddress, uint8_t candata1, uint
|
||||||
switch (cmdtype)
|
switch (cmdtype)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||||
Serial3.print("G");
|
Serial3.print("G");
|
||||||
Serial3.write(canaddress); //tscanid of speeduino device
|
Serial3.write(canaddress); //tscanid of speeduino device
|
||||||
Serial3.write(candata1); // table id
|
Serial3.write(candata1); // table id
|
||||||
Serial3.write(candata2); //table memory offset
|
Serial3.write(candata2); //table memory offset
|
||||||
|
#elif defined(CORE_STM32)
|
||||||
|
Serial2.print("G");
|
||||||
|
Serial2.write(canaddress); //tscanid of speeduino device
|
||||||
|
Serial2.write(candata1); // table id
|
||||||
|
Serial2.write(candata2); //table memory offset
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
Serial2.print("G");
|
||||||
|
Serial2.write(canaddress); //tscanid of speeduino device
|
||||||
|
Serial2.write(candata1); // table id
|
||||||
|
Serial2.write(candata2); //table memory offset
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: //send request to listen for a can message
|
case 1: //send request to listen for a can message
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||||
Serial3.print("L");
|
Serial3.print("L");
|
||||||
Serial3.write(canaddress); //11 bit canaddress of device to listen for
|
Serial3.write(canaddress); //11 bit canaddress of device to listen for
|
||||||
|
#elif defined(CORE_STM32)
|
||||||
|
Serial2.print("L");
|
||||||
|
Serial2.write(canaddress); //11 bit canaddress of device to listen for
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
Serial2.print("L");
|
||||||
|
Serial2.write(canaddress); //11 bit canaddress of device to listen for
|
||||||
|
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
Serial3.print("R");
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
||||||
|
Serial3.print("R"); //send "R" to request data from the parmagroup whos value is sent next
|
||||||
Serial3.write( lowByte(paramgroup) ); //send lsb first
|
Serial3.write( lowByte(paramgroup) ); //send lsb first
|
||||||
Serial3.write( lowByte(paramgroup >> 8) );
|
Serial3.write( lowByte(paramgroup >> 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;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
//send to truecan send routine
|
//send to truecan send routine
|
||||||
|
#if defined(CORE_STM32)
|
||||||
|
|
||||||
|
#elif defined(CORE_TEENSY)
|
||||||
|
#else return;
|
||||||
|
#endif
|
||||||
break;
|
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
|
|
||||||
|
|
Loading…
Reference in New Issue