Update main.cpp
Cosmetics and actually using MCU deepsleep (sigh)
This commit is contained in:
parent
b3d53e3191
commit
720e0edf8e
33
src/main.cpp
33
src/main.cpp
|
@ -26,14 +26,19 @@ void setup() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearInterrupts(void) {
|
||||||
|
radio.clearDio1Action();
|
||||||
|
radio.finishTransmit();
|
||||||
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (PacketReceived) {
|
if (PacketReceived) {
|
||||||
PacketReceived = false;
|
PacketReceived = false;
|
||||||
size_t length = radio.getPacketLength();
|
const size_t length = radio.getPacketLength();
|
||||||
state = radio.readData(radiobuf, length);
|
state = radio.readData(radiobuf, length);
|
||||||
MSG("[RX]");
|
MSG("[RX]");
|
||||||
if (state == RADIOLIB_ERR_NONE) {
|
if (state == RADIOLIB_ERR_NONE) {
|
||||||
int32_t payloadLen = length - sizeof(PacketHeader);
|
const int32_t payloadLen = length - sizeof(PacketHeader);
|
||||||
if (payloadLen < 0) {
|
if (payloadLen < 0) {
|
||||||
MSG("\n[WARN]Not a Meshtastic packet, too short!\n");
|
MSG("\n[WARN]Not a Meshtastic packet, too short!\n");
|
||||||
return; // will not repeat
|
return; // will not repeat
|
||||||
|
@ -51,15 +56,12 @@ void loop() {
|
||||||
MSG(" re-send=%s\n", ( (lastPacketID != h->id) && (hop_limit!=0) )?"YES":"NO");
|
MSG(" re-send=%s\n", ( (lastPacketID != h->id) && (hop_limit!=0) )?"YES":"NO");
|
||||||
|
|
||||||
if ( (lastPacketID != h->id) && (hop_limit!=0) ) {
|
if ( (lastPacketID != h->id) && (hop_limit!=0) ) {
|
||||||
h->flags -= 1;
|
h->flags -= 1; // decrease HopLim by 1
|
||||||
//do not send into other transmits
|
clearInterrupts();
|
||||||
radio.clearDio1Action();
|
|
||||||
radio.finishTransmit();
|
|
||||||
while ( radio.scanChannel() == RADIOLIB_LORA_DETECTED ) delay(100);
|
while ( radio.scanChannel() == RADIOLIB_LORA_DETECTED ) delay(100);
|
||||||
MSG("[TX] (id=0x%08X) HopLim=%i ... ", h->id, (h->flags & PACKET_FLAGS_HOP_MASK));
|
MSG("[TX] (id=0x%08X) HopLim=%i ... ", h->id, (h->flags & PACKET_FLAGS_HOP_MASK));
|
||||||
lastPacketID = h->id;
|
lastPacketID = h->id;
|
||||||
radio.clearDio1Action();
|
clearInterrupts();
|
||||||
radio.finishTransmit();
|
|
||||||
radio.setPacketSentAction(ISR_setPacketSent);
|
radio.setPacketSentAction(ISR_setPacketSent);
|
||||||
state=radio.startTransmit((uint8_t*)&radiobuf, length);
|
state=radio.startTransmit((uint8_t*)&radiobuf, length);
|
||||||
if (state == RADIOLIB_ERR_NONE) {
|
if (state == RADIOLIB_ERR_NONE) {
|
||||||
|
@ -67,29 +69,29 @@ void loop() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MSG("failed, ERR = %i - resume RX", state);
|
MSG("failed, ERR = %i - resume RX", state);
|
||||||
radio.clearDio1Action();
|
clearInterrupts();
|
||||||
radio.finishTransmit();
|
|
||||||
radio.setPacketReceivedAction(ISR_setReceived);
|
radio.setPacketReceivedAction(ISR_setReceived);
|
||||||
radio.startReceive();
|
radio.startReceive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
|
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
|
||||||
MSG("\n[ERROR]CRC error!\n");
|
MSG(" [ERROR]CRC error!\n");
|
||||||
} else {
|
} else {
|
||||||
MSG("[ERROR]Receive failed, code: %i!\n", state);
|
MSG(" [ERROR]Receive failed, code: %i!\n", state);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PacketSent) {
|
if (PacketSent) {
|
||||||
PacketSent = false;
|
PacketSent = false;
|
||||||
radio.clearDio1Action();
|
clearInterrupts();
|
||||||
radio.finishTransmit();
|
|
||||||
radio.setPacketReceivedAction(ISR_setReceived);
|
radio.setPacketReceivedAction(ISR_setReceived);
|
||||||
radio.startReceive();
|
radio.startReceive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delay(100); // wait for Serial
|
||||||
|
MCU_deepsleep();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCU_deepsleep(void) {
|
void MCU_deepsleep(void) {
|
||||||
|
@ -107,5 +109,4 @@ void MCU_deepsleep(void) {
|
||||||
#endif
|
#endif
|
||||||
#endif //CUBECELL
|
#endif //CUBECELL
|
||||||
|
|
||||||
//No rest for the wicked.
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue