mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Refactor debug logging across bridge implementations
This commit is contained in:
parent
9b4d93d112
commit
fb46e5cc8a
7 changed files with 48 additions and 70 deletions
|
|
@ -8,7 +8,7 @@ RS232Bridge::RS232Bridge(NodePrefs *prefs, Stream &serial, mesh::PacketManager *
|
|||
: BridgeBase(prefs, mgr, rtc), _serial(&serial) {}
|
||||
|
||||
void RS232Bridge::begin() {
|
||||
Serial.printf("%s: RS232 BRIDGE: Initializing at %d baud...\n", getLogDateTime(), _prefs->bridge_baud);
|
||||
BRIDGE_DEBUG_PRINTLN("Initializing at %d baud...\n", _prefs->bridge_baud);
|
||||
#if !defined(WITH_RS232_BRIDGE_RX) || !defined(WITH_RS232_BRIDGE_TX)
|
||||
#error "WITH_RS232_BRIDGE_RX and WITH_RS232_BRIDGE_TX must be defined"
|
||||
#endif
|
||||
|
|
@ -33,7 +33,7 @@ void RS232Bridge::begin() {
|
|||
}
|
||||
|
||||
void RS232Bridge::end() {
|
||||
Serial.printf("%s: RS232 BRIDGE: Stopping...\n", getLogDateTime());
|
||||
BRIDGE_DEBUG_PRINTLN("Stopping...\n");
|
||||
((HardwareSerial *)_serial)->end();
|
||||
|
||||
// Update bridge state
|
||||
|
|
@ -71,9 +71,7 @@ void RS232Bridge::loop() {
|
|||
|
||||
// Validate length field
|
||||
if (len > (MAX_TRANS_UNIT + 1)) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: RX invalid length %d, resetting\n", getLogDateTime(), len);
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("RX invalid length %d, resetting\n", len);
|
||||
_rx_buffer_pos = 0; // Invalid length, reset
|
||||
continue;
|
||||
}
|
||||
|
|
@ -82,30 +80,20 @@ void RS232Bridge::loop() {
|
|||
uint16_t received_checksum = (_rx_buffer[4 + len] << 8) | _rx_buffer[5 + len];
|
||||
|
||||
if (validateChecksum(_rx_buffer + 4, len, received_checksum)) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: RX, len=%d crc=0x%04x\n", getLogDateTime(), len,
|
||||
received_checksum);
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("RX, len=%d crc=0x%04x\n", len, received_checksum);
|
||||
mesh::Packet *pkt = _mgr->allocNew();
|
||||
if (pkt) {
|
||||
if (pkt->readFrom(_rx_buffer + 4, len)) {
|
||||
onPacketReceived(pkt);
|
||||
} else {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: RX failed to parse packet\n", getLogDateTime());
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("RX failed to parse packet\n");
|
||||
_mgr->free(pkt);
|
||||
}
|
||||
} else {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: RX failed to allocate packet\n", getLogDateTime());
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("RX failed to allocate packet\n");
|
||||
}
|
||||
} else {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: RX checksum mismatch, rcv=0x%04x\n", getLogDateTime(),
|
||||
received_checksum);
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("RX checksum mismatch, rcv=0x%04x\n", received_checksum);
|
||||
}
|
||||
_rx_buffer_pos = 0; // Reset for next packet
|
||||
}
|
||||
|
|
@ -122,9 +110,7 @@ void RS232Bridge::sendPacket(mesh::Packet *packet) {
|
|||
|
||||
// First validate the packet pointer
|
||||
if (!packet) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: TX invalid packet pointer\n", getLogDateTime());
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("TX invalid packet pointer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -135,10 +121,8 @@ void RS232Bridge::sendPacket(mesh::Packet *packet) {
|
|||
|
||||
// Check if packet fits within our maximum payload size
|
||||
if (len > (MAX_TRANS_UNIT + 1)) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: TX packet too large (payload=%d, max=%d)\n", getLogDateTime(), len,
|
||||
MAX_TRANS_UNIT + 1);
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("TX packet too large (payload=%d, max=%d)\n", len,
|
||||
MAX_TRANS_UNIT + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -156,9 +140,7 @@ void RS232Bridge::sendPacket(mesh::Packet *packet) {
|
|||
// Send complete packet
|
||||
_serial->write(buffer, len + SERIAL_OVERHEAD);
|
||||
|
||||
#if MESH_PACKET_LOGGING
|
||||
Serial.printf("%s: RS232 BRIDGE: TX, len=%d crc=0x%04x\n", getLogDateTime(), len, checksum);
|
||||
#endif
|
||||
BRIDGE_DEBUG_PRINTLN("TX, len=%d crc=0x%04x\n", len, checksum);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue