Serial bridge implementation
This commit is contained in:
+20
-4
@@ -1,7 +1,7 @@
|
||||
#include "Dispatcher.h"
|
||||
|
||||
#if MESH_PACKET_LOGGING
|
||||
#include <Arduino.h>
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
@@ -104,6 +104,7 @@ void Dispatcher::loop() {
|
||||
processRecvPacket(pkt);
|
||||
}
|
||||
}
|
||||
|
||||
checkRecv();
|
||||
checkSend();
|
||||
}
|
||||
@@ -115,6 +116,18 @@ void Dispatcher::checkRecv() {
|
||||
{
|
||||
uint8_t raw[MAX_TRANS_UNIT+1];
|
||||
int len = _radio->recvRaw(raw, MAX_TRANS_UNIT);
|
||||
|
||||
#ifdef BRIDGE_OVER_SERIAL
|
||||
// We are basically stamping metadata from the last RF packet into something that came from serial,
|
||||
// it works for now. But long term the code on checkRecv() should be refactored to be able to deal
|
||||
// with both use cases without dupeing the existing code. I've chosen [for now] not to dupe and just
|
||||
// fake the metadata.
|
||||
|
||||
if (len == 0) {
|
||||
len = bridge_interface->getPacket(raw);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (len > 0) {
|
||||
logRxRaw(_radio->getLastSNR(), _radio->getLastRSSI(), raw, len);
|
||||
|
||||
@@ -280,7 +293,11 @@ void Dispatcher::checkSend() {
|
||||
}
|
||||
outbound_expiry = futureMillis(max_airtime);
|
||||
|
||||
#if MESH_PACKET_LOGGING
|
||||
#ifdef BRIDGE_OVER_SERIAL
|
||||
bridge_interface->sendPacket(outbound);
|
||||
#endif
|
||||
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.print(getLogDateTime());
|
||||
Serial.printf(": TX, len=%d (type=%d, route=%s, payload_len=%d)",
|
||||
len, outbound->getPayloadType(), outbound->isRouteDirect() ? "D" : "F", outbound->payload_len);
|
||||
@@ -290,7 +307,7 @@ void Dispatcher::checkSend() {
|
||||
} else {
|
||||
Serial.printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,5 +345,4 @@ bool Dispatcher::millisHasNowPassed(unsigned long timestamp) const {
|
||||
unsigned long Dispatcher::futureMillis(int millis_from_now) const {
|
||||
return _ms->getMillis() + millis_from_now;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user