From cdb4756d9d12a21560ea9522ee8665e7e5786769 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 29 Mar 2021 20:56:02 +0800 Subject: [PATCH 01/13] fix native build --- docs/software/TODO.md | 10 ++++++++++ src/concurrency/BinarySemaphorePosix.h | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 828f4f93..af36c693 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -4,8 +4,14 @@ You probably don't care about this section - skip to the next one. ## before next release +* TCP mode for android, localhost is at 10.0.2.2 +* make sure USB still works in android +* add portduino builds to zip +* add license to portduino and make announcement +* @havealoha comments about odd sleep behavior * DONE naks are being dropped (though enqueuedLocal) sometimes before phone/PC gets them * DONE have android fill in if local GPS has poor signal +* release to beta and amazon * fix heltec battery scaling * add reference counting to mesh packets * allow multiple simultanteous phoneapi connections @@ -38,6 +44,10 @@ You probably don't care about this section - skip to the next one. ## MQTT +* do initial development inside of portduino +* do as much possible on the device side (so we can eventually just have ESP32 talk directly to server) +* eventually add a MQTTPacket on the ToRadio & FromRadio links + ## Multichannel support * DONE cleanup the external notification and serial plugins diff --git a/src/concurrency/BinarySemaphorePosix.h b/src/concurrency/BinarySemaphorePosix.h index 8a636867..475b2987 100644 --- a/src/concurrency/BinarySemaphorePosix.h +++ b/src/concurrency/BinarySemaphorePosix.h @@ -1,6 +1,5 @@ #pragma once -#include "configuration.h" #include "../freertosinc.h" namespace concurrency @@ -28,4 +27,4 @@ class BinarySemaphorePosix #endif -} \ No newline at end of file +} // namespace concurrency \ No newline at end of file From a9c8564524530668ec8348799042f451353d3139 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 30 Mar 2021 23:11:33 +0800 Subject: [PATCH 02/13] fix millisecond unsigned rollover errors found via portduino --- src/OSTimer.cpp | 2 +- src/gps/RTC.cpp | 2 +- src/mesh/PhoneAPI.cpp | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/OSTimer.cpp b/src/OSTimer.cpp index 0978163c..9be4bd3d 100644 --- a/src/OSTimer.cpp +++ b/src/OSTimer.cpp @@ -40,7 +40,7 @@ bool scheduleHWCallback(PendableFunction callback, void *param1, uint32_t param2 tParam1 = param1; tParam2 = param2; - timerAlarmWrite(timer, delayMsec * 1000L, false); // Do not reload, we want it to be a single shot timer + timerAlarmWrite(timer, delayMsec * 1000UL, false); // Do not reload, we want it to be a single shot timer timerRestart(timer); timerAlarmEnable(timer); return true; diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index 87b73ce8..5f6a54c5 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -39,7 +39,7 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) currentQuality = q; shouldSet = true; DEBUG_MSG("Upgrading time to RTC %ld secs (quality %d)\n", tv->tv_sec, q); - } else if(q == RTCQualityGPS && (now - lastSetMsec) > (12 * 60 * 60 * 1000L)) { + } else if(q == RTCQualityGPS && (now - lastSetMsec) > (12 * 60 * 60 * 1000UL)) { // Every 12 hrs we will slam in a new GPS time, to correct for local RTC clock drift shouldSet = true; DEBUG_MSG("Reapplying external time to correct clock drift %ld secs\n", tv->tv_sec); diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index db039afb..018ab6d3 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -15,7 +15,10 @@ #error ToRadio is too big #endif -PhoneAPI::PhoneAPI() {} +PhoneAPI::PhoneAPI() +{ + lastContactMsec = millis(); +} PhoneAPI::~PhoneAPI() { @@ -53,9 +56,12 @@ void PhoneAPI::close() void PhoneAPI::checkConnectionTimeout() { if (isConnected()) { - bool newConnected = (millis() - lastContactMsec < getPref_phone_timeout_secs() * 1000L); - if (!newConnected) + uint32_t now = millis(); + bool newContact = (now - lastContactMsec) < getPref_phone_timeout_secs() * 1000UL; + if (!newContact) { + DEBUG_MSG("Timed out on phone contact, dropping phone connection\n"); close(); + } } } From b70a359fe83a3a0d504db590482c290abdefdceb Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 30 Mar 2021 23:11:56 +0800 Subject: [PATCH 03/13] leave phone timeout off a bit longer --- src/PowerFSM.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 338412c3..e101c494 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -303,7 +303,9 @@ void PowerFSM_setup() #ifndef NRF52_SERIES // We never enter light-sleep or NB states on NRF52 (because the CPU uses so little power normally) - powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); + // I don't think this transition is correct, turning off for now - @geeksville + // powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); + powerFSM.add_timed_transition(&stateNB, &stateLS, getPref_min_wake_secs() * 1000, NULL, "Min wake timeout"); powerFSM.add_timed_transition(&stateDARK, &stateLS, getPref_wait_bluetooth_secs() * 1000, NULL, "Bluetooth timeout"); #else From 5fdcb72d467c3f6e92fdadef501dedd7c78141cb Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 30 Mar 2021 23:34:13 +0800 Subject: [PATCH 04/13] cleanup applyModemConfig based on porduino testing, share with sim --- docs/software/TODO.md | 2 ++ platformio.ini | 4 ++-- src/mesh/RF95Interface.cpp | 21 +++++++++++---------- src/mesh/RadioInterface.cpp | 18 +++++++++++++----- src/mesh/RadioInterface.h | 27 +++++++++++++-------------- src/mesh/SX1262Interface.cpp | 20 +++++++++++--------- 6 files changed, 52 insertions(+), 40 deletions(-) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index af36c693..f10e4bcc 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -4,6 +4,8 @@ You probably don't care about this section - skip to the next one. ## before next release +* don't store User admin or position broadcasts in the ToPhone queue +* DONE tcp stream problem in python+pordtuino, server thinks client dropped when client DID NOT DROP * TCP mode for android, localhost is at 10.0.2.2 * make sure USB still works in android * add portduino builds to zip diff --git a/platformio.ini b/platformio.ini index 519da9c3..32de8f5f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam +;default_envs = tbeam ;default_envs = tbeam0.7 ;default_envs = heltec ;default_envs = tlora-v1 @@ -18,7 +18,7 @@ default_envs = tbeam ;default_envs = lora-relay-v1 # nrf board ;default_envs = eink ;default_envs = nrf52840dk-geeksville -;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here [common] ; common is not currently used diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index a94a8d12..e99ec2e3 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -36,8 +36,6 @@ bool RF95Interface::init() { RadioLibInterface::init(); - applyModemConfig(); - if (power == 0) power = POWER_DEFAULT; @@ -86,24 +84,25 @@ void INTERRUPT_ATTR RF95Interface::disableInterrupt() lora->clearDio0Action(); } - - bool RF95Interface::reconfigure() { - applyModemConfig(); + RadioLibInterface::reconfigure(); // set mode to standby setStandby(); // configure publicly accessible settings int err = lora->setSpreadingFactor(sf); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setBandwidth(bw); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setCodingRate(cr); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora->setSyncWord(syncWord); assert(err == ERR_NONE); @@ -115,12 +114,14 @@ bool RF95Interface::reconfigure() assert(err == ERR_NONE); err = lora->setFrequency(freq); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); if (power > MAX_POWER) // This chip has lower power limits than some power = MAX_POWER; err = lora->setOutputPower(power); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); startReceive(); // restart receiving diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 0ee23529..abdd3c14 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -1,12 +1,12 @@ -#include "configuration.h" #include "RadioInterface.h" #include "Channels.h" #include "MeshRadio.h" #include "MeshService.h" #include "NodeDB.h" -#include "assert.h" #include "Router.h" +#include "assert.h" +#include "configuration.h" #include "sleep.h" #include #include @@ -31,8 +31,8 @@ const RegionInfo regions[] = { /* Notes about the RU bandplan (from @denis-d in https://meshtastic.discourse.group/t/russian-band-plan-proposal/2786/2): -According to Annex 12 to GKRCh (National Radio Frequency Commission) decision № 18-46-03-1 (September 11th 2018) https://digital.gov.ru/uploaded/files/prilozhenie-12-k-reshenyu-gkrch-18-46-03-1.pdf 1 -We have 3 options for 868 MHz: +According to Annex 12 to GKRCh (National Radio Frequency Commission) decision № 18-46-03-1 (September 11th 2018) +https://digital.gov.ru/uploaded/files/prilozhenie-12-k-reshenyu-gkrch-18-46-03-1.pdf 1 We have 3 options for 868 MHz: 864,0 - 865,0 MHz ERP 25mW, Duty Cycle 0.1% (3.6 sec in hour) or LBT (Listen Before Talk), prohibited in airports. 866,0 - 868,0 MHz ERP 25mW, Duty Cycle 1% or LBT, PSD (Power Spectrum Density) 1000mW/MHz, prohibited in airports @@ -153,7 +153,7 @@ void printPacket(const char *prefix, const MeshPacket *p) if (s.dest != 0) DEBUG_MSG(" dest=%08x", s.dest); - if(s.request_id) + if (s.request_id) DEBUG_MSG(" requestId=%0x", s.request_id); /* now inside Data and therefore kinda opaque @@ -185,6 +185,12 @@ RadioInterface::RadioInterface() // DEBUG_MSG("Set meshradio defaults name=%s\n", channelSettings.name); } +bool RadioInterface::reconfigure() +{ + applyModemConfig(); + return true; +} + bool RadioInterface::init() { DEBUG_MSG("Starting meshradio init...\n"); @@ -197,6 +203,8 @@ bool RadioInterface::init() // radioIf.setThisAddress(nodeDB.getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at constructor // time. + applyModemConfig(); + return true; } diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 9d19fa59..31842935 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -104,7 +104,11 @@ class RadioInterface virtual bool sleep() { return true; } /// Disable this interface (while disabled, no packets can be sent or received) - void disable() { disabled = true; sleep(); } + void disable() + { + disabled = true; + sleep(); + } /** * Send a packet (possibly by enquing in a private fifo). This routine will @@ -126,7 +130,7 @@ class RadioInterface /// Apply any radio provisioning changes /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. - virtual bool reconfigure() = 0; + virtual bool reconfigure(); /** The delay to use for retransmitting dropped packets */ uint32_t getRetransmissionMsec(const MeshPacket *p); @@ -174,13 +178,6 @@ class RadioInterface */ void limitPower(); - /** - * Convert our modemConfig enum into wf, sf, etc... - * - * These paramaters will be pull from the channelSettings global - */ - virtual void applyModemConfig(); - /** * Save the frequency we selected for later reuse. */ @@ -192,6 +189,13 @@ class RadioInterface virtual void saveChannelNum(uint32_t savedChannelNum); private: + /** + * Convert our modemConfig enum into wf, sf, etc... + * + * These paramaters will be pull from the channelSettings global + */ + void applyModemConfig(); + /// Return 0 if sleep is okay int preflightSleepCb(void *unused = NULL) { return canSleep() ? 0 : 1; } @@ -215,11 +219,6 @@ class SimRadio : public RadioInterface /// Make sure the Driver is properly configured before calling init(). /// \return true if initialisation succeeded. virtual bool init() { return true; } - - /// Apply any radio provisioning changes - /// Make sure the Driver is properly configured before calling init(). - /// \return true if initialisation succeeded. - virtual bool reconfigure() { return true; } }; /// Debug printing for packets diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index ad35d700..2a68bca3 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -23,8 +23,6 @@ bool SX1262Interface::init() pinMode(SX1262_POWER_EN, OUTPUT); #endif - RadioLibInterface::init(); - #ifdef SX1262_RXEN // set not rx or tx mode digitalWrite(SX1262_RXEN, LOW); // Set low before becoming an output pinMode(SX1262_RXEN, OUTPUT); @@ -38,11 +36,11 @@ bool SX1262Interface::init() float tcxoVoltage = 0; // None - we use an XTAL #else // Use DIO3 to power tcxo per https://github.com/jgromes/RadioLib/issues/12#issuecomment-520695575 - float tcxoVoltage = 1.8; + float tcxoVoltage = 1.8; #endif bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC? - applyModemConfig(); + RadioLibInterface::init(); if (power == 0) power = SX1262_MAX_POWER; @@ -72,20 +70,23 @@ bool SX1262Interface::init() bool SX1262Interface::reconfigure() { - applyModemConfig(); + RadioLibInterface::reconfigure(); // set mode to standby setStandby(); // configure publicly accessible settings int err = lora.setSpreadingFactor(sf); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora.setBandwidth(bw); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); err = lora.setCodingRate(cr); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); // Hmm - seems to lower SNR when the signal levels are high. Leaving off for now... err = lora.setRxGain(true); @@ -101,7 +102,8 @@ bool SX1262Interface::reconfigure() assert(err == ERR_NONE); err = lora.setFrequency(freq); - if(err != ERR_NONE) recordCriticalError(CriticalErrorCode_InvalidRadioSetting); + if (err != ERR_NONE) + recordCriticalError(CriticalErrorCode_InvalidRadioSetting); if (power > 22) // This chip has lower power limits than some power = 22; From b68397a9113f791e0a33d8f286272d4666e1dd54 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 30 Mar 2021 23:39:51 +0800 Subject: [PATCH 05/13] fix simradio init to work more like real radios --- .idea/workspace.xml | 27 ++++++++++++++++++--------- docs/software/TODO.md | 1 + src/mesh/RadioInterface.cpp | 2 ++ src/mesh/RadioInterface.h | 7 ------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1381bb27..ff02c992 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -16,15 +16,16 @@ - - + + + +