From 13ad5245381f936bea47d8b8bc0ace142b585108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 3 May 2024 15:10:57 +0200 Subject: [PATCH] make clang-format happy again. Also fix assorted variable shrouding and logic bleeps --- src/gps/GPS.cpp | 6 +++--- src/mesh/MeshService.cpp | 4 +--- src/mesh/NodeDB.cpp | 2 +- src/mesh/ProtobufModule.h | 3 +-- src/modules/NeighborInfoModule.cpp | 3 +-- src/modules/PositionModule.cpp | 2 +- src/modules/Telemetry/Sensor/RCWL9620Sensor.h | 12 ++++++------ src/platform/portduino/PortduinoGlue.cpp | 12 ++++++------ src/platform/stm32wl/LittleFS_File.cpp | 4 ++-- 9 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 1c1aac7ad..deea076b2 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -62,10 +62,10 @@ void GPS::CASChecksum(uint8_t *message, size_t length) // Iterate over the payload as a series of uint32_t's and // accumulate the cksum - uint32_t *payload = (uint32_t *)(message + 6); + uint32_t const *payload = (uint32_t *)(message + 6); for (size_t i = 0; i < (length - 10) / 4; i++) { - uint32_t p = payload[i]; - cksum += p; + uint32_t pl = payload[i]; + cksum += pl; } // Place the checksum values in the message diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 66a2e6952..ddad211a6 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -192,9 +192,7 @@ void MeshService::handleToRadio(meshtastic_MeshPacket &p) return; } #endif - if (p.from != 0) { // We don't let phones assign nodenums to their sent messages - p.from = 0; - } + p.from = 0; // We don't let phones assign nodenums to their sent messages if (p.id == 0) p.id = generatePacketId(); // If the phone didn't supply one, then pick one diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 249db627e..906356e7c 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -56,7 +56,7 @@ meshtastic_OEMStore oemStore; bool meshtastic_DeviceState_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_iter_t *field) { if (ostream) { - std::vector *vec = (std::vector *)field->pData; + std::vector const *vec = (std::vector *)field->pData; for (auto item : *vec) { if (!pb_encode_tag_for_field(ostream, field)) return false; diff --git a/src/mesh/ProtobufModule.h b/src/mesh/ProtobufModule.h index a2e89e98a..0d3da9568 100644 --- a/src/mesh/ProtobufModule.h +++ b/src/mesh/ProtobufModule.h @@ -95,12 +95,11 @@ template class ProtobufModule : protected SinglePortModule */ virtual void alterReceived(meshtastic_MeshPacket &mp) override { - auto &p = mp.decoded; - T scratch; T *decoded = NULL; if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.decoded.portnum == ourPortNum) { memset(&scratch, 0, sizeof(scratch)); + auto &p = mp.decoded; if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, fields, &scratch)) { decoded = &scratch; } else { diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index 8c8135deb..3925bea9a 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -116,9 +116,8 @@ Will be used for broadcast. */ int32_t NeighborInfoModule::runOnce() { - bool requestReplies = false; if (airTime->isTxAllowedChannelUtil(true) && airTime->isTxAllowedAirUtil()) { - sendNeighborInfo(NODENUM_BROADCAST, requestReplies); + sendNeighborInfo(NODENUM_BROADCAST, false); } return Default::getConfiguredOrDefaultMs(moduleConfig.neighbor_info.update_interval, default_broadcast_interval_secs); } diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 7c459dc35..9986f860d 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -343,7 +343,7 @@ int32_t PositionModule::runOnce() // The minimum time (in seconds) that would pass before we are able to send a new position packet. auto smartPosition = getDistanceTraveledSinceLastSend(node->position); - uint32_t msSinceLastSend = now - lastGpsSend; + msSinceLastSend = now - lastGpsSend; if (smartPosition.hasTraveledOverThreshold && Throttle::execute( diff --git a/src/modules/Telemetry/Sensor/RCWL9620Sensor.h b/src/modules/Telemetry/Sensor/RCWL9620Sensor.h index 4fb2aec2d..b78066f5c 100644 --- a/src/modules/Telemetry/Sensor/RCWL9620Sensor.h +++ b/src/modules/Telemetry/Sensor/RCWL9620Sensor.h @@ -5,15 +5,15 @@ class RCWL9620Sensor : public TelemetrySensor { private: - uint8_t _addr; - TwoWire *_wire; - uint8_t _scl; - uint8_t _sda; - uint8_t _speed; + uint8_t _addr = 0x57; + TwoWire *_wire = &Wire; + uint8_t _scl = -1; + uint8_t _sda = -1; + uint32_t _speed = 200000UL; protected: virtual void setup() override; - void begin(TwoWire *wire = &Wire, uint8_t addr = 0x57, uint8_t sda = -1, uint8_t scl = -1, uint32_t speed = 200000L); + void begin(TwoWire *wire = &Wire, uint8_t addr = 0x57, uint8_t sda = -1, uint8_t scl = -1, uint32_t speed = 200000UL); float getDistance(); public: diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 35cee2d2f..edb81261c 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -75,7 +75,7 @@ void portduinoSetup() { printf("Setting up Meshtastic on Portduino...\n"); int max_GPIO = 0; - configNames GPIO_lines[] = {cs, + const configNames GPIO_lines[] = {cs, irq, busy, reset, @@ -103,7 +103,7 @@ void portduinoSetup() std::cout << "Using " << configPath << " as config file" << std::endl; try { yamlConfig = YAML::LoadFile(configPath); - } catch (YAML::Exception e) { + } catch (YAML::Exception &e) { std::cout << "Could not open " << configPath << " because of error: " << e.what() << std::endl; exit(EXIT_FAILURE); } @@ -111,7 +111,7 @@ void portduinoSetup() std::cout << "Using local config.yaml as config file" << std::endl; try { yamlConfig = YAML::LoadFile("config.yaml"); - } catch (YAML::Exception e) { + } catch (YAML::Exception &e) { std::cout << "*** Exception " << e.what() << std::endl; exit(EXIT_FAILURE); } @@ -119,7 +119,7 @@ void portduinoSetup() std::cout << "Using /etc/meshtasticd/config.yaml as config file" << std::endl; try { yamlConfig = YAML::LoadFile("/etc/meshtasticd/config.yaml"); - } catch (YAML::Exception e) { + } catch (YAML::Exception &e) { std::cout << "*** Exception " << e.what() << std::endl; exit(EXIT_FAILURE); } @@ -276,7 +276,7 @@ void portduinoSetup() settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(200); - } catch (YAML::Exception e) { + } catch (YAML::Exception &e) { std::cout << "*** Exception " << e.what() << std::endl; exit(EXIT_FAILURE); } @@ -347,7 +347,7 @@ void portduinoSetup() return; } -int initGPIOPin(int pinNum, std::string gpioChipName) +int initGPIOPin(int pinNum, const std::string& gpioChipName) { std::string gpio_name = "GPIO" + std::to_string(pinNum); try { diff --git a/src/platform/stm32wl/LittleFS_File.cpp b/src/platform/stm32wl/LittleFS_File.cpp index cffb924e1..548a3d300 100644 --- a/src/platform/stm32wl/LittleFS_File.cpp +++ b/src/platform/stm32wl/LittleFS_File.cpp @@ -186,9 +186,9 @@ int File::available(void) _fs->_lockFS(); if (!this->_is_dir) { - uint32_t size = lfs_file_size(_fs->_getFS(), _file); + uint32_t fsize = lfs_file_size(_fs->_getFS(), _file); uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); - ret = size - pos; + ret = fsize - pos; } _fs->_unlockFS();