diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index c0610b7f8a..465f920ee9 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -1,9 +1,5 @@ #include "Dispatcher.h" -#if MESH_PACKET_LOGGING - #include -#endif - #include namespace mesh { @@ -218,21 +214,22 @@ void Dispatcher::checkRecv() { } if (pkt) { #if MESH_PACKET_LOGGING - Serial.print(getLogDateTime()); - Serial.printf(": RX, len=%d (type=%d, route=%s, payload_len=%d) SNR=%d RSSI=%d score=%d time=%d", + MESHCORE_LOG_PRINTF("%s", getLogDateTime()); + MESHCORE_LOG_PRINTF(": RX, len=%d (type=%d, route=%s, payload_len=%d) SNR=%d RSSI=%d score=%d time=%d", pkt->getRawLength(), pkt->getPayloadType(), pkt->isRouteDirect() ? "D" : "F", pkt->payload_len, (int)pkt->getSNR(), (int)_radio->getLastRSSI(), (int)(score*1000), air_time); static uint8_t packet_hash[MAX_HASH_SIZE]; pkt->calculatePacketHash(packet_hash); - Serial.print(" hash="); - mesh::Utils::printHex(Serial, packet_hash, MAX_HASH_SIZE); + char hash_hex[MAX_HASH_SIZE*2 + 1]; + mesh::Utils::toHex(hash_hex, packet_hash, MAX_HASH_SIZE); + MESHCORE_LOG_PRINTF(" hash=%s", hash_hex); 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]\n", (uint32_t)pkt->payload[1], (uint32_t)pkt->payload[0]); + MESHCORE_LOG_PRINTF(" [%02X -> %02X]\n", (uint32_t)pkt->payload[1], (uint32_t)pkt->payload[0]); } else { - Serial.printf("\n"); + MESHCORE_LOG_PRINTF("\n"); } #endif logRx(pkt, pkt->getRawLength(), score); // hook for custom logging @@ -339,14 +336,14 @@ void Dispatcher::checkSend() { outbound_expiry = futureMillis(max_airtime); #if MESH_PACKET_LOGGING - Serial.print(getLogDateTime()); - Serial.printf(": TX, len=%d (type=%d, route=%s, payload_len=%d)", + MESHCORE_LOG_PRINTF("%s", getLogDateTime()); + MESHCORE_LOG_PRINTF(": TX, len=%d (type=%d, route=%s, payload_len=%d)", len, outbound->getPayloadType(), outbound->isRouteDirect() ? "D" : "F", outbound->payload_len); if (outbound->getPayloadType() == PAYLOAD_TYPE_PATH || outbound->getPayloadType() == PAYLOAD_TYPE_REQ || outbound->getPayloadType() == PAYLOAD_TYPE_RESPONSE || outbound->getPayloadType() == PAYLOAD_TYPE_TXT_MSG) { - Serial.printf(" [%02X -> %02X]\n", (uint32_t)outbound->payload[1], (uint32_t)outbound->payload[0]); + MESHCORE_LOG_PRINTF(" [%02X -> %02X]\n", (uint32_t)outbound->payload[1], (uint32_t)outbound->payload[0]); } else { - Serial.printf("\n"); + MESHCORE_LOG_PRINTF("\n"); } #endif } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index c11f37cacf..cc94e0689d 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -1,5 +1,4 @@ #include "Mesh.h" -//#include namespace mesh { diff --git a/src/MeshCore.h b/src/MeshCore.h index e67371ef17..01ea8f864c 100644 --- a/src/MeshCore.h +++ b/src/MeshCore.h @@ -22,17 +22,28 @@ #define MAX_PATH_SIZE 64 #define MAX_TRANS_UNIT 255 -#if MESH_DEBUG && ARDUINO - #include - #define MESH_DEBUG_PRINT(F, ...) Serial.printf("DEBUG: " F, ##__VA_ARGS__) - #define MESH_DEBUG_PRINTLN(F, ...) Serial.printf("DEBUG: " F "\n", ##__VA_ARGS__) +// Single seam for all of MeshCore's diagnostic output. Platform ports define +// MESHCORE_LOG_PRINTF to whatever their console is; on Arduino it is Serial. +#ifndef MESHCORE_LOG_PRINTF + #ifdef ARDUINO + #include + #define MESHCORE_LOG_PRINTF(F, ...) Serial.printf(F, ##__VA_ARGS__) + #else + #include + #define MESHCORE_LOG_PRINTF(F, ...) printf(F, ##__VA_ARGS__) + #endif +#endif + +#if MESH_DEBUG + #define MESH_DEBUG_PRINT(F, ...) MESHCORE_LOG_PRINTF("DEBUG: " F, ##__VA_ARGS__) + #define MESH_DEBUG_PRINTLN(F, ...) MESHCORE_LOG_PRINTF("DEBUG: " F "\n", ##__VA_ARGS__) #else #define MESH_DEBUG_PRINT(...) {} #define MESH_DEBUG_PRINTLN(...) {} #endif -#if BRIDGE_DEBUG && ARDUINO -#define BRIDGE_DEBUG_PRINTLN(F, ...) Serial.printf("%s BRIDGE: " F, getLogDateTime(), ##__VA_ARGS__) +#if BRIDGE_DEBUG +#define BRIDGE_DEBUG_PRINTLN(F, ...) MESHCORE_LOG_PRINTF("%s BRIDGE: " F, getLogDateTime(), ##__VA_ARGS__) #else #define BRIDGE_DEBUG_PRINTLN(...) {} #endif diff --git a/src/Utils.cpp b/src/Utils.cpp index 5ae7f0e27e..4aa35623bc 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -9,9 +9,6 @@ #include "nrf_cc310/include/ssi_aes.h" #endif -#ifdef ARDUINO - #include -#endif namespace mesh { diff --git a/src/helpers/AdvertDataHelpers.cpp b/src/helpers/AdvertDataHelpers.cpp index 998733ae04..68765d3660 100644 --- a/src/helpers/AdvertDataHelpers.cpp +++ b/src/helpers/AdvertDataHelpers.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include @@ -60,7 +62,6 @@ } } -#include void AdvertTimeHelper::formatRelativeTimeDiff(char dest[], int32_t seconds_from_now, bool short_fmt) { const char *suffix; diff --git a/src/helpers/AutoDiscoverRTCClock.h b/src/helpers/AutoDiscoverRTCClock.h index 11364cd811..246df3bc2b 100644 --- a/src/helpers/AutoDiscoverRTCClock.h +++ b/src/helpers/AutoDiscoverRTCClock.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include class AutoDiscoverRTCClock : public mesh::RTCClock { diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index 972a97e9e6..d71534ff34 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/src/helpers/BaseChatMesh.h b/src/helpers/BaseChatMesh.h index d987854709..2f2fdea57e 100644 --- a/src/helpers/BaseChatMesh.h +++ b/src/helpers/BaseChatMesh.h @@ -1,6 +1,8 @@ #pragma once -#include // needed for PlatformIO +#include +#include +#include #include #include #include diff --git a/src/helpers/BaseSerialInterface.h b/src/helpers/BaseSerialInterface.h index 23933fcb4b..5f4af65ea7 100644 --- a/src/helpers/BaseSerialInterface.h +++ b/src/helpers/BaseSerialInterface.h @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include #define MAX_FRAME_SIZE 176 // +4 for transport codes (region scoping) diff --git a/src/helpers/ChannelDetails.h b/src/helpers/ChannelDetails.h index b9d38d4fc7..78bd996e17 100644 --- a/src/helpers/ChannelDetails.h +++ b/src/helpers/ChannelDetails.h @@ -1,6 +1,5 @@ #pragma once -#include #include struct ChannelDetails { diff --git a/src/helpers/ClientACL.h b/src/helpers/ClientACL.h index b758f7068d..3c153d4064 100644 --- a/src/helpers/ClientACL.h +++ b/src/helpers/ClientACL.h @@ -1,6 +1,7 @@ #pragma once -#include // needed for PlatformIO +#include +#include #include #include diff --git a/src/helpers/ContactInfo.h b/src/helpers/ContactInfo.h index ede977cace..2063686d61 100644 --- a/src/helpers/ContactInfo.h +++ b/src/helpers/ContactInfo.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #define OUT_PATH_UNKNOWN 0xFF diff --git a/src/helpers/MeshadventurerBoard.h b/src/helpers/MeshadventurerBoard.h index 0325161d5d..cd29edebae 100644 --- a/src/helpers/MeshadventurerBoard.h +++ b/src/helpers/MeshadventurerBoard.h @@ -1,6 +1,6 @@ #pragma once -#include +#include // LoRa radio module pins for Meshadventurer #define P_LORA_DIO_1 33 diff --git a/src/helpers/NRF52Board.h b/src/helpers/NRF52Board.h index dba15f974e..ca29bad405 100644 --- a/src/helpers/NRF52Board.h +++ b/src/helpers/NRF52Board.h @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include #include #if defined(NRF52_PLATFORM) diff --git a/src/helpers/RTC_RX8130CE.h b/src/helpers/RTC_RX8130CE.h index 1cf148a9fe..0b9c6dfb7a 100644 --- a/src/helpers/RTC_RX8130CE.h +++ b/src/helpers/RTC_RX8130CE.h @@ -1,7 +1,8 @@ #ifndef __RTC_RX8130CE_H__ #define __RTC_RX8130CE_H__ -#include +#include +#include #include #include #include "RTClib.h" diff --git a/src/helpers/TransportKeyStore.h b/src/helpers/TransportKeyStore.h index e3ba152434..9cdeeb782a 100644 --- a/src/helpers/TransportKeyStore.h +++ b/src/helpers/TransportKeyStore.h @@ -1,6 +1,6 @@ #pragma once -#include // needed for PlatformIO +#include #include #include diff --git a/src/helpers/TxtDataHelpers.cpp b/src/helpers/TxtDataHelpers.cpp index d327931fde..92c4fd964e 100644 --- a/src/helpers/TxtDataHelpers.cpp +++ b/src/helpers/TxtDataHelpers.cpp @@ -26,7 +26,9 @@ bool StrHelper::isBlank(const char* str) { return true; } -#include +#include +#include +#include union int32_Float_t { @@ -102,7 +104,7 @@ static void _ftoa(float f, char *p, int *status) *p++ = '0'; else { - ltoa(int_part, p, 10); + snprintf(p, 12, "%ld", (long)int_part); while (*p) p++; } diff --git a/src/helpers/nrf52/EthernetMac.h b/src/helpers/nrf52/EthernetMac.h index 0ee2ac06f5..ca4517a439 100644 --- a/src/helpers/nrf52/EthernetMac.h +++ b/src/helpers/nrf52/EthernetMac.h @@ -1,6 +1,6 @@ #pragma once -#include +#include static inline void generateEthernetMac(uint8_t mac[6]) { uint32_t device_id = NRF_FICR->DEVICEID[0]; diff --git a/src/helpers/stm32/InternalFileSystem.cpp b/src/helpers/stm32/InternalFileSystem.cpp index 6a7d7064ed..81aaec9228 100644 --- a/src/helpers/stm32/InternalFileSystem.cpp +++ b/src/helpers/stm32/InternalFileSystem.cpp @@ -22,7 +22,8 @@ * THE SOFTWARE. */ -#include +#include +#include #include "InternalFileSystem.h" //--------------------------------------------------------------------+ diff --git a/src/helpers/ui/DRV2605Vibration.h b/src/helpers/ui/DRV2605Vibration.h index a40894be11..1c1268d0d9 100644 --- a/src/helpers/ui/DRV2605Vibration.h +++ b/src/helpers/ui/DRV2605Vibration.h @@ -2,7 +2,6 @@ #ifdef HAS_DRV2605 -#include #include /* diff --git a/src/helpers/ui/GenericVibration.h b/src/helpers/ui/GenericVibration.h index 38755bd8d9..86539c0dda 100644 --- a/src/helpers/ui/GenericVibration.h +++ b/src/helpers/ui/GenericVibration.h @@ -2,7 +2,6 @@ #ifdef PIN_VIBRATION -#include /* * Vibration motor control class diff --git a/src/helpers/ui/MomentaryButton.h b/src/helpers/ui/MomentaryButton.h index 358a343b0f..b2468adc65 100644 --- a/src/helpers/ui/MomentaryButton.h +++ b/src/helpers/ui/MomentaryButton.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #define BUTTON_EVENT_NONE 0 #define BUTTON_EVENT_CLICK 1 diff --git a/src/helpers/ui/RotaryInput.h b/src/helpers/ui/RotaryInput.h index 2dda695be1..1ce589703a 100644 --- a/src/helpers/ui/RotaryInput.h +++ b/src/helpers/ui/RotaryInput.h @@ -1,6 +1,6 @@ #pragma once -#include +#include enum class RotaryInputEvent : uint8_t { None,