@ -463,6 +463,14 @@ const char *MyMesh::getLogDateTime() {
return tmp ;
}
namespace {
const char * packetLogTypeLabel ( const mesh : : Packet * pkt ) {
static char label [ 40 ] ;
mesh : : formatPayloadType ( pkt - > getPayloadType ( ) , label , sizeof label ) ;
return label ;
}
}
void MyMesh : : logRxRaw ( float snr , float rssi , const uint8_t raw [ ] , int len ) {
# if MESH_PACKET_LOGGING
Serial . print ( getLogDateTime ( ) ) ;
@ -472,6 +480,38 @@ void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
# endif
}
void MyMesh : : mirrorPacketLogRxToSerial ( mesh : : Packet * pkt , int len , float score ) {
Serial . print ( getLogDateTime ( ) ) ;
Serial . printf ( " : RX, len=%d (type=%s, route=%s, payload_len=%d) SNR=%d RSSI=%d score=%d " , len ,
packetLogTypeLabel ( pkt ) , pkt - > isRouteDirect ( ) ? " D " : " F " , pkt - > payload_len ,
( int ) _radio - > getLastSNR ( ) , ( int ) _radio - > getLastRSSI ( ) , ( int ) ( score * 1000 ) ) ;
if ( pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_PATH | | pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_REQ | |
pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_RESPONSE | | pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_TXT_MSG ) {
Serial . printf ( " [%02X -> %02X] " , ( uint32_t ) pkt - > payload [ 1 ] , ( uint32_t ) pkt - > payload [ 0 ] ) ;
}
Serial . print ( " \r \n " ) ;
}
void MyMesh : : mirrorPacketLogTxToSerial ( mesh : : Packet * pkt , int len ) {
Serial . print ( getLogDateTime ( ) ) ;
Serial . printf ( " : TX, len=%d (type=%s, route=%s, payload_len=%d) " , len , packetLogTypeLabel ( pkt ) ,
pkt - > isRouteDirect ( ) ? " D " : " F " , pkt - > payload_len ) ;
if ( pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_PATH | | pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_REQ | |
pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_RESPONSE | | pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_TXT_MSG ) {
Serial . printf ( " [%02X -> %02X] " , ( uint32_t ) pkt - > payload [ 1 ] , ( uint32_t ) pkt - > payload [ 0 ] ) ;
}
Serial . print ( " \r \n " ) ;
}
void MyMesh : : mirrorPacketLogTxFailToSerial ( mesh : : Packet * pkt , int len ) {
Serial . print ( getLogDateTime ( ) ) ;
Serial . printf ( " : TX FAIL!, len=%d (type=%s, route=%s, payload_len=%d) " , len , packetLogTypeLabel ( pkt ) ,
pkt - > isRouteDirect ( ) ? " D " : " F " , pkt - > payload_len ) ;
Serial . print ( " \r \n " ) ;
}
void MyMesh : : logRx ( mesh : : Packet * pkt , int len , float score ) {
# ifdef WITH_BRIDGE
if ( _prefs . bridge_pkt_src = = 1 ) {
@ -483,8 +523,8 @@ void MyMesh::logRx(mesh::Packet *pkt, int len, float score) {
File f = openAppend ( PACKET_LOG_FILE ) ;
if ( f ) {
f . print ( getLogDateTime ( ) ) ;
f . printf ( " : RX, len=%d (type=%d , route=%s, payload_len=%d) SNR=%d RSSI=%d score=%d " , len ,
pkt - > getPayloadType ( ) , pkt - > isRouteDirect ( ) ? " D " : " F " , pkt - > payload_len ,
f . printf ( " : RX, len=%d (type=%s , route=%s, payload_len=%d) SNR=%d RSSI=%d score=%d " , len ,
packetLogTypeLabel ( pkt ) , pkt - > isRouteDirect ( ) ? " D " : " F " , pkt - > payload_len ,
( int ) _radio - > getLastSNR ( ) , ( int ) _radio - > getLastRSSI ( ) , ( int ) ( score * 1000 ) ) ;
if ( pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_PATH | | pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_REQ | |
@ -496,6 +536,9 @@ void MyMesh::logRx(mesh::Packet *pkt, int len, float score) {
f . close ( ) ;
}
}
if ( _logging & & _tailing ) {
mirrorPacketLogRxToSerial ( pkt , len , score ) ;
}
}
void MyMesh : : logTx ( mesh : : Packet * pkt , int len ) {
@ -509,7 +552,7 @@ void MyMesh::logTx(mesh::Packet *pkt, int len) {
File f = openAppend ( PACKET_LOG_FILE ) ;
if ( f ) {
f . print ( getLogDateTime ( ) ) ;
f . printf ( " : TX, len=%d (type=%d , route=%s, payload_len=%d) " , len , pkt - > getPayloadType ( ) ,
f . printf ( " : TX, len=%d (type=%s , route=%s, payload_len=%d) " , len , packetLogTypeLabel ( pkt ) ,
pkt - > isRouteDirect ( ) ? " D " : " F " , pkt - > payload_len ) ;
if ( pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_PATH | | pkt - > getPayloadType ( ) = = PAYLOAD_TYPE_REQ | |
@ -521,6 +564,9 @@ void MyMesh::logTx(mesh::Packet *pkt, int len) {
f . close ( ) ;
}
}
if ( _logging & & _tailing ) {
mirrorPacketLogTxToSerial ( pkt , len ) ;
}
}
void MyMesh : : logTxFail ( mesh : : Packet * pkt , int len ) {
@ -528,11 +574,14 @@ void MyMesh::logTxFail(mesh::Packet *pkt, int len) {
File f = openAppend ( PACKET_LOG_FILE ) ;
if ( f ) {
f . print ( getLogDateTime ( ) ) ;
f . printf ( " : TX FAIL!, len=%d (type=%d , route=%s, payload_len=%d) \n " , len , pkt - > getPayloadType ( ) ,
f . printf ( " : TX FAIL!, len=%d (type=%s , route=%s, payload_len=%d) \n " , len , packetLogTypeLabel ( pkt ) ,
pkt - > isRouteDirect ( ) ? " D " : " F " , pkt - > payload_len ) ;
f . close ( ) ;
}
}
if ( _logging & & _tailing ) {
mirrorPacketLogTxFailToSerial ( pkt , len ) ;
}
}
int MyMesh : : calcRxDelay ( float score , uint32_t air_time ) const {
@ -864,6 +913,7 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
dirty_contacts_expiry = 0 ;
set_radio_at = revert_radio_at = 0 ;
_logging = false ;
_tailing = false ;
region_load_active = false ;
recv_pkt_region = NULL ;