changes to serial3 protocol and further tidyng with new canserial use

This commit is contained in:
darren siepka 2017-06-13 02:58:00 +01:00
parent 5428715eb4
commit 0296f06438
6 changed files with 98 additions and 93 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<msq xmlns="http://www.msefi.com/:msq"> <msq xmlns="http://www.msefi.com/:msq">
<bibliography author="TunerStudio MS(Beta) 3.0.22 - EFI Analytics, Inc." tuneComment="" writeDate="Mon Jun 05 14:40:33 AEST 2017"/> <bibliography author="TunerStudio MS(Beta) 3.0.23 - EFI Analytics, Inc." tuneComment="" writeDate="Sat Jun 10 23:42:28 BST 2017"/>
<versionInfo fileFormat="5.0" firmwareInfo="Speeduino+2017.05" nPages="10" signature="speeduino 201705"/> <versionInfo fileFormat="5.0" firmwareInfo="Speeduino+2017.06-dev" nPages="10" signature="speeduino 201706-dev"/>
<page> <page>
<pcVariable name="tsCanId">"CAN ID 0"</pcVariable> <pcVariable name="tsCanId">"CAN ID 0"</pcVariable>
</page> </page>
@ -216,7 +216,7 @@
<constant name="useResync">"No"</constant> <constant name="useResync">"No"</constant>
<constant digits="1" name="sparkDur" units="ms">25.5</constant> <constant digits="1" name="sparkDur" units="ms">25.5</constant>
<constant digits="0" name="IdleAdvRPM" units="RPM">3200.0</constant> <constant digits="0" name="IdleAdvRPM" units="RPM">3200.0</constant>
<constant digits="1" name="IdleAdvCLT" units="C">-21.0</constant> <constant digits="0" name="IdleAdvCLT" units="F">-5.814</constant>
<constant digits="0" name="IdleDelayTime" units="sec">38.0</constant> <constant digits="0" name="IdleDelayTime" units="sec">38.0</constant>
<constant digits="0" name="StgCycles" units="cycles">2.0</constant> <constant digits="0" name="StgCycles" units="cycles">2.0</constant>
<constant name="dwellcont">"Dwell control"</constant> <constant name="dwellcont">"Dwell control"</constant>
@ -247,17 +247,17 @@
74.0 74.0
85.0 85.0
</constant> </constant>
<constant cols="1" digits="0" name="wueBins" rows="10" units="C"> <constant cols="1" digits="0" name="wueBins" rows="10" units="F">
-40.0 -40.014
-26.0 -14.814
-8.0 17.586
9.0 48.186
26.0 78.786
38.0 100.386
49.0 120.186
60.0 139.986
69.0 156.186
80.0 175.986
</constant> </constant>
<constant digits="0" name="dwellLim" units="ms">8.0</constant> <constant digits="0" name="dwellLim" units="ms">8.0</constant>
<constant cols="1" digits="0" name="dwellRates" rows="6" units="%"> <constant cols="1" digits="0" name="dwellRates" rows="6" units="%">
@ -268,13 +268,13 @@
91.0 91.0
85.0 85.0
</constant> </constant>
<constant cols="1" digits="0" name="iatRetBins" rows="6" units="C"> <constant cols="1" digits="0" name="iatRetBins" rows="6" units="F">
58.0 136.386
82.0 179.586
93.0 199.386
104.0 219.186
116.0 240.786
140.0 283.986
</constant> </constant>
<constant cols="1" digits="0" name="iatRetRates" rows="6" units="deg"> <constant cols="1" digits="0" name="iatRetRates" rows="6" units="deg">
0.0 0.0
@ -356,7 +356,7 @@
<constant digits="0" name="egoKP" units="%">100.0</constant> <constant digits="0" name="egoKP" units="%">100.0</constant>
<constant digits="0" name="egoKI" units="%">20.0</constant> <constant digits="0" name="egoKI" units="%">20.0</constant>
<constant digits="0" name="egoKD" units="%">0.0</constant> <constant digits="0" name="egoKD" units="%">0.0</constant>
<constant digits="0" name="egoTemp" units="C">70.0</constant> <constant digits="0" name="egoTemp" units="F">157.986</constant>
<constant digits="0" name="egoCount">16.0</constant> <constant digits="0" name="egoCount">16.0</constant>
<constant digits="0" name="egoDelta" units="%">1.0</constant> <constant digits="0" name="egoDelta" units="%">1.0</constant>
<constant digits="0" name="egoLimit">15.0</constant> <constant digits="0" name="egoLimit">15.0</constant>
@ -387,16 +387,16 @@
100.0 100.0
98.0 98.0
</constant> </constant>
<constant cols="1" digits="0" name="airDenBins" rows="9" units="C"> <constant cols="1" digits="0" name="airDenBins" rows="9" units="F">
-40.0 -40.014
-20.0 -4.014
0.0 31.986
20.0 67.986
35.0 94.986
50.0 121.986
60.0 139.986
90.0 193.986
120.0 247.986
</constant> </constant>
<constant cols="1" digits="0" name="airDenRates" rows="9" units="%"> <constant cols="1" digits="0" name="airDenRates" rows="9" units="%">
126.0 126.0
@ -474,17 +474,17 @@
16.0 16.0
9.0 9.0
</constant> </constant>
<constant cols="1" digits="0" name="iacBins" rows="10" units="C"> <constant cols="1" digits="0" name="iacBins" rows="10" units="F">
-38.0 -36.414
-19.0 -2.214
1.0 33.786
17.0 62.586
34.0 93.186
50.0 121.986
63.0 145.386
79.0 174.186
98.0 208.386
143.0 289.386
</constant> </constant>
<constant cols="1" digits="0" name="iacCrankSteps" rows="4" units="Steps"> <constant cols="1" digits="0" name="iacCrankSteps" rows="4" units="Steps">
123.0 123.0
@ -498,30 +498,30 @@
44.0 44.0
60.0 60.0
</constant> </constant>
<constant cols="1" digits="0" name="iacCrankBins" rows="4" units="C"> <constant cols="1" digits="0" name="iacCrankBins" rows="4" units="F">
-28.0 -18.414
6.0 42.786
44.0 111.186
76.0 168.786
</constant> </constant>
<constant name="iacAlgorithm">"None"</constant> <constant name="iacAlgorithm">"None"</constant>
<constant name="iacStepTime">"3"</constant> <constant name="iacStepTime">"3"</constant>
<constant name="iacChannels">"1"</constant> <constant name="iacChannels">"1"</constant>
<constant name="iacPWMdir">"Normal"</constant> <constant name="iacPWMdir">"Normal"</constant>
<constant digits="0" name="iacFastTemp" units="C">20.0</constant> <constant digits="0" name="iacFastTemp" units="F">67.986</constant>
<constant digits="0" name="iacStepHome" units="Steps">240.0</constant> <constant digits="0" name="iacStepHome" units="Steps">240.0</constant>
<constant digits="0" name="iacStepHyster" units="Steps">4.0</constant> <constant digits="0" name="iacStepHyster" units="Steps">4.0</constant>
<constant name="fanInv">"No"</constant> <constant name="fanInv">"No"</constant>
<constant name="fanEnable">"Off"</constant> <constant name="fanEnable">"Off"</constant>
<constant name="fanPin">"Board Default"</constant> <constant name="fanPin">"Board Default"</constant>
<constant digits="0" name="fanSP" units="C">75.0</constant> <constant digits="0" name="fanSP" units="F">166.986</constant>
<constant digits="0" name="fanHyster" units="C">2.0</constant> <constant digits="0" name="fanHyster" units="F">36.0</constant>
<constant digits="0" name="fanFreq" units="Hz">6.0</constant> <constant digits="0" name="fanFreq" units="Hz">6.0</constant>
<constant cols="1" digits="0" name="fanPWMBins" rows="4" units="C"> <constant cols="1" digits="0" name="fanPWMBins" rows="4" units="F">
60.0 139.986
-20.0 -4.014
-40.0 -40.014
158.0 316.386
</constant> </constant>
</page> </page>
<page number="7" size="160"> <page number="7" size="160">
@ -713,6 +713,14 @@
<constant name="caninput_param_start_byte6">"8"</constant> <constant name="caninput_param_start_byte6">"8"</constant>
<constant name="caninput_param_start_byte7">"8"</constant> <constant name="caninput_param_start_byte7">"8"</constant>
<constant name="caninput_param_start_byte8">"8"</constant> <constant name="caninput_param_start_byte8">"8"</constant>
<constant name="caninput_param_num_bytes1">"1"</constant>
<constant name="caninput_param_num_bytes2">"1"</constant>
<constant name="caninput_param_num_bytes3">"1"</constant>
<constant name="caninput_param_num_bytes4">"1"</constant>
<constant name="caninput_param_num_bytes5">"1"</constant>
<constant name="caninput_param_num_bytes6">"1"</constant>
<constant name="caninput_param_num_bytes7">"1"</constant>
<constant name="caninput_param_num_bytes8">"1"</constant>
<constant digits="0" name="unused10_41">255.0</constant> <constant digits="0" name="unused10_41">255.0</constant>
<constant digits="0" name="unused10_42">255.0</constant> <constant digits="0" name="unused10_42">255.0</constant>
<constant digits="0" name="unused10_43">255.0</constant> <constant digits="0" name="unused10_43">255.0</constant>
@ -772,6 +780,7 @@
<constant digits="0" name="unused10_97">255.0</constant> <constant digits="0" name="unused10_97">255.0</constant>
<constant digits="0" name="unused10_98">255.0</constant> <constant digits="0" name="unused10_98">255.0</constant>
<constant digits="0" name="unused10_99">255.0</constant> <constant digits="0" name="unused10_99">255.0</constant>
<constant name="speeduino_tsCanId">"CAN ID 0"</constant>
<constant digits="0" name="unused10_101">255.0</constant> <constant digits="0" name="unused10_101">255.0</constant>
<constant digits="0" name="unused10_103">255.0</constant> <constant digits="0" name="unused10_103">255.0</constant>
<constant digits="0" name="unused10_105">255.0</constant> <constant digits="0" name="unused10_105">255.0</constant>
@ -799,9 +808,9 @@
</page> </page>
<settings Comment="These setting are only used if this msq is opened without a project."> <settings Comment="These setting are only used if this msq is opened without a project.">
<setting name="enablehardware_test_OFF" value="enablehardware_test_OFF"/> <setting name="enablehardware_test_OFF" value="enablehardware_test_OFF"/>
<setting name="FAHRENHEIT" value="FAHRENHEIT"/>
<setting name="SPEED_DENSITY" value="SPEED_DENSITY"/> <setting name="SPEED_DENSITY" value="SPEED_DENSITY"/>
<setting name="CAN_COMMANDS_OFF" value="CAN_COMMANDS_OFF"/> <setting name="CAN_COMMANDS_OFF" value="CAN_COMMANDS_OFF"/>
<setting name="CELSIUS" value="CELSIUS"/>
<setting name="AFR" value="AFR"/> <setting name="AFR" value="AFR"/>
</settings> </settings>
<userComments Comment="These are user comments that can be related to a particular setting or dialog."/> <userComments Comment="These are user comments that can be related to a particular setting or dialog."/>

