another small refactoring
This commit is contained in:
@@ -231,7 +231,7 @@ void loop(void)
|
||||
/*
|
||||
* RC_DATA QSP frame
|
||||
*/
|
||||
if (currentMillis - lastRcFrameTransmit > TX_RC_FRAME_RATE && !transmitPayload && qsp.protocolState == IDLE)
|
||||
if (currentMillis - lastRcFrameTransmit > TX_RC_FRAME_RATE && !transmitPayload && qsp.protocolState == QSP_STATE_IDLE)
|
||||
{
|
||||
lastRcFrameTransmit = currentMillis;
|
||||
|
||||
|
||||
26
qsp.cpp
26
qsp.cpp
@@ -128,18 +128,18 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
static uint8_t receivedPayload;
|
||||
static uint8_t packetId; //TODO move this to global scope maybe?
|
||||
|
||||
if (qsp->protocolState == IDLE && incomingByte == QSP_PREAMBLE)
|
||||
if (qsp->protocolState == QSP_STATE_IDLE && incomingByte == QSP_PREAMBLE)
|
||||
{
|
||||
//If in IDLE and correct preamble comes, start to decode frame
|
||||
qsp->protocolState = PREAMBLE_RECEIVED;
|
||||
qsp->protocolState = QSP_STATE_PREAMBLE_RECEIVED;
|
||||
qsp->crc = 0 ^ incomingByte;
|
||||
}
|
||||
else if (qsp->protocolState == PREAMBLE_RECEIVED)
|
||||
else if (qsp->protocolState == QSP_STATE_PREAMBLE_RECEIVED)
|
||||
{
|
||||
// Check if incomming channel ID is the same as receiver
|
||||
if (incomingByte == CHANNEL_ID)
|
||||
{
|
||||
qsp->protocolState = CHANNEL_RECEIVED;
|
||||
qsp->protocolState = QSP_STATE_CHANNEL_RECEIVED;
|
||||
qsp->crc ^= incomingByte;
|
||||
|
||||
qspClearPayload(qsp);
|
||||
@@ -149,10 +149,10 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
}
|
||||
else
|
||||
{
|
||||
qsp->protocolState = IDLE;
|
||||
qsp->protocolState = QSP_STATE_IDLE;
|
||||
}
|
||||
}
|
||||
else if (qsp->protocolState == CHANNEL_RECEIVED)
|
||||
else if (qsp->protocolState == QSP_STATE_CHANNEL_RECEIVED)
|
||||
{
|
||||
//Frame ID and payload length
|
||||
qsp->crc ^= incomingByte;
|
||||
@@ -160,15 +160,15 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
frameId = (incomingByte >> 4) & 0x0f;
|
||||
payloadLength = incomingByte & 0x0f;
|
||||
|
||||
qsp->protocolState = FRAME_TYPE_RECEIVED;
|
||||
qsp->protocolState = QSP_STATE_FRAME_TYPE_RECEIVED;
|
||||
}
|
||||
else if (qsp->protocolState == FRAME_TYPE_RECEIVED)
|
||||
else if (qsp->protocolState == QSP_STATE_FRAME_TYPE_RECEIVED)
|
||||
{
|
||||
qsp->crc ^= incomingByte;
|
||||
packetId = incomingByte;
|
||||
qsp->protocolState = PACKET_ID_RECEIVED;
|
||||
qsp->protocolState = QSP_STATE_PACKET_ID_RECEIVED;
|
||||
}
|
||||
else if (qsp->protocolState == PACKET_ID_RECEIVED)
|
||||
else if (qsp->protocolState == QSP_STATE_PACKET_ID_RECEIVED)
|
||||
{
|
||||
|
||||
//Now it's time for payload
|
||||
@@ -179,11 +179,11 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
|
||||
if (receivedPayload == payloadLength)
|
||||
{
|
||||
qsp->protocolState = PAYLOAD_RECEIVED;
|
||||
qsp->protocolState = QSP_STATE_PAYLOAD_RECEIVED;
|
||||
qsp->payloadLength = payloadLength;
|
||||
}
|
||||
}
|
||||
else if (qsp->protocolState == PAYLOAD_RECEIVED)
|
||||
else if (qsp->protocolState == QSP_STATE_PAYLOAD_RECEIVED)
|
||||
{
|
||||
|
||||
if (qsp->crc == incomingByte) {
|
||||
@@ -213,7 +213,7 @@ void qspDecodeIncomingFrame(QspConfiguration_t *qsp, uint8_t incomingByte, int p
|
||||
}
|
||||
|
||||
// In both cases switch to listening for next preamble
|
||||
qsp->protocolState = IDLE;
|
||||
qsp->protocolState = QSP_STATE_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
variables.h
16
variables.h
@@ -18,13 +18,13 @@
|
||||
#define PIN_LED 13
|
||||
|
||||
enum dataStates {
|
||||
IDLE,
|
||||
PREAMBLE_RECEIVED,
|
||||
CHANNEL_RECEIVED,
|
||||
FRAME_TYPE_RECEIVED,
|
||||
PACKET_ID_RECEIVED,
|
||||
PAYLOAD_RECEIVED,
|
||||
CRC_RECEIVED
|
||||
QSP_STATE_IDLE,
|
||||
QSP_STATE_PREAMBLE_RECEIVED,
|
||||
QSP_STATE_CHANNEL_RECEIVED,
|
||||
QSP_STATE_FRAME_TYPE_RECEIVED,
|
||||
QSP_STATE_PACKET_ID_RECEIVED,
|
||||
QSP_STATE_PAYLOAD_RECEIVED,
|
||||
QSP_STATE_CRC_RECEIVED
|
||||
};
|
||||
|
||||
#define PPM_INPUT_PIN 2
|
||||
@@ -37,7 +37,7 @@ enum dataStates {
|
||||
#define PPM_OUTPUT_PIN 10 //set PPM signal output pin on the arduino
|
||||
|
||||
struct QspConfiguration_t {
|
||||
uint8_t protocolState = IDLE;
|
||||
uint8_t protocolState = QSP_STATE_IDLE;
|
||||
uint8_t crc = 0;
|
||||
uint8_t payload[QSP_PAYLOAD_LENGTH] = {0};
|
||||
uint8_t payloadLength = 0;
|
||||
|
||||
Reference in New Issue
Block a user