From b3210f6c2cccc6477a232d4107af5112167f9f79 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 24 Jan 2022 07:00:14 +0000 Subject: [PATCH 1/6] fix some cppcheck warnings --- .gitignore | 2 ++ bin/check-all.sh | 18 ++++++++++++++++++ src/Power.cpp | 5 ++++- src/airtime.cpp | 8 +++++--- src/airtime.h | 6 +++--- src/esp32/SimpleAllocator.h | 4 ++-- src/gps/GeoCoord.cpp | 2 +- src/gps/GeoCoord.h | 10 +++++----- src/graphics/Screen.cpp | 12 ++++++------ src/input/RotaryEncoderInterruptBase.h | 12 ++++++------ src/mesh/CryptoEngine.h | 4 ++-- src/mesh/PhoneAPI.h | 4 ++-- src/mesh/RF95Interface.h | 4 ++-- src/mesh/RadioLibInterface.h | 4 ++-- src/mesh/StreamAPI.h | 6 +++--- src/plugins/EnvironmentalMeasurementPlugin.h | 8 ++++---- src/plugins/esp32/RangeTestPlugin.h | 2 +- src/plugins/esp32/SerialPlugin.h | 2 +- src/plugins/esp32/StoreForwardPlugin.cpp | 2 +- suppressions.txt | 12 ++++++++++++ 20 files changed, 82 insertions(+), 45 deletions(-) create mode 100755 bin/check-all.sh create mode 100644 suppressions.txt diff --git a/.gitignore b/.gitignore index 3d181a39a..d63accc92 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ __pycache__ *.swp *.swo *~ + +venv/ diff --git a/bin/check-all.sh b/bin/check-all.sh new file mode 100755 index 000000000..f7fd445d0 --- /dev/null +++ b/bin/check-all.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Note: This is a prototype for how we could add static code analysis to the CI. + +set -e + +VERSION=`bin/buildinfo.py long` + +# The shell vars the build tool expects to find +export APP_VERSION=$VERSION + +# only check high and medium in our source +# TODO: only doing tbeam (to start; add all/more later) +pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" -e tbeam --skip-packages --severity=medium --severity=high --pattern="src/" +return_code=$? + +# TODO: not sure why return_code is 0 +echo "return_code:${return_code}" diff --git a/src/Power.cpp b/src/Power.cpp index 4d2eca29d..b46153c6e 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -149,7 +149,10 @@ class AnalogBatteryLevel : public HasBatteryLevel AnalogBatteryLevel analogLevel; -Power::Power() : OSThread("Power") {} +Power::Power() : OSThread("Power") { + statusHandler = {}; + low_voltage_counter = 0; +} bool Power::analogInit() { diff --git a/src/airtime.cpp b/src/airtime.cpp index d8f0229c9..d497e4dc7 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -2,7 +2,7 @@ #include "NodeDB.h" #include "configuration.h" -AirTime *airTime; +AirTime *airTime = NULL; // Don't read out of this directly. Use the helper functions. @@ -117,7 +117,9 @@ float AirTime::utilizationTXPercent() return (float(sum) / float(MS_IN_HOUR)) * 100; } -AirTime::AirTime() : concurrency::OSThread("AirTime") {} +AirTime::AirTime() : concurrency::OSThread("AirTime") { + airtimes = {}; +} int32_t AirTime::runOnce() { @@ -183,4 +185,4 @@ int32_t AirTime::runOnce() DEBUG_MSG("\n"); */ return (1000 * 1); -} \ No newline at end of file +} diff --git a/src/airtime.h b/src/airtime.h index 8845ec34d..6491e3648 100644 --- a/src/airtime.h +++ b/src/airtime.h @@ -49,8 +49,8 @@ class AirTime : private concurrency::OSThread float utilizationTXPercent(); float UtilizationPercentTX(); - uint32_t channelUtilization[CHANNEL_UTILIZATION_PERIODS]; - uint32_t utilizationTX[MINUTES_IN_HOUR]; + uint32_t channelUtilization[CHANNEL_UTILIZATION_PERIODS] = {0}; + uint32_t utilizationTX[MINUTES_IN_HOUR] = {0}; void airtimeRotatePeriod(); uint8_t getPeriodsToLog(); @@ -79,4 +79,4 @@ class AirTime : private concurrency::OSThread virtual int32_t runOnce() override; }; -extern AirTime *airTime; \ No newline at end of file +extern AirTime *airTime; diff --git a/src/esp32/SimpleAllocator.h b/src/esp32/SimpleAllocator.h index acaab3409..a529c1a50 100644 --- a/src/esp32/SimpleAllocator.h +++ b/src/esp32/SimpleAllocator.h @@ -14,9 +14,9 @@ */ class SimpleAllocator { - uint8_t bytes[POOL_SIZE]; + uint8_t bytes[POOL_SIZE] = {}; - uint32_t nextFree; + uint32_t nextFree = 0; public: SimpleAllocator(); diff --git a/src/gps/GeoCoord.cpp b/src/gps/GeoCoord.cpp index d09b1addb..98f9c842b 100644 --- a/src/gps/GeoCoord.cpp +++ b/src/gps/GeoCoord.cpp @@ -447,4 +447,4 @@ std::shared_ptr GeoCoord::pointAtDistance(double bearing, double range return std::make_shared(double(lat), double(lon), this->getAltitude()); -} \ No newline at end of file +} diff --git a/src/gps/GeoCoord.h b/src/gps/GeoCoord.h index b3d218700..a2ac56d74 100644 --- a/src/gps/GeoCoord.h +++ b/src/gps/GeoCoord.h @@ -86,11 +86,11 @@ class GeoCoord { int32_t _longitude = 0; int32_t _altitude = 0; - DMS _dms; - UTM _utm; - MGRS _mgrs; - OSGR _osgr; - OLC _olc; + DMS _dms = {}; + UTM _utm = {}; + MGRS _mgrs = {}; + OSGR _osgr = {}; + OLC _olc = {}; bool _dirty = true; diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index d18c4ebc8..768c3875e 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -449,10 +449,10 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const if (gpsFormat == GpsCoordinateFormat_GpsFormatDec) { // Decimal Degrees sprintf(coordinateLine, "%f %f", geoCoord.getLatitude() * 1e-7, geoCoord.getLongitude() * 1e-7); } else if (gpsFormat == GpsCoordinateFormat_GpsFormatUTM) { // Universal Transverse Mercator - sprintf(coordinateLine, "%2i%1c %06i %07i", geoCoord.getUTMZone(), geoCoord.getUTMBand(), + sprintf(coordinateLine, "%2i%1c %06u %07u", geoCoord.getUTMZone(), geoCoord.getUTMBand(), geoCoord.getUTMEasting(), geoCoord.getUTMNorthing()); } else if (gpsFormat == GpsCoordinateFormat_GpsFormatMGRS) { // Military Grid Reference System - sprintf(coordinateLine, "%2i%1c %1c%1c %05i %05i", geoCoord.getMGRSZone(), geoCoord.getMGRSBand(), + sprintf(coordinateLine, "%2i%1c %1c%1c %05u %05u", geoCoord.getMGRSZone(), geoCoord.getMGRSBand(), geoCoord.getMGRSEast100k(), geoCoord.getMGRSNorth100k(), geoCoord.getMGRSEasting(), geoCoord.getMGRSNorthing()); } else if (gpsFormat == GpsCoordinateFormat_GpsFormatOLC) { // Open Location Code @@ -461,7 +461,7 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const if (geoCoord.getOSGRE100k() == 'I' || geoCoord.getOSGRN100k() == 'I') // OSGR is only valid around the UK region sprintf(coordinateLine, "%s", "Out of Boundary"); else - sprintf(coordinateLine, "%1c%1c %05i %05i", geoCoord.getOSGRE100k(), geoCoord.getOSGRN100k(), + sprintf(coordinateLine, "%1c%1c %05u %05u", geoCoord.getOSGRE100k(), geoCoord.getOSGRN100k(), geoCoord.getOSGREasting(), geoCoord.getOSGRNorthing()); } @@ -479,9 +479,9 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const } else { char latLine[22]; char lonLine[22]; - sprintf(latLine, "%2i° %2i' %2.4f\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(), + sprintf(latLine, "%2i° %2i' %2u\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(), geoCoord.getDMSLatCP()); - sprintf(lonLine, "%3i° %2i' %2.4f\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(), + sprintf(lonLine, "%3i° %2i' %2u\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(), geoCoord.getDMSLonCP()); display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(latLine))) / 2, y - FONT_HEIGHT_SMALL * 1, latLine); display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(lonLine))) / 2, y, lonLine); @@ -1050,7 +1050,7 @@ void Screen::handleStartBluetoothPinScreen(uint32_t pin) static FrameCallback btFrames[] = {drawFrameBluetooth}; - snprintf(btPIN, sizeof(btPIN), "%06lu", pin); + snprintf(btPIN, sizeof(btPIN), "%06u", pin); ui.disableAllIndicators(); ui.setFrames(btFrames, 1); diff --git a/src/input/RotaryEncoderInterruptBase.h b/src/input/RotaryEncoderInterruptBase.h index ae4af5262..443ba15fc 100644 --- a/src/input/RotaryEncoderInterruptBase.h +++ b/src/input/RotaryEncoderInterruptBase.h @@ -48,10 +48,10 @@ class RotaryEncoderInterruptBase : volatile RotaryEncoderInterruptBaseActionType action = ROTARY_ACTION_NONE; private: - uint8_t _pinA; - uint8_t _pinB; - char _eventCw; - char _eventCcw; - char _eventPressed; + uint8_t _pinA = 0; + uint8_t _pinB = 0; + char _eventCw = InputEventChar_KEY_NONE; + char _eventCcw = InputEventChar_KEY_NONE; + char _eventPressed = InputEventChar_KEY_NONE; const char *_originName; -}; \ No newline at end of file +}; diff --git a/src/mesh/CryptoEngine.h b/src/mesh/CryptoEngine.h index 9853f564a..179f4d139 100644 --- a/src/mesh/CryptoEngine.h +++ b/src/mesh/CryptoEngine.h @@ -20,9 +20,9 @@ class CryptoEngine { protected: /** Our per packet nonce */ - uint8_t nonce[16]; + uint8_t nonce[16] = {0}; - CryptoKey key; + CryptoKey key = {}; public: virtual ~CryptoEngine() {} diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index e818bba56..50ab3592c 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -45,7 +45,7 @@ class PhoneAPI /// We temporarily keep the nodeInfo here between the call to available and getFromRadio const NodeInfo *nodeInfoForPhone = NULL; - ToRadio toRadioScratch; // this is a static scratch object, any data must be copied elsewhere before returning + ToRadio toRadioScratch = {0}; // this is a static scratch object, any data must be copied elsewhere before returning /// Use to ensure that clients don't get confused about old messages from the radio uint32_t config_nonce = 0; @@ -86,7 +86,7 @@ class PhoneAPI protected: /// Our fromradio packet while it is being assembled - FromRadio fromRadioScratch; + FromRadio fromRadioScratch = {}; /** the last msec we heard from the client on the other side of this link */ uint32_t lastContactMsec = 0; diff --git a/src/mesh/RF95Interface.h b/src/mesh/RF95Interface.h index 59930adbd..d072f28e3 100644 --- a/src/mesh/RF95Interface.h +++ b/src/mesh/RF95Interface.h @@ -9,7 +9,7 @@ */ class RF95Interface : public RadioLibInterface { - RadioLibRF95 *lora; // Either a RFM95 or RFM96 depending on what was stuffed on this board + RadioLibRF95 *lora = NULL; // Either a RFM95 or RFM96 depending on what was stuffed on this board public: RF95Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass &spi); @@ -63,4 +63,4 @@ class RF95Interface : public RadioLibInterface private: /** Some boards require GPIO control of tx vs rx paths */ void setTransmitEnable(bool txon); -}; \ No newline at end of file +}; diff --git a/src/mesh/RadioLibInterface.h b/src/mesh/RadioLibInterface.h index 8fe2e2b81..b38d6d553 100644 --- a/src/mesh/RadioLibInterface.h +++ b/src/mesh/RadioLibInterface.h @@ -95,7 +95,7 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified PhysicalLayer *iface; /// are _trying_ to receive a packet currently (note - we might just be waiting for one) - bool isReceiving; + bool isReceiving = false; public: /** Our ISR code currently needs this to find our active instance @@ -183,4 +183,4 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified virtual void addReceiveMetadata(MeshPacket *mp) = 0; virtual void setStandby() = 0; -}; \ No newline at end of file +}; diff --git a/src/mesh/StreamAPI.h b/src/mesh/StreamAPI.h index 58af95b34..ca6cbdf16 100644 --- a/src/mesh/StreamAPI.h +++ b/src/mesh/StreamAPI.h @@ -35,7 +35,7 @@ class StreamAPI : public PhoneAPI, protected concurrency::OSThread */ Stream *stream; - uint8_t rxBuf[MAX_STREAM_BUF_SIZE]; + uint8_t rxBuf[MAX_STREAM_BUF_SIZE] = {0}; size_t rxPtr = 0; /// time of last rx, used, to slow down our polling if we haven't heard from anyone @@ -81,5 +81,5 @@ class StreamAPI : public PhoneAPI, protected concurrency::OSThread bool canWrite = true; /// Subclasses can use this scratch buffer if they wish - uint8_t txBuf[MAX_STREAM_BUF_SIZE]; -}; \ No newline at end of file + uint8_t txBuf[MAX_STREAM_BUF_SIZE] = {0}; +}; diff --git a/src/plugins/EnvironmentalMeasurementPlugin.h b/src/plugins/EnvironmentalMeasurementPlugin.h index 9eed72c8f..14da3b5ba 100644 --- a/src/plugins/EnvironmentalMeasurementPlugin.h +++ b/src/plugins/EnvironmentalMeasurementPlugin.h @@ -35,10 +35,10 @@ class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public Pro private: float CelsiusToFarenheit(float c); bool firstTime = 1; - DHT *dht; - OneWire *oneWire; - DS18B20 *ds18b20; + DHT *dht = NULL; + OneWire *oneWire = NULL; + DS18B20 *ds18b20 = NULL; Adafruit_BME280 bme; const MeshPacket *lastMeasurementPacket; uint32_t sensor_read_error_count = 0; -}; \ No newline at end of file +}; diff --git a/src/plugins/esp32/RangeTestPlugin.h b/src/plugins/esp32/RangeTestPlugin.h index d20a253a0..6b0b93289 100644 --- a/src/plugins/esp32/RangeTestPlugin.h +++ b/src/plugins/esp32/RangeTestPlugin.h @@ -25,7 +25,7 @@ extern RangeTestPlugin *rangeTestPlugin; */ class RangeTestPluginRadio : public SinglePortPlugin { - uint32_t lastRxID; + uint32_t lastRxID = 0; public: RangeTestPluginRadio() : SinglePortPlugin("RangeTestPluginRadio", PortNum_TEXT_MESSAGE_APP) {} diff --git a/src/plugins/esp32/SerialPlugin.h b/src/plugins/esp32/SerialPlugin.h index 27cd7e91a..ab28c2841 100644 --- a/src/plugins/esp32/SerialPlugin.h +++ b/src/plugins/esp32/SerialPlugin.h @@ -25,7 +25,7 @@ extern SerialPlugin *serialPlugin; */ class SerialPluginRadio : public SinglePortPlugin { - uint32_t lastRxID; + uint32_t lastRxID = 0; public: /* diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index f613fc7c0..f970f86dc 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -121,7 +121,7 @@ void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to) uint32_t queueSize = storeForwardPlugin->historyQueueCreate(msAgo, to); if (queueSize) { - snprintf(this->routerMessage, 80, "** S&F - Sending %d message(s)", queueSize); + snprintf(this->routerMessage, 80, "** S&F - Sending %u message(s)", queueSize); storeForwardPlugin->sendMessage(to, this->routerMessage); this->busy = true; // runOnce() will pickup the next steps once busy = true. diff --git a/suppressions.txt b/suppressions.txt new file mode 100644 index 000000000..074c9bfdf --- /dev/null +++ b/suppressions.txt @@ -0,0 +1,12 @@ +// cppcheck suppressions +assertWithSideEffect + +// TODO: need to come back to these +duplInheritedMember + +// most likely due to a cppcheck configuration issue (like missing an include) +syntaxError + +// ignore stuff that is not ours +*:.pio/* +*:*/libdeps/* From caaa235c5d310a42b2018321067479b551bf4def Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 24 Jan 2022 17:24:40 +0000 Subject: [PATCH 2/6] more cppcheck warnings fixes --- .gitignore | 1 + bin/check-all.sh | 3 ++- src/Observer.h | 4 ++-- src/Power.cpp | 10 ++++----- src/RedirectablePrint.h | 4 ++-- src/SerialConsole.h | 6 +++--- src/concurrency/LockGuard.h | 2 +- src/concurrency/NotifiedWorkerThread.h | 2 +- src/concurrency/Periodic.h | 2 +- src/esp32/ESP32CryptoEngine.cpp | 6 +++--- src/gps/GPS.h | 2 +- src/gps/NMEAGPS.h | 10 ++++----- src/gps/UBloxGPS.h | 16 +++++++------- src/graphics/EInkDisplay2.h | 8 +++---- src/graphics/Screen.h | 4 ++-- src/graphics/TFTDisplay.h | 8 +++---- src/input/RotaryEncoderInterruptBase.h | 2 +- src/main.cpp | 4 ++-- src/mesh/DSRRouter.h | 6 +++--- src/mesh/FloodingRouter.h | 6 +++--- src/mesh/MemoryPool.h | 6 +++--- src/mesh/MeshPlugin.h | 2 +- src/mesh/NodeDB.cpp | 4 ++-- src/mesh/PhoneAPI.h | 2 +- src/mesh/PointerQueue.h | 2 +- src/mesh/ProtobufPlugin.h | 2 +- src/mesh/RF95Interface.h | 20 +++++++++--------- src/mesh/RadioInterface.h | 4 ++-- src/mesh/RadioLibInterface.h | 10 ++++----- src/mesh/ReliableRouter.h | 12 +++++------ src/mesh/Router.h | 4 ++-- src/mesh/SX1268Interface.h | 4 ++-- src/mesh/SX126xInterface.h | 22 ++++++++++---------- src/mesh/SinglePortPlugin.h | 2 +- src/mesh/StreamAPI.h | 6 +++--- src/mesh/TypedQueue.h | 2 +- src/mesh/http/WebServer.h | 2 +- src/mesh/wifi/WiFiServerAPI.h | 10 ++++----- src/mqtt/MQTT.h | 2 +- src/nrf52/NRF52Bluetooth.cpp | 6 +++--- src/nrf52/NRF52CryptoEngine.cpp | 4 ++-- src/plugins/AdminPlugin.h | 4 ++-- src/plugins/CannedMessagePlugin.h | 8 +++---- src/plugins/EnvironmentalMeasurementPlugin.h | 8 +++---- src/plugins/ExternalNotificationPlugin.h | 4 ++-- src/plugins/NodeInfoPlugin.h | 8 +++---- src/plugins/PositionPlugin.h | 8 +++---- src/plugins/RemoteHardwarePlugin.h | 6 +++--- src/plugins/ReplyPlugin.h | 2 +- src/plugins/RoutingPlugin.h | 8 +++---- src/plugins/TextMessagePlugin.h | 4 ++-- src/plugins/esp32/RangeTestPlugin.h | 6 +++--- src/plugins/esp32/SerialPlugin.h | 6 +++--- src/plugins/esp32/StoreForwardPlugin.h | 8 +++---- src/portduino/CrossPlatformCryptoEngine.cpp | 6 +++--- src/power.h | 4 ++-- suppressions.txt | 4 ++++ 57 files changed, 167 insertions(+), 161 deletions(-) diff --git a/.gitignore b/.gitignore index d63accc92..e9d3cfdf9 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ __pycache__ *~ venv/ +release/ diff --git a/bin/check-all.sh b/bin/check-all.sh index f7fd445d0..f54ff03e4 100755 --- a/bin/check-all.sh +++ b/bin/check-all.sh @@ -11,7 +11,8 @@ export APP_VERSION=$VERSION # only check high and medium in our source # TODO: only doing tbeam (to start; add all/more later) -pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" -e tbeam --skip-packages --severity=medium --severity=high --pattern="src/" +#pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" -e tbeam --skip-packages --severity=medium --severity=high --pattern="src/" +pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" -e tbeam --skip-packages --pattern="src/" return_code=$? # TODO: not sure why return_code is 0 diff --git a/src/Observer.h b/src/Observer.h index 85c40b1ea..fb024dc82 100644 --- a/src/Observer.h +++ b/src/Observer.h @@ -47,7 +47,7 @@ template class CallbackObserver : public Observer CallbackObserver(Callback *_objPtr, ObserverCallback _method) : objPtr(_objPtr), method(_method) {} protected: - virtual int onNotify(T arg) { return (objPtr->*method)(arg); } + virtual int onNotify(T arg) override { return (objPtr->*method)(arg); } }; /** @@ -104,4 +104,4 @@ template void Observer::observe(Observable *o) observed = o; o->addObserver(this); -} \ No newline at end of file +} diff --git a/src/Power.cpp b/src/Power.cpp index b46153c6e..72e2d07f5 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -75,7 +75,7 @@ class AnalogBatteryLevel : public HasBatteryLevel * * FIXME - use a lipo lookup table, the current % full is super wrong */ - virtual int getBattPercentage() + virtual int getBattPercentage() override { float v = getBattVoltage(); @@ -94,7 +94,7 @@ class AnalogBatteryLevel : public HasBatteryLevel /** * The raw voltage of the batteryin millivolts or NAN if unknown */ - virtual float getBattVoltage() + virtual float getBattVoltage() override { #ifndef ADC_MULTIPLIER @@ -127,15 +127,15 @@ class AnalogBatteryLevel : public HasBatteryLevel /** * return true if there is a battery installed in this unit */ - virtual bool isBatteryConnect() { return getBattPercentage() != -1; } + virtual bool isBatteryConnect() override { return getBattPercentage() != -1; } /// If we see a battery voltage higher than physics allows - assume charger is pumping /// in power - virtual bool isVBUSPlug() { return getBattVoltage() > chargingVolt; } + virtual bool isVBUSPlug() override { return getBattVoltage() > chargingVolt; } /// Assume charging if we have a battery and external power is connected. /// we can't be smart enough to say 'full'? - virtual bool isChargeing() { return isBatteryConnect() && isVBUSPlug(); } + virtual bool isChargeing() override { return isBatteryConnect() && isVBUSPlug(); } private: /// If we see a battery voltage higher than physics allows - assume charger is pumping diff --git a/src/RedirectablePrint.h b/src/RedirectablePrint.h index 1eb60199b..bf797b41f 100644 --- a/src/RedirectablePrint.h +++ b/src/RedirectablePrint.h @@ -22,7 +22,7 @@ class RedirectablePrint : public Print volatile bool inDebugPrint = false; public: - RedirectablePrint(Print *_dest) : dest(_dest) {} + explicit RedirectablePrint(Print *_dest) : dest(_dest) {} /** * Set a new destination @@ -56,4 +56,4 @@ class NoopPrint : public Print /** * A printer that doesn't go anywhere */ -extern NoopPrint noopPrint; \ No newline at end of file +extern NoopPrint noopPrint; diff --git a/src/SerialConsole.h b/src/SerialConsole.h index cc3ec4ec3..e7b8af34f 100644 --- a/src/SerialConsole.h +++ b/src/SerialConsole.h @@ -15,9 +15,9 @@ class SerialConsole : public StreamAPI, public RedirectablePrint * we override this to notice when we've received a protobuf over the serial stream. Then we shunt off * debug serial output. */ - virtual bool handleToRadio(const uint8_t *buf, size_t len); + virtual bool handleToRadio(const uint8_t *buf, size_t len) override; - virtual size_t write(uint8_t c) + virtual size_t write(uint8_t c) override { if (c == '\n') // prefix any newlines with carriage return RedirectablePrint::write('\r'); @@ -27,7 +27,7 @@ class SerialConsole : public StreamAPI, public RedirectablePrint protected: /// Check the current underlying physical link to see if the client is currently connected - virtual bool checkIsConnected(); + virtual bool checkIsConnected() override; }; // A simple wrapper to allow non class aware code write to the console diff --git a/src/concurrency/LockGuard.h b/src/concurrency/LockGuard.h index dc09f40fb..89c288f6a 100644 --- a/src/concurrency/LockGuard.h +++ b/src/concurrency/LockGuard.h @@ -10,7 +10,7 @@ namespace concurrency { class LockGuard { public: - LockGuard(Lock *lock); + explicit LockGuard(Lock *lock); ~LockGuard(); LockGuard(const LockGuard &) = delete; diff --git a/src/concurrency/NotifiedWorkerThread.h b/src/concurrency/NotifiedWorkerThread.h index 628277850..83e73a571 100644 --- a/src/concurrency/NotifiedWorkerThread.h +++ b/src/concurrency/NotifiedWorkerThread.h @@ -39,7 +39,7 @@ class NotifiedWorkerThread : public OSThread virtual void onNotify(uint32_t notification) = 0; /// just calls checkNotification() - virtual int32_t runOnce(); + virtual int32_t runOnce() override; /// Sometimes we might want to check notifications independently of when our thread was getting woken up (i.e. if we are about to change /// radio transmit/receive modes we want to handle any pending interrupts first). You can call this method and if any notifications are currently diff --git a/src/concurrency/Periodic.h b/src/concurrency/Periodic.h index bf60280de..db07145a6 100644 --- a/src/concurrency/Periodic.h +++ b/src/concurrency/Periodic.h @@ -18,7 +18,7 @@ class Periodic : public OSThread Periodic(const char *name, int32_t (*_callback)()) : OSThread(name), callback(_callback) {} protected: - int32_t runOnce() { return callback(); } + int32_t runOnce() override { return callback(); } }; } // namespace concurrency diff --git a/src/esp32/ESP32CryptoEngine.cpp b/src/esp32/ESP32CryptoEngine.cpp index f04614c72..154491ccb 100644 --- a/src/esp32/ESP32CryptoEngine.cpp +++ b/src/esp32/ESP32CryptoEngine.cpp @@ -32,7 +32,7 @@ class ESP32CryptoEngine : public CryptoEngine * @param bytes a _static_ buffer that will remain valid for the life of this crypto instance (i.e. this class will cache the * provided pointer) */ - virtual void setKey(const CryptoKey &k) + virtual void setKey(const CryptoKey &k) override { CryptoEngine::setKey(k); @@ -47,7 +47,7 @@ class ESP32CryptoEngine : public CryptoEngine * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) + virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { uint8_t stream_block[16]; @@ -66,7 +66,7 @@ class ESP32CryptoEngine : public CryptoEngine } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) + virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { // DEBUG_MSG("ESP32 decrypt!\n"); diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 895d5607f..4764d1fb3 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -145,7 +145,7 @@ class GPS : private concurrency::OSThread */ void publishUpdate(); - virtual int32_t runOnce(); + virtual int32_t runOnce() override; }; // Creates an instance of the GPS class. diff --git a/src/gps/NMEAGPS.h b/src/gps/NMEAGPS.h index bc5582508..6133925dd 100644 --- a/src/gps/NMEAGPS.h +++ b/src/gps/NMEAGPS.h @@ -23,14 +23,14 @@ class NMEAGPS : public GPS #endif public: - virtual bool setupGPS(); + virtual bool setupGPS() override; protected: /** Subclasses should look for serial rx characters here and feed it to their GPS parser * * Return true if we received a valid message from the GPS */ - virtual bool whileIdle(); + virtual bool whileIdle() override; /** * Perform any processing that should be done only while the GPS is awake and looking for a fix. @@ -38,7 +38,7 @@ class NMEAGPS : public GPS * * @return true if we've acquired a time */ - virtual bool lookForTime(); + virtual bool lookForTime() override; /** * Perform any processing that should be done only while the GPS is awake and looking for a fix. @@ -46,7 +46,7 @@ class NMEAGPS : public GPS * * @return true if we've acquired a new location */ - virtual bool lookForLocation(); + virtual bool lookForLocation() override; - virtual bool hasLock(); + virtual bool hasLock() override; }; diff --git a/src/gps/UBloxGPS.h b/src/gps/UBloxGPS.h index 009744a52..c2521df23 100644 --- a/src/gps/UBloxGPS.h +++ b/src/gps/UBloxGPS.h @@ -22,22 +22,22 @@ class UBloxGPS : public GPS * * @return true for success */ - bool factoryReset(); + bool factoryReset() override; protected: /** * Returns true if we succeeded */ - virtual bool setupGPS(); + virtual bool setupGPS() override; /** Subclasses should look for serial rx characters here and feed it to their GPS parser * * Return true if we received a valid message from the GPS */ - virtual bool whileIdle(); + virtual bool whileIdle() override; /** Idle processing while GPS is looking for lock */ - virtual void whileActive(); + virtual void whileActive() override; /** * Perform any processing that should be done only while the GPS is awake and looking for a fix. @@ -45,7 +45,7 @@ class UBloxGPS : public GPS * * @return true if we've acquired a time */ - virtual bool lookForTime(); + virtual bool lookForTime() override; /** * Perform any processing that should be done only while the GPS is awake and looking for a fix. @@ -53,12 +53,12 @@ class UBloxGPS : public GPS * * @return true if we've acquired a new location */ - virtual bool lookForLocation(); + virtual bool lookForLocation() override; virtual bool hasLock(); /// If possible force the GPS into sleep/low power mode - virtual void sleep(); - virtual void wake(); + virtual void sleep() override; + virtual void wake() override; private: /// Attempt to connect to our GPS, returns false if no gps is present diff --git a/src/graphics/EInkDisplay2.h b/src/graphics/EInkDisplay2.h index 18b900305..76b2dc395 100644 --- a/src/graphics/EInkDisplay2.h +++ b/src/graphics/EInkDisplay2.h @@ -25,7 +25,7 @@ class EInkDisplay : public OLEDDisplay EInkDisplay(uint8_t address, int sda, int scl); // Write the buffer to the display memory (for eink we only do this occasionally) - virtual void display(void); + virtual void display(void) override; /** * Force a display update if we haven't drawn within the specified msecLimit @@ -36,13 +36,13 @@ class EInkDisplay : public OLEDDisplay protected: // the header size of the buffer used, e.g. for the SPI command header - virtual int getBufferOffset(void) { return 0; } + virtual int getBufferOffset(void) override { return 0; } // Send a command to the display (low level function) - virtual void sendCommand(uint8_t com); + virtual void sendCommand(uint8_t com) override; // Connect to the display - virtual bool connect(); + virtual bool connect() override; }; diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 6c50ea2b7..9c178cd0a 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -95,7 +95,7 @@ class Screen : public concurrency::OSThread CallbackObserver(this, &Screen::handleUIFrameEvent); public: - Screen(uint8_t address, int sda = -1, int scl = -1); + explicit Screen(uint8_t address, int sda = -1, int scl = -1); Screen(const Screen &) = delete; Screen &operator=(const Screen &) = delete; @@ -313,4 +313,4 @@ class Screen : public concurrency::OSThread }; } // namespace graphics -#endif \ No newline at end of file +#endif diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index 83168e2e1..c21f190ce 100644 --- a/src/graphics/TFTDisplay.h +++ b/src/graphics/TFTDisplay.h @@ -21,15 +21,15 @@ class TFTDisplay : public OLEDDisplay TFTDisplay(uint8_t address, int sda, int scl); // Write the buffer to the display memory - virtual void display(void); + virtual void display(void) override; protected: // the header size of the buffer used, e.g. for the SPI command header - virtual int getBufferOffset(void) { return 0; } + virtual int getBufferOffset(void) override { return 0; } // Send a command to the display (low level function) - virtual void sendCommand(uint8_t com); + virtual void sendCommand(uint8_t com) override; // Connect to the display - virtual bool connect(); + virtual bool connect() override; }; diff --git a/src/input/RotaryEncoderInterruptBase.h b/src/input/RotaryEncoderInterruptBase.h index 443ba15fc..2f2633870 100644 --- a/src/input/RotaryEncoderInterruptBase.h +++ b/src/input/RotaryEncoderInterruptBase.h @@ -34,7 +34,7 @@ class RotaryEncoderInterruptBase : void intBHandler(); protected: - virtual int32_t runOnce(); + virtual int32_t runOnce() override; RotaryEncoderInterruptBaseStateType intHandler( bool actualPinRaising, int otherPinLevel, diff --git a/src/main.cpp b/src/main.cpp index b0f90c445..7ad375db5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -141,7 +141,7 @@ class PowerFSMThread : public OSThread PowerFSMThread() : OSThread("PowerFSM") {} protected: - int32_t runOnce() + int32_t runOnce() override { powerFSM.run_machine(); @@ -242,7 +242,7 @@ class ButtonThread : public OSThread protected: /// If the button is pressed we suppress CPU sleep until release - int32_t runOnce() + int32_t runOnce() override { canSleep = true; // Assume we should not keep the board awake diff --git a/src/mesh/DSRRouter.h b/src/mesh/DSRRouter.h index 796dc236c..0caa9310a 100644 --- a/src/mesh/DSRRouter.h +++ b/src/mesh/DSRRouter.h @@ -8,14 +8,14 @@ class DSRRouter : public ReliableRouter * Every (non duplicate) packet this node receives will be passed through this method. This allows subclasses to * update routing tables etc... based on what we overhear (even for messages not destined to our node) */ - virtual void sniffReceived(const MeshPacket *p, const Routing *c); + virtual void sniffReceived(const MeshPacket *p, const Routing *c) override; /** * Send a packet on a suitable interface. This routine will * later free() the packet to pool. This routine is not allowed to stall. * If the txmit queue is full it might return an error */ - virtual ErrorCode send(MeshPacket *p); + virtual ErrorCode send(MeshPacket *p) override; private: /** @@ -77,4 +77,4 @@ class DSRRouter : public ReliableRouter * when the discovery is complete. */ void startDiscovery(NodeNum dest); -}; \ No newline at end of file +}; diff --git a/src/mesh/FloodingRouter.h b/src/mesh/FloodingRouter.h index ca5bac663..387b4576b 100644 --- a/src/mesh/FloodingRouter.h +++ b/src/mesh/FloodingRouter.h @@ -41,7 +41,7 @@ class FloodingRouter : public Router, protected PacketHistory * later free() the packet to pool. This routine is not allowed to stall. * If the txmit queue is full it might return an error */ - virtual ErrorCode send(MeshPacket *p); + virtual ErrorCode send(MeshPacket *p) override; protected: /** @@ -50,10 +50,10 @@ class FloodingRouter : public Router, protected PacketHistory * Called immedately on receiption, before any further processing. * @return true to abandon the packet */ - virtual bool shouldFilterReceived(MeshPacket *p); + virtual bool shouldFilterReceived(MeshPacket *p) override; /** * Look for broadcasts we need to rebroadcast */ - virtual void sniffReceived(const MeshPacket *p, const Routing *c); + virtual void sniffReceived(const MeshPacket *p, const Routing *c) override; }; diff --git a/src/mesh/MemoryPool.h b/src/mesh/MemoryPool.h index 8023aa6bc..de97fe259 100644 --- a/src/mesh/MemoryPool.h +++ b/src/mesh/MemoryPool.h @@ -58,7 +58,7 @@ template class MemoryDynamic : public Allocator { public: /// Return a buffer for use by others - virtual void release(T *p) + virtual void release(T *p) override { assert(p); free(p); @@ -66,7 +66,7 @@ template class MemoryDynamic : public Allocator protected: // Alloc some storage - virtual T *alloc(TickType_t maxWait) + virtual T *alloc(TickType_t maxWait) override { T *p = (T *)malloc(sizeof(T)); assert(p); @@ -87,7 +87,7 @@ template class MemoryPool : public Allocator size_t maxElements; public: - MemoryPool(size_t _maxElements) : dead(_maxElements), maxElements(_maxElements) + explicit MemoryPool(size_t _maxElements) : dead(_maxElements), maxElements(_maxElements) { buf = new T[maxElements]; diff --git a/src/mesh/MeshPlugin.h b/src/mesh/MeshPlugin.h index b6bcf22b8..456769dc0 100644 --- a/src/mesh/MeshPlugin.h +++ b/src/mesh/MeshPlugin.h @@ -154,4 +154,4 @@ class MeshPlugin /** set the destination and packet parameters of packet p intended as a reply to a particular "to" packet * This ensures that if the request packet was sent reliably, the reply is sent that way as well. */ -void setReplyTo(MeshPacket *p, const MeshPacket &to); \ No newline at end of file +void setReplyTo(MeshPacket *p, const MeshPacket &to); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 04359aaed..d7fefc88f 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -407,8 +407,8 @@ void NodeDB::saveToDisk() #ifdef FS FS.mkdir("/prefs"); #endif - bool okay = saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); - okay &= saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig); + saveProto(preffile, DeviceState_size, sizeof(devicestate), DeviceState_fields, &devicestate); + saveProto(radiofile, RadioConfig_size, sizeof(RadioConfig), RadioConfig_fields, &radioConfig); saveChannelsToDisk(); // remove any pre 1.2 pref files, turn on after 1.2 is in beta diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 50ab3592c..67b52d20a 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -123,5 +123,5 @@ class PhoneAPI bool handleToRadioPacket(MeshPacket &p); /// If the mesh service tells us fromNum has changed, tell the phone - virtual int onNotify(uint32_t newValue); + virtual int onNotify(uint32_t newValue) override; }; diff --git a/src/mesh/PointerQueue.h b/src/mesh/PointerQueue.h index b587ac649..b45245eb8 100644 --- a/src/mesh/PointerQueue.h +++ b/src/mesh/PointerQueue.h @@ -8,7 +8,7 @@ template class PointerQueue : public TypedQueue { public: - PointerQueue(int maxElements) : TypedQueue(maxElements) {} + explicit PointerQueue(int maxElements) : TypedQueue(maxElements) {} // returns a ptr or null if the queue was empty T *dequeuePtr(TickType_t maxWait = portMAX_DELAY) diff --git a/src/mesh/ProtobufPlugin.h b/src/mesh/ProtobufPlugin.h index 72e3b902e..940d60d76 100644 --- a/src/mesh/ProtobufPlugin.h +++ b/src/mesh/ProtobufPlugin.h @@ -51,7 +51,7 @@ template class ProtobufPlugin : protected SinglePortPlugin @return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual ProcessMessage handleReceived(const MeshPacket &mp) + virtual ProcessMessage handleReceived(const MeshPacket &mp) override { // FIXME - we currently update position data in the DB only if the message was a broadcast or destined to us // it would be better to update even if the message was destined to others. diff --git a/src/mesh/RF95Interface.h b/src/mesh/RF95Interface.h index d072f28e3..f62195a26 100644 --- a/src/mesh/RF95Interface.h +++ b/src/mesh/RF95Interface.h @@ -14,26 +14,26 @@ class RF95Interface : public RadioLibInterface public: RF95Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass &spi); - bool isIRQPending() { return lora->getPendingIRQ(); } + bool isIRQPending() override { return lora->getPendingIRQ(); } /// Initialise the Driver transport hardware and software. /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. - virtual bool init(); + virtual bool init() override; /// Apply any radio provisioning changes /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. - virtual bool reconfigure(); + virtual bool reconfigure() override; /// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep. - virtual bool sleep(); + virtual bool sleep() override; protected: /** * Glue functions called from ISR land */ - virtual void disableInterrupt(); + virtual void disableInterrupt() override; /** * Enable a particular ISR callback glue function @@ -41,24 +41,24 @@ class RF95Interface : public RadioLibInterface virtual void enableInterrupt(void (*callback)()) { lora->setDio0Action(callback); } /** are we actively receiving a packet (only called during receiving state) */ - virtual bool isActivelyReceiving(); + virtual bool isActivelyReceiving() override; /** * Start waiting to receive a message */ - virtual void startReceive(); + virtual void startReceive() override; /** * Add SNR data to received messages */ - virtual void addReceiveMetadata(MeshPacket *mp); + virtual void addReceiveMetadata(MeshPacket *mp) override; - virtual void setStandby(); + virtual void setStandby() override; /** * We override to turn on transmitter power as needed. */ - virtual void configHardwareForSend(); + virtual void configHardwareForSend() override; private: /** Some boards require GPIO control of tx vs rx paths */ diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 542b575da..6b286bef8 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -205,8 +205,8 @@ class RadioInterface class SimRadio : public RadioInterface { public: - virtual ErrorCode send(MeshPacket *p); + virtual ErrorCode send(MeshPacket *p) override; }; /// Debug printing for packets -void printPacket(const char *prefix, const MeshPacket *p); \ No newline at end of file +void printPacket(const char *prefix, const MeshPacket *p); diff --git a/src/mesh/RadioLibInterface.h b/src/mesh/RadioLibInterface.h index b38d6d553..a394c5f9f 100644 --- a/src/mesh/RadioLibInterface.h +++ b/src/mesh/RadioLibInterface.h @@ -54,7 +54,7 @@ class LockingModule : public Module \param numBytes Number of bytes to transfer. */ - virtual void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t *dataOut, uint8_t *dataIn, uint8_t numBytes); + virtual void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t *dataOut, uint8_t *dataIn, uint8_t numBytes) override; }; class RadioLibInterface : public RadioInterface, protected concurrency::NotifiedWorkerThread @@ -116,14 +116,14 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi, PhysicalLayer *iface = NULL); - virtual ErrorCode send(MeshPacket *p); + virtual ErrorCode send(MeshPacket *p) override; /** * Return true if we think the board can go to sleep (i.e. our tx queue is empty, we are not sending or receiving) * * This method must be used before putting the CPU into deep or light sleep. */ - virtual bool canSleep(); + virtual bool canSleep() override; /** * Start waiting to receive a message @@ -138,7 +138,7 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified virtual bool isActivelyReceiving() = 0; /** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */ - virtual bool cancelSending(NodeNum from, PacketId id); + virtual bool cancelSending(NodeNum from, PacketId id) override; private: /** if we have something waiting to send, start a short random timer so we can come check for collision before actually doing @@ -153,7 +153,7 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified static void timerCallback(void *p1, uint32_t p2); - virtual void onNotify(uint32_t notification); + virtual void onNotify(uint32_t notification) override; /** start an immediate transmit * This method is virtual so subclasses can hook as needed, subclasses should not call directly diff --git a/src/mesh/ReliableRouter.h b/src/mesh/ReliableRouter.h index 7bec0cf34..52e9b5af9 100644 --- a/src/mesh/ReliableRouter.h +++ b/src/mesh/ReliableRouter.h @@ -33,10 +33,10 @@ struct PendingPacket { MeshPacket *packet; /** The next time we should try to retransmit this packet */ - uint32_t nextTxMsec; + uint32_t nextTxMsec = 0; /** Starts at NUM_RETRANSMISSIONS -1(normally 3) and counts down. Once zero it will be removed from the list */ - uint8_t numRetransmissions; + uint8_t numRetransmissions = 0; /** True if we have started trying to find a route - for DSR usage * While trying to find a route we don't actually send the data packet. We just leave it here pending until @@ -74,10 +74,10 @@ class ReliableRouter : public FloodingRouter * later free() the packet to pool. This routine is not allowed to stall. * If the txmit queue is full it might return an error */ - virtual ErrorCode send(MeshPacket *p); + virtual ErrorCode send(MeshPacket *p) override; /** Do our retransmission handling */ - virtual int32_t runOnce() + virtual int32_t runOnce() override { // Note: We must doRetransmissions FIRST, because it might queue up work for the base class runOnce implementation auto d = doRetransmissions(); @@ -91,7 +91,7 @@ class ReliableRouter : public FloodingRouter /** * Look for acks/naks or someone retransmitting us */ - virtual void sniffReceived(const MeshPacket *p, const Routing *c); + virtual void sniffReceived(const MeshPacket *p, const Routing *c) override; /** * Try to find the pending packet record for this ID (or NULL if not found) @@ -102,7 +102,7 @@ class ReliableRouter : public FloodingRouter /** * We hook this method so we can see packets before FloodingRouter says they should be discarded */ - virtual bool shouldFilterReceived(MeshPacket *p); + virtual bool shouldFilterReceived(MeshPacket *p) override; /** * Add p to the list of packets to retransmit occasionally. We will free it once we stop retransmitting. diff --git a/src/mesh/Router.h b/src/mesh/Router.h index a11b47023..463596c85 100644 --- a/src/mesh/Router.h +++ b/src/mesh/Router.h @@ -37,7 +37,7 @@ class Router : protected concurrency::OSThread * do idle processing * Mostly looking in our incoming rxPacket queue and calling handleReceived. */ - virtual int32_t runOnce(); + virtual int32_t runOnce() override; /** * Works like send, but if we are sending to the local node, we directly put the message in the receive queue. @@ -143,4 +143,4 @@ extern Router *router; /// Generate a unique packet id // FIXME, move this someplace better -PacketId generatePacketId(); \ No newline at end of file +PacketId generatePacketId(); diff --git a/src/mesh/SX1268Interface.h b/src/mesh/SX1268Interface.h index c5b56171b..a288cdd09 100644 --- a/src/mesh/SX1268Interface.h +++ b/src/mesh/SX1268Interface.h @@ -9,7 +9,7 @@ class SX1268Interface : public SX126xInterface { public: /// override frequency of the SX1268 module regardless of the region (use EU433 value) - virtual float getFreq() { return 433.175f; } + virtual float getFreq() override { return 433.175f; } SX1268Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi); -}; \ No newline at end of file +}; diff --git a/src/mesh/SX126xInterface.h b/src/mesh/SX126xInterface.h index 953f89070..5168313e2 100644 --- a/src/mesh/SX126xInterface.h +++ b/src/mesh/SX126xInterface.h @@ -15,17 +15,17 @@ class SX126xInterface : public RadioLibInterface /// Initialise the Driver transport hardware and software. /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. - virtual bool init(); + virtual bool init() override; /// Apply any radio provisioning changes /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. - virtual bool reconfigure(); + virtual bool reconfigure() override; /// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep. - virtual bool sleep(); + virtual bool sleep() override; - bool isIRQPending() { return lora.getIrqStatus() != 0; } + bool isIRQPending() override { return lora.getIrqStatus() != 0; } protected: @@ -39,7 +39,7 @@ class SX126xInterface : public RadioLibInterface /** * Glue functions called from ISR land */ - virtual void disableInterrupt(); + virtual void disableInterrupt() override; /** * Enable a particular ISR callback glue function @@ -47,24 +47,24 @@ class SX126xInterface : public RadioLibInterface virtual void enableInterrupt(void (*callback)()) { lora.setDio1Action(callback); } /** are we actively receiving a packet (only called during receiving state) */ - virtual bool isActivelyReceiving(); + virtual bool isActivelyReceiving() override; /** * Start waiting to receive a message */ - virtual void startReceive(); + virtual void startReceive() override; /** * We override to turn on transmitter power as needed. */ - virtual void configHardwareForSend(); + virtual void configHardwareForSend() override; /** * Add SNR data to received messages */ - virtual void addReceiveMetadata(MeshPacket *mp); + virtual void addReceiveMetadata(MeshPacket *mp) override; - virtual void setStandby(); + virtual void setStandby() override; private: -}; \ No newline at end of file +}; diff --git a/src/mesh/SinglePortPlugin.h b/src/mesh/SinglePortPlugin.h index 305532dc5..60ca5e653 100644 --- a/src/mesh/SinglePortPlugin.h +++ b/src/mesh/SinglePortPlugin.h @@ -21,7 +21,7 @@ class SinglePortPlugin : public MeshPlugin /** * @return true if you want to receive the specified portnum */ - virtual bool wantPacket(const MeshPacket *p) { return p->decoded.portnum == ourPortNum; } + virtual bool wantPacket(const MeshPacket *p) override { return p->decoded.portnum == ourPortNum; } /** * Return a mesh packet which has been preinited as a data packet with a particular port number. diff --git a/src/mesh/StreamAPI.h b/src/mesh/StreamAPI.h index ca6cbdf16..0f36ecb06 100644 --- a/src/mesh/StreamAPI.h +++ b/src/mesh/StreamAPI.h @@ -48,7 +48,7 @@ class StreamAPI : public PhoneAPI, protected concurrency::OSThread * Currently we require frequent invocation from loop() to check for arrived serial packets and to send new packets to the * phone. */ - virtual int32_t runOnce(); + virtual int32_t runOnce() override; private: /** @@ -67,10 +67,10 @@ class StreamAPI : public PhoneAPI, protected concurrency::OSThread */ void emitRebooted(); - virtual void onConnectionChanged(bool connected); + virtual void onConnectionChanged(bool connected) override; /// Check the current underlying physical link to see if the client is currently connected - virtual bool checkIsConnected() = 0; + virtual bool checkIsConnected() override = 0; /** * Send the current txBuffer over our stream diff --git a/src/mesh/TypedQueue.h b/src/mesh/TypedQueue.h index 09d828a96..ad8bbed58 100644 --- a/src/mesh/TypedQueue.h +++ b/src/mesh/TypedQueue.h @@ -19,7 +19,7 @@ template class TypedQueue concurrency::OSThread *reader = NULL; public: - TypedQueue(int maxElements) + explicit TypedQueue(int maxElements) { h = xQueueCreate(maxElements, sizeof(T)); assert(h); diff --git a/src/mesh/http/WebServer.h b/src/mesh/http/WebServer.h index b036a303d..815d87432 100644 --- a/src/mesh/http/WebServer.h +++ b/src/mesh/http/WebServer.h @@ -16,7 +16,7 @@ class WebServerThread : private concurrency::OSThread uint32_t requestRestart = 0; protected: - virtual int32_t runOnce(); + virtual int32_t runOnce() override; }; extern WebServerThread *webServerThread; diff --git a/src/mesh/wifi/WiFiServerAPI.h b/src/mesh/wifi/WiFiServerAPI.h index b7b8c335a..416c94371 100644 --- a/src/mesh/wifi/WiFiServerAPI.h +++ b/src/mesh/wifi/WiFiServerAPI.h @@ -18,17 +18,17 @@ class WiFiServerAPI : public StreamAPI virtual ~WiFiServerAPI(); /// override close to also shutdown the TCP link - virtual void close(); + virtual void close() override; protected: /// We override this method to prevent publishing EVENT_SERIAL_CONNECTED/DISCONNECTED for wifi links (we want the board to /// stay in the POWERED state to prevent disabling wifi) - virtual void onConnectionChanged(bool connected) {} + virtual void onConnectionChanged(bool connected) override {} - virtual int32_t runOnce(); // Check for dropped client connections + virtual int32_t runOnce() override; // Check for dropped client connections /// Check the current underlying physical link to see if the client is currently connected - virtual bool checkIsConnected(); + virtual bool checkIsConnected() override; }; /** @@ -52,7 +52,7 @@ class WiFiServerPort : public WiFiServer, private concurrency::OSThread static void debugOut(char c); protected: - int32_t runOnce(); + int32_t runOnce() override; }; void initApiServer(); diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 3f4c8f80c..e03ad67b3 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -40,7 +40,7 @@ class MQTT : private concurrency::OSThread void reconnect(); protected: - virtual int32_t runOnce(); + virtual int32_t runOnce() override; private: /** return true if we have a channel that wants uplink/downlink diff --git a/src/nrf52/NRF52Bluetooth.cpp b/src/nrf52/NRF52Bluetooth.cpp index efe8dc6e1..41e7fef29 100644 --- a/src/nrf52/NRF52Bluetooth.cpp +++ b/src/nrf52/NRF52Bluetooth.cpp @@ -28,7 +28,7 @@ class BluetoothPhoneAPI : public PhoneAPI /** * Subclasses can use this as a hook to provide custom notifications for their transport (i.e. bluetooth notifies) */ - virtual void onNowHasData(uint32_t fromRadioNum) + virtual void onNowHasData(uint32_t fromRadioNum) override { PhoneAPI::onNowHasData(fromRadioNum); @@ -37,7 +37,7 @@ class BluetoothPhoneAPI : public PhoneAPI } /// Check the current underlying physical link to see if the client is currently connected - virtual bool checkIsConnected() { + virtual bool checkIsConnected() override { return bleConnected; } }; @@ -265,4 +265,4 @@ void NRF52Bluetooth::setup() void updateBatteryLevel(uint8_t level) { blebas.write(level); -} \ No newline at end of file +} diff --git a/src/nrf52/NRF52CryptoEngine.cpp b/src/nrf52/NRF52CryptoEngine.cpp index 435925f9c..4bf400fd1 100644 --- a/src/nrf52/NRF52CryptoEngine.cpp +++ b/src/nrf52/NRF52CryptoEngine.cpp @@ -17,7 +17,7 @@ class NRF52CryptoEngine : public CryptoEngine * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) + virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { // DEBUG_MSG("NRF52 encrypt!\n"); @@ -31,7 +31,7 @@ class NRF52CryptoEngine : public CryptoEngine } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) + virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { // DEBUG_MSG("NRF52 decrypt!\n"); diff --git a/src/plugins/AdminPlugin.h b/src/plugins/AdminPlugin.h index bbd0d14ad..4c4b956cc 100644 --- a/src/plugins/AdminPlugin.h +++ b/src/plugins/AdminPlugin.h @@ -17,7 +17,7 @@ class AdminPlugin : public ProtobufPlugin @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual bool handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *p); + virtual bool handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *p) override; private: void handleSetOwner(const User &o); @@ -28,4 +28,4 @@ class AdminPlugin : public ProtobufPlugin void handleGetRadio(const MeshPacket &req); }; -extern AdminPlugin *adminPlugin; \ No newline at end of file +extern AdminPlugin *adminPlugin; diff --git a/src/plugins/CannedMessagePlugin.h b/src/plugins/CannedMessagePlugin.h index b65c0b1a4..1f7dcf42e 100644 --- a/src/plugins/CannedMessagePlugin.h +++ b/src/plugins/CannedMessagePlugin.h @@ -40,7 +40,7 @@ class CannedMessagePlugin : protected: - virtual int32_t runOnce(); + virtual int32_t runOnce() override; void sendText( NodeNum dest, @@ -52,10 +52,10 @@ class CannedMessagePlugin : int getPrevIndex(); int handleInputEvent(const InputEvent *event); - virtual bool wantUIFrame() { return this->shouldDraw(); } - virtual Observable* getUIFrameObservable() { return this; } + virtual bool wantUIFrame() override { return this->shouldDraw(); } + virtual Observable* getUIFrameObservable() override { return this; } virtual void drawFrame( - OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); + OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override; int currentMessageIndex = -1; cannedMessagePluginRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; diff --git a/src/plugins/EnvironmentalMeasurementPlugin.h b/src/plugins/EnvironmentalMeasurementPlugin.h index 14da3b5ba..79f844e89 100644 --- a/src/plugins/EnvironmentalMeasurementPlugin.h +++ b/src/plugins/EnvironmentalMeasurementPlugin.h @@ -18,15 +18,15 @@ class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public Pro { lastMeasurementPacket = nullptr; } - virtual bool wantUIFrame(); - virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); + virtual bool wantUIFrame() override; + virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override; protected: /** Called to handle a particular incoming message @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual bool handleReceivedProtobuf(const MeshPacket &mp, EnvironmentalMeasurement *p); - virtual int32_t runOnce(); + virtual bool handleReceivedProtobuf(const MeshPacket &mp, EnvironmentalMeasurement *p) override; + virtual int32_t runOnce() override; /** * Send our EnvironmentalMeasurement into the mesh */ diff --git a/src/plugins/ExternalNotificationPlugin.h b/src/plugins/ExternalNotificationPlugin.h index b56b78288..dc8a1cb12 100644 --- a/src/plugins/ExternalNotificationPlugin.h +++ b/src/plugins/ExternalNotificationPlugin.h @@ -26,7 +26,7 @@ class ExternalNotificationPlugin : public SinglePortPlugin, private concurrency: @return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual ProcessMessage handleReceived(const MeshPacket &mp); + virtual ProcessMessage handleReceived(const MeshPacket &mp) override; - virtual int32_t runOnce(); + virtual int32_t runOnce() override; }; diff --git a/src/plugins/NodeInfoPlugin.h b/src/plugins/NodeInfoPlugin.h index d2b29c91a..3ad959518 100644 --- a/src/plugins/NodeInfoPlugin.h +++ b/src/plugins/NodeInfoPlugin.h @@ -26,14 +26,14 @@ class NodeInfoPlugin : public ProtobufPlugin, private concurrency::OSThrea @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual bool handleReceivedProtobuf(const MeshPacket &mp, User *p); + virtual bool handleReceivedProtobuf(const MeshPacket &mp, User *p) override; /** Messages can be received that have the want_response bit set. If set, this callback will be invoked * so that subclasses can (optionally) send a response back to the original sender. */ - virtual MeshPacket *allocReply(); + virtual MeshPacket *allocReply() override; /** Does our periodic broadcast */ - virtual int32_t runOnce(); + virtual int32_t runOnce() override; }; -extern NodeInfoPlugin *nodeInfoPlugin; \ No newline at end of file +extern NodeInfoPlugin *nodeInfoPlugin; diff --git a/src/plugins/PositionPlugin.h b/src/plugins/PositionPlugin.h index 402650afb..05042ac29 100644 --- a/src/plugins/PositionPlugin.h +++ b/src/plugins/PositionPlugin.h @@ -37,14 +37,14 @@ class PositionPlugin : public ProtobufPlugin, private concurrency::OST @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual bool handleReceivedProtobuf(const MeshPacket &mp, Position *p); + virtual bool handleReceivedProtobuf(const MeshPacket &mp, Position *p) override; /** Messages can be received that have the want_response bit set. If set, this callback will be invoked * so that subclasses can (optionally) send a response back to the original sender. */ - virtual MeshPacket *allocReply(); + virtual MeshPacket *allocReply() override; /** Does our periodic broadcast */ - virtual int32_t runOnce(); + virtual int32_t runOnce() override; }; -extern PositionPlugin *positionPlugin; \ No newline at end of file +extern PositionPlugin *positionPlugin; diff --git a/src/plugins/RemoteHardwarePlugin.h b/src/plugins/RemoteHardwarePlugin.h index 86a0bbd35..ab55c1a07 100644 --- a/src/plugins/RemoteHardwarePlugin.h +++ b/src/plugins/RemoteHardwarePlugin.h @@ -27,7 +27,7 @@ class RemoteHardwarePlugin : public ProtobufPlugin, private con @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual bool handleReceivedProtobuf(const MeshPacket &mp, HardwareMessage *p); + virtual bool handleReceivedProtobuf(const MeshPacket &mp, HardwareMessage *p) override; /** * Periodically read the gpios we have been asked to WATCH, if they have changed, @@ -37,7 +37,7 @@ class RemoteHardwarePlugin : public ProtobufPlugin, private con * * Returns desired period for next invocation (or RUN_SAME for no change) */ - virtual int32_t runOnce(); + virtual int32_t runOnce() override; }; -extern RemoteHardwarePlugin remoteHardwarePlugin; \ No newline at end of file +extern RemoteHardwarePlugin remoteHardwarePlugin; diff --git a/src/plugins/ReplyPlugin.h b/src/plugins/ReplyPlugin.h index 7d0ff8b71..16f0d1cdf 100644 --- a/src/plugins/ReplyPlugin.h +++ b/src/plugins/ReplyPlugin.h @@ -18,5 +18,5 @@ class ReplyPlugin : public SinglePortPlugin /** For reply plugin we do all of our processing in the (normally optional) * want_replies handling */ - virtual MeshPacket *allocReply(); + virtual MeshPacket *allocReply() override; }; diff --git a/src/plugins/RoutingPlugin.h b/src/plugins/RoutingPlugin.h index c0288f603..cb0eab13e 100644 --- a/src/plugins/RoutingPlugin.h +++ b/src/plugins/RoutingPlugin.h @@ -22,14 +22,14 @@ class RoutingPlugin : public ProtobufPlugin @return true if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual bool handleReceivedProtobuf(const MeshPacket &mp, Routing *p); + virtual bool handleReceivedProtobuf(const MeshPacket &mp, Routing *p) override; /** Messages can be received that have the want_response bit set. If set, this callback will be invoked * so that subclasses can (optionally) send a response back to the original sender. */ - virtual MeshPacket *allocReply(); + virtual MeshPacket *allocReply() override; /// Override wantPacket to say we want to see all packets, not just those for our port number - virtual bool wantPacket(const MeshPacket *p) { return true; } + virtual bool wantPacket(const MeshPacket *p) override { return true; } }; -extern RoutingPlugin *routingPlugin; \ No newline at end of file +extern RoutingPlugin *routingPlugin; diff --git a/src/plugins/TextMessagePlugin.h b/src/plugins/TextMessagePlugin.h index 87eb82e35..d730c3ae4 100644 --- a/src/plugins/TextMessagePlugin.h +++ b/src/plugins/TextMessagePlugin.h @@ -19,7 +19,7 @@ class TextMessagePlugin : public SinglePortPlugin, public Observable 0) { uint8_t stream_block[16]; @@ -67,7 +67,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) + virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same encrypt(fromNode, packetNum, numBytes, bytes); diff --git a/src/power.h b/src/power.h index 8168e09c0..5e5005a64 100644 --- a/src/power.h +++ b/src/power.h @@ -26,7 +26,7 @@ class Power : private concurrency::OSThread void shutdown(); void readPowerStatus(); virtual bool setup(); - virtual int32_t runOnce(); + virtual int32_t runOnce() override; void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; } protected: @@ -42,4 +42,4 @@ class Power : private concurrency::OSThread uint8_t low_voltage_counter; }; -extern Power *power; \ No newline at end of file +extern Power *power; diff --git a/suppressions.txt b/suppressions.txt index 074c9bfdf..d0deeb377 100644 --- a/suppressions.txt +++ b/suppressions.txt @@ -4,6 +4,10 @@ assertWithSideEffect // TODO: need to come back to these duplInheritedMember +// no real downside/harm in these +unusedFunction +unusedPrivateFunction + // most likely due to a cppcheck configuration issue (like missing an include) syntaxError From 7c362af3de9ac5e4f822dbd6a580d7080864ea5f Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 24 Jan 2022 18:39:17 +0000 Subject: [PATCH 3/6] more warning fixes --- src/GPSStatus.h | 4 ++-- src/Power.cpp | 16 ++++++++-------- src/PowerFSM.cpp | 10 +++++----- src/airtime.cpp | 3 +-- src/concurrency/BinarySemaphoreFreeRTOS.cpp | 5 ++--- src/concurrency/Lock.cpp | 3 +-- src/gps/Air530GPS.h | 4 ++-- src/gps/GeoCoord.cpp | 6 +++--- src/gps/GeoCoord.h | 4 ++-- src/gps/UBloxGPS.h | 2 +- src/graphics/Screen.cpp | 15 +++++++-------- src/input/RotaryEncoderInterruptBase.h | 2 +- src/memtest.cpp | 4 ++-- src/mesh/Channels.cpp | 4 ++-- src/mesh/Channels.h | 7 +++++-- src/mesh/MeshPacketQueue.h | 4 ++-- src/mesh/RadioLibRF95.h | 2 +- src/mesh/ReliableRouter.h | 4 ++-- src/mesh/TypedQueue.h | 3 +-- src/mesh/http/WebServer.cpp | 2 +- src/mesh/wifi/WiFiServerAPI.h | 2 +- src/plugins/ExternalNotificationPlugin.cpp | 3 +-- src/plugins/PositionPlugin.cpp | 8 ++++---- src/plugins/RemoteHardwarePlugin.cpp | 8 ++++---- src/plugins/esp32/StoreForwardPlugin.cpp | 6 +++--- src/portduino/CrossPlatformCryptoEngine.cpp | 4 ++-- suppressions.txt | 8 ++++++++ 27 files changed, 74 insertions(+), 69 deletions(-) diff --git a/src/GPSStatus.h b/src/GPSStatus.h index 7399d7e20..9586c9529 100644 --- a/src/GPSStatus.h +++ b/src/GPSStatus.h @@ -42,7 +42,7 @@ class GPSStatus : public Status } // preferred method - GPSStatus(bool hasLock, bool isConnected, Position pos) + GPSStatus(bool hasLock, bool isConnected, const Position& pos) : Status() { this->hasLock = hasLock; @@ -149,4 +149,4 @@ class GPSStatus : public Status } // namespace meshtastic -extern meshtastic::GPSStatus *gpsStatus; \ No newline at end of file +extern meshtastic::GPSStatus *gpsStatus; diff --git a/src/Power.cpp b/src/Power.cpp index 72e2d07f5..ed2eeae63 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -235,18 +235,18 @@ void Power::readPowerStatus() } // Notify any status instances that are observing us - const PowerStatus powerStatus = + const PowerStatus powerStatus2 = PowerStatus(hasBattery ? OptTrue : OptFalse, batteryLevel->isVBUSPlug() ? OptTrue : OptFalse, batteryLevel->isChargeing() ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent); - DEBUG_MSG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d\n", powerStatus.getHasUSB(), - powerStatus.getIsCharging(), powerStatus.getBatteryVoltageMv(), powerStatus.getBatteryChargePercent()); - newStatus.notifyObservers(&powerStatus); + DEBUG_MSG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d\n", powerStatus2.getHasUSB(), + powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent()); + newStatus.notifyObservers(&powerStatus2); // If we have a battery at all and it is less than 10% full, force deep sleep if we have more than 3 low readings in a row // Supect fluctuating voltage on the RAK4631 to force it to deep sleep even if battery is at 85% after only a few days #ifdef NRF52_SERIES - if (powerStatus.getHasBattery() && !powerStatus.getHasUSB()){ + if (powerStatus2.getHasBattery() && !powerStatus2.getHasUSB()){ if (batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS){ low_voltage_counter++; if (low_voltage_counter>3) @@ -257,13 +257,13 @@ void Power::readPowerStatus() } #else // If we have a battery at all and it is less than 10% full, force deep sleep - if (powerStatus.getHasBattery() && !powerStatus.getHasUSB() && batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS) + if (powerStatus2.getHasBattery() && !powerStatus2.getHasUSB() && batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS) powerFSM.trigger(EVENT_LOW_BATTERY); #endif } else { // No power sensing on this board - tell everyone else we have no idea what is happening - const PowerStatus powerStatus = PowerStatus(OptUnknown, OptUnknown, OptUnknown, -1, -1); - newStatus.notifyObservers(&powerStatus); + const PowerStatus powerStatus3 = PowerStatus(OptUnknown, OptUnknown, OptUnknown, -1, -1); + newStatus.notifyObservers(&powerStatus3); } } diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index a3c55c523..3316b208e 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -63,7 +63,7 @@ static void lsIdle() // DEBUG_MSG("lsIdle begin ls_secs=%u\n", getPref_ls_secs()); #ifndef NO_ESP32 - esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED; + esp_sleep_source_t wakeCause2 = ESP_SLEEP_WAKEUP_UNDEFINED; // Do we have more sleeping to do? if (secsSlept < getPref_ls_secs()) { @@ -73,14 +73,14 @@ static void lsIdle() // If some other service would stall sleep, don't let sleep happen yet if (doPreflightSleep()) { setLed(false); // Never leave led on while in light sleep - wakeCause = doLightSleep(sleepTime * 1000LL); + wakeCause2 = doLightSleep(sleepTime * 1000LL); - switch (wakeCause) { + switch (wakeCause2) { case ESP_SLEEP_WAKEUP_TIMER: // Normal case: timer expired, we should just go back to sleep ASAP setLed(true); // briefly turn on led - wakeCause = doLightSleep(1); // leave led on for 1ms + wakeCause2 = doLightSleep(1); // leave led on for 1ms secsSlept += sleepTime; // DEBUG_MSG("sleeping, flash led!\n"); @@ -94,7 +94,7 @@ static void lsIdle() default: // We woke for some other reason (button press, device interrupt) // uint64_t status = esp_sleep_get_ext1_wakeup_status(); - DEBUG_MSG("wakeCause %d\n", wakeCause); + DEBUG_MSG("wakeCause2 %d\n", wakeCause2); #ifdef BUTTON_PIN bool pressed = !digitalRead(BUTTON_PIN); diff --git a/src/airtime.cpp b/src/airtime.cpp index d497e4dc7..5c0378cfa 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -117,8 +117,7 @@ float AirTime::utilizationTXPercent() return (float(sum) / float(MS_IN_HOUR)) * 100; } -AirTime::AirTime() : concurrency::OSThread("AirTime") { - airtimes = {}; +AirTime::AirTime() : concurrency::OSThread("AirTime"),airtimes({}) { } int32_t AirTime::runOnce() diff --git a/src/concurrency/BinarySemaphoreFreeRTOS.cpp b/src/concurrency/BinarySemaphoreFreeRTOS.cpp index 96c647756..4d6d40d78 100644 --- a/src/concurrency/BinarySemaphoreFreeRTOS.cpp +++ b/src/concurrency/BinarySemaphoreFreeRTOS.cpp @@ -7,9 +7,8 @@ namespace concurrency { -BinarySemaphoreFreeRTOS::BinarySemaphoreFreeRTOS() +BinarySemaphoreFreeRTOS::BinarySemaphoreFreeRTOS() : semaphore(xSemaphoreCreateBinary()) { - semaphore = xSemaphoreCreateBinary(); assert(semaphore); } @@ -38,4 +37,4 @@ IRAM_ATTR void BinarySemaphoreFreeRTOS::giveFromISR(BaseType_t *pxHigherPriority } // namespace concurrency -#endif \ No newline at end of file +#endif diff --git a/src/concurrency/Lock.cpp b/src/concurrency/Lock.cpp index bcf92496e..50ce6a00f 100644 --- a/src/concurrency/Lock.cpp +++ b/src/concurrency/Lock.cpp @@ -6,9 +6,8 @@ namespace concurrency { #ifdef HAS_FREE_RTOS -Lock::Lock() +Lock::Lock() : handle(xSemaphoreCreateBinary()) { - handle = xSemaphoreCreateBinary(); assert(handle); assert(xSemaphoreGive(handle)); } diff --git a/src/gps/Air530GPS.h b/src/gps/Air530GPS.h index bbb9f8003..535b08029 100644 --- a/src/gps/Air530GPS.h +++ b/src/gps/Air530GPS.h @@ -11,10 +11,10 @@ class Air530GPS : public NMEAGPS { protected: /// If possible force the GPS into sleep/low power mode - virtual void sleep(); + virtual void sleep() override; /// wake the GPS into normal operation mode - virtual void wake(); + virtual void wake() override; private: /// Send a NMEA cmd with checksum diff --git a/src/gps/GeoCoord.cpp b/src/gps/GeoCoord.cpp index 98f9c842b..69c36ccb9 100644 --- a/src/gps/GeoCoord.cpp +++ b/src/gps/GeoCoord.cpp @@ -171,7 +171,7 @@ void GeoCoord::latLongToMGRS(const double lat, const double lon, MGRS &mgrs) { * Based on: https://www.movable-type.co.uk/scripts/latlong-os-gridref.html */ void GeoCoord::latLongToOSGR(const double lat, const double lon, OSGR &osgr) { - char letter[] = "ABCDEFGHJKLMNOPQRSTUVWXYZ"; // No 'I' in OSGR + const char letter[] = "ABCDEFGHJKLMNOPQRSTUVWXYZ"; // No 'I' in OSGR double a = 6377563.396; // Airy 1830 semi-major axis double b = 6356256.909; // Airy 1830 semi-minor axis double f0 = 0.9996012717; // National Grid point scale factor on the central meridian @@ -419,12 +419,12 @@ float GeoCoord::rangeRadiansToMeters(double range_radians) { } // Find distance from point to passed in point -int32_t GeoCoord::distanceTo(GeoCoord pointB) { +int32_t GeoCoord::distanceTo(const GeoCoord& pointB) { return latLongToMeter(this->getLatitude() * 1e-7, this->getLongitude() * 1e-7, pointB.getLatitude() * 1e-7, pointB.getLongitude() * 1e-7); } // Find bearing from point to passed in point -int32_t GeoCoord::bearingTo(GeoCoord pointB) { +int32_t GeoCoord::bearingTo(const GeoCoord& pointB) { return bearing(this->getLatitude() * 1e-7, this->getLongitude() * 1e-7, pointB.getLatitude() * 1e-7, pointB.getLongitude() * 1e-7); } diff --git a/src/gps/GeoCoord.h b/src/gps/GeoCoord.h index a2ac56d74..02980ea05 100644 --- a/src/gps/GeoCoord.h +++ b/src/gps/GeoCoord.h @@ -119,8 +119,8 @@ class GeoCoord { static float rangeMetersToRadians(double range_meters); // Point to point conversions - int32_t distanceTo(GeoCoord pointB); - int32_t bearingTo(GeoCoord pointB); + int32_t distanceTo(const GeoCoord& pointB); + int32_t bearingTo(const GeoCoord& pointB); std::shared_ptr pointAtDistance(double bearing, double range); // Lat lon alt getters diff --git a/src/gps/UBloxGPS.h b/src/gps/UBloxGPS.h index c2521df23..3d940832f 100644 --- a/src/gps/UBloxGPS.h +++ b/src/gps/UBloxGPS.h @@ -54,7 +54,7 @@ class UBloxGPS : public GPS * @return true if we've acquired a new location */ virtual bool lookForLocation() override; - virtual bool hasLock(); + virtual bool hasLock() override; /// If possible force the GPS into sleep/low power mode virtual void sleep() override; diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 768c3875e..e679227f7 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -651,7 +651,6 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ static char distStr[20]; strcpy(distStr, "? km"); // might not have location data - float headingRadian; NodeInfo *ourNode = nodeDB.getNode(nodeDB.getNodeNum()); const char *fields[] = {username, distStr, signalStr, lastStr, NULL}; @@ -679,7 +678,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ // it. currently we don't do this and instead draw north up only. float bearingToOther = GeoCoord::bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); - headingRadian = bearingToOther - myHeading; + float headingRadian = bearingToOther - myHeading; drawNodeHeading(display, compassX, compassY, headingRadian); } } @@ -943,20 +942,20 @@ int32_t Screen::runOnce() void Screen::drawDebugInfoTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { - Screen *screen = reinterpret_cast(state->userData); - screen->debugInfo.drawFrame(display, state, x, y); + Screen *screen2 = reinterpret_cast(state->userData); + screen2->debugInfo.drawFrame(display, state, x, y); } void Screen::drawDebugInfoSettingsTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { - Screen *screen = reinterpret_cast(state->userData); - screen->debugInfo.drawFrameSettings(display, state, x, y); + Screen *screen2 = reinterpret_cast(state->userData); + screen2->debugInfo.drawFrameSettings(display, state, x, y); } void Screen::drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { - Screen *screen = reinterpret_cast(state->userData); - screen->debugInfo.drawFrameWiFi(display, state, x, y); + Screen *screen2 = reinterpret_cast(state->userData); + screen2->debugInfo.drawFrameWiFi(display, state, x, y); } /* show a message that the SSL cert is being built diff --git a/src/input/RotaryEncoderInterruptBase.h b/src/input/RotaryEncoderInterruptBase.h index 2f2633870..72732261b 100644 --- a/src/input/RotaryEncoderInterruptBase.h +++ b/src/input/RotaryEncoderInterruptBase.h @@ -22,7 +22,7 @@ class RotaryEncoderInterruptBase : private concurrency::OSThread { public: - RotaryEncoderInterruptBase( + explicit RotaryEncoderInterruptBase( const char *name); void init( uint8_t pinA, uint8_t pinB, uint8_t pinPress, diff --git a/src/memtest.cpp b/src/memtest.cpp index f7e3eb3e8..d5d073998 100644 --- a/src/memtest.cpp +++ b/src/memtest.cpp @@ -247,7 +247,7 @@ static int mem_test(uint32_t *_start, size_t len, bool doRead = true, bool doWri { volatile uint32_t *addr; volatile uint32_t *start = (volatile uint32_t *)_start; - volatile uint32_t *end = start + len / sizeof(uint32_t); + const volatile uint32_t *end = start + len / sizeof(uint32_t); uint32_t pattern = 0; uint32_t val; uint32_t readback; @@ -315,4 +315,4 @@ void doMemTest() assert(0); // FIXME report error better iter++; -} \ No newline at end of file +} diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 37fa0d548..d757fdb33 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -102,7 +102,7 @@ void Channels::initDefaultChannel(ChannelIndex chIndex) CryptoKey Channels::getKey(ChannelIndex chIndex) { Channel &ch = getByIndex(chIndex); - ChannelSettings &channelSettings = ch.settings; + const ChannelSettings &channelSettings = ch.settings; assert(ch.has_settings); CryptoKey k; @@ -206,7 +206,7 @@ void Channels::setChannel(const Channel &c) const char *Channels::getName(size_t chIndex) { // Convert the short "" representation for Default into a usable string - ChannelSettings &channelSettings = getByIndex(chIndex).settings; + const ChannelSettings &channelSettings = getByIndex(chIndex).settings; const char *channelName = channelSettings.name; if (!*channelName) { // emptystring // Per mesh.proto spec, if bandwidth is specified we must ignore modemConfig enum, we assume that in that case diff --git a/src/mesh/Channels.h b/src/mesh/Channels.h index eb8422cb5..5c5af0ec2 100644 --- a/src/mesh/Channels.h +++ b/src/mesh/Channels.h @@ -26,9 +26,12 @@ class Channels ChannelIndex activeChannelIndex = 0; /// the precomputed hashes for each of our channels, or -1 for invalid - int16_t hashes[MAX_NUM_CHANNELS]; + int16_t hashes[MAX_NUM_CHANNELS] = {}; public: + + Channels() {} + /// Well known channel names static const char *adminChannel, *gpioChannel, *serialChannel; @@ -134,4 +137,4 @@ class Channels }; /// Singleton channel table -extern Channels channels; \ No newline at end of file +extern Channels channels; diff --git a/src/mesh/MeshPacketQueue.h b/src/mesh/MeshPacketQueue.h index 2c869db43..c74addf4e 100644 --- a/src/mesh/MeshPacketQueue.h +++ b/src/mesh/MeshPacketQueue.h @@ -18,7 +18,7 @@ class MeshPacketQueue bool replaceLowerPriorityPacket(MeshPacket *mp); public: - MeshPacketQueue(size_t _maxLen); + explicit MeshPacketQueue(size_t _maxLen); /** enqueue a packet, return false if full */ bool enqueue(MeshPacket *p); @@ -30,4 +30,4 @@ class MeshPacketQueue /** Attempt to find and remove a packet from this queue. Returns the packet which was removed from the queue */ MeshPacket *remove(NodeNum from, PacketId id); -}; \ No newline at end of file +}; diff --git a/src/mesh/RadioLibRF95.h b/src/mesh/RadioLibRF95.h index d6aeb541a..519554302 100644 --- a/src/mesh/RadioLibRF95.h +++ b/src/mesh/RadioLibRF95.h @@ -16,7 +16,7 @@ class RadioLibRF95: public SX1278 { \param mod Instance of Module that will be used to communicate with the %LoRa chip. */ - RadioLibRF95(Module* mod); + explicit RadioLibRF95(Module* mod); // basic methods diff --git a/src/mesh/ReliableRouter.h b/src/mesh/ReliableRouter.h index 52e9b5af9..3f89dcbd6 100644 --- a/src/mesh/ReliableRouter.h +++ b/src/mesh/ReliableRouter.h @@ -13,7 +13,7 @@ struct GlobalPacketId { bool operator==(const GlobalPacketId &p) const { return node == p.node && id == p.id; } - GlobalPacketId(const MeshPacket *p) + explicit GlobalPacketId(const MeshPacket *p) { node = getFrom(p); id = p->id; @@ -45,7 +45,7 @@ struct PendingPacket { bool wantRoute = false; PendingPacket() {} - PendingPacket(MeshPacket *p); + explicit PendingPacket(MeshPacket *p); }; class GlobalPacketIdHashFunction diff --git a/src/mesh/TypedQueue.h b/src/mesh/TypedQueue.h index ad8bbed58..d923a40b0 100644 --- a/src/mesh/TypedQueue.h +++ b/src/mesh/TypedQueue.h @@ -19,9 +19,8 @@ template class TypedQueue concurrency::OSThread *reader = NULL; public: - explicit TypedQueue(int maxElements) + explicit TypedQueue(int maxElements) : h(xQueueCreate(maxElements, sizeof(T))) { - h = xQueueCreate(maxElements, sizeof(T)); assert(h); } diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index d9d2ca6b4..1f376390b 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -130,8 +130,8 @@ static void taskCreateCert(void *parameter) void createSSLCert() { - bool runLoop = false; if (isWifiAvailable() && !isCertReady) { + bool runLoop = false; // Create a new process just to handle creating the cert. // This is a workaround for Bug: https://github.com/fhessel/esp32_https_server/issues/48 diff --git a/src/mesh/wifi/WiFiServerAPI.h b/src/mesh/wifi/WiFiServerAPI.h index 416c94371..272dd29ac 100644 --- a/src/mesh/wifi/WiFiServerAPI.h +++ b/src/mesh/wifi/WiFiServerAPI.h @@ -13,7 +13,7 @@ class WiFiServerAPI : public StreamAPI WiFiClient client; public: - WiFiServerAPI(WiFiClient &_client); + explicit WiFiServerAPI(WiFiClient &_client); virtual ~WiFiServerAPI(); diff --git a/src/plugins/ExternalNotificationPlugin.cpp b/src/plugins/ExternalNotificationPlugin.cpp index 8b25d77ed..122c77be8 100644 --- a/src/plugins/ExternalNotificationPlugin.cpp +++ b/src/plugins/ExternalNotificationPlugin.cpp @@ -156,13 +156,12 @@ ProcessMessage ExternalNotificationPlugin::handleReceived(const MeshPacket &mp) if (radioConfig.preferences.ext_notification_plugin_enabled) { - auto &p = mp.decoded; - if (getFrom(&mp) != nodeDB.getNodeNum()) { // TODO: This may be a problem if messages are sent in unicide, but I'm not sure if it will. // Need to know if and how this could be a problem. if (radioConfig.preferences.ext_notification_plugin_alert_bell) { + auto &p = mp.decoded; DEBUG_MSG("externalNotificationPlugin - Notification Bell\n"); for (int i = 0; i < p.payload.size; i++) { if (p.payload.bytes[i] == ASCII_BELL) { diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index 0a3a412d7..4292b26f2 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -145,9 +145,9 @@ int32_t PositionPlugin::runOnce() DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", node->position.pos_timestamp, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies); } else if (radioConfig.preferences.position_broadcast_smart == true) { - NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position + NodeInfo *node2 = service.refreshMyNodeInfo(); // should guarantee there is now a position - if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) { + if (node2->has_position && (node2->position.latitude_i != 0 || node2->position.longitude_i != 0)) { // The minimum distance to travel before we are able to send a new position packet. const uint32_t distanceTravelMinimum = 30; @@ -173,7 +173,7 @@ int32_t PositionPlugin::runOnce() bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; - DEBUG_MSG("Sending smart pos@%x:6 to mesh (wantReplies=%d, dt=%d, tt=%d)\n", node->position.pos_timestamp, requestReplies, distanceTravel, timeTravel); + DEBUG_MSG("Sending smart pos@%x:6 to mesh (wantReplies=%d, dt=%d, tt=%d)\n", node2->position.pos_timestamp, requestReplies, distanceTravel, timeTravel); sendOurPosition(NODENUM_BROADCAST, requestReplies); /* Update lastGpsSend to now. This means if the device is stationary, then @@ -185,4 +185,4 @@ int32_t PositionPlugin::runOnce() } return 5000; // to save power only wake for our callback occasionally -} \ No newline at end of file +} diff --git a/src/plugins/RemoteHardwarePlugin.cpp b/src/plugins/RemoteHardwarePlugin.cpp index 60ef816d9..55f22ccba 100644 --- a/src/plugins/RemoteHardwarePlugin.cpp +++ b/src/plugins/RemoteHardwarePlugin.cpp @@ -79,9 +79,9 @@ bool RemoteHardwarePlugin::handleReceivedProtobuf(const MeshPacket &req, Hardwar HardwareMessage r = HardwareMessage_init_default; r.typ = HardwareMessage_Type_READ_GPIOS_REPLY; r.gpio_value = res; - MeshPacket *p = allocDataProtobuf(r); - setReplyTo(p, req); - myReply = p; + MeshPacket *p2 = allocDataProtobuf(r); + setReplyTo(p2, req); + myReply = p2; break; } @@ -132,4 +132,4 @@ int32_t RemoteHardwarePlugin::runOnce() } return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg) -} \ No newline at end of file +} diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index f970f86dc..24535793e 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -179,7 +179,7 @@ uint32_t StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to) void StoreForwardPlugin::historyAdd(const MeshPacket &mp) { - auto &p = mp.decoded; + const auto &p = mp.decoded; this->packetHistory[this->packetHistoryCurrent].time = millis(); this->packetHistory[this->packetHistoryCurrent].to = mp.to; @@ -247,14 +247,14 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) DEBUG_MSG("--- S&F Received something\n"); - auto &p = mp.decoded; - // The router node should not be sending messages as a client. if (getFrom(&mp) != nodeDB.getNodeNum()) { if (mp.decoded.portnum == PortNum_TEXT_MESSAGE_APP) { DEBUG_MSG("Packet came from - PortNum_TEXT_MESSAGE_APP\n"); + auto &p = mp.decoded; + if ((p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') && (p.payload.bytes[2] == 0x00)) { DEBUG_MSG("--- --- --- Request to send\n"); diff --git a/src/portduino/CrossPlatformCryptoEngine.cpp b/src/portduino/CrossPlatformCryptoEngine.cpp index b728c8c57..b0f6fecdf 100644 --- a/src/portduino/CrossPlatformCryptoEngine.cpp +++ b/src/portduino/CrossPlatformCryptoEngine.cpp @@ -50,9 +50,9 @@ class CrossPlatformCryptoEngine : public CryptoEngine virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - uint8_t stream_block[16]; + //uint8_t stream_block[16]; static uint8_t scratch[MAX_BLOCKSIZE]; - size_t nc_off = 0; + //size_t nc_off = 0; // DEBUG_MSG("ESP32 encrypt!\n"); initNonce(fromNode, packetNum); diff --git a/suppressions.txt b/suppressions.txt index d0deeb377..d05ed57c9 100644 --- a/suppressions.txt +++ b/suppressions.txt @@ -4,6 +4,14 @@ assertWithSideEffect // TODO: need to come back to these duplInheritedMember +// TODO: +// "Using memset() on struct which contains a floating point number." +// tried: +// if (std::is_floating_point::value) { +// p = 0; +// in src/mesh/MemoryPool.h +memsetClassFloat + // no real downside/harm in these unusedFunction unusedPrivateFunction From 6883bc7afc0c3b66a1649abf534118149d3d3594 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 24 Jan 2022 19:58:07 +0000 Subject: [PATCH 4/6] fix more warnings; add to CI; suppress some warnings --- .github/workflows/main.yml | 7 +++++++ bin/check-all.sh | 15 +++++++++------ platformio.ini | 4 ++-- src/PowerFSM.cpp | 3 +-- src/esp32/SimpleAllocator.h | 2 +- src/mesh/MemoryPool.h | 2 +- src/mesh/PhoneAPI.h | 2 +- src/mesh/http/ContentHandler.h | 2 +- src/mesh/wifi/WiFiServerAPI.h | 2 +- src/nimble/NimbleBluetoothAPI.h | 6 +++--- src/plugins/esp32/RangeTestPlugin.cpp | 2 +- src/plugins/esp32/StoreForwardPlugin.cpp | 7 ++++--- src/plugins/esp32/StoreForwardPlugin.h | 10 +++++----- suppressions.txt | 14 ++++++++++++++ 14 files changed, 51 insertions(+), 27 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0425f13fa..78f7b6f1c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,6 +24,10 @@ jobs: with: submodules: 'recursive' + - name: Install cppcheck + run: | + apt-get install -y cppcheck + - name: Setup Python uses: actions/setup-python@v2 with: @@ -88,6 +92,9 @@ jobs: # - name: Build for wisblock RAK4631 # run: platformio run -e rak4631 + - name: Check everything + run: bin/check-all.sh + - name: Build everything run: bin/build-all.sh diff --git a/bin/check-all.sh b/bin/check-all.sh index f54ff03e4..90413bb25 100755 --- a/bin/check-all.sh +++ b/bin/check-all.sh @@ -9,11 +9,14 @@ VERSION=`bin/buildinfo.py long` # The shell vars the build tool expects to find export APP_VERSION=$VERSION -# only check high and medium in our source -# TODO: only doing tbeam (to start; add all/more later) -#pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" -e tbeam --skip-packages --severity=medium --severity=high --pattern="src/" -pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" -e tbeam --skip-packages --pattern="src/" -return_code=$? +if [[ $# -gt 0 ]]; then + # can override which environment by passing arg + BOARDS="-e $1" +else + BOARDS="-e tlora-v2 -e tlora-v1 -e tlora_v1_3 -e tlora-v2-1-1.6 -e tbeam -e heltec-v1 -e heltec-v2.0 -e heltec-v2.1 -e tbeam0.7 -e meshtastic-diy-v1 -e rak4631_5005 -e rak4631_19003 -e t-echo" +fi +#echo "BOARDS:${BOARDS}" +pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" $BOARDS --skip-packages --pattern="src/" +#return_code=$? # TODO: not sure why return_code is 0 -echo "return_code:${return_code}" diff --git a/platformio.ini b/platformio.ini index ca6c06a0d..98a9a7733 100644 --- a/platformio.ini +++ b/platformio.ini @@ -84,9 +84,9 @@ lib_deps = SPI https://github.com/geeksville/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3 PubSubClient - + ; Used for the code analysis in PIO Home / Inspect -check_tool = cppcheck, clangtidy +check_tool = cppcheck check_skip_packages = yes ; Common settings for conventional (non Portduino) Arduino targets diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 3316b208e..095f844b5 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -63,7 +63,6 @@ static void lsIdle() // DEBUG_MSG("lsIdle begin ls_secs=%u\n", getPref_ls_secs()); #ifndef NO_ESP32 - esp_sleep_source_t wakeCause2 = ESP_SLEEP_WAKEUP_UNDEFINED; // Do we have more sleeping to do? if (secsSlept < getPref_ls_secs()) { @@ -73,7 +72,7 @@ static void lsIdle() // If some other service would stall sleep, don't let sleep happen yet if (doPreflightSleep()) { setLed(false); // Never leave led on while in light sleep - wakeCause2 = doLightSleep(sleepTime * 1000LL); + esp_sleep_source_t wakeCause2 = doLightSleep(sleepTime * 1000LL); switch (wakeCause2) { case ESP_SLEEP_WAKEUP_TIMER: diff --git a/src/esp32/SimpleAllocator.h b/src/esp32/SimpleAllocator.h index a529c1a50..5fdb6738c 100644 --- a/src/esp32/SimpleAllocator.h +++ b/src/esp32/SimpleAllocator.h @@ -37,6 +37,6 @@ void *operator new(size_t size, SimpleAllocator &p); */ class AllocatorScope { public: - AllocatorScope(SimpleAllocator &a); + explicit AllocatorScope(SimpleAllocator &a); ~AllocatorScope(); }; diff --git a/src/mesh/MemoryPool.h b/src/mesh/MemoryPool.h index de97fe259..84cac7eff 100644 --- a/src/mesh/MemoryPool.h +++ b/src/mesh/MemoryPool.h @@ -99,7 +99,7 @@ template class MemoryPool : public Allocator ~MemoryPool() { delete[] buf; } /// Return a buffer for use by others - virtual void release(T *p) + void release(T *p) { assert(p >= buf && (size_t)(p - buf) < diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 67b52d20a..5a4ca381d 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -58,7 +58,7 @@ class PhoneAPI // Call this when the client drops the connection, resets the state to STATE_SEND_NOTHING // Unregisters our observer. A closed connection **can** be reopened by calling init again. - virtual void close(); + void close(); /** * Handle a ToRadio protobuf diff --git a/src/mesh/http/ContentHandler.h b/src/mesh/http/ContentHandler.h index 541fcff39..c3babdd72 100644 --- a/src/mesh/http/ContentHandler.h +++ b/src/mesh/http/ContentHandler.h @@ -36,7 +36,7 @@ class HttpAPI : public PhoneAPI protected: /// Check the current underlying physical link to see if the client is currently connected - virtual bool checkIsConnected() { return true; } // FIXME, be smarter about this + virtual bool checkIsConnected() override { return true; } // FIXME, be smarter about this }; diff --git a/src/mesh/wifi/WiFiServerAPI.h b/src/mesh/wifi/WiFiServerAPI.h index 272dd29ac..d3750e8c0 100644 --- a/src/mesh/wifi/WiFiServerAPI.h +++ b/src/mesh/wifi/WiFiServerAPI.h @@ -18,7 +18,7 @@ class WiFiServerAPI : public StreamAPI virtual ~WiFiServerAPI(); /// override close to also shutdown the TCP link - virtual void close() override; + virtual void close(); protected: /// We override this method to prevent publishing EVENT_SERIAL_CONNECTED/DISCONNECTED for wifi links (we want the board to diff --git a/src/nimble/NimbleBluetoothAPI.h b/src/nimble/NimbleBluetoothAPI.h index e2260ba4d..4df2498b8 100644 --- a/src/nimble/NimbleBluetoothAPI.h +++ b/src/nimble/NimbleBluetoothAPI.h @@ -10,10 +10,10 @@ protected: /** * Subclasses can use this as a hook to provide custom notifications for their transport (i.e. bluetooth notifies) */ - virtual void onNowHasData(uint32_t fromRadioNum); + virtual void onNowHasData(uint32_t fromRadioNum) override; /// Check the current underlying physical link to see if the client is currently connected - virtual bool checkIsConnected(); + virtual bool checkIsConnected() override; }; -extern PhoneAPI *bluetoothPhoneAPI; \ No newline at end of file +extern PhoneAPI *bluetoothPhoneAPI; diff --git a/src/plugins/esp32/RangeTestPlugin.cpp b/src/plugins/esp32/RangeTestPlugin.cpp index aa1881326..9ce009931 100644 --- a/src/plugins/esp32/RangeTestPlugin.cpp +++ b/src/plugins/esp32/RangeTestPlugin.cpp @@ -87,8 +87,8 @@ int32_t RangeTestPlugin::runOnce() DEBUG_MSG("Range Test Plugin - Disabled\n"); } - return (INT32_MAX); #endif + return (INT32_MAX); } MeshPacket *RangeTestPluginRadio::allocReply() diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index 24535793e..f556359f2 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -267,9 +267,10 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) } } else if ((p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') && (p.payload.bytes[2] == 'm') && (p.payload.bytes[3] == 0x00)) { - strcpy(this->routerMessage, "01234567890123456789012345678901234567890123456789012345678901234567890123456789" - "01234567890123456789012345678901234567890123456789012345678901234567890123456789" - "01234567890123456789012345678901234567890123456789012345678901234567890123456"); + strlcpy(this->routerMessage, "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456", + sizeof(this->routerMessage)); storeForwardPlugin->sendMessage(getFrom(&mp), this->routerMessage); } else { diff --git a/src/plugins/esp32/StoreForwardPlugin.h b/src/plugins/esp32/StoreForwardPlugin.h index 110b0a75a..2514b89bf 100644 --- a/src/plugins/esp32/StoreForwardPlugin.h +++ b/src/plugins/esp32/StoreForwardPlugin.h @@ -22,16 +22,16 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea { // bool firstTime = 1; bool busy = 0; - uint32_t busyTo; - char routerMessage[Constants_DATA_PAYLOAD_LEN]; + uint32_t busyTo = 0; + char routerMessage[Constants_DATA_PAYLOAD_LEN] = {0}; uint32_t receivedRecord[50][2] = {{0}}; - PacketHistoryStruct *packetHistory; + PacketHistoryStruct *packetHistory = 0; uint32_t packetHistoryCurrent = 0; - PacketHistoryStruct *packetHistoryTXQueue; - uint32_t packetHistoryTXQueue_size; + PacketHistoryStruct *packetHistoryTXQueue = 0; + uint32_t packetHistoryTXQueue_size = 0; uint32_t packetHistoryTXQueue_index = 0; uint32_t packetTimeMax = 2000; diff --git a/suppressions.txt b/suppressions.txt index d05ed57c9..cdf858753 100644 --- a/suppressions.txt +++ b/suppressions.txt @@ -12,6 +12,8 @@ duplInheritedMember // in src/mesh/MemoryPool.h memsetClassFloat +knownConditionTrueFalse + // no real downside/harm in these unusedFunction unusedPrivateFunction @@ -19,6 +21,18 @@ unusedPrivateFunction // most likely due to a cppcheck configuration issue (like missing an include) syntaxError +// try to quiet a few +//useInitializationList:src/main.cpp +useInitializationList + +//unreadVariable:src/graphics/Screen.cpp +unreadVariable + +redundantInitialization + +//cstyleCast:src/mesh/MemoryPool.h:71 +cstyleCast + // ignore stuff that is not ours *:.pio/* *:*/libdeps/* From 437aa1e9af5bfad8b1dab2bb2a8c80f477a40c65 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 24 Jan 2022 20:04:31 +0000 Subject: [PATCH 5/6] make check a different job on ci --- .github/workflows/main.yml | 51 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 78f7b6f1c..98a563b94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,15 +7,8 @@ on: branches: [ master ] jobs: - # setup: - # runs-on: ubuntu-latest - # steps: - - # - name: Startup - # run: echo "No action setup currently needed, skipping..." - ci-build: - # needs: setup + ci-check: runs-on: ubuntu-latest steps: @@ -26,7 +19,7 @@ jobs: - name: Install cppcheck run: | - apt-get install -y cppcheck + sudo apt-get install -y cppcheck - name: Setup Python uses: actions/setup-python@v2 @@ -40,9 +33,40 @@ jobs: path: ~/.cache/pip key: ${{ runner.os }}-pip - #- name: Install linux apt packages - # run: | - # sudo apt-get install -y libgpiod-dev + - name: Upgrade python tools and install platformio + run: | + python -m pip install --upgrade pip + pip install -U platformio + + - name: Upgrade platformio + run: | + pio upgrade + + - name: Check everything + run: bin/check-all.sh + + + + ci-build: + runs-on: ubuntu-latest + steps: + + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Cache python libs + uses: actions/cache@v1 + id: cache-pip # needed in if test + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip - name: Upgrade python tools # We actually want to run this every time @@ -92,9 +116,6 @@ jobs: # - name: Build for wisblock RAK4631 # run: platformio run -e rak4631 - - name: Check everything - run: bin/check-all.sh - - name: Build everything run: bin/build-all.sh From 3d718f45d5020f6c985687ae0c673e679d454ee0 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 24 Jan 2022 21:35:24 +0000 Subject: [PATCH 6/6] fail the build if we have any cppcheck warnings --- bin/check-all.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/check-all.sh b/bin/check-all.sh index 90413bb25..3cf8fa4bf 100755 --- a/bin/check-all.sh +++ b/bin/check-all.sh @@ -17,6 +17,4 @@ else fi #echo "BOARDS:${BOARDS}" -pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" $BOARDS --skip-packages --pattern="src/" -#return_code=$? -# TODO: not sure why return_code is 0 +pio check --flags "-DAPP_VERSION=${APP_VERSION} --suppressions-list=suppressions.txt" $BOARDS --skip-packages --pattern="src/" --fail-on-defect=low --fail-on-defect=medium --fail-on-defect=high