Merge pull request #17 from Autohome2/master

revised to share sendvalues() function and to use signature and firmw…
This commit is contained in:
Autohome2 2016-09-29 12:52:36 +01:00 committed by GitHub
commit c706ed918c
4 changed files with 41 additions and 84 deletions

View File

@ -19,12 +19,12 @@ void Cancommand()
{
switch (Serial3.read())
{
case 'A': // sends all the bytes of realtime values
sendCanValues();
break;
case 'A': // sends the bytes of realtime values
sendValues(packetSize,3); //send values to serial3
break;
case 'G': // this is the reply command sent by the Can interface
uint8_t Gdata;
uint8_t Gdata;
while (Serial3.available() == 0) { }
cancmdfail = Serial3.read();
if (cancmdfail == 0)
@ -33,10 +33,10 @@ void Cancommand()
}
while (Serial3.available() == 0) { }
Gdata= Serial3.read();
break;
break;
case 'L':
uint8_t Llength;
case 'L':
uint8_t Llength;
while (Serial3.available() == 0) { }
canlisten = Serial3.read();
if (canlisten == 0)
@ -52,79 +52,27 @@ void Cancommand()
// receive all x bytes into "Lbuffer"
Lbuffer[Lcount] = Serial3.read();
}
break;
break;
case 'S': // send code version
Serial3.print("Speeduino 2016.09_canio");
break;
for (unsigned int sig = 0; sig < sizeof(displaySignature) - 1; sig++){
Serial3.write(displaySignature[sig]);
}
//Serial3.print("speeduino 201609-dev");
break;
case 'Q': // send code version
Serial3.print("speeduino 201609-dev_canio");
break;
for (unsigned int revn = 0; revn < sizeof( TSfirmwareVersion) - 1; revn++){
Serial3.write( TSfirmwareVersion[revn]);
}
//Serial3.print("speeduino 201609-dev");
break;
default:
break;
break;
}
}
/*
This function returns the current values of a fixed group of variables. if this list is changed so must the list in the Can interface to prevent errors
*/
void sendCanValues()
{
uint8_t packetSize = 34;
uint8_t response[packetSize];
Serial3.write("A"); //confirm cmd type
Serial3.write(packetSize); //confirm no of byte to be sent
//now send the data
response[0] = currentStatus.secl; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
response[1] = currentStatus.squirt; //Squirt Bitfield
response[2] = currentStatus.engine; //Engine Status Bitfield
response[3] = (byte)(divu100(currentStatus.dwell)); //Dwell in ms * 10
response[4] = (byte)(currentStatus.MAP >> 1); //map value is divided by 2
response[5] = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); //mat
response[6] = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //Coolant ADC
response[7] = currentStatus.tpsADC; //TPS (Raw 0-255)
response[8] = currentStatus.battery10; //battery voltage
response[9] = currentStatus.O2; //O2
response[10] = currentStatus.egoCorrection; //Exhaust gas correction (%)
response[11] = currentStatus.iatCorrection; //Air temperature Correction (%)
response[12] = currentStatus.wueCorrection; //Warmup enrichment (%)
response[13] = lowByte(currentStatus.RPM); //rpm HB
response[14] = highByte(currentStatus.RPM); //rpm LB
response[15] = currentStatus.TAEamount; //acceleration enrichment (%)
response[16] = 0x00; //Barometer correction (%)
response[17] = currentStatus.corrections; //Total GammaE (%)
response[18] = currentStatus.VE; //Current VE 1 (%)
response[19] = currentStatus.afrTarget;
response[20] = (byte)(currentStatus.PW / 100); //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
response[21] = currentStatus.tpsDOT; //TPS DOT
response[22] = currentStatus.advance;
response[23] = currentStatus.TPS; // TPS (0% to 100%)
//Need to split the int loopsPerSecond value into 2 bytes
response[24] = lowByte(currentStatus.loopsPerSecond);
response[25] = highByte(currentStatus.loopsPerSecond);
//The following can be used to show the amount of free memory
currentStatus.freeRAM = freeRam();
response[26] = lowByte(currentStatus.freeRAM); //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF);
response[27] = highByte(currentStatus.freeRAM);
response[28] = currentStatus.batCorrection; //Battery voltage correction (%)
response[29] = currentStatus.spark; //Spark related bitfield
response[30] = currentStatus.O2_2; //O2
//rpmDOT must be sent as a signed integer
response[31] = lowByte(currentStatus.rpmDOT);
response[32] = highByte(currentStatus.rpmDOT);
response[33] = currentStatus.flex; //Flex sensor value (or 0 if not used)
Serial3.write(response, (size_t)packetSize);
return;
}
// this routine sends a request(either "0" for a "G" or "1" for a "L" to the Can interface
void sendCancommand(uint8_t cmdtype, uint16_t canaddress, uint8_t candata1, uint8_t candata2)
{

View File

@ -28,7 +28,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 sendValues();
void sendValues(int packetlength, byte portnum);
void receiveValue(int offset, byte newValue);
void saveConfig();
void sendPage(bool useChar);

View File

@ -17,8 +17,8 @@ void command()
{
switch (Serial.read())
{
case 'A': // send 22 bytes of realtime values
sendValues(22);
case 'A': // send x bytes of realtime values
sendValues(packetSize,0); //send values to serial0
break;
case 'B': // Burn current values to eeprom
@ -54,7 +54,7 @@ void command()
break;
case 'R': // send 39 bytes of realtime values
sendValues(39);
sendValues(39,0);
break;
case 'F': // send serial protocol version
@ -198,13 +198,20 @@ void command()
/*
This function returns the current values of a fixed group of variables
*/
void sendValues(int length)
void sendValues(int packetlength, byte portnum)
{
byte packetSize = 35;
byte response[packetSize];
if(requestCount == 0) { currentStatus.secl = 0; }
requestCount++;
byte response[packetlength];
if (portnum == 3){ //if port number is 3
Serial3.write("A"); //confirm cmd type
Serial3.write(packetlength); //confirm no of byte to be sent
}
else
{
if(requestCount == 0) { currentStatus.secl = 0; }
requestCount++;
}
currentStatus.spark ^= (-currentStatus.hasSync ^ currentStatus.spark) & (1 << BIT_SPARK_SYNC); //Set the sync bit of the Spark variable to match the hasSync variable
@ -253,7 +260,8 @@ void sendValues(int length)
response[34] = getNextError();
//cli();
Serial.write(response, (size_t)packetSize);
if (portnum == 0){Serial.write(response, (size_t)packetlength);}
else if (portnum == 3){Serial3.write(response, (size_t)packetlength);}
//Serial.flush();
//sei();
return;

View File

@ -6,12 +6,13 @@
const byte signature = 20;
//const char signature[] = "speeduino";
const char displaySignature[] = "Speeduino";
const char TSfirmwareVersion[] = "2016.05";
const char displaySignature[] = "speeduino 201609-dev";
const char TSfirmwareVersion[] = "Speeduino 2016.09";
const byte data_structure_version = 2; //This identifies the data structure when reading / writing.
const byte page_size = 64;
const int map_page_size = 288;
const byte packetSize = 35;
//Handy bitsetting macros
#define BIT_SET(a,b) ((a) |= (1<<(b)))