mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-08 13:10:29 +00:00
another async LoRa fix
hopefully the last?
This commit is contained in:
parent
d8b61a44e1
commit
e7f277e924
@ -85,8 +85,8 @@ RADIOLIB_MODULE radio = new Module(LORA_SS, LORA_DIO, LORA_RST, LORA_BUSY);
|
|||||||
|
|
||||||
|
|
||||||
#ifndef USE_ESPNOW // mac_prefix used for both ESP-NOW and LoRa - avoid redefinition warnings
|
#ifndef USE_ESPNOW // mac_prefix used for both ESP-NOW and LoRa - avoid redefinition warnings
|
||||||
const uint8_t mac_prefix[] = {MAC_PREFIX};
|
const uint8_t mac_prefix[] = {MAC_PREFIX};
|
||||||
const uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
|
const uint8_t selfAddress[] = {MAC_PREFIX, UNIT_MAC};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool pingFlag = false;
|
bool pingFlag = false;
|
||||||
@ -188,10 +188,10 @@ crcResult transmitLoRa(uint16_t *destMac, DataReading *packet, uint8_t len)
|
|||||||
// printf("CRC: %02X : %d\n",calcCRC, i);
|
// printf("CRC: %02X : %d\n",calcCRC, i);
|
||||||
calcCRC = crc16_update(calcCRC, pkt[i]);
|
calcCRC = crc16_update(calcCRC, pkt[i]);
|
||||||
}
|
}
|
||||||
if (*destMac == 0xFFFF)
|
//if (*destMac == 0xFFFF)
|
||||||
{
|
//{
|
||||||
calcCRC = crc16_update(calcCRC, 0xA1);
|
calcCRC = crc16_update(calcCRC, 0xA1);
|
||||||
}
|
//}
|
||||||
pkt[(len * sizeof(DataReading) + 4)] = (calcCRC >> 8); // Append calculated CRC to the last 2 bytes of the packet
|
pkt[(len * sizeof(DataReading) + 4)] = (calcCRC >> 8); // Append calculated CRC to the last 2 bytes of the packet
|
||||||
pkt[(len * sizeof(DataReading) + 5)] = (calcCRC & 0x00FF);
|
pkt[(len * sizeof(DataReading) + 5)] = (calcCRC & 0x00FF);
|
||||||
DBG("Transmitting LoRa message of size " + String(sizeof(pkt)) + " bytes with CRC 0x" + String(calcCRC, HEX) + " to LoRa MAC 0x" + String(*destMac, HEX));
|
DBG("Transmitting LoRa message of size " + String(sizeof(pkt)) + " bytes with CRC 0x" + String(calcCRC, HEX) + " to LoRa MAC 0x" + String(*destMac, HEX));
|
||||||
@ -515,74 +515,58 @@ void asyncReleaseLoRa(bool first_run)
|
|||||||
delay(3);
|
delay(3);
|
||||||
if (first_run)
|
if (first_run)
|
||||||
{
|
{
|
||||||
|
if (LORA1Buffer.len > 0) {
|
||||||
TxStatus = TxLoRa1;
|
TxStatus = TxLoRa1;
|
||||||
|
} else if (LORA2Buffer.len > 0) {
|
||||||
|
TxStatus = TxLoRa2;
|
||||||
|
} else if (LORABBuffer.len > 0) {
|
||||||
|
TxStatus = TxLoRaB;
|
||||||
|
} else {
|
||||||
|
goto TxFin;
|
||||||
|
}
|
||||||
tx_start_time = millis();
|
tx_start_time = millis();
|
||||||
}
|
}
|
||||||
switch (TxStatus)
|
switch (TxStatus)
|
||||||
{
|
{
|
||||||
case TxLoRa1:
|
case TxLoRa1:
|
||||||
if (LORA1Buffer.len == 0)
|
if (LORA1Buffer.len - tx_buffer_position > lora_size) {
|
||||||
{
|
|
||||||
TxStatus = TxLoRa2;
|
|
||||||
goto TxL2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (LORA1Buffer.len - tx_buffer_position > lora_size)
|
|
||||||
{
|
|
||||||
transmitLoRa(&LoRa1, &LORA1Buffer.buffer[tx_buffer_position], lora_size);
|
transmitLoRa(&LoRa1, &LORA1Buffer.buffer[tx_buffer_position], lora_size);
|
||||||
tx_buffer_position += lora_size;
|
tx_buffer_position += lora_size;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
transmitLoRa(&LoRa1, &LORA1Buffer.buffer[tx_buffer_position], LORA1Buffer.len - tx_buffer_position);
|
transmitLoRa(&LoRa1, &LORA1Buffer.buffer[tx_buffer_position], LORA1Buffer.len - tx_buffer_position);
|
||||||
tx_buffer_position = 0;
|
tx_buffer_position = 0;
|
||||||
|
if (LORA2Buffer.len > 0) {
|
||||||
TxStatus = TxLoRa2;
|
TxStatus = TxLoRa2;
|
||||||
|
} else if ((LORABBuffer.len > 0)) {
|
||||||
|
TxStatus = TxLoRaB;
|
||||||
|
} else {
|
||||||
|
goto TxFin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TxLoRa2:
|
case TxLoRa2:
|
||||||
TxL2:
|
if (LORA2Buffer.len - tx_buffer_position > lora_size) {
|
||||||
if (LORA2Buffer.len == 0)
|
|
||||||
{
|
|
||||||
TxStatus = TxLoRaB;
|
|
||||||
goto TxLB;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (LORA2Buffer.len - tx_buffer_position > lora_size)
|
|
||||||
{
|
|
||||||
transmitLoRa(&LoRa2, &LORA2Buffer.buffer[tx_buffer_position], lora_size);
|
transmitLoRa(&LoRa2, &LORA2Buffer.buffer[tx_buffer_position], lora_size);
|
||||||
tx_buffer_position += lora_size;
|
tx_buffer_position += lora_size;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
transmitLoRa(&LoRa2, &LORA2Buffer.buffer[tx_buffer_position], LORA2Buffer.len - tx_buffer_position);
|
transmitLoRa(&LoRa2, &LORA2Buffer.buffer[tx_buffer_position], LORA2Buffer.len - tx_buffer_position);
|
||||||
tx_buffer_position = 0;
|
tx_buffer_position = 0;
|
||||||
|
if (LORABBuffer.len > 0) {
|
||||||
TxStatus = TxLoRaB;
|
TxStatus = TxLoRaB;
|
||||||
|
} else {
|
||||||
|
goto TxFin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TxLoRaB:
|
case TxLoRaB:
|
||||||
TxLB:
|
if (LORABBuffer.len - tx_buffer_position > lora_size) {
|
||||||
// DBG(LORABBuffer.len);
|
|
||||||
if (LORABBuffer.len == 0)
|
|
||||||
{
|
|
||||||
TxStatus = TxIdle;
|
|
||||||
goto TxFin;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (LORABBuffer.len - tx_buffer_position > lora_size)
|
|
||||||
{
|
|
||||||
transmitLoRa(&loraBroadcast, &LORABBuffer.buffer[tx_buffer_position], lora_size);
|
transmitLoRa(&loraBroadcast, &LORABBuffer.buffer[tx_buffer_position], lora_size);
|
||||||
tx_buffer_position += lora_size;
|
tx_buffer_position += lora_size;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
transmitLoRa(&loraBroadcast, &LORABBuffer.buffer[tx_buffer_position], LORABBuffer.len - tx_buffer_position);
|
transmitLoRa(&loraBroadcast, &LORABBuffer.buffer[tx_buffer_position], LORABBuffer.len - tx_buffer_position);
|
||||||
TxFin:
|
TxFin:
|
||||||
if (LORABBuffer.len + LORA1Buffer.len +LORA2Buffer.len > 0)
|
if (LORABBuffer.len + LORA1Buffer.len + LORA2Buffer.len > 0) {
|
||||||
//radio.startReceive();
|
|
||||||
LORABBuffer.len = 0;
|
LORABBuffer.len = 0;
|
||||||
LORA1Buffer.len = 0;
|
LORA1Buffer.len = 0;
|
||||||
LORA2Buffer.len = 0;
|
LORA2Buffer.len = 0;
|
||||||
@ -592,9 +576,9 @@ void asyncReleaseLoRa(bool first_run)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void asyncReleaseLoRaFirst()
|
void asyncReleaseLoRaFirst()
|
||||||
{
|
{
|
||||||
asyncReleaseLoRa(true);
|
asyncReleaseLoRa(true);
|
||||||
@ -605,6 +589,10 @@ crcResult handleLoRa()
|
|||||||
crcResult crcReturned = CRC_NULL;
|
crcResult crcReturned = CRC_NULL;
|
||||||
if (operationDone) // the interrupt was triggered
|
if (operationDone) // the interrupt was triggered
|
||||||
{
|
{
|
||||||
|
// DBG("Interrupt triggered");
|
||||||
|
// DBG("TxFlag: " + String(transmitFlag));
|
||||||
|
// DBG("TxStatus: " + String(TxStatus));
|
||||||
|
|
||||||
enableInterrupt = false;
|
enableInterrupt = false;
|
||||||
operationDone = false;
|
operationDone = false;
|
||||||
if (transmitFlag) // the previous operation was transmission
|
if (transmitFlag) // the previous operation was transmission
|
||||||
|
Loading…
Reference in New Issue
Block a user