Compare commits

..

39 Commits
1.0.0 ... 1.1.0

Author SHA1 Message Date
Kevin Hester
5d8f541e70 Merge pull request #418 from geeksville/master
1.1.0
2020-09-19 10:33:48 -07:00
geeksville
bd126b866c 1.1.0 2020-09-19 10:32:57 -07:00
Kevin Hester
036a1991b8 Merge pull request #403 from r51n/anz
Add Australia/New Zealand channels and build target
2020-09-19 07:48:17 -07:00
Kevin Hester
5fb0bf2575 Merge branch 'master' into anz 2020-09-18 10:19:43 -07:00
Kevin Hester
9af2045dc1 Merge pull request #404 from geeksville/master
Merge portduino/sim beginnings into mainline
2020-09-18 10:18:33 -07:00
geeksville
3541228c1f update to my latest radiolib 2020-09-17 11:41:34 -07:00
geeksville
cc95361fdc Merge remote-tracking branch 'root/master' 2020-09-17 11:24:42 -07:00
geeksville
9b1d1ad0a5 add linux/portduino to the CI test build
Signed-off-by: geeksville <kevinh@geeksville.com>
2020-09-17 11:23:46 -07:00
geeksville
7e467f1466 Merge branch 'portduino' 2020-09-17 11:20:50 -07:00
geeksville
d3e28e3e2c Merge branch 'dev' 2020-09-17 11:20:41 -07:00
r51n
1a1a0fbfbe add ANZ to build list 2020-09-17 12:04:38 +00:00
r51n
91305c2c84 add AU/NZ channel definitions 2020-09-17 12:02:38 +00:00
Kevin Hester
004f1f625b Merge pull request #398 from geeksville/master
misc atomic bug fixes - see commits
2020-09-16 10:10:00 -07:00
geeksville
fc20f658e6 Fix #362 by @a-f-G-U-C - I was mispelling NMEA ;-) 2020-09-16 09:22:03 -07:00
geeksville
8e988cc926 fix #397 from @a-f-G-U-C - bogus GPS positions during locking could be reported
btw - from my read of the NMEA, the lowest value that means 'has a valid
position' is 1 not 2.  But I only know this because you pointed me at
it ;-)

Thanks!
2020-09-16 09:18:44 -07:00
geeksville
8c240b59f6 fix #393. immediately save node db to disk if user changes name 2020-09-16 09:08:35 -07:00
geeksville
f847e30a3c Merge remote-tracking branch 'root/master' 2020-09-16 09:04:27 -07:00
geeksville
7050ae4ba1 Merge branch 'master' into portduino 2020-09-15 21:14:42 -07:00
geeksville
3e64d8439d Merge branch 'master' into dev 2020-09-15 21:13:24 -07:00
geeksville
435c955acd make hash prototype a bit stricter 2020-09-15 21:05:57 -07:00
geeksville
c6d93d1a28 fix #346 limit tx power in japan 2020-09-15 18:54:50 -07:00
Kevin Hester
b0c82dcb5b Merge pull request #394 from geeksville/master
misc bug fixes
2020-09-15 18:19:58 -07:00
geeksville
7d4058f49d let users set 20 dBm if they wish 2020-09-15 18:00:21 -07:00
geeksville
31fc8fafec make default power level radio chipset specific 2020-09-15 17:55:33 -07:00
geeksville
313cee9a3f update webpage 2020-09-15 17:54:55 -07:00
geeksville
16de4a0d2e Merge remote-tracking branch 'root/master' 2020-09-14 09:25:31 -07:00
geeksville
621fcb598e Declare 1.0 2020-09-14 09:25:14 -07:00
geeksville
92df77f228 Merge remote-tracking branch 'root/master' into dev 2020-09-11 18:15:13 -07:00
geeksville
46ba36511a Merge branch 'portduino' into dev
# Conflicts:
#	platformio.ini
2020-09-07 16:31:17 -07:00
geeksville
f3d38d84c9 fix nrf52 build 2020-09-07 13:03:37 -07:00
geeksville
f8bb6bbcb4 try to bang on SPI from simulator 2020-09-06 16:32:13 -07:00
geeksville
e0d5b9dce1 use simradio on portduino 2020-09-06 16:09:07 -07:00
geeksville
94e4b30125 add crude sim getmacaddr 2020-09-06 16:07:32 -07:00
geeksville
2a067e7f6b make gps optional. Portduino almost works in sim! 2020-09-06 14:45:43 -07:00
geeksville
97ab07e05c WIP 2020-09-06 10:09:40 -07:00
geeksville
b8d39845cf portduino now links! 2020-09-06 09:24:08 -07:00
geeksville
fefd3d78f3 Portduino WIP now compiles but does not link 2020-09-05 12:34:48 -07:00
geeksville
6a475d8288 WIP 2020-09-04 17:23:17 -07:00
geeksville
c629b94333 portduino WIP 2020-09-04 15:03:22 -07:00
54 changed files with 595 additions and 244 deletions

View File

@@ -23,4 +23,4 @@ jobs:
run: | run: |
pip install -U adafruit-nrfutil pip install -U adafruit-nrfutil
- name: Build - name: Build
run: platformio run -e tbeam -e heltec -e lora-relay-v1 run: platformio run -e tbeam -e heltec -e lora-relay-v1 -e linux

View File

