mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-03 19:29:57 +00:00
Cleanup (Comments & Formatting) of S&F and PrositionPlugin.cpp
This commit is contained in:
parent
937f67c4ec
commit
d5506bb33c
@ -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;
|
||||
@ -155,8 +142,7 @@ 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
|
||||
@ -165,8 +151,9 @@ int32_t PositionPlugin::runOnce()
|
||||
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.
|
||||
/* 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.
|
||||
@ -176,14 +163,13 @@ int32_t PositionPlugin::runOnce()
|
||||
|
||||
// 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,8 @@
|
||||
#include "mesh/generated/storeforward.pb.h"
|
||||
#include "plugins/PluginDev.h"
|
||||
#include <Arduino.h>
|
||||
#include <map>
|
||||
#include <iterator>
|
||||
|
||||
#include <map>
|
||||
|
||||
StoreForwardPlugin *storeForwardPlugin;
|
||||
|
||||
@ -38,10 +37,10 @@ int32_t StoreForwardPlugin::runOnce()
|
||||
} 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<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(" 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 queueSize = storeForwardPlugin->historyQueueCreate(msAgo, to);
|
||||
|
||||
if (queueSize) {
|
||||
@ -125,7 +124,8 @@ 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;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return this->packetHistoryTXQueue_size;
|
||||
@ -222,7 +217,6 @@ 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
|
||||
@ -238,11 +232,8 @@ ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp)
|
||||
StoreAndForwardMessage sfm = StoreAndForwardMessage_init_default;
|
||||
|
||||
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 {
|
||||
|
@ -35,7 +35,6 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea
|
||||
|
||||
uint32_t packetTimeMax = 0;
|
||||
|
||||
|
||||
public:
|
||||
StoreForwardPlugin();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user