Speeduino
Loading...
Searching...
No Matches
Typedefs | Functions | Variables
comms.cpp File Reference
#include "globals.h"
#include "comms.h"
#include "comms_secondary.h"
#include "storage.h"
#include "maths.h"
#include "utilities.h"
#include "decoders.h"
#include "TS_CommandButtonHandler.h"
#include "errors.h"
#include "pages.h"
#include "page_crc.h"
#include "logger.h"
#include "comms_legacy.h"
#include "src/FastCRC/FastCRC.h"
#include <avr/pgmspace.h>

Typedefs

using crc_t = uint32_t
 

Functions

void processSerialCommand (void)
 Processes a message once it has been fully received.
 
void sendToothLog (void)
 Should be called when serialStatusFlag == SERIAL_TRANSMIT_TOOTH_INPROGRESS,.
 
void sendCompositeLog (void)
 Should be called when serialStatusFlag == LOG_SEND_COMPOSITE.
 
static bool isRxTimeout (void)
 Has the current receive operation timed out?
 
void flushRXbuffer (void)
 Flush all remaining bytes from the rx serial buffer.
 
static uint32_t reverse_bytes (uint32_t i)
 Reverse the byte order of a uint32_t.
 
void writeByteReliableBlocking (byte value)
 
static void readSerialTimeout (char *buffer, size_t length)
 Read from the serial port into the supplied buffer.
 
template<typename TIntegral >
static TIntegral readSerialIntegralTimeout (void)
 Reads an integral type, timing out if necessary.
 
static uint32_t serialWrite (uint32_t value)
 Write a uint32_t to Serial.
 
static void serialWrite (uint16_t value)
 Write a uint16_t to Serial.
 
static uint16_t writeNonBlocking (const byte *buffer, size_t length)
 Send as much data as possible without blocking the caller.
 
static size_t writeNonBlocking (size_t start, uint32_t value)
 Write a uint32_t to Serial without blocking the caller.
 
static uint16_t sendBufferAndCrcNonBlocking (const byte *buffer, size_t start, size_t length)
 Send the buffer, followed by it's CRC.
 
static void sendSerialPayloadNonBlocking (uint16_t payloadLength)
 Start sending the shared serialPayload buffer.
 
static void sendReturnCodeMsg (byte returnCode)
 Send a message to TS containing only a return code.
 
static bool updatePageValues (uint8_t pageNum, uint16_t offset, const byte *buffer, uint16_t length)
 Update a pages contents from a buffer.
 
static void loadPageValuesToBuffer (uint8_t pageNum, uint16_t offset, byte *buffer, uint16_t length)
 Loads a pages contents into a buffer.
 
static void generateLiveValues (uint16_t offset, uint16_t packetLength)
 Send a status record back to tuning/logging SW. This will "live" information from currentStatus struct.
 
static void loadO2CalibrationChunk (uint16_t offset, uint16_t chunkSize)
 Update the oxygen sensor table from serialPayload.
 
static uint16_t toTemperature (byte lo, byte hi)
 Convert 2 bytes into an offset temperature in degrees Celsius.
 
static void processTemperatureCalibrationTableUpdate (uint16_t calibrationLength, uint8_t calibrationPage, uint16_t *values, uint16_t *bins)
 Update a temperature calibration table from serialPayload.
 
void serialReceive (void)
 The serial receive pump. Should be called whenever the serial port has data available to read.
 
void serialTransmit (void)
 The serial transmit pump. Should be called when serialStatusFlag indicates a transmit operation is in progress.
 

Variables

static constexpr byte SERIAL_RC_OK = 0x00U
 Success.
 
static constexpr byte SERIAL_RC_REALTIME = 0x01U
 Unused.
 
static constexpr byte SERIAL_RC_PAGE = 0x02U
 Unused.
 
static constexpr byte SERIAL_RC_BURN_OK = 0x04U
 EEPROM write succeeded.
 
static constexpr byte SERIAL_RC_TIMEOUT = 0x80U
 Timeout error.
 
static constexpr byte SERIAL_RC_CRC_ERR = 0x82U
 CRC mismatch.
 
static constexpr byte SERIAL_RC_UKWN_ERR = 0x83U
 Unknown command.
 
static constexpr byte SERIAL_RC_RANGE_ERR = 0x84U
 Incorrect range. TS will not retry command.
 
static constexpr byte SERIAL_RC_BUSY_ERR = 0x85U
 TS will wait and retry.
 
static constexpr uint8_t SEND_OUTPUT_CHANNELS = 48U
 Code for the "send output channels command".
 
static constexpr byte serialVersion [] = {SERIAL_RC_OK, '0', '0', '2'}
 
static constexpr byte canId [] = {SERIAL_RC_OK, 0}
 
static constexpr byte codeVersion [] = { SERIAL_RC_OK, 's','p','e','e','d','u','i','n','o',' ','2','0','2','4','0','5','-','d','e','v'}
 
static constexpr byte productString [] = { SERIAL_RC_OK, 'S', 'p', 'e', 'e', 'd', 'u', 'i', 'n', 'o', ' ', '2', '0', '2', '4', '.', '0', '5', '-', 'd', 'e', 'v'}
 
static constexpr byte testCommsResponse [] = { SERIAL_RC_OK, 255 }
 
static uint16_t serialBytesRxTx = 0
 The number of bytes received or transmitted to date during nonblocking I/O.
 
static constexpr uint16_t SERIAL_TIMEOUT = 700
 Timeout threshold in milliseconds.
 
static uint32_t serialReceiveStartTime = 0
 The time in milliseconds at which the serial receive started. Used for calculating whether a timeout has occurred.
 
static FastCRC32 CRC32_serial
 Support accumulation of a CRC during non-blocking operations.
 
static uint8_t serialPayload [SERIAL_BUFFER_SIZE]
 Serial payload buffer.
 
static uint16_t serialPayloadLength = 0
 How many bytes in serialPayload were received or sent.
 
StreampPrimarySerial
 

Detailed Description

Process Incoming and outgoing serial communications.