Cleanup (Comments & Formatting) of S&F and PrositionPlugin.cpp

This commit is contained in:
Jm Casler 2021-11-28 19:41:34 -08:00
parent 937f67c4ec
commit d5506bb33c
3 changed files with 50 additions and 71 deletions

View File

@ -1,12 +1,11 @@
#include "configuration.h"
#include "PositionPlugin.h" #include "PositionPlugin.h"
#include "MeshService.h" #include "MeshService.h"
#include "NodeDB.h" #include "NodeDB.h"
#include "RTC.h" #include "RTC.h"
#include "Router.h" #include "Router.h"
#include "configuration.h"
#include "gps/GeoCoord.h" #include "gps/GeoCoord.h"
PositionPlugin *positionPlugin; PositionPlugin *positionPlugin;
PositionPlugin::PositionPlugin() PositionPlugin::PositionPlugin()
@ -32,23 +31,11 @@ bool PositionPlugin::handleReceivedProtobuf(const MeshPacket &mp, Position *pptr
} }
// Log packet size and list of fields // 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", 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,
getFrom(&mp), p.latitude_i ? "LAT " : "", p.longitude_i ? "LON " : "", p.altitude ? "MSL " : "", p.altitude_hae ? "HAE " : "",
mp.decoded.payload.size, p.alt_geoid_sep ? "GEO " : "", p.PDOP ? "PDOP " : "", p.HDOP ? "HDOP " : "", p.VDOP ? "VDOP " : "",
p.latitude_i ? "LAT ":"", p.sats_in_view ? "SIV " : "", p.fix_quality ? "FXQ " : "", p.fix_type ? "FXT " : "", p.pos_timestamp ? "PTS " : "",
p.longitude_i ? "LON ":"", p.time ? "TIME " : "", p.battery_level ? "BAT " : "");
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) { if (p.time) {
struct timeval tv; struct timeval tv;
@ -155,18 +142,18 @@ int32_t PositionPlugin::runOnce()
bool requestReplies = currentGeneration != radioGeneration; bool requestReplies = currentGeneration != radioGeneration;
currentGeneration = radioGeneration; currentGeneration = radioGeneration;
DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", node->position.pos_timestamp, requestReplies);
node->position.pos_timestamp, requestReplies);
sendOurPosition(NODENUM_BROADCAST, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies);
} else if (radioConfig.preferences.position_broadcast_smart == true) { } 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, 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 /* Please don't change these values. This accomodates for possible poor positioning
// in the event the GPS has a poor satelite lock. in the event the GPS has a poor satelite lock.
*/
const uint8_t distanceTravel = 150; const uint8_t distanceTravel = 150;
/* Minimum time between position updates. /* Minimum time between position updates.
@ -176,14 +163,13 @@ int32_t PositionPlugin::runOnce()
// If the distance traveled since the last update is greater than 100 meters // 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 // 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; bool requestReplies = currentGeneration != radioGeneration;
currentGeneration = radioGeneration; currentGeneration = radioGeneration;
DEBUG_MSG("Sending smart 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);
node->position.pos_timestamp, requestReplies);
sendOurPosition(NODENUM_BROADCAST, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies);
} }
} }
} }

View File

@ -8,9 +8,8 @@
#include "mesh/generated/storeforward.pb.h" #include "mesh/generated/storeforward.pb.h"
#include "plugins/PluginDev.h" #include "plugins/PluginDev.h"
#include <Arduino.h> #include <Arduino.h>
#include <map>
#include <iterator> #include <iterator>
#include <map>
StoreForwardPlugin *storeForwardPlugin; StoreForwardPlugin *storeForwardPlugin;
@ -26,22 +25,22 @@ int32_t StoreForwardPlugin::runOnce()
if (this->busy) { if (this->busy) {
// Send out the message queue. // 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); storeForwardPlugin->sendPayload(this->busyTo, this->packetHistoryTXQueue_index);
if (this->packetHistoryTXQueue_index == packetHistoryTXQueue_size) { if (this->packetHistoryTXQueue_index == packetHistoryTXQueue_size) {
strcpy(this->routerMessage, "** S&F - Done"); strcpy(this->routerMessage, "** S&F - Done");
storeForwardPlugin->sendMessage(this->busyTo, this->routerMessage); 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->packetHistoryTXQueue_index = 0;
this->busy = false; this->busy = false;
} else { } else {
this->packetHistoryTXQueue_index++; 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); return (this->packetTimeMax);
} else { } else {
DEBUG_MSG("Store & Forward Plugin - Disabled (is_router = false)\n"); DEBUG_MSG("Store & Forward Plugin - Disabled (is_router = false)\n");
@ -84,7 +83,8 @@ void StoreForwardPlugin::populatePSRAM()
: (((ESP.getFreePsram() / 3) * 2) / sizeof(PacketHistoryStruct))); : (((ESP.getFreePsram() / 3) * 2) / sizeof(PacketHistoryStruct)));
this->packetHistory = static_cast<PacketHistoryStruct *>(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct))); this->packetHistory = static_cast<PacketHistoryStruct *>(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct)));
this->packetHistoryTXQueue = static_cast<PacketHistoryStruct *>(ps_calloc(store_forward_plugin_replay_max_records, sizeof(PacketHistoryStruct))); this->packetHistoryTXQueue =
static_cast<PacketHistoryStruct *>(ps_calloc(store_forward_plugin_replay_max_records, sizeof(PacketHistoryStruct)));
DEBUG_MSG("After PSRAM initilization:\n"); DEBUG_MSG("After PSRAM initilization:\n");
DEBUG_MSG(" Total heap: %d\n", ESP.getHeapSize()); DEBUG_MSG(" Total heap: %d\n", ESP.getHeapSize());
@ -109,7 +109,6 @@ void StoreForwardPlugin::historySend(uint32_t msAgo, uint32_t to)
uint32_t packetsSent = 0; uint32_t packetsSent = 0;
uint32_t queueSize = storeForwardPlugin->historyQueueCreate(msAgo, to); uint32_t queueSize = storeForwardPlugin->historyQueueCreate(msAgo, to);
if (queueSize) { if (queueSize) {
@ -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 StoreForwardPlugin::historyQueueCreate(uint32_t msAgo, uint32_t to)
{
//uint32_t packetHistoryTXQueueIndex = 0; // uint32_t packetHistoryTXQueueIndex = 0;
this->packetHistoryTXQueue_size = 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 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. 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 if ((this->packetHistory[i].to & 0xffffffff) == 0xffffffff || ((this->packetHistory[i].to & 0xffffffff) == to)) {
||
((this->packetHistory[i].to & 0xffffffff) == to)
) {
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; 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].to = this->packetHistory[i].to;
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from;
this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload_size = this->packetHistory[i].payload_size; 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++; this->packetHistoryTXQueue_size++;
DEBUG_MSG("PacketHistoryStruct time=%d\n", this->packetHistory[i].time); 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->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; 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 p->decoded.payload.size = strlen(str); // You must specify how many bytes are in the reply
memcpy(p->decoded.payload.bytes, str, strlen(str)); memcpy(p->decoded.payload.bytes, str, strlen(str));
service.sendToMesh(p); service.sendToMesh(p);
//HardwareMessage_init_default // HardwareMessage_init_default
} }
ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp) ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp)
@ -237,12 +231,9 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp)
StoreAndForwardMessage sfm = StoreAndForwardMessage_init_default; StoreAndForwardMessage sfm = StoreAndForwardMessage_init_default;
switch(sfm.rr) { switch (sfm.rr) {
} }
auto &p = mp.decoded; auto &p = mp.decoded;
// The router node should not be sending messages as a client. // The router node should not be sending messages as a client.
@ -261,8 +252,11 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp)
} else { } else {
storeForwardPlugin->historySend(1000 * 60, getFrom(&mp)); 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)) { } else if ((p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') && (p.payload.bytes[2] == 'm') &&
strcpy(this->routerMessage, "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456"); (p.payload.bytes[3] == 0x00)) {
strcpy(this->routerMessage, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"
"01234567890123456789012345678901234567890123456789012345678901234567890123456789"
"01234567890123456789012345678901234567890123456789012345678901234567890123456");
storeForwardPlugin->sendMessage(getFrom(&mp), this->routerMessage); storeForwardPlugin->sendMessage(getFrom(&mp), this->routerMessage);
} else { } else {
@ -319,9 +313,9 @@ StoreForwardPlugin::StoreForwardPlugin()
// Calculate the packet time. // Calculate the packet time.
// this->packetTimeMax = RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN); // this->packetTimeMax = RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN);
//RadioLibInterface::instance->getPacketTime(Constants_DATA_PAYLOAD_LEN); // 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 // RadioInterface::getPacketTime(500)l
this->packetTimeMax = 2000; this->packetTimeMax = 2000;

View File

@ -19,7 +19,7 @@ struct PacketHistoryStruct {
class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThread class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThread
{ {
//bool firstTime = 1; // bool firstTime = 1;
bool busy = 0; bool busy = 0;
uint32_t busyTo; uint32_t busyTo;
char routerMessage[80]; char routerMessage[80];
@ -35,7 +35,6 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea
uint32_t packetTimeMax = 0; uint32_t packetTimeMax = 0;
public: public:
StoreForwardPlugin(); StoreForwardPlugin();