Remove fullStatus array for comms

This commit is contained in:
Josh Stewart 2021-02-02 13:14:47 +11:00
parent 132cc6200d
commit a810bfbfd1
5 changed files with 150 additions and 136 deletions

View File

@ -98,6 +98,6 @@ void testComm();
void commandButtons(int16_t);
void sendCompositeLog(uint8_t);
byte getPageValue(byte, uint16_t);
void updateFullStatus();
byte getStatusEntry(uint16_t);
#endif // COMMS_H

View File

@ -728,144 +728,161 @@ void command()
}
}
void updateFullStatus()
byte getStatusEntry(uint16_t byteNum)
{
fullStatus[0] = currentStatus.secl; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
fullStatus[1] = currentStatus.status1; //status1 Bitfield
fullStatus[2] = currentStatus.engine; //Engine Status Bitfield
fullStatus[3] = currentStatus.syncLossCounter;
fullStatus[4] = lowByte(currentStatus.MAP); //2 bytes for MAP
fullStatus[5] = highByte(currentStatus.MAP);
fullStatus[6] = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); //mat
fullStatus[7] = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //Coolant ADC
fullStatus[8] = currentStatus.batCorrection; //Battery voltage correction (%)
fullStatus[9] = currentStatus.battery10; //battery voltage
fullStatus[10] = currentStatus.O2; //O2
fullStatus[11] = currentStatus.egoCorrection; //Exhaust gas correction (%)
fullStatus[12] = currentStatus.iatCorrection; //Air temperature Correction (%)
fullStatus[13] = currentStatus.wueCorrection; //Warmup enrichment (%)
fullStatus[14] = lowByte(currentStatus.RPM); //rpm HB
fullStatus[15] = highByte(currentStatus.RPM); //rpm LB
fullStatus[16] = (byte)(currentStatus.AEamount >> 1); //TPS acceleration enrichment (%) divided by 2 (Can exceed 255)
fullStatus[17] = lowByte(currentStatus.corrections); //Total GammaE (%)
fullStatus[18] = highByte(currentStatus.corrections); //Total GammaE (%)
fullStatus[19] = currentStatus.VE1; //VE 1 (%)
fullStatus[20] = currentStatus.VE2; //VE 2 (%)
fullStatus[21] = currentStatus.afrTarget;
fullStatus[22] = currentStatus.tpsDOT; //TPS DOT
fullStatus[23] = currentStatus.advance;
fullStatus[24] = currentStatus.TPS; // TPS (0% to 100%)
//Need to split the int loopsPerSecond value into 2 bytes
if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;}
fullStatus[25] = lowByte(currentStatus.loopsPerSecond);
fullStatus[26] = highByte(currentStatus.loopsPerSecond);
byte statusValue = 0;
//The following can be used to show the amount of free memory
currentStatus.freeRAM = freeRam();
fullStatus[27] = lowByte(currentStatus.freeRAM); //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF);
fullStatus[28] = highByte(currentStatus.freeRAM);
switch(byteNum)
{
case 0: statusValue = currentStatus.secl; break; //secl is simply a counter that increments each second. Used to track unexpected resets (Which will reset this count to 0)
case 1: statusValue = currentStatus.status1; break; //status1 Bitfield
case 2: statusValue = currentStatus.engine; break; //Engine Status Bitfield
case 3: statusValue = currentStatus.syncLossCounter; break;
case 4: statusValue = lowByte(currentStatus.MAP); break; //2 bytes for MAP
case 5: statusValue = highByte(currentStatus.MAP); break;
case 6: statusValue = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); break; //mat
case 7: statusValue = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); break; //Coolant ADC
case 8: statusValue = currentStatus.batCorrection; break; //Battery voltage correction (%)
case 9: statusValue = currentStatus.battery10; break; //battery voltage
case 10: statusValue = currentStatus.O2; break; //O2
case 11: statusValue = currentStatus.egoCorrection; break; //Exhaust gas correction (%)
case 12: statusValue = currentStatus.iatCorrection; break; //Air temperature Correction (%)
case 13: statusValue = currentStatus.wueCorrection; break; //Warmup enrichment (%)
case 14: statusValue = lowByte(currentStatus.RPM); break; //rpm HB
case 15: statusValue = highByte(currentStatus.RPM); break; //rpm LB
case 16: statusValue = (byte)(currentStatus.AEamount >> 1); break; //TPS acceleration enrichment (%) divided by 2 (Can exceed 255)
case 17: statusValue = lowByte(currentStatus.corrections); break; //Total GammaE (%)
case 18: statusValue = highByte(currentStatus.corrections); break; //Total GammaE (%)
case 19: statusValue = currentStatus.VE1; break; //VE 1 (%)
case 20: statusValue = currentStatus.VE2; break; //VE 2 (%)
case 21: statusValue = currentStatus.afrTarget; break;
case 22: statusValue = currentStatus.tpsDOT; break; //TPS DOT
case 23: statusValue = currentStatus.advance; break;
case 24: statusValue = currentStatus.TPS; break; // TPS (0% to 100%)
case 25:
if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;}
statusValue = lowByte(currentStatus.loopsPerSecond);
break;
case 26:
if(currentStatus.loopsPerSecond > 60000) { currentStatus.loopsPerSecond = 60000;}
statusValue = highByte(currentStatus.loopsPerSecond);
break;
case 27:
currentStatus.freeRAM = freeRam();
statusValue = lowByte(currentStatus.freeRAM); //(byte)((currentStatus.loopsPerSecond >> 8) & 0xFF);
break;
case 28:
currentStatus.freeRAM = freeRam();
statusValue = highByte(currentStatus.freeRAM);
break;
fullStatus[29] = (byte)(currentStatus.boostTarget >> 1); //Divide boost target by 2 to fit in a byte
fullStatus[30] = (byte)(currentStatus.boostDuty / 100);
fullStatus[31] = currentStatus.spark; //Spark related bitfield
case 29: statusValue = (byte)(currentStatus.boostTarget >> 1); break; //Divide boost target by 2 to fit in a byte
case 30: statusValue = (byte)(currentStatus.boostDuty / 100); break;
case 31: statusValue = currentStatus.spark; break; //Spark related bitfield
//rpmDOT must be sent as a signed integer
fullStatus[32] = lowByte(currentStatus.rpmDOT);
fullStatus[33] = highByte(currentStatus.rpmDOT);
//rpmDOT must be sent as a signed integer
case 32: statusValue = lowByte(currentStatus.rpmDOT); break;
case 33: statusValue = highByte(currentStatus.rpmDOT); break;
fullStatus[34] = currentStatus.ethanolPct; //Flex sensor value (or 0 if not used)
fullStatus[35] = currentStatus.flexCorrection; //Flex fuel correction (% above or below 100)
fullStatus[36] = currentStatus.flexIgnCorrection; //Ignition correction (Increased degrees of advance) for flex fuel
case 34: statusValue = currentStatus.ethanolPct; break; //Flex sensor value (or 0 if not used)
case 35: statusValue = currentStatus.flexCorrection; break; //Flex fuel correction (% above or below 100)
case 36: statusValue = currentStatus.flexIgnCorrection; break; //Ignition correction (Increased degrees of advance) for flex fuel
fullStatus[37] = currentStatus.idleLoad;
fullStatus[38] = currentStatus.testOutputs;
case 37: statusValue = currentStatus.idleLoad; break;
case 38: statusValue = currentStatus.testOutputs; break;
fullStatus[39] = currentStatus.O2_2; //O2
fullStatus[40] = currentStatus.baro; //Barometer value
case 39: statusValue = currentStatus.O2_2; break; //O2
case 40: statusValue = currentStatus.baro; break; //Barometer value
fullStatus[41] = lowByte(currentStatus.canin[0]);
fullStatus[42] = highByte(currentStatus.canin[0]);
fullStatus[43] = lowByte(currentStatus.canin[1]);
fullStatus[44] = highByte(currentStatus.canin[1]);
fullStatus[45] = lowByte(currentStatus.canin[2]);
fullStatus[46] = highByte(currentStatus.canin[2]);
fullStatus[47] = lowByte(currentStatus.canin[3]);
fullStatus[48] = highByte(currentStatus.canin[3]);
fullStatus[49] = lowByte(currentStatus.canin[4]);
fullStatus[50] = highByte(currentStatus.canin[4]);
fullStatus[51] = lowByte(currentStatus.canin[5]);
fullStatus[52] = highByte(currentStatus.canin[5]);
fullStatus[53] = lowByte(currentStatus.canin[6]);
fullStatus[54] = highByte(currentStatus.canin[6]);
fullStatus[55] = lowByte(currentStatus.canin[7]);
fullStatus[56] = highByte(currentStatus.canin[7]);
fullStatus[57] = lowByte(currentStatus.canin[8]);
fullStatus[58] = highByte(currentStatus.canin[8]);
fullStatus[59] = lowByte(currentStatus.canin[9]);
fullStatus[60] = highByte(currentStatus.canin[9]);
fullStatus[61] = lowByte(currentStatus.canin[10]);
fullStatus[62] = highByte(currentStatus.canin[10]);
fullStatus[63] = lowByte(currentStatus.canin[11]);
fullStatus[64] = highByte(currentStatus.canin[11]);
fullStatus[65] = lowByte(currentStatus.canin[12]);
fullStatus[66] = highByte(currentStatus.canin[12]);
fullStatus[67] = lowByte(currentStatus.canin[13]);
fullStatus[68] = highByte(currentStatus.canin[13]);
fullStatus[69] = lowByte(currentStatus.canin[14]);
fullStatus[70] = highByte(currentStatus.canin[14]);
fullStatus[71] = lowByte(currentStatus.canin[15]);
fullStatus[72] = highByte(currentStatus.canin[15]);
case 41: statusValue = lowByte(currentStatus.canin[0]); break;
case 42: statusValue = highByte(currentStatus.canin[0]); break;
case 43: statusValue = lowByte(currentStatus.canin[1]); break;
case 44: statusValue = highByte(currentStatus.canin[1]); break;
case 45: statusValue = lowByte(currentStatus.canin[2]); break;
case 46: statusValue = highByte(currentStatus.canin[2]); break;
case 47: statusValue = lowByte(currentStatus.canin[3]); break;
case 48: statusValue = highByte(currentStatus.canin[3]); break;
case 49: statusValue = lowByte(currentStatus.canin[4]); break;
case 50: statusValue = highByte(currentStatus.canin[4]); break;
case 51: statusValue = lowByte(currentStatus.canin[5]); break;
case 52: statusValue = highByte(currentStatus.canin[5]); break;
case 53: statusValue = lowByte(currentStatus.canin[6]); break;
case 54: statusValue = highByte(currentStatus.canin[6]); break;
case 55: statusValue = lowByte(currentStatus.canin[7]); break;
case 56: statusValue = highByte(currentStatus.canin[7]); break;
case 57: statusValue = lowByte(currentStatus.canin[8]); break;
case 58: statusValue = highByte(currentStatus.canin[8]); break;
case 59: statusValue = lowByte(currentStatus.canin[9]); break;
case 60: statusValue = highByte(currentStatus.canin[9]); break;
case 61: statusValue = lowByte(currentStatus.canin[10]); break;
case 62: statusValue = highByte(currentStatus.canin[10]); break;
case 63: statusValue = lowByte(currentStatus.canin[11]); break;
case 64: statusValue = highByte(currentStatus.canin[11]); break;
case 65: statusValue = lowByte(currentStatus.canin[12]); break;
case 66: statusValue = highByte(currentStatus.canin[12]); break;
case 67: statusValue = lowByte(currentStatus.canin[13]); break;
case 68: statusValue = highByte(currentStatus.canin[13]); break;
case 69: statusValue = lowByte(currentStatus.canin[14]); break;
case 70: statusValue = highByte(currentStatus.canin[14]); break;
case 71: statusValue = lowByte(currentStatus.canin[15]); break;
case 72: statusValue = highByte(currentStatus.canin[15]); break;
fullStatus[73] = currentStatus.tpsADC;
fullStatus[74] = getNextError();
case 73: statusValue = currentStatus.tpsADC; break;
case 74: statusValue = getNextError(); break;
fullStatus[75] = lowByte(currentStatus.PW1); //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[76] = highByte(currentStatus.PW1); //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[77] = lowByte(currentStatus.PW2); //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[78] = highByte(currentStatus.PW2); //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[79] = lowByte(currentStatus.PW3); //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[80] = highByte(currentStatus.PW3); //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[81] = lowByte(currentStatus.PW4); //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[82] = highByte(currentStatus.PW4); //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
case 75: statusValue = lowByte(currentStatus.PW1); break; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
case 76: statusValue = highByte(currentStatus.PW1); break; //Pulsewidth 1 multiplied by 10 in ms. Have to convert from uS to mS.
case 77: statusValue = lowByte(currentStatus.PW2); break; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
case 78: statusValue = highByte(currentStatus.PW2); break; //Pulsewidth 2 multiplied by 10 in ms. Have to convert from uS to mS.
case 79: statusValue = lowByte(currentStatus.PW3); break; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
case 80: statusValue = highByte(currentStatus.PW3); break; //Pulsewidth 3 multiplied by 10 in ms. Have to convert from uS to mS.
case 81: statusValue = lowByte(currentStatus.PW4); break; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
case 82: statusValue = highByte(currentStatus.PW4); break; //Pulsewidth 4 multiplied by 10 in ms. Have to convert from uS to mS.
fullStatus[83] = currentStatus.status3;
fullStatus[84] = currentStatus.engineProtectStatus;
fullStatus[85] = lowByte(currentStatus.fuelLoad);
fullStatus[86] = highByte(currentStatus.fuelLoad);
fullStatus[87] = lowByte(currentStatus.ignLoad);
fullStatus[88] = highByte(currentStatus.ignLoad);
fullStatus[89] = lowByte(currentStatus.dwell);
fullStatus[90] = highByte(currentStatus.dwell);
fullStatus[91] = currentStatus.CLIdleTarget;
fullStatus[92] = currentStatus.mapDOT;
fullStatus[93] = (int8_t)currentStatus.vvt1Angle;
fullStatus[94] = currentStatus.vvt1TargetAngle;
fullStatus[95] = currentStatus.vvt1Duty;
fullStatus[96] = lowByte(currentStatus.flexBoostCorrection);
fullStatus[97] = highByte(currentStatus.flexBoostCorrection);
fullStatus[98] = currentStatus.baroCorrection;
fullStatus[99] = currentStatus.VE; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them
fullStatus[100] = currentStatus.ASEValue; //Current ASE (%)
fullStatus[101] = lowByte(currentStatus.vss);
fullStatus[102] = highByte(currentStatus.vss);
fullStatus[103] = currentStatus.gear;
fullStatus[104] = currentStatus.fuelPressure;
fullStatus[105] = currentStatus.oilPressure;
fullStatus[106] = currentStatus.wmiPW;
fullStatus[107] = currentStatus.wmiEmpty;
fullStatus[108] = (int8_t)currentStatus.vvt2Angle;
fullStatus[109] = currentStatus.vvt2TargetAngle;
fullStatus[110] = currentStatus.vvt2Duty;
fullStatus[111] = currentStatus.outputsStatus;
fullStatus[112] = (byte)(currentStatus.fuelTemp + CALIBRATION_TEMPERATURE_OFFSET); //Fuel temperature from flex sensor
fullStatus[113] = currentStatus.fuelTempCorrection; //Fuel temperature Correction (%)
fullStatus[114] = currentStatus.advance1; //advance 1 (%)
fullStatus[115] = currentStatus.advance2; //advance 2 (%)
fullStatus[116] = currentStatus.TS_SD_Status; //SD card status
case 83: statusValue = currentStatus.status3; break;
case 84: statusValue = currentStatus.engineProtectStatus; break;
case 85: statusValue = lowByte(currentStatus.fuelLoad); break;
case 86: statusValue = highByte(currentStatus.fuelLoad); break;
case 87: statusValue = lowByte(currentStatus.ignLoad); break;
case 88: statusValue = highByte(currentStatus.ignLoad); break;
case 89: statusValue = lowByte(currentStatus.dwell); break;
case 90: statusValue = highByte(currentStatus.dwell); break;
case 91: statusValue = currentStatus.CLIdleTarget; break;
case 92: statusValue = currentStatus.mapDOT; break;
case 93: statusValue = (int8_t)currentStatus.vvt1Angle; break;
case 94: statusValue = currentStatus.vvt1TargetAngle; break;
case 95: statusValue = currentStatus.vvt1Duty; break;
case 96: statusValue = lowByte(currentStatus.flexBoostCorrection); break;
case 97: statusValue = highByte(currentStatus.flexBoostCorrection); break;
case 98: statusValue = currentStatus.baroCorrection; break;
case 99: statusValue = currentStatus.VE; break; //Current VE (%). Can be equal to VE1 or VE2 or a calculated value from both of them
case 100: statusValue = currentStatus.ASEValue; break; //Current ASE (%)
case 101: statusValue = lowByte(currentStatus.vss); break;
case 102: statusValue = highByte(currentStatus.vss); break;
case 103: statusValue = currentStatus.gear; break;
case 104: statusValue = currentStatus.fuelPressure; break;
case 105: statusValue = currentStatus.oilPressure; break;
case 106: statusValue = currentStatus.wmiPW; break;
case 107: statusValue = currentStatus.wmiEmpty; break;
case 108: statusValue = (int8_t)currentStatus.vvt2Angle; break;
case 109: statusValue = currentStatus.vvt2TargetAngle; break;
case 110: statusValue = currentStatus.vvt2Duty; break;
case 111: statusValue = currentStatus.outputsStatus; break;
case 112: statusValue = (byte)(currentStatus.fuelTemp + CALIBRATION_TEMPERATURE_OFFSET); break; //Fuel temperature from flex sensor
case 113: statusValue = currentStatus.fuelTempCorrection; break; //Fuel temperature Correction (%)
case 114: statusValue = currentStatus.advance1; break; //advance 1 (%)
case 115: statusValue = currentStatus.advance2; break; //advance 2 (%)
case 116: statusValue = currentStatus.TS_SD_Status; break; //SD card status
}
return statusValue;
//Each new inclusion here need to be added on speeduino.ini@L78, only list first byte of an integer and second byte as "INVALID"
//Every integer added here should have it's lowByte index added to fsIntIndex array on globals.ino@L116
//Every 2-byte integer added here should have it's lowByte index added to fsIntIndex array on globals.ino@L116
}
/*
This function returns the current values of a fixed group of variables
*/
@ -891,15 +908,12 @@ void sendValues(uint16_t offset, uint16_t packetLength, byte cmd, byte portNum)
}
currentStatus.spark ^= (-currentStatus.hasSync ^ currentStatus.spark) & (1U << BIT_SPARK_SYNC); //Set the sync bit of the Spark variable to match the hasSync variable
updateFullStatus();
for(byte x=0; x<packetLength; x++)
{
if (portNum == 0) { Serial.write(fullStatus[offset+x]); }
if (portNum == 0) { Serial.write(getStatusEntry(offset+x)); }
#if defined(CANSerial_AVAILABLE)
else if (portNum == 3){ CANSerial.write(fullStatus[offset+x]); }
else if (portNum == 3){ CANSerial.write(getStatusEntry(offset+x)); }
#endif
//Check whether the tx buffer still has space

View File

@ -476,8 +476,7 @@ extern int ignition7StartAngle;
extern int ignition8StartAngle;
//These are variables used across multiple files
extern byte fullStatus[LOG_ENTRY_SIZE];
extern byte fsIntIndex[31];
extern const byte PROGMEM fsIntIndex[31];
extern bool initialisationComplete; //Tracks whether the setup() function has run completely
extern byte fpPrimeTime; //The time (in seconds, based on currentStatus.secl) that the fuel pump started priming
extern volatile uint16_t mainLoopCount;

View File

@ -112,8 +112,7 @@ int ignition7EndAngle = 0;
int ignition8EndAngle = 0;
//These are variables used across multiple files
byte fullStatus[LOG_ENTRY_SIZE];
byte fsIntIndex[31] = {4, 14, 25, 27, 32, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 75, 77, 79, 81, 85, 87, 89, 96, 101}; //int indexes in fullStatus array
const byte PROGMEM fsIntIndex[31] = {4, 14, 25, 27, 32, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 75, 77, 79, 81, 85, 87, 89, 96, 101}; //int indexes in fullStatus array
bool initialisationComplete = false; //Tracks whether the setup() function has run completely
byte fpPrimeTime = 0; //The time (in seconds, based on currentStatus.secl) that the fuel pump started priming
volatile uint16_t mainLoopCount;

View File

@ -299,12 +299,14 @@ int16_t ProgrammableIOGetData(uint16_t index)
uint8_t x;
if ( index < LOG_ENTRY_SIZE )
{
for(x = 0; x<sizeof(fsIntIndex); x++)
{
if (fsIntIndex[x] == index) { break; }
}
if (x >= sizeof(fsIntIndex)) { result = fullStatus[index]; }
else { result = word(fullStatus[index+1], fullStatus[index]); }
if (x >= sizeof(fsIntIndex)) { result = getStatusEntry(index); }
else { result = word(getStatusEntry(index+1), getStatusEntry(index)); }
//Special cases for temperatures
if( (index == 6) || (index == 7) ) { result -= CALIBRATION_TEMPERATURE_OFFSET; }