added non-blocking LoRa transmission

yet to be tested on hardware
This commit is contained in:
Timm Bogner 2023-01-28 20:39:45 -06:00
parent 3513811a7c
commit cb6ad63f39
2 changed files with 67 additions and 47 deletions

View File

@ -90,6 +90,17 @@ DataBuffer LORA1Buffer;
DataBuffer LORA2Buffer; DataBuffer LORA2Buffer;
DataBuffer LORABBuffer; DataBuffer LORABBuffer;
enum
{
TxLoRa1,
TxLoRa2,
TxLoRaB,
TxIdle
} TxStatus;
uint8_t tx_buffer_position = 0;
uint32_t tx_start_time;
#endif // USE_LORA #endif // USE_LORA
// Function prototypes // Function prototypes
@ -219,9 +230,9 @@ void printLoraPacket(uint8_t *p, int size)
printf("\n"); printf("\n");
} }
#ifdef USE_LORA
void begin_lora() void begin_lora()
{ {
#ifdef USE_LORA
int state = radio.begin(FDRS_LORA_FREQUENCY, FDRS_LORA_BANDWIDTH, FDRS_LORA_SF, FDRS_LORA_CR, FDRS_LORA_SYNCWORD, FDRS_LORA_TXPWR, 8, 0); int state = radio.begin(FDRS_LORA_FREQUENCY, FDRS_LORA_BANDWIDTH, FDRS_LORA_SF, FDRS_LORA_CR, FDRS_LORA_SYNCWORD, FDRS_LORA_TXPWR, 8, 0);
if (state == RADIOLIB_ERR_NONE) if (state == RADIOLIB_ERR_NONE)
{ {
@ -246,8 +257,8 @@ void begin_lora()
while (true) while (true)
; ;
} }
#endif // USE_LORA
} }
#endif // USE_LORA
crcResult getLoRa() crcResult getLoRa()
{ {
@ -455,58 +466,56 @@ void sendLoRaNbr(uint8_t interface)
#endif // USE_LORA #endif // USE_LORA
} }
void release_lora_buffer(uint8_t interface) void asyncReleaseLoRa(bool first_run)
{ {
#ifdef USE_LORA if (first_run)
DBG("Releasing LoRa buffers.");
DataReading thePacket[lora_size];
int j = 0;
for (int i = 0; i < LORA1Buffer.len; i++)
{ {
if (j > lora_size) TxStatus = TxLoRa1;
{ tx_start_time = millis();
transmitLoRa(&LoRa1, thePacket, j);
j = 0;
} }
thePacket[j] = LORA1Buffer.buffer[i]; switch (TxStatus)
j++;
}
transmitLoRa(&LoRa1, thePacket, j);
LORA1Buffer.len = 0;
j = 0;
for (int i = 0; i < LORA2Buffer.len; i++)
{ {
if (j > lora_size) case TxLoRa1:
if (LORA1Buffer.len - tx_buffer_position > lora_size)
{ {
transmitLoRa(&LoRa2, thePacket, j); transmitLoRa(&LoRa1, &LORA1Buffer.buffer[tx_buffer_position], lora_size);
j = 0; tx_buffer_position += lora_size;
} }
thePacket[j] = LORA2Buffer.buffer[i]; else
j++;
}
transmitLoRa(&LoRa2, thePacket, j);
LORA2Buffer.len = 0;
j = 0;
for (int i = 0; i < LORABBuffer.len; i++)
{ {
if (j > lora_size) transmitLoRa(&LoRa1, &LORA1Buffer.buffer[tx_buffer_position], LORA1Buffer.len - tx_buffer_position);
tx_buffer_position = 0;
TxStatus = TxLoRa2;
}
break;
case TxLoRa2:
if (LORA2Buffer.len - tx_buffer_position > lora_size)
{ {
transmitLoRa(&loraBroadcast, thePacket, j); transmitLoRa(&LoRa2, &LORA2Buffer.buffer[tx_buffer_position], lora_size);
j = 0; tx_buffer_position += lora_size;
} }
thePacket[j] = LORABBuffer.buffer[i]; else
j++; {
transmitLoRa(&LoRa2, &LORA2Buffer.buffer[tx_buffer_position], LORA2Buffer.len - tx_buffer_position);
tx_buffer_position = 0;
TxStatus = TxLoRaB;
}
break;
case TxLoRaB:
if (LORABBuffer.len - tx_buffer_position > lora_size)
{
transmitLoRa(&loraBroadcast, &LORABBuffer.buffer[tx_buffer_position], lora_size);
tx_buffer_position += lora_size;
}
else
{
transmitLoRa(&loraBroadcast, &LORABBuffer.buffer[tx_buffer_position], LORABBuffer.len - tx_buffer_position);
DBG(millis() - tx_start_time);
tx_buffer_position = 0;
TxStatus = TxIdle;
}
break;
} }
transmitLoRa(&loraBroadcast, thePacket, j);
LORABBuffer.len = 0;
#endif
} }
void handleLoRa() void handleLoRa()
@ -516,8 +525,14 @@ void handleLoRa()
{ {
enableInterrupt = false; enableInterrupt = false;
operationDone = false; operationDone = false;
if (transmitFlag) if (transmitFlag) // the previous operation was transmission
{ // the previous operation was transmission {
if (TxStatus != TxIdle)
{
asyncReleaseLoRa(false);
enableInterrupt = true;
}
radio.startReceive(); // return to listen mode radio.startReceive(); // return to listen mode
enableInterrupt = true; enableInterrupt = true;
transmitFlag = false; transmitFlag = false;
@ -534,3 +549,5 @@ void handleLoRa()
} }
#endif // USE_LORA #endif // USE_LORA
} }

View File

@ -0,0 +1,3 @@
void check_scheduler(){
}