2023-07-26 16:34:36 -07:00
|
|
|
/**
|
|
|
|
|
* @file RangeTestModule.cpp
|
|
|
|
|
* @brief Implementation of the RangeTestModule class and RangeTestModuleRadio class.
|
2023-07-26 17:08:04 -07:00
|
|
|
*
|
2023-07-26 16:34:36 -07:00
|
|
|
* As a sender, this module sends packets every n seconds with an incremented PacketID.
|
|
|
|
|
* As a receiver, this module receives packets from multiple senders and saves them to the Filesystem.
|
2023-07-26 17:08:04 -07:00
|
|
|
*
|
2023-07-26 16:34:36 -07:00
|
|
|
* The RangeTestModule class is an OSThread that runs the module.
|
|
|
|
|
* The RangeTestModuleRadio class handles sending and receiving packets.
|
|
|
|
|
*/
|
2022-02-27 01:27:17 -08:00
|
|
|
#include "RangeTestModule.h"
|
2023-05-31 20:08:32 -05:00
|
|
|
#include "FSCommon.h"
|
2021-01-31 09:12:36 -08:00
|
|
|
#include "MeshService.h"
|
|
|
|
|
#include "NodeDB.h"
|
2021-02-14 21:34:47 -08:00
|
|
|
#include "PowerFSM.h"
|
2021-01-31 09:12:36 -08:00
|
|
|
#include "RTC.h"
|
|
|
|
|
#include "Router.h"
|
2025-01-03 10:05:26 +08:00
|
|
|
#include "SPILock.h"
|
2022-01-26 22:20:13 -08:00
|
|
|
#include "airtime.h"
|
2021-01-31 09:12:36 -08:00
|
|
|
#include "configuration.h"
|
2021-10-09 13:28:51 -04:00
|
|
|
#include "gps/GeoCoord.h"
|
2021-01-31 09:12:36 -08:00
|
|
|
#include <Arduino.h>
|
2024-09-23 08:58:14 -05:00
|
|
|
#include <Throttle.h>
|
2021-01-31 09:12:36 -08:00
|
|
|
|
2022-02-27 01:49:24 -08:00
|
|
|
RangeTestModule *rangeTestModule;
|
|
|
|
|
RangeTestModuleRadio *rangeTestModuleRadio;
|
2021-01-31 09:12:36 -08:00
|
|
|
|
2024-11-04 12:16:25 -06:00
|
|
|
RangeTestModule::RangeTestModule() : concurrency::OSThread("RangeTest") {}
|
2021-01-31 09:12:36 -08:00
|
|
|
|
2021-02-13 22:21:01 -08:00
|
|
|
uint32_t packetSequence = 0;
|
2021-02-03 08:10:13 -08:00
|
|
|
|
2022-02-27 01:49:24 -08:00
|
|
|
int32_t RangeTestModule::runOnce()
|
2021-01-31 09:12:36 -08:00
|
|
|
{
|
2025-09-02 13:08:57 +01:00
|
|
|
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_STM32WL) || defined(ARCH_PORTDUINO)
|
2021-01-31 09:12:36 -08:00
|
|
|
|
2021-02-06 23:29:18 -08:00
|
|
|
/*
|
2022-02-27 00:29:05 -08:00
|
|
|
Uncomment the preferences below if you want to use the module
|
2021-02-06 23:29:18 -08:00
|
|
|
without having to configure it from the PythonAPI or WebUI.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-11-09 15:12:57 +01:00
|
|
|
// moduleConfig.range_test.enabled = 1;
|
|
|
|
|
// moduleConfig.range_test.sender = 30;
|
2022-05-22 13:27:56 +02:00
|
|
|
// moduleConfig.range_test.save = 1;
|
2025-09-03 12:23:59 +12:00
|
|
|
// moduleConfig.range_test.clear_on_reboot = 1;
|
2021-02-13 22:21:01 -08:00
|
|
|
|
|
|
|
|
// Fixed position is useful when testing indoors.
|
2022-11-09 15:12:57 +01:00
|
|
|
// config.position.fixed_position = 1;
|
2021-02-06 23:29:18 -08:00
|
|
|
|
2022-05-22 13:27:56 +02:00
|
|
|
uint32_t senderHeartbeat = moduleConfig.range_test.sender * 1000;
|
|
|
|
|
if (moduleConfig.range_test.enabled) {
|
2021-01-31 09:12:36 -08:00
|
|
|
|
|
|
|
|
if (firstTime) {
|
2022-02-27 01:49:24 -08:00
|
|
|
rangeTestModuleRadio = new RangeTestModuleRadio();
|
2021-01-31 09:12:36 -08:00
|
|
|
|
|
|
|
|
firstTime = 0;
|
|
|
|
|
|
2025-09-03 12:06:35 +12:00
|
|
|
if (moduleConfig.range_test.clear_on_reboot) {
|
2025-08-21 19:28:52 +12:00
|
|
|
// User wants to delete previous range test(s)
|
|
|
|
|
LOG_INFO("Range Test Module - Clearing out previous test file");
|
|
|
|
|
rangeTestModuleRadio->removeFile();
|
|
|
|
|
}
|
2022-05-22 13:27:56 +02:00
|
|
|
if (moduleConfig.range_test.sender) {
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_INFO("Init Range Test Module -- Sender");
|
2023-05-15 15:47:10 +02:00
|
|
|
started = millis(); // make a note of when we started
|
2023-07-14 17:25:20 -04:00
|
|
|
return (5000); // Sending first message 5 seconds after initialization.
|
2021-02-03 08:10:13 -08:00
|
|
|
} else {
|
2024-11-04 12:16:25 -06:00
|
|
|
LOG_INFO("Init Range Test Module -- Receiver");
|
2023-02-03 00:42:35 +01:00
|
|
|
return disable();
|
2022-11-09 15:12:57 +01:00
|
|
|
// This thread does not need to run as a receiver
|
2021-02-03 08:10:13 -08:00
|
|
|
}
|
2021-01-31 09:12:36 -08:00
|
|
|
} else {
|
2021-01-31 18:20:08 -08:00
|
|
|
|
2022-05-22 13:27:56 +02:00
|
|
|
if (moduleConfig.range_test.sender) {
|
2021-02-03 08:10:13 -08:00
|
|
|
// If sender
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("Range Test Module - Sending heartbeat every %d ms", (senderHeartbeat));
|
2021-02-06 23:29:18 -08:00
|
|
|
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("gpsStatus->getLatitude() %d", gpsStatus->getLatitude());
|
|
|
|
|
LOG_INFO("gpsStatus->getLongitude() %d", gpsStatus->getLongitude());
|
|
|
|
|
LOG_INFO("gpsStatus->getHasLock() %d", gpsStatus->getHasLock());
|
|
|
|
|
LOG_INFO("gpsStatus->getDOP() %d", gpsStatus->getDOP());
|
|
|
|
|
LOG_INFO("fixed_position() %d", config.position.fixed_position);
|
2021-01-31 18:20:08 -08:00
|
|
|
|
2022-01-26 22:20:13 -08:00
|
|
|
// Only send packets if the channel is less than 25% utilized.
|
2023-01-11 21:52:19 +01:00
|
|
|
if (airTime->isTxAllowedChannelUtil(true)) {
|
2022-02-27 01:49:24 -08:00
|
|
|
rangeTestModuleRadio->sendPayload();
|
2022-01-26 22:20:13 -08:00
|
|
|
}
|
|
|
|
|
|
2023-05-15 15:47:10 +02:00
|
|
|
// If we have been running for more than 8 hours, turn module back off
|
2024-09-23 08:58:14 -05:00
|
|
|
if (!Throttle::isWithinTimespanMs(started, 28800000)) {
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_INFO("Range Test Module - Disable after 8 hours");
|
2023-05-15 15:47:10 +02:00
|
|
|
return disable();
|
|
|
|
|
} else {
|
|
|
|
|
return (senderHeartbeat);
|
|
|
|
|
}
|
2021-01-31 18:20:08 -08:00
|
|
|
} else {
|
2022-12-29 18:48:33 -06:00
|
|
|
return disable();
|
2022-11-09 15:12:57 +01:00
|
|
|
// This thread does not need to run as a receiver
|
2021-01-31 18:20:08 -08:00
|
|
|
}
|
2021-01-31 09:12:36 -08:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("Range Test Module - Disabled");
|
2021-01-31 09:12:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
2022-12-29 18:49:40 -06:00
|
|
|
return disable();
|
2021-01-31 09:12:36 -08:00
|
|
|
}
|
|
|
|
|
|
2023-07-26 16:34:36 -07:00
|
|
|
/**
|
|
|
|
|
* Sends a payload to a specified destination node.
|
2023-07-26 17:08:04 -07:00
|
|
|
*
|
2023-07-26 16:34:36 -07:00
|
|
|
* @param dest The destination node number.
|
|
|
|
|
* @param wantReplies Whether or not to request replies from the destination node.
|
|
|
|
|
*/
|
2022-02-27 01:49:24 -08:00
|
|
|
void RangeTestModuleRadio::sendPayload(NodeNum dest, bool wantReplies)
|
2021-01-31 09:12:36 -08:00
|
|
|
{
|
2023-02-03 00:42:35 +01:00
|
|
|
meshtastic_MeshPacket *p = allocDataPacket();
|
2021-01-31 09:12:36 -08:00
|
|
|
p->to = dest;
|
|
|
|
|
p->decoded.want_response = wantReplies;
|
2024-03-10 05:39:37 -03:00
|
|
|
p->hop_limit = 0;
|
2024-03-11 13:49:46 -03:00
|
|
|
p->want_ack = false;
|
2021-01-31 18:20:08 -08:00
|
|
|
|
2021-02-03 08:10:13 -08:00
|
|
|
packetSequence++;
|
|
|
|
|
|
2024-09-23 09:20:32 -05:00
|
|
|
static char heartbeatString[MAX_LORA_PAYLOAD_LEN + 1];
|
2021-03-20 00:38:53 -07:00
|
|
|
snprintf(heartbeatString, sizeof(heartbeatString), "seq %u", packetSequence);
|
2021-01-31 18:20:08 -08:00
|
|
|
|
2021-02-22 10:39:46 +08:00
|
|
|
p->decoded.payload.size = strlen(heartbeatString); // You must specify how many bytes are in the reply
|
|
|
|
|
memcpy(p->decoded.payload.bytes, heartbeatString, p->decoded.payload.size);
|
2021-01-31 18:20:08 -08:00
|
|
|
|
2024-08-01 19:29:49 -05:00
|
|
|
service->sendToMesh(p);
|
2021-02-14 21:34:47 -08:00
|
|
|
|
|
|
|
|
// TODO: Handle this better. We want to keep the phone awake otherwise it stops sending.
|
|
|
|
|
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE);
|
2021-01-31 09:12:36 -08:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
ProcessMessage RangeTestModuleRadio::handleReceived(const meshtastic_MeshPacket &mp)
|
2021-01-31 09:12:36 -08:00
|
|
|
{
|
2025-09-02 13:08:57 +01:00
|
|
|
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_STM32WL) || defined(ARCH_PORTDUINO)
|
2021-01-31 09:12:36 -08:00
|
|
|
|
2022-05-22 13:27:56 +02:00
|
|
|
if (moduleConfig.range_test.enabled) {
|
2021-01-31 09:12:36 -08:00
|
|
|
|
2021-12-03 18:59:10 -08:00
|
|
|
/*
|
|
|
|
|
auto &p = mp.decoded;
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s",
|
2022-12-30 10:27:07 -06:00
|
|
|
LOG_INFO.getNodeNum(), mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes);
|
2021-12-03 18:59:10 -08:00
|
|
|
*/
|
2021-01-31 09:12:36 -08:00
|
|
|
|
2024-10-04 13:28:51 +02:00
|
|
|
if (!isFromUs(&mp)) {
|
2022-05-22 13:27:56 +02:00
|
|
|
if (moduleConfig.range_test.save) {
|
2021-02-13 22:21:01 -08:00
|
|
|
appendFile(mp);
|
2025-08-21 19:28:52 +12:00
|
|
|
}
|
2021-02-07 19:20:29 -08:00
|
|
|
|
2021-11-26 19:12:00 -08:00
|
|
|
/*
|
2024-03-21 09:06:37 -05:00
|
|
|
NodeInfoLite *n = nodeDB->getMeshNode(getFrom(&mp));
|
2021-12-03 18:59:10 -08:00
|
|
|
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("-----------------------------------------");
|
|
|
|
|
LOG_DEBUG("p.payload.bytes \"%s\"", p.payload.bytes);
|
|
|
|
|
LOG_DEBUG("p.payload.size %d", p.payload.size);
|
|
|
|
|
LOG_DEBUG("---- Received Packet:");
|
|
|
|
|
LOG_DEBUG("mp.from %d", mp.from);
|
|
|
|
|
LOG_DEBUG("mp.rx_snr %f", mp.rx_snr);
|
|
|
|
|
LOG_DEBUG("mp.hop_limit %d", mp.hop_limit);
|
|
|
|
|
LOG_DEBUG("---- Node Information of Received Packet (mp.from):");
|
|
|
|
|
LOG_DEBUG("n->user.long_name %s", n->user.long_name);
|
|
|
|
|
LOG_DEBUG("n->user.short_name %s", n->user.short_name);
|
|
|
|
|
LOG_DEBUG("n->has_position %d", n->has_position);
|
|
|
|
|
LOG_DEBUG("n->position.latitude_i %d", n->position.latitude_i);
|
|
|
|
|
LOG_DEBUG("n->position.longitude_i %d", n->position.longitude_i);
|
|
|
|
|
LOG_DEBUG("---- Current device location information:");
|
|
|
|
|
LOG_DEBUG("gpsStatus->getLatitude() %d", gpsStatus->getLatitude());
|
|
|
|
|
LOG_DEBUG("gpsStatus->getLongitude() %d", gpsStatus->getLongitude());
|
|
|
|
|
LOG_DEBUG("gpsStatus->getHasLock() %d", gpsStatus->getHasLock());
|
|
|
|
|
LOG_DEBUG("gpsStatus->getDOP() %d", gpsStatus->getDOP());
|
|
|
|
|
LOG_DEBUG("-----------------------------------------");
|
2021-11-26 19:12:00 -08:00
|
|
|
*/
|
2021-01-31 09:12:36 -08:00
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("Range Test Module Disabled");
|
2021-01-31 09:12:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-09-23 04:42:09 +03:00
|
|
|
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
|
2021-01-31 09:12:36 -08:00
|
|
|
}
|
2021-02-13 22:21:01 -08:00
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp)
|
2021-02-13 22:21:01 -08:00
|
|
|
{
|
2023-05-31 20:08:32 -05:00
|
|
|
#ifdef ARCH_ESP32
|
2021-02-22 10:39:46 +08:00
|
|
|
auto &p = mp.decoded;
|
2021-02-13 22:21:01 -08:00
|
|
|
|
2024-03-21 09:06:37 -05:00
|
|
|
meshtastic_NodeInfoLite *n = nodeDB->getMeshNode(getFrom(&mp));
|
2021-02-13 22:21:01 -08:00
|
|
|
/*
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("-----------------------------------------");
|
|
|
|
|
LOG_DEBUG("p.payload.bytes \"%s\"", p.payload.bytes);
|
|
|
|
|
LOG_DEBUG("p.payload.size %d", p.payload.size);
|
|
|
|
|
LOG_DEBUG("---- Received Packet:");
|
|
|
|
|
LOG_DEBUG("mp.from %d", mp.from);
|
|
|
|
|
LOG_DEBUG("mp.rx_snr %f", mp.rx_snr);
|
|
|
|
|
LOG_DEBUG("mp.hop_limit %d", mp.hop_limit);
|
|
|
|
|
LOG_DEBUG("---- Node Information of Received Packet (mp.from):");
|
|
|
|
|
LOG_DEBUG("n->user.long_name %s", n->user.long_name);
|
|
|
|
|
LOG_DEBUG("n->user.short_name %s", n->user.short_name);
|
|
|
|
|
LOG_DEBUG("n->has_position %d", n->has_position);
|
|
|
|
|
LOG_DEBUG("n->position.latitude_i %d", n->position.latitude_i);
|
|
|
|
|
LOG_DEBUG("n->position.longitude_i %d", n->position.longitude_i);
|
|
|
|
|
LOG_DEBUG("---- Current device location information:");
|
|
|
|
|
LOG_DEBUG("gpsStatus->getLatitude() %d", gpsStatus->getLatitude());
|
|
|
|
|
LOG_DEBUG("gpsStatus->getLongitude() %d", gpsStatus->getLongitude());
|
|
|
|
|
LOG_DEBUG("gpsStatus->getHasLock() %d", gpsStatus->getHasLock());
|
|
|
|
|
LOG_DEBUG("gpsStatus->getDOP() %d", gpsStatus->getDOP());
|
|
|
|
|
LOG_DEBUG("-----------------------------------------");
|
2021-02-13 22:21:01 -08:00
|
|
|
*/
|
2025-01-03 10:05:26 +08:00
|
|
|
concurrency::LockGuard g(spiLock);
|
2022-02-14 18:45:29 +01:00
|
|
|
if (!FSBegin()) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("An Error has occurred while mounting the filesystem");
|
2021-02-13 22:21:01 -08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-14 18:45:29 +01:00
|
|
|
if (FSCom.totalBytes() - FSCom.usedBytes() < 51200) {
|
2024-11-04 20:09:23 +08:00
|
|
|
LOG_DEBUG("Filesystem doesn't have enough free space. Aborting write");
|
2021-02-13 22:21:01 -08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-09 15:12:57 +01:00
|
|
|
FSCom.mkdir("/static");
|
|
|
|
|
|
2021-02-14 16:17:40 -08:00
|
|
|
// If the file doesn't exist, write the header.
|
2022-02-14 18:45:29 +01:00
|
|
|
if (!FSCom.exists("/static/rangetest.csv")) {
|
2021-02-14 16:17:40 -08:00
|
|
|
//--------- Write to file
|
2022-02-14 18:45:29 +01:00
|
|
|
File fileToWrite = FSCom.open("/static/rangetest.csv", FILE_WRITE);
|
2021-02-13 22:21:01 -08:00
|
|
|
|
2021-02-14 16:17:40 -08:00
|
|
|
if (!fileToWrite) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_ERROR("There was an error opening the file for writing");
|
2021-02-14 16:17:40 -08:00
|
|
|
return 0;
|
|
|
|
|
}
|
2021-02-13 22:21:01 -08:00
|
|
|
|
2021-03-25 19:25:20 -07:00
|
|
|
// Print the CSV header
|
|
|
|
|
if (fileToWrite.println(
|
2021-12-07 09:14:31 -08:00
|
|
|
"time,from,sender name,sender lat,sender long,rx lat,rx long,rx elevation,rx snr,distance,hop limit,payload")) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("File was written");
|
2021-02-14 16:17:40 -08:00
|
|
|
} else {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_ERROR("File write failed");
|
2021-02-14 16:17:40 -08:00
|
|
|
}
|
2023-04-14 10:55:05 +02:00
|
|
|
fileToWrite.flush();
|
2021-02-14 16:17:40 -08:00
|
|
|
fileToWrite.close();
|
|
|
|
|
}
|
2021-02-13 22:21:01 -08:00
|
|
|
|
2022-02-14 18:45:29 +01:00
|
|
|
//--------- Append content to file
|
|
|
|
|
File fileToAppend = FSCom.open("/static/rangetest.csv", FILE_APPEND);
|
2021-02-13 22:21:01 -08:00
|
|
|
|
|
|
|
|
if (!fileToAppend) {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_ERROR("There was an error opening the file for appending");
|
2021-02-13 22:21:01 -08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
if (!gettimeofday(&tv, NULL)) {
|
|
|
|
|
long hms = tv.tv_sec % SEC_PER_DAY;
|
|
|
|
|
hms = (hms + SEC_PER_DAY) % SEC_PER_DAY;
|
|
|
|
|
|
|
|
|
|
// Tear apart hms into h:m:s
|
|
|
|
|
int hour = hms / SEC_PER_HOUR;
|
|
|
|
|
int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN;
|
|
|
|
|
int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN
|
|
|
|
|
|
2021-02-14 16:17:40 -08:00
|
|
|
fileToAppend.printf("%02d:%02d:%02d,", hour, min, sec); // Time
|
2021-02-13 22:21:01 -08:00
|
|
|
} else {
|
2021-02-14 16:17:40 -08:00
|
|
|
fileToAppend.printf("??:??:??,"); // Time
|
2021-02-13 22:21:01 -08:00
|
|
|
}
|
|
|
|
|
|
2024-12-21 12:26:23 +11:00
|
|
|
fileToAppend.printf("%d,", getFrom(&mp)); // From
|
|
|
|
|
fileToAppend.printf("%s,", n->user.long_name); // Long Name
|
|
|
|
|
fileToAppend.printf("%f,", n->position.latitude_i * 1e-7); // Sender Lat
|
|
|
|
|
fileToAppend.printf("%f,", n->position.longitude_i * 1e-7); // Sender Long
|
|
|
|
|
if (gpsStatus->getIsConnected() || config.position.fixed_position) {
|
|
|
|
|
fileToAppend.printf("%f,", gpsStatus->getLatitude() * 1e-7); // RX Lat
|
|
|
|
|
fileToAppend.printf("%f,", gpsStatus->getLongitude() * 1e-7); // RX Long
|
|
|
|
|
fileToAppend.printf("%d,", gpsStatus->getAltitude()); // RX Altitude
|
|
|
|
|
} else {
|
|
|
|
|
// When the phone API is in use, the node info will be updated with position
|
|
|
|
|
meshtastic_NodeInfoLite *us = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
|
|
|
|
fileToAppend.printf("%f,", us->position.latitude_i * 1e-7); // RX Lat
|
|
|
|
|
fileToAppend.printf("%f,", us->position.longitude_i * 1e-7); // RX Long
|
|
|
|
|
fileToAppend.printf("%d,", us->position.altitude); // RX Altitude
|
|
|
|
|
}
|
2021-03-25 19:25:20 -07:00
|
|
|
|
|
|
|
|
fileToAppend.printf("%f,", mp.rx_snr); // RX SNR
|
2021-02-14 16:17:40 -08:00
|
|
|
|
|
|
|
|
if (n->position.latitude_i && n->position.longitude_i && gpsStatus->getLatitude() && gpsStatus->getLongitude()) {
|
2021-10-09 13:28:51 -04:00
|
|
|
float distance = GeoCoord::latLongToMeter(n->position.latitude_i * 1e-7, n->position.longitude_i * 1e-7,
|
2022-01-26 22:20:13 -08:00
|
|
|
gpsStatus->getLatitude() * 1e-7, gpsStatus->getLongitude() * 1e-7);
|
2021-02-14 16:17:40 -08:00
|
|
|
fileToAppend.printf("%f,", distance); // Distance in meters
|
|
|
|
|
} else {
|
|
|
|
|
fileToAppend.printf("0,");
|
|
|
|
|
}
|
2021-02-13 22:21:01 -08:00
|
|
|
|
2021-12-07 09:14:31 -08:00
|
|
|
fileToAppend.printf("%d,", mp.hop_limit); // Packet Hop Limit
|
|
|
|
|
|
2021-02-13 22:21:01 -08:00
|
|
|
// TODO: If quotes are found in the payload, it has to be escaped.
|
|
|
|
|
fileToAppend.printf("\"%s\"\n", p.payload.bytes);
|
2023-04-14 10:55:05 +02:00
|
|
|
fileToAppend.flush();
|
2021-02-13 22:21:01 -08:00
|
|
|
fileToAppend.close();
|
|
|
|
|
|
|
|
|
|
return 1;
|
2025-09-19 22:17:03 +12:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
LOG_ERROR("Failed to store range test results - feature only available for ESP32");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
2025-08-21 11:55:53 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RangeTestModuleRadio::removeFile()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ARCH_ESP32
|
2025-08-21 12:01:45 +12:00
|
|
|
if (!FSBegin()) {
|
|
|
|
|
LOG_DEBUG("An Error has occurred while mounting the filesystem");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!FSCom.exists("/static/rangetest.csv")) {
|
|
|
|
|
LOG_DEBUG("No range tests found.");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG_INFO("Deleting previous range test.");
|
|
|
|
|
bool result = FSCom.remove("/static/rangetest.csv");
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
LOG_ERROR("Failed to delete range test.");
|
|
|
|
|
return 0;
|
2025-08-21 11:55:53 +12:00
|
|
|
}
|
2025-08-21 12:01:45 +12:00
|
|
|
LOG_INFO("Range test removed.");
|
2025-08-21 11:55:53 +12:00
|
|
|
|
|
|
|
|
return 1;
|
2025-09-19 22:17:03 +12:00
|
|
|
#else
|
|
|
|
|
LOG_ERROR("Failed to remove range test results - feature only available for ESP32");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
2025-08-21 12:00:19 +12:00
|
|
|
}
|