progress
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -9,7 +9,8 @@
|
|||||||
"rope": "c",
|
"rope": "c",
|
||||||
"__locale": "c",
|
"__locale": "c",
|
||||||
"string": "c",
|
"string": "c",
|
||||||
"ios": "cpp"
|
"ios": "cpp",
|
||||||
|
"locale": "cpp"
|
||||||
},
|
},
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/build": true
|
"**/build": true
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
* DEVICE_MODE_TX
|
* DEVICE_MODE_TX
|
||||||
* DEVICE_MODE_RX
|
* DEVICE_MODE_RX
|
||||||
*/
|
*/
|
||||||
#define DEVICE_MODE_TX
|
// #define DEVICE_MODE_TX
|
||||||
// #define DEVICE_MODE_RX
|
#define DEVICE_MODE_RX
|
||||||
|
|
||||||
#define FEATURE_TX_OLED
|
#define FEATURE_TX_OLED
|
||||||
// #define FORCE_TX_WITHOUT_INPUT
|
// #define FORCE_TX_WITHOUT_INPUT
|
||||||
|
|||||||
@@ -155,9 +155,9 @@ void setup(void)
|
|||||||
qsp.onFailureCallback = onQspFailure;
|
qsp.onFailureCallback = onQspFailure;
|
||||||
|
|
||||||
#ifdef DEVICE_MODE_RX
|
#ifdef DEVICE_MODE_RX
|
||||||
qsp.deviceState = DEVICE_STATE_FAILSAFE;
|
platformNode.platformState = DEVICE_STATE_FAILSAFE;
|
||||||
#else
|
#else
|
||||||
qsp.deviceState = DEVICE_STATE_OK;
|
platformNode.platformState = DEVICE_STATE_OK;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
radioNode.init(LORA_SS_PIN, LORA_RST_PIN, LORA_DI0_PIN, onReceive);
|
radioNode.init(LORA_SS_PIN, LORA_RST_PIN, LORA_DI0_PIN, onReceive);
|
||||||
@@ -213,10 +213,10 @@ void setup(void)
|
|||||||
/*
|
/*
|
||||||
* Setup salt bind key
|
* Setup salt bind key
|
||||||
*/
|
*/
|
||||||
qsp.bindKey[0] = 0x12;
|
platformNode.bindKey[0] = 0x12;
|
||||||
qsp.bindKey[1] = 0x0a;
|
platformNode.bindKey[1] = 0x0a;
|
||||||
qsp.bindKey[2] = 0x36;
|
platformNode.bindKey[2] = 0x36;
|
||||||
qsp.bindKey[3] = 0xa7;
|
platformNode.bindKey[3] = 0xa7;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ void loop(void)
|
|||||||
txInput.loop();
|
txInput.loop();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
radioNode.deviceState == RADIO_STATE_RX &&
|
radioNode.radioState == RADIO_STATE_RX &&
|
||||||
qsp.protocolState == QSP_STATE_IDLE &&
|
qsp.protocolState == QSP_STATE_IDLE &&
|
||||||
qsp.lastTxSlotTimestamp + TX_TRANSMIT_SLOT_RATE < currentMillis
|
qsp.lastTxSlotTimestamp + TX_TRANSMIT_SLOT_RATE < currentMillis
|
||||||
) {
|
) {
|
||||||
@@ -391,11 +391,6 @@ void loop(void)
|
|||||||
uint8_t output = constrain(radioNode.rssi - 40, 0, 100);
|
uint8_t output = constrain(radioNode.rssi - 40, 0, 100);
|
||||||
|
|
||||||
rxDeviceState.indicatedRssi = (output * 10) + 1000;
|
rxDeviceState.indicatedRssi = (output * 10) + 1000;
|
||||||
if (qsp.deviceState == DEVICE_STATE_FAILSAFE) {
|
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
|
||||||
} else {
|
|
||||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -431,17 +426,17 @@ void loop(void)
|
|||||||
if (currentMillis > sbusTime) {
|
if (currentMillis > sbusTime) {
|
||||||
platformNode.setRcChannel(RSSI_CHANNEL - 1, rxDeviceState.indicatedRssi, 0);
|
platformNode.setRcChannel(RSSI_CHANNEL - 1, rxDeviceState.indicatedRssi, 0);
|
||||||
|
|
||||||
sbusPreparePacket(sbusPacket, false, (qsp.deviceState == DEVICE_STATE_FAILSAFE));
|
sbusPreparePacket(sbusPacket, false, (platformNode.platformState == DEVICE_STATE_FAILSAFE));
|
||||||
Serial1.write(sbusPacket, SBUS_PACKET_LENGTH);
|
Serial1.write(sbusPacket, SBUS_PACKET_LENGTH);
|
||||||
sbusTime = currentMillis + SBUS_UPDATE_RATE;
|
sbusTime = currentMillis + SBUS_UPDATE_RATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qsp.lastFrameReceivedAt[QSP_FRAME_RC_DATA] + RX_FAILSAFE_DELAY < currentMillis) {
|
if (qsp.lastFrameReceivedAt[QSP_FRAME_RC_DATA] + RX_FAILSAFE_DELAY < currentMillis) {
|
||||||
qsp.deviceState = DEVICE_STATE_FAILSAFE;
|
platformNode.platformState = DEVICE_STATE_FAILSAFE;
|
||||||
rxDeviceState.indicatedRssi = 0;
|
rxDeviceState.indicatedRssi = 0;
|
||||||
radioNode.rssi = 0;
|
radioNode.rssi = 0;
|
||||||
} else {
|
} else {
|
||||||
qsp.deviceState = DEVICE_STATE_OK;
|
platformNode.platformState = DEVICE_STATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -461,7 +456,7 @@ void loop(void)
|
|||||||
//TX module started to receive data
|
//TX module started to receive data
|
||||||
buzzerSingleMode(BUZZER_MODE_DOUBLE_CHIRP, &buzzer);
|
buzzerSingleMode(BUZZER_MODE_DOUBLE_CHIRP, &buzzer);
|
||||||
txDeviceState.isReceiving = true;
|
txDeviceState.isReceiving = true;
|
||||||
qsp.deviceState = DEVICE_STATE_OK;
|
platformNode.platformState = DEVICE_STATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Here we detect failsafe state on TX module
|
//Here we detect failsafe state on TX module
|
||||||
@@ -477,14 +472,14 @@ void loop(void)
|
|||||||
rxDeviceState.snr = 0;
|
rxDeviceState.snr = 0;
|
||||||
rxDeviceState.flags = 0;
|
rxDeviceState.flags = 0;
|
||||||
txDeviceState.roundtrip = 0;
|
txDeviceState.roundtrip = 0;
|
||||||
qsp.deviceState = DEVICE_STATE_FAILSAFE;
|
platformNode.platformState = DEVICE_STATE_FAILSAFE;
|
||||||
qsp.anyFrameRecivedAt = 0;
|
qsp.anyFrameRecivedAt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME rxDeviceState should be resetted also in RC_HEALT frame is not received in a long period
|
//FIXME rxDeviceState should be resetted also in RC_HEALT frame is not received in a long period
|
||||||
|
|
||||||
//Handle audible alarms
|
//Handle audible alarms
|
||||||
if (qsp.deviceState == DEVICE_STATE_FAILSAFE) {
|
if (platformNode.platformState == DEVICE_STATE_FAILSAFE) {
|
||||||
//Failsafe detected by TX
|
//Failsafe detected by TX
|
||||||
buzzerContinousMode(BUZZER_MODE_SLOW_BEEP, &buzzer);
|
buzzerContinousMode(BUZZER_MODE_SLOW_BEEP, &buzzer);
|
||||||
} else if (txDeviceState.isReceiving && (rxDeviceState.flags & 0x1) == 1) {
|
} else if (txDeviceState.isReceiving && (rxDeviceState.flags & 0x1) == 1) {
|
||||||
@@ -498,24 +493,32 @@ void loop(void)
|
|||||||
buzzerContinousMode(BUZZER_MODE_OFF, &buzzer);
|
buzzerContinousMode(BUZZER_MODE_OFF, &buzzer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle LED updates
|
* Handle LED updates
|
||||||
*/
|
*/
|
||||||
if (txDeviceState.nextLedUpdate < currentMillis) {
|
if (platformNode.nextLedUpdate < currentMillis) {
|
||||||
|
#ifdef DEVICE_MODE_TX
|
||||||
if (txDeviceState.isReceiving) {
|
if (txDeviceState.isReceiving) {
|
||||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||||
txDeviceState.nextLedUpdate = currentMillis + 300;
|
platformNode.nextLedUpdate = currentMillis + 300;
|
||||||
} else if (txInput.isReceiving()) {
|
} else if (txInput.isReceiving()) {
|
||||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||||
txDeviceState.nextLedUpdate = currentMillis + 100;
|
platformNode.nextLedUpdate = currentMillis + 100;
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
txDeviceState.nextLedUpdate = currentMillis + 200;
|
platformNode.nextLedUpdate = currentMillis + 200;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
platformNode.nextLedUpdate = currentMillis + 200;
|
||||||
|
if (platformNode.platformState == DEVICE_STATE_FAILSAFE) {
|
||||||
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
|
} else {
|
||||||
|
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +539,7 @@ void onReceive(int packetSize)
|
|||||||
*/
|
*/
|
||||||
LoRa.sleep();
|
LoRa.sleep();
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
radioNode.deviceState = RADIO_STATE_RX;
|
radioNode.radioState = RADIO_STATE_RX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,12 +9,21 @@
|
|||||||
#define PLATFORM_CHANNEL_COUNT 10
|
#define PLATFORM_CHANNEL_COUNT 10
|
||||||
#define PLATFORM_DEFAULT_CHANNEL_VALUE 1000
|
#define PLATFORM_DEFAULT_CHANNEL_VALUE 1000
|
||||||
|
|
||||||
|
enum deviceStates {
|
||||||
|
DEVICE_STATE_OK,
|
||||||
|
DEVICE_STATE_FAILSAFE,
|
||||||
|
DEVICE_STATE_UNDETERMINED
|
||||||
|
};
|
||||||
|
|
||||||
class PlatformNode {
|
class PlatformNode {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlatformNode(void);
|
PlatformNode(void);
|
||||||
int getRcChannel(uint8_t channel);
|
int getRcChannel(uint8_t channel);
|
||||||
void setRcChannel(uint8_t channel, int value, int offset);
|
void setRcChannel(uint8_t channel, int value, int offset);
|
||||||
|
uint8_t bindKey[4];
|
||||||
|
uint32_t nextLedUpdate = 0;
|
||||||
|
uint8_t platformState = DEVICE_STATE_UNDETERMINED;
|
||||||
private:
|
private:
|
||||||
volatile int _channels[PLATFORM_TOTAL_CHANNEL_COUNT];
|
volatile int _channels[PLATFORM_TOTAL_CHANNEL_COUNT];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ void encodeRxHealthPayload(QspConfiguration_t *qsp, RxDeviceState_t *rxDeviceSta
|
|||||||
|
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
|
|
||||||
if (qsp->deviceState == DEVICE_STATE_FAILSAFE) {
|
if (platformNode.platformState == DEVICE_STATE_FAILSAFE) {
|
||||||
flags |= 0x01 << 0;
|
flags |= 0x01 << 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ void qspClearPayload(QspConfiguration_t *qsp)
|
|||||||
void qspInitCrc(QspConfiguration_t *qsp) {
|
void qspInitCrc(QspConfiguration_t *qsp) {
|
||||||
qsp->crc = 0;
|
qsp->crc = 0;
|
||||||
for (uint8_t i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
qspComputeCrc(qsp, qsp->bindKey[i]);
|
qspComputeCrc(qsp, platformNode.bindKey[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ void RadioNode::init(uint8_t ss, uint8_t rst, uint8_t di0, void(*callback)(int))
|
|||||||
//Setup ISR callback and start receiving
|
//Setup ISR callback and start receiving
|
||||||
LoRa.onReceive(callback);
|
LoRa.onReceive(callback);
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
deviceState = RADIO_STATE_RX;
|
radioState = RADIO_STATE_RX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioNode::readRssi(void)
|
void RadioNode::readRssi(void)
|
||||||
@@ -82,7 +82,7 @@ void RadioNode::readAndDecode(
|
|||||||
LoRa.sleep();
|
LoRa.sleep();
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
|
|
||||||
deviceState = RADIO_STATE_RX;
|
radioState = RADIO_STATE_RX;
|
||||||
bytesToRead = NO_DATA_TO_READ;
|
bytesToRead = NO_DATA_TO_READ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ void RadioNode::handleTxDoneState(bool hop) {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
currentMillis > nextTxCheckMillis &&
|
currentMillis > nextTxCheckMillis &&
|
||||||
deviceState == RADIO_STATE_TX &&
|
radioState == RADIO_STATE_TX &&
|
||||||
!LoRa.isTransmitting()
|
!LoRa.isTransmitting()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ void RadioNode::handleTxDoneState(bool hop) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
deviceState = RADIO_STATE_RX;
|
radioState = RADIO_STATE_RX;
|
||||||
nextTxCheckMillis = currentMillis + 1; //We check of TX done every 1ms
|
nextTxCheckMillis = currentMillis + 1; //We check of TX done every 1ms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,5 +158,5 @@ void RadioNode::handleTx(QspConfiguration_t *qsp) {
|
|||||||
LoRa.endPacketAsync();
|
LoRa.endPacketAsync();
|
||||||
|
|
||||||
//Set state to be able to detect the moment when TX is done
|
//Set state to be able to detect the moment when TX is done
|
||||||
deviceState = RADIO_STATE_TX;
|
radioState = RADIO_STATE_TX;
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ class RadioNode {
|
|||||||
void handleTxDoneState(bool hop);
|
void handleTxDoneState(bool hop);
|
||||||
void handleTx(QspConfiguration_t *qsp);
|
void handleTx(QspConfiguration_t *qsp);
|
||||||
volatile int8_t bytesToRead = -1;
|
volatile int8_t bytesToRead = -1;
|
||||||
volatile uint8_t deviceState = RADIO_STATE_RX;
|
volatile uint8_t radioState = RADIO_STATE_RX;
|
||||||
uint8_t rssi = 0;
|
uint8_t rssi = 0;
|
||||||
uint8_t snr = 0;
|
uint8_t snr = 0;
|
||||||
uint8_t lastReceivedChannel = 0;
|
uint8_t lastReceivedChannel = 0;
|
||||||
|
|||||||
@@ -60,12 +60,6 @@ enum dataStates {
|
|||||||
QSP_STATE_CRC_RECEIVED
|
QSP_STATE_CRC_RECEIVED
|
||||||
};
|
};
|
||||||
|
|
||||||
enum deviceStates {
|
|
||||||
DEVICE_STATE_OK,
|
|
||||||
DEVICE_STATE_FAILSAFE,
|
|
||||||
DEVICE_STATE_UNDETERMINED
|
|
||||||
};
|
|
||||||
|
|
||||||
#define PPM_INPUT_PIN 0 // Has to be one of Interrupt pins
|
#define PPM_INPUT_PIN 0 // Has to be one of Interrupt pins
|
||||||
|
|
||||||
#define PPM_INPUT_CHANNEL_COUNT 10
|
#define PPM_INPUT_CHANNEL_COUNT 10
|
||||||
@@ -88,7 +82,6 @@ struct TxDeviceState_t {
|
|||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
uint32_t roundtrip = 0;
|
uint32_t roundtrip = 0;
|
||||||
bool isReceiving = false; //Indicates that TX module is receiving frames from RX module
|
bool isReceiving = false; //Indicates that TX module is receiving frames from RX module
|
||||||
uint32_t nextLedUpdate = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RxDeviceState_t {
|
struct RxDeviceState_t {
|
||||||
@@ -102,7 +95,6 @@ struct RxDeviceState_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct QspConfiguration_t {
|
struct QspConfiguration_t {
|
||||||
uint8_t bindKey[4] = {0, 0, 0, 0};
|
|
||||||
uint8_t protocolState = QSP_STATE_IDLE;
|
uint8_t protocolState = QSP_STATE_IDLE;
|
||||||
uint8_t crc = 0;
|
uint8_t crc = 0;
|
||||||
uint8_t payload[QSP_PAYLOAD_LENGTH] = {0};
|
uint8_t payload[QSP_PAYLOAD_LENGTH] = {0};
|
||||||
@@ -111,7 +103,6 @@ struct QspConfiguration_t {
|
|||||||
uint8_t frameId = 0;
|
uint8_t frameId = 0;
|
||||||
uint32_t lastFrameReceivedAt[QSP_FRAME_COUNT] = {0};
|
uint32_t lastFrameReceivedAt[QSP_FRAME_COUNT] = {0};
|
||||||
uint32_t anyFrameRecivedAt = 0;
|
uint32_t anyFrameRecivedAt = 0;
|
||||||
uint8_t deviceState = DEVICE_STATE_UNDETERMINED;
|
|
||||||
void (* onSuccessCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*, uint8_t receivedChannel);
|
void (* onSuccessCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*, uint8_t receivedChannel);
|
||||||
void (* onFailureCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*);
|
void (* onFailureCallback)(QspConfiguration_t*, TxDeviceState_t*, RxDeviceState_t*);
|
||||||
bool forcePongFrame = false;
|
bool forcePongFrame = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user