diff --git a/protobufs b/protobufs index e22381a3..8a908f72 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit e22381a3c6bbdd428f127ed8c0aa0a37789c3907 +Subproject commit 8a908f7250c355057d14223d41ba313acefc40f1 diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index ebe3debd..fb57949e 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -261,6 +261,9 @@ bool NodeDB::factoryReset(bool eraseBleBonds) if (FSCom.exists("/static/rangetest.csv") && !FSCom.remove("/static/rangetest.csv")) { LOG_ERROR("Could not remove rangetest.csv file"); } + if (FSCom.exists("/static/rangetestout.csv") && !FSCom.remove("/static/rangetestout.csv")) { + LOG_ERROR("Could not remove rangetestout.csv file"); + } #endif // second, install default state (this will deal with the duplicate mac address issue) installDefaultDeviceState(); @@ -1224,4 +1227,4 @@ void recordCriticalError(meshtastic_CriticalErrorCode code, uint32_t address, co LOG_ERROR("A critical failure occurred, portduino is exiting..."); exit(2); #endif -} +} \ No newline at end of file diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 5500a559..05800eb9 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -378,10 +378,10 @@ int32_t PositionModule::runOnce() default_broadcast_interval_secs, numOnlineNodes); uint32_t msSinceLastSend = now - lastGpsSend; // Only send packets if the channel util. is less than 25% utilized or we're a tracker with less than 40% utilized. - if (!airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER && - config.device.role != meshtastic_Config_DeviceConfig_Role_TAK_TRACKER)) { - return RUNONCE_INTERVAL; - } + // if (!airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER && + // config.device.role != meshtastic_Config_DeviceConfig_Role_TAK_TRACKER)) { + // return RUNONCE_INTERVAL; + //} if (lastGpsSend == 0 || msSinceLastSend >= intervalMs) { if (hasValidPosition(node)) { diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index 2deb2ba9..be27f2b7 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -75,17 +75,17 @@ int32_t RangeTestModule::runOnce() LOG_INFO("fixed_position() %d", config.position.fixed_position); // Only send packets if the channel is less than 25% utilized. - if (airTime->isTxAllowedChannelUtil(true)) { - rangeTestModuleRadio->sendPayload(); - } + // if (airTime->isTxAllowedChannelUtil(true)) { + rangeTestModuleRadio->sendPayload(); + //} // If we have been running for more than 8 hours, turn module back off - if (!Throttle::isWithinTimespanMs(started, 28800000)) { - LOG_INFO("Range Test Module - Disabling after 8 hours"); - return disable(); - } else { - return (senderHeartbeat); - } + // if (!Throttle::isWithinTimespanMs(started, 28800000)) { + // LOG_INFO("Range Test Module - Disabling after 8 hours"); + // return disable(); + //} else { + return (senderHeartbeat); + //} } else { return disable(); // This thread does not need to run as a receiver @@ -122,6 +122,7 @@ void RangeTestModuleRadio::sendPayload(NodeNum dest, bool wantReplies) memcpy(p->decoded.payload.bytes, heartbeatString, p->decoded.payload.size); service->sendToMesh(p); + appendSenderFile(*p); // TODO: Handle this better. We want to keep the phone awake otherwise it stops sending. powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); @@ -291,5 +292,102 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) fileToAppend.close(); #endif + return 1; +} + +bool RangeTestModuleRadio::appendSenderFile(const meshtastic_MeshPacket &mp) +{ +#ifdef ARCH_ESP32 + // auto &p = mp.decoded; + + meshtastic_NodeInfoLite *n = nodeDB->getMeshNode(getFrom(&mp)); + /* + 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("mp.decoded.position.latitude_i %d", mp.decoded.position.latitude_i); // Deprecated + // LOG_DEBUG("mp.decoded.position.longitude_i %d", mp.decoded.position.longitude_i); // Deprecated + 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("-----------------------------------------"); + */ + + if (!FSBegin()) { + LOG_DEBUG("An Error has occurred while mounting the filesystem..."); + return 0; + } + + if (FSCom.totalBytes() - FSCom.usedBytes() < 51200) { + LOG_DEBUG("Filesystem doesn't have enough free space. Aborting write."); + return 0; + } + + FSCom.mkdir("/static"); + + // If the file doesn't exist, write the header. + if (!FSCom.exists("/static/rangetestout.csv")) { + //--------- Write to file + File fileToWrite = FSCom.open("/static/rangetestout.csv", FILE_WRITE); + + if (!fileToWrite) { + LOG_ERROR("There was an error opening the file for writing"); + return 0; + } + + // Print the CSV header + if (fileToWrite.println("time,from,sender name,rx lat,rx long,rx elevation")) { + LOG_INFO("File was written"); + } else { + LOG_ERROR("File write failed"); + } + fileToWrite.flush(); + fileToWrite.close(); + } + + //--------- Append content to file + File fileToAppend = FSCom.open("/static/rangetestout.csv", FILE_APPEND); + + if (!fileToAppend) { + LOG_ERROR("There was an error opening the file for appending"); + 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 + + fileToAppend.printf("%02d:%02d:%02d,", hour, min, sec); // Time + } else { + fileToAppend.printf("??:??:??,"); // Time + } + + fileToAppend.printf("%d,", getFrom(&mp)); // From + fileToAppend.printf("%s,", n->user.long_name); // Long Name + fileToAppend.printf("%f,", gpsStatus->getLatitude() * 1e-7); // RX Lat + fileToAppend.printf("%f,", gpsStatus->getLongitude() * 1e-7); // RX Long + fileToAppend.printf("%d\n", gpsStatus->getAltitude()); // RX Altitude + fileToAppend.flush(); + fileToAppend.close(); +#endif + return 1; } \ No newline at end of file diff --git a/src/modules/RangeTestModule.h b/src/modules/RangeTestModule.h index b632d343..23d8a5b0 100644 --- a/src/modules/RangeTestModule.h +++ b/src/modules/RangeTestModule.h @@ -43,6 +43,7 @@ class RangeTestModuleRadio : public SinglePortModule * Append range test data to the file on the Filesystem */ bool appendFile(const meshtastic_MeshPacket &mp); + bool appendSenderFile(const meshtastic_MeshPacket &mp); protected: /** Called to handle a particular incoming message @@ -53,4 +54,4 @@ class RangeTestModuleRadio : public SinglePortModule virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override; }; -extern RangeTestModuleRadio *rangeTestModuleRadio; +extern RangeTestModuleRadio *rangeTestModuleRadio; \ No newline at end of file