mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-21 02:02:23 +00:00
Compare commits
238 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fab616a15e | ||
|
|
2419ebb04e | ||
|
|
88c576798b | ||
|
|
db766f18ed | ||
|
|
f9a805e3d4 | ||
|
|
e5f9a752d8 | ||
|
|
20b41836e2 | ||
|
|
c55df4d1cc | ||
|
|
908b1020c0 | ||
|
|
78470ed3f5 | ||
|
|
4ce7df295e | ||
|
|
598abb0d23 | ||
|
|
184eac6281 | ||
|
|
176532f55f | ||
|
|
8eb3045451 | ||
|
|
2fe145aed9 | ||
|
|
ab61e64056 | ||
|
|
5b17417e0c | ||
|
|
04a83fd6b7 | ||
|
|
7730bd762a | ||
|
|
62286fff52 | ||
|
|
25cca0628d | ||
|
|
65406eaa08 | ||
|
|
ea24394110 | ||
|
|
6afeb3e456 | ||
|
|
f108c576a7 | ||
|
|
6eb74415ab | ||
|
|
0d14b69a24 | ||
|
|
d4eb47e837 | ||
|
|
86716c4397 | ||
|
|
7bbcf101c1 | ||
|
|
8e495e417c | ||
|
|
a6e0d6d751 | ||
|
|
cff255a397 | ||
|
|
3336e821ad | ||
|
|
d75d603218 | ||
|
|
bf5be49186 | ||
|
|
39ff26aa45 | ||
|
|
02b5efed96 | ||
|
|
0a07c5692c | ||
|
|
2464784f00 | ||
|
|
a8f5ff1fbd | ||
|
|
0a6af936ed | ||
|
|
0b62083e35 | ||
|
|
5ca149fac9 | ||
|
|
80c69c28cd | ||
|
|
5904d66111 | ||
|
|
fd17193d5e | ||
|
|
5c379c4a98 | ||
|
|
9c5d626e7d | ||
|
|
4757b6807e | ||
|
|
ac7f3cd603 | ||
|
|
04ad8bb533 | ||
|
|
5924690ce3 | ||
|
|
3ac3baf1c1 | ||
|
|
aa88e2bb1f | ||
|
|
640cb3bf7f | ||
|
|
6ad451eb5f | ||
|
|
93a06906cb | ||
|
|
3754950a0e | ||
|
|
06a17885eb | ||
|
|
33624b7753 | ||
|
|
2d6b9320a5 | ||
|
|
6b35454570 | ||
|
|
753a57230d | ||
|
|
9c3e63e6b5 | ||
|
|
4d4d7b38cc | ||
|
|
23f148f8ce | ||
|
|
d150549754 | ||
|
|
441c4c7b3c | ||
|
|
c22df18e28 | ||
|
|
e32b41938a | ||
|
|
ef395a1596 | ||
|
|
af35f3006c | ||
|
|
13ac686c96 | ||
|
|
05a0266fc4 | ||
|
|
3acbf31198 | ||
|
|
2e82bf3ca1 | ||
|
|
63e1a3f47e | ||
|
|
07a8972aea | ||
|
|
d1cb45aa5d | ||
|
|
1b3610d0fa | ||
|
|
2fcdc2c09f | ||
|
|
da74803ffb | ||
|
|
890511615f | ||
|
|
17de6f9532 | ||
|
|
2a15195c32 | ||
|
|
1b050a6c3d | ||
|
|
1da62e5ba1 | ||
|
|
feb6f2e59e | ||
|
|
7dabad1b70 | ||
|
|
a73f466473 | ||
|
|
1fd92cf8eb | ||
|
|
dd671ceca6 | ||
|
|
8a76931b37 | ||
|
|
b071eecce1 | ||
|
|
81734f75c8 | ||
|
|
11d57e721a | ||
|
|
9b0e329bb9 | ||
|
|
450fb7bc35 | ||
|
|
c1f8c8cca4 | ||
|
|
ea250d9cd3 | ||
|
|
be468a2183 | ||
|
|
a47d6c4d68 | ||
|
|
5386a5b224 | ||
|
|
a350b3795b | ||
|
|
cf2aa37635 | ||
|
|
d1387be015 | ||
|
|
f8857ad45b | ||
|
|
d831beab3d | ||
|
|
5c4ae6c042 | ||
|
|
a0c97825e8 | ||
|
|
cc3bac7ea0 | ||
|
|
ce21859ada | ||
|
|
54cd082bfe | ||
|
|
4c35d1f207 | ||
|
|
4d54df4c9b | ||
|
|
aa9aca2b88 | ||
|
|
a579bbcb50 | ||
|
|
12e67d3b30 | ||
|
|
50d724780a | ||
|
|
45babab8c4 | ||
|
|
3443e60718 | ||
|
|
65128a04c9 | ||
|
|
7210c1ae5e | ||
|
|
9075501917 | ||
|
|
a3b70e7538 | ||
|
|
b4b8abe6ec | ||
|
|
d647be73df | ||
|
|
42d7966858 | ||
|
|
f4d368e1f4 | ||
|
|
3a756b0e08 | ||
|
|
34ead2d68e | ||
|
|
3f1161b68b | ||
|
|
f108e24bc1 | ||
|
|
1f83f7d9df | ||
|
|
756c7ca7b3 | ||
|
|
79f7bf77c9 | ||
|
|
dee3e530de | ||
|
|
3e44c2c3e1 | ||
|
|
3886665041 | ||
|
|
c9b269c3c0 | ||
|
|
eb51c92d08 | ||
|
|
992b525588 | ||
|
|
25288d8ed6 | ||
|
|
32ac5ac9ae | ||
|
|
ef5cdefca6 | ||
|
|
f6f9dfa463 | ||
|
|
2161ce21df | ||
|
|
534691f0c2 | ||
|
|
6bc8e1b10a | ||
|
|
c8b95f7691 | ||
|
|
daf8594b99 | ||
|
|
5b54fd6359 | ||
|
|
53765298e1 | ||
|
|
0d94458c4e | ||
|
|
5e55695862 | ||
|
|
c9e2e6c386 | ||
|
|
dbbb62f63e | ||
|
|
79ce7d929c | ||
|
|
33437b5246 | ||
|
|
f4bacb9d87 | ||
|
|
0ac218b06d | ||
|
|
2ce1b4bb2c | ||
|
|
f002bee4f4 | ||
|
|
9c69326ed9 | ||
|
|
7a617d5378 | ||
|
|
90edae1ce0 | ||
|
|
2134b4db9b | ||
|
|
7b1ffb5c09 | ||
|
|
535f07d927 | ||
|
|
bfad136137 | ||
|
|
36bee8fa53 | ||
|
|
99cb0b3855 | ||
|
|
41c95eaff7 | ||
|
|
ca8a25f585 | ||
|
|
51a8700391 | ||
|
|
f099a31a29 | ||
|
|
52dbc4e15d | ||
|
|
8cabb3ea3d | ||
|
|
7a4a1af332 | ||
|
|
90ecdf229e | ||
|
|
24ac907780 | ||
|
|
5037fb830e | ||
|
|
79f1346359 | ||
|
|
35dada683a | ||
|
|
30a431788d | ||
|
|
d0b8adab75 | ||
|
|
74f7b7b622 | ||
|
|
9ec8562ce7 | ||
|
|
0cbcb7a9bd | ||
|
|
2874b22d6c | ||
|
|
3c9be48445 | ||
|
|
b5201f928b | ||
|
|
2591859df5 | ||
|
|
c411db111b | ||
|
|
0d62a2be85 | ||
|
|
9c971d3686 | ||
|
|
3c1357b732 | ||
|
|
acd5e5d29d | ||
|
|
64109b25f2 | ||
|
|
e93bc76ac9 | ||
|
|
1107c6d23d | ||
|
|
9b2155402d | ||
|
|
35cf8a4859 | ||
|
|
76f21dfd6e | ||
|
|
b101dc2c88 | ||
|
|
9bbd658b9d | ||
|
|
4999da0824 | ||
|
|
a783341df1 | ||
|
|
04258755e7 | ||
|
|
ea711ece1f | ||
|
|
e93187b630 | ||
|
|
eca3cda8b9 | ||
|
|
2874adfd69 | ||
|
|
91227b25df | ||
|
|
4dfac03402 | ||
|
|
9bc895eb57 | ||
|
|
474026d7fe | ||
|
|
9995d2a7ab | ||
|
|
3028ac3f24 | ||
|
|
8605950eef | ||
|
|
0f856dea7b | ||
|
|
2a2bc5b1d6 | ||
|
|
f87cb00940 | ||
|
|
a4ebf83b69 | ||
|
|
5dbacbddba | ||
|
|
011864a2d3 | ||
|
|
8646d8aeba | ||
|
|
87782cdf8f | ||
|
|
10289ed11a | ||
|
|
5def6a66e6 | ||
|
|
2d3bb4bb75 | ||
|
|
ffe8bf2be6 | ||
|
|
ab73033e51 | ||
|
|
c66e24aa4d | ||
|
|
635e189007 | ||
|
|
6eba792537 |
6
.clang-format
Normal file
6
.clang-format
Normal file
@@ -0,0 +1,6 @@
|
||||
Language: Cpp
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 130
|
||||
PointerAlignment: Right
|
||||
BreakBeforeBraces: Linux
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -1,5 +1,7 @@
|
||||
name: Continuous Integration
|
||||
on: push
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
main:
|
||||
|
||||
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@@ -12,7 +12,7 @@
|
||||
"type": "platformio-debug",
|
||||
"request": "launch",
|
||||
"name": "PIO Debug",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/esp32/firmware.elf",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf",
|
||||
"toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin",
|
||||
"preLaunchTask": {
|
||||
"type": "PlatformIO",
|
||||
@@ -24,7 +24,7 @@
|
||||
"type": "platformio-debug",
|
||||
"request": "launch",
|
||||
"name": "PIO Debug (skip Pre-Debug)",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/esp32/firmware.elf",
|
||||
"executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf",
|
||||
"toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
|
||||
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@@ -42,10 +42,16 @@
|
||||
"typeinfo": "cpp",
|
||||
"string": "cpp",
|
||||
"*.xbm": "cpp",
|
||||
"list": "cpp"
|
||||
"list": "cpp",
|
||||
"atomic": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"optional": "cpp",
|
||||
"string_view": "cpp",
|
||||
"cassert": "cpp"
|
||||
},
|
||||
"cSpell.words": [
|
||||
"Meshtastic",
|
||||
"descs"
|
||||
"descs",
|
||||
"protobufs"
|
||||
]
|
||||
}
|
||||
147
README.md
147
README.md
@@ -1,39 +1,56 @@
|
||||
# Meshtastic-esp32
|
||||
This is the device side code for the [meshtastic.org](https://www.meshtastic.org) project.
|
||||
|
||||
This is the device side code for the [meshtastic.org](https://www.meshtastic.org) project.
|
||||
|
||||

|
||||
|
||||
Meshtastic is a project that lets you use
|
||||
inexpensive GPS mesh radios as an extensible, super long battery life mesh GPS communicator. These radios are great for hiking, skiing, paragliding -
|
||||
essentially any hobby where you don't have reliable internet access. Each member of your private mesh can always see the location and distance of all other
|
||||
inexpensive GPS mesh radios as an extensible, super long battery life mesh GPS communicator. These radios are great for hiking, skiing, paragliding -
|
||||
essentially any hobby where you don't have reliable internet access. Each member of your private mesh can always see the location and distance of all other
|
||||
members and any text messages sent to your group chat.
|
||||
|
||||
The radios automatically create a mesh to forward packets as needed, so everyone in the group can receive messages from even the furthest member. The radios
|
||||
The radios automatically create a mesh to forward packets as needed, so everyone in the group can receive messages from even the furthest member. The radios
|
||||
will optionally work with your phone, but no phone is required.
|
||||
|
||||
Typical time between recharging the radios should be about eight days.
|
||||
|
||||
This project is currently early-alpha, but if you have questions please join our chat [](https://gitter.im/Meshtastic/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge).
|
||||
This project is currently early-alpha, but if you have questions please [join our discussion forum](https://meshtastic.discourse.group/).
|
||||
|
||||
This software is 100% open source and developed by a group of hobbyist experimenters. No warranty is provided, if you'd like to improve it - we'd love your help. Please post in the chat.
|
||||
This software is 100% open source and developed by a group of hobbyist experimenters. No warranty is provided, if you'd like to improve it - we'd love your help. Please post in the chat.
|
||||
|
||||
## Supported hardware
|
||||
We currently support three models of radios. The [TTGO T-Beam](https://www.aliexpress.com/item/4000119152086.html), [TTGO LORA32](https://www.banggood.com/LILYGO-TTGO-LORA32-868Mhz-SX1276-ESP32-Oled-Display-bluetooth-WIFI-Lora-Development-Module-Board-p-1248652.html?cur_warehouse=UK) and the [Heltec LoRa 32](https://heltec.org/project/wifi-lora-32/). Most users should buy the T-Beam and a 18650 battery (total cost less than $35). Make
|
||||
sure to buy the frequency range which is legal for your country. For the USA, you should buy the 915MHz version. Getting a version that include a screen
|
||||
is optional, but highly recommended.
|
||||
|
||||
We currently support three models of radios. The [TTGO T-Beam](https://www.aliexpress.com/item/4000119152086.html), [TTGO LORA32](https://www.banggood.com/LILYGO-TTGO-LORA32-868Mhz-SX1276-ESP32-Oled-Display-bluetooth-WIFI-Lora-Development-Module-Board-p-1248652.html?cur_warehouse=UK) and the [Heltec LoRa 32](https://heltec.org/project/wifi-lora-32/). Most users should buy the T-Beam and an 18650 battery (total cost less than \$35). Make sure to buy the frequency range which is legal for your country (915MHz for US/JP/AU/NZ, 470MHz for CN, 433MHz and 870MHz for EU). Getting a version that includes a screen is optional, but highly recommended.
|
||||
|
||||
See (meshtastic.org) for 3D printable cases.
|
||||
|
||||
## Installing the firmware
|
||||
Prebuilt binaries for the supported radios is available in our [releases](https://github.com/meshtastic/Meshtastic-esp32/releases). Your initial installation has to happen over USB from your Mac, Windows or Linux PC. Once our software is installed, all future software updates happen over bluetooth from your phone.
|
||||
## Firmware Installation
|
||||
|
||||
The instructions currently require a few commmand lines, but it should be pretty straightforward. Please post comments on our group chat if you have problems or successes. Steps to install:
|
||||
Prebuilt binaries for the supported radios are available in our [releases](https://github.com/meshtastic/Meshtastic-esp32/releases). Your initial installation has to happen over USB from your Mac, Windows or Linux PC. Once our software is installed, all future software updates happen over bluetooth from your phone.
|
||||
|
||||
Please post comments on our [group chat](https://meshtastic.discourse.group/) if you have problems or successes.
|
||||
|
||||
### Installing from a GUI - Windows and Mac
|
||||
|
||||
1. Download and unzip the latest Meshtastic firmware [release](https://github.com/meshtastic/Meshtastic-esp32/releases).
|
||||
2. Download [ESPHome Flasher](https://github.com/esphome/esphome-flasher/releases) (either x86-32bit Windows or x64-64 bit Windows).
|
||||
3. Connect your radio to your USB port and open ESPHome Flasher.
|
||||
4. If your board is not showing under Serial Port then you likely need to install the drivers for the CP210X serial chip. In Windows you can check by searching “Device Manager” and ensuring the device is shown under “Ports”.
|
||||
5. If there is an error, download the drivers [here](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers), then unzip and run the Installer application.
|
||||
6. In ESPHome Flasher, refresh the serial ports and select your board.
|
||||
7. Browse to the previously downloaded firmware and select the correct firmware based on the board type, country and frequency.
|
||||
8. Select Flash ESP.
|
||||
9. Once finished, the terminal should start displaying debug messages including the Bluetooth passphrase when you try connect from your phone (handy if you don’t have a screen).
|
||||
|
||||
### Installing from a commandline
|
||||
|
||||
These instructions currently require a few commmand lines, but it should be pretty straightforward.
|
||||
|
||||
1. Install "pip". Pip is the python package manager we use to get the esptool installer app. Instructions [here](https://www.makeuseof.com/tag/install-pip-for-python/). If you are using OS-X, see these [special instructions](docs/software/install-OSX.md).
|
||||
2. Run "pip install --upgrade esptool" to get esptool installed on your machine.
|
||||
3. Connect your radio to your USB port.
|
||||
4. Confirm that your device is talking to your PC by running "esptool.py chip_id". The Heltec build also works on the TTGO LORA32 radio. You should see something like:
|
||||
|
||||
1. Purchase a radio (see above) with the correct frequencies for your country (915MHz for US or JP, 470MHz for CN, 870MHz for EU).
|
||||
2. Install "pip". Pip is the python package manager we use to get the esptool installer app. Instructions [here](https://www.makeuseof.com/tag/install-pip-for-python/).
|
||||
3. Run "pip install --upgrade esptool" to get esptool installed on your machine
|
||||
4. Connect your radio to your USB port
|
||||
5. Confirm that your device is talking to your PC by running "esptool.py chip_id". The Heltec build also works on the TTGO LORA32 radio. You should see something like:
|
||||
```
|
||||
mydir$ esptool.py chip_id
|
||||
esptool.py v2.6
|
||||
@@ -51,53 +68,105 @@ Warning: ESP32 has no Chip ID. Reading MAC instead.
|
||||
MAC: 24:6f:28:b5:36:71
|
||||
Hard resetting via RTS pin...
|
||||
```
|
||||
6. Install the correct firmware for your board with "esptool.py write_flash 0x10000 firmware-_board_-_country_.bin". For instance "esptool.py write_flash 0x10000 release/firmware-HELTEC-US-0.0.3.bin". You should see something like this:
|
||||
|
||||
5. cd into the directory where the release zip file was expanded.
|
||||
6. Install the correct firmware for your board with "device-install.sh firmware-_board_-_country_.bin". For instance "./device-install.sh firmware-HELTEC-US-0.0.3.bin".
|
||||
|
||||
Note: If you have previously installed meshtastic, you don't need to run this full script instead just run "esptool.py --baud 921600 write*flash 0x10000 firmware-\_board*-_country_.bin". This will be faster, also all of your current preferences will be preserved.
|
||||
|
||||
You should see something like this:
|
||||
|
||||
```
|
||||
~/development/meshtastic/meshtastic-esp32$ esptool.py write_flash 0x10000 release/firmware-HELTEC-US-0.0.3.bin
|
||||
kevinh@kevin-server:~/development/meshtastic/meshtastic-esp32/release/latest$ ./device-install.sh firmware-TBEAM-US-0.1.8.bin
|
||||
Trying to flash firmware-TBEAM-US-0.1.8.bin, but first erasing and writing system information
|
||||
esptool.py v2.6
|
||||
Found 2 serial ports
|
||||
Serial port /dev/ttyUSB0
|
||||
Connecting......
|
||||
Connecting........____
|
||||
Detecting chip type... ESP32
|
||||
Chip is ESP32D0WDQ6 (revision 1)
|
||||
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
|
||||
MAC: 24:6f:28:b5:36:71
|
||||
MAC: 24:6f:28:b2:01:6c
|
||||
Uploading stub...
|
||||
Running stub...
|
||||
Stub running...
|
||||
Changing baud rate to 921600
|
||||
Changed.
|
||||
Erasing flash (this may take a while)...
|
||||
Chip erase completed successfully in 6.1s
|
||||
Hard resetting via RTS pin...
|
||||
esptool.py v2.6
|
||||
Found 2 serial ports
|
||||
Serial port /dev/ttyUSB0
|
||||
Connecting.......
|
||||
Detecting chip type... ESP32
|
||||
Chip is ESP32D0WDQ6 (revision 1)
|
||||
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
|
||||
MAC: 24:6f:28:b2:01:6c
|
||||
Uploading stub...
|
||||
Running stub...
|
||||
Stub running...
|
||||
Changing baud rate to 921600
|
||||
Changed.
|
||||
Configuring flash size...
|
||||
Auto-detected Flash size: 8MB
|
||||
Compressed 1184800 bytes to 652635...
|
||||
Wrote 1184800 bytes (652635 compressed) at 0x00010000 in 57.6 seconds (effective 164.5 kbit/s)...
|
||||
Auto-detected Flash size: 4MB
|
||||
Flash params set to 0x0220
|
||||
Compressed 61440 bytes to 11950...
|
||||
Wrote 61440 bytes (11950 compressed) at 0x00001000 in 0.2 seconds (effective 3092.4 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
esptool.py v2.6
|
||||
Found 2 serial ports
|
||||
Serial port /dev/ttyUSB0
|
||||
Connecting.....
|
||||
Detecting chip type... ESP32
|
||||
Chip is ESP32D0WDQ6 (revision 1)
|
||||
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
|
||||
MAC: 24:6f:28:b2:01:6c
|
||||
Uploading stub...
|
||||
Running stub...
|
||||
Stub running...
|
||||
Changing baud rate to 921600
|
||||
Changed.
|
||||
Configuring flash size...
|
||||
Auto-detected Flash size: 4MB
|
||||
Compressed 1223568 bytes to 678412...
|
||||
Wrote 1223568 bytes (678412 compressed) at 0x00010000 in 10.7 seconds (effective 912.0 kbit/s)...
|
||||
Hash of data verified.
|
||||
|
||||
Leaving...
|
||||
Hard resetting via RTS pin...
|
||||
```
|
||||
|
||||
7. The board will boot and show the Meshtastic logo.
|
||||
8. Please post a comment on our chat so we know if these instructions worked for you ;-). If you find bugs/have-questions post there also - we will be rapidly iterating over the next few weeks.
|
||||
8. Please post a comment on our chat so we know if these instructions worked for you ;-). If you find bugs/have-questions post there also - we will be rapidly iterating over the next few weeks.
|
||||
|
||||
## Meshtastic Android app
|
||||
The source code for the (optional) Meshtastic Android app is [here](https://github.com/meshtastic/Meshtastic-Android).
|
||||
|
||||
Alpha test builds are current available by opting into our alpha test group. See (www.meshtastic.org) for instructions.
|
||||
The source code for the (optional) Meshtastic Android app is [here](https://github.com/meshtastic/Meshtastic-Android).
|
||||
|
||||
Alpha test builds are current available by opting into our alpha test group. See (www.meshtastic.org) for instructions.
|
||||
|
||||
After our rate of change slows a bit, we will make beta builds available here (without needing to join the alphatest group):
|
||||
[](https://play.google.com/store/apps/details?id=com.geeksville.mesh&referrer=utm_source%3Dgithub%26utm_medium%3Desp32-readme%26utm_campaign%3Dmeshtastic-esp32%2520readme%26anid%3Dadmob&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1)
|
||||
|
||||
# Development
|
||||
The following sections are probably only interesting if you want to join us in developing the software.
|
||||
|
||||
## Power measurements
|
||||
Since one of the main goals of this project is long battery life, it is important to consider that in our software/protocol design. Based on initial measurements it seems that the current code should run about three days between charging, and with a bit more software work (see the [TODO list](TODO.md)) a battery life of eight days should be quite doable. Our current power measurements/model is in [this spreadsheet](https://docs.google.com/spreadsheets/d/1ft1bS3iXqFKU8SApU8ZLTq9r7QQEGESYnVgdtvdT67k/edit?usp=sharing).
|
||||
We'd love to have you join us on this merry little project. Please see our [development documents](./docs/software/sw-design.md) and [join us in our discussion forum](https://meshtastic.discourse.group/).
|
||||
|
||||
## Build instructions
|
||||
This project uses the simple PlatformIO build system. You can use the IDE, but for brevity
|
||||
in these instructions I describe use of their command line tool.
|
||||
# Credits
|
||||
|
||||
1. Purchase a suitable radio (see above)
|
||||
2. Install [PlatformIO](https://platformio.org/platformio-ide)
|
||||
3. Download this git repo and cd into it
|
||||
4. Plug the radio into your USB port
|
||||
4. Type "pio run -t upload" (This command will fetch dependencies, build the project and install it on the board via USB)
|
||||
5. Platform IO also installs a very nice VisualStudio Code based IDE, see their [tutorial](https://docs.platformio.org/en/latest/tutorials/espressif32/arduino_debugging_unit_testing.html) if you'd like to use it
|
||||
This project is run by volunteers. Past contributors include:
|
||||
|
||||
- @astro-arphid: Added support for 433MHz radios in europe.
|
||||
- @claesg: Various documentation fixes and 3D print enclosures
|
||||
- @girtsf: Lots of improvements
|
||||
- @spattinson: Fixed interrupt handling for the AXP192 part
|
||||
|
||||
# IMPORTANT DISCLAIMERS AND FAQ
|
||||
|
||||
For a listing of currently missing features and a FAQ click [here](docs/faq.md).
|
||||
|
||||
Copyright 2019 Geeksville Industries, LLC. GPL V3 Licensed.
|
||||
|
||||
192
TODO.md
192
TODO.md
@@ -1,192 +0,0 @@
|
||||
# High priority
|
||||
|
||||
Items to complete soon (next couple of alpha releases).
|
||||
|
||||
* lower wait_bluetooth_secs to 30 seconds once we have the GPS power on (but GPS in sleep mode) across light sleep. For the time
|
||||
being I have it set at 2 minutes to ensure enough time for a GPS lock from scratch.
|
||||
|
||||
* use gps sleep mode instead of killing its power (to allow fast position when we wake)
|
||||
* enable fast lock and low power inside the gps chip
|
||||
* remeasure wake time power draws now that we run CPU down at 80MHz
|
||||
|
||||
# AXP192 tasks
|
||||
* "AXP192 interrupt is not firing, remove this temporary polling of battery state"
|
||||
* make debug info screen show real data (including battery level & charging) - close corresponding github issue
|
||||
|
||||
# Medium priority
|
||||
|
||||
Items to complete before the first beta release.
|
||||
|
||||
* Make a FAQ
|
||||
* good source of battery/signal/gps icons https://materialdesignicons.com/
|
||||
* investigate changing routing to https://github.com/sudomesh/LoRaLayer2 ?
|
||||
* check fcc rules on duty cycle. we might not need to freq hop. https://www.sunfiretesting.com/LoRa-FCC-Certification-Guide/
|
||||
* use fuse bits to store the board type and region. So one load can be used on all boards
|
||||
* research and implement better mesh algorithm
|
||||
* the BLE stack is leaking about 200 bytes each time we go to light sleep
|
||||
* rx signal measurements -3 marginal, -9 bad, 10 great, -10 means almost unusable. So scale this into % signal strength. preferably as a graph, with an X indicating loss of comms.
|
||||
* assign every "channel" a random shared 8 bit sync word (per 4.2.13.6 of datasheet) - use that word to filter packets before even checking CRC. This will ensure our CPU will only wake for packets on our "channel"
|
||||
* Note: we do not do address filtering at the chip level, because we might need to route for the mesh
|
||||
* add basic crypto - https://github.com/chegewara/esp32-mbedtls-aes-test/blob/master/main/main.c https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation - use ECB at first (though it is shit) because it doesn't require us to send 16 bytes of IV with each packet. Then OFB per example
|
||||
* add frequency hopping, dependent on the gps time, make the switch moment far from the time anyone is going to be transmitting
|
||||
* share channel settings over Signal (or qr code) by embedding an an URL which is handled by the MeshUtil app.
|
||||
* publish update articles on the web
|
||||
|
||||
# Pre-beta priority
|
||||
|
||||
During the beta timeframe the following improvements 'would be nice' (and yeah - I guess some of these items count as features, but it is a hobby project ;-) )
|
||||
|
||||
* If the phone doesn't read fromradio mailbox within X seconds, assume the phone is gone and we can stop queing location msgs
|
||||
for it (because it will redownload the nodedb when it comes back)
|
||||
* Figure out why the RF95 ISR is never seeing RH_RF95_VALID_HEADER, so it is not protecting our rx packets from getting stomped on by sends
|
||||
* fix the frequency error reading in the RF95 RX code (can't do floating point math in an ISR ;-)
|
||||
* See CustomRF95::send and fix the problem of dropping partially received packets if we want to start sending
|
||||
* make sure main cpu is not woken for packets with bad crc or not addressed to this node - do that in the radio hw
|
||||
* triple check fcc compliance
|
||||
* pick channel center frequency based on channel name? "dolphin" would hash to 900Mhz, "cat" to 905MHz etc? allows us to hide the concept of channel # from hte user.
|
||||
* scan to find channels with low background noise? (Use CAD mode of the RF95 to automatically find low noise channels)
|
||||
* make a no bluetooth configured yet screen - include this screen in the loop if the user hasn't yet paired
|
||||
* if radio params change fundamentally, discard the nodedb
|
||||
* reneable the bluetooth battery level service on the T-BEAM, because we can read battery level there
|
||||
|
||||
# Spinoff project ideas
|
||||
|
||||
* an open source version of https://www.burnair.ch/skynet/
|
||||
* a paragliding app like http://airwhere.co.uk/
|
||||
* a version with a solar cell for power, just mounted high to permanently provide routing for nodes in a valley. Someone just pointed me at disaster.radio
|
||||
* How do avalanche beacons work? Could this do that as well? possibly by using beacon mode feature of the RF95?
|
||||
* provide generalized (but slow) internet message forwarding servie if one of our nodes has internet connectivity
|
||||
|
||||
# Low priority
|
||||
|
||||
Items after the first final candidate release.
|
||||
|
||||
* use variable length arduino Strings in protobufs (instead of current fixed buffers)
|
||||
* use BLEDevice::setPower to lower our BLE transmit power - extra range doesn't help us, it costs amps and it increases snoopability
|
||||
* make an install script to let novices install software on their boards
|
||||
* use std::map<NodeInfo*, std::string> in node db
|
||||
* make a HAM build: yep - that's a great idea. I'll add it to the TODO. should be pretty painless - just a new frequency list, a bool to say 'never do encryption' and use hte callsign as that node's unique id. -from Girts
|
||||
* don't forward redundant pings or ping responses to the phone, it just wastes phone battery
|
||||
* use https://platformio.org/lib/show/1260/OneButton if necessary
|
||||
* don't send location packets if we haven't moved
|
||||
* scrub default radio config settings for bandwidth/range/speed
|
||||
* answer to pings (because some other user is looking at our nodeinfo) with our latest location (not a stale location)
|
||||
* show radio and gps signal strength as an image
|
||||
* only BLE advertise for a short time after the screen is on and button pressed - to save power and prevent people for sniffing for our BT app.
|
||||
* make mesh aware network timing state machine (sync wake windows to gps time)
|
||||
* split out the software update utility so other projects can use it. Have the appload specify the URL for downloads.
|
||||
* read the PMU battery fault indicators and blink/led/warn user on screen
|
||||
* the AXP debug output says it is trying to charge at 700mA, but the max I've seen is 180mA, so AXP registers probably need to be set to tell them the circuit can only provide 300mAish max. So that the low charge rate kicks in faster and we don't wear out batteries.
|
||||
* increase the max charging rate a bit for 18650s, currently it limits to 180mA (at 4V). Work backwards from the 500mA USB limit (at 5V) and let the AXP charge at that rate.
|
||||
* discard very old nodedb records (> 1wk)
|
||||
* using the genpartitions based table doesn't work on TTGO so for now I stay with my old memory map
|
||||
* We let anyone BLE scan for us (FIXME, perhaps only allow that until we are paired with a phone and configured)
|
||||
* use two different buildenv flags for ttgo vs lora32. https://docs.platformio.org/en/latest/ide/vscode.html#key-bindings
|
||||
* sim gps data for testing nodes that don't have hardware
|
||||
* do debug serial logging to android over bluetooth
|
||||
* break out my bluetooth OTA software as a seperate library so others can use it
|
||||
* Heltec LoRa32 has 8MB flash, use a bigger partition table if needed - TTGO is 4MB but has PSRAM
|
||||
* add a watchdog timer
|
||||
* handle millis() rollover in GPS.getTime - otherwise we will break after 50 days
|
||||
* report esp32 device code bugs back to the mothership via android
|
||||
|
||||
# Done
|
||||
|
||||
* change the partition table to take advantage of the 4MB flash on the wroom: http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
|
||||
* wrap in nice MeshRadio class
|
||||
* add mesh send & rx
|
||||
* make message send from android go to service, then to mesh radio
|
||||
* make message receive from radio go through to android
|
||||
* test loopback tx/rx path code without using radio
|
||||
* notify phone when rx packets arrive, currently the phone polls at startup only
|
||||
* figure out if we can use PA_BOOST - yes, it seems to be on both boards
|
||||
* implement new ble characteristics
|
||||
* have MeshService keep a node DB by sniffing user messages
|
||||
* have a state machine return the correct FromRadio packet to the phone, it isn't always going to be a MeshPacket. Do a notify on fromnum to force the radio to read our state machine generated packets
|
||||
* send my_node_num when phone sends WantsNodes
|
||||
* have meshservice periodically send location data on mesh (if device has a GPS)
|
||||
* implement getCurrentTime() - set based off gps but then updated locally
|
||||
* make default owner record have valid usernames
|
||||
* message loop between node 0x28 and 0x7c
|
||||
* check in my radiolib fixes
|
||||
* figure out what is busted with rx
|
||||
* send our owner info at boot, reply if we see anyone send theirs
|
||||
* add manager layers
|
||||
* confirm second device receives that gps message and updates device db
|
||||
* send correct hw vendor in the bluetooth info - needed so the android app can update different radio models
|
||||
* correctly map nodeids to nodenums, currently we just do a proof of concept by always doing a broadcast
|
||||
* add interrupt detach/sleep mode config to lora radio so we can enable deepsleep without panicing
|
||||
* make jtag work on second board
|
||||
* implement regen owner and radio prefs
|
||||
* use a better font
|
||||
* make nice screens (boot, about to sleep, debug info (gps signal, #people), latest text, person info - one frame per person on network)
|
||||
* turn framerate from ui->state.frameState to 1 fps (or less) unless in transition
|
||||
* switch to my gui layout manager
|
||||
* make basic gui. different screens: debug, one page for each user in the user db, last received text message
|
||||
* make button press cycle between screens
|
||||
* save our node db on entry to sleep
|
||||
* fix the logo
|
||||
* sent/received packets (especially if a node was just reset) have variant of zero sometimes - I think there is a bug (race-condtion?) in the radio send/rx path.
|
||||
* DONE dynamic nodenum assignment tasks
|
||||
* make jtag debugger id stable: https://askubuntu.com/questions/49910/how-to-distinguish-between-identical-usb-to-serial-adapters
|
||||
* reported altitude is crap
|
||||
* good tips on which bands might be more free https://github.com/TheThingsNetwork/ttn/issues/119
|
||||
* finish power measurements (GPS on during sleep vs LCD on during sleep vs LORA on during sleep) and est battery life
|
||||
* make screen sleep behavior work
|
||||
* make screen advance only when a new node update arrives, a new text arrives or the user presses a button, turn off screen after a while
|
||||
* after reboot, channel number is getting reset to zero! fix!
|
||||
* send user and location events much less often
|
||||
* send location (or if not available user) when the user wakes the device from display sleep (both for testing and to improve user experience)
|
||||
* make real implementation of getNumOnlineNodes
|
||||
* very occasionally send our position and user packet based on the schedule in the radio info (if for nothing else so that other nodes update last_seen)
|
||||
* show real text info on the text screen
|
||||
* apply radio settings from android land
|
||||
* cope with nodes that have 0xff or 0x00 as the last byte of their mac
|
||||
* allow setting full radio params from android
|
||||
* add receive timestamps to messages, inserted by esp32 when message is received but then shown on the phone
|
||||
* update build to generate both board types
|
||||
* have node info screen show real info (including distance and heading)
|
||||
* blink the power led less often
|
||||
* have radiohead ISR send messages to RX queue directly, to allow that thread to block until we have something to send
|
||||
* move lora rx/tx to own thread and block on IO
|
||||
* keep our pseudo time moving forward even if we enter deep sleep (use esp32 rtc)
|
||||
* for non GPS equipped devices, set time from phone
|
||||
* GUI on oled hangs for a few seconds occasionally, but comes back
|
||||
* update local GPS position (but do not broadcast) at whatever rate the GPS is giving it
|
||||
* don't send our times to other nodes
|
||||
* don't trust times from other nodes
|
||||
* draw compass rose based off local walking track
|
||||
* add requestResponse optional bool - use for location broadcasts when sending tests
|
||||
* post sample video to signal forum
|
||||
* support non US frequencies
|
||||
* send pr https://github.com/ThingPulse/esp8266-oled-ssd1306 to tell them about this project
|
||||
* document rules for sleep wrt lora/bluetooth/screen/gps. also: if I have text messages (only) for the phone, then give a few seconds in the hopes BLE can get it across before we have to go back to sleep.
|
||||
* wake from light sleep as needed for our next scheduled periodic task (needed for gps position broadcasts etc)
|
||||
* turn bluetooth off based on our sleep policy
|
||||
* blink LED while in LS sleep mode
|
||||
* scrolling between screens based on press is busted
|
||||
* Use Neo-M8M API to put it in sleep mode (on hold until my new boards arrive)
|
||||
* update the prebuilt bins for different regulatory regions
|
||||
* don't enter NB state if we've recently talked to the phone (to prevent breaking syncing or bluetooth sw update)
|
||||
* have sw update prevent BLE sleep
|
||||
* manually delete characteristics/descs
|
||||
* leave lora receiver always on
|
||||
* protobufs are sometimes corrupted after sleep!
|
||||
* stay awake while charging
|
||||
* check gps battery voltage
|
||||
* if a position report includes ground truth time and we don't have time yet, set our clock from that. It is better than nothing.
|
||||
* retest BLE software update for both board types
|
||||
* report on wikifactory
|
||||
* send note to the guy who designed the cases
|
||||
* turn light sleep on aggressively (while lora is on but BLE off)
|
||||
* Use the Periodic class for both position and user periodic broadcasts
|
||||
* don't treat north as up, instead adjust shown bearings for our guess at the users heading (i.e. subtract one from the other)
|
||||
* sendToMesh can currently block for a long time, instead have it just queue a packet for a radio freertos thread
|
||||
* don't even power on bluetooth until we have some data to send to the android phone. Most of the time we should be sleeping in a lowpower "listening for lora" only mode. Once we have some packets for the phone, then power on bluetooth
|
||||
until the phone pulls those packets. Ever so often power on bluetooth just so we can see if the phone wants to send some packets. Possibly might need ULP processor to help with this wake process.
|
||||
* do hibernation mode to get power draw down to 2.5uA https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/
|
||||
* fix GPS.zeroOffset calculation it is wrong
|
||||
* (needs testing) fixed the following during a plane flight:
|
||||
Have state machine properly enter deep sleep based on loss of mesh and phone comms.
|
||||
Default to enter deep sleep if no LORA received for two hours (indicates user has probably left the mesh).
|
||||
* (fixed I think) text messages are not showing on local screen if screen was on
|
||||
@@ -4,11 +4,13 @@ set -e
|
||||
|
||||
source bin/version.sh
|
||||
|
||||
COUNTRIES="US EU CN JP"
|
||||
# COUNTRIES=US
|
||||
COUNTRIES="US EU433 EU865 CN JP"
|
||||
#COUNTRIES=US
|
||||
#COUNTRIES=CN
|
||||
|
||||
BOARDS="ttgo-lora32-v2 ttgo-lora32-v1 tbeam heltec"
|
||||
#BOARDS=tbeam
|
||||
|
||||
SRCMAP=.pio/build/esp32/output.map
|
||||
SRCBIN=.pio/build/esp32/firmware.bin
|
||||
OUTDIR=release/latest
|
||||
|
||||
# We keep all old builds (and their map files in the archive dir)
|
||||
@@ -16,27 +18,35 @@ ARCHIVEDIR=release/archive
|
||||
|
||||
rm -f $OUTDIR/firmware*
|
||||
|
||||
mkdir -p $OUTDIR/bins $OUTDIR/elfs
|
||||
rm -f $OUTDIR/bins/*
|
||||
|
||||
# build the named environment and copy the bins to the release directory
|
||||
function do_build {
|
||||
ENV_NAME=$1
|
||||
echo "Building for $ENV_NAME with $PLATFORMIO_BUILD_FLAGS"
|
||||
SRCBIN=.pio/build/$ENV_NAME/firmware.bin
|
||||
SRCELF=.pio/build/$ENV_NAME/firmware.elf
|
||||
rm -f $SRCBIN
|
||||
|
||||
# The shell vars the build tool expects to find
|
||||
export HW_VERSION="1.0-$COUNTRY"
|
||||
export APP_VERSION=$VERSION
|
||||
export COUNTRY
|
||||
|
||||
pio run --jobs 4 --environment $ENV_NAME # -v
|
||||
cp $SRCBIN $OUTDIR/bins/firmware-$ENV_NAME-$COUNTRY-$VERSION.bin
|
||||
cp $SRCELF $OUTDIR/elfs/firmware-$ENV_NAME-$COUNTRY-$VERSION.elf
|
||||
}
|
||||
|
||||
for COUNTRY in $COUNTRIES; do
|
||||
|
||||
HWVERSTR="1.0-$COUNTRY"
|
||||
COMMONOPTS="-DAPP_VERSION=$VERSION -DHW_VERSION_$COUNTRY -DHW_VERSION=$HWVERSTR -Wall -Wextra -Wno-missing-field-initializers -Isrc -Os -Wl,-Map,.pio/build/esp32/output.map -DAXP_DEBUG_PORT=Serial"
|
||||
|
||||
export PLATFORMIO_BUILD_FLAGS="-DT_BEAM_V10 $COMMONOPTS"
|
||||
echo "Building with $PLATFORMIO_BUILD_FLAGS"
|
||||
rm -f $SRCBIN $SRCMAP
|
||||
pio run # -v
|
||||
cp $SRCBIN $OUTDIR/firmware-TBEAM-$COUNTRY-$VERSION.bin
|
||||
#cp $SRCMAP $ARCHIVEDIR/firmware-TBEAM-$COUNTRY-$VERSION.map
|
||||
|
||||
export PLATFORMIO_BUILD_FLAGS="-DHELTEC_LORA32 $COMMONOPTS"
|
||||
rm -f $SRCBIN $SRCMAP
|
||||
pio run # -v
|
||||
cp $SRCBIN $OUTDIR/firmware-HELTEC-$COUNTRY-$VERSION.bin
|
||||
#cp $SRCMAP $ARCHIVEDIR/firmware-HELTEC-$COUNTRY-$VERSION.map
|
||||
for BOARD in $BOARDS; do
|
||||
do_build $BOARD
|
||||
done
|
||||
done
|
||||
|
||||
# keep the bins in archive also
|
||||
cp $OUTDIR/firmware* $ARCHIVEDIR
|
||||
cp $OUTDIR/bins/firmware* $OUTDIR/elfs/firmware* $ARCHIVEDIR
|
||||
|
||||
cat >$OUTDIR/curfirmwareversion.xml <<XML
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -51,6 +61,6 @@ Generated by bin/buildall.sh -->
|
||||
XML
|
||||
|
||||
rm -f $ARCHIVEDIR/firmware-$VERSION.zip
|
||||
zip $ARCHIVEDIR/firmware-$VERSION.zip $OUTDIR/firmware-*-$VERSION.bin
|
||||
zip --junk-paths $ARCHIVEDIR/firmware-$VERSION.zip $OUTDIR/bins/firmware-*-$VERSION.* images/system-info.bin bin/device-install.sh
|
||||
|
||||
echo BUILT ALL
|
||||
11
bin/device-install.sh
Executable file
11
bin/device-install.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
FILENAME=$1
|
||||
|
||||
echo "Trying to flash $FILENAME, but first erasing and writing system information"
|
||||
esptool.py --baud 921600 erase_flash
|
||||
esptool.py --baud 921600 write_flash 0x1000 system-info.bin
|
||||
esptool.py --baud 921600 write_flash 0x10000 $FILENAME
|
||||
|
||||
329
bin/exception_decoder.py
Executable file
329
bin/exception_decoder.py
Executable file
@@ -0,0 +1,329 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""ESP Exception Decoder
|
||||
|
||||
github: https://github.com/janLo/EspArduinoExceptionDecoder
|
||||
license: GPL v3
|
||||
author: Jan Losinski
|
||||
|
||||
Meshtastic notes:
|
||||
* original version is at: https://github.com/janLo/EspArduinoExceptionDecoder
|
||||
* version that's checked into meshtastic repo is based on: https://github.com/me21/EspArduinoExceptionDecoder
|
||||
which adds in ESP32 Backtrace decoding.
|
||||
* this also updates the defaults to use ESP32, instead of ESP8266 and defaults to the built firmware.bin
|
||||
|
||||
To use, copy the "Backtrace: 0x...." line to a file, e.g., backtrace.txt, then run:
|
||||
$ bin/exception_decoder.py backtrace.txt
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import subprocess
|
||||
from collections import namedtuple
|
||||
|
||||
import sys
|
||||
|
||||
import os
|
||||
|
||||
EXCEPTIONS = [
|
||||
"Illegal instruction",
|
||||
"SYSCALL instruction",
|
||||
"InstructionFetchError: Processor internal physical address or data error during instruction fetch",
|
||||
"LoadStoreError: Processor internal physical address or data error during load or store",
|
||||
"Level1Interrupt: Level-1 interrupt as indicated by set level-1 bits in the INTERRUPT register",
|
||||
"Alloca: MOVSP instruction, if caller's registers are not in the register file",
|
||||
"IntegerDivideByZero: QUOS, QUOU, REMS, or REMU divisor operand is zero",
|
||||
"reserved",
|
||||
"Privileged: Attempt to execute a privileged operation when CRING ? 0",
|
||||
"LoadStoreAlignmentCause: Load or store to an unaligned address",
|
||||
"reserved",
|
||||
"reserved",
|
||||
"InstrPIFDataError: PIF data error during instruction fetch",
|
||||
"LoadStorePIFDataError: Synchronous PIF data error during LoadStore access",
|
||||
"InstrPIFAddrError: PIF address error during instruction fetch",
|
||||
"LoadStorePIFAddrError: Synchronous PIF address error during LoadStore access",
|
||||
"InstTLBMiss: Error during Instruction TLB refill",
|
||||
"InstTLBMultiHit: Multiple instruction TLB entries matched",
|
||||
"InstFetchPrivilege: An instruction fetch referenced a virtual address at a ring level less than CRING",
|
||||
"reserved",
|
||||
"InstFetchProhibited: An instruction fetch referenced a page mapped with an attribute that does not permit instruction fetch",
|
||||
"reserved",
|
||||
"reserved",
|
||||
"reserved",
|
||||
"LoadStoreTLBMiss: Error during TLB refill for a load or store",
|
||||
"LoadStoreTLBMultiHit: Multiple TLB entries matched for a load or store",
|
||||
"LoadStorePrivilege: A load or store referenced a virtual address at a ring level less than CRING",
|
||||
"reserved",
|
||||
"LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads",
|
||||
"StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores"
|
||||
]
|
||||
|
||||
PLATFORMS = {
|
||||
"ESP8266": "lx106",
|
||||
"ESP32": "esp32"
|
||||
}
|
||||
|
||||
BACKTRACE_REGEX = re.compile(r"(?:\s+(0x40[0-2](?:\d|[a-f]|[A-F]){5}):0x(?:\d|[a-f]|[A-F]){8})\b")
|
||||
EXCEPTION_REGEX = re.compile("^Exception \\((?P<exc>[0-9]*)\\):$")
|
||||
COUNTER_REGEX = re.compile('^epc1=(?P<epc1>0x[0-9a-f]+) epc2=(?P<epc2>0x[0-9a-f]+) epc3=(?P<epc3>0x[0-9a-f]+) '
|
||||
'excvaddr=(?P<excvaddr>0x[0-9a-f]+) depc=(?P<depc>0x[0-9a-f]+)$')
|
||||
CTX_REGEX = re.compile("^ctx: (?P<ctx>.+)$")
|
||||
POINTER_REGEX = re.compile('^sp: (?P<sp>[0-9a-f]+) end: (?P<end>[0-9a-f]+) offset: (?P<offset>[0-9a-f]+)$')
|
||||
STACK_BEGIN = '>>>stack>>>'
|
||||
STACK_END = '<<<stack<<<'
|
||||
STACK_REGEX = re.compile(
|
||||
'^(?P<off>[0-9a-f]+):\W+(?P<c1>[0-9a-f]+) (?P<c2>[0-9a-f]+) (?P<c3>[0-9a-f]+) (?P<c4>[0-9a-f]+)(\W.*)?$')
|
||||
|
||||
StackLine = namedtuple("StackLine", ["offset", "content"])
|
||||
|
||||
|
||||
class ExceptionDataParser(object):
|
||||
def __init__(self):
|
||||
self.exception = None
|
||||
|
||||
self.epc1 = None
|
||||
self.epc2 = None
|
||||
self.epc3 = None
|
||||
self.excvaddr = None
|
||||
self.depc = None
|
||||
|
||||
self.ctx = None
|
||||
|
||||
self.sp = None
|
||||
self.end = None
|
||||
self.offset = None
|
||||
|
||||
self.stack = []
|
||||
|
||||
def _parse_backtrace(self, line):
|
||||
if line.startswith('Backtrace:'):
|
||||
self.stack = [StackLine(offset=0, content=(addr,)) for addr in BACKTRACE_REGEX.findall(line)]
|
||||
return None
|
||||
return self._parse_backtrace
|
||||
|
||||
def _parse_exception(self, line):
|
||||
match = EXCEPTION_REGEX.match(line)
|
||||
if match is not None:
|
||||
self.exception = int(match.group('exc'))
|
||||
return self._parse_counters
|
||||
return self._parse_exception
|
||||
|
||||
def _parse_counters(self, line):
|
||||
match = COUNTER_REGEX.match(line)
|
||||
if match is not None:
|
||||
self.epc1 = match.group("epc1")
|
||||
self.epc2 = match.group("epc2")
|
||||
self.epc3 = match.group("epc3")
|
||||
self.excvaddr = match.group("excvaddr")
|
||||
self.depc = match.group("depc")
|
||||
return self._parse_ctx
|
||||
return self._parse_counters
|
||||
|
||||
def _parse_ctx(self, line):
|
||||
match = CTX_REGEX.match(line)
|
||||
if match is not None:
|
||||
self.ctx = match.group("ctx")
|
||||
return self._parse_pointers
|
||||
return self._parse_ctx
|
||||
|
||||
def _parse_pointers(self, line):
|
||||
match = POINTER_REGEX.match(line)
|
||||
if match is not None:
|
||||
self.sp = match.group("sp")
|
||||
self.end = match.group("end")
|
||||
self.offset = match.group("offset")
|
||||
return self._parse_stack_begin
|
||||
return self._parse_pointers
|
||||
|
||||
def _parse_stack_begin(self, line):
|
||||
if line == STACK_BEGIN:
|
||||
return self._parse_stack_line
|
||||
return self._parse_stack_begin
|
||||
|
||||
def _parse_stack_line(self, line):
|
||||
if line != STACK_END:
|
||||
match = STACK_REGEX.match(line)
|
||||
if match is not None:
|
||||
self.stack.append(StackLine(offset=match.group("off"),
|
||||
content=(match.group("c1"), match.group("c2"), match.group("c3"),
|
||||
match.group("c4"))))
|
||||
return self._parse_stack_line
|
||||
return None
|
||||
|
||||
def parse_file(self, file, platform, stack_only=False):
|
||||
if platform == 'ESP32':
|
||||
func = self._parse_backtrace
|
||||
else:
|
||||
func = self._parse_exception
|
||||
if stack_only:
|
||||
func = self._parse_stack_begin
|
||||
|
||||
for line in file:
|
||||
func = func(line.strip())
|
||||
if func is None:
|
||||
break
|
||||
|
||||
if func is not None:
|
||||
print("ERROR: Parser not complete!")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class AddressResolver(object):
|
||||
def __init__(self, tool_path, elf_path):
|
||||
self._tool = tool_path
|
||||
self._elf = elf_path
|
||||
self._address_map = {}
|
||||
|
||||
def _lookup(self, addresses):
|
||||
cmd = [self._tool, "-aipfC", "-e", self._elf] + [addr for addr in addresses if addr is not None]
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
output = subprocess.check_output(cmd)
|
||||
else:
|
||||
output = subprocess.check_output(cmd, encoding="utf-8")
|
||||
|
||||
line_regex = re.compile("^(?P<addr>[0-9a-fx]+): (?P<result>.+)$")
|
||||
|
||||
last = None
|
||||
for line in output.splitlines():
|
||||
line = line.strip()
|
||||
match = line_regex.match(line)
|
||||
|
||||
if match is None:
|
||||
if last is not None and line.startswith('(inlined by)'):
|
||||
line = line [12:].strip()
|
||||
self._address_map[last] += ("\n \-> inlined by: " + line)
|
||||
continue
|
||||
|
||||
if match.group("result") == '?? ??:0':
|
||||
continue
|
||||
|
||||
self._address_map[match.group("addr")] = match.group("result")
|
||||
last = match.group("addr")
|
||||
|
||||
def fill(self, parser):
|
||||
addresses = [parser.epc1, parser.epc2, parser.epc3, parser.excvaddr, parser.sp, parser.end, parser.offset]
|
||||
for line in parser.stack:
|
||||
addresses.extend(line.content)
|
||||
|
||||
self._lookup(addresses)
|
||||
|
||||
def _sanitize_addr(self, addr):
|
||||
if addr.startswith("0x"):
|
||||
addr = addr[2:]
|
||||
|
||||
fill = "0" * (8 - len(addr))
|
||||
return "0x" + fill + addr
|
||||
|
||||
def resolve_addr(self, addr):
|
||||
out = self._sanitize_addr(addr)
|
||||
|
||||
if out in self._address_map:
|
||||
out += ": " + self._address_map[out]
|
||||
|
||||
return out
|
||||
|
||||
def resolve_stack_addr(self, addr, full=True):
|
||||
addr = self._sanitize_addr(addr)
|
||||
if addr in self._address_map:
|
||||
return addr + ": " + self._address_map[addr]
|
||||
|
||||
if full:
|
||||
return "[DATA (0x" + addr + ")]"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def print_addr(name, value, resolver):
|
||||
print("{}:{} {}".format(name, " " * (8 - len(name)), resolver.resolve_addr(value)))
|
||||
|
||||
|
||||
def print_stack_full(lines, resolver):
|
||||
print("stack:")
|
||||
for line in lines:
|
||||
print(line.offset + ":")
|
||||
for content in line.content:
|
||||
print(" " + resolver.resolve_stack_addr(content))
|
||||
|
||||
|
||||
def print_stack(lines, resolver):
|
||||
print("stack:")
|
||||
for line in lines:
|
||||
for content in line.content:
|
||||
out = resolver.resolve_stack_addr(content, full=False)
|
||||
if out is None:
|
||||
continue
|
||||
print(out)
|
||||
|
||||
|
||||
def print_result(parser, resolver, platform, full=True, stack_only=False):
|
||||
if platform == 'ESP8266' and not stack_only:
|
||||
print('Exception: {} ({})'.format(parser.exception, EXCEPTIONS[parser.exception]))
|
||||
|
||||
print("")
|
||||
print_addr("epc1", parser.epc1, resolver)
|
||||
print_addr("epc2", parser.epc2, resolver)
|
||||
print_addr("epc3", parser.epc3, resolver)
|
||||
print_addr("excvaddr", parser.excvaddr, resolver)
|
||||
print_addr("depc", parser.depc, resolver)
|
||||
|
||||
print("")
|
||||
print("ctx: " + parser.ctx)
|
||||
|
||||
print("")
|
||||
print_addr("sp", parser.sp, resolver)
|
||||
print_addr("end", parser.end, resolver)
|
||||
print_addr("offset", parser.offset, resolver)
|
||||
|
||||
print("")
|
||||
if full:
|
||||
print_stack_full(parser.stack, resolver)
|
||||
else:
|
||||
print_stack(parser.stack, resolver)
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description="decode ESP Stacktraces.")
|
||||
|
||||
parser.add_argument("-p", "--platform", help="The platform to decode from", choices=PLATFORMS.keys(),
|
||||
default="ESP32")
|
||||
parser.add_argument("-t", "--tool", help="Path to the xtensa toolchain",
|
||||
default="~/.platformio/packages/toolchain-xtensa32/")
|
||||
parser.add_argument("-e", "--elf", help="path to elf file",
|
||||
default=".pio/build/esp32/firmware.elf")
|
||||
parser.add_argument("-f", "--full", help="Print full stack dump", action="store_true")
|
||||
parser.add_argument("-s", "--stack_only", help="Decode only a stractrace", action="store_true")
|
||||
parser.add_argument("file", help="The file to read the exception data from ('-' for STDIN)", default="-")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parse_args()
|
||||
|
||||
if args.file == "-":
|
||||
file = sys.stdin
|
||||
else:
|
||||
if not os.path.exists(args.file):
|
||||
print("ERROR: file " + args.file + " not found")
|
||||
sys.exit(1)
|
||||
file = open(args.file, "r")
|
||||
|
||||
addr2line = os.path.join(os.path.abspath(os.path.expanduser(args.tool)),
|
||||
"bin/xtensa-" + PLATFORMS[args.platform] + "-elf-addr2line")
|
||||
if os.name == 'nt':
|
||||
addr2line += '.exe'
|
||||
if not os.path.exists(addr2line):
|
||||
print("ERROR: addr2line not found (" + addr2line + ")")
|
||||
|
||||
elf_file = os.path.abspath(os.path.expanduser(args.elf))
|
||||
if not os.path.exists(elf_file):
|
||||
print("ERROR: elf file not found (" + elf_file + ")")
|
||||
|
||||
parser = ExceptionDataParser()
|
||||
resolver = AddressResolver(addr2line, elf_file)
|
||||
|
||||
parser.parse_file(file, args.platform, args.stack_only)
|
||||
resolver.fill(parser)
|
||||
|
||||
print_result(parser, resolver, args.platform, args.full, args.stack_only)
|
||||
@@ -3,4 +3,4 @@ set -e
|
||||
|
||||
source bin/version.sh
|
||||
|
||||
esptool.py --baud 921600 write_flash 0x10000 release/latest/firmware-HELTEC-US-$VERSION.bin
|
||||
esptool.py --baud 921600 write_flash 0x10000 release/latest/bins/firmware-heltec-US-$VERSION.bin
|
||||
|
||||
6
bin/program-release-tbeam.sh
Executable file
6
bin/program-release-tbeam.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
|
||||
set -e
|
||||
|
||||
source bin/version.sh
|
||||
|
||||
esptool.py --baud 921600 write_flash 0x10000 release/latest/bins/firmware-tbeam-US-$VERSION.bin
|
||||
1
bin/read-system-info.sh
Executable file
1
bin/read-system-info.sh
Executable file
@@ -0,0 +1 @@
|
||||
esptool.py --baud 921600 read_flash 0x1000 0xf000 system-info.img
|
||||
1
bin/run-1-monitor.sh
Executable file
1
bin/run-1-monitor.sh
Executable file
@@ -0,0 +1 @@
|
||||
pio run --upload-port /dev/ttyUSB1 -t upload -t monitor
|
||||
1
bin/start-terminal1.sh
Executable file
1
bin/start-terminal1.sh
Executable file
@@ -0,0 +1 @@
|
||||
pio device monitor -p /dev/ttyUSB1 -b 115200
|
||||
@@ -1,3 +1,3 @@
|
||||
|
||||
|
||||
export VERSION=0.1.0
|
||||
export VERSION=0.4.3
|
||||
@@ -4,6 +4,6 @@
|
||||
"namespace": "android_app",
|
||||
"package_name": "com.geeksville.mesh",
|
||||
"sha256_cert_fingerprints":
|
||||
["D0:05:E7:8B:D2:1B:FA:94:56:1D:6B:90:EB:53:07:1A:74:4F:D9:C2:6F:13:87:6A:D9:17:4F:C2:59:48:02:9D"]
|
||||
["D0:05:E7:8B:D2:1B:FA:94:56:1D:6B:90:EB:53:07:1A:74:4F:D9:C2:6F:13:87:6A:D9:17:4F:C2:59:48:02:9D", "42:17:52:DC:57:40:38:B5:6B:86:61:1C:2F:47:DB:2B:0F:A2:EA:59:E1:18:9C:AA:90:8D:37:D6:CD:40:0E:BB", "A9:3B:45:65:68:C1:75:DB:08:00:A0:9F:06:77:7F:89:2D:81:24:32:AD:B8:A3:DF:73:BC:3E:7F:06:C8:0C:6D"]
|
||||
}
|
||||
}]
|
||||
}]
|
||||
|
||||
@@ -1,82 +1,75 @@
|
||||
# What is Meshtastic?
|
||||
|
||||
Meshtastic is a project that lets you use
|
||||
inexpensive ($30 ish) GPS radios as an extensible, super long battery life mesh GPS communicator. These radios are great for hiking, skiing, paragliding -
|
||||
essentially any hobby where you don't have reliable internet access. Each member of your private mesh can always see the location and distance of all other
|
||||
members and any text messages sent to your group chat.
|
||||
inexpensive (\$30 ish) GPS radios as an extensible, super long battery life mesh GPS communicator. These radios are great for hiking, skiing, paragliding - essentially any hobby where you don't have reliable internet access. Each member of your private mesh can always see the location and distance of all other members and any text messages sent to your group chat.
|
||||
|
||||
The radios automatically create a mesh to forward packets as needed, so everyone in the group can receive messages from even the furthest member. The radios
|
||||
will optionally work with your phone, but no phone is required.
|
||||
The radios automatically create a mesh to forward packets as needed, so everyone in the group can receive messages from even the furthest member. The radios will optionally work with your phone, but no phone is required.
|
||||
|
||||
Note: Questions after reading this? See our new [forum](https://meshtastic.discourse.group/).
|
||||
|
||||
### Uses
|
||||
|
||||
* Outdoor sports where cellular coverage is limited. (Hiking, Skiing, Boating, Paragliding, Gliders etc..)
|
||||
* Applications where closed source GPS communicators just won't cut it (it is easy to add features for glider pilots etc...)
|
||||
* Secure long-range communication within groups without depending on cellular providers
|
||||
* Finding your lost kids ;-)
|
||||
- Outdoor sports where cellular coverage is limited. (Hiking, Skiing, Boating, Paragliding, Gliders etc..)
|
||||
- Applications where closed source GPS communicators just won't cut it (it is easy to add features for glider pilots etc...)
|
||||
- Secure long-range communication within groups without depending on cellular providers
|
||||
- Finding your lost kids ;-)
|
||||
|
||||
[](https://www.youtube.com/watch?v=WlNbMbVZlHI "Meshtastic early demo")
|
||||
|
||||
### Features
|
||||
Not all of these features are fully implemented yet - see **important** disclaimers below. But they should be in by the time we decide to call this project beta (three months?)
|
||||
|
||||
* Very long battery life (should be about eight days with the beta software)
|
||||
* Built in GPS and [LoRa](https://en.wikipedia.org/wiki/LoRa) radio, but we manage the radio automatically for you
|
||||
* Long range - a few miles per node but each node will forward packets as needed
|
||||
* Shows direction and distance to all members of your channel
|
||||
* Directed or broadcast text messages for channel members
|
||||
* Open and extensible codebase supporting multiple hardware vendors - no lock in to one vendor
|
||||
* Communication API for bluetooth devices (such as our Android app) to use the mesh. So if you have some application that needs long range low power networking, this might work for you.
|
||||
* Eventually (within a couple of months) we should have a modified version of Signal that works with this project.
|
||||
* Very easy sharing of private secured channels. Just share a special link or QR code with friends and they can join your encrypted mesh
|
||||
|
||||
This project is currently in early alpha - if you have questions please join our chat [](https://gitter.im/Meshtastic/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge).
|
||||
Not all of these features are fully implemented yet - see **important** disclaimers below. But they should be in by the time we decide to call this project beta (three months?)
|
||||
|
||||
This software is 100% open source and developed by a group of hobbyist experimenters. No warranty is provided, if you'd like to improve it - we'd love your help. Please post in the [chat](https://gitter.im/Meshtastic/community).
|
||||
- Very long battery life (should be about eight days with the beta software)
|
||||
- Built in GPS and [LoRa](https://en.wikipedia.org/wiki/LoRa) radio, but we manage the radio automatically for you
|
||||
- Long range - a few miles per node but each node will forward packets as needed
|
||||
- Shows direction and distance to all members of your channel
|
||||
- Directed or broadcast text messages for channel members
|
||||
- Open and extensible codebase supporting multiple hardware vendors - no lock in to one vendor
|
||||
- Communication API for bluetooth devices (such as our Android app) to use the mesh. So if you have some application that needs long range low power networking, this might work for you.
|
||||
- Eventually (within a couple of months) we should have a modified version of Signal that works with this project.
|
||||
- Very easy sharing of private secured channels. Just share a special link or QR code with friends and they can join your encrypted mesh
|
||||
|
||||
This project is currently in early alpha - if you have questions please [join our discussion forum](https://meshtastic.discourse.group/).
|
||||
|
||||
This software is 100% open source and developed by a group of hobbyist experimenters. No warranty is provided, if you'd like to improve it - we'd love your help. Please post in the [forum](https://meshtastic.discourse.group/).
|
||||
|
||||
# Updates
|
||||
|
||||
Note: Updates are happening almost daily, only major updates are listed below. For more details see our chat, github releases or the Android alpha tester emails.
|
||||
Note: Updates are happening almost daily, only major updates are listed below. For more details see our chat, github releases or the Android alpha tester emails.
|
||||
|
||||
* 03/03/2020 - 0.0.9 of the Android app and device code is released. Still an alpha but fairly functional.
|
||||
* 02/25/2020 - 0.0.4 of the Android app is released. This is a very early alpha, see below to join the alpha-testers group.
|
||||
* 02/23/2020 - 0.0.4 release. Still very bleeding edge but much closer to the final power management, a charged T-BEAM should run for many days with this load. If you'd like to try it, we'd love your feedback. Click [here](https://github.com/meshtastic/Meshtastic-esp32/blob/master/README.md) for instructions.
|
||||
* 02/20/2020 - Our first alpha release (0.0.3) of the radio software is ready brave early people.
|
||||
- 03/03/2020 - 0.0.9 of the Android app and device code is released. Still an alpha but fairly functional.
|
||||
- 02/25/2020 - 0.0.4 of the Android app is released. This is a very early alpha, see below to join the alpha-testers group.
|
||||
- 02/23/2020 - 0.0.4 release. Still very bleeding edge but much closer to the final power management, a charged T-BEAM should run for many days with this load. If you'd like to try it, we'd love your feedback. Click [here](https://github.com/meshtastic/Meshtastic-esp32/blob/master/README.md) for instructions.
|
||||
- 02/20/2020 - Our first alpha release (0.0.3) of the radio software is ready brave early people.
|
||||
|
||||
## Meshtastic Android app
|
||||
|
||||
Once out of alpha the companion Android application will be released here:
|
||||
|
||||
[](https://play.google.com/store/apps/details?id=com.geeksville.mesh&referrer=utm_source%3Dhomepage%26anid%3Dadmob)
|
||||
|
||||
But if you want the bleeding edge app now, we'd love to have your help testing. Three steps to opt-in to the alpha- test:
|
||||
But if you want the bleeding edge app now, we'd love to have your help testing. Three steps to opt-in to the alpha- test:
|
||||
|
||||
1. Join [this Google group](https://groups.google.com/forum/#!forum/meshtastic-alpha-testers) with the account you use in Google Play.
|
||||
2. Go to this [URL](https://play.google.com/apps/testing/com.geeksville.mesh) to opt-in to the alpha test.
|
||||
3. If you encounter any problems or have questions, post in our gitter chat and we'll help.
|
||||
3. If you encounter any problems or have questions, post in our [forum](https://meshtastic.discourse.group/) and we'll help.
|
||||
|
||||
If you'd like to help with development, the source code is [on github](https://github.com/meshtastic/Meshtastic-Android).
|
||||
|
||||
## Supported hardware
|
||||
We currently support two brands of radios. The [TTGO T-Beam](https://www.aliexpress.com/item/4000119152086.html) and the [Heltec LoRa 32](https://heltec.org/project/wifi-lora-32/). Most people should buy the T-Beam and a 18650 battery (total cost less than $35). Make
|
||||
sure to buy the frequency range which is legal for your country. For the USA, you should buy the 915MHz version. Getting a version that include a screen is optional, but highly recommended.
|
||||
|
||||
We currently support two brands of radios. The [TTGO T-Beam](https://www.aliexpress.com/item/4000119152086.html) and the [Heltec LoRa 32](https://heltec.org/project/wifi-lora-32/). Most people should buy the T-Beam and a 18650 battery (total cost less than \$35). Make
|
||||
sure to buy the frequency range which is legal for your country. For the USA, you should buy the 915MHz version. Getting a version that include a screen is optional, but highly recommended.
|
||||
|
||||
Instructions for installing prebuilt firmware can be found [here](https://github.com/meshtastic/Meshtastic-esp32/blob/master/README.md).
|
||||
|
||||
For a nice TTGO 3D printable case see this [design](https://www.thingiverse.com/thing:3773717) by [bsiege](https://www.thingiverse.com/bsiege).
|
||||
For a nice Heltec 3D printable case see this [design](https://www.thingiverse.com/thing:3125854) by [ornotermes](https://www.thingiverse.com/ornotermes).
|
||||
For a nice printable cases:
|
||||
|
||||
# Disclaimers
|
||||
1. TTGO T-Beam V0 see this [design](https://www.thingiverse.com/thing:3773717) by [bsiege](https://www.thingiverse.com/bsiege).
|
||||
2. TTGO T_Beam V1 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)
|
||||
3. Heltec Lora32 see this [design](https://www.thingiverse.com/thing:3125854) by [ornotermes](https://www.thingiverse.com/ornotermes).
|
||||
|
||||
This project is still pretty young but moving at a pretty good pace. Not all features are fully implemented in the current alpha builds.
|
||||
Most of these problems should be solved by the beta release:
|
||||
# IMPORTANT DISCLAIMERS AND FAQ
|
||||
|
||||
* We don't make these devices and they haven't been tested by UL or the FCC. If you use them you are experimenting and we can't promise they won't burn your house down ;-)
|
||||
* Encryption is turned off for now
|
||||
* A number of (straightforward) software work items have to be completed before battery life matches our measurements, currently battery life is about three days. Join us on chat if you want the spreadsheet of power measurements/calculations.
|
||||
* The current Android GUI is pretty ugly still
|
||||
* The Android API needs to be documented better
|
||||
* The Bluetooth API needs to be documented better
|
||||
* The mesh protocol is turned off for now, currently we only send packets one hop distant
|
||||
* No one has written an iOS app yet ;-)
|
||||
|
||||
For more details see the [device software TODO](https://github.com/meshtastic/Meshtastic-esp32/blob/master/TODO.md) or the [Android app TODO](https://github.com/meshtastic/Meshtastic-Android/blob/master/TODO.md).
|
||||
For a listing of currently missing features and a FAQ click [here](faq.md).
|
||||
|
||||
@@ -3,3 +3,6 @@ theme: jekyll-theme-cayman
|
||||
title: Meshtastic
|
||||
description: An opensource hiking, pilot, skiing, Signal-App-extending GPS mesh communicator
|
||||
google_analytics: G-DRZ5H5EXHV
|
||||
|
||||
include: [".well-known"]
|
||||
|
||||
|
||||
34
docs/faq.md
Normal file
34
docs/faq.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Disclaimers
|
||||
|
||||
This project is still pretty young but moving at a pretty good pace. Not all features are fully implemented in the current alpha builds.
|
||||
Most of these problems should be solved by the beta release (within three months):
|
||||
|
||||
- We don't make these devices and they haven't been tested by UL or the FCC. If you use them you are experimenting and we can't promise they won't burn your house down ;-)
|
||||
- Encryption is turned off for now
|
||||
- A number of (straightforward) software work items have to be completed before battery life matches our measurements, currently battery life is about three days. Join us on chat if you want the spreadsheet of power measurements/calculations.
|
||||
- The Android API needs to be documented better
|
||||
- No one has written an iOS app yet. But some good souls [are talking about it](https://github.com/meshtastic/Meshtastic-esp32/issues/14) ;-)
|
||||
|
||||
For more details see the [device software TODO](https://github.com/meshtastic/Meshtastic-esp32/blob/master/docs/software/TODO.md) or the [Android app TODO](https://github.com/meshtastic/Meshtastic-Android/blob/master/TODO.md).
|
||||
|
||||
# FAQ
|
||||
|
||||
If you have a question missing from this faq, please [ask in our discussion forum](https://meshtastic.discourse.group/). And if you are feeling extra generous send in a pull-request for this faq.md with whatever we answered ;-).
|
||||
|
||||
## Q: Which of the various supported radios should I buy?
|
||||
|
||||
Basically you just need the radio + (optional but recommended) battery. The TBEAM is usually better because it has gps and huge battery socket. The Heltec is basically the same hardware but without the GPS (the phone provides position data to the radio in that case, so the behavior is similar - but it does burn some battery in the phone). Also the battery for the Heltec can be smaller.
|
||||
|
||||
In addition to Aliexpress, (banggood.com) usually has stock and faster shipping, or Amazon. If buying a TBEAM, make sure to buy a version that includes the OLED screen - this project doesn't absolutely require the screen, but we use it if is installed.
|
||||
|
||||
@claesg has added links to various 3D printable cases, you can see them at (www.meshtastic.org).
|
||||
|
||||
## Q: Do you have plans to commercialize this project
|
||||
|
||||
Nope. though if some other person/group wanted to use this software and a more customized device we think that would be awesome (as long as they obey the GPL license).
|
||||
|
||||
## Q: Does this project use patented algorithms?
|
||||
|
||||
(Kindly borrowed from the geeks at [ffmpeg](http://ffmpeg.org/legal.html))
|
||||
|
||||
We do not know, we are not lawyers so we are not qualified to answer this. Also we have never read patents to implement any part of this, so even if we were qualified we could not answer it as we do not know what is patented. Furthermore the sheer number of software patents makes it impossible to read them all so no one (lawyer or not) could answer such a question with a definite no. We are merely geeks experimenting on a fun and free project.
|
||||
@@ -10,6 +10,13 @@ See [this site](https://www.rfwireless-world.com/Tutorials/LoRa-channels-list.ht
|
||||
|
||||
The maximum power allowed is +14dBM.
|
||||
|
||||
### 433 MHz
|
||||
|
||||
There are eight channels defined with a 0.2 MHz gap between them.
|
||||
Channel zero starts at 433.175 MHz
|
||||
|
||||
### 870 MHz
|
||||
|
||||
There are eight channels defined with a 0.3 MHz gap between them.
|
||||
Channel zero starts at 865.20 MHz
|
||||
|
||||
|
||||
207
docs/software/TODO.md
Normal file
207
docs/software/TODO.md
Normal file
@@ -0,0 +1,207 @@
|
||||
# High priority
|
||||
|
||||
Items to complete soon (next couple of alpha releases).
|
||||
|
||||
- lower wait_bluetooth_secs to 30 seconds once we have the GPS power on (but GPS in sleep mode) across light sleep. For the time
|
||||
being I have it set at 2 minutes to ensure enough time for a GPS lock from scratch.
|
||||
|
||||
- remeasure wake time power draws now that we run CPU down at 80MHz
|
||||
|
||||
# AXP192 tasks
|
||||
|
||||
- figure out why this fixme is needed: "FIXME, disable wake due to PMU because it seems to fire all the time?"
|
||||
- "AXP192 interrupt is not firing, remove this temporary polling of battery state"
|
||||
- make debug info screen show real data (including battery level & charging) - close corresponding github issue
|
||||
|
||||
# Medium priority
|
||||
|
||||
Items to complete before the first beta release.
|
||||
|
||||
- Don't store position packets in the to phone fifo if we are disconnected. The phone will get that info for 'free' when it
|
||||
fetches the fresh nodedb.
|
||||
- Use the RFM95 sequencer to stay in idle mode most of the time, then automatically go to receive mode and automatically go from transmit to receive mode. See 4.2.8.2 of manual.
|
||||
- possibly switch to https://github.com/SlashDevin/NeoGPS for gps comms
|
||||
- good source of battery/signal/gps icons https://materialdesignicons.com/
|
||||
- research and implement better mesh algorithm - investigate changing routing to https://github.com/sudomesh/LoRaLayer2 ?
|
||||
- check fcc rules on duty cycle. we might not need to freq hop. https://www.sunfiretesting.com/LoRa-FCC-Certification-Guide/
|
||||
- use fuse bits to store the board type and region. So one load can be used on all boards
|
||||
- the BLE stack is leaking about 200 bytes each time we go to light sleep
|
||||
- rx signal measurements -3 marginal, -9 bad, 10 great, -10 means almost unusable. So scale this into % signal strength. preferably as a graph, with an X indicating loss of comms.
|
||||
- assign every "channel" a random shared 8 bit sync word (per 4.2.13.6 of datasheet) - use that word to filter packets before even checking CRC. This will ensure our CPU will only wake for packets on our "channel"
|
||||
- Note: we do not do address filtering at the chip level, because we might need to route for the mesh
|
||||
- add basic crypto - https://github.com/chegewara/esp32-mbedtls-aes-test/blob/master/main/main.c https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation - use ECB at first (though it is shit) because it doesn't require us to send 16 bytes of IV with each packet. Then OFB per example. Possibly do this crypto at the data payload level only, so that all of the packet routing metadata
|
||||
is in cleartext (so that nodes will route for other radios that are cryptoed with a key we don't know)
|
||||
- add frequency hopping, dependent on the gps time, make the switch moment far from the time anyone is going to be transmitting
|
||||
- share channel settings over Signal (or qr code) by embedding an an URL which is handled by the MeshUtil app.
|
||||
- publish update articles on the web
|
||||
|
||||
# Pre-beta priority
|
||||
|
||||
During the beta timeframe the following improvements 'would be nice' (and yeah - I guess some of these items count as features, but it is a hobby project ;-) )
|
||||
|
||||
- If the phone doesn't read fromradio mailbox within X seconds, assume the phone is gone and we can stop queing location msgs
|
||||
for it (because it will redownload the nodedb when it comes back)
|
||||
- Figure out why the RF95 ISR is never seeing RH_RF95_VALID_HEADER, so it is not protecting our rx packets from getting stomped on by sends
|
||||
- fix the frequency error reading in the RF95 RX code (can't do floating point math in an ISR ;-)
|
||||
- See CustomRF95::send and fix the problem of dropping partially received packets if we want to start sending
|
||||
- make sure main cpu is not woken for packets with bad crc or not addressed to this node - do that in the radio hw
|
||||
- triple check fcc compliance
|
||||
- pick channel center frequency based on channel name? "dolphin" would hash to 900Mhz, "cat" to 905MHz etc? allows us to hide the concept of channel # from hte user.
|
||||
- scan to find channels with low background noise? (Use CAD mode of the RF95 to automatically find low noise channels)
|
||||
- make a no bluetooth configured yet screen - include this screen in the loop if the user hasn't yet paired
|
||||
- if radio params change fundamentally, discard the nodedb
|
||||
- reneable the bluetooth battery level service on the T-BEAM, because we can read battery level there
|
||||
|
||||
# Spinoff project ideas
|
||||
|
||||
- an open source version of https://www.burnair.ch/skynet/
|
||||
- a paragliding app like http://airwhere.co.uk/
|
||||
- a version with a solar cell for power, just mounted high to permanently provide routing for nodes in a valley. Someone just pointed me at disaster.radio
|
||||
- How do avalanche beacons work? Could this do that as well? possibly by using beacon mode feature of the RF95?
|
||||
- provide generalized (but slow) internet message forwarding servie if one of our nodes has internet connectivity
|
||||
|
||||
# Low priority
|
||||
|
||||
Items after the first final candidate release.
|
||||
|
||||
- use variable length arduino Strings in protobufs (instead of current fixed buffers)
|
||||
- use BLEDevice::setPower to lower our BLE transmit power - extra range doesn't help us, it costs amps and it increases snoopability
|
||||
- make an install script to let novices install software on their boards
|
||||
- use std::map<NodeInfo\*, std::string> in node db
|
||||
- make a HAM build: yep - that's a great idea. I'll add it to the TODO. should be pretty painless - just a new frequency list, a bool to say 'never do encryption' and use hte callsign as that node's unique id. -from Girts
|
||||
- don't forward redundant pings or ping responses to the phone, it just wastes phone battery
|
||||
- use https://platformio.org/lib/show/1260/OneButton if necessary
|
||||
- don't send location packets if we haven't moved
|
||||
- scrub default radio config settings for bandwidth/range/speed
|
||||
- answer to pings (because some other user is looking at our nodeinfo) with our latest location (not a stale location)
|
||||
- show radio and gps signal strength as an image
|
||||
- only BLE advertise for a short time after the screen is on and button pressed - to save power and prevent people for sniffing for our BT app.
|
||||
- make mesh aware network timing state machine (sync wake windows to gps time)
|
||||
- split out the software update utility so other projects can use it. Have the appload specify the URL for downloads.
|
||||
- read the PMU battery fault indicators and blink/led/warn user on screen
|
||||
- the AXP debug output says it is trying to charge at 700mA, but the max I've seen is 180mA, so AXP registers probably need to be set to tell them the circuit can only provide 300mAish max. So that the low charge rate kicks in faster and we don't wear out batteries.
|
||||
- increase the max charging rate a bit for 18650s, currently it limits to 180mA (at 4V). Work backwards from the 500mA USB limit (at 5V) and let the AXP charge at that rate.
|
||||
- discard very old nodedb records (> 1wk)
|
||||
- using the genpartitions based table doesn't work on TTGO so for now I stay with my old memory map
|
||||
- We let anyone BLE scan for us (FIXME, perhaps only allow that until we are paired with a phone and configured)
|
||||
- use two different buildenv flags for ttgo vs lora32. https://docs.platformio.org/en/latest/ide/vscode.html#key-bindings
|
||||
- sim gps data for testing nodes that don't have hardware
|
||||
- do debug serial logging to android over bluetooth
|
||||
- break out my bluetooth OTA software as a seperate library so others can use it
|
||||
- Heltec LoRa32 has 8MB flash, use a bigger partition table if needed - TTGO is 4MB but has PSRAM
|
||||
- add a watchdog timer
|
||||
- handle millis() rollover in GPS.getTime - otherwise we will break after 50 days
|
||||
- report esp32 device code bugs back to the mothership via android
|
||||
|
||||
# Done
|
||||
|
||||
- change the partition table to take advantage of the 4MB flash on the wroom: http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
|
||||
- wrap in nice MeshRadio class
|
||||
- add mesh send & rx
|
||||
- make message send from android go to service, then to mesh radio
|
||||
- make message receive from radio go through to android
|
||||
- test loopback tx/rx path code without using radio
|
||||
- notify phone when rx packets arrive, currently the phone polls at startup only
|
||||
- figure out if we can use PA_BOOST - yes, it seems to be on both boards
|
||||
- implement new ble characteristics
|
||||
- have MeshService keep a node DB by sniffing user messages
|
||||
- have a state machine return the correct FromRadio packet to the phone, it isn't always going to be a MeshPacket. Do a notify on fromnum to force the radio to read our state machine generated packets
|
||||
- send my_node_num when phone sends WantsNodes
|
||||
- have meshservice periodically send location data on mesh (if device has a GPS)
|
||||
- implement getCurrentTime() - set based off gps but then updated locally
|
||||
- make default owner record have valid usernames
|
||||
- message loop between node 0x28 and 0x7c
|
||||
- check in my radiolib fixes
|
||||
- figure out what is busted with rx
|
||||
- send our owner info at boot, reply if we see anyone send theirs
|
||||
- add manager layers
|
||||
- confirm second device receives that gps message and updates device db
|
||||
- send correct hw vendor in the bluetooth info - needed so the android app can update different radio models
|
||||
- correctly map nodeids to nodenums, currently we just do a proof of concept by always doing a broadcast
|
||||
- add interrupt detach/sleep mode config to lora radio so we can enable deepsleep without panicing
|
||||
- make jtag work on second board
|
||||
- implement regen owner and radio prefs
|
||||
- use a better font
|
||||
- make nice screens (boot, about to sleep, debug info (gps signal, #people), latest text, person info - one frame per person on network)
|
||||
- turn framerate from ui->state.frameState to 1 fps (or less) unless in transition
|
||||
- switch to my gui layout manager
|
||||
- make basic gui. different screens: debug, one page for each user in the user db, last received text message
|
||||
- make button press cycle between screens
|
||||
- save our node db on entry to sleep
|
||||
- fix the logo
|
||||
- sent/received packets (especially if a node was just reset) have variant of zero sometimes - I think there is a bug (race-condtion?) in the radio send/rx path.
|
||||
- DONE dynamic nodenum assignment tasks
|
||||
- make jtag debugger id stable: https://askubuntu.com/questions/49910/how-to-distinguish-between-identical-usb-to-serial-adapters
|
||||
- reported altitude is crap
|
||||
- good tips on which bands might be more free https://github.com/TheThingsNetwork/ttn/issues/119
|
||||
- finish power measurements (GPS on during sleep vs LCD on during sleep vs LORA on during sleep) and est battery life
|
||||
- make screen sleep behavior work
|
||||
- make screen advance only when a new node update arrives, a new text arrives or the user presses a button, turn off screen after a while
|
||||
- after reboot, channel number is getting reset to zero! fix!
|
||||
- send user and location events much less often
|
||||
- send location (or if not available user) when the user wakes the device from display sleep (both for testing and to improve user experience)
|
||||
- make real implementation of getNumOnlineNodes
|
||||
- very occasionally send our position and user packet based on the schedule in the radio info (if for nothing else so that other nodes update last_seen)
|
||||
- show real text info on the text screen
|
||||
- apply radio settings from android land
|
||||
- cope with nodes that have 0xff or 0x00 as the last byte of their mac
|
||||
- allow setting full radio params from android
|
||||
- add receive timestamps to messages, inserted by esp32 when message is received but then shown on the phone
|
||||
- update build to generate both board types
|
||||
- have node info screen show real info (including distance and heading)
|
||||
- blink the power led less often
|
||||
- have radiohead ISR send messages to RX queue directly, to allow that thread to block until we have something to send
|
||||
- move lora rx/tx to own thread and block on IO
|
||||
- keep our pseudo time moving forward even if we enter deep sleep (use esp32 rtc)
|
||||
- for non GPS equipped devices, set time from phone
|
||||
- GUI on oled hangs for a few seconds occasionally, but comes back
|
||||
- update local GPS position (but do not broadcast) at whatever rate the GPS is giving it
|
||||
- don't send our times to other nodes
|
||||
- don't trust times from other nodes
|
||||
- draw compass rose based off local walking track
|
||||
- add requestResponse optional bool - use for location broadcasts when sending tests
|
||||
- post sample video to signal forum
|
||||
- support non US frequencies
|
||||
- send pr https://github.com/ThingPulse/esp8266-oled-ssd1306 to tell them about this project
|
||||
- document rules for sleep wrt lora/bluetooth/screen/gps. also: if I have text messages (only) for the phone, then give a few seconds in the hopes BLE can get it across before we have to go back to sleep.
|
||||
- wake from light sleep as needed for our next scheduled periodic task (needed for gps position broadcasts etc)
|
||||
- turn bluetooth off based on our sleep policy
|
||||
- blink LED while in LS sleep mode
|
||||
- scrolling between screens based on press is busted
|
||||
- Use Neo-M8M API to put it in sleep mode (on hold until my new boards arrive)
|
||||
- update the prebuilt bins for different regulatory regions
|
||||
- don't enter NB state if we've recently talked to the phone (to prevent breaking syncing or bluetooth sw update)
|
||||
- have sw update prevent BLE sleep
|
||||
- manually delete characteristics/descs
|
||||
- leave lora receiver always on
|
||||
- protobufs are sometimes corrupted after sleep!
|
||||
- stay awake while charging
|
||||
- check gps battery voltage
|
||||
- if a position report includes ground truth time and we don't have time yet, set our clock from that. It is better than nothing.
|
||||
- retest BLE software update for both board types
|
||||
- report on wikifactory
|
||||
- send note to the guy who designed the cases
|
||||
- turn light sleep on aggressively (while lora is on but BLE off)
|
||||
- Use the Periodic class for both position and user periodic broadcasts
|
||||
- don't treat north as up, instead adjust shown bearings for our guess at the users heading (i.e. subtract one from the other)
|
||||
- sendToMesh can currently block for a long time, instead have it just queue a packet for a radio freertos thread
|
||||
- don't even power on bluetooth until we have some data to send to the android phone. Most of the time we should be sleeping in a lowpower "listening for lora" only mode. Once we have some packets for the phone, then power on bluetooth
|
||||
until the phone pulls those packets. Ever so often power on bluetooth just so we can see if the phone wants to send some packets. Possibly might need ULP processor to help with this wake process.
|
||||
- do hibernation mode to get power draw down to 2.5uA https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/
|
||||
- fix GPS.zeroOffset calculation it is wrong
|
||||
- (needs testing) fixed the following during a plane flight:
|
||||
Have state machine properly enter deep sleep based on loss of mesh and phone comms.
|
||||
Default to enter deep sleep if no LORA received for two hours (indicates user has probably left the mesh).
|
||||
- (fixed I think) text messages are not showing on local screen if screen was on
|
||||
- add links to todos
|
||||
- link to the kanban page
|
||||
- add a getting started page
|
||||
- finish mesh alg reeval
|
||||
- ublox gps parsing seems a little buggy (we shouldn't be sending out read solution commands, the device is already broadcasting them)
|
||||
- turn on gps https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/blob/master/examples/Example18_PowerSaveMode/Example18_PowerSaveMode.ino
|
||||
- switch gps to 38400 baud https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/blob/master/examples/Example11_ResetModule/Example2_FactoryDefaultsviaSerial/Example2_FactoryDefaultsviaSerial.ino
|
||||
- Use Neo-M8M API to put it in sleep mode
|
||||
- use gps sleep mode instead of killing its power (to allow fast position when we wake)
|
||||
- enable fast lock and low power inside the gps chip
|
||||
- Make a FAQ
|
||||
- add a SF12 transmit option for _super_ long range
|
||||
110
docs/software/bluetooth-api.md
Normal file
110
docs/software/bluetooth-api.md
Normal file
@@ -0,0 +1,110 @@
|
||||
# Bluetooth API
|
||||
|
||||
The Bluetooth API is design to have only a few characteristics and most polymorphism comes from the flexible set of Google Protocol Buffers which are sent over the wire. We use protocol buffers extensively both for the bluetooth API and for packets inside the mesh or when providing packets to other applications on the phone.
|
||||
|
||||
## A note on MTU sizes
|
||||
|
||||
This device will work with any MTU size, but it is highly recommended that you call your phone's "setMTU function to increase MTU to 512 bytes" as soon as you connect to a service. This will dramatically improve performance when reading/writing packets.
|
||||
|
||||
## MeshBluetoothService
|
||||
|
||||
This is the main bluetooth service for the device and provides the API your app should use to get information about the mesh, send packets or provision the radio.
|
||||
|
||||
For a reference implementation of a client that uses this service see [RadioInterfaceService](https://github.com/meshtastic/Meshtastic-Android/blob/master/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt). Typical flow when
|
||||
a phone connects to the device should be the following:
|
||||
|
||||
* SetMTU size to 512
|
||||
* Read a RadioConfig from "radio" - used to get the channel and radio settings
|
||||
* Read (and write if incorrect) a User from "user" - to get the username for this node
|
||||
* Read a MyNodeInfo from "mynode" to get information about this local device
|
||||
* Write an empty record to "nodeinfo" to restart the nodeinfo reading state machine
|
||||
* Read from "nodeinfo" until it returns empty to build the phone's copy of the current NodeDB for the mesh
|
||||
* Read from "fromradio" until it returns empty to get any messages that arrived for this node while the phone was away
|
||||
* Subscribe to notify on "fromnum" to get notified whenever the device has a new received packet
|
||||
* Read that new packet from "fromradio"
|
||||
* Whenever the phone has a packet to send write to "toradio"
|
||||
|
||||
For definitions (and documentation) on FromRadio, ToRadio, MyNodeInfo, NodeInfo and User protocol buffers see [mesh.proto](https://github.com/meshtastic/Meshtastic-protobufs/blob/master/mesh.proto)
|
||||
|
||||
UUID for the service: 6ba1b218-15a8-461f-9fa8-5dcae273eafd
|
||||
|
||||
Each characteristic is listed as follows:
|
||||
|
||||
UUID
|
||||
Properties
|
||||
Description (including human readable name)
|
||||
|
||||
8ba2bcc2-ee02-4a55-a531-c525c5e454d5
|
||||
read
|
||||
fromradio - contains a newly received FromRadio packet destined towards the phone (up to MAXPACKET bytes per packet).
|
||||
After reading the esp32 will put the next packet in this mailbox. If the FIFO is empty it will put an empty packet in this
|
||||
mailbox.
|
||||
|
||||
f75c76d2-129e-4dad-a1dd-7866124401e7
|
||||
write
|
||||
toradio - write ToRadio protobufs to this characteristic to send them (up to MAXPACKET len)
|
||||
|
||||
ed9da18c-a800-4f66-a670-aa7547e34453
|
||||
read,notify,write
|
||||
fromnum - the current packet # in the message waiting inside fromradio, if the phone sees this notify it should read messages
|
||||
until it catches up with this number.
|
||||
|
||||
The phone can write to this register to go backwards up to FIXME packets, to handle the rare case of a fromradio packet was dropped after the esp32 callback was called, but before it arrives at the phone. If the phone writes to this register the esp32 will discard older packets and put the next packet >= fromnum in fromradio.
|
||||
When the esp32 advances fromnum, it will delay doing the notify by 100ms, in the hopes that the notify will never actally need to be sent if the phone is already pulling from fromradio.
|
||||
|
||||
Note: that if the phone ever sees this number decrease, it means the esp32 has rebooted.
|
||||
|
||||
ea9f3f82-8dc4-4733-9452-1f6da28892a2
|
||||
read
|
||||
mynode - read this to access a MyNodeInfo protobuf
|
||||
|
||||
d31e02e0-c8ab-4d3f-9cc9-0b8466bdabe8
|
||||
read, write
|
||||
nodeinfo - read this to get a series of NodeInfos (ending with a null empty record), write to this to restart the read statemachine that returns all the node infos
|
||||
|
||||
b56786c8-839a-44a1-b98e-a1724c4a0262
|
||||
read,write
|
||||
radio - read/write this to access a RadioConfig protobuf
|
||||
|
||||
6ff1d8b6-e2de-41e3-8c0b-8fa384f64eb6
|
||||
read,write
|
||||
owner - read/write this to access a User protobuf
|
||||
|
||||
Re: queue management
|
||||
Not all messages are kept in the fromradio queue (filtered based on SubPacket):
|
||||
* only the most recent Position and User messages for a particular node are kept
|
||||
* all Data SubPackets are kept
|
||||
* No WantNodeNum / DenyNodeNum messages are kept
|
||||
A variable keepAllPackets, if set to true will suppress this behavior and instead keep everything for forwarding to the phone (for debugging)
|
||||
|
||||
|
||||
## Other bluetooth services
|
||||
|
||||
This document focuses on the core mesh service, but it is worth noting that the following other Bluetooth services are also
|
||||
provided by the device.
|
||||
|
||||
### BluetoothSoftwareUpdate
|
||||
|
||||
The software update service. For a sample function that performs a software update using this API see [startUpdate](https://github.com/meshtastic/Meshtastic-Android/blob/master/app/src/main/java/com/geeksville/mesh/service/SoftwareUpdateService.kt).
|
||||
|
||||
SoftwareUpdateService UUID cb0b9a0b-a84c-4c0d-bdbb-442e3144ee30
|
||||
|
||||
Characteristics
|
||||
|
||||
| UUID | properties | description|
|
||||
|--------------------------------------|------------------|------------|
|
||||
| e74dd9c0-a301-4a6f-95a1-f0e1dbea8e1e | write,read | total image size, 32 bit, write this first, then read read back to see if it was acceptable (0 mean not accepted) |
|
||||
| e272ebac-d463-4b98-bc84-5cc1a39ee517 | write | data, variable sized, recommended 512 bytes, write one for each block of file |
|
||||
| 4826129c-c22a-43a3-b066-ce8f0d5bacc6 | write | crc32, write last - writing this will complete the OTA operation, now you can read result |
|
||||
| 5e134862-7411-4424-ac4a-210937432c77 | read,notify | result code, readable but will notify when the OTA operation completes |
|
||||
| GATT_UUID_SW_VERSION_STR/0x2a28 | read | We also implement these standard GATT entries because SW update probably needs them: |
|
||||
| GATT_UUID_MANU_NAME/0x2a29 | read | |
|
||||
| GATT_UUID_HW_VERSION_STR/0x2a27 | read | |
|
||||
|
||||
### DeviceInformationService
|
||||
|
||||
Implements the standard BLE contract for this service (has software version, hardware model, serial number, etc...)
|
||||
|
||||
### BatteryLevelService
|
||||
|
||||
Implements the standard BLE contract service, provides battery level in a way that most client devices should automatically understand (i.e. it should show in the bluetooth devices screen automatically)
|
||||
21
docs/software/build-instructions.md
Normal file
21
docs/software/build-instructions.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Build instructions
|
||||
|
||||
This project uses the simple PlatformIO build system. You can use the IDE, but for brevity
|
||||
in these instructions I describe use of their command line tool.
|
||||
|
||||
1. Purchase a suitable radio (see above)
|
||||
2. Install [PlatformIO](https://platformio.org/platformio-ide)
|
||||
3. Download this git repo and cd into it
|
||||
4. If you are outside the USA, edit [platformio.ini](/platformio.ini) to set the correct frequency range for your country. The line you need to change starts with "hw_version" and instructions are provided above that line. Options are provided for EU433, EU835, CN, JP and US. Pull-requests eagerly accepted for other countries.
|
||||
5. Plug the radio into your USB port
|
||||
6. Type "pio run --environment XXX -t upload" (This command will fetch dependencies, build the project and install it on the board via USB). For XXX, use the board type you have (either tbeam, heltec, ttgo-lora32-v1, ttgo-lora32-v2).
|
||||
7. Platform IO also installs a very nice VisualStudio Code based IDE, see their [tutorial](https://docs.platformio.org/en/latest/tutorials/espressif32/arduino_debugging_unit_testing.html) if you'd like to use it.
|
||||
|
||||
## Decoding stack traces
|
||||
|
||||
If you get a crash, you can decode the addresses from the `Backtrace:` line:
|
||||
|
||||
1. Save the `Backtrace: 0x....` line to a file, e.g., `backtrace.txt`.
|
||||
2. Run `bin/exception_decoder.py backtrace.txt` (this uses symbols from the
|
||||
last `firmware.elf`, so you must be running the same binary that's still in
|
||||
your `.pio/build` directory).
|
||||
27
docs/software/install-OSX.md
Normal file
27
docs/software/install-OSX.md
Normal file
@@ -0,0 +1,27 @@
|
||||
(Here's some quick tips on installing the device code from OS-X, thanks to @android606)
|
||||
|
||||
First time using LoRa for anything, just checking it out.
|
||||
|
||||
I bought a T-Beam on eBay, followed the instructions to install the firmware here:
|
||||
[https://github.com/meshtastic/Meshtastic-esp32](https://github.com/meshtastic/Meshtastic-esp32)
|
||||
|
||||
I'm using a Mac for this, so that might account for differences in the steps to get it working. I just swapped out my SSD last month, I'm using a pretty fresh install of OS X 10.15.3/Catalina.
|
||||
|
||||
I got it working fairly smoothly, but there were two hang-ups I thought I'd mention:
|
||||
|
||||
1. I am about 0% familiar with Python, so there were some issues getting esptool.py working. Basically, this OS X comes with Python 2.7 and no pip. Pip installed okay, so I used it to install esptool. Esptool appeared to install correctly, but I couldn't get it to work to save my life. Simply typing "esptool.py" doesn't work, and I just don't know enough python to figure out why. For some reason, it installs but isn't in the \$PATH anywhere, and I don't know where it went. Python 2.7 kept giving me warning messages about being old and unsupported, so I figured that might be a hint that I should upgrade.
|
||||
|
||||
I ended up doing this:
|
||||
|
||||
- brew install pyenv (to install pyenv)
|
||||
- pyenv install 3.7.7 (to install and select python 3.7.7)
|
||||
- pyenv global 3.7.7 (to select the new version of python)
|
||||
- brew install pip (to install pip3)
|
||||
- pip3 install --upgrade esptool (note I specifically had to use "pip3", not "pip")
|
||||
|
||||
...then I was able to execute esptool.py
|
||||
|
||||
2. esptool.py didn't work though, because the virtual com port wasn't showing up as a device. I had to install a driver from Silicon Labs, which I got here:
|
||||
[driver for the CP210X USB to UART bridge from Silicon Labs](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers)
|
||||
|
||||
After I installed that, esptool.py was completely happy and the firmware loaded right up.
|
||||
95
docs/software/mesh-alg.md
Normal file
95
docs/software/mesh-alg.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# Mesh broadcast algorithm
|
||||
|
||||
FIXME - instead look for standard solutions. this approach seems really suboptimal, because too many nodes will try to rebroast. If
|
||||
all else fails could always use the stock Radiohead solution - though super inefficient.
|
||||
|
||||
great source of papers and class notes: http://www.cs.jhu.edu/~cs647/
|
||||
|
||||
TODO:
|
||||
|
||||
- DONE reread the radiohead mesh implementation - hop to hop acknoledgement seems VERY expensive but otherwise it seems like DSR
|
||||
- DONE read about mesh routing solutions (DSR and AODV)
|
||||
- DONE read about general mesh flooding solutions (naive, MPR, geo assisted)
|
||||
- DONE reread the disaster radio protocol docs - seems based on Babel (which is AODVish)
|
||||
- possibly dash7? https://www.slideshare.net/MaartenWeyn1/dash7-alliance-protocol-technical-presentation https://github.com/MOSAIC-LoPoW/dash7-ap-open-source-stack - does the opensource stack implement multihop routing? flooding? their discussion mailing list looks dead-dead
|
||||
- update duty cycle spreadsheet for our typical usecase
|
||||
- generalize naive flooding on top of radiohead or disaster.radio? (and fix radiohead to use my new driver)
|
||||
|
||||
a description of DSR: https://tools.ietf.org/html/rfc4728 good slides here: https://www.slideshare.net/ashrafmath/dynamic-source-routing
|
||||
good description of batman protocol: https://www.open-mesh.org/projects/open-mesh/wiki/BATMANConcept
|
||||
|
||||
interesting paper on lora mesh: https://portal.research.lu.se/portal/files/45735775/paper.pdf
|
||||
It seems like DSR might be the algorithm used by RadioheadMesh. DSR is described in https://tools.ietf.org/html/rfc4728
|
||||
https://en.wikipedia.org/wiki/Dynamic_Source_Routing
|
||||
|
||||
broadcast solution:
|
||||
Use naive flooding at first (FIXME - do some math for a 20 node, 3 hop mesh. A single flood will require a max of 20 messages sent)
|
||||
Then move to MPR later (http://www.olsr.org/docs/report_html/node28.html). Use altitude and location as heursitics in selecting the MPR set
|
||||
|
||||
compare to db sync algorithm?
|
||||
|
||||
what about never flooding gps broadcasts. instead only have them go one hop in the common case, but if any node X is looking at the position of Y on their gui, then send a unicast to Y asking for position update. Y replies.
|
||||
|
||||
If Y were to die, at least the neighbor nodes of Y would have their last known position of Y.
|
||||
|
||||
## approach 1
|
||||
|
||||
- send all broadcasts with a TTL
|
||||
- periodically(?) do a survey to find the max TTL that is needed to fully cover the current network.
|
||||
- to do a study first send a broadcast (maybe our current initial user announcement?) with TTL set to one (so therefore no one will rebroadcast our request)
|
||||
- survey replies are sent unicast back to us (and intervening nodes will need to keep the route table that they have built up based on past packets)
|
||||
- count the number of replies to this TTL 1 attempt. That is the number of nodes we can reach without any rebroadcasts
|
||||
- repeat the study with a TTL of 2 and then 3. stop once the # of replies stops going up.
|
||||
- it is important for any node to do listen before talk to prevent stomping on other rebroadcasters...
|
||||
- For these little networks I bet a max TTL would never be higher than 3?
|
||||
|
||||
## approach 2
|
||||
|
||||
- send a TTL1 broadcast, the replies let us build a list of the nodes (stored as a bitvector?) that we can see (and their rssis)
|
||||
- we then broadcast out that bitvector (also TTL1) asking "can any of ya'll (even indirectly) see anyone else?"
|
||||
- if a node can see someone I missed (and they are the best person to see that node), they reply (unidirectionally) with the missing nodes and their rssis (other nodes might sniff (and update their db) based on this reply but they don't have to)
|
||||
- given that the max number of nodes in this mesh will be like 20 (for normal cases), I bet globally updating this db of "nodenums and who has the best rssi for packets from that node" would be useful
|
||||
- once the global DB is shared, when a node wants to broadcast, it just sends out its broadcast . the first level receivers then make a decision "am I the best to rebroadcast to someone who likely missed this packet?" if so, rebroadcast
|
||||
|
||||
## approach 3
|
||||
|
||||
- when a node X wants to know other nodes positions, it broadcasts its position with want_replies=true. Then each of the nodes that received that request broadcast their replies (possibly by using special timeslots?)
|
||||
- all nodes constantly update their local db based on replies they witnessed.
|
||||
- after 10s (or whatever) if node Y notices that it didn't hear a reply from node Z (that Y has heard from recently ) to that initial request, that means Z never heard the request from X. Node Y will reply to X on Z's behalf.
|
||||
- could this work for more than one hop? Is more than one hop needed? Could it work for sending messages (i.e. for a msg sent to Z with want-reply set).
|
||||
|
||||
## approach 4
|
||||
|
||||
look into the literature for this idea specifically.
|
||||
|
||||
- don't view it as a mesh protocol as much as a "distributed db unification problem". When nodes talk to nearby nodes they work together
|
||||
to update their nodedbs. Each nodedb would have a last change date and any new changes that only one node has would get passed to the
|
||||
other node. This would nicely allow distant nodes to propogate their position to all other nodes (eventually).
|
||||
- handle group messages the same way, there would be a table of messages and time of creation.
|
||||
- when a node has a new position or message to send out, it does a broadcast. All the adjacent nodes update their db instantly (this handles 90% of messages I'll bet).
|
||||
- Occasionally a node might broadcast saying "anyone have anything newer than time X?" If someone does, they send the diffs since that date.
|
||||
- essentially everything in this variant becomes broadcasts of "request db updates for >time X - for _all_ or for a particular nodenum" and nodes sending (either due to request or because they changed state) "here's a set of db updates". Every node is constantly trying to
|
||||
build the most recent version of reality, and if some nodes are too far, then nodes closer in will eventually forward their changes to the distributed db.
|
||||
- construct non ambigious rules for who broadcasts to request db updates. ideally the algorithm should nicely realize node X can see most other nodes, so they should just listen to all those nodes and minimize the # of broadcasts. the distributed picture of nodes rssi could be useful here?
|
||||
- possibly view the BLE protocol to the radio the same way - just a process of reconverging the node/msgdb database.
|
||||
|
||||
# Old notes
|
||||
|
||||
FIXME, merge into the above:
|
||||
|
||||
|
||||
good description of batman protocol: https://www.open-mesh.org/projects/open-mesh/wiki/BATMANConcept
|
||||
|
||||
interesting paper on lora mesh: https://portal.research.lu.se/portal/files/45735775/paper.pdf
|
||||
It seems like DSR might be the algorithm used by RadioheadMesh. DSR is described in https://tools.ietf.org/html/rfc4728
|
||||
https://en.wikipedia.org/wiki/Dynamic_Source_Routing
|
||||
|
||||
broadcast solution:
|
||||
Use naive flooding at first (FIXME - do some math for a 20 node, 3 hop mesh. A single flood will require a max of 20 messages sent)
|
||||
Then move to MPR later (http://www.olsr.org/docs/report_html/node28.html). Use altitude and location as heursitics in selecting the MPR set
|
||||
|
||||
compare to db sync algorithm?
|
||||
|
||||
what about never flooding gps broadcasts. instead only have them go one hop in the common case, but if any node X is looking at the position of Y on their gui, then send a unicast to Y asking for position update. Y replies.
|
||||
|
||||
If Y were to die, at least the neighbor nodes of Y would have their last known position of Y.
|
||||
@@ -1,6 +1,10 @@
|
||||
This is a mini design doc for various core behaviors...
|
||||
# Power Management State Machine
|
||||
|
||||
# Rules for sleep
|
||||
i.e. sleep behavior
|
||||
|
||||
## Power measurements
|
||||
|
||||
Since one of the main goals of this project is long battery life, it is important to consider that in our software/protocol design. Based on initial measurements it seems that the current code should run about three days between charging, and with a bit more software work (see the [TODO list](TODO.md)) a battery life of eight days should be quite doable. Our current power measurements/model is in [this spreadsheet](https://docs.google.com/spreadsheets/d/1ft1bS3iXqFKU8SApU8ZLTq9r7QQEGESYnVgdtvdT67k/edit?usp=sharing).
|
||||
|
||||
## States
|
||||
|
||||
@@ -53,7 +57,8 @@ off during light sleep, but there is a TODO item to fix this.
|
||||
* While in ON: If it has been more than screen_on_secs since a press, lower to DARK
|
||||
* While in DARK: If time since last contact by our phone exceeds phone_timeout_secs (15 minutes), we transition down into NB mode
|
||||
* While in DARK or NB: If nothing above is forcing us to stay in a higher mode (wait_bluetooth_secs, min_wake_secs) we will lower down to LS state
|
||||
* While in LS: If either phone_sds_timeout_secs (default 2 hr) or mesh_sds_timeout_secs (default 2 hr) are exceeded we will lower into SDS mode for sds_secs (default 1 yr) (or a button press).
|
||||
* While in LS: If either phone_sds_timeout_secs (default 2 hr) or mesh_sds_timeout_secs (default 2 hr) are exceeded we will lower into SDS mode for sds_secs (default 1 yr) (or a button press). (Note: phone_sds_timeout_secs is currently disabled for now, because most users
|
||||
are using without a phone)
|
||||
* Any time we enter LS mode: We stay in that until an interrupt, button press or other state transition. Every ls_secs (default 1 hr) and let the arduino loop() run one iteration (FIXME, not sure if we need this at all), and then immediately reenter lightsleep mode on the CPU.
|
||||
|
||||
TODO: Eventually these scheduled intervals should be synchronized to the GPS clock, so that we can consider leaving the lora receiver off to save even more power.
|
||||
@@ -78,49 +83,3 @@ General ideas to hit the power draws our spreadsheet predicts. Do the easy ones
|
||||
* see section 7.3 of https://cdn.sparkfun.com/assets/learn_tutorials/8/0/4/RFM95_96_97_98W.pdf and have hope radio wake only when a valid packet is received. Possibly even wake the ESP32 from deep sleep via GPIO.
|
||||
* never enter deep sleep while connected to USB power (but still go to other low power modes)
|
||||
* when main cpu is idle (in loop), turn cpu clock rate down and/or activate special sleep modes. We want almost everything shutdown until it gets an interrupt.
|
||||
|
||||
# Mesh broadcast algoritm
|
||||
|
||||
FIXME - instead look for standard solutions. this approach seems really suboptimal, because too many nodes will try to rebroast. If
|
||||
all else fails could always use the stock radiohead solution - though super inefficent.
|
||||
|
||||
## approach 1
|
||||
|
||||
* send all broadcasts with a TTL
|
||||
* periodically(?) do a survey to find the max TTL that is needed to fully cover the current network.
|
||||
* to do a study first send a broadcast (maybe our current initial user announcement?) with TTL set to one (so therefore no one will rebroadcast our request)
|
||||
* survey replies are sent unicast back to us (and intervening nodes will need to keep the route table that they have built up based on past packets)
|
||||
* count the number of replies to this TTL 1 attempt. That is the number of nodes we can reach without any rebroadcasts
|
||||
* repeat the study with a TTL of 2 and then 3. stop once the # of replies stops going up.
|
||||
* it is important for any node to do listen before talk to prevent stomping on other rebroadcasters...
|
||||
* For these little networks I bet a max TTL would never be higher than 3?
|
||||
|
||||
## approach 2
|
||||
|
||||
* send a TTL1 broadcast, the replies let us build a list of the nodes (stored as a bitvector?) that we can see (and their rssis)
|
||||
* we then broadcast out that bitvector (also TTL1) asking "can any of ya'll (even indirectly) see anyone else?"
|
||||
* if a node can see someone I missed (and they are the best person to see that node), they reply (unidirectionally) with the missing nodes and their rssis (other nodes might sniff (and update their db) based on this reply but they don't have to)
|
||||
* given that the max number of nodes in this mesh will be like 20 (for normal cases), I bet globally updating this db of "nodenums and who has the best rssi for packets from that node" would be useful
|
||||
* once the global DB is shared, when a node wants to broadcast, it just sends out its broadcast . the first level receivers then make a decision "am I the best to rebroadcast to someone who likely missed this packet?" if so, rebroadcast
|
||||
|
||||
## approach 3
|
||||
|
||||
* when a node X wants to know other nodes positions, it broadcasts its position with want_replies=true. Then each of the nodes that received that request broadcast their replies (possibly by using special timeslots?)
|
||||
* all nodes constantly update their local db based on replies they witnessed.
|
||||
* after 10s (or whatever) if node Y notices that it didn't hear a reply from node Z (that Y has heard from recently ) to that initial request, that means Z never heard the request from X. Node Y will reply to X on Z's behalf.
|
||||
* could this work for more than one hop? Is more than one hop needed? Could it work for sending messages (i.e. for a msg sent to Z with want-reply set).
|
||||
|
||||
## approach 4
|
||||
|
||||
look into the literature for this idea specifically.
|
||||
|
||||
* don't view it as a mesh protocol as much as a "distributed db unification problem". When nodes talk to nearby nodes they work together
|
||||
to update their nodedbs. Each nodedb would have a last change date and any new changes that only one node has would get passed to the
|
||||
other node. This would nicely allow distant nodes to propogate their position to all other nodes (eventually).
|
||||
* handle group messages the same way, there would be a table of messages and time of creation.
|
||||
* when a node has a new position or message to send out, it does a broadcast. All the adjacent nodes update their db instantly (this handles 90% of messages I'll bet).
|
||||
* Occasionally a node might broadcast saying "anyone have anything newer than time X?" If someone does, they send the diffs since that date.
|
||||
* essentially everything in this variant becomes broadcasts of "request db updates for >time X - for _all_ or for a particular nodenum" and nodes sending (either due to request or because they changed state) "here's a set of db updates". Every node is constantly trying to
|
||||
build the most recent version of reality, and if some nodes are too far, then nodes closer in will eventually forward their changes to the distributed db.
|
||||
* construct non ambigious rules for who broadcasts to request db updates. ideally the algorithm should nicely realize node X can see most other nodes, so they should just listen to all those nodes and minimize the # of broadcasts. the distributed picture of nodes rssi could be useful here?
|
||||
* possibly view the BLE protocol to the radio the same way - just a process of reconverging the node/msgdb database.
|
||||
9
docs/software/sw-design.md
Normal file
9
docs/software/sw-design.md
Normal file
@@ -0,0 +1,9 @@
|
||||
This is a mini design doc for developing the meshtastic software.
|
||||
|
||||
* [Build instructions](build-instructions.md)
|
||||
* [TODO](TODO.md) - read this if you are looking for things to do (or curious about currently missing features)
|
||||
* Our [project board](https://github.com/orgs/meshtastic/projects/1) - shows what things we are currently working on and remaining work items for the current release.
|
||||
* [Power Management](power.md)
|
||||
* [Mesh algorithm](mesh-alg.md)
|
||||
* [Bluetooth API](bluetooth-api.md) and porting guide for new clients (iOS, python, etc...)
|
||||
* TODO: how to port the device code to a new device.
|
||||
BIN
images/system-info.bin
Normal file
BIN
images/system-info.bin
Normal file
Binary file not shown.
@@ -117,21 +117,7 @@ void bluetoothRebootCheck()
|
||||
}
|
||||
|
||||
/*
|
||||
SoftwareUpdateService UUID cb0b9a0b-a84c-4c0d-bdbb-442e3144ee30
|
||||
|
||||
Characteristics
|
||||
|
||||
UUID properties description
|
||||
e74dd9c0-a301-4a6f-95a1-f0e1dbea8e1e write|read total image size, 32 bit, write this first, then read read back to see if it was acceptable (0 mean not accepted)
|
||||
e272ebac-d463-4b98-bc84-5cc1a39ee517 write data, variable sized, recommended 512 bytes, write one for each block of file
|
||||
4826129c-c22a-43a3-b066-ce8f0d5bacc6 write crc32, write last - writing this will complete the OTA operation, now you can read result
|
||||
5e134862-7411-4424-ac4a-210937432c77 read|notify result code, readable but will notify when the OTA operation completes
|
||||
|
||||
We also implement the following standard GATT entries because SW update probably needs them:
|
||||
|
||||
ESP_GATT_UUID_SW_VERSION_STR/0x2a28
|
||||
ESP_GATT_UUID_MANU_NAME/0x2a29
|
||||
ESP_GATT_UUID_HW_VERSION_STR/0x2a27
|
||||
See bluetooth-api.md
|
||||
|
||||
*/
|
||||
BLEService *createUpdateService(BLEServer *server, std::string hwVendor, std::string swVersion, std::string hwVersion)
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <Arduino.h>
|
||||
#include <Update.h>
|
||||
#include "configuration.h"
|
||||
#include "screen.h"
|
||||
|
||||
SimpleAllocator btPool;
|
||||
|
||||
@@ -173,7 +172,7 @@ uint32_t getValue32(BLECharacteristic *c, uint32_t defaultValue)
|
||||
|
||||
class MySecurity : public BLESecurityCallbacks
|
||||
{
|
||||
|
||||
protected:
|
||||
bool onConfirmPIN(uint32_t pin)
|
||||
{
|
||||
Serial.printf("onConfirmPIN %u\n", pin);
|
||||
@@ -189,7 +188,7 @@ class MySecurity : public BLESecurityCallbacks
|
||||
void onPassKeyNotify(uint32_t pass_key)
|
||||
{
|
||||
Serial.printf("onPassKeyNotify %u\n", pass_key);
|
||||
screen_start_bluetooth(pass_key);
|
||||
startCb(pass_key);
|
||||
}
|
||||
|
||||
bool onSecurityRequest()
|
||||
@@ -211,9 +210,13 @@ class MySecurity : public BLESecurityCallbacks
|
||||
Serial.printf("onAuthenticationComplete -> fail %d\n", cmpl.fail_reason);
|
||||
}
|
||||
|
||||
// Remove our custom screen
|
||||
screen.setFrames();
|
||||
// Remove our custom PIN request screen.
|
||||
stopCb();
|
||||
}
|
||||
|
||||
public:
|
||||
StartBluetoothPinScreenCallback startCb;
|
||||
StopBluetoothPinScreenCallback stopCb;
|
||||
};
|
||||
|
||||
BLEServer *pServer;
|
||||
@@ -255,7 +258,10 @@ void deinitBLE()
|
||||
btPool.reset();
|
||||
}
|
||||
|
||||
BLEServer *initBLE(std::string deviceName, std::string hwVendor, std::string swVersion, std::string hwVersion)
|
||||
BLEServer *initBLE(
|
||||
StartBluetoothPinScreenCallback startBtPinScreen,
|
||||
StopBluetoothPinScreenCallback stopBtPinScreen,
|
||||
std::string deviceName, std::string hwVendor, std::string swVersion, std::string hwVersion)
|
||||
{
|
||||
BLEDevice::init(deviceName);
|
||||
BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
|
||||
@@ -264,6 +270,8 @@ BLEServer *initBLE(std::string deviceName, std::string hwVendor, std::string swV
|
||||
* Required in authentication process to provide displaying and/or input passkey or yes/no butttons confirmation
|
||||
*/
|
||||
static MySecurity mySecurity;
|
||||
mySecurity.startCb = startBtPinScreen;
|
||||
mySecurity.stopCb = stopBtPinScreen;
|
||||
BLEDevice::setSecurityCallbacks(&mySecurity);
|
||||
|
||||
// Create the BLE Server
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEServer.h>
|
||||
@@ -17,8 +19,14 @@ void dumpCharacteristic(BLECharacteristic *c);
|
||||
/** converting endianness pull out a 32 bit value */
|
||||
uint32_t getValue32(BLECharacteristic *c, uint32_t defaultValue);
|
||||
|
||||
// TODO(girts): create a class for the bluetooth utils helpers?
|
||||
using StartBluetoothPinScreenCallback = std::function<void(uint32_t pass_key)>;
|
||||
using StopBluetoothPinScreenCallback = std::function<void(void)>;
|
||||
|
||||
void loopBLE();
|
||||
BLEServer *initBLE(std::string devName, std::string hwVendor, std::string swVersion, std::string hwVersion = "");
|
||||
BLEServer *initBLE(
|
||||
StartBluetoothPinScreenCallback startBtPinScreen, StopBluetoothPinScreenCallback stopBtPinScreen,
|
||||
std::string devName, std::string hwVendor, std::string swVersion, std::string hwVersion = "");
|
||||
void deinitBLE();
|
||||
|
||||
/// Add a characteristic that we will delete when we restart
|
||||
|
||||
@@ -9,11 +9,20 @@
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = tbeam
|
||||
|
||||
[env:esp32]
|
||||
[common]
|
||||
; common is not currently used
|
||||
|
||||
; REQUIRED environment variables - if not set the specified default will be sued
|
||||
; The following environment variables must be set in the shell if you'd like to override them.
|
||||
; They are used in this ini file as systenv.VARNAME, so in your shell do export "VARNAME=fish"
|
||||
; HW_VERSION (default US)
|
||||
; APP_VERSION (default emptystring)
|
||||
; HW_VERSION (default emptystring)
|
||||
|
||||
[env]
|
||||
platform = espressif32
|
||||
board = ttgo-t-beam
|
||||
; board = heltec_wifi_lora_32_V2
|
||||
framework = arduino
|
||||
|
||||
; customize the partition table
|
||||
@@ -22,23 +31,26 @@ board_build.partitions = partition-table.csv
|
||||
|
||||
; 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
|
||||
build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Os -Wl,-Map,.pio/build/esp32/output.map -DAXP_DEBUG_PORT=Serial
|
||||
build_flags = -Wno-missing-field-initializers -Isrc -Isrc/rf95 -Os -Wl,-Map,.pio/build/output.map
|
||||
-DAXP_DEBUG_PORT=Serial
|
||||
-DHW_VERSION_${sysenv.COUNTRY}
|
||||
-DAPP_VERSION=${sysenv.APP_VERSION}
|
||||
-DHW_VERSION=${sysenv.HW_VERSION}
|
||||
|
||||
; 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
|
||||
; -DBOARD_HAS_PSRAM
|
||||
; -mfix-esp32-psram-cache-issue
|
||||
|
||||
|
||||
; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
|
||||
upload_speed = 921600
|
||||
upload_port = /dev/ttyUSB0
|
||||
; leave this commented out to avoid breaking Windows
|
||||
;upload_port = /dev/ttyUSB0
|
||||
;monitor_port = /dev/ttyUSB0
|
||||
|
||||
; the default is esptool
|
||||
; upload_protocol = esp-prog
|
||||
|
||||
monitor_port = /dev/ttyUSB0
|
||||
monitor_speed = 115200
|
||||
|
||||
# debug_tool = esp-prog
|
||||
@@ -53,24 +65,73 @@ debug_tool = jlink
|
||||
;debug_init_cmds =
|
||||
; monitor adapter_khz 10000
|
||||
|
||||
debug_init_break = tbreak setup
|
||||
|
||||
; Note: some libraries are specified by #ID where there are conflicting library
|
||||
; names.
|
||||
lib_deps =
|
||||
https://github.com/meshtastic/RadioHead.git
|
||||
1655 ; TinyGPSPlus
|
||||
https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
|
||||
AXP202X_Library
|
||||
SPI
|
||||
1260 ; OneButton
|
||||
; 1260 ; OneButton - not used yet
|
||||
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/SparkFun_Ublox_Arduino_Library.git
|
||||
|
||||
;[env:tbeam]
|
||||
; Common settings for ESP targes, mixin with extends = esp32_base
|
||||
[esp32_base]
|
||||
src_filter =
|
||||
${env.src_filter} -<bare/>
|
||||
upload_speed = 921600
|
||||
debug_init_break = tbreak setup
|
||||
build_flags =
|
||||
${env.build_flags} -Wall -Wextra
|
||||
|
||||
; The 1.0 release of the TBEAM board
|
||||
[env:tbeam]
|
||||
extends = esp32_base
|
||||
board = ttgo-t-beam
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
AXP202X_Library
|
||||
build_flags =
|
||||
${esp32_base.build_flags} -D TBEAM_V10
|
||||
|
||||
; The original TBEAM board without the AXP power chip and a few other changes
|
||||
; Note: I've heard reports this didn't work. Disabled until someone with a 0.7 can test and debug.
|
||||
;[env:tbeam0.7]
|
||||
;extends = esp32_base
|
||||
;board = ttgo-t-beam
|
||||
;build_flags =
|
||||
; ${esp32_base.build_flags} -D TBEAM_V07
|
||||
|
||||
;[env:heltec]
|
||||
[env:heltec]
|
||||
;build_type = debug ; to make it possible to step through our jtag debugger
|
||||
;board = heltec_wifi_lora_32_V2
|
||||
extends = esp32_base
|
||||
board = heltec_wifi_lora_32_V2
|
||||
|
||||
[env:ttgo-lora32-v1]
|
||||
extends = esp32_base
|
||||
board = ttgo-lora32-v1
|
||||
build_flags =
|
||||
${esp32_base.build_flags} -D TTGO_LORA_V1
|
||||
|
||||
; note: the platformio definition for lora32-v2 seems stale, it is missing a pins_arduino.h file, therefore I don't think it works
|
||||
[env:ttgo-lora32-v2]
|
||||
extends = esp32_base
|
||||
board = ttgo-lora32-v1
|
||||
build_flags =
|
||||
${esp32_base.build_flags} -D TTGO_LORA_V2
|
||||
|
||||
|
||||
; This is a temporary build target to test turning off particular hardare bits in the build (to improve modularity)
|
||||
[env:bare]
|
||||
platform = nordicnrf52
|
||||
board = nrf52840_dk_adafruit ; nicer than nrf52840_dk - more full gpio mappings
|
||||
framework = arduino
|
||||
debug_tool = jlink
|
||||
build_flags =
|
||||
${env.build_flags} -D BARE_BOARD -Wno-unused-variable -Isrc/bare
|
||||
src_filter =
|
||||
${env.src_filter} -<esp32/>
|
||||
lib_ignore =
|
||||
BluetoothOTA
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
monitor_port = /dev/ttyACM1
|
||||
2
proto
2
proto
Submodule proto updated: f309ee8f9e...e06645d8db
1
release/.gitignore
vendored
1
release/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
*.elf
|
||||
*.bin
|
||||
*.map
|
||||
*.zip
|
||||
1
release/latest/.gitignore
vendored
Normal file
1
release/latest/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
curfirmwareversion.xml
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- This file is kept in source control because it reflects the last stable
|
||||
release. It is used by the android app for forcing software updates. Do not edit.
|
||||
Generated by bin/buildall.sh -->
|
||||
|
||||
<resources>
|
||||
<string name="cur_firmware_version">0.0.9</string>
|
||||
</resources>
|
||||
193
src/GPS.cpp
193
src/GPS.cpp
@@ -1,30 +1,86 @@
|
||||
|
||||
#include "GPS.h"
|
||||
#include "time.h"
|
||||
#include <sys/time.h>
|
||||
#include "configuration.h"
|
||||
#include "time.h"
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
// stuff that really should be in in the instance instead...
|
||||
#ifdef GPS_RX_PIN
|
||||
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
|
||||
uint32_t timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
|
||||
uint64_t zeroOffsetSecs; // GPS based time in secs since 1970 - only updated once on initial lock
|
||||
#else
|
||||
// Assume NRF52
|
||||
// Uart _serial_gps(GPS_SERIAL_NUM);
|
||||
#endif
|
||||
|
||||
RTC_DATA_ATTR bool timeSetFromGPS; // We only reset our time once per _boot_ after that point just run from the internal clock (even across sleeps)
|
||||
bool timeSetFromGPS; // We try to set our time from GPS each time we wake from sleep
|
||||
|
||||
GPS gps;
|
||||
bool hasValidLocation; // default to false, until we complete our first read
|
||||
bool wantNewLocation = true;
|
||||
|
||||
GPS::GPS() : PeriodicTask()
|
||||
{
|
||||
}
|
||||
// stuff that really should be in in the instance instead...
|
||||
static uint32_t
|
||||
timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
|
||||
static uint64_t zeroOffsetSecs; // GPS based time in secs since 1970 - only updated once on initial lock
|
||||
|
||||
static bool wantNewLocation = true;
|
||||
|
||||
GPS::GPS() : PeriodicTask() {}
|
||||
|
||||
void GPS::setup()
|
||||
{
|
||||
readFromRTC();
|
||||
readFromRTC(); // read the main CPU RTC at first
|
||||
|
||||
#ifdef GPS_RX_PIN
|
||||
_serial_gps.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
||||
// _serial_gps.setRxBufferSize(1024); // the default is 256
|
||||
// ublox.enableDebugging(Serial);
|
||||
|
||||
// note: the lib's implementation has the wrong docs for what the return val is
|
||||
// it is not a bool, it returns zero for success
|
||||
isConnected = ublox.begin(_serial_gps);
|
||||
|
||||
// try a second time, the ublox lib serial parsing is buggy?
|
||||
if (!isConnected)
|
||||
isConnected = ublox.begin(_serial_gps);
|
||||
|
||||
if (isConnected) {
|
||||
DEBUG_MSG("Connected to GPS successfully, TXpin=%d\n", GPS_TX_PIN);
|
||||
|
||||
bool factoryReset = false;
|
||||
bool ok;
|
||||
if (factoryReset) {
|
||||
// It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have
|
||||
// GPS_TX connected)
|
||||
ublox.factoryReset();
|
||||
delay(2000);
|
||||
isConnected = ublox.begin(_serial_gps);
|
||||
DEBUG_MSG("Factory reset success=%d\n", isConnected);
|
||||
if (isConnected) {
|
||||
ublox.assumeAutoPVT(true, true); // Just parse NEMA for now
|
||||
}
|
||||
} else {
|
||||
ok = ublox.setUART1Output(COM_TYPE_UBX, 500); // Use native API
|
||||
assert(ok);
|
||||
ok = ublox.setNavigationFrequency(1, 500); // Produce 4x/sec to keep the amount of time we stall in getPVT low
|
||||
assert(ok);
|
||||
// ok = ublox.setAutoPVT(false); // Not implemented on NEO-6M
|
||||
// assert(ok);
|
||||
// ok = ublox.setDynamicModel(DYN_MODEL_BIKE); // probably PEDESTRIAN but just in case assume bike speeds
|
||||
// assert(ok);
|
||||
ok = ublox.powerSaveMode(); // use power save mode
|
||||
assert(ok);
|
||||
}
|
||||
ok = ublox.saveConfiguration(2000);
|
||||
assert(ok);
|
||||
} else {
|
||||
// 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.
|
||||
DEBUG_MSG("ERROR: No bidirectional GPS found, hoping that it still might work\n");
|
||||
|
||||
// tell lib, we are expecting the module to send PVT messages by itself to our Rx pin
|
||||
// you can set second parameter to "false" if you want to control the parsing and eviction of the data (need to call
|
||||
// checkUblox cyclically)
|
||||
ublox.assumeAutoPVT(true, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -32,8 +88,7 @@ void GPS::readFromRTC()
|
||||
{
|
||||
struct timeval tv; /* btw settimeofday() is helpfull here too*/
|
||||
|
||||
if (!gettimeofday(&tv, NULL))
|
||||
{
|
||||
if (!gettimeofday(&tv, NULL)) {
|
||||
uint32_t now = millis();
|
||||
|
||||
DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS);
|
||||
@@ -45,11 +100,14 @@ void GPS::readFromRTC()
|
||||
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
|
||||
void GPS::perhapsSetRTC(const struct timeval *tv)
|
||||
{
|
||||
if (!timeSetFromGPS)
|
||||
{
|
||||
if (!timeSetFromGPS) {
|
||||
timeSetFromGPS = true;
|
||||
DEBUG_MSG("Setting RTC %ld secs\n", tv->tv_sec);
|
||||
#ifndef NO_ESP32
|
||||
settimeofday(tv, NULL);
|
||||
#else
|
||||
assert(0);
|
||||
#endif
|
||||
readFromRTC();
|
||||
}
|
||||
}
|
||||
@@ -75,70 +133,85 @@ uint32_t GPS::getValidTime()
|
||||
/// Returns true if we think the board can enter deep or light sleep now (we might be trying to get a GPS lock)
|
||||
bool GPS::canSleep()
|
||||
{
|
||||
return !wantNewLocation;
|
||||
return true; // we leave GPS on during sleep now, so sleep is okay !wantNewLocation;
|
||||
}
|
||||
|
||||
/// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs
|
||||
void GPS::prepareSleep()
|
||||
{
|
||||
// discard all rx serial bytes so we don't try to parse them when we come back
|
||||
while (_serial_gps.available())
|
||||
{
|
||||
_serial_gps.read();
|
||||
}
|
||||
|
||||
// make the parser bail on whatever it was parsing
|
||||
encode('\n');
|
||||
if (isConnected)
|
||||
ublox.powerOff();
|
||||
}
|
||||
|
||||
void GPS::doTask()
|
||||
{
|
||||
#ifdef GPS_RX_PIN
|
||||
// Consume all characters that have arrived
|
||||
uint8_t fixtype = 3; // If we are only using the RX pin, assume we have a 3d fix
|
||||
|
||||
while (_serial_gps.available())
|
||||
{
|
||||
encode(_serial_gps.read());
|
||||
// DEBUG_MSG("Got GPS response\n");
|
||||
if (isConnected) {
|
||||
// Consume all characters that have arrived
|
||||
|
||||
// getPVT automatically calls checkUblox
|
||||
ublox.checkUblox(); // See if new data is available. Process bytes as they come in.
|
||||
|
||||
// If we don't have a fix (a quick check), don't try waiting for a solution)
|
||||
// Hmmm my fix type reading returns zeros for fix, which doesn't seem correct, because it is still sptting out positions
|
||||
// turn off for now
|
||||
// fixtype = ublox.getFixType();
|
||||
DEBUG_MSG("fix type %d\n", fixtype);
|
||||
}
|
||||
|
||||
if (!timeSetFromGPS && time.isValid() && date.isValid())
|
||||
{
|
||||
// DEBUG_MSG("sec %d\n", ublox.getSecond());
|
||||
// DEBUG_MSG("lat %d\n", ublox.getLatitude());
|
||||
|
||||
// any fix that has time
|
||||
if (!timeSetFromGPS && ublox.getT()) {
|
||||
struct timeval tv;
|
||||
|
||||
DEBUG_MSG("Got time from GPS\n");
|
||||
|
||||
/* Convert to unix time
|
||||
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
||||
*/
|
||||
/* Convert to unix time
|
||||
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970
|
||||
(midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
||||
*/
|
||||
struct tm t;
|
||||
t.tm_sec = time.second();
|
||||
t.tm_min = time.minute();
|
||||
t.tm_hour = time.hour();
|
||||
t.tm_mday = date.day();
|
||||
t.tm_mon = date.month() - 1;
|
||||
t.tm_year = date.year() - 1900;
|
||||
t.tm_sec = ublox.getSecond();
|
||||
t.tm_min = ublox.getMinute();
|
||||
t.tm_hour = ublox.getHour();
|
||||
t.tm_mday = ublox.getDay();
|
||||
t.tm_mon = ublox.getMonth() - 1;
|
||||
t.tm_year = ublox.getYear() - 1900;
|
||||
t.tm_isdst = false;
|
||||
time_t res = mktime(&t);
|
||||
tv.tv_sec = res;
|
||||
tv.tv_usec = 0; // time.centisecond() * (10 / 1000);
|
||||
|
||||
perhapsSetRTC(&tv);
|
||||
DEBUG_MSG("Got time from GPS month=%d, year=%d, unixtime=%ld\n", t.tm_mon, t.tm_year, tv.tv_sec);
|
||||
if (t.tm_year < 0 || t.tm_year >= 300)
|
||||
DEBUG_MSG("Ignoring invalid GPS time\n");
|
||||
else
|
||||
perhapsSetRTC(&tv);
|
||||
}
|
||||
|
||||
if ((fixtype >= 3 && fixtype <= 4) && ublox.getP()) // rd fixes only
|
||||
{
|
||||
// we only notify if position has changed
|
||||
latitude = ublox.getLatitude() * 1e-7;
|
||||
longitude = ublox.getLongitude() * 1e-7;
|
||||
altitude = ublox.getAltitude() / 1000; // in mm convert to meters
|
||||
DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d\n", latitude, longitude, altitude);
|
||||
|
||||
hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0
|
||||
if (hasValidLocation) {
|
||||
wantNewLocation = false;
|
||||
notifyObservers(NULL);
|
||||
// ublox.powerOff();
|
||||
}
|
||||
} else // we didn't get a location update, go back to sleep and hope the characters show up
|
||||
wantNewLocation = true;
|
||||
#endif
|
||||
|
||||
if (location.isValid() && location.isUpdated())
|
||||
{ // we only notify if position has changed
|
||||
// DEBUG_MSG("new gps pos\n");
|
||||
hasValidLocation = true;
|
||||
wantNewLocation = false;
|
||||
notifyObservers();
|
||||
}
|
||||
else // we didn't get a location update, go back to sleep and hope the characters show up
|
||||
wantNewLocation = true;
|
||||
|
||||
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 100ms until we have something over the serial
|
||||
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 100);
|
||||
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 1s until we have something over
|
||||
// the serial
|
||||
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 10 * 1000);
|
||||
}
|
||||
|
||||
void GPS::startLock()
|
||||
@@ -147,11 +220,3 @@ void GPS::startLock()
|
||||
wantNewLocation = true;
|
||||
setPeriod(1);
|
||||
}
|
||||
|
||||
String GPS::getTimeStr()
|
||||
{
|
||||
static char t[12]; // used to sprintf for Serial output
|
||||
|
||||
snprintf(t, sizeof(t), "%02d:%02d:%02d", time.hour(), time.minute(), time.second());
|
||||
return t;
|
||||
}
|
||||
|
||||
25
src/GPS.h
25
src/GPS.h
@@ -1,18 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <TinyGPS++.h>
|
||||
#include "PeriodicTask.h"
|
||||
#include "Observer.h"
|
||||
#include "PeriodicTask.h"
|
||||
#include "SparkFun_Ublox_Arduino_Library.h"
|
||||
#include "sys/time.h"
|
||||
|
||||
/**
|
||||
* A gps class that only reads from the GPS periodically (and FIXME - eventually keeps the gps powered down except when reading)
|
||||
*
|
||||
*
|
||||
* When new data is available it will notify observers.
|
||||
*/
|
||||
class GPS : public PeriodicTask, public Observable, public TinyGPSPlus
|
||||
class GPS : public PeriodicTask, public Observable<void *>
|
||||
{
|
||||
public:
|
||||
SFE_UBLOX_GPS ublox;
|
||||
|
||||
public:
|
||||
double latitude, longitude;
|
||||
uint32_t altitude;
|
||||
bool isConnected; // Do we have a GPS we are talking to
|
||||
|
||||
GPS();
|
||||
|
||||
/// Return time since 1970 in secs. Until we have a GPS lock we will be returning time based at zero
|
||||
@@ -21,8 +27,6 @@ public:
|
||||
/// Return time since 1970 in secs. If we don't have a GPS lock return zero
|
||||
uint32_t getValidTime();
|
||||
|
||||
String getTimeStr();
|
||||
|
||||
void setup();
|
||||
|
||||
virtual void loop();
|
||||
@@ -41,8 +45,13 @@ public:
|
||||
/// Restart our lock attempt - try to get and broadcast a GPS reading ASAP
|
||||
void startLock();
|
||||
|
||||
private:
|
||||
/// Returns ture if we have acquired GPS lock.
|
||||
bool hasLock() const { return hasValidLocation; }
|
||||
|
||||
private:
|
||||
void readFromRTC();
|
||||
|
||||
bool hasValidLocation = false; // default to false, until we complete our first read
|
||||
};
|
||||
|
||||
extern GPS gps;
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
#include "error.h"
|
||||
#include <SPI.h>
|
||||
#include "RH_RF95.h"
|
||||
#include <RHMesh.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
#include "MeshRadio.h"
|
||||
#include "configuration.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
|
||||
#define DEFAULT_CHANNEL_NUM 3 // we randomly pick one
|
||||
|
||||
/// 16 bytes of random PSK for our _public_ default channel that all devices power up on
|
||||
static const uint8_t defaultpsk[] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59, 0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf};
|
||||
#include "configuration.h"
|
||||
#include "sleep.h"
|
||||
#include <pb_decode.h>
|
||||
#include <pb_encode.h>
|
||||
|
||||
/**
|
||||
* ## LoRaWAN for North America
|
||||
@@ -21,112 +17,109 @@ LoRaWAN defines 64, 125 kHz channels from 902.3 to 914.9 MHz increments.
|
||||
|
||||
The maximum output power for North America is +30 dBM.
|
||||
|
||||
The band is from 902 to 928 MHz. It mentions channel number and its respective channel frequency. All the 13 channels are separated by 2.16 MHz with respect to the adjacent channels.
|
||||
Channel zero starts at 903.08 MHz center frequency.
|
||||
The band is from 902 to 928 MHz. It mentions channel number and its respective channel frequency. All the 13 channels are
|
||||
separated by 2.16 MHz with respect to the adjacent channels. Channel zero starts at 903.08 MHz center frequency.
|
||||
*/
|
||||
|
||||
/// Sometimes while debugging it is useful to set this false, to disable rf95 accesses
|
||||
bool useHardware = true;
|
||||
|
||||
MeshRadio::MeshRadio(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_rxDest)
|
||||
: rf95(_pool, _rxDest),
|
||||
manager(rf95)
|
||||
MeshRadio::MeshRadio() // , manager(radioIf)
|
||||
{
|
||||
myNodeInfo.num_channels = NUM_CHANNELS;
|
||||
myNodeInfo.num_channels = NUM_CHANNELS;
|
||||
|
||||
//radioConfig.modem_config = RadioConfig_ModemConfig_Bw125Cr45Sf128; // medium range and fast
|
||||
//channelSettings.modem_config = ChannelSettings_ModemConfig_Bw500Cr45Sf128; // short range and fast, but wide bandwidth so incompatible radios can talk together
|
||||
channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range
|
||||
|
||||
channelSettings.tx_power = 23;
|
||||
channelSettings.channel_num = DEFAULT_CHANNEL_NUM;
|
||||
memcpy(&channelSettings.psk, &defaultpsk, sizeof(channelSettings.psk));
|
||||
strcpy(channelSettings.name, "Default");
|
||||
// Can't print strings this early - serial not setup yet
|
||||
// DEBUG_MSG("Set meshradio defaults name=%s\n", channelSettings.name);
|
||||
// Can't print strings this early - serial not setup yet
|
||||
// DEBUG_MSG("Set meshradio defaults name=%s\n", channelSettings.name);
|
||||
}
|
||||
|
||||
bool MeshRadio::init()
|
||||
{
|
||||
if (!useHardware)
|
||||
return true;
|
||||
if (!useHardware)
|
||||
return true;
|
||||
|
||||
DEBUG_MSG("Starting meshradio init...\n");
|
||||
DEBUG_MSG("Starting meshradio init...\n");
|
||||
|
||||
configChangedObserver.observe(&service.configChanged);
|
||||
preflightSleepObserver.observe(&preflightSleep);
|
||||
notifyDeepSleepObserver.observe(¬ifyDeepSleep);
|
||||
|
||||
#ifdef RESET_GPIO
|
||||
pinMode(RESET_GPIO, OUTPUT); // Deassert reset
|
||||
digitalWrite(RESET_GPIO, HIGH);
|
||||
pinMode(RESET_GPIO, OUTPUT); // Deassert reset
|
||||
digitalWrite(RESET_GPIO, HIGH);
|
||||
|
||||
// pulse reset
|
||||
digitalWrite(RESET_GPIO, LOW);
|
||||
delay(10);
|
||||
digitalWrite(RESET_GPIO, HIGH);
|
||||
delay(10);
|
||||
// pulse reset
|
||||
digitalWrite(RESET_GPIO, LOW);
|
||||
delay(10);
|
||||
digitalWrite(RESET_GPIO, HIGH);
|
||||
delay(10);
|
||||
#endif
|
||||
|
||||
manager.setThisAddress(nodeDB.getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at constructor time.
|
||||
radioIf.setThisAddress(
|
||||
nodeDB.getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at constructor time.
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
DEBUG_MSG("LoRa radio init failed\n");
|
||||
DEBUG_MSG("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info\n");
|
||||
return false;
|
||||
}
|
||||
if (!radioIf.init()) {
|
||||
DEBUG_MSG("LoRa radio init failed\n");
|
||||
DEBUG_MSG("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// not needed - defaults on
|
||||
// rf95.setPayloadCRC(true);
|
||||
// not needed - defaults on
|
||||
// rf95.setPayloadCRC(true);
|
||||
|
||||
reloadConfig();
|
||||
reloadConfig();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MeshRadio::reloadConfig()
|
||||
/** hash a string into an integer
|
||||
*
|
||||
* djb2 by Dan Bernstein.
|
||||
* http://www.cse.yorku.ca/~oz/hash.html
|
||||
*/
|
||||
unsigned long hash(char *str)
|
||||
{
|
||||
rf95.setModeIdle(); // Need to be idle before doing init
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
|
||||
// Set up default configuration
|
||||
// No Sync Words in LORA mode.
|
||||
rf95.setModemConfig((RH_RF95::ModemConfigChoice)channelSettings.modem_config); // Radio default
|
||||
// setModemConfig(Bw125Cr48Sf4096); // slow and reliable?
|
||||
// rf95.setPreambleLength(8); // Default is 8
|
||||
while ((c = *str++) != 0)
|
||||
hash = ((hash << 5) + hash) + (unsigned char)c; /* hash * 33 + c */
|
||||
|
||||
assert(channelSettings.channel_num < NUM_CHANNELS); // If the phone tries to tell us to use an illegal channel then panic
|
||||
|
||||
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
|
||||
float center_freq = CH0 + CH_SPACING * channelSettings.channel_num;
|
||||
if (!rf95.setFrequency(center_freq))
|
||||
{
|
||||
DEBUG_MSG("setFrequency failed\n");
|
||||
assert(0); // fixme panic
|
||||
}
|
||||
|
||||
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
|
||||
|
||||
// The default transmitter power is 13dBm, using PA_BOOST.
|
||||
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
|
||||
// you can set transmitter powers from 5 to 23 dBm:
|
||||
// FIXME - can we do this? It seems to be in the Heltec board.
|
||||
rf95.setTxPower(channelSettings.tx_power, false);
|
||||
|
||||
DEBUG_MSG("Set radio: name=%s. config=%u, ch=%d, txpower=%d\n", channelSettings.name, channelSettings.modem_config, channelSettings.channel_num, channelSettings.tx_power);
|
||||
|
||||
// Done with init tell radio to start receiving
|
||||
rf95.setModeRx();
|
||||
return hash;
|
||||
}
|
||||
|
||||
ErrorCode MeshRadio::send(MeshPacket *p)
|
||||
int MeshRadio::reloadConfig(void *unused)
|
||||
{
|
||||
if (useHardware)
|
||||
return rf95.send(p);
|
||||
else
|
||||
{
|
||||
rf95.pool.release(p);
|
||||
return ERRNO_OK;
|
||||
}
|
||||
radioIf.setModeIdle(); // Need to be idle before doing init
|
||||
|
||||
// Set up default configuration
|
||||
// No Sync Words in LORA mode.
|
||||
radioIf.setModemConfig(
|
||||
(RH_RF95::ModemConfigChoice)channelSettings.modem_config); // Radio default
|
||||
// setModemConfig(Bw125Cr48Sf4096); // slow and reliable?
|
||||
// rf95.setPreambleLength(8); // Default is 8
|
||||
|
||||
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
|
||||
int channel_num = hash(channelSettings.name) % NUM_CHANNELS;
|
||||
float center_freq = CH0 + CH_SPACING * channel_num;
|
||||
if (!radioIf.setFrequency(center_freq)) {
|
||||
DEBUG_MSG("setFrequency failed\n");
|
||||
assert(0); // fixme panic
|
||||
}
|
||||
|
||||
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
|
||||
|
||||
// The default transmitter power is 13dBm, using PA_BOOST.
|
||||
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
|
||||
// you can set transmitter powers from 5 to 23 dBm:
|
||||
// FIXME - can we do this? It seems to be in the Heltec board.
|
||||
radioIf.setTxPower(channelSettings.tx_power, false);
|
||||
|
||||
DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, txpower=%d\n", channelSettings.name, channelSettings.modem_config,
|
||||
channel_num, channelSettings.tx_power);
|
||||
|
||||
// Done with init tell radio to start receiving
|
||||
radioIf.setModeRx();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshRadio::loop()
|
||||
{
|
||||
// Currently does nothing, since we do it all in ISRs now
|
||||
}
|
||||
|
||||
106
src/MeshRadio.h
106
src/MeshRadio.h
@@ -1,31 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "CustomRF95.h"
|
||||
#include <RHMesh.h>
|
||||
#include "MemoryPool.h"
|
||||
#include "mesh.pb.h"
|
||||
#include "PointerQueue.h"
|
||||
#include "MeshTypes.h"
|
||||
#include "Observer.h"
|
||||
#include "PointerQueue.h"
|
||||
#include "configuration.h"
|
||||
#include "mesh.pb.h"
|
||||
|
||||
// US channel settings
|
||||
#define CH0_US 903.08f // MHz
|
||||
#define CH_SPACING_US 2.16f // MHz
|
||||
#define CH0_US 903.08f // MHz
|
||||
#define CH_SPACING_US 2.16f // MHz
|
||||
#define NUM_CHANNELS_US 13
|
||||
|
||||
// EU channel settings
|
||||
#define CH0_EU 865.2f // MHz
|
||||
#define CH_SPACING_EU 0.3f // MHz
|
||||
#define NUM_CHANNELS_EU 10
|
||||
// EU433 channel settings
|
||||
#define CH0_EU433 433.175f // MHz
|
||||
#define CH_SPACING_EU433 0.2f // MHz
|
||||
#define NUM_CHANNELS_EU433 8
|
||||
|
||||
// EU865 channel settings
|
||||
#define CH0_EU865 865.2f // MHz
|
||||
#define CH_SPACING_EU865 0.3f // MHz
|
||||
#define NUM_CHANNELS_EU865 10
|
||||
|
||||
// CN channel settings
|
||||
#define CH0_CN 470.0f // MHz
|
||||
#define CH_SPACING_CN 2.0f // MHz FIXME, this is just a guess for 470-510
|
||||
#define CH0_CN 470.0f // MHz
|
||||
#define CH_SPACING_CN 2.0f // MHz FIXME, this is just a guess for 470-510
|
||||
#define NUM_CHANNELS_CN 20
|
||||
|
||||
// CN channel settings
|
||||
#define CH0_JP 920.0f // MHz
|
||||
#define CH_SPACING_JP 0.5f // MHz FIXME, this is just a guess for 920-925
|
||||
// JP channel settings
|
||||
#define CH0_JP 920.0f // MHz
|
||||
#define CH_SPACING_JP 0.5f // MHz FIXME, this is just a guess for 920-925
|
||||
#define NUM_CHANNELS_JP 10
|
||||
|
||||
// FIXME add defs for other regions and use them here
|
||||
@@ -33,10 +38,14 @@
|
||||
#define CH0 CH0_US
|
||||
#define CH_SPACING CH_SPACING_US
|
||||
#define NUM_CHANNELS NUM_CHANNELS_US
|
||||
#elif defined(HW_VERSION_EU)
|
||||
#define CH0 CH0_EU
|
||||
#define CH_SPACING CH_SPACING_EU
|
||||
#define NUM_CHANNELS NUM_CHANNELS_EU
|
||||
#elif defined(HW_VERSION_EU433)
|
||||
#define CH0 CH0_EU433
|
||||
#define CH_SPACING CH_SPACING_EU433
|
||||
#define NUM_CHANNELS NUM_CHANNELS_EU433
|
||||
#elif defined(HW_VERSION_EU865)
|
||||
#define CH0 CH0_EU865
|
||||
#define CH_SPACING CH_SPACING_EU865
|
||||
#define NUM_CHANNELS NUM_CHANNELS_EU865
|
||||
#elif defined(HW_VERSION_CN)
|
||||
#define CH0 CH0_CN
|
||||
#define CH_SPACING CH_SPACING_CN
|
||||
@@ -46,48 +55,53 @@
|
||||
#define CH_SPACING CH_SPACING_JP
|
||||
#define NUM_CHANNELS NUM_CHANNELS_JP
|
||||
#else
|
||||
#error "HW_VERSION not set"
|
||||
#endif
|
||||
|
||||
// HW version not set - assume US
|
||||
#define CH0 CH0_US
|
||||
#define CH_SPACING CH_SPACING_US
|
||||
#define NUM_CHANNELS NUM_CHANNELS_US
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A raw low level interface to our mesh. Only understands nodenums and bytes (not protobufs or node ids)
|
||||
*/
|
||||
class MeshRadio {
|
||||
public:
|
||||
CustomRF95 rf95; // the raw radio interface - for now I'm leaving public - because this class is shrinking to be almost nothing
|
||||
class MeshRadio
|
||||
{
|
||||
public:
|
||||
// Kinda ugly way of selecting different radio implementations, but soon this MeshRadio class will be going away
|
||||
// entirely. At that point we can make things pretty.
|
||||
#ifdef RF95_IRQ_GPIO
|
||||
CustomRF95
|
||||
radioIf; // the raw radio interface - for now I'm leaving public - because this class is shrinking to be almost nothing
|
||||
#else
|
||||
SimRadio radioIf;
|
||||
#endif
|
||||
|
||||
/** pool is the pool we will alloc our rx packets from
|
||||
* rxDest is where we will send any rx packets, it becomes receivers responsibility to return packet to the pool
|
||||
*/
|
||||
MeshRadio(MemoryPool<MeshPacket> &pool, PointerQueue<MeshPacket> &rxDest);
|
||||
MeshRadio();
|
||||
|
||||
bool init();
|
||||
|
||||
/// Send a packet (possibly by enquing in a private fifo). This routine will
|
||||
/// later free() the packet to pool. This routine is not allowed to stall because it is called from
|
||||
/// bluetooth comms code. If the txmit queue is empty it might return an error
|
||||
ErrorCode send(MeshPacket *p);
|
||||
private:
|
||||
CallbackObserver<MeshRadio, void *> configChangedObserver =
|
||||
CallbackObserver<MeshRadio, void *>(this, &MeshRadio::reloadConfig);
|
||||
|
||||
/// Do loop callback operations (we currently FIXME poll the receive mailbox here)
|
||||
/// for received packets it will call the rx handler
|
||||
void loop();
|
||||
CallbackObserver<MeshRadio, void *> preflightSleepObserver =
|
||||
CallbackObserver<MeshRadio, void *>(this, &MeshRadio::preflightSleepCb);
|
||||
|
||||
CallbackObserver<MeshRadio, void *> notifyDeepSleepObserver =
|
||||
CallbackObserver<MeshRadio, void *>(this, &MeshRadio::notifyDeepSleepDb);
|
||||
|
||||
/// The radioConfig object just changed, call this to force the hw to change to the new settings
|
||||
void reloadConfig();
|
||||
int reloadConfig(void *unused = NULL);
|
||||
|
||||
private:
|
||||
/// Return 0 if sleep is okay
|
||||
int preflightSleepCb(void *unused = NULL) { return radioIf.canSleep() ? 0 : 1; }
|
||||
|
||||
// RHDatagram manager;
|
||||
// RHReliableDatagram manager; // don't use mesh yet
|
||||
RHMesh manager;
|
||||
// MeshRXHandler rxHandler;
|
||||
|
||||
/// low level send, might block for mutiple seconds
|
||||
ErrorCode sendTo(NodeNum dest, const uint8_t *buf, size_t len);
|
||||
|
||||
/// enqueue a received packet in rxDest
|
||||
void handleReceive(MeshPacket *p);
|
||||
int notifyDeepSleepDb(void *unused = NULL)
|
||||
{
|
||||
radioIf.sleep();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,55 +1,64 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#include "mesh-pb-constants.h"
|
||||
#include "MeshService.h"
|
||||
#include "MeshBluetoothService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "GPS.h"
|
||||
#include "screen.h"
|
||||
//#include "MeshBluetoothService.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "Periodic.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "main.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
|
||||
/*
|
||||
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
|
||||
It is implemented with a FreeRTos queue (wrapped with a little RTQueue class) of pointers to MeshPacket protobufs (which were alloced with new).
|
||||
After a packet ptr is removed from the queue and processed it should be deleted. (eventually we should move sent packets into a 'sentToPhone' queue
|
||||
of packets we can delete just as soon as we are sure the phone has acked those packets - when the phone writes to FromNum)
|
||||
It is implemented with a FreeRTos queue (wrapped with a little RTQueue class) of pointers to MeshPacket protobufs (which were
|
||||
alloced with new). After a packet ptr is removed from the queue and processed it should be deleted. (eventually we should move
|
||||
sent packets into a 'sentToPhone' queue of packets we can delete just as soon as we are sure the phone has acked those packets -
|
||||
when the phone writes to FromNum)
|
||||
|
||||
mesh - an instance of Mesh class. Which manages the interface to the mesh radio library, reception of packets from other nodes, arbitrating to select
|
||||
a node number and keeping the current nodedb.
|
||||
mesh - an instance of Mesh class. Which manages the interface to the mesh radio library, reception of packets from other nodes,
|
||||
arbitrating to select a node number and keeping the current nodedb.
|
||||
|
||||
*/
|
||||
|
||||
/* Broadcast when a newly powered mesh node wants to find a node num it can use
|
||||
|
||||
The algoritm is as follows:
|
||||
* when a node starts up, it broadcasts their user and the normal flow is for all other nodes to reply with their User as well (so the new node can build its node db)
|
||||
* If a node ever receives a User (not just the first broadcast) message where the sender node number equals our node number, that indicates a collision has occurred and the following steps should happen:
|
||||
* when a node starts up, it broadcasts their user and the normal flow is for all other nodes to reply with their User as well (so
|
||||
the new node can build its node db)
|
||||
* If a node ever receives a User (not just the first broadcast) message where the sender node number equals our node number, that
|
||||
indicates a collision has occurred and the following steps should happen:
|
||||
|
||||
If the receiving node (that was already in the mesh)'s macaddr is LOWER than the new User who just tried to sign in: it gets to keep its nodenum. We send a broadcast message
|
||||
of OUR User (we use a broadcast so that the other node can receive our message, considering we have the same id - it also serves to let observers correct their nodedb) - this case is rare so it should be okay.
|
||||
If the receiving node (that was already in the mesh)'s macaddr is LOWER than the new User who just tried to sign in: it gets to
|
||||
keep its nodenum. We send a broadcast message of OUR User (we use a broadcast so that the other node can receive our message,
|
||||
considering we have the same id - it also serves to let observers correct their nodedb) - this case is rare so it should be okay.
|
||||
|
||||
If any node receives a User where the macaddr is GTE than their local macaddr, they have been vetoed and should pick a new random nodenum (filtering against whatever it knows about the nodedb) and
|
||||
rebroadcast their User.
|
||||
If any node receives a User where the macaddr is GTE than their local macaddr, they have been vetoed and should pick a new random
|
||||
nodenum (filtering against whatever it knows about the nodedb) and rebroadcast their User.
|
||||
|
||||
FIXME in the initial proof of concept we just skip the entire want/deny flow and just hand pick node numbers at first.
|
||||
*/
|
||||
|
||||
MeshService service;
|
||||
|
||||
// I think this is right, one packet for each of the three fifos + one packet being currently assembled for TX or RX
|
||||
#define MAX_PACKETS (MAX_RX_TOPHONE + MAX_RX_FROMRADIO + MAX_TX_QUEUE + 2) // max number of packets which can be in flight (either queued from reception or queued for sending)
|
||||
#include "Router.h"
|
||||
|
||||
#define MAX_RX_FROMRADIO 4 // max number of packets destined to our queue, we dispatch packets quickly so it doesn't need to be big
|
||||
#define NUM_PACKET_ID 255 // 0 is consider invalid
|
||||
|
||||
MeshService::MeshService()
|
||||
: packetPool(MAX_PACKETS),
|
||||
toPhoneQueue(MAX_RX_TOPHONE),
|
||||
fromRadioQueue(MAX_RX_FROMRADIO),
|
||||
fromNum(0),
|
||||
radio(packetPool, fromRadioQueue)
|
||||
/// Generate a unique packet id
|
||||
// FIXME, move this someplace better
|
||||
PacketId generatePacketId()
|
||||
{
|
||||
static uint32_t i;
|
||||
|
||||
i++;
|
||||
return (i % NUM_PACKET_ID) + 1; // return number between 1 and 255
|
||||
}
|
||||
|
||||
MeshService::MeshService() : toPhoneQueue(MAX_RX_TOPHONE)
|
||||
{
|
||||
// assert(MAX_RX_TOPHONE == 32); // FIXME, delete this, just checking my clever macro
|
||||
}
|
||||
@@ -58,21 +67,17 @@ void MeshService::init()
|
||||
{
|
||||
nodeDB.init();
|
||||
|
||||
if (!radio.init())
|
||||
DEBUG_MSG("radio init failed\n");
|
||||
|
||||
gps.addObserver(this);
|
||||
|
||||
// No need to call this here, our periodic task will fire quite soon
|
||||
// sendOwnerPeriod();
|
||||
gpsObserver.observe(&gps);
|
||||
packetReceivedObserver.observe(&router.notifyPacketReceived);
|
||||
}
|
||||
|
||||
void MeshService::sendOurOwner(NodeNum dest)
|
||||
void MeshService::sendOurOwner(NodeNum dest, bool wantReplies)
|
||||
{
|
||||
MeshPacket *p = allocForSending();
|
||||
p->to = dest;
|
||||
p->payload.which_variant = SubPacket_user_tag;
|
||||
User &u = p->payload.variant.user;
|
||||
p->payload.want_response = wantReplies;
|
||||
p->payload.has_user = true;
|
||||
User &u = p->payload.user;
|
||||
u = owner;
|
||||
DEBUG_MSG("sending owner %s/%s/%s\n", u.id, u.long_name, u.short_name);
|
||||
|
||||
@@ -80,118 +85,103 @@ void MeshService::sendOurOwner(NodeNum dest)
|
||||
}
|
||||
|
||||
/// handle a user packet that just arrived on the radio, return NULL if we should not process this packet at all
|
||||
MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
|
||||
const MeshPacket *MeshService::handleFromRadioUser(const MeshPacket *mp)
|
||||
{
|
||||
bool wasBroadcast = mp->to == NODENUM_BROADCAST;
|
||||
bool isCollision = mp->from == myNodeInfo.my_node_num;
|
||||
|
||||
// we win if we have a lower macaddr
|
||||
bool weWin = memcmp(&owner.macaddr, &mp->payload.variant.user.macaddr, sizeof(owner.macaddr)) < 0;
|
||||
bool weWin = memcmp(&owner.macaddr, &mp->payload.user.macaddr, sizeof(owner.macaddr)) < 0;
|
||||
|
||||
if (isCollision)
|
||||
{
|
||||
if (weWin)
|
||||
{
|
||||
if (isCollision) {
|
||||
if (weWin) {
|
||||
DEBUG_MSG("NOTE! Received a nodenum collision and we are vetoing\n");
|
||||
|
||||
packetPool.release(mp); // discard it
|
||||
mp = NULL;
|
||||
|
||||
sendOurOwner(); // send our owner as a _broadcast_ because that other guy is mistakenly using our nodenum
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// we lost, we need to try for a new nodenum!
|
||||
DEBUG_MSG("NOTE! Received a nodenum collision we lost, so picking a new nodenum\n");
|
||||
nodeDB.updateFrom(*mp); // update the DB early - before trying to repick (so we don't select the same node number again)
|
||||
nodeDB.updateFrom(
|
||||
*mp); // update the DB early - before trying to repick (so we don't select the same node number again)
|
||||
nodeDB.pickNewNodeNum();
|
||||
sendOurOwner(); // broadcast our new attempt at a node number
|
||||
}
|
||||
}
|
||||
else if (wasBroadcast)
|
||||
{
|
||||
// If we haven't yet abandoned the packet and it was a broadcast, reply (just to them) with our User record so they can build their DB
|
||||
} else if (wasBroadcast) {
|
||||
// If we haven't yet abandoned the packet and it was a broadcast, reply (just to them) with our User record so they can
|
||||
// build their DB
|
||||
|
||||
// Someone just sent us a User, reply with our Owner
|
||||
DEBUG_MSG("Received broadcast Owner from 0x%x, replying with our owner\n", mp->from);
|
||||
|
||||
sendOurOwner(mp->from);
|
||||
|
||||
String lcd = String("Joined: ") + mp->payload.variant.user.long_name + "\n";
|
||||
screen_print(lcd.c_str());
|
||||
String lcd = String("Joined: ") + mp->payload.user.long_name + "\n";
|
||||
screen.print(lcd.c_str());
|
||||
}
|
||||
|
||||
return mp;
|
||||
}
|
||||
|
||||
void MeshService::handleIncomingPosition(MeshPacket *mp)
|
||||
void MeshService::handleIncomingPosition(const MeshPacket *mp)
|
||||
{
|
||||
if (mp->has_payload && mp->payload.which_variant == SubPacket_position_tag)
|
||||
{
|
||||
DEBUG_MSG("handled incoming position time=%u\n", mp->payload.variant.position.time);
|
||||
if (mp->has_payload && mp->payload.has_position) {
|
||||
DEBUG_MSG("handled incoming position time=%u\n", mp->payload.position.time);
|
||||
|
||||
if (mp->payload.variant.position.time)
|
||||
{
|
||||
if (mp->payload.position.time) {
|
||||
struct timeval tv;
|
||||
uint32_t secs = mp->payload.variant.position.time;
|
||||
uint32_t secs = mp->payload.position.time;
|
||||
|
||||
tv.tv_sec = secs;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
gps.perhapsSetRTC(&tv);
|
||||
}
|
||||
} else {
|
||||
DEBUG_MSG("Ignoring incoming packet - not a position\n");
|
||||
}
|
||||
}
|
||||
|
||||
void MeshService::handleFromRadio(MeshPacket *mp)
|
||||
int MeshService::handleFromRadio(const MeshPacket *mp)
|
||||
{
|
||||
powerFSM.trigger(EVENT_RECEIVED_PACKET); // Possibly keep the node from sleeping
|
||||
|
||||
mp->rx_time = gps.getValidTime(); // store the arrival timestamp for the phone
|
||||
|
||||
// If it is a position packet, perhaps set our clock (if we don't have a GPS of our own, otherwise wait for that to work)
|
||||
if (!myNodeInfo.has_gps)
|
||||
if (!gps.isConnected)
|
||||
handleIncomingPosition(mp);
|
||||
else {
|
||||
DEBUG_MSG("Ignoring incoming time, because we have a GPS\n");
|
||||
}
|
||||
|
||||
if (mp->has_payload && mp->payload.which_variant == SubPacket_user_tag)
|
||||
{
|
||||
if (mp->has_payload && mp->payload.has_user) {
|
||||
mp = handleFromRadioUser(mp);
|
||||
}
|
||||
|
||||
// If we veto a received User packet, we don't put it into the DB or forward it to the phone (to prevent confusing it)
|
||||
if (mp)
|
||||
{
|
||||
if (mp) {
|
||||
DEBUG_MSG("Forwarding to phone, from=0x%x, rx_time=%u\n", mp->from, mp->rx_time);
|
||||
nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio
|
||||
|
||||
fromNum++;
|
||||
|
||||
if (toPhoneQueue.numFree() == 0)
|
||||
{
|
||||
if (toPhoneQueue.numFree() == 0) {
|
||||
DEBUG_MSG("NOTE: tophone queue is full, discarding oldest\n");
|
||||
MeshPacket *d = toPhoneQueue.dequeuePtr(0);
|
||||
if (d)
|
||||
releaseToPool(d);
|
||||
}
|
||||
assert(toPhoneQueue.enqueue(mp, 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
|
||||
|
||||
MeshPacket *copied = packetPool.allocCopy(*mp);
|
||||
assert(toPhoneQueue.enqueue(copied, 0)); // FIXME, instead of failing for full queue, delete the oldest mssages
|
||||
|
||||
if (mp->payload.want_response)
|
||||
sendNetworkPing(mp->from);
|
||||
} else {
|
||||
DEBUG_MSG("Not delivering vetoed User message\n");
|
||||
}
|
||||
else
|
||||
DEBUG_MSG("Dropping vetoed User message\n");
|
||||
}
|
||||
|
||||
void MeshService::handleFromRadio()
|
||||
{
|
||||
MeshPacket *mp;
|
||||
uint32_t oldFromNum = fromNum;
|
||||
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL)
|
||||
{
|
||||
handleFromRadio(mp);
|
||||
}
|
||||
if (oldFromNum != fromNum) // We don't want to generate extra notifies for multiple new packets
|
||||
bluetoothNotifyFromNum(fromNum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t sendOwnerCb()
|
||||
@@ -206,9 +196,10 @@ Periodic sendOwnerPeriod(sendOwnerCb);
|
||||
/// Do idle processing (mostly processing messages which have been queued from the radio)
|
||||
void MeshService::loop()
|
||||
{
|
||||
radio.loop(); // FIXME, possibly move radio interaction to own thread
|
||||
|
||||
handleFromRadio();
|
||||
if (oldFromNum != fromNum) { // We don't want to generate extra notifies for multiple new packets
|
||||
fromNumChanged.notifyObservers(fromNum);
|
||||
oldFromNum = fromNum;
|
||||
}
|
||||
|
||||
// occasionally send our owner info
|
||||
sendOwnerPeriod.loop();
|
||||
@@ -218,7 +209,8 @@ void MeshService::loop()
|
||||
void MeshService::reloadConfig()
|
||||
{
|
||||
// If we can successfully set this radio to these settings, save them to disk
|
||||
radio.reloadConfig();
|
||||
nodeDB.resetRadioConfig(); // Don't let the phone send us fatally bad settings
|
||||
configChanged.notifyObservers(NULL);
|
||||
nodeDB.saveToDisk();
|
||||
}
|
||||
|
||||
@@ -227,26 +219,32 @@ void MeshService::handleToRadio(std::string s)
|
||||
{
|
||||
static ToRadio r; // this is a static scratch object, any data must be copied elsewhere before returning
|
||||
|
||||
if (pb_decode_from_bytes((const uint8_t *)s.c_str(), s.length(), ToRadio_fields, &r))
|
||||
{
|
||||
switch (r.which_variant)
|
||||
{
|
||||
case ToRadio_packet_tag:
|
||||
{
|
||||
if (pb_decode_from_bytes((const uint8_t *)s.c_str(), s.length(), ToRadio_fields, &r)) {
|
||||
switch (r.which_variant) {
|
||||
case ToRadio_packet_tag: {
|
||||
// If our phone is sending a position, see if we can use it to set our RTC
|
||||
handleIncomingPosition(&r.variant.packet); // If it is a position packet, perhaps set our clock
|
||||
MeshPacket &p = r.variant.packet;
|
||||
handleIncomingPosition(&p); // If it is a position packet, perhaps set our clock
|
||||
|
||||
r.variant.packet.rx_time = gps.getValidTime(); // Record the time the packet arrived from the phone (so we update our nodedb for the local node)
|
||||
if (p.from == 0) // If the phone didn't set a sending node ID, use ours
|
||||
p.from = nodeDB.getNodeNum();
|
||||
|
||||
if (p.id == 0)
|
||||
p.id = generatePacketId(); // If the phone didn't supply one, then pick one
|
||||
|
||||
p.rx_time = gps.getValidTime(); // Record the time the packet arrived from the phone
|
||||
// (so we update our nodedb for the local node)
|
||||
|
||||
// Send the packet into the mesh
|
||||
sendToMesh(packetPool.allocCopy(r.variant.packet));
|
||||
|
||||
sendToMesh(packetPool.allocCopy(p));
|
||||
|
||||
bool loopback = false; // if true send any packet the phone sends back itself (for testing)
|
||||
if (loopback)
|
||||
{
|
||||
MeshPacket *mp = packetPool.allocCopy(r.variant.packet);
|
||||
handleFromRadio(mp);
|
||||
bluetoothNotifyFromNum(fromNum); // tell the phone a new packet arrived
|
||||
if (loopback) {
|
||||
// no need to copy anymore because handle from radio assumes it should _not_ delete
|
||||
// packetPool.allocCopy(r.variant.packet);
|
||||
handleFromRadio(&p);
|
||||
// handleFromRadio will tell the phone a new packet arrived
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -254,6 +252,8 @@ void MeshService::handleToRadio(std::string s)
|
||||
DEBUG_MSG("Error: unexpected ToRadio variant\n");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
DEBUG_MSG("Error: ignoring malformed toradio\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,24 +261,26 @@ void MeshService::sendToMesh(MeshPacket *p)
|
||||
{
|
||||
nodeDB.updateFrom(*p); // update our local DB for this packet (because phone might have sent position packets etc...)
|
||||
|
||||
// Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other nodes shouldn't trust it anyways)
|
||||
// Note: for now, we allow a device with a local GPS to include the time, so that gpsless devices can get time.
|
||||
if (p->has_payload && p->payload.which_variant == SubPacket_position_tag)
|
||||
{
|
||||
if (!myNodeInfo.has_gps)
|
||||
p->payload.variant.position.time = 0;
|
||||
else
|
||||
DEBUG_MSG("Providing time to mesh %u\n", p->payload.variant.position.time);
|
||||
// Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other
|
||||
// nodes shouldn't trust it anyways) Note: for now, we allow a device with a local GPS to include the time, so that gpsless
|
||||
// devices can get time.
|
||||
if (p->has_payload && p->payload.has_position) {
|
||||
if (!gps.isConnected) {
|
||||
DEBUG_MSG("Stripping time %u from position send\n", p->payload.position.time);
|
||||
p->payload.position.time = 0;
|
||||
} else
|
||||
DEBUG_MSG("Providing time to mesh %u\n", p->payload.position.time);
|
||||
}
|
||||
|
||||
// If the phone sent a packet just to us, don't send it out into the network
|
||||
if (p->to == nodeDB.getNodeNum())
|
||||
DEBUG_MSG("Dropping locally processed message\n");
|
||||
else
|
||||
{
|
||||
else {
|
||||
// Note: We might return !OK if our fifo was full, at that point the only option we have is to drop it
|
||||
if (radio.send(p) != ERRNO_OK)
|
||||
DEBUG_MSG("Dropped packet because send queue was full!\n");
|
||||
if (router.send(p) != ERRNO_OK) {
|
||||
DEBUG_MSG("No radio was able to send packet, discarding...\n");
|
||||
releaseToPool(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,23 +291,25 @@ MeshPacket *MeshService::allocForSending()
|
||||
p->has_payload = true;
|
||||
p->from = nodeDB.getNodeNum();
|
||||
p->to = NODENUM_BROADCAST;
|
||||
p->id = generatePacketId();
|
||||
p->rx_time = gps.getValidTime(); // Just in case we process the packet locally - make sure it has a valid timestamp
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void MeshService::sendNetworkPing(NodeNum dest)
|
||||
void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies)
|
||||
{
|
||||
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
||||
assert(node);
|
||||
|
||||
DEBUG_MSG("Sending network ping to 0x%x, with position=%d, wantReplies=%d\n", dest, node->has_position, wantReplies);
|
||||
if (node->has_position)
|
||||
sendOurPosition(dest);
|
||||
sendOurPosition(dest, wantReplies);
|
||||
else
|
||||
sendOurOwner(dest);
|
||||
sendOurOwner(dest, wantReplies);
|
||||
}
|
||||
|
||||
void MeshService::sendOurPosition(NodeNum dest)
|
||||
void MeshService::sendOurPosition(NodeNum dest, bool wantReplies)
|
||||
{
|
||||
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
|
||||
assert(node);
|
||||
@@ -314,45 +318,45 @@ void MeshService::sendOurPosition(NodeNum dest)
|
||||
// Update our local node info with our position (even if we don't decide to update anyone else)
|
||||
MeshPacket *p = allocForSending();
|
||||
p->to = dest;
|
||||
p->payload.which_variant = SubPacket_position_tag;
|
||||
p->payload.variant.position = node->position;
|
||||
p->payload.variant.position.time = gps.getValidTime(); // This nodedb timestamp might be stale, so update it if our clock is valid.
|
||||
p->payload.has_position = true;
|
||||
p->payload.position = node->position;
|
||||
p->payload.want_response = wantReplies;
|
||||
p->payload.position.time = gps.getValidTime(); // This nodedb timestamp might be stale, so update it if our clock is valid.
|
||||
sendToMesh(p);
|
||||
}
|
||||
|
||||
void MeshService::onGPSChanged()
|
||||
int MeshService::onGPSChanged(void *unused)
|
||||
{
|
||||
DEBUG_MSG("got gps notify\n");
|
||||
|
||||
// Update our local node info with our position (even if we don't decide to update anyone else)
|
||||
MeshPacket *p = allocForSending();
|
||||
p->payload.which_variant = SubPacket_position_tag;
|
||||
Position &pos = p->payload.variant.position;
|
||||
if (gps.altitude.isValid())
|
||||
pos.altitude = gps.altitude.meters();
|
||||
pos.latitude = gps.location.lat();
|
||||
pos.longitude = gps.location.lng();
|
||||
pos.time = gps.getValidTime();
|
||||
p->payload.has_position = true;
|
||||
|
||||
Position &pos = p->payload.position;
|
||||
// !zero or !zero lat/long means valid
|
||||
if (gps.latitude != 0 || gps.longitude != 0) {
|
||||
if (gps.altitude != 0)
|
||||
pos.altitude = gps.altitude;
|
||||
pos.latitude = gps.latitude;
|
||||
pos.longitude = gps.longitude;
|
||||
pos.time = gps.getValidTime();
|
||||
}
|
||||
|
||||
// We limit our GPS broadcasts to a max rate
|
||||
static uint32_t lastGpsSend;
|
||||
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;
|
||||
DEBUG_MSG("Sending position to mesh\n");
|
||||
|
||||
sendToMesh(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// We don't need to send this packet to anyone else, but it still serves as a nice uniform way to update our local state
|
||||
nodeDB.updateFrom(*p);
|
||||
|
||||
releaseToPool(p);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshService::onNotify(Observable *o)
|
||||
{
|
||||
DEBUG_MSG("got gps notify\n");
|
||||
onGPSChanged();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,20 +2,24 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#include "mesh.pb.h"
|
||||
#include "MeshRadio.h"
|
||||
#include "PointerQueue.h"
|
||||
#include "MemoryPool.h"
|
||||
#include "MeshRadio.h"
|
||||
#include "MeshTypes.h"
|
||||
#include "Observer.h"
|
||||
#include "PointerQueue.h"
|
||||
#include "mesh.pb.h"
|
||||
|
||||
/**
|
||||
* Top level app for this service. keeps the mesh, the radio config and the queue of received packets.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class MeshService: private Observer
|
||||
class MeshService
|
||||
{
|
||||
MemoryPool<MeshPacket> packetPool;
|
||||
CallbackObserver<MeshService, void *> gpsObserver = CallbackObserver<MeshService, void *>(this, &MeshService::onGPSChanged);
|
||||
CallbackObserver<MeshService, const MeshPacket *> packetReceivedObserver =
|
||||
CallbackObserver<MeshService, const MeshPacket *>(this, &MeshService::handleFromRadio);
|
||||
|
||||
/// received packets waiting for the phone to process them
|
||||
/// FIXME, change to a DropOldestQueue and keep a count of the number of dropped packets to ensure
|
||||
@@ -23,21 +27,23 @@ class MeshService: private Observer
|
||||
/// FIXME - save this to flash on deep sleep
|
||||
PointerQueue<MeshPacket> toPhoneQueue;
|
||||
|
||||
/// Packets which have just arrived from the radio, ready to be processed by this service and possibly
|
||||
/// forwarded to the phone.
|
||||
PointerQueue<MeshPacket> fromRadioQueue;
|
||||
|
||||
/// The current nonce for the newest packet which has been queued for the phone
|
||||
uint32_t fromNum;
|
||||
uint32_t fromNum = 0;
|
||||
|
||||
public:
|
||||
/// Updated in loop() to detect when fromNum changes
|
||||
uint32_t oldFromNum = 0;
|
||||
|
||||
MeshRadio radio;
|
||||
public:
|
||||
/// Called when some new packets have arrived from one of the radios
|
||||
Observable<uint32_t> fromNumChanged;
|
||||
|
||||
/// Called when radio config has changed (radios should observe this and set their hardware as required)
|
||||
Observable<void *> configChanged;
|
||||
|
||||
MeshService();
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
/// Do idle processing (mostly processing messages which have been queued from the radio)
|
||||
void loop();
|
||||
|
||||
@@ -56,40 +62,39 @@ public:
|
||||
|
||||
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
|
||||
void reloadOwner() { sendOurOwner(); }
|
||||
|
||||
|
||||
/// Allocate and return a meshpacket which defaults as send to broadcast from the current node.
|
||||
MeshPacket *allocForSending();
|
||||
|
||||
/// 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
|
||||
void sendNetworkPing(NodeNum dest = NODENUM_BROADCAST);
|
||||
/// 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
|
||||
void sendNetworkPing(NodeNum dest, bool wantReplies = false);
|
||||
|
||||
/// Send our owner info to a particular node
|
||||
void sendOurOwner(NodeNum dest = NODENUM_BROADCAST);
|
||||
private:
|
||||
/// Send our owner info to a particular node
|
||||
void sendOurOwner(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||
|
||||
private:
|
||||
/// Broadcasts our last known position
|
||||
void sendOurPosition(NodeNum dest = NODENUM_BROADCAST);
|
||||
void sendOurPosition(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||
|
||||
/// Send a packet into the mesh - note p must have been allocated from packetPool. We will return it to that pool after sending.
|
||||
/// This is the ONLY function you should use for sending messages into the mesh, because it also updates the nodedb cache
|
||||
/// Send a packet into the mesh - note p must have been allocated from packetPool. We will return it to that pool after
|
||||
/// sending. This is the ONLY function you should use for sending messages into the mesh, because it also updates the nodedb
|
||||
/// cache
|
||||
void sendToMesh(MeshPacket *p);
|
||||
|
||||
/// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh
|
||||
void onGPSChanged();
|
||||
/// returns 0 to allow futher processing
|
||||
int onGPSChanged(void *arg);
|
||||
|
||||
virtual void onNotify(Observable *o);
|
||||
|
||||
/// handle all the packets that just arrived from the mesh radio
|
||||
void handleFromRadio();
|
||||
|
||||
/// Handle a packet that just arrived from the radio
|
||||
void handleFromRadio(MeshPacket *p);
|
||||
/// Handle a packet that just arrived from the radio. This method does _not_ free the provided packet. If it needs
|
||||
/// to keep the packet around it makes a copy
|
||||
int handleFromRadio(const MeshPacket *p);
|
||||
|
||||
/// handle a user packet that just arrived on the radio, return NULL if we should not process this packet at all
|
||||
MeshPacket *handleFromRadioUser(MeshPacket *mp);
|
||||
const MeshPacket *handleFromRadioUser(const MeshPacket *mp);
|
||||
|
||||
/// look at inbound packets and if they contain a position with time, possibly set our clock
|
||||
void handleIncomingPosition(MeshPacket *mp);
|
||||
void handleIncomingPosition(const MeshPacket *mp);
|
||||
};
|
||||
|
||||
extern MeshService service;
|
||||
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
// low level types
|
||||
// low level types
|
||||
|
||||
#include "MemoryPool.h"
|
||||
#include "mesh.pb.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
typedef uint8_t NodeNum;
|
||||
typedef uint8_t PacketId; // A packet sequence number
|
||||
|
||||
#define NODENUM_BROADCAST 255
|
||||
#define ERRNO_OK 0
|
||||
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
|
||||
|
||||
typedef int ErrorCode;
|
||||
typedef int ErrorCode;
|
||||
|
||||
/// Alloc and free packets to our global, ISR safe pool
|
||||
extern MemoryPool<MeshPacket> packetPool;
|
||||
206
src/NodeDB.cpp
206
src/NodeDB.cpp
@@ -5,13 +5,14 @@
|
||||
#include "FS.h"
|
||||
#include "SPIFFS.h"
|
||||
|
||||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
#include "configuration.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
#include "NodeDB.h"
|
||||
#include "GPS.h"
|
||||
#include "NodeDB.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "configuration.h"
|
||||
#include "error.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
#include <pb_decode.h>
|
||||
#include <pb_encode.h>
|
||||
|
||||
NodeDB nodeDB;
|
||||
|
||||
@@ -22,17 +23,22 @@ RadioConfig &radioConfig = devicestate.radio;
|
||||
ChannelSettings &channelSettings = radioConfig.channel_settings;
|
||||
|
||||
/*
|
||||
DeviceState versions used to be defined in the .proto file but really only this function cares. So changed to a
|
||||
DeviceState versions used to be defined in the .proto file but really only this function cares. So changed to a
|
||||
#define here.
|
||||
*/
|
||||
|
||||
#define DEVICESTATE_CUR_VER 1
|
||||
#define DEVICESTATE_CUR_VER 7
|
||||
#define DEVICESTATE_MIN_VER DEVICESTATE_CUR_VER
|
||||
|
||||
#ifndef NO_ESP32
|
||||
#define FS SPIFFS
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
// FIXME - move this somewhere else
|
||||
extern void getMacAddr(uint8_t *dmac);
|
||||
|
||||
/**
|
||||
*
|
||||
* Normally userids are unique and start with +country code to look like Signal phone numbers.
|
||||
* But there are some special ids used when we haven't yet been configured by a user. In that case
|
||||
* we use !macaddr (no colons).
|
||||
@@ -41,45 +47,71 @@ User &owner = devicestate.owner;
|
||||
|
||||
static uint8_t ourMacAddr[6];
|
||||
|
||||
NodeDB::NodeDB() : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count)
|
||||
NodeDB::NodeDB() : nodes(devicestate.node_db), numNodes(&devicestate.node_db_count) {}
|
||||
|
||||
void NodeDB::resetRadioConfig()
|
||||
{
|
||||
/// 16 bytes of random PSK for our _public_ default channel that all devices power up on
|
||||
static const uint8_t defaultpsk[] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59,
|
||||
0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf};
|
||||
|
||||
if (radioConfig.preferences.sds_secs == 0) {
|
||||
DEBUG_MSG("RadioConfig reset!\n");
|
||||
radioConfig.preferences.send_owner_interval = 4; // per sw-design.md
|
||||
radioConfig.preferences.position_broadcast_secs = 15 * 60;
|
||||
radioConfig.preferences.wait_bluetooth_secs = 120;
|
||||
radioConfig.preferences.screen_on_secs = 5 * 60;
|
||||
radioConfig.preferences.mesh_sds_timeout_secs = 2 * 60 * 60;
|
||||
radioConfig.preferences.phone_sds_timeout_sec = 2 * 60 * 60;
|
||||
radioConfig.preferences.sds_secs = 365 * 24 * 60 * 60; // one year
|
||||
radioConfig.preferences.ls_secs = 60 * 60;
|
||||
radioConfig.preferences.phone_timeout_secs = 15 * 60;
|
||||
radioConfig.has_channel_settings = true;
|
||||
radioConfig.has_preferences = true;
|
||||
|
||||
// radioConfig.modem_config = RadioConfig_ModemConfig_Bw125Cr45Sf128; // medium range and fast
|
||||
// channelSettings.modem_config = ChannelSettings_ModemConfig_Bw500Cr45Sf128; // short range and fast, but wide bandwidth
|
||||
// so incompatible radios can talk together
|
||||
channelSettings.modem_config = ChannelSettings_ModemConfig_Bw125Cr48Sf4096; // slow and long range
|
||||
|
||||
channelSettings.tx_power = 23;
|
||||
memcpy(&channelSettings.psk, &defaultpsk, sizeof(channelSettings.psk));
|
||||
strcpy(channelSettings.name, "Default");
|
||||
}
|
||||
|
||||
// temp hack for quicker testing
|
||||
/*
|
||||
radioConfig.preferences.screen_on_secs = 30;
|
||||
radioConfig.preferences.wait_bluetooth_secs = 30;
|
||||
radioConfig.preferences.position_broadcast_secs = 15;
|
||||
*/
|
||||
}
|
||||
|
||||
void NodeDB::init()
|
||||
{
|
||||
|
||||
// init our devicestate with valid flags so protobuf writing/reading will work
|
||||
devicestate.has_my_node = true;
|
||||
devicestate.has_radio = true;
|
||||
devicestate.has_owner = true;
|
||||
devicestate.has_radio = true;
|
||||
devicestate.has_radio = false;
|
||||
devicestate.radio.has_channel_settings = true;
|
||||
devicestate.radio.has_preferences = true;
|
||||
devicestate.node_db_count = 0;
|
||||
devicestate.receive_queue_count = 0;
|
||||
|
||||
radioConfig.preferences.send_owner_interval = 4; // per sw-design.md
|
||||
radioConfig.preferences.position_broadcast_secs = 15 * 60;
|
||||
radioConfig.preferences.wait_bluetooth_secs = 120;
|
||||
radioConfig.preferences.screen_on_secs = 30;
|
||||
radioConfig.preferences.mesh_sds_timeout_secs = 2 * 60 * 60;
|
||||
radioConfig.preferences.phone_sds_timeout_sec = 2 * 60 * 60;
|
||||
radioConfig.preferences.sds_secs = 365 * 24 * 60 * 60; // one year
|
||||
radioConfig.preferences.ls_secs = 60 * 60;
|
||||
radioConfig.preferences.phone_timeout_secs = 15 * 60;
|
||||
resetRadioConfig();
|
||||
|
||||
// default to no GPS, until one has been found by probing
|
||||
myNodeInfo.has_gps = false;
|
||||
|
||||
#ifdef GPS_RX_PIN
|
||||
// some hardware defaults to have a built in GPS
|
||||
myNodeInfo.has_gps = true;
|
||||
#endif
|
||||
strncpy(myNodeInfo.region, xstr(HW_VERSION), sizeof(myNodeInfo.region));
|
||||
strncpy(myNodeInfo.firmware_version, xstr(APP_VERSION), sizeof(myNodeInfo.firmware_version));
|
||||
strncpy(myNodeInfo.hw_model, HW_VENDOR, sizeof(myNodeInfo.hw_model));
|
||||
|
||||
// Init our blank owner info to reasonable defaults
|
||||
esp_efuse_mac_get_default(ourMacAddr);
|
||||
sprintf(owner.id, "!%02x%02x%02x%02x%02x%02x", ourMacAddr[0],
|
||||
ourMacAddr[1], ourMacAddr[2], ourMacAddr[3], ourMacAddr[4], ourMacAddr[5]);
|
||||
getMacAddr(ourMacAddr);
|
||||
sprintf(owner.id, "!%02x%02x%02x%02x%02x%02x", ourMacAddr[0], ourMacAddr[1], ourMacAddr[2], ourMacAddr[3], ourMacAddr[4],
|
||||
ourMacAddr[5]);
|
||||
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
|
||||
|
||||
// make each node start with ad different random seed (but okay that the sequence is the same each boot)
|
||||
@@ -96,14 +128,9 @@ void NodeDB::init()
|
||||
info->user = owner;
|
||||
info->has_user = true;
|
||||
|
||||
if (!FS.begin(true)) // FIXME - do this in main?
|
||||
{
|
||||
DEBUG_MSG("ERROR SPIFFS Mount Failed\n");
|
||||
// FIXME - report failure to phone
|
||||
}
|
||||
|
||||
// saveToDisk();
|
||||
loadFromDisk();
|
||||
resetRadioConfig(); // If bogus settings got saved, then fix them
|
||||
|
||||
DEBUG_MSG("NODENUM=0x%x, dbsize=%d\n", myNodeInfo.my_node_num, *numNodes);
|
||||
}
|
||||
@@ -112,7 +139,7 @@ void NodeDB::init()
|
||||
#define NUM_RESERVED 4
|
||||
|
||||
/**
|
||||
* get our starting (provisional) nodenum from flash.
|
||||
* get our starting (provisional) nodenum from flash.
|
||||
*/
|
||||
void NodeDB::pickNewNodeNum()
|
||||
{
|
||||
@@ -122,8 +149,7 @@ void NodeDB::pickNewNodeNum()
|
||||
r = NUM_RESERVED; // don't pick a reserved node number
|
||||
|
||||
NodeInfo *found;
|
||||
while ((found = getNode(r)) && memcmp(found->user.macaddr, owner.macaddr, sizeof(owner.macaddr)))
|
||||
{
|
||||
while ((found = getNode(r)) && memcmp(found->user.macaddr, owner.macaddr, sizeof(owner.macaddr))) {
|
||||
NodeNum n = random(NUM_RESERVED, NODENUM_BROADCAST); // try a new random choice
|
||||
DEBUG_MSG("NOTE! Our desired nodenum 0x%x is in use, so trying for 0x%x\n", r, n);
|
||||
r = n;
|
||||
@@ -137,56 +163,59 @@ const char *preftmp = "/db.proto.tmp";
|
||||
|
||||
void NodeDB::loadFromDisk()
|
||||
{
|
||||
#ifdef FS
|
||||
static DeviceState scratch;
|
||||
|
||||
File f = FS.open(preffile);
|
||||
if (f)
|
||||
if (!FS.begin(true)) // FIXME - do this in main?
|
||||
{
|
||||
DEBUG_MSG("ERROR SPIFFS Mount Failed\n");
|
||||
// FIXME - report failure to phone
|
||||
}
|
||||
|
||||
File f = FS.open(preffile);
|
||||
if (f) {
|
||||
DEBUG_MSG("Loading saved preferences\n");
|
||||
pb_istream_t stream = {&readcb, &f, DeviceState_size};
|
||||
|
||||
//DEBUG_MSG("Preload channel name=%s\n", channelSettings.name);
|
||||
// DEBUG_MSG("Preload channel name=%s\n", channelSettings.name);
|
||||
|
||||
memset(&scratch, 0, sizeof(scratch));
|
||||
if (!pb_decode(&stream, DeviceState_fields, &scratch))
|
||||
{
|
||||
if (!pb_decode(&stream, DeviceState_fields, &scratch)) {
|
||||
DEBUG_MSG("Error: can't decode protobuf %s\n", PB_GET_ERROR(&stream));
|
||||
// FIXME - report failure to phone
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (scratch.version < DEVICESTATE_MIN_VER)
|
||||
DEBUG_MSG("Warn: devicestate is old, discarding\n");
|
||||
else
|
||||
{
|
||||
else {
|
||||
DEBUG_MSG("Loaded saved preferences version %d\n", scratch.version);
|
||||
devicestate = scratch;
|
||||
}
|
||||
|
||||
//DEBUG_MSG("Postload channel name=%s\n", channelSettings.name);
|
||||
// DEBUG_MSG("Postload channel name=%s\n", channelSettings.name);
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEBUG_MSG("No saved preferences found\n");
|
||||
}
|
||||
#else
|
||||
DEBUG_MSG("ERROR: Filesystem not implemented\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void NodeDB::saveToDisk()
|
||||
{
|
||||
#ifdef FS
|
||||
File f = FS.open(preftmp, "w");
|
||||
if (f)
|
||||
{
|
||||
if (f) {
|
||||
DEBUG_MSG("Writing preferences\n");
|
||||
|
||||
pb_ostream_t stream = {&writecb, &f, SIZE_MAX, 0};
|
||||
|
||||
//DEBUG_MSG("Presave channel name=%s\n", channelSettings.name);
|
||||
// DEBUG_MSG("Presave channel name=%s\n", channelSettings.name);
|
||||
|
||||
devicestate.version = DEVICESTATE_CUR_VER;
|
||||
if (!pb_encode(&stream, DeviceState_fields, &devicestate))
|
||||
{
|
||||
if (!pb_encode(&stream, DeviceState_fields, &devicestate)) {
|
||||
DEBUG_MSG("Error: can't write protobuf %s\n", PB_GET_ERROR(&stream));
|
||||
// FIXME - report failure to phone
|
||||
}
|
||||
@@ -198,11 +227,12 @@ void NodeDB::saveToDisk()
|
||||
DEBUG_MSG("Warning: Can't remove old pref file\n");
|
||||
if (!FS.rename(preftmp, preffile))
|
||||
DEBUG_MSG("Error: can't rename new pref file\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEBUG_MSG("ERROR: can't write prefs\n"); // FIXME report to app
|
||||
}
|
||||
#else
|
||||
DEBUG_MSG("ERROR filesystem not implemented\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
const NodeInfo *NodeDB::readNextInfo()
|
||||
@@ -244,10 +274,9 @@ size_t NodeDB::getNumOnlineNodes()
|
||||
/// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw
|
||||
void NodeDB::updateFrom(const MeshPacket &mp)
|
||||
{
|
||||
if (mp.has_payload)
|
||||
{
|
||||
if (mp.has_payload) {
|
||||
const SubPacket &p = mp.payload;
|
||||
DEBUG_MSG("Update DB node 0x%x for variant %d, rx_time=%u\n", mp.from, p.which_variant, mp.rx_time);
|
||||
DEBUG_MSG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time);
|
||||
|
||||
int oldNumNodes = *numNodes;
|
||||
NodeInfo *info = getOrCreateNode(mp.from);
|
||||
@@ -255,33 +284,25 @@ void NodeDB::updateFrom(const MeshPacket &mp)
|
||||
if (oldNumNodes != *numNodes)
|
||||
updateGUI = true; // we just created a nodeinfo
|
||||
|
||||
if (mp.rx_time)
|
||||
{ // if the packet has a valid timestamp use it to update our last_seen
|
||||
if (mp.rx_time) { // if the packet has a valid timestamp use it to update our last_seen
|
||||
info->has_position = true; // at least the time is valid
|
||||
info->position.time = mp.rx_time;
|
||||
}
|
||||
|
||||
switch (p.which_variant)
|
||||
{
|
||||
case SubPacket_position_tag:
|
||||
{
|
||||
if (p.has_position) {
|
||||
// we carefully preserve the old time, because we always trust our local timestamps more
|
||||
uint32_t oldtime = info->position.time;
|
||||
info->position = p.variant.position;
|
||||
info->position = p.position;
|
||||
info->position.time = oldtime;
|
||||
info->has_position = true;
|
||||
updateGUIforNode = info;
|
||||
break;
|
||||
}
|
||||
|
||||
case SubPacket_data_tag:
|
||||
{
|
||||
if (p.has_data) {
|
||||
// Keep a copy of the most recent text message.
|
||||
if (p.variant.data.typ == Data_Type_CLEAR_TEXT)
|
||||
{
|
||||
DEBUG_MSG("Received text msg from=0%0x, msg=%.*s\n", mp.from, p.variant.data.payload.size, p.variant.data.payload.bytes);
|
||||
if (mp.to == NODENUM_BROADCAST || mp.to == nodeDB.getNodeNum())
|
||||
{
|
||||
if (p.data.typ == Data_Type_CLEAR_TEXT) {
|
||||
DEBUG_MSG("Received text msg from=0%0x, msg=%.*s\n", mp.from, p.data.payload.size, p.data.payload.bytes);
|
||||
if (mp.to == NODENUM_BROADCAST || mp.to == nodeDB.getNodeNum()) {
|
||||
// We only store/display messages destined for us.
|
||||
devicestate.rx_text_message = mp;
|
||||
devicestate.has_rx_text_message = true;
|
||||
@@ -289,21 +310,19 @@ void NodeDB::updateFrom(const MeshPacket &mp)
|
||||
powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SubPacket_user_tag:
|
||||
{
|
||||
if (p.has_user) {
|
||||
DEBUG_MSG("old user %s/%s/%s\n", info->user.id, info->user.long_name, info->user.short_name);
|
||||
|
||||
bool changed = memcmp(&info->user, &p.variant.user, sizeof(info->user)); // Both of these blocks start as filled with zero so I think this is okay
|
||||
bool changed = memcmp(&info->user, &p.user,
|
||||
sizeof(info->user)); // Both of these blocks start as filled with zero so I think this is okay
|
||||
|
||||
info->user = p.variant.user;
|
||||
info->user = p.user;
|
||||
DEBUG_MSG("updating changed=%d user %s/%s/%s\n", changed, info->user.id, info->user.long_name, info->user.short_name);
|
||||
info->has_user = true;
|
||||
|
||||
if (changed)
|
||||
{
|
||||
if (changed) {
|
||||
updateGUIforNode = info;
|
||||
powerFSM.trigger(EVENT_NODEDB_UPDATED);
|
||||
|
||||
@@ -311,11 +330,6 @@ void NodeDB::updateFrom(const MeshPacket &mp)
|
||||
// We just changed something important about the user, store our DB
|
||||
// saveToDisk();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break; // Ignore other packet types
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,8 +350,7 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n)
|
||||
{
|
||||
NodeInfo *info = getNode(n);
|
||||
|
||||
if (!info)
|
||||
{
|
||||
if (!info) {
|
||||
// add the node
|
||||
assert(*numNodes < MAX_NUM_NODES);
|
||||
info = &nodes[(*numNodes)++];
|
||||
@@ -348,4 +361,13 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n)
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
/// Record an error that should be reported via analytics
|
||||
void recordCriticalError(CriticalErrorCode code, uint32_t address)
|
||||
{
|
||||
DEBUG_MSG("NOTE! Recording critical error %d, address=%x\n", code, address);
|
||||
myNodeInfo.error_code = code;
|
||||
myNodeInfo.error_address = address;
|
||||
myNodeInfo.error_count++;
|
||||
}
|
||||
|
||||
30
src/NodeDB.h
30
src/NodeDB.h
@@ -3,8 +3,8 @@
|
||||
#include <Arduino.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "mesh-pb-constants.h"
|
||||
#include "MeshTypes.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
|
||||
extern DeviceState devicestate;
|
||||
extern MyNodeInfo &myNodeInfo;
|
||||
@@ -28,10 +28,10 @@ class NodeDB
|
||||
|
||||
int readPointer = 0;
|
||||
|
||||
public:
|
||||
bool updateGUI = false; // we think the gui should definitely be redrawn, screen will clear this once handled
|
||||
public:
|
||||
bool updateGUI = false; // we think the gui should definitely be redrawn, screen will clear this once handled
|
||||
NodeInfo *updateGUIforNode = NULL; // if currently showing this node, we think you should update the GUI
|
||||
bool updateTextMessage = false; // if true, the GUI should show a new text message
|
||||
bool updateTextMessage = false; // if true, the GUI should show a new text message
|
||||
|
||||
/// don't do mesh based algoritm for node id assignment (initially)
|
||||
/// instead just store in flash - possibly even in the initial alpha release do this hack
|
||||
@@ -43,6 +43,9 @@ public:
|
||||
/// write to flash
|
||||
void saveToDisk();
|
||||
|
||||
// Reinit radio config if needed, because sometimes a buggy android app might send us bogus settings
|
||||
void resetRadioConfig();
|
||||
|
||||
/// given a subpacket sniffed from the network, update our DB state
|
||||
/// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw
|
||||
void updateFrom(const MeshPacket &p);
|
||||
@@ -56,10 +59,11 @@ public:
|
||||
// bool handleWantNodeNum(NodeNum n);
|
||||
|
||||
/* void handleDenyNodeNum(NodeNum FIXME read mesh proto docs, perhaps picking a random node num is not a great idea
|
||||
and instead we should use a special 'im unconfigured node number' and include our desired node number in the wantnum message. the
|
||||
unconfigured node num would only be used while initially joining the mesh so low odds of conflicting (especially if we randomly select
|
||||
from a small number of nodenums which can be used temporarily for this operation). figure out what the lower level
|
||||
mesh sw does if it does conflict? would it be better for people who are replying with denynode num to just broadcast their denial?)
|
||||
and instead we should use a special 'im unconfigured node number' and include our desired node number in the wantnum message.
|
||||
the unconfigured node num would only be used while initially joining the mesh so low odds of conflicting (especially if we
|
||||
randomly select from a small number of nodenums which can be used temporarily for this operation). figure out what the lower
|
||||
level mesh sw does if it does conflict? would it be better for people who are replying with denynode num to just broadcast
|
||||
their denial?)
|
||||
*/
|
||||
|
||||
/// Called from bluetooth when the user wants to start reading the node DB from scratch.
|
||||
@@ -74,13 +78,16 @@ public:
|
||||
/// Find a node in our DB, return null for missing
|
||||
NodeInfo *getNode(NodeNum n);
|
||||
|
||||
NodeInfo *getNodeByIndex(size_t x) { assert(x < *numNodes); return &nodes[x]; }
|
||||
NodeInfo *getNodeByIndex(size_t x)
|
||||
{
|
||||
assert(x < *numNodes);
|
||||
return &nodes[x];
|
||||
}
|
||||
|
||||
/// Return the number of nodes we've heard from recently (within the last 2 hrs?)
|
||||
size_t getNumOnlineNodes();
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
/// Find a node in our DB, create an empty NodeInfo if missing
|
||||
NodeInfo *getOrCreateNode(NodeNum n);
|
||||
|
||||
@@ -89,4 +96,3 @@ private:
|
||||
};
|
||||
|
||||
extern NodeDB nodeDB;
|
||||
|
||||
|
||||
@@ -1,13 +1,2 @@
|
||||
#include "Observer.h"
|
||||
|
||||
Observer::~Observer()
|
||||
{
|
||||
if (observed)
|
||||
observed->removeObserver(this);
|
||||
observed = NULL;
|
||||
}
|
||||
|
||||
void Observer::observe(Observable *o)
|
||||
{
|
||||
o->addObserver(this);
|
||||
}
|
||||
104
src/Observer.h
104
src/Observer.h
@@ -4,46 +4,96 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
class Observable;
|
||||
template <class T> class Observable;
|
||||
|
||||
class Observer
|
||||
/**
|
||||
* An observer which can be mixed in as a baseclass. Implement onNotify as a method in your class.
|
||||
*/
|
||||
template <class T> class Observer
|
||||
{
|
||||
Observable *observed;
|
||||
Observable<T> *observed = NULL;
|
||||
|
||||
public:
|
||||
Observer() : observed(NULL) {}
|
||||
public:
|
||||
|
||||
virtual ~Observer();
|
||||
|
||||
void observe(Observable *o);
|
||||
void observe(Observable<T> *o);
|
||||
|
||||
private:
|
||||
friend class Observable;
|
||||
private:
|
||||
friend class Observable<T>;
|
||||
|
||||
virtual void onNotify(Observable *o) = 0;
|
||||
protected:
|
||||
/**
|
||||
* returns 0 if other observers should continue to be called
|
||||
* returns !0 if the observe calls should be aborted and this result code returned for notifyObservers
|
||||
**/
|
||||
virtual int onNotify(T arg) = 0;
|
||||
};
|
||||
|
||||
class Observable
|
||||
/**
|
||||
* An observer that calls an arbitrary method
|
||||
*/
|
||||
template <class Callback, class T> class CallbackObserver : public Observer<T>
|
||||
{
|
||||
std::list<Observer *> observers;
|
||||
typedef int (Callback::*ObserverCallback)(T arg);
|
||||
|
||||
public:
|
||||
void notifyObservers()
|
||||
{
|
||||
for (std::list<Observer *>::const_iterator iterator = observers.begin(); iterator != observers.end(); ++iterator)
|
||||
{
|
||||
(*iterator)->onNotify(this);
|
||||
}
|
||||
}
|
||||
Callback *objPtr;
|
||||
ObserverCallback method;
|
||||
|
||||
void addObserver(Observer *o)
|
||||
{
|
||||
observers.push_back(o);
|
||||
}
|
||||
public:
|
||||
CallbackObserver(Callback *_objPtr, ObserverCallback _method) : objPtr(_objPtr), method(_method) {}
|
||||
|
||||
void removeObserver(Observer *o)
|
||||
{
|
||||
observers.remove(o);
|
||||
}
|
||||
protected:
|
||||
virtual int onNotify(T arg) { return (objPtr->*method)(arg); }
|
||||
};
|
||||
|
||||
/**
|
||||
* An observable class that will notify observers anytime notifyObservers is called. Argument type T can be any type, but for
|
||||
* performance reasons a pointer or word sized object is recommended.
|
||||
*/
|
||||
template <class T> class Observable
|
||||
{
|
||||
std::list<Observer<T> *> observers;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Tell all observers about a change, observers can process arg as they wish
|
||||
*
|
||||
* returns !0 if an observer chose to abort processing by returning this code
|
||||
*/
|
||||
int notifyObservers(T arg)
|
||||
{
|
||||
for (typename std::list<Observer<T> *>::const_iterator iterator = observers.begin(); iterator != observers.end();
|
||||
++iterator) {
|
||||
int result = (*iterator)->onNotify(arg);
|
||||
if (result != 0)
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class Observer<T>;
|
||||
|
||||
// Not called directly, instead call observer.observe
|
||||
void addObserver(Observer<T> *o) { observers.push_back(o); }
|
||||
|
||||
void removeObserver(Observer<T> *o) { observers.remove(o); }
|
||||
};
|
||||
|
||||
template <class T> Observer<T>::~Observer()
|
||||
{
|
||||
if (observed)
|
||||
observed->removeObserver(this);
|
||||
observed = NULL;
|
||||
}
|
||||
|
||||
template <class T> void Observer<T>::observe(Observable<T> *o)
|
||||
{
|
||||
// We can only watch one thing at a time
|
||||
assert(!observed);
|
||||
|
||||
observed = o;
|
||||
o->addObserver(this);
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "PeriodicTask.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
/**
|
||||
* Periodically invoke a callback.
|
||||
*
|
||||
*
|
||||
* This just provides C style callback conventions rather than a virtual function - FIXME, remove?
|
||||
*/
|
||||
class Periodic : public PeriodicTask
|
||||
{
|
||||
uint32_t (*callback)();
|
||||
uint32_t (*callback)();
|
||||
|
||||
public:
|
||||
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
||||
Periodic(uint32_t (*_callback)()) : callback(_callback) {}
|
||||
public:
|
||||
// callback returns the period for the next callback invocation (or 0 if we should no longer be called)
|
||||
Periodic(uint32_t (*_callback)()) : callback(_callback) {}
|
||||
|
||||
protected:
|
||||
|
||||
void doTask();
|
||||
protected:
|
||||
void doTask();
|
||||
};
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
#include "PeriodicTask.h"
|
||||
#include "Periodic.h"
|
||||
|
||||
PeriodicTask::PeriodicTask(uint32_t initialPeriod) : period(initialPeriod)
|
||||
{
|
||||
}
|
||||
PeriodicTask::PeriodicTask(uint32_t initialPeriod) : period(initialPeriod) {}
|
||||
|
||||
/// call this from loop
|
||||
void PeriodicTask::loop()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
if (period && (now - lastMsec) >= period)
|
||||
{
|
||||
meshtastic::LockGuard lg(&lock);
|
||||
uint32_t now = millis();
|
||||
if (!period || (now - lastMsec) < period) {
|
||||
return;
|
||||
}
|
||||
lastMsec = now;
|
||||
doTask();
|
||||
}
|
||||
// Release the lock in case the task wants to change the period.
|
||||
doTask();
|
||||
}
|
||||
|
||||
void Periodic::doTask()
|
||||
{
|
||||
uint32_t p = callback();
|
||||
setPeriod(p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "configuration.h"
|
||||
#include <cstdint>
|
||||
|
||||
#include "lock.h"
|
||||
|
||||
/**
|
||||
* A base class for tasks that want their doTask() method invoked periodically
|
||||
*
|
||||
*
|
||||
* FIXME: currently just syntatic sugar for polling in loop (you must call .loop), but eventually
|
||||
* generalize with the freertos scheduler so we can save lots of power by having everything either in
|
||||
* something like this or triggered off of an irq.
|
||||
@@ -15,9 +16,10 @@ class PeriodicTask
|
||||
uint32_t lastMsec = 0;
|
||||
uint32_t period = 1; // call soon after creation
|
||||
|
||||
public:
|
||||
uint32_t periodMsec;
|
||||
// Protects the above variables.
|
||||
meshtastic::Lock lock;
|
||||
|
||||
public:
|
||||
virtual ~PeriodicTask() {}
|
||||
|
||||
PeriodicTask(uint32_t initialPeriod = 1);
|
||||
@@ -26,8 +28,12 @@ public:
|
||||
virtual void loop();
|
||||
|
||||
/// Set a new period in msecs (can be called from doTask or elsewhere and the scheduler will cope)
|
||||
void setPeriod(uint32_t p) { period = p; }
|
||||
void setPeriod(uint32_t p)
|
||||
{
|
||||
meshtastic::LockGuard lg(&lock);
|
||||
period = p;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void doTask() = 0;
|
||||
};
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
|
||||
#include "sleep.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "GPS.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "configuration.h"
|
||||
#include "screen.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "GPS.h"
|
||||
#include "main.h"
|
||||
#include "screen.h"
|
||||
#include "sleep.h"
|
||||
#include "target_specific.h"
|
||||
|
||||
static void sdsEnter()
|
||||
{
|
||||
@@ -23,27 +24,26 @@ static void sdsEnter()
|
||||
doDeepSleep(radioConfig.preferences.sds_secs * 1000LL);
|
||||
}
|
||||
|
||||
#include "error.h"
|
||||
|
||||
static void lsEnter()
|
||||
{
|
||||
DEBUG_MSG("lsEnter begin, ls_secs=%u\n", radioConfig.preferences.ls_secs);
|
||||
screen.setOn(false);
|
||||
|
||||
while (!service.radio.rf95.canSleep())
|
||||
delay(10); // Kinda yucky - wait until radio says say we can shutdown (finished in process sends/receives)
|
||||
|
||||
gps.prepareSleep(); // abandon in-process parsing
|
||||
|
||||
if (!isUSBPowered) // FIXME - temp hack until we can put gps in sleep mode, if we have AC when we go to sleep then leave GPS on
|
||||
setGPSPower(false); // kill GPS power
|
||||
DEBUG_MSG("lsEnter end\n");
|
||||
}
|
||||
|
||||
static void lsIdle()
|
||||
{
|
||||
DEBUG_MSG("lsIdle begin ls_secs=%u\n", radioConfig.preferences.ls_secs);
|
||||
|
||||
#ifndef NO_ESP32
|
||||
uint32_t secsSlept = 0;
|
||||
esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED;
|
||||
bool reached_ls_secs = false;
|
||||
|
||||
while (!reached_ls_secs)
|
||||
{
|
||||
while (!reached_ls_secs) {
|
||||
// Briefly come out of sleep long enough to blink the led once every few seconds
|
||||
uint32_t sleepTime = 5;
|
||||
|
||||
@@ -62,21 +62,31 @@ static void lsIdle()
|
||||
}
|
||||
setLed(false);
|
||||
|
||||
if (reached_ls_secs)
|
||||
{
|
||||
if (reached_ls_secs) {
|
||||
// stay in LS mode but let loop check whatever it wants
|
||||
DEBUG_MSG("reached ls_secs, servicing loop()\n");
|
||||
} else {
|
||||
DEBUG_MSG("wakeCause %d\n", wakeCause);
|
||||
|
||||
#ifdef BUTTON_PIN
|
||||
bool pressed = !digitalRead(BUTTON_PIN);
|
||||
#else
|
||||
bool pressed = false;
|
||||
#endif
|
||||
if (pressed) // If we woke because of press, instead generate a PRESS event.
|
||||
{
|
||||
powerFSM.trigger(EVENT_PRESS);
|
||||
} else {
|
||||
// Otherwise let the NB state handle the IRQ (and that state will handle stuff like IRQs etc)
|
||||
powerFSM.trigger(EVENT_WAKE_TIMER);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Regardless of why we woke just transition to NB (and that state will handle stuff like IRQs etc)
|
||||
powerFSM.trigger(EVENT_WAKE_TIMER);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void lsExit()
|
||||
{
|
||||
setGPSPower(true); // restore GPS power
|
||||
// setGPSPower(true); // restore GPS power
|
||||
gps.startLock();
|
||||
}
|
||||
|
||||
@@ -90,6 +100,7 @@ static void nbEnter()
|
||||
|
||||
static void darkEnter()
|
||||
{
|
||||
setBluetoothEnable(true);
|
||||
screen.setOn(false);
|
||||
}
|
||||
|
||||
@@ -97,38 +108,47 @@ static void onEnter()
|
||||
{
|
||||
screen.setOn(true);
|
||||
setBluetoothEnable(true);
|
||||
|
||||
static uint32_t lastPingMs;
|
||||
|
||||
uint32_t now = millis();
|
||||
|
||||
if (now - lastPingMs > 60 * 1000) { // if more than a minute since our last press, ask other nodes to update their state
|
||||
service.sendNetworkPing(NODENUM_BROADCAST, true);
|
||||
lastPingMs = now;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void wakeForPing()
|
||||
{
|
||||
}
|
||||
static void wakeForPing() {}
|
||||
|
||||
static void screenPress()
|
||||
{
|
||||
screen.onPress();
|
||||
}
|
||||
|
||||
static void bootEnter() {}
|
||||
|
||||
State stateSDS(sdsEnter, NULL, NULL, "SDS");
|
||||
State stateLS(lsEnter, lsIdle, lsExit, "LS");
|
||||
State stateNB(nbEnter, NULL, NULL, "NB");
|
||||
State stateDARK(darkEnter, NULL, NULL, "DARK");
|
||||
State stateBOOT(bootEnter, NULL, NULL, "BOOT");
|
||||
State stateON(onEnter, NULL, NULL, "ON");
|
||||
Fsm powerFSM(&stateDARK);
|
||||
Fsm powerFSM(&stateBOOT);
|
||||
|
||||
void PowerFSM_setup()
|
||||
{
|
||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot");
|
||||
powerFSM.add_timed_transition(&stateBOOT, &stateON, 3 * 1000, NULL, "boot timeout");
|
||||
|
||||
powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing, "Wake timer");
|
||||
|
||||
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it handles things
|
||||
// powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet");
|
||||
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it
|
||||
// handles things powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet");
|
||||
|
||||
powerFSM.add_transition(&stateNB, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet, resetting win wake");
|
||||
|
||||
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it handles things
|
||||
// powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL, "Press");
|
||||
|
||||
// Handle press events
|
||||
powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL, "Press");
|
||||
powerFSM.add_transition(&stateNB, &stateON, EVENT_PRESS, NULL, "Press");
|
||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_PRESS, NULL, "Press");
|
||||
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress, "Press"); // reenter On to restart our timers
|
||||
@@ -155,10 +175,14 @@ void PowerFSM_setup()
|
||||
|
||||
powerFSM.add_timed_transition(&stateNB, &stateLS, radioConfig.preferences.min_wake_secs * 1000, NULL, "Min wake timeout");
|
||||
|
||||
powerFSM.add_timed_transition(&stateDARK, &stateLS, radioConfig.preferences.wait_bluetooth_secs * 1000, NULL, "Bluetooth timeout");
|
||||
powerFSM.add_timed_transition(&stateDARK, &stateLS, radioConfig.preferences.wait_bluetooth_secs * 1000, NULL,
|
||||
"Bluetooth timeout");
|
||||
|
||||
powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.mesh_sds_timeout_secs * 1000, NULL, "mesh timeout");
|
||||
powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.phone_sds_timeout_sec * 1000, NULL, "phone timeout");
|
||||
powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.mesh_sds_timeout_secs * 1000, NULL,
|
||||
"mesh timeout");
|
||||
// removing for now, because some users don't even have phones
|
||||
// powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.phone_sds_timeout_sec * 1000, NULL, "phone
|
||||
// timeout");
|
||||
|
||||
powerFSM.run_machine(); // run one interation of the state machine, so we run our on enter tasks for the initial DARK state
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <Fsm.h>
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#define EVENT_RECEIVED_PACKET 3
|
||||
#define EVENT_PACKET_FOR_PHONE 4
|
||||
#define EVENT_RECEIVED_TEXT_MSG 5
|
||||
#define EVENT_BOOT 6
|
||||
// #define EVENT_BOOT 6 // now done with a timed transition
|
||||
#define EVENT_BLUETOOTH_PAIR 7
|
||||
#define EVENT_NODEDB_UPDATED 8 // NodeDB has a big enough change that we think you should turn on the screen
|
||||
#define EVENT_NODEDB_UPDATED 8 // NodeDB has a big enough change that we think you should turn on the screen
|
||||
#define EVENT_CONTACT_FROM_PHONE 9 // the phone just talked to us over bluetooth
|
||||
|
||||
extern Fsm powerFSM;
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <assert.h>
|
||||
|
||||
/**
|
||||
* A wrapper for freertos queues. Note: each element object must be quite small, so T should be only
|
||||
* pointer types or ints
|
||||
*/
|
||||
template <class T>
|
||||
class TypedQueue
|
||||
{
|
||||
QueueHandle_t h;
|
||||
|
||||
public:
|
||||
TypedQueue(int maxElements)
|
||||
{
|
||||
h = xQueueCreate(maxElements, sizeof(T));
|
||||
assert(h);
|
||||
}
|
||||
|
||||
~TypedQueue()
|
||||
{
|
||||
vQueueDelete(h);
|
||||
}
|
||||
|
||||
int numFree()
|
||||
{
|
||||
return uxQueueSpacesAvailable(h);
|
||||
}
|
||||
|
||||
bool isEmpty()
|
||||
{
|
||||
return uxQueueMessagesWaiting(h) == 0;
|
||||
}
|
||||
|
||||
// pdTRUE for success else failure
|
||||
BaseType_t enqueue(T x, TickType_t maxWait = portMAX_DELAY)
|
||||
{
|
||||
return xQueueSendToBack(h, &x, maxWait);
|
||||
}
|
||||
|
||||
BaseType_t enqueueFromISR(T x, BaseType_t *higherPriWoken)
|
||||
{
|
||||
return xQueueSendToBackFromISR(h, &x, higherPriWoken);
|
||||
}
|
||||
|
||||
// pdTRUE for success else failure
|
||||
BaseType_t dequeue(T *p, TickType_t maxWait = portMAX_DELAY)
|
||||
{
|
||||
return xQueueReceive(h, p, maxWait);
|
||||
}
|
||||
|
||||
BaseType_t dequeueFromISR(T *p, BaseType_t *higherPriWoken)
|
||||
{
|
||||
return xQueueReceiveFromISR(h, p, higherPriWoken);
|
||||
}
|
||||
};
|
||||
3
src/bare/FS.h
Normal file
3
src/bare/FS.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
// FIXME - make a FS abstraction for NRF52
|
||||
3
src/bare/SPIFFS.h
Normal file
3
src/bare/SPIFFS.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
// FIXME - make a FS abstraction for NRF52
|
||||
6
src/bare/main-bare.cpp
Normal file
6
src/bare/main-bare.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "target_specific.h"
|
||||
|
||||
void setBluetoothEnable(bool on)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
@@ -31,25 +31,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// If app version is not specified we assume we are not being invoked by the build script
|
||||
#ifndef APP_VERSION
|
||||
#define APP_VERSION 0.0.0 // this def normally comes from build-all.sh
|
||||
#define HW_VERSION 1.0 - US // normally comes from build-all.sh and contains the region code
|
||||
#error APP_VERSION, HW_VERSION, and HW_VERSION_countryname must be set by the build environment
|
||||
//#define APP_VERSION 0.0.0 // this def normally comes from build-all.sh
|
||||
//#define HW_VERSION 1.0 - US // normally comes from build-all.sh and contains the region code
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Configuration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Select which board is being used. If the outside build environment has sent a choice, just use that
|
||||
#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32)
|
||||
// #define T_BEAM_V10 // AKA Rev1 (second board released)
|
||||
#define HELTEC_LORA32
|
||||
|
||||
#define HW_VERSION_US // We encode the hardware freq range in the hw version string, so sw update can eventually install the correct build
|
||||
#endif
|
||||
|
||||
// If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled)
|
||||
// we don't support jtag on the ttgo - access to gpio 12 is a PITA
|
||||
#ifdef HELTEC_LORA32
|
||||
#ifdef ARDUINO_HELTEC_WIFI_LORA_32_V2
|
||||
//#define USE_JTAG
|
||||
#endif
|
||||
|
||||
@@ -77,6 +70,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#define SSD1306_ADDRESS 0x3C
|
||||
|
||||
// Flip the screen upside down by default as it makes more sense on T-BEAM
|
||||
// devices. Comment this out to not rotate screen 180 degrees.
|
||||
#define FLIP_SCREEN_VERTICALLY
|
||||
|
||||
// DEBUG LED
|
||||
|
||||
#define LED_INVERTED 0 // define as 1 if LED is active low (on)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// GPS
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -84,14 +85,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define GPS_SERIAL_NUM 1
|
||||
#define GPS_BAUDRATE 9600
|
||||
|
||||
#if defined(T_BEAM_V10)
|
||||
#define GPS_RX_PIN 34
|
||||
#ifdef USE_JTAG
|
||||
#define GPS_TX_PIN -1
|
||||
#else
|
||||
#define GPS_TX_PIN 12
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// LoRa SPI
|
||||
@@ -102,11 +101,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define MOSI_GPIO 27
|
||||
#define NSS_GPIO 18
|
||||
|
||||
#if defined(T_BEAM_V10)
|
||||
#if defined(TBEAM_V10)
|
||||
// This string must exactly match the case used in release file names or the android updater won't work
|
||||
#define HW_VENDOR "TBEAM"
|
||||
#define HW_VENDOR "tbeam"
|
||||
|
||||
#define BICOLOR_DISPLAY // we have yellow at the top 16 lines
|
||||
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep
|
||||
|
||||
#define I2C_SDA 21
|
||||
#define I2C_SCL 22
|
||||
@@ -116,34 +115,114 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#ifndef USE_JTAG
|
||||
#define RESET_GPIO 14
|
||||
#endif
|
||||
#define DIO0_GPIO 26
|
||||
#define RF95_IRQ_GPIO 26
|
||||
#define DIO1_GPIO 33 // Note: not really used on this board
|
||||
#define DIO2_GPIO 32 // Note: not really used on this board
|
||||
|
||||
// Leave undefined to disable our PMU IRQ handler
|
||||
#define PMU_IRQ 35
|
||||
|
||||
#elif defined(HELTEC_LORA32)
|
||||
#elif defined(TBEAM_V07)
|
||||
// This string must exactly match the case used in release file names or the android updater won't work
|
||||
#define HW_VENDOR "HELTEC"
|
||||
#define HW_VENDOR "tbeam0.7"
|
||||
|
||||
#ifndef USE_JTAG // gpio15 is TDO for JTAG, so no I2C on this board while doing jtag
|
||||
#define I2C_SDA 4
|
||||
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep
|
||||
|
||||
#define I2C_SDA 21
|
||||
#define I2C_SCL 22
|
||||
|
||||
#define BUTTON_PIN 39
|
||||
|
||||
#ifndef USE_JTAG
|
||||
#define RESET_GPIO 23
|
||||
#endif
|
||||
#define RF95_IRQ_GPIO 26
|
||||
#define DIO1_GPIO 33 // Note: not really used on this board
|
||||
#define DIO2_GPIO 32 // Note: not really used on this board
|
||||
|
||||
// This board has different GPS pins than all other boards
|
||||
#undef GPS_RX_PIN
|
||||
#undef GPS_TX_PIN
|
||||
#define GPS_RX_PIN 12
|
||||
#define GPS_TX_PIN 15
|
||||
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2)
|
||||
// This string must exactly match the case used in release file names or the android updater won't work
|
||||
#define HW_VENDOR "heltec"
|
||||
|
||||
#ifndef USE_JTAG // gpio15 is TDO for JTAG, so no I2C on this board while doing jtag
|
||||
#define I2C_SDA 4 // I2C pins for this board
|
||||
#define I2C_SCL 15
|
||||
#endif
|
||||
|
||||
#define RESET_OLED 16
|
||||
#define RESET_OLED 16 // If defined, this pin will be used to reset the display controller
|
||||
|
||||
#define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost
|
||||
#define LED_PIN 25
|
||||
#define BUTTON_PIN 0
|
||||
#define LED_PIN 25 // If defined we will blink this LED
|
||||
#define BUTTON_PIN 0 // If defined, this will be used for user button presses
|
||||
|
||||
#ifndef USE_JTAG
|
||||
#define RESET_GPIO 14
|
||||
#define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio
|
||||
#endif
|
||||
#define DIO0_GPIO 26
|
||||
#define DIO1_GPIO 35
|
||||
#define DIO2_GPIO 34
|
||||
#define RF95_IRQ_GPIO 26
|
||||
#define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
|
||||
#define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
|
||||
#elif defined(TTGO_LORA_V1)
|
||||
// This string must exactly match the case used in release file names or the android updater won't work
|
||||
#define HW_VENDOR "ttgo-lora32-v1"
|
||||
|
||||
#define I2C_SDA 4 // I2C pins for this board
|
||||
#define I2C_SCL 15
|
||||
|
||||
#define RESET_OLED 16 // If defined, this pin will be used to reset the display controller
|
||||
|
||||
// #define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost
|
||||
#define LED_PIN 2 // If defined we will blink this LED
|
||||
#define BUTTON_PIN 0 // If defined, this will be used for user button presses
|
||||
|
||||
#define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio
|
||||
#define RF95_IRQ_GPIO 26 // IRQ line for the LORA radio
|
||||
#define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
|
||||
#define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
|
||||
#elif defined(TTGO_LORA_V2)
|
||||
// This string must exactly match the case used in release file names or the android updater won't work
|
||||
#define HW_VENDOR "ttgo-lora32-v2"
|
||||
|
||||
#define I2C_SDA 21 // I2C pins for this board
|
||||
#define I2C_SCL 22
|
||||
|
||||
#define RESET_OLED 16 // If defined, this pin will be used to reset the display controller
|
||||
|
||||
#define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost
|
||||
#define LED_PIN 25 // If defined we will blink this LED
|
||||
#define BUTTON_PIN \
|
||||
0 // If defined, this will be used for user button presses, if your board doesn't have a physical switch, you can wire one
|
||||
// between this pin and ground
|
||||
|
||||
#define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio
|
||||
#define RF95_IRQ_GPIO 26 // IRQ line for the LORA radio
|
||||
#define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
|
||||
#define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
|
||||
#elif defined(BARE_BOARD)
|
||||
// This string must exactly match the case used in release file names or the android updater won't work
|
||||
#define HW_VENDOR "bare"
|
||||
|
||||
#define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
|
||||
|
||||
// Turn off GPS code for now
|
||||
#undef GPS_RX_PIN
|
||||
#undef GPS_TX_PIN
|
||||
|
||||
// FIXME, not yet ready for NRF52
|
||||
#define RTC_DATA_ATTR
|
||||
|
||||
#define LED_PIN PIN_LED1 // LED1 on nrf52840-DK
|
||||
#define BUTTON_PIN PIN_BUTTON1
|
||||
|
||||
// This board uses 0 to be mean LED on
|
||||
#undef LED_INVERTED
|
||||
#define LED_INVERTED 1
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
20
src/debug.cpp
Normal file
20
src/debug.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "debug.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "freertosinc.h"
|
||||
#include "configuration.h"
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
||||
void printThreadInfo(const char *extra)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
uint32_t taskHandle = reinterpret_cast<uint32_t>(xTaskGetCurrentTaskHandle());
|
||||
DEBUG_MSG("printThreadInfo(%s) task: %" PRIx32 " core id: %u min free stack: %u\n", extra, taskHandle, xPortGetCoreID(),
|
||||
uxTaskGetStackHighWaterMark(nullptr));
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace meshtastic
|
||||
10
src/debug.h
Normal file
10
src/debug.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
||||
/// Dumps out which core we are running on, and min level of remaining stack
|
||||
/// seen.
|
||||
void printThreadInfo(const char *extra);
|
||||
|
||||
} // namespace meshtastic
|
||||
9
src/error.h
Normal file
9
src/error.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/// Error codes for critical error
|
||||
enum CriticalErrorCode { NoError, ErrTxWatchdog, ErrSleepEnterWait, ErrNoRadio };
|
||||
|
||||
/// Record an error that should be reported via analytics
|
||||
void recordCriticalError(CriticalErrorCode code, uint32_t address = 0);
|
||||
@@ -1,19 +1,22 @@
|
||||
#include "BluetoothUtil.h"
|
||||
#include "MeshBluetoothService.h"
|
||||
#include <esp_gatt_defs.h>
|
||||
#include <BLE2902.h>
|
||||
#include "BluetoothUtil.h"
|
||||
#include <Arduino.h>
|
||||
#include <BLE2902.h>
|
||||
#include <assert.h>
|
||||
#include <esp_gatt_defs.h>
|
||||
|
||||
#include "mesh.pb.h"
|
||||
#include "MeshService.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
#include "NodeDB.h"
|
||||
#include "configuration.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "CallbackCharacteristic.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "configuration.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
#include "mesh.pb.h"
|
||||
|
||||
// This scratch buffer is used for various bluetooth reads/writes - but it is safe because only one bt operation can be in proccess at once
|
||||
#include "GPS.h"
|
||||
|
||||
// This scratch buffer is used for various bluetooth reads/writes - but it is safe because only one bt operation can be in
|
||||
// proccess at once
|
||||
static uint8_t trBytes[_max(_max(_max(_max(ToRadio_size, RadioConfig_size), User_size), MyNodeInfo_size), FromRadio_size)];
|
||||
|
||||
class ProtobufCharacteristic : public CallbackCharacteristic
|
||||
@@ -21,11 +24,9 @@ class ProtobufCharacteristic : public CallbackCharacteristic
|
||||
const pb_msgdesc_t *fields;
|
||||
void *my_struct;
|
||||
|
||||
public:
|
||||
public:
|
||||
ProtobufCharacteristic(const char *uuid, uint32_t btprops, const pb_msgdesc_t *_fields, void *_my_struct)
|
||||
: CallbackCharacteristic(uuid, btprops),
|
||||
fields(_fields),
|
||||
my_struct(_my_struct)
|
||||
: CallbackCharacteristic(uuid, btprops), fields(_fields), my_struct(_my_struct)
|
||||
{
|
||||
setCallbacks(this);
|
||||
}
|
||||
@@ -44,7 +45,7 @@ public:
|
||||
writeToDest(c, my_struct);
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/// like onWrite, but we provide an different destination to write to, for use by subclasses that
|
||||
/// want to optionally ignore parts of writes.
|
||||
/// returns true for success
|
||||
@@ -59,9 +60,10 @@ protected:
|
||||
|
||||
class NodeInfoCharacteristic : public BLECharacteristic, public BLEKeepAliveCallbacks
|
||||
{
|
||||
public:
|
||||
public:
|
||||
NodeInfoCharacteristic()
|
||||
: BLECharacteristic("d31e02e0-c8ab-4d3f-9cc9-0b8466bdabe8", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ)
|
||||
: BLECharacteristic("d31e02e0-c8ab-4d3f-9cc9-0b8466bdabe8",
|
||||
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ)
|
||||
{
|
||||
setCallbacks(this);
|
||||
}
|
||||
@@ -72,14 +74,12 @@ public:
|
||||
|
||||
const NodeInfo *info = nodeDB.readNextInfo();
|
||||
|
||||
if (info)
|
||||
{
|
||||
DEBUG_MSG("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->position.time, info->user.id, info->user.long_name);
|
||||
if (info) {
|
||||
DEBUG_MSG("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->position.time, info->user.id,
|
||||
info->user.long_name);
|
||||
size_t numbytes = pb_encode_to_bytes(trBytes, sizeof(trBytes), NodeInfo_fields, info);
|
||||
c->setValue(trBytes, numbytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
c->setValue(trBytes, 0); // Send an empty response
|
||||
DEBUG_MSG("Done sending nodeinfos\n");
|
||||
}
|
||||
@@ -96,14 +96,23 @@ public:
|
||||
// wrap our protobuf version with something that forces the service to reload the config
|
||||
class RadioCharacteristic : public ProtobufCharacteristic
|
||||
{
|
||||
public:
|
||||
public:
|
||||
RadioCharacteristic()
|
||||
: ProtobufCharacteristic("b56786c8-839a-44a1-b98e-a1724c4a0262", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, RadioConfig_fields, &radioConfig)
|
||||
: ProtobufCharacteristic("b56786c8-839a-44a1-b98e-a1724c4a0262",
|
||||
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, RadioConfig_fields,
|
||||
&radioConfig)
|
||||
{
|
||||
}
|
||||
|
||||
void onRead(BLECharacteristic *c)
|
||||
{
|
||||
DEBUG_MSG("Reading radio config, sdsecs %u\n", radioConfig.preferences.sds_secs);
|
||||
ProtobufCharacteristic::onRead(c);
|
||||
}
|
||||
|
||||
void onWrite(BLECharacteristic *c)
|
||||
{
|
||||
DEBUG_MSG("Writing radio config\n");
|
||||
ProtobufCharacteristic::onWrite(c);
|
||||
service.reloadConfig();
|
||||
}
|
||||
@@ -112,33 +121,31 @@ public:
|
||||
// wrap our protobuf version with something that forces the service to reload the owner
|
||||
class OwnerCharacteristic : public ProtobufCharacteristic
|
||||
{
|
||||
public:
|
||||
public:
|
||||
OwnerCharacteristic()
|
||||
: ProtobufCharacteristic("6ff1d8b6-e2de-41e3-8c0b-8fa384f64eb6", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, User_fields, &owner)
|
||||
: ProtobufCharacteristic("6ff1d8b6-e2de-41e3-8c0b-8fa384f64eb6",
|
||||
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ, User_fields, &owner)
|
||||
{
|
||||
}
|
||||
|
||||
void onWrite(BLECharacteristic *c)
|
||||
{
|
||||
BLEKeepAliveCallbacks::onWrite(c); // NOTE: We do not call the standard ProtobufCharacteristic superclass, because we want custom write behavior
|
||||
BLEKeepAliveCallbacks::onWrite(
|
||||
c); // NOTE: We do not call the standard ProtobufCharacteristic superclass, because we want custom write behavior
|
||||
|
||||
static User o; // if the phone doesn't set ID we are careful to keep ours, we also always keep our macaddr
|
||||
if (writeToDest(c, &o))
|
||||
{
|
||||
if (writeToDest(c, &o)) {
|
||||
int changed = 0;
|
||||
|
||||
if (*o.long_name)
|
||||
{
|
||||
if (*o.long_name) {
|
||||
changed |= strcmp(owner.long_name, o.long_name);
|
||||
strcpy(owner.long_name, o.long_name);
|
||||
}
|
||||
if (*o.short_name)
|
||||
{
|
||||
if (*o.short_name) {
|
||||
changed |= strcmp(owner.short_name, o.short_name);
|
||||
strcpy(owner.short_name, o.short_name);
|
||||
}
|
||||
if (*o.id)
|
||||
{
|
||||
if (*o.id) {
|
||||
changed |= strcmp(owner.id, o.id);
|
||||
strcpy(owner.id, o.id);
|
||||
}
|
||||
@@ -151,11 +158,8 @@ public:
|
||||
|
||||
class ToRadioCharacteristic : public CallbackCharacteristic
|
||||
{
|
||||
public:
|
||||
ToRadioCharacteristic()
|
||||
: CallbackCharacteristic("f75c76d2-129e-4dad-a1dd-7866124401e7", BLECharacteristic::PROPERTY_WRITE)
|
||||
{
|
||||
}
|
||||
public:
|
||||
ToRadioCharacteristic() : CallbackCharacteristic("f75c76d2-129e-4dad-a1dd-7866124401e7", BLECharacteristic::PROPERTY_WRITE) {}
|
||||
|
||||
void onWrite(BLECharacteristic *c)
|
||||
{
|
||||
@@ -168,9 +172,8 @@ public:
|
||||
|
||||
class FromRadioCharacteristic : public CallbackCharacteristic
|
||||
{
|
||||
public:
|
||||
FromRadioCharacteristic()
|
||||
: CallbackCharacteristic("8ba2bcc2-ee02-4a55-a531-c525c5e454d5", BLECharacteristic::PROPERTY_READ)
|
||||
public:
|
||||
FromRadioCharacteristic() : CallbackCharacteristic("8ba2bcc2-ee02-4a55-a531-c525c5e454d5", BLECharacteristic::PROPERTY_READ)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -181,13 +184,10 @@ public:
|
||||
|
||||
// Someone is going to read our value as soon as this callback returns. So fill it with the next message in the queue
|
||||
// or make empty if the queue is empty
|
||||
if (!mp)
|
||||
{
|
||||
if (!mp) {
|
||||
DEBUG_MSG("toPhone queue is empty\n");
|
||||
c->setValue((uint8_t *)"", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
static FromRadio fRadio;
|
||||
|
||||
// Encapsulate as a FromRadio packet
|
||||
@@ -204,13 +204,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class FromNumCharacteristic : public CallbackCharacteristic
|
||||
class FromNumCharacteristic : public CallbackCharacteristic, public Observer<uint32_t>
|
||||
{
|
||||
public:
|
||||
public:
|
||||
FromNumCharacteristic()
|
||||
: CallbackCharacteristic("ed9da18c-a800-4f66-a670-aa7547e34453",
|
||||
BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY)
|
||||
: CallbackCharacteristic("ed9da18c-a800-4f66-a670-aa7547e34453", BLECharacteristic::PROPERTY_WRITE |
|
||||
BLECharacteristic::PROPERTY_READ |
|
||||
BLECharacteristic::PROPERTY_NOTIFY)
|
||||
{
|
||||
observe(&service.fromNumChanged);
|
||||
}
|
||||
|
||||
void onRead(BLECharacteristic *c)
|
||||
@@ -218,85 +220,48 @@ public:
|
||||
BLEKeepAliveCallbacks::onRead(c);
|
||||
DEBUG_MSG("FIXME implement fromnum read\n");
|
||||
}
|
||||
|
||||
/// If the mesh service tells us fromNum has changed, tell the phone
|
||||
virtual int onNotify(uint32_t newValue)
|
||||
{
|
||||
setValue(newValue);
|
||||
notify();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class MyNodeInfoCharacteristic : public ProtobufCharacteristic
|
||||
{
|
||||
public:
|
||||
MyNodeInfoCharacteristic()
|
||||
: ProtobufCharacteristic("ea9f3f82-8dc4-4733-9452-1f6da28892a2", BLECharacteristic::PROPERTY_READ, MyNodeInfo_fields,
|
||||
&myNodeInfo)
|
||||
{
|
||||
}
|
||||
|
||||
void onRead(BLECharacteristic *c)
|
||||
{
|
||||
// update gps connection state
|
||||
myNodeInfo.has_gps = gps.isConnected;
|
||||
|
||||
ProtobufCharacteristic::onRead(c);
|
||||
|
||||
myNodeInfo.error_code = 0; // The phone just read us, so throw it away
|
||||
myNodeInfo.error_address = 0;
|
||||
}
|
||||
};
|
||||
|
||||
FromNumCharacteristic *meshFromNumCharacteristic;
|
||||
|
||||
/**
|
||||
* Tell any bluetooth clients that the number of rx packets has changed
|
||||
*/
|
||||
void bluetoothNotifyFromNum(uint32_t newValue)
|
||||
{
|
||||
if (meshFromNumCharacteristic)
|
||||
{
|
||||
// if bt not running ignore
|
||||
meshFromNumCharacteristic->setValue(newValue);
|
||||
meshFromNumCharacteristic->notify();
|
||||
}
|
||||
}
|
||||
|
||||
BLEService *meshService;
|
||||
|
||||
/*
|
||||
MeshBluetoothService UUID 6ba1b218-15a8-461f-9fa8-5dcae273eafd
|
||||
|
||||
FIXME - notify vs indication for fromradio output. Using notify for now, not sure if that is best
|
||||
FIXME - in the esp32 mesh managment code, occasionally mirror the current net db to flash, so that if we reboot we still have a good guess of users who are out there.
|
||||
FIXME - make sure this protocol is guaranteed robust and won't drop packets
|
||||
|
||||
"According to the BLE specification the notification length can be max ATT_MTU - 3. The 3 bytes subtracted is the 3-byte header(OP-code (operation, 1 byte) and the attribute handle (2 bytes)).
|
||||
In BLE 4.1 the ATT_MTU is 23 bytes (20 bytes for payload), but in BLE 4.2 the ATT_MTU can be negotiated up to 247 bytes."
|
||||
|
||||
MAXPACKET is 256? look into what the lora lib uses. FIXME
|
||||
|
||||
Characteristics:
|
||||
UUID
|
||||
properties
|
||||
description
|
||||
|
||||
8ba2bcc2-ee02-4a55-a531-c525c5e454d5
|
||||
read
|
||||
fromradio - contains a newly received packet destined towards the phone (up to MAXPACKET bytes? per packet).
|
||||
After reading the esp32 will put the next packet in this mailbox. If the FIFO is empty it will put an empty packet in this
|
||||
mailbox.
|
||||
|
||||
f75c76d2-129e-4dad-a1dd-7866124401e7
|
||||
write
|
||||
toradio - write ToRadio protobufs to this charstic to send them (up to MAXPACKET len)
|
||||
|
||||
ed9da18c-a800-4f66-a670-aa7547e34453
|
||||
read|notify|write
|
||||
fromnum - the current packet # in the message waiting inside fromradio, if the phone sees this notify it should read messages
|
||||
until it catches up with this number.
|
||||
The phone can write to this register to go backwards up to FIXME packets, to handle the rare case of a fromradio packet was dropped after the esp32
|
||||
callback was called, but before it arrives at the phone. If the phone writes to this register the esp32 will discard older packets and put the next packet >= fromnum in fromradio.
|
||||
When the esp32 advances fromnum, it will delay doing the notify by 100ms, in the hopes that the notify will never actally need to be sent if the phone is already pulling from fromradio.
|
||||
Note: that if the phone ever sees this number decrease, it means the esp32 has rebooted.
|
||||
|
||||
meshMyNodeCharacteristic("ea9f3f82-8dc4-4733-9452-1f6da28892a2", BLECharacteristic::PROPERTY_READ)
|
||||
mynode - read this to access a MyNodeInfo protobuf
|
||||
|
||||
meshNodeInfoCharacteristic("d31e02e0-c8ab-4d3f-9cc9-0b8466bdabe8", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ),
|
||||
nodeinfo - read this to get a series of node infos (ending with a null empty record), write to this to restart the read statemachine that returns all the node infos
|
||||
|
||||
meshRadioCharacteristic("b56786c8-839a-44a1-b98e-a1724c4a0262", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ),
|
||||
radio - read/write this to access a RadioConfig protobuf
|
||||
|
||||
meshOwnerCharacteristic("6ff1d8b6-e2de-41e3-8c0b-8fa384f64eb6", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_READ)
|
||||
owner - read/write this to access a User protobuf
|
||||
|
||||
Re: queue management
|
||||
Not all messages are kept in the fromradio queue (filtered based on SubPacket):
|
||||
* only the most recent Position and User messages for a particular node are kept
|
||||
* all Data SubPackets are kept
|
||||
* No WantNodeNum / DenyNodeNum messages are kept
|
||||
A variable keepAllPackets, if set to true will suppress this behavior and instead keep everything for forwarding to the phone (for debugging)
|
||||
|
||||
See bluetooth-api.md for documentation.
|
||||
*/
|
||||
BLEService *createMeshBluetoothService(BLEServer *server)
|
||||
{
|
||||
// Create the BLE Service, we need more than the default of 15 handles
|
||||
BLEService *service = server->createService(BLEUUID("6ba1b218-15a8-461f-9fa8-5dcae273eafd"), 25, 0);
|
||||
BLEService *service = server->createService(BLEUUID("6ba1b218-15a8-461f-9fa8-5dcae273eafd"), 30, 0);
|
||||
|
||||
assert(!meshFromNumCharacteristic);
|
||||
meshFromNumCharacteristic = new FromNumCharacteristic;
|
||||
@@ -304,8 +269,7 @@ BLEService *createMeshBluetoothService(BLEServer *server)
|
||||
addWithDesc(service, meshFromNumCharacteristic, "fromRadio");
|
||||
addWithDesc(service, new ToRadioCharacteristic, "toRadio");
|
||||
addWithDesc(service, new FromRadioCharacteristic, "fromNum");
|
||||
|
||||
addWithDesc(service, new ProtobufCharacteristic("ea9f3f82-8dc4-4733-9452-1f6da28892a2", BLECharacteristic::PROPERTY_READ, MyNodeInfo_fields, &myNodeInfo), "myNode");
|
||||
addWithDesc(service, new MyNodeInfoCharacteristic, "myNode");
|
||||
addWithDesc(service, new RadioCharacteristic, "radio");
|
||||
addWithDesc(service, new OwnerCharacteristic, "owner");
|
||||
addWithDesc(service, new NodeInfoCharacteristic, "nodeinfo");
|
||||
@@ -316,8 +280,7 @@ BLEService *createMeshBluetoothService(BLEServer *server)
|
||||
|
||||
// We only add to advertisting once, because the ESP32 arduino code is dumb and that object never dies
|
||||
static bool firstTime = true;
|
||||
if (firstTime)
|
||||
{
|
||||
if (firstTime) {
|
||||
firstTime = false;
|
||||
server->getAdvertising()->addServiceUUID(service->getUUID());
|
||||
}
|
||||
@@ -335,8 +298,6 @@ void stopMeshBluetoothService()
|
||||
meshService->stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroyMeshBluetoothService()
|
||||
{
|
||||
assert(meshService);
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <BLEService.h>
|
||||
#include <BLEServer.h>
|
||||
#include <Arduino.h>
|
||||
#include <BLEServer.h>
|
||||
#include <BLEService.h>
|
||||
|
||||
BLEService *createMeshBluetoothService(BLEServer* server);
|
||||
BLEService *createMeshBluetoothService(BLEServer *server);
|
||||
void destroyMeshBluetoothService();
|
||||
|
||||
/**
|
||||
53
src/esp32/main-esp32.cpp
Normal file
53
src/esp32/main-esp32.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "BluetoothUtil.h"
|
||||
#include "MeshBluetoothService.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
#include "target_specific.h"
|
||||
|
||||
bool bluetoothOn;
|
||||
|
||||
// This routine is called multiple times, once each time we come back from sleep
|
||||
void reinitBluetooth()
|
||||
{
|
||||
DEBUG_MSG("Starting bluetooth\n");
|
||||
|
||||
// FIXME - we are leaking like crazy
|
||||
// AllocatorScope scope(btPool);
|
||||
|
||||
// Note: these callbacks might be coming in from a different thread.
|
||||
BLEServer *serve = initBLE(
|
||||
[](uint32_t pin) {
|
||||
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
|
||||
screen.startBluetoothPinScreen(pin);
|
||||
},
|
||||
[]() { screen.stopBluetoothPinScreen(); }, getDeviceName(), HW_VENDOR, xstr(APP_VERSION),
|
||||
xstr(HW_VERSION)); // FIXME, use a real name based on the macaddr
|
||||
createMeshBluetoothService(serve);
|
||||
|
||||
// Start advertising - this must be done _after_ creating all services
|
||||
serve->getAdvertising()->start();
|
||||
}
|
||||
|
||||
// Enable/disable bluetooth.
|
||||
void setBluetoothEnable(bool on)
|
||||
{
|
||||
if (on != bluetoothOn) {
|
||||
DEBUG_MSG("Setting bluetooth enable=%d\n", on);
|
||||
|
||||
bluetoothOn = on;
|
||||
if (on) {
|
||||
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
|
||||
// ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
||||
reinitBluetooth();
|
||||
} else {
|
||||
// We have to totally teardown our bluetooth objects to prevent leaks
|
||||
stopMeshBluetoothService(); // Must do before shutting down bluetooth
|
||||
deinitBLE();
|
||||
destroyMeshBluetoothService(); // must do after deinit, because it frees our service
|
||||
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
|
||||
// ESP_ERROR_CHECK( heap_trace_stop() );
|
||||
// heap_trace_dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
838
src/fonts.h
838
src/fonts.h
@@ -1,423 +1,423 @@
|
||||
const uint8_t Custom_ArialMT_Plain_10[] PROGMEM = {
|
||||
0x0A, // Width: 10
|
||||
0x0A, // Height: 10
|
||||
0x20, // First Char: 32
|
||||
0xE0, // Numbers of Chars: 224
|
||||
0x0A, // Width: 10
|
||||
0x0A, // Height: 10
|
||||
0x20, // First Char: 32
|
||||
0xE0, // Numbers of Chars: 224
|
||||
|
||||
// Jump Table:
|
||||
0xFF, 0xFF, 0x00, 0x03, // 32:65535
|
||||
0x00, 0x00, 0x04, 0x03, // 33:0
|
||||
0x00, 0x04, 0x05, 0x04, // 34:4
|
||||
0x00, 0x09, 0x09, 0x06, // 35:9
|
||||
0x00, 0x12, 0x0A, 0x06, // 36:18
|
||||
0x00, 0x1C, 0x10, 0x09, // 37:28
|
||||
0x00, 0x2C, 0x0E, 0x07, // 38:44
|
||||
0x00, 0x3A, 0x01, 0x02, // 39:58
|
||||
0x00, 0x3B, 0x06, 0x03, // 40:59
|
||||
0x00, 0x41, 0x06, 0x03, // 41:65
|
||||
0x00, 0x47, 0x05, 0x04, // 42:71
|
||||
0x00, 0x4C, 0x09, 0x06, // 43:76
|
||||
0x00, 0x55, 0x04, 0x03, // 44:85
|
||||
0x00, 0x59, 0x03, 0x03, // 45:89
|
||||
0x00, 0x5C, 0x04, 0x03, // 46:92
|
||||
0x00, 0x60, 0x05, 0x03, // 47:96
|
||||
0x00, 0x65, 0x0A, 0x06, // 48:101
|
||||
0x00, 0x6F, 0x08, 0x06, // 49:111
|
||||
0x00, 0x77, 0x0A, 0x06, // 50:119
|
||||
0x00, 0x81, 0x0A, 0x06, // 51:129
|
||||
0x00, 0x8B, 0x0B, 0x06, // 52:139
|
||||
0x00, 0x96, 0x0A, 0x06, // 53:150
|
||||
0x00, 0xA0, 0x0A, 0x06, // 54:160
|
||||
0x00, 0xAA, 0x09, 0x06, // 55:170
|
||||
0x00, 0xB3, 0x0A, 0x06, // 56:179
|
||||
0x00, 0xBD, 0x0A, 0x06, // 57:189
|
||||
0x00, 0xC7, 0x04, 0x03, // 58:199
|
||||
0x00, 0xCB, 0x04, 0x03, // 59:203
|
||||
0x00, 0xCF, 0x0A, 0x06, // 60:207
|
||||
0x00, 0xD9, 0x09, 0x06, // 61:217
|
||||
0x00, 0xE2, 0x09, 0x06, // 62:226
|
||||
0x00, 0xEB, 0x0B, 0x06, // 63:235
|
||||
0x00, 0xF6, 0x14, 0x0A, // 64:246
|
||||
0x01, 0x0A, 0x0E, 0x07, // 65:266
|
||||
0x01, 0x18, 0x0C, 0x07, // 66:280
|
||||
0x01, 0x24, 0x0C, 0x07, // 67:292
|
||||
0x01, 0x30, 0x0B, 0x07, // 68:304
|
||||
0x01, 0x3B, 0x0C, 0x07, // 69:315
|
||||
0x01, 0x47, 0x09, 0x06, // 70:327
|
||||
0x01, 0x50, 0x0D, 0x08, // 71:336
|
||||
0x01, 0x5D, 0x0C, 0x07, // 72:349
|
||||
0x01, 0x69, 0x04, 0x03, // 73:361
|
||||
0x01, 0x6D, 0x08, 0x05, // 74:365
|
||||
0x01, 0x75, 0x0E, 0x07, // 75:373
|
||||
0x01, 0x83, 0x0C, 0x06, // 76:387
|
||||
0x01, 0x8F, 0x10, 0x08, // 77:399
|
||||
0x01, 0x9F, 0x0C, 0x07, // 78:415
|
||||
0x01, 0xAB, 0x0E, 0x08, // 79:427
|
||||
0x01, 0xB9, 0x0B, 0x07, // 80:441
|
||||
0x01, 0xC4, 0x0E, 0x08, // 81:452
|
||||
0x01, 0xD2, 0x0C, 0x07, // 82:466
|
||||
0x01, 0xDE, 0x0C, 0x07, // 83:478
|
||||
0x01, 0xEA, 0x0B, 0x06, // 84:490
|
||||
0x01, 0xF5, 0x0C, 0x07, // 85:501
|
||||
0x02, 0x01, 0x0D, 0x07, // 86:513
|
||||
0x02, 0x0E, 0x11, 0x09, // 87:526
|
||||
0x02, 0x1F, 0x0E, 0x07, // 88:543
|
||||
0x02, 0x2D, 0x0D, 0x07, // 89:557
|
||||
0x02, 0x3A, 0x0C, 0x06, // 90:570
|
||||
0x02, 0x46, 0x06, 0x03, // 91:582
|
||||
0x02, 0x4C, 0x06, 0x03, // 92:588
|
||||
0x02, 0x52, 0x04, 0x03, // 93:594
|
||||
0x02, 0x56, 0x09, 0x05, // 94:598
|
||||
0x02, 0x5F, 0x0C, 0x06, // 95:607
|
||||
0x02, 0x6B, 0x03, 0x03, // 96:619
|
||||
0x02, 0x6E, 0x0A, 0x06, // 97:622
|
||||
0x02, 0x78, 0x0A, 0x06, // 98:632
|
||||
0x02, 0x82, 0x0A, 0x05, // 99:642
|
||||
0x02, 0x8C, 0x0A, 0x06, // 100:652
|
||||
0x02, 0x96, 0x0A, 0x06, // 101:662
|
||||
0x02, 0xA0, 0x05, 0x03, // 102:672
|
||||
0x02, 0xA5, 0x0A, 0x06, // 103:677
|
||||
0x02, 0xAF, 0x0A, 0x06, // 104:687
|
||||
0x02, 0xB9, 0x04, 0x02, // 105:697
|
||||
0x02, 0xBD, 0x04, 0x02, // 106:701
|
||||
0x02, 0xC1, 0x08, 0x05, // 107:705
|
||||
0x02, 0xC9, 0x04, 0x02, // 108:713
|
||||
0x02, 0xCD, 0x10, 0x08, // 109:717
|
||||
0x02, 0xDD, 0x0A, 0x06, // 110:733
|
||||
0x02, 0xE7, 0x0A, 0x06, // 111:743
|
||||
0x02, 0xF1, 0x0A, 0x06, // 112:753
|
||||
0x02, 0xFB, 0x0A, 0x06, // 113:763
|
||||
0x03, 0x05, 0x05, 0x03, // 114:773
|
||||
0x03, 0x0A, 0x08, 0x05, // 115:778
|
||||
0x03, 0x12, 0x06, 0x03, // 116:786
|
||||
0x03, 0x18, 0x0A, 0x06, // 117:792
|
||||
0x03, 0x22, 0x09, 0x05, // 118:802
|
||||
0x03, 0x2B, 0x0E, 0x07, // 119:811
|
||||
0x03, 0x39, 0x0A, 0x05, // 120:825
|
||||
0x03, 0x43, 0x09, 0x05, // 121:835
|
||||
0x03, 0x4C, 0x0A, 0x05, // 122:844
|
||||
0x03, 0x56, 0x06, 0x03, // 123:854
|
||||
0x03, 0x5C, 0x04, 0x03, // 124:860
|
||||
0x03, 0x60, 0x05, 0x03, // 125:864
|
||||
0x03, 0x65, 0x09, 0x06, // 126:869
|
||||
0xFF, 0xFF, 0x00, 0x00, // 127:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 128:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 129:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 130:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 131:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 132:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 133:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 134:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 135:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 136:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 137:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 138:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 139:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 140:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 141:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 142:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 143:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 144:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 145:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 146:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 147:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 148:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 149:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 150:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 151:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 152:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 153:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 154:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 155:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 156:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 157:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 158:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 159:65535
|
||||
0xFF, 0xFF, 0x00, 0x03, // 160:65535
|
||||
0x03, 0x6E, 0x04, 0x03, // 161:878
|
||||
0x03, 0x72, 0x0A, 0x06, // 162:882
|
||||
0x03, 0x7C, 0x0C, 0x06, // 163:892
|
||||
0x03, 0x88, 0x0A, 0x06, // 164:904
|
||||
0x03, 0x92, 0x0A, 0x06, // 165:914
|
||||
0x03, 0x9C, 0x04, 0x03, // 166:924
|
||||
0x03, 0xA0, 0x0A, 0x06, // 167:928
|
||||
0x03, 0xAA, 0x05, 0x03, // 168:938
|
||||
0x03, 0xAF, 0x0D, 0x07, // 169:943
|
||||
0x03, 0xBC, 0x07, 0x04, // 170:956
|
||||
0x03, 0xC3, 0x0A, 0x06, // 171:963
|
||||
0x03, 0xCD, 0x09, 0x06, // 172:973
|
||||
0x03, 0xD6, 0x03, 0x03, // 173:982
|
||||
0x03, 0xD9, 0x0D, 0x07, // 174:985
|
||||
0x03, 0xE6, 0x0B, 0x06, // 175:998
|
||||
0x03, 0xF1, 0x07, 0x04, // 176:1009
|
||||
0x03, 0xF8, 0x0A, 0x05, // 177:1016
|
||||
0x04, 0x02, 0x05, 0x03, // 178:1026
|
||||
0x04, 0x07, 0x05, 0x03, // 179:1031
|
||||
0x04, 0x0C, 0x05, 0x03, // 180:1036
|
||||
0x04, 0x11, 0x0A, 0x06, // 181:1041
|
||||
0x04, 0x1B, 0x09, 0x05, // 182:1051
|
||||
0x04, 0x24, 0x03, 0x03, // 183:1060
|
||||
0x04, 0x27, 0x06, 0x03, // 184:1063
|
||||
0x04, 0x2D, 0x05, 0x03, // 185:1069
|
||||
0x04, 0x32, 0x07, 0x04, // 186:1074
|
||||
0x04, 0x39, 0x0A, 0x06, // 187:1081
|
||||
0x04, 0x43, 0x10, 0x08, // 188:1091
|
||||
0x04, 0x53, 0x10, 0x08, // 189:1107
|
||||
0x04, 0x63, 0x10, 0x08, // 190:1123
|
||||
0x04, 0x73, 0x0A, 0x06, // 191:1139
|
||||
0x04, 0x7D, 0x0E, 0x07, // 192:1149
|
||||
0x04, 0x8B, 0x0E, 0x07, // 193:1163
|
||||
0x04, 0x99, 0x0E, 0x07, // 194:1177
|
||||
0x04, 0xA7, 0x0E, 0x07, // 195:1191
|
||||
0x04, 0xB5, 0x0E, 0x07, // 196:1205
|
||||
0x04, 0xC3, 0x0E, 0x07, // 197:1219
|
||||
0x04, 0xD1, 0x12, 0x0A, // 198:1233
|
||||
0x04, 0xE3, 0x0C, 0x07, // 199:1251
|
||||
0x04, 0xEF, 0x0C, 0x07, // 200:1263
|
||||
0x04, 0xFB, 0x0C, 0x07, // 201:1275
|
||||
0x05, 0x07, 0x0C, 0x07, // 202:1287
|
||||
0x05, 0x13, 0x0C, 0x07, // 203:1299
|
||||
0x05, 0x1F, 0x05, 0x03, // 204:1311
|
||||
0x05, 0x24, 0x04, 0x03, // 205:1316
|
||||
0x05, 0x28, 0x04, 0x03, // 206:1320
|
||||
0x05, 0x2C, 0x05, 0x03, // 207:1324
|
||||
0x05, 0x31, 0x0B, 0x07, // 208:1329
|
||||
0x05, 0x3C, 0x0C, 0x07, // 209:1340
|
||||
0x05, 0x48, 0x0E, 0x08, // 210:1352
|
||||
0x05, 0x56, 0x0E, 0x08, // 211:1366
|
||||
0x05, 0x64, 0x0E, 0x08, // 212:1380
|
||||
0x05, 0x72, 0x0E, 0x08, // 213:1394
|
||||
0x05, 0x80, 0x0E, 0x08, // 214:1408
|
||||
0x05, 0x8E, 0x0A, 0x06, // 215:1422
|
||||
0x05, 0x98, 0x0D, 0x08, // 216:1432
|
||||
0x05, 0xA5, 0x0C, 0x07, // 217:1445
|
||||
0x05, 0xB1, 0x0C, 0x07, // 218:1457
|
||||
0x05, 0xBD, 0x0C, 0x07, // 219:1469
|
||||
0x05, 0xC9, 0x0C, 0x07, // 220:1481
|
||||
0x05, 0xD5, 0x0D, 0x07, // 221:1493
|
||||
0x05, 0xE2, 0x0B, 0x07, // 222:1506
|
||||
0x05, 0xED, 0x0C, 0x06, // 223:1517
|
||||
0x05, 0xF9, 0x0A, 0x06, // 224:1529
|
||||
0x06, 0x03, 0x0A, 0x06, // 225:1539
|
||||
0x06, 0x0D, 0x0A, 0x06, // 226:1549
|
||||
0x06, 0x17, 0x0A, 0x06, // 227:1559
|
||||
0x06, 0x21, 0x0A, 0x06, // 228:1569
|
||||
0x06, 0x2B, 0x0A, 0x06, // 229:1579
|
||||
0x06, 0x35, 0x10, 0x09, // 230:1589
|
||||
0x06, 0x45, 0x0A, 0x05, // 231:1605
|
||||
0x06, 0x4F, 0x0A, 0x06, // 232:1615
|
||||
0x06, 0x59, 0x0A, 0x06, // 233:1625
|
||||
0x06, 0x63, 0x0A, 0x06, // 234:1635
|
||||
0x06, 0x6D, 0x0A, 0x06, // 235:1645
|
||||
0x06, 0x77, 0x05, 0x03, // 236:1655
|
||||
0x06, 0x7C, 0x04, 0x03, // 237:1660
|
||||
0x06, 0x80, 0x05, 0x03, // 238:1664
|
||||
0x06, 0x85, 0x05, 0x03, // 239:1669
|
||||
0x06, 0x8A, 0x0A, 0x06, // 240:1674
|
||||
0x06, 0x94, 0x0A, 0x06, // 241:1684
|
||||
0x06, 0x9E, 0x0A, 0x06, // 242:1694
|
||||
0x06, 0xA8, 0x0A, 0x06, // 243:1704
|
||||
0x06, 0xB2, 0x0A, 0x06, // 244:1714
|
||||
0x06, 0xBC, 0x0A, 0x06, // 245:1724
|
||||
0x06, 0xC6, 0x0A, 0x06, // 246:1734
|
||||
0x06, 0xD0, 0x09, 0x05, // 247:1744
|
||||
0x06, 0xD9, 0x0A, 0x06, // 248:1753
|
||||
0x06, 0xE3, 0x0A, 0x06, // 249:1763
|
||||
0x06, 0xED, 0x0A, 0x06, // 250:1773
|
||||
0x06, 0xF7, 0x0A, 0x06, // 251:1783
|
||||
0x07, 0x01, 0x0A, 0x06, // 252:1793
|
||||
0x07, 0x0B, 0x09, 0x05, // 253:1803
|
||||
0x07, 0x14, 0x0A, 0x06, // 254:1812
|
||||
0x07, 0x1E, 0x09, 0x05, // 255:1822
|
||||
// Jump Table:
|
||||
0xFF, 0xFF, 0x00, 0x03, // 32:65535
|
||||
0x00, 0x00, 0x04, 0x03, // 33:0
|
||||
0x00, 0x04, 0x05, 0x04, // 34:4
|
||||
0x00, 0x09, 0x09, 0x06, // 35:9
|
||||
0x00, 0x12, 0x0A, 0x06, // 36:18
|
||||
0x00, 0x1C, 0x10, 0x09, // 37:28
|
||||
0x00, 0x2C, 0x0E, 0x07, // 38:44
|
||||
0x00, 0x3A, 0x01, 0x02, // 39:58
|
||||
0x00, 0x3B, 0x06, 0x03, // 40:59
|
||||
0x00, 0x41, 0x06, 0x03, // 41:65
|
||||
0x00, 0x47, 0x05, 0x04, // 42:71
|
||||
0x00, 0x4C, 0x09, 0x06, // 43:76
|
||||
0x00, 0x55, 0x04, 0x03, // 44:85
|
||||
0x00, 0x59, 0x03, 0x03, // 45:89
|
||||
0x00, 0x5C, 0x04, 0x03, // 46:92
|
||||
0x00, 0x60, 0x05, 0x03, // 47:96
|
||||
0x00, 0x65, 0x0A, 0x06, // 48:101
|
||||
0x00, 0x6F, 0x08, 0x06, // 49:111
|
||||
0x00, 0x77, 0x0A, 0x06, // 50:119
|
||||
0x00, 0x81, 0x0A, 0x06, // 51:129
|
||||
0x00, 0x8B, 0x0B, 0x06, // 52:139
|
||||
0x00, 0x96, 0x0A, 0x06, // 53:150
|
||||
0x00, 0xA0, 0x0A, 0x06, // 54:160
|
||||
0x00, 0xAA, 0x09, 0x06, // 55:170
|
||||
0x00, 0xB3, 0x0A, 0x06, // 56:179
|
||||
0x00, 0xBD, 0x0A, 0x06, // 57:189
|
||||
0x00, 0xC7, 0x04, 0x03, // 58:199
|
||||
0x00, 0xCB, 0x04, 0x03, // 59:203
|
||||
0x00, 0xCF, 0x0A, 0x06, // 60:207
|
||||
0x00, 0xD9, 0x09, 0x06, // 61:217
|
||||
0x00, 0xE2, 0x09, 0x06, // 62:226
|
||||
0x00, 0xEB, 0x0B, 0x06, // 63:235
|
||||
0x00, 0xF6, 0x14, 0x0A, // 64:246
|
||||
0x01, 0x0A, 0x0E, 0x07, // 65:266
|
||||
0x01, 0x18, 0x0C, 0x07, // 66:280
|
||||
0x01, 0x24, 0x0C, 0x07, // 67:292
|
||||
0x01, 0x30, 0x0B, 0x07, // 68:304
|
||||
0x01, 0x3B, 0x0C, 0x07, // 69:315
|
||||
0x01, 0x47, 0x09, 0x06, // 70:327
|
||||
0x01, 0x50, 0x0D, 0x08, // 71:336
|
||||
0x01, 0x5D, 0x0C, 0x07, // 72:349
|
||||
0x01, 0x69, 0x04, 0x03, // 73:361
|
||||
0x01, 0x6D, 0x08, 0x05, // 74:365
|
||||
0x01, 0x75, 0x0E, 0x07, // 75:373
|
||||
0x01, 0x83, 0x0C, 0x06, // 76:387
|
||||
0x01, 0x8F, 0x10, 0x08, // 77:399
|
||||
0x01, 0x9F, 0x0C, 0x07, // 78:415
|
||||
0x01, 0xAB, 0x0E, 0x08, // 79:427
|
||||
0x01, 0xB9, 0x0B, 0x07, // 80:441
|
||||
0x01, 0xC4, 0x0E, 0x08, // 81:452
|
||||
0x01, 0xD2, 0x0C, 0x07, // 82:466
|
||||
0x01, 0xDE, 0x0C, 0x07, // 83:478
|
||||
0x01, 0xEA, 0x0B, 0x06, // 84:490
|
||||
0x01, 0xF5, 0x0C, 0x07, // 85:501
|
||||
0x02, 0x01, 0x0D, 0x07, // 86:513
|
||||
0x02, 0x0E, 0x11, 0x09, // 87:526
|
||||
0x02, 0x1F, 0x0E, 0x07, // 88:543
|
||||
0x02, 0x2D, 0x0D, 0x07, // 89:557
|
||||
0x02, 0x3A, 0x0C, 0x06, // 90:570
|
||||
0x02, 0x46, 0x06, 0x03, // 91:582
|
||||
0x02, 0x4C, 0x06, 0x03, // 92:588
|
||||
0x02, 0x52, 0x04, 0x03, // 93:594
|
||||
0x02, 0x56, 0x09, 0x05, // 94:598
|
||||
0x02, 0x5F, 0x0C, 0x06, // 95:607
|
||||
0x02, 0x6B, 0x03, 0x03, // 96:619
|
||||
0x02, 0x6E, 0x0A, 0x06, // 97:622
|
||||
0x02, 0x78, 0x0A, 0x06, // 98:632
|
||||
0x02, 0x82, 0x0A, 0x05, // 99:642
|
||||
0x02, 0x8C, 0x0A, 0x06, // 100:652
|
||||
0x02, 0x96, 0x0A, 0x06, // 101:662
|
||||
0x02, 0xA0, 0x05, 0x03, // 102:672
|
||||
0x02, 0xA5, 0x0A, 0x06, // 103:677
|
||||
0x02, 0xAF, 0x0A, 0x06, // 104:687
|
||||
0x02, 0xB9, 0x04, 0x02, // 105:697
|
||||
0x02, 0xBD, 0x04, 0x02, // 106:701
|
||||
0x02, 0xC1, 0x08, 0x05, // 107:705
|
||||
0x02, 0xC9, 0x04, 0x02, // 108:713
|
||||
0x02, 0xCD, 0x10, 0x08, // 109:717
|
||||
0x02, 0xDD, 0x0A, 0x06, // 110:733
|
||||
0x02, 0xE7, 0x0A, 0x06, // 111:743
|
||||
0x02, 0xF1, 0x0A, 0x06, // 112:753
|
||||
0x02, 0xFB, 0x0A, 0x06, // 113:763
|
||||
0x03, 0x05, 0x05, 0x03, // 114:773
|
||||
0x03, 0x0A, 0x08, 0x05, // 115:778
|
||||
0x03, 0x12, 0x06, 0x03, // 116:786
|
||||
0x03, 0x18, 0x0A, 0x06, // 117:792
|
||||
0x03, 0x22, 0x09, 0x05, // 118:802
|
||||
0x03, 0x2B, 0x0E, 0x07, // 119:811
|
||||
0x03, 0x39, 0x0A, 0x05, // 120:825
|
||||
0x03, 0x43, 0x09, 0x05, // 121:835
|
||||
0x03, 0x4C, 0x0A, 0x05, // 122:844
|
||||
0x03, 0x56, 0x06, 0x03, // 123:854
|
||||
0x03, 0x5C, 0x04, 0x03, // 124:860
|
||||
0x03, 0x60, 0x05, 0x03, // 125:864
|
||||
0x03, 0x65, 0x09, 0x06, // 126:869
|
||||
0xFF, 0xFF, 0x00, 0x00, // 127:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 128:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 129:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 130:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 131:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 132:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 133:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 134:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 135:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 136:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 137:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 138:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 139:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 140:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 141:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 142:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 143:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 144:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 145:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 146:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 147:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 148:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 149:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 150:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 151:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 152:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 153:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 154:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 155:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 156:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 157:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 158:65535
|
||||
0xFF, 0xFF, 0x00, 0x0A, // 159:65535
|
||||
0xFF, 0xFF, 0x00, 0x03, // 160:65535
|
||||
0x03, 0x6E, 0x04, 0x03, // 161:878
|
||||
0x03, 0x72, 0x0A, 0x06, // 162:882
|
||||
0x03, 0x7C, 0x0C, 0x06, // 163:892
|
||||
0x03, 0x88, 0x0A, 0x06, // 164:904
|
||||
0x03, 0x92, 0x0A, 0x06, // 165:914
|
||||
0x03, 0x9C, 0x04, 0x03, // 166:924
|
||||
0x03, 0xA0, 0x0A, 0x06, // 167:928
|
||||
0x03, 0xAA, 0x05, 0x03, // 168:938
|
||||
0x03, 0xAF, 0x0D, 0x07, // 169:943
|
||||
0x03, 0xBC, 0x07, 0x04, // 170:956
|
||||
0x03, 0xC3, 0x0A, 0x06, // 171:963
|
||||
0x03, 0xCD, 0x09, 0x06, // 172:973
|
||||
0x03, 0xD6, 0x03, 0x03, // 173:982
|
||||
0x03, 0xD9, 0x0D, 0x07, // 174:985
|
||||
0x03, 0xE6, 0x0B, 0x06, // 175:998
|
||||
0x03, 0xF1, 0x07, 0x04, // 176:1009
|
||||
0x03, 0xF8, 0x0A, 0x05, // 177:1016
|
||||
0x04, 0x02, 0x05, 0x03, // 178:1026
|
||||
0x04, 0x07, 0x05, 0x03, // 179:1031
|
||||
0x04, 0x0C, 0x05, 0x03, // 180:1036
|
||||
0x04, 0x11, 0x0A, 0x06, // 181:1041
|
||||
0x04, 0x1B, 0x09, 0x05, // 182:1051
|
||||
0x04, 0x24, 0x03, 0x03, // 183:1060
|
||||
0x04, 0x27, 0x06, 0x03, // 184:1063
|
||||
0x04, 0x2D, 0x05, 0x03, // 185:1069
|
||||
0x04, 0x32, 0x07, 0x04, // 186:1074
|
||||
0x04, 0x39, 0x0A, 0x06, // 187:1081
|
||||
0x04, 0x43, 0x10, 0x08, // 188:1091
|
||||
0x04, 0x53, 0x10, 0x08, // 189:1107
|
||||
0x04, 0x63, 0x10, 0x08, // 190:1123
|
||||
0x04, 0x73, 0x0A, 0x06, // 191:1139
|
||||
0x04, 0x7D, 0x0E, 0x07, // 192:1149
|
||||
0x04, 0x8B, 0x0E, 0x07, // 193:1163
|
||||
0x04, 0x99, 0x0E, 0x07, // 194:1177
|
||||
0x04, 0xA7, 0x0E, 0x07, // 195:1191
|
||||
0x04, 0xB5, 0x0E, 0x07, // 196:1205
|
||||
0x04, 0xC3, 0x0E, 0x07, // 197:1219
|
||||
0x04, 0xD1, 0x12, 0x0A, // 198:1233
|
||||
0x04, 0xE3, 0x0C, 0x07, // 199:1251
|
||||
0x04, 0xEF, 0x0C, 0x07, // 200:1263
|
||||
0x04, 0xFB, 0x0C, 0x07, // 201:1275
|
||||
0x05, 0x07, 0x0C, 0x07, // 202:1287
|
||||
0x05, 0x13, 0x0C, 0x07, // 203:1299
|
||||
0x05, 0x1F, 0x05, 0x03, // 204:1311
|
||||
0x05, 0x24, 0x04, 0x03, // 205:1316
|
||||
0x05, 0x28, 0x04, 0x03, // 206:1320
|
||||
0x05, 0x2C, 0x05, 0x03, // 207:1324
|
||||
0x05, 0x31, 0x0B, 0x07, // 208:1329
|
||||
0x05, 0x3C, 0x0C, 0x07, // 209:1340
|
||||
0x05, 0x48, 0x0E, 0x08, // 210:1352
|
||||
0x05, 0x56, 0x0E, 0x08, // 211:1366
|
||||
0x05, 0x64, 0x0E, 0x08, // 212:1380
|
||||
0x05, 0x72, 0x0E, 0x08, // 213:1394
|
||||
0x05, 0x80, 0x0E, 0x08, // 214:1408
|
||||
0x05, 0x8E, 0x0A, 0x06, // 215:1422
|
||||
0x05, 0x98, 0x0D, 0x08, // 216:1432
|
||||
0x05, 0xA5, 0x0C, 0x07, // 217:1445
|
||||
0x05, 0xB1, 0x0C, 0x07, // 218:1457
|
||||
0x05, 0xBD, 0x0C, 0x07, // 219:1469
|
||||
0x05, 0xC9, 0x0C, 0x07, // 220:1481
|
||||
0x05, 0xD5, 0x0D, 0x07, // 221:1493
|
||||
0x05, 0xE2, 0x0B, 0x07, // 222:1506
|
||||
0x05, 0xED, 0x0C, 0x06, // 223:1517
|
||||
0x05, 0xF9, 0x0A, 0x06, // 224:1529
|
||||
0x06, 0x03, 0x0A, 0x06, // 225:1539
|
||||
0x06, 0x0D, 0x0A, 0x06, // 226:1549
|
||||
0x06, 0x17, 0x0A, 0x06, // 227:1559
|
||||
0x06, 0x21, 0x0A, 0x06, // 228:1569
|
||||
0x06, 0x2B, 0x0A, 0x06, // 229:1579
|
||||
0x06, 0x35, 0x10, 0x09, // 230:1589
|
||||
0x06, 0x45, 0x0A, 0x05, // 231:1605
|
||||
0x06, 0x4F, 0x0A, 0x06, // 232:1615
|
||||
0x06, 0x59, 0x0A, 0x06, // 233:1625
|
||||
0x06, 0x63, 0x0A, 0x06, // 234:1635
|
||||
0x06, 0x6D, 0x0A, 0x06, // 235:1645
|
||||
0x06, 0x77, 0x05, 0x03, // 236:1655
|
||||
0x06, 0x7C, 0x04, 0x03, // 237:1660
|
||||
0x06, 0x80, 0x05, 0x03, // 238:1664
|
||||
0x06, 0x85, 0x05, 0x03, // 239:1669
|
||||
0x06, 0x8A, 0x0A, 0x06, // 240:1674
|
||||
0x06, 0x94, 0x0A, 0x06, // 241:1684
|
||||
0x06, 0x9E, 0x0A, 0x06, // 242:1694
|
||||
0x06, 0xA8, 0x0A, 0x06, // 243:1704
|
||||
0x06, 0xB2, 0x0A, 0x06, // 244:1714
|
||||
0x06, 0xBC, 0x0A, 0x06, // 245:1724
|
||||
0x06, 0xC6, 0x0A, 0x06, // 246:1734
|
||||
0x06, 0xD0, 0x09, 0x05, // 247:1744
|
||||
0x06, 0xD9, 0x0A, 0x06, // 248:1753
|
||||
0x06, 0xE3, 0x0A, 0x06, // 249:1763
|
||||
0x06, 0xED, 0x0A, 0x06, // 250:1773
|
||||
0x06, 0xF7, 0x0A, 0x06, // 251:1783
|
||||
0x07, 0x01, 0x0A, 0x06, // 252:1793
|
||||
0x07, 0x0B, 0x09, 0x05, // 253:1803
|
||||
0x07, 0x14, 0x0A, 0x06, // 254:1812
|
||||
0x07, 0x1E, 0x09, 0x05, // 255:1822
|
||||
|
||||
// Font Data:
|
||||
0x00,0x00,0xF8,0x02, // 33
|
||||
0x38,0x00,0x00,0x00,0x38, // 34
|
||||
0xA0,0x03,0xE0,0x00,0xB8,0x03,0xE0,0x00,0xB8, // 35
|
||||
0x30,0x01,0x28,0x02,0xF8,0x07,0x48,0x02,0x90,0x01, // 36
|
||||
0x00,0x00,0x30,0x00,0x48,0x00,0x30,0x03,0xC0,0x00,0xB0,0x01,0x48,0x02,0x80,0x01, // 37
|
||||
0x80,0x01,0x50,0x02,0x68,0x02,0xA8,0x02,0x18,0x01,0x80,0x03,0x80,0x02, // 38
|
||||
0x38, // 39
|
||||
0xE0,0x03,0x10,0x04,0x08,0x08, // 40
|
||||
0x08,0x08,0x10,0x04,0xE0,0x03, // 41
|
||||
0x28,0x00,0x18,0x00,0x28, // 42
|
||||
0x40,0x00,0x40,0x00,0xF0,0x01,0x40,0x00,0x40, // 43
|
||||
0x00,0x00,0x00,0x06, // 44
|
||||
0x80,0x00,0x80, // 45
|
||||
0x00,0x00,0x00,0x02, // 46
|
||||
0x00,0x03,0xE0,0x00,0x18, // 47
|
||||
0xF0,0x01,0x08,0x02,0x08,0x02,0x08,0x02,0xF0,0x01, // 48
|
||||
0x00,0x00,0x20,0x00,0x10,0x00,0xF8,0x03, // 49
|
||||
0x10,0x02,0x08,0x03,0x88,0x02,0x48,0x02,0x30,0x02, // 50
|
||||
0x10,0x01,0x08,0x02,0x48,0x02,0x48,0x02,0xB0,0x01, // 51
|
||||
0xC0,0x00,0xA0,0x00,0x90,0x00,0x88,0x00,0xF8,0x03,0x80, // 52
|
||||
0x60,0x01,0x38,0x02,0x28,0x02,0x28,0x02,0xC8,0x01, // 53
|
||||
0xF0,0x01,0x28,0x02,0x28,0x02,0x28,0x02,0xD0,0x01, // 54
|
||||
0x08,0x00,0x08,0x03,0xC8,0x00,0x38,0x00,0x08, // 55
|
||||
0xB0,0x01,0x48,0x02,0x48,0x02,0x48,0x02,0xB0,0x01, // 56
|
||||
0x70,0x01,0x88,0x02,0x88,0x02,0x88,0x02,0xF0,0x01, // 57
|
||||
0x00,0x00,0x20,0x02, // 58
|
||||
0x00,0x00,0x20,0x06, // 59
|
||||
0x00,0x00,0x40,0x00,0xA0,0x00,0xA0,0x00,0x10,0x01, // 60
|
||||
0xA0,0x00,0xA0,0x00,0xA0,0x00,0xA0,0x00,0xA0, // 61
|
||||
0x00,0x00,0x10,0x01,0xA0,0x00,0xA0,0x00,0x40, // 62
|
||||
0x10,0x00,0x08,0x00,0x08,0x00,0xC8,0x02,0x48,0x00,0x30, // 63
|
||||
0x00,0x00,0xC0,0x03,0x30,0x04,0xD0,0x09,0x28,0x0A,0x28,0x0A,0xC8,0x0B,0x68,0x0A,0x10,0x05,0xE0,0x04, // 64
|
||||
0x00,0x02,0xC0,0x01,0xB0,0x00,0x88,0x00,0xB0,0x00,0xC0,0x01,0x00,0x02, // 65
|
||||
0x00,0x00,0xF8,0x03,0x48,0x02,0x48,0x02,0x48,0x02,0xF0,0x01, // 66
|
||||
0x00,0x00,0xF0,0x01,0x08,0x02,0x08,0x02,0x08,0x02,0x10,0x01, // 67
|
||||
0x00,0x00,0xF8,0x03,0x08,0x02,0x08,0x02,0x10,0x01,0xE0, // 68
|
||||
0x00,0x00,0xF8,0x03,0x48,0x02,0x48,0x02,0x48,0x02,0x48,0x02, // 69
|
||||
0x00,0x00,0xF8,0x03,0x48,0x00,0x48,0x00,0x08, // 70
|
||||
0x00,0x00,0xE0,0x00,0x10,0x01,0x08,0x02,0x48,0x02,0x50,0x01,0xC0, // 71
|
||||
0x00,0x00,0xF8,0x03,0x40,0x00,0x40,0x00,0x40,0x00,0xF8,0x03, // 72
|
||||
0x00,0x00,0xF8,0x03, // 73
|
||||
0x00,0x03,0x00,0x02,0x00,0x02,0xF8,0x01, // 74
|
||||
0x00,0x00,0xF8,0x03,0x80,0x00,0x60,0x00,0x90,0x00,0x08,0x01,0x00,0x02, // 75
|
||||
0x00,0x00,0xF8,0x03,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02, // 76
|
||||
0x00,0x00,0xF8,0x03,0x30,0x00,0xC0,0x01,0x00,0x02,0xC0,0x01,0x30,0x00,0xF8,0x03, // 77
|
||||
0x00,0x00,0xF8,0x03,0x30,0x00,0x40,0x00,0x80,0x01,0xF8,0x03, // 78
|
||||
0x00,0x00,0xF0,0x01,0x08,0x02,0x08,0x02,0x08,0x02,0x08,0x02,0xF0,0x01, // 79
|
||||
0x00,0x00,0xF8,0x03,0x48,0x00,0x48,0x00,0x48,0x00,0x30, // 80
|
||||
0x00,0x00,0xF0,0x01,0x08,0x02,0x08,0x02,0x08,0x03,0x08,0x03,0xF0,0x02, // 81
|
||||
0x00,0x00,0xF8,0x03,0x48,0x00,0x48,0x00,0xC8,0x00,0x30,0x03, // 82
|
||||
0x00,0x00,0x30,0x01,0x48,0x02,0x48,0x02,0x48,0x02,0x90,0x01, // 83
|
||||
0x00,0x00,0x08,0x00,0x08,0x00,0xF8,0x03,0x08,0x00,0x08, // 84
|
||||
0x00,0x00,0xF8,0x01,0x00,0x02,0x00,0x02,0x00,0x02,0xF8,0x01, // 85
|
||||
0x08,0x00,0x70,0x00,0x80,0x01,0x00,0x02,0x80,0x01,0x70,0x00,0x08, // 86
|
||||
0x18,0x00,0xE0,0x01,0x00,0x02,0xF0,0x01,0x08,0x00,0xF0,0x01,0x00,0x02,0xE0,0x01,0x18, // 87
|
||||
0x00,0x02,0x08,0x01,0x90,0x00,0x60,0x00,0x90,0x00,0x08,0x01,0x00,0x02, // 88
|
||||
0x08,0x00,0x10,0x00,0x20,0x00,0xC0,0x03,0x20,0x00,0x10,0x00,0x08, // 89
|
||||
0x08,0x03,0x88,0x02,0xC8,0x02,0x68,0x02,0x38,0x02,0x18,0x02, // 90
|
||||
0x00,0x00,0xF8,0x0F,0x08,0x08, // 91
|
||||
0x18,0x00,0xE0,0x00,0x00,0x03, // 92
|
||||
0x08,0x08,0xF8,0x0F, // 93
|
||||
0x40,0x00,0x30,0x00,0x08,0x00,0x30,0x00,0x40, // 94
|
||||
0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08, // 95
|
||||
0x08,0x00,0x10, // 96
|
||||
0x00,0x00,0x00,0x03,0xA0,0x02,0xA0,0x02,0xE0,0x03, // 97
|
||||
0x00,0x00,0xF8,0x03,0x20,0x02,0x20,0x02,0xC0,0x01, // 98
|
||||
0x00,0x00,0xC0,0x01,0x20,0x02,0x20,0x02,0x40,0x01, // 99
|
||||
0x00,0x00,0xC0,0x01,0x20,0x02,0x20,0x02,0xF8,0x03, // 100
|
||||
0x00,0x00,0xC0,0x01,0xA0,0x02,0xA0,0x02,0xC0,0x02, // 101
|
||||
0x20,0x00,0xF0,0x03,0x28, // 102
|
||||
0x00,0x00,0xC0,0x05,0x20,0x0A,0x20,0x0A,0xE0,0x07, // 103
|
||||
0x00,0x00,0xF8,0x03,0x20,0x00,0x20,0x00,0xC0,0x03, // 104
|
||||
0x00,0x00,0xE8,0x03, // 105
|
||||
0x00,0x08,0xE8,0x07, // 106
|
||||
0xF8,0x03,0x80,0x00,0xC0,0x01,0x20,0x02, // 107
|
||||
0x00,0x00,0xF8,0x03, // 108
|
||||
0x00,0x00,0xE0,0x03,0x20,0x00,0x20,0x00,0xE0,0x03,0x20,0x00,0x20,0x00,0xC0,0x03, // 109
|
||||
0x00,0x00,0xE0,0x03,0x20,0x00,0x20,0x00,0xC0,0x03, // 110
|
||||
0x00,0x00,0xC0,0x01,0x20,0x02,0x20,0x02,0xC0,0x01, // 111
|
||||
0x00,0x00,0xE0,0x0F,0x20,0x02,0x20,0x02,0xC0,0x01, // 112
|
||||
0x00,0x00,0xC0,0x01,0x20,0x02,0x20,0x02,0xE0,0x0F, // 113
|
||||
0x00,0x00,0xE0,0x03,0x20, // 114
|
||||
0x40,0x02,0xA0,0x02,0xA0,0x02,0x20,0x01, // 115
|
||||
0x20,0x00,0xF8,0x03,0x20,0x02, // 116
|
||||
0x00,0x00,0xE0,0x01,0x00,0x02,0x00,0x02,0xE0,0x03, // 117
|
||||
0x20,0x00,0xC0,0x01,0x00,0x02,0xC0,0x01,0x20, // 118
|
||||
0xE0,0x01,0x00,0x02,0xC0,0x01,0x20,0x00,0xC0,0x01,0x00,0x02,0xE0,0x01, // 119
|
||||
0x20,0x02,0x40,0x01,0x80,0x00,0x40,0x01,0x20,0x02, // 120
|
||||
0x20,0x00,0xC0,0x09,0x00,0x06,0xC0,0x01,0x20, // 121
|
||||
0x20,0x02,0x20,0x03,0xA0,0x02,0x60,0x02,0x20,0x02, // 122
|
||||
0x80,0x00,0x78,0x0F,0x08,0x08, // 123
|
||||
0x00,0x00,0xF8,0x0F, // 124
|
||||
0x08,0x08,0x78,0x0F,0x80, // 125
|
||||
0xC0,0x00,0x40,0x00,0xC0,0x00,0x80,0x00,0xC0, // 126
|
||||
0x00,0x00,0xA0,0x0F, // 161
|
||||
0x00,0x00,0xC0,0x01,0xA0,0x0F,0x78,0x02,0x40,0x01, // 162
|
||||
0x40,0x02,0x70,0x03,0xC8,0x02,0x48,0x02,0x08,0x02,0x10,0x02, // 163
|
||||
0x00,0x00,0xE0,0x01,0x20,0x01,0x20,0x01,0xE0,0x01, // 164
|
||||
0x48,0x01,0x70,0x01,0xC0,0x03,0x70,0x01,0x48,0x01, // 165
|
||||
0x00,0x00,0x38,0x0F, // 166
|
||||
0xD0,0x04,0x28,0x09,0x48,0x09,0x48,0x0A,0x90,0x05, // 167
|
||||
0x08,0x00,0x00,0x00,0x08, // 168
|
||||
0xE0,0x00,0x10,0x01,0x48,0x02,0xA8,0x02,0xA8,0x02,0x10,0x01,0xE0, // 169
|
||||
0x68,0x00,0x68,0x00,0x68,0x00,0x78, // 170
|
||||
0x00,0x00,0x80,0x01,0x40,0x02,0x80,0x01,0x40,0x02, // 171
|
||||
0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0xE0, // 172
|
||||
0x80,0x00,0x80, // 173
|
||||
0xE0,0x00,0x10,0x01,0xE8,0x02,0x68,0x02,0xC8,0x02,0x10,0x01,0xE0, // 174
|
||||
0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02, // 175
|
||||
0x00,0x00,0x38,0x00,0x28,0x00,0x38, // 176
|
||||
0x40,0x02,0x40,0x02,0xF0,0x03,0x40,0x02,0x40,0x02, // 177
|
||||
0x48,0x00,0x68,0x00,0x58, // 178
|
||||
0x48,0x00,0x58,0x00,0x68, // 179
|
||||
0x00,0x00,0x10,0x00,0x08, // 180
|
||||
0x00,0x00,0xE0,0x0F,0x00,0x02,0x00,0x02,0xE0,0x03, // 181
|
||||
0x70,0x00,0xF8,0x0F,0x08,0x00,0xF8,0x0F,0x08, // 182
|
||||
0x00,0x00,0x40, // 183
|
||||
0x00,0x00,0x00,0x14,0x00,0x18, // 184
|
||||
0x00,0x00,0x10,0x00,0x78, // 185
|
||||
0x30,0x00,0x48,0x00,0x48,0x00,0x30, // 186
|
||||
0x00,0x00,0x40,0x02,0x80,0x01,0x40,0x02,0x80,0x01, // 187
|
||||
0x00,0x00,0x10,0x02,0x78,0x01,0xC0,0x00,0x20,0x01,0x90,0x01,0xC8,0x03,0x00,0x01, // 188
|
||||
0x00,0x00,0x10,0x02,0x78,0x01,0x80,0x00,0x60,0x00,0x50,0x02,0x48,0x03,0xC0,0x02, // 189
|
||||
0x48,0x00,0x58,0x00,0x68,0x03,0x80,0x00,0x60,0x01,0x90,0x01,0xC8,0x03,0x00,0x01, // 190
|
||||
0x00,0x00,0x00,0x06,0x00,0x09,0xA0,0x09,0x00,0x04, // 191
|
||||
0x00,0x02,0xC0,0x01,0xB0,0x00,0x89,0x00,0xB2,0x00,0xC0,0x01,0x00,0x02, // 192
|
||||
0x00,0x02,0xC0,0x01,0xB0,0x00,0x8A,0x00,0xB1,0x00,0xC0,0x01,0x00,0x02, // 193
|
||||
0x00,0x02,0xC0,0x01,0xB2,0x00,0x89,0x00,0xB2,0x00,0xC0,0x01,0x00,0x02, // 194
|
||||
0x00,0x02,0xC2,0x01,0xB1,0x00,0x8A,0x00,0xB1,0x00,0xC0,0x01,0x00,0x02, // 195
|
||||
0x00,0x02,0xC0,0x01,0xB2,0x00,0x88,0x00,0xB2,0x00,0xC0,0x01,0x00,0x02, // 196
|
||||
0x00,0x02,0xC0,0x01,0xBE,0x00,0x8A,0x00,0xBE,0x00,0xC0,0x01,0x00,0x02, // 197
|
||||
0x00,0x03,0xC0,0x00,0xE0,0x00,0x98,0x00,0x88,0x00,0xF8,0x03,0x48,0x02,0x48,0x02,0x48,0x02, // 198
|
||||
0x00,0x00,0xF0,0x01,0x08,0x02,0x08,0x16,0x08,0x1A,0x10,0x01, // 199
|
||||
0x00,0x00,0xF8,0x03,0x49,0x02,0x4A,0x02,0x48,0x02,0x48,0x02, // 200
|
||||
0x00,0x00,0xF8,0x03,0x48,0x02,0x4A,0x02,0x49,0x02,0x48,0x02, // 201
|
||||
0x00,0x00,0xFA,0x03,0x49,0x02,0x4A,0x02,0x48,0x02,0x48,0x02, // 202
|
||||
0x00,0x00,0xF8,0x03,0x4A,0x02,0x48,0x02,0x4A,0x02,0x48,0x02, // 203
|
||||
0x00,0x00,0xF9,0x03,0x02, // 204
|
||||
0x02,0x00,0xF9,0x03, // 205
|
||||
0x01,0x00,0xFA,0x03, // 206
|
||||
0x02,0x00,0xF8,0x03,0x02, // 207
|
||||
0x40,0x00,0xF8,0x03,0x48,0x02,0x48,0x02,0x10,0x01,0xE0, // 208
|
||||
0x00,0x00,0xFA,0x03,0x31,0x00,0x42,0x00,0x81,0x01,0xF8,0x03, // 209
|
||||
0x00,0x00,0xF0,0x01,0x08,0x02,0x09,0x02,0x0A,0x02,0x08,0x02,0xF0,0x01, // 210
|
||||
0x00,0x00,0xF0,0x01,0x08,0x02,0x0A,0x02,0x09,0x02,0x08,0x02,0xF0,0x01, // 211
|
||||
0x00,0x00,0xF0,0x01,0x08,0x02,0x0A,0x02,0x09,0x02,0x0A,0x02,0xF0,0x01, // 212
|
||||
0x00,0x00,0xF0,0x01,0x0A,0x02,0x09,0x02,0x0A,0x02,0x09,0x02,0xF0,0x01, // 213
|
||||
0x00,0x00,0xF0,0x01,0x0A,0x02,0x08,0x02,0x0A,0x02,0x08,0x02,0xF0,0x01, // 214
|
||||
0x10,0x01,0xA0,0x00,0xE0,0x00,0xA0,0x00,0x10,0x01, // 215
|
||||
0x00,0x00,0xF0,0x02,0x08,0x03,0xC8,0x02,0x28,0x02,0x18,0x03,0xE8, // 216
|
||||
0x00,0x00,0xF8,0x01,0x01,0x02,0x02,0x02,0x00,0x02,0xF8,0x01, // 217
|
||||
0x00,0x00,0xF8,0x01,0x02,0x02,0x01,0x02,0x00,0x02,0xF8,0x01, // 218
|
||||
0x00,0x00,0xF8,0x01,0x02,0x02,0x01,0x02,0x02,0x02,0xF8,0x01, // 219
|
||||
0x00,0x00,0xF8,0x01,0x02,0x02,0x00,0x02,0x02,0x02,0xF8,0x01, // 220
|
||||
0x08,0x00,0x10,0x00,0x20,0x00,0xC2,0x03,0x21,0x00,0x10,0x00,0x08, // 221
|
||||
0x00,0x00,0xF8,0x03,0x10,0x01,0x10,0x01,0x10,0x01,0xE0, // 222
|
||||
0x00,0x00,0xF0,0x03,0x08,0x01,0x48,0x02,0xB0,0x02,0x80,0x01, // 223
|
||||
0x00,0x00,0x00,0x03,0xA4,0x02,0xA8,0x02,0xE0,0x03, // 224
|
||||
0x00,0x00,0x00,0x03,0xA8,0x02,0xA4,0x02,0xE0,0x03, // 225
|
||||
0x00,0x00,0x00,0x03,0xA8,0x02,0xA4,0x02,0xE8,0x03, // 226
|
||||
0x00,0x00,0x08,0x03,0xA4,0x02,0xA8,0x02,0xE4,0x03, // 227
|
||||
0x00,0x00,0x00,0x03,0xA8,0x02,0xA0,0x02,0xE8,0x03, // 228
|
||||
0x00,0x00,0x00,0x03,0xAE,0x02,0xAA,0x02,0xEE,0x03, // 229
|
||||
0x00,0x00,0x40,0x03,0xA0,0x02,0xA0,0x02,0xC0,0x01,0xA0,0x02,0xA0,0x02,0xC0,0x02, // 230
|
||||
0x00,0x00,0xC0,0x01,0x20,0x16,0x20,0x1A,0x40,0x01, // 231
|
||||
0x00,0x00,0xC0,0x01,0xA4,0x02,0xA8,0x02,0xC0,0x02, // 232
|
||||
0x00,0x00,0xC0,0x01,0xA8,0x02,0xA4,0x02,0xC0,0x02, // 233
|
||||
0x00,0x00,0xC0,0x01,0xA8,0x02,0xA4,0x02,0xC8,0x02, // 234
|
||||
0x00,0x00,0xC0,0x01,0xA8,0x02,0xA0,0x02,0xC8,0x02, // 235
|
||||
0x00,0x00,0xE4,0x03,0x08, // 236
|
||||
0x08,0x00,0xE4,0x03, // 237
|
||||
0x08,0x00,0xE4,0x03,0x08, // 238
|
||||
0x08,0x00,0xE0,0x03,0x08, // 239
|
||||
0x00,0x00,0xC0,0x01,0x28,0x02,0x38,0x02,0xE0,0x01, // 240
|
||||
0x00,0x00,0xE8,0x03,0x24,0x00,0x28,0x00,0xC4,0x03, // 241
|
||||
0x00,0x00,0xC0,0x01,0x24,0x02,0x28,0x02,0xC0,0x01, // 242
|
||||
0x00,0x00,0xC0,0x01,0x28,0x02,0x24,0x02,0xC0,0x01, // 243
|
||||
0x00,0x00,0xC0,0x01,0x28,0x02,0x24,0x02,0xC8,0x01, // 244
|
||||
0x00,0x00,0xC8,0x01,0x24,0x02,0x28,0x02,0xC4,0x01, // 245
|
||||
0x00,0x00,0xC0,0x01,0x28,0x02,0x20,0x02,0xC8,0x01, // 246
|
||||
0x40,0x00,0x40,0x00,0x50,0x01,0x40,0x00,0x40, // 247
|
||||
0x00,0x00,0xC0,0x02,0xA0,0x03,0x60,0x02,0xA0,0x01, // 248
|
||||
0x00,0x00,0xE0,0x01,0x04,0x02,0x08,0x02,0xE0,0x03, // 249
|
||||
0x00,0x00,0xE0,0x01,0x08,0x02,0x04,0x02,0xE0,0x03, // 250
|
||||
0x00,0x00,0xE8,0x01,0x04,0x02,0x08,0x02,0xE0,0x03, // 251
|
||||
0x00,0x00,0xE0,0x01,0x08,0x02,0x00,0x02,0xE8,0x03, // 252
|
||||
0x20,0x00,0xC0,0x09,0x08,0x06,0xC4,0x01,0x20, // 253
|
||||
0x00,0x00,0xF8,0x0F,0x20,0x02,0x20,0x02,0xC0,0x01, // 254
|
||||
0x20,0x00,0xC8,0x09,0x00,0x06,0xC8,0x01,0x20 // 255
|
||||
// Font Data:
|
||||
0x00, 0x00, 0xF8, 0x02, // 33
|
||||
0x38, 0x00, 0x00, 0x00, 0x38, // 34
|
||||
0xA0, 0x03, 0xE0, 0x00, 0xB8, 0x03, 0xE0, 0x00, 0xB8, // 35
|
||||
0x30, 0x01, 0x28, 0x02, 0xF8, 0x07, 0x48, 0x02, 0x90, 0x01, // 36
|
||||
0x00, 0x00, 0x30, 0x00, 0x48, 0x00, 0x30, 0x03, 0xC0, 0x00, 0xB0, 0x01, 0x48, 0x02, 0x80, 0x01, // 37
|
||||
0x80, 0x01, 0x50, 0x02, 0x68, 0x02, 0xA8, 0x02, 0x18, 0x01, 0x80, 0x03, 0x80, 0x02, // 38
|
||||
0x38, // 39
|
||||
0xE0, 0x03, 0x10, 0x04, 0x08, 0x08, // 40
|
||||
0x08, 0x08, 0x10, 0x04, 0xE0, 0x03, // 41
|
||||
0x28, 0x00, 0x18, 0x00, 0x28, // 42
|
||||
0x40, 0x00, 0x40, 0x00, 0xF0, 0x01, 0x40, 0x00, 0x40, // 43
|
||||
0x00, 0x00, 0x00, 0x06, // 44
|
||||
0x80, 0x00, 0x80, // 45
|
||||
0x00, 0x00, 0x00, 0x02, // 46
|
||||
0x00, 0x03, 0xE0, 0x00, 0x18, // 47
|
||||
0xF0, 0x01, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0xF0, 0x01, // 48
|
||||
0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0xF8, 0x03, // 49
|
||||
0x10, 0x02, 0x08, 0x03, 0x88, 0x02, 0x48, 0x02, 0x30, 0x02, // 50
|
||||
0x10, 0x01, 0x08, 0x02, 0x48, 0x02, 0x48, 0x02, 0xB0, 0x01, // 51
|
||||
0xC0, 0x00, 0xA0, 0x00, 0x90, 0x00, 0x88, 0x00, 0xF8, 0x03, 0x80, // 52
|
||||
0x60, 0x01, 0x38, 0x02, 0x28, 0x02, 0x28, 0x02, 0xC8, 0x01, // 53
|
||||
0xF0, 0x01, 0x28, 0x02, 0x28, 0x02, 0x28, 0x02, 0xD0, 0x01, // 54
|
||||
0x08, 0x00, 0x08, 0x03, 0xC8, 0x00, 0x38, 0x00, 0x08, // 55
|
||||
0xB0, 0x01, 0x48, 0x02, 0x48, 0x02, 0x48, 0x02, 0xB0, 0x01, // 56
|
||||
0x70, 0x01, 0x88, 0x02, 0x88, 0x02, 0x88, 0x02, 0xF0, 0x01, // 57
|
||||
0x00, 0x00, 0x20, 0x02, // 58
|
||||
0x00, 0x00, 0x20, 0x06, // 59
|
||||
0x00, 0x00, 0x40, 0x00, 0xA0, 0x00, 0xA0, 0x00, 0x10, 0x01, // 60
|
||||
0xA0, 0x00, 0xA0, 0x00, 0xA0, 0x00, 0xA0, 0x00, 0xA0, // 61
|
||||
0x00, 0x00, 0x10, 0x01, 0xA0, 0x00, 0xA0, 0x00, 0x40, // 62
|
||||
0x10, 0x00, 0x08, 0x00, 0x08, 0x00, 0xC8, 0x02, 0x48, 0x00, 0x30, // 63
|
||||
0x00, 0x00, 0xC0, 0x03, 0x30, 0x04, 0xD0, 0x09, 0x28, 0x0A, 0x28, 0x0A, 0xC8, 0x0B, 0x68, 0x0A, 0x10, 0x05, 0xE0, 0x04, // 64
|
||||
0x00, 0x02, 0xC0, 0x01, 0xB0, 0x00, 0x88, 0x00, 0xB0, 0x00, 0xC0, 0x01, 0x00, 0x02, // 65
|
||||
0x00, 0x00, 0xF8, 0x03, 0x48, 0x02, 0x48, 0x02, 0x48, 0x02, 0xF0, 0x01, // 66
|
||||
0x00, 0x00, 0xF0, 0x01, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x10, 0x01, // 67
|
||||
0x00, 0x00, 0xF8, 0x03, 0x08, 0x02, 0x08, 0x02, 0x10, 0x01, 0xE0, // 68
|
||||
0x00, 0x00, 0xF8, 0x03, 0x48, 0x02, 0x48, 0x02, 0x48, 0x02, 0x48, 0x02, // 69
|
||||
0x00, 0x00, 0xF8, 0x03, 0x48, 0x00, 0x48, 0x00, 0x08, // 70
|
||||
0x00, 0x00, 0xE0, 0x00, 0x10, 0x01, 0x08, 0x02, 0x48, 0x02, 0x50, 0x01, 0xC0, // 71
|
||||
0x00, 0x00, 0xF8, 0x03, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0xF8, 0x03, // 72
|
||||
0x00, 0x00, 0xF8, 0x03, // 73
|
||||
0x00, 0x03, 0x00, 0x02, 0x00, 0x02, 0xF8, 0x01, // 74
|
||||
0x00, 0x00, 0xF8, 0x03, 0x80, 0x00, 0x60, 0x00, 0x90, 0x00, 0x08, 0x01, 0x00, 0x02, // 75
|
||||
0x00, 0x00, 0xF8, 0x03, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, // 76
|
||||
0x00, 0x00, 0xF8, 0x03, 0x30, 0x00, 0xC0, 0x01, 0x00, 0x02, 0xC0, 0x01, 0x30, 0x00, 0xF8, 0x03, // 77
|
||||
0x00, 0x00, 0xF8, 0x03, 0x30, 0x00, 0x40, 0x00, 0x80, 0x01, 0xF8, 0x03, // 78
|
||||
0x00, 0x00, 0xF0, 0x01, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0xF0, 0x01, // 79
|
||||
0x00, 0x00, 0xF8, 0x03, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x30, // 80
|
||||
0x00, 0x00, 0xF0, 0x01, 0x08, 0x02, 0x08, 0x02, 0x08, 0x03, 0x08, 0x03, 0xF0, 0x02, // 81
|
||||
0x00, 0x00, 0xF8, 0x03, 0x48, 0x00, 0x48, 0x00, 0xC8, 0x00, 0x30, 0x03, // 82
|
||||
0x00, 0x00, 0x30, 0x01, 0x48, 0x02, 0x48, 0x02, 0x48, 0x02, 0x90, 0x01, // 83
|
||||
0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0xF8, 0x03, 0x08, 0x00, 0x08, // 84
|
||||
0x00, 0x00, 0xF8, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0xF8, 0x01, // 85
|
||||
0x08, 0x00, 0x70, 0x00, 0x80, 0x01, 0x00, 0x02, 0x80, 0x01, 0x70, 0x00, 0x08, // 86
|
||||
0x18, 0x00, 0xE0, 0x01, 0x00, 0x02, 0xF0, 0x01, 0x08, 0x00, 0xF0, 0x01, 0x00, 0x02, 0xE0, 0x01, 0x18, // 87
|
||||
0x00, 0x02, 0x08, 0x01, 0x90, 0x00, 0x60, 0x00, 0x90, 0x00, 0x08, 0x01, 0x00, 0x02, // 88
|
||||
0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0xC0, 0x03, 0x20, 0x00, 0x10, 0x00, 0x08, // 89
|
||||
0x08, 0x03, 0x88, 0x02, 0xC8, 0x02, 0x68, 0x02, 0x38, 0x02, 0x18, 0x02, // 90
|
||||
0x00, 0x00, 0xF8, 0x0F, 0x08, 0x08, // 91
|
||||
0x18, 0x00, 0xE0, 0x00, 0x00, 0x03, // 92
|
||||
0x08, 0x08, 0xF8, 0x0F, // 93
|
||||
0x40, 0x00, 0x30, 0x00, 0x08, 0x00, 0x30, 0x00, 0x40, // 94
|
||||
0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, // 95
|
||||
0x08, 0x00, 0x10, // 96
|
||||
0x00, 0x00, 0x00, 0x03, 0xA0, 0x02, 0xA0, 0x02, 0xE0, 0x03, // 97
|
||||
0x00, 0x00, 0xF8, 0x03, 0x20, 0x02, 0x20, 0x02, 0xC0, 0x01, // 98
|
||||
0x00, 0x00, 0xC0, 0x01, 0x20, 0x02, 0x20, 0x02, 0x40, 0x01, // 99
|
||||
0x00, 0x00, 0xC0, 0x01, 0x20, 0x02, 0x20, 0x02, 0xF8, 0x03, // 100
|
||||
0x00, 0x00, 0xC0, 0x01, 0xA0, 0x02, 0xA0, 0x02, 0xC0, 0x02, // 101
|
||||
0x20, 0x00, 0xF0, 0x03, 0x28, // 102
|
||||
0x00, 0x00, 0xC0, 0x05, 0x20, 0x0A, 0x20, 0x0A, 0xE0, 0x07, // 103
|
||||
0x00, 0x00, 0xF8, 0x03, 0x20, 0x00, 0x20, 0x00, 0xC0, 0x03, // 104
|
||||
0x00, 0x00, 0xE8, 0x03, // 105
|
||||
0x00, 0x08, 0xE8, 0x07, // 106
|
||||
0xF8, 0x03, 0x80, 0x00, 0xC0, 0x01, 0x20, 0x02, // 107
|
||||
0x00, 0x00, 0xF8, 0x03, // 108
|
||||
0x00, 0x00, 0xE0, 0x03, 0x20, 0x00, 0x20, 0x00, 0xE0, 0x03, 0x20, 0x00, 0x20, 0x00, 0xC0, 0x03, // 109
|
||||
0x00, 0x00, 0xE0, 0x03, 0x20, 0x00, 0x20, 0x00, 0xC0, 0x03, // 110
|
||||
0x00, 0x00, 0xC0, 0x01, 0x20, 0x02, 0x20, 0x02, 0xC0, 0x01, // 111
|
||||
0x00, 0x00, 0xE0, 0x0F, 0x20, 0x02, 0x20, 0x02, 0xC0, 0x01, // 112
|
||||
0x00, 0x00, 0xC0, 0x01, 0x20, 0x02, 0x20, 0x02, 0xE0, 0x0F, // 113
|
||||
0x00, 0x00, 0xE0, 0x03, 0x20, // 114
|
||||
0x40, 0x02, 0xA0, 0x02, 0xA0, 0x02, 0x20, 0x01, // 115
|
||||
0x20, 0x00, 0xF8, 0x03, 0x20, 0x02, // 116
|
||||
0x00, 0x00, 0xE0, 0x01, 0x00, 0x02, 0x00, 0x02, 0xE0, 0x03, // 117
|
||||
0x20, 0x00, 0xC0, 0x01, 0x00, 0x02, 0xC0, 0x01, 0x20, // 118
|
||||
0xE0, 0x01, 0x00, 0x02, 0xC0, 0x01, 0x20, 0x00, 0xC0, 0x01, 0x00, 0x02, 0xE0, 0x01, // 119
|
||||
0x20, 0x02, 0x40, 0x01, 0x80, 0x00, 0x40, 0x01, 0x20, 0x02, // 120
|
||||
0x20, 0x00, 0xC0, 0x09, 0x00, 0x06, 0xC0, 0x01, 0x20, // 121
|
||||
0x20, 0x02, 0x20, 0x03, 0xA0, 0x02, 0x60, 0x02, 0x20, 0x02, // 122
|
||||
0x80, 0x00, 0x78, 0x0F, 0x08, 0x08, // 123
|
||||
0x00, 0x00, 0xF8, 0x0F, // 124
|
||||
0x08, 0x08, 0x78, 0x0F, 0x80, // 125
|
||||
0xC0, 0x00, 0x40, 0x00, 0xC0, 0x00, 0x80, 0x00, 0xC0, // 126
|
||||
0x00, 0x00, 0xA0, 0x0F, // 161
|
||||
0x00, 0x00, 0xC0, 0x01, 0xA0, 0x0F, 0x78, 0x02, 0x40, 0x01, // 162
|
||||
0x40, 0x02, 0x70, 0x03, 0xC8, 0x02, 0x48, 0x02, 0x08, 0x02, 0x10, 0x02, // 163
|
||||
0x00, 0x00, 0xE0, 0x01, 0x20, 0x01, 0x20, 0x01, 0xE0, 0x01, // 164
|
||||
0x48, 0x01, 0x70, 0x01, 0xC0, 0x03, 0x70, 0x01, 0x48, 0x01, // 165
|
||||
0x00, 0x00, 0x38, 0x0F, // 166
|
||||
0xD0, 0x04, 0x28, 0x09, 0x48, 0x09, 0x48, 0x0A, 0x90, 0x05, // 167
|
||||
0x08, 0x00, 0x00, 0x00, 0x08, // 168
|
||||
0xE0, 0x00, 0x10, 0x01, 0x48, 0x02, 0xA8, 0x02, 0xA8, 0x02, 0x10, 0x01, 0xE0, // 169
|
||||
0x68, 0x00, 0x68, 0x00, 0x68, 0x00, 0x78, // 170
|
||||
0x00, 0x00, 0x80, 0x01, 0x40, 0x02, 0x80, 0x01, 0x40, 0x02, // 171
|
||||
0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0xE0, // 172
|
||||
0x80, 0x00, 0x80, // 173
|
||||
0xE0, 0x00, 0x10, 0x01, 0xE8, 0x02, 0x68, 0x02, 0xC8, 0x02, 0x10, 0x01, 0xE0, // 174
|
||||
0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, // 175
|
||||
0x00, 0x00, 0x38, 0x00, 0x28, 0x00, 0x38, // 176
|
||||
0x40, 0x02, 0x40, 0x02, 0xF0, 0x03, 0x40, 0x02, 0x40, 0x02, // 177
|
||||
0x48, 0x00, 0x68, 0x00, 0x58, // 178
|
||||
0x48, 0x00, 0x58, 0x00, 0x68, // 179
|
||||
0x00, 0x00, 0x10, 0x00, 0x08, // 180
|
||||
0x00, 0x00, 0xE0, 0x0F, 0x00, 0x02, 0x00, 0x02, 0xE0, 0x03, // 181
|
||||
0x70, 0x00, 0xF8, 0x0F, 0x08, 0x00, 0xF8, 0x0F, 0x08, // 182
|
||||
0x00, 0x00, 0x40, // 183
|
||||
0x00, 0x00, 0x00, 0x14, 0x00, 0x18, // 184
|
||||
0x00, 0x00, 0x10, 0x00, 0x78, // 185
|
||||
0x30, 0x00, 0x48, 0x00, 0x48, 0x00, 0x30, // 186
|
||||
0x00, 0x00, 0x40, 0x02, 0x80, 0x01, 0x40, 0x02, 0x80, 0x01, // 187
|
||||
0x00, 0x00, 0x10, 0x02, 0x78, 0x01, 0xC0, 0x00, 0x20, 0x01, 0x90, 0x01, 0xC8, 0x03, 0x00, 0x01, // 188
|
||||
0x00, 0x00, 0x10, 0x02, 0x78, 0x01, 0x80, 0x00, 0x60, 0x00, 0x50, 0x02, 0x48, 0x03, 0xC0, 0x02, // 189
|
||||
0x48, 0x00, 0x58, 0x00, 0x68, 0x03, 0x80, 0x00, 0x60, 0x01, 0x90, 0x01, 0xC8, 0x03, 0x00, 0x01, // 190
|
||||
0x00, 0x00, 0x00, 0x06, 0x00, 0x09, 0xA0, 0x09, 0x00, 0x04, // 191
|
||||
0x00, 0x02, 0xC0, 0x01, 0xB0, 0x00, 0x89, 0x00, 0xB2, 0x00, 0xC0, 0x01, 0x00, 0x02, // 192
|
||||
0x00, 0x02, 0xC0, 0x01, 0xB0, 0x00, 0x8A, 0x00, 0xB1, 0x00, 0xC0, 0x01, 0x00, 0x02, // 193
|
||||
0x00, 0x02, 0xC0, 0x01, 0xB2, 0x00, 0x89, 0x00, 0xB2, 0x00, 0xC0, 0x01, 0x00, 0x02, // 194
|
||||
0x00, 0x02, 0xC2, 0x01, 0xB1, 0x00, 0x8A, 0x00, 0xB1, 0x00, 0xC0, 0x01, 0x00, 0x02, // 195
|
||||
0x00, 0x02, 0xC0, 0x01, 0xB2, 0x00, 0x88, 0x00, 0xB2, 0x00, 0xC0, 0x01, 0x00, 0x02, // 196
|
||||
0x00, 0x02, 0xC0, 0x01, 0xBE, 0x00, 0x8A, 0x00, 0xBE, 0x00, 0xC0, 0x01, 0x00, 0x02, // 197
|
||||
0x00, 0x03, 0xC0, 0x00, 0xE0, 0x00, 0x98, 0x00, 0x88, 0x00, 0xF8, 0x03, 0x48, 0x02, 0x48, 0x02, 0x48, 0x02, // 198
|
||||
0x00, 0x00, 0xF0, 0x01, 0x08, 0x02, 0x08, 0x16, 0x08, 0x1A, 0x10, 0x01, // 199
|
||||
0x00, 0x00, 0xF8, 0x03, 0x49, 0x02, 0x4A, 0x02, 0x48, 0x02, 0x48, 0x02, // 200
|
||||
0x00, 0x00, 0xF8, 0x03, 0x48, 0x02, 0x4A, 0x02, 0x49, 0x02, 0x48, 0x02, // 201
|
||||
0x00, 0x00, 0xFA, 0x03, 0x49, 0x02, 0x4A, 0x02, 0x48, 0x02, 0x48, 0x02, // 202
|
||||
0x00, 0x00, 0xF8, 0x03, 0x4A, 0x02, 0x48, 0x02, 0x4A, 0x02, 0x48, 0x02, // 203
|
||||
0x00, 0x00, 0xF9, 0x03, 0x02, // 204
|
||||
0x02, 0x00, 0xF9, 0x03, // 205
|
||||
0x01, 0x00, 0xFA, 0x03, // 206
|
||||
0x02, 0x00, 0xF8, 0x03, 0x02, // 207
|
||||
0x40, 0x00, 0xF8, 0x03, 0x48, 0x02, 0x48, 0x02, 0x10, 0x01, 0xE0, // 208
|
||||
0x00, 0x00, 0xFA, 0x03, 0x31, 0x00, 0x42, 0x00, 0x81, 0x01, 0xF8, 0x03, // 209
|
||||
0x00, 0x00, 0xF0, 0x01, 0x08, 0x02, 0x09, 0x02, 0x0A, 0x02, 0x08, 0x02, 0xF0, 0x01, // 210
|
||||
0x00, 0x00, 0xF0, 0x01, 0x08, 0x02, 0x0A, 0x02, 0x09, 0x02, 0x08, 0x02, 0xF0, 0x01, // 211
|
||||
0x00, 0x00, 0xF0, 0x01, 0x08, 0x02, 0x0A, 0x02, 0x09, 0x02, 0x0A, 0x02, 0xF0, 0x01, // 212
|
||||
0x00, 0x00, 0xF0, 0x01, 0x0A, 0x02, 0x09, 0x02, 0x0A, 0x02, 0x09, 0x02, 0xF0, 0x01, // 213
|
||||
0x00, 0x00, 0xF0, 0x01, 0x0A, 0x02, 0x08, 0x02, 0x0A, 0x02, 0x08, 0x02, 0xF0, 0x01, // 214
|
||||
0x10, 0x01, 0xA0, 0x00, 0xE0, 0x00, 0xA0, 0x00, 0x10, 0x01, // 215
|
||||
0x00, 0x00, 0xF0, 0x02, 0x08, 0x03, 0xC8, 0x02, 0x28, 0x02, 0x18, 0x03, 0xE8, // 216
|
||||
0x00, 0x00, 0xF8, 0x01, 0x01, 0x02, 0x02, 0x02, 0x00, 0x02, 0xF8, 0x01, // 217
|
||||
0x00, 0x00, 0xF8, 0x01, 0x02, 0x02, 0x01, 0x02, 0x00, 0x02, 0xF8, 0x01, // 218
|
||||
0x00, 0x00, 0xF8, 0x01, 0x02, 0x02, 0x01, 0x02, 0x02, 0x02, 0xF8, 0x01, // 219
|
||||
0x00, 0x00, 0xF8, 0x01, 0x02, 0x02, 0x00, 0x02, 0x02, 0x02, 0xF8, 0x01, // 220
|
||||
0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0xC2, 0x03, 0x21, 0x00, 0x10, 0x00, 0x08, // 221
|
||||
0x00, 0x00, 0xF8, 0x03, 0x10, 0x01, 0x10, 0x01, 0x10, 0x01, 0xE0, // 222
|
||||
0x00, 0x00, 0xF0, 0x03, 0x08, 0x01, 0x48, 0x02, 0xB0, 0x02, 0x80, 0x01, // 223
|
||||
0x00, 0x00, 0x00, 0x03, 0xA4, 0x02, 0xA8, 0x02, 0xE0, 0x03, // 224
|
||||
0x00, 0x00, 0x00, 0x03, 0xA8, 0x02, 0xA4, 0x02, 0xE0, 0x03, // 225
|
||||
0x00, 0x00, 0x00, 0x03, 0xA8, 0x02, 0xA4, 0x02, 0xE8, 0x03, // 226
|
||||
0x00, 0x00, 0x08, 0x03, 0xA4, 0x02, 0xA8, 0x02, 0xE4, 0x03, // 227
|
||||
0x00, 0x00, 0x00, 0x03, 0xA8, 0x02, 0xA0, 0x02, 0xE8, 0x03, // 228
|
||||
0x00, 0x00, 0x00, 0x03, 0xAE, 0x02, 0xAA, 0x02, 0xEE, 0x03, // 229
|
||||
0x00, 0x00, 0x40, 0x03, 0xA0, 0x02, 0xA0, 0x02, 0xC0, 0x01, 0xA0, 0x02, 0xA0, 0x02, 0xC0, 0x02, // 230
|
||||
0x00, 0x00, 0xC0, 0x01, 0x20, 0x16, 0x20, 0x1A, 0x40, 0x01, // 231
|
||||
0x00, 0x00, 0xC0, 0x01, 0xA4, 0x02, 0xA8, 0x02, 0xC0, 0x02, // 232
|
||||
0x00, 0x00, 0xC0, 0x01, 0xA8, 0x02, 0xA4, 0x02, 0xC0, 0x02, // 233
|
||||
0x00, 0x00, 0xC0, 0x01, 0xA8, 0x02, 0xA4, 0x02, 0xC8, 0x02, // 234
|
||||
0x00, 0x00, 0xC0, 0x01, 0xA8, 0x02, 0xA0, 0x02, 0xC8, 0x02, // 235
|
||||
0x00, 0x00, 0xE4, 0x03, 0x08, // 236
|
||||
0x08, 0x00, 0xE4, 0x03, // 237
|
||||
0x08, 0x00, 0xE4, 0x03, 0x08, // 238
|
||||
0x08, 0x00, 0xE0, 0x03, 0x08, // 239
|
||||
0x00, 0x00, 0xC0, 0x01, 0x28, 0x02, 0x38, 0x02, 0xE0, 0x01, // 240
|
||||
0x00, 0x00, 0xE8, 0x03, 0x24, 0x00, 0x28, 0x00, 0xC4, 0x03, // 241
|
||||
0x00, 0x00, 0xC0, 0x01, 0x24, 0x02, 0x28, 0x02, 0xC0, 0x01, // 242
|
||||
0x00, 0x00, 0xC0, 0x01, 0x28, 0x02, 0x24, 0x02, 0xC0, 0x01, // 243
|
||||
0x00, 0x00, 0xC0, 0x01, 0x28, 0x02, 0x24, 0x02, 0xC8, 0x01, // 244
|
||||
0x00, 0x00, 0xC8, 0x01, 0x24, 0x02, 0x28, 0x02, 0xC4, 0x01, // 245
|
||||
0x00, 0x00, 0xC0, 0x01, 0x28, 0x02, 0x20, 0x02, 0xC8, 0x01, // 246
|
||||
0x40, 0x00, 0x40, 0x00, 0x50, 0x01, 0x40, 0x00, 0x40, // 247
|
||||
0x00, 0x00, 0xC0, 0x02, 0xA0, 0x03, 0x60, 0x02, 0xA0, 0x01, // 248
|
||||
0x00, 0x00, 0xE0, 0x01, 0x04, 0x02, 0x08, 0x02, 0xE0, 0x03, // 249
|
||||
0x00, 0x00, 0xE0, 0x01, 0x08, 0x02, 0x04, 0x02, 0xE0, 0x03, // 250
|
||||
0x00, 0x00, 0xE8, 0x01, 0x04, 0x02, 0x08, 0x02, 0xE0, 0x03, // 251
|
||||
0x00, 0x00, 0xE0, 0x01, 0x08, 0x02, 0x00, 0x02, 0xE8, 0x03, // 252
|
||||
0x20, 0x00, 0xC0, 0x09, 0x08, 0x06, 0xC4, 0x01, 0x20, // 253
|
||||
0x00, 0x00, 0xF8, 0x0F, 0x20, 0x02, 0x20, 0x02, 0xC0, 0x01, // 254
|
||||
0x20, 0x00, 0xC8, 0x09, 0x00, 0x06, 0xC8, 0x01, 0x20 // 255
|
||||
};
|
||||
|
||||
16
src/freertosinc.h
Normal file
16
src/freertosinc.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
// 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
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/queue.h>
|
||||
#else
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <semphr.h>
|
||||
#include <queue.h>
|
||||
#endif
|
||||
11
src/images.h
11
src/images.h
@@ -1,11 +1,8 @@
|
||||
#define SATELLITE_IMAGE_WIDTH 16
|
||||
#define SATELLITE_IMAGE_HEIGHT 15
|
||||
const uint8_t SATELLITE_IMAGE[] PROGMEM = {
|
||||
0x00, 0x08, 0x00, 0x1C, 0x00, 0x0E, 0x20, 0x07, 0x70, 0x02, 0xF8, 0x00,
|
||||
0xF0, 0x01, 0xE0, 0x03, 0xC8, 0x01, 0x9C, 0x54, 0x0E, 0x52, 0x07, 0x48,
|
||||
0x02, 0x26, 0x00, 0x10, 0x00, 0x0E
|
||||
};
|
||||
|
||||
const uint8_t SATELLITE_IMAGE[] PROGMEM = {0x00, 0x08, 0x00, 0x1C, 0x00, 0x0E, 0x20, 0x07, 0x70, 0x02,
|
||||
0xF8, 0x00, 0xF0, 0x01, 0xE0, 0x03, 0xC8, 0x01, 0x9C, 0x54,
|
||||
0x0E, 0x52, 0x07, 0x48, 0x02, 0x26, 0x00, 0x10, 0x00, 0x0E};
|
||||
|
||||
const
|
||||
#include "icon.xbm"
|
||||
@@ -14,7 +11,7 @@ const
|
||||
#if 0
|
||||
const
|
||||
#include "compass.xbm"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
const uint8_t activeSymbol[] PROGMEM = {
|
||||
|
||||
35
src/lock.cpp
Normal file
35
src/lock.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "lock.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
||||
Lock::Lock()
|
||||
{
|
||||
handle = xSemaphoreCreateBinary();
|
||||
assert(handle);
|
||||
assert(xSemaphoreGive(handle));
|
||||
}
|
||||
|
||||
void Lock::lock()
|
||||
{
|
||||
assert(xSemaphoreTake(handle, portMAX_DELAY));
|
||||
}
|
||||
|
||||
void Lock::unlock()
|
||||
{
|
||||
assert(xSemaphoreGive(handle));
|
||||
}
|
||||
|
||||
LockGuard::LockGuard(Lock *lock) : lock(lock)
|
||||
{
|
||||
lock->lock();
|
||||
}
|
||||
|
||||
LockGuard::~LockGuard()
|
||||
{
|
||||
lock->unlock();
|
||||
}
|
||||
|
||||
} // namespace meshtastic
|
||||
45
src/lock.h
Normal file
45
src/lock.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "freertosinc.h"
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
||||
// Simple wrapper around FreeRTOS API for implementing a mutex lock.
|
||||
class Lock
|
||||
{
|
||||
public:
|
||||
Lock();
|
||||
|
||||
Lock(const Lock &) = delete;
|
||||
Lock &operator=(const Lock &) = delete;
|
||||
|
||||
/// Locks the lock.
|
||||
//
|
||||
// Must not be called from an ISR.
|
||||
void lock();
|
||||
|
||||
// Unlocks the lock.
|
||||
//
|
||||
// Must not be called from an ISR.
|
||||
void unlock();
|
||||
|
||||
private:
|
||||
SemaphoreHandle_t handle;
|
||||
};
|
||||
|
||||
// RAII lock guard.
|
||||
class LockGuard
|
||||
{
|
||||
public:
|
||||
LockGuard(Lock *lock);
|
||||
~LockGuard();
|
||||
|
||||
LockGuard(const LockGuard &) = delete;
|
||||
LockGuard &operator=(const LockGuard &) = delete;
|
||||
|
||||
private:
|
||||
Lock *lock;
|
||||
};
|
||||
|
||||
} // namespace meshtastic
|
||||
517
src/main.cpp
517
src/main.cpp
@@ -21,38 +21,48 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "configuration.h"
|
||||
#include "rom/rtc.h"
|
||||
#include <driver/rtc_io.h>
|
||||
#include <TinyGPS++.h>
|
||||
#include <Wire.h>
|
||||
#include "BluetoothUtil.h"
|
||||
#include "MeshBluetoothService.h"
|
||||
#include "MeshService.h"
|
||||
#include "GPS.h"
|
||||
#include "screen.h"
|
||||
#include "MeshRadio.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "Periodic.h"
|
||||
#include "esp32/pm.h"
|
||||
#include "esp_pm.h"
|
||||
#include "MeshRadio.h"
|
||||
#include "sleep.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "configuration.h"
|
||||
#include "error.h"
|
||||
#include "power.h"
|
||||
// #include "rom/rtc.h"
|
||||
#include "FloodingRouter.h"
|
||||
#include "screen.h"
|
||||
#include "sleep.h"
|
||||
#include <Wire.h>
|
||||
// #include <driver/rtc_io.h>
|
||||
|
||||
#ifdef T_BEAM_V10
|
||||
#ifndef NO_ESP32
|
||||
#include "BluetoothUtil.h"
|
||||
#endif
|
||||
|
||||
#ifdef TBEAM_V10
|
||||
#include "axp20x.h"
|
||||
AXP20X_Class axp;
|
||||
bool pmu_irq = false;
|
||||
#endif
|
||||
|
||||
// these flags are all in bss so they default false
|
||||
bool isCharging;
|
||||
bool isUSBPowered;
|
||||
// Global Screen singleton
|
||||
#ifdef I2C_SDA
|
||||
meshtastic::Screen screen(SSD1306_ADDRESS, I2C_SDA, I2C_SCL);
|
||||
#else
|
||||
// Fake values for pins to keep build happy, we won't ever initialize it.
|
||||
meshtastic::Screen screen(SSD1306_ADDRESS, 0, 0);
|
||||
#endif
|
||||
|
||||
// Global power status singleton
|
||||
static meshtastic::PowerStatus powerStatus;
|
||||
|
||||
bool ssd1306_found;
|
||||
bool axp192_found;
|
||||
|
||||
bool bluetoothOn;
|
||||
FloodingRouter realRouter;
|
||||
Router &router = realRouter; // Users of router don't care what sort of subclass implements that API
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Application
|
||||
@@ -60,84 +70,89 @@ bool bluetoothOn;
|
||||
|
||||
void scanI2Cdevice(void)
|
||||
{
|
||||
byte err, addr;
|
||||
int nDevices = 0;
|
||||
for (addr = 1; addr < 127; addr++)
|
||||
{
|
||||
Wire.beginTransmission(addr);
|
||||
err = Wire.endTransmission();
|
||||
if (err == 0)
|
||||
{
|
||||
DEBUG_MSG("I2C device found at address 0x%x\n", addr);
|
||||
byte err, addr;
|
||||
int nDevices = 0;
|
||||
for (addr = 1; addr < 127; addr++) {
|
||||
Wire.beginTransmission(addr);
|
||||
err = Wire.endTransmission();
|
||||
if (err == 0) {
|
||||
DEBUG_MSG("I2C device found at address 0x%x\n", addr);
|
||||
|
||||
nDevices++;
|
||||
nDevices++;
|
||||
|
||||
if (addr == SSD1306_ADDRESS)
|
||||
{
|
||||
ssd1306_found = true;
|
||||
DEBUG_MSG("ssd1306 display found\n");
|
||||
}
|
||||
#ifdef T_BEAM_V10
|
||||
if (addr == AXP192_SLAVE_ADDRESS)
|
||||
{
|
||||
axp192_found = true;
|
||||
DEBUG_MSG("axp192 PMU found\n");
|
||||
}
|
||||
if (addr == SSD1306_ADDRESS) {
|
||||
ssd1306_found = true;
|
||||
DEBUG_MSG("ssd1306 display found\n");
|
||||
}
|
||||
#ifdef TBEAM_V10
|
||||
if (addr == AXP192_SLAVE_ADDRESS) {
|
||||
axp192_found = true;
|
||||
DEBUG_MSG("axp192 PMU found\n");
|
||||
}
|
||||
#endif
|
||||
} else if (err == 4) {
|
||||
DEBUG_MSG("Unknow error at address 0x%x\n", addr);
|
||||
}
|
||||
}
|
||||
else if (err == 4)
|
||||
{
|
||||
DEBUG_MSG("Unknow error at address 0x%x\n", addr);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
DEBUG_MSG("No I2C devices found\n");
|
||||
else
|
||||
DEBUG_MSG("done\n");
|
||||
if (nDevices == 0)
|
||||
DEBUG_MSG("No I2C devices found\n");
|
||||
else
|
||||
DEBUG_MSG("done\n");
|
||||
}
|
||||
|
||||
#ifdef TBEAM_V10
|
||||
/// Reads power status to powerStatus singleton.
|
||||
//
|
||||
// TODO(girts): move this and other axp stuff to power.h/power.cpp.
|
||||
void readPowerStatus()
|
||||
{
|
||||
powerStatus.haveBattery = axp.isBatteryConnect();
|
||||
if (powerStatus.haveBattery) {
|
||||
powerStatus.batteryVoltageMv = axp.getBattVoltage();
|
||||
}
|
||||
powerStatus.usb = axp.isVBUSPlug();
|
||||
powerStatus.charging = axp.isChargeing();
|
||||
}
|
||||
#endif // TBEAM_V10
|
||||
|
||||
/**
|
||||
* Init the power manager chip
|
||||
*
|
||||
* axp192 power
|
||||
DCDC1 0.7-3.5V @ 1200mA max -> OLED // If you turn this off you'll lose comms to the axp192 because the OLED and the axp192 share the same i2c bus, instead use ssd1306 sleep mode
|
||||
DCDC2 -> unused
|
||||
DCDC3 0.7-3.5V @ 700mA max -> ESP32 (keep this on!)
|
||||
LDO1 30mA -> charges GPS backup battery // charges the tiny J13 battery by the GPS to power the GPS ram (for a couple of days), can not be turned off
|
||||
LDO2 200mA -> LORA
|
||||
LDO3 200mA -> GPS
|
||||
*
|
||||
* axp192 power
|
||||
DCDC1 0.7-3.5V @ 1200mA max -> OLED // If you turn this off you'll lose comms to the axp192 because the OLED and the axp192
|
||||
share the same i2c bus, instead use ssd1306 sleep mode DCDC2 -> unused DCDC3 0.7-3.5V @ 700mA max -> ESP32 (keep this on!) LDO1
|
||||
30mA -> charges GPS backup battery // charges the tiny J13 battery by the GPS to power the GPS ram (for a couple of days), can
|
||||
not be turned off LDO2 200mA -> LORA LDO3 200mA -> GPS
|
||||
*/
|
||||
void axp192Init()
|
||||
{
|
||||
#ifdef T_BEAM_V10
|
||||
if (axp192_found)
|
||||
{
|
||||
if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS))
|
||||
{
|
||||
DEBUG_MSG("AXP192 Begin PASS\n");
|
||||
#ifdef TBEAM_V10
|
||||
if (axp192_found) {
|
||||
if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) {
|
||||
DEBUG_MSG("AXP192 Begin PASS\n");
|
||||
|
||||
// axp.setChgLEDMode(LED_BLINK_4HZ);
|
||||
DEBUG_MSG("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("----------------------------------------\n");
|
||||
// axp.setChgLEDMode(LED_BLINK_4HZ);
|
||||
DEBUG_MSG("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("----------------------------------------\n");
|
||||
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA radio
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS main power
|
||||
axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
axp.setDCDC1Voltage(3300); // for the OLED power
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA radio
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS main power
|
||||
axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
axp.setDCDC1Voltage(3300); // for the OLED power
|
||||
|
||||
DEBUG_MSG("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC1: %s\n", axp.isDCDC1Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC2: %s\n", axp.isDCDC2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO2: %s\n", axp.isLDO2Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("LDO3: %s\n", axp.isLDO3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("DCDC3: %s\n", axp.isDCDC3Enable() ? "ENABLE" : "DISABLE");
|
||||
DEBUG_MSG("Exten: %s\n", axp.isExtenEnable() ? "ENABLE" : "DISABLE");
|
||||
|
||||
#if 0
|
||||
// cribbing from https://github.com/m5stack/M5StickC/blob/master/src/AXP192.cpp to fix charger to be more like 300ms.
|
||||
@@ -158,155 +173,141 @@ void axp192Init()
|
||||
//val = 0x46;
|
||||
//axp._writeByte(AXP202_OFF_CTL, 1, &val); // enable bat detection
|
||||
#endif
|
||||
axp.debugCharging();
|
||||
axp.debugCharging();
|
||||
|
||||
#ifdef PMU_IRQ
|
||||
pinMode(PMU_IRQ, INPUT_PULLUP);
|
||||
attachInterrupt(PMU_IRQ, [] {
|
||||
pmu_irq = true;
|
||||
},
|
||||
RISING);
|
||||
pinMode(PMU_IRQ, INPUT);
|
||||
attachInterrupt(
|
||||
PMU_IRQ, [] { pmu_irq = true; }, FALLING);
|
||||
|
||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
||||
axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1);
|
||||
axp.clearIRQ();
|
||||
axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
|
||||
axp.enableIRQ(AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ | AXP202_CHARGING_FINISHED_IRQ | AXP202_CHARGING_IRQ |
|
||||
AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_PEK_SHORTPRESS_IRQ,
|
||||
1);
|
||||
|
||||
axp.clearIRQ();
|
||||
#endif
|
||||
readPowerStatus();
|
||||
} else {
|
||||
DEBUG_MSG("AXP192 Begin FAIL\n");
|
||||
}
|
||||
} else {
|
||||
DEBUG_MSG("AXP192 not found\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
isCharging = axp.isChargeing() ? 1 : 0;
|
||||
isUSBPowered = axp.isVBUSPlug() ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_MSG("AXP192 Begin FAIL\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_MSG("AXP192 not found\n");
|
||||
}
|
||||
void getMacAddr(uint8_t *dmac)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
assert(esp_efuse_mac_get_default(dmac) == ESP_OK);
|
||||
#else
|
||||
dmac[0] = 0xde;
|
||||
dmac[1] = 0xad;
|
||||
dmac[2] = 0xbe;
|
||||
dmac[3] = 0xef;
|
||||
dmac[4] = 0x01;
|
||||
dmac[5] = 0x02; // FIXME, macaddr stuff needed for NRF52
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *getDeviceName()
|
||||
{
|
||||
uint8_t dmac[6];
|
||||
assert(esp_efuse_mac_get_default(dmac) == ESP_OK);
|
||||
uint8_t dmac[6];
|
||||
|
||||
// Meshtastic_ab3c
|
||||
static char name[20];
|
||||
sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]);
|
||||
return name;
|
||||
getMacAddr(dmac);
|
||||
|
||||
// Meshtastic_ab3c
|
||||
static char name[20];
|
||||
sprintf(name, "Meshtastic_%02x%02x", dmac[4], dmac[5]);
|
||||
return name;
|
||||
}
|
||||
|
||||
static MeshRadio *radio = NULL;
|
||||
|
||||
#include "Router.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Debug
|
||||
#ifdef DEBUG_PORT
|
||||
DEBUG_PORT.begin(SERIAL_BAUD);
|
||||
DEBUG_PORT.begin(SERIAL_BAUD);
|
||||
#endif
|
||||
|
||||
initDeepSleep();
|
||||
initDeepSleep();
|
||||
|
||||
#ifdef VEXT_ENABLE
|
||||
pinMode(VEXT_ENABLE, OUTPUT);
|
||||
digitalWrite(VEXT_ENABLE, 0); // turn on the display power
|
||||
pinMode(VEXT_ENABLE, OUTPUT);
|
||||
digitalWrite(VEXT_ENABLE, 0); // turn on the display power
|
||||
#endif
|
||||
|
||||
#ifdef RESET_OLED
|
||||
pinMode(RESET_OLED, OUTPUT);
|
||||
digitalWrite(RESET_OLED, 1);
|
||||
pinMode(RESET_OLED, OUTPUT);
|
||||
digitalWrite(RESET_OLED, 1);
|
||||
#endif
|
||||
|
||||
#ifdef I2C_SDA
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
scanI2Cdevice();
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
scanI2Cdevice();
|
||||
#endif
|
||||
|
||||
axp192Init();
|
||||
|
||||
// Buttons & LED
|
||||
// Buttons & LED
|
||||
#ifdef BUTTON_PIN
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
digitalWrite(BUTTON_PIN, 1);
|
||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||
digitalWrite(BUTTON_PIN, 1);
|
||||
#endif
|
||||
#ifdef LED_PIN
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, 1); // turn on for now
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, 1 ^ LED_INVERTED); // turn on for now
|
||||
#endif
|
||||
|
||||
// Hello
|
||||
DEBUG_MSG("Meshtastic swver=%s, hwver=%s\n", xstr(APP_VERSION), xstr(HW_VERSION));
|
||||
// Hello
|
||||
DEBUG_MSG("Meshtastic swver=%s, hwver=%s\n", xstr(APP_VERSION), xstr(HW_VERSION));
|
||||
|
||||
// Don't init display if we don't have one or we are waking headless due to a timer event
|
||||
if (wakeCause == ESP_SLEEP_WAKEUP_TIMER)
|
||||
ssd1306_found = false; // forget we even have the hardware
|
||||
#ifndef NO_ESP32
|
||||
// Don't init display if we don't have one or we are waking headless due to a timer event
|
||||
if (wakeCause == ESP_SLEEP_WAKEUP_TIMER)
|
||||
ssd1306_found = false; // forget we even have the hardware
|
||||
#endif
|
||||
|
||||
if (ssd1306_found)
|
||||
screen.setup();
|
||||
// Initialize the screen first so we can show the logo while we start up everything else.
|
||||
if (ssd1306_found)
|
||||
screen.setup();
|
||||
|
||||
// Init GPS
|
||||
gps.setup();
|
||||
axp192Init();
|
||||
|
||||
screen_print("Started...\n");
|
||||
screen.print("Started...\n");
|
||||
|
||||
service.init();
|
||||
// Init GPS
|
||||
gps.setup();
|
||||
|
||||
// setBluetoothEnable(false); we now don't start bluetooth until we enter the proper state
|
||||
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
||||
service.init();
|
||||
|
||||
PowerFSM_setup();
|
||||
powerFSM.trigger(EVENT_BOOT); // transition to ON, FIXME, only do this for cold boots, not waking from SDS
|
||||
}
|
||||
#ifndef NO_ESP32
|
||||
// MUST BE AFTER service.init, so we have our radio config settings (from nodedb init)
|
||||
radio = new MeshRadio();
|
||||
router.addInterface(&radio->radioIf);
|
||||
#endif
|
||||
|
||||
void initBluetooth()
|
||||
{
|
||||
DEBUG_MSG("Starting bluetooth\n");
|
||||
if (radio && !radio->init())
|
||||
recordCriticalError(ErrNoRadio);
|
||||
|
||||
// FIXME - we are leaking like crazy
|
||||
// AllocatorScope scope(btPool);
|
||||
// This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values
|
||||
PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS
|
||||
|
||||
BLEServer *serve = initBLE(getDeviceName(), HW_VENDOR, xstr(APP_VERSION), xstr(HW_VERSION)); // FIXME, use a real name based on the macaddr
|
||||
createMeshBluetoothService(serve);
|
||||
|
||||
// Start advertising - this must be done _after_ creating all services
|
||||
serve->getAdvertising()->start();
|
||||
}
|
||||
|
||||
void setBluetoothEnable(bool on)
|
||||
{
|
||||
if (on != bluetoothOn)
|
||||
{
|
||||
DEBUG_MSG("Setting bluetooth enable=%d\n", on);
|
||||
|
||||
bluetoothOn = on;
|
||||
if (on)
|
||||
{
|
||||
Serial.printf("Pre BT: %u heap size\n", ESP.getFreeHeap());
|
||||
//ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );
|
||||
initBluetooth();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have to totally teardown our bluetooth objects to prevent leaks
|
||||
stopMeshBluetoothService(); // Must do before shutting down bluetooth
|
||||
deinitBLE();
|
||||
destroyMeshBluetoothService(); // must do after deinit, because it frees our service
|
||||
Serial.printf("Shutdown BT: %u heap size\n", ESP.getFreeHeap());
|
||||
//ESP_ERROR_CHECK( heap_trace_stop() );
|
||||
//heap_trace_dump();
|
||||
}
|
||||
}
|
||||
// setBluetoothEnable(false); we now don't start bluetooth until we enter the proper state
|
||||
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
||||
}
|
||||
|
||||
uint32_t ledBlinker()
|
||||
{
|
||||
static bool ledOn;
|
||||
ledOn ^= 1;
|
||||
static bool ledOn;
|
||||
ledOn ^= 1;
|
||||
|
||||
setLed(ledOn);
|
||||
setLed(ledOn);
|
||||
|
||||
// have a very sparse duty cycle of LED being on, unless charging, then blink 0.5Hz square wave rate to indicate that
|
||||
return isCharging ? 1000 : (ledOn ? 2 : 1000);
|
||||
// have a very sparse duty cycle of LED being on, unless charging, then blink 0.5Hz square wave rate to indicate that
|
||||
return powerStatus.charging ? 1000 : (ledOn ? 2 : 1000);
|
||||
}
|
||||
|
||||
Periodic ledPeriodic(ledBlinker);
|
||||
@@ -314,105 +315,119 @@ Periodic ledPeriodic(ledBlinker);
|
||||
#if 0
|
||||
// Turn off for now
|
||||
|
||||
uint32_t axpReads()
|
||||
uint32_t axpDebugRead()
|
||||
{
|
||||
axp.debugCharging();
|
||||
DEBUG_MSG("vbus current %f\n", axp.getVbusCurrent());
|
||||
DEBUG_MSG("charge current %f\n", axp.getBattChargeCurrent());
|
||||
DEBUG_MSG("bat voltage %f\n", axp.getBattVoltage());
|
||||
DEBUG_MSG("batt pct %d\n", axp.getBattPercentage());
|
||||
DEBUG_MSG("is battery connected %d\n", axp.isBatteryConnect());
|
||||
DEBUG_MSG("is USB connected %d\n", axp.isVBUSPlug());
|
||||
DEBUG_MSG("is charging %d\n", axp.isChargeing());
|
||||
|
||||
return 30 * 1000;
|
||||
}
|
||||
|
||||
Periodic axpDebugOutput(axpReads);
|
||||
Periodic axpDebugOutput(axpDebugRead);
|
||||
#endif
|
||||
|
||||
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?
|
||||
|
||||
powerFSM.run_machine();
|
||||
gps.loop();
|
||||
screen.loop();
|
||||
service.loop();
|
||||
gps.loop();
|
||||
router.loop();
|
||||
powerFSM.run_machine();
|
||||
service.loop();
|
||||
|
||||
ledPeriodic.loop();
|
||||
// axpDebugOutput.loop();
|
||||
loopBLE();
|
||||
ledPeriodic.loop();
|
||||
// axpDebugOutput.loop();
|
||||
|
||||
#ifndef NO_ESP32
|
||||
loopBLE();
|
||||
#endif
|
||||
|
||||
// for debug printing
|
||||
// radio.radioIf.canSleep();
|
||||
|
||||
#ifdef T_BEAM_V10
|
||||
if (axp192_found)
|
||||
{
|
||||
#ifdef PMU_IRQ
|
||||
if (pmu_irq)
|
||||
{
|
||||
pmu_irq = false;
|
||||
axp.readIRQ();
|
||||
if (pmu_irq) {
|
||||
pmu_irq = false;
|
||||
axp.readIRQ();
|
||||
|
||||
DEBUG_MSG("pmu irq!\n");
|
||||
DEBUG_MSG("pmu irq!\n");
|
||||
|
||||
isCharging = axp.isChargeing() ? 1 : 0;
|
||||
isUSBPowered = axp.isVBUSPlug() ? 1 : 0;
|
||||
if (axp.isChargingIRQ()) {
|
||||
DEBUG_MSG("Battery start charging\n");
|
||||
}
|
||||
if (axp.isChargingDoneIRQ()) {
|
||||
DEBUG_MSG("Battery fully charged\n");
|
||||
}
|
||||
if (axp.isVbusRemoveIRQ()) {
|
||||
DEBUG_MSG("USB unplugged\n");
|
||||
}
|
||||
if (axp.isVbusPlugInIRQ()) {
|
||||
DEBUG_MSG("USB plugged In\n");
|
||||
}
|
||||
if (axp.isBattPlugInIRQ()) {
|
||||
DEBUG_MSG("Battery inserted\n");
|
||||
}
|
||||
if (axp.isBattRemoveIRQ()) {
|
||||
DEBUG_MSG("Battery removed\n");
|
||||
}
|
||||
if (axp.isPEKShortPressIRQ()) {
|
||||
DEBUG_MSG("PEK short button press\n");
|
||||
}
|
||||
|
||||
axp.clearIRQ();
|
||||
readPowerStatus();
|
||||
axp.clearIRQ();
|
||||
}
|
||||
|
||||
// FIXME AXP192 interrupt is not firing, remove this temporary polling of battery state
|
||||
isCharging = axp.isChargeing() ? 1 : 0;
|
||||
isUSBPowered = axp.isVBUSPlug() ? 1 : 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif // T_BEAM_V10
|
||||
|
||||
#ifdef BUTTON_PIN
|
||||
// if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of this boilerplate)
|
||||
static bool wasPressed = false;
|
||||
static uint32_t minPressMs; // what tick should we call this press long enough
|
||||
static uint32_t lastPingMs;
|
||||
// if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of
|
||||
// this boilerplate)
|
||||
static bool wasPressed = false;
|
||||
|
||||
if (!digitalRead(BUTTON_PIN))
|
||||
{
|
||||
if (!wasPressed)
|
||||
{ // just started a new press
|
||||
DEBUG_MSG("pressing\n");
|
||||
if (!digitalRead(BUTTON_PIN)) {
|
||||
if (!wasPressed) { // just started a new press
|
||||
DEBUG_MSG("pressing\n");
|
||||
|
||||
//doLightSleep();
|
||||
// esp_pm_dump_locks(stdout); // FIXME, do this someplace better
|
||||
wasPressed = true;
|
||||
// doLightSleep();
|
||||
// esp_pm_dump_locks(stdout); // FIXME, do this someplace better
|
||||
wasPressed = true;
|
||||
|
||||
uint32_t now = millis();
|
||||
minPressMs = now + 3000;
|
||||
|
||||
if (now - lastPingMs > 60 * 1000)
|
||||
{ // if more than a minute since our last press, ask other nodes to update their state
|
||||
service.sendNetworkPing();
|
||||
lastPingMs = now;
|
||||
}
|
||||
|
||||
powerFSM.trigger(EVENT_PRESS);
|
||||
powerFSM.trigger(EVENT_PRESS);
|
||||
}
|
||||
} else if (wasPressed) {
|
||||
// we just did a release
|
||||
wasPressed = false;
|
||||
}
|
||||
}
|
||||
else if (wasPressed)
|
||||
{
|
||||
// we just did a release
|
||||
wasPressed = false;
|
||||
if (millis() > minPressMs)
|
||||
{
|
||||
// held long enough
|
||||
screen_print("Erasing prefs");
|
||||
delay(5000); // Give some time to read the screen
|
||||
// ESP.restart();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in)
|
||||
// i.e. don't just keep spinning in loop as fast as we can.
|
||||
//DEBUG_MSG("msecs %d\n", msecstosleep);
|
||||
// Show boot screen for first 3 seconds, then switch to normal operation.
|
||||
static bool showingBootScreen = true;
|
||||
if (showingBootScreen && (millis() > 3000)) {
|
||||
screen.stopBootScreen();
|
||||
showingBootScreen = false;
|
||||
}
|
||||
|
||||
// FIXME - until button press handling is done by interrupt (see polling above) we can't sleep very long at all or buttons feel slow
|
||||
msecstosleep = 10;
|
||||
// Update the screen last, after we've figured out what to show.
|
||||
screen.debug()->setNodeNumbersStatus(nodeDB.getNumOnlineNodes(), nodeDB.getNumNodes());
|
||||
screen.debug()->setChannelNameStatus(channelSettings.name);
|
||||
screen.debug()->setPowerStatus(powerStatus);
|
||||
// TODO(#4): use something based on hdop to show GPS "signal" strength.
|
||||
screen.debug()->setGPSStatus(gps.hasLock() ? "ok" : ":(");
|
||||
screen.loop();
|
||||
|
||||
delay(msecstosleep);
|
||||
}
|
||||
// No GPS lock yet, let the OS put the main CPU in low power mode for 100ms (or until another interrupt comes in)
|
||||
// i.e. don't just keep spinning in loop as fast as we can.
|
||||
// DEBUG_MSG("msecs %d\n", msecstosleep);
|
||||
|
||||
// FIXME - until button press handling is done by interrupt (see polling above) we can't sleep very long at all or buttons
|
||||
// feel slow
|
||||
msecstosleep = 10;
|
||||
|
||||
delay(msecstosleep);
|
||||
}
|
||||
|
||||
10
src/main.h
10
src/main.h
@@ -1,6 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
extern bool axp192_found;
|
||||
extern bool ssd1306_found;
|
||||
extern bool isCharging;
|
||||
extern bool isUSBPowered;
|
||||
extern bool isUSBPowered;
|
||||
|
||||
// Global Screen singleton.
|
||||
extern meshtastic::Screen screen;
|
||||
|
||||
// Return a human readable string of the form "Meshtastic_ab13"
|
||||
const char *getDeviceName();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <Arduino.h>
|
||||
#include "configuration.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
#include <assert.h>
|
||||
#include "FS.h"
|
||||
#include "configuration.h"
|
||||
#include <Arduino.h>
|
||||
#include <assert.h>
|
||||
#include <pb_decode.h>
|
||||
#include <pb_encode.h>
|
||||
|
||||
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
||||
/// returns the encoded packet size
|
||||
@@ -12,42 +12,34 @@ size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc
|
||||
{
|
||||
|
||||
pb_ostream_t stream = pb_ostream_from_buffer(destbuf, destbufsize);
|
||||
if (!pb_encode(&stream, fields, src_struct))
|
||||
{
|
||||
if (!pb_encode(&stream, fields, src_struct)) {
|
||||
DEBUG_MSG("Error: can't encode protobuf %s\n", PB_GET_ERROR(&stream));
|
||||
assert(0); // FIXME - panic
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return stream.bytes_written;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// helper function for decoding a record as a protobuf, we will return false if the decoding failed
|
||||
bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msgdesc_t *fields, void *dest_struct)
|
||||
{
|
||||
pb_istream_t stream = pb_istream_from_buffer(srcbuf, srcbufsize);
|
||||
if (!pb_decode(&stream, fields, dest_struct))
|
||||
{
|
||||
DEBUG_MSG("Error: can't decode protobuf %s\n", PB_GET_ERROR(&stream));
|
||||
if (!pb_decode(&stream, fields, dest_struct)) {
|
||||
DEBUG_MSG("Error: can't decode protobuf %s, pb_msgdesc 0x%p\n", PB_GET_ERROR(&stream), fields);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Read from an Arduino File
|
||||
bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
|
||||
{
|
||||
bool status = false;
|
||||
#ifndef NO_ESP32
|
||||
File *file = (File *)stream->state;
|
||||
bool status;
|
||||
|
||||
if (buf == NULL)
|
||||
{
|
||||
if (buf == NULL) {
|
||||
while (count-- && file->read() != EOF)
|
||||
;
|
||||
return count == 0;
|
||||
@@ -57,15 +49,18 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count)
|
||||
|
||||
if (file->available() == 0)
|
||||
stream->bytes_left = 0;
|
||||
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/// Write to an arduino file
|
||||
bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count)
|
||||
{
|
||||
File *file = (File*) stream->state;
|
||||
//DEBUG_MSG("writing %d bytes to protobuf file\n", count);
|
||||
return file->write(buf, count) == count;
|
||||
#ifndef NO_ESP32
|
||||
File *file = (File *)stream->state;
|
||||
// DEBUG_MSG("writing %d bytes to protobuf file\n", count);
|
||||
return file->write(buf, count) == count;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
#define member_size(type, member) sizeof(((type *)0)->member)
|
||||
|
||||
/// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf
|
||||
#define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0]))
|
||||
#define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0]))
|
||||
|
||||
/// max number of nodes allowed in the mesh
|
||||
#define MAX_NUM_NODES (member_size(DeviceState, node_db) / member_size(DeviceState, node_db[0]))
|
||||
|
||||
#define MAX_NUM_NODES (member_size(DeviceState, node_db) / member_size(DeviceState, node_db[0]))
|
||||
|
||||
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
||||
/// returns the encoded packet size
|
||||
|
||||
@@ -15,6 +15,9 @@ PB_BIND(Data, Data, 2)
|
||||
PB_BIND(User, User, AUTO)
|
||||
|
||||
|
||||
PB_BIND(RouteDiscovery, RouteDiscovery, AUTO)
|
||||
|
||||
|
||||
PB_BIND(SubPacket, SubPacket, 2)
|
||||
|
||||
|
||||
|
||||
@@ -32,9 +32,12 @@ typedef enum _ChannelSettings_ModemConfig {
|
||||
} ChannelSettings_ModemConfig;
|
||||
|
||||
/* Struct definitions */
|
||||
typedef struct _RouteDiscovery {
|
||||
pb_callback_t route;
|
||||
} RouteDiscovery;
|
||||
|
||||
typedef struct _ChannelSettings {
|
||||
int32_t tx_power;
|
||||
uint32_t channel_num;
|
||||
ChannelSettings_ModemConfig modem_config;
|
||||
pb_byte_t psk[16];
|
||||
char name[12];
|
||||
@@ -51,8 +54,11 @@ typedef struct _MyNodeInfo {
|
||||
bool has_gps;
|
||||
int32_t num_channels;
|
||||
char region[12];
|
||||
char hw_model[12];
|
||||
char hw_model[16];
|
||||
char firmware_version[12];
|
||||
uint32_t error_code;
|
||||
uint32_t error_address;
|
||||
uint32_t error_count;
|
||||
} MyNodeInfo;
|
||||
|
||||
typedef struct _Position {
|
||||
@@ -104,12 +110,12 @@ typedef struct _RadioConfig {
|
||||
} RadioConfig;
|
||||
|
||||
typedef struct _SubPacket {
|
||||
pb_size_t which_variant;
|
||||
union {
|
||||
Position position;
|
||||
Data data;
|
||||
User user;
|
||||
} variant;
|
||||
bool has_position;
|
||||
Position position;
|
||||
bool has_data;
|
||||
Data data;
|
||||
bool has_user;
|
||||
User user;
|
||||
bool want_response;
|
||||
} SubPacket;
|
||||
|
||||
@@ -119,6 +125,8 @@ typedef struct _MeshPacket {
|
||||
bool has_payload;
|
||||
SubPacket payload;
|
||||
uint32_t rx_time;
|
||||
int32_t rx_snr;
|
||||
uint32_t id;
|
||||
} MeshPacket;
|
||||
|
||||
typedef struct _DeviceState {
|
||||
@@ -171,33 +179,35 @@ typedef struct _ToRadio {
|
||||
#define Position_init_default {0, 0, 0, 0, 0}
|
||||
#define Data_init_default {_Data_Type_MIN, {0, {0}}}
|
||||
#define User_init_default {"", "", "", {0}}
|
||||
#define SubPacket_init_default {0, {Position_init_default}, 0}
|
||||
#define MeshPacket_init_default {0, 0, false, SubPacket_init_default, 0}
|
||||
#define ChannelSettings_init_default {0, 0, _ChannelSettings_ModemConfig_MIN, {0}, ""}
|
||||
#define RouteDiscovery_init_default {{{NULL}, NULL}}
|
||||
#define SubPacket_init_default {false, Position_init_default, false, Data_init_default, false, User_init_default, 0}
|
||||
#define MeshPacket_init_default {0, 0, false, SubPacket_init_default, 0, 0, 0}
|
||||
#define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0}, ""}
|
||||
#define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default}
|
||||
#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
#define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0}
|
||||
#define MyNodeInfo_init_default {0, 0, 0, "", "", ""}
|
||||
#define MyNodeInfo_init_default {0, 0, 0, "", "", "", 0, 0, 0}
|
||||
#define DeviceState_init_default {false, RadioConfig_init_default, false, MyNodeInfo_init_default, false, User_init_default, 0, {NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default, NodeInfo_init_default}, 0, {MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default, MeshPacket_init_default}, false, MeshPacket_init_default, 0}
|
||||
#define FromRadio_init_default {0, 0, {MeshPacket_init_default}}
|
||||
#define ToRadio_init_default {0, {MeshPacket_init_default}}
|
||||
#define Position_init_zero {0, 0, 0, 0, 0}
|
||||
#define Data_init_zero {_Data_Type_MIN, {0, {0}}}
|
||||
#define User_init_zero {"", "", "", {0}}
|
||||
#define SubPacket_init_zero {0, {Position_init_zero}, 0}
|
||||
#define MeshPacket_init_zero {0, 0, false, SubPacket_init_zero, 0}
|
||||
#define ChannelSettings_init_zero {0, 0, _ChannelSettings_ModemConfig_MIN, {0}, ""}
|
||||
#define RouteDiscovery_init_zero {{{NULL}, NULL}}
|
||||
#define SubPacket_init_zero {false, Position_init_zero, false, Data_init_zero, false, User_init_zero, 0}
|
||||
#define MeshPacket_init_zero {0, 0, false, SubPacket_init_zero, 0, 0, 0}
|
||||
#define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0}, ""}
|
||||
#define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero}
|
||||
#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
#define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0}
|
||||
#define MyNodeInfo_init_zero {0, 0, 0, "", "", ""}
|
||||
#define MyNodeInfo_init_zero {0, 0, 0, "", "", "", 0, 0, 0}
|
||||
#define DeviceState_init_zero {false, RadioConfig_init_zero, false, MyNodeInfo_init_zero, false, User_init_zero, 0, {NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero, NodeInfo_init_zero}, 0, {MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero, MeshPacket_init_zero}, false, MeshPacket_init_zero, 0}
|
||||
#define FromRadio_init_zero {0, 0, {MeshPacket_init_zero}}
|
||||
#define ToRadio_init_zero {0, {MeshPacket_init_zero}}
|
||||
|
||||
/* Field tags (for use in manual encoding/decoding) */
|
||||
#define RouteDiscovery_route_tag 2
|
||||
#define ChannelSettings_tx_power_tag 1
|
||||
#define ChannelSettings_channel_num_tag 2
|
||||
#define ChannelSettings_modem_config_tag 3
|
||||
#define ChannelSettings_psk_tag 4
|
||||
#define ChannelSettings_name_tag 5
|
||||
@@ -209,6 +219,9 @@ typedef struct _ToRadio {
|
||||
#define MyNodeInfo_region_tag 4
|
||||
#define MyNodeInfo_hw_model_tag 5
|
||||
#define MyNodeInfo_firmware_version_tag 6
|
||||
#define MyNodeInfo_error_code_tag 7
|
||||
#define MyNodeInfo_error_address_tag 8
|
||||
#define MyNodeInfo_error_count_tag 9
|
||||
#define Position_latitude_tag 1
|
||||
#define Position_longitude_tag 2
|
||||
#define Position_altitude_tag 3
|
||||
@@ -246,6 +259,8 @@ typedef struct _ToRadio {
|
||||
#define MeshPacket_to_tag 2
|
||||
#define MeshPacket_payload_tag 3
|
||||
#define MeshPacket_rx_time_tag 4
|
||||
#define MeshPacket_rx_snr_tag 5
|
||||
#define MeshPacket_id_tag 6
|
||||
#define DeviceState_radio_tag 1
|
||||
#define DeviceState_my_node_tag 2
|
||||
#define DeviceState_owner_tag 3
|
||||
@@ -281,29 +296,35 @@ X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, macaddr, 4)
|
||||
#define User_CALLBACK NULL
|
||||
#define User_DEFAULT NULL
|
||||
|
||||
#define RouteDiscovery_FIELDLIST(X, a) \
|
||||
X(a, CALLBACK, REPEATED, INT32, route, 2)
|
||||
#define RouteDiscovery_CALLBACK pb_default_field_callback
|
||||
#define RouteDiscovery_DEFAULT NULL
|
||||
|
||||
#define SubPacket_FIELDLIST(X, a) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (variant,position,variant.position), 1) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (variant,data,variant.data), 3) \
|
||||
X(a, STATIC, ONEOF, MESSAGE, (variant,user,variant.user), 4) \
|
||||
X(a, STATIC, OPTIONAL, MESSAGE, position, 1) \
|
||||
X(a, STATIC, OPTIONAL, MESSAGE, data, 3) \
|
||||
X(a, STATIC, OPTIONAL, MESSAGE, user, 4) \
|
||||
X(a, STATIC, SINGULAR, BOOL, want_response, 5)
|
||||
#define SubPacket_CALLBACK NULL
|
||||
#define SubPacket_DEFAULT NULL
|
||||
#define SubPacket_variant_position_MSGTYPE Position
|
||||
#define SubPacket_variant_data_MSGTYPE Data
|
||||
#define SubPacket_variant_user_MSGTYPE User
|
||||
#define SubPacket_position_MSGTYPE Position
|
||||
#define SubPacket_data_MSGTYPE Data
|
||||
#define SubPacket_user_MSGTYPE User
|
||||
|
||||
#define MeshPacket_FIELDLIST(X, a) \
|
||||
X(a, STATIC, SINGULAR, INT32, from, 1) \
|
||||
X(a, STATIC, SINGULAR, INT32, to, 2) \
|
||||
X(a, STATIC, OPTIONAL, MESSAGE, payload, 3) \
|
||||
X(a, STATIC, SINGULAR, UINT32, rx_time, 4)
|
||||
X(a, STATIC, SINGULAR, UINT32, rx_time, 4) \
|
||||
X(a, STATIC, SINGULAR, SINT32, rx_snr, 5) \
|
||||
X(a, STATIC, SINGULAR, UINT32, id, 6)
|
||||
#define MeshPacket_CALLBACK NULL
|
||||
#define MeshPacket_DEFAULT NULL
|
||||
#define MeshPacket_payload_MSGTYPE SubPacket
|
||||
|
||||
#define ChannelSettings_FIELDLIST(X, a) \
|
||||
X(a, STATIC, SINGULAR, INT32, tx_power, 1) \
|
||||
X(a, STATIC, SINGULAR, UINT32, channel_num, 2) \
|
||||
X(a, STATIC, SINGULAR, UENUM, modem_config, 3) \
|
||||
X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, psk, 4) \
|
||||
X(a, STATIC, SINGULAR, STRING, name, 5)
|
||||
@@ -352,7 +373,10 @@ X(a, STATIC, SINGULAR, BOOL, has_gps, 2) \
|
||||
X(a, STATIC, SINGULAR, INT32, num_channels, 3) \
|
||||
X(a, STATIC, SINGULAR, STRING, region, 4) \
|
||||
X(a, STATIC, SINGULAR, STRING, hw_model, 5) \
|
||||
X(a, STATIC, SINGULAR, STRING, firmware_version, 6)
|
||||
X(a, STATIC, SINGULAR, STRING, firmware_version, 6) \
|
||||
X(a, STATIC, SINGULAR, UINT32, error_code, 7) \
|
||||
X(a, STATIC, SINGULAR, UINT32, error_address, 8) \
|
||||
X(a, STATIC, SINGULAR, UINT32, error_count, 9)
|
||||
#define MyNodeInfo_CALLBACK NULL
|
||||
#define MyNodeInfo_DEFAULT NULL
|
||||
|
||||
@@ -389,6 +413,7 @@ X(a, STATIC, ONEOF, MESSAGE, (variant,packet,variant.packet), 1)
|
||||
extern const pb_msgdesc_t Position_msg;
|
||||
extern const pb_msgdesc_t Data_msg;
|
||||
extern const pb_msgdesc_t User_msg;
|
||||
extern const pb_msgdesc_t RouteDiscovery_msg;
|
||||
extern const pb_msgdesc_t SubPacket_msg;
|
||||
extern const pb_msgdesc_t MeshPacket_msg;
|
||||
extern const pb_msgdesc_t ChannelSettings_msg;
|
||||
@@ -404,6 +429,7 @@ extern const pb_msgdesc_t ToRadio_msg;
|
||||
#define Position_fields &Position_msg
|
||||
#define Data_fields &Data_msg
|
||||
#define User_fields &User_msg
|
||||
#define RouteDiscovery_fields &RouteDiscovery_msg
|
||||
#define SubPacket_fields &SubPacket_msg
|
||||
#define MeshPacket_fields &MeshPacket_msg
|
||||
#define ChannelSettings_fields &ChannelSettings_msg
|
||||
@@ -419,16 +445,17 @@ extern const pb_msgdesc_t ToRadio_msg;
|
||||
#define Position_size 46
|
||||
#define Data_size 256
|
||||
#define User_size 72
|
||||
#define SubPacket_size 261
|
||||
#define MeshPacket_size 292
|
||||
#define ChannelSettings_size 50
|
||||
#define RadioConfig_size 126
|
||||
/* RouteDiscovery_size depends on runtime parameters */
|
||||
#define SubPacket_size 383
|
||||
#define MeshPacket_size 426
|
||||
#define ChannelSettings_size 44
|
||||
#define RadioConfig_size 120
|
||||
#define RadioConfig_UserPreferences_size 72
|
||||
#define NodeInfo_size 155
|
||||
#define MyNodeInfo_size 63
|
||||
#define DeviceState_size 15064
|
||||
#define FromRadio_size 301
|
||||
#define ToRadio_size 295
|
||||
#define MyNodeInfo_size 85
|
||||
#define DeviceState_size 19502
|
||||
#define FromRadio_size 435
|
||||
#define ToRadio_size 429
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
18
src/power.h
Normal file
18
src/power.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
namespace meshtastic
|
||||
{
|
||||
|
||||
/// Describes the state of the power system.
|
||||
struct PowerStatus {
|
||||
/// Whether we have a battery connected
|
||||
bool haveBattery;
|
||||
/// Battery voltage in mV, valid if haveBattery is true
|
||||
int batteryVoltageMv;
|
||||
/// Whether USB is connected
|
||||
bool usb;
|
||||
/// Whether we are charging the battery
|
||||
bool charging;
|
||||
};
|
||||
|
||||
} // namespace meshtastic
|
||||
@@ -1,27 +1,28 @@
|
||||
#include "CustomRF95.h"
|
||||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
#include "configuration.h"
|
||||
#include "NodeDB.h" // FIXME, this class should not need to touch nodedb
|
||||
#include "assert.h"
|
||||
#include "NodeDB.h"
|
||||
#include "configuration.h"
|
||||
#include <pb_decode.h>
|
||||
#include <pb_encode.h>
|
||||
|
||||
#ifdef RF95_IRQ_GPIO
|
||||
|
||||
/// A temporary buffer used for sending/receving packets, sized to hold the biggest buffer we might need
|
||||
#define MAX_RHPACKETLEN 251
|
||||
static uint8_t radiobuf[MAX_RHPACKETLEN];
|
||||
|
||||
CustomRF95::CustomRF95(MemoryPool<MeshPacket> &_pool, PointerQueue<MeshPacket> &_rxDest)
|
||||
: RH_RF95(NSS_GPIO, DIO0_GPIO),
|
||||
pool(_pool),
|
||||
rxDest(_rxDest),
|
||||
txQueue(MAX_TX_QUEUE),
|
||||
sendingPacket(NULL)
|
||||
{
|
||||
}
|
||||
CustomRF95::CustomRF95() : RH_RF95(NSS_GPIO, RF95_IRQ_GPIO), txQueue(MAX_TX_QUEUE) {}
|
||||
|
||||
bool CustomRF95::canSleep()
|
||||
{
|
||||
// We allow initializing mode, because sometimes while testing we don't ever call init() to turn on the hardware
|
||||
return (_mode == RHModeInitialising || _mode == RHModeIdle || _mode == RHModeRx) && !_isReceiving && txQueue.isEmpty();
|
||||
bool isRx = isReceiving();
|
||||
|
||||
bool res = (_mode == RHModeInitialising || _mode == RHModeIdle || _mode == RHModeRx) && !isRx && txQueue.isEmpty();
|
||||
if (!res) // only print debug messages if we are vetoing sleep
|
||||
DEBUG_MSG("radio wait to sleep, mode=%d, isRx=%d, txEmpty=%d, txGood=%d\n", _mode, isRx, txQueue.isEmpty(), _txGood);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CustomRF95::sleep()
|
||||
@@ -46,46 +47,49 @@ bool CustomRF95::init()
|
||||
ErrorCode CustomRF95::send(MeshPacket *p)
|
||||
{
|
||||
// We wait _if_ we are partially though receiving a packet (rather than just merely waiting for one).
|
||||
// To do otherwise would be doubly bad because not only would we drop the packet that was on the way in,
|
||||
// To do otherwise would be doubly bad because not only would we drop the packet that was on the way in,
|
||||
// we almost certainly guarantee no one outside will like the packet we are sending.
|
||||
if (_mode == RHModeIdle || (_mode == RHModeRx && !_isReceiving))
|
||||
{
|
||||
if (_mode == RHModeIdle || (_mode == RHModeRx && !isReceiving())) {
|
||||
// if the radio is idle, we can send right away
|
||||
DEBUG_MSG("immedate send on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", txGood(), rxGood(), rxBad());
|
||||
DEBUG_MSG("immediate send on mesh fr=0x%x,to=0x%x,id=%d\n (txGood=%d,rxGood=%d,rxBad=%d)\n", p->from, p->to, p->id,
|
||||
txGood(), rxGood(), rxBad());
|
||||
|
||||
waitPacketSent(); // Make sure we dont interrupt an outgoing message
|
||||
|
||||
if (!waitCAD())
|
||||
return false; // Check channel activity
|
||||
|
||||
startSend(p);
|
||||
return ERRNO_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEBUG_MSG("enquing packet for send from=0x%x, to=0x%x\n", p->from, p->to);
|
||||
ErrorCode res = txQueue.enqueue(p, 0) ? ERRNO_OK : ERRNO_UNKNOWN;
|
||||
|
||||
if (res != ERRNO_OK) // we weren't able to queue it, so we must drop it to prevent leaks
|
||||
pool.release(p);
|
||||
packetPool.release(p);
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
// After doing standard behavior, check to see if a new packet arrived or one was sent and start a new send or receive as necessary
|
||||
// After doing standard behavior, check to see if a new packet arrived or one was sent and start a new send or receive as
|
||||
// necessary
|
||||
void CustomRF95::handleInterrupt()
|
||||
{
|
||||
RH_RF95::handleInterrupt();
|
||||
|
||||
BaseType_t higherPriWoken = false;
|
||||
if (_mode == RHModeIdle) // We are now done sending or receiving
|
||||
{
|
||||
if (sendingPacket) // Were we sending?
|
||||
{
|
||||
// We are done sending that packet, release it
|
||||
pool.releaseFromISR(sendingPacket, &higherPriWoken);
|
||||
packetPool.release(sendingPacket);
|
||||
sendingPacket = NULL;
|
||||
// DEBUG_MSG("Done with send\n");
|
||||
}
|
||||
|
||||
// If we just finished receiving a packet, forward it into a queue
|
||||
if (_rxBufValid)
|
||||
{
|
||||
if (_rxBufValid) {
|
||||
// We received a packet
|
||||
|
||||
// Skip the 4 headers that are at the beginning of the rxBuf
|
||||
@@ -94,15 +98,17 @@ void CustomRF95::handleInterrupt()
|
||||
|
||||
// FIXME - throws exception if called in ISR context: frequencyError() - probably the floating point math
|
||||
int32_t freqerr = -1, snr = lastSNR();
|
||||
//DEBUG_MSG("Received packet from mesh src=0x%x,dest=0x%x,id=%d,len=%d rxGood=%d,rxBad=%d,freqErr=%d,snr=%d\n",
|
||||
// DEBUG_MSG("Received packet from mesh src=0x%x,dest=0x%x,id=%d,len=%d rxGood=%d,rxBad=%d,freqErr=%d,snr=%d\n",
|
||||
// srcaddr, destaddr, id, rxlen, rf95.rxGood(), rf95.rxBad(), freqerr, snr);
|
||||
|
||||
MeshPacket *mp = pool.allocZeroed();
|
||||
MeshPacket *mp = packetPool.allocZeroed();
|
||||
|
||||
SubPacket *p = &mp->payload;
|
||||
|
||||
mp->from = _rxHeaderFrom;
|
||||
mp->to = _rxHeaderTo;
|
||||
mp->id = _rxHeaderId;
|
||||
|
||||
//_rxHeaderId = _buf[2];
|
||||
//_rxHeaderFlags = _buf[3];
|
||||
|
||||
@@ -110,55 +116,41 @@ void CustomRF95::handleInterrupt()
|
||||
// Note: we can't create it at this point, because it might be a bogus User node allocation. But odds are we will
|
||||
// already have a record we can hide this debugging info in.
|
||||
NodeInfo *info = nodeDB.getNode(mp->from);
|
||||
if (info)
|
||||
{
|
||||
if (info) {
|
||||
info->snr = snr;
|
||||
info->frequency_error = freqerr;
|
||||
}
|
||||
|
||||
if (!pb_decode_from_bytes(payload, payloadLen, SubPacket_fields, p))
|
||||
{
|
||||
pool.releaseFromISR(mp, &higherPriWoken);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!pb_decode_from_bytes(payload, payloadLen, SubPacket_fields, p)) {
|
||||
packetPool.release(mp);
|
||||
} else {
|
||||
// parsing was successful, queue for our recipient
|
||||
mp->has_payload = true;
|
||||
|
||||
int res = rxDest.enqueueFromISR(mp, &higherPriWoken); // NOWAIT - fixme, if queue is full, delete older messages
|
||||
assert(res == pdTRUE);
|
||||
deliverToReceiver(mp);
|
||||
}
|
||||
|
||||
clearRxBuf(); // This message accepted and cleared
|
||||
}
|
||||
|
||||
higherPriWoken |= handleIdleISR();
|
||||
handleIdleISR();
|
||||
}
|
||||
|
||||
// If we call this _IT WILL NOT RETURN_
|
||||
if (higherPriWoken)
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
|
||||
/** The ISR doesn't have any good work to do, give a new assignment.
|
||||
*
|
||||
*
|
||||
* Return true if a higher pri task has woken
|
||||
*/
|
||||
bool CustomRF95::handleIdleISR()
|
||||
void CustomRF95::handleIdleISR()
|
||||
{
|
||||
BaseType_t higherPriWoken = false;
|
||||
|
||||
// First send any outgoing packets we have ready
|
||||
MeshPacket *txp = txQueue.dequeuePtrFromISR(0);
|
||||
MeshPacket *txp = txQueue.dequeuePtr(0);
|
||||
if (txp)
|
||||
startSend(txp);
|
||||
else
|
||||
{
|
||||
else {
|
||||
// Nothing to send, let's switch back to receive mode
|
||||
setModeRx();
|
||||
}
|
||||
|
||||
return higherPriWoken;
|
||||
}
|
||||
|
||||
/// This routine might be called either from user space or ISR
|
||||
@@ -169,14 +161,18 @@ void CustomRF95::startSend(MeshPacket *txp)
|
||||
// DEBUG_MSG("sending queued packet on mesh (txGood=%d,rxGood=%d,rxBad=%d)\n", rf95.txGood(), rf95.rxGood(), rf95.rxBad());
|
||||
assert(txp->has_payload);
|
||||
|
||||
lastTxStart = millis();
|
||||
|
||||
size_t numbytes = pb_encode_to_bytes(radiobuf, sizeof(radiobuf), SubPacket_fields, &txp->payload);
|
||||
|
||||
sendingPacket = txp;
|
||||
|
||||
setHeaderTo(txp->to);
|
||||
setHeaderFrom(nodeDB.getNodeNum()); // We must do this before each send, because we might have just changed our nodenum
|
||||
setHeaderId(txp->id);
|
||||
|
||||
// setHeaderId(0);
|
||||
// if the sender nodenum is zero, that means uninitialized
|
||||
assert(txp->from);
|
||||
setHeaderFrom(txp->from); // We must do this before each send, because we might have just changed our nodenum
|
||||
|
||||
assert(numbytes <= 251); // Make sure we don't overflow the tiny max packet size
|
||||
|
||||
@@ -184,4 +180,29 @@ void CustomRF95::startSend(MeshPacket *txp)
|
||||
|
||||
int res = RH_RF95::send(radiobuf, numbytes);
|
||||
assert(res);
|
||||
}
|
||||
}
|
||||
|
||||
#define TX_WATCHDOG_TIMEOUT 30 * 1000
|
||||
|
||||
#include "error.h"
|
||||
|
||||
void CustomRF95::loop()
|
||||
{
|
||||
RH_RF95::loop();
|
||||
|
||||
// It should never take us more than 30 secs to send a packet, if it does, we have a bug, FIXME, move most of this
|
||||
// into CustomRF95
|
||||
uint32_t now = millis();
|
||||
if (lastTxStart != 0 && (now - lastTxStart) > TX_WATCHDOG_TIMEOUT && mode() == RHGenericDriver::RHModeTx) {
|
||||
DEBUG_MSG("ERROR! Bug! Tx packet took too long to send, forcing radio into rx mode\n");
|
||||
setModeRx();
|
||||
if (sendingPacket) { // There was probably a packet we were trying to send, free it
|
||||
packetPool.release(sendingPacket);
|
||||
sendingPacket = NULL;
|
||||
}
|
||||
recordCriticalError(ErrTxWatchdog);
|
||||
lastTxStart = 0; // Stop checking for now, because we just warned the developer
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,36 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <RH_RF95.h>
|
||||
#include <RHMesh.h>
|
||||
#include "MemoryPool.h"
|
||||
#include "RadioInterface.h"
|
||||
#include "mesh.pb.h"
|
||||
#include "PointerQueue.h"
|
||||
#include "MeshTypes.h"
|
||||
#include <RH_RF95.h>
|
||||
|
||||
#define MAX_TX_QUEUE 16 // max number of packets which can be waiting for transmission
|
||||
|
||||
|
||||
/**
|
||||
* A version of the RF95 driver which is smart enough to manage packets via queues (no polling or blocking in user threads!)
|
||||
*/
|
||||
class CustomRF95 : public RH_RF95
|
||||
class CustomRF95 : public RH_RF95, public RadioInterface
|
||||
{
|
||||
friend class MeshRadio; // for debugging we let that class touch pool
|
||||
|
||||
MemoryPool<MeshPacket> &pool;
|
||||
PointerQueue<MeshPacket> &rxDest;
|
||||
PointerQueue<MeshPacket> txQueue;
|
||||
|
||||
MeshPacket *sendingPacket; // The packet we are currently sending
|
||||
public:
|
||||
uint32_t lastTxStart = 0L;
|
||||
|
||||
public:
|
||||
/** pool is the pool we will alloc our rx packets from
|
||||
* rxDest is where we will send any rx packets, it becomes receivers responsibility to return packet to the pool
|
||||
*/
|
||||
CustomRF95(MemoryPool<MeshPacket> &pool, PointerQueue<MeshPacket> &rxDest);
|
||||
CustomRF95();
|
||||
|
||||
/**
|
||||
* Return true if we think the board can go to sleep (i.e. our tx queue is empty, we are not sending or receiving)
|
||||
*
|
||||
*
|
||||
* This method must be used before putting the CPU into deep or light sleep.
|
||||
*/
|
||||
bool canSleep();
|
||||
@@ -45,14 +40,17 @@ public:
|
||||
|
||||
bool init();
|
||||
|
||||
protected:
|
||||
// After doing standard behavior, check to see if a new packet arrived or one was sent and start a new send or receive as necessary
|
||||
void loop(); // Idle processing
|
||||
|
||||
protected:
|
||||
// After doing standard behavior, check to see if a new packet arrived or one was sent and start a new send or receive as
|
||||
// necessary
|
||||
virtual void handleInterrupt();
|
||||
|
||||
private:
|
||||
private:
|
||||
/// Send a new packet - this low level call can be called from either ISR or userspace
|
||||
void startSend(MeshPacket *txp);
|
||||
|
||||
/// Return true if a higher pri task has woken
|
||||
bool handleIdleISR();
|
||||
void handleIdleISR();
|
||||
};
|
||||
99
src/rf95/FloodingRouter.cpp
Normal file
99
src/rf95/FloodingRouter.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "FloodingRouter.h"
|
||||
#include "configuration.h"
|
||||
#include "mesh-pb-constants.h"
|
||||
|
||||
/// We clear our old flood record five minute after we see the last of it
|
||||
#define FLOOD_EXPIRE_TIME (5 * 60 * 1000L)
|
||||
|
||||
FloodingRouter::FloodingRouter()
|
||||
{
|
||||
recentBroadcasts.reserve(MAX_NUM_NODES); // Prealloc the worst case # of records - to prevent heap fragmentation
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet on a suitable interface. This routine will
|
||||
* later free() the packet to pool. This routine is not allowed to stall.
|
||||
* If the txmit queue is full it might return an error
|
||||
*/
|
||||
ErrorCode FloodingRouter::send(MeshPacket *p)
|
||||
{
|
||||
// We update our table of recent broadcasts, even for messages we send
|
||||
wasSeenRecently(p);
|
||||
|
||||
return Router::send(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from loop()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
*
|
||||
* Note: this method will free the provided packet
|
||||
*/
|
||||
void FloodingRouter::handleReceived(MeshPacket *p)
|
||||
{
|
||||
if (wasSeenRecently(p)) {
|
||||
DEBUG_MSG("Ignoring incoming floodmsg, because we've already seen it\n");
|
||||
packetPool.release(p);
|
||||
} else {
|
||||
if (p->to == NODENUM_BROADCAST) {
|
||||
if (p->id != 0) {
|
||||
DEBUG_MSG("Rebroadcasting received floodmsg to neighbors fr=0x%x,to=0x%x,id=%d\n", p->from, p->to, p->id);
|
||||
// FIXME, wait a random delay
|
||||
|
||||
MeshPacket *tosend = packetPool.allocCopy(*p);
|
||||
// Note: we are careful to resend using the original senders node id
|
||||
Router::send(tosend); // We are careful not to call our hooked version of send()
|
||||
} else {
|
||||
DEBUG_MSG("Ignoring a simple (0 hop) broadcast\n");
|
||||
}
|
||||
}
|
||||
|
||||
// handle the packet as normal
|
||||
Router::handleReceived(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update recentBroadcasts and return true if we have already seen this packet
|
||||
*/
|
||||
bool FloodingRouter::wasSeenRecently(const MeshPacket *p)
|
||||
{
|
||||
if (p->to != NODENUM_BROADCAST)
|
||||
return false; // Not a broadcast, so we don't care
|
||||
|
||||
if (p->id == 0) {
|
||||
DEBUG_MSG("Ignoring message with zero id\n");
|
||||
return false; // Not a floodable message ID, so we don't care
|
||||
}
|
||||
|
||||
uint32_t now = millis();
|
||||
for (int i = 0; i < recentBroadcasts.size();) {
|
||||
BroadcastRecord &r = recentBroadcasts[i];
|
||||
|
||||
if ((now - r.rxTimeMsec) >= FLOOD_EXPIRE_TIME) {
|
||||
DEBUG_MSG("Deleting old broadcast record %d\n", i);
|
||||
recentBroadcasts.erase(recentBroadcasts.begin() + i); // delete old record
|
||||
} else {
|
||||
if (r.id == p->id && r.sender == p->from) {
|
||||
DEBUG_MSG("Found existing broadcast record for fr=0x%x,to=0x%x,id=%d\n", p->from, p->to, p->id);
|
||||
|
||||
// Update the time on this record to now
|
||||
r.rxTimeMsec = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Didn't find an existing record, make one
|
||||
BroadcastRecord r;
|
||||
r.id = p->id;
|
||||
r.sender = p->from;
|
||||
r.rxTimeMsec = now;
|
||||
recentBroadcasts.push_back(r);
|
||||
DEBUG_MSG("Adding broadcast record for fr=0x%x,to=0x%x,id=%d\n", p->from, p->to, p->id);
|
||||
|
||||
return false;
|
||||
}
|
||||
72
src/rf95/FloodingRouter.h
Normal file
72
src/rf95/FloodingRouter.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "Router.h"
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* A record of a recent message broadcast
|
||||
*/
|
||||
struct BroadcastRecord {
|
||||
NodeNum sender;
|
||||
PacketId id;
|
||||
uint32_t rxTimeMsec; // Unix time in msecs - the time we received it
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a mixin that extends Router with the ability to do Naive Flooding (in the standard mesh protocol sense)
|
||||
*
|
||||
* Rules for broadcasting (listing here for now, will move elsewhere eventually):
|
||||
|
||||
If to==BROADCAST and id==0, this is a simple broadcast (0 hops). It will be
|
||||
sent only by the current node and other nodes will not attempt to rebroadcast
|
||||
it.
|
||||
|
||||
If to==BROADCAST and id!=0, this is a "naive flooding" broadcast. The initial
|
||||
node will send it on all local interfaces.
|
||||
|
||||
When other nodes receive this message, they will
|
||||
first check if their recentBroadcasts table contains the (from, id) pair that
|
||||
indicates this message. If so, we've already seen it - so we discard it. If
|
||||
not, we add it to the table and then resend this message on all interfaces.
|
||||
When resending we are careful to use the "from" ID of the original sender. Not
|
||||
our own ID. When resending we pick a random delay between 0 and 10 seconds to
|
||||
decrease the chance of collisions with transmitters we can not even hear.
|
||||
|
||||
Any entries in recentBroadcasts that are older than X seconds (longer than the
|
||||
max time a flood can take) will be discarded.
|
||||
*/
|
||||
class FloodingRouter : public Router
|
||||
{
|
||||
private:
|
||||
std::vector<BroadcastRecord> recentBroadcasts;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
FloodingRouter();
|
||||
|
||||
/**
|
||||
* Send a packet on a suitable interface. This routine will
|
||||
* later free() the packet to pool. This routine is not allowed to stall.
|
||||
* If the txmit queue is full it might return an error
|
||||
*/
|
||||
virtual ErrorCode send(MeshPacket *p);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called from loop()
|
||||
* Handle any packet that is received by an interface on this node.
|
||||
* Note: some packets may merely being passed through this node and will be forwarded elsewhere.
|
||||
*
|
||||
* Note: this method will free the provided packet
|
||||
*/
|
||||
virtual void handleReceived(MeshPacket *p);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Update recentBroadcasts and return true if we have already seen this packet
|
||||
*/
|
||||
bool wasSeenRecently(const MeshPacket *p);
|
||||
};
|
||||
17
src/rf95/LICENSE
Normal file
17
src/rf95/LICENSE
Normal file
@@ -0,0 +1,17 @@
|
||||
This software is Copyright (C) 2008 Mike McCauley. Use is subject to license
|
||||
conditions. The main licensing options available are GPL V2 or Commercial:
|
||||
|
||||
Open Source Licensing GPL V2
|
||||
|
||||
This is the appropriate option if you want to share the source code of your
|
||||
application with everyone you distribute it to, and you also want to give them
|
||||
the right to share who uses it. If you wish to use this software under Open
|
||||
Source Licensing, you must contribute all your source code to the open source
|
||||
community in accordance with the GPL Version 2 when your application is
|
||||
distributed. See http://www.gnu.org/copyleft/gpl.html
|
||||
|
||||
Commercial Licensing
|
||||
|
||||
This is the appropriate option if you are creating proprietary applications
|
||||
and you are not prepared to distribute and share the source code of your
|
||||
application. Contact info@open.com.au for details.
|
||||
@@ -7,11 +7,10 @@
|
||||
|
||||
/**
|
||||
* A pool based allocator
|
||||
*
|
||||
*
|
||||
* Eventually this routine will even be safe for ISR use...
|
||||
*/
|
||||
template <class T>
|
||||
class MemoryPool
|
||||
template <class T> class MemoryPool
|
||||
{
|
||||
PointerQueue<T> dead;
|
||||
|
||||
@@ -19,22 +18,20 @@ class MemoryPool
|
||||
|
||||
size_t maxElements;
|
||||
|
||||
public:
|
||||
public:
|
||||
MemoryPool(size_t _maxElements) : dead(_maxElements), maxElements(_maxElements)
|
||||
{
|
||||
buf = new T[maxElements];
|
||||
|
||||
// prefill dead
|
||||
for (int i = 0; i < maxElements; i++)
|
||||
for (size_t i = 0; i < maxElements; i++)
|
||||
release(&buf[i]);
|
||||
}
|
||||
|
||||
~MemoryPool()
|
||||
{
|
||||
delete[] buf;
|
||||
}
|
||||
~MemoryPool() { delete[] buf; }
|
||||
|
||||
/// Return a queable object which has been prefilled with zeros. Panic if no buffer is available
|
||||
/// Note: this method is safe to call from regular OR ISR code
|
||||
T *allocZeroed()
|
||||
{
|
||||
T *p = allocZeroed(0);
|
||||
@@ -43,7 +40,8 @@ public:
|
||||
return p;
|
||||
}
|
||||
|
||||
/// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you probably don't want this version)
|
||||
/// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you probably
|
||||
/// don't want this version).
|
||||
T *allocZeroed(TickType_t maxWait)
|
||||
{
|
||||
T *p = dead.dequeuePtr(maxWait);
|
||||
@@ -66,16 +64,18 @@ public:
|
||||
/// Return a buffer for use by others
|
||||
void release(T *p)
|
||||
{
|
||||
int res = dead.enqueue(p, 0);
|
||||
assert(res == pdTRUE);
|
||||
assert(p >= buf && (p - buf) < maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
|
||||
assert(dead.enqueue(p, 0));
|
||||
assert(p >= buf &&
|
||||
(size_t)(p - buf) <
|
||||
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
|
||||
}
|
||||
|
||||
/// Return a buffer from an ISR, if higherPriWoken is set to true you have some work to do ;-)
|
||||
void releaseFromISR(T *p, BaseType_t *higherPriWoken)
|
||||
{
|
||||
int res = dead.enqueueFromISR(p, higherPriWoken);
|
||||
assert(res == pdTRUE);
|
||||
assert(p >= buf && (p - buf) < maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
|
||||
assert(dead.enqueueFromISR(p, higherPriWoken));
|
||||
assert(p >= buf &&
|
||||
(size_t)(p - buf) <
|
||||
maxElements); // sanity check to make sure a programmer didn't free something that didn't come from this pool
|
||||
}
|
||||
};
|
||||
@@ -5,20 +5,17 @@
|
||||
/**
|
||||
* A wrapper for freertos queues that assumes each element is a pointer
|
||||
*/
|
||||
template <class T>
|
||||
class PointerQueue : public TypedQueue<T *>
|
||||
template <class T> class PointerQueue : public TypedQueue<T *>
|
||||
{
|
||||
public:
|
||||
PointerQueue(int maxElements) : TypedQueue<T *>(maxElements)
|
||||
{
|
||||
}
|
||||
public:
|
||||
PointerQueue(int maxElements) : TypedQueue<T *>(maxElements) {}
|
||||
|
||||
// returns a ptr or null if the queue was empty
|
||||
T *dequeuePtr(TickType_t maxWait = portMAX_DELAY)
|
||||
{
|
||||
T *p;
|
||||
|
||||
return this->dequeue(&p, maxWait) == pdTRUE ? p : NULL;
|
||||
return this->dequeue(&p, maxWait) ? p : nullptr;
|
||||
}
|
||||
|
||||
// returns a ptr or null if the queue was empty
|
||||
@@ -26,6 +23,6 @@ public:
|
||||
{
|
||||
T *p;
|
||||
|
||||
return this->dequeueFromISR(&p, higherPriWoken) == pdTRUE ? p : NULL;
|
||||
return this->dequeueFromISR(&p, higherPriWoken) ? p : nullptr;
|
||||
}
|
||||
};
|
||||
4
src/rf95/README.md
Normal file
4
src/rf95/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# RF95
|
||||
|
||||
This is a heavily modified version of the Mike McCauley's RadioHead RF95 driver. We are using it under the GPL V3 License. See the
|
||||
file LICENSE for Mike's license terms (which listed GPL as acceptible).
|
||||
207
src/rf95/RHGenericDriver.cpp
Normal file
207
src/rf95/RHGenericDriver.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
// RHGenericDriver.cpp
|
||||
//
|
||||
// Copyright (C) 2014 Mike McCauley
|
||||
// $Id: RHGenericDriver.cpp,v 1.23 2018/02/11 23:57:18 mikem Exp $
|
||||
|
||||
#include <RHGenericDriver.h>
|
||||
|
||||
RHGenericDriver::RHGenericDriver()
|
||||
: _mode(RHModeInitialising), _thisAddress(RH_BROADCAST_ADDRESS), _txHeaderTo(RH_BROADCAST_ADDRESS),
|
||||
_txHeaderFrom(RH_BROADCAST_ADDRESS), _txHeaderId(0), _txHeaderFlags(0), _rxBad(0), _rxGood(0), _txGood(0), _cad_timeout(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool RHGenericDriver::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Blocks until a valid message is received
|
||||
void RHGenericDriver::waitAvailable()
|
||||
{
|
||||
while (!available())
|
||||
YIELD;
|
||||
}
|
||||
|
||||
// Blocks until a valid message is received or timeout expires
|
||||
// Return true if there is a message available
|
||||
// Works correctly even on millis() rollover
|
||||
bool RHGenericDriver::waitAvailableTimeout(uint16_t timeout)
|
||||
{
|
||||
unsigned long starttime = millis();
|
||||
while ((millis() - starttime) < timeout) {
|
||||
if (available()) {
|
||||
return true;
|
||||
}
|
||||
YIELD;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RHGenericDriver::waitPacketSent()
|
||||
{
|
||||
while (_mode == RHModeTx)
|
||||
YIELD; // Wait for any previous transmit to finish
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RHGenericDriver::waitPacketSent(uint16_t timeout)
|
||||
{
|
||||
unsigned long starttime = millis();
|
||||
while ((millis() - starttime) < timeout) {
|
||||
if (_mode != RHModeTx) // Any previous transmit finished?
|
||||
return true;
|
||||
YIELD;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait until no channel activity detected or timeout
|
||||
bool RHGenericDriver::waitCAD()
|
||||
{
|
||||
if (!_cad_timeout)
|
||||
return true;
|
||||
|
||||
// Wait for any channel activity to finish or timeout
|
||||
// Sophisticated DCF function...
|
||||
// DCF : BackoffTime = random() x aSlotTime
|
||||
// 100 - 1000 ms
|
||||
// 10 sec timeout
|
||||
unsigned long t = millis();
|
||||
while (isChannelActive()) {
|
||||
if (millis() - t > _cad_timeout)
|
||||
return false;
|
||||
#if (RH_PLATFORM == RH_PLATFORM_STM32) // stdlib on STMF103 gets confused if random is redefined
|
||||
delay(_random(1, 10) * 100);
|
||||
#else
|
||||
delay(random(1, 10) * 100); // Should these values be configurable? Macros?
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// subclasses are expected to override if CAD is available for that radio
|
||||
bool RHGenericDriver::isChannelActive()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setPromiscuous(bool promiscuous)
|
||||
{
|
||||
_promiscuous = promiscuous;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setThisAddress(uint8_t address)
|
||||
{
|
||||
_thisAddress = address;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setHeaderTo(uint8_t to)
|
||||
{
|
||||
_txHeaderTo = to;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setHeaderFrom(uint8_t from)
|
||||
{
|
||||
_txHeaderFrom = from;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setHeaderId(uint8_t id)
|
||||
{
|
||||
_txHeaderId = id;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setHeaderFlags(uint8_t set, uint8_t clear)
|
||||
{
|
||||
_txHeaderFlags &= ~clear;
|
||||
_txHeaderFlags |= set;
|
||||
}
|
||||
|
||||
uint8_t RHGenericDriver::headerTo()
|
||||
{
|
||||
return _rxHeaderTo;
|
||||
}
|
||||
|
||||
uint8_t RHGenericDriver::headerFrom()
|
||||
{
|
||||
return _rxHeaderFrom;
|
||||
}
|
||||
|
||||
uint8_t RHGenericDriver::headerId()
|
||||
{
|
||||
return _rxHeaderId;
|
||||
}
|
||||
|
||||
uint8_t RHGenericDriver::headerFlags()
|
||||
{
|
||||
return _rxHeaderFlags;
|
||||
}
|
||||
|
||||
int16_t RHGenericDriver::lastRssi()
|
||||
{
|
||||
return _lastRssi;
|
||||
}
|
||||
|
||||
RHGenericDriver::RHMode RHGenericDriver::mode()
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setMode(RHMode mode)
|
||||
{
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
bool RHGenericDriver::sleep()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Diagnostic help
|
||||
void RHGenericDriver::printBuffer(const char *prompt, const uint8_t *buf, uint8_t len)
|
||||
{
|
||||
#ifdef RH_HAVE_SERIAL
|
||||
Serial.println(prompt);
|
||||
uint8_t i;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (i % 16 == 15)
|
||||
Serial.println(buf[i], HEX);
|
||||
else {
|
||||
Serial.print(buf[i], HEX);
|
||||
Serial.print(' ');
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t RHGenericDriver::rxBad()
|
||||
{
|
||||
return _rxBad;
|
||||
}
|
||||
|
||||
uint16_t RHGenericDriver::rxGood()
|
||||
{
|
||||
return _rxGood;
|
||||
}
|
||||
|
||||
uint16_t RHGenericDriver::txGood()
|
||||
{
|
||||
return _txGood;
|
||||
}
|
||||
|
||||
void RHGenericDriver::setCADTimeout(unsigned long cad_timeout)
|
||||
{
|
||||
_cad_timeout = cad_timeout;
|
||||
}
|
||||
|
||||
#if (RH_PLATFORM == RH_PLATFORM_ATTINY)
|
||||
// Tinycore does not have __cxa_pure_virtual, so without this we
|
||||
// get linking complaints from the default code generated for pure virtual functions
|
||||
extern "C" void __cxa_pure_virtual()
|
||||
{
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
#endif
|
||||
280
src/rf95/RHGenericDriver.h
Normal file
280
src/rf95/RHGenericDriver.h
Normal file
@@ -0,0 +1,280 @@
|
||||
// RHGenericDriver.h
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2014 Mike McCauley
|
||||
// $Id: RHGenericDriver.h,v 1.23 2018/09/23 23:54:01 mikem Exp $
|
||||
|
||||
#ifndef RHGenericDriver_h
|
||||
#define RHGenericDriver_h
|
||||
|
||||
#include <RadioHead.h>
|
||||
|
||||
// Defines bits of the FLAGS header reserved for use by the RadioHead library and
|
||||
// the flags available for use by applications
|
||||
#define RH_FLAGS_RESERVED 0xf0
|
||||
#define RH_FLAGS_APPLICATION_SPECIFIC 0x0f
|
||||
#define RH_FLAGS_NONE 0
|
||||
|
||||
// Default timeout for waitCAD() in ms
|
||||
#define RH_CAD_DEFAULT_TIMEOUT 10000
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// \class RHGenericDriver RHGenericDriver.h <RHGenericDriver.h>
|
||||
/// \brief Abstract base class for a RadioHead driver.
|
||||
///
|
||||
/// This class defines the functions that must be provided by any RadioHead driver.
|
||||
/// Different types of driver will implement all the abstract functions, and will perhaps override
|
||||
/// other functions in this subclass, or perhaps add new functions specifically required by that driver.
|
||||
/// Do not directly instantiate this class: it is only to be subclassed by driver classes.
|
||||
///
|
||||
/// Subclasses are expected to implement a half-duplex, unreliable, error checked, unaddressed packet transport.
|
||||
/// They are expected to carry a message payload with an appropriate maximum length for the transport hardware
|
||||
/// and to also carry unaltered 4 message headers: TO, FROM, ID, FLAGS
|
||||
///
|
||||
/// \par Headers
|
||||
///
|
||||
/// Each message sent and received by a RadioHead driver includes 4 headers:
|
||||
/// -TO The node address that the message is being sent to (broadcast RH_BROADCAST_ADDRESS (255) is permitted)
|
||||
/// -FROM The node address of the sending node
|
||||
/// -ID A message ID, distinct (over short time scales) for each message sent by a particilar node
|
||||
/// -FLAGS A bitmask of flags. The most significant 4 bits are reserved for use by RadioHead. The least
|
||||
/// significant 4 bits are reserved for applications.
|
||||
class RHGenericDriver
|
||||
{
|
||||
public:
|
||||
/// \brief Defines different operating modes for the transport hardware
|
||||
///
|
||||
/// These are the different values that can be adopted by the _mode variable and
|
||||
/// returned by the mode() member function,
|
||||
typedef enum {
|
||||
RHModeInitialising = 0, ///< Transport is initialising. Initial default value until init() is called..
|
||||
RHModeSleep, ///< Transport hardware is in low power sleep mode (if supported)
|
||||
RHModeIdle, ///< Transport is idle.
|
||||
RHModeTx, ///< Transport is in the process of transmitting a message.
|
||||
RHModeRx, ///< Transport is in the process of receiving a message.
|
||||
RHModeCad ///< Transport is in the process of detecting channel activity (if supported)
|
||||
} RHMode;
|
||||
|
||||
/// Constructor
|
||||
RHGenericDriver();
|
||||
|
||||
/// Initialise the Driver transport hardware and software.
|
||||
/// Make sure the Driver is properly configured before calling init().
|
||||
/// \return true if initialisation succeeded.
|
||||
virtual bool init();
|
||||
|
||||
/// Tests whether a new message is available
|
||||
/// from the Driver.
|
||||
/// On most drivers, if there is an uncollected received message, and there is no message
|
||||
/// currently bing transmitted, this will also put the Driver into RHModeRx mode until
|
||||
/// a message is actually received by the transport, when it will be returned to RHModeIdle.
|
||||
/// This can be called multiple times in a timeout loop.
|
||||
/// \return true if a new, complete, error-free uncollected message is available to be retreived by recv().
|
||||
virtual bool available() = 0;
|
||||
|
||||
/// Returns the maximum message length
|
||||
/// available in this Driver.
|
||||
/// \return The maximum legal message length
|
||||
virtual uint8_t maxMessageLength() = 0;
|
||||
|
||||
/// Starts the receiver and blocks until a valid received
|
||||
/// message is available.
|
||||
virtual void waitAvailable();
|
||||
|
||||
/// Blocks until the transmitter
|
||||
/// is no longer transmitting.
|
||||
virtual bool waitPacketSent();
|
||||
|
||||
/// Blocks until the transmitter is no longer transmitting.
|
||||
/// or until the timeout occuers, whichever happens first
|
||||
/// \param[in] timeout Maximum time to wait in milliseconds.
|
||||
/// \return true if the radio completed transmission within the timeout period. False if it timed out.
|
||||
virtual bool waitPacketSent(uint16_t timeout);
|
||||
|
||||
/// Starts the receiver and blocks until a received message is available or a timeout
|
||||
/// \param[in] timeout Maximum time to wait in milliseconds.
|
||||
/// \return true if a message is available
|
||||
virtual bool waitAvailableTimeout(uint16_t timeout);
|
||||
|
||||
// Bent G Christensen (bentor@gmail.com), 08/15/2016
|
||||
/// Channel Activity Detection (CAD).
|
||||
/// Blocks until channel activity is finished or CAD timeout occurs.
|
||||
/// Uses the radio's CAD function (if supported) to detect channel activity.
|
||||
/// Implements random delays of 100 to 1000ms while activity is detected and until timeout.
|
||||
/// Caution: the random() function is not seeded. If you want non-deterministic behaviour, consider
|
||||
/// using something like randomSeed(analogRead(A0)); in your sketch.
|
||||
/// Permits the implementation of listen-before-talk mechanism (Collision Avoidance).
|
||||
/// Calls the isChannelActive() member function for the radio (if supported)
|
||||
/// to determine if the channel is active. If the radio does not support isChannelActive(),
|
||||
/// always returns true immediately
|
||||
/// \return true if the radio-specific CAD (as returned by isChannelActive())
|
||||
/// shows the channel is clear within the timeout period (or the timeout period is 0), else returns false.
|
||||
virtual bool waitCAD();
|
||||
|
||||
/// Sets the Channel Activity Detection timeout in milliseconds to be used by waitCAD().
|
||||
/// The default is 0, which means do not wait for CAD detection.
|
||||
/// CAD detection depends on support for isChannelActive() by your particular radio.
|
||||
void setCADTimeout(unsigned long cad_timeout);
|
||||
|
||||
/// Determine if the currently selected radio channel is active.
|
||||
/// This is expected to be subclassed by specific radios to implement their Channel Activity Detection
|
||||
/// if supported. If the radio does not support CAD, returns true immediately. If a RadioHead radio
|
||||
/// supports isChannelActive() it will be documented in the radio specific documentation.
|
||||
/// This is called automatically by waitCAD().
|
||||
/// \return true if the radio-specific CAD (as returned by override of isChannelActive()) shows the
|
||||
/// current radio channel as active, else false. If there is no radio-specific CAD, returns false.
|
||||
virtual bool isChannelActive();
|
||||
|
||||
/// Sets the address of this node. Defaults to 0xFF. Subclasses or the user may want to change this.
|
||||
/// This will be used to test the adddress in incoming messages. In non-promiscuous mode,
|
||||
/// only messages with a TO header the same as thisAddress or the broadcast addess (0xFF) will be accepted.
|
||||
/// In promiscuous mode, all messages will be accepted regardless of the TO header.
|
||||
/// In a conventional multinode system, all nodes will have a unique address
|
||||
/// (which you could store in EEPROM).
|
||||
/// You would normally set the header FROM address to be the same as thisAddress (though you dont have to,
|
||||
/// allowing the possibilty of address spoofing).
|
||||
/// \param[in] thisAddress The address of this node.
|
||||
virtual void setThisAddress(uint8_t thisAddress);
|
||||
|
||||
/// Sets the TO header to be sent in all subsequent messages
|
||||
/// \param[in] to The new TO header value
|
||||
virtual void setHeaderTo(uint8_t to);
|
||||
|
||||
/// Sets the FROM header to be sent in all subsequent messages
|
||||
/// \param[in] from The new FROM header value
|
||||
virtual void setHeaderFrom(uint8_t from);
|
||||
|
||||
/// Sets the ID header to be sent in all subsequent messages
|
||||
/// \param[in] id The new ID header value
|
||||
virtual void setHeaderId(uint8_t id);
|
||||
|
||||
/// Sets and clears bits in the FLAGS header to be sent in all subsequent messages
|
||||
/// First it clears he FLAGS according to the clear argument, then sets the flags according to the
|
||||
/// set argument. The default for clear always clears the application specific flags.
|
||||
/// \param[in] set bitmask of bits to be set. Flags are cleared with the clear mask before being set.
|
||||
/// \param[in] clear bitmask of flags to clear. Defaults to RH_FLAGS_APPLICATION_SPECIFIC
|
||||
/// which clears the application specific flags, resulting in new application specific flags
|
||||
/// identical to the set.
|
||||
virtual void setHeaderFlags(uint8_t set, uint8_t clear = RH_FLAGS_APPLICATION_SPECIFIC);
|
||||
|
||||
/// Tells the receiver to accept messages with any TO address, not just messages
|
||||
/// addressed to thisAddress or the broadcast address
|
||||
/// \param[in] promiscuous true if you wish to receive messages with any TO address
|
||||
virtual void setPromiscuous(bool promiscuous);
|
||||
|
||||
/// Returns the TO header of the last received message
|
||||
/// \return The TO header
|
||||
virtual uint8_t headerTo();
|
||||
|
||||
/// Returns the FROM header of the last received message
|
||||
/// \return The FROM header
|
||||
virtual uint8_t headerFrom();
|
||||
|
||||
/// Returns the ID header of the last received message
|
||||
/// \return The ID header
|
||||
virtual uint8_t headerId();
|
||||
|
||||
/// Returns the FLAGS header of the last received message
|
||||
/// \return The FLAGS header
|
||||
virtual uint8_t headerFlags();
|
||||
|
||||
/// Returns the most recent RSSI (Receiver Signal Strength Indicator).
|
||||
/// Usually it is the RSSI of the last received message, which is measured when the preamble is received.
|
||||
/// If you called readRssi() more recently, it will return that more recent value.
|
||||
/// \return The most recent RSSI measurement in dBm.
|
||||
virtual int16_t lastRssi();
|
||||
|
||||
/// Returns the operating mode of the library.
|
||||
/// \return the current mode, one of RF69_MODE_*
|
||||
virtual RHMode mode();
|
||||
|
||||
/// Sets the operating mode of the transport.
|
||||
virtual void setMode(RHMode mode);
|
||||
|
||||
/// Sets the transport hardware into low-power sleep mode
|
||||
/// (if supported). May be overridden by specific drivers to initialte sleep mode.
|
||||
/// If successful, the transport will stay in sleep mode until woken by
|
||||
/// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)
|
||||
/// \return true if sleep mode is supported by transport hardware and the RadioHead driver, and if sleep mode
|
||||
/// was successfully entered. If sleep mode is not suported, return false.
|
||||
virtual bool sleep();
|
||||
|
||||
/// Prints a data buffer in HEX.
|
||||
/// For diagnostic use
|
||||
/// \param[in] prompt string to preface the print
|
||||
/// \param[in] buf Location of the buffer to print
|
||||
/// \param[in] len Length of the buffer in octets.
|
||||
static void printBuffer(const char *prompt, const uint8_t *buf, uint8_t len);
|
||||
|
||||
/// Returns the count of the number of bad received packets (ie packets with bad lengths, checksum etc)
|
||||
/// which were rejected and not delivered to the application.
|
||||
/// Caution: not all drivers can correctly report this count. Some underlying hardware only report
|
||||
/// good packets.
|
||||
/// \return The number of bad packets received.
|
||||
virtual uint16_t rxBad();
|
||||
|
||||
/// Returns the count of the number of
|
||||
/// good received packets
|
||||
/// \return The number of good packets received.
|
||||
virtual uint16_t rxGood();
|
||||
|
||||
/// Returns the count of the number of
|
||||
/// packets successfully transmitted (though not necessarily received by the destination)
|
||||
/// \return The number of packets successfully transmitted
|
||||
virtual uint16_t txGood();
|
||||
|
||||
protected:
|
||||
/// The current transport operating mode
|
||||
volatile RHMode _mode;
|
||||
|
||||
/// This node id
|
||||
uint8_t _thisAddress;
|
||||
|
||||
/// Whether the transport is in promiscuous mode
|
||||
bool _promiscuous;
|
||||
|
||||
/// TO header in the last received mesasge
|
||||
volatile uint8_t _rxHeaderTo;
|
||||
|
||||
/// FROM header in the last received mesasge
|
||||
volatile uint8_t _rxHeaderFrom;
|
||||
|
||||
/// ID header in the last received mesasge
|
||||
volatile uint8_t _rxHeaderId;
|
||||
|
||||
/// FLAGS header in the last received mesasge
|
||||
volatile uint8_t _rxHeaderFlags;
|
||||
|
||||
/// TO header to send in all messages
|
||||
uint8_t _txHeaderTo;
|
||||
|
||||
/// FROM header to send in all messages
|
||||
uint8_t _txHeaderFrom;
|
||||
|
||||
/// ID header to send in all messages
|
||||
uint8_t _txHeaderId;
|
||||
|
||||
/// FLAGS header to send in all messages
|
||||
uint8_t _txHeaderFlags;
|
||||
|
||||
/// The value of the last received RSSI value, in some transport specific units
|
||||
volatile int16_t _lastRssi;
|
||||
|
||||
/// Count of the number of bad messages (eg bad checksum etc) received
|
||||
volatile uint16_t _rxBad;
|
||||
|
||||
/// Count of the number of successfully transmitted messaged
|
||||
volatile uint16_t _rxGood;
|
||||
|
||||
/// Count of the number of bad messages (correct checksum etc) received
|
||||
volatile uint16_t _txGood;
|
||||
|
||||
/// Channel activity detected
|
||||
volatile bool _cad;
|
||||
|
||||
/// Channel activity timeout in ms
|
||||
unsigned int _cad_timeout;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
31
src/rf95/RHGenericSPI.cpp
Normal file
31
src/rf95/RHGenericSPI.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// RHGenericSPI.cpp
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2011 Mike McCauley
|
||||
// Contributed by Joanna Rutkowska
|
||||
// $Id: RHGenericSPI.cpp,v 1.2 2014/04/12 05:26:05 mikem Exp $
|
||||
|
||||
#include <RHGenericSPI.h>
|
||||
|
||||
RHGenericSPI::RHGenericSPI(Frequency frequency, BitOrder bitOrder, DataMode dataMode)
|
||||
:
|
||||
_frequency(frequency),
|
||||
_bitOrder(bitOrder),
|
||||
_dataMode(dataMode)
|
||||
{
|
||||
}
|
||||
|
||||
void RHGenericSPI::setBitOrder(BitOrder bitOrder)
|
||||
{
|
||||
_bitOrder = bitOrder;
|
||||
}
|
||||
|
||||
void RHGenericSPI::setDataMode(DataMode dataMode)
|
||||
{
|
||||
_dataMode = dataMode;
|
||||
}
|
||||
|
||||
void RHGenericSPI::setFrequency(Frequency frequency)
|
||||
{
|
||||
_frequency = frequency;
|
||||
}
|
||||
|
||||
183
src/rf95/RHGenericSPI.h
Normal file
183
src/rf95/RHGenericSPI.h
Normal file
@@ -0,0 +1,183 @@
|
||||
// RHGenericSPI.h
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2011 Mike McCauley
|
||||
// Contributed by Joanna Rutkowska
|
||||
// $Id: RHGenericSPI.h,v 1.9 2020/01/05 07:02:23 mikem Exp mikem $
|
||||
|
||||
#ifndef RHGenericSPI_h
|
||||
#define RHGenericSPI_h
|
||||
|
||||
#include <RadioHead.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// \class RHGenericSPI RHGenericSPI.h <RHGenericSPI.h>
|
||||
/// \brief Base class for SPI interfaces
|
||||
///
|
||||
/// This generic abstract class is used to encapsulate hardware or software SPI interfaces for
|
||||
/// a variety of platforms.
|
||||
/// The intention is so that driver classes can be configured to use hardware or software SPI
|
||||
/// without changing the main code.
|
||||
///
|
||||
/// You must provide a subclass of this class to driver constructors that require SPI.
|
||||
/// A concrete subclass that encapsualates the standard Arduino hardware SPI and a bit-banged
|
||||
/// software implementation is included.
|
||||
///
|
||||
/// Do not directly use this class: it must be subclassed and the following abstract functions at least
|
||||
/// must be implmented:
|
||||
/// - begin()
|
||||
/// - end()
|
||||
/// - transfer()
|
||||
class RHGenericSPI
|
||||
{
|
||||
public:
|
||||
|
||||
/// \brief Defines constants for different SPI modes
|
||||
///
|
||||
/// Defines constants for different SPI modes
|
||||
/// that can be passed to the constructor or setMode()
|
||||
/// We need to define these in a device and platform independent way, because the
|
||||
/// SPI implementation is different on each platform.
|
||||
typedef enum
|
||||
{
|
||||
DataMode0 = 0, ///< SPI Mode 0: CPOL = 0, CPHA = 0
|
||||
DataMode1, ///< SPI Mode 1: CPOL = 0, CPHA = 1
|
||||
DataMode2, ///< SPI Mode 2: CPOL = 1, CPHA = 0
|
||||
DataMode3, ///< SPI Mode 3: CPOL = 1, CPHA = 1
|
||||
} DataMode;
|
||||
|
||||
/// \brief Defines constants for different SPI bus frequencies
|
||||
///
|
||||
/// Defines constants for different SPI bus frequencies
|
||||
/// that can be passed to setFrequency().
|
||||
/// The frequency you get may not be exactly the one according to the name.
|
||||
/// We need to define these in a device and platform independent way, because the
|
||||
/// SPI implementation is different on each platform.
|
||||
typedef enum
|
||||
{
|
||||
Frequency1MHz = 0, ///< SPI bus frequency close to 1MHz
|
||||
Frequency2MHz, ///< SPI bus frequency close to 2MHz
|
||||
Frequency4MHz, ///< SPI bus frequency close to 4MHz
|
||||
Frequency8MHz, ///< SPI bus frequency close to 8MHz
|
||||
Frequency16MHz ///< SPI bus frequency close to 16MHz
|
||||
} Frequency;
|
||||
|
||||
/// \brief Defines constants for different SPI endianness
|
||||
///
|
||||
/// Defines constants for different SPI endianness
|
||||
/// that can be passed to setBitOrder()
|
||||
/// We need to define these in a device and platform independent way, because the
|
||||
/// SPI implementation is different on each platform.
|
||||
typedef enum
|
||||
{
|
||||
BitOrderMSBFirst = 0, ///< SPI MSB first
|
||||
BitOrderLSBFirst, ///< SPI LSB first
|
||||
} BitOrder;
|
||||
|
||||
/// Constructor
|
||||
/// Creates an instance of an abstract SPI interface.
|
||||
/// Do not use this contructor directly: you must instead use on of the concrete subclasses provided
|
||||
/// such as RHHardwareSPI or RHSoftwareSPI
|
||||
/// \param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency
|
||||
/// is mapped to the closest available bus frequency on the platform.
|
||||
/// \param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or
|
||||
/// RHGenericSPI::BitOrderLSBFirst.
|
||||
/// \param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode
|
||||
RHGenericSPI(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
|
||||
|
||||
/// Transfer a single octet to and from the SPI interface
|
||||
/// \param[in] data The octet to send
|
||||
/// \return The octet read from SPI while the data octet was sent
|
||||
virtual uint8_t transfer(uint8_t data) = 0;
|
||||
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
/// Transfer up to 2 bytes on the SPI interface
|
||||
/// \param[in] byte0 The first byte to be sent on the SPI interface
|
||||
/// \param[in] byte1 The second byte to be sent on the SPI interface
|
||||
/// \return The second byte clocked in as the second byte is sent.
|
||||
virtual uint8_t transfer2B(uint8_t byte0, uint8_t byte1) = 0;
|
||||
|
||||
/// Read a number of bytes on the SPI interface from an NRF device
|
||||
/// \param[in] reg The NRF device register to read
|
||||
/// \param[out] dest The buffer to hold the bytes read
|
||||
/// \param[in] len The number of bytes to read
|
||||
/// \return The NRF status byte
|
||||
virtual uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len) = 0;
|
||||
|
||||
/// Wrte a number of bytes on the SPI interface to an NRF device
|
||||
/// \param[in] reg The NRF device register to read
|
||||
/// \param[out] src The buffer to hold the bytes write
|
||||
/// \param[in] len The number of bytes to write
|
||||
/// \return The NRF status byte
|
||||
virtual uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len) = 0;
|
||||
|
||||
#endif
|
||||
|
||||
/// SPI Configuration methods
|
||||
/// Enable SPI interrupts (if supported)
|
||||
/// This can be used in an SPI slave to indicate when an SPI message has been received
|
||||
virtual void attachInterrupt() {};
|
||||
|
||||
/// Disable SPI interrupts (if supported)
|
||||
/// This can be used to diable the SPI interrupt in slaves where that is supported.
|
||||
virtual void detachInterrupt() {};
|
||||
|
||||
/// Initialise the SPI library.
|
||||
/// Call this after configuring and before using the SPI library
|
||||
virtual void begin() = 0;
|
||||
|
||||
/// Disables the SPI bus (leaving pin modes unchanged).
|
||||
/// Call this after you have finished using the SPI interface
|
||||
virtual void end() = 0;
|
||||
|
||||
/// Sets the bit order the SPI interface will use
|
||||
/// Sets the order of the bits shifted out of and into the SPI bus, either
|
||||
/// LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first).
|
||||
/// \param[in] bitOrder Bit order to be used: one of RHGenericSPI::BitOrder
|
||||
virtual void setBitOrder(BitOrder bitOrder);
|
||||
|
||||
/// Sets the SPI data mode: that is, clock polarity and phase.
|
||||
/// See the Wikipedia article on SPI for details.
|
||||
/// \param[in] dataMode The mode to use: one of RHGenericSPI::DataMode
|
||||
virtual void setDataMode(DataMode dataMode);
|
||||
|
||||
/// Sets the SPI clock divider relative to the system clock.
|
||||
/// On AVR based boards, the dividers available are 2, 4, 8, 16, 32, 64 or 128.
|
||||
/// The default setting is SPI_CLOCK_DIV4, which sets the SPI clock to one-quarter
|
||||
/// the frequency of the system clock (4 Mhz for the boards at 16 MHz).
|
||||
/// \param[in] frequency The data rate to use: one of RHGenericSPI::Frequency
|
||||
virtual void setFrequency(Frequency frequency);
|
||||
|
||||
/// Signal the start of an SPI transaction that must not be interrupted by other SPI actions
|
||||
/// In subclasses that support transactions this will ensure that other SPI transactions
|
||||
/// are blocked until this one is completed by endTransaction().
|
||||
/// Base does nothing
|
||||
/// Might be overridden in subclass
|
||||
virtual void beginTransaction(){}
|
||||
|
||||
/// Signal the end of an SPI transaction
|
||||
/// Base does nothing
|
||||
/// Might be overridden in subclass
|
||||
virtual void endTransaction(){}
|
||||
|
||||
/// Specify the interrupt number of the interrupt that will use SPI transactions
|
||||
/// Tells the SPI support software that SPI transactions will occur with the interrupt
|
||||
/// handler assocated with interruptNumber
|
||||
/// Base does nothing
|
||||
/// Might be overridden in subclass
|
||||
/// \param[in] interruptNumber The number of the interrupt
|
||||
virtual void usingInterrupt(uint8_t interruptNumber){
|
||||
(void)interruptNumber;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/// The configure SPI Bus frequency, one of RHGenericSPI::Frequency
|
||||
Frequency _frequency; // Bus frequency, one of RHGenericSPI::Frequency
|
||||
|
||||
/// Bit order, one of RHGenericSPI::BitOrder
|
||||
BitOrder _bitOrder;
|
||||
|
||||
/// SPI bus mode, one of RHGenericSPI::DataMode
|
||||
DataMode _dataMode;
|
||||
};
|
||||
#endif
|
||||
499
src/rf95/RHHardwareSPI.cpp
Normal file
499
src/rf95/RHHardwareSPI.cpp
Normal file
@@ -0,0 +1,499 @@
|
||||
// RHHardwareSPI.cpp
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2011 Mike McCauley
|
||||
// Contributed by Joanna Rutkowska
|
||||
// $Id: RHHardwareSPI.cpp,v 1.25 2020/01/05 07:02:23 mikem Exp mikem $
|
||||
|
||||
#include <RHHardwareSPI.h>
|
||||
|
||||
#ifdef RH_HAVE_HARDWARE_SPI
|
||||
|
||||
// Declare a single default instance of the hardware SPI interface class
|
||||
RHHardwareSPI hardware_spi;
|
||||
|
||||
|
||||
#if (RH_PLATFORM == RH_PLATFORM_STM32) // Maple etc
|
||||
// Declare an SPI interface to use
|
||||
HardwareSPI SPI(1);
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_STM32STD) // STM32F4 Discovery
|
||||
// Declare an SPI interface to use
|
||||
HardwareSPI SPI(1);
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS) // Mongoose OS platform
|
||||
HardwareSPI SPI(1);
|
||||
#endif
|
||||
|
||||
// Arduino Due has default SPI pins on central SPI headers, and not on 10, 11, 12, 13
|
||||
// as per other Arduinos
|
||||
// http://21stdigitalhome.blogspot.com.au/2013/02/arduino-due-hardware-spi.html
|
||||
#if defined (__arm__) && !defined(CORE_TEENSY) && !defined(SPI_CLOCK_DIV16) && !defined(RH_PLATFORM_NRF52)
|
||||
// Arduino Due in 1.5.5 has no definitions for SPI dividers
|
||||
// SPI clock divider is based on MCK of 84MHz
|
||||
#define SPI_CLOCK_DIV16 (VARIANT_MCK/84000000) // 1MHz
|
||||
#define SPI_CLOCK_DIV8 (VARIANT_MCK/42000000) // 2MHz
|
||||
#define SPI_CLOCK_DIV4 (VARIANT_MCK/21000000) // 4MHz
|
||||
#define SPI_CLOCK_DIV2 (VARIANT_MCK/10500000) // 8MHz
|
||||
#define SPI_CLOCK_DIV1 (VARIANT_MCK/5250000) // 16MHz
|
||||
#endif
|
||||
|
||||
RHHardwareSPI::RHHardwareSPI(Frequency frequency, BitOrder bitOrder, DataMode dataMode)
|
||||
:
|
||||
RHGenericSPI(frequency, bitOrder, dataMode)
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t RHHardwareSPI::transfer(uint8_t data)
|
||||
{
|
||||
return SPI.transfer(data);
|
||||
}
|
||||
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
uint8_t RHHardwareSPI::transfer2B(uint8_t byte0, uint8_t byte1)
|
||||
{
|
||||
return SPI.transfer2B(byte0, byte1);
|
||||
}
|
||||
|
||||
uint8_t RHHardwareSPI::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)
|
||||
{
|
||||
return SPI.spiBurstRead(reg, dest, len);
|
||||
}
|
||||
|
||||
uint8_t RHHardwareSPI::spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len)
|
||||
{
|
||||
uint8_t status = SPI.spiBurstWrite(reg, src, len);
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RHHardwareSPI::attachInterrupt()
|
||||
{
|
||||
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO || RH_PLATFORM == RH_PLATFORM_NRF52)
|
||||
SPI.attachInterrupt();
|
||||
#endif
|
||||
}
|
||||
|
||||
void RHHardwareSPI::detachInterrupt()
|
||||
{
|
||||
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO || RH_PLATFORM == RH_PLATFORM_NRF52)
|
||||
SPI.detachInterrupt();
|
||||
#endif
|
||||
}
|
||||
|
||||
void RHHardwareSPI::begin()
|
||||
{
|
||||
#if defined(SPI_HAS_TRANSACTION)
|
||||
// Perhaps this is a uniform interface for SPI?
|
||||
// Currently Teensy and ESP32 only
|
||||
uint32_t frequency;
|
||||
if (_frequency == Frequency16MHz)
|
||||
frequency = 16000000;
|
||||
else if (_frequency == Frequency8MHz)
|
||||
frequency = 8000000;
|
||||
else if (_frequency == Frequency4MHz)
|
||||
frequency = 4000000;
|
||||
else if (_frequency == Frequency2MHz)
|
||||
frequency = 2000000;
|
||||
else
|
||||
frequency = 1000000;
|
||||
|
||||
#if ((RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && (defined(ARDUINO_SAM_DUE) || defined(ARDUINO_ARCH_SAMD))) || defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32) || defined(NRF52)
|
||||
// Arduino Due in 1.5.5 has its own BitOrder :-(
|
||||
// So too does Arduino Zero
|
||||
// So too does rogerclarkmelbourne/Arduino_STM32
|
||||
::BitOrder bitOrder;
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_ATTINY_MEGA)
|
||||
::BitOrder bitOrder;
|
||||
#else
|
||||
uint8_t bitOrder;
|
||||
#endif
|
||||
|
||||
if (_bitOrder == BitOrderLSBFirst)
|
||||
bitOrder = LSBFIRST;
|
||||
else
|
||||
bitOrder = MSBFIRST;
|
||||
|
||||
uint8_t dataMode;
|
||||
if (_dataMode == DataMode0)
|
||||
dataMode = SPI_MODE0;
|
||||
else if (_dataMode == DataMode1)
|
||||
dataMode = SPI_MODE1;
|
||||
else if (_dataMode == DataMode2)
|
||||
dataMode = SPI_MODE2;
|
||||
else if (_dataMode == DataMode3)
|
||||
dataMode = SPI_MODE3;
|
||||
else
|
||||
dataMode = SPI_MODE0;
|
||||
|
||||
// Save the settings for use in transactions
|
||||
_settings = SPISettings(frequency, bitOrder, dataMode);
|
||||
SPI.begin();
|
||||
|
||||
#else // SPI_HAS_TRANSACTION
|
||||
|
||||
// Sigh: there are no common symbols for some of these SPI options across all platforms
|
||||
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) || (RH_PLATFORM == RH_PLATFORM_UNO32) || (RH_PLATFORM == RH_PLATFORM_CHIPKIT_CORE || RH_PLATFORM == RH_PLATFORM_NRF52)
|
||||
uint8_t dataMode;
|
||||
if (_dataMode == DataMode0)
|
||||
dataMode = SPI_MODE0;
|
||||
else if (_dataMode == DataMode1)
|
||||
dataMode = SPI_MODE1;
|
||||
else if (_dataMode == DataMode2)
|
||||
dataMode = SPI_MODE2;
|
||||
else if (_dataMode == DataMode3)
|
||||
dataMode = SPI_MODE3;
|
||||
else
|
||||
dataMode = SPI_MODE0;
|
||||
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(__arm__) && defined(CORE_TEENSY)
|
||||
// Temporary work-around due to problem where avr_emulation.h does not work properly for the setDataMode() cal
|
||||
SPCR &= ~SPI_MODE_MASK;
|
||||
#else
|
||||
#if ((RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && defined(ARDUINO_ARCH_SAMD)) || defined(ARDUINO_ARCH_NRF52)
|
||||
// Zero requires begin() before anything else :-)
|
||||
SPI.begin();
|
||||
#endif
|
||||
|
||||
SPI.setDataMode(dataMode);
|
||||
#endif
|
||||
|
||||
#if ((RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined (__arm__) && (defined(ARDUINO_SAM_DUE) || defined(ARDUINO_ARCH_SAMD))) || defined(ARDUINO_ARCH_NRF52) || defined (ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_STM32)
|
||||
// Arduino Due in 1.5.5 has its own BitOrder :-(
|
||||
// So too does Arduino Zero
|
||||
// So too does rogerclarkmelbourne/Arduino_STM32
|
||||
::BitOrder bitOrder;
|
||||
#else
|
||||
uint8_t bitOrder;
|
||||
#endif
|
||||
if (_bitOrder == BitOrderLSBFirst)
|
||||
bitOrder = LSBFIRST;
|
||||
else
|
||||
bitOrder = MSBFIRST;
|
||||
SPI.setBitOrder(bitOrder);
|
||||
uint8_t divider;
|
||||
switch (_frequency)
|
||||
{
|
||||
case Frequency1MHz:
|
||||
default:
|
||||
#if F_CPU == 8000000
|
||||
divider = SPI_CLOCK_DIV8;
|
||||
#else
|
||||
divider = SPI_CLOCK_DIV16;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case Frequency2MHz:
|
||||
#if F_CPU == 8000000
|
||||
divider = SPI_CLOCK_DIV4;
|
||||
#else
|
||||
divider = SPI_CLOCK_DIV8;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case Frequency4MHz:
|
||||
#if F_CPU == 8000000
|
||||
divider = SPI_CLOCK_DIV2;
|
||||
#else
|
||||
divider = SPI_CLOCK_DIV4;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case Frequency8MHz:
|
||||
divider = SPI_CLOCK_DIV2; // 4MHz on an 8MHz Arduino
|
||||
break;
|
||||
|
||||
case Frequency16MHz:
|
||||
divider = SPI_CLOCK_DIV2; // Not really 16MHz, only 8MHz. 4MHz on an 8MHz Arduino
|
||||
break;
|
||||
|
||||
}
|
||||
SPI.setClockDivider(divider);
|
||||
SPI.begin();
|
||||
// Teensy requires it to be set _after_ begin()
|
||||
SPI.setClockDivider(divider);
|
||||
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_STM32) // Maple etc
|
||||
spi_mode dataMode;
|
||||
// Hmmm, if we do this as a switch, GCC on maple gets v confused!
|
||||
if (_dataMode == DataMode0)
|
||||
dataMode = SPI_MODE_0;
|
||||
else if (_dataMode == DataMode1)
|
||||
dataMode = SPI_MODE_1;
|
||||
else if (_dataMode == DataMode2)
|
||||
dataMode = SPI_MODE_2;
|
||||
else if (_dataMode == DataMode3)
|
||||
dataMode = SPI_MODE_3;
|
||||
else
|
||||
dataMode = SPI_MODE_0;
|
||||
|
||||
uint32 bitOrder;
|
||||
if (_bitOrder == BitOrderLSBFirst)
|
||||
bitOrder = LSBFIRST;
|
||||
else
|
||||
bitOrder = MSBFIRST;
|
||||
|
||||
SPIFrequency frequency; // Yes, I know these are not exact equivalents.
|
||||
switch (_frequency)
|
||||
{
|
||||
case Frequency1MHz:
|
||||
default:
|
||||
frequency = SPI_1_125MHZ;
|
||||
break;
|
||||
|
||||
case Frequency2MHz:
|
||||
frequency = SPI_2_25MHZ;
|
||||
break;
|
||||
|
||||
case Frequency4MHz:
|
||||
frequency = SPI_4_5MHZ;
|
||||
break;
|
||||
|
||||
case Frequency8MHz:
|
||||
frequency = SPI_9MHZ;
|
||||
break;
|
||||
|
||||
case Frequency16MHz:
|
||||
frequency = SPI_18MHZ;
|
||||
break;
|
||||
|
||||
}
|
||||
SPI.begin(frequency, bitOrder, dataMode);
|
||||
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_STM32STD) // STM32F4 discovery
|
||||
uint8_t dataMode;
|
||||
if (_dataMode == DataMode0)
|
||||
dataMode = SPI_MODE0;
|
||||
else if (_dataMode == DataMode1)
|
||||
dataMode = SPI_MODE1;
|
||||
else if (_dataMode == DataMode2)
|
||||
dataMode = SPI_MODE2;
|
||||
else if (_dataMode == DataMode3)
|
||||
dataMode = SPI_MODE3;
|
||||
else
|
||||
dataMode = SPI_MODE0;
|
||||
|
||||
uint32_t bitOrder;
|
||||
if (_bitOrder == BitOrderLSBFirst)
|
||||
bitOrder = LSBFIRST;
|
||||
else
|
||||
bitOrder = MSBFIRST;
|
||||
|
||||
SPIFrequency frequency; // Yes, I know these are not exact equivalents.
|
||||
switch (_frequency)
|
||||
{
|
||||
case Frequency1MHz:
|
||||
default:
|
||||
frequency = SPI_1_3125MHZ;
|
||||
break;
|
||||
|
||||
case Frequency2MHz:
|
||||
frequency = SPI_2_625MHZ;
|
||||
break;
|
||||
|
||||
case Frequency4MHz:
|
||||
frequency = SPI_5_25MHZ;
|
||||
break;
|
||||
|
||||
case Frequency8MHz:
|
||||
frequency = SPI_10_5MHZ;
|
||||
break;
|
||||
|
||||
case Frequency16MHz:
|
||||
frequency = SPI_21_0MHZ;
|
||||
break;
|
||||
|
||||
}
|
||||
SPI.begin(frequency, bitOrder, dataMode);
|
||||
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_STM32F2) // Photon
|
||||
uint8_t dataMode;
|
||||
if (_dataMode == DataMode0)
|
||||
dataMode = SPI_MODE0;
|
||||
else if (_dataMode == DataMode1)
|
||||
dataMode = SPI_MODE1;
|
||||
else if (_dataMode == DataMode2)
|
||||
dataMode = SPI_MODE2;
|
||||
else if (_dataMode == DataMode3)
|
||||
dataMode = SPI_MODE3;
|
||||
else
|
||||
dataMode = SPI_MODE0;
|
||||
SPI.setDataMode(dataMode);
|
||||
if (_bitOrder == BitOrderLSBFirst)
|
||||
SPI.setBitOrder(LSBFIRST);
|
||||
else
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
|
||||
switch (_frequency)
|
||||
{
|
||||
case Frequency1MHz:
|
||||
default:
|
||||
SPI.setClockSpeed(1, MHZ);
|
||||
break;
|
||||
|
||||
case Frequency2MHz:
|
||||
SPI.setClockSpeed(2, MHZ);
|
||||
break;
|
||||
|
||||
case Frequency4MHz:
|
||||
SPI.setClockSpeed(4, MHZ);
|
||||
break;
|
||||
|
||||
case Frequency8MHz:
|
||||
SPI.setClockSpeed(8, MHZ);
|
||||
break;
|
||||
|
||||
case Frequency16MHz:
|
||||
SPI.setClockSpeed(16, MHZ);
|
||||
break;
|
||||
}
|
||||
|
||||
// SPI.setClockDivider(SPI_CLOCK_DIV4); // 72MHz / 4MHz = 18MHz
|
||||
// SPI.setClockSpeed(1, MHZ);
|
||||
SPI.begin();
|
||||
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_ESP8266)
|
||||
// Requires SPI driver for ESP8266 from https://github.com/esp8266/Arduino/tree/master/libraries/SPI
|
||||
// Which ppears to be in Arduino Board Manager ESP8266 Community version 2.1.0
|
||||
// Contributed by David Skinner
|
||||
// begin comes first
|
||||
SPI.begin();
|
||||
|
||||
// datamode
|
||||
switch ( _dataMode )
|
||||
{
|
||||
case DataMode1:
|
||||
SPI.setDataMode ( SPI_MODE1 );
|
||||
break;
|
||||
case DataMode2:
|
||||
SPI.setDataMode ( SPI_MODE2 );
|
||||
break;
|
||||
case DataMode3:
|
||||
SPI.setDataMode ( SPI_MODE3 );
|
||||
break;
|
||||
case DataMode0:
|
||||
default:
|
||||
SPI.setDataMode ( SPI_MODE0 );
|
||||
break;
|
||||
}
|
||||
|
||||
// bitorder
|
||||
SPI.setBitOrder(_bitOrder == BitOrderLSBFirst ? LSBFIRST : MSBFIRST);
|
||||
|
||||
// frequency (this sets the divider)
|
||||
switch (_frequency)
|
||||
{
|
||||
case Frequency1MHz:
|
||||
default:
|
||||
SPI.setFrequency(1000000);
|
||||
break;
|
||||
case Frequency2MHz:
|
||||
SPI.setFrequency(2000000);
|
||||
break;
|
||||
case Frequency4MHz:
|
||||
SPI.setFrequency(4000000);
|
||||
break;
|
||||
case Frequency8MHz:
|
||||
SPI.setFrequency(8000000);
|
||||
break;
|
||||
case Frequency16MHz:
|
||||
SPI.setFrequency(16000000);
|
||||
break;
|
||||
}
|
||||
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_RASPI) // Raspberry PI
|
||||
uint8_t dataMode;
|
||||
if (_dataMode == DataMode0)
|
||||
dataMode = BCM2835_SPI_MODE0;
|
||||
else if (_dataMode == DataMode1)
|
||||
dataMode = BCM2835_SPI_MODE1;
|
||||
else if (_dataMode == DataMode2)
|
||||
dataMode = BCM2835_SPI_MODE2;
|
||||
else if (_dataMode == DataMode3)
|
||||
dataMode = BCM2835_SPI_MODE3;
|
||||
|
||||
uint8_t bitOrder;
|
||||
if (_bitOrder == BitOrderLSBFirst)
|
||||
bitOrder = BCM2835_SPI_BIT_ORDER_LSBFIRST;
|
||||
else
|
||||
bitOrder = BCM2835_SPI_BIT_ORDER_MSBFIRST;
|
||||
|
||||
uint32_t divider;
|
||||
switch (_frequency)
|
||||
{
|
||||
case Frequency1MHz:
|
||||
default:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_256;
|
||||
break;
|
||||
case Frequency2MHz:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_128;
|
||||
break;
|
||||
case Frequency4MHz:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_64;
|
||||
break;
|
||||
case Frequency8MHz:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_32;
|
||||
break;
|
||||
case Frequency16MHz:
|
||||
divider = BCM2835_SPI_CLOCK_DIVIDER_16;
|
||||
break;
|
||||
}
|
||||
SPI.begin(divider, bitOrder, dataMode);
|
||||
#elif (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
uint8_t dataMode = SPI_MODE0;
|
||||
uint32_t frequency = 4000000; //!!! ESP32/NRF902 works ok at 4MHz but not at 8MHz SPI clock.
|
||||
uint32_t bitOrder = MSBFIRST;
|
||||
|
||||
if (_dataMode == DataMode0) {
|
||||
dataMode = SPI_MODE0;
|
||||
} else if (_dataMode == DataMode1) {
|
||||
dataMode = SPI_MODE1;
|
||||
} else if (_dataMode == DataMode2) {
|
||||
dataMode = SPI_MODE2;
|
||||
} else if (_dataMode == DataMode3) {
|
||||
dataMode = SPI_MODE3;
|
||||
}
|
||||
|
||||
if (_bitOrder == BitOrderLSBFirst) {
|
||||
bitOrder = LSBFIRST;
|
||||
}
|
||||
|
||||
if (_frequency == Frequency4MHz)
|
||||
frequency = 4000000;
|
||||
else if (_frequency == Frequency2MHz)
|
||||
frequency = 2000000;
|
||||
else
|
||||
frequency = 1000000;
|
||||
|
||||
SPI.begin(frequency, bitOrder, dataMode);
|
||||
#else
|
||||
#warning RHHardwareSPI does not support this platform yet. Consider adding it and contributing a patch.
|
||||
#endif
|
||||
|
||||
#endif // SPI_HAS_TRANSACTION
|
||||
}
|
||||
|
||||
void RHHardwareSPI::end()
|
||||
{
|
||||
return SPI.end();
|
||||
}
|
||||
|
||||
void RHHardwareSPI::beginTransaction()
|
||||
{
|
||||
#if defined(SPI_HAS_TRANSACTION)
|
||||
SPI.beginTransaction(_settings);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RHHardwareSPI::endTransaction()
|
||||
{
|
||||
#if defined(SPI_HAS_TRANSACTION)
|
||||
SPI.endTransaction();
|
||||
#endif
|
||||
}
|
||||
|
||||
void RHHardwareSPI::usingInterrupt(uint8_t interrupt)
|
||||
{
|
||||
#if defined(SPI_HAS_TRANSACTION) && !defined(RH_MISSING_SPIUSINGINTERRUPT)
|
||||
SPI.usingInterrupt(interrupt);
|
||||
#endif
|
||||
(void)interrupt;
|
||||
}
|
||||
|
||||
#endif
|
||||
116
src/rf95/RHHardwareSPI.h
Normal file
116
src/rf95/RHHardwareSPI.h
Normal file
@@ -0,0 +1,116 @@
|
||||
// RHHardwareSPI.h
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2011 Mike McCauley
|
||||
// Contributed by Joanna Rutkowska
|
||||
// $Id: RHHardwareSPI.h,v 1.12 2020/01/05 07:02:23 mikem Exp mikem $
|
||||
|
||||
#ifndef RHHardwareSPI_h
|
||||
#define RHHardwareSPI_h
|
||||
|
||||
#include <RHGenericSPI.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// \class RHHardwareSPI RHHardwareSPI.h <RHHardwareSPI.h>
|
||||
/// \brief Encapsulate a hardware SPI bus interface
|
||||
///
|
||||
/// This concrete subclass of GenericSPIClass encapsulates the standard Arduino hardware and other
|
||||
/// hardware SPI interfaces.
|
||||
///
|
||||
/// SPI transactions are supported in development environments that support it with SPI_HAS_TRANSACTION.
|
||||
class RHHardwareSPI : public RHGenericSPI
|
||||
{
|
||||
#ifdef RH_HAVE_HARDWARE_SPI
|
||||
public:
|
||||
/// Constructor
|
||||
/// Creates an instance of a hardware SPI interface, using whatever SPI hardware is available on
|
||||
/// your processor platform. On Arduino and Uno32, uses SPI. On Maple, uses HardwareSPI.
|
||||
/// \param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency
|
||||
/// is mapped to the closest available bus frequency on the platform.
|
||||
/// \param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or
|
||||
/// RHGenericSPI::BitOrderLSBFirst.
|
||||
/// \param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode
|
||||
RHHardwareSPI(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
|
||||
|
||||
/// Transfer a single octet to and from the SPI interface
|
||||
/// \param[in] data The octet to send
|
||||
/// \return The octet read from SPI while the data octet was sent
|
||||
uint8_t transfer(uint8_t data);
|
||||
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
/// Transfer (write) 2 bytes on the SPI interface to an NRF device
|
||||
/// \param[in] byte0 The first byte to be sent on the SPI interface
|
||||
/// \param[in] byte1 The second byte to be sent on the SPI interface
|
||||
/// \return The second byte clocked in as the second byte is sent.
|
||||
uint8_t transfer2B(uint8_t byte0, uint8_t byte1);
|
||||
|
||||
/// Read a number of bytes on the SPI interface from an NRF device
|
||||
/// \param[in] reg The NRF device register to read
|
||||
/// \param[out] dest The buffer to hold the bytes read
|
||||
/// \param[in] len The number of bytes to read
|
||||
/// \return The NRF status byte
|
||||
uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
|
||||
|
||||
/// Wrte a number of bytes on the SPI interface to an NRF device
|
||||
/// \param[in] reg The NRF device register to read
|
||||
/// \param[out] src The buffer to hold the bytes write
|
||||
/// \param[in] len The number of bytes to write
|
||||
/// \return The NRF status byte
|
||||
uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);
|
||||
|
||||
#endif
|
||||
|
||||
// SPI Configuration methods
|
||||
/// Enable SPI interrupts
|
||||
/// This can be used in an SPI slave to indicate when an SPI message has been received
|
||||
/// It will cause the SPI_STC_vect interrupt vectr to be executed
|
||||
void attachInterrupt();
|
||||
|
||||
/// Disable SPI interrupts
|
||||
/// This can be used to diable the SPI interrupt in slaves where that is supported.
|
||||
void detachInterrupt();
|
||||
|
||||
/// Initialise the SPI library
|
||||
/// Call this after configuring the SPI interface and before using it to transfer data.
|
||||
/// Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
|
||||
void begin();
|
||||
|
||||
/// Disables the SPI bus (leaving pin modes unchanged).
|
||||
/// Call this after you have finished using the SPI interface.
|
||||
void end();
|
||||
#else
|
||||
// not supported on ATTiny etc
|
||||
uint8_t transfer(uint8_t /*data*/) {return 0;}
|
||||
void begin(){}
|
||||
void end(){}
|
||||
|
||||
#endif
|
||||
|
||||
/// Signal the start of an SPI transaction that must not be interrupted by other SPI actions
|
||||
/// In subclasses that support transactions this will ensure that other SPI transactions
|
||||
/// are blocked until this one is completed by endTransaction().
|
||||
/// Uses the underlying SPI transaction support if available as specified by SPI_HAS_TRANSACTION.
|
||||
virtual void beginTransaction();
|
||||
|
||||
/// Signal the end of an SPI transaction
|
||||
/// Uses the underlying SPI transaction support if available as specified by SPI_HAS_TRANSACTION.
|
||||
virtual void endTransaction();
|
||||
|
||||
/// Specify the interrupt number of the interrupt that will use SPI transactions
|
||||
/// Tells the SPI support software that SPI transactions will occur with the interrupt
|
||||
/// handler assocated with interruptNumber
|
||||
/// Uses the underlying SPI transaction support if available as specified by SPI_HAS_TRANSACTION.
|
||||
/// \param[in] interruptNumber The number of the interrupt
|
||||
virtual void usingInterrupt(uint8_t interruptNumber);
|
||||
|
||||
protected:
|
||||
|
||||
#if defined(SPI_HAS_TRANSACTION)
|
||||
// Storage for SPI settings used in SPI transactions
|
||||
SPISettings _settings;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Built in default instance
|
||||
extern RHHardwareSPI hardware_spi;
|
||||
|
||||
#endif
|
||||
137
src/rf95/RHNRFSPIDriver.cpp
Normal file
137
src/rf95/RHNRFSPIDriver.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
// RHNRFSPIDriver.cpp
|
||||
//
|
||||
// Copyright (C) 2014 Mike McCauley
|
||||
// $Id: RHNRFSPIDriver.cpp,v 1.5 2020/01/05 07:02:23 mikem Exp mikem $
|
||||
|
||||
#include <RHNRFSPIDriver.h>
|
||||
|
||||
RHNRFSPIDriver::RHNRFSPIDriver(uint8_t slaveSelectPin, RHGenericSPI& spi)
|
||||
:
|
||||
_spi(spi),
|
||||
_slaveSelectPin(slaveSelectPin)
|
||||
{
|
||||
}
|
||||
|
||||
bool RHNRFSPIDriver::init()
|
||||
{
|
||||
// start the SPI library with the default speeds etc:
|
||||
// On Arduino Due this defaults to SPI1 on the central group of 6 SPI pins
|
||||
_spi.begin();
|
||||
|
||||
// Initialise the slave select pin
|
||||
// On Maple, this must be _after_ spi.begin
|
||||
pinMode(_slaveSelectPin, OUTPUT);
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
|
||||
delay(100);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Low level commands for interfacing with the device
|
||||
uint8_t RHNRFSPIDriver::spiCommand(uint8_t command)
|
||||
{
|
||||
uint8_t status;
|
||||
ATOMIC_BLOCK_START;
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
status = _spi.transfer(command);
|
||||
#else
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
status = _spi.transfer(command);
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
#endif
|
||||
ATOMIC_BLOCK_END;
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t RHNRFSPIDriver::spiRead(uint8_t reg)
|
||||
{
|
||||
uint8_t val;
|
||||
ATOMIC_BLOCK_START;
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
val = _spi.transfer2B(reg, 0); // Send the address, discard the status, The written value is ignored, reg value is read
|
||||
#else
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
_spi.transfer(reg); // Send the address, discard the status
|
||||
val = _spi.transfer(0); // The written value is ignored, reg value is read
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
#endif
|
||||
ATOMIC_BLOCK_END;
|
||||
return val;
|
||||
}
|
||||
|
||||
uint8_t RHNRFSPIDriver::spiWrite(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
ATOMIC_BLOCK_START;
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
status = _spi.transfer2B(reg, val);
|
||||
#else
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
status = _spi.transfer(reg); // Send the address
|
||||
_spi.transfer(val); // New value follows
|
||||
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(__arm__) && defined(CORE_TEENSY)
|
||||
// Sigh: some devices, such as MRF89XA dont work properly on Teensy 3.1:
|
||||
// At 1MHz, the clock returns low _after_ slave select goes high, which prevents SPI
|
||||
// write working. This delay gixes time for the clock to return low.
|
||||
delayMicroseconds(5);
|
||||
#endif
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
#endif
|
||||
ATOMIC_BLOCK_END;
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t RHNRFSPIDriver::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
ATOMIC_BLOCK_START;
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
status = _spi.spiBurstRead(reg, dest, len);
|
||||
#else
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
status = _spi.transfer(reg); // Send the start address
|
||||
while (len--)
|
||||
*dest++ = _spi.transfer(0);
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
#endif
|
||||
ATOMIC_BLOCK_END;
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t RHNRFSPIDriver::spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
ATOMIC_BLOCK_START;
|
||||
#if (RH_PLATFORM == RH_PLATFORM_MONGOOSE_OS)
|
||||
status = _spi.spiBurstWrite(reg, src, len);
|
||||
#else
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
status = _spi.transfer(reg); // Send the start address
|
||||
while (len--)
|
||||
_spi.transfer(*src++);
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
#endif
|
||||
ATOMIC_BLOCK_END;
|
||||
return status;
|
||||
}
|
||||
|
||||
void RHNRFSPIDriver::setSlaveSelectPin(uint8_t slaveSelectPin)
|
||||
{
|
||||
_slaveSelectPin = slaveSelectPin;
|
||||
}
|
||||
|
||||
void RHNRFSPIDriver::spiUsingInterrupt(uint8_t interruptNumber)
|
||||
{
|
||||
_spi.usingInterrupt(interruptNumber);
|
||||
}
|
||||
|
||||
101
src/rf95/RHNRFSPIDriver.h
Normal file
101
src/rf95/RHNRFSPIDriver.h
Normal file
@@ -0,0 +1,101 @@
|
||||
// RHNRFSPIDriver.h
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2014 Mike McCauley
|
||||
// $Id: RHNRFSPIDriver.h,v 1.5 2017/11/06 00:04:08 mikem Exp $
|
||||
|
||||
#ifndef RHNRFSPIDriver_h
|
||||
#define RHNRFSPIDriver_h
|
||||
|
||||
#include <RHGenericDriver.h>
|
||||
#include <RHHardwareSPI.h>
|
||||
|
||||
class RHGenericSPI;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// \class RHNRFSPIDriver RHNRFSPIDriver.h <RHNRFSPIDriver.h>
|
||||
/// \brief Base class for RadioHead drivers that use the SPI bus
|
||||
/// to communicate with its NRF family transport hardware.
|
||||
///
|
||||
/// This class can be subclassed by Drivers that require to use the SPI bus.
|
||||
/// It can be configured to use either the RHHardwareSPI class (if there is one available on the platform)
|
||||
/// of the bitbanged RHSoftwareSPI class. The dfault behaviour is to use a pre-instantiated built-in RHHardwareSPI
|
||||
/// interface.
|
||||
///
|
||||
/// SPI bus access is protected by ATOMIC_BLOCK_START and ATOMIC_BLOCK_END, which will ensure interrupts
|
||||
/// are disabled during access.
|
||||
///
|
||||
/// The read and write routines use SPI conventions as used by Nordic NRF radios and otehr devices,
|
||||
/// but these can be overriden
|
||||
/// in subclasses if necessary.
|
||||
///
|
||||
/// Application developers are not expected to instantiate this class directly:
|
||||
/// it is for the use of Driver developers.
|
||||
class RHNRFSPIDriver : public RHGenericDriver
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
/// \param[in] slaveSelectPin The controller pin to use to select the desired SPI device. This pin will be driven LOW
|
||||
/// during SPI communications with the SPI device that uis iused by this Driver.
|
||||
/// \param[in] spi Reference to the SPI interface to use. The default is to use a default built-in Hardware interface.
|
||||
RHNRFSPIDriver(uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);
|
||||
|
||||
/// Initialise the Driver transport hardware and software.
|
||||
/// Make sure the Driver is properly configured before calling init().
|
||||
/// \return true if initialisation succeeded.
|
||||
bool init();
|
||||
|
||||
/// Sends a single command to the device
|
||||
/// \param[in] command The command code to send to the device.
|
||||
/// \return Some devices return a status byte during the first data transfer. This byte is returned.
|
||||
/// it may or may not be meaningfule depending on the the type of device being accessed.
|
||||
uint8_t spiCommand(uint8_t command);
|
||||
|
||||
/// Reads a single register from the SPI device
|
||||
/// \param[in] reg Register number
|
||||
/// \return The value of the register
|
||||
uint8_t spiRead(uint8_t reg);
|
||||
|
||||
/// Writes a single byte to the SPI device
|
||||
/// \param[in] reg Register number
|
||||
/// \param[in] val The value to write
|
||||
/// \return Some devices return a status byte during the first data transfer. This byte is returned.
|
||||
/// it may or may not be meaningfule depending on the the type of device being accessed.
|
||||
uint8_t spiWrite(uint8_t reg, uint8_t val);
|
||||
|
||||
/// Reads a number of consecutive registers from the SPI device using burst read mode
|
||||
/// \param[in] reg Register number of the first register
|
||||
/// \param[in] dest Array to write the register values to. Must be at least len bytes
|
||||
/// \param[in] len Number of bytes to read
|
||||
/// \return Some devices return a status byte during the first data transfer. This byte is returned.
|
||||
/// it may or may not be meaningfule depending on the the type of device being accessed.
|
||||
uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
|
||||
|
||||
/// Write a number of consecutive registers using burst write mode
|
||||
/// \param[in] reg Register number of the first register
|
||||
/// \param[in] src Array of new register values to write. Must be at least len bytes
|
||||
/// \param[in] len Number of bytes to write
|
||||
/// \return Some devices return a status byte during the first data transfer. This byte is returned.
|
||||
/// it may or may not be meaningfule depending on the the type of device being accessed.
|
||||
uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);
|
||||
|
||||
/// Set or change the pin to be used for SPI slave select.
|
||||
/// This can be called at any time to change the
|
||||
/// pin that will be used for slave select in subsquent SPI operations.
|
||||
/// \param[in] slaveSelectPin The pin to use
|
||||
void setSlaveSelectPin(uint8_t slaveSelectPin);
|
||||
|
||||
/// Set the SPI interrupt number
|
||||
/// If SPI transactions can occur within an interrupt, tell the low level SPI
|
||||
/// interface which interrupt is used
|
||||
/// \param[in] interruptNumber the interrupt number
|
||||
void spiUsingInterrupt(uint8_t interruptNumber);
|
||||
|
||||
protected:
|
||||
/// Reference to the RHGenericSPI instance to use to trasnfer data with teh SPI device
|
||||
RHGenericSPI& _spi;
|
||||
|
||||
/// The pin number of the Slave Select pin that is used to select the desired device.
|
||||
uint8_t _slaveSelectPin;
|
||||
};
|
||||
|
||||
#endif
|
||||
95
src/rf95/RHSPIDriver.cpp
Normal file
95
src/rf95/RHSPIDriver.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
// RHSPIDriver.cpp
|
||||
//
|
||||
// Copyright (C) 2014 Mike McCauley
|
||||
// $Id: RHSPIDriver.cpp,v 1.11 2017/11/06 00:04:08 mikem Exp $
|
||||
|
||||
#include <RHSPIDriver.h>
|
||||
|
||||
RHSPIDriver::RHSPIDriver(uint8_t slaveSelectPin, RHGenericSPI& spi)
|
||||
:
|
||||
_spi(spi),
|
||||
_slaveSelectPin(slaveSelectPin)
|
||||
{
|
||||
}
|
||||
|
||||
bool RHSPIDriver::init()
|
||||
{
|
||||
// start the SPI library with the default speeds etc:
|
||||
// On Arduino Due this defaults to SPI1 on the central group of 6 SPI pins
|
||||
_spi.begin();
|
||||
|
||||
// Initialise the slave select pin
|
||||
// On Maple, this must be _after_ spi.begin
|
||||
pinMode(_slaveSelectPin, OUTPUT);
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
|
||||
delay(100);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t RHSPIDriver::spiRead(uint8_t reg)
|
||||
{
|
||||
uint8_t val;
|
||||
ATOMIC_BLOCK_START;
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
_spi.transfer(reg & ~RH_SPI_WRITE_MASK); // Send the address with the write mask off
|
||||
val = _spi.transfer(0); // The written value is ignored, reg value is read
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
ATOMIC_BLOCK_END;
|
||||
return val;
|
||||
}
|
||||
|
||||
uint8_t RHSPIDriver::spiWrite(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
ATOMIC_BLOCK_START;
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
status = _spi.transfer(reg | RH_SPI_WRITE_MASK); // Send the address with the write mask on
|
||||
_spi.transfer(val); // New value follows
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
ATOMIC_BLOCK_END;
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t RHSPIDriver::spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
ATOMIC_BLOCK_START;
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
status = _spi.transfer(reg & ~RH_SPI_WRITE_MASK); // Send the start address with the write mask off
|
||||
while (len--)
|
||||
*dest++ = _spi.transfer(0);
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
ATOMIC_BLOCK_END;
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t RHSPIDriver::spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
ATOMIC_BLOCK_START;
|
||||
_spi.beginTransaction();
|
||||
digitalWrite(_slaveSelectPin, LOW);
|
||||
status = _spi.transfer(reg | RH_SPI_WRITE_MASK); // Send the start address with the write mask on
|
||||
while (len--)
|
||||
_spi.transfer(*src++);
|
||||
digitalWrite(_slaveSelectPin, HIGH);
|
||||
_spi.endTransaction();
|
||||
ATOMIC_BLOCK_END;
|
||||
return status;
|
||||
}
|
||||
|
||||
void RHSPIDriver::setSlaveSelectPin(uint8_t slaveSelectPin)
|
||||
{
|
||||
_slaveSelectPin = slaveSelectPin;
|
||||
}
|
||||
|
||||
void RHSPIDriver::spiUsingInterrupt(uint8_t interruptNumber)
|
||||
{
|
||||
_spi.usingInterrupt(interruptNumber);
|
||||
}
|
||||
|
||||
100
src/rf95/RHSPIDriver.h
Normal file
100
src/rf95/RHSPIDriver.h
Normal file
@@ -0,0 +1,100 @@
|
||||
// RHSPIDriver.h
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2014 Mike McCauley
|
||||
// $Id: RHSPIDriver.h,v 1.14 2019/09/06 04:40:40 mikem Exp $
|
||||
|
||||
#ifndef RHSPIDriver_h
|
||||
#define RHSPIDriver_h
|
||||
|
||||
#include <RHGenericDriver.h>
|
||||
#include <RHHardwareSPI.h>
|
||||
|
||||
// This is the bit in the SPI address that marks it as a write
|
||||
#define RH_SPI_WRITE_MASK 0x80
|
||||
|
||||
class RHGenericSPI;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// \class RHSPIDriver RHSPIDriver.h <RHSPIDriver.h>
|
||||
/// \brief Base class for RadioHead drivers that use the SPI bus
|
||||
/// to communicate with its transport hardware.
|
||||
///
|
||||
/// This class can be subclassed by Drivers that require to use the SPI bus.
|
||||
/// It can be configured to use either the RHHardwareSPI class (if there is one available on the platform)
|
||||
/// of the bitbanged RHSoftwareSPI class. The default behaviour is to use a pre-instantiated built-in RHHardwareSPI
|
||||
/// interface.
|
||||
///
|
||||
/// SPI bus access is protected by ATOMIC_BLOCK_START and ATOMIC_BLOCK_END, which will ensure interrupts
|
||||
/// are disabled during access.
|
||||
///
|
||||
/// The read and write routines implement commonly used SPI conventions: specifically that the MSB
|
||||
/// of the first byte transmitted indicates that it is a write and the remaining bits indicate the rehgister to access)
|
||||
/// This can be overriden
|
||||
/// in subclasses if necessaryor an alternative class, RHNRFSPIDriver can be used to access devices like
|
||||
/// Nordic NRF series radios, which have different requirements.
|
||||
///
|
||||
/// Application developers are not expected to instantiate this class directly:
|
||||
/// it is for the use of Driver developers.
|
||||
class RHSPIDriver : public RHGenericDriver
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
/// \param[in] slaveSelectPin The controler pin to use to select the desired SPI device. This pin will be driven LOW
|
||||
/// during SPI communications with the SPI device that uis iused by this Driver.
|
||||
/// \param[in] spi Reference to the SPI interface to use. The default is to use a default built-in Hardware interface.
|
||||
RHSPIDriver(uint8_t slaveSelectPin = SS, RHGenericSPI& spi = hardware_spi);
|
||||
|
||||
/// Initialise the Driver transport hardware and software.
|
||||
/// Make sure the Driver is properly configured before calling init().
|
||||
/// \return true if initialisation succeeded.
|
||||
bool init();
|
||||
|
||||
/// Reads a single register from the SPI device
|
||||
/// \param[in] reg Register number
|
||||
/// \return The value of the register
|
||||
uint8_t spiRead(uint8_t reg);
|
||||
|
||||
/// Writes a single byte to the SPI device
|
||||
/// \param[in] reg Register number
|
||||
/// \param[in] val The value to write
|
||||
/// \return Some devices return a status byte during the first data transfer. This byte is returned.
|
||||
/// it may or may not be meaningfule depending on the the type of device being accessed.
|
||||
uint8_t spiWrite(uint8_t reg, uint8_t val);
|
||||
|
||||
/// Reads a number of consecutive registers from the SPI device using burst read mode
|
||||
/// \param[in] reg Register number of the first register
|
||||
/// \param[in] dest Array to write the register values to. Must be at least len bytes
|
||||
/// \param[in] len Number of bytes to read
|
||||
/// \return Some devices return a status byte during the first data transfer. This byte is returned.
|
||||
/// it may or may not be meaningfule depending on the the type of device being accessed.
|
||||
uint8_t spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
|
||||
|
||||
/// Write a number of consecutive registers using burst write mode
|
||||
/// \param[in] reg Register number of the first register
|
||||
/// \param[in] src Array of new register values to write. Must be at least len bytes
|
||||
/// \param[in] len Number of bytes to write
|
||||
/// \return Some devices return a status byte during the first data transfer. This byte is returned.
|
||||
/// it may or may not be meaningfule depending on the the type of device being accessed.
|
||||
uint8_t spiBurstWrite(uint8_t reg, const uint8_t* src, uint8_t len);
|
||||
|
||||
/// Set or change the pin to be used for SPI slave select.
|
||||
/// This can be called at any time to change the
|
||||
/// pin that will be used for slave select in subsquent SPI operations.
|
||||
/// \param[in] slaveSelectPin The pin to use
|
||||
void setSlaveSelectPin(uint8_t slaveSelectPin);
|
||||
|
||||
/// Set the SPI interrupt number
|
||||
/// If SPI transactions can occur within an interrupt, tell the low level SPI
|
||||
/// interface which interrupt is used
|
||||
/// \param[in] interruptNumber the interrupt number
|
||||
void spiUsingInterrupt(uint8_t interruptNumber);
|
||||
|
||||
protected:
|
||||
/// Reference to the RHGenericSPI instance to use to transfer data with the SPI device
|
||||
RHGenericSPI& _spi;
|
||||
|
||||
/// The pin number of the Slave Select pin that is used to select the desired device.
|
||||
uint8_t _slaveSelectPin;
|
||||
};
|
||||
|
||||
#endif
|
||||
166
src/rf95/RHSoftwareSPI.cpp
Normal file
166
src/rf95/RHSoftwareSPI.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
// SoftwareSPI.cpp
|
||||
// Author: Chris Lapa (chris@lapa.com.au)
|
||||
// Copyright (C) 2014 Chris Lapa
|
||||
// Contributed by Chris Lapa
|
||||
|
||||
#include <RHSoftwareSPI.h>
|
||||
|
||||
RHSoftwareSPI::RHSoftwareSPI(Frequency frequency, BitOrder bitOrder, DataMode dataMode)
|
||||
:
|
||||
RHGenericSPI(frequency, bitOrder, dataMode)
|
||||
{
|
||||
setPins(12, 11, 13);
|
||||
}
|
||||
|
||||
// Caution: on Arduino Uno and many other CPUs, digitalWrite is quite slow, taking about 4us
|
||||
// digitalWrite is also slow, taking about 3.5us
|
||||
// resulting in very slow SPI bus speeds using this technique, up to about 120us per octet of transfer
|
||||
uint8_t RHSoftwareSPI::transfer(uint8_t data)
|
||||
{
|
||||
uint8_t readData;
|
||||
uint8_t writeData;
|
||||
uint8_t builtReturn;
|
||||
uint8_t mask;
|
||||
|
||||
if (_bitOrder == BitOrderMSBFirst)
|
||||
{
|
||||
mask = 0x80;
|
||||
}
|
||||
else
|
||||
{
|
||||
mask = 0x01;
|
||||
}
|
||||
builtReturn = 0;
|
||||
readData = 0;
|
||||
|
||||
for (uint8_t count=0; count<8; count++)
|
||||
{
|
||||
if (data & mask)
|
||||
{
|
||||
writeData = HIGH;
|
||||
}
|
||||
else
|
||||
{
|
||||
writeData = LOW;
|
||||
}
|
||||
|
||||
if (_clockPhase == 1)
|
||||
{
|
||||
// CPHA=1, miso/mosi changing state now
|
||||
digitalWrite(_mosi, writeData);
|
||||
digitalWrite(_sck, ~_clockPolarity);
|
||||
delayPeriod();
|
||||
|
||||
// CPHA=1, miso/mosi stable now
|
||||
readData = digitalRead(_miso);
|
||||
digitalWrite(_sck, _clockPolarity);
|
||||
delayPeriod();
|
||||
}
|
||||
else
|
||||
{
|
||||
// CPHA=0, miso/mosi changing state now
|
||||
digitalWrite(_mosi, writeData);
|
||||
digitalWrite(_sck, _clockPolarity);
|
||||
delayPeriod();
|
||||
|
||||
// CPHA=0, miso/mosi stable now
|
||||
readData = digitalRead(_miso);
|
||||
digitalWrite(_sck, ~_clockPolarity);
|
||||
delayPeriod();
|
||||
}
|
||||
|
||||
if (_bitOrder == BitOrderMSBFirst)
|
||||
{
|
||||
mask >>= 1;
|
||||
builtReturn |= (readData << (7 - count));
|
||||
}
|
||||
else
|
||||
{
|
||||
mask <<= 1;
|
||||
builtReturn |= (readData << count);
|
||||
}
|
||||
}
|
||||
|
||||
digitalWrite(_sck, _clockPolarity);
|
||||
|
||||
return builtReturn;
|
||||
}
|
||||
|
||||
/// Initialise the SPI library
|
||||
void RHSoftwareSPI::begin()
|
||||
{
|
||||
if (_dataMode == DataMode0 ||
|
||||
_dataMode == DataMode1)
|
||||
{
|
||||
_clockPolarity = LOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
_clockPolarity = HIGH;
|
||||
}
|
||||
|
||||
if (_dataMode == DataMode0 ||
|
||||
_dataMode == DataMode2)
|
||||
{
|
||||
_clockPhase = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_clockPhase = 1;
|
||||
}
|
||||
digitalWrite(_sck, _clockPolarity);
|
||||
|
||||
// Caution: these counts assume that digitalWrite is very fast, which is usually not true
|
||||
switch (_frequency)
|
||||
{
|
||||
case Frequency1MHz:
|
||||
_delayCounts = 8;
|
||||
break;
|
||||
|
||||
case Frequency2MHz:
|
||||
_delayCounts = 4;
|
||||
break;
|
||||
|
||||
case Frequency4MHz:
|
||||
_delayCounts = 2;
|
||||
break;
|
||||
|
||||
case Frequency8MHz:
|
||||
_delayCounts = 1;
|
||||
break;
|
||||
|
||||
case Frequency16MHz:
|
||||
_delayCounts = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Disables the SPI bus usually, in this case
|
||||
/// there is no hardware controller to disable.
|
||||
void RHSoftwareSPI::end() { }
|
||||
|
||||
/// Sets the pins used by this SoftwareSPIClass instance.
|
||||
/// \param[in] miso master in slave out pin used
|
||||
/// \param[in] mosi master out slave in pin used
|
||||
/// \param[in] sck clock pin used
|
||||
void RHSoftwareSPI::setPins(uint8_t miso, uint8_t mosi, uint8_t sck)
|
||||
{
|
||||
_miso = miso;
|
||||
_mosi = mosi;
|
||||
_sck = sck;
|
||||
|
||||
pinMode(_miso, INPUT);
|
||||
pinMode(_mosi, OUTPUT);
|
||||
pinMode(_sck, OUTPUT);
|
||||
digitalWrite(_sck, _clockPolarity);
|
||||
}
|
||||
|
||||
|
||||
void RHSoftwareSPI::delayPeriod()
|
||||
{
|
||||
for (uint8_t count = 0; count < _delayCounts; count++)
|
||||
{
|
||||
__asm__ __volatile__ ("nop");
|
||||
}
|
||||
}
|
||||
|
||||
90
src/rf95/RHSoftwareSPI.h
Normal file
90
src/rf95/RHSoftwareSPI.h
Normal file
@@ -0,0 +1,90 @@
|
||||
// SoftwareSPI.h
|
||||
// Author: Chris Lapa (chris@lapa.com.au)
|
||||
// Copyright (C) 2014 Chris Lapa
|
||||
// Contributed by Chris Lapa
|
||||
|
||||
#ifndef RHSoftwareSPI_h
|
||||
#define RHSoftwareSPI_h
|
||||
|
||||
#include <RHGenericSPI.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// \class RHSoftwareSPI RHSoftwareSPI.h <RHSoftwareSPI.h>
|
||||
/// \brief Encapsulate a software SPI interface
|
||||
///
|
||||
/// This concrete subclass of RHGenericSPI enapsulates a bit-banged software SPI interface.
|
||||
/// Caution: this software SPI interface will be much slower than hardware SPI on most
|
||||
/// platforms.
|
||||
///
|
||||
/// SPI transactions are not supported, and associated functions do nothing.
|
||||
///
|
||||
/// \par Usage
|
||||
///
|
||||
/// Usage varies slightly depending on what driver you are using.
|
||||
///
|
||||
/// For RF22, for example:
|
||||
/// \code
|
||||
/// #include <RHSoftwareSPI.h>
|
||||
/// RHSoftwareSPI spi;
|
||||
/// RH_RF22 driver(SS, 2, spi);
|
||||
/// RHReliableDatagram(driver, CLIENT_ADDRESS);
|
||||
/// void setup()
|
||||
/// {
|
||||
/// spi.setPins(6, 5, 7); // Or whatever SPI pins you need
|
||||
/// ....
|
||||
/// }
|
||||
/// \endcode
|
||||
class RHSoftwareSPI : public RHGenericSPI
|
||||
{
|
||||
public:
|
||||
|
||||
/// Constructor
|
||||
/// Creates an instance of a bit-banged software SPI interface.
|
||||
/// Sets the SPI pins to the defaults of
|
||||
/// MISO = 12, MOSI = 11, SCK = 13. If you need other assigments, call setPins() before
|
||||
/// calling manager.init() or driver.init().
|
||||
/// \param[in] frequency One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency
|
||||
/// is mapped to the closest available bus frequency on the platform. CAUTION: the achieved
|
||||
/// frequency will almost certainly be very much slower on most platforms. eg on Arduino Uno, the
|
||||
/// the clock rate is likely to be at best around 46kHz.
|
||||
/// \param[in] bitOrder Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or
|
||||
/// RHGenericSPI::BitOrderLSBFirst.
|
||||
/// \param[in] dataMode Selects the SPI bus data mode. One of RHGenericSPI::DataMode
|
||||
RHSoftwareSPI(Frequency frequency = Frequency1MHz, BitOrder bitOrder = BitOrderMSBFirst, DataMode dataMode = DataMode0);
|
||||
|
||||
/// Transfer a single octet to and from the SPI interface
|
||||
/// \param[in] data The octet to send
|
||||
/// \return The octet read from SPI while the data octet was sent.
|
||||
uint8_t transfer(uint8_t data);
|
||||
|
||||
/// Initialise the software SPI library
|
||||
/// Call this after configuring the SPI interface and before using it to transfer data.
|
||||
/// Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
|
||||
void begin();
|
||||
|
||||
/// Disables the SPI bus usually, in this case
|
||||
/// there is no hardware controller to disable.
|
||||
void end();
|
||||
|
||||
/// Sets the pins used by this SoftwareSPIClass instance.
|
||||
/// The defaults are: MISO = 12, MOSI = 11, SCK = 13.
|
||||
/// \param[in] miso master in slave out pin used
|
||||
/// \param[in] mosi master out slave in pin used
|
||||
/// \param[in] sck clock pin used
|
||||
void setPins(uint8_t miso = 12, uint8_t mosi = 11, uint8_t sck = 13);
|
||||
|
||||
private:
|
||||
|
||||
/// Delay routine for bus timing.
|
||||
void delayPeriod();
|
||||
|
||||
private:
|
||||
uint8_t _miso;
|
||||
uint8_t _mosi;
|
||||
uint8_t _sck;
|
||||
uint8_t _delayCounts;
|
||||
uint8_t _clockPolarity;
|
||||
uint8_t _clockPhase;
|
||||
};
|
||||
|
||||
#endif
|
||||
646
src/rf95/RH_RF95.cpp
Normal file
646
src/rf95/RH_RF95.cpp
Normal file
@@ -0,0 +1,646 @@
|
||||
// RH_RF95.cpp
|
||||
//
|
||||
// Copyright (C) 2011 Mike McCauley
|
||||
// $Id: RH_RF95.cpp,v 1.22 2020/01/05 07:02:23 mikem Exp mikem $
|
||||
|
||||
#include <RH_RF95.h>
|
||||
|
||||
// Interrupt vectors for the 3 Arduino interrupt pins
|
||||
// Each interrupt can be handled by a different instance of RH_RF95, allowing you to have
|
||||
// 2 or more LORAs per Arduino
|
||||
RH_RF95 *RH_RF95::_deviceForInterrupt[RH_RF95_NUM_INTERRUPTS] = {0, 0, 0};
|
||||
uint8_t RH_RF95::_interruptCount = 0; // Index into _deviceForInterrupt for next device
|
||||
|
||||
// These are indexed by the values of ModemConfigChoice
|
||||
// Stored in flash (program) memory to save SRAM
|
||||
PROGMEM static const RH_RF95::ModemConfig MODEM_CONFIG_TABLE[] = {
|
||||
// 1d, 1e, 26
|
||||
{0x72, 0x74, 0x04}, // Bw125Cr45Sf128 (the chip default), AGC enabled
|
||||
{0x92, 0x74, 0x04}, // Bw500Cr45Sf128, AGC enabled
|
||||
{0x48, 0x94, 0x04}, // Bw31_25Cr48Sf512, AGC enabled
|
||||
{0x78, 0xc4, 0x0c}, // Bw125Cr48Sf4096, AGC enabled
|
||||
|
||||
};
|
||||
|
||||
RH_RF95::RH_RF95(uint8_t slaveSelectPin, uint8_t interruptPin, RHGenericSPI &spi)
|
||||
: RHSPIDriver(slaveSelectPin, spi), _rxBufValid(0)
|
||||
{
|
||||
_interruptPin = interruptPin;
|
||||
_myInterruptIndex = 0xff; // Not allocated yet
|
||||
}
|
||||
|
||||
bool RH_RF95::init()
|
||||
{
|
||||
if (!RHSPIDriver::init())
|
||||
return false;
|
||||
|
||||
#ifdef RH_ATTACHINTERRUPT_TAKES_PIN_NUMBER
|
||||
interruptNumber = _interruptPin;
|
||||
#endif
|
||||
|
||||
// Tell the low level SPI interface we will use SPI within this interrupt
|
||||
// spiUsingInterrupt(interruptNumber);
|
||||
|
||||
// No way to check the device type :-(
|
||||
|
||||
// Add by Adrien van den Bossche <vandenbo@univ-tlse2.fr> for Teensy
|
||||
// ARM M4 requires the below. else pin interrupt doesn't work properly.
|
||||
// On all other platforms, its innocuous, belt and braces
|
||||
pinMode(_interruptPin, INPUT);
|
||||
|
||||
bool isWakeFromDeepSleep =
|
||||
false; // true if we think we are waking from deep sleep AND the rf95 seems to have a valid configuration
|
||||
|
||||
if (!isWakeFromDeepSleep) {
|
||||
// Set sleep mode, so we can also set LORA mode:
|
||||
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE);
|
||||
delay(10); // Wait for sleep mode to take over from say, CAD
|
||||
// Check we are in sleep mode, with LORA set
|
||||
if (spiRead(RH_RF95_REG_01_OP_MODE) != (RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE)) {
|
||||
// Serial.println(spiRead(RH_RF95_REG_01_OP_MODE), HEX);
|
||||
return false; // No device present?
|
||||
}
|
||||
|
||||
// Set up FIFO
|
||||
// We configure so that we can use the entire 256 byte FIFO for either receive
|
||||
// or transmit, but not both at the same time
|
||||
spiWrite(RH_RF95_REG_0E_FIFO_TX_BASE_ADDR, 0);
|
||||
spiWrite(RH_RF95_REG_0F_FIFO_RX_BASE_ADDR, 0);
|
||||
|
||||
// Packet format is preamble + explicit-header + payload + crc
|
||||
// Explicit Header Mode
|
||||
// payload is TO + FROM + ID + FLAGS + message data
|
||||
// RX mode is implmented with RXCONTINUOUS
|
||||
// max message data length is 255 - 4 = 251 octets
|
||||
|
||||
setModeIdle();
|
||||
|
||||
// Set up default configuration
|
||||
// No Sync Words in LORA mode.
|
||||
setModemConfig(Bw125Cr45Sf128); // Radio default
|
||||
// setModemConfig(Bw125Cr48Sf4096); // slow and reliable?
|
||||
setPreambleLength(8); // Default is 8
|
||||
// An innocuous ISM frequency, same as RF22's
|
||||
setFrequency(434.0);
|
||||
// Lowish power
|
||||
setTxPower(13);
|
||||
|
||||
Serial.printf("IRQ flag mask 0x%x\n", spiRead(RH_RF95_REG_11_IRQ_FLAGS_MASK));
|
||||
} else {
|
||||
// FIXME
|
||||
// restore mode base off reading RS95 registers
|
||||
|
||||
// Only let CPU enter deep sleep if RF95 is sitting waiting on a receive or is in idle or sleep.
|
||||
}
|
||||
|
||||
// geeksville: we do this last, because if there is an interrupt pending from during the deep sleep, this attach will cause it
|
||||
// to be taken.
|
||||
|
||||
// Set up interrupt handler
|
||||
// Since there are a limited number of interrupt glue functions isr*() available,
|
||||
// we can only support a limited number of devices simultaneously
|
||||
// ON some devices, notably most Arduinos, the interrupt pin passed in is actuallt the
|
||||
// interrupt number. You have to figure out the interruptnumber-to-interruptpin mapping
|
||||
// yourself based on knwledge of what Arduino board you are running on.
|
||||
if (_myInterruptIndex == 0xff) {
|
||||
// First run, no interrupt allocated yet
|
||||
if (_interruptCount <= RH_RF95_NUM_INTERRUPTS)
|
||||
_myInterruptIndex = _interruptCount++;
|
||||
else
|
||||
return false; // Too many devices, not enough interrupt vectors
|
||||
}
|
||||
_deviceForInterrupt[_myInterruptIndex] = this;
|
||||
|
||||
return enableInterrupt();
|
||||
}
|
||||
|
||||
bool RH_RF95::enableInterrupt()
|
||||
{
|
||||
// Determine the interrupt number that corresponds to the interruptPin
|
||||
int interruptNumber = digitalPinToInterrupt(_interruptPin);
|
||||
if (interruptNumber == NOT_AN_INTERRUPT)
|
||||
return false;
|
||||
|
||||
if (_myInterruptIndex == 0)
|
||||
attachInterrupt(interruptNumber, isr0, ONHIGH);
|
||||
else if (_myInterruptIndex == 1)
|
||||
attachInterrupt(interruptNumber, isr1, ONHIGH);
|
||||
else if (_myInterruptIndex == 2)
|
||||
attachInterrupt(interruptNumber, isr2, ONHIGH);
|
||||
else
|
||||
return false; // Too many devices, not enough interrupt vectors
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RH_INTERRUPT_ATTR RH_RF95::disableInterrupt()
|
||||
{
|
||||
int interruptNumber = digitalPinToInterrupt(_interruptPin);
|
||||
detachInterrupt(interruptNumber);
|
||||
}
|
||||
|
||||
void RH_RF95::prepareDeepSleep()
|
||||
{
|
||||
// Determine the interrupt number that corresponds to the interruptPin
|
||||
int interruptNumber = digitalPinToInterrupt(_interruptPin);
|
||||
|
||||
detachInterrupt(interruptNumber);
|
||||
}
|
||||
|
||||
bool RH_RF95::isReceiving()
|
||||
{
|
||||
// 0x0b == Look for header info valid, signal synchronized or signal detected
|
||||
uint8_t reg = spiRead(RH_RF95_REG_18_MODEM_STAT) & 0x1f;
|
||||
// Serial.printf("reg %x\n", reg);
|
||||
return _mode == RHModeRx && (reg & (RH_RF95_MODEM_STATUS_SIGNAL_DETECTED | RH_RF95_MODEM_STATUS_SIGNAL_SYNCHRONIZED |
|
||||
RH_RF95_MODEM_STATUS_HEADER_INFO_VALID)) != 0;
|
||||
}
|
||||
|
||||
void RH_INTERRUPT_ATTR RH_RF95::handleInterruptLevel0()
|
||||
{
|
||||
disableInterrupt(); // Disable our interrupt until our helper thread can run (because the IRQ will remain asserted until we
|
||||
// talk to it via SPI)
|
||||
pendingInterrupt = true;
|
||||
}
|
||||
|
||||
// C++ level interrupt handler for this instance
|
||||
// LORA is unusual in that it has several interrupt lines, and not a single, combined one.
|
||||
// On MiniWirelessLoRa, only one of the several interrupt lines (DI0) from the RFM95 is usefuly
|
||||
// connnected to the processor.
|
||||
// We use this to get RxDone and TxDone interrupts
|
||||
void RH_RF95::handleInterrupt()
|
||||
{
|
||||
// Read the interrupt register
|
||||
uint8_t irq_flags = spiRead(RH_RF95_REG_12_IRQ_FLAGS);
|
||||
|
||||
// ack all interrupts
|
||||
// note from radiohead author wrt old code (with IMO wrong fix)
|
||||
// Sigh: on some processors, for some unknown reason, doing this only once does not actually
|
||||
// clear the radio's interrupt flag. So we do it twice. Why? (kevinh - I think the root cause we want level
|
||||
// triggered interrupts here - not edge. Because edge allows us to miss handling secondard interrupts that occurred
|
||||
// while this ISR was running. Better to instead, configure the interrupts as level triggered and clear pending
|
||||
// at the _beginning_ of the ISR. If any interrupts occur while handling the ISR, the signal will remain asserted and
|
||||
// our ISR will be reinvoked to handle that case)
|
||||
spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags
|
||||
|
||||
// Note: there can be substantial latency between ISR assertion and this function being run, therefore
|
||||
// multiple flags might be set. Handle them all
|
||||
|
||||
// Note: we are running the chip in continuous receive mode (currently, so RX_TIMEOUT shouldn't ever occur)
|
||||
bool haveRxError = irq_flags & (RH_RF95_RX_TIMEOUT | RH_RF95_PAYLOAD_CRC_ERROR);
|
||||
if (haveRxError) {
|
||||
_rxBad++;
|
||||
clearRxBuf();
|
||||
} else if (irq_flags & RH_RF95_RX_DONE) {
|
||||
// Read the RegHopChannel register to check if CRC presence is signalled
|
||||
// in the header. If not it might be a stray (noise) packet.*
|
||||
uint8_t crc_present = spiRead(RH_RF95_REG_1C_HOP_CHANNEL) & RH_RF95_RX_PAYLOAD_CRC_IS_ON;
|
||||
|
||||
if (!crc_present) {
|
||||
_rxBad++;
|
||||
clearRxBuf();
|
||||
} else {
|
||||
// Have received a packet
|
||||
uint8_t len = spiRead(RH_RF95_REG_13_RX_NB_BYTES);
|
||||
|
||||
// Reset the fifo read ptr to the beginning of the packet
|
||||
spiWrite(RH_RF95_REG_0D_FIFO_ADDR_PTR, spiRead(RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR));
|
||||
spiBurstRead(RH_RF95_REG_00_FIFO, _buf, len);
|
||||
_bufLen = len;
|
||||
|
||||
// Remember the last signal to noise ratio, LORA mode
|
||||
// Per page 111, SX1276/77/78/79 datasheet
|
||||
_lastSNR = (int8_t)spiRead(RH_RF95_REG_19_PKT_SNR_VALUE) / 4;
|
||||
|
||||
// Remember the RSSI of this packet, LORA mode
|
||||
// this is according to the doc, but is it really correct?
|
||||
// weakest receiveable signals are reported RSSI at about -66
|
||||
_lastRssi = spiRead(RH_RF95_REG_1A_PKT_RSSI_VALUE);
|
||||
// Adjust the RSSI, datasheet page 87
|
||||
if (_lastSNR < 0)
|
||||
_lastRssi = _lastRssi + _lastSNR;
|
||||
else
|
||||
_lastRssi = (int)_lastRssi * 16 / 15;
|
||||
if (_usingHFport)
|
||||
_lastRssi -= 157;
|
||||
else
|
||||
_lastRssi -= 164;
|
||||
|
||||
// We have received a message.
|
||||
validateRxBuf();
|
||||
if (_rxBufValid)
|
||||
setModeIdle(); // Got one
|
||||
}
|
||||
}
|
||||
|
||||
if (irq_flags & RH_RF95_TX_DONE) {
|
||||
_txGood++;
|
||||
setModeIdle();
|
||||
}
|
||||
|
||||
if (_mode == RHModeCad && (irq_flags & RH_RF95_CAD_DONE)) {
|
||||
_cad = irq_flags & RH_RF95_CAD_DETECTED;
|
||||
setModeIdle();
|
||||
}
|
||||
|
||||
enableInterrupt(); // Let ISR run again
|
||||
}
|
||||
|
||||
void RH_RF95::loop()
|
||||
{
|
||||
while (pendingInterrupt) {
|
||||
pendingInterrupt = false; // If the flag was set, it is _guaranteed_ the ISR won't be running, because it masked itself
|
||||
handleInterrupt();
|
||||
}
|
||||
}
|
||||
|
||||
// These are low level functions that call the interrupt handler for the correct
|
||||
// instance of RH_RF95.
|
||||
// 3 interrupts allows us to have 3 different devices
|
||||
void RH_INTERRUPT_ATTR RH_RF95::isr0()
|
||||
{
|
||||
if (_deviceForInterrupt[0])
|
||||
_deviceForInterrupt[0]->handleInterruptLevel0();
|
||||
}
|
||||
void RH_INTERRUPT_ATTR RH_RF95::isr1()
|
||||
{
|
||||
if (_deviceForInterrupt[1])
|
||||
_deviceForInterrupt[1]->handleInterruptLevel0();
|
||||
}
|
||||
void RH_INTERRUPT_ATTR RH_RF95::isr2()
|
||||
{
|
||||
if (_deviceForInterrupt[2])
|
||||
_deviceForInterrupt[2]->handleInterruptLevel0();
|
||||
}
|
||||
|
||||
// Check whether the latest received message is complete and uncorrupted
|
||||
void RH_RF95::validateRxBuf()
|
||||
{
|
||||
if (_bufLen < 4)
|
||||
return; // Too short to be a real message
|
||||
// Extract the 4 headers
|
||||
_rxHeaderTo = _buf[0];
|
||||
_rxHeaderFrom = _buf[1];
|
||||
_rxHeaderId = _buf[2];
|
||||
_rxHeaderFlags = _buf[3];
|
||||
if (_promiscuous || _rxHeaderTo == _thisAddress || _rxHeaderTo == RH_BROADCAST_ADDRESS) {
|
||||
_rxGood++;
|
||||
_rxBufValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool RH_RF95::available()
|
||||
{
|
||||
if (_mode == RHModeTx)
|
||||
return false;
|
||||
setModeRx();
|
||||
return _rxBufValid; // Will be set by the interrupt handler when a good message is received
|
||||
}
|
||||
|
||||
void RH_RF95::clearRxBuf()
|
||||
{
|
||||
ATOMIC_BLOCK_START;
|
||||
_rxBufValid = false;
|
||||
_bufLen = 0;
|
||||
ATOMIC_BLOCK_END;
|
||||
}
|
||||
|
||||
/// Note: This routine might be called from inside the RF95 ISR
|
||||
bool RH_RF95::send(const uint8_t *data, uint8_t len)
|
||||
{
|
||||
if (len > RH_RF95_MAX_MESSAGE_LEN)
|
||||
return false;
|
||||
|
||||
setModeIdle();
|
||||
|
||||
// Position at the beginning of the FIFO
|
||||
spiWrite(RH_RF95_REG_0D_FIFO_ADDR_PTR, 0);
|
||||
// The headers
|
||||
spiWrite(RH_RF95_REG_00_FIFO, _txHeaderTo);
|
||||
spiWrite(RH_RF95_REG_00_FIFO, _txHeaderFrom);
|
||||
spiWrite(RH_RF95_REG_00_FIFO, _txHeaderId);
|
||||
spiWrite(RH_RF95_REG_00_FIFO, _txHeaderFlags);
|
||||
// The message data
|
||||
spiBurstWrite(RH_RF95_REG_00_FIFO, data, len);
|
||||
spiWrite(RH_RF95_REG_22_PAYLOAD_LENGTH, len + RH_RF95_HEADER_LEN);
|
||||
|
||||
setModeTx(); // Start the transmitter
|
||||
// when Tx is done, interruptHandler will fire and radio mode will return to STANDBY
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RH_RF95::printRegisters()
|
||||
{
|
||||
#ifdef RH_HAVE_SERIAL
|
||||
uint8_t registers[] = {0x01, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
||||
0x11, 0x12, 0x13, 0x014, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c,
|
||||
0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27};
|
||||
|
||||
uint8_t i;
|
||||
for (i = 0; i < sizeof(registers); i++) {
|
||||
Serial.print(registers[i], HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println(spiRead(registers[i]), HEX);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t RH_RF95::maxMessageLength()
|
||||
{
|
||||
return RH_RF95_MAX_MESSAGE_LEN;
|
||||
}
|
||||
|
||||
bool RH_RF95::setFrequency(float centre)
|
||||
{
|
||||
// Frf = FRF / FSTEP
|
||||
uint32_t frf = (centre * 1000000.0) / RH_RF95_FSTEP;
|
||||
spiWrite(RH_RF95_REG_06_FRF_MSB, (frf >> 16) & 0xff);
|
||||
spiWrite(RH_RF95_REG_07_FRF_MID, (frf >> 8) & 0xff);
|
||||
spiWrite(RH_RF95_REG_08_FRF_LSB, frf & 0xff);
|
||||
_usingHFport = (centre >= 779.0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RH_RF95::setModeIdle()
|
||||
{
|
||||
if (_mode != RHModeIdle) {
|
||||
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_STDBY);
|
||||
_mode = RHModeIdle;
|
||||
}
|
||||
}
|
||||
|
||||
bool RH_RF95::sleep()
|
||||
{
|
||||
if (_mode != RHModeSleep) {
|
||||
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_SLEEP);
|
||||
_mode = RHModeSleep;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RH_RF95::setModeRx()
|
||||
{
|
||||
if (_mode != RHModeRx) {
|
||||
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_RXCONTINUOUS);
|
||||
spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x00); // Interrupt on RxDone
|
||||
_mode = RHModeRx;
|
||||
}
|
||||
}
|
||||
|
||||
void RH_RF95::setModeTx()
|
||||
{
|
||||
if (_mode != RHModeTx) {
|
||||
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_TX);
|
||||
spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x40); // Interrupt on TxDone
|
||||
_mode = RHModeTx;
|
||||
}
|
||||
}
|
||||
|
||||
void RH_RF95::setTxPower(int8_t power, bool useRFO)
|
||||
{
|
||||
// Sigh, different behaviours depending on whther the module use PA_BOOST or the RFO pin
|
||||
// for the transmitter output
|
||||
if (useRFO) {
|
||||
if (power > 14)
|
||||
power = 14;
|
||||
if (power < -1)
|
||||
power = -1;
|
||||
spiWrite(RH_RF95_REG_09_PA_CONFIG, RH_RF95_MAX_POWER | (power + 1));
|
||||
} else {
|
||||
if (power > 23)
|
||||
power = 23;
|
||||
if (power < 5)
|
||||
power = 5;
|
||||
|
||||
// For RH_RF95_PA_DAC_ENABLE, manual says '+20dBm on PA_BOOST when OutputPower=0xf'
|
||||
// RH_RF95_PA_DAC_ENABLE actually adds about 3dBm to all power levels. We will us it
|
||||
// for 21, 22 and 23dBm
|
||||
if (power > 20) {
|
||||
spiWrite(RH_RF95_REG_4D_PA_DAC, RH_RF95_PA_DAC_ENABLE);
|
||||
power -= 3;
|
||||
} else {
|
||||
spiWrite(RH_RF95_REG_4D_PA_DAC, RH_RF95_PA_DAC_DISABLE);
|
||||
}
|
||||
|
||||
// RFM95/96/97/98 does not have RFO pins connected to anything. Only PA_BOOST
|
||||
// pin is connected, so must use PA_BOOST
|
||||
// Pout = 2 + OutputPower.
|
||||
// The documentation is pretty confusing on this topic: PaSelect says the max power is 20dBm,
|
||||
// but OutputPower claims it would be 17dBm.
|
||||
// My measurements show 20dBm is correct
|
||||
spiWrite(RH_RF95_REG_09_PA_CONFIG, RH_RF95_PA_SELECT | (power - 5));
|
||||
}
|
||||
}
|
||||
|
||||
// Sets registers from a canned modem configuration structure
|
||||
void RH_RF95::setModemRegisters(const ModemConfig *config)
|
||||
{
|
||||
spiWrite(RH_RF95_REG_1D_MODEM_CONFIG1, config->reg_1d);
|
||||
spiWrite(RH_RF95_REG_1E_MODEM_CONFIG2, config->reg_1e);
|
||||
spiWrite(RH_RF95_REG_26_MODEM_CONFIG3, config->reg_26);
|
||||
}
|
||||
|
||||
// Set one of the canned FSK Modem configs
|
||||
// Returns true if its a valid choice
|
||||
bool RH_RF95::setModemConfig(ModemConfigChoice index)
|
||||
{
|
||||
if (index > (signed int)(sizeof(MODEM_CONFIG_TABLE) / sizeof(ModemConfig)))
|
||||
return false;
|
||||
|
||||
ModemConfig cfg;
|
||||
memcpy_P(&cfg, &MODEM_CONFIG_TABLE[index], sizeof(RH_RF95::ModemConfig));
|
||||
setModemRegisters(&cfg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RH_RF95::setPreambleLength(uint16_t bytes)
|
||||
{
|
||||
spiWrite(RH_RF95_REG_20_PREAMBLE_MSB, bytes >> 8);
|
||||
spiWrite(RH_RF95_REG_21_PREAMBLE_LSB, bytes & 0xff);
|
||||
}
|
||||
|
||||
bool RH_RF95::isChannelActive()
|
||||
{
|
||||
// Set mode RHModeCad
|
||||
if (_mode != RHModeCad) {
|
||||
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_CAD);
|
||||
spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x80); // Interrupt on CadDone
|
||||
_mode = RHModeCad;
|
||||
}
|
||||
|
||||
while (_mode == RHModeCad)
|
||||
YIELD;
|
||||
|
||||
return _cad;
|
||||
}
|
||||
|
||||
void RH_RF95::enableTCXO()
|
||||
{
|
||||
while ((spiRead(RH_RF95_REG_4B_TCXO) & RH_RF95_TCXO_TCXO_INPUT_ON) != RH_RF95_TCXO_TCXO_INPUT_ON) {
|
||||
sleep();
|
||||
spiWrite(RH_RF95_REG_4B_TCXO, (spiRead(RH_RF95_REG_4B_TCXO) | RH_RF95_TCXO_TCXO_INPUT_ON));
|
||||
}
|
||||
}
|
||||
|
||||
// From section 4.1.5 of SX1276/77/78/79
|
||||
// Ferror = FreqError * 2**24 * BW / Fxtal / 500
|
||||
int RH_RF95::frequencyError()
|
||||
{
|
||||
int32_t freqerror = 0;
|
||||
|
||||
// Convert 2.5 bytes (5 nibbles, 20 bits) to 32 bit signed int
|
||||
// Caution: some C compilers make errors with eg:
|
||||
// freqerror = spiRead(RH_RF95_REG_28_FEI_MSB) << 16
|
||||
// so we go more carefully.
|
||||
freqerror = spiRead(RH_RF95_REG_28_FEI_MSB);
|
||||
freqerror <<= 8;
|
||||
freqerror |= spiRead(RH_RF95_REG_29_FEI_MID);
|
||||
freqerror <<= 8;
|
||||
freqerror |= spiRead(RH_RF95_REG_2A_FEI_LSB);
|
||||
// Sign extension into top 3 nibbles
|
||||
if (freqerror & 0x80000)
|
||||
freqerror |= 0xfff00000;
|
||||
|
||||
int error = 0; // In hertz
|
||||
float bw_tab[] = {7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250, 500};
|
||||
uint8_t bwindex = spiRead(RH_RF95_REG_1D_MODEM_CONFIG1) >> 4;
|
||||
if (bwindex < (sizeof(bw_tab) / sizeof(float)))
|
||||
error = (float)freqerror * bw_tab[bwindex] * ((float)(1L << 24) / (float)RH_RF95_FXOSC / 500.0);
|
||||
// else not defined
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int RH_RF95::lastSNR()
|
||||
{
|
||||
return _lastSNR;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
//
|
||||
// additions below by Brian Norman 9th Nov 2018
|
||||
// brian.n.norman@gmail.com
|
||||
//
|
||||
// Routines intended to make changing BW, SF and CR
|
||||
// a bit more intuitive
|
||||
//
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
void RH_RF95::setSpreadingFactor(uint8_t sf)
|
||||
{
|
||||
if (sf <= 6)
|
||||
sf = RH_RF95_SPREADING_FACTOR_64CPS;
|
||||
else if (sf == 7)
|
||||
sf = RH_RF95_SPREADING_FACTOR_128CPS;
|
||||
else if (sf == 8)
|
||||
sf = RH_RF95_SPREADING_FACTOR_256CPS;
|
||||
else if (sf == 9)
|
||||
sf = RH_RF95_SPREADING_FACTOR_512CPS;
|
||||
else if (sf == 10)
|
||||
sf = RH_RF95_SPREADING_FACTOR_1024CPS;
|
||||
else if (sf == 11)
|
||||
sf = RH_RF95_SPREADING_FACTOR_2048CPS;
|
||||
else if (sf >= 12)
|
||||
sf = RH_RF95_SPREADING_FACTOR_4096CPS;
|
||||
|
||||
// set the new spreading factor
|
||||
spiWrite(RH_RF95_REG_1E_MODEM_CONFIG2, (spiRead(RH_RF95_REG_1E_MODEM_CONFIG2) & ~RH_RF95_SPREADING_FACTOR) | sf);
|
||||
// check if Low data Rate bit should be set or cleared
|
||||
setLowDatarate();
|
||||
}
|
||||
|
||||
void RH_RF95::setSignalBandwidth(long sbw)
|
||||
{
|
||||
uint8_t bw; // register bit pattern
|
||||
|
||||
if (sbw <= 7800)
|
||||
bw = RH_RF95_BW_7_8KHZ;
|
||||
else if (sbw <= 10400)
|
||||
bw = RH_RF95_BW_10_4KHZ;
|
||||
else if (sbw <= 15600)
|
||||
bw = RH_RF95_BW_15_6KHZ;
|
||||
else if (sbw <= 20800)
|
||||
bw = RH_RF95_BW_20_8KHZ;
|
||||
else if (sbw <= 31250)
|
||||
bw = RH_RF95_BW_31_25KHZ;
|
||||
else if (sbw <= 41700)
|
||||
bw = RH_RF95_BW_41_7KHZ;
|
||||
else if (sbw <= 62500)
|
||||
bw = RH_RF95_BW_62_5KHZ;
|
||||
else if (sbw <= 125000)
|
||||
bw = RH_RF95_BW_125KHZ;
|
||||
else if (sbw <= 250000)
|
||||
bw = RH_RF95_BW_250KHZ;
|
||||
else
|
||||
bw = RH_RF95_BW_500KHZ;
|
||||
|
||||
// top 4 bits of reg 1D control bandwidth
|
||||
spiWrite(RH_RF95_REG_1D_MODEM_CONFIG1, (spiRead(RH_RF95_REG_1D_MODEM_CONFIG1) & ~RH_RF95_BW) | bw);
|
||||
// check if low data rate bit should be set or cleared
|
||||
setLowDatarate();
|
||||
}
|
||||
|
||||
void RH_RF95::setCodingRate4(uint8_t denominator)
|
||||
{
|
||||
int cr = RH_RF95_CODING_RATE_4_5;
|
||||
|
||||
// if (denominator <= 5)
|
||||
// cr = RH_RF95_CODING_RATE_4_5;
|
||||
if (denominator == 6)
|
||||
cr = RH_RF95_CODING_RATE_4_6;
|
||||
else if (denominator == 7)
|
||||
cr = RH_RF95_CODING_RATE_4_7;
|
||||
else if (denominator >= 8)
|
||||
cr = RH_RF95_CODING_RATE_4_8;
|
||||
|
||||
// CR is bits 3..1 of RH_RF95_REG_1D_MODEM_CONFIG1
|
||||
spiWrite(RH_RF95_REG_1D_MODEM_CONFIG1, (spiRead(RH_RF95_REG_1D_MODEM_CONFIG1) & ~RH_RF95_CODING_RATE) | cr);
|
||||
}
|
||||
|
||||
void RH_RF95::setLowDatarate()
|
||||
{
|
||||
// called after changing bandwidth and/or spreading factor
|
||||
// Semtech modem design guide AN1200.13 says
|
||||
// "To avoid issues surrounding drift of the crystal reference oscillator due to either temperature change
|
||||
// or motion,the low data rate optimization bit is used. Specifically for 125 kHz bandwidth and SF = 11 and 12,
|
||||
// this adds a small overhead to increase robustness to reference frequency variations over the timescale of the LoRa
|
||||
// packet."
|
||||
|
||||
// read current value for BW and SF
|
||||
uint8_t BW = spiRead(RH_RF95_REG_1D_MODEM_CONFIG1) >> 4; // bw is in bits 7..4
|
||||
uint8_t SF = spiRead(RH_RF95_REG_1E_MODEM_CONFIG2) >> 4; // sf is in bits 7..4
|
||||
|
||||
// calculate symbol time (see Semtech AN1200.22 section 4)
|
||||
float bw_tab[] = {7800, 10400, 15600, 20800, 31250, 41700, 62500, 125000, 250000, 500000};
|
||||
|
||||
float bandwidth = bw_tab[BW];
|
||||
|
||||
float symbolTime = 1000.0 * pow(2, SF) / bandwidth; // ms
|
||||
|
||||
// the symbolTime for SF 11 BW 125 is 16.384ms.
|
||||
// and, according to this :-
|
||||
// https://www.thethingsnetwork.org/forum/t/a-point-to-note-lora-low-data-rate-optimisation-flag/12007
|
||||
// the LDR bit should be set if the Symbol Time is > 16ms
|
||||
// So the threshold used here is 16.0ms
|
||||
|
||||
// the LDR is bit 3 of RH_RF95_REG_26_MODEM_CONFIG3
|
||||
uint8_t current = spiRead(RH_RF95_REG_26_MODEM_CONFIG3) & ~RH_RF95_LOW_DATA_RATE_OPTIMIZE; // mask off the LDR bit
|
||||
if (symbolTime > 16.0)
|
||||
spiWrite(RH_RF95_REG_26_MODEM_CONFIG3, current | RH_RF95_LOW_DATA_RATE_OPTIMIZE);
|
||||
else
|
||||
spiWrite(RH_RF95_REG_26_MODEM_CONFIG3, current);
|
||||
}
|
||||
|
||||
void RH_RF95::setPayloadCRC(bool on)
|
||||
{
|
||||
// Payload CRC is bit 2 of register 1E
|
||||
uint8_t current = spiRead(RH_RF95_REG_1E_MODEM_CONFIG2) & ~RH_RF95_PAYLOAD_CRC_ON; // mask off the CRC
|
||||
|
||||
if (on)
|
||||
spiWrite(RH_RF95_REG_1E_MODEM_CONFIG2, current | RH_RF95_PAYLOAD_CRC_ON);
|
||||
else
|
||||
spiWrite(RH_RF95_REG_1E_MODEM_CONFIG2, current);
|
||||
}
|
||||
890
src/rf95/RH_RF95.h
Normal file
890
src/rf95/RH_RF95.h
Normal file
@@ -0,0 +1,890 @@
|
||||
// RH_RF95.h
|
||||
//
|
||||
// Definitions for HopeRF LoRa radios per:
|
||||
// http://www.hoperf.com/upload/rf/RFM95_96_97_98W.pdf
|
||||
// http://www.hoperf.cn/upload/rfchip/RF96_97_98.pdf
|
||||
//
|
||||
// Author: Mike McCauley (mikem@airspayce.com)
|
||||
// Copyright (C) 2014 Mike McCauley
|
||||
// $Id: RH_RF95.h,v 1.23 2019/11/02 02:34:22 mikem Exp $
|
||||
//
|
||||
|
||||
#ifndef RH_RF95_h
|
||||
#define RH_RF95_h
|
||||
|
||||
#include <RHSPIDriver.h>
|
||||
|
||||
// This is the maximum number of interrupts the driver can support
|
||||
// Most Arduinos can handle 2, Megas can handle more
|
||||
#define RH_RF95_NUM_INTERRUPTS 3
|
||||
|
||||
// Max number of octets the LORA Rx/Tx FIFO can hold
|
||||
#define RH_RF95_FIFO_SIZE 255
|
||||
|
||||
// This is the maximum number of bytes that can be carried by the LORA.
|
||||
// We use some for headers, keeping fewer for RadioHead messages
|
||||
#define RH_RF95_MAX_PAYLOAD_LEN RH_RF95_FIFO_SIZE
|
||||
|
||||
// The length of the headers we add.
|
||||
// The headers are inside the LORA's payload
|
||||
#define RH_RF95_HEADER_LEN 4
|
||||
|
||||
// This is the maximum message length that can be supported by this driver.
|
||||
// Can be pre-defined to a smaller size (to save SRAM) prior to including this header
|
||||
// Here we allow for 1 byte message length, 4 bytes headers, user data and 2 bytes of FCS
|
||||
#ifndef RH_RF95_MAX_MESSAGE_LEN
|
||||
#define RH_RF95_MAX_MESSAGE_LEN (RH_RF95_MAX_PAYLOAD_LEN - RH_RF95_HEADER_LEN)
|
||||
#endif
|
||||
|
||||
// The crystal oscillator frequency of the module
|
||||
#define RH_RF95_FXOSC 32000000.0
|
||||
|
||||
// The Frequency Synthesizer step = RH_RF95_FXOSC / 2^^19
|
||||
#define RH_RF95_FSTEP (RH_RF95_FXOSC / 524288)
|
||||
|
||||
// Register names (LoRa Mode, from table 85)
|
||||
#define RH_RF95_REG_00_FIFO 0x00
|
||||
#define RH_RF95_REG_01_OP_MODE 0x01
|
||||
#define RH_RF95_REG_02_RESERVED 0x02
|
||||
#define RH_RF95_REG_03_RESERVED 0x03
|
||||
#define RH_RF95_REG_04_RESERVED 0x04
|
||||
#define RH_RF95_REG_05_RESERVED 0x05
|
||||
#define RH_RF95_REG_06_FRF_MSB 0x06
|
||||
#define RH_RF95_REG_07_FRF_MID 0x07
|
||||
#define RH_RF95_REG_08_FRF_LSB 0x08
|
||||
#define RH_RF95_REG_09_PA_CONFIG 0x09
|
||||
#define RH_RF95_REG_0A_PA_RAMP 0x0a
|
||||
#define RH_RF95_REG_0B_OCP 0x0b
|
||||
#define RH_RF95_REG_0C_LNA 0x0c
|
||||
#define RH_RF95_REG_0D_FIFO_ADDR_PTR 0x0d
|
||||
#define RH_RF95_REG_0E_FIFO_TX_BASE_ADDR 0x0e
|
||||
#define RH_RF95_REG_0F_FIFO_RX_BASE_ADDR 0x0f
|
||||
#define RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR 0x10
|
||||
#define RH_RF95_REG_11_IRQ_FLAGS_MASK 0x11
|
||||
#define RH_RF95_REG_12_IRQ_FLAGS 0x12
|
||||
#define RH_RF95_REG_13_RX_NB_BYTES 0x13
|
||||
#define RH_RF95_REG_14_RX_HEADER_CNT_VALUE_MSB 0x14
|
||||
#define RH_RF95_REG_15_RX_HEADER_CNT_VALUE_LSB 0x15
|
||||
#define RH_RF95_REG_16_RX_PACKET_CNT_VALUE_MSB 0x16
|
||||
#define RH_RF95_REG_17_RX_PACKET_CNT_VALUE_LSB 0x17
|
||||
#define RH_RF95_REG_18_MODEM_STAT 0x18
|
||||
#define RH_RF95_REG_19_PKT_SNR_VALUE 0x19
|
||||
#define RH_RF95_REG_1A_PKT_RSSI_VALUE 0x1a
|
||||
#define RH_RF95_REG_1B_RSSI_VALUE 0x1b
|
||||
#define RH_RF95_REG_1C_HOP_CHANNEL 0x1c
|
||||
#define RH_RF95_REG_1D_MODEM_CONFIG1 0x1d
|
||||
#define RH_RF95_REG_1E_MODEM_CONFIG2 0x1e
|
||||
#define RH_RF95_REG_1F_SYMB_TIMEOUT_LSB 0x1f
|
||||
#define RH_RF95_REG_20_PREAMBLE_MSB 0x20
|
||||
#define RH_RF95_REG_21_PREAMBLE_LSB 0x21
|
||||
#define RH_RF95_REG_22_PAYLOAD_LENGTH 0x22
|
||||
#define RH_RF95_REG_23_MAX_PAYLOAD_LENGTH 0x23
|
||||
#define RH_RF95_REG_24_HOP_PERIOD 0x24
|
||||
#define RH_RF95_REG_25_FIFO_RX_BYTE_ADDR 0x25
|
||||
#define RH_RF95_REG_26_MODEM_CONFIG3 0x26
|
||||
|
||||
#define RH_RF95_REG_27_PPM_CORRECTION 0x27
|
||||
#define RH_RF95_REG_28_FEI_MSB 0x28
|
||||
#define RH_RF95_REG_29_FEI_MID 0x29
|
||||
#define RH_RF95_REG_2A_FEI_LSB 0x2a
|
||||
#define RH_RF95_REG_2C_RSSI_WIDEBAND 0x2c
|
||||
#define RH_RF95_REG_31_DETECT_OPTIMIZE 0x31
|
||||
#define RH_RF95_REG_33_INVERT_IQ 0x33
|
||||
#define RH_RF95_REG_37_DETECTION_THRESHOLD 0x37
|
||||
#define RH_RF95_REG_39_SYNC_WORD 0x39
|
||||
|
||||
#define RH_RF95_REG_40_DIO_MAPPING1 0x40
|
||||
#define RH_RF95_REG_41_DIO_MAPPING2 0x41
|
||||
#define RH_RF95_REG_42_VERSION 0x42
|
||||
|
||||
#define RH_RF95_REG_4B_TCXO 0x4b
|
||||
#define RH_RF95_REG_4D_PA_DAC 0x4d
|
||||
#define RH_RF95_REG_5B_FORMER_TEMP 0x5b
|
||||
#define RH_RF95_REG_61_AGC_REF 0x61
|
||||
#define RH_RF95_REG_62_AGC_THRESH1 0x62
|
||||
#define RH_RF95_REG_63_AGC_THRESH2 0x63
|
||||
#define RH_RF95_REG_64_AGC_THRESH3 0x64
|
||||
|
||||
// RH_RF95_REG_01_OP_MODE 0x01
|
||||
#define RH_RF95_LONG_RANGE_MODE 0x80
|
||||
#define RH_RF95_ACCESS_SHARED_REG 0x40
|
||||
#define RH_RF95_LOW_FREQUENCY_MODE 0x08
|
||||
#define RH_RF95_MODE 0x07
|
||||
#define RH_RF95_MODE_SLEEP 0x00
|
||||
#define RH_RF95_MODE_STDBY 0x01
|
||||
#define RH_RF95_MODE_FSTX 0x02
|
||||
#define RH_RF95_MODE_TX 0x03
|
||||
#define RH_RF95_MODE_FSRX 0x04
|
||||
#define RH_RF95_MODE_RXCONTINUOUS 0x05
|
||||
#define RH_RF95_MODE_RXSINGLE 0x06
|
||||
#define RH_RF95_MODE_CAD 0x07
|
||||
|
||||
// RH_RF95_REG_09_PA_CONFIG 0x09
|
||||
#define RH_RF95_PA_SELECT 0x80
|
||||
#define RH_RF95_MAX_POWER 0x70
|
||||
#define RH_RF95_OUTPUT_POWER 0x0f
|
||||
|
||||
// RH_RF95_REG_0A_PA_RAMP 0x0a
|
||||
#define RH_RF95_LOW_PN_TX_PLL_OFF 0x10
|
||||
#define RH_RF95_PA_RAMP 0x0f
|
||||
#define RH_RF95_PA_RAMP_3_4MS 0x00
|
||||
#define RH_RF95_PA_RAMP_2MS 0x01
|
||||
#define RH_RF95_PA_RAMP_1MS 0x02
|
||||
#define RH_RF95_PA_RAMP_500US 0x03
|
||||
#define RH_RF95_PA_RAMP_250US 0x04
|
||||
#define RH_RF95_PA_RAMP_125US 0x05
|
||||
#define RH_RF95_PA_RAMP_100US 0x06
|
||||
#define RH_RF95_PA_RAMP_62US 0x07
|
||||
#define RH_RF95_PA_RAMP_50US 0x08
|
||||
#define RH_RF95_PA_RAMP_40US 0x09
|
||||
#define RH_RF95_PA_RAMP_31US 0x0a
|
||||
#define RH_RF95_PA_RAMP_25US 0x0b
|
||||
#define RH_RF95_PA_RAMP_20US 0x0c
|
||||
#define RH_RF95_PA_RAMP_15US 0x0d
|
||||
#define RH_RF95_PA_RAMP_12US 0x0e
|
||||
#define RH_RF95_PA_RAMP_10US 0x0f
|
||||
|
||||
// RH_RF95_REG_0B_OCP 0x0b
|
||||
#define RH_RF95_OCP_ON 0x20
|
||||
#define RH_RF95_OCP_TRIM 0x1f
|
||||
|
||||
// RH_RF95_REG_0C_LNA 0x0c
|
||||
#define RH_RF95_LNA_GAIN 0xe0
|
||||
#define RH_RF95_LNA_GAIN_G1 0x20
|
||||
#define RH_RF95_LNA_GAIN_G2 0x40
|
||||
#define RH_RF95_LNA_GAIN_G3 0x60
|
||||
#define RH_RF95_LNA_GAIN_G4 0x80
|
||||
#define RH_RF95_LNA_GAIN_G5 0xa0
|
||||
#define RH_RF95_LNA_GAIN_G6 0xc0
|
||||
#define RH_RF95_LNA_BOOST_LF 0x18
|
||||
#define RH_RF95_LNA_BOOST_LF_DEFAULT 0x00
|
||||
#define RH_RF95_LNA_BOOST_HF 0x03
|
||||
#define RH_RF95_LNA_BOOST_HF_DEFAULT 0x00
|
||||
#define RH_RF95_LNA_BOOST_HF_150PC 0x03
|
||||
|
||||
// RH_RF95_REG_11_IRQ_FLAGS_MASK 0x11
|
||||
#define RH_RF95_RX_TIMEOUT_MASK 0x80
|
||||
#define RH_RF95_RX_DONE_MASK 0x40
|
||||
#define RH_RF95_PAYLOAD_CRC_ERROR_MASK 0x20
|
||||
#define RH_RF95_VALID_HEADER_MASK 0x10
|
||||
#define RH_RF95_TX_DONE_MASK 0x08
|
||||
#define RH_RF95_CAD_DONE_MASK 0x04
|
||||
#define RH_RF95_FHSS_CHANGE_CHANNEL_MASK 0x02
|
||||
#define RH_RF95_CAD_DETECTED_MASK 0x01
|
||||
|
||||
// RH_RF95_REG_12_IRQ_FLAGS 0x12
|
||||
#define RH_RF95_RX_TIMEOUT 0x80
|
||||
#define RH_RF95_RX_DONE 0x40
|
||||
#define RH_RF95_PAYLOAD_CRC_ERROR 0x20
|
||||
#define RH_RF95_VALID_HEADER 0x10
|
||||
#define RH_RF95_TX_DONE 0x08
|
||||
#define RH_RF95_CAD_DONE 0x04
|
||||
#define RH_RF95_FHSS_CHANGE_CHANNEL 0x02
|
||||
#define RH_RF95_CAD_DETECTED 0x01
|
||||
|
||||
// RH_RF95_REG_18_MODEM_STAT 0x18
|
||||
#define RH_RF95_RX_CODING_RATE 0xe0
|
||||
#define RH_RF95_MODEM_STATUS_CLEAR 0x10
|
||||
#define RH_RF95_MODEM_STATUS_HEADER_INFO_VALID 0x08
|
||||
#define RH_RF95_MODEM_STATUS_RX_ONGOING 0x04
|
||||
#define RH_RF95_MODEM_STATUS_SIGNAL_SYNCHRONIZED 0x02
|
||||
#define RH_RF95_MODEM_STATUS_SIGNAL_DETECTED 0x01
|
||||
|
||||
// RH_RF95_REG_1C_HOP_CHANNEL 0x1c
|
||||
#define RH_RF95_PLL_TIMEOUT 0x80
|
||||
#define RH_RF95_RX_PAYLOAD_CRC_IS_ON 0x40
|
||||
#define RH_RF95_FHSS_PRESENT_CHANNEL 0x3f
|
||||
|
||||
// RH_RF95_REG_1D_MODEM_CONFIG1 0x1d
|
||||
#define RH_RF95_BW 0xf0
|
||||
|
||||
#define RH_RF95_BW_7_8KHZ 0x00
|
||||
#define RH_RF95_BW_10_4KHZ 0x10
|
||||
#define RH_RF95_BW_15_6KHZ 0x20
|
||||
#define RH_RF95_BW_20_8KHZ 0x30
|
||||
#define RH_RF95_BW_31_25KHZ 0x40
|
||||
#define RH_RF95_BW_41_7KHZ 0x50
|
||||
#define RH_RF95_BW_62_5KHZ 0x60
|
||||
#define RH_RF95_BW_125KHZ 0x70
|
||||
#define RH_RF95_BW_250KHZ 0x80
|
||||
#define RH_RF95_BW_500KHZ 0x90
|
||||
#define RH_RF95_CODING_RATE 0x0e
|
||||
#define RH_RF95_CODING_RATE_4_5 0x02
|
||||
#define RH_RF95_CODING_RATE_4_6 0x04
|
||||
#define RH_RF95_CODING_RATE_4_7 0x06
|
||||
#define RH_RF95_CODING_RATE_4_8 0x08
|
||||
#define RH_RF95_IMPLICIT_HEADER_MODE_ON 0x01
|
||||
|
||||
// RH_RF95_REG_1E_MODEM_CONFIG2 0x1e
|
||||
#define RH_RF95_SPREADING_FACTOR 0xf0
|
||||
#define RH_RF95_SPREADING_FACTOR_64CPS 0x60
|
||||
#define RH_RF95_SPREADING_FACTOR_128CPS 0x70
|
||||
#define RH_RF95_SPREADING_FACTOR_256CPS 0x80
|
||||
#define RH_RF95_SPREADING_FACTOR_512CPS 0x90
|
||||
#define RH_RF95_SPREADING_FACTOR_1024CPS 0xa0
|
||||
#define RH_RF95_SPREADING_FACTOR_2048CPS 0xb0
|
||||
#define RH_RF95_SPREADING_FACTOR_4096CPS 0xc0
|
||||
#define RH_RF95_TX_CONTINUOUS_MODE 0x08
|
||||
|
||||
#define RH_RF95_PAYLOAD_CRC_ON 0x04
|
||||
#define RH_RF95_SYM_TIMEOUT_MSB 0x03
|
||||
|
||||
// RH_RF95_REG_26_MODEM_CONFIG3
|
||||
#define RH_RF95_MOBILE_NODE 0x08 // HopeRF term
|
||||
#define RH_RF95_LOW_DATA_RATE_OPTIMIZE 0x08 // Semtechs term
|
||||
#define RH_RF95_AGC_AUTO_ON 0x04
|
||||
|
||||
// RH_RF95_REG_4B_TCXO 0x4b
|
||||
#define RH_RF95_TCXO_TCXO_INPUT_ON 0x10
|
||||
|
||||
// RH_RF95_REG_4D_PA_DAC 0x4d
|
||||
#define RH_RF95_PA_DAC_DISABLE 0x04
|
||||
#define RH_RF95_PA_DAC_ENABLE 0x07
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
/// \class RH_RF95 RH_RF95.h <RH_RF95.h>
|
||||
/// \brief Driver to send and receive unaddressed, unreliable datagrams via a LoRa
|
||||
/// capable radio transceiver.
|
||||
///
|
||||
/// For Semtech SX1276/77/78/79 and HopeRF RF95/96/97/98 and other similar LoRa capable radios.
|
||||
/// Based on http://www.hoperf.com/upload/rf/RFM95_96_97_98W.pdf
|
||||
/// and http://www.hoperf.cn/upload/rfchip/RF96_97_98.pdf
|
||||
/// and http://www.semtech.com/images/datasheet/LoraDesignGuide_STD.pdf
|
||||
/// and http://www.semtech.com/images/datasheet/sx1276.pdf
|
||||
/// and http://www.semtech.com/images/datasheet/sx1276_77_78_79.pdf
|
||||
/// FSK/GFSK/OOK modes are not (yet) supported.
|
||||
///
|
||||
/// Works with
|
||||
/// - the excellent MiniWirelessLoRa from Anarduino http://www.anarduino.com/miniwireless
|
||||
/// - The excellent Modtronix inAir4 http://modtronix.com/inair4.html
|
||||
/// and inAir9 modules http://modtronix.com/inair9.html.
|
||||
/// - the excellent Rocket Scream Mini Ultra Pro with the RFM95W
|
||||
/// http://www.rocketscream.com/blog/product/mini-ultra-pro-with-radio/
|
||||
/// - Lora1276 module from NiceRF http://www.nicerf.com/product_view.aspx?id=99
|
||||
/// - Adafruit Feather M0 with RFM95
|
||||
/// - The very fine Talk2 Whisper Node LoRa boards https://wisen.com.au/store/products/whisper-node-lora
|
||||
/// an Arduino compatible board, which include an on-board RFM95/96 LoRa Radio (Semtech SX1276), external antenna,
|
||||
/// run on 2xAAA batteries and support low power operations. RF95 examples work without modification.
|
||||
/// Use Arduino Board Manager to install the Talk2 code support. Upload the code with an FTDI adapter set to 5V.
|
||||
/// - heltec / TTGO ESP32 LoRa OLED
|
||||
/// https://www.aliexpress.com/item/Internet-Development-Board-SX1278-ESP32-WIFI-chip-0-96-inch-OLED-Bluetooth-WIFI-Lora-Kit-32/32824535649.html
|
||||
///
|
||||
/// \par Overview
|
||||
///
|
||||
/// This class provides basic functions for sending and receiving unaddressed,
|
||||
/// unreliable datagrams of arbitrary length to 251 octets per packet.
|
||||
///
|
||||
/// Manager classes may use this class to implement reliable, addressed datagrams and streams,
|
||||
/// mesh routers, repeaters, translators etc.
|
||||
///
|
||||
/// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and
|
||||
/// modulation scheme.
|
||||
///
|
||||
/// This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF
|
||||
/// RFM95/96/97/98(W), Semtech SX1276/77/78/79 and compatible radio modules in LoRa mode.
|
||||
///
|
||||
/// The Hope-RF (http://www.hoperf.com) RFM95/96/97/98(W) and Semtech SX1276/77/78/79 is a low-cost ISM transceiver
|
||||
/// chip. It supports FSK, GFSK, OOK over a wide range of frequencies and
|
||||
/// programmable data rates, and it also supports the proprietary LoRA (Long Range) mode, which
|
||||
/// is the only mode supported in this RadioHead driver.
|
||||
///
|
||||
/// This Driver provides functions for sending and receiving messages of up
|
||||
/// to 251 octets on any frequency supported by the radio, in a range of
|
||||
/// predefined Bandwidths, Spreading Factors and Coding Rates. Frequency can be set with
|
||||
/// 61Hz precision to any frequency from 240.0MHz to 960.0MHz. Caution: most modules only support a more limited
|
||||
/// range of frequencies due to antenna tuning.
|
||||
///
|
||||
/// Up to 2 modules can be connected to an Arduino (3 on a Mega),
|
||||
/// permitting the construction of translators and frequency changers, etc.
|
||||
///
|
||||
/// Support for other features such as transmitter power control etc is
|
||||
/// also provided.
|
||||
///
|
||||
/// Tested on MinWirelessLoRa with arduino-1.0.5
|
||||
/// on OpenSuSE 13.1.
|
||||
/// Also tested with Teensy3.1, Modtronix inAir4 and Arduino 1.6.5 on OpenSuSE 13.1
|
||||
///
|
||||
/// \par Packet Format
|
||||
///
|
||||
/// All messages sent and received by this RH_RF95 Driver conform to this packet format:
|
||||
///
|
||||
/// - LoRa mode:
|
||||
/// - 8 symbol PREAMBLE
|
||||
/// - Explicit header with header CRC (handled internally by the radio)
|
||||
/// - 4 octets HEADER: (TO, FROM, ID, FLAGS)
|
||||
/// - 0 to 251 octets DATA
|
||||
/// - CRC (handled internally by the radio)
|
||||
///
|
||||
/// \par Connecting RFM95/96/97/98 and Semtech SX1276/77/78/79 to Arduino
|
||||
///
|
||||
/// We tested with Anarduino MiniWirelessLoRA, which is an Arduino Duemilanove compatible with a RFM96W
|
||||
/// module on-board. Therefore it needs no connections other than the USB
|
||||
/// programming connection and an antenna to make it work.
|
||||
///
|
||||
/// If you have a bare RFM95/96/97/98 that you want to connect to an Arduino, you
|
||||
/// might use these connections (untested): CAUTION: you must use a 3.3V type
|
||||
/// Arduino, otherwise you will also need voltage level shifters between the
|
||||
/// Arduino and the RFM95. CAUTION, you must also ensure you connect an
|
||||
/// antenna.
|
||||
///
|
||||
/// \code
|
||||
/// Arduino RFM95/96/97/98
|
||||
/// GND----------GND (ground in)
|
||||
/// 3V3----------3.3V (3.3V in)
|
||||
/// interrupt 0 pin D2-----------DIO0 (interrupt request out)
|
||||
/// SS pin D10----------NSS (CS chip select in)
|
||||
/// SCK pin D13----------SCK (SPI clock in)
|
||||
/// MOSI pin D11----------MOSI (SPI Data in)
|
||||
/// MISO pin D12----------MISO (SPI Data out)
|
||||
/// \endcode
|
||||
/// With these connections, you can then use the default constructor RH_RF95().
|
||||
/// You can override the default settings for the SS pin and the interrupt in
|
||||
/// the RH_RF95 constructor if you wish to connect the slave select SS to other
|
||||
/// than the normal one for your Arduino (D10 for Diecimila, Uno etc and D53
|
||||
/// for Mega) or the interrupt request to other than pin D2 (Caution,
|
||||
/// different processors have different constraints as to the pins available
|
||||
/// for interrupts).
|
||||
///
|
||||
/// You can connect a Modtronix inAir4 or inAir9 directly to a 3.3V part such as a Teensy 3.1 like
|
||||
/// this (tested).
|
||||
/// \code
|
||||
/// Teensy inAir4 inAir9
|
||||
/// GND----------0V (ground in)
|
||||
/// 3V3----------3.3V (3.3V in)
|
||||
/// interrupt 0 pin D2-----------D0 (interrupt request out)
|
||||
/// SS pin D10----------CS (CS chip select in)
|
||||
/// SCK pin D13----------CK (SPI clock in)
|
||||
/// MOSI pin D11----------SI (SPI Data in)
|
||||
/// MISO pin D12----------SO (SPI Data out)
|
||||
/// \endcode
|
||||
/// With these connections, you can then use the default constructor RH_RF95().
|
||||
/// you must also set the transmitter power with useRFO:
|
||||
/// driver.setTxPower(13, true);
|
||||
///
|
||||
/// Note that if you are using Modtronix inAir4 or inAir9,or any other module which uses the
|
||||
/// transmitter RFO pins and not the PA_BOOST pins
|
||||
/// that you must configure the power transmitter power for -1 to 14 dBm and with useRFO true.
|
||||
/// Failure to do that will result in extremely low transmit powers.
|
||||
///
|
||||
/// If you have an Arduino M0 Pro from arduino.org,
|
||||
/// you should note that you cannot use Pin 2 for the interrupt line
|
||||
/// (Pin 2 is for the NMI only). The same comments apply to Pin 4 on Arduino Zero from arduino.cc.
|
||||
/// Instead you can use any other pin (we use Pin 3) and initialise RH_RF69 like this:
|
||||
/// \code
|
||||
/// // Slave Select is pin 10, interrupt is Pin 3
|
||||
/// RH_RF95 driver(10, 3);
|
||||
/// \endcode
|
||||
///
|
||||
/// If you have a Rocket Scream Mini Ultra Pro with the RFM95W:
|
||||
/// - Ensure you have Arduino SAMD board support 1.6.5 or later in Arduino IDE 1.6.8 or later.
|
||||
/// - The radio SS is hardwired to pin D5 and the DIO0 interrupt to pin D2,
|
||||
/// so you need to initialise the radio like this:
|
||||
/// \code
|
||||
/// RH_RF95 driver(5, 2);
|
||||
/// \endcode
|
||||
/// - The name of the serial port on that board is 'SerialUSB', not 'Serial', so this may be helpful at the top of our
|
||||
/// sample sketches:
|
||||
/// \code
|
||||
/// #define Serial SerialUSB
|
||||
/// \endcode
|
||||
/// - You also need this in setup before radio initialisation
|
||||
/// \code
|
||||
/// // Ensure serial flash is not interfering with radio communication on SPI bus
|
||||
/// pinMode(4, OUTPUT);
|
||||
/// digitalWrite(4, HIGH);
|
||||
/// \endcode
|
||||
/// - and if you have a 915MHz part, you need this after driver/manager intitalisation:
|
||||
/// \code
|
||||
/// rf95.setFrequency(915.0);
|
||||
/// \endcode
|
||||
/// which adds up to modifying sample sketches something like:
|
||||
/// \code
|
||||
/// #include <SPI.h>
|
||||
/// #include <RH_RF95.h>
|
||||
/// RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
|
||||
/// #define Serial SerialUSB
|
||||
///
|
||||
/// void setup()
|
||||
/// {
|
||||
/// // Ensure serial flash is not interfering with radio communication on SPI bus
|
||||
/// pinMode(4, OUTPUT);
|
||||
/// digitalWrite(4, HIGH);
|
||||
///
|
||||
/// Serial.begin(9600);
|
||||
/// while (!Serial) ; // Wait for serial port to be available
|
||||
/// if (!rf95.init())
|
||||
/// Serial.println("init failed");
|
||||
/// rf95.setFrequency(915.0);
|
||||
/// }
|
||||
/// ...
|
||||
/// \endcode
|
||||
///
|
||||
/// For Adafruit Feather M0 with RFM95, construct the driver like this:
|
||||
/// \code
|
||||
/// RH_RF95 rf95(8, 3);
|
||||
/// \endcode
|
||||
///
|
||||
/// If you have a talk2 Whisper Node LoRa board with on-board RF95 radio,
|
||||
/// the example rf95_* sketches work without modification. Initialise the radio like
|
||||
/// with the default constructor:
|
||||
/// \code
|
||||
/// RH_RF95 driver;
|
||||
/// \endcode
|
||||
///
|
||||
/// It is possible to have 2 or more radios connected to one Arduino, provided
|
||||
/// each radio has its own SS and interrupt line (SCK, SDI and SDO are common
|
||||
/// to all radios)
|
||||
///
|
||||
/// Caution: on some Arduinos such as the Mega 2560, if you set the slave
|
||||
/// select pin to be other than the usual SS pin (D53 on Mega 2560), you may
|
||||
/// need to set the usual SS pin to be an output to force the Arduino into SPI
|
||||
/// master mode.
|
||||
///
|
||||
/// Caution: Power supply requirements of the RFM module may be relevant in some circumstances:
|
||||
/// RFM95/96/97/98 modules are capable of pulling 120mA+ at full power, where Arduino's 3.3V line can
|
||||
/// give 50mA. You may need to make provision for alternate power supply for
|
||||
/// the RFM module, especially if you wish to use full transmit power, and/or you have
|
||||
/// other shields demanding power. Inadequate power for the RFM is likely to cause symptoms such as:
|
||||
/// - reset's/bootups terminate with "init failed" messages
|
||||
/// - random termination of communication after 5-30 packets sent/received
|
||||
/// - "fake ok" state, where initialization passes fluently, but communication doesn't happen
|
||||
/// - shields hang Arduino boards, especially during the flashing
|
||||
///
|
||||
/// \par Interrupts
|
||||
///
|
||||
/// The RH_RF95 driver uses interrupts to react to events in the RFM module,
|
||||
/// such as the reception of a new packet, or the completion of transmission
|
||||
/// of a packet. The RH_RF95 driver interrupt service routine reads status from
|
||||
/// and writes data to the the RFM module via the SPI interface. It is very
|
||||
/// important therefore, that if you are using the RH_RF95 driver with another
|
||||
/// SPI based deviced, that you disable interrupts while you transfer data to
|
||||
/// and from that other device. Use cli() to disable interrupts and sei() to
|
||||
/// reenable them.
|
||||
///
|
||||
/// \par Memory
|
||||
///
|
||||
/// The RH_RF95 driver requires non-trivial amounts of memory. The sample
|
||||
/// programs all compile to about 8kbytes each, which will fit in the
|
||||
/// flash proram memory of most Arduinos. However, the RAM requirements are
|
||||
/// more critical. Therefore, you should be vary sparing with RAM use in
|
||||
/// programs that use the RH_RF95 driver.
|
||||
///
|
||||
/// It is often hard to accurately identify when you are hitting RAM limits on Arduino.
|
||||
/// The symptoms can include:
|
||||
/// - Mysterious crashes and restarts
|
||||
/// - Changes in behaviour when seemingly unrelated changes are made (such as adding print() statements)
|
||||
/// - Hanging
|
||||
/// - Output from Serial.print() not appearing
|
||||
///
|
||||
/// \par Range
|
||||
///
|
||||
/// We have made some simple range tests under the following conditions:
|
||||
/// - rf95_client base station connected to a VHF discone antenna at 8m height above ground
|
||||
/// - rf95_server mobile connected to 17.3cm 1/4 wavelength antenna at 1m height, no ground plane.
|
||||
/// - Both configured for 13dBm, 434MHz, Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range
|
||||
/// - Minimum reported RSSI seen for successful comms was about -91
|
||||
/// - Range over flat ground through heavy trees and vegetation approx 2km.
|
||||
/// - At 20dBm (100mW) otherwise identical conditions approx 3km.
|
||||
/// - At 20dBm, along salt water flat sandy beach, 3.2km.
|
||||
///
|
||||
/// It should be noted that at this data rate, a 12 octet message takes 2 seconds to transmit.
|
||||
///
|
||||
/// At 20dBm (100mW) with Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on.
|
||||
/// (Default medium range) in the conditions described above.
|
||||
/// - Range over flat ground through heavy trees and vegetation approx 2km.
|
||||
///
|
||||
/// Caution: the performance of this radio, especially with narrow bandwidths is strongly dependent on the
|
||||
/// accuracy and stability of the chip clock. HopeRF and Semtech do not appear to
|
||||
/// recommend bandwidths of less than 62.5 kHz
|
||||
/// unless you have the optional Temperature Compensated Crystal Oscillator (TCXO) installed and
|
||||
/// enabled on your radio module. See the refernece manual for more data.
|
||||
/// Also https://lowpowerlab.com/forum/rf-range-antennas-rfm69-library/lora-library-experiences-range/15/
|
||||
/// and http://www.semtech.com/images/datasheet/an120014-xo-guidance-lora-modulation.pdf
|
||||
///
|
||||
/// \par Transmitter Power
|
||||
///
|
||||
/// You can control the transmitter power on the RF transceiver
|
||||
/// with the RH_RF95::setTxPower() function. The argument can be any of
|
||||
/// +5 to +23 (for modules that use PA_BOOST)
|
||||
/// -1 to +14 (for modules that use RFO transmitter pin)
|
||||
/// The default is 13. Eg:
|
||||
/// \code
|
||||
/// driver.setTxPower(10); // use PA_BOOST transmitter pin
|
||||
/// driver.setTxPower(10, true); // use PA_RFO pin transmitter pin
|
||||
/// \endcode
|
||||
///
|
||||
/// We have made some actual power measurements against
|
||||
/// programmed power for Anarduino MiniWirelessLoRa (which has RFM96W-433Mhz installed)
|
||||
/// - MiniWirelessLoRa RFM96W-433Mhz, USB power
|
||||
/// - 30cm RG316 soldered direct to RFM96W module ANT and GND
|
||||
/// - SMA connector
|
||||
/// - 12db attenuator
|
||||
/// - SMA connector
|
||||
/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)
|
||||
/// - Tektronix TDS220 scope to measure the Vout from power head
|
||||
/// \code
|
||||
/// Program power Measured Power
|
||||
/// dBm dBm
|
||||
/// 5 5
|
||||
/// 7 7
|
||||
/// 9 8
|
||||
/// 11 11
|
||||
/// 13 13
|
||||
/// 15 15
|
||||
/// 17 16
|
||||
/// 19 18
|
||||
/// 20 20
|
||||
/// 21 21
|
||||
/// 22 22
|
||||
/// 23 23
|
||||
/// \endcode
|
||||
///
|
||||
/// We have also measured the actual power output from a Modtronix inAir4 http://modtronix.com/inair4.html
|
||||
/// connected to a Teensy 3.1:
|
||||
/// Teensy 3.1 this is a 3.3V part, connected directly to:
|
||||
/// Modtronix inAir4 with SMA antenna connector, connected as above:
|
||||
/// 10cm SMA-SMA cable
|
||||
/// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)
|
||||
/// - Tektronix TDS220 scope to measure the Vout from power head
|
||||
/// \code
|
||||
/// Program power Measured Power
|
||||
/// dBm dBm
|
||||
/// -1 0
|
||||
/// 1 2
|
||||
/// 3 4
|
||||
/// 5 7
|
||||
/// 7 10
|
||||
/// 9 13
|
||||
/// 11 14.2
|
||||
/// 13 15
|
||||
/// 14 16
|
||||
/// \endcode
|
||||
/// (Caution: we dont claim laboratory accuracy for these power measurements)
|
||||
/// You would not expect to get anywhere near these powers to air with a simple 1/4 wavelength wire antenna.
|
||||
class RH_RF95 : public RHSPIDriver
|
||||
{
|
||||
public:
|
||||
/// \brief Defines register values for a set of modem configuration registers
|
||||
///
|
||||
/// Defines register values for a set of modem configuration registers
|
||||
/// that can be passed to setModemRegisters() if none of the choices in
|
||||
/// ModemConfigChoice suit your need setModemRegisters() writes the
|
||||
/// register values from this structure to the appropriate registers
|
||||
/// to set the desired spreading factor, coding rate and bandwidth
|
||||
typedef struct {
|
||||
uint8_t reg_1d; ///< Value for register RH_RF95_REG_1D_MODEM_CONFIG1
|
||||
uint8_t reg_1e; ///< Value for register RH_RF95_REG_1E_MODEM_CONFIG2
|
||||
uint8_t reg_26; ///< Value for register RH_RF95_REG_26_MODEM_CONFIG3
|
||||
} ModemConfig;
|
||||
|
||||
/// Choices for setModemConfig() for a selected subset of common
|
||||
/// data rates. If you need another configuration,
|
||||
/// determine the necessary settings and call setModemRegisters() with your
|
||||
/// desired settings. It might be helpful to use the LoRa calculator mentioned in
|
||||
/// http://www.semtech.com/images/datasheet/LoraDesignGuide_STD.pdf
|
||||
/// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic
|
||||
/// definitions and not their integer equivalents: its possible that new values will be
|
||||
/// introduced in later versions (though we will try to avoid it).
|
||||
/// Caution: if you are using slow packet rates and long packets with RHReliableDatagram or subclasses
|
||||
/// you may need to change the RHReliableDatagram timeout for reliable operations.
|
||||
/// Caution: for some slow rates nad with ReliableDatagrams youi may need to increase the reply timeout
|
||||
/// with manager.setTimeout() to
|
||||
/// deal with the long transmission times.
|
||||
typedef enum {
|
||||
Bw125Cr45Sf128 = 0, ///< Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range
|
||||
Bw500Cr45Sf128, ///< Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range
|
||||
Bw31_25Cr48Sf512, ///< Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range
|
||||
Bw125Cr48Sf4096, ///< Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. Slow+long range
|
||||
} ModemConfigChoice;
|
||||
|
||||
/// Constructor. You can have multiple instances, but each instance must have its own
|
||||
/// interrupt and slave select pin. After constructing, you must call init() to initialise the interface
|
||||
/// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient
|
||||
/// distinct interrupt lines, one for each instance.
|
||||
/// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RH_RF22 before
|
||||
/// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)
|
||||
/// \param[in] interruptPin The interrupt Pin number that is connected to the RFM DIO0 interrupt line.
|
||||
/// Defaults to pin 2, as required by Anarduino MinWirelessLoRa module.
|
||||
/// Caution: You must specify an interrupt capable pin.
|
||||
/// On many Arduino boards, there are limitations as to which pins may be used as interrupts.
|
||||
/// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin.
|
||||
/// On Arduino Zero from arduino.cc, any digital pin other than 4.
|
||||
/// On Arduino M0 Pro from arduino.org, any digital pin other than 2.
|
||||
/// On other Arduinos pins 2 or 3.
|
||||
/// See http://arduino.cc/en/Reference/attachInterrupt for more details.
|
||||
/// On Chipkit Uno32, pins 38, 2, 7, 8, 35.
|
||||
/// On other boards, any digital pin may be used.
|
||||
/// \param[in] spi Pointer to the SPI interface object to use.
|
||||
/// Defaults to the standard Arduino hardware SPI interface
|
||||
RH_RF95(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, RHGenericSPI &spi = hardware_spi);
|
||||
|
||||
/// Initialise the Driver transport hardware and software.
|
||||
/// Make sure the Driver is properly configured before calling init().
|
||||
/// \return true if initialisation succeeded.
|
||||
virtual bool init();
|
||||
|
||||
/// The main CPU is about to enter deep sleep, prepare the RF95 so it will be able to wake properly after we reboot
|
||||
/// i.e. confirm we are in idle or rx mode, set a rtcram flag with state we need to restore after boot. Later in boot
|
||||
/// we'll need to be careful not to wipe registers and be ready to handle any pending interrupts that occurred while
|
||||
/// the main CPU was powered down.
|
||||
void prepareDeepSleep();
|
||||
|
||||
/// Prints the value of all chip registers
|
||||
/// to the Serial device if RH_HAVE_SERIAL is defined for the current platform
|
||||
/// For debugging purposes only.
|
||||
/// \return true on success
|
||||
bool printRegisters();
|
||||
|
||||
/// Sets all the registered required to configure the data modem in the RF95/96/97/98, including the bandwidth,
|
||||
/// spreading factor etc. You can use this to configure the modem with custom configurations if none of the
|
||||
/// canned configurations in ModemConfigChoice suit you.
|
||||
/// \param[in] config A ModemConfig structure containing values for the modem configuration registers.
|
||||
void setModemRegisters(const ModemConfig *config);
|
||||
|
||||
/// Select one of the predefined modem configurations. If you need a modem configuration not provided
|
||||
/// here, use setModemRegisters() with your own ModemConfig.
|
||||
/// Caution: the slowest protocols may require a radio module with TCXO temperature controlled oscillator
|
||||
/// for reliable operation.
|
||||
/// \param[in] index The configuration choice.
|
||||
/// \return true if index is a valid choice.
|
||||
bool setModemConfig(ModemConfigChoice index);
|
||||
|
||||
/// Tests whether a new message is available
|
||||
/// from the Driver.
|
||||
/// On most drivers, this will also put the Driver into RHModeRx mode until
|
||||
/// a message is actually received by the transport, when it wil be returned to RHModeIdle.
|
||||
/// This can be called multiple times in a timeout loop
|
||||
/// \return true if a new, complete, error-free uncollected message is available to be retreived by recv()
|
||||
virtual bool available();
|
||||
|
||||
/// Sets the length of the preamble
|
||||
/// in bytes.
|
||||
/// Caution: this should be set to the same
|
||||
/// value on all nodes in your network. Default is 8.
|
||||
/// Sets the message preamble length in RH_RF95_REG_??_PREAMBLE_?SB
|
||||
/// \param[in] bytes Preamble length in bytes.
|
||||
void setPreambleLength(uint16_t bytes);
|
||||
|
||||
/// Returns the maximum message length
|
||||
/// available in this Driver.
|
||||
/// \return The maximum legal message length
|
||||
virtual uint8_t maxMessageLength();
|
||||
|
||||
/// Sets the transmitter and receiver
|
||||
/// centre frequency.
|
||||
/// \param[in] centre Frequency in MHz. 137.0 to 1020.0. Caution: RFM95/96/97/98 comes in several
|
||||
/// different frequency ranges, and setting a frequency outside that range of your radio will probably not work
|
||||
/// \return true if the selected frquency centre is within range
|
||||
bool setFrequency(float centre);
|
||||
|
||||
/// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running,
|
||||
/// disables them.
|
||||
void setModeIdle();
|
||||
|
||||
/// If current mode is Tx or Idle, changes it to Rx.
|
||||
/// Starts the receiver in the RF95/96/97/98.
|
||||
void setModeRx();
|
||||
|
||||
/// If current mode is Rx or Idle, changes it to Rx. F
|
||||
/// Starts the transmitter in the RF95/96/97/98.
|
||||
void setModeTx();
|
||||
|
||||
/// Sets the transmitter power output level, and configures the transmitter pin.
|
||||
/// Be a good neighbour and set the lowest power level you need.
|
||||
/// Some SX1276/77/78/79 and compatible modules (such as RFM95/96/97/98)
|
||||
/// use the PA_BOOST transmitter pin for high power output (and optionally the PA_DAC)
|
||||
/// while some (such as the Modtronix inAir4 and inAir9)
|
||||
/// use the RFO transmitter pin for lower power but higher efficiency.
|
||||
/// You must set the appropriate power level and useRFO argument for your module.
|
||||
/// Check with your module manufacturer which transmtter pin is used on your module
|
||||
/// to ensure you are setting useRFO correctly.
|
||||
/// Failure to do so will result in very low
|
||||
/// transmitter power output.
|
||||
/// Caution: legal power limits may apply in certain countries.
|
||||
/// After init(), the power will be set to 13dBm, with useRFO false (ie PA_BOOST enabled).
|
||||
/// \param[in] power Transmitter power level in dBm. For RFM95/96/97/98 LORA with useRFO false,
|
||||
/// valid values are from +5 to +23.
|
||||
/// For Modtronix inAir4 and inAir9 with useRFO true (ie RFO pins in use),
|
||||
/// valid values are from -1 to 14.
|
||||
/// \param[in] useRFO If true, enables the use of the RFO transmitter pins instead of
|
||||
/// the PA_BOOST pin (false). Choose the correct setting for your module.
|
||||
void setTxPower(int8_t power, bool useRFO = false);
|
||||
|
||||
/// Sets the radio into low-power sleep mode.
|
||||
/// If successful, the transport will stay in sleep mode until woken by
|
||||
/// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)
|
||||
/// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode.
|
||||
/// \return true if sleep mode was successfully entered.
|
||||
virtual bool sleep();
|
||||
|
||||
// Bent G Christensen (bentor@gmail.com), 08/15/2016
|
||||
/// Use the radio's Channel Activity Detect (CAD) function to detect channel activity.
|
||||
/// Sets the RF95 radio into CAD mode and waits until CAD detection is complete.
|
||||
/// To be used in a listen-before-talk mechanism (Collision Avoidance)
|
||||
/// with a reasonable time backoff algorithm.
|
||||
/// This is called automatically by waitCAD().
|
||||
/// \return true if channel is in use.
|
||||
virtual bool isChannelActive();
|
||||
|
||||
/// Enable TCXO mode
|
||||
/// Call this immediately after init(), to force your radio to use an external
|
||||
/// frequency source, such as a Temperature Compensated Crystal Oscillator (TCXO), if available.
|
||||
/// See the comments in the main documentation about the sensitivity of this radio to
|
||||
/// clock frequency especially when using narrow bandwidths.
|
||||
/// Leaves the module in sleep mode.
|
||||
/// Caution, this function has not been tested by us.
|
||||
/// Caution, the TCXO model radios are not low power when in sleep (consuming
|
||||
/// about ~600 uA, reported by Phang Moh Lim.<br>
|
||||
void enableTCXO();
|
||||
|
||||
/// Returns the last measured frequency error.
|
||||
/// The LoRa receiver estimates the frequency offset between the receiver centre frequency
|
||||
/// and that of the received LoRa signal. This function returns the estimates offset (in Hz)
|
||||
/// of the last received message. Caution: this measurement is not absolute, but is measured
|
||||
/// relative to the local receiver's oscillator.
|
||||
/// Apparent errors may be due to the transmitter, the receiver or both.
|
||||
/// \return The estimated centre frequency offset in Hz of the last received message.
|
||||
/// If the modem bandwidth selector in
|
||||
/// register RH_RF95_REG_1D_MODEM_CONFIG1 is invalid, returns 0.
|
||||
int frequencyError();
|
||||
|
||||
/// Returns the Signal-to-noise ratio (SNR) of the last received message, as measured
|
||||
/// by the receiver.
|
||||
/// \return SNR of the last received message in dB
|
||||
int lastSNR();
|
||||
|
||||
/// brian.n.norman@gmail.com 9th Nov 2018
|
||||
/// Sets the radio spreading factor.
|
||||
/// valid values are 6 through 12.
|
||||
/// Out of range values below 6 are clamped to 6
|
||||
/// Out of range values above 12 are clamped to 12
|
||||
/// See Semtech DS SX1276/77/78/79 page 27 regarding SF6 configuration.
|
||||
///
|
||||
/// \param[in] uint8_t sf (spreading factor 6..12)
|
||||
/// \return nothing
|
||||
void setSpreadingFactor(uint8_t sf);
|
||||
|
||||
/// brian.n.norman@gmail.com 9th Nov 2018
|
||||
/// Sets the radio signal bandwidth
|
||||
/// sbw ranges and resultant settings are as follows:-
|
||||
/// sbw range actual bw (kHz)
|
||||
/// 0-7800 7.8
|
||||
/// 7801-10400 10.4
|
||||
/// 10401-15600 15.6
|
||||
/// 15601-20800 20.8
|
||||
/// 20801-31250 31.25
|
||||
/// 31251-41700 41.7
|
||||
/// 41701-62500 62.5
|
||||
/// 62501-12500 125.0
|
||||
/// 12501-250000 250.0
|
||||
/// >250000 500.0
|
||||
/// NOTE caution Earlier - Semtech do not recommend BW below 62.5 although, in testing
|
||||
/// I managed 31.25 with two devices in close proximity.
|
||||
/// \param[in] sbw long, signal bandwidth e.g. 125000
|
||||
void setSignalBandwidth(long sbw);
|
||||
|
||||
/// brian.n.norman@gmail.com 9th Nov 2018
|
||||
/// Sets the coding rate to 4/5, 4/6, 4/7 or 4/8.
|
||||
/// Valid denominator values are 5, 6, 7 or 8. A value of 5 sets the coding rate to 4/5 etc.
|
||||
/// Values below 5 are clamped at 5
|
||||
/// values above 8 are clamped at 8
|
||||
/// \param[in] denominator uint8_t range 5..8
|
||||
void setCodingRate4(uint8_t denominator);
|
||||
|
||||
/// brian.n.norman@gmail.com 9th Nov 2018
|
||||
/// sets the low data rate flag if symbol time exceeds 16ms
|
||||
/// ref: https://www.thethingsnetwork.org/forum/t/a-point-to-note-lora-low-data-rate-optimisation-flag/12007
|
||||
/// called by setBandwidth() and setSpreadingfactor() since these affect the symbol time.
|
||||
void setLowDatarate();
|
||||
|
||||
/// brian.n.norman@gmail.com 9th Nov 2018
|
||||
/// allows the payload CRC bit to be turned on/off. Normally this should be left on
|
||||
/// so that packets with a bad CRC are rejected
|
||||
/// \patam[in] on bool, true turns the payload CRC on, false turns it off
|
||||
void setPayloadCRC(bool on);
|
||||
|
||||
/// Return true if we are currently receiving a packet
|
||||
bool isReceiving();
|
||||
|
||||
void loop(); // Perform idle processing
|
||||
|
||||
protected:
|
||||
/// This is a low level function to handle the interrupts for one instance of RH_RF95.
|
||||
/// Called automatically by isr*()
|
||||
/// Should not need to be called by user code.
|
||||
virtual void handleInterrupt();
|
||||
|
||||
/// This is the only code called in ISR context, it just queues up our helper thread to run handleInterrupt();
|
||||
void RH_INTERRUPT_ATTR handleInterruptLevel0();
|
||||
|
||||
/// Examine the revceive buffer to determine whether the message is for this node
|
||||
void validateRxBuf();
|
||||
|
||||
/// Clear our local receive buffer
|
||||
void clearRxBuf();
|
||||
|
||||
/// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().
|
||||
/// Then optionally waits for Channel Activity Detection (CAD)
|
||||
/// to show the channnel is clear (if the radio supports CAD) by calling waitCAD().
|
||||
/// Then loads a message into the transmitter and starts the transmitter. Note that a message length
|
||||
/// of 0 is permitted.
|
||||
/// \param[in] data Array of data to be sent
|
||||
/// \param[in] len Number of bytes of data to send
|
||||
/// specify the maximum time in ms to wait. If 0 (the default) do not wait for CAD before transmitting.
|
||||
/// \return true if the message length was valid and it was correctly queued for transmit. Return false
|
||||
/// if CAD was requested and the CAD timeout timed out before clear channel was detected.
|
||||
virtual bool send(const uint8_t *data, uint8_t len);
|
||||
|
||||
private:
|
||||
/// Low level interrupt service routine for device connected to interrupt 0
|
||||
static void isr0();
|
||||
|
||||
/// Low level interrupt service routine for device connected to interrupt 1
|
||||
static void isr1();
|
||||
|
||||
/// Low level interrupt service routine for device connected to interrupt 1
|
||||
static void isr2();
|
||||
|
||||
/// Array of instances connected to interrupts 0 and 1
|
||||
static RH_RF95 *_deviceForInterrupt[];
|
||||
|
||||
/// Index of next interrupt number to use in _deviceForInterrupt
|
||||
static uint8_t _interruptCount;
|
||||
|
||||
bool enableInterrupt(); // enable our IRQ
|
||||
void disableInterrupt(); // disable our IRQ
|
||||
|
||||
volatile bool pendingInterrupt = false;
|
||||
|
||||
/// The configured interrupt pin connected to this instance
|
||||
uint8_t _interruptPin;
|
||||
|
||||
/// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)
|
||||
/// else 0xff
|
||||
uint8_t _myInterruptIndex;
|
||||
|
||||
// True if we are using the HF port (779.0 MHz and above)
|
||||
bool _usingHFport;
|
||||
|
||||
// Last measured SNR, dB
|
||||
int8_t _lastSNR;
|
||||
|
||||
protected:
|
||||
/// Number of octets in the buffer
|
||||
volatile uint8_t _bufLen;
|
||||
|
||||
/// The receiver/transmitter buffer
|
||||
uint8_t _buf[RH_RF95_MAX_PAYLOAD_LEN];
|
||||
|
||||
/// True when there is a valid message in the buffer
|
||||
volatile bool _rxBufValid;
|
||||
};
|
||||
|
||||
/// @example rf95_client.pde
|
||||
/// @example rf95_server.pde
|
||||
/// @example rf95_encrypted_client.pde
|
||||
/// @example rf95_encrypted_server.pde
|
||||
/// @example rf95_reliable_datagram_client.pde
|
||||
/// @example rf95_reliable_datagram_server.pde
|
||||
|
||||
#endif
|
||||
71
src/rf95/RHutil/atomic.h
Normal file
71
src/rf95/RHutil/atomic.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This is port of Dean Camera's ATOMIC_BLOCK macros for AVR to ARM Cortex M3
|
||||
* v1.0
|
||||
* Mark Pendrith, Nov 27, 2012.
|
||||
*
|
||||
* From Mark:
|
||||
* >When I ported the macros I emailed Dean to ask what attribution would be
|
||||
* >appropriate, and here is his response:
|
||||
* >
|
||||
* >>Mark,
|
||||
* >>I think it's great that you've ported the macros; consider them
|
||||
* >>public domain, to do with whatever you wish. I hope you find them >useful .
|
||||
* >>
|
||||
* >>Cheers!
|
||||
* >>- Dean
|
||||
*/
|
||||
|
||||
#ifdef __arm__
|
||||
#ifndef _CORTEX_M3_ATOMIC_H_
|
||||
#define _CORTEX_M3_ATOMIC_H_
|
||||
|
||||
static __inline__ uint32_t __get_primask(void) \
|
||||
{ uint32_t primask = 0; \
|
||||
__asm__ volatile ("MRS %[result], PRIMASK\n\t":[result]"=r"(primask)::); \
|
||||
return primask; } // returns 0 if interrupts enabled, 1 if disabled
|
||||
|
||||
static __inline__ void __set_primask(uint32_t setval) \
|
||||
{ __asm__ volatile ("MSR PRIMASK, %[value]\n\t""dmb\n\t""dsb\n\t""isb\n\t"::[value]"r"(setval):);
|
||||
__asm__ volatile ("" ::: "memory");}
|
||||
|
||||
static __inline__ uint32_t __iSeiRetVal(void) \
|
||||
{ __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); return 1; }
|
||||
|
||||
static __inline__ uint32_t __iCliRetVal(void) \
|
||||
{ __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); return 1; }
|
||||
|
||||
static __inline__ void __iSeiParam(const uint32_t *__s) \
|
||||
{ __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); (void)__s; }
|
||||
|
||||
static __inline__ void __iCliParam(const uint32_t *__s) \
|
||||
{ __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); (void)__s; }
|
||||
|
||||
static __inline__ void __iRestore(const uint32_t *__s) \
|
||||
{ __set_primask(*__s); __asm__ volatile ("dmb\n\t""dsb\n\t""isb\n\t"); \
|
||||
__asm__ volatile ("" ::: "memory"); }
|
||||
|
||||
|
||||
#define ATOMIC_BLOCK(type) \
|
||||
for ( type, __ToDo = __iCliRetVal(); __ToDo ; __ToDo = 0 )
|
||||
|
||||
#define ATOMIC_RESTORESTATE \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask()
|
||||
|
||||
#define ATOMIC_FORCEON \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iSeiParam))) = 0
|
||||
|
||||
#define NONATOMIC_BLOCK(type) \
|
||||
for ( type, __ToDo = __iSeiRetVal(); __ToDo ; __ToDo = 0 )
|
||||
|
||||
#define NONATOMIC_RESTORESTATE \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask()
|
||||
|
||||
#define NONATOMIC_FORCEOFF \
|
||||
uint32_t primask_save __attribute__((__cleanup__(__iCliParam))) = 0
|
||||
|
||||
#endif
|
||||
#endif
|
||||
1595
src/rf95/RadioHead.h
Normal file
1595
src/rf95/RadioHead.h
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user