From d685682dd918158d2f30b43c692c9c48e674a7ed Mon Sep 17 00:00:00 2001 From: Joar Svensson Date: Fri, 26 Nov 2021 13:28:20 +0100 Subject: [PATCH 1/9] Define battery pin --- src/configuration.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/configuration.h b/src/configuration.h index 7eed800d0..4e73531db 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -327,6 +327,8 @@ along with this program. If not, see . #define GPS_RX_PIN 36 #define GPS_TX_PIN 37 +#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage + #define I2C_SDA 4 // I2C pins for this board #define I2C_SCL 15 From c5f210384f1a1f789ddc4bb54315a7bec7ec673a Mon Sep 17 00:00:00 2001 From: Ryan Tolboom Date: Fri, 26 Nov 2021 15:09:16 -0500 Subject: [PATCH 2/9] add SSL notification at boot --- src/graphics/Screen.cpp | 21 +++++++++++++++++++++ src/graphics/Screen.h | 3 +++ src/mesh/http/WebServer.cpp | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 38f22b1d3..f4dae5e51 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -147,6 +147,17 @@ static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int1 drawIconScreen(region, display, state, x, y); } +// Used on boot when a certificate is being created +static void drawSSLScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ + display->setTextAlignment(TEXT_ALIGN_CENTER); + display->setFont(FONT_SMALL); + display->drawString(64 + x, y, "Creating SSL certificate"); + + display->setFont(FONT_SMALL); + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait..."); +} + #ifdef HAS_EINK /// Used on eink displays while in deep sleep static void drawSleepScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) @@ -898,6 +909,16 @@ void Screen::drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiStat screen->debugInfo.drawFrameWiFi(display, state, x, y); } +/* show a message that the SSL cert is being built + * it is expected that this will be used during the boot phase */ +void Screen::setSSLFrames() +{ + DEBUG_MSG("showing SSL frames\n"); + static FrameCallback sslFrames[] = {drawSSLScreen}; + ui.setFrames(sslFrames, 1); + ui.update(); +} + // restore our regular frame list void Screen::setFrames() { diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 1c543dbf0..e4b9044c7 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -220,6 +220,9 @@ class Screen : public concurrency::OSThread /// Used to force (super slow) eink displays to draw critical frames void forceDisplay(); + /// Draws our SSL cert screen during boot (called from WebServer) + void setSSLFrames(); + protected: /// Updates the UI. // diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index 0f3ae5cd7..f9e2e99dc 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -1,3 +1,4 @@ +#include "main.h" #include "mesh/http/WebServer.h" #include "NodeDB.h" #include "mesh/http/WiFiAPClient.h" @@ -77,7 +78,7 @@ static void taskCreateCert(void *parameter) { prefs.begin("MeshtasticHTTPS", false); - // Delete the saved certs + // Delete the saved certs (used in debugging) if (0) { DEBUG_MSG("Deleting any saved SSL keys ...\n"); // prefs.clear(); @@ -166,11 +167,16 @@ void createSSLCert() NULL); /* Task handle. */ DEBUG_MSG("Waiting for SSL Cert to be generated.\n"); + int seconds = 0; while (!isCertReady) { DEBUG_MSG("."); delay(1000); yield(); esp_task_wdt_reset(); + seconds++; + if ((seconds == 3) && screen) { + screen->setSSLFrames(); + } } DEBUG_MSG("SSL Cert Ready!\n"); } From f75aac8ebfb127260f9dfcb41a6b589cb8a09309 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Fri, 26 Nov 2021 18:13:21 -0800 Subject: [PATCH 3/9] updating submodule to latest --- proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto b/proto index e24fa8c6e..1babd02e6 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit e24fa8c6edd46c2bf66005f45d2547ebd15887c1 +Subproject commit 1babd02e62553df83789bb28141fc623ac514ed4 From f6fde553630061836e10e894a927e89a39f47542 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Fri, 26 Nov 2021 18:25:08 -0800 Subject: [PATCH 4/9] Update protobufs with the latest from meshtastic-protobufs --- src/mesh/generated/admin.pb.h | 2 +- src/mesh/generated/deviceonly.pb.h | 2 +- src/mesh/generated/mesh.pb.h | 19 ++++++++++++++----- src/mesh/generated/radioconfig.pb.h | 11 +++++++---- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index ad07b358c..a2da87520 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -79,7 +79,7 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#define AdminMessage_size 420 +#define AdminMessage_size 423 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/deviceonly.pb.h b/src/mesh/generated/deviceonly.pb.h index 6b6c7406f..591c3cc2f 100644 --- a/src/mesh/generated/deviceonly.pb.h +++ b/src/mesh/generated/deviceonly.pb.h @@ -125,7 +125,7 @@ extern const pb_msgdesc_t ChannelFile_msg; /* Maximum encoded size of messages (where known) */ #define LegacyRadioConfig_size 4 #define LegacyRadioConfig_LegacyPreferences_size 2 -#define DeviceState_size 9000 +#define DeviceState_size 9594 #define ChannelFile_size 832 #ifdef __cplusplus diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 44013196e..94d9a73e7 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -198,6 +198,9 @@ typedef struct _User { HardwareModel hw_model; bool is_licensed; Team team; + uint32_t tx_power_dbm; + uint32_t ant_gain_dbi; + uint32_t ant_azimuth; } User; typedef PB_BYTES_ARRAY_T(256) MeshPacket_encrypted_t; @@ -306,7 +309,7 @@ extern "C" { /* Initializer values for message structs */ #define Position_init_default {0, 0, 0, 0, 0, _Position_LocSource_MIN, _Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define User_init_default {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN} +#define User_init_default {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN, 0, 0, 0} #define RouteDiscovery_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define Routing_init_default {0, {RouteDiscovery_init_default}} #define Data_init_default {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0} @@ -318,7 +321,7 @@ extern "C" { #define ToRadio_init_default {0, {MeshPacket_init_default}} #define ToRadio_PeerInfo_init_default {0, 0} #define Position_init_zero {0, 0, 0, 0, 0, _Position_LocSource_MIN, _Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define User_init_zero {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN} +#define User_init_zero {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN, 0, 0, 0} #define RouteDiscovery_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define Routing_init_zero {0, {RouteDiscovery_init_zero}} #define Data_init_zero {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0} @@ -387,6 +390,9 @@ extern "C" { #define User_hw_model_tag 6 #define User_is_licensed_tag 7 #define User_team_tag 8 +#define User_tx_power_dbm_tag 10 +#define User_ant_gain_dbi_tag 11 +#define User_ant_azimuth_tag 12 #define MeshPacket_from_tag 1 #define MeshPacket_to_tag 2 #define MeshPacket_channel_tag 3 @@ -454,7 +460,10 @@ X(a, STATIC, SINGULAR, STRING, short_name, 3) \ X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, macaddr, 4) \ X(a, STATIC, SINGULAR, UENUM, hw_model, 6) \ X(a, STATIC, SINGULAR, BOOL, is_licensed, 7) \ -X(a, STATIC, SINGULAR, UENUM, team, 8) +X(a, STATIC, SINGULAR, UENUM, team, 8) \ +X(a, STATIC, SINGULAR, UINT32, tx_power_dbm, 10) \ +X(a, STATIC, SINGULAR, UINT32, ant_gain_dbi, 11) \ +X(a, STATIC, SINGULAR, UINT32, ant_azimuth, 12) #define User_CALLBACK NULL #define User_DEFAULT NULL @@ -595,12 +604,12 @@ extern const pb_msgdesc_t ToRadio_PeerInfo_msg; /* Maximum encoded size of messages (where known) */ #define Position_size 153 -#define User_size 78 +#define User_size 96 #define RouteDiscovery_size 40 #define Routing_size 42 #define Data_size 260 #define MeshPacket_size 309 -#define NodeInfo_size 252 +#define NodeInfo_size 270 #define MyNodeInfo_size 101 #define LogRecord_size 81 #define FromRadio_size 318 diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index c92072205..2381e60b9 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -101,6 +101,7 @@ typedef struct _RadioConfig_UserPreferences { bool wifi_ap_mode; RegionCode region; ChargeCurrent charge_current; + bool position_broadcast_smart; LocationSharing location_share; GpsOperation gps_operation; uint32_t gps_update_interval; @@ -190,9 +191,9 @@ extern "C" { /* Initializer values for message structs */ #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 @@ -210,6 +211,7 @@ extern "C" { #define RadioConfig_UserPreferences_wifi_ap_mode_tag 14 #define RadioConfig_UserPreferences_region_tag 15 #define RadioConfig_UserPreferences_charge_current_tag 16 +#define RadioConfig_UserPreferences_position_broadcast_smart_tag 17 #define RadioConfig_UserPreferences_location_share_tag 32 #define RadioConfig_UserPreferences_gps_operation_tag 33 #define RadioConfig_UserPreferences_gps_update_interval_tag 34 @@ -279,6 +281,7 @@ X(a, STATIC, SINGULAR, STRING, wifi_password, 13) \ X(a, STATIC, SINGULAR, BOOL, wifi_ap_mode, 14) \ X(a, STATIC, SINGULAR, UENUM, region, 15) \ X(a, STATIC, SINGULAR, UENUM, charge_current, 16) \ +X(a, STATIC, SINGULAR, BOOL, position_broadcast_smart, 17) \ X(a, STATIC, SINGULAR, UENUM, location_share, 32) \ X(a, STATIC, SINGULAR, UENUM, gps_operation, 33) \ X(a, STATIC, SINGULAR, UINT32, gps_update_interval, 34) \ @@ -334,8 +337,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg; #define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg /* Maximum encoded size of messages (where known) */ -#define RadioConfig_size 417 -#define RadioConfig_UserPreferences_size 414 +#define RadioConfig_size 420 +#define RadioConfig_UserPreferences_size 417 #ifdef __cplusplus } /* extern "C" */ From 3ec508169a296d110b215bc8e5880d1f6e4a9b77 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Fri, 26 Nov 2021 19:12:00 -0800 Subject: [PATCH 5/9] Implementation of smart positioning #934 Initial check in for https://github.com/meshtastic/Meshtastic-device/issues/934 --- src/plugins/PositionPlugin.cpp | 32 +++++++++++++++++++++++++++ src/plugins/PositionPlugin.h | 4 ++++ src/plugins/esp32/RangeTestPlugin.cpp | 2 ++ 3 files changed, 38 insertions(+) diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index 509750c83..a64ead3b3 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -4,6 +4,8 @@ #include "NodeDB.h" #include "RTC.h" #include "Router.h" +#include "gps/GeoCoord.h" + PositionPlugin *positionPlugin; @@ -144,6 +146,9 @@ int32_t PositionPlugin::runOnce() lastGpsSend = now; + lastGpsLatitude = node->position.latitude_i; + lastGpsLongitude = node->position.longitude_i; + // If we changed channels, ask everyone else for their latest info bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; @@ -151,6 +156,33 @@ 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) { + // radioConfig.preferences.position_broadcast_smart + //NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position + + if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0) ) { + float distance = GeoCoord::latLongToMeter(lastGpsLatitude * 1e-7, lastGpsLongitude * 1e-7, + node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); + + // Please don't change this value. This accomodates for possible poor positioning + // in the event the GPS has a poor satelite lock. + const uint8_t distanceTravel = 100; + + // Minimum time between position updates. + const uint8_t timeTravel = 60; + + // If the distance traveled since the last update is greater than 100 meters + // and it's been at least 60 seconds since the last update + if ((abs(distance) >= distanceTravel) && (lastGpsSend == 0 || now - timeTravel >= getPref_position_broadcast_secs() * 1000)) { + bool requestReplies = currentGeneration != radioGeneration; + currentGeneration = radioGeneration; + + DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", + node->position.pos_timestamp, requestReplies); + sendOurPosition(NODENUM_BROADCAST, requestReplies); + + } + } } return 5000; // to save power only wake for our callback occasionally diff --git a/src/plugins/PositionPlugin.h b/src/plugins/PositionPlugin.h index 3e4034d4f..5ffe04803 100644 --- a/src/plugins/PositionPlugin.h +++ b/src/plugins/PositionPlugin.h @@ -13,6 +13,10 @@ class PositionPlugin : public ProtobufPlugin, private concurrency::OST /// We limit our GPS broadcasts to a max rate uint32_t lastGpsSend = 0; + // Store the latest good lat / long + uint32_t lastGpsLatitude = 0; + uint32_t lastGpsLongitude = 0; + /// We force a rebroadcast if the radio settings change uint32_t currentGeneration = 0; diff --git a/src/plugins/esp32/RangeTestPlugin.cpp b/src/plugins/esp32/RangeTestPlugin.cpp index 1252fe74b..f5cc87d1a 100644 --- a/src/plugins/esp32/RangeTestPlugin.cpp +++ b/src/plugins/esp32/RangeTestPlugin.cpp @@ -151,6 +151,7 @@ ProcessMessage RangeTestPluginRadio::handleReceived(const MeshPacket &mp) appendFile(mp); } + /* DEBUG_MSG("-----------------------------------------\n"); DEBUG_MSG("p.payload.bytes \"%s\"\n", p.payload.bytes); DEBUG_MSG("p.payload.size %d\n", p.payload.size); @@ -174,6 +175,7 @@ ProcessMessage RangeTestPluginRadio::handleReceived(const MeshPacket &mp) DEBUG_MSG("gpsStatus->getHasLock() %d\n", gpsStatus->getHasLock()); DEBUG_MSG("gpsStatus->getDOP() %d\n", gpsStatus->getDOP()); DEBUG_MSG("-----------------------------------------\n"); + */ } } else { From 88fd6718805762f50cbeee55bfba801d0a96f657 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Fri, 26 Nov 2021 21:26:36 -0800 Subject: [PATCH 6/9] Tweaking values of Smart Position #934 Tweaking values of Smart Position #934 --- src/plugins/PositionPlugin.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index a64ead3b3..d026fb88c 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -139,6 +139,8 @@ void PositionPlugin::sendOurPosition(NodeNum dest, bool wantReplies) int32_t PositionPlugin::runOnce() { NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); + + // radioConfig.preferences.position_broadcast_smart = true; // We limit our GPS broadcasts to a max rate uint32_t now = millis(); @@ -157,18 +159,19 @@ int32_t PositionPlugin::runOnce() node->position.pos_timestamp, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies); } else if (radioConfig.preferences.position_broadcast_smart == true) { - // radioConfig.preferences.position_broadcast_smart //NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position - + if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0) ) { float distance = GeoCoord::latLongToMeter(lastGpsLatitude * 1e-7, lastGpsLongitude * 1e-7, node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); // Please don't change this value. This accomodates for possible poor positioning // in the event the GPS has a poor satelite lock. - const uint8_t distanceTravel = 100; + const uint8_t distanceTravel = 150; - // Minimum time between position updates. + /* Minimum time between position updates. + Note: At an average walking speed of 3.5mph, it takes 90 seconds to travel 150 meters. + */ const uint8_t timeTravel = 60; // If the distance traveled since the last update is greater than 100 meters @@ -177,7 +180,7 @@ int32_t PositionPlugin::runOnce() bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; - DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", + DEBUG_MSG("Sending smart pos@%x:6 to mesh (wantReplies=%d)\n", node->position.pos_timestamp, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies); From d7315778d6ed5743bc53542f3c2d36e17348d67f Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 28 Nov 2021 19:25:50 -0800 Subject: [PATCH 7/9] Generated protos for S&F --- src/mesh/generated/admin.pb.h | 2 +- src/mesh/generated/radioconfig.pb.h | 17 +++- src/mesh/generated/storeforward.pb.c | 19 ++++ src/mesh/generated/storeforward.pb.h | 136 +++++++++++++++++++++++++++ 4 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 src/mesh/generated/storeforward.pb.c create mode 100644 src/mesh/generated/storeforward.pb.h diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index a2da87520..2a538c2a9 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -79,7 +79,7 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#define AdminMessage_size 423 +#define AdminMessage_size 440 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index 2381e60b9..96e23b19f 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -136,6 +136,8 @@ typedef struct _RadioConfig_UserPreferences { uint32_t range_test_plugin_sender; bool range_test_plugin_save; uint32_t store_forward_plugin_records; + uint32_t store_forward_plugin_history_return_max; + uint32_t store_forward_plugin_history_return_window; bool environmental_measurement_plugin_measurement_enabled; bool environmental_measurement_plugin_screen_enabled; uint32_t environmental_measurement_plugin_read_error_count_threshold; @@ -145,6 +147,7 @@ typedef struct _RadioConfig_UserPreferences { RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType environmental_measurement_plugin_sensor_type; uint32_t environmental_measurement_plugin_sensor_pin; bool store_forward_plugin_enabled; + bool store_forward_plugin_heartbeat; uint32_t position_flags; bool is_always_powered; } RadioConfig_UserPreferences; @@ -191,9 +194,9 @@ extern "C" { /* Initializer values for message structs */ #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 @@ -245,6 +248,8 @@ extern "C" { #define RadioConfig_UserPreferences_range_test_plugin_sender_tag 133 #define RadioConfig_UserPreferences_range_test_plugin_save_tag 134 #define RadioConfig_UserPreferences_store_forward_plugin_records_tag 137 +#define RadioConfig_UserPreferences_store_forward_plugin_history_return_max_tag 138 +#define RadioConfig_UserPreferences_store_forward_plugin_history_return_window_tag 139 #define RadioConfig_UserPreferences_environmental_measurement_plugin_measurement_enabled_tag 140 #define RadioConfig_UserPreferences_environmental_measurement_plugin_screen_enabled_tag 141 #define RadioConfig_UserPreferences_environmental_measurement_plugin_read_error_count_threshold_tag 142 @@ -254,6 +259,7 @@ extern "C" { #define RadioConfig_UserPreferences_environmental_measurement_plugin_sensor_type_tag 146 #define RadioConfig_UserPreferences_environmental_measurement_plugin_sensor_pin_tag 147 #define RadioConfig_UserPreferences_store_forward_plugin_enabled_tag 148 +#define RadioConfig_UserPreferences_store_forward_plugin_heartbeat_tag 149 #define RadioConfig_UserPreferences_position_flags_tag 150 #define RadioConfig_UserPreferences_is_always_powered_tag 151 #define RadioConfig_preferences_tag 1 @@ -315,6 +321,8 @@ X(a, STATIC, SINGULAR, BOOL, range_test_plugin_enabled, 132) \ X(a, STATIC, SINGULAR, UINT32, range_test_plugin_sender, 133) \ X(a, STATIC, SINGULAR, BOOL, range_test_plugin_save, 134) \ X(a, STATIC, SINGULAR, UINT32, store_forward_plugin_records, 137) \ +X(a, STATIC, SINGULAR, UINT32, store_forward_plugin_history_return_max, 138) \ +X(a, STATIC, SINGULAR, UINT32, store_forward_plugin_history_return_window, 139) \ X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_measurement_enabled, 140) \ X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_screen_enabled, 141) \ X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_read_error_count_threshold, 142) \ @@ -324,6 +332,7 @@ X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_display_fare X(a, STATIC, SINGULAR, UENUM, environmental_measurement_plugin_sensor_type, 146) \ X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_sensor_pin, 147) \ X(a, STATIC, SINGULAR, BOOL, store_forward_plugin_enabled, 148) \ +X(a, STATIC, SINGULAR, BOOL, store_forward_plugin_heartbeat, 149) \ X(a, STATIC, SINGULAR, UINT32, position_flags, 150) \ X(a, STATIC, SINGULAR, BOOL, is_always_powered, 151) #define RadioConfig_UserPreferences_CALLBACK NULL @@ -337,8 +346,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg; #define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg /* Maximum encoded size of messages (where known) */ -#define RadioConfig_size 420 -#define RadioConfig_UserPreferences_size 417 +#define RadioConfig_size 437 +#define RadioConfig_UserPreferences_size 434 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/storeforward.pb.c b/src/mesh/generated/storeforward.pb.c new file mode 100644 index 000000000..a348ee01b --- /dev/null +++ b/src/mesh/generated/storeforward.pb.c @@ -0,0 +1,19 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.4.4 */ + +#include "storeforward.pb.h" +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +PB_BIND(StoreAndForwardMessage, StoreAndForwardMessage, AUTO) + + +PB_BIND(StoreAndForwardMessage_Statistics, StoreAndForwardMessage_Statistics, AUTO) + + +PB_BIND(StoreAndForwardMessage_History, StoreAndForwardMessage_History, AUTO) + + + + diff --git a/src/mesh/generated/storeforward.pb.h b/src/mesh/generated/storeforward.pb.h new file mode 100644 index 000000000..988ff3276 --- /dev/null +++ b/src/mesh/generated/storeforward.pb.h @@ -0,0 +1,136 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.4.4 */ + +#ifndef PB_STOREFORWARD_PB_H_INCLUDED +#define PB_STOREFORWARD_PB_H_INCLUDED +#include + +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +/* Enum definitions */ +typedef enum _StoreAndForwardMessage_RequestResponse { + StoreAndForwardMessage_RequestResponse_UNSET = 0, + StoreAndForwardMessage_RequestResponse_ROUTER_ERROR = 1, + StoreAndForwardMessage_RequestResponse_ROUTER_HEARTBEAT = 2, + StoreAndForwardMessage_RequestResponse_ROUTER_PING = 3, + StoreAndForwardMessage_RequestResponse_ROUTER_PONG = 4, + StoreAndForwardMessage_RequestResponse_ROUTER_BUSY = 5, + StoreAndForwardMessage_RequestResponse_CLIENT_ERROR = 101, + StoreAndForwardMessage_RequestResponse_CLIENT_HISTORY = 102, + StoreAndForwardMessage_RequestResponse_CLIENT_STATS = 103, + StoreAndForwardMessage_RequestResponse_CLIENT_PING = 104, + StoreAndForwardMessage_RequestResponse_CLIENT_PONG = 105, + StoreAndForwardMessage_RequestResponse_MAX = 255 +} StoreAndForwardMessage_RequestResponse; + +/* Struct definitions */ +typedef struct _StoreAndForwardMessage_History { + uint32_t HistoryMessages; + uint32_t Window; +} StoreAndForwardMessage_History; + +typedef struct _StoreAndForwardMessage_Statistics { + uint32_t MessagesTotal; + uint32_t MessagesSaved; + uint32_t MessagesMax; + uint32_t UpTime; + uint32_t Requests; + uint32_t RequestsHistory; + bool Heartbeat; + uint32_t ReturnMax; + uint32_t ReturnWindow; +} StoreAndForwardMessage_Statistics; + +typedef struct _StoreAndForwardMessage { + StoreAndForwardMessage_RequestResponse rr; + bool has_stats; + StoreAndForwardMessage_Statistics stats; + bool has_history; + StoreAndForwardMessage_History history; +} StoreAndForwardMessage; + + +/* Helper constants for enums */ +#define _StoreAndForwardMessage_RequestResponse_MIN StoreAndForwardMessage_RequestResponse_UNSET +#define _StoreAndForwardMessage_RequestResponse_MAX StoreAndForwardMessage_RequestResponse_MAX +#define _StoreAndForwardMessage_RequestResponse_ARRAYSIZE ((StoreAndForwardMessage_RequestResponse)(StoreAndForwardMessage_RequestResponse_MAX+1)) + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Initializer values for message structs */ +#define StoreAndForwardMessage_init_default {_StoreAndForwardMessage_RequestResponse_MIN, false, StoreAndForwardMessage_Statistics_init_default, false, StoreAndForwardMessage_History_init_default} +#define StoreAndForwardMessage_Statistics_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0} +#define StoreAndForwardMessage_History_init_default {0, 0} +#define StoreAndForwardMessage_init_zero {_StoreAndForwardMessage_RequestResponse_MIN, false, StoreAndForwardMessage_Statistics_init_zero, false, StoreAndForwardMessage_History_init_zero} +#define StoreAndForwardMessage_Statistics_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0} +#define StoreAndForwardMessage_History_init_zero {0, 0} + +/* Field tags (for use in manual encoding/decoding) */ +#define StoreAndForwardMessage_History_HistoryMessages_tag 1 +#define StoreAndForwardMessage_History_Window_tag 2 +#define StoreAndForwardMessage_Statistics_MessagesTotal_tag 1 +#define StoreAndForwardMessage_Statistics_MessagesSaved_tag 2 +#define StoreAndForwardMessage_Statistics_MessagesMax_tag 3 +#define StoreAndForwardMessage_Statistics_UpTime_tag 4 +#define StoreAndForwardMessage_Statistics_Requests_tag 5 +#define StoreAndForwardMessage_Statistics_RequestsHistory_tag 6 +#define StoreAndForwardMessage_Statistics_Heartbeat_tag 7 +#define StoreAndForwardMessage_Statistics_ReturnMax_tag 8 +#define StoreAndForwardMessage_Statistics_ReturnWindow_tag 9 +#define StoreAndForwardMessage_rr_tag 1 +#define StoreAndForwardMessage_stats_tag 2 +#define StoreAndForwardMessage_history_tag 3 + +/* Struct field encoding specification for nanopb */ +#define StoreAndForwardMessage_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UENUM, rr, 1) \ +X(a, STATIC, OPTIONAL, MESSAGE, stats, 2) \ +X(a, STATIC, OPTIONAL, MESSAGE, history, 3) +#define StoreAndForwardMessage_CALLBACK NULL +#define StoreAndForwardMessage_DEFAULT NULL +#define StoreAndForwardMessage_stats_MSGTYPE StoreAndForwardMessage_Statistics +#define StoreAndForwardMessage_history_MSGTYPE StoreAndForwardMessage_History + +#define StoreAndForwardMessage_Statistics_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, MessagesTotal, 1) \ +X(a, STATIC, SINGULAR, UINT32, MessagesSaved, 2) \ +X(a, STATIC, SINGULAR, UINT32, MessagesMax, 3) \ +X(a, STATIC, SINGULAR, UINT32, UpTime, 4) \ +X(a, STATIC, SINGULAR, UINT32, Requests, 5) \ +X(a, STATIC, SINGULAR, UINT32, RequestsHistory, 6) \ +X(a, STATIC, SINGULAR, BOOL, Heartbeat, 7) \ +X(a, STATIC, SINGULAR, UINT32, ReturnMax, 8) \ +X(a, STATIC, SINGULAR, UINT32, ReturnWindow, 9) +#define StoreAndForwardMessage_Statistics_CALLBACK NULL +#define StoreAndForwardMessage_Statistics_DEFAULT NULL + +#define StoreAndForwardMessage_History_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, HistoryMessages, 1) \ +X(a, STATIC, SINGULAR, UINT32, Window, 2) +#define StoreAndForwardMessage_History_CALLBACK NULL +#define StoreAndForwardMessage_History_DEFAULT NULL + +extern const pb_msgdesc_t StoreAndForwardMessage_msg; +extern const pb_msgdesc_t StoreAndForwardMessage_Statistics_msg; +extern const pb_msgdesc_t StoreAndForwardMessage_History_msg; + +/* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define StoreAndForwardMessage_fields &StoreAndForwardMessage_msg +#define StoreAndForwardMessage_Statistics_fields &StoreAndForwardMessage_Statistics_msg +#define StoreAndForwardMessage_History_fields &StoreAndForwardMessage_History_msg + +/* Maximum encoded size of messages (where known) */ +#define StoreAndForwardMessage_size 69 +#define StoreAndForwardMessage_Statistics_size 50 +#define StoreAndForwardMessage_History_size 12 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif From 937f67c4ec2a9a5606483f948293c75f1c565323 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 28 Nov 2021 19:34:35 -0800 Subject: [PATCH 8/9] Check in partial work on S&F --- src/plugins/esp32/StoreForwardPlugin.cpp | 13 +++++++++++++ src/plugins/esp32/StoreForwardPlugin.h | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index 6c3263432..8c8740cfd 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -5,6 +5,7 @@ #include "Router.h" #include "configuration.h" #include "mesh-pb-constants.h" +#include "mesh/generated/storeforward.pb.h" #include "plugins/PluginDev.h" #include #include @@ -223,6 +224,8 @@ void StoreForwardPlugin::sendMessage(NodeNum dest, char *str) service.sendToMesh(p); + + //HardwareMessage_init_default } ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) @@ -232,6 +235,14 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) DEBUG_MSG("--- S&F Received something\n"); + StoreAndForwardMessage sfm = StoreAndForwardMessage_init_default; + + switch(sfm.rr) { + + + } + + auto &p = mp.decoded; // The router node should not be sending messages as a client. @@ -258,6 +269,8 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) storeForwardPlugin->historyAdd(mp); } + } else if (mp.decoded.portnum == PortNum_STORE_FORWARD_APP) { + } else { DEBUG_MSG("Packet came from an unknown port %u\n", mp.decoded.portnum); } diff --git a/src/plugins/esp32/StoreForwardPlugin.h b/src/plugins/esp32/StoreForwardPlugin.h index 3df640778..e841ff4ac 100644 --- a/src/plugins/esp32/StoreForwardPlugin.h +++ b/src/plugins/esp32/StoreForwardPlugin.h @@ -2,6 +2,8 @@ #include "SinglePortPlugin.h" #include "concurrency/OSThread.h" +#include "mesh/generated/storeforward.pb.h" + #include "configuration.h" #include #include @@ -53,7 +55,10 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea void sendPayload(NodeNum dest = NODENUM_BROADCAST, uint32_t packetHistory_index = 0); void sendMessage(NodeNum dest, char *str); virtual MeshPacket *allocReply(); - virtual bool wantPortnum(PortNum p) { return true; }; + /* + Override the wantPortnum method. + */ + virtual bool wantPortnum(PortNum p) { return true; }; private: void populatePSRAM(); From d5506bb33ccbc0d6cfd26faac2f656efe41df8bd Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 28 Nov 2021 19:41:34 -0800 Subject: [PATCH 9/9] Cleanup (Comments & Formatting) of S&F and PrositionPlugin.cpp --- src/plugins/PositionPlugin.cpp | 54 ++++++++------------- src/plugins/esp32/StoreForwardPlugin.cpp | 60 +++++++++++------------- src/plugins/esp32/StoreForwardPlugin.h | 7 ++- 3 files changed, 50 insertions(+), 71 deletions(-) diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index d026fb88c..11d13abae 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -1,12 +1,11 @@ -#include "configuration.h" #include "PositionPlugin.h" #include "MeshService.h" #include "NodeDB.h" #include "RTC.h" #include "Router.h" +#include "configuration.h" #include "gps/GeoCoord.h" - PositionPlugin *positionPlugin; PositionPlugin::PositionPlugin() @@ -32,23 +31,11 @@ bool PositionPlugin::handleReceivedProtobuf(const MeshPacket &mp, Position *pptr } // Log packet size and list of fields - DEBUG_MSG("POSITION node=%08x l=%d %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", - getFrom(&mp), - mp.decoded.payload.size, - p.latitude_i ? "LAT ":"", - p.longitude_i ? "LON ":"", - p.altitude ? "MSL ":"", - p.altitude_hae ? "HAE ":"", - p.alt_geoid_sep ? "GEO ":"", - p.PDOP ? "PDOP ":"", - p.HDOP ? "HDOP ":"", - p.VDOP ? "VDOP ":"", - p.sats_in_view ? "SIV ":"", - p.fix_quality ? "FXQ ":"", - p.fix_type ? "FXT ":"", - p.pos_timestamp ? "PTS ":"", - p.time ? "TIME ":"", - p.battery_level ? "BAT ":""); + DEBUG_MSG("POSITION node=%08x l=%d %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", getFrom(&mp), mp.decoded.payload.size, + p.latitude_i ? "LAT " : "", p.longitude_i ? "LON " : "", p.altitude ? "MSL " : "", p.altitude_hae ? "HAE " : "", + p.alt_geoid_sep ? "GEO " : "", p.PDOP ? "PDOP " : "", p.HDOP ? "HDOP " : "", p.VDOP ? "VDOP " : "", + p.sats_in_view ? "SIV " : "", p.fix_quality ? "FXQ " : "", p.fix_type ? "FXT " : "", p.pos_timestamp ? "PTS " : "", + p.time ? "TIME " : "", p.battery_level ? "BAT " : ""); if (p.time) { struct timeval tv; @@ -75,7 +62,7 @@ MeshPacket *PositionPlugin::allocReply() uint32_t pos_flags = radioConfig.preferences.position_flags; // Populate a Position struct with ONLY the requested fields - Position p = Position_init_default; // Start with an empty structure + Position p = Position_init_default; // Start with an empty structure // lat/lon are unconditionally included - IF AVAILABLE! p.latitude_i = node->position.latitude_i; @@ -139,7 +126,7 @@ void PositionPlugin::sendOurPosition(NodeNum dest, bool wantReplies) int32_t PositionPlugin::runOnce() { NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); - + // radioConfig.preferences.position_broadcast_smart = true; // We limit our GPS broadcasts to a max rate @@ -155,35 +142,34 @@ int32_t PositionPlugin::runOnce() bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; - DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", - node->position.pos_timestamp, requestReplies); + 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 *node = service.refreshMyNodeInfo(); // should guarantee there is now a position - if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0) ) { + if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) { float distance = GeoCoord::latLongToMeter(lastGpsLatitude * 1e-7, lastGpsLongitude * 1e-7, - node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); + node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); - // Please don't change this value. This accomodates for possible poor positioning - // in the event the GPS has a poor satelite lock. - const uint8_t distanceTravel = 150; + /* Please don't change these values. This accomodates for possible poor positioning + in the event the GPS has a poor satelite lock. + */ + const uint8_t distanceTravel = 150; /* Minimum time between position updates. Note: At an average walking speed of 3.5mph, it takes 90 seconds to travel 150 meters. */ - const uint8_t timeTravel = 60; + const uint8_t timeTravel = 60; // If the distance traveled since the last update is greater than 100 meters // and it's been at least 60 seconds since the last update - if ((abs(distance) >= distanceTravel) && (lastGpsSend == 0 || now - timeTravel >= getPref_position_broadcast_secs() * 1000)) { + if ((abs(distance) >= distanceTravel) && + (lastGpsSend == 0 || now - timeTravel >= getPref_position_broadcast_secs() * 1000)) { bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; - DEBUG_MSG("Sending smart pos@%x:6 to mesh (wantReplies=%d)\n", - node->position.pos_timestamp, requestReplies); + DEBUG_MSG("Sending smart pos@%x:6 to mesh (wantReplies=%d)\n", node->position.pos_timestamp, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies); - } } } diff --git a/src/plugins/esp32/StoreForwardPlugin.cpp b/src/plugins/esp32/StoreForwardPlugin.cpp index 8c8740cfd..3b2372ccc 100644 --- a/src/plugins/esp32/StoreForwardPlugin.cpp +++ b/src/plugins/esp32/StoreForwardPlugin.cpp @@ -8,9 +8,8 @@ #include "mesh/generated/storeforward.pb.h" #include "plugins/PluginDev.h" #include -#include #include - +#include StoreForwardPlugin *storeForwardPlugin; @@ -26,22 +25,22 @@ int32_t StoreForwardPlugin::runOnce() if (this->busy) { // Send out the message queue. - //DEBUG_MSG("--- --- --- In busy loop 1 %d\n", this->packetHistoryTXQueue_index); + // DEBUG_MSG("--- --- --- In busy loop 1 %d\n", this->packetHistoryTXQueue_index); storeForwardPlugin->sendPayload(this->busyTo, this->packetHistoryTXQueue_index); - + if (this->packetHistoryTXQueue_index == packetHistoryTXQueue_size) { strcpy(this->routerMessage, "** S&F - Done"); storeForwardPlugin->sendMessage(this->busyTo, this->routerMessage); - //DEBUG_MSG("--- --- --- In busy loop - Done \n"); + // DEBUG_MSG("--- --- --- In busy loop - Done \n"); this->packetHistoryTXQueue_index = 0; this->busy = false; } else { this->packetHistoryTXQueue_index++; } - } - // TODO: Dynamicly adjust the time this returns in the loop based on the size of the packets being actually transmitted. + // TODO: Dynamicly adjust the time this returns in the loop based on the size of the packets being actually + // transmitted. return (this->packetTimeMax); } else { DEBUG_MSG("Store & Forward Plugin - Disabled (is_router = false)\n"); @@ -84,7 +83,8 @@ void StoreForwardPlugin::populatePSRAM() : (((ESP.getFreePsram() / 3) * 2) / sizeof(PacketHistoryStruct))); this->packetHistory = static_cast(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct))); - this->packetHistoryTXQueue = static_cast(ps_calloc(store_forward_plugin_replay_max_records, sizeof(PacketHistoryStruct))); + this->packetHistoryTXQueue = + static_cast(ps_calloc(store_forward_plugin_replay_max_records, sizeof(PacketHistoryStruct))); DEBUG_MSG("After PSRAM initilization:\n"); DEBUG_MSG(" Total heap: %d\n", ESP.getHeapSize()); @@ -108,7 +108,6 @@ void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to) { uint32_t packetsSent = 0; - uint32_t queueSize = storeForwardPlugin->historyQueueCreate(msAgo, to); @@ -125,9 +124,10 @@ void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to) } } -uint32_t StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to) { - - //uint32_t packetHistoryTXQueueIndex = 0; +uint32_t StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to) +{ + + // uint32_t packetHistoryTXQueueIndex = 0; this->packetHistoryTXQueue_size = 0; @@ -147,24 +147,19 @@ uint32_t StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to) { TODO: The condition (this->packetHistory[i].to & 0xffffffff) == to) is not tested since I don't have an easy way to target a specific user. Will need to do this soon. */ - if ((this->packetHistory[i].to & 0xffffffff) == 0xffffffff - || - ((this->packetHistory[i].to & 0xffffffff) == to) - ) { + if ((this->packetHistory[i].to & 0xffffffff) == 0xffffffff || ((this->packetHistory[i].to & 0xffffffff) == to)) { this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].to = this->packetHistory[i].to; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload_size = this->packetHistory[i].payload_size; - memcpy(this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload, this->packetHistory[i].payload, Constants_DATA_PAYLOAD_LEN); + memcpy(this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload, this->packetHistory[i].payload, + Constants_DATA_PAYLOAD_LEN); this->packetHistoryTXQueue_size++; DEBUG_MSG("PacketHistoryStruct time=%d\n", this->packetHistory[i].time); DEBUG_MSG("PacketHistoryStruct msg=%.*s\n", this->packetHistory[i].payload); - //DEBUG_MSG("PacketHistoryStruct msg=%.*s\n", this->packetHistoryTXQueue[packetHistoryTXQueueIndex].payload); - - + // DEBUG_MSG("PacketHistoryStruct msg=%.*s\n", this->packetHistoryTXQueue[packetHistoryTXQueueIndex].payload); } - } } return this->packetHistoryTXQueue_size; @@ -222,10 +217,9 @@ void StoreForwardPlugin::sendMessage(NodeNum dest, char *str) p->decoded.payload.size = strlen(str); // You must specify how many bytes are in the reply memcpy(p->decoded.payload.bytes, str, strlen(str)); - service.sendToMesh(p); - - //HardwareMessage_init_default + + // HardwareMessage_init_default } ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) @@ -237,12 +231,9 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) StoreAndForwardMessage sfm = StoreAndForwardMessage_init_default; - switch(sfm.rr) { - - + switch (sfm.rr) { } - auto &p = mp.decoded; // The router node should not be sending messages as a client. @@ -261,8 +252,11 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) } else { storeForwardPlugin->historySend(1000 * 60, getFrom(&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, "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456"); + } 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"); storeForwardPlugin->sendMessage(getFrom(&mp), this->routerMessage); } else { @@ -319,9 +313,9 @@ StoreForwardPlugin::StoreForwardPlugin() // Calculate the packet time. // this->packetTimeMax = RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN); - //RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN); - //RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN); - //RadioInterface::getPacketTime(500)l + // RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN); + // RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN); + // RadioInterface::getPacketTime(500)l this->packetTimeMax = 2000; diff --git a/src/plugins/esp32/StoreForwardPlugin.h b/src/plugins/esp32/StoreForwardPlugin.h index e841ff4ac..cd8daed7c 100644 --- a/src/plugins/esp32/StoreForwardPlugin.h +++ b/src/plugins/esp32/StoreForwardPlugin.h @@ -19,7 +19,7 @@ struct PacketHistoryStruct { class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThread { - //bool firstTime = 1; + // bool firstTime = 1; bool busy = 0; uint32_t busyTo; char routerMessage[80]; @@ -32,9 +32,8 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea PacketHistoryStruct *packetHistoryTXQueue; uint32_t packetHistoryTXQueue_size; uint32_t packetHistoryTXQueue_index = 0; - - uint32_t packetTimeMax = 0; + uint32_t packetTimeMax = 0; public: StoreForwardPlugin(); @@ -58,7 +57,7 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea /* Override the wantPortnum method. */ - virtual bool wantPortnum(PortNum p) { return true; }; + virtual bool wantPortnum(PortNum p) { return true; }; private: void populatePSRAM();