View File

@ -738,9 +738,9 @@ page = 10
defaultValue = boostMaxDuty,100 defaultValue = boostMaxDuty,100
defaultValue = sparkDur, 1.0 defaultValue = sparkDur, 1.0
defaultValue = speeduino_tsCanId, 0 defaultValue = speeduino_tsCanId, 0
;defaultValue = true_address, 0 ; defaultValue = true_address, 0
;defaultValue = realtime_base_address, 0 ; defaultValue = realtime_base_address, 0
;defaultValue = obd_address, 0 ; defaultValue = obd_address, 0
;Default pins ;Default pins
defaultValue = fanPin, 0 defaultValue = fanPin, 0
@ -949,9 +949,9 @@ menuDialog = main
#else #else
enable_canbus = "This Enables the IO on the secondary serial port. This is serial3 on mega2560 processor, and Serial2 on STM32 and Teensy processor " enable_canbus = "This Enables the IO on the secondary serial port. This is serial3 on mega2560 processor, and Serial2 on STM32 and Teensy processor "
#endif #endif
speeduino_tsCanId = "This is the TsCanId that the Speeduino ECU will respond to. This should match the main controller CAN ID in project properties if it is connected directy to TunerStudio, Otherwise the device ID if connected via CAN passthrough" ;speeduino_tsCanId = "This is the TsCanId that the Speeduino ECU will respond to. This should match the main controller CAN ID in project properties if it is connected directy to TunerStudio, Otherwise the device ID if connected via CAN passthrough"
true_address = "This is the 11bit Can address of the Speeduino ECU " ;true_address = "This is the 11bit Can address of the Speeduino ECU "
obd_address = "The 11bit Can address that the Speeduino ECU responds to for OBD2 diagnostic requests" ;obd_address = "The 11bit Can address that the Speeduino ECU responds to for OBD2 diagnostic requests"
caninput_sel1 = "This Enables CAN data input channel 1 " caninput_sel1 = "This Enables CAN data input channel 1 "
caninput_sel2 = "This Enables CAN data input channel 2 " caninput_sel2 = "This Enables CAN data input channel 2 "
caninput_sel3 = "This Enables CAN data input channel 3 " caninput_sel3 = "This Enables CAN data input channel 3 "
@ -1588,9 +1588,9 @@ menuDialog = main
dialog = can_serial3IO, "CanBus/Serial3 IO interface" dialog = can_serial3IO, "CanBus/Serial3 IO interface"
topicHelp = "http://speeduino.com/wiki/index.php/Secondary_Serial_IO_interface" topicHelp = "http://speeduino.com/wiki/index.php/Secondary_Serial_IO_interface"
field = "Enable CanBus/Second Serial", enable_canbus field = "Enable CanBus/Second Serial", enable_canbus
field = "Speeduino TsCanId", speeduino_tsCanId ; field = "Speeduino TsCanId", speeduino_tsCanId
field = "Realtime Data Base Can Address", realtime_base_address ; field = "Realtime Data Base Can Address", realtime_base_address
field = "Speeduino OBD address", obd_address ; field = "Speeduino OBD address", obd_address
dialog = serial3IO, "Serial3 IO interface" dialog = serial3IO, "Serial3 IO interface"
topicHelp = "http://speeduino.com/wiki/index.php/Serial3_IO_interface" topicHelp = "http://speeduino.com/wiki/index.php/Serial3_IO_interface"

