From 60f5f4d74125c6e0cfd67842a9e8ad7bd0d023ec Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Mon, 4 Sep 2023 09:50:33 +0900 Subject: [PATCH 01/34] Add LIS3DH INTx pin define --- variants/Seeed_Wio_Tracker_1110/variant.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variants/Seeed_Wio_Tracker_1110/variant.h b/variants/Seeed_Wio_Tracker_1110/variant.h index 8f4a800cc..5b09bc7fd 100644 --- a/variants/Seeed_Wio_Tracker_1110/variant.h +++ b/variants/Seeed_Wio_Tracker_1110/variant.h @@ -108,3 +108,5 @@ static const uint8_t SS = PINS_COUNT; // No connection #define PIN_LR1110_IRQ (2) // WM1110 LR_DIO9 #define PIN_GNSS_LNA (37) #define PIN_POWER_SUPPLY_GROVE (33) +#define PIN_LIS3DH_INT1 (35) +#define PIN_LIS3DH_INT2 (36) From 8546ae108759394d49fac5e89756573d198e439e Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Fri, 15 Sep 2023 19:42:26 +0900 Subject: [PATCH 02/34] Remove submodules(WIP) --- .gitmodules | 6 ------ libraries/SdFat | 1 - libraries/Wio_Tracker_1110_Examples | 1 - 3 files changed, 8 deletions(-) delete mode 160000 libraries/SdFat delete mode 160000 libraries/Wio_Tracker_1110_Examples diff --git a/.gitmodules b/.gitmodules index 0b3c1a565..965563e79 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,12 +13,6 @@ [submodule "libraries/LBM_WM1110"] path = libraries/LBM_WM1110 url = https://github.com/SeeedJP/LBM_WM1110 -[submodule "libraries/Wio_Tracker_1110_Examples"] - path = libraries/Wio_Tracker_1110_Examples - url = https://github.com/SeeedJP/Wio_Tracker_1110_Examples -[submodule "libraries/SdFat"] - path = libraries/SdFat - url = https://github.com/adafruit/SdFat [submodule "libraries/Adafruit_SPIFlash"] path = libraries/Adafruit_SPIFlash url = https://github.com/adafruit/Adafruit_SPIFlash diff --git a/libraries/SdFat b/libraries/SdFat deleted file mode 160000 index 5c0b73ada..000000000 --- a/libraries/SdFat +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5c0b73ada271658d64577738464a0ac2bf337a05 diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples deleted file mode 160000 index 90576054a..000000000 --- a/libraries/Wio_Tracker_1110_Examples +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 90576054a5c2b337a1f7775c86af1f2c770e57d5 From 00e43498be37aa954c68399c6c8ac88ffdab319a Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Fri, 15 Sep 2023 19:57:34 +0900 Subject: [PATCH 03/34] Merge 1.feat:support for wio_tracker_1110 board --- .gitmodules | 41 +++++++++++++++++++---- README.md | 2 +- extras/pack_release.sh | 3 -- libraries/Grove_Sunlight_Sensor | 1 + libraries/SdFat | 1 + libraries/Seeed_Arduino_DPS310 | 1 + libraries/Seeed_Arduino_LIS3DHTR | 1 + libraries/Seeed_Arduino_UltrasonicRanger | 1 + libraries/Sensirion_Core | 1 - libraries/Wio_Tracker_1110_Examples | 1 + libraries/arduino-core | 1 + libraries/arduino-gas-index-algorithm | 1 + libraries/arduino-i2c-sgp41 | 1 + libraries/arduino-i2c-sht4x | 1 + variants/Seeed_Wio_Tracker_1110/variant.h | 5 +-- 15 files changed, 49 insertions(+), 13 deletions(-) create mode 160000 libraries/Grove_Sunlight_Sensor create mode 160000 libraries/SdFat create mode 160000 libraries/Seeed_Arduino_DPS310 create mode 160000 libraries/Seeed_Arduino_LIS3DHTR create mode 160000 libraries/Seeed_Arduino_UltrasonicRanger delete mode 160000 libraries/Sensirion_Core create mode 160000 libraries/Wio_Tracker_1110_Examples create mode 160000 libraries/arduino-core create mode 160000 libraries/arduino-gas-index-algorithm create mode 160000 libraries/arduino-i2c-sgp41 create mode 160000 libraries/arduino-i2c-sht4x diff --git a/.gitmodules b/.gitmodules index 965563e79..dc05f0125 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,15 +4,44 @@ [submodule "libraries/Adafruit_TinyUSB_Arduino"] path = libraries/Adafruit_TinyUSB_Arduino url = https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git -[submodule "libraries/Sensirion_Core"] - path = libraries/Sensirion_Core - url = https://github.com/Sensirion/arduino-core +[submodule "libraries/arduino-core"] + path = libraries/arduino-core + url = https://github.com/Sensirion/arduino-core.git [submodule "libraries/LBMX"] path = libraries/LBMX - url = https://github.com/SeeedJP/LBMX + url = https://github.com/SeeedJP/LBMX.git [submodule "libraries/LBM_WM1110"] path = libraries/LBM_WM1110 - url = https://github.com/SeeedJP/LBM_WM1110 + url = https://github.com/SeeedJP/LBM_WM1110.git +[submodule "libraries/SdFat"] + path = libraries/SdFat + url = https://github.com/adafruit/SdFat.git [submodule "libraries/Adafruit_SPIFlash"] path = libraries/Adafruit_SPIFlash - url = https://github.com/adafruit/Adafruit_SPIFlash + url = https://github.com/adafruit/Adafruit_SPIFlash.git +[submodule "libraries/arduino-gas-index-algorithm"] + path = libraries/arduino-gas-index-algorithm + url = https://github.com/Sensirion/arduino-gas-index-algorithm.git +[submodule "libraries/arduino-i2c-sgp41"] + path = libraries/arduino-i2c-sgp41 + url = https://github.com/Sensirion/arduino-i2c-sgp41.git +[submodule "libraries/arduino-i2c-sht4x"] + path = libraries/arduino-i2c-sht4x + url = https://github.com/Sensirion/arduino-i2c-sht4x.git +[submodule "libraries/Seeed_Arduino_DPS310"] + path = libraries/Seeed_Arduino_DPS310 + url = https://github.com/Seeed-Studio/Seeed_Arduino_DPS310.git + branch = dps310 +[submodule "libraries/Seeed_Arduino_LIS3DHTR"] + path = libraries/Seeed_Arduino_LIS3DHTR + url = https://github.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR.git +[submodule "libraries/Seeed_Arduino_UltrasonicRanger"] + path = libraries/Seeed_Arduino_UltrasonicRanger + url = https://github.com/Seeed-Studio/Seeed_Arduino_UltrasonicRanger.git +[submodule "libraries/Grove_Sunlight_Sensor"] + path = libraries/Grove_Sunlight_Sensor + url = https://github.com/Seeed-Studio/Grove_Sunlight_Sensor.git + branch = Si1151 +[submodule "libraries/Wio_Tracker_1110_Examples"] + path = libraries/Wio_Tracker_1110_Examples + url = https://github.com/Seeed-Studio/Wio_Tracker_1110_Examples.git diff --git a/README.md b/README.md index c4a3fd2c2..4edc3a23f 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ There are two methods that you can use to install this BSP. We highly recommend ### Optional (Core Development): Create Seeed nRF52 BSP file ``` -$ git clone --depth 1 --recurse-submodules https://github.com/SeeedJP/Adafruit_nRF52_Arduino Seeed_nRF52_Boards +$ git clone --depth 1 --recurse-submodules https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino Seeed_nRF52_Boards $ cd Seeed_nRF52_Boards $ ./extras/pack_release.sh ``` diff --git a/extras/pack_release.sh b/extras/pack_release.sh index 20b749e2f..1acb8b772 100755 --- a/extras/pack_release.sh +++ b/extras/pack_release.sh @@ -30,6 +30,3 @@ tar --transform "s|$FOLDERNAME|$VERSION|g" --exclude=extras/** --exclude=.git* cd - mv ../$FOLDERNAME-$VERSION.tar.bz2 . - -echo checksum ... SHA-256:`sha256sum $FOLDERNAME-$VERSION.tar.bz2 | awk '{print $1}'` -echo size ... `wc -c Seeed_nRF52_Boards-1.1.4.tar.bz2 | awk '{print $1}'` diff --git a/libraries/Grove_Sunlight_Sensor b/libraries/Grove_Sunlight_Sensor new file mode 160000 index 000000000..5e27ad611 --- /dev/null +++ b/libraries/Grove_Sunlight_Sensor @@ -0,0 +1 @@ +Subproject commit 5e27ad611baf6432a2f191c302b835efd422d656 diff --git a/libraries/SdFat b/libraries/SdFat new file mode 160000 index 000000000..4f43a678f --- /dev/null +++ b/libraries/SdFat @@ -0,0 +1 @@ +Subproject commit 4f43a678f05b2420a26edd6265ac0a4e90ab5f6f diff --git a/libraries/Seeed_Arduino_DPS310 b/libraries/Seeed_Arduino_DPS310 new file mode 160000 index 000000000..5cadfca6c --- /dev/null +++ b/libraries/Seeed_Arduino_DPS310 @@ -0,0 +1 @@ +Subproject commit 5cadfca6c10fca55f2b05c575b3662741924fac9 diff --git a/libraries/Seeed_Arduino_LIS3DHTR b/libraries/Seeed_Arduino_LIS3DHTR new file mode 160000 index 000000000..29aa3f7ab --- /dev/null +++ b/libraries/Seeed_Arduino_LIS3DHTR @@ -0,0 +1 @@ +Subproject commit 29aa3f7ab1b833324c0e54fd499864ea6f84adac diff --git a/libraries/Seeed_Arduino_UltrasonicRanger b/libraries/Seeed_Arduino_UltrasonicRanger new file mode 160000 index 000000000..107ee5b8a --- /dev/null +++ b/libraries/Seeed_Arduino_UltrasonicRanger @@ -0,0 +1 @@ +Subproject commit 107ee5b8a145651abfa2061e45a3627fc73eecd8 diff --git a/libraries/Sensirion_Core b/libraries/Sensirion_Core deleted file mode 160000 index c994f16fc..000000000 --- a/libraries/Sensirion_Core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c994f16fcbc0ffc39d996c651d9caf5d060f302e diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples new file mode 160000 index 000000000..6f1adfe46 --- /dev/null +++ b/libraries/Wio_Tracker_1110_Examples @@ -0,0 +1 @@ +Subproject commit 6f1adfe4603861677f886b9afda821bf42498071 diff --git a/libraries/arduino-core b/libraries/arduino-core new file mode 160000 index 000000000..41fd02cac --- /dev/null +++ b/libraries/arduino-core @@ -0,0 +1 @@ +Subproject commit 41fd02cacf307ec4945955c58ae495e56809b96c diff --git a/libraries/arduino-gas-index-algorithm b/libraries/arduino-gas-index-algorithm new file mode 160000 index 000000000..c23c93d9f --- /dev/null +++ b/libraries/arduino-gas-index-algorithm @@ -0,0 +1 @@ +Subproject commit c23c93d9f8753c36fb010ad7cbd6635838d72ba2 diff --git a/libraries/arduino-i2c-sgp41 b/libraries/arduino-i2c-sgp41 new file mode 160000 index 000000000..c2877f142 --- /dev/null +++ b/libraries/arduino-i2c-sgp41 @@ -0,0 +1 @@ +Subproject commit c2877f1429f3cfe86be3db2eb6e4a0d2d122c6c1 diff --git a/libraries/arduino-i2c-sht4x b/libraries/arduino-i2c-sht4x new file mode 160000 index 000000000..4e4361017 --- /dev/null +++ b/libraries/arduino-i2c-sht4x @@ -0,0 +1 @@ +Subproject commit 4e4361017c86c8e3ee3752805c82b5178e780fc8 diff --git a/variants/Seeed_Wio_Tracker_1110/variant.h b/variants/Seeed_Wio_Tracker_1110/variant.h index 5b09bc7fd..4bf9e1be2 100644 --- a/variants/Seeed_Wio_Tracker_1110/variant.h +++ b/variants/Seeed_Wio_Tracker_1110/variant.h @@ -108,5 +108,6 @@ static const uint8_t SS = PINS_COUNT; // No connection #define PIN_LR1110_IRQ (2) // WM1110 LR_DIO9 #define PIN_GNSS_LNA (37) #define PIN_POWER_SUPPLY_GROVE (33) -#define PIN_LIS3DH_INT1 (35) -#define PIN_LIS3DH_INT2 (36) + +#define PIN_LIS3DHTR_INT1 (35) +#define PIN_LIS3DHTR_INT2 (36) From 32309ff88b529500ccb342c11c4a4fb0e495f85e Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Sat, 16 Sep 2023 10:38:24 +0800 Subject: [PATCH 04/34] 1.fix:fix issues for https://github.com/Seeed-Studio/Wio_Tracker_1110_Examples/issues#1~#8 --- libraries/Grove-main/library.properties | 2 - .../Accelerometer_MMA7660-1.0.0/License.txt | 21 - .../src/Accelerometer_MMA7660-1.0.0/README.md | 26 - .../MMA7660FC_Demo/MMA7660FC_Demo.ino | 61 - .../Accelerometer_MMA7660-1.0.0/keywords.txt | 43 - .../library.properties | 10 - libraries/Grove-main/src/grove_sensor.hpp | 16 - libraries/Grove-main/src/mma7660/License.txt | 21 - libraries/Grove-main/src/mma7660/MMA7660.cpp | 239 ---- libraries/Grove-main/src/mma7660/MMA7660.h | 119 -- libraries/Grove-main/src/mma7660/README.md | 26 - libraries/Grove-main/src/mma7660/keywords.txt | 43 - .../Grove-main/src/mma7660/library.properties | 10 - .../src/sht4x/SensirionI2CSht4x.cpp | 489 -------- .../Grove-main/src/sht4x/SensirionI2CSht4x.h | 345 ------ libraries/LBM_packet-main/library.properties | 3 - .../LBM_packet-main/src/internal/main_lbm.cpp | 114 -- .../src/internal/main_packet.cpp | 37 - .../src/internal/main_packet.h | 25 - .../src/internal/main_sensor.cpp | 92 -- .../src/internal/main_sensor.h | 18 - libraries/LBM_packet/library.properties | 13 + .../src/Lbm_packet.hpp | 0 .../src/app_param/app_config_param.c | 0 .../src/app_param/app_config_param.h | 0 .../src/app_param/default_config_datas.cpp | 0 .../src/app_param/default_config_datas.h | 0 .../src/common/README.md | 0 .../src/common/apps_modem_common.c | 0 .../src/common/apps_modem_common.h | 0 .../src/common/apps_modem_common.mk | 0 .../src/common/apps_modem_event.c | 0 .../src/common/apps_modem_event.h | 0 .../src/common/apps_utilities.c | 0 .../src/common/apps_utilities.h | 0 .../src/common/lorawan_key_config.h | 0 .../src/common/printers/smtc_modem_api_str.c | 0 .../src/common/printers/smtc_modem_api_str.h | 0 .../src/common/smtc_board/smtc_board.h | 0 .../src/common/smtc_board/smtc_board_lr11xx.c | 0 .../src/common/smtc_board/smtc_board_ralf.h | 0 .../src/common/smtc_hal_dbg_trace.h | 0 .../src/common/smtc_hal_mcu.cpp | 0 .../src/common/smtc_hal_mcu.h | 0 .../src/common/smtc_hal_options.h | 0 .../src/internal/main_ble.cpp | 18 +- .../src/internal/main_ble.h | 0 .../src/internal/main_gps.cpp | 8 +- .../src/internal/main_gps.h | 0 .../LBM_packet/src/internal/main_lbm.cpp | 214 ++++ .../src/internal/main_lbm.h | 18 +- .../src/internal/main_lora.cpp | 54 +- .../src/internal/main_lora.h | 6 +- .../LBM_packet/src/internal/main_packet.cpp | 114 ++ .../LBM_packet/src/internal/main_packet.h | 35 + .../LBM_packet/src/internal/main_sensor.cpp | 1017 +++++++++++++++++ .../LBM_packet/src/internal/main_sensor.h | 315 +++++ .../src/internal/main_track.cpp | 279 ++--- .../src/internal/main_track.h | 24 +- .../src/internal/main_wifi.cpp | 9 +- .../src/internal/main_wifi.h | 0 61 files changed, 1912 insertions(+), 1972 deletions(-) delete mode 100644 libraries/Grove-main/library.properties delete mode 100644 libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/License.txt delete mode 100644 libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/README.md delete mode 100644 libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/examples/MMA7660FC_Demo/MMA7660FC_Demo.ino delete mode 100644 libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/keywords.txt delete mode 100644 libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/library.properties delete mode 100644 libraries/Grove-main/src/grove_sensor.hpp delete mode 100644 libraries/Grove-main/src/mma7660/License.txt delete mode 100644 libraries/Grove-main/src/mma7660/MMA7660.cpp delete mode 100644 libraries/Grove-main/src/mma7660/MMA7660.h delete mode 100644 libraries/Grove-main/src/mma7660/README.md delete mode 100644 libraries/Grove-main/src/mma7660/keywords.txt delete mode 100644 libraries/Grove-main/src/mma7660/library.properties delete mode 100644 libraries/Grove-main/src/sht4x/SensirionI2CSht4x.cpp delete mode 100644 libraries/Grove-main/src/sht4x/SensirionI2CSht4x.h delete mode 100644 libraries/LBM_packet-main/library.properties delete mode 100644 libraries/LBM_packet-main/src/internal/main_lbm.cpp delete mode 100644 libraries/LBM_packet-main/src/internal/main_packet.cpp delete mode 100644 libraries/LBM_packet-main/src/internal/main_packet.h delete mode 100644 libraries/LBM_packet-main/src/internal/main_sensor.cpp delete mode 100644 libraries/LBM_packet-main/src/internal/main_sensor.h create mode 100644 libraries/LBM_packet/library.properties rename libraries/{LBM_packet-main => LBM_packet}/src/Lbm_packet.hpp (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/app_param/app_config_param.c (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/app_param/app_config_param.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/app_param/default_config_datas.cpp (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/app_param/default_config_datas.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/README.md (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/apps_modem_common.c (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/apps_modem_common.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/apps_modem_common.mk (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/apps_modem_event.c (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/apps_modem_event.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/apps_utilities.c (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/apps_utilities.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/lorawan_key_config.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/printers/smtc_modem_api_str.c (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/printers/smtc_modem_api_str.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/smtc_board/smtc_board.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/smtc_board/smtc_board_lr11xx.c (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/smtc_board/smtc_board_ralf.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/smtc_hal_dbg_trace.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/smtc_hal_mcu.cpp (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/smtc_hal_mcu.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/common/smtc_hal_options.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_ble.cpp (91%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_ble.h (100%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_gps.cpp (90%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_gps.h (100%) create mode 100644 libraries/LBM_packet/src/internal/main_lbm.cpp rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_lbm.h (64%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_lora.cpp (78%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_lora.h (96%) create mode 100644 libraries/LBM_packet/src/internal/main_packet.cpp create mode 100644 libraries/LBM_packet/src/internal/main_packet.h create mode 100644 libraries/LBM_packet/src/internal/main_sensor.cpp create mode 100644 libraries/LBM_packet/src/internal/main_sensor.h rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_track.cpp (50%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_track.h (69%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_wifi.cpp (90%) rename libraries/{LBM_packet-main => LBM_packet}/src/internal/main_wifi.h (100%) diff --git a/libraries/Grove-main/library.properties b/libraries/Grove-main/library.properties deleted file mode 100644 index 8c9fff20f..000000000 --- a/libraries/Grove-main/library.properties +++ /dev/null @@ -1,2 +0,0 @@ -architectures=nrf52 -inlcude=grove_sensor.hpp diff --git a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/License.txt b/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/License.txt deleted file mode 100644 index baf484b44..000000000 --- a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/License.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Seeed Technology Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/README.md b/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/README.md deleted file mode 100644 index 088e2570a..000000000 --- a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/README.md +++ /dev/null @@ -1,26 +0,0 @@ -## Accelerometer_MMA7660 -![image](https://statics3.seeedstudio.com/images/101020039%201.jpg) - -[Grove - 3-Axis Digital Accelerometer(±1.5g)](https://www.seeedstudio.com/Grove-3Axis-Digital-Accelerometer15g-p-765.html) - -3-Axis Digital Accelerometer is the key part in projects like orientation detection, gesture detection and Motion detection. This 3-Asix Digital Accelerometer(±1.5g) is based on Freescale's low power consumption module, MMA7660FC. It features up to 10,000g high shock surviability and configurable Samples per Second rate. For generous applications that don't require too large measurement range, this is a great choice because it's durable, energy saving and cost-efficient. - -For more information, please refer to [Grove_3Axis_Digital_Accelerometer_MMA7660][1] - ----- -This software is written by Frankie Chu for seeed studio
-and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
- -Contributing to this software is warmly welcomed. You can do this basically by
-[forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
-for operating guide). Adding change log and your contact into file header is encouraged.
-Thanks for your contribution. - -Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond. - - -[1]:http://wiki.seeedstudio.com/Grove-3-Axis_Digital_Accelerometer-1.5g/ - - - -[![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Accelerometer_MMA7660)](https://github.com/igrigorik/ga-beacon) diff --git a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/examples/MMA7660FC_Demo/MMA7660FC_Demo.ino b/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/examples/MMA7660FC_Demo/MMA7660FC_Demo.ino deleted file mode 100644 index fc3ebba4f..000000000 --- a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/examples/MMA7660FC_Demo/MMA7660FC_Demo.ino +++ /dev/null @@ -1,61 +0,0 @@ -/*****************************************************************************/ -// Function: Get the accelemeter of the x/y/z axis. -// Hardware: Grove - 3-Axis Digital Accelerometer(±1.5g) -// Arduino IDE: Arduino-1.0 -// Author: Frankie.Chu -// Date: Jan 10,2013 -// Version: v0.9b -// by www.seeedstudio.com -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// -/*******************************************************************************/ - -#include -#include "MMA7660.h" -MMA7660 accelemeter; -void setup() -{ - accelemeter.init(); - Serial.begin(9600); -} -void loop() -{ - int8_t x; - int8_t y; - int8_t z; - float ax,ay,az; - accelemeter.getXYZ(&x,&y,&z); - - Serial.print("x = "); - Serial.println(x); - Serial.print("y = "); - Serial.println(y); - Serial.print("z = "); - Serial.println(z); - - accelemeter.getAcceleration(&ax,&ay,&az); - Serial.println("accleration of X/Y/Z: "); - Serial.print(ax); - Serial.println(" g"); - Serial.print(ay); - Serial.println(" g"); - Serial.print(az); - Serial.println(" g"); - Serial.println("*************"); - delay(500); -} - - diff --git a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/keywords.txt b/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/keywords.txt deleted file mode 100644 index 34f3c3e2f..000000000 --- a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/keywords.txt +++ /dev/null @@ -1,43 +0,0 @@ -####################################### -# Syntax Coloring Map DigitalAccelerometer_MMA7660FC -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -MMA7660 KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### -init KEYWORD2 -setMode KEYWORD2 -setSampleRate KEYWORD2 -getXYZ KEYWORD2 -getAcceleration KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### -MMA7660_X LITERAL1 -MMA7660_Y LITERAL1 -MMA7660_Z LITERAL1 -MMA7660_TILT LITERAL1 -MMA7660_SRST LITERAL1 -MMA7660_SPCN LITERAL1 -MMA7660_INTSU LITERAL1 -MMA7660_MODE LITERAL1 -MMA7660_STAND_BY LITERAL1 -MMA7660_ACTIVE LITERAL1 -MMA7660_SR LITERAL1 -AUTO_SLEEP_120 LITERAL1 -AUTO_SLEEP_64 LITERAL1 -AUTO_SLEEP_32 LITERAL1 -AUTO_SLEEP_16 LITERAL1 -AUTO_SLEEP_8 LITERAL1 -AUTO_SLEEP_4 LITERAL1 -AUTO_SLEEP_2 LITERAL1 -AUTO_SLEEP_1 LITERAL1 -MMA7660_PDET LITERAL1 -MMA7660_PD LITERAL1 \ No newline at end of file diff --git a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/library.properties b/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/library.properties deleted file mode 100644 index 0eb485b6e..000000000 --- a/libraries/Grove-main/src/Accelerometer_MMA7660-1.0.0/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=Accelerometer_MMA7660 -version=1.0.0 -author=Seeed Studio -maintainer=Seeed Studio -sentence=Arduino library to control Grove - 3-Axis Digital Accelerometer(±1.5g). -paragraph=Arduino library to control Grove - 3-Axis Digital Accelerometer(±1.5g). -category=Sensors -url=https://github.com/Seeed-Studio/Accelerometer_MMA7660 -architectures=* -includes=MMA7660.h \ No newline at end of file diff --git a/libraries/Grove-main/src/grove_sensor.hpp b/libraries/Grove-main/src/grove_sensor.hpp deleted file mode 100644 index af792c8b9..000000000 --- a/libraries/Grove-main/src/grove_sensor.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * grove_sensor.hpp - * Copyright (C) 2023 Seeed K.K. - * MIT License - */ - -#pragma once - -//////////////////////////////////////////////////////////////////////////////// -// Includes - -#include "sht4x/SensirionI2CSht4x.h" - -#include "mma7660/MMA7660.h" - -//////////////////////////////////////////////////////////////////////////////// diff --git a/libraries/Grove-main/src/mma7660/License.txt b/libraries/Grove-main/src/mma7660/License.txt deleted file mode 100644 index baf484b44..000000000 --- a/libraries/Grove-main/src/mma7660/License.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Seeed Technology Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/libraries/Grove-main/src/mma7660/MMA7660.cpp b/libraries/Grove-main/src/mma7660/MMA7660.cpp deleted file mode 100644 index cd49eb94d..000000000 --- a/libraries/Grove-main/src/mma7660/MMA7660.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - * MMA7760.h - * Library for accelerometer_MMA7760 - * - * Copyright (c) 2013 seeed technology inc. - * Author : FrankieChu - * Create Time : Jan 2013 - * Change Log : - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include "MMA7660.h" - -#define MMA7660TIMEOUT 500 // us -/*Function: Write a byte to the register of the MMA7660*/ -void MMA7660::write(uint8_t _register, uint8_t _data) { - Wire.begin(); - Wire.beginTransmission(MMA7660_ADDR); - Wire.write(_register); - Wire.write(_data); - Wire.endTransmission(); -} - -/*Function: Read a byte from the regitster of the MMA7660*/ -uint8_t MMA7660::read(uint8_t _register) { - uint8_t data_read; - Wire.begin(); - Wire.beginTransmission(MMA7660_ADDR); - Wire.write(_register); - Wire.endTransmission(); - Wire.beginTransmission(MMA7660_ADDR); - Wire.requestFrom(MMA7660_ADDR,1); - while(Wire.available()) - { - data_read = Wire.read(); - } - Wire.endTransmission(); - return data_read; -} - -// populate lookup table based on the MMA7660 datasheet at http://www.farnell.com/datasheets/1670762.pdf -void MMA7660::initAccelTable() { - int i; - float val, valZ; - - for (i = 0, val = 0; i < 32; i++) { - accLookup[i].g = val; - val += 0.047; - } - - for (i = 63, val = -0.047; i > 31; i--) { - accLookup[i].g = val; - val -= 0.047; - } - - for (i = 0, val = 0, valZ = 90; i < 22; i++) { - accLookup[i].xyAngle = val; - accLookup[i].zAngle = valZ; - - val += 2.69; - valZ -= 2.69; - } - - for (i = 63, val = -2.69, valZ = -87.31; i > 42; i--) { - accLookup[i].xyAngle = val; - accLookup[i].zAngle = valZ; - - val -= 2.69; - valZ += 2.69; - } - - for (i = 22; i < 43; i++) { - accLookup[i].xyAngle = 255; - accLookup[i].zAngle = 255; - } -} - -void MMA7660::init() -{ - initAccelTable(); - setMode(MMA7660_STAND_BY); - setSampleRate(AUTO_SLEEP_32); - setMode(MMA7660_ACTIVE); -} - -void MMA7660::init(uint8_t interrupts) -{ - initAccelTable(); - setMode(MMA7660_STAND_BY); - setSampleRate(AUTO_SLEEP_32); - write(MMA7660_INTSU, interrupts); - setMode(MMA7660_ACTIVE); -} -void MMA7660::setMode(uint8_t mode) { - write(MMA7660_MODE,mode); -} -void MMA7660::setSampleRate(uint8_t rate) { - write(MMA7660_SR,rate); -} - -/*Function: Get the contents of the registers in the MMA7660*/ -/* so as to calculate the acceleration. */ -bool MMA7660::getXYZ(int8_t *x,int8_t *y,int8_t *z) -{ - -START: - - unsigned char val[3]; - int count = 0; - val[0] = val[1] = val[2] = 64; - while(Wire.available() > 0) - Wire.read(); - - Wire.requestFrom(MMA7660_ADDR,3); - - unsigned long timer_s = micros(); - - while(Wire.available()) - { - if(count < 3) - { - while ( val[count] > 63 ) // reload the damn thing it is bad - { - val[count] = Wire.read(); - - if(micros()-timer_s > MMA7660TIMEOUT) - { - goto START; - } - } - } - count++; - } - - *x = ((int8_t)(val[0]<<2))/4; - *y = ((int8_t)(val[1]<<2))/4; - *z = ((int8_t)(val[2]<<2))/4; - - return 1; -} - -bool MMA7660::getAcceleration(float *ax,float *ay,float *az) -{ - int8_t x,y,z; - if(!getXYZ(&x,&y,&z))return 0; - *ax = x/21.00; - *ay = y/21.00; - *az = z/21.00; - - return 1; -} - -bool MMA7660::getAcceleration(MMA7660_ACC_DATA *data) { - unsigned char val[3]; - int count; - bool error; - - unsigned long timer_s = micros(); - do { - error = false; - count = 0; - - while(Wire.available() > 0) { - Wire.read(); - } - - Wire.requestFrom(MMA7660_ADDR, 3); - while(Wire.available()) { - if (count < 3) { - val[count] = Wire.read(); - if (0x40 & val[count] == 0x40) { // alert bit is set, data is garbage and we have to start over. - error = true; - break; - } - } - count++; - } - - if(micros()-timer_s > MMA7660TIMEOUT)return 0; - } while (error); - - (*data).x = accLookup[val[0]]; - (*data).y = accLookup[val[1]]; - (*data).z = accLookup[val[2]]; - - return 1; -} - -bool MMA7660::getAllData(MMA7660_DATA *data) { - int count = 0; - uint8_t val[11] = {0}; - - while (Wire.available() > 0) { - Wire.read(); - } - - Wire.requestFrom(MMA7660_ADDR, 11); - while (Wire.available()) { - if (count < 11) { - val[count] = Wire.read(); - } - count++; - } - - data->X = val[0]; - data->Y = val[1]; - data->Z = val[2]; - data->TILT = val[3]; - data->SRST = val[4]; - data->SPCNT = val[5]; - data->INTSU = val[6]; - data->MODE = val[7]; - data->SR = val[8]; - data->PDET = val[9]; - data->PD = val[10]; - - return 1; -} diff --git a/libraries/Grove-main/src/mma7660/MMA7660.h b/libraries/Grove-main/src/mma7660/MMA7660.h deleted file mode 100644 index 0fef65ddf..000000000 --- a/libraries/Grove-main/src/mma7660/MMA7660.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * MMA7760.h - * Library for accelerometer_MMA7760 - * - * Copyright (c) 2013 seeed technology inc. - * Author : FrankieChu - * Create Time : Jan 2013 - * Change Log : - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef __MMC7660_H__ -#define __MMC7660_H__ - -#define MMA7660_ADDR 0x4c - -#define MMA7660_X 0x00 -#define MMA7660_Y 0x01 -#define MMA7660_Z 0x02 -#define MMA7660_TILT 0x03 -#define MMA7660_SRST 0x04 -#define MMA7660_SPCNT 0x05 -#define MMA7660_INTSU 0x06 - #define MMA7660_SHINTX 0x80 - #define MMA7660_SHINTY 0x40 - #define MMA7660_SHINTZ 0x20 - #define MMA7660_GINT 0x10 - #define MMA7660_ASINT 0x08 - #define MMA7660_PDINT 0x04 - #define MMA7660_PLINT 0x02 - #define MMA7660_FBINT 0x01 -#define MMA7660_MODE 0x07 - #define MMA7660_STAND_BY 0x00 - #define MMA7660_ACTIVE 0x01 -#define MMA7660_SR 0x08 //sample rate register - #define AUTO_SLEEP_120 0X00//120 sample per second - #define AUTO_SLEEP_64 0X01 - #define AUTO_SLEEP_32 0X02 - #define AUTO_SLEEP_16 0X03 - #define AUTO_SLEEP_8 0X04 - #define AUTO_SLEEP_4 0X05 - #define AUTO_SLEEP_2 0X06 - #define AUTO_SLEEP_1 0X07 -#define MMA7660_PDET 0x09 -#define MMA7660_PD 0x0A - -struct MMA7660_DATA { - uint8_t X; - uint8_t Y; - uint8_t Z; - uint8_t TILT; - uint8_t SRST; - uint8_t SPCNT; - uint8_t INTSU; - uint8_t MODE; - uint8_t SR; - uint8_t PDET; - uint8_t PD; -}; - -struct MMA7660_LOOKUP { - float g; - float xyAngle; - float zAngle; -}; - -struct MMA7660_ACC_DATA { - MMA7660_LOOKUP x; - MMA7660_LOOKUP y; - MMA7660_LOOKUP z; -}; - -class MMA7660 { -private: - void write(uint8_t _register, uint8_t _data); - uint8_t read(uint8_t _register); - void initAccelTable(); - - MMA7660_LOOKUP accLookup[64]; - -public: - void init(); - void init(uint8_t interrupts); - void setMode(uint8_t mode); - void setSampleRate(uint8_t rate); - - // get the signed value of x,y,z register - bool getXYZ(int8_t *x,int8_t *y,int8_t *z); - - // calculate the acceleration from the signed value of x,y,z register - bool getAcceleration(float *ax,float *ay,float *az); - - // lookup the acceleration from the lookup table from this chip's datasheet - bool getAcceleration(MMA7660_ACC_DATA *data); - - // get all the register value - bool getAllData(MMA7660_DATA *data); -}; - -#endif diff --git a/libraries/Grove-main/src/mma7660/README.md b/libraries/Grove-main/src/mma7660/README.md deleted file mode 100644 index 088e2570a..000000000 --- a/libraries/Grove-main/src/mma7660/README.md +++ /dev/null @@ -1,26 +0,0 @@ -## Accelerometer_MMA7660 -![image](https://statics3.seeedstudio.com/images/101020039%201.jpg) - -[Grove - 3-Axis Digital Accelerometer(±1.5g)](https://www.seeedstudio.com/Grove-3Axis-Digital-Accelerometer15g-p-765.html) - -3-Axis Digital Accelerometer is the key part in projects like orientation detection, gesture detection and Motion detection. This 3-Asix Digital Accelerometer(±1.5g) is based on Freescale's low power consumption module, MMA7660FC. It features up to 10,000g high shock surviability and configurable Samples per Second rate. For generous applications that don't require too large measurement range, this is a great choice because it's durable, energy saving and cost-efficient. - -For more information, please refer to [Grove_3Axis_Digital_Accelerometer_MMA7660][1] - ----- -This software is written by Frankie Chu for seeed studio
-and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
- -Contributing to this software is warmly welcomed. You can do this basically by
-[forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
-for operating guide). Adding change log and your contact into file header is encouraged.
-Thanks for your contribution. - -Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond. - - -[1]:http://wiki.seeedstudio.com/Grove-3-Axis_Digital_Accelerometer-1.5g/ - - - -[![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Accelerometer_MMA7660)](https://github.com/igrigorik/ga-beacon) diff --git a/libraries/Grove-main/src/mma7660/keywords.txt b/libraries/Grove-main/src/mma7660/keywords.txt deleted file mode 100644 index 34f3c3e2f..000000000 --- a/libraries/Grove-main/src/mma7660/keywords.txt +++ /dev/null @@ -1,43 +0,0 @@ -####################################### -# Syntax Coloring Map DigitalAccelerometer_MMA7660FC -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -MMA7660 KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### -init KEYWORD2 -setMode KEYWORD2 -setSampleRate KEYWORD2 -getXYZ KEYWORD2 -getAcceleration KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### -MMA7660_X LITERAL1 -MMA7660_Y LITERAL1 -MMA7660_Z LITERAL1 -MMA7660_TILT LITERAL1 -MMA7660_SRST LITERAL1 -MMA7660_SPCN LITERAL1 -MMA7660_INTSU LITERAL1 -MMA7660_MODE LITERAL1 -MMA7660_STAND_BY LITERAL1 -MMA7660_ACTIVE LITERAL1 -MMA7660_SR LITERAL1 -AUTO_SLEEP_120 LITERAL1 -AUTO_SLEEP_64 LITERAL1 -AUTO_SLEEP_32 LITERAL1 -AUTO_SLEEP_16 LITERAL1 -AUTO_SLEEP_8 LITERAL1 -AUTO_SLEEP_4 LITERAL1 -AUTO_SLEEP_2 LITERAL1 -AUTO_SLEEP_1 LITERAL1 -MMA7660_PDET LITERAL1 -MMA7660_PD LITERAL1 \ No newline at end of file diff --git a/libraries/Grove-main/src/mma7660/library.properties b/libraries/Grove-main/src/mma7660/library.properties deleted file mode 100644 index 0eb485b6e..000000000 --- a/libraries/Grove-main/src/mma7660/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=Accelerometer_MMA7660 -version=1.0.0 -author=Seeed Studio -maintainer=Seeed Studio -sentence=Arduino library to control Grove - 3-Axis Digital Accelerometer(±1.5g). -paragraph=Arduino library to control Grove - 3-Axis Digital Accelerometer(±1.5g). -category=Sensors -url=https://github.com/Seeed-Studio/Accelerometer_MMA7660 -architectures=* -includes=MMA7660.h \ No newline at end of file diff --git a/libraries/Grove-main/src/sht4x/SensirionI2CSht4x.cpp b/libraries/Grove-main/src/sht4x/SensirionI2CSht4x.cpp deleted file mode 100644 index 8189cb265..000000000 --- a/libraries/Grove-main/src/sht4x/SensirionI2CSht4x.cpp +++ /dev/null @@ -1,489 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * I2C-Generator: 0.2.0 - * Yaml Version: 0.1.0 - * Template Version: 0.7.0-12-g6411a7e - */ -/* - * Copyright (c) 2021, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "SensirionI2CSht4x.h" -#include "Arduino.h" -#include "SensirionCore.h" -#include - - -SensirionI2CSht4x::SensirionI2CSht4x() { -} - -void SensirionI2CSht4x::begin(TwoWire& i2cBus) { - _i2cBus = &i2cBus; -} - -uint16_t -SensirionI2CSht4x::measureHighPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0xFD, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(10); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::measureHighPrecision(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = measureHighPrecisionTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t -SensirionI2CSht4x::measureMediumPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0xF6, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(5); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::measureMediumPrecision(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = measureMediumPrecisionTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t -SensirionI2CSht4x::measureLowestPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0xE0, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(2); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::measureLowestPrecision(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = measureLowestPrecisionTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t SensirionI2CSht4x::activateHighestHeaterPowerLongTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x39, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(1100); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::activateHighestHeaterPowerLong(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = - activateHighestHeaterPowerLongTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t SensirionI2CSht4x::activateHighestHeaterPowerShortTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x32, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(110); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::activateHighestHeaterPowerShort(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = - activateHighestHeaterPowerShortTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t SensirionI2CSht4x::activateMediumHeaterPowerLongTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x2F, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(1100); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::activateMediumHeaterPowerLong(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = activateMediumHeaterPowerLongTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t SensirionI2CSht4x::activateMediumHeaterPowerShortTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x24, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(110); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::activateMediumHeaterPowerShort(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = - activateMediumHeaterPowerShortTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t SensirionI2CSht4x::activateLowestHeaterPowerLongTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x1E, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(1100); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::activateLowestHeaterPowerLong(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = activateLowestHeaterPowerLongTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t SensirionI2CSht4x::activateLowestHeaterPowerShortTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x15, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(110); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt16(temperatureTicks); - error |= rxFrame.getUInt16(humidityTicks); - return error; -} - -uint16_t SensirionI2CSht4x::activateLowestHeaterPowerShort(float& temperature, - float& humidity) { - uint16_t error; - uint16_t temperatureTicks; - uint16_t humidityTicks; - - error = - activateLowestHeaterPowerShortTicks(temperatureTicks, humidityTicks); - if (error) { - return error; - } - - temperature = _convertTicksToCelsius(temperatureTicks); - humidity = _convertTicksToPercentRH(humidityTicks); - return NoError; -} - -uint16_t SensirionI2CSht4x::serialNumber(uint32_t& serialNumber) { - uint16_t error; - uint8_t buffer[6]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x89, buffer, 6); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - if (error) { - return error; - } - - delay(10); - - SensirionI2CRxFrame rxFrame(buffer, 6); - error = SensirionI2CCommunication::receiveFrame(SHT4X_I2C_ADDRESS, 6, - rxFrame, *_i2cBus); - if (error) { - return error; - } - - error |= rxFrame.getUInt32(serialNumber); - return error; -} - -uint16_t SensirionI2CSht4x::softReset() { - uint16_t error; - uint8_t buffer[1]; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x94, buffer, 1); - - error = SensirionI2CCommunication::sendFrame(SHT4X_I2C_ADDRESS, txFrame, - *_i2cBus); - delay(10); - return error; -} - -float SensirionI2CSht4x::_convertTicksToCelsius(uint16_t ticks) { - return static_cast(ticks * 175.0 / 65535.0 - 45.0); -} - -float SensirionI2CSht4x::_convertTicksToPercentRH(uint16_t ticks) { - return static_cast(ticks * 125.0 / 65535.0 - 6); -} \ No newline at end of file diff --git a/libraries/Grove-main/src/sht4x/SensirionI2CSht4x.h b/libraries/Grove-main/src/sht4x/SensirionI2CSht4x.h deleted file mode 100644 index 4266e73a7..000000000 --- a/libraries/Grove-main/src/sht4x/SensirionI2CSht4x.h +++ /dev/null @@ -1,345 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * I2C-Generator: 0.2.0 - * Yaml Version: 0.1.0 - * Template Version: 0.7.0-12-g6411a7e - */ -/* - * Copyright (c) 2021, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SENSIRIONI2CSHT4X_H -#define SENSIRIONI2CSHT4X_H - -#include - -#include - -#define SHT4X_I2C_ADDRESS 0x44 - -class SensirionI2CSht4x { - - public: - SensirionI2CSht4x(); - /** - * begin() - Initializes the SensirionI2CSht4x class. - * - * @param serial Arduino stream object to be communicated with. - * - */ - void begin(TwoWire& i2cBus); - - /** - * measureHighPrecisionTicks() - SHT4x command for a single shot measurement - * with high repeatability. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t measureHighPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * measureHighPrecision() - SHT4x command for a single shot - * measurement with high repeatability. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t measureHighPrecision(float& temperature, float& humidity); - - /** - * measureMediumPrecisionTicks() - SHT4x command for a single shot - * measurement with medium repeatability. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t measureMediumPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * measureMediumPrecision() - SHT4x command for a single shot - * measurement with medium repeatability. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t measureMediumPrecision(float& temperature, float& humidity); - - /** - * measureLowestPrecisionTicks() - SHT4x command for a single shot - * measurement with lowest repeatability. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t measureLowestPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * measureLowestPrecision() - SHT4x command for a single shot - * measurement with lowest repeatability. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t measureLowestPrecision(float& temperature, float& humidity); - - /** - * activateHighestHeaterPowerLongTicks() - SHT4x command to activate highest - * heater power and perform a single shot high precision measurement for 1s. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateHighestHeaterPowerLongTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * activateHighestHeaterPowerLong() - SHT4x command to activate highest - * heater power and perform a single shot high precision measurement for 1s. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateHighestHeaterPowerLong(float& temperature, - float& humidity); - - /** - * activateHighestHeaterPowerShortTicks() - SHT4x command to activate - * highest heater power and perform a single shot high precision measurement - * for 0.1s. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateHighestHeaterPowerShortTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * activateHighestHeaterPowerShort() - SHT4x command to activate highest - * heater power and perform a single shot high precision measurement for - * 0.1s. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateHighestHeaterPowerShort(float& temperature, - float& humidity); - - /** - * activateMediumHeaterPowerLongTicks() - SHT4x command to activate medium - * heater power and perform a single shot high precision measurement for 1s. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateMediumHeaterPowerLongTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * activateMediumHeaterPowerLong() - SHT4x command to activate medium - * heater power and perform a single shot high precision measurement for 1s. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateMediumHeaterPowerLong(float& temperature, float& humidity); - - /** - * activateMediumHeaterPowerShortTicks() - SHT4x command to activate medium - * heater power and perform a single shot high precision measurement for - * 0.1s. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateMediumHeaterPowerShortTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * activateMediumHeaterPowerShort() - SHT4x command to activate medium - * heater power and perform a single shot high precision measurement for - * 0.1s. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateMediumHeaterPowerShort(float& temperature, - float& humidity); - - /** - * activateLowestHeaterPowerLongTicks() - SHT4x command to activate lowest - * heater power and perform a single shot high precision measurement for 1s. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateLowestHeaterPowerLongTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * activateLowestHeaterPowerLong() - SHT4x command to activate lowest - * heater power and perform a single shot high precision measurement for 1s. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateLowestHeaterPowerLong(float& temperature, float& humidity); - - /** - * activateLowestHeaterPowerShortTicks() - SHT4x command to activate lowest - * heater power and perform a single shot high precision measurement for - * 0.1s. - * - * @param temperatureTicks Temperature ticks. Convert to degrees celsius by - * (175 * value / 65535) - 45 - * - * @param humidityTicks Humidity ticks. Convert to degrees celsius by (125 * - * value / 65535) - 6 - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateLowestHeaterPowerShortTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * activateLowestHeaterPowerShort() - SHT4x command to activate lowest - * heater power and perform a single shot high precision measurement for - * 0.1s. - * - * @param temperature Temperature in degrees celsius. - * - * @param humidity Humidity in percent relative humidity. - * - * @return 0 on success, an error code otherwise - */ - uint16_t activateLowestHeaterPowerShort(float& temperature, - float& humidity); - - /** - * serialNumber() - Read out the serial number - * - * @note Each sensor has a unique serial number that is assigned by - * Sensirion during production. It is stored in the one-time-programmable - * memory and cannot be manipulated after production. - * - * @param serialNumber Unique serial number - * - * @return 0 on success, an error code otherwise - */ - uint16_t serialNumber(uint32_t& serialNumber); - - /** - * softReset() - Perform a soft reset. - * - * @note A reset of the sensor can be achieved in three ways: By perform a - * soft reset using this function, by using an I2C general call, at which - * all devices on the I2C bus will be reset, or by a power down (incl. - * pulling SCL and SDA low). See the datasheet for more detailed - * information. - * - * @return 0 on success, an error code otherwise - */ - uint16_t softReset(void); - - private: - TwoWire* _i2cBus = nullptr; - float _convertTicksToCelsius(uint16_t ticks); - float _convertTicksToPercentRH(uint16_t ticks); -}; - -#endif /* SENSIRIONI2CSHT4X_H */ diff --git a/libraries/LBM_packet-main/library.properties b/libraries/LBM_packet-main/library.properties deleted file mode 100644 index 0797c2b85..000000000 --- a/libraries/LBM_packet-main/library.properties +++ /dev/null @@ -1,3 +0,0 @@ - -architectures=nrf52 -includes=Lbm_packet.hpp \ No newline at end of file diff --git a/libraries/LBM_packet-main/src/internal/main_lbm.cpp b/libraries/LBM_packet-main/src/internal/main_lbm.cpp deleted file mode 100644 index 1529ca158..000000000 --- a/libraries/LBM_packet-main/src/internal/main_lbm.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "Lbm_packet.hpp" - -#include -#include - -uint8_t app_task_lora_tx_buffer_len[APP_TASK_LORA_TX_QUEUE_MAX] = { 0 }; -bool app_task_lora_tx_buffer_confirmed[APP_TASK_LORA_TX_QUEUE_MAX] = { false }; -uint8_t app_task_lora_tx_buffer[APP_TASK_LORA_TX_QUEUE_MAX][LORAWAN_APP_DATA_MAX_SIZE] = { 0 }; -uint8_t app_task_lora_tx_in = 0; -uint8_t app_task_lora_tx_out = 0; - -uint32_t app_lora_sync_in_rtc_second = 0; -uint32_t app_lora_sync_in_utc_second = 0; - - -bool app_task_lora_tx_engine( void ) -{ - static uint8_t send_count = 0; - static uint32_t app_task_lora_tx_toa = 0; - static uint32_t tx_last_timestemp = 0; - smtc_modem_status_mask_t modem_status; - smtc_modem_region_t cur_region; - uint8_t dutycycle_enable = 0; - - uint32_t tx_now_timestemp = smtc_modem_hal_get_time_in_ms( ); - - ASSERT_SMTC_MODEM_RC( smtc_modem_get_region(0, &cur_region)); - - ASSERT_SMTC_MODEM_RC( smtc_modem_get_duty_cycle_enable(&dutycycle_enable)); - - if(dutycycle_enable == 1) - { - if((cur_region == SMTC_MODEM_REGION_EU_868) || (cur_region == SMTC_MODEM_REGION_RU_864)) - { - if(tx_now_timestemp<(tx_last_timestemp+app_task_lora_tx_toa * 99)) //Limit dutycycle to less than 1% - { - return false; - } - } - } - - uint8_t out = app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX; - - if( app_task_lora_tx_buffer_len[out] ) - { - smtc_modem_get_status( 0, &modem_status ); - if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED - && app_lora_is_idle( ) - && app_task_radio_gnss_is_busy( ) == false && app_task_radio_wifi_is_busy( ) == false - && app_task_track_gnss_is_busy( ) == false && app_task_track_wifi_is_busy( ) == false ) - { - bool result = app_lora_send_frame( app_task_lora_tx_buffer[out], app_task_lora_tx_buffer_len[out], app_task_lora_tx_buffer_confirmed[out], false ); - if( result ) - { - ASSERT_SMTC_MODEM_RC( smtc_modem_get_toa_status(&app_task_lora_tx_toa,app_task_lora_tx_buffer_len[out] + 13)); - tx_last_timestemp = smtc_modem_hal_get_time_in_ms( ); - send_count++; - hal_mcu_trace_print( "app_task_lora_tx_out: %u\r\n", app_task_lora_tx_out ); - if(send_count>=2) - { - send_count = 0; - memset(app_task_lora_tx_buffer[out],0,app_task_lora_tx_buffer_len[out]); - app_task_lora_tx_buffer_len[out] = 0; - app_task_lora_tx_buffer_confirmed[out] = 0; - app_task_lora_tx_out = (++out)% APP_TASK_LORA_TX_QUEUE_MAX; - } - } - } - else - { - return false; - } - } - else - { - return false; - } - return true; -} - -bool app_task_lora_tx_queue( uint8_t *buf, uint8_t len, bool confirmed, bool emergency ) -{ - bool result = false; - smtc_modem_status_mask_t modem_status; - smtc_modem_get_status( 0, &modem_status ); - if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED ) - { - hal_mcu_trace_print( "app_task_lora_tx_in: %u\r\n", app_task_lora_tx_in ); - uint8_t in = app_task_lora_tx_in % APP_TASK_LORA_TX_QUEUE_MAX; - app_task_lora_tx_buffer_len[in] = len; - app_task_lora_tx_buffer_confirmed[in] = confirmed; - for( uint8_t j = 0; j < len; j++ ) - { - app_task_lora_tx_buffer[in][j] = buf[j]; - } - app_task_lora_tx_in = (++app_task_lora_tx_in)%APP_TASK_LORA_TX_QUEUE_MAX; - } - else - { - result = false; - } - - return result; -} - -uint32_t app_task_lora_get_timestamp( void ) -{ - uint32_t timestamp_now = 0; - if( app_task_lora_clock_is_synch( )) - { - timestamp_now = apps_modem_common_get_utc_time( ); - } - return timestamp_now; -} \ No newline at end of file diff --git a/libraries/LBM_packet-main/src/internal/main_packet.cpp b/libraries/LBM_packet-main/src/internal/main_packet.cpp deleted file mode 100644 index 0cfa9414d..000000000 --- a/libraries/LBM_packet-main/src/internal/main_packet.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "Lbm_packet.hpp" - -#include -#include - -#include "app_param/default_config_datas.h" - -//////////////////////////////////////////////////////////////////////////////// -// Variables - -uint8_t app_lora_packet_buffer[LORAWAN_APP_DATA_MAX_SIZE] = { 0 }; -uint8_t app_lora_packet_len = 0; - - - - - - -void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ) -{ - dst = dst + ( size - 1 ); - while( size-- ) - { - *dst-- = *src++; - } -} - -void default_param_load(void) -{ - is_first_time_sync = false; - lorawan_param_init(); -} - - - - - diff --git a/libraries/LBM_packet-main/src/internal/main_packet.h b/libraries/LBM_packet-main/src/internal/main_packet.h deleted file mode 100644 index 960abe0dc..000000000 --- a/libraries/LBM_packet-main/src/internal/main_packet.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _APP_TASK_PACKET_H_ -#define _APP_TASK_PACKET_H_ - -#include -#include -#include "main_lora.h" - -#define DATA_ID_UP_PACKET_WIFI_SEN_BAT 0x07 -#define DATA_ID_UP_PACKET_BLE_SEN_BAT 0x08 -#define DATA_ID_UP_PACKET_WIFI_BAT 0x0A -#define DATA_ID_UP_PACKET_BLE_BAT 0x0B - -#define DATA_ID_UP_PACKET_GNSS_RAW 0x0E -#define DATA_ID_UP_PACKET_GNSS_SEN_BAT 0x0F -#define DATA_ID_UP_PACKET_GNSS_BAT 0x10 -#define DATA_ID_UP_PACKET_POS_STATUS 0x11 - -extern uint8_t app_lora_packet_buffer[LORAWAN_APP_DATA_MAX_SIZE]; -extern uint8_t app_lora_packet_len; - - -void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ); -void default_param_load(void); - -#endif diff --git a/libraries/LBM_packet-main/src/internal/main_sensor.cpp b/libraries/LBM_packet-main/src/internal/main_sensor.cpp deleted file mode 100644 index 4b6f2db47..000000000 --- a/libraries/LBM_packet-main/src/internal/main_sensor.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "Lbm_packet.hpp" - -#include -#include - -#include - -#include -#include -#include "internal/nrf_hal/gpio.hpp" -#include "internal/nrf_hal/gpiote.hpp" - -int16_t temperture_val = 0; -uint16_t light_val = 0; - -SensirionI2CSht4x sht4x; -MMA7660 accelemeter; - -int adcin = D6; -int adcvalue = 0; -float mv_per_lsb = 3600.0F/1024.0F; // 10-bit ADC with 3.6V input range -uint8_t sensor_types=0; -static constexpr int mma7660_IRQ_PIN = D0; // -void mma7660_irq_callback(void) -{ - MMA7660_DATA data; - accelemeter.getAllData(&data); - // hal_mcu_trace_print("mma7660_irq:%x\r\n",data.TILT); - state_all = state_all|TRACKER_STATE_BIT0_SOS; -} - - -void sensor_init_detect(void) -{ - void* context = 0; - //power on - digitalWrite(PIN_POWER_SUPPLY_GROVE, HIGH); //grove power on - pinMode(PIN_POWER_SUPPLY_GROVE, OUTPUT); - - delay(1000); - Wire.begin(); - delay(1000); - Wire.beginTransmission(SHT4X_I2C_ADDRESS); - if ( 0 == Wire.endTransmission() ) - { - sensor_types = sensor_types|sht40_sensor_type; - sht4x.begin(Wire); - delay(1000); - } - Wire.beginTransmission(MMA7660_ADDR); - if ( 0 == Wire.endTransmission() ) - { - sensor_types = sensor_types|mma7660_sensor_type; - accelemeter.init(MMA7660_SHINTX|MMA7660_SHINTY|MMA7660_SHINTZ); - - pinMode(mma7660_IRQ_PIN, INPUT_PULLUP); - attachInterrupt(mma7660_IRQ_PIN, mma7660_irq_callback, ISR_DEFERRED | FALLING); - } -} -//get sensor data -void sensor_datas_get(void) -{ - float light_vcc; - if(sensor_types&sht40_sensor_type) - { - uint16_t error; - float temperature; - float humidity; - - error = sht4x.measureHighPrecision(temperature, humidity); - if (error == 0) - { - temperture_val = temperature*10; - } - } - if(sensor_types&mma7660_sensor_type) - { - MMA7660_DATA data; - accelemeter.getAllData(&data); - if(data.TILT&0x80) - { - state_all = state_all|TRACKER_STATE_BIT0_SOS; - } - } - adcvalue = analogRead(adcin); - light_vcc = (float)(adcvalue * mv_per_lsb); - light_val = 100*(light_vcc-30)/2000; //percentage - if(light_val<0) light_val = 0; - if(light_val>100) light_val = 100; - // hal_mcu_trace_print("Temperature:%d,light_val:%d\r\n",temperture_val,light_val); -} - diff --git a/libraries/LBM_packet-main/src/internal/main_sensor.h b/libraries/LBM_packet-main/src/internal/main_sensor.h deleted file mode 100644 index 81fbfc38a..000000000 --- a/libraries/LBM_packet-main/src/internal/main_sensor.h +++ /dev/null @@ -1,18 +0,0 @@ - -#ifndef _MAIN_SENSOR_H_ -#define _MAIN_SENSOR_H_ - -#include -#include - -#define sht40_sensor_type 0x01 -#define mma7660_sensor_type 0x02 - -extern int16_t temperture_val; -extern uint16_t light_val; - -void sensor_init_detect(void); - -//get sensor data -void sensor_datas_get(void); -#endif diff --git a/libraries/LBM_packet/library.properties b/libraries/LBM_packet/library.properties new file mode 100644 index 000000000..b726c7af8 --- /dev/null +++ b/libraries/LBM_packet/library.properties @@ -0,0 +1,13 @@ +name=LBM packet main function +version=0.1 +author= +maintainer= +sentence= +paragraph= +category=Communication +url= +architectures=nrf52 +includes=Lbm_packet.hpp + + + diff --git a/libraries/LBM_packet-main/src/Lbm_packet.hpp b/libraries/LBM_packet/src/Lbm_packet.hpp similarity index 100% rename from libraries/LBM_packet-main/src/Lbm_packet.hpp rename to libraries/LBM_packet/src/Lbm_packet.hpp diff --git a/libraries/LBM_packet-main/src/app_param/app_config_param.c b/libraries/LBM_packet/src/app_param/app_config_param.c similarity index 100% rename from libraries/LBM_packet-main/src/app_param/app_config_param.c rename to libraries/LBM_packet/src/app_param/app_config_param.c diff --git a/libraries/LBM_packet-main/src/app_param/app_config_param.h b/libraries/LBM_packet/src/app_param/app_config_param.h similarity index 100% rename from libraries/LBM_packet-main/src/app_param/app_config_param.h rename to libraries/LBM_packet/src/app_param/app_config_param.h diff --git a/libraries/LBM_packet-main/src/app_param/default_config_datas.cpp b/libraries/LBM_packet/src/app_param/default_config_datas.cpp similarity index 100% rename from libraries/LBM_packet-main/src/app_param/default_config_datas.cpp rename to libraries/LBM_packet/src/app_param/default_config_datas.cpp diff --git a/libraries/LBM_packet-main/src/app_param/default_config_datas.h b/libraries/LBM_packet/src/app_param/default_config_datas.h similarity index 100% rename from libraries/LBM_packet-main/src/app_param/default_config_datas.h rename to libraries/LBM_packet/src/app_param/default_config_datas.h diff --git a/libraries/LBM_packet-main/src/common/README.md b/libraries/LBM_packet/src/common/README.md similarity index 100% rename from libraries/LBM_packet-main/src/common/README.md rename to libraries/LBM_packet/src/common/README.md diff --git a/libraries/LBM_packet-main/src/common/apps_modem_common.c b/libraries/LBM_packet/src/common/apps_modem_common.c similarity index 100% rename from libraries/LBM_packet-main/src/common/apps_modem_common.c rename to libraries/LBM_packet/src/common/apps_modem_common.c diff --git a/libraries/LBM_packet-main/src/common/apps_modem_common.h b/libraries/LBM_packet/src/common/apps_modem_common.h similarity index 100% rename from libraries/LBM_packet-main/src/common/apps_modem_common.h rename to libraries/LBM_packet/src/common/apps_modem_common.h diff --git a/libraries/LBM_packet-main/src/common/apps_modem_common.mk b/libraries/LBM_packet/src/common/apps_modem_common.mk similarity index 100% rename from libraries/LBM_packet-main/src/common/apps_modem_common.mk rename to libraries/LBM_packet/src/common/apps_modem_common.mk diff --git a/libraries/LBM_packet-main/src/common/apps_modem_event.c b/libraries/LBM_packet/src/common/apps_modem_event.c similarity index 100% rename from libraries/LBM_packet-main/src/common/apps_modem_event.c rename to libraries/LBM_packet/src/common/apps_modem_event.c diff --git a/libraries/LBM_packet-main/src/common/apps_modem_event.h b/libraries/LBM_packet/src/common/apps_modem_event.h similarity index 100% rename from libraries/LBM_packet-main/src/common/apps_modem_event.h rename to libraries/LBM_packet/src/common/apps_modem_event.h diff --git a/libraries/LBM_packet-main/src/common/apps_utilities.c b/libraries/LBM_packet/src/common/apps_utilities.c similarity index 100% rename from libraries/LBM_packet-main/src/common/apps_utilities.c rename to libraries/LBM_packet/src/common/apps_utilities.c diff --git a/libraries/LBM_packet-main/src/common/apps_utilities.h b/libraries/LBM_packet/src/common/apps_utilities.h similarity index 100% rename from libraries/LBM_packet-main/src/common/apps_utilities.h rename to libraries/LBM_packet/src/common/apps_utilities.h diff --git a/libraries/LBM_packet-main/src/common/lorawan_key_config.h b/libraries/LBM_packet/src/common/lorawan_key_config.h similarity index 100% rename from libraries/LBM_packet-main/src/common/lorawan_key_config.h rename to libraries/LBM_packet/src/common/lorawan_key_config.h diff --git a/libraries/LBM_packet-main/src/common/printers/smtc_modem_api_str.c b/libraries/LBM_packet/src/common/printers/smtc_modem_api_str.c similarity index 100% rename from libraries/LBM_packet-main/src/common/printers/smtc_modem_api_str.c rename to libraries/LBM_packet/src/common/printers/smtc_modem_api_str.c diff --git a/libraries/LBM_packet-main/src/common/printers/smtc_modem_api_str.h b/libraries/LBM_packet/src/common/printers/smtc_modem_api_str.h similarity index 100% rename from libraries/LBM_packet-main/src/common/printers/smtc_modem_api_str.h rename to libraries/LBM_packet/src/common/printers/smtc_modem_api_str.h diff --git a/libraries/LBM_packet-main/src/common/smtc_board/smtc_board.h b/libraries/LBM_packet/src/common/smtc_board/smtc_board.h similarity index 100% rename from libraries/LBM_packet-main/src/common/smtc_board/smtc_board.h rename to libraries/LBM_packet/src/common/smtc_board/smtc_board.h diff --git a/libraries/LBM_packet-main/src/common/smtc_board/smtc_board_lr11xx.c b/libraries/LBM_packet/src/common/smtc_board/smtc_board_lr11xx.c similarity index 100% rename from libraries/LBM_packet-main/src/common/smtc_board/smtc_board_lr11xx.c rename to libraries/LBM_packet/src/common/smtc_board/smtc_board_lr11xx.c diff --git a/libraries/LBM_packet-main/src/common/smtc_board/smtc_board_ralf.h b/libraries/LBM_packet/src/common/smtc_board/smtc_board_ralf.h similarity index 100% rename from libraries/LBM_packet-main/src/common/smtc_board/smtc_board_ralf.h rename to libraries/LBM_packet/src/common/smtc_board/smtc_board_ralf.h diff --git a/libraries/LBM_packet-main/src/common/smtc_hal_dbg_trace.h b/libraries/LBM_packet/src/common/smtc_hal_dbg_trace.h similarity index 100% rename from libraries/LBM_packet-main/src/common/smtc_hal_dbg_trace.h rename to libraries/LBM_packet/src/common/smtc_hal_dbg_trace.h diff --git a/libraries/LBM_packet-main/src/common/smtc_hal_mcu.cpp b/libraries/LBM_packet/src/common/smtc_hal_mcu.cpp similarity index 100% rename from libraries/LBM_packet-main/src/common/smtc_hal_mcu.cpp rename to libraries/LBM_packet/src/common/smtc_hal_mcu.cpp diff --git a/libraries/LBM_packet-main/src/common/smtc_hal_mcu.h b/libraries/LBM_packet/src/common/smtc_hal_mcu.h similarity index 100% rename from libraries/LBM_packet-main/src/common/smtc_hal_mcu.h rename to libraries/LBM_packet/src/common/smtc_hal_mcu.h diff --git a/libraries/LBM_packet-main/src/common/smtc_hal_options.h b/libraries/LBM_packet/src/common/smtc_hal_options.h similarity index 100% rename from libraries/LBM_packet-main/src/common/smtc_hal_options.h rename to libraries/LBM_packet/src/common/smtc_hal_options.h diff --git a/libraries/LBM_packet-main/src/internal/main_ble.cpp b/libraries/LBM_packet/src/internal/main_ble.cpp similarity index 91% rename from libraries/LBM_packet-main/src/internal/main_ble.cpp rename to libraries/LBM_packet/src/internal/main_ble.cpp index f2cd1de5c..c32ac3856 100644 --- a/libraries/LBM_packet-main/src/internal/main_ble.cpp +++ b/libraries/LBM_packet/src/internal/main_ble.cpp @@ -99,7 +99,7 @@ void scan_params_init(void) Bluefruit.setName("wio tracker"); /* Set the LED interval for blinky pattern on BLUE LED */ - Bluefruit.setConnLedInterval(250); + // Bluefruit.setConnLedInterval(250); /* Start Central Scanning * - Enable auto scan if disconnected * - Filter out packet with a min rssi @@ -215,27 +215,27 @@ bool app_ble_get_results( uint8_t *result, uint8_t *size ) void app_ble_display_results( void ) { - hal_mcu_trace_print( "iBeacon: %d\r\n", ble_beacon_res_num ); + printf( "iBeacon: %d\r\n", ble_beacon_res_num ); for( uint8_t i = 0; i < ble_beacon_res_num; i ++ ) { - hal_mcu_trace_print("%04x, ", ble_beacon_buf[ble_beacon_rssi_array[i]].company_id ); + printf("%04x, ", ble_beacon_buf[ble_beacon_rssi_array[i]].company_id ); for( uint8_t j = 0; j < 16; j++ ) { - hal_mcu_trace_print( "%02x ", ble_beacon_buf[ble_beacon_rssi_array[i]].uuid[j] ); + printf( "%02x ", ble_beacon_buf[ble_beacon_rssi_array[i]].uuid[j] ); } uint16_t major = 0, minor = 0; memcpyr(( uint8_t *)( &major ), ( uint8_t *)( &ble_beacon_buf[ble_beacon_rssi_array[i]].major ), 2 ); memcpyr(( uint8_t *)( &minor ), ( uint8_t *)( &ble_beacon_buf[ble_beacon_rssi_array[i]].minor ), 2 ); - hal_mcu_trace_print(", %04x, ", major ); - hal_mcu_trace_print("%04x, ", minor ); - hal_mcu_trace_print("%d/%d dBm, ", ble_beacon_buf[ble_beacon_rssi_array[i]].rssi, ble_beacon_buf[ble_beacon_rssi_array[i]].rssi_ ); + printf(", %04x, ", major ); + printf("%04x, ", minor ); + printf("%d/%d dBm, ", ble_beacon_buf[ble_beacon_rssi_array[i]].rssi, ble_beacon_buf[ble_beacon_rssi_array[i]].rssi_ ); for( uint8_t j = 0; j < 5; j++ ) { - hal_mcu_trace_print( "%02x:", ble_beacon_buf[ble_beacon_rssi_array[i]].mac[5 - j] ); + printf( "%02x:", ble_beacon_buf[ble_beacon_rssi_array[i]].mac[5 - j] ); } - hal_mcu_trace_print( "%02x\r\n", ble_beacon_buf[ble_beacon_rssi_array[i]].mac[0] ); + printf( "%02x\r\n", ble_beacon_buf[ble_beacon_rssi_array[i]].mac[0] ); } } diff --git a/libraries/LBM_packet-main/src/internal/main_ble.h b/libraries/LBM_packet/src/internal/main_ble.h similarity index 100% rename from libraries/LBM_packet-main/src/internal/main_ble.h rename to libraries/LBM_packet/src/internal/main_ble.h diff --git a/libraries/LBM_packet-main/src/internal/main_gps.cpp b/libraries/LBM_packet/src/internal/main_gps.cpp similarity index 90% rename from libraries/LBM_packet-main/src/internal/main_gps.cpp rename to libraries/LBM_packet/src/internal/main_gps.cpp index 06b778028..f95eb326a 100644 --- a/libraries/LBM_packet-main/src/internal/main_gps.cpp +++ b/libraries/LBM_packet/src/internal/main_gps.cpp @@ -14,7 +14,7 @@ uint8_t gps_scan_status = 0; void app_gps_scan_init( void ) { gps_scan_status = 1; - gnss_group_id_init(); + // gnss_group_id_init(); } bool app_gps_scan_start( void ) @@ -77,14 +77,14 @@ void app_gps_display_results( void ) { if( gnss_mw_custom_send_buffer_num ) { - hal_mcu_trace_print( "GNSS Raw:\r\n" ); + printf( "GNSS Raw:\r\n" ); } for( uint8_t i = 0; i < gnss_mw_custom_send_buffer_num; i++ ) { for( uint8_t j = 0; j < gnss_mw_custom_send_buffer_len[i]; j++ ) { - hal_mcu_trace_print( "%02X", gnss_mw_custom_send_buffer[i][j] ); + printf( "%02X", gnss_mw_custom_send_buffer[i][j] ); } - hal_mcu_trace_print( "\r\n" ); + printf( "\r\n" ); } } diff --git a/libraries/LBM_packet-main/src/internal/main_gps.h b/libraries/LBM_packet/src/internal/main_gps.h similarity index 100% rename from libraries/LBM_packet-main/src/internal/main_gps.h rename to libraries/LBM_packet/src/internal/main_gps.h diff --git a/libraries/LBM_packet/src/internal/main_lbm.cpp b/libraries/LBM_packet/src/internal/main_lbm.cpp new file mode 100644 index 000000000..5a332dc18 --- /dev/null +++ b/libraries/LBM_packet/src/internal/main_lbm.cpp @@ -0,0 +1,214 @@ +#include "Lbm_packet.hpp" + +#include +#include + +uint8_t send_retry_type = 1; // 0:don't need check confirm 1: at most confirm once; 2: at most confirm twice; + + +uint8_t app_task_lora_tx_buffer_len[APP_TASK_LORA_TX_QUEUE_MAX] = { 0 }; +bool app_task_lora_tx_buffer_confirmed[APP_TASK_LORA_TX_QUEUE_MAX] = { false }; +uint8_t app_task_lora_tx_buffer[APP_TASK_LORA_TX_QUEUE_MAX][LORAWAN_APP_DATA_MAX_SIZE] = { 0 }; +uint8_t app_task_lora_tx_in = 0; +uint8_t app_task_lora_tx_out = 0; + +uint32_t app_lora_sync_in_rtc_second = 0; +uint32_t app_lora_sync_in_utc_second = 0; + +uint32_t app_send_confirmed_count = 0; +uint32_t app_task_lora_tx_confirmed_count = 0; + +bool app_task_lora_tx_check = false; + +void app_lora_confirmed_count_increment( void ) +{ + app_send_confirmed_count++; +} + +uint32_t app_lora_get_confirmed_count( void ) +{ + return app_send_confirmed_count; +} + + +bool app_task_lora_tx_engine( void ) +{ + static uint8_t packet_send_cnt = 0; + static uint32_t app_task_lora_tx_toa = 0; + static uint32_t tx_last_timestemp = 0; + smtc_modem_status_mask_t modem_status; + smtc_modem_region_t cur_region; + uint8_t dutycycle_enable = 0; + + static uint8_t last_time_tx_res = false; + static uint8_t out = 0; + + uint32_t tx_now_timestemp = smtc_modem_hal_get_time_in_ms( ); + + ASSERT_SMTC_MODEM_RC( smtc_modem_get_region(0, &cur_region)); + + ASSERT_SMTC_MODEM_RC( smtc_modem_get_duty_cycle_enable(&dutycycle_enable)); + + if(dutycycle_enable == 1) + { + if((cur_region == SMTC_MODEM_REGION_EU_868) || (cur_region == SMTC_MODEM_REGION_RU_864)) + { + hal_mcu_trace_print( "app_task_lora_tx_toa: %u\r\n", app_task_lora_tx_toa ); + if(tx_now_timestemp<(tx_last_timestemp+app_task_lora_tx_toa * 99)) //Limit dutycycle to less than 1% + { + last_time_tx_res = false; + return false; + } + } + } + + if( app_task_lora_tx_check ) //need check confirmed last time send packet + { + app_task_lora_tx_check = false; + uint32_t count_temp = app_lora_get_confirmed_count( ); + + if( app_task_lora_tx_confirmed_count >= count_temp ) //unconfirmed + { + if(send_retry_type == 1) //just confirm once,then unconfirm + { + if(packet_send_cnt >= 1) + { + packet_send_cnt = 0; + app_task_lora_tx_buffer_confirmed[app_task_lora_tx_out] = false; + } + } + else if(send_retry_type == 2) //confirm twice,then unconfirm + { + if(packet_send_cnt >= 2) + { + packet_send_cnt = 0; + app_task_lora_tx_buffer_confirmed[app_task_lora_tx_out] = false; + } + } + else + { + packet_send_cnt = 0; + app_task_lora_tx_buffer_len[out] = 0; //Clear the last data + out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + } + } + else //confirmed + { + app_task_lora_tx_buffer_len[out] = 0; //Clear the last data + out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + } + } + else + { + if(last_time_tx_res == true) + { + app_task_lora_tx_buffer_len[out] = 0; //Clear the last data + out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + } + } + + if( app_task_lora_tx_buffer_len[out] ) + { + smtc_modem_get_status( 0, &modem_status ); + if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED + && app_lora_is_idle( ) + && app_task_radio_gnss_is_busy( ) == false && app_task_radio_wifi_is_busy( ) == false + && app_task_track_gnss_is_busy( ) == false && app_task_track_wifi_is_busy( ) == false ) + { + bool result = app_lora_send_frame( app_task_lora_tx_buffer[out], app_task_lora_tx_buffer_len[out], app_task_lora_tx_buffer_confirmed[out], false ); + if( result ) + { + app_task_lora_tx_out = out; + hal_mcu_trace_print( "app_task_lora_tx_out: %u,confirm:%s\r\n", app_task_lora_tx_out,app_task_lora_tx_buffer_confirmed[out] == true ? "true":"false" ); + + if( app_task_lora_tx_buffer_confirmed[out] ) + { + packet_send_cnt ++; + app_task_lora_tx_check = true; + app_task_lora_tx_confirmed_count = app_lora_get_confirmed_count( ); + } + else + { + app_task_lora_tx_check = false; + } + last_time_tx_res = true; + return true; + } + } + else + { + last_time_tx_res = false; + return false; + } + } + else + { + last_time_tx_res = false; + return false; + } + last_time_tx_res = true; + return true; +} + + +bool app_task_lora_tx_queue( uint8_t *buf, uint8_t len, bool confirmed, bool emergency ) +{ + bool result = false; + smtc_modem_status_mask_t modem_status; + smtc_modem_get_status( 0, &modem_status ); + if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED ) + { + hal_mcu_trace_print( "app_task_lora_tx_in: %u\r\n", app_task_lora_tx_in ); + uint8_t in = app_task_lora_tx_in % APP_TASK_LORA_TX_QUEUE_MAX; + app_task_lora_tx_buffer_len[in] = len; + app_task_lora_tx_buffer_confirmed[in] = confirmed; + for( uint8_t j = 0; j < len; j++ ) + { + app_task_lora_tx_buffer[in][j] = buf[j]; + } + app_task_lora_tx_in = (++app_task_lora_tx_in)%APP_TASK_LORA_TX_QUEUE_MAX; + } + else + { + result = false; + } + + return result; +} + +uint32_t app_task_lora_get_timestamp( void ) +{ + uint32_t timestamp_now = 0; + if( app_task_lora_clock_is_synch( )) + { + timestamp_now = apps_modem_common_get_utc_time( ); + } + return timestamp_now; +} + + +void app_task_packet_downlink_decode( uint8_t *buf, uint8_t len ) +{ + uint8_t data_id = 0; + + if( buf && len ) + { + data_id = buf[0]; + switch( data_id ) + { + case DATA_ID_DOWN_PACKET_USER_CODE: + { + + } + break; + + default: + break; + } + } +} + + + + + diff --git a/libraries/LBM_packet-main/src/internal/main_lbm.h b/libraries/LBM_packet/src/internal/main_lbm.h similarity index 64% rename from libraries/LBM_packet-main/src/internal/main_lbm.h rename to libraries/LBM_packet/src/internal/main_lbm.h index ebd81a8ee..fe4322a1a 100644 --- a/libraries/LBM_packet-main/src/internal/main_lbm.h +++ b/libraries/LBM_packet/src/internal/main_lbm.h @@ -7,33 +7,29 @@ #include "main_lora.h" -#define LBM_LORA_TX_TEST 0 #define APP_TASK_LORA_TX_QUEUE_MAX 48 -#define APP_TASK_TX_OFFLINE_CONFIRMED_LOST_MAX 1 -#define APP_TASK_JOIN_RUN_MAX 600000 -#define APP_TASK_JOIN_STOP_MAX 600000 -#define APP_TASK_OFFLINE_RUN_24H_MAX 86400000 - -#define APP_TASK_LBM_TX_FAST_DELAY 20000 - - -extern uint8_t app_task_lora_tx_in; +extern uint8_t send_retry_type; // 0:don't need check confirm 1: at most confirm once; 2: at most confirm twice; +extern uint8_t app_task_lora_tx_in; extern uint8_t app_task_lora_tx_out; extern uint32_t app_lora_sync_in_rtc_second; extern uint32_t app_lora_sync_in_utc_second; +extern uint32_t app_send_confirmed_count; +extern uint32_t app_task_lora_tx_confirmed_count; extern uint8_t app_task_lora_tx_buffer_len[APP_TASK_LORA_TX_QUEUE_MAX] ; extern bool app_task_lora_tx_buffer_confirmed[APP_TASK_LORA_TX_QUEUE_MAX]; extern uint8_t app_task_lora_tx_buffer[APP_TASK_LORA_TX_QUEUE_MAX][LORAWAN_APP_DATA_MAX_SIZE] ; +void app_lora_confirmed_count_increment( void ); +uint32_t app_lora_get_confirmed_count( void ); bool app_task_lora_tx_queue( uint8_t *buf, uint8_t len, bool confirmed, bool emergency ); uint32_t app_task_lora_get_timestamp( void ); @@ -42,4 +38,6 @@ void app_task_lora_tx_done_wakeup( void ); bool app_task_lora_tx_engine( void ); +void app_task_packet_downlink_decode( uint8_t *buf, uint8_t len ); + #endif diff --git a/libraries/LBM_packet-main/src/internal/main_lora.cpp b/libraries/LBM_packet/src/internal/main_lora.cpp similarity index 78% rename from libraries/LBM_packet-main/src/internal/main_lora.cpp rename to libraries/LBM_packet/src/internal/main_lora.cpp index 1c9ab4211..870e0d0cb 100644 --- a/libraries/LBM_packet-main/src/internal/main_lora.cpp +++ b/libraries/LBM_packet/src/internal/main_lora.cpp @@ -29,6 +29,8 @@ uint8_t app_lora_data_tx_size = 0; uint32_t app_lora_tx_recent_time = 0; +uint8_t app_lora_data_rx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; +uint8_t app_lora_data_rx_size = 0; /*! * @brief First time sync status for application startup @@ -154,14 +156,52 @@ bool app_task_radio_wifi_is_busy( void ) return wifi_mw_custom_get_scan_busy(); } -void app_task_lora_clock_run_synch( void ) + + +void app_set_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf) { - smtc_modem_status_mask_t modem_status; - smtc_modem_get_status( 0, &modem_status ); - if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED ) + switch(REGION) { - hal_mcu_trace_print( "start sync clock at %u\r\n", smtc_modem_hal_get_time_in_ms( )); - smtc_modem_time_stop_sync_service( stack_id ); - smtc_modem_time_start_sync_service( stack_id, SMTC_MODEM_TIME_ALC_SYNC ); + case SMTC_MODEM_REGION_EU_868: + memcpy(buf,adr_custom_list_eu868_default,16); + break; + + case SMTC_MODEM_REGION_AS_923_GRP1: + case SMTC_MODEM_REGION_AS_923_GRP2: + case SMTC_MODEM_REGION_AS_923_GRP3: + case SMTC_MODEM_REGION_AS_923_GRP4: + memcpy(buf,adr_custom_list_as923_default,16); + break; + + case SMTC_MODEM_REGION_US_915: + memcpy(buf,adr_custom_list_us915_default,16); + break; + + case SMTC_MODEM_REGION_AU_915: + memcpy(buf,adr_custom_list_au915_default,16); + break; + + case SMTC_MODEM_REGION_IN_865: + memcpy(buf,adr_custom_list_in865_default,16); + break; + + case SMTC_MODEM_REGION_RU_864: + memcpy(buf,adr_custom_list_ru864_default,16); + break; + + case SMTC_MODEM_REGION_KR_920: + memcpy(buf,adr_custom_list_kr920_default,16); + break; + + case SMTC_MODEM_REGION_CN_470_RP_1_0: + case SMTC_MODEM_REGION_WW2G4: + case SMTC_MODEM_REGION_CN_470: + + default: + + break; } + + } + diff --git a/libraries/LBM_packet-main/src/internal/main_lora.h b/libraries/LBM_packet/src/internal/main_lora.h similarity index 96% rename from libraries/LBM_packet-main/src/internal/main_lora.h rename to libraries/LBM_packet/src/internal/main_lora.h index 1f7437e73..64dbbb0d3 100644 --- a/libraries/LBM_packet-main/src/internal/main_lora.h +++ b/libraries/LBM_packet/src/internal/main_lora.h @@ -142,6 +142,8 @@ extern uint8_t mw_gnss_event_state; extern uint8_t app_lora_data_tx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; extern uint8_t app_lora_data_tx_size; +extern uint8_t app_lora_data_rx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; +extern uint8_t app_lora_data_rx_size; extern uint8_t adr_custom_list_eu868_default[16]; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 extern uint8_t adr_custom_list_us915_default[16]; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7 @@ -172,9 +174,9 @@ bool app_lora_is_idle( void ); bool app_task_lora_clock_is_synch( void ); bool app_task_radio_gnss_is_busy( void ); bool app_task_radio_wifi_is_busy( void ); -void app_task_lora_clock_run_synch( void ); -void custom_lora_adr_compute( uint8_t min, uint8_t max, uint8_t *buf ); +void custom_lora_adr_compute( uint8_t min, uint8_t max, uint8_t *buf ); +void app_set_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf); #endif diff --git a/libraries/LBM_packet/src/internal/main_packet.cpp b/libraries/LBM_packet/src/internal/main_packet.cpp new file mode 100644 index 000000000..eee37b5d2 --- /dev/null +++ b/libraries/LBM_packet/src/internal/main_packet.cpp @@ -0,0 +1,114 @@ +#include "Lbm_packet.hpp" + +#include +#include + +#include "app_param/default_config_datas.h" + +//////////////////////////////////////////////////////////////////////////////// +// Variables + +uint8_t app_lora_packet_buffer[LORAWAN_APP_DATA_MAX_SIZE] = { 0 }; +uint8_t app_lora_packet_len = 0; + +uint8_t factory_sensor_temp_len = 0; +uint8_t factory_sensor_data_temp[64] = { 0 }; + +void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ) +{ + dst = dst + ( size - 1 ); + while( size-- ) + { + *dst-- = *src++; + } +} + +void default_param_load(void) +{ + is_first_time_sync = false; + lorawan_param_init(); +} + + +void app_task_factory_sensor_data_send( void ) +{ + memset( factory_sensor_data_temp, 0, sizeof( factory_sensor_data_temp )); + factory_sensor_temp_len = 0; + + factory_sensor_data_temp[0] = DATA_ID_UP_PACKET_FACT_SENSOR; + + //event status + factory_sensor_data_temp[1] = ( state_all >> 16 ) & 0xff; + factory_sensor_data_temp[2] = ( state_all >> 8 ) & 0xff; + factory_sensor_data_temp[3] = ( state_all ) & 0xff; + + factory_sensor_temp_len = factory_sensor_temp_len + 4; + + //utc time + uint32_t utc_temp = app_task_track_get_utc( ); + memcpyr( factory_sensor_data_temp + 4, ( uint8_t * )( &utc_temp ), 4 ); + + factory_sensor_temp_len = factory_sensor_temp_len + 4; + + //sensor datas + memcpy( factory_sensor_data_temp + factory_sensor_temp_len, factory_sensor_data, factory_sensor_data_len ); // utc + sensor data + factory_sensor_temp_len = factory_sensor_data_len + factory_sensor_temp_len; + + app_task_lora_tx_queue( factory_sensor_data_temp, factory_sensor_temp_len, true, false ); + factory_sensor_data_len = 20; + + hal_mcu_trace_print("factory sensor datas uplink:"); + for(uint8_t u8i = 0; u8i < factory_sensor_temp_len; u8i++ ) + { + hal_mcu_trace_print("%02x",factory_sensor_data_temp[u8i]); + } + hal_mcu_trace_print("\r\n"); + + sound_sample_index = 0; + sound_average_data = 0; + state_all = 0; + +} + + + +void app_task_user_sensor_data_send( void ) +{ + uint8_t user_sensor_temp_len = 0; + uint8_t user_sensor_data_temp[64] = { 0 }; + memset( user_sensor_data_temp, 0, sizeof( user_sensor_data_temp )); + user_sensor_temp_len = 0; + + user_sensor_data_temp[0] = DATA_ID_UP_PACKET_USER_SENSOR; + + //event status + user_sensor_data_temp[2] = ( state_all >> 16 ) & 0xff; + user_sensor_data_temp[3] = ( state_all >> 8 ) & 0xff; + user_sensor_data_temp[4] = ( state_all ) & 0xff; + + //utc time + uint32_t utc_temp = app_task_track_get_utc( ); + memcpyr( user_sensor_data_temp + 5, ( uint8_t * )( &utc_temp ), 4 ); + user_sensor_temp_len = 9; + + //sensor datas + if(user_sensor_data_len % 4 == 0) //must be 4 bytes/group + { + memcpy( user_sensor_data_temp + user_sensor_temp_len, user_sensor_data, user_sensor_data_len ); // sensor data + user_sensor_temp_len = user_sensor_temp_len + user_sensor_data_len; + } + //package len + user_sensor_data_temp[1] = user_sensor_temp_len; + + app_task_lora_tx_queue( user_sensor_data_temp, user_sensor_temp_len, true, false ); + + user_sensor_data_len = 0; + hal_mcu_trace_print("user sensor datas uplink:"); + for(uint8_t u8i = 0; u8i < user_sensor_temp_len; u8i++ ) + { + hal_mcu_trace_print("%02x ",user_sensor_data_temp[u8i]); + } + hal_mcu_trace_print("\r\n"); + + state_all = 0; +} diff --git a/libraries/LBM_packet/src/internal/main_packet.h b/libraries/LBM_packet/src/internal/main_packet.h new file mode 100644 index 000000000..1ddce0480 --- /dev/null +++ b/libraries/LBM_packet/src/internal/main_packet.h @@ -0,0 +1,35 @@ +#ifndef _APP_TASK_PACKET_H_ +#define _APP_TASK_PACKET_H_ + +#include +#include +#include "main_lora.h" + +//uplink +#define DATA_ID_UP_PACKET_GNSS_RAW 0x12 +#define DATA_ID_UP_PACKET_GNSS_END 0x13 +#define DATA_ID_UP_PACKET_WIFI_RAW 0x14 +#define DATA_ID_UP_PACKET_BLE_RAW 0x15 +#define DATA_ID_UP_PACKET_POS_STATUS 0x16 + +#define DATA_ID_UP_PACKET_USER_SENSOR 0x17 +#define DATA_ID_UP_PACKET_FACT_SENSOR 0x18 + +//downlink +#define DATA_ID_DOWN_PACKET_USER_CODE 0x8E + + + +extern uint8_t app_lora_packet_buffer[LORAWAN_APP_DATA_MAX_SIZE]; +extern uint8_t app_lora_packet_len; +extern uint8_t factory_sensor_temp_len; +extern uint8_t factory_sensor_data_temp[64]; + +void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ); +void default_param_load(void); + + +void app_task_factory_sensor_data_send( void ); +void app_task_user_sensor_data_send( void ); + +#endif diff --git a/libraries/LBM_packet/src/internal/main_sensor.cpp b/libraries/LBM_packet/src/internal/main_sensor.cpp new file mode 100644 index 000000000..74e3ae781 --- /dev/null +++ b/libraries/LBM_packet/src/internal/main_sensor.cpp @@ -0,0 +1,1017 @@ +#include "Lbm_packet.hpp" + +#include +#include + + +#include +#include +#include "internal/nrf_hal/gpio.hpp" +#include "internal/nrf_hal/gpiote.hpp" + +#include "LIS3DHTR.h" +#include "SensirionI2CSht4x.h" +#include "SensirionI2CSgp41.h" +#include "VOCGasIndexAlgorithm.h" +#include "Dps310.h" +#include "Si115X.h" +#include "Ultrasonic.h" + +//IIC slave device addr +#define LIS3DHTR_I2C_ADDRESS (LIS3DHTR_ADDRESS_UPDATED) +#define SHT4X_I2C_ADDRESS (0x44) +#define SI1151_I2C_ADDRESS (0x53) +#define SGP41_I2C_ADDRESS (0x59) +#define DP310_IIC_ADDRESS (0x77) + + +uint8_t factory_sensor_data_len = 20; +uint8_t factory_sensor_data[20] = { 0 }; // for factory default sensor + +uint8_t user_sensor_data_len = 0; // for the sensor that define by user +uint8_t user_sensor_data[40] = { 0 }; + +uint16_t sound_sample_index = 0; // sound sensor sampling times before data was uploaded to lorawan +uint16_t sound_average_data = 0; + +volatile bool iic_mutex_status = false; // Ensure that devices are mutually exclusive when using the iic bus + +uint32_t lis3dhtr_irq_count = 0; +float mv_per_lsb = 3600.0F/1024.0F; // 10-bit ADC with 3.6V input range +float acc_convert = 9.80F; // 1g = 9.8m/s2 + +uint32_t sensor_types = 0; +static float sampling_interval = 10.f; // sampling period for sgp41 + +bool relay_switch_on = false; // relay + +//Sensor raw data +float sht4x_temperature = 0.0; +float sht4x_humidity = 0.0; +float lis3dhtr_x = 0.0; +float lis3dhtr_y = 0.0; +float lis3dhtr_z = 0.0; +int32_t sgp41_voc_index = 0; +float UV_val = 0.0; +uint16_t sound_val = 0; +uint16_t ultrasonic_distance_cm = 0; +uint32_t dps310_pressure_val = 0; + + +//sensor handle +static SensirionI2CSht4x sht4x; +static LIS3DHTR LIS; +static SensirionI2CSgp41 sgp41; +static Si115X si1151; +Dps310 Dps310PressureSensor = Dps310(); + +static VOCGasIndexAlgorithm voc_algorithm(sampling_interval); // Used to calculate voc_index + +//sensor irq pin +static constexpr int lis3dhtr_irq_pin = PIN_LIS3DHTR_INT2; + +//digital pin +static constexpr int ultrasonic_pin = D0; +static Ultrasonic ultrasonic(ultrasonic_pin); + +static constexpr int relay_pin = D2; +//analog pin +static constexpr int sound_adc_pin = A0; + + + +//irq callback---------------------------------------------------- +void lis3dhtr_irq_callback(void) +{ + lis3dhtr_irq_count ++; +} + +//grove power init ----------------------------------------------------- +void grove_init_power(void) +{ + //power on + digitalWrite(PIN_POWER_SUPPLY_GROVE, HIGH); //grove power on + pinMode(PIN_POWER_SUPPLY_GROVE, OUTPUT); + delay(100); +} + +//sensor available detect----------------------------------------------------- +void sensor_available_detect(void) +{ + Wire.begin(); + for (int addr = 1; addr < 128; addr++) + { + Wire.beginTransmission(addr); + if ( 0 == Wire.endTransmission() ) + { + if(addr==SHT4X_I2C_ADDRESS) + { + sensor_types = sensor_types|sht4x_sensor_type; + } + else if(addr==LIS3DHTR_I2C_ADDRESS) + { + sensor_types = sensor_types|lis3dhtr_sensor_type; + } + else if(addr==SI1151_I2C_ADDRESS ) + { + sensor_types = sensor_types|si1151_sensor_type; + } + else if(addr==SGP41_I2C_ADDRESS) + { + sensor_types = sensor_types|sgp41_sensor_type; + } + else if(addr==DP310_IIC_ADDRESS) + { + sensor_types = sensor_types|dps310_sensor_type; + } + else + { + + } + hal_mcu_trace_print("Found: 0x%02x ",addr); + } + } + hal_mcu_trace_print("\r\n"); +} + +bool iic_slave_available_detect(uint8_t slave_addr) +{ + if(slave_addr<1 || slave_addr >127) + { + return false; + } + Wire.beginTransmission(slave_addr); + if ( 0 == Wire.endTransmission() ) + { + return true; + } + return false; +} + +bool sht4x_available_detect(void) +{ + if(iic_slave_available_detect(SHT4X_I2C_ADDRESS)) + { + sensor_types = sensor_types|sht4x_sensor_type; + return true; + } + return false; +} +bool lis3dhtr_available_detect(void) +{ + if(iic_slave_available_detect(LIS3DHTR_I2C_ADDRESS)) + { + sensor_types = sensor_types|lis3dhtr_sensor_type; + return true; + } + return false; +} +bool si1151_available_detect(void) +{ + if(iic_slave_available_detect(SI1151_I2C_ADDRESS)) + { + sensor_types = sensor_types|si1151_sensor_type; + return true; + } + return false; +} +bool sgp41_available_detect(void) +{ + if(iic_slave_available_detect(SGP41_I2C_ADDRESS)) + { + sensor_types = sensor_types|sgp41_sensor_type; + return true; + } + return false; +} +bool dps310_available_detect(void) +{ + if(iic_slave_available_detect(DP310_IIC_ADDRESS)) + { + sensor_types = sensor_types|dps310_sensor_type; + return true; + } + return false; +} + +//hardwar init----------------------------------------------------- +void sensor_init_detect(void) +{ + //power on + grove_init_power(); + + //found available sensor + sensor_available_detect(); + + #if(SOUND_SENSOR_AVAILABLE == 1) + sensor_types = sensor_types|sound_sensor_type; + #endif + #if(ULTRASONIC_SENSOR_AVAILABLE == 1) + sensor_types = sensor_types|ultrasonic_sensor_type; + #endif + + //sht4x + sensor_sht4x_init(); + + //lis3dhtr + sensor_lis3dhtr_init(); + + //sgp41 + sensor_sgp41_init(); + + //si1151 + sensor_si1151_init(); + + //dps310 + sensor_dps310_init(); +} + +//sht4x +void sensor_sht4x_init(void) +{ + if(sensor_types&sht4x_sensor_type) + { + sht4x.begin(Wire); + } +} + +//lis3dhtr +void sensor_lis3dhtr_init(void) +{ + if(sensor_types&lis3dhtr_sensor_type) + { + pinMode(lis3dhtr_irq_pin, INPUT); + attachInterrupt(lis3dhtr_irq_pin, lis3dhtr_irq_callback, ISR_DEFERRED | FALLING); //RISING + + LIS.begin(Wire, LIS3DHTR_ADDRESS_UPDATED); + LIS.setInterrupt(); + } +} + +//sgp41 +void sensor_sgp41_init(void) +{ + if(sensor_types&sgp41_sensor_type) + { + sgp41.begin(Wire); + } +} + +//si1151 +void sensor_si1151_init(void) +{ + if(sensor_types&si1151_sensor_type) + { + si1151.Begin(); + } +} +//dps310 +void sensor_dps310_init(void) +{ + if(sensor_types&dps310_sensor_type) + { + Dps310PressureSensor.begin(Wire); + } +} + + +//get sensor data ----------------------------------------------------- + +//sht4x-------------------- +//Consume 12ms +bool sht4x_data_get(float* temperature, float* humidity) // 11ms +{ + if(iic_mutex_status == true) + return false; + iic_mutex_status = true; + +#if(SENSOR_HOT_SWAPPABLE_DETECT == 1) + if(sht4x_available_detect()) + { + sensor_sht4x_init(); + } +#endif + if(sensor_types&sht4x_sensor_type) + { + uint16_t error; + error = sht4x.measureHighPrecision(*temperature, *humidity); + if (error == 0) + { + uint8_t humi = *humidity; + if(humi >= 100) //Prevents the humidity calculation from being greater than 100% + { + *humidity = 100.f; + } + iic_mutex_status = false; + return true; + } + } + else + { + iic_mutex_status = false; + return false; + } + iic_mutex_status = false; + return true; +} + +//lis3dhtr-------------------- +//Consume 1ms +bool lis3dhtr_data_get(float* x, float* y, float* z) +{ + static uint32_t irq_count = 0; + if(iic_mutex_status == true) + return false; + iic_mutex_status = true; + +#if(SENSOR_HOT_SWAPPABLE_DETECT == 1) + if(lis3dhtr_available_detect()) + { + sensor_lis3dhtr_init(); + } +#endif + + if(sensor_types&lis3dhtr_sensor_type) + { + uint8_t flag = 0; + LIS.getIntStatus(&flag); + LIS.getAcceleration(x, y, z); + if(irq_count != lis3dhtr_irq_count) + { + irq_count = lis3dhtr_irq_count; + state_all = state_all|TRACKER_STATE_BIT2_MOT_BEG; + app_task_track_motion_index_update(); + } + else + { + state_all = state_all|TRACKER_STATE_BIT4_DEV_STATIC; + } + iic_mutex_status = false; + return true; + } + else + { + iic_mutex_status = false; + return false; + } + iic_mutex_status = false; + return true; +} + +//sgp41-------------------- +//Consume 250ms +bool sgp41_data_get(float temperature, float humidity, int32_t* voc_index) +{ + uint16_t compensationT; + uint16_t compensationRh; + + if(iic_mutex_status == true) + return false; + iic_mutex_status = true; + +#if(SENSOR_HOT_SWAPPABLE_DETECT == 1) + if(sgp41_available_detect()) + { + sensor_sgp41_init(); + } +#endif + + //temperature and humidity for SGP internal compensation + if(sensor_types&sht4x_sensor_type) + { + // convert temperature and humidity to ticks as defined by sgp41 + // interface + // NOTE: in case you read RH and T raw signals check out the + // ticks specification in the datasheet, as they can be different for + // different sensors + compensationT = static_cast((temperature + 45) * 65535 / 175); + compensationRh = static_cast(humidity * 65535 / 100); + } + else + { + compensationRh = 0x8000; // initialized to default value in ticks as defined by sgp41 + compensationT = 0x6666; // initialized to default value in ticks as defined by sgp41 + } + if(sensor_types&sgp41_sensor_type) + { + uint16_t srawVoc = 0; + uint16_t srawNox = 0; + uint16_t error; + // Request a first measurement to heat up the plate (ignoring the result) + error = sgp41.measureRawSignals(compensationRh, compensationT, srawVoc,srawNox); + if (error) + { + iic_mutex_status = false; + return false; + } + delay(140); + // Request the measurement values + error = sgp41.measureRawSignals(compensationRh, compensationT, srawVoc,srawNox); + if (error) + { + iic_mutex_status = false; + return false; + } + error = sgp41.turnHeaterOff(); //for low power consumption + if (error) + { + iic_mutex_status = false; + return false; + } + // Process raw signals by Gas Index Algorithm to get the VOC index values + *voc_index = voc_algorithm.process(srawVoc); + iic_mutex_status = false; + return true; + } + else + { + iic_mutex_status = false; + return false; + } + iic_mutex_status = false; + return true; +} + +//In order to calculate the voc_index, it is necessary to periodically sample sgp41 +float sgp41_sampling_period_get(void) +{ + return voc_algorithm.get_sampling_interval(); +} + + +//si1151-------------------- +//consume 4ms +bool si1151_data_get(float* UV_val) +{ + if(iic_mutex_status == true) + return false; + iic_mutex_status = true; +#if(SENSOR_HOT_SWAPPABLE_DETECT == 1) + if(si1151_available_detect()) + { + sensor_si1151_init(); + } +#endif + if(sensor_types&si1151_sensor_type) + { + *UV_val = si1151.ReadHalfWord_UV(); + iic_mutex_status = false; + return true; + } + else + { + iic_mutex_status = false; + return false; + } + iic_mutex_status = false; + return true; +} + + +//sound sensor-------------------- +//consume 30ms +bool sound_data_get(uint16_t* sound_val) +{ + static bool init_average = false; + static uint8_t index = 1; + + uint32_t sum = 0; + int adc_val = 0; + uint16_t temp_val = 0; + + if(sensor_types&sound_sensor_type) + { + for(int i=0; i<16; i++) + { + sum += analogRead(sound_adc_pin); + delay(2); + } + adc_val = sum >>4; + *sound_val = (uint16_t)((float)adc_val * mv_per_lsb); + + //average + temp_val = *sound_val; + sum = sound_average_data*sound_sample_index; + + sound_sample_index ++; + sound_average_data = (sum+temp_val)/sound_sample_index; + + return true; + } + return false; +} +uint16_t sound_average_get(void) +{ + + return sound_average_data; +} + +//ultrasonic sensor-------------------- +//less than 40ms +bool ultrasonic_distance_get(uint16_t* distance_cm) +{ + if(sensor_types&ultrasonic_sensor_type) + { + *distance_cm = ultrasonic.MeasureInCentimeters(40000); //40ms timeout 4m => 4*2 /340 *1000 = 23.5ms Velocity of sound:340m/s + if(*distance_cm > 400) + *distance_cm = 0xFFFF; + return true; + } + return false; +} + +//DPS310 sensor-------------------- +//consume 219ms +bool dps310_data_get(uint32_t* pressure_val) +{ + float Detection_pressure; + uint8_t oversampling = 7; + int16_t ret; + int i; + int size = 10; + + if(iic_mutex_status == true) + return false; + iic_mutex_status = true; + +#if(SENSOR_HOT_SWAPPABLE_DETECT == 1) + if(dps310_available_detect()) + { + sensor_dps310_init(); + } +#endif + if(sensor_types&dps310_sensor_type) + { + ret = Dps310PressureSensor.measurePressureOnce(Detection_pressure, oversampling); + *pressure_val = Detection_pressure; + iic_mutex_status = false; + return true; + } + else + { + iic_mutex_status = false; + return false; + } + iic_mutex_status = false; + return true; +} + +//factory sensor-------------------- +void sensor_datas_get(void) +{ + //temperture & humidity + if(sht4x_data_get(&sht4x_temperature, &sht4x_humidity)) + { + int16_t temp = sht4x_temperature*10; + uint8_t humi = sht4x_humidity; + memcpyr( factory_sensor_data, ( uint8_t * )( &temp ), 2 ); //temperature + + factory_sensor_data[2] = humi; //humidity + } + else + { + factory_sensor_data[0] = 0x80; + factory_sensor_data[1] = 0x00; + + factory_sensor_data[2] = 0x80; + } + + //Atmospheric pressure + if(dps310_data_get(&dps310_pressure_val)) + { + factory_sensor_data[3] = (dps310_pressure_val>>16)&0xFF; //pressure + factory_sensor_data[4] = (dps310_pressure_val>>8)&0xFF; + factory_sensor_data[5] = dps310_pressure_val&0xFF; + } + else + { + //pressure + factory_sensor_data[3] = 0x80; + factory_sensor_data[4] = 0x00; + factory_sensor_data[5] = 0x00; + } + + //ultrasonic + if(ultrasonic_distance_get(&ultrasonic_distance_cm)) + { + memcpyr( &factory_sensor_data[6], ( uint8_t * )( &ultrasonic_distance_cm ), 2 ); //distance + } + else + { + //distance + factory_sensor_data[6] = 0x80; + factory_sensor_data[7] = 0x00; + } + + //UV + if(si1151_data_get(&UV_val)) + { + uint16_t temp_val = UV_val*100; + memcpyr( &factory_sensor_data[8], ( uint8_t * )( &temp_val ), 2 ); //UV + } + else + { + //uv + factory_sensor_data[8] = 0x80; + factory_sensor_data[9] = 0x00; + } + + //voc index + if(sgp41_data_get(sht4x_temperature, sht4x_humidity, &sgp41_voc_index)) + { + factory_sensor_data[10] = (sgp41_voc_index>>8)&0xFF; //voc_index + factory_sensor_data[11] = sgp41_voc_index&0xFF; + } + else + { + + factory_sensor_data[10] = 0x80; + factory_sensor_data[11] = 0x00; + } + + //sound + if(sound_data_get(&sound_val)) + { + sound_val = sound_average_get(); + memcpyr( &factory_sensor_data[12], ( uint8_t * )( &sound_val ), 2 ); //sound vcc + } + else + { + + factory_sensor_data[12] = 0x80; + factory_sensor_data[13] = 0x00; + } + + //3-axis + if(lis3dhtr_data_get(&lis3dhtr_x, &lis3dhtr_y, &lis3dhtr_z)) + { + int16_t acc_x; + int16_t acc_y; + int16_t acc_z; + + acc_x = 100*lis3dhtr_x*acc_convert; + acc_y = 100*lis3dhtr_y*acc_convert; + acc_z = 100*lis3dhtr_z*acc_convert; + + memcpyr( &factory_sensor_data[14], ( uint8_t * )( &acc_x ), 2 ); //x-axis + memcpyr( &factory_sensor_data[16], ( uint8_t * )( &acc_y ), 2 ); //y-axis + memcpyr( &factory_sensor_data[18], ( uint8_t * )( &acc_z ), 2 ); //z-axis + } + else + { + + factory_sensor_data[14] = 0x80; + factory_sensor_data[15] = 0x00; + + factory_sensor_data[16] = 0x80; + factory_sensor_data[17] = 0x00; + //z-axis + factory_sensor_data[18] = 0x80; + factory_sensor_data[19] = 0x00; + } + factory_sensor_data_len = 20; +} + + +// +bool single_fact_sensor_data_get(uint8_t type) +{ + switch(type) + { + case sht4x_sensor_type: + //temperture & humidity + if(sht4x_data_get(&sht4x_temperature, &sht4x_humidity)) + { + return true; + } + break; + case lis3dhtr_sensor_type: + if(lis3dhtr_data_get(&lis3dhtr_x, &lis3dhtr_y, &lis3dhtr_z)) + { + return true; + } + break; + case dps310_sensor_type: + if(dps310_data_get(&dps310_pressure_val)) + { + return true; + } + break; + case sgp41_sensor_type: + if(sgp41_data_get(sht4x_temperature, sht4x_humidity, &sgp41_voc_index)) + { + return true; + } + break; + case si1151_sensor_type: + if(si1151_data_get(&UV_val)) + { + return true; + } + break; + case sound_sensor_type: + if(sound_data_get(&sound_val)) + { + return true; + } + break; + case ultrasonic_sensor_type: + if(ultrasonic_distance_get(&ultrasonic_distance_cm)) + { + return true; + } + break; + default: + break; + } + return false; +} + + +void single_fact_sensor_display_results(uint8_t type) +{ + switch(type) + { + case sht4x_sensor_type: + //temperture & humidity + if(sensor_types&sht4x_sensor_type) + { + printf("temperature:%0.2f, humidity:%0.2f%%\r\n",sht4x_temperature, sht4x_humidity); + } + break; + case lis3dhtr_sensor_type: + //3-axis + if(sensor_types&lis3dhtr_sensor_type) + { + printf("x:%0.2f y:%0.2f z:%0.2f\r\n",lis3dhtr_x,lis3dhtr_y,lis3dhtr_z); + } + break; + case dps310_sensor_type: + //pressure + if(sensor_types&dps310_sensor_type) + { + printf("pressure value:%u\r\n",dps310_pressure_val); + } + break; + case sgp41_sensor_type: + //voc index + if(sensor_types&sgp41_sensor_type) + { + printf("voc_index:%d\r\n",sgp41_voc_index); + } + break; + case si1151_sensor_type: + //uv + if(sensor_types&si1151_sensor_type ) + { + printf("UV val:%0.2f\r\n",UV_val); + } + break; + case sound_sensor_type: + //sound + printf("sound_val:%d mV\r\n",sound_val); + break; + case ultrasonic_sensor_type: + //distance + printf("distance:%d cm\r\n",ultrasonic_distance_cm); + break; + default: + break; + } +} + +void factory_sensor_data_combined(void) +{ + //temperture & humidity + if(sensor_types&sht4x_sensor_type) + { + int16_t temp = sht4x_temperature*10; + uint8_t humi = sht4x_humidity; + memcpyr( factory_sensor_data, ( uint8_t * )( &temp ), 2 ); //temperature + + factory_sensor_data[2] = humi; //humidity + } + else + { + factory_sensor_data[0] = 0x80; + factory_sensor_data[1] = 0x00; + + factory_sensor_data[2] = 0x80; + } + + //Atmospheric pressure + if(sensor_types&dps310_sensor_type) + { + factory_sensor_data[3] = (dps310_pressure_val>>16)&0xFF; //pressure + factory_sensor_data[4] = (dps310_pressure_val>>8)&0xFF; + factory_sensor_data[5] = dps310_pressure_val&0xFF; + } + else + { + //pressure + factory_sensor_data[3] = 0x80; + factory_sensor_data[4] = 0x00; + factory_sensor_data[5] = 0x00; + } + + //ultrasonic + if((sensor_types&ultrasonic_sensor_type) && (ultrasonic_distance_cm != 0xFFFF)) + { + memcpyr( &factory_sensor_data[6], ( uint8_t * )( &ultrasonic_distance_cm ), 2 ); //distance + } + else + { + //distance + factory_sensor_data[6] = 0x80; + factory_sensor_data[7] = 0x00; + } + + //UV + if(sensor_types&si1151_sensor_type) + { + uint16_t temp_val = UV_val*100; + memcpyr( &factory_sensor_data[8], ( uint8_t * )( &temp_val ), 2 ); //UV + } + else + { + //uv + factory_sensor_data[8] = 0x80; + factory_sensor_data[9] = 0x00; + } + + //voc index + if(sensor_types&sgp41_sensor_type) + { + factory_sensor_data[10] = (sgp41_voc_index>>8)&0xFF; //voc_index + factory_sensor_data[11] = sgp41_voc_index&0xFF; + } + else + { + + factory_sensor_data[10] = 0x80; + factory_sensor_data[11] = 0x00; + } + + //sound + if(sensor_types&sound_sensor_type) + { + sound_val = sound_average_get(); + memcpyr( &factory_sensor_data[12], ( uint8_t * )( &sound_val ), 2 ); //sound vcc + } + else + { + factory_sensor_data[10] = 0x80; + factory_sensor_data[11] = 0x00; + } + + //3-axis + if(sensor_types&lis3dhtr_sensor_type) + { + int16_t acc_x; + int16_t acc_y; + int16_t acc_z; + + acc_x = 100*lis3dhtr_x*acc_convert; + acc_y = 100*lis3dhtr_y*acc_convert; + acc_z = 100*lis3dhtr_z*acc_convert; + + memcpyr( &factory_sensor_data[14], ( uint8_t * )( &acc_x ), 2 ); //x-axis + memcpyr( &factory_sensor_data[16], ( uint8_t * )( &acc_y ), 2 ); //y-axis + memcpyr( &factory_sensor_data[18], ( uint8_t * )( &acc_z ), 2 ); //z-axis + } + else + { + + factory_sensor_data[14] = 0x80; + factory_sensor_data[15] = 0x00; + + factory_sensor_data[16] = 0x80; + factory_sensor_data[17] = 0x00; + //z-axis + factory_sensor_data[18] = 0x80; + factory_sensor_data[19] = 0x00; + } +} + +void app_sensor_buffer_display_results( void ) +{ + printf("sensor datas:"); + for(uint8_t u8i = 0; u8i < 20; u8i++ ) + { + printf("%02x ",factory_sensor_data[u8i]); + } + printf("\r\n"); +} + +void app_sensor_data_display_results( void ) +{ + //temperture & humidity + if(sensor_types&sht4x_sensor_type) + { + printf("temperature:%0.2f, humidity:%0.2f%%\r\n",sht4x_temperature, sht4x_humidity); + } + + //pressure + if(sensor_types&dps310_sensor_type) + { + printf("pressure value:%u\r\n",dps310_pressure_val); + } + + //distance + printf("distance:%d cm\r\n",ultrasonic_distance_cm); + + //uv + if(sensor_types&si1151_sensor_type ) + { + printf("UV val:%0.2f\r\n",UV_val); + } + + //voc index + if(sensor_types&sgp41_sensor_type) + { + printf("voc_index:%d\r\n",sgp41_voc_index); + } + + //sound + + printf("sound_val:%d mV\r\n",sound_val); + + //3-axis + if(sensor_types&lis3dhtr_sensor_type) + { + printf("x:%0.2f y:%0.2f z:%0.2f\r\n",lis3dhtr_x,lis3dhtr_y,lis3dhtr_z); + } +} + +void relay_status_control( bool switch_on ) +{ + if(switch_on) + { + digitalWrite(relay_pin, HIGH); + pinMode(relay_pin, OUTPUT); + relay_switch_on = true; + } + else + { + digitalWrite(relay_pin, LOW); + pinMode(relay_pin, OUTPUT); + relay_switch_on = false; + } +} +bool relay_status_on( void ) +{ + return relay_switch_on; +} + + +//user sensor-------------------- + +bool user_sensor_datas_set(uint8_t *buff, uint8_t len) +{ + //it's must be 4bytes/group + if((len > 40) || (len%4!=0)) + { + return false; + } + else if(len != 0) + { + memcpy(user_sensor_data,buff,len); + user_sensor_data_len = len; + return true; + } + else + { + return true; + } + return true; +} + +void app_user_data_display_results( void ) +{ + printf("user sensor datas:"); + for(uint8_t u8i = 0; u8i < user_sensor_data_len; u8i++ ) + { + printf("%02x",user_sensor_data[u8i]); + } + printf("\r\n"); +} + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/LBM_packet/src/internal/main_sensor.h b/libraries/LBM_packet/src/internal/main_sensor.h new file mode 100644 index 000000000..2129c5272 --- /dev/null +++ b/libraries/LBM_packet/src/internal/main_sensor.h @@ -0,0 +1,315 @@ + +#ifndef _MAIN_SENSOR_H_ +#define _MAIN_SENSOR_H_ + +#include +#include + + + +//If defined as 1:detect iic slave device hot swap function +#ifndef SENSOR_HOT_SWAPPABLE_DETECT +#define SENSOR_HOT_SWAPPABLE_DETECT 1 +#endif + + +//This parameter is defined based on whether the actual sensor is connected +#define SOUND_SENSOR_AVAILABLE 1 // for mission pack the sound sensor is delivered with the system by default +#define ULTRASONIC_SENSOR_AVAILABLE 1 // for mission pack the ultrasonic sensor is delivered with the system by default + + + +//sensor type +#define sht4x_sensor_type (0x01<<0) +#define lis3dhtr_sensor_type (0x01<<1) +#define dps310_sensor_type (0x01<<2) +#define sgp41_sensor_type (0x01<<3) +#define si1151_sensor_type (0x01<<4) +#define sound_sensor_type (0x01<<5) +#define ultrasonic_sensor_type (0x01<<6) + + + +extern float sht4x_temperature; +extern float sht4x_humidity; +extern float lis3dhtr_x; +extern float lis3dhtr_y; +extern float lis3dhtr_z; +extern int32_t sgp41_voc_index; +extern float UV_val; +extern uint16_t sound_val; +extern uint16_t ultrasonic_distance_cm; +extern uint32_t dps310_pressure_val; + + +extern uint8_t factory_sensor_data_len; +extern uint8_t factory_sensor_data[20]; + +extern uint8_t user_sensor_data_len; +extern uint8_t user_sensor_data[40]; + +extern uint16_t sound_sample_index; +extern uint16_t sound_average_data; + + + +/** + * grove_init_power() - power on for grove. + * + */ +void grove_init_power(void); + +/** + * sensor_available_detect() - detect sensor connect. + * + */ +void sensor_available_detect(void); + +/** + * iic_slave_available_detect() - detect iic slave connect. + * + * @param slave_addr iic slave device address. + * + * @return true: connected, false: disconnected. + */ +bool iic_slave_available_detect(uint8_t slave_addr); + +/** + * sht4x_available_detect() - detect iic slave device(sht4x) connect. + * + * @return true: connected, false: disconnected. + */ +bool sht4x_available_detect(void); + +/** + * lis3dhtr_available_detect() - detect iic slave device(lis3dhtr) connect. + * + * @return true: connected, false: disconnected. + */ +bool lis3dhtr_available_detect(void); + +/** + * si1151_available_detect() - detect iic slave device(si1151) connect + * + * @return true: connected, false: disconnected + */ +bool si1151_available_detect(void); + +/** + * sgp41_available_detect() - detect iic slave device(sgp41) connect + * + * @return true: connected, false: disconnected + */ +bool sgp41_available_detect(void); + +/** + * dps310_available_detect() - detect iic slave device(dps310) connect + * + * @return true: connected, false: disconnected + */ +bool dps310_available_detect(void); + +/** + * sensor_init_detect() - Initializes the sensor device + * + */ +void sensor_init_detect(void); + +/** + * sensor_sht4x_init() - Initializes sht4x + * + */ +void sensor_sht4x_init(void); + +/** + * sensor_lis3dhtr_init() - Initializes lis3dhtr + * + */ +void sensor_lis3dhtr_init(void); + +/** + * sensor_sgp41_init() - Initializes sgp41 + * + */ +void sensor_sgp41_init(void); + +/** + * sensor_si1151_init() - Initializes si1151 + * + */ +void sensor_si1151_init(void); + +/** + * sensor_dps310_init() - Initializes dps310 + * + */ +void sensor_dps310_init(void); + +/** + * sensor_datas_get() - Get all sensor data + * + */ +void sensor_datas_get(void); //missioin pack + +/** + * sht4x_data_get() - Get sht4x data + * + * @param temperature Temperature in degrees celsius. + * + * @param humidity Humidity in percent relative humidity. + * + * @return true: success, false: fail + */ +bool sht4x_data_get(float* temperature, float* humidity); + +/** + * lis3dhtr_data_get() - Get lis3dhtr data. + * + * @param x X-Axis Acceleration Data of LIS3DHTR. + * + * @param y Y-Axis Acceleration Data of LIS3DHTR. + * + * @param z Z-Axis Acceleration Data of LIS3DHTR. + * + * @return true: success, false: fail . + */ +bool lis3dhtr_data_get(float* x, float* y, float* z); + +/** + * sgp41_data_get() - Get sgp41 data,use Algorithm to calculate the voc index. + * + * @param temperature temperature compensation in degrees celsius. + * + * @param humidity humidity compensation in percent relative humidity. + * + * @param voc_index VOC index values. + * + * @return true: success, false: fail + */ +bool sgp41_data_get(float temperature, float humidity, int32_t* voc_index); + +/** + * sgp41_sampling_period_get() - Get sgp41 sampling period + * + * @return sgp41 sampling period + */ +float sgp41_sampling_period_get(void); + +/** + * si1151_data_get() - Get si1151 data + * + * @param UV_val Ultraviolet index value. + * + * @return true: success, false: fail + */ +bool si1151_data_get(float* UV_val); + +/** + * sound_data_get() - Get sound data + * + * @param sound_val Sound voltage value + * + * @return true: success, false: fail + */ +bool sound_data_get(uint16_t* sound_val); + +/** + * sound_average_get() - Get sound average data + * + * @return sound average voltage data + */ +uint16_t sound_average_get(void); + +/** + * ultrasonic_distance_get() - Get ultrasonic distance data + * + * @param distance_cm Distance, in cm + * + * @return true: success, false: fail + */ +bool ultrasonic_distance_get(uint16_t* distance_cm); + +/** + * dps310_data_get() - Get dps310 data + * + * @param pressure_val Air pressure value + * + * @return true: success, false: fail + */ +bool dps310_data_get(uint32_t* pressure_val); + +/** + * single_fact_sensor_data_get() - Get individual sensor data + * + * @param type sensor type + * + * @return true: success, false: fail + */ +bool single_fact_sensor_data_get(uint8_t type); + +/** + * factory_sensor_data_combined() - Combine all sensor data + * + * @return true: success, false: fail + */ +void factory_sensor_data_combined(void); + +/** + * relay_status_control() - control relay on/off + * + * @param switch_on true:on false:off + * + * @return true: success, false: fail + */ +void relay_status_control( bool switch_on ); + +/** + * relay_status_on() - get relay on/off status + * + * @return true: on, false: off + */ +bool relay_status_on( void ); + + +/** + * app_sensor_buffer_display_results() - print sensor buffer + * + */ +void app_sensor_buffer_display_results( void ); + +/** + * app_sensor_data_display_results() - print all sensor raw data + * + */ +void app_sensor_data_display_results( void ); + +/** + * app_sensor_data_display_results() - print sensor raw data by sensor type + * + * @param type sensor type + * + */ +void single_fact_sensor_display_results(uint8_t type); + + +//user data + +/** + * user_sensor_datas_set() - set user data to user data buffer + * + * @param buff user datas + * + * @param len user datas len(must be a 4bytes/group) + * + * @return true: success, false: fail + * + */ +bool user_sensor_datas_set(uint8_t *buff, uint8_t len); + +/** + * app_user_data_display_results() - print user data buffer + * + */ +void app_user_data_display_results( void ); + +#endif diff --git a/libraries/LBM_packet-main/src/internal/main_track.cpp b/libraries/LBM_packet/src/internal/main_track.cpp similarity index 50% rename from libraries/LBM_packet-main/src/internal/main_track.cpp rename to libraries/LBM_packet/src/internal/main_track.cpp index 7ceacde41..a5e3a054c 100644 --- a/libraries/LBM_packet-main/src/internal/main_track.cpp +++ b/libraries/LBM_packet/src/internal/main_track.cpp @@ -31,7 +31,6 @@ uint8_t tracker_scan_temp_len = 0; uint8_t tracker_scan_data_temp[64] = { 0 }; uint8_t tracker_scan_type = TRACKER_SCAN_BLE_WIFI_GPS; // 0: gps, 1: wifi, 2: ble, 3: gps/wifi, 4: gps/ble, 5: gps/wifi/ble -uint8_t tracker_sensor_en = TRACKER_SENSOR_ON; // 0: sensor data off, 1: sensor data on uint32_t state_all = 0; @@ -45,7 +44,6 @@ uint32_t app_task_track_time_stamp = 0; - uint32_t app_task_track_get_utc( void ) { uint32_t utc_lns = 0, utc_ble = 0; @@ -76,31 +74,22 @@ void app_task_track_motion_index_clear( void ) motion_index = 0; } +//track------------------------------------------------- void app_task_track_scan_send( void ) { - int16_t temp = 0; - uint16_t light = 0; - int8_t battery = 0; uint8_t motion_index_temp = 0; memset( tracker_scan_data_temp, 0, sizeof( tracker_scan_data_temp )); tracker_scan_temp_len = 0; - if(( state_all & TRACKER_STATE_BIT3_MOT_END ) == TRACKER_STATE_BIT3_MOT_END ) - { - motion_index_temp = motion_index_backup; - } - else - { - motion_index_temp = motion_index; - } + motion_index_temp = motion_index; -#if TRACKER_DATA_SEND - + //Location failure if( gnss_mw_custom_send_buffer_num == 0 && tracker_wifi_scan_len == 0 && tracker_ble_scan_len == 0 ) { tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_POS_STATUS; + //Location failure type if(( app_task_lora_clock_is_synch( ) == false ) || ( mw_gnss_event_state == GNSS_MW_EVENT_ERROR_NO_TIME )) { tracker_scan_data_temp[1] = 13; // sync time fail @@ -114,33 +103,29 @@ void app_task_track_scan_send( void ) tracker_scan_data_temp[1] = tracker_scan_type + 1; } + //event status tracker_scan_data_temp[2] = ( state_all >> 16 ) & 0xff; tracker_scan_data_temp[3] = ( state_all >> 8 ) & 0xff; tracker_scan_data_temp[4] = ( state_all ) & 0xff; tracker_scan_temp_len += 5; - // uint32_t utc_temp = app_task_track_get_utc( ); + + //utc time uint32_t utc_temp = app_task_track_time_stamp; memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &utc_temp ), 4 ); tracker_scan_temp_len += 4; - if( tracker_sensor_en ) - { - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &temperture_val ), 2 ); - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len + 2, ( uint8_t * )( &light_val ), 2 ); - tracker_scan_temp_len += 4; - } - else + + hal_mcu_trace_print("Location failure uplink:"); + for(uint8_t u8i = 0; u8i < tracker_scan_temp_len; u8i++ ) { - uint16_t data_temp = 0x8000; - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &data_temp ), 2 ); - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len + 2, ( uint8_t * )( &data_temp ), 2 ); - tracker_scan_temp_len += 4; + hal_mcu_trace_print("%02x",tracker_scan_data_temp[u8i]); } - memcpy( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &battery ), 1 ); - tracker_scan_temp_len += 1; + hal_mcu_trace_print("\r\n"); + + app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, true, false ); - app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, false, false ); } + //Location success #if TRACKER_GPS_EN if( gnss_mw_custom_send_buffer_num ) { @@ -179,152 +164,115 @@ void app_task_track_scan_send( void ) gnss_mw_custom_send_buffer[len_array[gnss_raw_num - 1]][0] |= 0x80; // set last raw byte[0] high bit7 uint8_t fragment_total = gnss_raw_num + 1; - if( tracker_sensor_en ) - { - for( uint8_t i = 0; i < gnss_raw_num; i++ ) - { - memset( tracker_scan_data_temp, 0, sizeof( tracker_scan_data_temp )); - tracker_scan_temp_len = 0; - - tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_GNSS_RAW; - tracker_scan_temp_len += 1; - - tracker_scan_data_temp[1] = ( fragment_total << 4 ) + i; // fragment data - tracker_scan_temp_len += 1; - - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &track_gnss_group_id ), 2 ); // group id - tracker_scan_temp_len += 2; - - tracker_scan_data_temp[4] = gnss_mw_custom_send_buffer_len[len_array[i]]; // GNSS raw lenght - tracker_scan_temp_len += 1; - - memcpy( tracker_scan_data_temp + tracker_scan_temp_len, gnss_mw_custom_send_buffer[len_array[i]], gnss_mw_custom_send_buffer_len[len_array[i]] ); - tracker_scan_temp_len += gnss_mw_custom_send_buffer_len[len_array[i]]; - - app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, false, false ); - } + //gnss datas need to subcontract delivery + //these are gnss datas package + for( uint8_t i = 0; i < gnss_raw_num; i++ ) + { memset( tracker_scan_data_temp, 0, sizeof( tracker_scan_data_temp )); tracker_scan_temp_len = 0; - tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_GNSS_SEN_BAT; - tracker_scan_data_temp[1] = ( state_all >> 16 ) & 0xff; - tracker_scan_data_temp[2] = ( state_all >> 8 ) & 0xff; - tracker_scan_data_temp[3] = ( state_all ) & 0xff; - tracker_scan_data_temp[4] = motion_index_temp; - tracker_scan_temp_len += 5; - - // uint32_t utc_temp = app_task_track_get_utc( ); - uint32_t utc_temp = app_task_track_time_stamp; - memcpyr( tracker_scan_data_temp + 5, ( uint8_t * )( &utc_temp ), 4 ); - tracker_scan_temp_len += 4; - - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &temperture_val ), 2 ); - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len + 2, ( uint8_t * )( &light_val ), 2 ); - tracker_scan_temp_len += 4; - - memcpy( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &battery ), 1 ); + tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_GNSS_RAW; tracker_scan_temp_len += 1; - tracker_scan_data_temp[tracker_scan_temp_len] = ( fragment_total << 4 ) + gnss_raw_num; // fragment data + // fragment data,package num + tracker_scan_data_temp[1] = ( fragment_total << 4 ) + i; // fragment data,package num tracker_scan_temp_len += 1; + //group id memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &track_gnss_group_id ), 2 ); // group id tracker_scan_temp_len += 2; - app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, false, false ); - } - else - { - for( uint8_t i = 0; i < gnss_raw_num; i++ ) - { - memset( tracker_scan_data_temp, 0, sizeof( tracker_scan_data_temp )); - tracker_scan_temp_len = 0; - - tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_GNSS_RAW; - tracker_scan_temp_len += 1; - - tracker_scan_data_temp[1] = ( fragment_total << 4 ) + i; // fragment data - tracker_scan_temp_len += 1; + //raw data len + tracker_scan_data_temp[4] = gnss_mw_custom_send_buffer_len[len_array[i]]; + tracker_scan_temp_len += 1; - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &track_gnss_group_id ), 2 ); // group id - tracker_scan_temp_len += 2; + //raw data + memcpy( tracker_scan_data_temp + tracker_scan_temp_len, gnss_mw_custom_send_buffer[len_array[i]], gnss_mw_custom_send_buffer_len[len_array[i]] ); + tracker_scan_temp_len += gnss_mw_custom_send_buffer_len[len_array[i]]; + hal_mcu_trace_print("gnss uplink:"); + for(uint8_t u8i = 0; u8i < tracker_scan_temp_len; u8i++ ) + { + hal_mcu_trace_print("%02x",tracker_scan_data_temp[u8i]); + } + hal_mcu_trace_print("\r\n"); + app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, true, false ); + } - tracker_scan_data_temp[4] = gnss_mw_custom_send_buffer_len[len_array[i]]; - tracker_scan_temp_len += 1; + //this is a gnss datas end package + memset( tracker_scan_data_temp, 0, sizeof( tracker_scan_data_temp )); + tracker_scan_temp_len = 0; - memcpy( tracker_scan_data_temp + tracker_scan_temp_len, gnss_mw_custom_send_buffer[len_array[i]], gnss_mw_custom_send_buffer_len[len_array[i]] ); - tracker_scan_temp_len += gnss_mw_custom_send_buffer_len[len_array[i]]; + tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_GNSS_END; - app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, false, false ); - } + //event status + tracker_scan_data_temp[1] = ( state_all >> 16 ) & 0xff; + tracker_scan_data_temp[2] = ( state_all >> 8 ) & 0xff; + tracker_scan_data_temp[3] = ( state_all ) & 0xff; - memset( tracker_scan_data_temp, 0, sizeof( tracker_scan_data_temp )); - tracker_scan_temp_len = 0; + //motion index + tracker_scan_data_temp[4] = motion_index_temp; + tracker_scan_temp_len += 5; - tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_GNSS_BAT; - tracker_scan_data_temp[1] = ( state_all >> 16 ) & 0xff; - tracker_scan_data_temp[2] = ( state_all >> 8 ) & 0xff; - tracker_scan_data_temp[3] = ( state_all ) & 0xff; - tracker_scan_data_temp[4] = motion_index_temp; - tracker_scan_temp_len += 5; + //utc time + uint32_t utc_temp = app_task_track_time_stamp; + memcpyr( tracker_scan_data_temp + 5, ( uint8_t * )( &utc_temp ), 4 ); + tracker_scan_temp_len += 4; - // uint32_t utc_temp = app_task_track_get_utc( ); - uint32_t utc_temp = app_task_track_time_stamp; - memcpyr( tracker_scan_data_temp + 5, ( uint8_t * )( &utc_temp ), 4 ); - tracker_scan_temp_len += 4; + //fragment data + tracker_scan_data_temp[tracker_scan_temp_len] = ( fragment_total << 4 ) + gnss_raw_num; + tracker_scan_temp_len += 1; - memcpy( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &battery ), 1 ); - tracker_scan_temp_len += 1; + //group id + memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &track_gnss_group_id ), 2 ); + tracker_scan_temp_len += 2; - tracker_scan_data_temp[tracker_scan_temp_len] = ( fragment_total << 4 ) + gnss_raw_num; // fragment data - tracker_scan_temp_len += 1; - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &track_gnss_group_id ), 2 ); // group id - tracker_scan_temp_len += 2; - - app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, false, false ); + hal_mcu_trace_print("gnss uplink:"); + for(uint8_t u8i = 0; u8i < tracker_scan_temp_len; u8i++ ) + { + hal_mcu_trace_print("%02x",tracker_scan_data_temp[u8i]); } + hal_mcu_trace_print("\r\n"); + + app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, true, false ); + //clear buffer gnss_mw_custom_send_buffer_num = 0; for( uint8_t i = 0; i < GNSS_SCAN_GROUP_SIZE_MAX; i++ ) gnss_mw_custom_send_buffer_len[i] = 0; - hal_mcu_trace_print( "GNSS raw group id: 0x%04x\r\n", track_gnss_group_id ); + hal_mcu_trace_print( "GNSS raw group id: 0x%04x\r\n", track_gnss_group_id ); track_gnss_group_id ++; - if(!gnss_group_id_write()) - { - hal_mcu_trace_print( "save gnss raw group id error\r\n" ); - } } #endif #if TRACKER_WIFI_EN if( tracker_wifi_scan_len ) { - if( tracker_sensor_en ) tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_WIFI_SEN_BAT; - else tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_WIFI_BAT; + tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_WIFI_RAW; + //event status tracker_scan_data_temp[1] = ( state_all >> 16 ) & 0xff; tracker_scan_data_temp[2] = ( state_all >> 8 ) & 0xff; tracker_scan_data_temp[3] = ( state_all ) & 0xff; + + //motion index tracker_scan_data_temp[4] = motion_index_temp; + // utc + wifi memcpy( tracker_scan_data_temp + 5, tracker_wifi_scan_data, tracker_wifi_scan_len ); // utc + wifi tracker_scan_temp_len = tracker_wifi_scan_len + 5; + //utc time,the previous UTC time is overwritten here(utc + wifi) uint32_t utc_temp = app_task_track_time_stamp; memcpyr( tracker_scan_data_temp + 5, ( uint8_t * )( &utc_temp ), 4 ); - if( tracker_sensor_en ) + hal_mcu_trace_print("wifi uplink:"); + for(uint8_t u8i = 0; u8i < tracker_scan_temp_len; u8i++ ) { - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &temperture_val ), 2 ); - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len + 2, ( uint8_t * )( &light_val ), 2 ); - tracker_scan_temp_len += 4; + hal_mcu_trace_print("%02x",tracker_scan_data_temp[u8i]); } - - memcpy( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &battery ), 1 ); - tracker_scan_temp_len += 1; - - app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, false, false ); + hal_mcu_trace_print("\r\n"); + app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, true, false ); tracker_wifi_scan_len = 0; } #endif @@ -332,55 +280,41 @@ void app_task_track_scan_send( void ) #if TRACKER_BLE_EN if( tracker_ble_scan_len ) { - if( tracker_sensor_en ) tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_BLE_SEN_BAT; - else tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_BLE_BAT; + tracker_scan_data_temp[0] = DATA_ID_UP_PACKET_BLE_RAW; + //event status tracker_scan_data_temp[1] = ( state_all >> 16 ) & 0xff; tracker_scan_data_temp[2] = ( state_all >> 8 ) & 0xff; tracker_scan_data_temp[3] = ( state_all ) & 0xff; + + //motion index tracker_scan_data_temp[4] = motion_index_temp; - memcpy( tracker_scan_data_temp + 5, tracker_ble_scan_data, tracker_ble_scan_len ); // utc + ble + // utc + ble + memcpy( tracker_scan_data_temp + 5, tracker_ble_scan_data, tracker_ble_scan_len ); tracker_scan_temp_len = tracker_ble_scan_len + 5; + //utc time,the previous UTC time is overwritten here(utc + wifi) uint32_t utc_temp = app_task_track_time_stamp; memcpyr( tracker_scan_data_temp + 5, ( uint8_t * )( &utc_temp ), 4 ); - if( tracker_sensor_en ) + hal_mcu_trace_print("ble uplink:"); + for(uint8_t u8i = 0; u8i < tracker_scan_temp_len; u8i++ ) { - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &temperture_val ), 2 ); - memcpyr( tracker_scan_data_temp + tracker_scan_temp_len + 2, ( uint8_t * )( &light_val ), 2 ); - tracker_scan_temp_len += 4; + hal_mcu_trace_print("%02x",tracker_scan_data_temp[u8i]); } + hal_mcu_trace_print("\r\n"); - memcpy( tracker_scan_data_temp + tracker_scan_temp_len, ( uint8_t * )( &battery ), 1 ); - tracker_scan_temp_len += 1; - - app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, false, false ); + app_task_lora_tx_queue( tracker_scan_data_temp, tracker_scan_temp_len, true, false ); tracker_ble_scan_len = 0; } state_all = 0; #endif -#endif -} - - -void app_task_lora_load_utc_by_cache( void ) -{ - bool result = false; - if( result ) - { - app_gps_lock_in_utc_second = app_utc_param.sync_utc; - hal_mcu_trace_print( "app load old utc ok: %u\r\n", app_gps_lock_in_utc_second ); - } - else - { - hal_mcu_trace_print( "app load old utc fail\r\n" ); - } } + bool app_task_track_gnss_is_busy( void ) { return track_gnss_busy; @@ -392,6 +326,30 @@ bool app_task_track_wifi_is_busy( void ) return track_wifi_busy; } +void tracker_scan_type_set( uint8_t scan_type ) +{ + switch(scan_type) + { + case TRACKER_SCAN_GPS: + tracker_scan_type = TRACKER_SCAN_GPS; + break; + case TRACKER_SCAN_WIFI: + tracker_scan_type = TRACKER_SCAN_WIFI; + break; + case TRACKER_SCAN_BLE: + tracker_scan_type = TRACKER_SCAN_BLE; + break; + case TRACKER_SCAN_BLE_WIFI_GPS: + tracker_scan_type = TRACKER_SCAN_BLE_WIFI_GPS; + break; + default: + tracker_scan_type = TRACKER_SCAN_GPS; + } +} + + + +//group id----------------------------------------- void gnss_group_id_init(void) { uint32_t group_id_temp; @@ -405,6 +363,7 @@ void gnss_group_id_init(void) if ( ret == 0 ) { uint8_t readlen; + ret = lfs_file_rewind(lfs, &file); len = lfs_file_read(lfs, &file, &group_id_temp, len); lfs_file_close(lfs, &file); track_gnss_group_id = group_id_temp; @@ -419,8 +378,9 @@ void gnss_group_id_init(void) lfs_file_write(lfs, &file, &group_id_temp, sizeof(group_id_temp)); lfs_file_close(lfs, &file); } - } + } } + bool gnss_group_id_write(void) { uint32_t group_id_temp; @@ -433,10 +393,9 @@ bool gnss_group_id_write(void) lfs_file_close(lfs, &file); return false; } - ret = lfs_file_read(lfs, &file, &group_id_temp, sizeof(group_id_temp)); ret = lfs_file_rewind(lfs, &file); ret = lfs_file_write(lfs, &file, &group_id_temp, sizeof(group_id_temp)); - lfs_file_close(lfs, &file); + lfs_file_close(lfs, &file); return true; } diff --git a/libraries/LBM_packet-main/src/internal/main_track.h b/libraries/LBM_packet/src/internal/main_track.h similarity index 69% rename from libraries/LBM_packet-main/src/internal/main_track.h rename to libraries/LBM_packet/src/internal/main_track.h index 4974d1981..dfa7c4c99 100644 --- a/libraries/LBM_packet-main/src/internal/main_track.h +++ b/libraries/LBM_packet/src/internal/main_track.h @@ -9,31 +9,24 @@ #define TRACKER_GPS_EN 1 #define TRACKER_WIFI_EN 1 #define TRACKER_BLE_EN 1 -#define TRACKER_DATA_SEND 1 -#define TRACKER_SCAN_MUTEX 1 -#define TEACKER_BATTERY_SEND_INTERVAL 20 -#define TRACKER_SCAN_BLE_WIFI_GPS 7 +#define TRACKER_SCAN_GPS 0 +#define TRACKER_SCAN_WIFI 1 +#define TRACKER_SCAN_BLE 4 +#define TRACKER_SCAN_BLE_WIFI_GPS 7 -#define TRACKER_SENSOR_OFF 0 -#define TRACKER_SENSOR_ON 1 -#define TRACKER_SCAN_EVENT_MOT 0 -#define TRACKER_SCAN_EVENT_TEMP 1 -#define TRACKER_SCAN_EVENT_LIGHT 2 #define TRACKER_STATE_BIT2_MOT_BEG 0x0001 #define TRACKER_STATE_BIT3_MOT_END 0x0002 #define TRACKER_STATE_BIT4_DEV_STATIC 0x0004 #define TRACKER_STATE_BIT5_DEV_SHOCK 0x0008 -#define TRACKER_STATE_BIT6_TEMP_EVENT 0x0010 -#define TRACKER_STATE_BIT7_LIGHT_EVENT 0x0020 -#define TRACKER_STATE_BIT0_SOS 0x0040 + + #define TRACKER_STATE_BIT1_USER 0x0080 -#define TRACKER_GPS_SCAN_TIME_BOOT 180000 extern uint8_t tracker_gps_scan_len; @@ -49,7 +42,6 @@ extern uint8_t tracker_scan_temp_len; extern uint8_t tracker_scan_data_temp[64]; extern uint8_t tracker_scan_type; // 0: gps, 1: wifi, 2: ble, 3: gps/wifi, 4: gps/ble, 5: gps/wifi/ble -extern uint8_t tracker_sensor_en; // 0: sensor data off, 1: sensor data on extern uint32_t state_all; @@ -67,16 +59,16 @@ extern uint32_t app_task_track_time_stamp; void app_task_track_scan_send( void ); -void app_task_track_init_function( void ); uint32_t app_task_track_get_utc( void ); +void tracker_scan_type_set( uint8_t scan_type ); + void app_task_track_set_scan_state( uint32_t bit ); void app_task_track_clear_scan_state( uint32_t bit ); void app_task_track_motion_index_update( void ); void app_task_track_motion_index_clear( void ); -void app_task_lora_load_utc_by_cache( void ); bool app_task_track_wifi_is_busy( void ); bool app_task_track_gnss_is_busy( void ); diff --git a/libraries/LBM_packet-main/src/internal/main_wifi.cpp b/libraries/LBM_packet/src/internal/main_wifi.cpp similarity index 90% rename from libraries/LBM_packet-main/src/internal/main_wifi.cpp rename to libraries/LBM_packet/src/internal/main_wifi.cpp index 545653caa..dd72fc474 100644 --- a/libraries/LBM_packet-main/src/internal/main_wifi.cpp +++ b/libraries/LBM_packet/src/internal/main_wifi.cpp @@ -94,16 +94,17 @@ bool app_wifi_get_results( uint8_t* result, uint8_t *size ) void app_wifi_display_results( void ) { - hal_mcu_trace_print( "Number of results: %u\r\n", wifi_results.nbr_results ); + printf( "Number of results: %u\r\n", wifi_results.nbr_results ); for( uint8_t i = 0; i < wifi_results.nbr_results; i++ ) { for( uint8_t j = 0; j < WIFI_AP_ADDRESS_SIZE; j++ ) { printf( "%02X ", wifi_results.results[i].mac_address[j] ); } - hal_mcu_trace_print( "Channel: %d, ", wifi_results.results[i].channel ); - hal_mcu_trace_print( "Type: %d, ", wifi_results.results[i].type ); - hal_mcu_trace_print( "RSSI: %d\r\n", wifi_results.results[i].rssi ); + printf( "\r\n"); + printf( "Channel: %d, ", wifi_results.results[i].channel ); + printf( "Type: %d, ", wifi_results.results[i].type ); + printf( "RSSI: %d\r\n", wifi_results.results[i].rssi ); } } diff --git a/libraries/LBM_packet-main/src/internal/main_wifi.h b/libraries/LBM_packet/src/internal/main_wifi.h similarity index 100% rename from libraries/LBM_packet-main/src/internal/main_wifi.h rename to libraries/LBM_packet/src/internal/main_wifi.h From ae5595bef432d1c7d56d61294a31419431dc234f Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Sat, 16 Sep 2023 17:09:05 +0900 Subject: [PATCH 05/34] Update Wio_Tracker_1110_Examples --- libraries/Wio_Tracker_1110_Examples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples index 6f1adfe46..20bd093a7 160000 --- a/libraries/Wio_Tracker_1110_Examples +++ b/libraries/Wio_Tracker_1110_Examples @@ -1 +1 @@ -Subproject commit 6f1adfe4603861677f886b9afda821bf42498071 +Subproject commit 20bd093a7203cc2a202d50989b7d1b87ebd9d972 From 07765e77c736b8e9c63ae1ff656a634ab845c5cd Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Mon, 18 Sep 2023 13:59:32 +0900 Subject: [PATCH 06/34] Add grove power supply setting in menu --- boards.txt | 9 ++++++++- variants/Seeed_Wio_Tracker_1110/variant.cpp | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/boards.txt b/boards.txt index a8d7ad9be..a233deec7 100644 --- a/boards.txt +++ b/boards.txt @@ -2,6 +2,7 @@ menu.softdevice=SoftDevice menu.debug=Debug menu.debug_output=Print Port menu.usb_cdc=Serial (USB-CDC) +menu.power_supply_grove=Grove power supply # ---------------------------------- # Seeed XIAO nRF52840 @@ -140,7 +141,7 @@ wio_tracker_1110.build.core=nRF5 wio_tracker_1110.build.variant=Seeed_Wio_Tracker_1110 wio_tracker_1110.build.usb_manufacturer="Seeed" wio_tracker_1110.build.usb_product="Wio Tracker 1110" -wio_tracker_1110.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DSEGGER_RTT_MAX_NUM_UP_BUFFERS=2 -DSEGGER_RTT_MAX_NUM_DOWN_BUFFERS=2 -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_NO_BLOCK_SKIP -DBUFFER_SIZE_UP=2048 -DBUFFER_SIZE_DOWN=4 -DNRFX_NVMC_ENABLED=1 -DNRFX_RNG_ENABLED=1 -DNRFX_RTC_ENABLED=1 -DNRFX_RTC2_ENABLED=1 -DNRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY=6 -DNRFX_TIMER_ENABLED=1 -DNRFX_TIMER2_ENABLED=1 -DNRFX_WDT_ENABLED=1 -DNRFX_WDT0_ENABLED=1 -DLR11XX -DLR11XX_TRANSCEIVER -DUSE_LR11XX_CE -DENABLE_MODEM_GNSS_FEATURE -DRP2_103 -DREGION_AS_923 -DREGION_AU_915 -DREGION_CN_470 -DREGION_CN_470_RP_1_0 -DREGION_EU_868 -DREGION_IN_865 -DREGION_KR_920 -DREGION_RU_864 -DREGION_US_915 -DREGION_WW2G4 -DWW2G4_SINGLE_DATARATE -DSMTC_MULTICAST -DADD_SMTC_STREAM -DADD_SMTC_FILE_UPLOAD -DADD_SMTC_ALC_SYNC -DMODEM_HAL_DBG_TRACE=1 -DMODEM_HAL_DEEP_DBG_TRACE=0 -DMODEM_HAL_DBG_TRACE_RP=0 -DMODEM_HAL_DBG_TRACE_COLOR=0 -DTASK_EXTENDED_1 -DTASK_EXTENDED_2 -DLR11XX_DISABLE_WARNINGS -DMW_DBG_TRACE=1 -DMW_DBG_TRACE_COLOR=0 -DWM1110_TRACE_MAX_LENGTH=256 +wio_tracker_1110.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} {build.flags.power_supply_grove} -DSEGGER_RTT_MAX_NUM_UP_BUFFERS=2 -DSEGGER_RTT_MAX_NUM_DOWN_BUFFERS=2 -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_NO_BLOCK_SKIP -DBUFFER_SIZE_UP=2048 -DBUFFER_SIZE_DOWN=4 -DNRFX_NVMC_ENABLED=1 -DNRFX_RNG_ENABLED=1 -DNRFX_RTC_ENABLED=1 -DNRFX_RTC2_ENABLED=1 -DNRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY=6 -DNRFX_TIMER_ENABLED=1 -DNRFX_TIMER2_ENABLED=1 -DNRFX_WDT_ENABLED=1 -DNRFX_WDT0_ENABLED=1 -DLR11XX -DLR11XX_TRANSCEIVER -DUSE_LR11XX_CE -DENABLE_MODEM_GNSS_FEATURE -DRP2_103 -DREGION_AS_923 -DREGION_AU_915 -DREGION_CN_470 -DREGION_CN_470_RP_1_0 -DREGION_EU_868 -DREGION_IN_865 -DREGION_KR_920 -DREGION_RU_864 -DREGION_US_915 -DREGION_WW2G4 -DWW2G4_SINGLE_DATARATE -DSMTC_MULTICAST -DADD_SMTC_STREAM -DADD_SMTC_FILE_UPLOAD -DADD_SMTC_ALC_SYNC -DMODEM_HAL_DBG_TRACE=1 -DMODEM_HAL_DEEP_DBG_TRACE=0 -DMODEM_HAL_DBG_TRACE_RP=0 -DMODEM_HAL_DBG_TRACE_COLOR=0 -DTASK_EXTENDED_1 -DTASK_EXTENDED_2 -DLR11XX_DISABLE_WARNINGS -DMW_DBG_TRACE=1 -DMW_DBG_TRACE_COLOR=0 -DWM1110_TRACE_MAX_LENGTH=256 wio_tracker_1110.build.ldscript=nrf52840_s140_v6.ld wio_tracker_1110.build.vid=0x2886 wio_tracker_1110.build.pid=0x8055 @@ -165,3 +166,9 @@ wio_tracker_1110.menu.debug_output.none.build.logger_flags=-DCFG_LOGGER=3 wio_tracker_1110.menu.usb_cdc.enable=Enable wio_tracker_1110.menu.usb_cdc.disable=Disable wio_tracker_1110.menu.usb_cdc.disable.build.flags.usb= + +# Grove power supply +wio_tracker_1110.menu.power_supply_grove.on=On +wio_tracker_1110.menu.power_supply_grove.on.build.flags.power_supply_grove=-DPOWER_SUPPLY_GROVE=1 +wio_tracker_1110.menu.power_supply_grove.off=Off +wio_tracker_1110.menu.power_supply_grove.off.build.flags.power_supply_grove=-DPOWER_SUPPLY_GROVE=0 diff --git a/variants/Seeed_Wio_Tracker_1110/variant.cpp b/variants/Seeed_Wio_Tracker_1110/variant.cpp index 5c7ec892f..b5d53e5e8 100644 --- a/variants/Seeed_Wio_Tracker_1110/variant.cpp +++ b/variants/Seeed_Wio_Tracker_1110/variant.cpp @@ -69,7 +69,11 @@ void initVariant() digitalWrite(PIN_GNSS_LNA, LOW); pinMode(PIN_GNSS_LNA, OUTPUT); +#if defined(POWER_SUPPLY_GROVE) && POWER_SUPPLY_GROVE == 1 + digitalWrite(PIN_POWER_SUPPLY_GROVE, HIGH); +#else digitalWrite(PIN_POWER_SUPPLY_GROVE, LOW); +#endif pinMode(PIN_POWER_SUPPLY_GROVE, OUTPUT); ledOff(LED_BUILTIN); From b72930d4cce63fe002b0859f0a9ea23ad86bec82 Mon Sep 17 00:00:00 2001 From: SeeedWenzy <142080102+SeeedWenzy@users.noreply.github.com> Date: Mon, 18 Sep 2023 17:28:58 +0800 Subject: [PATCH 07/34] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4edc3a23f..eedc389c2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This repository contains the Arduino BSP for Seeed nRF52 series: - [Seeed Studio XIAO nRF52840](https://www.seeedstudio.com/Seeed-XIAO-BLE-nRF52840-p-5201.html) - [Seeed Studio XIAO nRF52840 Sense](https://www.seeedstudio.com/Seeed-XIAO-BLE-Sense-nRF52840-p-5253.html) -- Wio Tracker 1110 +- [Seeed Studio Wio Tracker 1110](https://www.seeedstudio.com/Wio-Tracker-1110-Dev-Board-p-5799.html) ## BSP Installation @@ -71,4 +71,4 @@ The following libraries are used: - [FreeRTOS](https://www.freertos.org/) as operating system - [LittleFS](https://github.com/ARMmbed/littlefs) for internal file system - [nrfx](https://github.com/NordicSemiconductor/nrfx) for peripherals driver -- [TinyUSB](https://github.com/hathach/tinyusb) as usb stack \ No newline at end of file +- [TinyUSB](https://github.com/hathach/tinyusb) as usb stack From 6d44b470fda99ce8ff446e1498166627da67827a Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Tue, 19 Sep 2023 09:07:10 +0900 Subject: [PATCH 08/34] Change Serial.begin() calling conditions --- cores/nRF5/main.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index 19a36268e..ef27994a3 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -52,12 +52,27 @@ static void loop_task(void* arg) TinyUSB_Device_Init(0); #endif +#if defined(ARDUINO_Seeed_XIAO_nRF52840) || defined(ARDUINO_Seeed_XIAO_nRF52840_Sense) + +#if CFG_DEBUG + // If Serial is not begin(), call it to avoid hard fault + if(!Serial) Serial.begin(115200); +#endif + +#elif defined(ARDUINO_WIO_TRACKER_1110) + #if CFG_LOGGER == 0 // If Serial is not begin(), call it to avoid hard fault if(!Serial) Serial.begin(115200); #elif CFG_LOGGER == 1 // If Serial1 is not begin(), call it to avoid hard fault if(!Serial1) Serial1.begin(115200); +#endif + +#else + +#error "Unsupported board" + #endif setup(); @@ -118,7 +133,7 @@ void resumeLoop(void) } } -#if CFG_LOGGER != 3 || defined(NRF52832_XXAA) +#if CFG_LOGGER != 3 extern "C" { @@ -130,12 +145,10 @@ int _write (int fd, const void *buf, size_t count) size_t ret = 0; -#if CFG_LOGGER == 0 || defined(NRF52832_XXAA) +#if CFG_LOGGER == 2 || CFG_SYSVIEW - if ( Serial ) - { - ret = Serial.write((const uint8_t *) buf, count); - } + SEGGER_RTT_Write(0, buf, count); + ret = count; #elif CFG_LOGGER == 1 @@ -144,10 +157,12 @@ int _write (int fd, const void *buf, size_t count) ret = Serial1.write((const uint8_t *) buf, count); } -#elif CFG_LOGGER == 2 +#elif CFG_LOGGER == 0 - SEGGER_RTT_Write(0, buf, count); - ret = count; + if ( Serial ) + { + ret = Serial.write((const uint8_t *) buf, count); + } #endif From 50bdb71c09905374b2c918f5ab371be9d86ab477 Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Tue, 19 Sep 2023 09:48:50 +0900 Subject: [PATCH 09/34] 1.1.5 --- platform.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.txt b/platform.txt index cc78a166d..0fa64edf9 100644 --- a/platform.txt +++ b/platform.txt @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA name=Seeed nRF52 Boards -version=1.1.4 +version=1.1.5 # Compile variables # ----------------- From fc49dd461c4b722176a4acf9b9bd6f233e76f7a7 Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Tue, 19 Sep 2023 11:45:53 +0900 Subject: [PATCH 10/34] Fix pack_release.sh --- extras/pack_release.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extras/pack_release.sh b/extras/pack_release.sh index 1acb8b772..ea9262b34 100755 --- a/extras/pack_release.sh +++ b/extras/pack_release.sh @@ -30,3 +30,6 @@ tar --transform "s|$FOLDERNAME|$VERSION|g" --exclude=extras/** --exclude=.git* cd - mv ../$FOLDERNAME-$VERSION.tar.bz2 . + +echo checksum ... SHA-256:`sha256sum $FOLDERNAME-$VERSION.tar.bz2 | awk '{print $1}'` +echo size ... `wc -c $FOLDERNAME-$VERSION.tar.bz2 | awk '{print $1}'` From dd63ec0d6862cdf2a76a59d3ebe39b7206c6f3e6 Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Tue, 19 Sep 2023 15:58:28 +0900 Subject: [PATCH 11/34] Fix warning at WInterrupts.c --- cores/nRF5/WInterrupts.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/nRF5/WInterrupts.c b/cores/nRF5/WInterrupts.c index b2f73a89c..0693e0dac 100644 --- a/cores/nRF5/WInterrupts.c +++ b/cores/nRF5/WInterrupts.c @@ -184,7 +184,7 @@ void enableInterruptIRQ(uint32_t pin) for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) { - if (channelMap[ch] == pin) + if ((uint32_t)channelMap[ch] == pin) { nrf_gpiote_int_enable(NRF_GPIOTE, 1 << ch); break; @@ -199,7 +199,7 @@ void disableInterruptIRQ(uint32_t pin) for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) { - if (channelMap[ch] == pin) + if ((uint32_t)channelMap[ch] == pin) { nrf_gpiote_int_disable(NRF_GPIOTE, 1 << ch); break; @@ -214,7 +214,7 @@ void clearInterruptIRQ(uint32_t pin) for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) { - if (channelMap[ch] == pin) + if ((uint32_t)channelMap[ch] == pin) { nrf_gpiote_event_clear(NRF_GPIOTE, ch); break; From 4f43a29c302e8523c33a256e0259a9628f817de0 Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Wed, 20 Sep 2023 08:30:44 +0900 Subject: [PATCH 12/34] Fix compile error in secondary_receiver.ino --- libraries/Wire/Wire_nRF52.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/Wire/Wire_nRF52.cpp b/libraries/Wire/Wire_nRF52.cpp index 6073739fc..829404025 100755 --- a/libraries/Wire/Wire_nRF52.cpp +++ b/libraries/Wire/Wire_nRF52.cpp @@ -29,6 +29,13 @@ extern "C" { #include "Wire.h" +#if defined(ARDUINO_Seeed_XIAO_nRF52840) || defined(ARDUINO_Seeed_XIAO_nRF52840_Sense) +#include // for Serial +#elif defined(ARDUINO_WIO_TRACKER_1110) +#else +#error "Unsupported board" +#endif + static volatile uint32_t* pincfg_reg(uint32_t pin) { NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&pin); From 4f17e1db03594a7109a03c649d75d81530ea262a Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Wed, 20 Sep 2023 08:33:19 +0900 Subject: [PATCH 13/34] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c4a3fd2c2..10cd71138 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This repository contains the Arduino BSP for Seeed nRF52 series: - [Seeed Studio XIAO nRF52840](https://www.seeedstudio.com/Seeed-XIAO-BLE-nRF52840-p-5201.html) - [Seeed Studio XIAO nRF52840 Sense](https://www.seeedstudio.com/Seeed-XIAO-BLE-Sense-nRF52840-p-5253.html) -- Wio Tracker 1110 +- [Seeed Studio Wio Tracker 1110](https://www.seeedstudio.com/Wio-Tracker-1110-Dev-Board-p-5799.html) ## BSP Installation @@ -46,7 +46,7 @@ There are two methods that you can use to install this BSP. We highly recommend ### Optional (Core Development): Create Seeed nRF52 BSP file ``` -$ git clone --depth 1 --recurse-submodules https://github.com/SeeedJP/Adafruit_nRF52_Arduino Seeed_nRF52_Boards +$ git clone --depth 1 --recurse-submodules https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino Seeed_nRF52_Boards $ cd Seeed_nRF52_Boards $ ./extras/pack_release.sh ``` From 871b2abcd3307c6229e86aefece2e047dc97ae0e Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Thu, 21 Sep 2023 13:24:05 +0900 Subject: [PATCH 14/34] Update LBM_WM1110 --- libraries/LBM_WM1110 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index e14306a43..f7338ca40 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit e14306a43c986666f18ae6079b15c4149e6c8b16 +Subproject commit f7338ca400ab07cb89766591058904e3dd15a343 From 0d6a2bf7db42f8c7ea470c93624d3d58a6230d74 Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Fri, 22 Sep 2023 11:19:26 +0800 Subject: [PATCH 15/34] 1.feat:add data cache 2.feat:add Bluetooth configuration service to communicate with Sensecap mobile app 3.Add factory default firmware 4.feat:Add a local update almanac 5.feat:add comment --- .gitmodules | 2 + libraries/Bluefruit52Lib/src/bluefruit.h | 3 + .../Bluefruit52Lib/src/services/BLEComm.cpp | 322 ++++++ .../Bluefruit52Lib/src/services/BLEComm.h | 120 +++ libraries/LBM_packet/library.properties | 3 - libraries/LBM_packet/src/Lbm_packet.hpp | 8 + .../src/app_param/app_config_param.c | 21 +- .../src/app_param/app_config_param.h | 146 ++- libraries/LBM_packet/src/app_param/at.cpp | 989 ++++++++++++++++++ libraries/LBM_packet/src/app_param/at.h | 390 +++++++ .../LBM_packet/src/app_param/at_command.cpp | 290 +++++ .../LBM_packet/src/app_param/at_command.h | 49 + .../src/app_param/default_config_datas.cpp | 14 + .../src/app_param/default_config_datas.h | 5 + .../src/app_param/key_value_fds.cpp | 347 ++++++ .../LBM_packet/src/app_param/key_value_fds.h | 163 +++ .../src/app_param/user_stored_data.cpp | 810 ++++++++++++++ .../src/app_param/user_stored_data.h | 270 +++++ libraries/LBM_packet/src/internal/almanac.h | 5 + .../src/internal/get_full_almanac.py | 111 ++ .../LBM_packet/src/internal/main_almanac.cpp | 154 +++ .../LBM_packet/src/internal/main_almanac.h | 28 + .../LBM_packet/src/internal/main_ble.cpp | 184 +++- libraries/LBM_packet/src/internal/main_ble.h | 123 ++- .../LBM_packet/src/internal/main_gps.cpp | 2 +- libraries/LBM_packet/src/internal/main_gps.h | 34 +- .../LBM_packet/src/internal/main_lbm.cpp | 280 ++++- libraries/LBM_packet/src/internal/main_lbm.h | 84 +- .../LBM_packet/src/internal/main_lora.cpp | 5 +- libraries/LBM_packet/src/internal/main_lora.h | 182 ++-- .../LBM_packet/src/internal/main_packet.cpp | 44 +- .../LBM_packet/src/internal/main_packet.h | 52 +- .../LBM_packet/src/internal/main_sensor.cpp | 26 +- .../LBM_packet/src/internal/main_sensor.h | 37 +- .../LBM_packet/src/internal/main_track.cpp | 85 +- .../LBM_packet/src/internal/main_track.h | 74 +- libraries/LBM_packet/src/internal/main_wifi.h | 34 +- libraries/Wio_Tracker_1110_Examples | 2 +- 38 files changed, 5147 insertions(+), 351 deletions(-) create mode 100644 libraries/Bluefruit52Lib/src/services/BLEComm.cpp create mode 100644 libraries/Bluefruit52Lib/src/services/BLEComm.h create mode 100644 libraries/LBM_packet/src/app_param/at.cpp create mode 100644 libraries/LBM_packet/src/app_param/at.h create mode 100644 libraries/LBM_packet/src/app_param/at_command.cpp create mode 100644 libraries/LBM_packet/src/app_param/at_command.h create mode 100644 libraries/LBM_packet/src/app_param/key_value_fds.cpp create mode 100644 libraries/LBM_packet/src/app_param/key_value_fds.h create mode 100644 libraries/LBM_packet/src/app_param/user_stored_data.cpp create mode 100644 libraries/LBM_packet/src/app_param/user_stored_data.h create mode 100644 libraries/LBM_packet/src/internal/almanac.h create mode 100644 libraries/LBM_packet/src/internal/get_full_almanac.py create mode 100644 libraries/LBM_packet/src/internal/main_almanac.cpp create mode 100644 libraries/LBM_packet/src/internal/main_almanac.h diff --git a/.gitmodules b/.gitmodules index dc05f0125..0ad4b8a55 100644 --- a/.gitmodules +++ b/.gitmodules @@ -42,6 +42,8 @@ path = libraries/Grove_Sunlight_Sensor url = https://github.com/Seeed-Studio/Grove_Sunlight_Sensor.git branch = Si1151 + [submodule "libraries/Wio_Tracker_1110_Examples"] path = libraries/Wio_Tracker_1110_Examples url = https://github.com/Seeed-Studio/Wio_Tracker_1110_Examples.git + branch = dev/wenzy diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index f11055bd7..440cd58c3 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -69,6 +69,9 @@ #include "services/BLEMidi.h" #include "services/EddyStone.h" +#include "services/BLEComm.h" + + #include "clients/BLEAncs.h" #include "clients/BLEClientUart.h" #include "clients/BLEClientDis.h" diff --git a/libraries/Bluefruit52Lib/src/services/BLEComm.cpp b/libraries/Bluefruit52Lib/src/services/BLEComm.cpp new file mode 100644 index 000000000..bd3379801 --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEComm.cpp @@ -0,0 +1,322 @@ +/**************************************************************************/ +/*! + @file BLEComm.cpp + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2018, Adafruit Industries (adafruit.com) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ + +#include "bluefruit.h" +#include "utility/TimeoutTimer.h" + + + +const uint8_t BLECOMM_UUID_SERVICE[] = +{ + 0x55, 0xE4, 0x05, 0xD2, 0xAF, 0x9F, 0xA9, 0x8F, + 0xE5, 0x4A, 0x7D, 0xFE, 0x43, 0x53, 0x53, 0x49 +}; + +const uint8_t BLECOMM_UUID_CHR_RXD[] = +{ + 0xB3, 0x9B, 0x72, 0x34, 0xBE, 0xEC, 0xD4, 0xA8, + 0xF4, 0x43, 0x41, 0x88, 0x43, 0x53, 0x53, 0x49 +}; + +const uint8_t BLECOMM_UUID_CHR_TXD[] = +{ + 0x16, 0x96, 0x24, 0x47, 0xC6, 0x23, 0x61, 0xBA, + 0xD9, 0x4B, 0x4D, 0x1E, 0x43, 0x53, 0x53, 0x49 +}; + +// Constructor +BLEComm::BLEComm(uint16_t fifo_depth) + : BLEService(BLECOMM_UUID_SERVICE), _txd(BLECOMM_UUID_CHR_TXD), _rxd(BLECOMM_UUID_CHR_RXD) +{ + _rx_fifo = NULL; + _rx_fifo_depth = fifo_depth; + + _rx_cb = NULL; + _notify_cb = NULL; + _overflow_cb = NULL; + + _tx_fifo = NULL; + _tx_buffered = false; +} + +// Destructor +BLEComm::~BLEComm() +{ + if ( _tx_fifo ) delete _tx_fifo; +} + +// Callback when received new data +void BLEComm::blecomm_rxd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len) +{ + BLEComm& svc = (BLEComm&) chr->parentService(); + uint16_t wrcount = svc._rx_fifo->write(data, len); + + if ( wrcount < len ) + { + LOG_LV1("MEMORY", "blecomm rxd fifo OVERFLOWED!"); + + // invoke overflow callback + if (svc._overflow_cb) svc._overflow_cb(conn_hdl, len - wrcount); + } + +#if CFG_DEBUG >= 2 + LOG_LV2("BLEComm", "RX: "); + PRINT_BUFFER(data, len); +#endif + + // invoke user callback + if ( svc._rx_cb ) svc._rx_cb(conn_hdl); +} + +void BLEComm::blecomm_txd_cccd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value) +{ + BLEComm& svc = (BLEComm&) chr->parentService(); + + if ( svc._notify_cb ) svc._notify_cb(conn_hdl, value & BLE_GATT_HVX_NOTIFICATION); +} + +void BLEComm::setRxCallback(rx_callback_t fp, bool deferred) +{ + _rx_cb = fp; + + _rxd.setWriteCallback(BLEComm::blecomm_rxd_cb, deferred); +} + +void BLEComm::setRxOverflowCallback(rx_overflow_callback_t fp) +{ + _overflow_cb = fp; +} + +void BLEComm::setNotifyCallback(notify_callback_t fp) +{ + _notify_cb = fp; + _txd.setCccdWriteCallback( fp ? BLEComm::blecomm_txd_cccd_cb : NULL ); +} + +/** + * Enable packet buffered for TXD + * Note: packet is sent right away if it reach MTU bytes + * @param enable true or false + */ +void BLEComm::bufferTXD(bool enable) +{ + _tx_buffered = enable; + + if ( enable ) + { + // Create FIFO for TXD + if ( _tx_fifo == NULL ) + { + _tx_fifo = new Adafruit_FIFO(1); + _tx_fifo->begin( Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH) ); + } + }else + { + if ( _tx_fifo ) delete _tx_fifo; + } +} + +err_t BLEComm::begin(void) +{ + _rx_fifo = new Adafruit_FIFO(1); + _rx_fifo->begin(_rx_fifo_depth); + + // Invoke base class begin() + VERIFY_STATUS( BLEService::begin() ); + + uint16_t max_mtu = Bluefruit.getMaxMtu(BLE_GAP_ROLE_PERIPH); + + // Add TXD Characteristic + _txd.setProperties(CHR_PROPS_NOTIFY); + // TODO enable encryption when bonding is enabled + _txd.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _txd.setMaxLen( max_mtu ); + // _txd.setUserDescriptor("TXD"); + VERIFY_STATUS( _txd.begin() ); + + // Add RXD Characteristic + _rxd.setProperties(CHR_PROPS_WRITE | CHR_PROPS_WRITE_WO_RESP); + _rxd.setWriteCallback(BLEComm::blecomm_rxd_cb, true); + + // TODO enable encryption when bonding is enabled + _rxd.setPermission(SECMODE_NO_ACCESS, SECMODE_OPEN); + _rxd.setMaxLen( max_mtu ); + // _rxd.setUserDescriptor("RXD"); + VERIFY_STATUS(_rxd.begin()); + + return ERROR_NONE; +} + +bool BLEComm::notifyEnabled(void) +{ + return this->notifyEnabled(Bluefruit.connHandle()); +} + +bool BLEComm::notifyEnabled(uint16_t conn_hdl) +{ + return _txd.notifyEnabled(conn_hdl); +} + +/*------------------------------------------------------------------*/ +/* STREAM API + *------------------------------------------------------------------*/ +int BLEComm::read (void) +{ + uint8_t ch; + return read(&ch, 1) ? (int) ch : EOF; +} + +int BLEComm::read(uint8_t * buf, size_t size) +{ + return _rx_fifo->read(buf, size); +} + +uint8_t BLEComm::read8 (void) +{ + uint8_t num; + return read(&num, sizeof(num)) ? num : 0; +} + +uint16_t BLEComm::read16(void) +{ + uint16_t num; + return read((uint8_t*) &num, sizeof(num)) ? num : 0; +} + +uint32_t BLEComm::read32(void) +{ + uint32_t num; + return read((uint8_t*) &num, sizeof(num)) ? num : 0; +} + +size_t BLEComm::write(uint8_t b) +{ + return this->write(Bluefruit.connHandle(), &b, 1); +} + +size_t BLEComm::write(uint16_t conn_hdl, uint8_t b) +{ + return this->write(conn_hdl, &b, 1); +} + +size_t BLEComm::write(const uint8_t *content, size_t len) +{ + return this->write(Bluefruit.connHandle(), content, len); +} + +size_t BLEComm::write(uint16_t conn_hdl, const uint8_t *content, size_t len) +{ + BLEConnection* conn = Bluefruit.Connection(conn_hdl); + VERIFY(conn, 0); + + // skip if not enabled + if ( !notifyEnabled(conn_hdl) ) return 0; + + // notify right away if txd buffered is not enabled + if ( !(_tx_buffered && _tx_fifo) ) + { + return _txd.notify(conn_hdl, content, len) ? len : 0; + }else + { + uint16_t written = _tx_fifo->write(content, len); + + // Not up to GATT MTU, notify will be sent later by TXD timer handler + if ( _tx_fifo->count() < (conn->getMtu() - 3) ) + { + return len; + } + else + { + // TX fifo has enough data, send notify right away + VERIFY( flushTXD(conn_hdl), 0); + + // still more data left, send them all + if ( written < len ) + { + VERIFY(_txd.notify(conn_hdl, content+written, len-written), written); + } + + return len; + } + } +} + +int BLEComm::available (void) +{ + return _rx_fifo->count(); +} + +int BLEComm::peek (void) +{ + uint8_t ch; + return _rx_fifo->peek(&ch) ? (int) ch : EOF; +} + +void BLEComm::flush (void) +{ + _rx_fifo->clear(); +} + +bool BLEComm::flushTXD (void) +{ + return flushTXD(Bluefruit.connHandle()); +} + +bool BLEComm::flushTXD(uint16_t conn_hdl) +{ + BLEConnection* conn = Bluefruit.Connection(conn_hdl); + VERIFY(conn); + + uint16_t const gatt_mtu = conn->getMtu() - 3; + uint8_t* ff_data = (uint8_t*) rtos_malloc( gatt_mtu ); + VERIFY(ff_data); + + uint16_t len = _tx_fifo->read(ff_data, gatt_mtu); + bool result = true; + + if ( len ) + { + result = _txd.notify(conn_hdl, ff_data, len); + } + + rtos_free(ff_data); + + return result; +} + + + + diff --git a/libraries/Bluefruit52Lib/src/services/BLEComm.h b/libraries/Bluefruit52Lib/src/services/BLEComm.h new file mode 100644 index 000000000..27c10ed5f --- /dev/null +++ b/libraries/Bluefruit52Lib/src/services/BLEComm.h @@ -0,0 +1,120 @@ +/**************************************************************************/ +/*! + @file BLEComm.h + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2018, Adafruit Industries (adafruit.com) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef BLECOMM_H_ +#define BLECOMM_H_ + +#include "bluefruit_common.h" +#include "utility/adafruit_fifo.h" + +#include "BLECharacteristic.h" +#include "BLEService.h" + +#define BLE_COMM_DEFAULT_FIFO_DEPTH 256 + +extern const uint8_t BLECOMM_UUID_SERVICE[]; +extern const uint8_t BLECOMM_UUID_CHR_RXD[]; +extern const uint8_t BLECOMM_UUID_CHR_TXD[]; + +class BLEComm : public BLEService, public Stream +{ + public: + typedef void (*rx_callback_t) (uint16_t conn_hdl); + typedef void (*notify_callback_t)(uint16_t conn_hdl, bool enabled); + typedef void (*rx_overflow_callback_t) (uint16_t conn_hdl, uint16_t leftover); + + BLEComm(uint16_t fifo_depth = BLE_COMM_DEFAULT_FIFO_DEPTH); + virtual ~BLEComm(); + + virtual err_t begin(void); + + bool notifyEnabled(void); + bool notifyEnabled(uint16_t conn_hdl); + + void setRxCallback (rx_callback_t fp, bool deferred = true); + void setRxOverflowCallback(rx_overflow_callback_t fp); + void setNotifyCallback(notify_callback_t fp); + + void bufferTXD(bool enable); + + bool flushTXD (void); + bool flushTXD (uint16_t conn_hdl); + + // Read helper + uint8_t read8 (void); + uint16_t read16(void); + uint32_t read32(void); + + // Stream API + virtual int read ( void ); + virtual int read ( uint8_t * buf, size_t size ); + int read ( char * buf, size_t size ) { return read( (uint8_t*) buf, size); } + + virtual size_t write ( uint8_t b ); + virtual size_t write ( const uint8_t *content, size_t len); + + virtual size_t write (uint16_t conn_hdl, uint8_t b); + virtual size_t write (uint16_t conn_hdl, const uint8_t *content, size_t len); + + virtual int available ( void ); + virtual int peek ( void ); + virtual void flush ( void ); + + // pull in write(str) and write(buf, size) from Print + using Print::write; + + protected: + BLECharacteristic _txd; + BLECharacteristic _rxd; + + // RXD + Adafruit_FIFO* _rx_fifo; + uint16_t _rx_fifo_depth; + + // TXD + Adafruit_FIFO* _tx_fifo; + bool _tx_buffered; // default is false + + // Callbacks + rx_callback_t _rx_cb; + notify_callback_t _notify_cb; + rx_overflow_callback_t _overflow_cb; + + // Static Method for callbacks + static void blecomm_rxd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len); + static void blecomm_txd_cccd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value); +}; + +#endif /* BLEUART_H_ */ diff --git a/libraries/LBM_packet/library.properties b/libraries/LBM_packet/library.properties index b726c7af8..37d593a8c 100644 --- a/libraries/LBM_packet/library.properties +++ b/libraries/LBM_packet/library.properties @@ -8,6 +8,3 @@ category=Communication url= architectures=nrf52 includes=Lbm_packet.hpp - - - diff --git a/libraries/LBM_packet/src/Lbm_packet.hpp b/libraries/LBM_packet/src/Lbm_packet.hpp index 07c79b1ea..e3e428034 100644 --- a/libraries/LBM_packet/src/Lbm_packet.hpp +++ b/libraries/LBM_packet/src/Lbm_packet.hpp @@ -20,6 +20,8 @@ #include "internal/main_track.h" #include "internal/main_wifi.h" #include "internal/main_gps.h" +#include "internal/main_almanac.h" + #include "common/apps_modem_common.h" #include "common/smtc_hal_dbg_trace.h" @@ -43,4 +45,10 @@ #include "app_param/app_config_param.h" #include "app_param/default_config_datas.h" +#include "app_param/key_value_fds.h" +#include "app_param/user_stored_data.h" +#include "app_param/at.h" +#include "app_param/at_command.h" + + diff --git a/libraries/LBM_packet/src/app_param/app_config_param.c b/libraries/LBM_packet/src/app_param/app_config_param.c index 43af25215..d8bc315e0 100644 --- a/libraries/LBM_packet/src/app_param/app_config_param.c +++ b/libraries/LBM_packet/src/app_param/app_config_param.c @@ -31,11 +31,30 @@ adding_pos_param_t app_adding_pos_param = .latitude = 22577064, .longitude = 113922456, }; + +pos_msg_file_id_t pos_msg_file_id = +{ + .reboot_cnt = 0, + .log_cnt = 0, +} +; +pos_msg_param_t pos_msg_param = +{ + 0 +}; + gnss_group_param_t app_gnss_group_param= { .group_id = 0, }; - +append_param_t app_append_param = +{ + .Platform = IOT_PLATFORM_SENSECAP_TTN, + .Retry = 1, + .cache_en = true, + .position_interval = 5, + .sample_interval = 5, +}; diff --git a/libraries/LBM_packet/src/app_param/app_config_param.h b/libraries/LBM_packet/src/app_param/app_config_param.h index b1258ac2e..bef4bbd9b 100644 --- a/libraries/LBM_packet/src/app_param/app_config_param.h +++ b/libraries/LBM_packet/src/app_param/app_config_param.h @@ -6,8 +6,11 @@ #include #include #include + #define LORAWAN_APP_PARAM_ENABLE + + typedef enum eLoRaMacRegion { LORAMAC_REGION_TTN_AS923_2 = 0, //TTN AS923_2 @@ -28,12 +31,24 @@ typedef enum eLoRaMacRegion LORAMAC_REGION_AS923_4, //AS band on 923MHz LORAMAC_REGION_AS923_1B, //Helium AS923_1B LORAMAC_REGION_TTN_AS923_1, //TTN AS923_1 - LORAMAC_REGION_AS_920_923_LBT, + LORAMAC_REGION_AS_GP_2, + LORAMAC_REGION_AS_GP_3, + LORAMAC_REGION_AS_GP_4, #endif LORAMAC_REGION_MAX = 0xFF//none }LoRaMacRegion_t; +typedef enum +{ + IOT_PLATFORM_SENSECAP_TTN, + IOT_PLATFORM_OTHER, + IOT_PLATFORM_HELIUM, + IOT_PLATFORM_TTN, + IOT_PLATFORM_SENSECAP_HELIUM, + IOT_PLATFORM_MAX +} platform_t; + typedef enum eActivationType { ACTIVATION_TYPE_NONE = 0, //None @@ -41,26 +56,34 @@ typedef enum eActivationType ACTIVATION_TYPE_OTAA = 2, //Over-The-Air Activation (ACTIVATION_TYPE_OTAA) }ActivationType_t; -// +typedef enum epos_type +{ + pos_gnss_raw = 0x12, + pos_wifi = 0x14, + pos_beac = 0x15, + pos_state = 0x16, +}epos_type_t; + + typedef struct lora_info { - //LoRaWAN - uint8_t DevEui[8]; - uint8_t JoinEui[8]; - uint8_t DeviceKey[16]; - uint8_t AppKey[16]; + //LoRaWAN + uint8_t DevEui[8]; + uint8_t JoinEui[8]; + uint8_t DeviceKey[16]; + uint8_t AppKey[16]; + + uint8_t ActiveRegion; //Regional spectrum in LoRaMacRegion_t + uint8_t ActivationType; //access net type 0: none,1: ABP 2: OTAA + uint8_t ChannelGroup; - uint8_t ActiveRegion; //Regional spectrum in LoRaMacRegion_t - uint8_t ActivationType; //access net type 0: none,1: ABP 2: OTAA - uint8_t ChannelGroup; - - uint32_t DevAddr; - uint8_t DeviceCode[8]; + uint32_t DevAddr; + uint8_t DeviceCode[8]; - uint8_t NwkKey[16]; - uint8_t AppSKey[16]; - uint8_t NwkSKey[16]; + uint8_t NwkKey[16]; + uint8_t AppSKey[16]; + uint8_t NwkSKey[16]; }lora_info_t; @@ -70,6 +93,19 @@ typedef struct hardware_info uint8_t hw_ver; }hardware_info_t; +typedef struct beac_context +{ + uint8_t beac_mac[6]; + int8_t cur_rssi; +}beac_context_t; + +typedef struct wifi_context +{ + uint8_t wifi_mac[6]; + int8_t cur_rssi; +}wifi_context_t; + + #pragma pack(4) typedef struct app_param { @@ -81,32 +117,94 @@ typedef struct app_param typedef struct utc_param { - uint32_t sync_utc; + uint32_t sync_utc; }utc_param_t; typedef struct gnss_group_param { - uint32_t group_id; + uint32_t group_id; }gnss_group_param_t; typedef struct adding_pos_param { - int32_t latitude; - int32_t longitude; + int32_t latitude; + int32_t longitude; }adding_pos_param_t; + +typedef struct pos_msg_param +{ + uint8_t pos_type; + uint8_t context_count; + uint32_t utc_time; + uint32_t pos_status; + union{ + struct + { + uint8_t zone_flag; + uint16_t group_id; + uint8_t gnss_len; + uint8_t gnss_res[46]; + }gps_context; + struct + { + uint8_t len; + uint8_t sensor_data[49]; + }sensor_context; + wifi_context_t wifi_context[4]; + beac_context_t beac_context[3]; + }context; +}pos_msg_param_t; + +typedef struct pos_msg_file_id +{ + uint8_t reboot_cnt; + uint16_t log_cnt; + uint16_t file_id_start; + uint16_t file_id_cur; +}pos_msg_file_id_t; + +typedef struct various_interval +{ + uint16_t position_interval; + uint16_t sample_interval; +}various_interval_t; + + +typedef struct append_param +{ + platform_t Platform; // 0:Sencap platform;1:Third-party platform + uint8_t Retry; + bool cache_en; //cache data enabled/disable + uint8_t res1; //Four-byte alignment + uint16_t position_interval; + uint16_t sample_interval; + union{ + struct + { + uint8_t res2; + uint8_t res3; + uint8_t res4; + uint8_t res5; + }Reserved_param; + uint32_t Reserved; + uint8_t res[4]; + }; +}append_param_t; + + #pragma pack() extern app_param_t app_param; +extern pos_msg_file_id_t pos_msg_file_id; +extern pos_msg_param_t pos_msg_param; + extern utc_param_t app_utc_param; extern adding_pos_param_t app_adding_pos_param; extern gnss_group_param_t app_gnss_group_param; - -void hexTonum(unsigned char *out_data, unsigned char *in_data, unsigned short Size); -void numTohex(unsigned char *out_data, unsigned char *in_data, unsigned short Size); -uint8_t Char2Nibble(char Char); +extern append_param_t app_append_param; #endif diff --git a/libraries/LBM_packet/src/app_param/at.cpp b/libraries/LBM_packet/src/app_param/at.cpp new file mode 100644 index 000000000..bccba0111 --- /dev/null +++ b/libraries/LBM_packet/src/app_param/at.cpp @@ -0,0 +1,989 @@ +#include "at.h" +#include "at_command.h" +#include "app_config_param.h" +#include "lbm/smtc_modem_api/smtc_modem_api.h" +#include "internal/main_sensor.h" + +#define tiny_sscanf sscanf // add by wen 2022.6.16 + +#define SE_KEY_SIZE 16 +#define SE_EUI_SIZE 8 + +uint8_t parse_cmd_type = 0; +uint8_t def_eui[8]; + +/** + * @brief Print 4 bytes as %02x + * @param value containing the 4 bytes to print + */ +static void print_uint32_as_02x(uint32_t value); + +/** + * @brief Print 16 bytes as %02X + * @param pt pointer containing the 16 bytes to print + */ +static void print_16_02x(uint8_t *pt); + +/** + * @brief Print 8 bytes as %02X + * @param pt pointer containing the 8 bytes to print + */ +static void print_8_02x(uint8_t *pt); + +/** + * @brief Print an int + * @param value to print + */ +static void print_d(int32_t value); + +/** + * @brief Print an unsigned int + * @param value to print + */ +static void print_u(uint32_t value); + +/** + * @brief Check if character in parameter is alphanumeric + * @param Char for the alphanumeric check + */ +static int32_t isHex(char Char); + + +/** + * @brief Check if character in parameter is number + * @param Char for the number check + */ +static int32_t isNum(char Char); + +/** + * @brief Check if character in parameter is number + * @param str for the number check + * @param Size for the number size we want check + */ +int32_t isNums(const char *str, uint32_t Size); + +/** + * @brief Converts hex string to a nibble ( 0x0X ) + * @param Char hex string + * @retval the nibble. Returns 0xF0 in case input was not an hex string (a..f; A..F or 0..9) + */ +//static uint8_t Char2Nibble(char Char); + +/** + * @brief Convert a string into a buffer of data + * @param str string to convert + * @param data output buffer + * @param Size of input string + */ +static int32_t stringToData(const char *str, uint8_t *data, uint32_t Size); +void hexTonum(unsigned char *out_data, unsigned char *in_data, unsigned short Size) +{ + for(unsigned char i = 0; i < Size; i++) + { + out_data[2*i] = (in_data[i]>>4); + out_data[2*i+1] = (in_data[i]&0x0F); + } + for(unsigned char i = 0; i < 2*Size; i++) + { + if ((out_data[i] >= 0) && (out_data[i] <= 9)) + { + out_data[i] = '0'+out_data[i]; + } + else if ((out_data[i] >= 0x0A) && (out_data[i] <= 0x0F)) + { + out_data[i] = 'A'- 10 +out_data[i]; + } + else + { + return; + } + } +} +void numTohex(unsigned char *out_data, unsigned char *in_data, unsigned short Size) +{ + unsigned char temp; + for(unsigned char i = 0; i < Size; i++) + { + temp = Char2Nibble(in_data[2*i]); + temp = temp<<4; + temp += Char2Nibble(in_data[2*i+1]); + out_data[i] = temp; + } +} + + +uint8_t Char2Nibble(char Char) +{ + if (((Char >= '0') && (Char <= '9'))) + { + return Char - '0'; + } + else if (((Char >= 'a') && (Char <= 'f'))) + { + return Char - 'a' + 10; + } + else if ((Char >= 'A') && (Char <= 'F')) + { + return Char - 'A' + 10; + } + else + { + return 0xF0; + } +} + + +/* USER CODE BEGIN PFP */ +static int8_t ascii_4bit_to_hex(uint8_t ascii) { + int8_t result = -1; + if ((ascii >= '0') && (ascii <= '9')) { + result = ascii - 0x30; + } else if ((ascii >= 'a') && (ascii <= 'f')) { + result = ascii - 'a' + 10; + } else if ((ascii >= 'A') && (ascii <= 'F')) { + result = ascii - 'A' + 10; + } + return result; +} + +static void uint64_to_bytes(uint64_t data,uint8_t *bytes) { + bytes[0] = (uint8_t)(data>>56); + bytes[1] = (uint8_t)(data>>48); + bytes[2] = (uint8_t)(data>>40); + bytes[3] = (uint8_t)(data>>32); + bytes[4] = (uint8_t)(data>>24); + bytes[5] = (uint8_t)(data>>16); + bytes[6] = (uint8_t)(data>>8); + bytes[7] = (uint8_t)(data); +} + + +static int8_t Data_Analysis(const char *param, uint8_t Buff[], uint8_t lenth) { + uint8_t param_length = 0; + int8_t result = 0; + for (uint8_t j = 0; j < lenth; j++) { + if (param_length > strlen(param)) { + return -1; + } + result = ascii_4bit_to_hex(param[param_length++]); + if (result == -1) { + return -1; + } else { + Buff[j] = result << 4; + } + result = ascii_4bit_to_hex(param[param_length++]); + if (result == -1) { + return -1; + } else { + Buff[j] = Buff[j] | result; + } + param_length++; // The byte is a colon + } + return 0; +} + +/* Private Functions Definition -----------------------------------------------*/ +static void print_uint32_as_02x(uint32_t value) +{ + AT_PRINTF("\"%02X:%02X:%02X:%02X\"", + (unsigned)((unsigned char *)(&value))[3], + (unsigned)((unsigned char *)(&value))[2], + (unsigned)((unsigned char *)(&value))[1], + (unsigned)((unsigned char *)(&value))[0]); +} + +static void print_16_02x(uint8_t *pt) +{ + AT_PRINTF("\"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\"", + pt[0], pt[1], pt[2], pt[3], + pt[4], pt[5], pt[6], pt[7], + pt[8], pt[9], pt[10], pt[11], + pt[12], pt[13], pt[14], pt[15]); +} + +static void print_8_02x(uint8_t *pt) +{ + AT_PRINTF("\"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\"", + pt[0], pt[1], pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]); +} + +static void print_d(int32_t value) +{ + AT_PRINTF("%d\r\n", value); +} + +static void print_u(uint32_t value) +{ + AT_PRINTF("%u\r\n", value); +} + +static int32_t stringToData(const char *str, uint8_t *data, uint32_t Size) +{ + char hex[3]; + hex[2] = 0; + int32_t ii = 0; + while (Size-- > 0) + { + hex[0] = *str++; + hex[1] = *str++; + + /*check if input is hex */ + if ((isHex(hex[0]) == -1) || (isHex(hex[1]) == -1)) + { + return -1; + } + /*check if input is even nb of character*/ + if ((hex[1] == '\0') || (hex[1] == ',')) + { + return -1; + } + data[ii] = (Char2Nibble(hex[0]) << 4) + Char2Nibble(hex[1]); + ii++; + } + + return 0; +} + + +static int32_t isHex(char Char) +{ + if (((Char >= '0') && (Char <= '9')) || + ((Char >= 'a') && (Char <= 'f')) || + ((Char >= 'A') && (Char <= 'F'))) + { + return 0; + } + else + { + return -1; + } +} +static int32_t isNum(char Char) +{ + if ((Char >= '0') && (Char <= '9')) + { + return 0; + } + else + { + return -1; + } +} +int32_t isNums(const char *str, uint32_t Size) +{ + for(uint8_t u8i; u8i < Size; u8i++) + { + /*check if input is hex */ + if ((isNum(str[u8i]) == -1)) + { + return -1; + } + } + return 0; +} + + +ATEerror_t AT_return_ok(const char *param) +{ + return AT_OK; +} + +ATEerror_t AT_return_error(const char *param) +{ + return AT_ERROR; +} + +/* --------------- Keys, IDs and EUIs management commands --------------- */ + +/*------------------------AT+APPEUI=?\r\n-------------------------------------*/ +ATEerror_t AT_JoinEUI_get(const char *param) { + print_8_02x(app_param.lora_info.JoinEui); + return AT_OK; +} + +ATEerror_t AT_JoinEUI_set(const char *param) { + uint8_t joineui[8]; + + if ((Data_Analysis(param, joineui, 8) == -1) || (strlen(param) != 25)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.JoinEui[0],joineui,SE_EUI_SIZE) != 0) + { + memcpy((uint8_t *)app_param.lora_info.JoinEui, joineui, SE_EUI_SIZE); + } + return AT_OK; +} +/*------------------------AT+APPEUI=?\r\n-------------------------------------*/ + +/*------------------------AT+NWKKEY=?\r\n-------------------------------------*/ +ATEerror_t AT_NwkKey_get(const char *param) { + print_16_02x(app_param.lora_info.NwkKey); + + return AT_OK; +} + +ATEerror_t AT_NwkKey_set(const char *param) { + uint8_t nwkKey[16]; + + if ((Data_Analysis(param, nwkKey, 16) == -1) || (strlen(param) != 49)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.NwkKey[0],nwkKey,SE_KEY_SIZE) != 0) + { + memcpy((uint8_t *)app_param.lora_info.NwkKey, nwkKey, SE_KEY_SIZE); + } + return AT_OK; +} +/*------------------------AT+NWKKEY=?\r\n-------------------------------------*/ + +/*------------------------AT+APPKEY=?\r\n-------------------------------------*/ +ATEerror_t AT_AppKey_get(const char *param) { + print_16_02x(app_param.lora_info.AppKey); + + return AT_OK; +} + +ATEerror_t AT_AppKey_set(const char *param) { + + uint8_t appKey[16]; + if ((Data_Analysis(param, appKey, 16) == -1) || (strlen(param) != 49)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.AppKey[0], appKey, SE_KEY_SIZE) != 0) + { + memcpy((uint8_t *)app_param.lora_info.AppKey, appKey, SE_KEY_SIZE); + } + return AT_OK; +} +/*------------------------AT+APPKEY=?\r\n-------------------------------------*/ +/*------------------------AT+NWKSKEY=?\r\n-------------------------------------*/ + +ATEerror_t AT_NwkSKey_get(const char *param) { + print_16_02x(app_param.lora_info.NwkSKey); + return AT_OK; +} + +ATEerror_t AT_NwkSKey_set(const char *param) { + uint8_t nwkSKey[16]; + + if ((Data_Analysis(param, nwkSKey, 16) == -1) || (strlen(param) != 49)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.NwkSKey[0], nwkSKey, 16) != 0) + { + memcpy((uint8_t *)app_param.lora_info.NwkSKey, nwkSKey, 16); + } + return AT_OK; +} +/*------------------------AT+NWKSKEY=?\r\n-------------------------------------*/ + +/*------------------------AT+APPSKEY=?\r\n -------------------------------------*/ +ATEerror_t AT_AppSKey_get(const char *param) { + print_16_02x(app_param.lora_info.AppSKey); + + return AT_OK; +} + +ATEerror_t AT_AppSKey_set(const char *param) { + + uint8_t appskey[16]; + + if ((Data_Analysis(param, appskey, 16) == -1) || (strlen(param) != 49)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.AppSKey[0], appskey, SE_KEY_SIZE) != 0) + { + memcpy((uint8_t *)app_param.lora_info.AppSKey, appskey, SE_KEY_SIZE); + } + return AT_OK; +} +/*------------------------AT+APPSKEY=?\r\n -------------------------------------*/ +/*------------------------AT+DADDR=?\r\n -------------------------------------*/ +ATEerror_t AT_DevAddr_get(const char *param) { + print_uint32_as_02x(app_param.lora_info.DevAddr); + + return AT_OK; +} + +ATEerror_t AT_DevAddr_set(const char *param) { + + uint32_t devAddr; + uint8_t devAddrtmp[4]; + if ((Data_Analysis(param, devAddrtmp, 4) == -1) || (strlen(param) != 13)) { + return AT_PARAM_ERROR; + } + + devAddr = (devAddrtmp[0] << 24) | (devAddrtmp[1] << 16) | (devAddrtmp[2] << 8) | devAddrtmp[3]; + if(app_param.lora_info.DevAddr != devAddr) + { + app_param.lora_info.DevAddr = devAddr; + } + return AT_OK; +} +/*------------------------AT+DADDR=?\r\n -------------------------------------*/ + +/*------------------------AT+DEUI=?\r\n-------------------------------------*/ +ATEerror_t AT_DevEUI_get(const char *param) { + print_8_02x(app_param.lora_info.DevEui); + return AT_OK; +} +ATEerror_t AT_DevEUI_set(const char *param) { + uint8_t devEui[8]; + + if ((Data_Analysis(param, devEui, 8) == -1) || (strlen(param) != 25)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.DevEui[0], devEui, SE_EUI_SIZE)!= 0) + { + memcpy((uint8_t *)app_param.lora_info.DevEui, devEui, SE_EUI_SIZE); + } + return AT_OK; +} +/*------------------------AT+DEUI=?\r\n-------------------------------------*/ + +/* --------------- LoRaWAN network management commands --------------- */ +/*------------------------AT+VER=?\r\n-------------------------------------*/ + +ATEerror_t AT_version_get(const char *param) { + smtc_modem_return_code_t modem_response_code = SMTC_MODEM_RC_OK; + smtc_modem_lorawan_version_t lorawan_version; + AT_PRINTF("\r\n{\r\n\t\"hw_ver\": \"V%d.%d\",", app_param.hardware_info.hw_ver&0xf0,app_param.hardware_info.hw_ver&0x0f); + modem_response_code = smtc_modem_get_lorawan_version( &lorawan_version ); + if( modem_response_code == SMTC_MODEM_RC_OK ) + { + AT_PRINTF("\r\n\t\"LoRaWAN\": \"V%X.%X.%X\"\r\n}", lorawan_version.major, lorawan_version.minor, lorawan_version.patch); + } + return AT_OK; +} +/*------------------------AT+VER=?\r\n-------------------------------------*/ + +/*------------------------AT+BAND=?\r\n-------------------------------------*/ +ATEerror_t AT_Region_get(const char *param) { + +#ifdef LORAWAN_APP_PARAM_ENABLE + //const char *regionStrings[] = {"AS923", "AU915", "CN470", "CN779", "EU433", "EU868", "KR920", "IN865", "US915", "RU864", "AS923_1", "AS923_2", "AS923_3", "AS923_4"}; + if (app_param.lora_info.ActiveRegion > LORAMAC_REGION_AS_GP_4 && app_param.lora_info.ActiveRegion != 0xFF) { + return AT_PARAM_ERROR; + } +#else + // const char *regionStrings[] = { "AS923", "AU915", "CN470", "CN779", "EU433", "EU868", "KR920", "IN865", "US915", "RU864" }; + if (app_param.lora_info.ActiveRegion > LORAMAC_REGION_RU864) { + return AT_PARAM_ERROR; + } +#endif + + AT_PRINTF("%d", app_param.lora_info.ActiveRegion); + + return AT_OK; +} + +ATEerror_t AT_Region_set(const char *param) { + + LoRaMacRegion_t region; + if (tiny_sscanf(param, "%hhu", ®ion) != 1) { + return AT_PARAM_ERROR; + } +#ifdef LORAWAN_APP_PARAM_ENABLE + if (((region > LORAMAC_REGION_AS_GP_4)&& (region != LORAMAC_REGION_MAX)) || (region == LORAMAC_REGION_CN470) || (region == LORAMAC_REGION_CN779) || (region == LORAMAC_REGION_EU433)) { + return AT_PARAM_ERROR; + } +#else + if (((region > LORAMAC_REGION_RU864)&& (region != LORAMAC_REGION_MAX)) || (region == LORAMAC_REGION_CN470) || (region == LORAMAC_REGION_CN779) || (region == LORAMAC_REGION_EU433)) { + return AT_PARAM_ERROR; + } +#endif + if(app_param.lora_info.ActiveRegion != region) + { + app_param.lora_info.ActiveRegion = region; + } + return AT_OK; +} + +/*------------------------AT+BAND=?\r\n-------------------------------------*/ +/*------------------------AT+TYPE=?\r\n-------------------------------------*/ +ATEerror_t AT_ActivationType_get(const char *param) { +// const char *activationTypeStrings[] = {"NONE", "ABP", "OTAA"}; + + if (app_param.lora_info.ActivationType > ACTIVATION_TYPE_OTAA) { + return AT_PARAM_ERROR; + } + AT_PRINTF("%d", app_param.lora_info.ActivationType); + return AT_OK; +} + +ATEerror_t AT_ActivationType_set(const char *param) { + uint8_t activetype; + if (tiny_sscanf(param, "%hhu", &activetype) != 1) { + return AT_PARAM_ERROR; + } + if (activetype > ACTIVATION_TYPE_OTAA) { + return AT_PARAM_ERROR; + } + if(app_param.lora_info.ActivationType != activetype) + { + app_param.lora_info.ActivationType = activetype == ACTIVATION_TYPE_OTAA ? ACTIVATION_TYPE_OTAA : ACTIVATION_TYPE_ABP; + } + return AT_OK; +} +/*------------------------AT+TYPE=?\r\n -------------------------------------*/ +/*------------------------AT+CHANNEL=?\r\n -------------------------------------*/ +ATEerror_t AT_ChannelGroup_get(const char *param) { + AT_PRINTF("%d", app_param.lora_info.ChannelGroup); + return AT_OK; +} + +ATEerror_t AT_ChannelGroup_set(const char *param) { + + uint8_t channelgroup = 0; + if (tiny_sscanf(param, "%hhu", &channelgroup) != 1) { + return AT_PARAM_ERROR; + } + if ((channelgroup <= 7) && ((app_param.lora_info.ActiveRegion == LORAMAC_REGION_US915) || (app_param.lora_info.ActiveRegion == LORAMAC_REGION_AU915))) { + if(app_param.lora_info.ChannelGroup != channelgroup) + { + app_param.lora_info.ChannelGroup = channelgroup; + } + return AT_OK; + } + else + { + return AT_PARAM_ERROR; + } + return AT_OK; +} +/*------------------------AT+CHANNEL=?\r\n -------------------------------------*/ + +/*------------------------AT+CONFIG=?\r\n -------------------------------------*/ +ATEerror_t AT_Config_get(const char *param) { + + read_current_param_config(); + AT_PRINTF("\r\n{\r\n"); + + AT_PRINTF("\t\"devMdl\": "); + if (AT_SensorType_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"deviceEui\": "); + if (AT_DevEUI_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"defEui\": "); + if (AT_DefEUI_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"appEui\": "); + if (AT_JoinEUI_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"frequency\": "); + if (AT_Region_get(param) != AT_OK) { + return AT_ERROR; + } + AT_PRINTF(",\r\n\t\"subBand\": "); + if (AT_ChannelGroup_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"joinType\": "); + if (AT_ActivationType_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"appKey\": "); + if (AT_AppKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"nwkSkey\": "); + if (AT_NwkSKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"appSkey\": "); + if (AT_AppSKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"devAddr\": "); + if (AT_DevAddr_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"devCode\": "); + if (AT_DevCODE_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"platform\": "); + if (AT_Platform_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"devKey\": "); + if (AT_DeviceKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"posInt\": "); + if (AT_POS_INT_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"sampleInt\": "); + if (AT_SAMPLE_INT_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF("\r\n}"); + return AT_OK; +} +/*------------------------AT+CONFIG=?\r\n -------------------------------------*/ + + +/*------------------------AT+AT_DEFPARAM=?\r\n -------------------------------------*/ +ATEerror_t AT_DefParam_get(const char *param) { + + read_default_param_config(); + AT_PRINTF("\r\n{\r\n"); + + AT_PRINTF("\t\"devMdl\": "); + if (AT_SensorType_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"deviceEui\": "); + if (AT_DevEUI_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"defEui\": "); + if (AT_DefEUI_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"appEui\": "); + if (AT_JoinEUI_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"frequency\": "); + if (AT_Region_get(param) != AT_OK) { + return AT_ERROR; + } + AT_PRINTF(",\r\n\t\"subBand\": "); + if (AT_ChannelGroup_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"joinType\": "); + if (AT_ActivationType_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"appKey\": "); + if (AT_AppKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"nwkSkey\": "); + if (AT_NwkSKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"appSkey\": "); + if (AT_AppSKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"devAddr\": "); + if (AT_DevAddr_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"devCode\": "); + if (AT_DevCODE_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"platform\": "); + if (AT_Platform_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"devKey\": "); + if (AT_DeviceKey_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"posInt\": "); + if (AT_POS_INT_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF(",\r\n\t\"sampleInt\": "); + if (AT_SAMPLE_INT_get(param) != AT_OK) { + return AT_ERROR; + } + + AT_PRINTF("\r\n}"); + read_current_param_config(); + return AT_OK; +} +/*------------------------AT+AT_DEFPARAM=?\r\n -------------------------------------*/ + + +/*------------------------AT+DCODE=?\r\n-------------------------------------*/ +ATEerror_t AT_DevCODE_get(const char *param) { + print_8_02x(app_param.lora_info.DeviceCode); + + return AT_OK; +} + +ATEerror_t AT_DevCODE_set(const char *param) { + + uint8_t devCode[8]; + + if ((Data_Analysis(param, devCode, 8) == -1) || (strlen(param) != 25)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.DeviceCode[0], devCode, SE_EUI_SIZE) != 0) + { + memcpy((uint8_t *)app_param.lora_info.DeviceCode, devCode, SE_EUI_SIZE); + } + + return AT_OK; +} +/*------------------------AT+DCODE=?\r\n-------------------------------------*/ + +/*------------------------AT+SN=?\r\n-------------------------------------*/ +ATEerror_t AT_Sn_get(const char *param) { + + AT_PRINTF("\"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\"", app_param.hardware_info.Sn[0], app_param.hardware_info.Sn[1], + app_param.hardware_info.Sn[2], app_param.hardware_info.Sn[3], + app_param.hardware_info.Sn[4], app_param.hardware_info.Sn[5], + app_param.hardware_info.Sn[6], app_param.hardware_info.Sn[7], + app_param.hardware_info.Sn[8]); + + + return AT_OK; +} + +ATEerror_t AT_Sn_set(const char *param) { + uint8_t sn[9]; + + if ((Data_Analysis(param, sn, 9) == -1) || (strlen(param) != 28)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.hardware_info.Sn[0], sn, 9) != 0) + { + memcpy((uint8_t *)app_param.hardware_info.Sn, sn, 9); + } + return AT_OK; +} +/*------------------------AT+SN=?\r\n-------------------------------------*/ +/*------------------------AT+DKEY=?\r\n-------------------------------------*/ +ATEerror_t AT_DeviceKey_get(const char *param) { + print_16_02x(app_param.lora_info.DeviceKey); + return AT_OK; +} + +ATEerror_t AT_DeviceKey_set(const char *param) +{ + uint8_t deviceKey[16]; + if ((Data_Analysis(param, deviceKey, 16) == -1) || (strlen(param) != 49)) { + return AT_PARAM_ERROR; + } + if(memcmp(&app_param.lora_info.DeviceKey[0], deviceKey, SE_KEY_SIZE) != 0) + { + memcpy((uint8_t *)app_param.lora_info.DeviceKey, deviceKey, SE_KEY_SIZE); + } + return AT_OK; +} + +/*------------------------AT+DKEY=?\r\n-------------------------------------*/ + +/*------------------------AT+HARDWAREVER=?\r\n-------------------------------------*/ +ATEerror_t AT_HARDWAREVER_get(const char *param) +{ + AT_PRINTF("%d.%d",app_param.hardware_info.hw_ver&0xf0,app_param.hardware_info.hw_ver&0x0f); + return AT_OK; +} + +/*------------------------AT+RESTORE\r\n-------------------------------------*/ +ATEerror_t AT_Parameter_Reset(const char *param) +{ + if (!read_default_param_config()) + { + return AT_READ_ERROR; + } + else + { + if (!write_current_param_config()) + { + return AT_SAVE_FAILED; + } + else + { + app_append_param.position_interval = 5; + app_append_param.sample_interval = 5; + app_append_param.cache_en = true; + app_append_param.Platform = IOT_PLATFORM_SENSECAP_TTN; + app_append_param.Retry = 1; + if(0 != write_app_append_param()) + { + return AT_SAVE_FAILED; + } + } + return AT_OK; + } + return AT_OK; +} +/*------------------------AT+RESTORE\r\n-------------------------------------*/ + +/*------------------------AT+POS_INT\r\n-------------------------------------*/ +ATEerror_t AT_POS_INT_get(const char *param) +{ + AT_PRINTF("%d",app_append_param.position_interval); + return AT_OK; +} + +ATEerror_t AT_POS_INT_set(const char *param) +{ + uint16_t pos_interval = 0; + if (tiny_sscanf(param, "%hu", &pos_interval) != 1) { + return AT_PARAM_ERROR; + } + if((pos_interval < 5)||(pos_interval > 1440)) + { + return AT_PARAM_ERROR; + } + if(pos_interval != app_append_param.position_interval) + { + app_append_param.position_interval = pos_interval; + if(0 != write_app_append_param()) + { + return AT_SAVE_FAILED; + } + } + return AT_OK; +} +/*------------------------AT+POS_INT\r\n-------------------------------------*/ + +/*------------------------AT+SAMPLE_INT\r\n-------------------------------------*/ +ATEerror_t AT_SAMPLE_INT_get(const char *param) +{ + AT_PRINTF("%d",app_append_param.sample_interval); + return AT_OK; +} + +ATEerror_t AT_SAMPLE_INT_set(const char *param) +{ + uint16_t sample_interval = 0; + if (tiny_sscanf(param, "%hu", &sample_interval) != 1) { + return AT_PARAM_ERROR; + } + if((sample_interval < 5)||(sample_interval > 1440)) + { + return AT_PARAM_ERROR; + } + if(sample_interval != app_append_param.sample_interval) + { + app_append_param.sample_interval = sample_interval; + if(0 != write_app_append_param()) + { + return AT_SAVE_FAILED; + } + } + return AT_OK; +} +/*------------------------AT+SAMPLE_INT\r\n-------------------------------------*/ + + +/*------------------------AT+SENSOR=?\r\n -------------------------------------*/ +ATEerror_t AT_SensorType_get(const char *param) { + + AT_PRINTF("%s", "\"Wio Tracker 1110\""); + return AT_OK; +} +/*------------------------AT+SENSOR=?\r\n -------------------------------------*/ + +/*------------------------AT+PLATFORM=?\r\n-------------------------------------*/ +ATEerror_t AT_Platform_get(const char *param) { + AT_PRINTF("%d", app_append_param.Platform); + + return AT_OK; +} + +ATEerror_t AT_Platform_set(const char *param) { + + uint8_t platform = 0; + if (tiny_sscanf(param, "%hhu", &platform) != 1) { + return AT_PARAM_ERROR; + } + + if (platform < IOT_PLATFORM_MAX) + { + if(app_append_param.Platform != platform) + { + app_append_param.Platform = (platform_t)platform; + if(0 != write_app_append_param()) + { + return AT_SAVE_FAILED; + } + } + return AT_OK; + } + else + { + return AT_PARAM_ERROR; + } + return AT_OK; +} + + +/*------------------------AT+PLATFORM=?\r\n-------------------------------------*/ + +ATEerror_t AT_DefEUI_get(const char *param) { + + memset(def_eui,0,8); + if(!default_factory_eui_get(def_eui)) + { + return AT_READ_ERROR; + } + print_8_02x(def_eui); + return AT_OK; +} + + +/*------------------------AT+MEA=?\r\n-------------------------------------*/ + +ATEerror_t AT_MeasurementValue_get(const char *param) { + + int16_t temperture_temp = 0; + uint8_t humidity_temp = 0; + int16_t acc_x_temp; + int16_t acc_y_temp; + int16_t acc_z_temp; + + + single_fact_sensor_data_get(lis3dhtr_sensor_type); + single_fact_sensor_data_get(sht4x_sensor_type); + temperture_temp = 10*sht4x_temperature; + humidity_temp = sht4x_humidity; + acc_x_temp = 100*lis3dhtr_x*9.80; + acc_y_temp = 100*lis3dhtr_y*9.80; + acc_z_temp = 100*lis3dhtr_z*9.80; + AT_PRINTF("\r\n{\r\n\t\"4097\":\t%d",(temperture_temp*100)); + AT_PRINTF(",\r\n\t\"4098\":\t%d",humidity_temp*1000); + AT_PRINTF(",\r\n\t\"4150\":\t%d",acc_x_temp*10); + AT_PRINTF(",\r\n\t\"4151\":\t%d",acc_y_temp*10); + AT_PRINTF(",\r\n\t\"4152\":\t%d\r\n}\r\n",acc_z_temp*10); + + // hal_mcu_gpio_deinit(VCC_SENSOR_CTR); + return AT_OK; +} +/*------------------------AT+MEA=?\r\n-------------------------------------*/ diff --git a/libraries/LBM_packet/src/app_param/at.h b/libraries/LBM_packet/src/app_param/at.h new file mode 100644 index 000000000..e5dd5f72f --- /dev/null +++ b/libraries/LBM_packet/src/app_param/at.h @@ -0,0 +1,390 @@ +#ifndef __AT_H__ +#define __AT_H__ + +#include +#include +#include +#include +#include + +#include "Lbm_packet.hpp" + +#include "at_command.h" + +extern uint8_t parse_cmd_type; +extern void hal_mcu_trace_print( const char* fmt, ... ); +extern void hal_ble_trace_print( const char* fmt, ... ); + +#define AT_PRINTF(...) do{ if(parse_cmd_type == 1)\ + {\ + hal_ble_trace_print ( __VA_ARGS__ );\ + }\ + hal_mcu_wait_ms(1);\ + }while(0) +#define AT_PPRINTF(...) do{ if(parse_cmd_type == 1)\ + {\ + hal_ble_trace_print ( __VA_ARGS__ );\ + }\ + hal_mcu_wait_ms(1);\ + }while(0) + + +/* AT Command strings. Commands start with AT */ +/* General commands */ +#define AT_VER "+VER" + +#define AT_CONFIG "+CONFIG" +#define AT_DEFPARAM "+DEFPARAM" + +#define AT_SN "+SN" + +/* LoRaWAN network management commands */ +#define AT_TYPE "+TYPE" +#define AT_BAND "+BAND" +#define AT_CHANNEL "+CHANNEL" +#define AT_RETEY "+RETRY" +#define AT_DCODE "+DCODE" + +/* Keys, IDs and EUIs management commands */ +#define AT_JOINEUI "+APPEUI" +#define AT_NWKKEY "+NWKKEY" +#define AT_APPKEY "+APPKEY" +#define AT_NWKSKEY "+NWKSKEY" +#define AT_APPSKEY "+APPSKEY" +#define AT_DADDR "+DADDR" +#define AT_DEUI "+DEUI" +#define AT_DKEY "+DKEY" + +#define AT_HARDWAREVER "+HARDWAREVER" + + +#define AT_RESTORE "+RESTORE" +#define AT_POS_INT "+POS_INT" +#define AT_SAMPLE_INT "+SAMPLE_INT" +#define AT_SENSOR "+SENSOR" +#define AT_PLATFORM "+PLATFORM" +#define AT_MEA "+MEA" + + +/* USER CODE BEGIN EM */ +void hexTonum(unsigned char *out_data, unsigned char *in_data, unsigned short Size); +void numTohex(unsigned char *out_data, unsigned char *in_data, unsigned short Size); +uint8_t Char2Nibble(char Char); + +/* USER CODE END EM */ + +/* Exported functions prototypes ---------------------------------------------*/ +/** + * @brief Return AT_OK in all cases + * @param param string of the AT command - unused + * @retval AT_OK + */ +ATEerror_t AT_return_ok(const char *param); + +/** + * @brief Return AT_ERROR in all cases + * @param param string of the AT command - unused + * @retval AT_ERROR + */ +ATEerror_t AT_return_error(const char *param); + +/* --------------- Application events --------------- */ + +/* --------------- General commands --------------- */ + +/* --------------- Keys, IDs and EUIs management commands --------------- */ +/** + * @brief Print Join Eui + * @param param string of the AT command + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ +ATEerror_t AT_JoinEUI_get(const char *param); + +/** + * @brief Set Join Eui + * @param param string of the AT command + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ +ATEerror_t AT_JoinEUI_set(const char *param); + +/** + * @brief Print Network Key + * @param param string of the AT command + * @retval AT_OK + */ +ATEerror_t AT_NwkKey_get(const char *param); + +/** + * @brief Set Network Key + * @param param string of the AT command + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ +ATEerror_t AT_NwkKey_set(const char *param); + +/** + * @brief Print Application Key + * @param param string of the AT command + * @retval AT_OK + */ +ATEerror_t AT_AppKey_get(const char *param); + +/** + * @brief Set Application Key + * @param param string of the AT command + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ +ATEerror_t AT_AppKey_set(const char *param); + +/** + * @brief Print Network Session Key + * @param param string of the AT command + * @retval AT_OK + */ +ATEerror_t AT_NwkSKey_get(const char *param); + +/** + * @brief Set Network Session Key + * @param param String pointing to provided DevAddr + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ +ATEerror_t AT_NwkSKey_set(const char *param); + +/** + * @brief Print Application Session Key + * @param param string of the AT command + * @retval AT_OK + */ +ATEerror_t AT_AppSKey_get(const char *param); + +/** + * @brief Set Application Session Key + * @param param String pointing to provided DevAddr + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ +ATEerror_t AT_AppSKey_set(const char *param); + +/** + * @brief Print the DevAddr + * @param param String pointing to provided DevAddr + * @retval AT_OK + */ +ATEerror_t AT_DevAddr_get(const char *param); + +/** + * @brief Set DevAddr + * @param param String pointing to provided DevAddr + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ +ATEerror_t AT_DevAddr_set(const char *param); + +/** + * @brief Print Device EUI + * @param param string of the AT command - unused + * @retval AT_OK + */ +ATEerror_t AT_DevEUI_get(const char *param); + +/** + * @brief Set Device EUI + * @param param string of the AT command + * @retval AT_OK if OK + */ +ATEerror_t AT_DevEUI_set(const char *param); + +/* --------------- LoRaWAN join and send data commands --------------- */ + +/* --------------- LoRaWAN network management commands --------------- */ +/** + * @brief Print the version of the AT_Slave FW + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_version_get(const char *param); +/** + * @brief Print the version of the device + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_config_ver_get(const char *param); + +/** + * @brief Print actual Active Region + * @param param string of the AT command - unused + * @retval AT_OK + */ +ATEerror_t AT_Region_get(const char *param); + +/** + * @brief Set Active Region + * @param param string of the AT command + * @retval AT_OK if OK + */ +ATEerror_t AT_Region_set(const char *param); + +/** + * @brief Print actual Active Type + * @param param string of the AT command - unused + * @retval AT_OK + */ +ATEerror_t AT_ActivationType_get(const char *param); + +/** + * @brief Set Active Type + * @param param string of the AT command + * @retval AT_OK if OK + */ +ATEerror_t AT_ActivationType_set(const char *param); + +/** + * @brief Print channel group + * @param param string of the AT command - unused + * @retval AT_OK + */ +ATEerror_t AT_ChannelGroup_get(const char *param); + +/** + * @brief Set channel group + * @param param string of the AT command + * @retval AT_OK if OK + */ +ATEerror_t AT_ChannelGroup_set(const char *param); + +/** + * @brief Set Sensor Type + * @param param String pointing to provided param + * @retval AT_OK if OK, or an appropriate AT_xxx error code + */ + +ATEerror_t AT_DeviceClass_get(const char *param); + +/** + * @brief get device paramenter + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_Config_get(const char *param); + +/** + * @brief get device paramenter + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_DefParam_get(const char *param); +/** + * @brief set device code + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_DevCODE_set(const char *param); +/** + * @brief get device code + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_DevCODE_get(const char *param); + +/** + * @brief set device serial number + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_Sn_set(const char *param); +/** + * @brief get device serial number + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_Sn_get(const char *param); +/** + * @brief set lora device key + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_DeviceKey_set(const char *param); +/** + * @brief get lora device key + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_DeviceKey_get(const char *param); + +/** + * @brief get hardware version + * @param param String parameter + * @retval AT_OK + */ + +ATEerror_t AT_HARDWAREVER_get(const char *param); + +/** + * @brief restore param + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_Parameter_Reset(const char *param); + +/** + * @brief get position interval + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_POS_INT_get(const char *param); + +/** + * @brief set position interval + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_POS_INT_set(const char *param); + +/** + * @brief get sample interval + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_SAMPLE_INT_get(const char *param); + +/** + * @brief set sample interval + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_SAMPLE_INT_set(const char *param); + +/** + * @brief get device type + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_SensorType_get(const char *param); + +/** + * @brief set lora join net platform + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_Platform_set(const char *param); +/** + * @brief get lora join net platform + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_Platform_get(const char *param); + +/** + * @brief get default DevEui + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_DefEUI_get(const char *param); + +/** + * @brief collect sensor data + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_MeasurementValue_get(const char *param); + +#endif /* __AT_H__ */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libraries/LBM_packet/src/app_param/at_command.cpp b/libraries/LBM_packet/src/app_param/at_command.cpp new file mode 100644 index 000000000..42e1d8622 --- /dev/null +++ b/libraries/LBM_packet/src/app_param/at_command.cpp @@ -0,0 +1,290 @@ +#include +#include + +#include "at.h" +#include "at_command.h" +#include "default_config_datas.h" + + + + +/** + * @brief Array corresponding to the description of each possible AT Error + */ +static const char *const ATError_description[] = +{ + "\r\nOK\r\n", /* AT_OK */ + "\r\nAT_ERROR\r\n", /* AT_ERROR */ + "\r\nAT_PARAM_ERROR\r\n", /* AT_PARAM_ERROR */ + "\r\nAT_BUSY_ERROR\r\n", /* AT_BUSY_ERROR */ + "\r\nAT_TEST_PARAM_OVERFLOW\r\n", /* AT_TEST_PARAM_OVERFLOW */ + "\r\nAT_NO_NETWORK_JOINED\r\n", /* AT_NO_NET_JOINED */ + "\r\nAT_RX_ERROR\r\n", /* AT_RX_ERROR */ + "\r\nAT_NO_CLASS_B_ENABLE\r\n", /* AT_NO_CLASS_B_ENABLE */ + "\r\nAT_DUTYCYCLE_RESTRICTED\r\n", /* AT_DUTYCYCLE_RESTRICTED */ + "\r\nAT_CRYPTO_ERROR\r\n", /* AT_CRYPTO_ERROR */ + "\r\nAT_SAVE_FAILED\r\n", /* AT_SAVE_FAILED */ + "\r\nAT_READ_FAILED\r\n", /* AT_READ_ERROR */ + "\r\nAT_DELETE_ERROR\r\n", /* AT_READ_ERROR */ + "\r\nerror unknown\r\n", /* AT_MAX */ +}; + +/** + * @brief Array of all supported AT Commands + */ +static const struct ATCommand_s ATCommand[] = +{ + /* Keys, IDs and EUIs management commands */ + { + .string = AT_JOINEUI, + .size_string = sizeof(AT_JOINEUI) - 1, + .get = AT_JoinEUI_get, + .set = AT_JoinEUI_set, + .run = AT_return_error, + }, + { + .string = AT_NWKKEY, + .size_string = sizeof(AT_NWKKEY) - 1, + .get = AT_NwkKey_get, + .set = AT_NwkKey_set, + .run = AT_return_error, + }, + { + .string = AT_APPKEY, + .size_string = sizeof(AT_APPKEY) - 1, + .get = AT_AppKey_get, + .set = AT_AppKey_set, + .run = AT_return_error, + }, + { + .string = AT_NWKSKEY, + .size_string = sizeof(AT_NWKSKEY) - 1, + .get = AT_NwkSKey_get, + .set = AT_NwkSKey_set, + .run = AT_return_error, + }, + { + .string = AT_APPSKEY, + .size_string = sizeof(AT_APPSKEY) - 1, + .get = AT_AppSKey_get, + .set = AT_AppSKey_set, + .run = AT_return_error, + }, + { + .string = AT_DADDR, + .size_string = sizeof(AT_DADDR) - 1, + .get = AT_DevAddr_get, + .set = AT_DevAddr_set, + .run = AT_return_error, + }, + + { + .string = AT_DEUI, + .size_string = sizeof(AT_DEUI) - 1, + .get = AT_DevEUI_get, + .set = AT_DevEUI_set, + .run = AT_return_error, + }, + + /* LoRaWAN network management commands */ + { + .string = AT_VER, + .size_string = sizeof(AT_VER) - 1, + .get = AT_version_get, + .set = AT_return_error, + .run = AT_return_error, + }, + { + .string = AT_BAND, + .size_string = sizeof(AT_BAND) - 1, + .get = AT_Region_get, + .set = AT_Region_set, + .run = AT_return_error, + }, + + { + .string = AT_TYPE, + .size_string = sizeof(AT_TYPE) - 1, + .get = AT_ActivationType_get, + .set = AT_ActivationType_set, + .run = AT_return_error, + }, + + { + .string = AT_CHANNEL, + .size_string = sizeof(AT_CHANNEL) - 1, + .get = AT_ChannelGroup_get, + .set = AT_ChannelGroup_set, + .run = AT_return_error, + }, + { + .string = AT_CONFIG, + .size_string = sizeof(AT_CONFIG) - 1, + .get = AT_Config_get, + .set = AT_return_error, + .run = AT_return_error, + }, + { + .string = AT_DEFPARAM, + .size_string = sizeof(AT_DEFPARAM) - 1, + .get = AT_DefParam_get, + .set = AT_return_error, + .run = AT_return_error, + }, + { + .string = AT_DCODE, + .size_string = sizeof(AT_DCODE) - 1, + .get = AT_DevCODE_get, + .set = AT_DevCODE_set, + .run = AT_return_error, + }, + + { + .string = AT_SN, + .size_string = sizeof(AT_SN) - 1, + .get = AT_Sn_get, + .set = AT_Sn_set, + .run = AT_return_error, + }, + { + .string = AT_DKEY, + .size_string = sizeof(AT_DKEY) - 1, + .get = AT_DeviceKey_get, + .set = AT_DeviceKey_set, + .run = AT_return_error, + }, + { + .string = AT_HARDWAREVER, + .size_string = sizeof(AT_HARDWAREVER) - 1, + .get = AT_HARDWAREVER_get, + .set = AT_return_error, + .run = AT_return_error, + }, + { + .string = AT_RESTORE, + .size_string = sizeof(AT_RESTORE) - 1, + .get = AT_return_error, + .set = AT_return_error, + .run = AT_Parameter_Reset, + }, + { + .string = AT_POS_INT, + .size_string = sizeof(AT_POS_INT) - 1, + .get = AT_POS_INT_get, + .set = AT_POS_INT_set, + .run = AT_return_error, + }, + { + .string = AT_SAMPLE_INT, + .size_string = sizeof(AT_SAMPLE_INT) - 1, + .get = AT_SAMPLE_INT_get, + .set = AT_SAMPLE_INT_set, + .run = AT_return_error, + }, + { + .string = AT_SENSOR, + .size_string = sizeof(AT_SENSOR) - 1, + .get = AT_SensorType_get, + .set = AT_return_error, + .run = AT_return_error, + }, + { + .string = AT_PLATFORM, + .size_string = sizeof(AT_PLATFORM) - 1, + .get = AT_Platform_get, + .set = AT_Platform_set, + .run = AT_return_error, + }, + { + .string = AT_MEA, + .size_string = sizeof(AT_MEA) - 1, + .get = AT_MeasurementValue_get, + .set = AT_return_error, + .run = AT_return_error, + }, +}; + +/** + * @brief Parse a command and process it + * @param cmd The command + * @param cmd length + */ + +void parse_cmd(const char *cmd, uint16_t length) +{ + ATEerror_t status = AT_OK; + const struct ATCommand_s *Current_ATCommand; + int32_t i; + + if (strncmp(cmd, "AT", 2)) + { + status = AT_ERROR; + + // trace_debug("Invail cmd:%s\r\n", cmd); + } + else if (cmd[2] == '\0') + { + /* status = AT_OK; */ + } + else + { + /*excluding AT */ + if ((cmd[length - 1] != '\n') || (cmd[length - 2] != '\r')) + { + status = AT_PARAM_ERROR; + } + else + { + status = AT_ERROR; + cmd += 2; + for (i = 0; i < (sizeof(ATCommand) / sizeof(struct ATCommand_s)); i++) + { + if (strncmp(cmd, ATCommand[i].string, ATCommand[i].size_string) == 0) + { + Current_ATCommand = &(ATCommand[i]); + /* point to the string after the command to parse it */ + cmd += Current_ATCommand->size_string; + + /* parse after the command */ + switch (cmd[0]) + { + case '\r': /* nothing after the command */ + if (cmd[1] == '\n') + { + status = Current_ATCommand->run(cmd); + } + break; + case '=': + // if ((cmd[1] == '?') && (cmd[2] == '\0')) + if ((cmd[1] == '?') && (cmd[2] == '\r') && (cmd[3] == '\n')) //) + { + status = Current_ATCommand->get(cmd + 1); + } + else + { + status = Current_ATCommand->set(cmd + 1); + if (status == AT_OK) + { + if (!write_current_param_config()) + { + status = AT_SAVE_FAILED; + } + } + } + break; + case '?': + status = AT_OK; + break; + default: + /* not recognized */ + break; + } + break; + } + } + } + } + AT_PPRINTF("%s", status < AT_MAX ? ATError_description[status] : ATError_description[AT_MAX]); +} + + diff --git a/libraries/LBM_packet/src/app_param/at_command.h b/libraries/LBM_packet/src/app_param/at_command.h new file mode 100644 index 000000000..d9b1e7986 --- /dev/null +++ b/libraries/LBM_packet/src/app_param/at_command.h @@ -0,0 +1,49 @@ +#ifndef __AT_COMMAND_H__ +#define __AT_COMMAND_H__ + +#include +#include "at.h" + + +/* + * AT Command Id errors. Note that they are in sync with ATError_description static array + * in command.c + */ +typedef enum eATEerror +{ + AT_OK = 0, + AT_ERROR, + AT_PARAM_ERROR, + AT_BUSY_ERROR, + AT_TEST_PARAM_OVERFLOW, + AT_NO_NET_JOINED, + AT_RX_ERROR, + AT_NO_CLASS_B_ENABLE, + AT_DUTYCYCLE_RESTRICTED, + AT_CRYPTO_ERROR, + AT_SAVE_FAILED, + AT_READ_ERROR, + AT_DELETE_ERROR, + AT_MAX, +} ATEerror_t; + + + +/** + * @brief Structure defining an AT Command + */ +struct ATCommand_s +{ + const char *string; /*< command string, after the "AT" */ + const int32_t size_string; /*< size of the command string, not including the final \0 */ + ATEerror_t (*get)(const char *param); /*< =? after the string to get the current value*/ + ATEerror_t (*set)(const char *param); /*< = (but not =?\0) after the string to set a value */ + ATEerror_t (*run)(const char *param); /*< \0 after the string - run the command */ /* !NO_HELP */ +}; + + +void parse_cmd(const char *cmd,uint16_t length); + + +#endif /* __AT_COMMAND_H__*/ + diff --git a/libraries/LBM_packet/src/app_param/default_config_datas.cpp b/libraries/LBM_packet/src/app_param/default_config_datas.cpp index b22e763f2..fe3a05ff0 100644 --- a/libraries/LBM_packet/src/app_param/default_config_datas.cpp +++ b/libraries/LBM_packet/src/app_param/default_config_datas.cpp @@ -91,3 +91,17 @@ uint8_t crc8(uint8_t *data, uint8_t data_len) return crc ^0x00; } + + + + + + + + + + + + + + diff --git a/libraries/LBM_packet/src/app_param/default_config_datas.h b/libraries/LBM_packet/src/app_param/default_config_datas.h index 7d975cdc1..d1d5cf634 100644 --- a/libraries/LBM_packet/src/app_param/default_config_datas.h +++ b/libraries/LBM_packet/src/app_param/default_config_datas.h @@ -14,6 +14,11 @@ int default_config_write (uint8_t *buffer, uint8_t size); bool save_Config(void); void get_Config(void); uint8_t crc8(uint8_t *data, uint8_t data_len); + + + + + #endif diff --git a/libraries/LBM_packet/src/app_param/key_value_fds.cpp b/libraries/LBM_packet/src/app_param/key_value_fds.cpp new file mode 100644 index 000000000..1ea720e2e --- /dev/null +++ b/libraries/LBM_packet/src/app_param/key_value_fds.cpp @@ -0,0 +1,347 @@ +/** + ***************************************************************************************** + * + * @file key_value_fds.c + * + * @brief Key Value Flash Data Storage Implementation. + * + ***************************************************************************************** + * @attention + #####Copyright (c) 2019 GOODIX + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GOODIX nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + ***************************************************************************************** + */ + +/* + * INCLUDE FILES + ***************************************************************************************** + */ +#include "key_value_fds.h" + +#include "Lbm_packet.hpp" + +using namespace Adafruit_LittleFS_Namespace; + + + +#define KEY_VALUE_FDS_VERIFY(ret) \ +do \ +{ \ + if (ret) \ + { \ + return ret; \ + } \ +} while(0) + + +#define KEY_VALUE_FDS_CACHE_SIZE 256 + +static __attribute__ ((aligned (4))) uint8_t s_file_buffer[KEY_VALUE_FDS_CACHE_SIZE]; + + + +static lfs_t s_default_instance; +static lfs_t *s_op_instance_ptr; + +#if !KEY_VALUE_FDS_KEY_STRING_TYPE +static char s_key_char[10] = {0}; +#endif + +#if !KEY_VALUE_FDS_KEY_STRING_TYPE +uint32_t key_value_fds_char_key_convert(const char *str) +{ + uint32_t num = 0; + const char *p = str; + + while (*p >= '0' && *p <= '9') + { + num = num * 10 + (*p - '0'); + p++; + } + + return num; +} + +static char * key_value_fds_int_key_convert(uint32_t key) +{ + uint16_t digit = 0; + uint32_t temp = key; + + do + { + temp /= 10; + digit++; + } while (temp > 0); + + s_key_char[digit] = '\0'; + + do { + digit--; + s_key_char[digit] = key % 10 + '0'; + key /= 10; + } while (key > 0); + + return s_key_char; +} +#endif + + +int key_value_fds_init(void) +{ + if(InternalFS.begin()) + { + s_op_instance_ptr = InternalFS._getFS(); + s_default_instance = *s_op_instance_ptr; + return KEY_VALUE_FDS_ERR_OK; + } + return KEY_VALUE_FDS_ERR_IO; +} + +int key_value_fds_value_write(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + const void *p_value, + uint32_t length) +{ + int ret; + + lfs_file_t file_id; + struct lfs_file_config file_config = {0}; + + file_config.buffer = s_file_buffer; + + // s_op_instance_ptr = NULL == p_instance ? &s_default_instance : p_instance; + +#if KEY_VALUE_FDS_KEY_STRING_TYPE + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, p_key, LFS_O_RDWR | LFS_O_CREAT, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#else + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, key_value_fds_int_key_convert(key), LFS_O_RDWR | LFS_O_CREAT, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#endif + + ret = lfs_file_rewind(s_op_instance_ptr, &file_id); + if (ret) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_write(s_op_instance_ptr, &file_id, p_value, length); + if (ret) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_close(s_op_instance_ptr, &file_id); + KEY_VALUE_FDS_VERIFY(ret); + + return KEY_VALUE_FDS_ERR_OK; +} + +int key_value_fds_value_read(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + void *p_buffer, + uint32_t length) +{ + int ret; + + lfs_file_t file_id; + struct lfs_file_config file_config = {0}; + + file_config.buffer = s_file_buffer; + + // s_op_instance_ptr = NULL == p_instance ? &s_default_instance : p_instance; +#if KEY_VALUE_FDS_KEY_STRING_TYPE + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, p_key, LFS_O_RDWR | LFS_O_CREAT, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#else + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, key_value_fds_int_key_convert(key), LFS_O_RDONLY, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#endif + ret = lfs_file_rewind(s_op_instance_ptr, &file_id); + if (ret) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_read(s_op_instance_ptr, &file_id, p_buffer, length); + if (ret) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_close(s_op_instance_ptr, &file_id); + KEY_VALUE_FDS_VERIFY(ret); + + return KEY_VALUE_FDS_ERR_OK; +} + + +int key_value_fds_value_delete(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key) +#else + uint32_t key) +#endif +{ + // s_op_instance_ptr = NULL == p_instance ? &s_default_instance : p_instance; +#if KEY_VALUE_FDS_KEY_STRING_TYPE + return lfs_remove(s_op_instance_ptr, p_key); +#else + return lfs_remove(s_op_instance_ptr, key_value_fds_int_key_convert(key)); +#endif +} + + + + +int key_value_fds_get_file_size(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key) +#else + uint32_t key) +#endif +{ + int ret; + lfs_file_t file_id; + struct lfs_file_config file_config = {0}; + file_config.buffer = s_file_buffer; + // s_op_instance_ptr = NULL == p_instance ? &s_default_instance : p_instance; +#if KEY_VALUE_FDS_KEY_STRING_TYPE + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, p_key, LFS_O_RDWR | LFS_O_CREAT, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#else + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, key_value_fds_int_key_convert(key), LFS_O_RDONLY, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#endif + ret = lfs_file_size(s_op_instance_ptr, &file_id); + lfs_file_close(s_op_instance_ptr, &file_id); + + return ret; +} + +int key_value_fds_value_write_pos(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + const void *p_value, + uint32_t length, + int32_t pos) +{ + int ret; + + lfs_file_t file_id; + struct lfs_file_config file_config = {0}; + + file_config.buffer = s_file_buffer; + + // s_op_instance_ptr = NULL == p_instance ? &s_default_instance : p_instance; +#if KEY_VALUE_FDS_KEY_STRING_TYPE + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, p_key, LFS_O_RDWR | LFS_O_CREAT, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#else + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, key_value_fds_int_key_convert(key), LFS_O_RDWR | LFS_O_CREAT, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#endif + + ret = lfs_file_seek(s_op_instance_ptr, &file_id, pos, LFS_SEEK_SET); + if (ret < 0) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_write(s_op_instance_ptr, &file_id, p_value, length); + if (ret) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_close(s_op_instance_ptr, &file_id); + KEY_VALUE_FDS_VERIFY(ret); + + return KEY_VALUE_FDS_ERR_OK; +} + +int key_value_fds_value_read_pos(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + void *p_buffer, + uint32_t length, + int32_t pos) +{ + int ret; + + lfs_file_t file_id; + struct lfs_file_config file_config = {0}; + + file_config.buffer = s_file_buffer; + + // s_op_instance_ptr = NULL == p_instance ? &s_default_instance : p_instance; +#if KEY_VALUE_FDS_KEY_STRING_TYPE + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, p_key, LFS_O_RDWR | LFS_O_CREAT, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#else + ret = lfs_file_opencfg(s_op_instance_ptr, &file_id, key_value_fds_int_key_convert(key), LFS_O_RDONLY, &file_config); + KEY_VALUE_FDS_VERIFY(ret); +#endif + + ret = lfs_file_seek(s_op_instance_ptr, &file_id, pos, LFS_SEEK_SET); + if (ret < 0) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_read(s_op_instance_ptr, &file_id, p_buffer, length); + if (ret) + { + lfs_file_close(s_op_instance_ptr, &file_id); + return ret; + } + + ret = lfs_file_close(s_op_instance_ptr, &file_id); + KEY_VALUE_FDS_VERIFY(ret); + + return KEY_VALUE_FDS_ERR_OK; +} \ No newline at end of file diff --git a/libraries/LBM_packet/src/app_param/key_value_fds.h b/libraries/LBM_packet/src/app_param/key_value_fds.h new file mode 100644 index 000000000..226c5b3c6 --- /dev/null +++ b/libraries/LBM_packet/src/app_param/key_value_fds.h @@ -0,0 +1,163 @@ +/** + **************************************************************************************** + * + * @file key_value_fds.h + * + * @brief Key-value flash data storage.h + * + **************************************************************************************** + * @attention + #####Copyright (c) 2019 GOODIX + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GOODIX nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + ***************************************************************************************** + */ + +#ifndef __KEY_VALUE_FDS_H__ +#define __KEY_VALUE_FDS_H__ + +#include +#include + +#include +#include + +#include +#include + + +/** + * @defgroup KEY_VALUE_FDS_MAROC Defines + * @{ + */ +#define KEY_VALUE_FDS_KEY_STRING_TYPE 0 /**< 1: String type, 0: Int type. */ + +/** + * @defgroup KEY_VALUE_FDS_ERROR_CODE Possible error codes + * @{ + */ +#define KEY_VALUE_FDS_ERR_OK 0 /**< No error. */ +#define KEY_VALUE_FDS_ERR_NO_ENTRY -2 /**< No entry. */ +#define KEY_VALUE_FDS_ERR_IO -5 /**< Error during device operation. */ +#define KEY_VALUE_FDS_ERR_NO_MEM -12 /**< No more memory available. */ +#define KEY_VALUE_FDS_ERR_EXIST -17 /**< Entry already exists . */ +#define KEY_VALUE_FDS_ERR_INVAL -22 /**< Invalid parameter. */ +#define KEY_VALUE_FDS_ERR_VALUE_BIG -27 /**< Value length too large. */ +#define KEY_VALUE_FDS_ERR_NO_SPACE -28 /**< No space left on device. */ +#define KEY_VALUE_FDS_ERR_CORRUPT -84 /**< Corrupted. */ +/** @} */ + +int key_value_fds_init(void); + +/** + ***************************************************************************************** + * @brief Key-value fds write. + * + * @param[in] p_instance: Pointer to key-value fds instance, @note Can be NULL, means that there use deafult instance. + * @param[in] p_key/key: Value key. + * @param[in] p_value: Pointer to value. + * @param[in] length: Length of value. + * + * @return Number of bytes write, or a negative error code on failure. + ***************************************************************************************** + */ +int key_value_fds_value_write(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + const void *p_value, + uint32_t length); + +/** + ***************************************************************************************** + * @brief Key-value fds read. + * + * @param[in] p_instance: Pointer to key-value fds instance, @note Can be NULL, means that there use deafult instance. + * @param[in] p_key/key: Value key. + * @param[in] p_value: Pointer to buffer. + * @param[in] length: Length of buffer. + * + * @return Number of bytes read, or a negative error code on failure. + ***************************************************************************************** + */ +int key_value_fds_value_read(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + void *p_buffer, + uint32_t length); + +/** + ***************************************************************************************** + * @brief Key-value fds delete. + * + * @param[in] p_instance: Pointer to key-value fds instance, @note Can be NULL, means that there use deafult instance. + * @param[in] p_key/key: Value key. + * + * @return Result of operation. + ***************************************************************************************** + */ +int key_value_fds_value_delete(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key); +#else + uint32_t key); +#endif + +int key_value_fds_get_file_size(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key); +#else + uint32_t key); +#endif + +int key_value_fds_value_write_pos(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + const void *p_value, + uint32_t length, + int32_t pos); + +int key_value_fds_value_read_pos(lfs_t *p_instance, +#if KEY_VALUE_FDS_KEY_STRING_TYPE + char *p_key, +#else + uint32_t key, +#endif + void *p_buffer, + uint32_t length, + int32_t pos); + +#endif +/** @} */ +/** @} */ + diff --git a/libraries/LBM_packet/src/app_param/user_stored_data.cpp b/libraries/LBM_packet/src/app_param/user_stored_data.cpp new file mode 100644 index 000000000..ee4b4500f --- /dev/null +++ b/libraries/LBM_packet/src/app_param/user_stored_data.cpp @@ -0,0 +1,810 @@ +#include "user_stored_data.h" +#include "Lbm_packet.hpp" + + +#define FILENAME "/group_id.txt" + +volatile uint16_t delete_datas_cnt = 0; +volatile bool delete_datas_fifo = false; + + + +uint8_t read_lfs_file( uint16_t file_name, uint8_t *data, uint16_t *len ) +{ + int ret = 0; + ret = key_value_fds_value_read( NULL, file_name, data, *len ); + if( ret >= 0 ) + { + // *len = ret; + return 0; + } + hal_mcu_trace_print("key_value_fds_value_read error,ret:%02x\r\n",ret); + return ret; +} + +uint8_t write_lfs_file( uint16_t file_name, uint8_t *data, uint16_t len ) +{ + int ret = 0; + ret = key_value_fds_value_write( NULL, file_name, data, len ); + if( ret >= 0 ) + { + return 0; + } + hal_mcu_trace_print("key_value_fds_value_write error,ret:%02x\r\n",ret); + return ret; +} + +uint8_t read_lfs_file_one( uint16_t file_name, uint8_t *data, uint16_t *len ) +{ + int ret = 0xff; + uint16_t file_name_start = 0; + uint32_t file_name_offset = 0; + + if( file_name >= POS_FILE_ID_START && file_name <= POS_FILE_ID_END ) + { + // file_name_start = POS_FILE_ID_START; + // file_name_offset = ( file_name - file_name_start ) * ( *len ); + file_name_start = POS_FILE_ID_START + ( file_name - POS_FILE_ID_START ) / POS_SAVE_IN_FILE_MAX; + file_name_offset = (( file_name - POS_FILE_ID_START ) % POS_SAVE_IN_FILE_MAX ) * ( *len ); + } + else + { + return ret; + } + + ret = key_value_fds_value_read_pos( NULL, file_name_start, data, *len, file_name_offset ); + if( ret >= 0 ) + { + // *len = ret; + return 0; + } + hal_mcu_trace_print("key_value_fds_value_read_pos error,ret:%02x\r\n",ret); + return ret; +} + +uint8_t write_lfs_file_one( uint16_t file_name, uint8_t *data, uint16_t len ) +{ + int ret = 0xff; + uint16_t file_name_start = 0; + uint32_t file_name_offset = 0; + + if( file_name >= POS_FILE_ID_START && file_name <= POS_FILE_ID_END ) + { + // file_name_start = POS_FILE_ID_START; + // file_name_offset = ( file_name - file_name_start ) * ( len ); + file_name_start = POS_FILE_ID_START + ( file_name - POS_FILE_ID_START ) / POS_SAVE_IN_FILE_MAX; + file_name_offset = (( file_name - POS_FILE_ID_START ) % POS_SAVE_IN_FILE_MAX ) * ( len ); + } + else + { + return ret; + } + + ret = key_value_fds_value_write_pos( NULL, file_name_start, data, len, file_name_offset ); + if( ret >= 0 ) + { + return 0; + } + hal_mcu_trace_print("key_value_fds_value_write_pos error,ret:%02x\r\n",ret); + return ret; +} + + +uint8_t delete_lfs_file( uint16_t file_name ) +{ + int ret = 0; + return ret; +} + +void param_init_func(void) +{ + uint16_t param_len = 0; + uint16_t log_len = 0; + uint16_t pos_info_len = 0; + uint8_t ret=0; + uint8_t u8_crc=0; + app_param_t app_param_temp = {0}; + param_len = sizeof(app_param_t); + + //flash - Factory Settings + lorawan_param_init(); + + //flash - Internal File System + ret = key_value_fds_init(); + if(ret != 0) + { + hal_mcu_trace_print("key_value_fds_init:%02x\r\n",ret); + } + ret = read_lfs_file(DEV_INFO_FILE,(uint8_t *)&app_param_temp,¶m_len); + + //init current param + if(ret != 0) + { + //use code default + app_param.param_len = ((uint8_t *)&app_param.crc-(uint8_t *)&app_param.param_len); + app_param.crc = crc8((uint8_t *)&app_param, app_param.param_len); + ret = write_lfs_file(DEV_INFO_FILE, (uint8_t *)&app_param, sizeof(app_param_t)); + if(ret != 0) + { + hal_mcu_trace_print("app_param,len:%02x,crc:%02x\r\n",app_param.param_len,app_param.crc); + } + } + else + { + //checksum + u8_crc = crc8((uint8_t *)&app_param_temp, app_param_temp.param_len); + if(u8_crc != app_param_temp.crc) + { + hal_mcu_trace_print("param crc error,u8_crc:%02x,crc:%02x\r\n",u8_crc,app_param_temp.crc); + app_param.param_len = ((uint8_t *)&app_param.crc-(uint8_t *)&app_param.param_len); + app_param.crc = crc8((uint8_t *)&app_param, app_param.param_len); + ret = write_lfs_file(DEV_INFO_FILE, (uint8_t *)&app_param, sizeof(app_param_t)); + if(ret != 0) + { + hal_mcu_trace_print("app_param,len:%02x,crc:%02x\r\n",app_param.param_len,app_param.crc); + } + } + else + { + memcpy(&app_param,&app_param_temp,param_len); + } + } + //default param + param_len = sizeof(app_param_t); + ret = read_lfs_file(DEF_DEV_INFO_FILE,(uint8_t *)&app_param_temp,¶m_len); + if(ret != 0) + { + //init default param + ret = write_lfs_file(DEF_DEV_INFO_FILE, (uint8_t *)&app_param, sizeof(app_param_t)); + if(ret != 0) + { + hal_mcu_trace_print("default app_param,len:%02x,crc:%02x\r\n",app_param.param_len,app_param.crc); + } + } + else + { + //checksum + u8_crc = crc8((uint8_t *)&app_param_temp, app_param_temp.param_len); + if(u8_crc != app_param_temp.crc) + { + hal_mcu_trace_print("param crc error,u8_crc:%02x,crc:%02x\r\n",u8_crc,app_param_temp.crc); + app_param.param_len = ((uint8_t *)&app_param.crc-(uint8_t *)&app_param.param_len); + app_param.crc = crc8((uint8_t *)&app_param, app_param.param_len); + ret = write_lfs_file(DEF_DEV_INFO_FILE, (uint8_t *)&app_param, sizeof(app_param_t)); + if(ret != 0) + { + hal_mcu_trace_print("app_param,len:%02x,crc:%02x\r\n",app_param.param_len,app_param.crc); + } + } + } + + //pos msg info + pos_info_len = sizeof(pos_msg_file_id_t); + ret = read_lfs_file(POS_INFO_FILE,(uint8_t *)&pos_msg_file_id,&pos_info_len); + if( ret != 0 || pos_msg_file_id.log_cnt > POS_SAVE_COUNT_MAX || pos_msg_file_id.file_id_start > POS_FILE_ID_END || pos_msg_file_id.file_id_cur > POS_FILE_ID_END ) + { + //init default log file id + pos_msg_file_id.reboot_cnt = 0; + pos_msg_file_id.log_cnt = 0; + pos_msg_file_id.file_id_start = POS_FILE_ID_START; + pos_msg_file_id.file_id_cur = POS_FILE_ID_START; + ret = write_lfs_file(POS_INFO_FILE, (uint8_t *)&pos_msg_file_id, sizeof(pos_msg_file_id_t)); + if(ret != 0) + { + hal_mcu_trace_print("default pos msg info,code:%02x\r\n",ret); + } + } + else + { + if(pos_msg_file_id.file_id_start < POS_FILE_ID_START ||pos_msg_file_id.file_id_cur= 0) + { + return true; + } + return false; +} +bool read_default_param_config(void) +{ + uint16_t r_len = sizeof(app_param_t); + if (read_lfs_file(DEF_DEV_INFO_FILE, (uint8_t *)&app_param, &r_len)) + return false; + return true; +} + +bool default_factory_eui_get(uint8_t *def_eui) +{ + app_param_t app_param_temp; + uint16_t r_len = sizeof(app_param_t); + if (read_lfs_file(DEF_DEV_INFO_FILE, (uint8_t *)&app_param_temp, &r_len)) + return false; + memcpy(def_eui,app_param_temp.lora_info.DevEui,8); + return true; + +} + +bool write_current_param_config(void) +{ + int ret = 0; + + app_param.param_len = ((uint8_t *)&app_param.crc-(uint8_t *)&app_param.param_len); + app_param.crc = crc8((uint8_t *)&app_param, app_param.param_len); + + ret = write_lfs_file(DEV_INFO_FILE,(uint8_t *)&app_param,sizeof(app_param_t)); + if(ret >= 0) + { + return true; + } + return false; +} + +bool read_current_param_config(void) +{ + uint16_t r_len = sizeof(app_param_t); + if (read_lfs_file(DEV_INFO_FILE, (uint8_t *)&app_param, &r_len)) + return false; + return true; +} + + +bool restore_lorawan_param_config(void) +{ + app_param_t app_param_temp; + uint16_t r_len = sizeof(app_param_t); + + if (read_lfs_file(DEF_DEV_INFO_FILE, (uint8_t *)&app_param_temp, &r_len)) + return false; + r_len = sizeof(lora_info_t); + memcpy((uint8_t *)&app_param.lora_info,(uint8_t *)&app_param_temp.lora_info,r_len); + return true; +} + +bool reset_factory_param(void) +{ + if (!read_default_param_config()) + { + return false; + } + else + { + if (!save_Config()) + { + return false; + } + return true; + } +} + + +uint8_t write_position_msg(void) +{ + uint8_t rc = 0; + uint16_t app_tag_id= 0; + uint16_t pos_data_len= 0; + + //on the basis of cur file id to save log data + app_tag_id = pos_msg_file_id.file_id_cur; + + //data integration + + //update log data + pos_data_len = sizeof(pos_msg_param_t); + rc = write_lfs_file_one(app_tag_id, (uint8_t *)&pos_msg_param, pos_data_len); + if (rc != 0) + { + hal_mcu_trace_print("write position msg error,code:%d\r\n",rc); + return rc; + } + rc = reflash_pos_msg_info(); + if (rc != 0) + { + hal_mcu_trace_print("reflash log_info error,code:%d\r\n",rc); + return rc; + } + return rc; +} + + +uint8_t reflash_pos_msg_info(void) +{ + uint8_t rc = 0; + uint16_t rlen = 0; + + pos_msg_file_id.file_id_cur++; + pos_msg_file_id.log_cnt++; + +// PRINTF("file_id_start:%04x,file_id_cur:%04x log_cnt:%d\r\n",pos_msg_file_id.file_id_start,pos_msg_file_id.file_id_cur,pos_msg_file_id.log_cnt); + if(pos_msg_file_id.file_id_cur > POS_FILE_ID_END) //judge file id range + { + pos_msg_file_id.file_id_cur = POS_FILE_ID_START; + } + if(pos_msg_file_id.log_cnt > POS_SAVE_COUNT_MAX) + { + pos_msg_file_id.log_cnt = POS_SAVE_COUNT_MAX; + pos_msg_file_id.file_id_start++; + if(pos_msg_file_id.file_id_start > POS_FILE_ID_END) //judge file id range + { + pos_msg_file_id.file_id_start = POS_FILE_ID_START; + } + } + rc = write_lfs_file(POS_INFO_FILE, (uint8_t *)&pos_msg_file_id, sizeof(pos_msg_file_id_t)); + if (rc != 0) + { + rlen = sizeof(pos_msg_file_id_t); + read_lfs_file(POS_INFO_FILE,(uint8_t *)&pos_msg_file_id, &rlen); + hal_mcu_trace_print("reflash log_info error,code:%d\r\n",rc); + return rc; + } + return 0; +} + + +bool get_pos_msg_info(void) +{ + uint8_t rc = 0; + uint16_t rlen = 0; + rlen = sizeof(pos_msg_file_id_t); + rc = read_lfs_file(POS_INFO_FILE,(uint8_t *)&pos_msg_file_id, &rlen); + if (rc != 0) + { + return false; + } + return true; +} + +void get_pos_msg_data(void) +{ + uint8_t rc = 0; + uint16_t log_real_cnt = 0,log_fail_cnt = 0; + uint16_t app_tag_id = 0; + uint16_t rlen = sizeof(pos_msg_param_t); + + if(pos_msg_file_id.log_cnt == 0) return; + //on the basis of cur file id to get log data + if(pos_msg_file_id.file_id_start < pos_msg_file_id.file_id_cur) + { + app_tag_id = pos_msg_file_id.file_id_start; + while(app_tag_id < pos_msg_file_id.file_id_cur) + { + rc = read_lfs_file_one(app_tag_id, (uint8_t*)&pos_msg_param, &rlen); + if (rc == 0) + { + print_pos_msg_data(); + app_tag_id ++; + log_real_cnt ++; + } + else + { + app_tag_id ++; + log_fail_cnt++; + } + } + } + else + { + app_tag_id = pos_msg_file_id.file_id_start; + while(app_tag_id <= POS_FILE_ID_END) + { + + rc = read_lfs_file_one(app_tag_id, (uint8_t*)&pos_msg_param, &rlen); + if (rc == 0) + { + print_pos_msg_data(); + app_tag_id ++; + log_real_cnt ++; + } + else + { + app_tag_id ++; + log_fail_cnt++; + } + } + app_tag_id = POS_FILE_ID_START; + while(app_tag_id < pos_msg_file_id.file_id_cur) + { + rc = read_lfs_file_one(app_tag_id, (uint8_t*)&pos_msg_param, &rlen); + if (rc == 0) + { + print_pos_msg_data(); + app_tag_id ++; + log_real_cnt ++; + } + else + { + app_tag_id ++; + log_fail_cnt++; + } + } + } + hal_mcu_trace_print("log_real_cnt:%d log_fail_cnt:%d\r\n",log_real_cnt,log_fail_cnt); +} + +uint16_t get_pos_msg_cnt(void) +{ + return pos_msg_file_id.log_cnt; +} + + + +bool read_pos_data(pos_msg_param_t *pos_msg_temp,bool is_old) +{ + uint8_t rc = 0; + uint16_t app_tag_id = 0; + uint16_t rlen = sizeof(pos_msg_param_t); + + if(pos_msg_file_id.log_cnt == 0) return false; + + if(is_old) + { + app_tag_id = pos_msg_file_id.file_id_start; + } + else + { + app_tag_id = pos_msg_file_id.file_id_cur-1; + if(app_tag_id < POS_FILE_ID_START) + { + app_tag_id = POS_FILE_ID_END; + } + } + rc = read_lfs_file_one(app_tag_id, (uint8_t*)pos_msg_temp, &rlen); + if (rc == 0) + { + return true; + } + return false; +} + + +bool read_sequence_pos_data(pos_msg_param_t *pos_msg_temp,bool is_old,uint16_t sequence_num) +{ + uint8_t rc = 0; + uint16_t app_tag_id = 0; + uint16_t rlen = sizeof(pos_msg_param_t); + + if(pos_msg_file_id.log_cnt == 0) return false; + + if(sequence_num == 0 || sequence_num > pos_msg_file_id.log_cnt) return false; + + if(is_old) + { + if(pos_msg_file_id.file_id_start+sequence_num-1 > POS_FILE_ID_END) + { + app_tag_id = pos_msg_file_id.file_id_start+sequence_num-1 - POS_FILE_ID_END + POS_FILE_ID_START-1; + } + else + { + app_tag_id = pos_msg_file_id.file_id_start+sequence_num-1; + } + } + else + { + if(pos_msg_file_id.file_id_cur-sequence_num < POS_FILE_ID_START) + { + app_tag_id = POS_FILE_ID_END-(POS_FILE_ID_START-(pos_msg_file_id.file_id_cur-sequence_num))+1; + } + else + { + app_tag_id = pos_msg_file_id.file_id_cur-sequence_num; + } + + } + rc = read_lfs_file_one(app_tag_id, (uint8_t*)pos_msg_temp, &rlen); + if (rc == 0) + { + return true; + } + return false; +} + + +uint8_t delete_position_msg(void) +{ + return delete_pos_msg_datas(delete_datas_cnt,delete_datas_fifo); +} + +uint8_t delete_pos_msg_datas(uint16_t del_cnt,bool is_old) +{ + uint8_t rc = 0; + uint16_t app_tag_id = 0; + uint16_t cursor_dir = 0; + uint16_t rlen = sizeof(pos_msg_param_t); + uint8_t del_status = 0; + uint16_t rlen1 = sizeof(pos_msg_file_id_t); + pos_msg_file_id_t pos_msg_file_temp; + memset(&pos_msg_file_temp,0,rlen1); + + + if(pos_msg_file_id.log_cnt < del_cnt) return 1; + + hal_mcu_trace_print("delete pos msg count:%d,%d\r\n",del_cnt,pos_msg_file_id.log_cnt); + + hal_mcu_trace_print("start:%04x,end:%04x,log_cnt:%d\r\n",pos_msg_file_id.file_id_start,pos_msg_file_id.file_id_cur,pos_msg_file_id.log_cnt); + + if(is_old) + { + app_tag_id = pos_msg_file_id.file_id_start; + cursor_dir = 1; + } + else + { + app_tag_id = pos_msg_file_id.file_id_cur-1; + cursor_dir = 0; + } + for(uint16_t u16i = 0; u16i < del_cnt; u16i++) + { + del_status = 0; + rc = delete_lfs_file(app_tag_id); + if (rc == 0) + { + pos_msg_file_id.log_cnt--; + if(cursor_dir == 1) + { + pos_msg_file_id.file_id_start++; + if(pos_msg_file_id.file_id_start > POS_FILE_ID_END) //judge file id range + { + pos_msg_file_id.file_id_start = POS_FILE_ID_START; + } + } + else + { + if(pos_msg_file_id.file_id_cur < POS_FILE_ID_START) //judge file id range + { + pos_msg_file_id.file_id_cur = POS_FILE_ID_END; + } + } + rc = write_lfs_file(POS_INFO_FILE, (uint8_t *)&pos_msg_file_id, sizeof(pos_msg_file_id_t)); + if (rc != 0) + { + rlen1 = sizeof(pos_msg_file_id_t); + read_lfs_file(POS_INFO_FILE,(uint8_t *)&pos_msg_file_id, &rlen1); + hal_mcu_trace_print("delete_pos_datas but reflash log_info error,code:%d\r\n",rc); + return rc; + } + hal_mcu_trace_print("u_start:%04x,u_end:%04x,u_log_cnt:%d\r\n",pos_msg_file_id.file_id_start,pos_msg_file_id.file_id_cur,pos_msg_file_id.log_cnt); + } + else if(rc != 1) + { + hal_mcu_trace_print("delete_pos_datas error,code:%d\r\n",rc); + return rc; + } + else + { + del_status = 1; + } + if(cursor_dir == 1) + { + app_tag_id = pos_msg_file_id.file_id_start; + if(del_status == 1) + { + pos_msg_file_id.log_cnt--; + app_tag_id = pos_msg_file_id.file_id_start++; + if(pos_msg_file_id.file_id_start > POS_FILE_ID_END) //judge file id range + { + pos_msg_file_id.file_id_start = POS_FILE_ID_START; + } + } + } + else + { + app_tag_id = app_tag_id-1; + if(app_tag_id < POS_FILE_ID_START) + { + app_tag_id = POS_FILE_ID_END; + } + if(del_status == 1) + { + + } + } + } + rlen1 = sizeof(pos_msg_file_id_t); + read_lfs_file(POS_INFO_FILE,(uint8_t *)&pos_msg_file_temp, &rlen1); + hal_mcu_trace_print("start:%04x,end:%04x,log_cnt:%d\r\n",pos_msg_file_id.file_id_start,pos_msg_file_id.file_id_cur,pos_msg_file_id.log_cnt); + hal_mcu_trace_print("t_start:%04x,t_end:%04x,t_log_cnt:%d\r\n",pos_msg_file_temp.file_id_start,pos_msg_file_temp.file_id_cur,pos_msg_file_temp.log_cnt); + + return 0; +} + +void print_pos_msg_data(void) +{ + if( pos_msg_param.pos_type == pos_state ) + { + hal_mcu_trace_print( "utc:%u,pos_state:%d,event_status:%d\r\n",pos_msg_param.utc_time, ( pos_msg_param.pos_status >> 24 ) & 0xff,pos_msg_param.pos_status & 0xffffff ); + } + else + { + hal_mcu_trace_print( "utc:%u,event_status:%d,motion_index:%d,",pos_msg_param.utc_time, ( pos_msg_param.pos_status >> 8 ) & 0xffffff, pos_msg_param.pos_status & 0xff ); + switch(pos_msg_param.pos_type) + { + case pos_gnss_raw: + hal_mcu_trace_print("gnss: zone_flag:%u, group_id:%u, len:%u\r\n", pos_msg_param.context.gps_context.zone_flag,\ + pos_msg_param.context.gps_context.group_id,\ + pos_msg_param.context.gps_context.gnss_len); + for(uint8_t u8i = 0;u8i +#include +#include +#include "app_config_param.h" +#include "key_value_fds.h" + +#define DEV_INFO_FILE (0x100) +#define DEF_DEV_INFO_FILE (0x101) + +#define POS_INFO_FILE (0x104) + +#define GROUP_ID_INFO_FILE (0x109) +#define APPEND_PARAM_INFO_FILE (0x10A) + +#define POS_SAVE_COUNT_MAX 120 +#define POS_SAVE_IN_FILE_MAX 60 +#define POS_FILE_ID_START (0x400) +#define POS_FILE_ID_END (0x400+POS_SAVE_COUNT_MAX) + + +/** + * read_lfs_file() - read lfs file datas + * + * @param file_name file name + * + * @param data data buffer + * + * @param len data len + * + * @return 0:success, others:fail + */ +uint8_t read_lfs_file(uint16_t file_name, uint8_t *data, uint16_t *len) ; + +/** + * write_lfs_file() - write lfs file datas + * + * @param file_name file name + * + * @param data data buffer + * + * @param len data len + * + * @return 0:success, others:fail + */ +uint8_t write_lfs_file(uint16_t file_name, uint8_t *data, uint16_t len); + +/** + * read_lfs_file_one() - read position file datas + * + * @param file_name file name + * + * @param data data buffer + * + * @param len data len + * + * @return 0:success, others:fail + */ +uint8_t read_lfs_file_one( uint16_t file_name, uint8_t *data, uint16_t *len ); + +/** + * write_lfs_file_one() - read position file datas + * + * @param file_name file name + * + * @param data data buffer + * + * @param len data len + * + * @return 0:success, others:fail + */ +uint8_t write_lfs_file_one( uint16_t file_name, uint8_t *data, uint16_t len ); + + +/** + * delete_lfs_file() - delete lfs file datas + * + * @param file_name file name + * + * @return 0:success, others:fail + */ +uint8_t delete_lfs_file(uint16_t file_name); + + +/** + * param_init_func() - init lfs file datas + * + */ +void param_init_func(void); + +/** + * write_default_param_config() - write default parameters config + * + * @return true:success, false:fail + */ +bool write_default_param_config(void); + +/** + * read_default_param_config() - read default parameters config + * + * @return true:success, false:fail + */ +bool read_default_param_config(void); + +/** + * write_current_param_config() - write current parameters config + * + * @return true:success, false:fail + */ +bool write_current_param_config(void); + +/** + * read_current_param_config() - read current parameters config + * + * @return true:success, false:fail + */ +bool read_current_param_config(void); + +/** + * default_factory_eui_get() - get default DevEui + * + * @param def_eui eui buffer + * + * @return true:success, false:fail + */ +bool default_factory_eui_get(uint8_t *def_eui); + +/** + * reset_factory_param() - Restore all parameters to default + * + * @return true:success, false:fail + */ +bool reset_factory_param(void); + +/** + * restore_lorawan_param_config() - Restore LoRaWAN parameters to default + * + * @return true:success, false:fail + */ +bool restore_lorawan_param_config(void); + + +/** + * write_position_msg() - write position message datas to lfs + * + * @return 0:success, others:fail + */ +uint8_t write_position_msg(void); + +/** + * get_pos_msg_data() - print position message datas + * + * @return 0:success, others:fail + */ +void get_pos_msg_data(void); + +/** + * read_pos_data() - read single position data + * + * @param pos_msg_temp position data + * + * @param is_old old one or new + * + * @return true:success, false:fail + */ +bool read_pos_data(pos_msg_param_t *pos_msg_temp,bool is_old); + +/** + * read_sequence_pos_data() - read position data + * + * @param pos_msg_temp position data + * + * @param is_old old one or new + * + * @param sequence_num sequence number + * + * @return true:success, false:fail + */ +bool read_sequence_pos_data(pos_msg_param_t *pos_msg_temp,bool is_old,uint16_t sequence_num); + +/** + * get_pos_msg_cnt() - get the number of location data items + * + * @return number of location data items + */ +uint16_t get_pos_msg_cnt(void); + +/** + * get_pos_msg_cnt() - get the number of location data items + * + * @return number of location data items + */ +uint8_t delete_position_msg(void); + +/** + * delete_pos_msg_datas() - delete position datas + * + * @param del_cnt delete cnt + * + * @param is_old old one or new + * + * @return 0:success others:fail + */ +uint8_t delete_pos_msg_datas(uint16_t del_cnt,bool is_old); + +/** + * reflash_pos_msg_info() - reflash position message info + * + * @return 0:success others:fail + */ +uint8_t reflash_pos_msg_info(void); + +/** + * get_pos_msg_info() - get position message info + * + * @return true:success false:fail + */ +bool get_pos_msg_info(void); + +/** + * print_pos_msg_data() - print position data + * + * @return true:success false:fail + */ +void print_pos_msg_data(void); + +/** + * read_gnss_group_id_param() - read group id + * + * @return true:success false:fail + */ +bool read_gnss_group_id_param(void); + +/** + * write_gnss_group_id_param() - write group id + * + * @return true:success false:fail + */ +uint8_t write_gnss_group_id_param(void); + +/** + * gnss_group_id_param_init() - init group id + * + * @return true:success false:fail + */ +void gnss_group_id_param_init(void); + +/** + * read_app_append_param() - app append param + * + * @return true:success false:fail + */ +bool read_app_append_param(void); +/** + * write_app_append_param() - write app append param + * + * @return 0:success other:fail + */ +uint8_t write_app_append_param(void); +/** + * app_append_param_init() - init app append param + * + */ +void app_append_param_init(void); + +#endif + + diff --git a/libraries/LBM_packet/src/internal/almanac.h b/libraries/LBM_packet/src/internal/almanac.h new file mode 100644 index 000000000..9c8a869fe --- /dev/null +++ b/libraries/LBM_packet/src/internal/almanac.h @@ -0,0 +1,5 @@ +/* This file has been auto-generated by the get_full_almanac.py script */ + +#include "lbm/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.h" + +static uint8_t full_almanac[( LR11XX_GNSS_FULL_UPDATE_N_ALMANACS * LR11XX_GNSS_SINGLE_ALMANAC_WRITE_SIZE ) + 20] = { 0x80, 0x58, 0x06, 0xD3, 0x65, 0x52, 0xD4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x6A, 0x43, 0x28, 0x17, 0x04, 0x70, 0x27, 0x58, 0xDF, 0x31, 0xC9, 0xD0, 0x06, 0xAC, 0xFF, 0x6F, 0x00, 0x01, 0x00, 0x02, 0x17, 0x43, 0x28, 0x4F, 0x01, 0xF0, 0x27, 0xD2, 0x40, 0x3F, 0x2D, 0xDF, 0x34, 0xA9, 0xFF, 0x37, 0x00, 0x01, 0x00, 0x03, 0x21, 0x43, 0x28, 0xA7, 0x00, 0x41, 0x27, 0x19, 0xBC, 0xF9, 0x83, 0xE9, 0x60, 0xA6, 0xFF, 0x1B, 0x00, 0x01, 0x00, 0x04, 0x5A, 0x43, 0x28, 0x8B, 0x01, 0x69, 0x27, 0x03, 0xD8, 0xFC, 0x31, 0xEA, 0x32, 0xA7, 0xFF, 0xA4, 0x01, 0x01, 0x00, 0x05, 0x6A, 0x43, 0x28, 0xB5, 0x00, 0x54, 0x28, 0xA6, 0x7A, 0x20, 0xDF, 0x97, 0x0A, 0xAF, 0xFF, 0xD2, 0x00, 0x01, 0x00, 0x06, 0x5B, 0x43, 0x28, 0x7F, 0x04, 0xBD, 0x26, 0x77, 0x55, 0x7B, 0xA7, 0x39, 0x8A, 0xA5, 0xFF, 0xA6, 0x01, 0x01, 0x00, 0x07, 0x61, 0x43, 0x28, 0x36, 0x02, 0xFD, 0x26, 0x78, 0xC9, 0x0B, 0x0B, 0x52, 0xDE, 0xA3, 0xFF, 0xD3, 0x00, 0x01, 0x00, 0x08, 0x7D, 0x43, 0x28, 0xBA, 0x00, 0xFC, 0x26, 0x3C, 0xE0, 0x6C, 0x4F, 0x91, 0x5E, 0xA5, 0xFF, 0x69, 0x00, 0x01, 0x00, 0x09, 0x44, 0x43, 0x28, 0x41, 0x02, 0xED, 0x27, 0x9C, 0x1C, 0x6F, 0x9C, 0xC4, 0x34, 0xA7, 0xFF, 0xBB, 0x00, 0x01, 0x00, 0x0A, 0x1D, 0x43, 0x28, 0x4B, 0x00, 0x5D, 0x27, 0xEA, 0xB0, 0xE4, 0x8F, 0x2B, 0x0C, 0xAC, 0xFF, 0x5D, 0x00, 0x01, 0x00, 0x0B, 0x76, 0x43, 0x28, 0x32, 0x02, 0x48, 0x27, 0x5C, 0x3B, 0xA6, 0x38, 0xA8, 0xB7, 0xA6, 0xFF, 0x17, 0x00, 0x01, 0x00, 0x0C, 0x3C, 0x43, 0x28, 0xEC, 0x01, 0x8A, 0x27, 0xDC, 0xBA, 0x30, 0x26, 0x2B, 0x65, 0xA8, 0xFF, 0x0B, 0x00, 0x01, 0x00, 0x0D, 0x3A, 0x43, 0x28, 0xE9, 0x00, 0x9A, 0x26, 0xC3, 0x36, 0x21, 0x88, 0x02, 0xB6, 0xA2, 0xFF, 0x05, 0x00, 0x01, 0x00, 0x0E, 0x6D, 0x43, 0x28, 0xF3, 0x03, 0x05, 0x26, 0x5A, 0xA0, 0xA8, 0x32, 0x9F, 0x59, 0xA4, 0xFF, 0x02, 0x00, 0x01, 0x00, 0x0F, 0x32, 0x43, 0x28, 0x6E, 0x03, 0x44, 0x27, 0xBA, 0xF1, 0x53, 0x20, 0x66, 0xB8, 0xA5, 0xFF, 0x01, 0x00, 0x01, 0x00, 0x10, 0x0E, 0x43, 0x28, 0x84, 0x03, 0xA1, 0x27, 0xD5, 0xC9, 0xF7, 0xC6, 0x05, 0xE2, 0xAA, 0xFF, 0x91, 0x01, 0x01, 0x00, 0x11, 0x3E, 0x43, 0x28, 0xF4, 0x00, 0xB5, 0x27, 0x21, 0x77, 0x77, 0x81, 0xE7, 0x0A, 0xAD, 0xFF, 0xC8, 0x00, 0x01, 0x00, 0x12, 0x2F, 0x43, 0x28, 0x69, 0x02, 0x98, 0x27, 0xE6, 0x1E, 0x56, 0x62, 0xD5, 0xE3, 0xA7, 0xFF, 0x64, 0x00, 0x01, 0x00, 0x13, 0x1F, 0x43, 0x28, 0x0C, 0x01, 0xB4, 0x26, 0x9F, 0x94, 0xFC, 0x8B, 0xD8, 0x2D, 0xA6, 0xFF, 0x32, 0x00, 0x01, 0x00, 0x14, 0x12, 0x43, 0x28, 0x58, 0x06, 0x34, 0x27, 0x4C, 0xCA, 0x3F, 0xE3, 0x95, 0x06, 0xA8, 0xFF, 0x19, 0x00, 0x01, 0x00, 0x15, 0x18, 0x43, 0x28, 0xEE, 0x03, 0x3C, 0x27, 0x2C, 0xE1, 0x9A, 0xCF, 0x88, 0xB8, 0xA0, 0xFF, 0x0C, 0x00, 0x01, 0x00, 0x16, 0x3F, 0x43, 0x28, 0xEF, 0x00, 0xBB, 0x27, 0x49, 0x4E, 0xFA, 0x81, 0xA2, 0x33, 0xA7, 0xFF, 0xCC, 0x01, 0x01, 0x00, 0x17, 0x2D, 0x43, 0x28, 0xB3, 0x03, 0x13, 0x26, 0xE9, 0x7E, 0x78, 0x25, 0x74, 0x86, 0xAA, 0xFF, 0x39, 0x00, 0x01, 0x00, 0x18, 0x3C, 0x43, 0x28, 0xDC, 0x02, 0xC9, 0x26, 0x31, 0x32, 0xDC, 0x2A, 0x3F, 0xB4, 0xA1, 0xFF, 0x1C, 0x00, 0x01, 0x00, 0x19, 0x5F, 0x43, 0x28, 0x19, 0x02, 0x01, 0x26, 0x99, 0x14, 0x1A, 0x13, 0xE4, 0xB1, 0xA0, 0xFF, 0x0E, 0x00, 0x01, 0x00, 0x1A, 0x39, 0x43, 0x28, 0xFA, 0x02, 0x5A, 0x27, 0x72, 0xCC, 0x3B, 0x1E, 0x50, 0xDF, 0xA6, 0xFF, 0x07, 0x00, 0x01, 0x00, 0x1B, 0x67, 0x43, 0x28, 0x2D, 0x00, 0x32, 0x27, 0xB4, 0x1D, 0x04, 0x40, 0xC2, 0x88, 0xAA, 0xFF, 0x03, 0x00, 0x01, 0x00, 0x1C, 0x52, 0x43, 0x28, 0xAA, 0x00, 0xB9, 0x27, 0x5B, 0xC6, 0x46, 0x68, 0x9B, 0xE2, 0xA8, 0xFF, 0xA8, 0x01, 0x01, 0x00, 0x1D, 0x6E, 0x43, 0x28, 0xAF, 0x01, 0x22, 0x26, 0xEB, 0x51, 0x3D, 0x98, 0x67, 0x8A, 0xA5, 0xFF, 0xD4, 0x00, 0x01, 0x00, 0x1E, 0x28, 0x43, 0x28, 0xAE, 0x02, 0xE8, 0x26, 0xF5, 0x32, 0xD0, 0x17, 0x0F, 0x8B, 0xA8, 0xFF, 0x6A, 0x00, 0x01, 0x00, 0x1F, 0x08, 0x43, 0x28, 0xC9, 0x01, 0x21, 0x27, 0xC0, 0xE4, 0x7D, 0xA5, 0x1F, 0x5F, 0xA5, 0xFF, 0x35, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x30, 0xBB, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x66, 0x00, 0x00, 0x87, 0x01, 0x02, 0x01, 0x41, 0xB9, 0xB8, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB5, 0x3B, 0x00, 0x00, 0x39, 0x06, 0x02, 0x01, 0x42, 0x0E, 0xBA, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x4E, 0x00, 0x00, 0xE6, 0x01, 0x02, 0x01, 0x43, 0xFB, 0xB9, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9D, 0x71, 0x00, 0x00, 0x09, 0x06, 0x02, 0x01, 0x44, 0x98, 0xBE, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x29, 0x00, 0x00, 0x05, 0x06, 0x02, 0x01, 0x45, 0xDC, 0xBB, 0x32, 0xEE, 0x00, 0x9D, 0x26, 0x75, 0x49, 0x7C, 0x84, 0x7C, 0x7D, 0xED, 0xFF, 0xF8, 0x01, 0x02, 0x01, 0x46, 0x50, 0xBA, 0x32, 0xCF, 0x00, 0x17, 0x23, 0x65, 0xE9, 0x6C, 0x96, 0x37, 0xCD, 0xDC, 0xFF, 0x06, 0x06, 0x02, 0x01, 0x47, 0x87, 0xBA, 0x32, 0xBB, 0x00, 0x55, 0x2B, 0xE8, 0xAB, 0x8F, 0x7A, 0x7F, 0x26, 0xED, 0xFF, 0xF9, 0x01, 0x02, 0x01, 0x48, 0xEB, 0xBA, 0x32, 0xD7, 0x02, 0xCF, 0x26, 0xD4, 0x22, 0xCD, 0xA1, 0x4B, 0x7F, 0xED, 0xFF, 0x04, 0x07, 0x02, 0x01, 0x49, 0xBE, 0xBA, 0x32, 0x6B, 0x02, 0x2E, 0x23, 0x89, 0xDA, 0xA8, 0x9C, 0xFB, 0xCC, 0xDD, 0xFF, 0xBE, 0x07, 0x02, 0x01, 0x4A, 0x30, 0x45, 0x29, 0x8E, 0x00, 0x31, 0x28, 0x34, 0x22, 0xD6, 0xB4, 0xD1, 0xF3, 0xB9, 0xFF, 0x61, 0x00, 0x02, 0x01, 0x4B, 0x2F, 0x45, 0x29, 0x52, 0x00, 0x20, 0x28, 0xEC, 0x43, 0xE7, 0xB3, 0x51, 0xF3, 0xBA, 0xFF, 0x8E, 0x07, 0x02, 0x01, 0x4C, 0x6F, 0xBA, 0x32, 0x33, 0x01, 0xC7, 0x29, 0x44, 0x85, 0x27, 0x9A, 0x55, 0x25, 0xEC, 0xFF, 0x82, 0x07, 0x02, 0x01, 0x4D, 0x24, 0x45, 0x29, 0x46, 0x00, 0x98, 0x27, 0x1F, 0x88, 0x1A, 0xFA, 0xA4, 0x47, 0xB2, 0xFF, 0x7F, 0x00, 0x02, 0x01, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x4F, 0x94, 0xBA, 0x32, 0x9D, 0x01, 0x3E, 0x27, 0xD5, 0x2F, 0xBA, 0xA3, 0x44, 0x7D, 0xED, 0xFF, 0x7E, 0x00, 0x02, 0x01, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x52, 0x22, 0x45, 0x29, 0x25, 0x00, 0xB3, 0x27, 0x36, 0x13, 0x66, 0xDE, 0xAF, 0x47, 0xB2, 0xFF, 0x3C, 0x00, 0x02, 0x01, 0x53, 0x23, 0x45, 0x29, 0x23, 0x00, 0xB3, 0x27, 0xA3, 0x11, 0x29, 0xFE, 0xB6, 0x47, 0xB3, 0xFF, 0xC1, 0x07, 0x02, 0x01, 0x54, 0x25, 0x45, 0x29, 0x1C, 0x00, 0xAC, 0x27, 0x03, 0xBE, 0x6A, 0xF3, 0xC2, 0x47, 0xB2, 0xFF, 0x3F, 0x00, 0x02, 0x01, 0x55, 0x24, 0x45, 0x29, 0x26, 0x00, 0xAC, 0x27, 0x7B, 0xB5, 0xC4, 0x1B, 0xC1, 0x47, 0xB2, 0xFF, 0xC0, 0x07, 0x02, 0x01, 0x56, 0x25, 0x45, 0x29, 0x13, 0x00, 0x88, 0x26, 0x80, 0x2D, 0x15, 0xD2, 0x10, 0x9D, 0xB4, 0xFF, 0xEF, 0x07, 0x02, 0x01, 0x57, 0x2E, 0x45, 0x29, 0x25, 0x00, 0x88, 0x26, 0x09, 0x30, 0x71, 0x0F, 0x0E, 0x9D, 0xB3, 0xFF, 0xE3, 0x07, 0x02, 0x01, 0x58, 0x28, 0x45, 0x29, 0x1F, 0x00, 0x97, 0x26, 0x80, 0x0B, 0x9A, 0x12, 0x13, 0x9C, 0xB4, 0xFF, 0x1E, 0x00, 0x02, 0x01, 0x59, 0x28, 0x45, 0x29, 0x34, 0x00, 0x98, 0x26, 0x5B, 0x49, 0x90, 0x14, 0x19, 0x9C, 0xB4, 0xFF, 0xE0, 0x07, 0x02, 0x01, 0x5A, 0x25, 0x45, 0x29, 0x24, 0x00, 0x33, 0x27, 0x3D, 0x4C, 0x6D, 0x3A, 0xD2, 0xF2, 0xB5, 0xFF, 0x1F, 0x00, 0x02, 0x01, 0x5B, 0x2D, 0x45, 0x29, 0x0F, 0x00, 0x32, 0x27, 0xA2, 0x06, 0x6F, 0x9D, 0xCF, 0xF2, 0xB6, 0xFF, 0x0C, 0x00, 0x02, 0x01, 0x5C, 0x24, 0x45, 0x29, 0x0B, 0x00, 0x1F, 0x27, 0xDD, 0xE8, 0x5E, 0x5E, 0x35, 0xF1, 0xB6, 0xFF, 0xF1, 0x07, 0x02, 0x01, 0x5D, 0x23, 0x45, 0x29, 0x16, 0x00, 0x1F, 0x27, 0x76, 0x50, 0x24, 0x18, 0x3B, 0xF1, 0xB5, 0xFF, 0x0F, 0x00, 0x02, 0x01, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x5F, 0x21, 0x45, 0x29, 0x10, 0x00, 0xA6, 0x27, 0xC2, 0x4C, 0xE2, 0xE4, 0x6D, 0x47, 0xB3, 0xFF, 0xFD, 0x07, 0x02, 0x01, 0x60, 0x22, 0x45, 0x29, 0x15, 0x00, 0xA7, 0x27, 0xE1, 0x59, 0xEF, 0x17, 0x6C, 0x47, 0xB2, 0xFF, 0x03, 0x00, 0x02, 0x01, 0x61, 0x25, 0x45, 0x29, 0x1B, 0x00, 0x0C, 0x27, 0x75, 0xC2, 0xAC, 0x23, 0x4C, 0xF1, 0xB6, 0xFF, 0xFC, 0x07, 0x02, 0x01, 0x62, 0x3F, 0x45, 0x29, 0x2B, 0x00, 0x0C, 0x27, 0x02, 0x11, 0x3B, 0x13, 0x4B, 0xF1, 0xB5, 0xFF, 0xFE, 0x07, 0x02, 0x01, 0x63, 0x23, 0x45, 0x29, 0x34, 0x00, 0x97, 0x26, 0xAE, 0xD4, 0xD7, 0xCA, 0x01, 0x9D, 0xB4, 0xFF, 0x01, 0x00, 0x02, 0x01, 0x64, 0x2F, 0x45, 0x29, 0x2D, 0x00, 0x97, 0x26, 0xA0, 0xFC, 0xC1, 0xE2, 0xFF, 0x9C, 0xB4, 0xFF, 0xFF, 0x07, 0x02, 0x01, 0x65, 0x85, 0xBA, 0x32, 0x9A, 0x00, 0xB0, 0x28, 0xAE, 0xA7, 0x4D, 0x88, 0x50, 0x25, 0xEB, 0xFF, 0x57, 0x04, 0x02, 0x01, 0x66, 0xF3, 0xBA, 0x32, 0xD5, 0x00, 0x43, 0x27, 0x81, 0x50, 0x39, 0x8A, 0x60, 0x7A, 0xEC, 0xFF, 0xED, 0x04, 0x02, 0x01, 0x67, 0x6D, 0xBA, 0x32, 0xE5, 0x00, 0x29, 0x28, 0xE6, 0xFC, 0xED, 0x85, 0x88, 0xD2, 0xE2, 0xFF, 0xDD, 0x04, 0x02, 0x01, 0x68, 0x20, 0x45, 0x29, 0x56, 0x00, 0x9A, 0x27, 0x73, 0x8E, 0x16, 0xC4, 0x8F, 0x47, 0xB2, 0xFF, 0xD1, 0x04, 0x02, 0x01, 0x69, 0x22, 0x45, 0x29, 0x48, 0x00, 0x9B, 0x27, 0x07, 0xC1, 0x5B, 0xD1, 0x95, 0x47, 0xB2, 0xFF, 0xD2, 0x04, 0x02, 0x01, 0x6A, 0x23, 0x45, 0x29, 0x18, 0x00, 0xEC, 0x26, 0x8C, 0xAA, 0x36, 0x1E, 0x42, 0xF1, 0xB6, 0xFF, 0x2D, 0x03, 0x02, 0x01, 0x6B, 0x27, 0x45, 0x29, 0x26, 0x00, 0xF1, 0x26, 0xFB, 0xEB, 0x06, 0x1B, 0x45, 0xF1, 0xB5, 0xFF, 0x8C, 0x04, 0x02, 0x01, 0x6C, 0x26, 0x45, 0x29, 0x21, 0x00, 0xC0, 0x26, 0x45, 0x87, 0x5B, 0xF7, 0x26, 0x9D, 0xB5, 0xFF, 0x92, 0x04, 0x02, 0x01, 0x6D, 0x29, 0x45, 0x29, 0x35, 0x00, 0xC0, 0x26, 0xAA, 0xBF, 0x9B, 0xFD, 0x2B, 0x9D, 0xB4, 0xFF, 0xBC, 0x04, 0x02, 0x01, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x7A, 0x47, 0xBA, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x63, 0x00, 0x00, 0x3B, 0x05, 0x02, 0x01, 0x7B, 0xE3, 0xBC, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD5, 0x38, 0x00, 0x00, 0x37, 0x05, 0x02, 0x01, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 }; diff --git a/libraries/LBM_packet/src/internal/get_full_almanac.py b/libraries/LBM_packet/src/internal/get_full_almanac.py new file mode 100644 index 000000000..0755dfb43 --- /dev/null +++ b/libraries/LBM_packet/src/internal/get_full_almanac.py @@ -0,0 +1,111 @@ +""" +The Clear BSD License +Copyright Semtech Corporation 2021. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the disclaimer +below) provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Semtech corporation nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY +THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +""" + +import base64 +import requests + +import sys +from argparse import ArgumentParser + +# refer to https://github.com/Lora-net/SWSD004/blob/master/apps/examples/full_almanac_update/get_full_almanac.py +# mgs_token : +# filename: almanac.h +# Command example: +# python .\get_full_almanac.py -f almanac.h mgs_token + + +def main(): + + # The file in which the almanac will be written to + filename_default = "almanac.h" + parser = ArgumentParser( + description="Companion software that generates almanac header file to be compiled for LR1110/LR1120 embedded full almanac update." + ) + parser.add_argument( + "mgs_token", help="MGS LoRa Cloud token to use to fetch the almanac" + ) + parser.add_argument( + "-f", + "--output_file", + help="file that will contain the results", + default=filename_default, + ) + args = parser.parse_args() + + mgs_token = args.mgs_token + filename = args.output_file + + # Build request URL + url = "https://mgs.loracloud.com/api/v1/almanac/full" + print("Requesting latest full almanac image available...") + + # HTTP request to MGS + my_header = {"Authorization": mgs_token} + res = requests.get(url, headers=my_header) + + if res.status_code != 200: + print("ERROR: failed to get almanac - " + str(res)) + sys.exit(2) + else: + print("Success") + print(res.json()) + print() + raw_bytes = bytes(base64.b64decode(res.json()["result"]["almanac_image"])) + + print(len(raw_bytes)) + print(raw_bytes) + # Build the byte array containing the almanac to be written to LR11xx + my_almanac_in_hex = "static uint8_t full_almanac[( LR11XX_GNSS_FULL_UPDATE_N_ALMANACS * LR11XX_GNSS_SINGLE_ALMANAC_WRITE_SIZE ) + 20] = { " + my_almanac_in_hex += ", ".join("0x{:02X}".format(byt) for byt in raw_bytes) + my_almanac_in_hex += " };" + + # Write C file to be included to the full_almanac_update application for writting to LR11xx + file_header = ( + "/* This file has been auto-generated by the get_full_almanac.py script */\n\n" + ) + file_header += '#include "lbm/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.h"\n\n' + with open(filename, "w") as f: + f.write(file_header + my_almanac_in_hex + "\n") + + print("Almanac image written to " + filename + " file") + + + output_path = 'test_acmanac.bin' # 输出文件的路径和文件名称,这里直接放在工程根目录下,所以没有写绝对路径 + + # 待写入的数据 + + with open(output_path, 'ab') as f: + f.write(raw_bytes) + f.close() + + + +if __name__ == "__main__": + main() diff --git a/libraries/LBM_packet/src/internal/main_almanac.cpp b/libraries/LBM_packet/src/internal/main_almanac.cpp new file mode 100644 index 000000000..37d10b68a --- /dev/null +++ b/libraries/LBM_packet/src/internal/main_almanac.cpp @@ -0,0 +1,154 @@ + +#include "common/smtc_board/smtc_board.h" +#include "common/apps_modem_common.h" +#include "common/apps_modem_event.h" + +#include +#include +#include + +#include +#include "almanac.h" +#include "main_almanac.h" + +#include "Lbm_packet.hpp" +#include +#include + +#define OFFSET_BETWEEN_GPS_EPOCH_AND_UNIX_EPOCH 315964800 + +lr11xx_gnss_almanac_full_read_bytestream_t lr11xx_almanac; + + +static LbmWm1110& lbmWm1110 = LbmWm1110::getInstance(); +ralf_t* modem_radio = lbmWm1110.getRadio(); + +volatile uint32_t almanac_date_time; + +/*! + * @brief + */ +static bool almanac_update( const void* ral_context, uint8_t *almanac_data, uint16_t almanac_len ); + +/*! + * @brief + */ +static bool get_almanac_crc( const void* ral_context, uint32_t* almanac_crc ); + +void app_task_full_almanac_update( void ) +{ + uint32_t almanac_date = app_task_radio_get_almanac_date( ); + hal_mcu_trace_print("LR1110 almanac date: %u, Local almanac date: %u\r\n", almanac_date, almanac_date_time ); + + // almanac_update( modem_radio->ral.context, full_almanac, sizeof( full_almanac )); // just for test + + if( almanac_date < almanac_date_time ) + { + almanac_update( modem_radio->ral.context, full_almanac, sizeof( full_almanac )); + } +} + +uint32_t app_task_radio_get_almanac_date( void ) +{ + if( lr11xx_gnss_read_almanac( modem_radio->ral.context , lr11xx_almanac ) == LR11XX_STATUS_OK ) + { + hal_mcu_trace_print( "almanac_date_raw: %02x%02x, %02x%02x\r\n", lr11xx_almanac[2], lr11xx_almanac[1], lr11xx_almanac[24], lr11xx_almanac[23] ); + // uint16_t almanac_date_raw = ( uint16_t )( ( lr11xx_almanac[2] << 8 ) | lr11xx_almanac[1] ); + uint16_t almanac_date_raw = ( uint16_t )( ( lr11xx_almanac[24] << 8 ) | lr11xx_almanac[23] ); + uint32_t almanac_date = ( OFFSET_BETWEEN_GPS_EPOCH_AND_UNIX_EPOCH + 24 * 3600 * ( 2048 * 7 + almanac_date_raw ) ); + return almanac_date; + } + else + { + return 0; + } +} + +static bool get_almanac_crc( const void* ral_context, uint32_t* almanac_crc ) +{ + lr11xx_status_t err; + lr11xx_gnss_context_status_bytestream_t context_status_bytestream; + lr11xx_gnss_context_status_t context_status; + + err = lr11xx_gnss_get_context_status( ral_context, context_status_bytestream ); + if( err != LR11XX_STATUS_OK ) + { + hal_mcu_trace_print( "Failed to get gnss context status\n" ); + return false; + } + + err = lr11xx_gnss_parse_context_status_buffer( context_status_bytestream, &context_status ); + if( err != LR11XX_STATUS_OK ) + { + hal_mcu_trace_print( "Failed to parse gnss context status to get almanac status\n" ); + return false; + } + + *almanac_crc = context_status.global_almanac_crc; + + return true; +} + +static bool almanac_update( const void* ral_context, uint8_t *almanac_data, uint16_t almanac_len ) +{ + uint32_t global_almanac_crc, local_almanac_crc; + local_almanac_crc = ( almanac_data[6] << 24 ) + ( almanac_data[5] << 16 ) + ( almanac_data[4] << 8 ) + ( almanac_data[3] ); + + if( get_almanac_crc( ral_context, &global_almanac_crc ) == false ) + { + hal_mcu_trace_print( "Failed to get almanac CRC before update\n" ); + return false; + } + if( global_almanac_crc != local_almanac_crc ) + { + hal_mcu_trace_print( "Local almanac doesn't match LR11XX almanac -> start update\n" ); + + /* Load almanac in flash */ + uint16_t almanac_idx = 0; + while( almanac_idx < almanac_len ) + { + if( lr11xx_gnss_almanac_update( ral_context, almanac_data + almanac_idx, 1 ) != LR11XX_STATUS_OK ) + { + hal_mcu_trace_print( "Failed to update almanac\n" ); + return false; + } + almanac_idx += LR11XX_GNSS_SINGLE_ALMANAC_WRITE_SIZE; + } + + /* Check CRC again to confirm proper update */ + if( get_almanac_crc( ral_context, &global_almanac_crc ) == false ) + { + hal_mcu_trace_print( "Failed to get almanac CRC after update\n" ); + return false; + } + if( global_almanac_crc != local_almanac_crc ) + { + hal_mcu_trace_print( "0x%08x, 0x%08x\r\n", global_almanac_crc, local_almanac_crc ); + hal_mcu_trace_print( "Local almanac doesn't match LR11XX almanac -> update failed\n" ); + return false; + } + else + { + uint32_t almanac_date = app_task_radio_get_almanac_date( ); + hal_mcu_trace_print("LR1110 new almanac date: %u\r\n", almanac_date ); + hal_mcu_trace_print( "Almanac update succeeded\r\n" ); + } + } + else + { + hal_mcu_trace_print( "Local almanac matches LR11XX almanac -> no update\n" ); + } + + return true; +} +uint32_t get_almanac_date_from_buffer( void ) +{ + //current + uint16_t almanac_date_raw = ( uint16_t )( ( full_almanac[2] << 8 ) | full_almanac[1] ); + uint32_t almanac_date = ( OFFSET_BETWEEN_GPS_EPOCH_AND_UNIX_EPOCH + 24 * 3600 * ( 2048 * 7 + almanac_date_raw ) ); + + almanac_date_time = almanac_date; + return almanac_date_time; +} + + diff --git a/libraries/LBM_packet/src/internal/main_almanac.h b/libraries/LBM_packet/src/internal/main_almanac.h new file mode 100644 index 000000000..e23fb6231 --- /dev/null +++ b/libraries/LBM_packet/src/internal/main_almanac.h @@ -0,0 +1,28 @@ +#ifndef _MAIN_ALMANAC_H_ +#define _MAIN_ALMANAC_H_ + + +/** + * app_task_full_almanac_update() - Update full almanac to lr1110 + * + */ +void app_task_full_almanac_update( void ); + +/** + * app_task_radio_get_almanac_date() - Get almanac date from lr1110 + * + * @return almanac date + * + */ +uint32_t app_task_radio_get_almanac_date( void ); + +/** + * get_almanac_date_from_buffer() - Get almanac date from full_almanac buffer + * + * @return almanac date + * + */ +uint32_t get_almanac_date_from_buffer( void ); + + +#endif diff --git a/libraries/LBM_packet/src/internal/main_ble.cpp b/libraries/LBM_packet/src/internal/main_ble.cpp index c32ac3856..bad5fd638 100644 --- a/libraries/LBM_packet/src/internal/main_ble.cpp +++ b/libraries/LBM_packet/src/internal/main_ble.cpp @@ -5,15 +5,29 @@ #include +uint8_t ble_scan_status = 0; - -uint8_t ble_scan_status = 0; - -uint8_t ble_beacon_res_num = 0; +uint8_t ble_beacon_res_num = 0; BleBeacons_t ble_beacon_buf[BLE_BEACON_BUF_MAX] = { 0 }; uint8_t ble_beacon_rssi_array[BLE_BEACON_BUF_MAX] = { 0 }; +// BLE adv Service +const uint16_t TRACKER_UUID1 = 0x2886; +const uint16_t TRACKER_UUID2 = 0xA886; + +BLEUuid uuid1 = BLEUuid(TRACKER_UUID1); +BLEUuid uuid2 = BLEUuid(TRACKER_UUID2); +BLEComm blecomm; + +volatile uint8_t ble_connect_status = 0; //0: none 1:init 2:connect 3:disconnect + +volatile bool notify_status = false; +char ble_rec_data_buf[244] = {0}; +uint8_t ble_rec_data_len = 0; +volatile bool ble_rec_done = false; +static char ble_tx_buf[244]; + bool buf_cmp_value( uint8_t *a, uint8_t *b, uint8_t len ) @@ -92,11 +106,18 @@ static void ble_scanner_evt_handler( ble_gap_evt_adv_report_t* report ) void scan_params_init(void) { + char adv_device_name[24] = {0}; + hexTonum((unsigned char *)adv_device_name, app_param.hardware_info.Sn, 9); + + uint8_t templen = strlen("-1110"); + + memcpy(&adv_device_name[18],"-1110",templen); + Bluefruit.begin(0, 1); Bluefruit.setTxPower(4); // Check bluefruit.h for supported values /* Set the device name */ - Bluefruit.setName("wio tracker"); + Bluefruit.setName(adv_device_name); /* Set the LED interval for blinky pattern on BLUE LED */ // Bluefruit.setConnLedInterval(250); @@ -240,3 +261,156 @@ void app_ble_display_results( void ) } +void app_ble_adv_init( void ) +{ + adv_params_init(); +} + + +void adv_params_init(void) +{ + char adv_device_name[24] = {0}; + hexTonum((unsigned char *)adv_device_name, app_param.hardware_info.Sn, 9); + + uint8_t templen = strlen("-1110"); + + memcpy(&adv_device_name[18],"-1110",templen); + + // Config the peripheral connection with maximum bandwidth + // more SRAM required by SoftDevice + // Note: All config***() function must be called before begin() + Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); + + Bluefruit.begin(); + Bluefruit.setTxPower(4); // Check bluefruit.h for supported values + Bluefruit.setName(adv_device_name); + + + Bluefruit.Periph.setConnectCallback(connect_callback); + Bluefruit.Periph.setDisconnectCallback(disconnect_callback); + + // Configure and Start BLE Uart Service + blecomm.begin(); + + // Set up and start advertising + startAdv(); + memset(ble_rec_data_buf,0,244); + ble_rec_data_len = 0; + ble_rec_done = false; + + ble_connect_status = 1; +} + +void startAdv(void) +{ + + Bluefruit.Advertising.addUuid(uuid1,uuid2); + Bluefruit.Advertising.addName(); + + /* Start Advertising + * - Enable auto advertising if disconnected + * - Interval: fast mode = 20 ms, slow mode = 152.5 ms + * - Timeout for fast mode is 30 seconds + * - Start(timeout) with timeout = 0 will advertise forever (until connected) + * + * For recommended advertising interval + * https://developer.apple.com/library/content/qa/qa1931/_index.html + */ + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds +} + +// callback invoked when central connects +void connect_callback(uint16_t conn_handle) +{ + // Get the reference to current connection + BLEConnection* connection = Bluefruit.Connection(conn_handle); + char central_name[32] = { 0 }; + ble_gap_addr_t ble_gap_addr; + ble_gap_addr = connection->getPeerAddr(); + connection->getPeerName(central_name, sizeof(central_name)); + hal_mcu_trace_print("Connected to %s\r\n",central_name); + hal_mcu_trace_print("mac:%02x:%02x:%02x:%02x:%02x:%02x\r\n",ble_gap_addr.addr[5],ble_gap_addr.addr[4],ble_gap_addr.addr[3],\ + ble_gap_addr.addr[2],ble_gap_addr.addr[1],ble_gap_addr.addr[0]); + + // request to update data length + connection->requestDataLengthUpdate(); + + // // request mtu exchange + // connection->requestMtuExchange(247); + + ble_connect_status = 2; +} + +bool bleMtuExchange(void) +{ + BLEConnection* connection = Bluefruit.Connection(0); + // request to update data length + connection->requestDataLengthUpdate(); + + // request to update data length + bool ret = connection->requestDataLengthUpdate(); + return ret; +} + + + +/** + * Callback invoked when a connection is dropped + * @param conn_handle connection where this event happens + * @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h + */ +void disconnect_callback(uint16_t conn_handle, uint8_t reason) +{ + (void) conn_handle; + (void) reason; + + hal_mcu_trace_print("Disconnected, reason = 0x%0x",reason); + ble_connect_status = 3; +} + + +static void vprint(const char *fmt, va_list argp) +{ + uint8_t ble_tx_len = 0; + + notify_status = blecomm.notifyEnabled(); + if(notify_status == true) + { + if (0 < vsprintf(ble_tx_buf, fmt, argp)) // build string + { + ble_tx_len = strlen(ble_tx_buf); + blecomm.write( ble_tx_buf, ble_tx_len ); + } + } +} + +void hal_ble_trace_print(const char *fmt, ...) +{ + va_list argp; + va_start(argp, fmt); + vprint(fmt, argp); + va_end(argp); +} + + +bool hal_ble_rec_data(void) +{ + ble_rec_data_len = blecomm.available(); + parse_cmd_type = 0; + if(ble_rec_data_len > 0 ) + { + parse_cmd_type = 1; + blecomm.read(ble_rec_data_buf,ble_rec_data_len); + ble_rec_done = true; + blecomm.flush(); // empty rx fifo + return true; + } + return false; +} + + + + diff --git a/libraries/LBM_packet/src/internal/main_ble.h b/libraries/LBM_packet/src/internal/main_ble.h index 2b8cd2836..e7f069077 100644 --- a/libraries/LBM_packet/src/internal/main_ble.h +++ b/libraries/LBM_packet/src/internal/main_ble.h @@ -12,7 +12,7 @@ #define BEACON_DATA_LEN 0x15 #define BEACON_DATA_TYPE 0x02 -#define COMPANY_IDENTIFIER 0x004C +#define COMPANY_IDENTIFIER 0x004C //Apple's company ID #define BLE_BEACON_BUF_MAX 16 #define BLE_BEACON_SEND_MUM 3 @@ -20,34 +20,131 @@ typedef struct sBleBeacons { - uint32_t utc; - uint16_t company_id; - uint8_t uuid[16]; + uint32_t utc; //time + uint16_t company_id; //ibeacon company id + uint8_t uuid[16]; //ibeacon uuid uint16_t major; uint16_t minor; - int8_t rssi; + int8_t rssi; int8_t rssi_; uint8_t mac[8]; }BleBeacons_t; extern uint8_t ble_scan_status; //0:none 1:init 2:start 3:stop -extern uint8_t ble_beacon_res_num; -extern BleBeacons_t ble_beacon_buf[BLE_BEACON_BUF_MAX]; -extern uint8_t ble_beacon_rssi_array[BLE_BEACON_BUF_MAX]; - - +extern uint8_t ble_beacon_res_num; //Number of ibeacons scanned +extern BleBeacons_t ble_beacon_buf[BLE_BEACON_BUF_MAX]; //ibeacons data buffer +extern uint8_t ble_beacon_rssi_array[BLE_BEACON_BUF_MAX]; //ibeacons rssi data buffer + +extern char ble_rec_data_buf[244]; //ble receive data buffer +extern uint8_t ble_rec_data_len; //ble receive data len +extern volatile bool ble_rec_done; //ble receive complete flag + +extern volatile uint8_t ble_connect_status; //0: none 1:init 2:connect 3:disconnect + +/** + * buf_cmp_value() - Compare the two groups to see if the numbers are the same + * + * @param a Data + * + * @param b Data + * + * @param len Data len + * + */ +bool buf_cmp_value( uint8_t *a, uint8_t *b, uint8_t len ); +/** + * app_ble_scan_init() - Initializes the Bluetooth scan + * + */ +void app_ble_scan_init( void ); -bool buf_cmp_value( uint8_t *a, uint8_t *b, uint8_t len ); +/** + * scan_params_init() - Initializes the Bluetooth scan parameter + * + */ +void scan_params_init(void); -void app_ble_scan_init( void ); +/** + * app_ble_scan_start() - Start the Bluetooth scan + * + */ bool app_ble_scan_start( void ); + +/** + * app_ble_get_results() - Get the Bluetooth scan results + * + * @param result Data results + * + * @param size Size + * + */ bool app_ble_get_results( uint8_t *result, uint8_t *size ); + +/** + * app_ble_scan_stop() - Stop the Bluetooth scan + * + */ void app_ble_scan_stop( void ); +/** + * app_ble_display_results() - Display the Bluetooth scan results + * + */ void app_ble_display_results( void ); -void scan_params_init(void); +/** + * app_ble_adv_init() - Initializes the Bluetooth Advertising + * + */ +void app_ble_adv_init( void ); + +/** + * adv_params_init() - Initialize Bluetooth Advertising parameters + * + */ +void adv_params_init(void); + +/** + * startAdv() - start Bluetooth Advertising + * + */ +void startAdv(void); + +/** + * connect_callback() - Callback invoked when device connection + * + * @param conn_handle connection where this event happens + * + */ +void connect_callback(uint16_t conn_handle); + +/** + * disconnect_callback() - Callback invoked when device disconnection + * + * @param conn_handle connection where this event happens + * + * @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h + * + */ +void disconnect_callback(uint16_t conn_handle, uint8_t reason); + +/** + * hal_ble_trace_print() - print data by ble + * + * @param fmt param + * + */ +void hal_ble_trace_print(const char *fmt, ...); + +/** + * hal_ble_rec_data() - Detects whether Bluetooth receives data + * + * @return true: received, false: none. + */ +bool hal_ble_rec_data(void) ; + + #endif diff --git a/libraries/LBM_packet/src/internal/main_gps.cpp b/libraries/LBM_packet/src/internal/main_gps.cpp index f95eb326a..90b616437 100644 --- a/libraries/LBM_packet/src/internal/main_gps.cpp +++ b/libraries/LBM_packet/src/internal/main_gps.cpp @@ -14,7 +14,7 @@ uint8_t gps_scan_status = 0; void app_gps_scan_init( void ) { gps_scan_status = 1; - // gnss_group_id_init(); + } bool app_gps_scan_start( void ) diff --git a/libraries/LBM_packet/src/internal/main_gps.h b/libraries/LBM_packet/src/internal/main_gps.h index de0f56941..0c3130e31 100644 --- a/libraries/LBM_packet/src/internal/main_gps.h +++ b/libraries/LBM_packet/src/internal/main_gps.h @@ -17,17 +17,41 @@ extern uint8_t app_gnss_scan_mode; // 0: GNSS_MW_MODE_STATIC, 1: GNSS_MW_MODE_MOBILE -extern uint32_t app_gps_lock_in_rtc_second; -extern uint32_t app_gps_lock_in_utc_second; - extern uint8_t gps_scan_status; //0:none 1:init 2:start 3:stop - - +/** + * app_gps_scan_init() - Initializes the gnss scan + * + */ void app_gps_scan_init( void ); + +/** + * app_gps_scan_start() - Start the gnss scan + * + * @return true: success, false: fail. + */ bool app_gps_scan_start( void ); + +/** + * app_gps_get_results() - Get the gnss scan results + * + * @param buf Data results + * + * @param size Size + * + */ bool app_gps_get_results( uint8_t *buf, uint8_t *size ); + +/** + * app_gps_scan_stop() - Stop the gnss scan + * + */ void app_gps_scan_stop( void ); + +/** + * app_gps_display_results() - Display the gnss scan results + * + */ void app_gps_display_results( void ); #endif diff --git a/libraries/LBM_packet/src/internal/main_lbm.cpp b/libraries/LBM_packet/src/internal/main_lbm.cpp index 5a332dc18..2926128cd 100644 --- a/libraries/LBM_packet/src/internal/main_lbm.cpp +++ b/libraries/LBM_packet/src/internal/main_lbm.cpp @@ -3,7 +3,7 @@ #include #include -uint8_t send_retry_type = 1; // 0:don't need check confirm 1: at most confirm once; 2: at most confirm twice; +uint8_t send_retry_type = 1; // 0: at most confirm twice; 1: at most confirm once; 2:don't need check confirm uint8_t app_task_lora_tx_buffer_len[APP_TASK_LORA_TX_QUEUE_MAX] = { 0 }; @@ -12,14 +12,18 @@ uint8_t app_task_lora_tx_buffer[APP_TASK_LORA_TX_QUEUE_MAX][LORAWAN_APP_DATA_MAX uint8_t app_task_lora_tx_in = 0; uint8_t app_task_lora_tx_out = 0; -uint32_t app_lora_sync_in_rtc_second = 0; -uint32_t app_lora_sync_in_utc_second = 0; - uint32_t app_send_confirmed_count = 0; uint32_t app_task_lora_tx_confirmed_count = 0; +static uint32_t tx_last_timestemp = 0; + bool app_task_lora_tx_check = false; +bool app_task_lora_tx_off_line = false; +bool app_task_lora_tx_cache = true; +static uint32_t app_task_lora_tx_toa = 0; + + void app_lora_confirmed_count_increment( void ) { app_send_confirmed_count++; @@ -34,8 +38,7 @@ uint32_t app_lora_get_confirmed_count( void ) bool app_task_lora_tx_engine( void ) { static uint8_t packet_send_cnt = 0; - static uint32_t app_task_lora_tx_toa = 0; - static uint32_t tx_last_timestemp = 0; + smtc_modem_status_mask_t modem_status; smtc_modem_region_t cur_region; uint8_t dutycycle_enable = 0; @@ -69,31 +72,57 @@ bool app_task_lora_tx_engine( void ) if( app_task_lora_tx_confirmed_count >= count_temp ) //unconfirmed { - if(send_retry_type == 1) //just confirm once,then unconfirm - { - if(packet_send_cnt >= 1) - { - packet_send_cnt = 0; - app_task_lora_tx_buffer_confirmed[app_task_lora_tx_out] = false; - } - } - else if(send_retry_type == 2) //confirm twice,then unconfirm + if(app_task_lora_tx_cache == true) { if(packet_send_cnt >= 2) { packet_send_cnt = 0; - app_task_lora_tx_buffer_confirmed[app_task_lora_tx_out] = false; - } + app_task_lora_save_tx_data( app_task_lora_tx_buffer[app_task_lora_tx_out], app_task_lora_tx_buffer_len[app_task_lora_tx_out] ); + app_task_lora_tx_buffer_len[out] = 0; //Clear the last data + out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + } } else { - packet_send_cnt = 0; - app_task_lora_tx_buffer_len[out] = 0; //Clear the last data - out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + if(send_retry_type == 1) //just confirm once,then unconfirm + { + if(packet_send_cnt >= 1) + { + packet_send_cnt = 0; + app_task_lora_tx_buffer_confirmed[app_task_lora_tx_out] = false; + } + } + else if(send_retry_type == 0) //confirm twice,then unconfirm + { + if(packet_send_cnt >= 2) + { + packet_send_cnt = 0; + app_task_lora_tx_buffer_confirmed[app_task_lora_tx_out] = false; + } + } + else + { + packet_send_cnt = 0; + app_task_lora_tx_buffer_len[out] = 0; //Clear the last data + out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + } } } else //confirmed { + if( app_task_lora_tx_off_line ) + { + app_task_lora_tx_off_line = false; + int8_t i = 3; + while( i-- ) + { + if( delete_pos_msg_datas( 1, true )) + { + hal_mcu_trace_print( "app delete old pos data ok\r\n" ); + break; + } + } + } app_task_lora_tx_buffer_len[out] = 0; //Clear the last data out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); } @@ -109,6 +138,7 @@ bool app_task_lora_tx_engine( void ) if( app_task_lora_tx_buffer_len[out] ) { + smtc_modem_get_status( 0, &modem_status ); if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED && app_lora_is_idle( ) @@ -118,13 +148,17 @@ bool app_task_lora_tx_engine( void ) bool result = app_lora_send_frame( app_task_lora_tx_buffer[out], app_task_lora_tx_buffer_len[out], app_task_lora_tx_buffer_confirmed[out], false ); if( result ) { + tx_last_timestemp = smtc_modem_hal_get_time_in_ms( ); app_task_lora_tx_out = out; hal_mcu_trace_print( "app_task_lora_tx_out: %u,confirm:%s\r\n", app_task_lora_tx_out,app_task_lora_tx_buffer_confirmed[out] == true ? "true":"false" ); + + smtc_modem_get_toa_status( &app_task_lora_tx_toa,app_task_lora_tx_buffer_len[out] + 13 ); if( app_task_lora_tx_buffer_confirmed[out] ) { packet_send_cnt ++; app_task_lora_tx_check = true; + app_task_lora_tx_off_line = false; app_task_lora_tx_confirmed_count = app_lora_get_confirmed_count( ); } else @@ -143,6 +177,10 @@ bool app_task_lora_tx_engine( void ) } else { + if(app_task_lora_tx_cache == true) + { + app_taks_lora_off_line_send_and_check(); + } last_time_tx_res = false; return false; } @@ -209,6 +247,208 @@ void app_task_packet_downlink_decode( uint8_t *buf, uint8_t len ) } +bool app_task_lora_save_tx_data( uint8_t *buf, uint8_t len ) +{ + bool result = false; + uint8_t ret = 0; + + memset(( uint8_t * )( &pos_msg_param ), 0, sizeof( pos_msg_param )); + + pos_msg_param.pos_type = buf[0]; + + if( pos_msg_param.pos_type != DATA_ID_UP_PACKET_GNSS_RAW ) + { + memcpyr(( uint8_t * )( &pos_msg_param.pos_status ), buf + 1, 4 ); + memcpyr(( uint8_t * )( &pos_msg_param.utc_time ), buf + 5, 4 ); + } + + switch( pos_msg_param.pos_type ) + { + case DATA_ID_UP_PACKET_GNSS_RAW: + { + pos_msg_param.context_count = 1; + pos_msg_param.context.gps_context.zone_flag = buf[1]; // fragment data + pos_msg_param.context.gps_context.gnss_len = buf[4]; // GNSS raw lenght + memcpyr(( uint8_t * )( &pos_msg_param.context.gps_context.group_id ), buf + 2, 2 ); // group id + memcpy( pos_msg_param.context.gps_context.gnss_res, buf + 5, pos_msg_param.context.gps_context.gnss_len ); // GNSS raw data + } + break; + case DATA_ID_UP_PACKET_GNSS_END: + { + pos_msg_param.context_count = 1; + pos_msg_param.context.gps_context.zone_flag = buf[9]; // fragment data + memcpyr(( uint8_t * )( &pos_msg_param.context.gps_context.group_id ), buf + 10, 2 ); // group id + pos_msg_param.context.gps_context.gnss_len = 0; // GNSS raw lenght + } + break; + case DATA_ID_UP_PACKET_WIFI_RAW: + { + pos_msg_param.context_count = ( len - 9 ) / 7; + for( uint8_t i = 0; i < pos_msg_param.context_count; i++ ) + { + memcpy( &pos_msg_param.context.wifi_context[i].wifi_mac, buf + 9 + i * 7, 6 ); + memcpy( &pos_msg_param.context.wifi_context[i].cur_rssi, buf + 9 + i * 7 + 6, 1 ); + } + } + break; + case DATA_ID_UP_PACKET_BLE_RAW: + { + pos_msg_param.context_count = ( len - 9 ) / 7; + for( uint8_t i = 0; i < pos_msg_param.context_count; i++ ) + { + memcpy( &pos_msg_param.context.beac_context[i].beac_mac, buf + 9 + i * 7, 6 ); + memcpy( &pos_msg_param.context.beac_context[i].cur_rssi, buf + 9 + i * 7 + 6, 1 ); + } + } + break; + case DATA_ID_UP_PACKET_POS_STATUS: + { + pos_msg_param.context_count = 1; + } + break; + case DATA_ID_UP_PACKET_USER_SENSOR: + { + pos_msg_param.context_count = 1; + pos_msg_param.context.sensor_context.len = len-1; + memcpy( &pos_msg_param.context.sensor_context.sensor_data, &buf[1], len-1 ); + + } + break; + case DATA_ID_UP_PACKET_FACT_SENSOR: + { + pos_msg_param.context_count = 1; + pos_msg_param.context.sensor_context.len = len-1; + memcpy( &pos_msg_param.context.sensor_context.sensor_data, &buf[1], len-1 ); + } + break; + default: + break; + } + ret = write_position_msg( ); + if( ret ) hal_mcu_trace_print( "Save off-line data ok\r\n" ); + else hal_mcu_trace_print( "Save off-line data fail\r\n" ); + return result = ret == 0 ? true:false; +} + +void app_taks_lora_off_line_send_and_check( void ) +{ + smtc_modem_status_mask_t modem_status; + pos_msg_param_t pos_msg; + memset( app_lora_data_tx_buffer, 0, sizeof( app_lora_data_tx_buffer )); + app_lora_data_tx_size = 0; + uint16_t pos_msg_cnt = get_pos_msg_cnt( ); + if( pos_msg_cnt == 0 ) + { + return; + } + + if( read_pos_data( &pos_msg, true )) + { + app_lora_data_tx_buffer[0] = pos_msg.pos_type; + + if( pos_msg.pos_type != DATA_ID_UP_PACKET_GNSS_RAW ) + { + memcpyr( app_lora_data_tx_buffer + 1, ( uint8_t * )( &pos_msg.pos_status ), 4 ); + memcpyr( app_lora_data_tx_buffer + 5, ( uint8_t * )( &pos_msg.utc_time ), 4 ); + } + + switch( pos_msg.pos_type ) + { + case DATA_ID_UP_PACKET_WIFI_RAW: + { + for( uint8_t i = 0; i < pos_msg.context_count; i++ ) + { + memcpy( app_lora_data_tx_buffer + 9 + i * 7, &pos_msg.context.wifi_context[i].wifi_mac, 6 ); + memcpy( app_lora_data_tx_buffer + 9 + i * 7 + 6, &pos_msg.context.wifi_context[i].cur_rssi, 1 ); + } + app_lora_data_tx_size = 9 + pos_msg.context_count * 7; + } + break; + + case DATA_ID_UP_PACKET_BLE_RAW: + { + for( uint8_t i = 0; i < pos_msg.context_count; i++ ) + { + memcpy( app_lora_data_tx_buffer + 9 + i * 7, &pos_msg.context.beac_context[i].beac_mac, 6 ); + memcpy( app_lora_data_tx_buffer + 9 + i * 7 + 6, &pos_msg.context.beac_context[i].cur_rssi, 1 ); + } + app_lora_data_tx_size = 9 + pos_msg.context_count * 7; + } + break; + + case DATA_ID_UP_PACKET_GNSS_RAW: + { + app_lora_data_tx_buffer[1] = pos_msg.context.gps_context.zone_flag; // fragment data + app_lora_data_tx_buffer[4] = pos_msg.context.gps_context.gnss_len; // GNSS raw lenght + memcpyr( app_lora_data_tx_buffer + 2, ( uint8_t * )( &pos_msg.context.gps_context.group_id ), 2 ); // group id + memcpy( app_lora_data_tx_buffer + 5, pos_msg.context.gps_context.gnss_res, pos_msg.context.gps_context.gnss_len ); // GNSS raw data + app_lora_data_tx_size = 5 + pos_msg.context.gps_context.gnss_len; + } + break; + + case DATA_ID_UP_PACKET_GNSS_END: + { + app_lora_data_tx_buffer[9] = pos_msg.context.gps_context.zone_flag; // fragment data + memcpyr( app_lora_data_tx_buffer + 11, ( uint8_t * )( &pos_msg.context.gps_context.group_id ), 2 ); // group id + app_lora_data_tx_size = 12; + } + break; + + case DATA_ID_UP_PACKET_POS_STATUS: + { + app_lora_data_tx_size = app_lora_data_tx_size + 9; + } + break; + case DATA_ID_UP_PACKET_USER_SENSOR: + { + memcpy( &app_lora_data_tx_buffer[1], ( uint8_t * )( pos_msg.context.sensor_context.sensor_data ), pos_msg.context.sensor_context.len ); + app_lora_data_tx_size = app_lora_data_tx_size + pos_msg.context.sensor_context.len+1; + } + break; + case DATA_ID_UP_PACKET_FACT_SENSOR: + { + memcpy( &app_lora_data_tx_buffer[1], ( uint8_t * )( pos_msg.context.sensor_context.sensor_data ), pos_msg.context.sensor_context.len ); + app_lora_data_tx_size = app_lora_data_tx_size + pos_msg.context.sensor_context.len+1; + } + break; + default: + { + delete_pos_msg_datas( 1, true ); + return; + } + break; + } + + hal_mcu_trace_print( "app data off-line: " ); + for( uint8_t i = 0; i < app_lora_data_tx_size; i++ ) + { + hal_mcu_trace_print( "%02x ", app_lora_data_tx_buffer[i] ); + } + hal_mcu_trace_print( "\r\n" ); + + smtc_modem_get_status( 0, &modem_status ); + if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED + && app_lora_is_idle( ) + && app_task_radio_gnss_is_busy( ) == false && app_task_radio_wifi_is_busy( ) == false + && app_task_track_gnss_is_busy( ) == false && app_task_track_wifi_is_busy( ) == false ) + { + + bool result = app_lora_send_frame( app_lora_data_tx_buffer, app_lora_data_tx_size, true, false ); + if( result ) + { + tx_last_timestemp = smtc_modem_hal_get_time_in_ms( ); + smtc_modem_get_toa_status( &app_task_lora_tx_toa,app_lora_data_tx_size + 13 ); + app_task_lora_tx_check = true; + app_task_lora_tx_off_line = true; + app_task_lora_tx_confirmed_count = app_lora_get_confirmed_count( ); + } + } + } + else + { + hal_mcu_trace_print( "app read old pos data fail\r\n" ); + } +} diff --git a/libraries/LBM_packet/src/internal/main_lbm.h b/libraries/LBM_packet/src/internal/main_lbm.h index fe4322a1a..d942313e0 100644 --- a/libraries/LBM_packet/src/internal/main_lbm.h +++ b/libraries/LBM_packet/src/internal/main_lbm.h @@ -8,36 +8,96 @@ #include "main_lora.h" -#define APP_TASK_LORA_TX_QUEUE_MAX 48 +#define APP_TASK_LORA_TX_QUEUE_MAX 48 extern uint8_t send_retry_type; // 0:don't need check confirm 1: at most confirm once; 2: at most confirm twice; -extern uint8_t app_task_lora_tx_in; +extern uint8_t app_task_lora_tx_in; // lora sends data input number -extern uint8_t app_task_lora_tx_out; +extern uint8_t app_task_lora_tx_out; // lora sends data output number -extern uint32_t app_lora_sync_in_rtc_second; -extern uint32_t app_lora_sync_in_utc_second; -extern uint32_t app_send_confirmed_count; -extern uint32_t app_task_lora_tx_confirmed_count; +extern uint32_t app_send_confirmed_count; // loracloud confirmed receive data count +extern uint32_t app_task_lora_tx_confirmed_count; // confirmed receive data count temp +extern bool app_task_lora_tx_cache; // Whether to cache historical data -extern uint8_t app_task_lora_tx_buffer_len[APP_TASK_LORA_TX_QUEUE_MAX] ; -extern bool app_task_lora_tx_buffer_confirmed[APP_TASK_LORA_TX_QUEUE_MAX]; -extern uint8_t app_task_lora_tx_buffer[APP_TASK_LORA_TX_QUEUE_MAX][LORAWAN_APP_DATA_MAX_SIZE] ; +extern uint8_t app_task_lora_tx_buffer_len[APP_TASK_LORA_TX_QUEUE_MAX] ; // lora tx data len +extern bool app_task_lora_tx_buffer_confirmed[APP_TASK_LORA_TX_QUEUE_MAX]; // Whether lora tx data need confirm +extern uint8_t app_task_lora_tx_buffer[APP_TASK_LORA_TX_QUEUE_MAX][LORAWAN_APP_DATA_MAX_SIZE] ; //lora tx data +/** + * app_lora_confirmed_count_increment() - Receive confirm that loracloud receives the data + * + */ void app_lora_confirmed_count_increment( void ); + +/** + * app_lora_get_confirmed_count() - Get confirmed count + * + * @return confirmed count + */ uint32_t app_lora_get_confirmed_count( void ); +/** + * app_task_lora_tx_queue() - Insert data to lora tx queue + * + * @param buf Data buffer + * + * @param len Data len + * + * @param confirmed Whether need confirm + * + * @param emergency Whether need emergency + * + * @return true: success, false: fail + */ bool app_task_lora_tx_queue( uint8_t *buf, uint8_t len, bool confirmed, bool emergency ); -uint32_t app_task_lora_get_timestamp( void ); -void app_task_lora_tx_done_wakeup( void ); +/** + * app_task_lora_get_timestamp() - Get timestamp + * + * @return Timestamp + */ +uint32_t app_task_lora_get_timestamp( void ); +/** + * app_task_lora_tx_engine() - Lora tx engine + * + * @return true: success, false: fail + */ bool app_task_lora_tx_engine( void ); +/** + * app_task_packet_downlink_decode() - Decode Lora downlink + * + * @param buf Data buffer + * + * @param len Data len + * + */ void app_task_packet_downlink_decode( uint8_t *buf, uint8_t len ); +/** + * app_task_lora_save_tx_data() - Save lora data that failed to send + * + * @param buf Data buffer + * + * @param len Data len + * + */ +bool app_task_lora_save_tx_data( uint8_t *buf, uint8_t len ); + +/** + * app_taks_lora_off_line_send_and_check() - Check and resend historical data + * + * @param buf Data buffer + * + * @param len Data len + * + */ +void app_taks_lora_off_line_send_and_check( void ); + + #endif diff --git a/libraries/LBM_packet/src/internal/main_lora.cpp b/libraries/LBM_packet/src/internal/main_lora.cpp index 870e0d0cb..6a00eb7bd 100644 --- a/libraries/LBM_packet/src/internal/main_lora.cpp +++ b/libraries/LBM_packet/src/internal/main_lora.cpp @@ -27,8 +27,6 @@ uint8_t adr_custom_list_region[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint8_t app_lora_data_tx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; uint8_t app_lora_data_tx_size = 0; -uint32_t app_lora_tx_recent_time = 0; - uint8_t app_lora_data_rx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; uint8_t app_lora_data_rx_size = 0; @@ -120,7 +118,6 @@ bool app_lora_send_frame( uint8_t* buffer, uint8_t length, bool tx_confirmed, bo if( result == SMTC_MODEM_RC_OK ) { - app_lora_tx_recent_time = smtc_modem_hal_get_time_in_ms( ); return true; } else return false; @@ -158,7 +155,7 @@ bool app_task_radio_wifi_is_busy( void ) -void app_set_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf) +void app_get_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf) { switch(REGION) { diff --git a/libraries/LBM_packet/src/internal/main_lora.h b/libraries/LBM_packet/src/internal/main_lora.h index 64dbbb0d3..b5905961f 100644 --- a/libraries/LBM_packet/src/internal/main_lora.h +++ b/libraries/LBM_packet/src/internal/main_lora.h @@ -1,11 +1,5 @@ - -#ifndef _MAIN_TASK_H_ -#define _MAIN_TASK_H_ - -/* - * ----------------------------------------------------------------------------- - * --- DEPENDENCIES ------------------------------------------------------------ - */ +#ifndef _MAIN_LORA_H_ +#define _MAIN_LORA_H_ #include #include @@ -22,80 +16,24 @@ #include "lbm/smtc_modem_api/smtc_modem_utilities.h" -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC MACROS ----------------------------------------------------------- - */ + #define MODEM_EXAMPLE_ASSISTANCE_POSITION_LAT_DEFAULT ( 22.576814 ) #define MODEM_EXAMPLE_ASSISTANCE_POSITION_LONG_DEFAULT ( 113.922068 ) -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC CONSTANTS -------------------------------------------------------- - */ -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE MACROS----------------------------------------------------------- - */ -/*! - * @brief Stringify constants - */ #define xstr( a ) str( a ) #define str( a ) #a -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE CONSTANTS ------------------------------------------------------- - */ -/** - * @brief Duration in second after last ALC sync response received to consider the local clock time invalid - * - * Set time valid for 1 day (to be fine tuned depending on board properties) - */ -#define APP_ALC_TIMING_INVALID ( 3600 * 24 ) -/** - * @brief Interval in second between two consecutive ALC sync requests - * - * 3 time sync requests per day - */ -#define APP_ALC_TIMING_INTERVAL ( APP_ALC_TIMING_INVALID / 3 ) +#define LORAWAN_APP_PORT 5 //The default LoRaWAN application port for uploading data to the sensecap platform -#define APP_LBM_IRQ_ERROR_CHECK 0 - -/*! - * @brief Defines the application data transmission duty cycle. 60s, value in [s]. - */ -#define APP_TX_DUTYCYCLE 60 - -/*! - * @brief LoRaWAN application port - */ -#define LORAWAN_APP_PORT 5 +#define LORAWAN_APP_DATA_MAX_SIZE 242 //Maximum lora data length -/*! - * @brief User application data buffer size - */ -#define LORAWAN_APP_DATA_MAX_SIZE 242 - -/* - * ----------------------------------------------------------------------------- - * --- LoRaWAN Configuration --------------------------------------------------- - */ - -/*! - * @brief LoRaWAN confirmed messages - */ -#define LORAWAN_CONFIRMED_MSG_ON false - -/*! - * @brief Default datarate - * - * @remark See @ref smtc_modem_adr_profile_t - */ #define LORAWAN_DEFAULT_DATARATE SMTC_MODEM_ADR_PROFILE_CUSTOM + +//Default lora data DR Control +//It must ensure that the minimum device can send 51 bytes of data,So that no subcontracting is required to send data #define LORAWAN_EU868_DR_MIN 0 #define LORAWAN_EU868_DR_MAX 6 @@ -117,34 +55,26 @@ #define LORAWAN_RU864_DR_MIN 0 #define LORAWAN_RU864_DR_MAX 6 -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC TYPES ------------------------------------------------------------ - */ -extern uint8_t stack_id; - -// extern ralf_t* modem_radio; - - -extern uint8_t app_lora_port; - -extern bool adr_user_enable; +extern uint8_t stack_id; // Lora stack id +extern uint8_t app_lora_port; // lora data sending port -extern float app_task_gnss_aiding_position_latitude; +//aiding position coordinate +extern float app_task_gnss_aiding_position_latitude; extern float app_task_gnss_aiding_position_longitude; -extern uint8_t adr_custom_list_region[16]; +extern uint8_t adr_custom_list_region[16]; // custom adr lists of different regions -extern uint32_t app_lora_tx_recent_time; -extern uint8_t mw_gnss_event_state; -extern uint8_t app_lora_data_tx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; -extern uint8_t app_lora_data_tx_size; +extern uint8_t mw_gnss_event_state; // gnss event see gnss_mw_event_type_t +extern uint8_t app_lora_data_tx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; //lora tx buffer +extern uint8_t app_lora_data_tx_size; //lora tx buffer size -extern uint8_t app_lora_data_rx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; -extern uint8_t app_lora_data_rx_size; +extern uint8_t app_lora_data_rx_buffer[LORAWAN_APP_DATA_MAX_SIZE]; //lora rx buffer +extern uint8_t app_lora_data_rx_size; //lora rx buffer size + +//default adr list for different regions extern uint8_t adr_custom_list_eu868_default[16]; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 extern uint8_t adr_custom_list_us915_default[16]; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7 extern uint8_t adr_custom_list_au915_default[16]; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7 @@ -154,29 +84,83 @@ extern uint8_t adr_custom_list_in865_default[16]; // SF12,SF12,SF12,SF11,SF11,SF extern uint8_t adr_custom_list_ru864_default[16]; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 -extern volatile bool is_first_time_sync; - +extern volatile bool is_first_time_sync; // the time synchronization flag -extern wifi_mw_event_data_scan_done_t wifi_results; +extern wifi_mw_event_data_scan_done_t wifi_results; //wifi result -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- +/** + * app_lora_set_port() - Set LoRaWAN application port + * + * @param port port + * */ - - void app_lora_set_port( uint8_t port ); + +/** + * app_lora_send_frame() - Send lora data frame + * + * @param buffer Data buffer + * + * @param length Data length + * + * @param tx_confirmed Whether need confirm + * + * @param emergency Whether need emergency + * + */ bool app_lora_send_frame( uint8_t* buffer, uint8_t length, bool tx_confirmed, bool emergency ); +/** + * app_lora_is_idle() - Check whether lora is idle + * + * @return true: idle, false: busy + */ bool app_lora_is_idle( void ); +/** + * app_task_lora_clock_is_synch() - Check whether time synchronization is complete + * + * @return true: success, false: fail + */ bool app_task_lora_clock_is_synch( void ); + +/** + * app_task_radio_gnss_is_busy() - Check whether gnss scanning + * + * @return true: busy, false: idle + */ bool app_task_radio_gnss_is_busy( void ); + +/** + * app_task_radio_wifi_is_busy() - Check whether Wifi scanning + * + * @return true: idle, false: busy + */ bool app_task_radio_wifi_is_busy( void ); +/** + * custom_lora_adr_compute() - Generate an adr list based on the DR Range + * + * @param min DR min + * + * @param max DR max + * + * @param buf adr list + * + * @return true: idle, false: busy + */ void custom_lora_adr_compute( uint8_t min, uint8_t max, uint8_t *buf ); -void app_set_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf); + +/** + * app_get_profile_list_by_region() - Get the default adr list of the region + * + * @param REGION region + * + * @param buf adr list + * + */ +void app_get_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf); #endif diff --git a/libraries/LBM_packet/src/internal/main_packet.cpp b/libraries/LBM_packet/src/internal/main_packet.cpp index eee37b5d2..c40a421fb 100644 --- a/libraries/LBM_packet/src/internal/main_packet.cpp +++ b/libraries/LBM_packet/src/internal/main_packet.cpp @@ -5,11 +5,7 @@ #include "app_param/default_config_datas.h" -//////////////////////////////////////////////////////////////////////////////// -// Variables -uint8_t app_lora_packet_buffer[LORAWAN_APP_DATA_MAX_SIZE] = { 0 }; -uint8_t app_lora_packet_len = 0; uint8_t factory_sensor_temp_len = 0; uint8_t factory_sensor_data_temp[64] = { 0 }; @@ -26,7 +22,12 @@ void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ) void default_param_load(void) { is_first_time_sync = false; - lorawan_param_init(); + param_init_func(); + + app_task_lora_tx_cache = app_append_param.cache_en; + send_retry_type = app_append_param.Retry; + + } @@ -112,3 +113,36 @@ void app_task_user_sensor_data_send( void ) state_all = 0; } + + +smtc_modem_region_t sensecap_lorawan_region(void) +{ + switch(app_param.lora_info.ActiveRegion) + { + case LORAMAC_REGION_AU915: + return SMTC_MODEM_REGION_AU_915; + case LORAMAC_REGION_CN470: + return SMTC_MODEM_REGION_CN_470; + case LORAMAC_REGION_EU868: + return SMTC_MODEM_REGION_EU_868; + case LORAMAC_REGION_US915: + return SMTC_MODEM_REGION_US_915; + case LORAMAC_REGION_RU864: + return SMTC_MODEM_REGION_RU_864; + case LORAMAC_REGION_KR920: + return SMTC_MODEM_REGION_KR_920; + case LORAMAC_REGION_IN865: + return SMTC_MODEM_REGION_IN_865; + default: + break; + + } + return SMTC_MODEM_REGION_EU_868; +} + + + + + + + diff --git a/libraries/LBM_packet/src/internal/main_packet.h b/libraries/LBM_packet/src/internal/main_packet.h index 1ddce0480..7cdfc0c2e 100644 --- a/libraries/LBM_packet/src/internal/main_packet.h +++ b/libraries/LBM_packet/src/internal/main_packet.h @@ -1,11 +1,11 @@ -#ifndef _APP_TASK_PACKET_H_ -#define _APP_TASK_PACKET_H_ +#ifndef _MAIN_PACKET_H_ +#define _MAIN_PACKET_H_ #include #include #include "main_lora.h" -//uplink +/*--------------------------- uplink ---------------------------*/ #define DATA_ID_UP_PACKET_GNSS_RAW 0x12 #define DATA_ID_UP_PACKET_GNSS_END 0x13 #define DATA_ID_UP_PACKET_WIFI_RAW 0x14 @@ -15,21 +15,53 @@ #define DATA_ID_UP_PACKET_USER_SENSOR 0x17 #define DATA_ID_UP_PACKET_FACT_SENSOR 0x18 -//downlink +/*--------------------------- downlink ---------------------------*/ #define DATA_ID_DOWN_PACKET_USER_CODE 0x8E +extern uint8_t factory_sensor_temp_len; // Manufacturer default sensor data len temp +extern uint8_t factory_sensor_data_temp[64]; // Manufacturer default sensor data buffer temp -extern uint8_t app_lora_packet_buffer[LORAWAN_APP_DATA_MAX_SIZE]; -extern uint8_t app_lora_packet_len; -extern uint8_t factory_sensor_temp_len; -extern uint8_t factory_sensor_data_temp[64]; - +/** + * memcpyr() - Copy data in a format with high byte data in front + * + * @param dst Destination data buffer + * + * @param src Source data buffer + * + * @param size Data size + * + */ void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ); -void default_param_load(void); +/** + * default_param_load() - Load default configuration parameters + * + */ +void default_param_load(void); +/** + * app_task_factory_sensor_data_send() - Send Manufacturer default sensor data + * + * @param dst Destination data buffer + * + * @param src Source data buffer + * + * @param size Data size + * + */ void app_task_factory_sensor_data_send( void ); + +/** + * app_task_user_sensor_data_send() - Send user sensor data + * + */ void app_task_user_sensor_data_send( void ); +/** + * sensecap_lorawan_region() - get region from flash + * + */ +smtc_modem_region_t sensecap_lorawan_region(void); + #endif diff --git a/libraries/LBM_packet/src/internal/main_sensor.cpp b/libraries/LBM_packet/src/internal/main_sensor.cpp index 74e3ae781..ccbbda7c0 100644 --- a/libraries/LBM_packet/src/internal/main_sensor.cpp +++ b/libraries/LBM_packet/src/internal/main_sensor.cpp @@ -56,8 +56,10 @@ float UV_val = 0.0; uint16_t sound_val = 0; uint16_t ultrasonic_distance_cm = 0; uint32_t dps310_pressure_val = 0; - - + +volatile uint8_t lis3dhtr_irq_flag = 0; +uint8_t move_trig_position = 0; +uint8_t move_trig_collect = 0; //sensor handle static SensirionI2CSht4x sht4x; static LIS3DHTR LIS; @@ -78,12 +80,13 @@ static constexpr int relay_pin = D2; //analog pin static constexpr int sound_adc_pin = A0; - - //irq callback---------------------------------------------------- void lis3dhtr_irq_callback(void) { lis3dhtr_irq_count ++; + lis3dhtr_irq_flag = 1; + move_trig_position = 1; + move_trig_collect = 1; } //grove power init ----------------------------------------------------- @@ -285,12 +288,6 @@ bool sht4x_data_get(float* temperature, float* humidity) // 11ms return false; iic_mutex_status = true; -#if(SENSOR_HOT_SWAPPABLE_DETECT == 1) - if(sht4x_available_detect()) - { - sensor_sht4x_init(); - } -#endif if(sensor_types&sht4x_sensor_type) { uint16_t error; @@ -324,13 +321,6 @@ bool lis3dhtr_data_get(float* x, float* y, float* z) return false; iic_mutex_status = true; -#if(SENSOR_HOT_SWAPPABLE_DETECT == 1) - if(lis3dhtr_available_detect()) - { - sensor_lis3dhtr_init(); - } -#endif - if(sensor_types&lis3dhtr_sensor_type) { uint8_t flag = 0; @@ -339,7 +329,7 @@ bool lis3dhtr_data_get(float* x, float* y, float* z) if(irq_count != lis3dhtr_irq_count) { irq_count = lis3dhtr_irq_count; - state_all = state_all|TRACKER_STATE_BIT2_MOT_BEG; + state_all = state_all|TRACKER_STATE_BIT5_DEV_SHOCK; app_task_track_motion_index_update(); } else diff --git a/libraries/LBM_packet/src/internal/main_sensor.h b/libraries/LBM_packet/src/internal/main_sensor.h index 2129c5272..23612e1d1 100644 --- a/libraries/LBM_packet/src/internal/main_sensor.h +++ b/libraries/LBM_packet/src/internal/main_sensor.h @@ -1,4 +1,3 @@ - #ifndef _MAIN_SENSOR_H_ #define _MAIN_SENSOR_H_ @@ -7,6 +6,7 @@ + //If defined as 1:detect iic slave device hot swap function #ifndef SENSOR_HOT_SWAPPABLE_DETECT #define SENSOR_HOT_SWAPPABLE_DETECT 1 @@ -30,26 +30,29 @@ -extern float sht4x_temperature; -extern float sht4x_humidity; -extern float lis3dhtr_x; -extern float lis3dhtr_y; -extern float lis3dhtr_z; -extern int32_t sgp41_voc_index; -extern float UV_val; -extern uint16_t sound_val; -extern uint16_t ultrasonic_distance_cm; -extern uint32_t dps310_pressure_val; +extern float sht4x_temperature; // sht41 temperture data +extern float sht4x_humidity; // sht41 humidity data +extern float lis3dhtr_x; // lis3dhtr X-axis data +extern float lis3dhtr_y; // lis3dhtr Y-axis data +extern float lis3dhtr_z; // lis3dhtr Z-axis data +extern int32_t sgp41_voc_index;// sgp41 voc index data +extern float UV_val; // si1151 uv data +extern uint16_t sound_val; // sound sensor data +extern uint16_t ultrasonic_distance_cm; // ultrasonic distance sensor data +extern uint32_t dps310_pressure_val; // dps310 Atmospheric pressure data +extern volatile uint8_t lis3dhtr_irq_flag; // lis3dhtr interrupt trigger flag +extern uint8_t move_trig_position; // lis3dhtr interrupt trigger position flag +extern uint8_t move_trig_collect; // lis3dhtr interrupt trigger collect sensor data flag -extern uint8_t factory_sensor_data_len; -extern uint8_t factory_sensor_data[20]; +extern uint8_t factory_sensor_data_len; // Manufacturer default sensor data len +extern uint8_t factory_sensor_data[20]; // Manufacturer default sensor data buffer -extern uint8_t user_sensor_data_len; -extern uint8_t user_sensor_data[40]; +extern uint8_t user_sensor_data_len; // user sensor data len +extern uint8_t user_sensor_data[40]; // user sensor data buffer -extern uint16_t sound_sample_index; -extern uint16_t sound_average_data; +extern uint16_t sound_sample_index; // sound sensor sample count index +extern uint16_t sound_average_data; // sound sensor average data diff --git a/libraries/LBM_packet/src/internal/main_track.cpp b/libraries/LBM_packet/src/internal/main_track.cpp index a5e3a054c..c5228873c 100644 --- a/libraries/LBM_packet/src/internal/main_track.cpp +++ b/libraries/LBM_packet/src/internal/main_track.cpp @@ -3,21 +3,6 @@ #include #include - -#include -#include -#include // for Serial - -using namespace Adafruit_LittleFS_Namespace; - -#define FILENAME "/group_id.txt" - - -static lfs_t *lfs; -static lfs_file_t file; - - - uint8_t tracker_gps_scan_len = 0; uint8_t tracker_gps_scan_data[64] = { 0 }; @@ -52,28 +37,11 @@ uint32_t app_task_track_get_utc( void ) else return smtc_modem_hal_get_time_in_s( ); } - -void app_task_track_set_scan_state( uint32_t bit ) -{ - state_all |= bit; -} - -void app_task_track_clear_scan_state( uint32_t bit ) -{ - state_all &= ( ~bit ); -} - void app_task_track_motion_index_update( void ) { motion_index = motion_index_backup + 1; } -void app_task_track_motion_index_clear( void ) -{ - motion_index_backup = motion_index; - motion_index = 0; -} - //track------------------------------------------------- void app_task_track_scan_send( void ) { @@ -326,7 +294,7 @@ bool app_task_track_wifi_is_busy( void ) return track_wifi_busy; } -void tracker_scan_type_set( uint8_t scan_type ) +void track_scan_type_set( uint8_t scan_type ) { switch(scan_type) { @@ -348,54 +316,3 @@ void tracker_scan_type_set( uint8_t scan_type ) } - -//group id----------------------------------------- -void gnss_group_id_init(void) -{ - uint32_t group_id_temp; - uint8_t len = sizeof(group_id_temp); - int ret = 0; - InternalFS.begin(); - lfs = InternalFS._getFS(); - - ret = lfs_file_open(lfs, &file, FILENAME, LFS_O_RDONLY); - // file existed - if ( ret == 0 ) - { - uint8_t readlen; - ret = lfs_file_rewind(lfs, &file); - len = lfs_file_read(lfs, &file, &group_id_temp, len); - lfs_file_close(lfs, &file); - track_gnss_group_id = group_id_temp; - } - else - { - ret = lfs_file_open(lfs, &file, FILENAME, LFS_O_RDWR | LFS_O_CREAT); - if( ret == 0 ) - { - group_id_temp = track_gnss_group_id; - lfs_file_rewind(lfs, &file); - lfs_file_write(lfs, &file, &group_id_temp, sizeof(group_id_temp)); - lfs_file_close(lfs, &file); - } - } -} - -bool gnss_group_id_write(void) -{ - uint32_t group_id_temp; - int ret = 0; - - group_id_temp = track_gnss_group_id; - ret = lfs_file_open(lfs, &file, FILENAME, LFS_O_RDWR | LFS_O_CREAT); - if(ret != 0) - { - lfs_file_close(lfs, &file); - return false; - } - - ret = lfs_file_rewind(lfs, &file); - ret = lfs_file_write(lfs, &file, &group_id_temp, sizeof(group_id_temp)); - lfs_file_close(lfs, &file); - return true; -} diff --git a/libraries/LBM_packet/src/internal/main_track.h b/libraries/LBM_packet/src/internal/main_track.h index dfa7c4c99..e58bc5ea9 100644 --- a/libraries/LBM_packet/src/internal/main_track.h +++ b/libraries/LBM_packet/src/internal/main_track.h @@ -1,4 +1,3 @@ - #ifndef _MAIN_TRACK_H_ #define _MAIN_TRACK_H_ @@ -24,55 +23,80 @@ #define TRACKER_STATE_BIT4_DEV_STATIC 0x0004 #define TRACKER_STATE_BIT5_DEV_SHOCK 0x0008 - +#define TRACKER_STATE_BIT0_SOS 0x0040 #define TRACKER_STATE_BIT1_USER 0x0080 -extern uint8_t tracker_gps_scan_len; -extern uint8_t tracker_gps_scan_data[64]; +extern uint8_t tracker_gps_scan_len; // gnss scan results len +extern uint8_t tracker_gps_scan_data[64]; // gnss scan results data buffer -extern uint8_t tracker_wifi_scan_len; -extern uint8_t tracker_wifi_scan_data[64]; +extern uint8_t tracker_wifi_scan_len; // wifi scan results data len +extern uint8_t tracker_wifi_scan_data[64]; // wifi scan results data buffer -extern uint8_t tracker_ble_scan_len; -extern uint8_t tracker_ble_scan_data[64]; +extern uint8_t tracker_ble_scan_len; // ble scan results len +extern uint8_t tracker_ble_scan_data[64]; // ble scan results data buffer -extern uint8_t tracker_scan_temp_len; -extern uint8_t tracker_scan_data_temp[64]; +extern uint8_t tracker_scan_temp_len; // tracker scan results temp len +extern uint8_t tracker_scan_data_temp[64]; // tracker scan results temp data len extern uint8_t tracker_scan_type; // 0: gps, 1: wifi, 2: ble, 3: gps/wifi, 4: gps/ble, 5: gps/wifi/ble -extern uint32_t state_all; -extern uint8_t motion_index; -extern uint8_t motion_index_backup; +extern uint32_t state_all; // event flag +extern uint8_t motion_index; // motion sequence index +extern uint8_t motion_index_backup; // backup motion sequence index + +extern bool track_gnss_busy; // gnss scan busy flag -extern bool track_gnss_busy; -extern bool track_wifi_busy; +extern bool track_wifi_busy; // wifi scan busy flag -extern uint16_t track_gnss_group_id; -extern uint32_t app_task_track_time_stamp; +extern uint16_t track_gnss_group_id; // gnss positioning group id +extern uint32_t app_task_track_time_stamp; // start track timestamp +/** + * app_task_track_scan_send() - Send tracker results + * + */ void app_task_track_scan_send( void ); +/** + * app_task_track_get_utc() - Get current utc + * + * @return utc + */ uint32_t app_task_track_get_utc( void ); -void tracker_scan_type_set( uint8_t scan_type ); - -void app_task_track_set_scan_state( uint32_t bit ); -void app_task_track_clear_scan_state( uint32_t bit ); +/** + * track_scan_type_set() - set track scan type + * + * @param scan_type TRACKER_SCAN_GPS/TRACKER_SCAN_WIFI/TRACKER_SCAN_BLE/TRACKER_SCAN_BLE_WIFI_GPS + * + */ +void track_scan_type_set( uint8_t scan_type ); + +/** + * app_task_track_motion_index_update() - Updata motion index + * + */ void app_task_track_motion_index_update( void ); -void app_task_track_motion_index_clear( void ); +/** + * app_task_track_wifi_is_busy() - check Whether wifi scan busy + * + * @return true: busy, false: idle + */ bool app_task_track_wifi_is_busy( void ); -bool app_task_track_gnss_is_busy( void ); -void gnss_group_id_init(void); -bool gnss_group_id_write(void); +/** + * app_task_track_gnss_is_busy() - check Whether gnss scan busy + * + * @return true: busy, false: idle + */ +bool app_task_track_gnss_is_busy( void ); #endif diff --git a/libraries/LBM_packet/src/internal/main_wifi.h b/libraries/LBM_packet/src/internal/main_wifi.h index a0e82caa5..ce93b4255 100644 --- a/libraries/LBM_packet/src/internal/main_wifi.h +++ b/libraries/LBM_packet/src/internal/main_wifi.h @@ -1,4 +1,3 @@ - #ifndef _MAIN_WIFI_H_ #define _MAIN_WIFI_H_ @@ -9,7 +8,7 @@ #include "mw/geolocation_middleware/wifi/src/wifi_helpers_defs.h" #include "mw/geolocation_middleware/wifi/src/wifi_middleware.h" -#define WIFI_AP_RSSI_EN 1 +#define WIFI_AP_RSSI_EN 1 /** * @brief Size in bytes to store the RSSI of a detected WiFi Access-Point @@ -31,12 +30,39 @@ extern uint8_t wifi_result_buffer[4+( WIFI_AP_RSSI_SIZE + WIFI_AP_ADDRESS_SIZE ) * WIFI_MAX_RESULTS + 4]; extern uint8_t wifi_scan_status; //0:none 1:init 2:start 3:stop - - +/** + * app_wifi_scan_init() - Initializes the wifi scan + * + */ void app_wifi_scan_init(); + +/** + * app_wifi_scan_start() - Start the wifi scan + * + * @return true: success, false: fail. + */ bool app_wifi_scan_start( void ); + +/** + * app_wifi_get_results() - Get the wifi scan results + * + * @param result Data results + * + * @param size Size + * + */ bool app_wifi_get_results( uint8_t *result, uint8_t *size ); + +/** + * app_wifi_scan_stop() - Stop the gnss scan + * + */ void app_wifi_scan_stop( void ); + +/** + * app_wifi_display_results() - Display the gnss scan results + * + */ void app_wifi_display_results( void ); #endif diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples index 20bd093a7..0046f1ad9 160000 --- a/libraries/Wio_Tracker_1110_Examples +++ b/libraries/Wio_Tracker_1110_Examples @@ -1 +1 @@ -Subproject commit 20bd093a7203cc2a202d50989b7d1b87ebd9d972 +Subproject commit 0046f1ad9f3328c5da83f7df8ef74c963c833d01 From 23eac926ef71d2bb6999248a807a05052e5d898f Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Fri, 22 Sep 2023 13:36:50 +0900 Subject: [PATCH 16/34] Update LBM_WM1110 --- libraries/LBM_WM1110 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index f7338ca40..a3b616c86 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit f7338ca400ab07cb89766591058904e3dd15a343 +Subproject commit a3b616c8651f40063279cb5353c681ea90152682 From c141d8f32d87cade5ac3fe00501453a5750dbbdd Mon Sep 17 00:00:00 2001 From: SeeedWenzy <142080102+SeeedWenzy@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:43:33 +0800 Subject: [PATCH 17/34] Update smtc_hal_mcu.h --- .../LBM_packet/src/common/smtc_hal_mcu.h | 63 +------------------ 1 file changed, 3 insertions(+), 60 deletions(-) diff --git a/libraries/LBM_packet/src/common/smtc_hal_mcu.h b/libraries/LBM_packet/src/common/smtc_hal_mcu.h index 27c2be543..59385ec72 100644 --- a/libraries/LBM_packet/src/common/smtc_hal_mcu.h +++ b/libraries/LBM_packet/src/common/smtc_hal_mcu.h @@ -112,20 +112,6 @@ void hal_mcu_critical_section_begin( uint32_t* mask ); */ void hal_mcu_critical_section_end( uint32_t* mask ); -/*! - * @brief Disable irq at core side - */ -void hal_mcu_disable_irq( void ); - -/*! - * @brief Enable irq at core side - */ -void hal_mcu_enable_irq( void ); - -/*! - * @brief Initializes HAL used MCU - */ -void hal_mcu_init( void ); /*! * @brief Resets the MCU @@ -140,25 +126,12 @@ void hal_mcu_reset( void ); void hal_mcu_wait_us( const int32_t microseconds ); /*! - * Sets the MCU in sleep mode for the given number of milliseconds. + * @brief Waits for delay milliseconds * - * @param[in] milliseconds Number of milliseconds to stay in sleep mode + * @param [in] ms Delay to wait in milliseconds */ -void hal_mcu_set_sleep_for_ms( const int32_t milliseconds ); +void hal_mcu_wait_ms( const int32_t ms ); -/*! - * @brief Get Vref intern from the MCU in mV - * - * @returns Vref In in mV. - */ -uint16_t hal_mcu_get_vref_level( void ); - -/*! - * @brief Get Temperature intern from the MCU in Celsius degree - * - * @returns Temperature in Celsius degree. - */ -int16_t hal_mcu_get_temperature( void ); /*! * @brief Prints debug trace @@ -167,36 +140,6 @@ int16_t hal_mcu_get_temperature( void ); */ void hal_mcu_trace_print( const char* fmt, ... ); -/*! - * @brief Suspend low power process and avoid looping on it - */ -void hal_mcu_disable_low_power_wait( void ); - -/*! - * @brief Enable low power process - */ -void hal_mcu_enable_low_power_wait( void ); - -/*! - * @brief Enable/Disable partial sleep - * - * @param [in] enable Activate the partial sleep - */ -void hal_mcu_partial_sleep_enable( bool enable ); - -/*! - * @brief Wait n ms defined by the user - * - * @param [in] delay_ms value in ms - */ -void hal_mcu_delay_ms( uint32_t delay_ms ); - -/*! - * @brief Wait n ms defined by the user - * - * @returns return tick. - */ -uint32_t hal_mcu_get_tick( void ); #ifdef __cplusplus } From 59bf13ece9d18f31172e361a37d0b0c1325666c6 Mon Sep 17 00:00:00 2001 From: SeeedWenzy <142080102+SeeedWenzy@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:44:02 +0800 Subject: [PATCH 18/34] Update smtc_hal_mcu.cpp --- .../LBM_packet/src/common/smtc_hal_mcu.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libraries/LBM_packet/src/common/smtc_hal_mcu.cpp b/libraries/LBM_packet/src/common/smtc_hal_mcu.cpp index a356133d6..9742617ab 100644 --- a/libraries/LBM_packet/src/common/smtc_hal_mcu.cpp +++ b/libraries/LBM_packet/src/common/smtc_hal_mcu.cpp @@ -24,3 +24,24 @@ void hal_mcu_trace_print( const char* fmt, ... ) va_end(args); #endif } + +void __attribute__( ( optimize( "O0" ) ) ) hal_mcu_wait_us( const int32_t microseconds ) +{ + // Work @64MHz + const uint32_t nb_nop = microseconds * 1000 / 171; + for( uint32_t i = 0; i < nb_nop; i++ ) + { + __NOP( ); + } +} +void hal_mcu_wait_ms( const int32_t ms ) +{ + for( uint32_t i = 0; i < ms; i++ ) + hal_mcu_wait_us( 1000 ); +} + +void hal_mcu_reset( void ) +{ + smtc_modem_hal_reset_mcu(); +} + From 43f27dec9726c0d05562a47f896bac79f6c44f22 Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Fri, 22 Sep 2023 20:35:15 +0800 Subject: [PATCH 19/34] 1.feat:add new region --- .gitmodules | 1 + libraries/LBM_WM1110 | 2 +- .../src/app_param/app_config_param.c | 2 +- .../src/app_param/app_config_param.h | 2 +- .../LBM_packet/src/internal/main_lbm.cpp | 2 +- .../LBM_packet/src/internal/main_lora.cpp | 7 +- .../LBM_packet/src/internal/main_packet.cpp | 88 +++++++++++++++---- libraries/Wio_Tracker_1110_Examples | 2 +- 8 files changed, 82 insertions(+), 24 deletions(-) diff --git a/.gitmodules b/.gitmodules index dc05f0125..5ecb8c741 100644 --- a/.gitmodules +++ b/.gitmodules @@ -45,3 +45,4 @@ [submodule "libraries/Wio_Tracker_1110_Examples"] path = libraries/Wio_Tracker_1110_Examples url = https://github.com/Seeed-Studio/Wio_Tracker_1110_Examples.git + branch = dev/wenzy diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index a3b616c86..473fbd0dc 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit a3b616c8651f40063279cb5353c681ea90152682 +Subproject commit 473fbd0dc68a2dbe20a3b32de76b692be261eed0 diff --git a/libraries/LBM_packet/src/app_param/app_config_param.c b/libraries/LBM_packet/src/app_param/app_config_param.c index d8bc315e0..69ce59bdb 100644 --- a/libraries/LBM_packet/src/app_param/app_config_param.c +++ b/libraries/LBM_packet/src/app_param/app_config_param.c @@ -51,7 +51,7 @@ gnss_group_param_t app_gnss_group_param= append_param_t app_append_param = { - .Platform = IOT_PLATFORM_SENSECAP_TTN, + .Platform = IOT_PLATFORM_SENSECAP_TTN, // 0: SENSECAP_TTN, 1: OTHER, 2: Helium, 3: TTN, 4:SENSECAP_HELIUM .Retry = 1, .cache_en = true, .position_interval = 5, diff --git a/libraries/LBM_packet/src/app_param/app_config_param.h b/libraries/LBM_packet/src/app_param/app_config_param.h index bef4bbd9b..8a67a1b45 100644 --- a/libraries/LBM_packet/src/app_param/app_config_param.h +++ b/libraries/LBM_packet/src/app_param/app_config_param.h @@ -174,7 +174,7 @@ typedef struct various_interval typedef struct append_param { - platform_t Platform; // 0:Sencap platform;1:Third-party platform + platform_t Platform; // 0: SENSECAP_TTN, 1: OTHER, 2: Helium, 3: TTN, 4:SENSECAP_HELIUM uint8_t Retry; bool cache_en; //cache data enabled/disable uint8_t res1; //Four-byte alignment diff --git a/libraries/LBM_packet/src/internal/main_lbm.cpp b/libraries/LBM_packet/src/internal/main_lbm.cpp index 2926128cd..6ab9ad214 100644 --- a/libraries/LBM_packet/src/internal/main_lbm.cpp +++ b/libraries/LBM_packet/src/internal/main_lbm.cpp @@ -326,7 +326,7 @@ bool app_task_lora_save_tx_data( uint8_t *buf, uint8_t len ) } ret = write_position_msg( ); - if( ret ) hal_mcu_trace_print( "Save off-line data ok\r\n" ); + if( ret == 0 ) hal_mcu_trace_print( "Save off-line data ok\r\n" ); else hal_mcu_trace_print( "Save off-line data fail\r\n" ); return result = ret == 0 ? true:false; } diff --git a/libraries/LBM_packet/src/internal/main_lora.cpp b/libraries/LBM_packet/src/internal/main_lora.cpp index 6a00eb7bd..6a35560f4 100644 --- a/libraries/LBM_packet/src/internal/main_lora.cpp +++ b/libraries/LBM_packet/src/internal/main_lora.cpp @@ -167,6 +167,11 @@ void app_get_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf) case SMTC_MODEM_REGION_AS_923_GRP2: case SMTC_MODEM_REGION_AS_923_GRP3: case SMTC_MODEM_REGION_AS_923_GRP4: + case SMTC_MODEM_REGION_AS_923_HELIUM_1: + case SMTC_MODEM_REGION_AS_923_HELIUM_2: + case SMTC_MODEM_REGION_AS_923_HELIUM_3: + case SMTC_MODEM_REGION_AS_923_HELIUM_4: + case SMTC_MODEM_REGION_AS_923_HELIUM_1B: memcpy(buf,adr_custom_list_as923_default,16); break; @@ -195,7 +200,7 @@ void app_get_profile_list_by_region(smtc_modem_region_t REGION,uint8_t *buf) case SMTC_MODEM_REGION_CN_470: default: - + break; } diff --git a/libraries/LBM_packet/src/internal/main_packet.cpp b/libraries/LBM_packet/src/internal/main_packet.cpp index c40a421fb..f9af726d4 100644 --- a/libraries/LBM_packet/src/internal/main_packet.cpp +++ b/libraries/LBM_packet/src/internal/main_packet.cpp @@ -117,27 +117,79 @@ void app_task_user_sensor_data_send( void ) smtc_modem_region_t sensecap_lorawan_region(void) { - switch(app_param.lora_info.ActiveRegion) + smtc_modem_region_t lorawan_region = SMTC_MODEM_REGION_EU_868; // can be change by user + uint8_t lorawan_region_sub_band = 2; // can be change by user + + switch( app_param.lora_info.ActiveRegion ) { - case LORAMAC_REGION_AU915: - return SMTC_MODEM_REGION_AU_915; - case LORAMAC_REGION_CN470: - return SMTC_MODEM_REGION_CN_470; - case LORAMAC_REGION_EU868: - return SMTC_MODEM_REGION_EU_868; - case LORAMAC_REGION_US915: - return SMTC_MODEM_REGION_US_915; - case LORAMAC_REGION_RU864: - return SMTC_MODEM_REGION_RU_864; - case LORAMAC_REGION_KR920: - return SMTC_MODEM_REGION_KR_920; - case LORAMAC_REGION_IN865: - return SMTC_MODEM_REGION_IN_865; + case 0: + case 15: + lorawan_region = SMTC_MODEM_REGION_AS_923_GRP1; + break; + + case 16: + lorawan_region = SMTC_MODEM_REGION_AS_923_GRP2; + break; + + case 17: + lorawan_region = SMTC_MODEM_REGION_AS_923_GRP3; + break; + + case 18: + lorawan_region = SMTC_MODEM_REGION_AS_923_GRP4; + break; + + case 1: + lorawan_region = SMTC_MODEM_REGION_AU_915; + break; + + case 5: + lorawan_region = SMTC_MODEM_REGION_EU_868; + break; + + case 6: + lorawan_region = SMTC_MODEM_REGION_KR_920; + break; + + case 7: + lorawan_region = SMTC_MODEM_REGION_IN_865; + break; + + case 8: + lorawan_region = SMTC_MODEM_REGION_US_915; + break; + + case 9: + lorawan_region = SMTC_MODEM_REGION_RU_864; + break; + + case 10: + lorawan_region = SMTC_MODEM_REGION_AS_923_HELIUM_1; + break; + + case 11: + lorawan_region = SMTC_MODEM_REGION_AS_923_HELIUM_2; + break; + + case 12: + lorawan_region = SMTC_MODEM_REGION_AS_923_HELIUM_3; + break; + + case 13: + lorawan_region = SMTC_MODEM_REGION_AS_923_HELIUM_4; + break; + + case 14: + lorawan_region = SMTC_MODEM_REGION_AS_923_HELIUM_1B; + break; + default: - break; - + break; } - return SMTC_MODEM_REGION_EU_868; + + lorawan_region_sub_band = app_param.lora_info.ChannelGroup + 1; + + return lorawan_region; } diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples index 20bd093a7..cda3ff165 160000 --- a/libraries/Wio_Tracker_1110_Examples +++ b/libraries/Wio_Tracker_1110_Examples @@ -1 +1 @@ -Subproject commit 20bd093a7203cc2a202d50989b7d1b87ebd9d972 +Subproject commit cda3ff1656755df968d125f7c59032deaa7940df From 5432931c6669c7ea5b0f80e63eef8540ec2fb873 Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Sun, 24 Sep 2023 14:05:38 +0800 Subject: [PATCH 20/34] 1.feat:update submodule --- .gitmodules | 6 +++--- libraries/LBM_WM1110 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index 5ecb8c741..d38a8fe72 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,9 +10,6 @@ [submodule "libraries/LBMX"] path = libraries/LBMX url = https://github.com/SeeedJP/LBMX.git -[submodule "libraries/LBM_WM1110"] - path = libraries/LBM_WM1110 - url = https://github.com/SeeedJP/LBM_WM1110.git [submodule "libraries/SdFat"] path = libraries/SdFat url = https://github.com/adafruit/SdFat.git @@ -46,3 +43,6 @@ path = libraries/Wio_Tracker_1110_Examples url = https://github.com/Seeed-Studio/Wio_Tracker_1110_Examples.git branch = dev/wenzy +[submodule "libraries/LBM_WM1110"] + path = libraries/LBM_WM1110 + url = https://github.com/SeeedJP/LBM_WM1110.git diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index 473fbd0dc..a3b616c86 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit 473fbd0dc68a2dbe20a3b32de76b692be261eed0 +Subproject commit a3b616c8651f40063279cb5353c681ea90152682 From 7b7b5a63f04f77afd09bb5fdf3ffab3fb829c66f Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Sun, 24 Sep 2023 15:06:13 +0800 Subject: [PATCH 21/34] 1.fix:Change the LBM_WM1110 submodules --- .gitmodules | 1 + libraries/LBM_WM1110 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index d38a8fe72..aaccac1e0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -46,3 +46,4 @@ [submodule "libraries/LBM_WM1110"] path = libraries/LBM_WM1110 url = https://github.com/SeeedJP/LBM_WM1110.git + branch = dev/wenzy diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index a3b616c86..156b989ed 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit a3b616c8651f40063279cb5353c681ea90152682 +Subproject commit 156b989ededcd8a252b3dfe48e3c9d0842bec4b1 From c90c8e5a89ec26d7d5c56511bc7274b4be1b9bbd Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Sun, 24 Sep 2023 20:08:44 +0800 Subject: [PATCH 22/34] 1.fix:fix uplink current packet error 2.feat:add function to delete history data --- libraries/LBM_packet/src/app_param/at.cpp | 27 +++++++++++++++++++ libraries/LBM_packet/src/app_param/at.h | 9 ++++++- .../LBM_packet/src/app_param/at_command.cpp | 7 +++++ .../src/internal/get_full_almanac.py | 10 +++---- .../LBM_packet/src/internal/main_lbm.cpp | 9 ++++--- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/libraries/LBM_packet/src/app_param/at.cpp b/libraries/LBM_packet/src/app_param/at.cpp index bccba0111..5f66c3182 100644 --- a/libraries/LBM_packet/src/app_param/at.cpp +++ b/libraries/LBM_packet/src/app_param/at.cpp @@ -987,3 +987,30 @@ ATEerror_t AT_MeasurementValue_get(const char *param) { return AT_OK; } /*------------------------AT+MEA=?\r\n-------------------------------------*/ + +/*------------------------AT+POS_DEL\r\n-------------------------------------*/ +ATEerror_t AT_POS_DEL_run(const char *param) +{ + uint16_t del_cnt = 0; + del_cnt = get_pos_msg_cnt(); + if(del_cnt > 0) + { + if(delete_pos_msg_datas(del_cnt,true) != 0) + { + return AT_DELETE_ERROR; + } + } + return AT_OK; +} +/*------------------------AT+POS_DEL\r\n-------------------------------------*/ + + + + + + + + + + + diff --git a/libraries/LBM_packet/src/app_param/at.h b/libraries/LBM_packet/src/app_param/at.h index e5dd5f72f..6e2029786 100644 --- a/libraries/LBM_packet/src/app_param/at.h +++ b/libraries/LBM_packet/src/app_param/at.h @@ -64,7 +64,7 @@ extern void hal_ble_trace_print( const char* fmt, ... ); #define AT_SENSOR "+SENSOR" #define AT_PLATFORM "+PLATFORM" #define AT_MEA "+MEA" - +#define AT_POS_DEL "+POS_DEL" /* USER CODE BEGIN EM */ void hexTonum(unsigned char *out_data, unsigned char *in_data, unsigned short Size); @@ -385,6 +385,13 @@ ATEerror_t AT_DefEUI_get(const char *param); */ ATEerror_t AT_MeasurementValue_get(const char *param); +/** + * @brief delete history data + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_POS_DEL_run(const char *param); + #endif /* __AT_H__ */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libraries/LBM_packet/src/app_param/at_command.cpp b/libraries/LBM_packet/src/app_param/at_command.cpp index 42e1d8622..06f77834c 100644 --- a/libraries/LBM_packet/src/app_param/at_command.cpp +++ b/libraries/LBM_packet/src/app_param/at_command.cpp @@ -202,6 +202,13 @@ static const struct ATCommand_s ATCommand[] = .set = AT_return_error, .run = AT_return_error, }, + { + .string = AT_POS_DEL, + .size_string = sizeof(AT_POS_DEL) - 1, + .get = AT_return_error, + .set = AT_return_error, + .run = AT_POS_DEL_run, + }, }; /** diff --git a/libraries/LBM_packet/src/internal/get_full_almanac.py b/libraries/LBM_packet/src/internal/get_full_almanac.py index 0755dfb43..55a783a63 100644 --- a/libraries/LBM_packet/src/internal/get_full_almanac.py +++ b/libraries/LBM_packet/src/internal/get_full_almanac.py @@ -97,13 +97,13 @@ def main(): print("Almanac image written to " + filename + " file") - output_path = 'test_acmanac.bin' # 输出文件的路径和文件名称,这里直接放在工程根目录下,所以没有写绝对路径 + # output_path = 'test_acmanac.bin' # 输出文件的路径和文件名称,这里直接放在工程根目录下,所以没有写绝对路径 - # 待写入的数据 + # # 待写入的数据 - with open(output_path, 'ab') as f: - f.write(raw_bytes) - f.close() + # with open(output_path, 'ab') as f: + # f.write(raw_bytes) + # f.close() diff --git a/libraries/LBM_packet/src/internal/main_lbm.cpp b/libraries/LBM_packet/src/internal/main_lbm.cpp index 6ab9ad214..acbe2422a 100644 --- a/libraries/LBM_packet/src/internal/main_lbm.cpp +++ b/libraries/LBM_packet/src/internal/main_lbm.cpp @@ -123,8 +123,11 @@ bool app_task_lora_tx_engine( void ) } } } - app_task_lora_tx_buffer_len[out] = 0; //Clear the last data - out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + else + { + app_task_lora_tx_buffer_len[out] = 0; //Clear the last data + out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + } } } else @@ -138,7 +141,7 @@ bool app_task_lora_tx_engine( void ) if( app_task_lora_tx_buffer_len[out] ) { - + smtc_modem_get_status( 0, &modem_status ); if(( modem_status & SMTC_MODEM_STATUS_JOINED ) == SMTC_MODEM_STATUS_JOINED && app_lora_is_idle( ) From 207c238801fa3350dc3f94819beaff407982b308 Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Sun, 24 Sep 2023 20:25:53 +0800 Subject: [PATCH 23/34] 1.fix:offline data is stored incorrectly --- .../LBM_packet/src/internal/main_lbm.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libraries/LBM_packet/src/internal/main_lbm.cpp b/libraries/LBM_packet/src/internal/main_lbm.cpp index acbe2422a..24f5f25e2 100644 --- a/libraries/LBM_packet/src/internal/main_lbm.cpp +++ b/libraries/LBM_packet/src/internal/main_lbm.cpp @@ -74,13 +74,20 @@ bool app_task_lora_tx_engine( void ) { if(app_task_lora_tx_cache == true) { - if(packet_send_cnt >= 2) + if(app_task_lora_tx_off_line) { - packet_send_cnt = 0; - app_task_lora_save_tx_data( app_task_lora_tx_buffer[app_task_lora_tx_out], app_task_lora_tx_buffer_len[app_task_lora_tx_out] ); - app_task_lora_tx_buffer_len[out] = 0; //Clear the last data - out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); - } + app_task_lora_tx_off_line = false; + } + else + { + if(packet_send_cnt >= 2) + { + packet_send_cnt = 0; + app_task_lora_save_tx_data( app_task_lora_tx_buffer[app_task_lora_tx_out], app_task_lora_tx_buffer_len[app_task_lora_tx_out] ); + app_task_lora_tx_buffer_len[out] = 0; //Clear the last data + out = (++app_task_lora_tx_out % APP_TASK_LORA_TX_QUEUE_MAX); + } + } } else { From 703e5d70634593949b7d9acf5f4eeb2a6574ea66 Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Sun, 24 Sep 2023 21:32:34 +0800 Subject: [PATCH 24/34] 1.fix:fix the bug init group id error --- libraries/LBM_packet/src/app_param/user_stored_data.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/LBM_packet/src/app_param/user_stored_data.cpp b/libraries/LBM_packet/src/app_param/user_stored_data.cpp index ee4b4500f..2cff6ec03 100644 --- a/libraries/LBM_packet/src/app_param/user_stored_data.cpp +++ b/libraries/LBM_packet/src/app_param/user_stored_data.cpp @@ -212,6 +212,8 @@ void param_init_func(void) } gnss_group_id_param_init(); + hal_mcu_trace_print("track_gnss_group_id:%d\r\n",track_gnss_group_id); + app_append_param_init(); } @@ -758,7 +760,10 @@ void gnss_group_id_param_init(void) hal_mcu_trace_print("gnss_group_id_param_init error,code:%02x\r\n",ret); } track_gnss_group_id = app_gnss_group_param.group_id; - } + } + else{ + track_gnss_group_id = app_gnss_group_param.group_id; + } } } From 0cc6aa4da52394942cfbd1b783b6250e70cdef04 Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Mon, 25 Sep 2023 08:42:20 +0900 Subject: [PATCH 25/34] Update LBM_WM1110 --- libraries/LBM_WM1110 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index a3b616c86..3e51f2449 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit a3b616c8651f40063279cb5353c681ea90152682 +Subproject commit 3e51f244921d32304b7bb46558718e46deb34e55 From 857261ff1f45981e1f18031718550471537c9b8a Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Mon, 25 Sep 2023 09:03:36 +0900 Subject: [PATCH 26/34] Update Wio_Tracker_1110_Examples --- libraries/Wio_Tracker_1110_Examples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples index 20bd093a7..b31ec0ca1 160000 --- a/libraries/Wio_Tracker_1110_Examples +++ b/libraries/Wio_Tracker_1110_Examples @@ -1 +1 @@ -Subproject commit 20bd093a7203cc2a202d50989b7d1b87ebd9d972 +Subproject commit b31ec0ca1864a306bfb9e75ee1cf57e8a084f28c From 2ca7c07ac6064b71e0f412bdf4e6d6cfe7c34d0b Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Mon, 25 Sep 2023 08:33:23 +0800 Subject: [PATCH 27/34] 1.fix:fix the bug that location data cannot be reported because sensor data collection is triggered continuously --- .gitmodules | 8 ++++---- libraries/LBM_packet/src/internal/main_sensor.cpp | 7 +++++-- libraries/Wio_Tracker_1110_Examples | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitmodules b/.gitmodules index aaccac1e0..87a9248b5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -39,11 +39,11 @@ path = libraries/Grove_Sunlight_Sensor url = https://github.com/Seeed-Studio/Grove_Sunlight_Sensor.git branch = Si1151 -[submodule "libraries/Wio_Tracker_1110_Examples"] - path = libraries/Wio_Tracker_1110_Examples - url = https://github.com/Seeed-Studio/Wio_Tracker_1110_Examples.git - branch = dev/wenzy [submodule "libraries/LBM_WM1110"] path = libraries/LBM_WM1110 url = https://github.com/SeeedJP/LBM_WM1110.git branch = dev/wenzy +[submodule "libraries/Wio_Tracker_1110_Examples"] + path = libraries/Wio_Tracker_1110_Examples + url = https://github.com/Seeed-Studio/Wio_Tracker_1110_Examples.git + branch = dev/wenzy diff --git a/libraries/LBM_packet/src/internal/main_sensor.cpp b/libraries/LBM_packet/src/internal/main_sensor.cpp index ccbbda7c0..84c38e7b1 100644 --- a/libraries/LBM_packet/src/internal/main_sensor.cpp +++ b/libraries/LBM_packet/src/internal/main_sensor.cpp @@ -85,8 +85,11 @@ void lis3dhtr_irq_callback(void) { lis3dhtr_irq_count ++; lis3dhtr_irq_flag = 1; - move_trig_position = 1; - move_trig_collect = 1; + if((move_trig_position == 0) && (move_trig_collect == 0)) + { + move_trig_position = 1; + move_trig_collect = 1; + } } //grove power init ----------------------------------------------------- diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples index cda3ff165..10ee389e6 160000 --- a/libraries/Wio_Tracker_1110_Examples +++ b/libraries/Wio_Tracker_1110_Examples @@ -1 +1 @@ -Subproject commit cda3ff1656755df968d125f7c59032deaa7940df +Subproject commit 10ee389e65bf920369eb0151c0eda50bd5287a9d From 9597238cfc693f19db90981eeaf9ff0179b6fa71 Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Mon, 25 Sep 2023 13:52:19 +0900 Subject: [PATCH 28/34] Update Wio_Tracker_1110_Examples --- libraries/Wio_Tracker_1110_Examples | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Wio_Tracker_1110_Examples b/libraries/Wio_Tracker_1110_Examples index d27a540a9..cece5e064 160000 --- a/libraries/Wio_Tracker_1110_Examples +++ b/libraries/Wio_Tracker_1110_Examples @@ -1 +1 @@ -Subproject commit d27a540a91dadc54d7f1bc9f00281c6b1bc343e4 +Subproject commit cece5e064e155437777a7e9ed77b446e93e272c2 From 2477c1c91bbc3fa332066f8dfe1f7eff2648d7ba Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Tue, 26 Sep 2023 15:31:06 +0800 Subject: [PATCH 29/34] 1.fix:fix historical data being incorrectly deleted --- libraries/LBM_packet/src/internal/main_lbm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/LBM_packet/src/internal/main_lbm.cpp b/libraries/LBM_packet/src/internal/main_lbm.cpp index 24f5f25e2..eb4586ff9 100644 --- a/libraries/LBM_packet/src/internal/main_lbm.cpp +++ b/libraries/LBM_packet/src/internal/main_lbm.cpp @@ -123,7 +123,7 @@ bool app_task_lora_tx_engine( void ) int8_t i = 3; while( i-- ) { - if( delete_pos_msg_datas( 1, true )) + if(0 == delete_pos_msg_datas( 1, true )) { hal_mcu_trace_print( "app delete old pos data ok\r\n" ); break; From 61cbde3771109b53a89699086b0232c582f9c3dc Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Tue, 26 Sep 2023 19:57:17 +0800 Subject: [PATCH 30/34] 1.fix:fix the reported location status error --- libraries/LBM_packet/src/internal/main_track.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/LBM_packet/src/internal/main_track.cpp b/libraries/LBM_packet/src/internal/main_track.cpp index c5228873c..95302a6ea 100644 --- a/libraries/LBM_packet/src/internal/main_track.cpp +++ b/libraries/LBM_packet/src/internal/main_track.cpp @@ -60,10 +60,12 @@ void app_task_track_scan_send( void ) //Location failure type if(( app_task_lora_clock_is_synch( ) == false ) || ( mw_gnss_event_state == GNSS_MW_EVENT_ERROR_NO_TIME )) { + mw_gnss_event_state = 0; tracker_scan_data_temp[1] = 13; // sync time fail } else if( mw_gnss_event_state == GNSS_MW_EVENT_ERROR_ALMANAC_UPDATE ) { + mw_gnss_event_state = 0; tracker_scan_data_temp[1] = 14; // almanac too old } else From 82d270ddd7f1ee65e781f2016a0489116c64135b Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Wed, 27 Sep 2023 09:11:21 +0900 Subject: [PATCH 31/34] Add "Customize LoRaWAN modem" menu --- boards.txt | 9 ++++++++- libraries/LBM_WM1110 | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/boards.txt b/boards.txt index a233deec7..c3ca6023d 100644 --- a/boards.txt +++ b/boards.txt @@ -2,6 +2,7 @@ menu.softdevice=SoftDevice menu.debug=Debug menu.debug_output=Print Port menu.usb_cdc=Serial (USB-CDC) +menu.lbm_custom=Customize LoRaWAN modem menu.power_supply_grove=Grove power supply # ---------------------------------- @@ -141,7 +142,7 @@ wio_tracker_1110.build.core=nRF5 wio_tracker_1110.build.variant=Seeed_Wio_Tracker_1110 wio_tracker_1110.build.usb_manufacturer="Seeed" wio_tracker_1110.build.usb_product="Wio Tracker 1110" -wio_tracker_1110.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} {build.flags.power_supply_grove} -DSEGGER_RTT_MAX_NUM_UP_BUFFERS=2 -DSEGGER_RTT_MAX_NUM_DOWN_BUFFERS=2 -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_NO_BLOCK_SKIP -DBUFFER_SIZE_UP=2048 -DBUFFER_SIZE_DOWN=4 -DNRFX_NVMC_ENABLED=1 -DNRFX_RNG_ENABLED=1 -DNRFX_RTC_ENABLED=1 -DNRFX_RTC2_ENABLED=1 -DNRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY=6 -DNRFX_TIMER_ENABLED=1 -DNRFX_TIMER2_ENABLED=1 -DNRFX_WDT_ENABLED=1 -DNRFX_WDT0_ENABLED=1 -DLR11XX -DLR11XX_TRANSCEIVER -DUSE_LR11XX_CE -DENABLE_MODEM_GNSS_FEATURE -DRP2_103 -DREGION_AS_923 -DREGION_AU_915 -DREGION_CN_470 -DREGION_CN_470_RP_1_0 -DREGION_EU_868 -DREGION_IN_865 -DREGION_KR_920 -DREGION_RU_864 -DREGION_US_915 -DREGION_WW2G4 -DWW2G4_SINGLE_DATARATE -DSMTC_MULTICAST -DADD_SMTC_STREAM -DADD_SMTC_FILE_UPLOAD -DADD_SMTC_ALC_SYNC -DMODEM_HAL_DBG_TRACE=1 -DMODEM_HAL_DEEP_DBG_TRACE=0 -DMODEM_HAL_DBG_TRACE_RP=0 -DMODEM_HAL_DBG_TRACE_COLOR=0 -DTASK_EXTENDED_1 -DTASK_EXTENDED_2 -DLR11XX_DISABLE_WARNINGS -DMW_DBG_TRACE=1 -DMW_DBG_TRACE_COLOR=0 -DWM1110_TRACE_MAX_LENGTH=256 +wio_tracker_1110.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} {build.flags.power_supply_grove} {build.flags.lbm_custom} -DSEGGER_RTT_MAX_NUM_UP_BUFFERS=2 -DSEGGER_RTT_MAX_NUM_DOWN_BUFFERS=2 -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_NO_BLOCK_SKIP -DBUFFER_SIZE_UP=2048 -DBUFFER_SIZE_DOWN=4 -DNRFX_NVMC_ENABLED=1 -DNRFX_RNG_ENABLED=1 -DNRFX_RTC_ENABLED=1 -DNRFX_RTC2_ENABLED=1 -DNRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY=6 -DNRFX_TIMER_ENABLED=1 -DNRFX_TIMER2_ENABLED=1 -DNRFX_WDT_ENABLED=1 -DNRFX_WDT0_ENABLED=1 -DLR11XX -DLR11XX_TRANSCEIVER -DUSE_LR11XX_CE -DENABLE_MODEM_GNSS_FEATURE -DRP2_103 -DREGION_AS_923 -DREGION_AU_915 -DREGION_CN_470 -DREGION_CN_470_RP_1_0 -DREGION_EU_868 -DREGION_IN_865 -DREGION_KR_920 -DREGION_RU_864 -DREGION_US_915 -DREGION_WW2G4 -DWW2G4_SINGLE_DATARATE -DSMTC_MULTICAST -DADD_SMTC_STREAM -DADD_SMTC_FILE_UPLOAD -DADD_SMTC_ALC_SYNC -DMODEM_HAL_DBG_TRACE=1 -DMODEM_HAL_DEEP_DBG_TRACE=0 -DMODEM_HAL_DBG_TRACE_RP=0 -DMODEM_HAL_DBG_TRACE_COLOR=0 -DTASK_EXTENDED_1 -DTASK_EXTENDED_2 -DLR11XX_DISABLE_WARNINGS -DMW_DBG_TRACE=1 -DMW_DBG_TRACE_COLOR=0 -DWM1110_TRACE_MAX_LENGTH=256 wio_tracker_1110.build.ldscript=nrf52840_s140_v6.ld wio_tracker_1110.build.vid=0x2886 wio_tracker_1110.build.pid=0x8055 @@ -172,3 +173,9 @@ wio_tracker_1110.menu.power_supply_grove.on=On wio_tracker_1110.menu.power_supply_grove.on.build.flags.power_supply_grove=-DPOWER_SUPPLY_GROVE=1 wio_tracker_1110.menu.power_supply_grove.off=Off wio_tracker_1110.menu.power_supply_grove.off.build.flags.power_supply_grove=-DPOWER_SUPPLY_GROVE=0 + +# Customize LoRaWAN modem +wio_tracker_1110.menu.lbm_custom.standard=No +wio_tracker_1110.menu.lbm_custom.standard.build.flags.lbm_custom=-DLBM_CUSTOM=0 +wio_tracker_1110.menu.lbm_custom.sensecap=SenseCAP +wio_tracker_1110.menu.lbm_custom.sensecap.build.flags.lbm_custom=-DLBM_CUSTOM=1 diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index 3e51f2449..2f02328b4 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit 3e51f244921d32304b7bb46558718e46deb34e55 +Subproject commit 2f02328b4277eb2e4758f785c51fcc5b886037f5 From c1d5d3f457864c5ecf89e5f872c4b1b6b50c4ccc Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Wed, 27 Sep 2023 19:54:20 +0800 Subject: [PATCH 32/34] 1.fix:Fixed an issue where packets could not be sent out due to the slow speed --- libraries/LBM_packet/src/internal/main_lora.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/LBM_packet/src/internal/main_lora.cpp b/libraries/LBM_packet/src/internal/main_lora.cpp index 6a35560f4..5423452fc 100644 --- a/libraries/LBM_packet/src/internal/main_lora.cpp +++ b/libraries/LBM_packet/src/internal/main_lora.cpp @@ -13,13 +13,18 @@ uint8_t stack_id = 0; uint8_t app_lora_port = LORAWAN_APP_PORT; -uint8_t adr_custom_list_eu868_default[16] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5 }; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 +// uint8_t adr_custom_list_eu868_default[16] = { 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5 }; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 uint8_t adr_custom_list_us915_default[16] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7 uint8_t adr_custom_list_au915_default[16] = { 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5 }; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7 uint8_t adr_custom_list_as923_default[16] = { 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5 }; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7 uint8_t adr_custom_list_kr920_default[16] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5 }; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 uint8_t adr_custom_list_in865_default[16] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5 }; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 -uint8_t adr_custom_list_ru864_default[16] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5 }; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 +// uint8_t adr_custom_list_ru864_default[16] = { 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5 }; // SF12,SF12,SF12,SF11,SF11,SF11,SF10,SF10,SF10,SF9,SF9,SF9,SF8,SF8,SF7,SF7 + + +uint8_t adr_custom_list_eu868_default[16] = { 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5 }; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7,SF7 +uint8_t adr_custom_list_ru864_default[16] = { 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5 }; // SF9,SF9,SF9,SF9,SF9,SF8,SF8,SF8,SF8,SF8,SF7,SF7,SF7,SF7,SF7,SF7 + uint8_t adr_custom_list_region[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; From 684a104d18667a04fa2d75182f80a102b85b707a Mon Sep 17 00:00:00 2001 From: SeeedWenzy Date: Thu, 28 Sep 2023 11:40:18 +0800 Subject: [PATCH 33/34] 1.add command for disconnect ble --- libraries/LBM_packet/src/app_param/at.cpp | 8 +++++++- libraries/LBM_packet/src/app_param/at.h | 8 ++++++++ libraries/LBM_packet/src/app_param/at_command.cpp | 9 ++++++++- libraries/LBM_packet/src/internal/get_full_almanac.py | 7 ------- libraries/LBM_packet/src/internal/main_ble.cpp | 5 +++++ libraries/LBM_packet/src/internal/main_ble.h | 6 +++++- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/libraries/LBM_packet/src/app_param/at.cpp b/libraries/LBM_packet/src/app_param/at.cpp index 5f66c3182..c4ace09e6 100644 --- a/libraries/LBM_packet/src/app_param/at.cpp +++ b/libraries/LBM_packet/src/app_param/at.cpp @@ -1004,7 +1004,13 @@ ATEerror_t AT_POS_DEL_run(const char *param) } /*------------------------AT+POS_DEL\r\n-------------------------------------*/ - +/*------------------------AT+DISCONNECT\r\n-------------------------------------*/ +ATEerror_t AT_Disconnect(const char *param) +{ + app_ble_disconnect(); + return AT_OK; +} +/*------------------------AT+DISCONNECT\r\n-------------------------------------*/ diff --git a/libraries/LBM_packet/src/app_param/at.h b/libraries/LBM_packet/src/app_param/at.h index 6e2029786..707ec43e5 100644 --- a/libraries/LBM_packet/src/app_param/at.h +++ b/libraries/LBM_packet/src/app_param/at.h @@ -66,6 +66,8 @@ extern void hal_ble_trace_print( const char* fmt, ... ); #define AT_MEA "+MEA" #define AT_POS_DEL "+POS_DEL" +#define AT_DISCONNECT "+DISCONNECT" + /* USER CODE BEGIN EM */ void hexTonum(unsigned char *out_data, unsigned char *in_data, unsigned short Size); void numTohex(unsigned char *out_data, unsigned char *in_data, unsigned short Size); @@ -392,6 +394,12 @@ ATEerror_t AT_MeasurementValue_get(const char *param); */ ATEerror_t AT_POS_DEL_run(const char *param); +/** + * @brief control ble disconnect + * @param param String parameter + * @retval AT_OK + */ +ATEerror_t AT_Disconnect(const char *param); #endif /* __AT_H__ */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/libraries/LBM_packet/src/app_param/at_command.cpp b/libraries/LBM_packet/src/app_param/at_command.cpp index 06f77834c..2f2f89f9b 100644 --- a/libraries/LBM_packet/src/app_param/at_command.cpp +++ b/libraries/LBM_packet/src/app_param/at_command.cpp @@ -208,7 +208,14 @@ static const struct ATCommand_s ATCommand[] = .get = AT_return_error, .set = AT_return_error, .run = AT_POS_DEL_run, - }, + }, + { + .string = AT_DISCONNECT, + .size_string = sizeof(AT_DISCONNECT) - 1, + .get = AT_return_error, + .set = AT_return_error, + .run = AT_Disconnect, + }, }; /** diff --git a/libraries/LBM_packet/src/internal/get_full_almanac.py b/libraries/LBM_packet/src/internal/get_full_almanac.py index 55a783a63..1b228beab 100644 --- a/libraries/LBM_packet/src/internal/get_full_almanac.py +++ b/libraries/LBM_packet/src/internal/get_full_almanac.py @@ -97,13 +97,6 @@ def main(): print("Almanac image written to " + filename + " file") - # output_path = 'test_acmanac.bin' # 输出文件的路径和文件名称,这里直接放在工程根目录下,所以没有写绝对路径 - - # # 待写入的数据 - - # with open(output_path, 'ab') as f: - # f.write(raw_bytes) - # f.close() diff --git a/libraries/LBM_packet/src/internal/main_ble.cpp b/libraries/LBM_packet/src/internal/main_ble.cpp index bad5fd638..8b4e92e9d 100644 --- a/libraries/LBM_packet/src/internal/main_ble.cpp +++ b/libraries/LBM_packet/src/internal/main_ble.cpp @@ -412,5 +412,10 @@ bool hal_ble_rec_data(void) } +void app_ble_disconnect( void ) +{ + bool ret = false; + ret = Bluefruit.disconnect(0);; +} diff --git a/libraries/LBM_packet/src/internal/main_ble.h b/libraries/LBM_packet/src/internal/main_ble.h index e7f069077..e217ff1be 100644 --- a/libraries/LBM_packet/src/internal/main_ble.h +++ b/libraries/LBM_packet/src/internal/main_ble.h @@ -146,5 +146,9 @@ void hal_ble_trace_print(const char *fmt, ...); */ bool hal_ble_rec_data(void) ; - +/** + * app_ble_disconnect() - disconnect ble + * + */ +void app_ble_disconnect( void ); #endif From b5b79b1db9aea5b210b197706a1e09fa5ccd4ea5 Mon Sep 17 00:00:00 2001 From: MATSUOKA Takashi Date: Thu, 28 Sep 2023 15:56:07 +0900 Subject: [PATCH 34/34] Update LBM_WM1110 --- libraries/LBM_WM1110 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/LBM_WM1110 b/libraries/LBM_WM1110 index 2f02328b4..dce2d0394 160000 --- a/libraries/LBM_WM1110 +++ b/libraries/LBM_WM1110 @@ -1 +1 @@ -Subproject commit 2f02328b4277eb2e4758f785c51fcc5b886037f5 +Subproject commit dce2d03946000e633fcb719b694dfff1a7c8580c