TX happening in single SPI transaction
This commit is contained in:
14
crossbow.ino
14
crossbow.ino
@@ -1,5 +1,5 @@
|
|||||||
// #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
|
||||||
@@ -60,6 +60,8 @@ RxDeviceState_t rxDeviceState = {};
|
|||||||
TxDeviceState_t txDeviceState = {};
|
TxDeviceState_t txDeviceState = {};
|
||||||
volatile RadioState_t radioState;
|
volatile RadioState_t radioState;
|
||||||
|
|
||||||
|
uint8_t tmpBuffer[MAX_PACKET_SIZE];
|
||||||
|
|
||||||
uint8_t getRadioRssi(void)
|
uint8_t getRadioRssi(void)
|
||||||
{
|
{
|
||||||
return 164 - constrain(LoRa.packetRssi() * -1, 0, 164);
|
return 164 - constrain(LoRa.packetRssi() * -1, 0, 164);
|
||||||
@@ -263,8 +265,6 @@ void loop(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (radioState.bytesToRead != NO_DATA_TO_READ) {
|
if (radioState.bytesToRead != NO_DATA_TO_READ) {
|
||||||
static uint8_t tmpBuffer[20];
|
|
||||||
|
|
||||||
LoRa.read(tmpBuffer, radioState.bytesToRead);
|
LoRa.read(tmpBuffer, radioState.bytesToRead);
|
||||||
|
|
||||||
for (int i = 0; i < radioState.bytesToRead; i++) {
|
for (int i = 0; i < radioState.bytesToRead; i++) {
|
||||||
@@ -395,8 +395,12 @@ void loop(void)
|
|||||||
|
|
||||||
if (qsp.canTransmit && transmitPayload)
|
if (qsp.canTransmit && transmitPayload)
|
||||||
{
|
{
|
||||||
|
uint8_t size;
|
||||||
LoRa.beginPacket();
|
LoRa.beginPacket();
|
||||||
qspEncodeFrame(&qsp);
|
//Prepare packet
|
||||||
|
qspEncodeFrame(&qsp, tmpBuffer, &size);
|
||||||
|
//Sent it to radio in one SPI transaction
|
||||||
|
LoRa.write(tmpBuffer, size);
|
||||||
LoRa.endPacket();
|
LoRa.endPacket();
|
||||||
//After ending packet, put device into receive mode again
|
//After ending packet, put device into receive mode again
|
||||||
LoRa.receive();
|
LoRa.receive();
|
||||||
|
|||||||
17
qsp.cpp
17
qsp.cpp
@@ -230,26 +230,27 @@ void qspDecodeIncomingFrame(
|
|||||||
/**
|
/**
|
||||||
* Encode frame is corrent format and write to hardware
|
* Encode frame is corrent format and write to hardware
|
||||||
*/
|
*/
|
||||||
void qspEncodeFrame(QspConfiguration_t *qsp) {
|
void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size) {
|
||||||
//Zero CRC
|
//Zero CRC
|
||||||
qsp->crc = 0;
|
qsp->crc = 0;
|
||||||
|
|
||||||
//Write CHANNEL_ID
|
qspComputeCrc(qsp, CHANNEL_ID);
|
||||||
qsp->hardwareWriteFunction(CHANNEL_ID, qsp);
|
buffer[0] = CHANNEL_ID;
|
||||||
|
|
||||||
//Write frame type and length
|
//Write frame type and length
|
||||||
uint8_t data = qsp->payloadLength & 0x0f;
|
uint8_t data = qsp->payloadLength & 0x0f;
|
||||||
data |= (qsp->frameToSend << 4) & 0xf0;
|
data |= (qsp->frameToSend << 4) & 0xf0;
|
||||||
qsp->hardwareWriteFunction(data, qsp);
|
qspComputeCrc(qsp, data);
|
||||||
|
buffer[1] = data;
|
||||||
|
|
||||||
//Write payload
|
|
||||||
for (uint8_t i = 0; i < qsp->payloadLength; i++)
|
for (uint8_t i = 0; i < qsp->payloadLength; i++)
|
||||||
{
|
{
|
||||||
qsp->hardwareWriteFunction(qsp->payload[i], qsp);
|
qspComputeCrc(qsp, qsp->payload[i]);
|
||||||
|
buffer[i + 2] = qsp->payload[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Finally write CRC
|
buffer[qsp->payloadLength + 2] = qsp->crc;
|
||||||
qsp->hardwareWriteFunction(qsp->crc, qsp);
|
*size = qsp->payloadLength + 3; //Total length of QSP frame
|
||||||
}
|
}
|
||||||
|
|
||||||
void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros) {
|
void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros) {
|
||||||
|
|||||||
2
qsp.h
2
qsp.h
@@ -17,6 +17,6 @@ void qspDecodeIncomingFrame(
|
|||||||
RadioState_t *radioState
|
RadioState_t *radioState
|
||||||
);
|
);
|
||||||
void qspClearPayload(QspConfiguration_t *qsp);
|
void qspClearPayload(QspConfiguration_t *qsp);
|
||||||
void qspEncodeFrame(QspConfiguration_t *qsp);
|
void qspEncodeFrame(QspConfiguration_t *qsp, uint8_t buffer[], uint8_t *size);
|
||||||
|
|
||||||
void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros);
|
void encodePingPayload(QspConfiguration_t *qsp, uint32_t currentMicros);
|
||||||
Reference in New Issue
Block a user