diff --git a/reference/speeduino.ini b/reference/speeduino.ini index b5c4ccbe..08a5b48e 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -5492,7 +5492,7 @@ cmdVSSratio6 = "E\x99\x06" stopCommand = "j" ;dataReadCommand = "T" ; Basic TS command format. Note that this is shared with the composite logger. Firmware detects which log is currently running dataReadCommand = "T\$tsCanId\x00\x00\x00\x02\x7B" ; Basic TS command format. Note that this is shared with the composite logger. Firmware detects which log is currently running - dataReadTimeout = 50000 ; time in ms + dataReadTimeout = 5000 ; time in ms dataReadyCondition = { toothLog1Ready == 1 } continuousRead = true dataLength = 127 ; Number of records to show on a single screen. Should match TOOTH_LOG_SIZE in the code diff --git a/speeduino/comms.cpp b/speeduino/comms.cpp index 89c4bd9e..0ea61781 100644 --- a/speeduino/comms.cpp +++ b/speeduino/comms.cpp @@ -466,7 +466,7 @@ void serialReceive(void) legacySerialCommand(); return; } - else if( ((highByte >= 'A') && (highByte <= 'z')) || (highByte == '?') && (BIT_CHECK(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS)) ) + else if( (((highByte >= 'A') && (highByte <= 'z')) || (highByte == '?')) && (BIT_CHECK(currentStatus.status4, BIT_STATUS4_ALLOW_LEGACY_COMMS)) ) { //Handle legacy cases here legacySerialCommand(); @@ -1027,104 +1027,109 @@ void processSerialCommand(void) void sendToothLog(void) { //We need TOOTH_LOG_SIZE number of records to send to TunerStudio. If there aren't that many in the buffer then we just return and wait for the next call - if (BIT_CHECK(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY)) //Sanity check. Flagging system means this should always be true + if (BIT_CHECK(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY) == false) //Sanity check. Flagging system means this should always be true { - uint32_t CRC32_val = 0; - if(logItemsTransmitted == 0) + //If the buffer is not yet full but TS has timed out, pad the rest of the buffer with 0s + while(toothHistoryIndex < TOOTH_LOG_SIZE) { - //Transmit the size of the packet - (void)serialWrite((uint16_t)(sizeof(toothHistory) + 1U)); //Size of the tooth log (uint32_t values) plus the return code - //Begin new CRC hash - const uint8_t returnCode = SERIAL_RC_OK; - CRC32_val = CRC32_serial.crc32(&returnCode, 1, false); - - //Send the return code - writeByteReliableBlocking(returnCode); + toothHistory[toothHistoryIndex] = 0; + toothHistoryIndex++; } - - for (; logItemsTransmitted < TOOTH_LOG_SIZE; logItemsTransmitted++) - { - //Check whether the tx buffer still has space - if(Serial.availableForWrite() < 4) - { - //tx buffer is full. Store the current state so it can be resumed later - serialStatusFlag = SERIAL_TRANSMIT_TOOTH_INPROGRESS; - return; - } - - //Transmit the tooth time - uint32_t transmitted = serialWrite(toothHistory[logItemsTransmitted]); - CRC32_val = CRC32_serial.crc32_upd((const byte*)&transmitted, sizeof(transmitted), false); - } - BIT_CLEAR(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY); - serialStatusFlag = SERIAL_INACTIVE; - toothHistoryIndex = 0; - logItemsTransmitted = 0; - - //Apply the CRC reflection - CRC32_val = ~CRC32_val; - - //Send the CRC - (void)serialWrite(CRC32_val); } - else - { - sendReturnCodeMsg(SERIAL_RC_BUSY_ERR); - serialStatusFlag = SERIAL_INACTIVE; - } + + uint32_t CRC32_val = 0; + if(logItemsTransmitted == 0) + { + //Transmit the size of the packet + (void)serialWrite((uint16_t)(sizeof(toothHistory) + 1U)); //Size of the tooth log (uint32_t values) plus the return code + //Begin new CRC hash + const uint8_t returnCode = SERIAL_RC_OK; + CRC32_val = CRC32_serial.crc32(&returnCode, 1, false); + + //Send the return code + writeByteReliableBlocking(returnCode); + } + + for (; logItemsTransmitted < TOOTH_LOG_SIZE; logItemsTransmitted++) + { + //Check whether the tx buffer still has space + if(Serial.availableForWrite() < 4) + { + //tx buffer is full. Store the current state so it can be resumed later + serialStatusFlag = SERIAL_TRANSMIT_TOOTH_INPROGRESS; + return; + } + + //Transmit the tooth time + uint32_t transmitted = serialWrite(toothHistory[logItemsTransmitted]); + CRC32_val = CRC32_serial.crc32_upd((const byte*)&transmitted, sizeof(transmitted), false); + } + BIT_CLEAR(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY); + serialStatusFlag = SERIAL_INACTIVE; + toothHistoryIndex = 0; + logItemsTransmitted = 0; + + //Apply the CRC reflection + CRC32_val = ~CRC32_val; + + //Send the CRC + (void)serialWrite(CRC32_val); } void sendCompositeLog(void) { - if ( (BIT_CHECK(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY)) || (serialStatusFlag == SERIAL_TRANSMIT_COMPOSITE_INPROGRESS) ) //Sanity check. Flagging system means this should always be true + if ( BIT_CHECK(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY) == false ) //Sanity check. Flagging system means this should always be true { - uint32_t CRC32_val = 0; - if(logItemsTransmitted == 0) - { - //Transmit the size of the packet - (void)serialWrite((uint16_t)(sizeof(toothHistory) + sizeof(compositeLogHistory) + 1U)); //Size of the tooth log (uint32_t values) plus the return code - - //Begin new CRC hash - const uint8_t returnCode = SERIAL_RC_OK; - CRC32_val = CRC32_serial.crc32(&returnCode, 1, false); - - //Send the return code - writeByteReliableBlocking(returnCode); - } - - for (; logItemsTransmitted < TOOTH_LOG_SIZE; logItemsTransmitted++) + //If the buffer is not yet full but TS has timed out, pad the rest of the buffer with 0s + while(toothHistoryIndex < TOOTH_LOG_SIZE) { - //Check whether the tx buffer still has space - if((uint16_t)Serial.availableForWrite() < sizeof(toothHistory[logItemsTransmitted])+sizeof(compositeLogHistory[logItemsTransmitted])) - { - //tx buffer is full. Store the current state so it can be resumed later - serialStatusFlag = SERIAL_TRANSMIT_COMPOSITE_INPROGRESS; - return; - } - - uint32_t transmitted = serialWrite(toothHistory[logItemsTransmitted]); //This combined runtime (in us) that the log was going for by this record - CRC32_serial.crc32_upd((const byte*)&transmitted, sizeof(transmitted), false); - - //The status byte (Indicates the trigger edge, whether it was a pri/sec pulse, the sync status) - writeByteReliableBlocking(compositeLogHistory[logItemsTransmitted]); - CRC32_val = CRC32_serial.crc32_upd((const byte*)&compositeLogHistory[logItemsTransmitted], sizeof(compositeLogHistory[logItemsTransmitted]), false); + toothHistory[toothHistoryIndex] = toothHistory[toothHistoryIndex-1]; //Composite logger needs a realistic time value to display correctly. Copy the last value + compositeLogHistory[toothHistoryIndex] = 0; + toothHistoryIndex++; } - BIT_CLEAR(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY); - toothHistoryIndex = 0; - serialStatusFlag = SERIAL_INACTIVE; - logItemsTransmitted = 0; - - //Apply the CRC reflection - CRC32_val = ~CRC32_val; - - //Send the CRC - (void)serialWrite(CRC32_val); } - else + + uint32_t CRC32_val = 0; + if(logItemsTransmitted == 0) { - sendReturnCodeMsg(SERIAL_RC_BUSY_ERR); - serialStatusFlag = SERIAL_INACTIVE; - } + //Transmit the size of the packet + (void)serialWrite((uint16_t)(sizeof(toothHistory) + sizeof(compositeLogHistory) + 1U)); //Size of the tooth log (uint32_t values) plus the return code + + //Begin new CRC hash + const uint8_t returnCode = SERIAL_RC_OK; + CRC32_val = CRC32_serial.crc32(&returnCode, 1, false); + + //Send the return code + writeByteReliableBlocking(returnCode); + } + + for (; logItemsTransmitted < TOOTH_LOG_SIZE; logItemsTransmitted++) + { + //Check whether the tx buffer still has space + if((uint16_t)Serial.availableForWrite() < sizeof(toothHistory[logItemsTransmitted])+sizeof(compositeLogHistory[logItemsTransmitted])) + { + //tx buffer is full. Store the current state so it can be resumed later + serialStatusFlag = SERIAL_TRANSMIT_COMPOSITE_INPROGRESS; + return; + } + + uint32_t transmitted = serialWrite(toothHistory[logItemsTransmitted]); //This combined runtime (in us) that the log was going for by this record + CRC32_serial.crc32_upd((const byte*)&transmitted, sizeof(transmitted), false); + + //The status byte (Indicates the trigger edge, whether it was a pri/sec pulse, the sync status) + writeByteReliableBlocking(compositeLogHistory[logItemsTransmitted]); + CRC32_val = CRC32_serial.crc32_upd((const byte*)&compositeLogHistory[logItemsTransmitted], sizeof(compositeLogHistory[logItemsTransmitted]), false); + } + BIT_CLEAR(currentStatus.status1, BIT_STATUS1_TOOTHLOG1READY); + toothHistoryIndex = 0; + serialStatusFlag = SERIAL_INACTIVE; + logItemsTransmitted = 0; + + //Apply the CRC reflection + CRC32_val = ~CRC32_val; + + //Send the CRC + (void)serialWrite(CRC32_val); } #if defined(CORE_AVR)