Reduce flash usage for 2560 to prevent burn issues.

This commit is contained in:
Josh Stewart 2024-08-23 23:55:51 +10:00
parent a9642f461a
commit cfc3854d97
1 changed files with 221 additions and 221 deletions

View File

@ -58,17 +58,17 @@ void legacySerialCommand(void)
case 'a':
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
if (primarySerial.available() >= 2)
if (Serial.available() >= 2)
{
primarySerial.read(); //Ignore the first value, it's always 0
primarySerial.read(); //Ignore the second value, it's always 6
Serial.read(); //Ignore the first value, it's always 0
Serial.read(); //Ignore the second value, it's always 6
sendValuesLegacy();
serialStatusFlag = SERIAL_INACTIVE;
}
break;
case 'A': // send x bytes of realtime values
sendValues(0, LOG_ENTRY_SIZE, 0x31, Serial, serialStatusFlag); //send values to serial0
sendValues(0, LOG_ENTRY_SIZE, 0x31, primarySerial, serialStatusFlag); //send values to serial0
firstCommsRequest = false;
break;
@ -86,23 +86,23 @@ void legacySerialCommand(void)
break;
case 'c': //Send the current loops/sec value
primarySerial.write(lowByte(currentStatus.loopsPerSecond));
primarySerial.write(highByte(currentStatus.loopsPerSecond));
Serial.write(lowByte(currentStatus.loopsPerSecond));
Serial.write(highByte(currentStatus.loopsPerSecond));
break;
case 'd': // Send a CRC32 hash of a given page
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
if (primarySerial.available() >= 2)
if (Serial.available() >= 2)
{
primarySerial.read(); //Ignore the first byte value, it's always 0
uint32_t CRC32_val = calculatePageCRC32( primarySerial.read() );
Serial.read(); //Ignore the first byte value, it's always 0
uint32_t CRC32_val = calculatePageCRC32( Serial.read() );
//Split the 4 bytes of the CRC32 value into individual bytes and send
primarySerial.write( ((CRC32_val >> 24) & 255) );
primarySerial.write( ((CRC32_val >> 16) & 255) );
primarySerial.write( ((CRC32_val >> 8) & 255) );
primarySerial.write( (CRC32_val & 255) );
Serial.write( ((CRC32_val >> 24) & 255) );
Serial.write( ((CRC32_val >> 16) & 255) );
Serial.write( ((CRC32_val >> 8) & 255) );
Serial.write( (CRC32_val & 255) );
serialStatusFlag = SERIAL_INACTIVE;
}
@ -111,10 +111,10 @@ void legacySerialCommand(void)
case 'E': // receive command button commands
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
if(primarySerial.available() >= 2)
if(Serial.available() >= 2)
{
byte cmdGroup = (byte)Serial.read();
(void)TS_CommandButtonsHandler(word(cmdGroup, primarySerial.read()));
(void)TS_CommandButtonsHandler(word(cmdGroup, Serial.read()));
serialStatusFlag = SERIAL_INACTIVE;
}
break;
@ -127,13 +127,13 @@ void legacySerialCommand(void)
case 'G': // Dumps the EEPROM values to serial
//The format is 2 bytes for the overall EEPROM size, a comma and then a raw dump of the EEPROM values
primarySerial.write(lowByte(getEEPROMSize()));
primarySerial.write(highByte(getEEPROMSize()));
primarySerial.print(',');
Serial.write(lowByte(getEEPROMSize()));
Serial.write(highByte(getEEPROMSize()));
Serial.print(',');
for(uint16_t x = 0; x < getEEPROMSize(); x++)
{
primarySerial.write(EEPROMReadRaw(x));
Serial.write(EEPROMReadRaw(x));
}
serialStatusFlag = SERIAL_INACTIVE;
break;
@ -141,20 +141,20 @@ void legacySerialCommand(void)
case 'g': // Receive a dump of raw EEPROM values from the user
{
//Format is similar to the above command. 2 bytes for the EEPROM size that is about to be transmitted, a comma and then a raw dump of the EEPROM values
while(primarySerial.available() < 3) { delay(1); }
uint16_t eepromSize = word(primarySerial.read(), primarySerial.read());
while(Serial.available() < 3) { delay(1); }
uint16_t eepromSize = word(Serial.read(), Serial.read());
if(eepromSize != getEEPROMSize())
{
//Client is trying to send the wrong EEPROM size. Don't let it
primarySerial.println(F("ERR; Incorrect EEPROM size"));
Serial.println(F("ERR; Incorrect EEPROM size"));
break;
}
else
{
for(uint16_t x = 0; x < eepromSize; x++)
{
while(primarySerial.available() < 3) { delay(1); }
EEPROMWriteRaw(x, primarySerial.read());
while(Serial.available() < 3) { delay(1); }
EEPROMWriteRaw(x, Serial.read());
}
}
serialStatusFlag = SERIAL_INACTIVE;
@ -163,7 +163,7 @@ void legacySerialCommand(void)
case 'H': //Start the tooth logger
startToothLogger();
primarySerial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
Serial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
break;
case 'h': //Stop the tooth logger
@ -172,7 +172,7 @@ void legacySerialCommand(void)
case 'J': //Start the composite logger
startCompositeLogger();
primarySerial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
Serial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
break;
case 'j': //Stop the composite logger
@ -187,8 +187,8 @@ void legacySerialCommand(void)
case 'm': //Send the current free memory
currentStatus.freeRAM = freeRam();
primarySerial.write(lowByte(currentStatus.freeRAM));
primarySerial.write(highByte(currentStatus.freeRAM));
Serial.write(lowByte(currentStatus.freeRAM));
Serial.write(highByte(currentStatus.freeRAM));
break;
case 'M':
@ -196,12 +196,12 @@ void legacySerialCommand(void)
break;
case 'N': // Displays a new line. Like pushing enter in a text editor
primarySerial.println();
Serial.println();
break;
case 'O': //Start the composite logger 2nd cam (teritary)
startCompositeLoggerTertiary();
primarySerial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
Serial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
break;
case 'o': //Stop the composite logger 2nd cam (tertiary)
@ -210,7 +210,7 @@ void legacySerialCommand(void)
case 'X': //Start the composite logger 2nd cam (teritary)
startCompositeLoggerCams();
primarySerial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
Serial.write(1); //TS needs an acknowledgement that this was received. I don't know if this is the correct response, but it seems to work
break;
case 'x': //Stop the composite logger 2nd cam (tertiary)
@ -222,9 +222,9 @@ void legacySerialCommand(void)
//A 2nd byte of data is required after the 'P' specifying the new page number.
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
if (primarySerial.available() > 0)
if (Serial.available() > 0)
{
currentPage = primarySerial.read();
currentPage = Serial.read();
//This converts the ASCII number char into binary. Note that this will break everything if there are ever more than 48 pages (48 = asci code for '0')
if ((currentPage >= '0') && (currentPage <= '9')) // 0 - 9
{
@ -252,24 +252,24 @@ void legacySerialCommand(void)
//2 - Page identifier
//2 - offset
//2 - Length
if(primarySerial.available() >= 6)
if(Serial.available() >= 6)
{
byte offset1, offset2, length1, length2;
int length;
byte tempPage;
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
tempPage = primarySerial.read();
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
tempPage = Serial.read();
//currentPage = 1;
offset1 = primarySerial.read();
offset2 = primarySerial.read();
offset1 = Serial.read();
offset2 = Serial.read();
valueOffset = word(offset2, offset1);
length1 = primarySerial.read();
length2 = primarySerial.read();
length1 = Serial.read();
length2 = Serial.read();
length = word(length2, length1);
for(int i = 0; i < length; i++)
{
primarySerial.write( getPageValue(tempPage, valueOffset + i) );
Serial.write( getPageValue(tempPage, valueOffset + i) );
}
serialStatusFlag = SERIAL_INACTIVE;
@ -283,17 +283,17 @@ void legacySerialCommand(void)
case 'r': //New format for the optimised OutputChannels
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
byte cmd;
if (primarySerial.available() >= 6)
if (Serial.available() >= 6)
{
primarySerial.read(); //Read the $tsCanId
cmd = primarySerial.read(); // read the command
Serial.read(); //Read the $tsCanId
cmd = Serial.read(); // read the command
uint16_t offset, length;
byte tmp;
tmp = primarySerial.read();
offset = word(primarySerial.read(), tmp);
tmp = primarySerial.read();
length = word(primarySerial.read(), tmp);
tmp = Serial.read();
offset = word(Serial.read(), tmp);
tmp = Serial.read();
length = word(Serial.read(), tmp);
serialStatusFlag = SERIAL_INACTIVE;
@ -319,14 +319,14 @@ void legacySerialCommand(void)
//2 - offset
//2 - Length
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
if(primarySerial.available() >= 6)
if(Serial.available() >= 6)
{
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
if(currentStatus.toothLogEnabled == true) { sendToothLog_legacy(0); } //Sends tooth log values as ints
else if (currentStatus.compositeTriggerUsed > 0) { sendCompositeLog_legacy(0); }
@ -339,8 +339,8 @@ void legacySerialCommand(void)
//byte canID;
//The first 2 bytes sent represent the canID and tableID
while (primarySerial.available() == 0) { }
tableID = primarySerial.read(); //Not currently used for anything
while (Serial.available() == 0) { }
tableID = Serial.read(); //Not currently used for anything
receiveCalibration(tableID); //Receive new values and store in memory
writeCalibration(); //Store received values in EEPROM
@ -351,16 +351,16 @@ void legacySerialCommand(void)
if (resetControl != RESET_CONTROL_DISABLED)
{
#ifndef SMALL_FLASH_MODE
if (serialStatusFlag == SERIAL_INACTIVE) { primarySerial.println(F("Comms halted. Next byte will reset the Arduino.")); }
if (serialStatusFlag == SERIAL_INACTIVE) { Serial.println(F("Comms halted. Next byte will reset the Arduino.")); }
#endif
while (primarySerial.available() == 0) { }
while (Serial.available() == 0) { }
digitalWrite(pinResetControl, LOW);
}
else
{
#ifndef SMALL_FLASH_MODE
if (serialStatusFlag == SERIAL_INACTIVE) { primarySerial.println(F("Reset control is currently disabled.")); }
if (serialStatusFlag == SERIAL_INACTIVE) { Serial.println(F("Reset control is currently disabled.")); }
#endif
}
break;
@ -374,22 +374,22 @@ void legacySerialCommand(void)
if (isMap())
{
if(primarySerial.available() >= 3) // 1 additional byte is required on the MAP pages which are larger than 255 bytes
if(Serial.available() >= 3) // 1 additional byte is required on the MAP pages which are larger than 255 bytes
{
byte offset1, offset2;
offset1 = primarySerial.read();
offset2 = primarySerial.read();
offset1 = Serial.read();
offset2 = Serial.read();
valueOffset = word(offset2, offset1);
setPageValue(currentPage, valueOffset, primarySerial.read());
setPageValue(currentPage, valueOffset, Serial.read());
serialStatusFlag = SERIAL_INACTIVE;
}
}
else
{
if(primarySerial.available() >= 2)
if(Serial.available() >= 2)
{
valueOffset = primarySerial.read();
setPageValue(currentPage, valueOffset, primarySerial.read());
valueOffset = Serial.read();
setPageValue(currentPage, valueOffset, Serial.read());
serialStatusFlag = SERIAL_INACTIVE;
}
}
@ -398,53 +398,53 @@ void legacySerialCommand(void)
case 'w':
//No w commands are supported in legacy mode. This should never be called
if(primarySerial.available() >= 7)
if(Serial.available() >= 7)
{
byte offset1, offset2, length1, length2;
primarySerial.read(); // First byte of the page identifier can be ignored. It's always 0
currentPage = primarySerial.read();
Serial.read(); // First byte of the page identifier can be ignored. It's always 0
currentPage = Serial.read();
//currentPage = 1;
offset1 = primarySerial.read();
offset2 = primarySerial.read();
offset1 = Serial.read();
offset2 = Serial.read();
valueOffset = word(offset2, offset1);
length1 = primarySerial.read();
length2 = primarySerial.read();
length1 = Serial.read();
length2 = Serial.read();
chunkSize = word(length2, length1);
}
break;
case 'Z': //Totally non-standard testing function. Will be removed once calibration testing is completed. This function takes 1.5kb of program space! :S
#ifndef SMALL_FLASH_MODE
primarySerial.println(F("Coolant"));
Serial.println(F("Coolant"));
for (int x = 0; x < 32; x++)
{
primarySerial.print(cltCalibration_bins[x]);
primarySerial.print(", ");
primarySerial.println(cltCalibration_values[x]);
Serial.print(cltCalibration_bins[x]);
Serial.print(", ");
Serial.println(cltCalibration_values[x]);
}
primarySerial.println(F("Inlet temp"));
Serial.println(F("Inlet temp"));
for (int x = 0; x < 32; x++)
{
primarySerial.print(iatCalibration_bins[x]);
primarySerial.print(", ");
primarySerial.println(iatCalibration_values[x]);
Serial.print(iatCalibration_bins[x]);
Serial.print(", ");
Serial.println(iatCalibration_values[x]);
}
primarySerial.println(F("O2"));
Serial.println(F("O2"));
for (int x = 0; x < 32; x++)
{
primarySerial.print(o2Calibration_bins[x]);
primarySerial.print(", ");
primarySerial.println(o2Calibration_values[x]);
Serial.print(o2Calibration_bins[x]);
Serial.print(", ");
Serial.println(o2Calibration_values[x]);
}
primarySerial.println(F("WUE"));
Serial.println(F("WUE"));
for (int x = 0; x < 10; x++)
{
primarySerial.print(configPage4.wueBins[x]);
primarySerial.print(F(", "));
primarySerial.println(configPage2.wueValues[x]);
Serial.print(configPage4.wueBins[x]);
Serial.print(F(", "));
Serial.println(configPage2.wueValues[x]);
}
primarySerial.flush();
Serial.flush();
#endif
break;
@ -455,8 +455,8 @@ void legacySerialCommand(void)
case '`': //Custom 16u2 firmware is making its presence known
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
if (primarySerial.available() >= 1) {
configPage4.bootloaderCaps = primarySerial.read();
if (Serial.available() >= 1) {
configPage4.bootloaderCaps = Serial.read();
serialStatusFlag = SERIAL_INACTIVE;
}
break;
@ -464,7 +464,7 @@ void legacySerialCommand(void)
case '?':
#ifndef SMALL_FLASH_MODE
primarySerial.println
Serial.println
(F(
"\n"
"===Command Help===\n\n"
@ -498,7 +498,7 @@ void legacySerialCommand(void)
default:
//Serial.println(F("Err: Unknown cmd"));
//while(primarySerial.available() && primarySerial.peek()!='A') { primarySerial.read(); }
//while(Serial.available() && Serial.peek()!='A') { Serial.read(); }
serialStatusFlag = SERIAL_INACTIVE;
break;
}
@ -748,123 +748,123 @@ void sendValuesLegacy(void)
uint16_t temp;
int bytestosend = 114;
bytestosend -= primarySerial.write(currentStatus.secl>>8);
bytestosend -= primarySerial.write(currentStatus.secl);
bytestosend -= primarySerial.write(currentStatus.PW1>>8);
bytestosend -= primarySerial.write(currentStatus.PW1);
bytestosend -= primarySerial.write(currentStatus.PW2>>8);
bytestosend -= primarySerial.write(currentStatus.PW2);
bytestosend -= primarySerial.write(currentStatus.RPM>>8);
bytestosend -= primarySerial.write(currentStatus.RPM);
bytestosend -= Serial.write(currentStatus.secl>>8);
bytestosend -= Serial.write(currentStatus.secl);
bytestosend -= Serial.write(currentStatus.PW1>>8);
bytestosend -= Serial.write(currentStatus.PW1);
bytestosend -= Serial.write(currentStatus.PW2>>8);
bytestosend -= Serial.write(currentStatus.PW2);
bytestosend -= Serial.write(currentStatus.RPM>>8);
bytestosend -= Serial.write(currentStatus.RPM);
temp = currentStatus.advance * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
bytestosend -= primarySerial.write(currentStatus.nSquirts);
bytestosend -= primarySerial.write(currentStatus.engine);
bytestosend -= primarySerial.write(currentStatus.afrTarget);
bytestosend -= primarySerial.write(currentStatus.afrTarget); // send twice so afrtgt1 == afrtgt2
bytestosend -= primarySerial.write(99); // send dummy data as we don't have wbo2_en1
bytestosend -= primarySerial.write(99); // send dummy data as we don't have wbo2_en2
bytestosend -= Serial.write(currentStatus.nSquirts);
bytestosend -= Serial.write(currentStatus.engine);
bytestosend -= Serial.write(currentStatus.afrTarget);
bytestosend -= Serial.write(currentStatus.afrTarget); // send twice so afrtgt1 == afrtgt2
bytestosend -= Serial.write(99); // send dummy data as we don't have wbo2_en1
bytestosend -= Serial.write(99); // send dummy data as we don't have wbo2_en2
temp = currentStatus.baro * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
temp = currentStatus.MAP * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
temp = currentStatus.IAT * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
temp = currentStatus.coolant * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
temp = currentStatus.TPS * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
bytestosend -= primarySerial.write(currentStatus.battery10>>8);
bytestosend -= primarySerial.write(currentStatus.battery10);
bytestosend -= primarySerial.write(currentStatus.O2>>8);
bytestosend -= primarySerial.write(currentStatus.O2);
bytestosend -= primarySerial.write(currentStatus.O2_2>>8);
bytestosend -= primarySerial.write(currentStatus.O2_2);
bytestosend -= Serial.write(currentStatus.battery10>>8);
bytestosend -= Serial.write(currentStatus.battery10);
bytestosend -= Serial.write(currentStatus.O2>>8);
bytestosend -= Serial.write(currentStatus.O2);
bytestosend -= Serial.write(currentStatus.O2_2>>8);
bytestosend -= Serial.write(currentStatus.O2_2);
bytestosend -= primarySerial.write(99); // knock
bytestosend -= primarySerial.write(99); // knock
bytestosend -= Serial.write(99); // knock
bytestosend -= Serial.write(99); // knock
temp = currentStatus.egoCorrection * 10;
bytestosend -= primarySerial.write(temp>>8); // egocor1
bytestosend -= primarySerial.write(temp); // egocor1
bytestosend -= primarySerial.write(temp>>8); // egocor2
bytestosend -= primarySerial.write(temp); // egocor2
bytestosend -= Serial.write(temp>>8); // egocor1
bytestosend -= Serial.write(temp); // egocor1
bytestosend -= Serial.write(temp>>8); // egocor2
bytestosend -= Serial.write(temp); // egocor2
temp = currentStatus.iatCorrection * 10;
bytestosend -= primarySerial.write(temp>>8); // aircor
bytestosend -= primarySerial.write(temp); // aircor
bytestosend -= Serial.write(temp>>8); // aircor
bytestosend -= Serial.write(temp); // aircor
temp = currentStatus.wueCorrection * 10;
bytestosend -= primarySerial.write(temp>>8); // warmcor
bytestosend -= primarySerial.write(temp); // warmcor
bytestosend -= Serial.write(temp>>8); // warmcor
bytestosend -= Serial.write(temp); // warmcor
bytestosend -= primarySerial.write(99); // accelEnrich
bytestosend -= primarySerial.write(99); // accelEnrich
bytestosend -= primarySerial.write(99); // tpsFuelCut
bytestosend -= primarySerial.write(99); // tpsFuelCut
bytestosend -= primarySerial.write(99); // baroCorrection
bytestosend -= primarySerial.write(99); // baroCorrection
bytestosend -= Serial.write(99); // accelEnrich
bytestosend -= Serial.write(99); // accelEnrich
bytestosend -= Serial.write(99); // tpsFuelCut
bytestosend -= Serial.write(99); // tpsFuelCut
bytestosend -= Serial.write(99); // baroCorrection
bytestosend -= Serial.write(99); // baroCorrection
temp = currentStatus.corrections * 10;
bytestosend -= primarySerial.write(temp>>8); // gammaEnrich
bytestosend -= primarySerial.write(temp); // gammaEnrich
bytestosend -= Serial.write(temp>>8); // gammaEnrich
bytestosend -= Serial.write(temp); // gammaEnrich
temp = currentStatus.VE * 10;
bytestosend -= primarySerial.write(temp>>8); // ve1
bytestosend -= primarySerial.write(temp); // ve1
bytestosend -= Serial.write(temp>>8); // ve1
bytestosend -= Serial.write(temp); // ve1
temp = currentStatus.VE2 * 10;
bytestosend -= primarySerial.write(temp>>8); // ve2
bytestosend -= primarySerial.write(temp); // ve2
bytestosend -= Serial.write(temp>>8); // ve2
bytestosend -= Serial.write(temp); // ve2
bytestosend -= primarySerial.write(99); // iacstep
bytestosend -= primarySerial.write(99); // iacstep
bytestosend -= primarySerial.write(99); // cold_adv_deg
bytestosend -= primarySerial.write(99); // cold_adv_deg
bytestosend -= Serial.write(99); // iacstep
bytestosend -= Serial.write(99); // iacstep
bytestosend -= Serial.write(99); // cold_adv_deg
bytestosend -= Serial.write(99); // cold_adv_deg
temp = currentStatus.tpsDOT;
bytestosend -= primarySerial.write(temp>>8); // TPSdot
bytestosend -= primarySerial.write(temp); // TPSdot
bytestosend -= Serial.write(temp>>8); // TPSdot
bytestosend -= Serial.write(temp); // TPSdot
temp = currentStatus.mapDOT;
bytestosend -= primarySerial.write(temp >> 8); // MAPdot
bytestosend -= primarySerial.write(temp); // MAPdot
bytestosend -= Serial.write(temp >> 8); // MAPdot
bytestosend -= Serial.write(temp); // MAPdot
temp = currentStatus.dwell * 10U;
bytestosend -= primarySerial.write(temp>>8); // dwell
bytestosend -= primarySerial.write(temp); // dwell
bytestosend -= Serial.write(temp>>8); // dwell
bytestosend -= Serial.write(temp); // dwell
bytestosend -= primarySerial.write(99); // MAF
bytestosend -= primarySerial.write(99); // MAF
bytestosend -= primarySerial.write(currentStatus.fuelLoad*10); // fuelload
bytestosend -= primarySerial.write(99); // fuelcor
bytestosend -= primarySerial.write(99); // fuelcor
bytestosend -= primarySerial.write(99); // portStatus
bytestosend -= Serial.write(99); // MAF
bytestosend -= Serial.write(99); // MAF
bytestosend -= Serial.write(currentStatus.fuelLoad*10); // fuelload
bytestosend -= Serial.write(99); // fuelcor
bytestosend -= Serial.write(99); // fuelcor
bytestosend -= Serial.write(99); // portStatus
temp = currentStatus.advance1 * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
temp = currentStatus.advance2 * 10;
bytestosend -= primarySerial.write(temp>>8);
bytestosend -= primarySerial.write(temp);
bytestosend -= Serial.write(temp>>8);
bytestosend -= Serial.write(temp);
for(int i = 0; i < bytestosend; i++)
{
// send dummy data to fill remote's buffer
primarySerial.write(99);
Serial.write(99);
}
}
@ -872,7 +872,7 @@ namespace {
void send_raw_entity(const page_iterator_t &entity)
{
primarySerial.write((byte *)entity.pData, entity.size);
Serial.write((byte *)entity.pData, entity.size);
}
inline void send_table_values(table_value_iterator it)
@ -880,7 +880,7 @@ namespace {
while (!it.at_end())
{
auto row = *it;
primarySerial.write(&*row, row.size());
Serial.write(&*row, row.size());
++it;
}
}
@ -890,7 +890,7 @@ namespace {
const table3d_axis_io_converter converter = get_table3d_axis_converter(it.get_domain());
while (!it.at_end())
{
primarySerial.write(converter.to_byte(*it));
Serial.write(converter.to_byte(*it));
++it;
}
}
@ -950,7 +950,7 @@ namespace {
{
while (first!=last)
{
primarySerial.println(*first);
Serial.println(*first);
++first;
}
}
@ -958,7 +958,7 @@ namespace {
{
while (first!=last)
{
primarySerial.println(*first);
Serial.println(*first);
++first;
}
}
@ -967,11 +967,11 @@ namespace {
{
while (first!=last)
{
primarySerial.print(*first);// This displays the values horizontally on the screen
primarySerial.print(F(" "));
Serial.print(*first);// This displays the values horizontally on the screen
Serial.print(F(" "));
++first;
}
primarySerial.println();
Serial.println();
}
#define serial_print_space_delimited_array(array) serial_print_space_delimited(array, _end_range_address(array))
@ -979,10 +979,10 @@ namespace {
{
if (value < 100)
{
primarySerial.print(F(" "));
Serial.print(F(" "));
if (value < 10)
{
primarySerial.print(F(" "));
Serial.print(F(" "));
}
}
}
@ -990,8 +990,8 @@ namespace {
void serial_print_prepadded_value(byte value)
{
serial_print_prepadding(value);
primarySerial.print(value);
primarySerial.print(F(" "));
Serial.print(value);
Serial.print(F(" "));
}
void print_row(const table_axis_iterator &y_it, table_row_iterator row)
@ -1003,12 +1003,12 @@ namespace {
serial_print_prepadded_value(*row);
++row;
}
primarySerial.println();
Serial.println();
}
void print_x_axis(void *pTable, table_type_t key)
{
primarySerial.print(F(" "));
Serial.print(F(" "));
auto x_it = x_begin(pTable, key);
const table3d_axis_io_converter converter = get_table3d_axis_converter(x_it.get_domain());
@ -1033,7 +1033,7 @@ namespace {
}
print_x_axis(pTable, key);
primarySerial.println();
Serial.println();
}
}
@ -1047,12 +1047,12 @@ void sendPageASCII(void)
switch (currentPage)
{
case veMapPage:
primarySerial.println(F("\nVE Map"));
Serial.println(F("\nVE Map"));
serial_print_3dtable(&fuelTable, fuelTable.type_key);
break;
case veSetPage:
primarySerial.println(F("\nPg 2 Cfg"));
Serial.println(F("\nPg 2 Cfg"));
// The following loop displays in human readable form of all byte values in config page 1 up to but not including the first array.
serial_println_range((byte *)&configPage2, configPage2.wueValues);
serial_print_space_delimited_array(configPage2.wueValues);
@ -1062,36 +1062,36 @@ void sendPageASCII(void)
serial_println_range(configPage2.injAng, configPage2.injAng + _countof(configPage2.injAng));
// Following loop displays byte values between the unsigned ints
serial_println_range(_end_range_byte_address(configPage2.injAng), (byte*)&configPage2.mapMax);
primarySerial.println(configPage2.mapMax);
Serial.println(configPage2.mapMax);
// Following loop displays remaining byte values of the page
serial_println_range(&configPage2.fpPrime, (byte *)&configPage2 + sizeof(configPage2));
break;
case ignMapPage:
primarySerial.println(F("\nIgnition Map"));
Serial.println(F("\nIgnition Map"));
serial_print_3dtable(&ignitionTable, ignitionTable.type_key);
break;
case ignSetPage:
primarySerial.println(F("\nPg 4 Cfg"));
primarySerial.println(configPage4.triggerAngle);// configPage4.triggerAngle is an int so just display it without complication
Serial.println(F("\nPg 4 Cfg"));
Serial.println(configPage4.triggerAngle);// configPage4.triggerAngle is an int so just display it without complication
// Following loop displays byte values after that first int up to but not including the first array in config page 2
serial_println_range((byte*)&configPage4.FixAng, configPage4.taeBins);
serial_print_space_delimited_array(configPage4.taeBins);
serial_print_space_delimited_array(configPage4.taeValues);
serial_print_space_delimited_array(configPage4.wueBins);
primarySerial.println(configPage4.dwellLimit);// Little lonely byte stuck between two arrays. No complications just display it.
Serial.println(configPage4.dwellLimit);// Little lonely byte stuck between two arrays. No complications just display it.
serial_print_space_delimited_array(configPage4.dwellCorrectionValues);
serial_println_range(_end_range_byte_address(configPage4.dwellCorrectionValues), (byte *)&configPage4 + sizeof(configPage4));
break;
case afrMapPage:
primarySerial.println(F("\nAFR Map"));
Serial.println(F("\nAFR Map"));
serial_print_3dtable(&afrTable, afrTable.type_key);
break;
case afrSetPage:
primarySerial.println(F("\nPg 6 Config"));
Serial.println(F("\nPg 6 Config"));
serial_println_range((byte *)&configPage6, configPage6.voltageCorrectionBins);
serial_print_space_delimited_array(configPage6.voltageCorrectionBins);
serial_print_space_delimited_array(configPage6.injVoltageCorrectionValues);
@ -1110,34 +1110,34 @@ void sendPageASCII(void)
break;
case boostvvtPage:
primarySerial.println(F("\nBoost Map"));
Serial.println(F("\nBoost Map"));
serial_print_3dtable(&boostTable, boostTable.type_key);
primarySerial.println(F("\nVVT Map"));
Serial.println(F("\nVVT Map"));
serial_print_3dtable(&vvtTable, vvtTable.type_key);
break;
case seqFuelPage:
primarySerial.println(F("\nTrim 1 Table"));
Serial.println(F("\nTrim 1 Table"));
serial_print_3dtable(&trim1Table, trim1Table.type_key);
break;
case canbusPage:
primarySerial.println(F("\nPage 9 Cfg"));
Serial.println(F("\nPage 9 Cfg"));
serial_println_range((byte *)&configPage9, (byte *)&configPage9 + sizeof(configPage9));
break;
case fuelMap2Page:
primarySerial.println(F("\n2nd Fuel Map"));
Serial.println(F("\n2nd Fuel Map"));
serial_print_3dtable(&fuelTable2, fuelTable2.type_key);
break;
case ignMap2Page:
primarySerial.println(F("\n2nd Ignition Map"));
Serial.println(F("\n2nd Ignition Map"));
serial_print_3dtable(&ignitionTable2, ignitionTable2.type_key);
break;
case boostvvtPage2:
primarySerial.println(F("\nBoost lookup table"));
Serial.println(F("\nBoost lookup table"));
serial_print_3dtable(&boostTableLookupDuty, boostTableLookupDuty.type_key);
break;
@ -1145,7 +1145,7 @@ void sendPageASCII(void)
case progOutsPage:
default:
#ifndef SMALL_FLASH_MODE
primarySerial.println(F("\nPage has not been implemented yet"));
Serial.println(F("\nPage has not been implemented yet"));
#endif
break;
}
@ -1204,8 +1204,8 @@ void receiveCalibration(byte tableID)
//O2 calibration. Comes through as 1024 8-bit values of which we use every 32nd
for (int x = 0; x < 1024; x++)
{
while ( primarySerial.available() < 1 ) {}
tempValue = primarySerial.read();
while ( Serial.available() < 1 ) {}
tempValue = Serial.read();
if( (x % 32) == 0)
{
@ -1220,9 +1220,9 @@ void receiveCalibration(byte tableID)
//Temperature calibrations are sent as 32 16-bit values
for (uint16_t x = 0; x < 32; x++)
{
while ( primarySerial.available() < 2 ) {}
tempBuffer[0] = primarySerial.read();
tempBuffer[1] = primarySerial.read();
while ( Serial.available() < 2 ) {}
tempBuffer[0] = Serial.read();
tempBuffer[1] = Serial.read();
tempValue = (int16_t)(word(tempBuffer[1], tempBuffer[0])); //Combine the 2 bytes into a single, signed 16-bit value
tempValue = div(tempValue, DIVISION_FACTOR).quot; //TS sends values multiplied by 10 so divide back to whole degrees.
@ -1242,7 +1242,7 @@ void receiveCalibration(byte tableID)
writeCalibration();
}
/** Send 256 tooth log entries to primarySerial.
/** Send 256 tooth log entries to Serial.
* if useChar is true, the values are sent as chars to be printed out by a terminal emulator
* if useChar is false, the values are sent as a 2 byte integer which is readable by TunerStudios tooth logger
*/
@ -1254,10 +1254,10 @@ void sendToothLog_legacy(byte startOffset) /* Blocking */
serialStatusFlag = SERIAL_TRANSMIT_TOOTH_INPROGRESS_LEGACY;
for (uint8_t x = startOffset; x < TOOTH_LOG_SIZE; ++x)
{
primarySerial.write(toothHistory[x] >> 24);
primarySerial.write(toothHistory[x] >> 16);
primarySerial.write(toothHistory[x] >> 8);
primarySerial.write(toothHistory[x]);
Serial.write(toothHistory[x] >> 24);
Serial.write(toothHistory[x] >> 16);
Serial.write(toothHistory[x] >> 8);
Serial.write(toothHistory[x]);
}
BIT_CLEAR(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY);
serialStatusFlag = SERIAL_INACTIVE;
@ -1268,7 +1268,7 @@ void sendToothLog_legacy(byte startOffset) /* Blocking */
//TunerStudio has timed out, send a LOG of all 0s
for(uint16_t x = 0U; x < (4U*TOOTH_LOG_SIZE); ++x)
{
primarySerial.write(static_cast<byte>(0x00)); //GCC9 fix
Serial.write(static_cast<byte>(0x00)); //GCC9 fix
}
serialStatusFlag = SERIAL_INACTIVE;
}
@ -1283,7 +1283,7 @@ void sendCompositeLog_legacy(byte startOffset) /* Non-blocking */
for (uint8_t x = startOffset; x < TOOTH_LOG_SIZE; ++x)
{
//Check whether the tx buffer still has space
if(primarySerial.availableForWrite() < 4)
if(Serial.availableForWrite() < 4)
{
//tx buffer is full. Store the current state so it can be resumed later
logItemsTransmitted = x;
@ -1292,12 +1292,12 @@ void sendCompositeLog_legacy(byte startOffset) /* Non-blocking */
uint32_t inProgressCompositeTime = toothHistory[x]; //This combined runtime (in us) that the log was going for by this record)
primarySerial.write(inProgressCompositeTime >> 24);
primarySerial.write(inProgressCompositeTime >> 16);
primarySerial.write(inProgressCompositeTime >> 8);
primarySerial.write(inProgressCompositeTime);
Serial.write(inProgressCompositeTime >> 24);
Serial.write(inProgressCompositeTime >> 16);
Serial.write(inProgressCompositeTime >> 8);
Serial.write(inProgressCompositeTime);
primarySerial.write(compositeLogHistory[x]); //The status byte (Indicates the trigger edge, whether it was a pri/sec pulse, the sync status)
Serial.write(compositeLogHistory[x]); //The status byte (Indicates the trigger edge, whether it was a pri/sec pulse, the sync status)
}
BIT_CLEAR(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY);
toothHistoryIndex = 0;
@ -1308,7 +1308,7 @@ void sendCompositeLog_legacy(byte startOffset) /* Non-blocking */
//TunerStudio has timed out, send a LOG of all 0s
for(uint16_t x = 0U; x < (5U*TOOTH_LOG_SIZE); ++x)
{
primarySerial.write(static_cast<byte>(0x00)); //GCC9 fix
Serial.write(static_cast<byte>(0x00)); //GCC9 fix
}
serialStatusFlag = SERIAL_INACTIVE;
}
@ -1316,6 +1316,6 @@ void sendCompositeLog_legacy(byte startOffset) /* Non-blocking */
void testComm(void)
{
primarySerial.write(1);
Serial.write(1);
return;
}