Add serial compatibility mode option

This commit is contained in:
Josh Stewart 2023-03-23 11:05:10 +11:00
parent 1886eb3861
commit e5e46b1d73
5 changed files with 45 additions and 12 deletions

View File

@ -25,6 +25,7 @@
;settingGroup = boostUnits, "Boost table units"
;settingOption = DEFAULT, "kPa"
;settingOption = BOOSTPSI, "PSI"
settingGroup = pressure_units, "Pressure Display"
settingOption = DEFAULT, "PSI"
@ -43,6 +44,10 @@
settingGroup = NEW_COMMS, "Use new comms protocol"
settingGroup = COMMS_COMPAT_GROUP, "Serial Mode"
settingOption = COMMS_COMPAT, "Compatibility Mode"
settingOption = DEFAULT, "Normal"
[PcVariables]
; valid types: boolean, double, int, list
;
@ -232,16 +237,25 @@
; New commands
pageIdentifier = "\$tsCanId\x01", "\$tsCanId\x02", "\$tsCanId\x03", "\$tsCanId\x04", "\$tsCanId\x05", "\$tsCanId\x06", "\$tsCanId\x07", "\$tsCanId\x08", "\$tsCanId\x09", "\$tsCanId\x0A", "\$tsCanId\x0B", "\$tsCanId\x0C", "\$tsCanId\x0D", "\$tsCanId\x0E", "\$tsCanId\x0F"
burnCommand = "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i"
pageReadCommand = "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c", "p%2i%2o%2c"
pageValueWrite = "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v"
pageChunkWrite = "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v", "M%2i%2o%2c%v"
crc32CheckCommand = "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i", "d%2i"
#if COMMS_COMPAT
;Comms compat mode uses a different burn command in order to slow down the EEPROM burn rate
burnCommand = "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i", "B%2i"
#else
burnCommand = "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i", "b%2i"
#endif
#if mcu_stm32
blockingFactor = 121
#else
blockingFactor = 251 ; Serial buffer is 257 bytes and there are 6 bytes of overhead (2 for the size and 4 for the CRC). Total payload is therefore 257-6=251.
#endif
#if COMMS_COMPAT
blockingFactor = 121
#endif
tableBlockingFactor = 244 ; Serial buffer is 257 bytes. There are 7 bytes overhead for the M command + 2 bytes for the size + 4 bytes for the CRC. 257 - 7 - 2 - 4 = 244 bytes.
delayAfterPortOpen=1000
@ -372,8 +386,8 @@ page = 1
aeTaperMin = scalar, U08, 59, "RPM", 100, 0.0, 1000, 10000, 0
aeTaperMax = scalar, U08, 60, "RPM", 100, 0.0, 2000, 10000, 0
iacCLminValue = scalar, U08, 61, "% / Steps", idleRes, 0.0, 0.0, idleResMax, 0 ; Minimum and maximum duty cycles when using closed loop idle
iacCLmaxValue = scalar, U08, 62, "% / Steps", idleRes, 0.0, 0.0, idleResMax, 0
iacCLminValue = scalar, U08, 61, "% / Steps", idleRes, 0.0, 0.0, idleResMax, 0 ; Minimum and maximum duty cycles when using closed loop idle
iacCLmaxValue = scalar, U08, 62, "% / Steps", idleRes, 0.0, 0.0, idleResMax, 0
boostMinDuty = scalar, U08, 63, "%", 1.0, 0.0, 0.0, 100.0, 0 ; Minimum and maximum duty cycles for boost control
baroMin = scalar, S08, 64, "kpa", 1.0, 0.0, -100, 127.0, 0
@ -1034,7 +1048,7 @@ page = 9
boostByGearEnabled = bits, U08, 153, [4:5], "Off", "Multiplied %", "Constant limit", "INVALID"
blankfield = bits, U08, 153, [6:6], "",""
unused10_153 = bits, U08, 153, [7:7], "", ""
unused9_153 = bits, U08, 153, [7:7], "Off", "On"
iacMaxSteps = scalar, U08, 154, "Steps", 3, 0, 0, {iacStepHome-3}, 0
idleAdvStartDelay = scalar, U08, 155, "S", 0.1, 0.0, 0.0, 25.5, 1
@ -5585,6 +5599,9 @@ cmdVSSratio6 = "E\x99\x06"
#else
tableBlockingFactor = 256
#endif
#if COMMS_COMPAT
tableBlockingFactor = 64
#endif
#endif
referenceTable = std_ms2gentherm, "Calibrate Thermistor Tables."
topicHelp = "https://wiki.speeduino.com/en/configuration/Sensor_Calibration"