View File

@ -18,7 +18,7 @@ void canCommand()
switch (currentcanCommand) 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,0x30,3); //send values to serial3
break; break;
case 'G': // this is the reply command sent by the Can interface case 'G': // this is the reply command sent by the Can interface
@ -86,23 +86,22 @@ void canCommand()
break; break;
case 'r': //New format for the optimised OutputChannels case 'r': //New format for the optimised OutputChannels
byte cmd; byte Cmd;
if (CANSerial.available() >= 6) if (CANSerial.available() >= 6)
{ {
CANSerial.read(); //Read the $tsCanId CANSerial.read(); //Read the $tsCanId
cmd = CANSerial.read(); Cmd = CANSerial.read();
uint16_t offset, length; uint16_t offset, length;
if(cmd == 0x30) //Send output channels command 0x30 is 48dec if((Cmd == 0x30) || (Cmd >= 0x40 && Cmd <0x50) ) //Send output channels command 0x30 is 48dec, 0x40(64dec)-0x4F are external can request
{ {
byte tmp; byte tmp;
tmp = CANSerial.read(); tmp = CANSerial.read();
offset = word(CANSerial.read(), tmp); offset = word(CANSerial.read(), tmp);
tmp = CANSerial.read(); tmp = CANSerial.read();
length = word(CANSerial.read(), tmp); length = word(CANSerial.read(), tmp);
sendValues(offset, length,Cmd, 3);
sendValues(offset, length, 3);
} }
else else
{ {

View File

@ -40,7 +40,7 @@ const char pageTitles[] PROGMEM //This is being stored in the avr flash instead
}; };
void command();//This is the heart of the Command Line Interpeter. All that needed to be done was to make it human readable. void command();//This is the heart of the Command Line Interpeter. All that needed to be done was to make it human readable.
void sendValues(uint16_t offset, uint16_t packetlength, byte portnum); void sendValues(uint16_t offset, uint16_t packetlength,byte cmd, byte portnum);
void receiveValue(int offset, byte newValue); void receiveValue(int offset, byte newValue);
void saveConfig(); void saveConfig();
void sendPage(bool useChar); void sendPage(bool useChar);

View File

@ -21,7 +21,7 @@ void command()
{ {
case 'A': // send x bytes of realtime values case 'A': // send x bytes of realtime values
sendValues(0, packetSize, 0); //send values to serial0 sendValues(0, packetSize,0x30, 0); //send values to serial0
break; break;
@ -190,7 +190,7 @@ void command()
offset = word(Serial.read(), tmp); offset = word(Serial.read(), tmp);
tmp = Serial.read(); tmp = Serial.read();
length = word(Serial.read(), tmp); length = word(Serial.read(), tmp);
sendValues(offset, length, 0); sendValues(offset, length,cmd, 0);
} }
else else
{ {
@ -244,33 +244,23 @@ void command()
This function returns the current values of a fixed group of variables This function returns the current values of a fixed group of variables
*/ */
//void sendValues(int packetlength, byte portNum) //void sendValues(int packetlength, byte portNum)
void sendValues(uint16_t offset, uint16_t packetLength, byte portNum) void sendValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portNum)
{ {
byte fullStatus[packetSize]; byte fullStatus[packetSize];
if (portNum == 3) if (portNum == 3)
{ {
//CAN serial //CAN serial
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)|| defined(CORE_STM32) || defined (CORE_TEENSY) //ATmega2561 does not have Serial3
if (offset == 0) if (offset == 0)
{ {
Serial3.write("A"); //confirm cmd type CANSerial.write("A"); //confirm cmd type
} }
else else
{ {
Serial3.write("r"); //confirm cmd type CANSerial.write("r"); //confirm cmd type
CANSerial.write(cmd);
} }
Serial3.write(packetLength); //confirm no of byte to be sent
#elif defined(CORE_STM32) || defined (CORE_TEENSY)
if (offset == 0)
{
Serial2.write("A"); //confirm cmd type
}
else
{
Serial2.write("r"); //confirm cmd type
}
Serial2.write(packetLength); //confirm no of byte to be sent
#endif #endif
} }
else else
@ -350,7 +340,14 @@ void sendValues(uint16_t offset, uint16_t packetLength, byte portNum)
for(byte x=0; x<packetLength; x++) for(byte x=0; x<packetLength; x++)
{ {
if (portNum == 0) { Serial.write(fullStatus[offset+x]); } if (portNum == 0) { Serial.write(fullStatus[offset+x]); }
else if (portNum == 3) { CANSerial.write(fullStatus[offset+x]); } else if (portNum == 3){ CANSerial.write(fullStatus[offset+x]); }
//if (portNum == 3) //TESTING USE!
//{
// Serial.print("r"); //confirm cmd type
// Serial.print(cmd);
// Serial.print(fullStatus[offset+x]);
//}
} }
} }

View File

@ -852,9 +852,9 @@ void loop()
//if serial3 interface is enabled then check for serial3 requests. //if serial3 interface is enabled then check for serial3 requests.
if (configPage10.enable_canbus == 1) if (configPage10.enable_canbus == 1)
{ {
if ( ((mainLoopCount & 31) == 1) or (Serial3.available() > SERIAL_BUFFER_THRESHOLD) ) if ( ((mainLoopCount & 31) == 1) or (CANSerial.available() > SERIAL_BUFFER_THRESHOLD) )
{ {
if (Serial3.available() > 0) if (CANSerial.available() > 0)
{ {
canCommand(); canCommand();
} }