@@ -48,7 +48,8 @@
"optional": "cpp", "optional": "cpp",
"string_view": "cpp", "string_view": "cpp",
"cassert": "cpp", "cassert": "cpp",
"iterator": "cpp" "iterator": "cpp",
"shared_mutex": "cpp"
}, },
"cSpell.words": [ "cSpell.words": [
"Blox", "Blox",

View File

@@ -4,7 +4,7 @@ set -e
source bin/version.sh source bin/version.sh
COUNTRIES="US EU433 EU865 CN JP" COUNTRIES="US EU433 EU865 CN JP ANZ"
#COUNTRIES=US #COUNTRIES=US
#COUNTRIES=CN #COUNTRIES=CN

View File

@@ -1,3 +1,3 @@
export VERSION=1.0.0 export VERSION=1.1.0

View File

@@ -43,7 +43,8 @@ For an detailed walk-through aimed at beginners, we recommend [meshtastic.letsta
Note: Updates are happening almost daily, only major updates are listed below. For more details see our forum. Note: Updates are happening almost daily, only major updates are listed below. For more details see our forum.
- 06/24/2020 - 0.7.x Now with over 1000 android users, over 600 people using the radios and translated into 13 languages. Fairly stable and we are working through bugs to get to 1.0. - 09/14/2020 - 1.0.0 Now with over 1700 android users, over 2000 nodes and translated into 15 languages. This project will always be a "beta" experiment, but now quite usable. We are currently selecting 1.1 features in our discussion forum.
- 06/24/2020 - 0.7.x Now with over 1000 android users, over 600 people using the radios and translated into 22 languages. Fairly stable and we are working through bugs to get to 1.0.
- 06/04/2020 - 0.6.7 Beta releases of both the application and the device code are released. Features are fairly solid now with a sizable number of users. - 06/04/2020 - 0.6.7 Beta releases of both the application and the device code are released. Features are fairly solid now with a sizable number of users.
- 04/28/2020 - 0.6.0 [Python API](https://pypi.org/project/meshtastic/) released. Makes it easy to use meshtastic devices as "zero config / just works" mesh transport adapters for other projects. - 04/28/2020 - 0.6.0 [Python API](https://pypi.org/project/meshtastic/) released. Makes it easy to use meshtastic devices as "zero config / just works" mesh transport adapters for other projects.
- 04/20/2020 - 0.4.3 Pretty solid now both for the android app and the device code. Many people have donated translations and code. Probably going to call it a beta soon. - 04/20/2020 - 0.4.3 Pretty solid now both for the android app and the device code. Many people have donated translations and code. Probably going to call it a beta soon.
@@ -77,13 +78,14 @@ Make sure to buy the frequency range which is legal for your country. For the US
Instructions for installing prebuilt firmware can be found [here](https://github.com/meshtastic/Meshtastic-esp32/blob/master/README.md). Instructions for installing prebuilt firmware can be found [here](https://github.com/meshtastic/Meshtastic-esp32/blob/master/README.md).
For a nice looking cases: For a nice looking cases:
- 3D printable cases
1. TTGO T-Beam V0 see this [design](https://www.thingiverse.com/thing:3773717) by [bsiege](https://www.thingiverse.com/bsiege). - 3D printable cases
2. TTGO T_Beam V1 (SMA) see this [design](https://www.thingiverse.com/thing:3830711) by [rwanrooy](https://www.thingiverse.com/rwanrooy) or this [remix](https://www.thingiverse.com/thing:3949330) by [8ung](https://www.thingiverse.com/8ung) 1. TTGO T-Beam V0 see this [design](https://www.thingiverse.com/thing:3773717) by [bsiege](https://www.thingiverse.com/bsiege).
3. TTGO T_Beam V1 (IPEX) see this [design](https://www.thingiverse.com/thing:4587297) by [drewsed](https://www.thingiverse.com/drewsed) 2. TTGO T_Beam V1 (SMA) see this [design](https://www.thingiverse.com/thing:3830711) by [rwanrooy](https://www.thingiverse.com/rwanrooy) or this [remix](https://www.thingiverse.com/thing:3949330) by [8ung](https://www.thingiverse.com/8ung)
4. Heltec Lora32 see this [design](https://www.thingiverse.com/thing:3125854) by [ornotermes](https://www.thingiverse.com/ornotermes). 3. TTGO T_Beam V1 (IPEX) see this [design](https://www.thingiverse.com/thing:4587297) by [drewsed](https://www.thingiverse.com/drewsed)
- Laser-cut cases 4. Heltec Lora32 see this [design](https://www.thingiverse.com/thing:3125854) by [ornotermes](https://www.thingiverse.com/ornotermes).
1. TTGO T_Beam V1 (SMA) see this [design](https://www.thingiverse.com/thing:4552771) by [jefish](https://www.thingiverse.com/jefish) - Laser-cut cases
1. TTGO T_Beam V1 (SMA) see this [design](https://www.thingiverse.com/thing:4552771) by [jefish](https://www.thingiverse.com/jefish)
# IMPORTANT DISCLAIMERS AND FAQ # IMPORTANT DISCLAIMERS AND FAQ

View File

@@ -196,7 +196,7 @@ Nice ideas worth considering someday...
- DONE neg 7 error code from receive - DONE neg 7 error code from receive
- DONE remove unused sx1262 lib from github - DONE remove unused sx1262 lib from github
- at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug. - at boot we are starting our message IDs at 1, rather we should start them at a random number. also, seed random based on timer. this could be the cause of our first message not seen bug.
- add a NEMA based GPS driver to test GPS - add a NMEA based GPS driver to test GPS
- DONE use "variants" to get all gpio bindings - DONE use "variants" to get all gpio bindings
- DONE plug in correct variants for the real board - DONE plug in correct variants for the real board
- turn on DFU assistance in the appload using the nordic DFU helper lib call - turn on DFU assistance in the appload using the nordic DFU helper lib call

View File

@@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
default_envs = tbeam # or if you'd like to change the default to something like lora-relay-v1 put that here default_envs = tbeam # 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]
; common is not currently used ; common is not currently used
@@ -23,15 +23,9 @@ default_envs = tbeam # or if you'd like to change the default to something like
[env] [env]
framework = arduino
; customize the partition table
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
board_build.partitions = partition-table.csv
; note: we add src to our include search path so that lmic_project_config can override ; note: we add src to our include search path so that lmic_project_config can override
; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc ; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc
build_flags = -Wno-missing-field-initializers -Isrc -Isrc/mesh -Isrc/gps -Ilib/nanopb/include -Os -Wl,-Map,.pio/build/output.map build_flags = -Wno-missing-field-initializers -Isrc -Isrc/mesh -Isrc/gps -Ilib/nanopb/include -Wl,-Map,.pio/build/output.map
-DHW_VERSION_${sysenv.COUNTRY} -DHW_VERSION_${sysenv.COUNTRY}
-DAPP_VERSION=${sysenv.APP_VERSION} -DAPP_VERSION=${sysenv.APP_VERSION}
-DHW_VERSION=${sysenv.HW_VERSION} -DHW_VERSION=${sysenv.HW_VERSION}
@@ -60,25 +54,38 @@ debug_tool = jlink
lib_deps = lib_deps =
https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306 https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
SPI
1260 ; OneButton library for non-blocking button debounce 1260 ; OneButton library for non-blocking button debounce
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib 1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
Wire ; explicitly needed here because the AXP202 library forgets to add it
https://github.com/meshtastic/arduino-fsm.git https://github.com/meshtastic/arduino-fsm.git
https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git
https://github.com/meshtastic/RadioLib.git#7989a269be590a5d4914ac04069b58f4930c45c1 https://github.com/meshtastic/RadioLib.git#ac7feac00f5e0bd95a3ac5d5852b4cc7344cf95c
https://github.com/meshtastic/TinyGPSPlus.git https://github.com/meshtastic/TinyGPSPlus.git
https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460 https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460
Wire ; explicitly needed here because the AXP202 library forgets to add it
SPI
; Common settings for conventional (non Portduino) Ardino targets
[arduino_base]
framework = arduino
lib_deps =
${env.lib_deps}
build_flags = ${env.build_flags} -Os
src_filter = ${env.src_filter} -<portduino/>
; Common settings for ESP targes, mixin with extends = esp32_base ; Common settings for ESP targes, mixin with extends = esp32_base
[esp32_base] [esp32_base]
extends = arduino_base
platform = espressif32 platform = espressif32
src_filter = src_filter =
${env.src_filter} -<nrf52/> ${arduino_base.src_filter} -<nrf52/>
upload_speed = 921600 upload_speed = 921600
debug_init_break = tbreak setup debug_init_break = tbreak setup
build_flags = build_flags =
${env.build_flags} -Wall -Wextra -Isrc/esp32 -mfix-esp32-psram-cache-issue -lnimble -std=c++11 ${arduino_base.build_flags} -Wall -Wextra -Isrc/esp32 -Isrc/esp32-mfix-esp32-psram-cache-issue -lnimble -std=c++11
-DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DAXP_DEBUG_PORT=Serial -DAXP_DEBUG_PORT=Serial
# Hmm - this doesn't work yet # Hmm - this doesn't work yet
@@ -87,6 +94,10 @@ lib_ignore = segger_rtt
platform_packages = platform_packages =
framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#2814f110aa618429bdd9a0a2d6a93c55f29f87a6 framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#2814f110aa618429bdd9a0a2d6a93c55f29f87a6
; customize the partition table
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
board_build.partitions = partition-table.csv
; not needed included in ttgo-t-beam board file ; not needed included in ttgo-t-beam board file
; also to use PSRAM https://docs.platformio.org/en/latest/platforms/espressif32.html#external-ram-psram ; also to use PSRAM https://docs.platformio.org/en/latest/platforms/espressif32.html#external-ram-psram
; -DBOARD_HAS_PSRAM ; -DBOARD_HAS_PSRAM
@@ -99,7 +110,7 @@ platform_packages =
extends = esp32_base extends = esp32_base
board = ttgo-t-beam board = ttgo-t-beam
lib_deps = lib_deps =
${env.lib_deps} ${arduino_base.lib_deps}
build_flags = build_flags =
${esp32_base.build_flags} -D TBEAM_V10 ${esp32_base.build_flags} -D TBEAM_V10
@@ -142,25 +153,26 @@ build_flags =
platform = https://github.com/HelTecAutomation/platform-asrmicro650x.git ; we use top-of-tree because stable version has too many bugs - asrmicro650x platform = https://github.com/HelTecAutomation/platform-asrmicro650x.git ; we use top-of-tree because stable version has too many bugs - asrmicro650x
board = cubecell_board_plus board = cubecell_board_plus
; FIXME, bug in cubecell arduino - they are supposed to set ARDUINO ; FIXME, bug in cubecell arduino - they are supposed to set ARDUINO
build_flags = ${env.build_flags} -DARDUINO=100 -Isrc/cubecell build_flags = ${arduino_base.build_flags} -DARDUINO=100 -Isrc/cubecell
src_filter = src_filter =
${env.src_filter} -<esp32/> -<nrf52/> ${arduino_base.src_filter} -<esp32/> -<nrf52/>
; Common settings for NRF52 based targets ; Common settings for NRF52 based targets
[nrf52_base] [nrf52_base]
; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files ; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files
; platform = nordicnrf52 ; platform = nordicnrf52
platform = https://github.com/meshtastic/platform-nordicnrf52.git#1a2639a6b0f79b5df66bea3e3089f0d5285fdc63 platform = https://github.com/meshtastic/platform-nordicnrf52.git#1a2639a6b0f79b5df66bea3e3089f0d5285fdc63
extends = arduino_base
debug_tool = jlink debug_tool = jlink
build_type = debug ; I'm debugging with ICE a lot now build_type = debug ; I'm debugging with ICE a lot now
; note: liboberon provides the AES256 implementation for NRF52 (though not using the hardware acceleration of the NRF52840 - FIXME) ; note: liboberon provides the AES256 implementation for NRF52 (though not using the hardware acceleration of the NRF52840 - FIXME)
build_flags = build_flags =
${env.build_flags} -Wno-unused-variable ${arduino_base.build_flags} -Wno-unused-variable
-Isrc/nrf52 -Isrc/nrf52
-Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.3 -Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.3
;-DCFG_DEBUG=3 ;-DCFG_DEBUG=3
src_filter = src_filter =
${env.src_filter} -<esp32/> -<nimble/> ${arduino_base.src_filter} -<esp32/> -<nimble/>
lib_ignore = lib_ignore =
BluetoothOTA BluetoothOTA
monitor_port = /dev/ttyACM1 monitor_port = /dev/ttyACM1
@@ -212,7 +224,7 @@ monitor_speed = 115200
extends = nrf52_base extends = nrf52_base
board = ppr board = ppr
lib_deps = lib_deps =
${env.lib_deps} ${arduino_base.lib_deps}
UC1701 UC1701
; The https://github.com/BigCorvus/SX1262-LoRa-BLE-Relay board by @BigCorvus ; The https://github.com/BigCorvus/SX1262-LoRa-BLE-Relay board by @BigCorvus
@@ -233,11 +245,15 @@ build_flags = ${nrf52_base.build_flags} -Ivariants/lora_relay_v1
-DSPI_FREQUENCY=27000000 -DSPI_FREQUENCY=27000000
src_filter = ${nrf52_base.src_filter} +<../variants/lora_relay_v1> src_filter = ${nrf52_base.src_filter} +<../variants/lora_relay_v1>
lib_deps = lib_deps =
${env.lib_deps} ${arduino_base.lib_deps}
SparkFun BQ27441 LiPo Fuel Gauge Arduino Library SparkFun BQ27441 LiPo Fuel Gauge Arduino Library
TFT_eSPI TFT_eSPI
# Adafruit ST7735 and ST7789 Library # Adafruit ST7735 and ST7789 Library
; The Portduino based sim environment on top of linux
[env:linux]
platform = https://github.com/geeksville/platform-portduino.git
src_filter = ${env.src_filter} -<esp32/> -<nimble/> -<nrf52/>
build_flags = ${arduino_base.build_flags} -O0
framework = arduino
board = linux_x86_64

View File

@@ -8,7 +8,6 @@
#include "graphics/Screen.h" #include "graphics/Screen.h"
#include "sleep.h" #include "sleep.h"
#include "target_specific.h" #include "target_specific.h"
#include "timing.h"
static void sdsEnter() static void sdsEnter()
{ {
@@ -16,7 +15,7 @@ static void sdsEnter()
// Don't deepsleep if we have USB power or if the user as pressed a button recently // Don't deepsleep if we have USB power or if the user as pressed a button recently
// !isUSBPowered <- doesn't work yet because the axp192 isn't letting the battery fully charge when we are awake - FIXME // !isUSBPowered <- doesn't work yet because the axp192 isn't letting the battery fully charge when we are awake - FIXME
if (timing::millis() - lastPressMs > radioConfig.preferences.mesh_sds_timeout_secs) if (millis() - lastPressMs > radioConfig.preferences.mesh_sds_timeout_secs)
{ {
doDeepSleep(radioConfig.preferences.sds_secs); doDeepSleep(radioConfig.preferences.sds_secs);
} }
@@ -131,7 +130,7 @@ static void onEnter()
static uint32_t lastPingMs; static uint32_t lastPingMs;
uint32_t now = timing::millis(); uint32_t now = millis();
if (now - lastPingMs > 30 * 1000) { // if more than a minute since our last press, ask other nodes to update their state if (now - lastPingMs > 30 * 1000) { // if more than a minute since our last press, ask other nodes to update their state
if (displayedNodeNum) if (displayedNodeNum)

View File

@@ -0,0 +1,44 @@
#pragma once
#include "WorkerThread.h"
namespace concurrency {
/**
* @brief A worker thread that waits on a freertos notification
*/
class BaseNotifiedWorkerThread : public WorkerThread
{
public:
/**
* Notify this thread so it can run
*/
virtual void notify(uint32_t v = 0, eNotifyAction action = eNoAction) = 0;
/**
* Notify from an ISR
*
* This must be inline or IRAM_ATTR on ESP32
*/
virtual void notifyFromISR(BaseType_t *highPriWoken, uint32_t v = 0, eNotifyAction action = eNoAction) { notify(v, action); }
protected:
/**
* The notification that was most recently used to wake the thread. Read from loop()
*/
uint32_t notification = 0;
/**
* What notification bits should be cleared just after we read and return them in notification?
*
* Defaults to clear all of them.
*/
uint32_t clearOnRead = UINT32_MAX;
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block() = 0;
};
} // namespace concurrency

View File

@@ -0,0 +1,12 @@
#include "Thread.h"
#include <assert.h>
namespace concurrency
{
void BaseThread::callRun(void *_this)
{
((BaseThread *)_this)->doRun();
}
} // namespace concurrency

View File

@@ -0,0 +1,47 @@
#pragma once
#include <cstdlib>
#include <stdint.h>
#include "freertosinc.h"
namespace concurrency
{
/**
* @brief Base threading
*/
class BaseThread
{
protected:
/**
* set this to true to ask thread to cleanly exit asap
*/
volatile bool wantExit = false;
public:
virtual void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY) = 0;
virtual ~BaseThread() {}
// uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
/**
* All thread run methods must periodically call serviceWatchdog, or the system will declare them hung and panic.
*
* this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog()
*/
virtual void serviceWatchdog() {}
virtual void startWatchdog() {}
virtual void stopWatchdog() {}
static void callRun(void *_this);
};
} // namespace concurrency

View File

@@ -1,19 +1,23 @@
#include "NotifiedWorkerThread.h" #include "NotifiedWorkerThread.h"
#ifdef HAS_FREE_RTOS
namespace concurrency { namespace concurrency {
/** /**
* Notify this thread so it can run * Notify this thread so it can run
*/ */
void NotifiedWorkerThread::notify(uint32_t v, eNotifyAction action) void FreeRtosNotifiedWorkerThread::notify(uint32_t v, eNotifyAction action)
{ {
xTaskNotify(taskHandle, v, action); xTaskNotify(taskHandle, v, action);
} }
void NotifiedWorkerThread::block() void FreeRtosNotifiedWorkerThread::block()
{ {
xTaskNotifyWait(0, // don't clear notification on entry xTaskNotifyWait(0, // don't clear notification on entry
clearOnRead, &notification, portMAX_DELAY); // Wait forever clearOnRead, &notification, portMAX_DELAY); // Wait forever
} }
} // namespace concurrency } // namespace concurrency
#endif

View File

@@ -0,0 +1,40 @@
#pragma once
#include "BaseNotifiedWorkerThread.h"
#ifdef HAS_FREE_RTOS
namespace concurrency {
/**
* @brief A worker thread that waits on a freertos notification
*/
class FreeRtosNotifiedWorkerThread : public BaseNotifiedWorkerThread
{
public:
/**
* Notify this thread so it can run
*/
void notify(uint32_t v = 0, eNotifyAction action = eNoAction);
/**
* Notify from an ISR
*
* This must be inline or IRAM_ATTR on ESP32
*/
inline void notifyFromISR(BaseType_t *highPriWoken, uint32_t v = 0, eNotifyAction action = eNoAction)
{
xTaskNotifyFromISR(taskHandle, v, action, highPriWoken);
}
protected:
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block();
};
} // namespace concurrency
#endif

View File

@@ -1,5 +1,7 @@
#include "Thread.h" #include "FreeRtosThread.h"
#include "timing.h"
#ifdef HAS_FREE_RTOS
#include <assert.h> #include <assert.h>
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
@@ -9,25 +11,20 @@
namespace concurrency namespace concurrency
{ {
void Thread::start(const char *name, size_t stackSize, uint32_t priority) void FreeRtosThread::start(const char *name, size_t stackSize, uint32_t priority)
{ {
auto r = xTaskCreate(callRun, name, stackSize, this, priority, &taskHandle); auto r = xTaskCreate(callRun, name, stackSize, this, priority, &taskHandle);
assert(r == pdPASS); assert(r == pdPASS);
} }
void Thread::callRun(void *_this) void FreeRtosThread::serviceWatchdog()
{
((Thread *)_this)->doRun();
}
void Thread::serviceWatchdog()
{ {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
esp_task_wdt_reset(); esp_task_wdt_reset();
#endif #endif
} }
void Thread::startWatchdog() void FreeRtosThread::startWatchdog()
{ {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
auto r = esp_task_wdt_add(taskHandle); auto r = esp_task_wdt_add(taskHandle);
@@ -35,7 +32,7 @@ void Thread::startWatchdog()
#endif #endif
} }
void Thread::stopWatchdog() void FreeRtosThread::stopWatchdog()
{ {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
auto r = esp_task_wdt_delete(taskHandle); auto r = esp_task_wdt_delete(taskHandle);
@@ -44,3 +41,5 @@ void Thread::stopWatchdog()
} }
} // namespace concurrency } // namespace concurrency
#endif

View File

@@ -0,0 +1,44 @@
#pragma once
#include "BaseThread.h"
#include "freertosinc.h"
#ifdef HAS_FREE_RTOS
namespace concurrency
{
/**
* @brief Base threading
*/
class FreeRtosThread : public BaseThread
{
protected:
TaskHandle_t taskHandle = NULL;
public:
void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY);
virtual ~FreeRtosThread() { vTaskDelete(taskHandle); }
// uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
/**
* All thread run methods must periodically call serviceWatchdog, or the system will declare them hung and panic.
*
* this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog()
*/
void serviceWatchdog();
void startWatchdog();
void stopWatchdog();
};
} // namespace concurrency
#endif

View File

@@ -1,8 +1,10 @@
#include "Lock.h" #include "Lock.h"
#include <cassert> #include <cassert>
namespace concurrency { namespace concurrency
{
#ifdef HAS_FREE_RTOS
Lock::Lock() Lock::Lock()
{ {
handle = xSemaphoreCreateBinary(); handle = xSemaphoreCreateBinary();
@@ -19,5 +21,12 @@ void Lock::unlock()
{ {
assert(xSemaphoreGive(handle)); assert(xSemaphoreGive(handle));
} }
#else
Lock::Lock() {}
void Lock::lock() {}
void Lock::unlock() {}
#endif
} // namespace concurrency } // namespace concurrency

View File

@@ -2,7 +2,8 @@
#include "../freertosinc.h" #include "../freertosinc.h"
namespace concurrency { namespace concurrency
{
/** /**
* @brief Simple wrapper around FreeRTOS API for implementing a mutex lock * @brief Simple wrapper around FreeRTOS API for implementing a mutex lock
@@ -26,8 +27,9 @@ class Lock
void unlock(); void unlock();
private: private:
#ifdef HAS_FREE_RTOS
SemaphoreHandle_t handle; SemaphoreHandle_t handle;
#endif
}; };
} // namespace concurrency } // namespace concurrency

View File

@@ -1,47 +1,17 @@
#pragma once #pragma once
#include "WorkerThread.h" #include "FreeRtosNotifiedWorkerThread.h"
#include "PosixNotifiedWorkerThread.h"
namespace concurrency { namespace concurrency
/**
* @brief A worker thread that waits on a freertos notification
*/
class NotifiedWorkerThread : public WorkerThread
{ {
public:
/**
* Notify this thread so it can run
*/
void notify(uint32_t v = 0, eNotifyAction action = eNoAction);
/** #ifdef HAS_FREE_RTOS
* Notify from an ISR typedef FreeRtosNotifiedWorkerThread NotifiedWorkerThread;
* #endif
* This must be inline or IRAM_ATTR on ESP32
*/
inline void notifyFromISR(BaseType_t *highPriWoken, uint32_t v = 0, eNotifyAction action = eNoAction)
{
xTaskNotifyFromISR(taskHandle, v, action, highPriWoken);
}
protected: #ifdef __unix__
/** typedef PosixNotifiedWorkerThread NotifiedWorkerThread;
* The notification that was most recently used to wake the thread. Read from loop() #endif
*/
uint32_t notification = 0;
/**
* What notification bits should be cleared just after we read and return them in notification?
*
* Defaults to clear all of them.
*/
uint32_t clearOnRead = UINT32_MAX;
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block();
};
} // namespace concurrency } // namespace concurrency

View File

@@ -1,7 +1,6 @@
#include "PeriodicScheduler.h" #include "PeriodicScheduler.h"
#include "PeriodicTask.h" #include "PeriodicTask.h"
#include "LockGuard.h" #include "LockGuard.h"
#include "../timing.h"
namespace concurrency { namespace concurrency {
@@ -10,7 +9,7 @@ void PeriodicScheduler::loop()
{ {
LockGuard lg(&lock); LockGuard lg(&lock);
uint32_t now = timing::millis(); uint32_t now = millis();
for (auto t : tasks) { for (auto t : tasks) {
if (t->period && (now - t->lastMsec) >= t->period) { if (t->period && (now - t->lastMsec) >= t->period) {

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <Arduino.h>
#include "PeriodicScheduler.h" #include "PeriodicScheduler.h"
#include "timing.h"
namespace concurrency { namespace concurrency {
@@ -38,7 +38,7 @@ class PeriodicTask
*/ */
void setPeriod(uint32_t p) void setPeriod(uint32_t p)
{ {
lastMsec = timing::millis(); // reset starting from now lastMsec = millis(); // reset starting from now
period = p; period = p;
} }

View File

@@ -0,0 +1,19 @@
#include "PosixNotifiedWorkerThread.h"
#ifdef __unix__
#include <Utility.h>
using namespace concurrency;
/**
* Notify this thread so it can run
*/
void PosixNotifiedWorkerThread::notify(uint32_t v, eNotifyAction action) NOT_IMPLEMENTED("notify");
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
void PosixNotifiedWorkerThread::block() NOT_IMPLEMENTED("block");
#endif

View File

@@ -0,0 +1,26 @@
#pragma once
#include "BaseNotifiedWorkerThread.h"
namespace concurrency {
/**
* @brief A worker thread that waits on a freertos notification
*/
class PosixNotifiedWorkerThread : public BaseNotifiedWorkerThread
{
public:
/**
* Notify this thread so it can run
*/
void notify(uint32_t v = 0, eNotifyAction action = eNoAction);
protected:
/**
* A method that should block execution - either waiting ona queue/mutex or a "task notification"
*/
virtual void block();
};
} // namespace concurrency

View File

@@ -0,0 +1,33 @@
#pragma once
#include "BaseThread.h"
#ifdef __unix__
namespace concurrency
{
/**
* @brief Base threading
*/
class PosixThread : public BaseThread
{
protected:
public:
void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY) {}
virtual ~PosixThread() {}
// uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
};
} // namespace concurrency
#endif

View File

@@ -1,47 +1,17 @@
#pragma once #pragma once
#include "freertosinc.h" #include "FreeRtosThread.h"
#include "PosixThread.h"
namespace concurrency { namespace concurrency
/**
* @brief Base threading
*/
class Thread
{ {
protected:
TaskHandle_t taskHandle = NULL;
/** #ifdef HAS_FREE_RTOS
* set this to true to ask thread to cleanly exit asap typedef FreeRtosThread Thread;
*/ #endif
volatile bool wantExit = false;
public:
void start(const char *name, size_t stackSize = 1024, uint32_t priority = tskIDLE_PRIORITY);
virtual ~Thread() { vTaskDelete(taskHandle); }
uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); }
protected:
/**
* The method that will be called when start is called.
*/
virtual void doRun() = 0;
/**
* All thread run methods must periodically call serviceWatchdog, or the system will declare them hung and panic.
*
* this only applies after startWatchdog() has been called. If you need to sleep for a long time call stopWatchdog()
*/
void serviceWatchdog();
void startWatchdog();
void stopWatchdog();
private:
static void callRun(void *_this);
};
#ifdef __unix__
typedef PosixThread Thread;
#endif
} // namespace concurrency } // namespace concurrency

View File

@@ -1,5 +1,4 @@
#include "WorkerThread.h" #include "WorkerThread.h"
#include "timing.h"
namespace concurrency { namespace concurrency {
@@ -17,8 +16,8 @@ void WorkerThread::doRun()
#ifdef DEBUG_STACK #ifdef DEBUG_STACK
static uint32_t lastPrint = 0; static uint32_t lastPrint = 0;
if (timing::millis() - lastPrint > 10 * 1000L) { if (millis() - lastPrint > 10 * 1000L) {
lastPrint = timing::millis(); lastPrint = millis();
meshtastic::printThreadInfo("net"); meshtastic::printThreadInfo("net");
} }
#endif #endif

View File

@@ -55,24 +55,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/// Convert a preprocessor name into a quoted string and if that string is empty use "unset" /// Convert a preprocessor name into a quoted string and if that string is empty use "unset"
#define optstr(s) (xstr(s)[0] ? xstr(s) : "unset") #define optstr(s) (xstr(s)[0] ? xstr(s) : "unset")
#ifdef NRF52_SERIES // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be #ifdef PORTDUINO
// board specific
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
#elif defined(NRF52_SERIES) // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be
// board specific
// //
// Standard definitions for NRF52 targets // Standard definitions for NRF52 targets
// //
// Nop definition for these attributes - not used on NRF52
#define EXT_RAM_ATTR
#define IRAM_ATTR
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth) #define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
// We bind to the GPS using variant.h instead for this platform (Serial1) // We bind to the GPS using variant.h instead for this platform (Serial1)
// FIXME, not yet ready for NRF52
#define RTC_DATA_ATTR
#define LED_PIN PIN_LED1 // LED1 on nrf52840-DK #define LED_PIN PIN_LED1 // LED1 on nrf52840-DK
// If the variant filed defines as standard button // If the variant filed defines as standard button
@@ -89,9 +86,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth) #define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
// FIXME, not yet ready for NRF52
#define RTC_DATA_ATTR
#define LED_PIN -1 // FIXME totally bogus #define LED_PIN -1 // FIXME totally bogus
#define BUTTON_PIN -1 #define BUTTON_PIN -1
@@ -123,6 +117,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif #endif
//
// Standard definitions for !ESP32 targets
//
#ifdef NO_ESP32
// Nop definition for these attributes - not used on NRF52
#define EXT_RAM_ATTR
#define IRAM_ATTR
#define RTC_DATA_ATTR
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// OLED // OLED
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -195,8 +200,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define BUTTON_PIN 39 #define BUTTON_PIN 39
#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage
#define USE_RF95
#define USE_RF95 #define USE_RF95
#define LORA_DIO0 26 // a No connect on the SX1262 module #define LORA_DIO0 26 // a No connect on the SX1262 module
#define LORA_RESET 23 #define LORA_RESET 23
@@ -338,6 +341,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define HW_VENDOR "nrf52unknown" // FIXME - unknown nrf52 board #define HW_VENDOR "nrf52unknown" // FIXME - unknown nrf52 board
#elif PORTDUINO
#define HW_VENDOR "portduino"
#define USE_SIM_RADIO
#define USE_RF95
#define LORA_DIO0 26 // a No connect on the SX1262 module
#define LORA_RESET 23
#define LORA_DIO1 33 // Not really used
#define LORA_DIO2 32 // Not really used
// Fake SPI device selections
#define RF95_SCK 5
#define RF95_MISO 19
#define RF95_MOSI 27
#define RF95_NSS 18
#endif #endif
#ifdef USE_RF95 #ifdef USE_RF95

View File

@@ -1,7 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "../concurrency/LockGuard.h" #include "../concurrency/LockGuard.h"
#include "../timing.h"
#include "BluetoothSoftwareUpdate.h" #include "BluetoothSoftwareUpdate.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "RadioLibInterface.h" #include "RadioLibInterface.h"
@@ -102,7 +101,7 @@ int update_crc32_callback(uint16_t conn_handle, uint16_t attr_handle, struct ble
} else { } else {
if (Update.end()) { if (Update.end()) {
DEBUG_MSG("OTA done, rebooting in 5 seconds!\n"); DEBUG_MSG("OTA done, rebooting in 5 seconds!\n");
rebootAtMsec = timing::millis() + 5000; rebootAtMsec = millis() + 5000;
} else { } else {
DEBUG_MSG("Error Occurred. Error #: %d\n", Update.getError()); DEBUG_MSG("Error Occurred. Error #: %d\n", Update.getError());
} }
@@ -128,7 +127,7 @@ int update_result_callback(uint16_t conn_handle, uint16_t attr_handle, struct bl
void bluetoothRebootCheck() void bluetoothRebootCheck()
{ {
if (rebootAtMsec && timing::millis() > rebootAtMsec) { if (rebootAtMsec && millis() > rebootAtMsec) {
DEBUG_MSG("Rebooting for update\n"); DEBUG_MSG("Rebooting for update\n");
ESP.restart(); ESP.restart();
} }

View File

@@ -3,22 +3,32 @@
// The FreeRTOS includes are in a different directory on ESP32 and I can't figure out how to make that work with platformio gcc // The FreeRTOS includes are in a different directory on ESP32 and I can't figure out how to make that work with platformio gcc
// options so this is my quick hack to make things work // options so this is my quick hack to make things work
#ifdef ARDUINO_ARCH_ESP32 #if defined(ARDUINO_ARCH_ESP32)
#define HAS_FREE_RTOS #define HAS_FREE_RTOS
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/queue.h> #include <freertos/queue.h>
#include <freertos/semphr.h> #include <freertos/semphr.h>
#include <freertos/task.h> #include <freertos/task.h>
#else #endif
// not yet supported on cubecell
#ifndef CubeCell_BoardPlus #if defined(ARDUINO_NRF52_ADAFRUIT)
#define HAS_FREE_RTOS #define HAS_FREE_RTOS
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <queue.h> #include <queue.h>
#include <semphr.h> #include <semphr.h>
#include <task.h> #include <task.h>
#endif
#ifdef HAS_FREE_RTOS
// Include real FreeRTOS defs above
#else #else
// Include placeholder fake FreeRTOS defs
#include <Arduino.h> #include <Arduino.h>
typedef uint32_t TickType_t; typedef uint32_t TickType_t;
@@ -26,5 +36,12 @@ typedef uint32_t BaseType_t;
#define portMAX_DELAY UINT32_MAX #define portMAX_DELAY UINT32_MAX
#endif #define tskIDLE_PRIORITY 0
#define configMAX_PRIORITIES 10 // Highest priority level
// Don't do anything on non free rtos platforms when done with the ISR
#define portYIELD_FROM_ISR(x)
enum eNotifyAction { eNoAction, eSetValueWithoutOverwrite, eSetValueWithOverwrite };
#endif #endif

View File

@@ -1,7 +1,6 @@
#include "GPS.h" #include "GPS.h"
#include "configuration.h" #include "configuration.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
@@ -36,7 +35,7 @@ void readFromRTC()
struct timeval tv; /* btw settimeofday() is helpfull here too*/ struct timeval tv; /* btw settimeofday() is helpfull here too*/
if (!gettimeofday(&tv, NULL)) { if (!gettimeofday(&tv, NULL)) {
uint32_t now = timing::millis(); uint32_t now = millis();
DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS); DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS);
timeStartMsec = now; timeStartMsec = now;
@@ -79,7 +78,7 @@ void perhapsSetRTC(struct tm &t)
uint32_t getTime() uint32_t getTime()
{ {
return ((timing::millis() - timeStartMsec) / 1000) + zeroOffsetSecs; return ((millis() - timeStartMsec) / 1000) + zeroOffsetSecs;
} }
uint32_t getValidTime() uint32_t getValidTime()

View File

@@ -1,6 +1,5 @@
#include "NEMAGPS.h" #include "NMEAGPS.h"
#include "configuration.h" #include "configuration.h"
#include "timing.h"
static int32_t toDegInt(RawDegrees d) static int32_t toDegInt(RawDegrees d)
{ {
@@ -11,7 +10,7 @@ static int32_t toDegInt(RawDegrees d)
return r; return r;
} }
void NEMAGPS::loop() void NMEAGPS::loop()
{ {
while (_serial_gps->available() > 0) { while (_serial_gps->available() > 0) {
int c = _serial_gps->read(); int c = _serial_gps->read();
@@ -19,7 +18,7 @@ void NEMAGPS::loop()
reader.encode(c); reader.encode(c);
} }
uint32_t now = timing::millis(); uint32_t now = millis();
if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume if ((now - lastUpdateMsec) > 20 * 1000) { // Ugly hack for now - limit update checks to once every 20 secs (but still consume
// serial chars at whatever rate) // serial chars at whatever rate)
lastUpdateMsec = now; lastUpdateMsec = now;
@@ -44,6 +43,9 @@ void NEMAGPS::loop()
isConnected = true; // we seem to have a real GPS (but not necessarily a lock) isConnected = true; // we seem to have a real GPS (but not necessarily a lock)
} }
uint8_t fixtype = reader.fixQuality();
hasValidLocation = ((fixtype >= 1) && (fixtype <= 5));
if (reader.location.isUpdated()) { if (reader.location.isUpdated()) {
if (reader.altitude.isValid()) if (reader.altitude.isValid())
altitude = reader.altitude.meters(); altitude = reader.altitude.meters();
@@ -58,18 +60,21 @@ void NEMAGPS::loop()
dop = reader.hdop.value(); dop = reader.hdop.value();
} }
if (reader.course.isValid()) { if (reader.course.isValid()) {
heading = reader.course.value() * 1e3; //Scale the heading (in degrees * 10^-2) to match the expected degrees * 10^-5 heading =
reader.course.value() * 1e3; // Scale the heading (in degrees * 10^-2) to match the expected degrees * 10^-5
} }
if (reader.satellites.isValid()) { if (reader.satellites.isValid()) {
numSatellites = reader.satellites.value(); numSatellites = reader.satellites.value();
} }
// expect gps pos lat=37.520825, lon=-122.309162, alt=158 // expect gps pos lat=37.520825, lon=-122.309162, alt=158
DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d, hdop=%f, heading=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, dop * 1e-2, heading * 1e-5); DEBUG_MSG("new NMEA GPS pos lat=%f, lon=%f, alt=%d, hdop=%f, heading=%f\n", latitude * 1e-7, longitude * 1e-7,
altitude, dop * 1e-2, heading * 1e-5);
} }
// Notify any status instances that are observing us // Notify any status instances that are observing us
const meshtastic::GPSStatus status = meshtastic::GPSStatus(hasLock(), isConnected, latitude, longitude, altitude, dop, heading, numSatellites); const meshtastic::GPSStatus status =
meshtastic::GPSStatus(hasLock(), isConnected, latitude, longitude, altitude, dop, heading, numSatellites);
newStatus.notifyObservers(&status); newStatus.notifyObservers(&status);
} }
} }

View File

@@ -1,16 +1,16 @@
#pragma once #pragma once
#include "../concurrency/PeriodicTask.h"
#include "GPS.h" #include "GPS.h"
#include "Observer.h" #include "Observer.h"
#include "../concurrency/PeriodicTask.h"
#include "TinyGPS++.h" #include "TinyGPS++.h"
/** /**
* A gps class thatreads from a NEMA GPS stream (and FIXME - eventually keeps the gps powered down except when reading) * A gps class thatreads from a NMEA GPS stream (and FIXME - eventually keeps the gps powered down except when reading)
* *
* When new data is available it will notify observers. * When new data is available it will notify observers.
*/ */
class NEMAGPS : public GPS class NMEAGPS : public GPS
{ {
TinyGPSPlus reader; TinyGPSPlus reader;

View File

@@ -103,7 +103,7 @@ bool UBloxGPS::factoryReset()
{ {
bool ok = false; bool ok = false;
// It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have // It is useful to force back into factory defaults (9600baud, NMEA to test the behavior of boards that don't have
// GPS_TX connected) // GPS_TX connected)
ublox.factoryReset(); ublox.factoryReset();
delay(5000); delay(5000);

View File

@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graphics/images.h" #include "graphics/images.h"
#include "main.h" #include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "target_specific.h"
#include "utils.h" #include "utils.h"
using namespace meshtastic; /** @todo remove */ using namespace meshtastic; /** @todo remove */

View File

@@ -23,7 +23,7 @@
#include "MeshRadio.h" #include "MeshRadio.h"
#include "MeshService.h" #include "MeshService.h"
#include "NEMAGPS.h" #include "NMEAGPS.h"
#include "NodeDB.h" #include "NodeDB.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "UBloxGPS.h" #include "UBloxGPS.h"
@@ -38,7 +38,7 @@
#include "graphics/Screen.h" #include "graphics/Screen.h"
#include "main.h" #include "main.h"
#include "sleep.h" #include "sleep.h"
#include "timing.h" #include "target_specific.h"
#include <OneButton.h> #include <OneButton.h>
#include <Wire.h> #include <Wire.h>
// #include <driver/rtc_io.h> // #include <driver/rtc_io.h>
@@ -223,7 +223,7 @@ void setup()
// Init our SPI controller (must be before screen and lora) // Init our SPI controller (must be before screen and lora)
initSPI(); initSPI();
#ifdef NRF52_SERIES #ifdef NO_ESP32
SPI.begin(); SPI.begin();
#else #else
// ESP32 // ESP32
@@ -256,19 +256,22 @@ void setup()
if (GPS::_serial_gps) { if (GPS::_serial_gps) {
// Some boards might have only the TX line from the GPS connected, in that case, we can't configure it at all. Just // Some boards might have only the TX line from the GPS connected, in that case, we can't configure it at all. Just
// assume NEMA at 9600 baud. // assume NMEA at 9600 baud.
DEBUG_MSG("Hoping that NEMA might work\n"); DEBUG_MSG("Hoping that NMEA might work\n");
// dumb NEMA access only work for serial GPSes) // dumb NMEA access only work for serial GPSes)
gps = new NEMAGPS(); gps = new NMEAGPS();
gps->setup(); gps->setup();
} }
} }
#else #else
gps = new NEMAGPS(); gps = new NMEAGPS();
gps->setup(); gps->setup();
#endif #endif
gpsStatus->observe(&gps->newStatus); if (gps)
gpsStatus->observe(&gps->newStatus);
else
DEBUG_MSG("Warning: No GPS found - running without GPS\n");
nodeStatus->observe(&nodeDB.newStatus); nodeStatus->observe(&nodeDB.newStatus);
service.init(); service.init();
@@ -362,7 +365,8 @@ void loop()
{ {
uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop? uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop?
gps->loop(); // FIXME, remove from main, instead block on read if (gps)
gps->loop(); // FIXME, remove from main, instead block on read
router.loop(); router.loop();
powerFSM.run_machine(); powerFSM.run_machine();
service.loop(); service.loop();
@@ -392,15 +396,15 @@ void loop()
// Show boot screen for first 3 seconds, then switch to normal operation. // Show boot screen for first 3 seconds, then switch to normal operation.
static bool showingBootScreen = true; static bool showingBootScreen = true;
if (showingBootScreen && (timing::millis() > 3000)) { if (showingBootScreen && (millis() > 3000)) {
screen.stopBootScreen(); screen.stopBootScreen();
showingBootScreen = false; showingBootScreen = false;
} }
#ifdef DEBUG_STACK #ifdef DEBUG_STACK
static uint32_t lastPrint = 0; static uint32_t lastPrint = 0;
if (timing::millis() - lastPrint > 10 * 1000L) { if (millis() - lastPrint > 10 * 1000L) {
lastPrint = timing::millis(); lastPrint = millis();
meshtastic::printThreadInfo("main"); meshtastic::printThreadInfo("main");
} }
#endif #endif

View File

@@ -21,6 +21,6 @@ extern graphics::Screen screen;
// Return a human readable string of the form "Meshtastic_ab13" // Return a human readable string of the form "Meshtastic_ab13"
const char *getDeviceName(); const char *getDeviceName();
void getMacAddr(uint8_t *dmac);
void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop();

View File

@@ -36,6 +36,11 @@
#define CH_SPACING_TW 0.2 #define CH_SPACING_TW 0.2
#define NUM_CHANNELS_TW 10 #define NUM_CHANNELS_TW 10
// AU/NZ channel settings 915-928MHz
#define CH0_ANZ 916.0f // MHz - avoid overcrowding on 915.0
#define CH_SPACING_ANZ 0.5f
#define NUM_CHANNELS_ANZ 20
// FIXME add defs for other regions and use them here // FIXME add defs for other regions and use them here
#ifdef HW_VERSION_US #ifdef HW_VERSION_US
#define CH0 CH0_US #define CH0 CH0_US
@@ -63,6 +68,11 @@
#define CH0 CH0_TW #define CH0 CH0_TW
#define CH_SPACING CH_SPACING_TW #define CH_SPACING CH_SPACING_TW
#define NUM_CHANNELS NUM_CHANNELS_TW #define NUM_CHANNELS NUM_CHANNELS_TW
#elif defined(HW_VERSION_ANZ)
// Australia and NZ
#define CH0 CH0_ANZ
#define CH_SPACING CH_SPACING_ANZ
#define NUM_CHANNELS NUM_CHANNELS_ANZ
#else #else
// HW version not set - assume US // HW version not set - assume US
#define CH0 CH0_US #define CH0 CH0_US

View File

@@ -13,7 +13,6 @@
#include "main.h" #include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "power.h" #include "power.h"
#include "timing.h"
/* /*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone. receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
@@ -68,8 +67,8 @@ void MeshService::init()
sendOwnerPeriod.setup(); sendOwnerPeriod.setup();
nodeDB.init(); nodeDB.init();
assert(gps); if (gps)
gpsObserver.observe(&gps->newStatus); gpsObserver.observe(&gps->newStatus);
packetReceivedObserver.observe(&router.notifyPacketReceived); packetReceivedObserver.observe(&router.notifyPacketReceived);
} }
@@ -206,6 +205,13 @@ void MeshService::reloadConfig()
nodeDB.saveToDisk(); nodeDB.saveToDisk();
} }
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
void MeshService::reloadOwner()
{
sendOurOwner();
nodeDB.saveToDisk();
}
/** /**
* Given a ToRadio buffer parse it and properly handle it (setup radio, owner or send packet into the mesh) * Given a ToRadio buffer parse it and properly handle it (setup radio, owner or send packet into the mesh)
* Called by PhoneAPI.handleToRadio. Note: p is a scratch buffer, this function is allowed to write to it but it can not keep a * Called by PhoneAPI.handleToRadio. Note: p is a scratch buffer, this function is allowed to write to it but it can not keep a
@@ -292,8 +298,8 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused)
p->decoded.which_payload = SubPacket_position_tag; p->decoded.which_payload = SubPacket_position_tag;
Position &pos = p->decoded.position; Position &pos = p->decoded.position;
// !zero or !zero lat/long means valid
if (gps->latitude != 0 || gps->longitude != 0) { if (gps->hasLock()) {
if (gps->altitude != 0) if (gps->altitude != 0)
pos.altitude = gps->altitude; pos.altitude = gps->altitude;
pos.latitude_i = gps->latitude; pos.latitude_i = gps->latitude;
@@ -309,7 +315,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused)
// We limit our GPS broadcasts to a max rate // We limit our GPS broadcasts to a max rate
static uint32_t lastGpsSend; static uint32_t lastGpsSend;
uint32_t now = timing::millis(); uint32_t now = millis();
if (lastGpsSend == 0 || now - lastGpsSend > radioConfig.preferences.position_broadcast_secs * 1000) { if (lastGpsSend == 0 || now - lastGpsSend > radioConfig.preferences.position_broadcast_secs * 1000) {
lastGpsSend = now; lastGpsSend = now;
DEBUG_MSG("Sending position to mesh\n"); DEBUG_MSG("Sending position to mesh\n");

View File

@@ -67,7 +67,7 @@ class MeshService
void reloadConfig(); void reloadConfig();
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh /// The owner User record just got updated, update our node DB and broadcast the info into the mesh
void reloadOwner() { sendOurOwner(); } void reloadOwner();
/// Called when the user wakes up our GUI, normally sends our latest location to the mesh (if we have it), otherwise at least /// Called when the user wakes up our GUI, normally sends our latest location to the mesh (if we have it), otherwise at least
/// sends our owner /// sends our owner

View File

@@ -32,7 +32,14 @@ DeviceState versions used to be defined in the .proto file but really only this
#define DEVICESTATE_CUR_VER 11 #define DEVICESTATE_CUR_VER 11
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER #define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
#ifndef NO_ESP32 #ifdef PORTDUINO
// Portduino version
#include "PortduinoFS.h"
#define FS PortduinoFS
#define FSBegin() true
#define FILE_O_WRITE "w"
#define FILE_O_READ "r"
#elif !defined(NO_ESP32)
// ESP32 version // ESP32 version
#include "SPIFFS.h" #include "SPIFFS.h"
#define FS SPIFFS #define FS SPIFFS

View File

@@ -1,7 +1,6 @@
#include "PacketHistory.h" #include "PacketHistory.h"
#include "configuration.h" #include "configuration.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "../timing.h"
PacketHistory::PacketHistory() PacketHistory::PacketHistory()
{ {
@@ -19,7 +18,7 @@ bool PacketHistory::wasSeenRecently(const MeshPacket *p, bool withUpdate)
return false; // Not a floodable message ID, so we don't care return false; // Not a floodable message ID, so we don't care
} }
uint32_t now = timing::millis(); uint32_t now = millis();
for (size_t i = 0; i < recentPackets.size();) { for (size_t i = 0; i < recentPackets.size();) {
PacketRecord &r = recentPackets[i]; PacketRecord &r = recentPackets[i];

View File

@@ -4,7 +4,6 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "PowerFSM.h" #include "PowerFSM.h"
#include "RadioInterface.h" #include "RadioInterface.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
PhoneAPI::PhoneAPI() PhoneAPI::PhoneAPI()
@@ -21,7 +20,7 @@ void PhoneAPI::init()
void PhoneAPI::checkConnectionTimeout() void PhoneAPI::checkConnectionTimeout()
{ {
if (isConnected) { if (isConnected) {
bool newConnected = (timing::millis() - lastContactMsec < radioConfig.preferences.phone_timeout_secs * 1000L); bool newConnected = (millis() - lastContactMsec < radioConfig.preferences.phone_timeout_secs * 1000L);
if (!newConnected) { if (!newConnected) {
isConnected = false; isConnected = false;
onConnectionChanged(isConnected); onConnectionChanged(isConnected);
@@ -35,7 +34,7 @@ void PhoneAPI::checkConnectionTimeout()
void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength)
{ {
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); // As long as the phone keeps talking to us, don't let the radio go to sleep powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); // As long as the phone keeps talking to us, don't let the radio go to sleep
lastContactMsec = timing::millis(); lastContactMsec = millis();
if (!isConnected) { if (!isConnected) {
isConnected = true; isConnected = true;
onConnectionChanged(isConnected); onConnectionChanged(isConnected);

View File

@@ -3,9 +3,11 @@
#include "RadioLibRF95.h" #include "RadioLibRF95.h"
#include <configuration.h> #include <configuration.h>
#define MAX_POWER 17 #define MAX_POWER 20
// if we use 20 we are limited to 1% duty cycle or hw might overheat. For continuous operation set a limit of 17 // if we use 20 we are limited to 1% duty cycle or hw might overheat. For continuous operation set a limit of 17
#define POWER_DEFAULT 17 // How much power to use if the user hasn't set a power level
RF95Interface::RF95Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass &spi) RF95Interface::RF95Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass &spi)
: RadioLibInterface(cs, irq, rst, 0, spi) : RadioLibInterface(cs, irq, rst, 0, spi)
{ {
@@ -32,9 +34,15 @@ bool RF95Interface::init()
RadioLibInterface::init(); RadioLibInterface::init();
applyModemConfig(); applyModemConfig();
if (power == 0)
power = POWER_DEFAULT;
if (power > MAX_POWER) // This chip has lower power limits than some if (power > MAX_POWER) // This chip has lower power limits than some
power = MAX_POWER; power = MAX_POWER;
limitPower();
iface = lora = new RadioLibRF95(&module); iface = lora = new RadioLibRF95(&module);
#ifdef RF95_TCXO #ifdef RF95_TCXO

View File

@@ -6,7 +6,6 @@
#include "assert.h" #include "assert.h"
#include "configuration.h" #include "configuration.h"
#include "sleep.h" #include "sleep.h"
#include "timing.h"
#include <assert.h> #include <assert.h>
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
@@ -107,7 +106,7 @@ bool RadioInterface::init()
* djb2 by Dan Bernstein. * djb2 by Dan Bernstein.
* http://www.cse.yorku.ca/~oz/hash.html * http://www.cse.yorku.ca/~oz/hash.html
*/ */
unsigned long hash(char *str) unsigned long hash(const char *str)
{ {
unsigned long hash = 5381; unsigned long hash = 5381;
int c; int c;
@@ -118,8 +117,6 @@ unsigned long hash(char *str)
return hash; return hash;
} }
#define POWER_DEFAULT 17
/** /**
* Pull our channel settings etc... from protobufs to the dumb interface settings * Pull our channel settings etc... from protobufs to the dumb interface settings
*/ */
@@ -129,8 +126,6 @@ void RadioInterface::applyModemConfig()
// No Sync Words in LORA mode // No Sync Words in LORA mode
power = channelSettings.tx_power; power = channelSettings.tx_power;
if (power == 0)
power = POWER_DEFAULT;
// If user has manually specified a channel num, then use that, otherwise generate one by hashing the name // If user has manually specified a channel num, then use that, otherwise generate one by hashing the name
int channel_num = (channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelSettings.name)) % NUM_CHANNELS; int channel_num = (channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelSettings.name)) % NUM_CHANNELS;
@@ -140,6 +135,25 @@ void RadioInterface::applyModemConfig()
power); power);
} }
/**
* Some regulatory regions limit xmit power.
* This function should be called by subclasses after setting their desired power. It might lower it
*/
void RadioInterface::limitPower()
{
uint8_t maxPower = 255; // No limit
#ifdef HW_VERSION_JP
maxPower = 13; // See https://github.com/meshtastic/Meshtastic-device/issues/346
#endif
if (power > maxPower) {
DEBUG_MSG("Lowering transmit power because of regulatory limits\n");
power = maxPower;
}
DEBUG_MSG("Set radio: final power level=%d\n", power);
}
ErrorCode SimRadio::send(MeshPacket *p) ErrorCode SimRadio::send(MeshPacket *p)
{ {
DEBUG_MSG("SimRadio.send\n"); DEBUG_MSG("SimRadio.send\n");
@@ -163,7 +177,7 @@ size_t RadioInterface::beginSending(MeshPacket *p)
// DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad()); // DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad());
assert(p->which_payload == MeshPacket_encrypted_tag); // It should have already been encoded by now assert(p->which_payload == MeshPacket_encrypted_tag); // It should have already been encoded by now
lastTxStart = timing::millis(); lastTxStart = millis();
PacketHeader *h = (PacketHeader *)radiobuf; PacketHeader *h = (PacketHeader *)radiobuf;

View File

@@ -119,6 +119,12 @@ class RadioInterface : protected concurrency::NotifiedWorkerThread
virtual void loop() {} // Idle processing virtual void loop() {} // Idle processing
/**
* Some regulatory regions limit xmit power.
* This function should be called by subclasses after setting their desired power. It might lower it
*/
void limitPower();
/** /**
* Convert our modemConfig enum into wf, sf, etc... * Convert our modemConfig enum into wf, sf, etc...
* *

View File

@@ -2,7 +2,6 @@
#include "MeshTypes.h" #include "MeshTypes.h"
#include "configuration.h" #include "configuration.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "timing.h"
// ReliableRouter::ReliableRouter() {} // ReliableRouter::ReliableRouter() {}
@@ -163,7 +162,7 @@ PendingPacket *ReliableRouter::startRetransmission(MeshPacket *p)
*/ */
void ReliableRouter::doRetransmissions() void ReliableRouter::doRetransmissions()
{ {
uint32_t now = timing::millis(); uint32_t now = millis();
// FIXME, we should use a better datastructure rather than walking through this map. // FIXME, we should use a better datastructure rather than walking through this map.
// for(auto el: pending) { // for(auto el: pending) {

View File

@@ -2,7 +2,6 @@
#include "FloodingRouter.h" #include "FloodingRouter.h"
#include "../concurrency/PeriodicTask.h" #include "../concurrency/PeriodicTask.h"
#include "../timing.h"
#include <unordered_map> #include <unordered_map>
/** /**
@@ -49,7 +48,7 @@ struct PendingPacket {
PendingPacket() {} PendingPacket() {}
PendingPacket(MeshPacket *p); PendingPacket(MeshPacket *p);
void setNextTx() { nextTxMsec = timing::millis() + random(20 * 1000L, 22 * 1000L); } void setNextTx() { nextTxMsec = millis() + random(20 * 1000L, 22 * 1000L); }
}; };
class GlobalPacketIdHashFunction class GlobalPacketIdHashFunction

View File

@@ -37,8 +37,15 @@ bool SX1262Interface::init()
bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC? bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC?
applyModemConfig(); applyModemConfig();
if (power == 0)
power = 22;
if (power > 22) // This chip has lower power limits than some if (power > 22) // This chip has lower power limits than some
power = 22; power = 22;
limitPower();
int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO); int res = lora.begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength, tcxoVoltage, useRegulatorLDO);
DEBUG_MSG("SX1262 init result %d\n", res); DEBUG_MSG("SX1262 init result %d\n", res);

View File

@@ -53,7 +53,7 @@ template <class T> class TypedQueue
public: public:
TypedQueue(int maxElements) {} TypedQueue(int maxElements) {}
// int numFree() { return uxQueueSpacesAvailable(h); } int numFree() { return 1; } // Always claim 1 free, because we can grow to any size
bool isEmpty() { return q.empty(); } bool isEmpty() { return q.empty(); }

View File

@@ -6,7 +6,7 @@
#include <pb_decode.h> #include <pb_decode.h>
#include <pb_encode.h> #include <pb_encode.h>
#ifdef NO_ESP32 #ifdef ARDUINO_ARCH_NRF52
#include "Adafruit_LittleFS.h" #include "Adafruit_LittleFS.h"
using namespace Adafruit_LittleFS_Namespace; // To get File type using namespace Adafruit_LittleFS_Namespace; // To get File type
#endif #endif
@@ -49,7 +49,7 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
return count == 0; return count == 0;
} }
status = (file->read(buf, count) == (int) count); status = (file->read(buf, count) == (int)count);
if (file->available() == 0) if (file->available() == 0)
stream->bytes_left = 0; stream->bytes_left = 0;

View File

@@ -0,0 +1,32 @@
#include "CryptoEngine.h"
#include "target_specific.h"
#include <Utility.h>
// FIXME - move getMacAddr/setBluetoothEnable into a HALPlatform class
uint32_t hwId; // fixme move into portduino
void getMacAddr(uint8_t *dmac)
{
if (!hwId) {
notImplemented("getMacAddr");
hwId = random();
}
dmac[0] = 0x80;
dmac[1] = 0;
dmac[2] = 0;
dmac[3] = hwId >> 16;
dmac[4] = hwId >> 8;
dmac[5] = hwId & 0xff;
}
void setBluetoothEnable(bool on)
{
notImplemented("setBluetoothEnable");
}
// FIXME - implement real crypto for linux
CryptoEngine *crypto = new CryptoEngine();
void updateBatteryLevel(uint8_t level) NOT_IMPLEMENTED("updateBatteryLevel");

View File

@@ -7,7 +7,6 @@
#include "error.h" #include "error.h"
#include "main.h" #include "main.h"
#include "target_specific.h" #include "target_specific.h"
#include "timing.h"
#ifndef NO_ESP32 #ifndef NO_ESP32
#include "esp32/pm.h" #include "esp32/pm.h"
@@ -123,11 +122,11 @@ bool doPreflightSleep()
/// Tell devices we are going to sleep and wait for them to handle things /// Tell devices we are going to sleep and wait for them to handle things
static void waitEnterSleep() static void waitEnterSleep()
{ {
uint32_t now = timing::millis(); uint32_t now = millis();
while (!doPreflightSleep()) { while (!doPreflightSleep()) {
delay(100); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives) delay(100); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives)
if (timing::millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep if (millis() - now > 30 * 1000) { // If we wait too long just report an error and go to sleep
recordCriticalError(ErrSleepEnterWait); recordCriticalError(ErrSleepEnterWait);
assert(0); // FIXME - for now we just restart, need to fix bug #167 assert(0); // FIXME - for now we just restart, need to fix bug #167
break; break;

View File

@@ -1,6 +1,10 @@
#pragma once #pragma once
#include <Arduino.h>
// Functions that are unique to particular target types (esp32, bare, nrf52 etc...) // Functions that are unique to particular target types (esp32, bare, nrf52 etc...)
// Enable/disable bluetooth. // Enable/disable bluetooth.
void setBluetoothEnable(bool on); void setBluetoothEnable(bool on);
void getMacAddr(uint8_t *dmac);

View File

@@ -1,10 +0,0 @@
#include "timing.h"
#include "freertosinc.h"
namespace timing {
uint32_t millis() {
return xTaskGetTickCount();
}
} // namespace timing

View File

@@ -1,9 +0,0 @@
#pragma once
#include <cstdint>
namespace timing {
uint32_t millis();
} // namespace timing