View File

@ -564,6 +564,15 @@ void processSerialCommand(void)
sendReturnCodeMsg(SERIAL_RC_BURN_OK);
break;
case 'B': // Same as above, but for the comms compat mode. Slows down the burn rate and increases the defer time
BIT_SET(currentStatus.status4, BIT_STATUS4_COMMS_COMPAT); //Force the compat mode
deferEEPROMWritesUntil += (EEPROM_DEFER_DELAY/4); //Add 25% more to the EEPROM defer time
if( (micros() > deferEEPROMWritesUntil)) { writeConfig(serialPayload[2]); } //Read the table number and perform burn. Note that byte 1 in the array is unused
else { BIT_SET(currentStatus.status4, BIT_STATUS4_BURNPENDING); }
sendReturnCodeMsg(SERIAL_RC_BURN_OK);
break;
case 'C': // test communications. This is used by Tunerstudio to see whether there is an ECU on a given serial port
(void)memcpy_P(serialPayload, testCommsResponse, sizeof(testCommsResponse) );
sendSerialPayloadNonBlocking(sizeof(testCommsResponse));

View File

@ -69,12 +69,6 @@ void legacySerialCommand(void)
sendValues(0, LOG_ENTRY_SIZE, 0x31, 0); //send values to serial0
break;
case 'B': // Burn current values to eeprom
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
writeAllConfig();
serialStatusFlag = SERIAL_INACTIVE;
break;
case 'b': // New EEPROM burn command to only burn a single page at a time
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
@ -86,6 +80,18 @@ void legacySerialCommand(void)
}
break;
case 'B': // AS above but for the serial compatibility mode.
serialStatusFlag = SERIAL_COMMAND_INPROGRESS_LEGACY;
BIT_SET(currentStatus.status4, BIT_STATUS4_COMMS_COMPAT); //Force the compat mode
if (Serial.available() >= 2)
{
Serial.read(); //Ignore the first table value, it's always 0
writeConfig(Serial.read());
serialStatusFlag = SERIAL_INACTIVE;
}
break;
case 'C': // test communications. This is used by Tunerstudio to see whether there is an ECU on a given serial port
testComm();
break;

View File

@ -227,7 +227,7 @@
#define BIT_STATUS4_FAN 3 //Fan Status
#define BIT_STATUS4_BURNPENDING 4
#define BIT_STATUS4_STAGING_ACTIVE 5
#define BIT_STATUS4_UNUSED7 6
#define BIT_STATUS4_COMMS_COMPAT 6
#define BIT_STATUS4_UNUSED8 7
#define BIT_AIRCON_REQUEST 0 //Indicates whether the A/C button is pressed

View File

@ -160,7 +160,8 @@ void writeConfig(uint8_t pageNum)
#elif defined(CORE_STM32) || defined(CORE_TEENSY)
uint8_t EEPROM_MAX_WRITE_BLOCK = 64;
#else
uint8_t EEPROM_MAX_WRITE_BLOCK = 20;
uint8_t EEPROM_MAX_WRITE_BLOCK = 18;
if(BIT_CHECK(currentStatus.status4, BIT_STATUS4_COMMS_COMPAT)) { EEPROM_MAX_WRITE_BLOCK = 8; } //If comms compatibility mode is on, slow the burn rate down even further
#ifdef CORE_AVR
//In order to prevent missed pulses during EEPROM writes on AVR, scale the