diff --git a/.github/actions/setup-base/action.yml b/.github/actions/setup-base/action.yml index 7f8659523b..61466655d1 100644 --- a/.github/actions/setup-base/action.yml +++ b/.github/actions/setup-base/action.yml @@ -11,7 +11,7 @@ runs: ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} - - name: Install dependencies + - name: Install dependencies shell: bash run: | sudo apt-get -y update --fix-missing @@ -22,19 +22,20 @@ runs: with: python-version: 3.x - - name: Cache python libs - uses: actions/cache@v4 - id: cache-pip # needed in if test - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip + # - name: Cache python libs + # uses: actions/cache@v4 + # id: cache-pip # needed in if test + # with: + # path: ~/.cache/pip + # key: ${{ runner.os }}-pip - name: Upgrade python tools shell: bash run: | python -m pip install --upgrade pip - pip install -U platformio adafruit-nrfutil - pip install -U meshtastic --pre + pip install -U --no-build-isolation --no-cache-dir "setuptools<72" + pip install -U platformio adafruit-nrfutil --no-build-isolation + pip install -U meshtastic --pre --no-build-isolation - name: Upgrade platformio shell: bash diff --git a/.github/workflows/build_stm32.yml b/.github/workflows/build_stm32.yml new file mode 100644 index 0000000000..d13c52c8a1 --- /dev/null +++ b/.github/workflows/build_stm32.yml @@ -0,0 +1,33 @@ +name: Build STM32 + +on: + workflow_call: + inputs: + board: + required: true + type: string + +jobs: + build-stm32: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build base + id: base + uses: ./.github/actions/setup-base + + - name: Build STM32 + run: bin/build-stm32.sh ${{ inputs.board }} + + - name: Get release version string + run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT + id: version + + - name: Store binaries as an artifact + uses: actions/upload-artifact@v4 + with: + name: firmware-${{ inputs.board }}-${{ steps.version.outputs.version }}.zip + overwrite: true + path: | + release/*.hex + release/*.bin diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 14c8a9d10c..36125f72f1 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -24,7 +24,7 @@ jobs: strategy: fail-fast: false matrix: - arch: [esp32, esp32s3, esp32c3, nrf52840, rp2040, check] + arch: [esp32, esp32s3, esp32c3, nrf52840, rp2040, stm32, check] runs-on: ubuntu-latest steps: - id: checkout @@ -41,6 +41,7 @@ jobs: esp32c3: ${{ steps.jsonStep.outputs.esp32c3 }} nrf52840: ${{ steps.jsonStep.outputs.nrf52840 }} rp2040: ${{ steps.jsonStep.outputs.rp2040 }} + stm32: ${{ steps.jsonStep.outputs.stm32 }} check: ${{ steps.jsonStep.outputs.check }} check: @@ -103,6 +104,15 @@ jobs: with: board: ${{ matrix.board }} + build-stm32: + needs: setup + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.setup.outputs.stm32) }} + uses: ./.github/workflows/build_stm32.yml + with: + board: ${{ matrix.board }} + package-raspbian: uses: ./.github/workflows/package_raspbian.yml @@ -134,6 +144,7 @@ jobs: build-esp32-c3, build-nrf52, build-rpi2040, + build-stm32, package-raspbian, package-raspbian-armv7l, package-native, diff --git a/arch/stm32/stm32.ini b/arch/stm32/stm32.ini new file mode 100644 index 0000000000..2cea4bbc58 --- /dev/null +++ b/arch/stm32/stm32.ini @@ -0,0 +1,36 @@ +[stm32_base] +extends = arduino_base +platform = ststm32 +platform_packages = platformio/framework-arduinoststm32@https://github.com/stm32duino/Arduino_Core_STM32.git#361a7fdb67e2a7104e99b4f42a802469eef8b129 + +build_type = release + +;board_build.flash_offset = 0x08000000 + +build_flags = + ${arduino_base.build_flags} + -flto + -Isrc/platform/stm32wl -g + -DMESHTASTIC_MINIMIZE_BUILD + -DDEBUG_MUTE +; -DVECT_TAB_OFFSET=0x08000000 + -DconfigUSE_CMSIS_RTOS_V2=1 +; -DSPI_MODE_0=SPI_MODE0 + -fmerge-all-constants + -ffunction-sections + -fdata-sections + +build_src_filter = + ${arduino_base.build_src_filter} - - - - - - - - - - - - - - + +board_upload.offset_address = 0x08000000 +upload_protocol = stlink + +lib_deps = + ${env.lib_deps} + charlesbaynham/OSFS@^1.2.3 + https://github.com/caveman99/Crypto.git#f61ae26a53f7a2d0ba5511625b8bf8eff3a35d5e + +lib_ignore = + mathertel/OneButton + Wire \ No newline at end of file diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini deleted file mode 100644 index 4d74ade8fb..0000000000 --- a/arch/stm32/stm32wl5e.ini +++ /dev/null @@ -1,28 +0,0 @@ -[stm32wl5e_base] -platform_packages = platformio/framework-arduinoststm32 @ https://github.com/stm32duino/Arduino_Core_STM32.git#6e3f9910d0122e82a6c3438507dfac3d2fd80a39 -platform = ststm32 -board = generic_wl5e -framework = arduino - -build_type = debug - -build_flags = - ${arduino_base.build_flags} - -Isrc/platform/stm32wl -g - -DconfigUSE_CMSIS_RTOS_V2=1 - -DVECT_TAB_OFFSET=0x08000000 - -build_src_filter = - ${arduino_base.build_src_filter} - - - - - - - - - - - - - - - -board_upload.offset_address = 0x08000000 -upload_protocol = stlink - -lib_deps = - ${env.lib_deps} - https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b - https://github.com/littlefs-project/littlefs.git#v2.5.1 - https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 - -lib_ignore = - mathertel/OneButton \ No newline at end of file diff --git a/bin/build-esp32.sh b/bin/build-esp32.sh index f60331ed52..adb6ab12ad 100755 --- a/bin/build-esp32.sh +++ b/bin/build-esp32.sh @@ -11,7 +11,7 @@ rm -f $OUTDIR/firmware* rm -r $OUTDIR/* || true # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio pkg update +platformio pkg update -e $1 echo "Building for $1 with $PLATFORMIO_BUILD_FLAGS" rm -f .pio/build/$1/firmware.* diff --git a/bin/build-nrf52.sh b/bin/build-nrf52.sh index c0658dad95..060d06cfda 100755 --- a/bin/build-nrf52.sh +++ b/bin/build-nrf52.sh @@ -11,7 +11,7 @@ rm -f $OUTDIR/firmware* rm -r $OUTDIR/* || true # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio pkg update +platformio pkg update -e $1 echo "Building for $1 with $PLATFORMIO_BUILD_FLAGS" rm -f .pio/build/$1/firmware.* diff --git a/bin/build-rpi2040.sh b/bin/build-rpi2040.sh index fe0725085a..dad6a7e67e 100755 --- a/bin/build-rpi2040.sh +++ b/bin/build-rpi2040.sh @@ -11,7 +11,7 @@ rm -f $OUTDIR/firmware* rm -r $OUTDIR/* || true # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio pkg update +platformio pkg update -e $1 echo "Building for $1 with $PLATFORMIO_BUILD_FLAGS" rm -f .pio/build/$1/firmware.* diff --git a/bin/build-stm32.sh b/bin/build-stm32.sh new file mode 100755 index 0000000000..76c5a75fb2 --- /dev/null +++ b/bin/build-stm32.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -e + +VERSION=$(bin/buildinfo.py long) +SHORT_VERSION=$(bin/buildinfo.py short) + +OUTDIR=release/ + +rm -f $OUTDIR/firmware* +rm -r $OUTDIR/* || true + +# Important to pull latest version of libs into all device flavors, otherwise some devices might be stale +platformio pkg update -e $1 + +echo "Building for $1 with $PLATFORMIO_BUILD_FLAGS" +rm -f .pio/build/$1/firmware.* + +# The shell vars the build tool expects to find +export APP_VERSION=$VERSION + +basename=firmware-$1-$VERSION + +pio run --environment $1 # -v +SRCELF=.pio/build/$1/firmware.elf +cp $SRCELF $OUTDIR/$basename.elf + +SRCBIN=.pio/build/$1/firmware.bin +cp $SRCBIN $OUTDIR/$basename.bin diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index e1320198a8..0517b1e6b0 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -54,6 +54,8 @@ Lora: # ch341_quirk: true # Uncomment this to use the chunked SPI transfer that seems to fix the ch341 +# spiSpeed: 2000000 + ### Set gpio chip to use in /dev/. Defaults to 0. ### Notably the Raspberry Pi 5 puts the GPIO header on gpiochip4 # gpiochip: 4 @@ -134,6 +136,9 @@ Display: # OffsetRotate: 1 # Invert: true +### You can also specify the spi device for the display to use +# spidev: spidev0.0 + Touchscreen: ### Note, at least for now, the touchscreen must have a CS pin defined, even if you let Linux manage the CS switching. @@ -149,15 +154,20 @@ Touchscreen: # CS: 7 # IRQ: 17 -### Configure device for direct keyboard input +### You can also specify the spi device for the touchscreen to use +# spidev: spidev0.0 + Input: +### Configure device for direct keyboard input + # KeyboardDevice: /dev/input/by-id/usb-_Raspberry_Pi_Internal_Keyboard-event-kbd ### Logging: LogLevel: info # debug, info, warn, error +# TraceFile: /var/log/meshtasticd.json Webserver: # Port: 443 # Port for Webserver & Webservices @@ -165,3 +175,4 @@ Webserver: General: MaxNodes: 200 + MaxMessageQueue: 100 \ No newline at end of file diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index 3202a1e7a9..065f1267b4 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -91,3 +91,12 @@ def esp32_create_combined_bin(source, target, env): "-DAPP_VERSION_SHORT=" + verObj["short"], ] ) + +# Add a custom p.io project task to run the UF2 conversion script. +env.AddCustomTarget( + name="Convert Hex to UF2", + dependencies=None, + actions=["PYTHON .\\bin\\uf2conv.py $BUILD_DIR\$env\\firmware.hex -c -f 0xADA52840 -o $BUILD_DIR\$env\\firmware.uf2"], + title="Convert hex to uf2", + description="Runs the python script to convert an already-built .hex file into .uf2 for copying to a device" +) diff --git a/boards/heltec_vision_master_e290.json b/boards/heltec_vision_master_e290.json new file mode 100644 index 0000000000..70f7d5f02f --- /dev/null +++ b/boards/heltec_vision_master_e290.json @@ -0,0 +1,42 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_8MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=0", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + ["0x303A", "0x1001"], + ["0x303A", "0x0002"] + ], + "mcu": "esp32s3", + "variant": "heltec_vision_master_e290" + }, + "connectivity": ["wifi", "bluetooth", "lora"], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": ["arduino", "espidf"], + "name": "Heltec Vision Master E290", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://heltec.org/project/vision-master-e290/", + "vendor": "Heltec" +} diff --git a/boards/generic_wl5e.json b/boards/wiscore_rak3172.json similarity index 91% rename from boards/generic_wl5e.json rename to boards/wiscore_rak3172.json index 5c4bc24a75..714e09115e 100644 --- a/boards/generic_wl5e.json +++ b/boards/wiscore_rak3172.json @@ -1,5 +1,8 @@ { "build": { + "arduino": { + "variant_h": "variant_RAK3172_MODULE.h" + }, "core": "stm32", "cpu": "cortex-m4", "extra_flags": "-DSTM32WLxx -DSTM32WLE5xx -DARDUINO_GENERIC_WLE5CCUX", diff --git a/protobufs b/protobufs index 7f90178f18..976748839f 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 7f90178f183820e288aec41133144f30723228fe +Subproject commit 976748839fafcf0049bb364fe2c7226a194d18a9 diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index 914ff8e06a..1b101044fd 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -144,8 +144,8 @@ int32_t ButtonThread::runOnce() case BUTTON_EVENT_DOUBLE_PRESSED: { LOG_BUTTON("Double press!\n"); - service.refreshLocalMeshNode(); - auto sentPosition = service.trySendPosition(NODENUM_BROADCAST, true); + service->refreshLocalMeshNode(); + auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true); if (screen) { if (sentPosition) screen->print("Sent ad-hoc position\n"); diff --git a/src/ButtonThread.h b/src/ButtonThread.h index d7a9201a34..9cd7b3dac3 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -13,7 +13,7 @@ #endif #ifndef BUTTON_TOUCH_MS -#define BUTTON_TOCH_MS 400 +#define BUTTON_TOUCH_MS 400 #endif class ButtonThread : public concurrency::OSThread diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index 7d3788c4d9..3017ec085c 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -24,6 +24,30 @@ SPIClass SPI1(HSPI); #endif // HAS_SDCARD +#if defined(ARCH_STM32WL) + +uint16_t OSFS::startOfEEPROM = 1; +uint16_t OSFS::endOfEEPROM = 2048; + +// 3) How do I read from the medium? +void OSFS::readNBytes(uint16_t address, unsigned int num, byte *output) +{ + for (uint16_t i = address; i < address + num; i++) { + *output = EEPROM.read(i); + output++; + } +} + +// 4) How to I write to the medium? +void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte *input) +{ + for (uint16_t i = address; i < address + num; i++) { + EEPROM.update(i, *input); + input++; + } +} +#endif + /** * @brief Copies a file from one location to another. * @@ -33,7 +57,33 @@ SPIClass SPI1(HSPI); */ bool copyFile(const char *from, const char *to) { -#ifdef FSCom +#ifdef ARCH_STM32WL + unsigned char cbuffer[2048]; + + // Var to hold the result of actions + OSFS::result r; + + r = OSFS::getFile(from, cbuffer); + + if (r == notfound) { + LOG_ERROR("Failed to open source file %s\n", from); + return false; + } else if (r == noerr) { + r = OSFS::newFile(to, cbuffer, true); + if (r == noerr) { + return true; + } else { + LOG_ERROR("OSFS Error %d\n", r); + return false; + } + + } else { + LOG_ERROR("OSFS Error %d\n", r); + return false; + } + return true; + +#elif defined(FSCom) unsigned char cbuffer[16]; File f1 = FSCom.open(from, FILE_O_READ); @@ -70,7 +120,13 @@ bool copyFile(const char *from, const char *to) */ bool renameFile(const char *pathFrom, const char *pathTo) { -#ifdef FSCom +#ifdef ARCH_STM32WL + if (copyFile(pathFrom, pathTo) && (OSFS::deleteFile(pathFrom) == OSFS::result::NO_ERROR)) { + return true; + } else { + return false; + } +#elif defined(FSCom) #ifdef ARCH_ESP32 // rename was fixed for ESP32 IDF LittleFS in April return FSCom.rename(pathFrom, pathTo); diff --git a/src/FSCommon.h b/src/FSCommon.h index 8fbabd9526..3d485d1b1d 100644 --- a/src/FSCommon.h +++ b/src/FSCommon.h @@ -15,10 +15,13 @@ #endif #if defined(ARCH_STM32WL) -#include "platform/stm32wl/InternalFileSystem.h" // STM32WL version -#define FSCom InternalFS -#define FSBegin() FSCom.begin() -using namespace LittleFS_Namespace; +// STM32WL series 2 Kbytes (8 rows of 256 bytes) +#include +#include + +// Useful consts +const OSFS::result noerr = OSFS::result::NO_ERROR; +const OSFS::result notfound = OSFS::result::FILE_NOT_FOUND; #endif #if defined(ARCH_RP2040) diff --git a/src/OSTimer.cpp b/src/OSTimer.cpp deleted file mode 100644 index f6739d75e0..0000000000 --- a/src/OSTimer.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "OSTimer.h" -#include "configuration.h" - -/** - * Schedule a callback to run. The callback must _not_ block, though it is called from regular thread level (not ISR) - * - * NOTE! xTimerPend... seems to ignore the time passed in on ESP32 and on NRF52 - * The reason this didn't work is because xTimerPednFunctCall really isn't a timer function at all - it just means run the -callback - * from the timer thread the next time you have spare cycles. - * - * @return true if successful, false if the timer fifo is too full. - -bool scheduleOSCallback(PendableFunction callback, void *param1, uint32_t param2, uint32_t delayMsec) -{ - return xTimerPendFunctionCall(callback, param1, param2, pdMS_TO_TICKS(delayMsec)); -} */ - -#ifdef ARCH_ESP32 - -// Super skanky quick hack to use hardware timers of the ESP32 -static hw_timer_t *timer; -static PendableFunction tCallback; -static void *tParam1; -static uint32_t tParam2; - -static void IRAM_ATTR onTimer() -{ - (*tCallback)(tParam1, tParam2); -} - -/** - * Schedules a hardware callback function to be executed after a specified delay. - * - * @param callback The function to be executed. - * @param param1 The first parameter to be passed to the function. - * @param param2 The second parameter to be passed to the function. - * @param delayMsec The delay time in milliseconds before the function is executed. - * - * @return True if the function was successfully scheduled, false otherwise. - */ -bool scheduleHWCallback(PendableFunction callback, void *param1, uint32_t param2, uint32_t delayMsec) -{ - if (!timer) { - timer = timerBegin(0, 80, true); // one usec per tick (main clock is 80MhZ on ESP32) - assert(timer); - timerAttachInterrupt(timer, &onTimer, true); - } - - tCallback = callback; - tParam1 = param1; - tParam2 = param2; - - timerAlarmWrite(timer, delayMsec * 1000UL, false); // Do not reload, we want it to be a single shot timer - timerRestart(timer); - timerAlarmEnable(timer); - return true; -} - -#endif \ No newline at end of file diff --git a/src/OSTimer.h b/src/OSTimer.h deleted file mode 100644 index 37415f3a6e..0000000000 --- a/src/OSTimer.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -typedef void (*PendableFunction)(void *pvParameter1, uint32_t ulParameter2); - -/// Uses a hardware timer, but calls the handler in _interrupt_ context -bool scheduleHWCallback(PendableFunction callback, void *param1, uint32_t param2, uint32_t delayMsec); \ No newline at end of file diff --git a/src/Power.cpp b/src/Power.cpp index 19c5c99375..138b06e719 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -200,7 +200,8 @@ class AnalogBatteryLevel : public HasBatteryLevel } #endif -#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) && !defined(HAS_PMU) && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR +#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !defined(HAS_PMU) && \ + !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR if (hasINA()) { LOG_DEBUG("Using INA on I2C addr 0x%x for device battery voltage\n", config.power.device_battery_ina_address); return getINAVoltage(); @@ -420,7 +421,7 @@ class AnalogBatteryLevel : public HasBatteryLevel } #endif -#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO) +#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) uint16_t getINAVoltage() { if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) { diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 9c3dcdc987..05d349de92 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -49,7 +49,11 @@ size_t RedirectablePrint::write(uint8_t c) size_t RedirectablePrint::vprintf(const char *logLevel, const char *format, va_list arg) { va_list copy; +#if ENABLE_JSON_LOGGING || ARCH_PORTDUINO + static char printBuf[512]; +#else static char printBuf[160]; +#endif va_copy(copy, arg); size_t len = vsnprintf(printBuf, sizeof(printBuf), format, copy); @@ -98,6 +102,8 @@ void RedirectablePrint::log_to_serial(const char *logLevel, const char *format, Print::write("\u001b[33m", 6); if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_ERROR) == 0) Print::write("\u001b[31m", 6); + if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_TRACE) == 0) + Print::write("\u001b[35m", 6); uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice, true); // display local time on logfile if (rtc_sec > 0) { long hms = rtc_sec % SEC_PER_DAY; @@ -244,7 +250,21 @@ meshtastic_LogRecord_Level RedirectablePrint::getLogLevel(const char *logLevel) void RedirectablePrint::log(const char *logLevel, const char *format, ...) { -#ifdef ARCH_PORTDUINO +#if ARCH_PORTDUINO + // level trace is special, two possible ways to handle it. + if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_TRACE) == 0) { + if (settingsStrings[traceFilename] != "") { + va_list arg; + va_start(arg, format); + try { + traceFile << va_arg(arg, char *) << std::endl; + } catch (const std::ios_base::failure &e) { + } + va_end(arg); + } + if (settingsMap[logoutputlevel] < level_trace && strcmp(logLevel, MESHTASTIC_LOG_LEVEL_TRACE) == 0) + return; + } if (settingsMap[logoutputlevel] < level_debug && strcmp(logLevel, MESHTASTIC_LOG_LEVEL_DEBUG) == 0) return; else if (settingsMap[logoutputlevel] < level_info && strcmp(logLevel, MESHTASTIC_LOG_LEVEL_INFO) == 0) diff --git a/src/SerialConsole.cpp b/src/SerialConsole.cpp index 9a9331e473..d25b81da7b 100644 --- a/src/SerialConsole.cpp +++ b/src/SerialConsole.cpp @@ -96,7 +96,7 @@ bool SerialConsole::handleToRadio(const uint8_t *buf, size_t len) void SerialConsole::log_to_serial(const char *logLevel, const char *format, va_list arg) { - if (usingProtobufs) { + if (usingProtobufs && config.device.debug_log_enabled) { meshtastic_LogRecord_Level ll = meshtastic_LogRecord_Level_UNSET; // default to unset switch (logLevel[0]) { case 'D': @@ -120,4 +120,4 @@ void SerialConsole::log_to_serial(const char *logLevel, const char *format, va_l emitLogRecord(ll, thread ? thread->ThreadName.c_str() : "", format, arg); } else RedirectablePrint::log_to_serial(logLevel, format, arg); -} \ No newline at end of file +} diff --git a/src/StatusHandler.h b/src/StatusHandler.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/configuration.h b/src/configuration.h index f069669536..4c5b3bc601 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -52,10 +52,6 @@ along with this program. If not, see . // Configuration // ----------------------------------------------------------------------------- -// If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled) -// we don't support jtag on the ttgo - access to gpio 12 is a PITA -#define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found - /// Convert a preprocessor name into a quoted string #define xstr(s) ystr(s) #define ystr(s) #s @@ -262,6 +258,7 @@ along with this program. If not, see . #define MESHTASTIC_EXCLUDE_SCREEN 1 #define MESHTASTIC_EXCLUDE_MQTT 1 #define MESHTASTIC_EXCLUDE_POWERMON 1 +#define MESHTASTIC_EXCLUDE_I2C 1 #endif // Turn off all optional modules diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 6b6d485b0a..d2892b7d42 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -1,7 +1,8 @@ #include "ScanI2CTwoWire.h" +#if !MESHTASTIC_EXCLUDE_I2C + #include "concurrency/LockGuard.h" -#include "configuration.h" #if defined(ARCH_PORTDUINO) #include "linux/LinuxHardwareI2C.h" #endif @@ -403,3 +404,4 @@ size_t ScanI2CTwoWire::countDevices() const { return foundDevices.size(); } +#endif \ No newline at end of file diff --git a/src/detect/ScanI2CTwoWire.h b/src/detect/ScanI2CTwoWire.h index 82b48f6b47..c8dd96469a 100644 --- a/src/detect/ScanI2CTwoWire.h +++ b/src/detect/ScanI2CTwoWire.h @@ -1,5 +1,8 @@ #pragma once +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_I2C + #include #include #include @@ -55,4 +58,5 @@ class ScanI2CTwoWire : public ScanI2C uint16_t getRegisterValue(const RegisterLocation &, ResponseWidth) const; DeviceType probeOLED(ScanI2C::DeviceAddress) const; -}; \ No newline at end of file +}; +#endif \ No newline at end of file diff --git a/src/freertosinc.h b/src/freertosinc.h index 166054241c..e9e6cd53a0 100644 --- a/src/freertosinc.h +++ b/src/freertosinc.h @@ -12,7 +12,7 @@ #include #endif -#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_RP2040) +#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_RP2040) #define HAS_FREE_RTOS #include diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index c50bc7b410..d6ea2cb08a 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -400,12 +400,6 @@ bool GPS::setup() int msglen = 0; if (!didSerialInit) { -#ifdef GNSS_AIROHA - if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { - probe(GPS_BAUDRATE); - LOG_INFO("GPS setting to %d.\n", GPS_BAUDRATE); - } -#else #if !defined(GPS_UC6580) if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { @@ -784,7 +778,6 @@ bool GPS::setup() LOG_INFO("GNSS module configuration saved!\n"); } } -#endif didSerialInit = true; } @@ -1182,7 +1175,7 @@ int GPS::prepareDeepSleep(void *unused) GnssModel_t GPS::probe(int serialSpeed) { -#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) +#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) || defined(ARCH_STM32WL) _serial_gps->end(); _serial_gps->begin(serialSpeed); #else @@ -1191,10 +1184,6 @@ GnssModel_t GPS::probe(int serialSpeed) _serial_gps->updateBaudRate(serialSpeed); } #endif -#ifdef GNSS_AIROHA - - return GNSS_MODEL_UNKNOWN; -#else #ifdef GPS_DEBUG for (int i = 0; i < 20; i++) { getACK("$GP", 200); @@ -1217,7 +1206,7 @@ GnssModel_t GPS::probe(int serialSpeed) return GNSS_MODEL_UC6580; } - // Get version information + // Get version information for ATGM336H clearBuffer(); _serial_gps->write("$PCAS06,1*1A\r\n"); if (getACK("$GPTXT,01,01,02,HW=ATGM336H", 500) == GNSS_RESPONSE_OK) { @@ -1225,6 +1214,15 @@ GnssModel_t GPS::probe(int serialSpeed) return GNSS_MODEL_ATGM336H; } + /* ATGM332D series (-11(GPS), -21(BDS), -31(GPS+BDS), -51(GPS+GLONASS), -71-0(GPS+BDS+GLONASS)) + based on AT6558 */ + clearBuffer(); + _serial_gps->write("$PCAS06,1*1A\r\n"); + if (getACK("$GPTXT,01,01,02,HW=ATGM332D", 500) == GNSS_RESPONSE_OK) { + LOG_INFO("ATGM332D detected, using ATGM336H Module\n"); + return GNSS_MODEL_ATGM336H; + } + // Get version information clearBuffer(); _serial_gps->write("$PCAS06,0*1B\r\n"); @@ -1270,7 +1268,7 @@ GnssModel_t GPS::probe(int serialSpeed) _serial_gps->write(_message_prt, sizeof(_message_prt)); delay(500); serialSpeed = 9600; -#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) +#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) || defined(ARCH_STM32WL) _serial_gps->end(); _serial_gps->begin(serialSpeed); #else @@ -1350,7 +1348,6 @@ GnssModel_t GPS::probe(int serialSpeed) } return GNSS_MODEL_UBLOX; -#endif // !GNSS_Airoha } GPS *GPS::createGps() @@ -1800,4 +1797,4 @@ void GPS::toggleGpsMode() enable(); } } -#endif // Exclude GPS +#endif // Exclude GPS \ No newline at end of file diff --git a/src/gps/GeoCoord.cpp b/src/gps/GeoCoord.cpp index 2224bd2816..5abb25a06c 100644 --- a/src/gps/GeoCoord.cpp +++ b/src/gps/GeoCoord.cpp @@ -493,7 +493,7 @@ std::shared_ptr GeoCoord::pointAtDistance(double bearing, double range * The bearing in string format * @return Bearing in degrees */ -uint GeoCoord::bearingToDegrees(const char *bearing) +unsigned int GeoCoord::bearingToDegrees(const char *bearing) { if (strcmp(bearing, "N") == 0) return 0; @@ -537,7 +537,7 @@ uint GeoCoord::bearingToDegrees(const char *bearing) * The bearing in degrees * @return Bearing in string format */ -const char *GeoCoord::degreesToBearing(uint degrees) +const char *GeoCoord::degreesToBearing(unsigned int degrees) { if (degrees >= 348 || degrees < 11) return "N"; diff --git a/src/gps/GeoCoord.h b/src/gps/GeoCoord.h index b02d12afb8..ecdaf0ec7b 100644 --- a/src/gps/GeoCoord.h +++ b/src/gps/GeoCoord.h @@ -117,8 +117,8 @@ class GeoCoord static float bearing(double lat1, double lon1, double lat2, double lon2); static float rangeRadiansToMeters(double range_radians); static float rangeMetersToRadians(double range_meters); - static uint bearingToDegrees(const char *bearing); - static const char *degreesToBearing(uint degrees); + static unsigned int bearingToDegrees(const char *bearing); + static const char *degreesToBearing(unsigned int degrees); // Point to point conversions int32_t distanceTo(const GeoCoord &pointB); diff --git a/src/gps/RTC.h b/src/gps/RTC.h index 4b065b3760..d31e85433c 100644 --- a/src/gps/RTC.h +++ b/src/gps/RTC.h @@ -43,4 +43,4 @@ time_t gm_mktime(struct tm *tm); #define SEC_PER_DAY 86400 #define SEC_PER_HOUR 3600 -#define SEC_PER_MIN 60 \ No newline at end of file +#define SEC_PER_MIN 60 diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 83704ce517..703839bd52 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -20,6 +20,7 @@ along with this program. If not, see . */ #include "Screen.h" +#include "../userPrefs.h" #include "configuration.h" #if HAS_SCREEN #include @@ -156,7 +157,11 @@ static void drawIconScreen(const char *upperMsg, OLEDDisplay *display, OLEDDispl display->setFont(FONT_MEDIUM); display->setTextAlignment(TEXT_ALIGN_LEFT); +#ifdef SPLASH_TITLE_USERPREFS + const char *title = SPLASH_TITLE_USERPREFS; +#else const char *title = "meshtastic.org"; +#endif display->drawString(x + getStringCenteredX(title), y + SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM, title); display->setFont(FONT_SMALL); @@ -1897,6 +1902,13 @@ int32_t Screen::runOnce() // standard screen loop handling here if (config.display.auto_screen_carousel_secs > 0 && (millis() - lastScreenTransition) > (config.display.auto_screen_carousel_secs * 1000)) { + +// If an E-Ink display struggles with fast refresh, force carousel to use full refresh instead +// Carousel is potentially a major source of E-Ink display wear +#if !defined(EINK_BACKGROUND_USES_FAST) + EINK_ADD_FRAMEFLAG(dispdev, COSMETIC); +#endif + LOG_DEBUG("LastScreenTransition exceeded %ums transitioning to next frame\n", (millis() - lastScreenTransition)); handleOnPress(); } diff --git a/src/graphics/img/icon.xbm b/src/graphics/img/icon.xbm index 297f31ed6f..f90cf4946f 100644 --- a/src/graphics/img/icon.xbm +++ b/src/graphics/img/icon.xbm @@ -1,3 +1,4 @@ +#ifndef HAS_USERPREFS_SPLASH #define icon_width 50 #define icon_height 28 static uint8_t icon_bits[] = { @@ -17,4 +18,5 @@ static uint8_t icon_bits[] = { 0xFE, 0x00, 0x00, 0xFC, 0x01, 0x7E, 0x00, 0x7F, 0x00, 0x00, 0xF8, 0x01, 0x7E, 0x00, 0x3E, 0x00, 0x00, 0xF8, 0x01, 0x38, 0x00, 0x3C, 0x00, 0x00, 0x70, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, }; \ No newline at end of file + 0x00, 0x00, 0x00, 0x00, }; +#endif \ No newline at end of file diff --git a/src/input/SerialKeyboard.cpp b/src/input/SerialKeyboard.cpp new file mode 100644 index 0000000000..fa3eb2528a --- /dev/null +++ b/src/input/SerialKeyboard.cpp @@ -0,0 +1,170 @@ +#include "SerialKeyboard.h" +#include "configuration.h" + +#ifdef INPUTBROKER_SERIAL_TYPE +#define CANNED_MESSAGE_MODULE_ENABLE 1 // in case it's not set in the variant file + +#if INPUTBROKER_SERIAL_TYPE == 1 // It's a Chatter +// 3 SHIFT level (lower case, upper case, numbers), up to 4 repeated presses, button number +unsigned char KeyMap[3][4][10] = {{{'.', 'a', 'd', 'g', 'j', 'm', 'p', 't', 'w', ' '}, + {',', 'b', 'e', 'h', 'k', 'n', 'q', 'u', 'x', ' '}, + {'?', 'c', 'f', 'i', 'l', 'o', 'r', 'v', 'y', ' '}, + {'1', '2', '3', '4', '5', '6', 's', '8', 'z', ' '}}, // low case + {{'!', 'A', 'D', 'G', 'J', 'M', 'P', 'T', 'W', ' '}, + {'+', 'B', 'E', 'H', 'K', 'N', 'Q', 'U', 'X', ' '}, + {'-', 'C', 'F', 'I', 'L', 'O', 'R', 'V', 'Y', ' '}, + {'1', '2', '3', '4', '5', '6', 'S', '8', 'Z', ' '}}, // upper case + {{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}, + {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}, + {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}, + {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}}}; // numbers + +#endif + +SerialKeyboard::SerialKeyboard(const char *name) : concurrency::OSThread(name) +{ + this->_originName = name; +} + +void SerialKeyboard::erase() +{ + InputEvent e; + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK; + e.kbchar = 0x08; + e.source = this->_originName; + this->notifyObservers(&e); +} + +int32_t SerialKeyboard::runOnce() +{ + if (!INPUTBROKER_SERIAL_TYPE) { + // Input device is not requested. + return disable(); + } + + if (firstTime) { + // This is the first time the OSThread library has called this function, so do port setup + firstTime = 0; + pinMode(KB_LOAD, OUTPUT); + pinMode(KB_CLK, OUTPUT); + pinMode(KB_DATA, INPUT); + digitalWrite(KB_LOAD, HIGH); + digitalWrite(KB_CLK, LOW); + prevKeys = 0b1111111111111111; + LOG_DEBUG("Serial Keyboard setup\n"); + } + + if (INPUTBROKER_SERIAL_TYPE == 1) { // Chatter V1.0 & V2.0 keypads + // scan for keypresses + // Write pulse to load pin + digitalWrite(KB_LOAD, LOW); + delayMicroseconds(5); + digitalWrite(KB_LOAD, HIGH); + delayMicroseconds(5); + + // Get data from 74HC165 + byte shiftRegister1 = shiftIn(KB_DATA, KB_CLK, LSBFIRST); + byte shiftRegister2 = shiftIn(KB_DATA, KB_CLK, LSBFIRST); + + keys = (shiftRegister1 << 8) + shiftRegister2; + + // Print to serial monitor + // Serial.print (shiftRegister1, BIN); + // Serial.print ("X"); + // Serial.println (shiftRegister2, BIN); + + if (millis() - lastPressTime > 500) { + quickPress = 0; + } + + if (keys < prevKeys) { // a new key has been pressed (and not released), doesn't works for multiple presses at once but + // shouldn't be a limitation + InputEvent e; + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + e.source = this->_originName; + // SELECT OR SEND OR CANCEL EVENT + if (!(shiftRegister2 & (1 << 3))) { + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP; + } else if (!(shiftRegister2 & (1 << 2))) { + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT; + e.kbchar = 0xb7; + } else if (!(shiftRegister2 & (1 << 1))) { + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT; + } else if (!(shiftRegister2 & (1 << 0))) { + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL; + } + + // TEXT INPUT EVENT + else if (!(shiftRegister1 & (1 << 4))) { + keyPressed = 0; + } else if (!(shiftRegister1 & (1 << 3))) { + keyPressed = 1; + } else if (!(shiftRegister2 & (1 << 4))) { + keyPressed = 2; + } else if (!(shiftRegister1 & (1 << 5))) { + keyPressed = 3; + } else if (!(shiftRegister1 & (1 << 2))) { + keyPressed = 4; + } else if (!(shiftRegister2 & (1 << 5))) { + keyPressed = 5; + } else if (!(shiftRegister1 & (1 << 6))) { + keyPressed = 6; + } else if (!(shiftRegister1 & (1 << 1))) { + keyPressed = 7; + } else if (!(shiftRegister2 & (1 << 6))) { + keyPressed = 8; + } else if (!(shiftRegister1 & (1 << 0))) { + keyPressed = 9; + } + // BACKSPACE or TAB + else if (!(shiftRegister1 & (1 << 7))) { + if (shift == 0 || shift == 2) { // BACKSPACE + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK; + e.kbchar = 0x08; + } else { // shift = 1 => TAB + e.inputEvent = ANYKEY; + e.kbchar = 0x09; + } + } + // SHIFT + else if (!(shiftRegister2 & (1 << 7))) { + keyPressed = 10; + } + + if (keyPressed < 11) { + if (keyPressed == lastKeyPressed && millis() - lastPressTime < 500) { + quickPress += 1; + if (quickPress > 3) { + quickPress = 0; + } + } + if (keyPressed != lastKeyPressed) { + quickPress = 0; + } + if (keyPressed < 10) { // if it's a letter + if (keyPressed == lastKeyPressed && millis() - lastPressTime < 500) { + erase(); + } + e.inputEvent = ANYKEY; + e.kbchar = char(KeyMap[shift][quickPress][keyPressed]); + } else { // then it's shift + shift += 1; + if (shift > 2) { + shift = 0; + } + } + lastPressTime = millis(); + lastKeyPressed = keyPressed; + keyPressed = 13; + } + + if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { + this->notifyObservers(&e); + } + } + prevKeys = keys; + } + return 50; +} + +#endif // INPUTBROKER_SERIAL_TYPE \ No newline at end of file diff --git a/src/input/SerialKeyboard.h b/src/input/SerialKeyboard.h new file mode 100644 index 0000000000..1480c4d583 --- /dev/null +++ b/src/input/SerialKeyboard.h @@ -0,0 +1,25 @@ +#pragma once + +#include "InputBroker.h" +#include "concurrency/OSThread.h" + +class SerialKeyboard : public Observable, public concurrency::OSThread +{ + public: + explicit SerialKeyboard(const char *name); + + protected: + virtual int32_t runOnce() override; + void erase(); + + private: + const char *_originName; + bool firstTime = 1; + int prevKeys = 0; + int keys = 0; + int shift = 0; + int keyPressed = 13; + int lastKeyPressed = 13; + int quickPress = 0; + unsigned long lastPressTime = 0; +}; \ No newline at end of file diff --git a/src/input/SerialKeyboardImpl.cpp b/src/input/SerialKeyboardImpl.cpp new file mode 100644 index 0000000000..249b76fe3c --- /dev/null +++ b/src/input/SerialKeyboardImpl.cpp @@ -0,0 +1,21 @@ +#include "SerialKeyboardImpl.h" +#include "InputBroker.h" +#include "configuration.h" + +#ifdef INPUTBROKER_SERIAL_TYPE + +SerialKeyboardImpl *aSerialKeyboardImpl; + +SerialKeyboardImpl::SerialKeyboardImpl() : SerialKeyboard("serialKB") {} + +void SerialKeyboardImpl::init() +{ + if (!INPUTBROKER_SERIAL_TYPE) { + disable(); + return; + } + + inputBroker->registerSource(this); +} + +#endif // INPUTBROKER_SERIAL_TYPE \ No newline at end of file diff --git a/src/input/SerialKeyboardImpl.h b/src/input/SerialKeyboardImpl.h new file mode 100644 index 0000000000..7f62aa420c --- /dev/null +++ b/src/input/SerialKeyboardImpl.h @@ -0,0 +1,19 @@ +#pragma once +#include "SerialKeyboard.h" +#include "main.h" + +/** + * @brief The idea behind this class to have static methods for the event handlers. + * Check attachInterrupt() at RotaryEncoderInteruptBase.cpp + * Technically you can have as many rotary encoders hardver attached + * to your device as you wish, but you always need to have separate event + * handlers, thus you need to have a RotaryEncoderInterrupt implementation. + */ +class SerialKeyboardImpl : public SerialKeyboard +{ + public: + SerialKeyboardImpl(); + void init(); +}; + +extern SerialKeyboardImpl *aSerialKeyboardImpl; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 81c842b993..b1256664fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,11 @@ #include "concurrency/OSThread.h" #include "concurrency/Periodic.h" #include "detect/ScanI2C.h" + +#if !MESHTASTIC_EXCLUDE_I2C #include "detect/ScanI2CTwoWire.h" +#include +#endif #include "detect/axpDebug.h" #include "detect/einkScan.h" #include "graphics/RAKled.h" @@ -31,7 +35,6 @@ #include "shutdown.h" #include "sleep.h" #include "target_specific.h" -#include #include #include // #include @@ -172,8 +175,10 @@ bool pauseBluetoothLogging = false; bool pmu_found; +#if !MESHTASTIC_EXCLUDE_I2C // Array map of sensor types with i2c address and wire as we'll find in the i2c scan std::pair nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1] = {}; +#endif Router *router = NULL; // Users of router don't care what sort of subclass implements that API @@ -218,7 +223,6 @@ uint32_t timeLastPowered = 0; static Periodic *ledPeriodic; static OSThread *powerFSMthread; static OSThread *ambientLightingThread; -SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0); RadioInterface *rIf = NULL; @@ -241,6 +245,12 @@ void printInfo() void setup() { concurrency::hasBeenSetup = true; +#if ARCH_PORTDUINO + SPISettings spiSettings(settingsMap[spiSpeed], MSBFIRST, SPI_MODE0); +#else + SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0); +#endif + meshtastic_Config_DisplayConfig_OledType screen_model = meshtastic_Config_DisplayConfig_OledType::meshtastic_Config_DisplayConfig_OledType_OLED_AUTO; OLEDDISPLAY_GEOMETRY screen_geometry = GEOMETRY_128_64; @@ -369,6 +379,7 @@ void setup() #endif +#if !MESHTASTIC_EXCLUDE_I2C #if defined(I2C_SDA1) && defined(ARCH_RP2040) Wire1.setSDA(I2C_SDA1); Wire1.setSCL(I2C_SCL1); @@ -393,6 +404,7 @@ void setup() #elif HAS_WIRE Wire.begin(); #endif +#endif #ifdef PIN_LCD_RESET // FIXME - move this someplace better, LCD is at address 0x3F @@ -425,6 +437,7 @@ void setup() powerStatus->observe(&power->newStatus); power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration +#if !MESHTASTIC_EXCLUDE_I2C // We need to scan here to decide if we have a screen for nodeDB.init() and because power has been applied to // accessories auto i2cScanner = std::unique_ptr(new ScanI2CTwoWire()); @@ -579,6 +592,7 @@ void setup() SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::DFROBOT_LARK, meshtastic_TelemetrySensorType_DFROBOT_LARK) i2cScanner.reset(); +#endif #ifdef HAS_SDCARD setupSDCard(); @@ -639,6 +653,7 @@ void setup() screen_model = meshtastic_Config_DisplayConfig_OledType_OLED_SH1107; // keep dimension of 128x64 #endif +#if !MESHTASTIC_EXCLUDE_I2C #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR if (acc_info.type != ScanI2C::DeviceType::NONE) { config.display.wake_on_tap_or_motion = true; @@ -654,6 +669,7 @@ void setup() ambientLightingThread = new AmbientLightingThread(rgb_found.type); } #endif +#endif #ifdef T_WATCH_S3 drv.begin(); @@ -804,8 +820,8 @@ void setup() LOG_DEBUG("Starting audio thread\n"); audioThread = new AudioThread(); #endif - - service.init(); + service = new MeshService(); + service->init(); // Now that the mesh service is created, create any modules setupModules(); @@ -822,6 +838,7 @@ void setup() RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_NO_AXP192); // Record a hardware fault for missing hardware #endif +#if !MESHTASTIC_EXCLUDE_I2C // Don't call screen setup until after nodedb is setup (because we need // the current region name) #if defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7789_CS) || defined(HX8357_CS) || \ @@ -834,6 +851,7 @@ void setup() #else if (screen_found.port != ScanI2C::I2CPort::NO_I2C) screen->setup(); +#endif #endif screen->print("Started...\n"); @@ -1061,9 +1079,16 @@ void setup() mqttInit(); #endif +#ifdef RF95_FAN_EN + // Ability to disable FAN if PIN has been set with RF95_FAN_EN. + // Make sure LoRa has been started before disabling FAN. + if (config.lora.pa_fan_disabled) + digitalWrite(RF95_FAN_EN, LOW ^ 0); +#endif + #ifndef ARCH_PORTDUINO - // Initialize Wifi + // Initialize Wifi #if HAS_WIFI initWifi(); #endif @@ -1173,7 +1198,7 @@ void loop() // TODO: This should go into a thread handled by FreeRTOS. // handleWebResponse(); - service.loop(); + service->loop(); long delayMsec = mainController.runOrDelay(); diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index bb4d629e7b..8d5b4353b5 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -1,5 +1,7 @@ #include "Channels.h" +#include "../userPrefs.h" #include "CryptoEngine.h" +#include "Default.h" #include "DisplayFormatters.h" #include "NodeDB.h" #include "RadioInterface.h" @@ -90,6 +92,7 @@ void Channels::initDefaultChannel(ChannelIndex chIndex) loraConfig.modem_preset = meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST; // Default to Long Range & Fast loraConfig.use_preset = true; loraConfig.tx_power = 0; // default + loraConfig.channel_num = 0; uint8_t defaultpskIndex = 1; channelSettings.psk.bytes[0] = defaultpskIndex; channelSettings.psk.size = 1; @@ -99,6 +102,29 @@ void Channels::initDefaultChannel(ChannelIndex chIndex) ch.has_settings = true; ch.role = meshtastic_Channel_Role_PRIMARY; + +#ifdef LORACONFIG_MODEM_PRESET_USERPREFS + loraConfig.modem_preset = LORACONFIG_MODEM_PRESET_USERPREFS; +#endif +#ifdef LORACONFIG_CHANNEL_NUM_USERPREFS + loraConfig.channel_num = LORACONFIG_CHANNEL_NUM_USERPREFS; +#endif + + // Install custom defaults. Will eventually support setting multiple default channels + if (chIndex == 0) { +#ifdef CHANNEL_0_PSK_USERPREFS + static const uint8_t defaultpsk[] = CHANNEL_0_PSK_USERPREFS; + memcpy(channelSettings.psk.bytes, defaultpsk, sizeof(defaultpsk)); + channelSettings.psk.size = sizeof(defaultpsk); + +#endif +#ifdef CHANNEL_0_NAME_USERPREFS + strcpy(channelSettings.name, CHANNEL_0_NAME_USERPREFS); +#endif +#ifdef CHANNEL_0_PRECISION_USERPREFS + channelSettings.module_settings.position_precision = CHANNEL_0_PRECISION_USERPREFS; +#endif + } } CryptoKey Channels::getKey(ChannelIndex chIndex) @@ -251,6 +277,12 @@ void Channels::setChannel(const meshtastic_Channel &c) bool Channels::anyMqttEnabled() { +#if EVENT_MODE + // Don't publish messages on the public MQTT broker if we are in event mode + if (strcmp(moduleConfig.mqtt.address, default_mqtt_address) == 0) { + return false; + } +#endif for (int i = 0; i < getNumChannels(); i++) if (channelFile.channels[i].role != meshtastic_Channel_Role_DISABLED && channelFile.channels[i].has_settings && (channelFile.channels[i].settings.downlink_enabled || channelFile.channels[i].settings.uplink_enabled)) @@ -330,4 +362,4 @@ bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash) int16_t Channels::setActiveByIndex(ChannelIndex channelIndex) { return setCrypto(channelIndex); -} +} \ No newline at end of file diff --git a/src/mesh/Default.cpp b/src/mesh/Default.cpp index d4e9b3d790..ac74413949 100644 --- a/src/mesh/Default.cpp +++ b/src/mesh/Default.cpp @@ -1,4 +1,5 @@ #include "Default.h" +#include "../userPrefs.h" uint32_t Default::getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t defaultInterval) { @@ -40,4 +41,13 @@ uint32_t Default::getConfiguredOrDefaultMsScaled(uint32_t configured, uint32_t d return getConfiguredOrDefaultMs(configured, defaultValue); return getConfiguredOrDefaultMs(configured, defaultValue) * congestionScalingCoefficient(numOnlineNodes); +} + +uint8_t Default::getConfiguredOrDefaultHopLimit(uint8_t configured) +{ +#if EVENT_MODE + return (configured > HOP_RELIABLE) ? HOP_RELIABLE : config.lora.hop_limit; +#else + return (configured >= HOP_MAX) ? HOP_MAX : config.lora.hop_limit; +#endif } \ No newline at end of file diff --git a/src/mesh/Default.h b/src/mesh/Default.h index 7d79d696e5..3c95544dac 100644 --- a/src/mesh/Default.h +++ b/src/mesh/Default.h @@ -30,6 +30,7 @@ class Default static uint32_t getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t defaultInterval); static uint32_t getConfiguredOrDefault(uint32_t configured, uint32_t defaultValue); static uint32_t getConfiguredOrDefaultMsScaled(uint32_t configured, uint32_t defaultValue, uint32_t numOnlineNodes); + static uint8_t getConfiguredOrDefaultHopLimit(uint8_t configured); private: static float congestionScalingCoefficient(int numOnlineNodes) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index 0fdde52772..fbe56159c0 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -1,4 +1,5 @@ #include "FloodingRouter.h" +#include "../userPrefs.h" #include "configuration.h" #include "mesh-pb-constants.h" @@ -46,6 +47,13 @@ void FloodingRouter::sniffReceived(const meshtastic_MeshPacket *p, const meshtas meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); // keep a copy because we will be sending it tosend->hop_limit--; // bump down the hop count +#if EVENT_MODE + if (tosend->hop_limit > 2) { + // if we are "correcting" the hop_limit, "correct" the hop_start by the same amount to preserve hops away. + tosend->hop_start -= (tosend->hop_limit - 2); + tosend->hop_limit = 2; + } +#endif LOG_INFO("Rebroadcasting received floodmsg to neighbors\n"); // Note: we are careful to resend using the original senders node id diff --git a/src/mesh/MeshModule.cpp b/src/mesh/MeshModule.cpp index 1ef4f60d8c..604ac9dc4f 100644 --- a/src/mesh/MeshModule.cpp +++ b/src/mesh/MeshModule.cpp @@ -170,7 +170,7 @@ void MeshModule::callModules(meshtastic_MeshPacket &mp, RxSource src) if (isDecoded && mp.decoded.want_response && toUs) { if (currentReply) { printPacket("Sending response", currentReply); - service.sendToMesh(currentReply); + service->sendToMesh(currentReply); currentReply = NULL; } else if (mp.from != ourNodeNum && !ignoreRequest) { // Note: if the message started with the local node or a module asked to ignore the request, we don't want to send a diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 1181ffb9a8..fd07c3801c 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -23,6 +23,10 @@ #include "nimble/NimbleBluetooth.h" #endif +#if ARCH_PORTDUINO +#include "PortduinoGlue.h" +#endif + /* receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone. It is implemented with a FreeRTos queue (wrapped with a little RTQueue class) of pointers to MeshPacket protobufs (which were @@ -53,7 +57,7 @@ nodenum (filtering against whatever it knows about the nodedb) and rebroadcast t FIXME in the initial proof of concept we just skip the entire want/deny flow and just hand pick node numbers at first. */ -MeshService service; +MeshService *service; static MemoryDynamic staticMqttClientProxyMessagePool; diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index ef92ba7d40..528adb1379 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -150,4 +150,4 @@ class MeshService friend class RoutingModule; }; -extern MeshService service; \ No newline at end of file +extern MeshService *service; \ No newline at end of file diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index b23a788b13..eeb55e67c6 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1,3 +1,4 @@ +#include "../userPrefs.h" #include "configuration.h" #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" @@ -199,9 +200,11 @@ bool NodeDB::factoryReset() LOG_INFO("Performing factory reset!\n"); // first, remove the "/prefs" (this removes most prefs) rmDir("/prefs"); +#ifdef FSCom if (FSCom.exists("/static/rangetest.csv") && !FSCom.remove("/static/rangetest.csv")) { LOG_ERROR("Could not remove rangetest.csv file\n"); } +#endif // second, install default state (this will deal with the duplicate mac address issue) installDefaultDeviceState(); installDefaultConfig(); @@ -242,10 +245,22 @@ void NodeDB::installDefaultConfig() config.lora.tx_enabled = true; // FIXME: maybe false in the future, and setting region to enable it. (unset region forces it off) config.lora.override_duty_cycle = false; +#ifdef CONFIG_LORA_REGION_USERPREFS + config.lora.region = CONFIG_LORA_REGION_USERPREFS; +#else config.lora.region = meshtastic_Config_LoRaConfig_RegionCode_UNSET; +#endif +#ifdef LORACONFIG_MODEM_PRESET_USERPREFS + config.lora.modem_preset = LORACONFIG_MODEM_PRESET_USERPREFS; +#else config.lora.modem_preset = meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST; +#endif config.lora.hop_limit = HOP_RELIABLE; +#ifdef CONFIG_LORA_IGNORE_MQTT_USERPREFS + config.lora.ignore_mqtt = CONFIG_LORA_IGNORE_MQTT_USERPREFS; +#else config.lora.ignore_mqtt = false; +#endif #ifdef PIN_GPS_EN config.position.gps_en_gpio = PIN_GPS_EN; #endif @@ -295,13 +310,17 @@ void NodeDB::installDefaultConfig() meshtastic_Config_PositionConfig_PositionFlags_SPEED | meshtastic_Config_PositionConfig_PositionFlags_HEADING | meshtastic_Config_PositionConfig_PositionFlags_DOP | meshtastic_Config_PositionConfig_PositionFlags_SATINVIEW); -#ifdef RADIOMASTER_900_BANDIT_NANO +#ifdef DISPLAY_FLIP_SCREEN config.display.flip_screen = true; #endif #ifdef T_WATCH_S3 config.display.screen_on_secs = 30; config.display.wake_on_tap_or_motion = true; #endif +#ifdef HELTEC_VISION_MASTER_E290 + // Orient so that LoRa antenna faces up + config.display.flip_screen = true; +#endif initConfigIntervals(); } @@ -581,7 +600,7 @@ LoadFileResult NodeDB::loadProto(const char *filename, size_t protoSize, size_t state = LoadFileResult::DECODE_FAILED; } else { LOG_INFO("Loaded %s successfully\n", filename); - state = LoadFileResult::SUCCESS; + state = LoadFileResult::LOAD_SUCCESS; } f.close(); } else { @@ -589,7 +608,7 @@ LoadFileResult NodeDB::loadProto(const char *filename, size_t protoSize, size_t } #else LOG_ERROR("ERROR: Filesystem not implemented\n"); - state = LoadFileState::NO_FILESYSTEM; + state = LoadFileResult::NO_FILESYSTEM; #endif return state; } @@ -600,7 +619,7 @@ void NodeDB::loadFromDisk() auto state = loadProto(prefFileName, sizeof(meshtastic_DeviceState) + MAX_NUM_NODES * sizeof(meshtastic_NodeInfo), sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, &devicestate); - if (state != LoadFileResult::SUCCESS) { + if (state != LoadFileResult::LOAD_SUCCESS) { installDefaultDeviceState(); // Our in RAM copy might now be corrupt } else { if (devicestate.version < DEVICESTATE_MIN_VER) { @@ -617,7 +636,7 @@ void NodeDB::loadFromDisk() state = loadProto(configFileName, meshtastic_LocalConfig_size, sizeof(meshtastic_LocalConfig), &meshtastic_LocalConfig_msg, &config); - if (state != LoadFileResult::SUCCESS) { + if (state != LoadFileResult::LOAD_SUCCESS) { installDefaultConfig(); // Our in RAM copy might now be corrupt } else { if (config.version < DEVICESTATE_MIN_VER) { @@ -630,7 +649,7 @@ void NodeDB::loadFromDisk() state = loadProto(moduleConfigFileName, meshtastic_LocalModuleConfig_size, sizeof(meshtastic_LocalModuleConfig), &meshtastic_LocalModuleConfig_msg, &moduleConfig); - if (state != LoadFileResult::SUCCESS) { + if (state != LoadFileResult::LOAD_SUCCESS) { installDefaultModuleConfig(); // Our in RAM copy might now be corrupt } else { if (moduleConfig.version < DEVICESTATE_MIN_VER) { @@ -643,7 +662,7 @@ void NodeDB::loadFromDisk() state = loadProto(channelFileName, meshtastic_ChannelFile_size, sizeof(meshtastic_ChannelFile), &meshtastic_ChannelFile_msg, &channelFile); - if (state != LoadFileResult::SUCCESS) { + if (state != LoadFileResult::LOAD_SUCCESS) { installDefaultChannels(); // Our in RAM copy might now be corrupt } else { if (channelFile.version < DEVICESTATE_MIN_VER) { @@ -655,7 +674,7 @@ void NodeDB::loadFromDisk() } state = loadProto(oemConfigFile, meshtastic_OEMStore_size, sizeof(meshtastic_OEMStore), &meshtastic_OEMStore_msg, &oemStore); - if (state == LoadFileResult::SUCCESS) { + if (state == LoadFileResult::LOAD_SUCCESS) { LOG_INFO("Loaded OEMStore\n"); } diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 5207d8629b..e2c2471d44 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -40,7 +40,7 @@ uint32_t sinceReceived(const meshtastic_MeshPacket *p); enum LoadFileResult { // Successfully opened the file - SUCCESS = 1, + LOAD_SUCCESS = 1, // File does not exist NOT_FOUND = 2, // Device does not have a filesystem @@ -204,9 +204,6 @@ extern NodeDB *nodeDB; prefs.is_power_saving = True */ -// Our delay functions check for this for times that should never expire -#define NODE_DELAY_FOREVER 0xffffffff - /// Sometimes we will have Position objects that only have a time, so check for /// valid lat/lon static inline bool hasValidPosition(const meshtastic_NodeInfoLite *n) @@ -231,4 +228,4 @@ extern uint32_t error_address; ModuleConfig_RangeTestConfig_size + ModuleConfig_SerialConfig_size + ModuleConfig_StoreForwardConfig_size + \ ModuleConfig_TelemetryConfig_size + ModuleConfig_size) -// Please do not remove this comment, it makes trunk and compiler happy at the same time. \ No newline at end of file +// Please do not remove this comment, it makes trunk and compiler happy at the same time. diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 0b63b4a581..fc0099e87f 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -41,8 +41,10 @@ void PhoneAPI::handleStartConfig() // Must be before setting state (because state is how we know !connected) if (!isConnected()) { onConnectionChanged(true); - observe(&service.fromNumChanged); + observe(&service->fromNumChanged); +#ifdef FSCom observe(&xModem.packetReady); +#endif } // even if we were already connected - restart our state machine @@ -61,8 +63,10 @@ void PhoneAPI::close() if (state != STATE_SEND_NOTHING) { state = STATE_SEND_NOTHING; - unobserve(&service.fromNumChanged); + unobserve(&service->fromNumChanged); +#ifdef FSCom unobserve(&xModem.packetReady); +#endif releasePhonePacket(); // Don't leak phone packets on shutdown releaseQueueStatusPhonePacket(); releaseMqttClientProxyPhonePacket(); @@ -110,7 +114,9 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) break; case meshtastic_ToRadio_xmodemPacket_tag: LOG_INFO("Got xmodem packet\n"); +#ifdef FSCom xModem.handlePacket(toRadioScratch.xmodemPacket); +#endif break; #if !MESHTASTIC_EXCLUDE_MQTT case meshtastic_ToRadio_mqttClientProxyMessage_tag: @@ -180,7 +186,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) fromRadioScratch.my_info = myNodeInfo; state = STATE_SEND_OWN_NODEINFO; - service.refreshLocalMeshNode(); // Update my NodeInfo because the client will be asking for it soon. + service->refreshLocalMeshNode(); // Update my NodeInfo because the client will be asking for it soon. break; case STATE_SEND_OWN_NODEINFO: { @@ -437,7 +443,7 @@ void PhoneAPI::handleDisconnect() void PhoneAPI::releasePhonePacket() { if (packetForPhone) { - service.releaseToPool(packetForPhone); // we just copied the bytes, so don't need this buffer anymore + service->releaseToPool(packetForPhone); // we just copied the bytes, so don't need this buffer anymore packetForPhone = NULL; } } @@ -445,7 +451,7 @@ void PhoneAPI::releasePhonePacket() void PhoneAPI::releaseQueueStatusPhonePacket() { if (queueStatusPacketForPhone) { - service.releaseQueueStatusToPool(queueStatusPacketForPhone); + service->releaseQueueStatusToPool(queueStatusPacketForPhone); queueStatusPacketForPhone = NULL; } } @@ -453,7 +459,7 @@ void PhoneAPI::releaseQueueStatusPhonePacket() void PhoneAPI::releaseMqttClientProxyPhonePacket() { if (mqttClientProxyMessageForPhone) { - service.releaseMqttClientProxyMessageToPool(mqttClientProxyMessageForPhone); + service->releaseMqttClientProxyMessageToPool(mqttClientProxyMessageForPhone); mqttClientProxyMessageForPhone = NULL; } } @@ -489,19 +495,21 @@ bool PhoneAPI::available() return true; // Always say we have something, because we might need to advance our state machine case STATE_SEND_PACKETS: { if (!queueStatusPacketForPhone) - queueStatusPacketForPhone = service.getQueueStatusForPhone(); + queueStatusPacketForPhone = service->getQueueStatusForPhone(); if (!mqttClientProxyMessageForPhone) - mqttClientProxyMessageForPhone = service.getMqttClientProxyMessageForPhone(); + mqttClientProxyMessageForPhone = service->getMqttClientProxyMessageForPhone(); bool hasPacket = !!queueStatusPacketForPhone || !!mqttClientProxyMessageForPhone; if (hasPacket) return true; +#ifdef FSCom if (xmodemPacketForPhone.control == meshtastic_XModem_Control_NUL) xmodemPacketForPhone = xModem.getForPhone(); if (xmodemPacketForPhone.control != meshtastic_XModem_Control_NUL) { xModem.resetForPhone(); return true; } +#endif #ifdef ARCH_ESP32 #if !MESHTASTIC_EXCLUDE_STOREFORWARD @@ -512,7 +520,7 @@ bool PhoneAPI::available() #endif if (!packetForPhone) - packetForPhone = service.getForPhone(); + packetForPhone = service->getForPhone(); hasPacket = !!packetForPhone; // LOG_DEBUG("available hasPacket=%d\n", hasPacket); return hasPacket; @@ -530,7 +538,7 @@ bool PhoneAPI::available() bool PhoneAPI::handleToRadioPacket(meshtastic_MeshPacket &p) { printPacket("PACKET FROM PHONE", &p); - service.handleToRadio(p); + service->handleToRadio(p); return true; } diff --git a/src/mesh/ProtobufModule.h b/src/mesh/ProtobufModule.h index ed76b877f1..3b438ebebd 100644 --- a/src/mesh/ProtobufModule.h +++ b/src/mesh/ProtobufModule.h @@ -38,7 +38,7 @@ template class ProtobufModule : protected SinglePortModule /** * Return a mesh packet which has been preinited with a particular protobuf data payload and port number. * You can then send this packet (after customizing any of the payload fields you might need) with - * service.sendToMesh() + * service->sendToMesh() */ meshtastic_MeshPacket *allocDataProtobuf(const T &payload) { diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index bd1ebdb0e6..b6083e7f9e 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -16,7 +16,6 @@ // In theory up to 27 dBm is possible, but the modules installed in most radios can cope with a max of 20. So BIG WARNING // if you set power to something higher than 17 or 20 you might fry your board. -#define POWER_DEFAULT 17 // How much power to use if the user hasn't set a power level #ifdef RADIOMASTER_900_BANDIT_NANO // Structure to hold DAC and DB values typedef struct { diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 343b7f2008..262d2d6a99 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -177,9 +177,6 @@ The band is from 902 to 928 MHz. It mentions channel number and its respective c separated by 2.16 MHz with respect to the adjacent channels. Channel zero starts at 903.08 MHz center frequency. */ -// 1kb was too small -#define RADIO_STACK_SIZE 4096 - /** * Calculate airtime per * https://www.rs-online.com/designspark/rel-assets/ds-assets/uploads/knowledge-items/application-notes-for-the-internet-of-things/LoRa%20Design%20Guide.pdf @@ -337,7 +334,7 @@ bool RadioInterface::init() { LOG_INFO("Starting meshradio init...\n"); - configChangedObserver.observe(&service.configChanged); + configChangedObserver.observe(&service->configChanged); preflightSleepObserver.observe(&preflightSleep); notifyDeepSleepObserver.observe(¬ifyDeepSleep); @@ -588,4 +585,4 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p) sendingPacket = p; return p->encrypted.size + sizeof(PacketHeader); -} +} \ No newline at end of file diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index d3246b48d0..c91ce50c5b 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -1,4 +1,5 @@ #include "ReliableRouter.h" +#include "Default.h" #include "MeshModule.h" #include "MeshTypes.h" #include "configuration.h" @@ -17,7 +18,7 @@ ErrorCode ReliableRouter::send(meshtastic_MeshPacket *p) // message will rebroadcast. But asking for hop_limit 0 in that context means the client app has no preference on hop // counts and we want this message to get through the whole mesh, so use the default. if (p->hop_limit == 0) { - p->hop_limit = (config.lora.hop_limit >= HOP_MAX) ? HOP_MAX : config.lora.hop_limit; + p->hop_limit = Default::getConfiguredOrDefaultHopLimit(config.lora.hop_limit); } auto copy = packetPool.allocCopy(*p); diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 35536e7149..1260b7c045 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -11,6 +11,14 @@ #if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" #endif +#include "Default.h" +#if ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif +#if ENABLE_JSON_LOGGING || ARCH_PORTDUINO +#include "serialization/MeshPacketSerializer.h" +#endif +#include "../userPrefs.h" /** * Router todo * @@ -119,7 +127,7 @@ meshtastic_MeshPacket *Router::allocForSending() p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Assume payload is decoded at start. p->from = nodeDB->getNodeNum(); p->to = NODENUM_BROADCAST; - p->hop_limit = (config.lora.hop_limit >= HOP_MAX) ? HOP_MAX : config.lora.hop_limit; + p->hop_limit = Default::getConfiguredOrDefaultHopLimit(config.lora.hop_limit); p->id = generatePacketId(); p->rx_time = getValidTime(RTCQualityFromNet); // Just in case we process the packet locally - make sure it has a valid timestamp @@ -356,6 +364,13 @@ bool perhapsDecode(meshtastic_MeshPacket *p) } */ printPacket("decoded message", p); +#if ENABLE_JSON_LOGGING + LOG_TRACE("%s\n", MeshPacketSerializer::JsonSerialize(p, false).c_str()); +#elif ARCH_PORTDUINO + if (settingsStrings[traceFilename] != "" || settingsMap[logoutputlevel] == level_trace) { + LOG_TRACE("%s\n", MeshPacketSerializer::JsonSerialize(p, false).c_str()); + } +#endif return true; } } @@ -471,6 +486,20 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) cancelSending(p->from, p->id); skipHandle = true; } + +#if EVENT_MODE + if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag && + (p->decoded.portnum == meshtastic_PortNum_ATAK_FORWARDER || p->decoded.portnum == meshtastic_PortNum_ATAK_PLUGIN || + p->decoded.portnum == meshtastic_PortNum_PAXCOUNTER_APP || p->decoded.portnum == meshtastic_PortNum_IP_TUNNEL_APP || + p->decoded.portnum == meshtastic_PortNum_AUDIO_APP || p->decoded.portnum == meshtastic_PortNum_PRIVATE_APP || + p->decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP || + p->decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP || + p->decoded.portnum == meshtastic_PortNum_REMOTE_HARDWARE_APP)) { + LOG_DEBUG("Ignoring packet on blacklisted portnum during event\n"); + cancelSending(p->from, p->id); + skipHandle = true; + } +#endif } else { printPacket("packet decoding failed or skipped (no PSK?)", p); } @@ -491,6 +520,17 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) { +#if ENABLE_JSON_LOGGING + // Even ignored packets get logged in the trace + p->rx_time = getValidTime(RTCQualityFromNet); // store the arrival timestamp for the phone + LOG_TRACE("%s\n", MeshPacketSerializer::JsonSerializeEncrypted(p).c_str()); +#elif ARCH_PORTDUINO + // Even ignored packets get logged in the trace + if (settingsStrings[traceFilename] != "" || settingsMap[logoutputlevel] == level_trace) { + p->rx_time = getValidTime(RTCQualityFromNet); // store the arrival timestamp for the phone + LOG_TRACE("%s\n", MeshPacketSerializer::JsonSerializeEncrypted(p).c_str()); + } +#endif // assert(radioConfig.has_preferences); bool ignore = is_in_repeated(config.lora.ignore_incoming, p->from) || (config.lora.ignore_mqtt && p->via_mqtt); diff --git a/src/mesh/STM32WLE5JCInterface.h b/src/mesh/STM32WLE5JCInterface.h index 73d53d92f9..fad7933329 100644 --- a/src/mesh/STM32WLE5JCInterface.h +++ b/src/mesh/STM32WLE5JCInterface.h @@ -23,7 +23,7 @@ static const float tcxoVoltage = 1.7; * Wio-E5 module ONLY transmits through RFO_HP * Receive: PA4=1, PA5=0 * Transmit(high output power, SMPS mode): PA4=0, PA5=1 */ -static const RADIOLIB_PIN_TYPE rfswitch_pins[3] = {PA4, PA5, RADIOLIB_NC}; +static const RADIOLIB_PIN_TYPE rfswitch_pins[5] = {PA4, PA5, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC}; static const Module::RfSwitchMode_t rfswitch_table[4] = { {STM32WLx::MODE_IDLE, {LOW, LOW}}, {STM32WLx::MODE_RX, {HIGH, LOW}}, {STM32WLx::MODE_TX_HP, {LOW, HIGH}}, END_OF_MODE_TABLE}; diff --git a/src/mesh/SinglePortModule.h b/src/mesh/SinglePortModule.h index a5aaa2582f..e43de09d12 100644 --- a/src/mesh/SinglePortModule.h +++ b/src/mesh/SinglePortModule.h @@ -26,7 +26,7 @@ class SinglePortModule : public MeshModule /** * Return a mesh packet which has been preinited as a data packet with a particular port number. * You can then send this packet (after customizing any of the payload fields you might need) with - * service.sendToMesh() + * service->sendToMesh() */ meshtastic_MeshPacket *allocDataPacket() { @@ -36,4 +36,4 @@ class SinglePortModule : public MeshModule return p; } -}; +}; \ No newline at end of file diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index 841ca7aa4b..ca860aed53 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -178,6 +178,8 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_HELTEC_MESH_NODE_T114 = 69, /* Sensecap Indicator from Seeed Studio. ESP32-S3 device with TFT and RP2040 coprocessor */ meshtastic_HardwareModel_SENSECAP_INDICATOR = 70, + /* Seeed studio T1000-E tracker card. NRF52840 w/ LR1110 radio, GPS, button, buzzer, and sensors. */ + meshtastic_HardwareModel_TRACKER_T1000_E = 71, /* ------------------------------------------------------------------------------------------------------------------------------------------ Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. ------------------------------------------------------------------------------------------------------------------------------------------ */ diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index b309484e23..ca2c5d4be7 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -9,8 +9,8 @@ #if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif -#include "mqtt/JSON.h" #include "power.h" +#include "serialization/JSON.h" #include "sleep.h" #include #include diff --git a/src/mesh/mesh-pb-constants.cpp b/src/mesh/mesh-pb-constants.cpp index 93dbf0178b..676208e25a 100644 --- a/src/mesh/mesh-pb-constants.cpp +++ b/src/mesh/mesh-pb-constants.cpp @@ -1,6 +1,7 @@ -#include "mesh-pb-constants.h" -#include "FSCommon.h" #include "configuration.h" + +#include "FSCommon.h" +#include "mesh-pb-constants.h" #include #include #include @@ -15,6 +16,7 @@ size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc LOG_ERROR("Panic: can't encode protobuf reason='%s'\n", PB_GET_ERROR(&stream)); assert( 0); // If this assert fails it probably means you made a field too large for the max limits specified in mesh.options + return 0; } else { return stream.bytes_written; } diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index b8ef236c99..f91c485605 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -14,7 +14,9 @@ /// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf // FIXME - max_count is actually 32 but we save/load this as one long string of preencoded MeshPacket bytes - not a big array in // RAM #define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0])) +#ifndef MAX_RX_TOPHONE #define MAX_RX_TOPHONE 32 +#endif /// max number of nodes allowed in the mesh #ifndef MAX_NUM_NODES diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 37724f6260..8b7ba773ea 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -16,6 +16,7 @@ #ifdef ARCH_PORTDUINO #include "unistd.h" #endif +#include "../userPrefs.h" #include "Default.h" #include "TypeConversions.h" @@ -259,11 +260,13 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } case meshtastic_AdminMessage_delete_file_request_tag: { LOG_DEBUG("Client is requesting to delete file: %s\n", r->delete_file_request); +#ifdef FSCom if (FSCom.remove(r->delete_file_request)) { LOG_DEBUG("Successfully deleted file\n"); } else { LOG_DEBUG("Failed to delete file\n"); } +#endif break; } #ifdef ARCH_PORTDUINO @@ -345,7 +348,7 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) } if (changed) { // If nothing really changed, don't broadcast on the network or write to flash - service.reloadOwner(!hasOpenEditTransaction); + service->reloadOwner(!hasOpenEditTransaction); saveChanges(SEGMENT_DEVICESTATE); } } @@ -398,6 +401,13 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) requiresReboot = true; } } +#if EVENT_MODE + // If we're in event mode, nobody is a Router or Repeater + if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER || + config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER) { + config.device.role = meshtastic_Config_DeviceConfig_Role_CLIENT; + } +#endif break; case meshtastic_Config_position_tag: LOG_INFO("Setting config: Position\n"); @@ -457,6 +467,15 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) config.lora.sx126x_rx_boosted_gain == c.payload_variant.lora.sx126x_rx_boosted_gain) { requiresReboot = false; } + +#ifdef RF95_FAN_EN + // Turn PA off if disabled by config + if (c.payload_variant.lora.pa_fan_disabled) { + digitalWrite(RF95_FAN_EN, LOW ^ 0); + } else { + digitalWrite(RF95_FAN_EN, HIGH ^ 0); + } +#endif config.lora = c.payload_variant.lora; // If we're setting region for the first time, init the region if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { @@ -833,7 +852,7 @@ void AdminModule::saveChanges(int saveWhat, bool shouldReboot) { if (!hasOpenEditTransaction) { LOG_INFO("Saving changes to disk\n"); - service.reloadConfig(saveWhat); // Calls saveToDisk among other things + service->reloadConfig(saveWhat); // Calls saveToDisk among other things } else { LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n"); } @@ -864,7 +883,7 @@ void AdminModule::handleSetHamMode(const meshtastic_HamParameters &p) channels.setChannel(primaryChannel); channels.onConfigChanged(); - service.reloadOwner(false); + service->reloadOwner(false); saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); } diff --git a/src/modules/AtakPluginModule.cpp b/src/modules/AtakPluginModule.cpp index c05f055d41..437a341db6 100644 --- a/src/modules/AtakPluginModule.cpp +++ b/src/modules/AtakPluginModule.cpp @@ -188,7 +188,7 @@ void AtakPluginModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtast pb_encode_to_bytes(decompressedCopy->decoded.payload.bytes, sizeof(decompressedCopy->decoded.payload), meshtastic_TAKPacket_fields, &uncompressed); - service.sendToPhone(decompressedCopy); + service->sendToPhone(decompressedCopy); } return; -} +} \ No newline at end of file diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 8f3bfa65c7..78ecdf3a47 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -17,6 +17,9 @@ #if !MESHTASTIC_EXCLUDE_GPS #include "GPS.h" #endif +#if defined(USE_EINK) && defined(USE_EINK_DYNAMICDISPLAY) +#include "graphics/EInkDynamicDisplay.h" // To select between full and fast refresh on E-Ink displays +#endif #ifndef INPUTBROKER_MATRIX_TYPE #define INPUTBROKER_MATRIX_TYPE 0 @@ -264,8 +267,8 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) #endif break; case 0xaf: // fn+space send network ping like double press does - service.refreshLocalMeshNode(); - if (service.trySendPosition(NODENUM_BROADCAST, true)) { + service->refreshLocalMeshNode(); + if (service->trySendPosition(NODENUM_BROADCAST, true)) { showTemporaryMessage("Position \nUpdate Sent"); } else { showTemporaryMessage("Node Info \nUpdate Sent"); @@ -388,7 +391,7 @@ void CannedMessageModule::sendText(NodeNum dest, ChannelIndex channel, const cha LOG_INFO("Sending message id=%d, dest=%x, msg=%.*s\n", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes); - service.sendToMesh( + service->sendToMesh( p, RX_SRC_LOCAL, true); // send to mesh, cc to phone. Even if there's no phone connected, this stores the message to match ACKs } @@ -929,6 +932,9 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st display->setFont(FONT_MEDIUM); display->drawString(display->getWidth() / 2 + x, 0 + y + 12, temporaryMessage); } else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED) { + // E-Ink: clean the screen *after* this pop-up + EINK_ADD_FRAMEFLAG(display, COSMETIC); + requestFocus(); // Tell Screen::setFrames to move to our module's frame display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(FONT_MEDIUM); @@ -951,6 +957,9 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st display->drawStringf(display->getWidth() / 2 + x, y + 130, buffer, rssiString, this->lastRxRssi); } } else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) { + // E-Ink: clean the screen *after* this pop-up + EINK_ADD_FRAMEFLAG(display, COSMETIC); + requestFocus(); // Tell Screen::setFrames to move to our module's frame display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(FONT_MEDIUM); @@ -1050,7 +1059,7 @@ ProcessMessage CannedMessageModule::handleReceived(const meshtastic_MeshPacket & e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen requestFocus(); // Tell Screen::setFrames that our module's frame should be shown, even if not "first" in the frameset this->runState = CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED; - this->incoming = service.getNodenumFromRequestId(mp.decoded.request_id); + this->incoming = service->getNodenumFromRequestId(mp.decoded.request_id); meshtastic_Routing decoded = meshtastic_Routing_init_default; pb_decode_from_bytes(mp.decoded.payload.bytes, mp.decoded.payload.size, meshtastic_Routing_fields, &decoded); this->ack = decoded.error_reason == meshtastic_Routing_Error_NONE; @@ -1068,7 +1077,7 @@ void CannedMessageModule::loadProtoForModule() { if (nodeDB->loadProto(cannedMessagesConfigFile, meshtastic_CannedMessageModuleConfig_size, sizeof(meshtastic_CannedMessageModuleConfig), &meshtastic_CannedMessageModuleConfig_msg, - &cannedMessageModuleConfig) != LoadFileResult::SUCCESS) { + &cannedMessageModuleConfig) != LoadFileResult::LOAD_SUCCESS) { installDefaultCannedMessageModuleConfig(); } } diff --git a/src/modules/DetectionSensorModule.cpp b/src/modules/DetectionSensorModule.cpp index b6e5f1e298..20d91a381b 100644 --- a/src/modules/DetectionSensorModule.cpp +++ b/src/modules/DetectionSensorModule.cpp @@ -82,7 +82,7 @@ void DetectionSensorModule::sendDetectionMessage() } LOG_INFO("Sending message id=%d, dest=%x, msg=%.*s\n", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes); lastSentToMesh = millis(); - service.sendToMesh(p); + service->sendToMesh(p); delete[] message; } @@ -97,7 +97,7 @@ void DetectionSensorModule::sendCurrentStateMessage() memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size); LOG_INFO("Sending message id=%d, dest=%x, msg=%.*s\n", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes); lastSentToMesh = millis(); - service.sendToMesh(p); + service->sendToMesh(p); delete[] message; } diff --git a/src/modules/DropzoneModule.cpp b/src/modules/DropzoneModule.cpp index 8c5b5dcdd8..b1ca2af819 100644 --- a/src/modules/DropzoneModule.cpp +++ b/src/modules/DropzoneModule.cpp @@ -1,7 +1,7 @@ #if !MESHTASTIC_EXCLUDE_DROPZONE #include "DropzoneModule.h" -#include "MeshService.h" +#include "Meshservice->h" #include "configuration.h" #include "gps/GeoCoord.h" #include "gps/RTC.h" @@ -20,7 +20,7 @@ int32_t DropzoneModule::runOnce() { // Send on a 5 second delay from receiving the matching request if (startSendConditions != 0 && (startSendConditions + 5000U) < millis()) { - service.sendToMesh(sendConditions(), RX_SRC_LOCAL); + service->sendToMesh(sendConditions(), RX_SRC_LOCAL); startSendConditions = 0; } // Run every second to check if we need to send conditions diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index c025592401..652db04d3d 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -355,7 +355,7 @@ ExternalNotificationModule::ExternalNotificationModule() if (moduleConfig.external_notification.enabled) { if (nodeDB->loadProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, sizeof(meshtastic_RTTTLConfig), - &meshtastic_RTTTLConfig_msg, &rtttlConfig) != LoadFileResult::SUCCESS) { + &meshtastic_RTTTLConfig_msg, &rtttlConfig) != LoadFileResult::LOAD_SUCCESS) { memset(rtttlConfig.ringtone, 0, sizeof(rtttlConfig.ringtone)); strncpy(rtttlConfig.ringtone, "24:d=32,o=5,b=565:f6,p,f6,4p,p,f6,p,f6,2p,p,b6,p,b6,p,b6,p,b6,p,b,p,b,p,b,p,b,p,b,p,b,p,b,p,b,1p.,2p.,p", diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index 64a2de1685..98c37827ad 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -2,12 +2,15 @@ #if !MESHTASTIC_EXCLUDE_INPUTBROKER #include "input/InputBroker.h" #include "input/RotaryEncoderInterruptImpl1.h" +#include "input/SerialKeyboardImpl.h" #include "input/TrackballInterruptImpl1.h" #include "input/UpDownInterruptImpl1.h" #include "input/cardKbI2cImpl.h" #include "input/kbMatrixImpl.h" #endif +#if !MESHTASTIC_EXCLUDE_ADMIN #include "modules/AdminModule.h" +#endif #if !MESHTASTIC_EXCLUDE_ATAK #include "modules/AtakPluginModule.h" #endif @@ -20,7 +23,9 @@ #if !MESHTASTIC_EXCLUDE_NEIGHBORINFO #include "modules/NeighborInfoModule.h" #endif +#if !MESHTASTIC_EXCLUDE_NODEINFO #include "modules/NodeInfoModule.h" +#endif #if !MESHTASTIC_EXCLUDE_GPS #include "modules/PositionModule.h" #endif @@ -88,8 +93,12 @@ void setupModules() #if (HAS_BUTTON || ARCH_PORTDUINO) && !MESHTASTIC_EXCLUDE_INPUTBROKER inputBroker = new InputBroker(); #endif +#if !MESHTASTIC_EXCLUDE_ADMIN adminModule = new AdminModule(); +#endif +#if !MESHTASTIC_EXCLUDE_NODEINFO nodeInfoModule = new NodeInfoModule(); +#endif #if !MESHTASTIC_EXCLUDE_GPS positionModule = new PositionModule(); #endif @@ -141,6 +150,10 @@ void setupModules() kbMatrixImpl = new KbMatrixImpl(); kbMatrixImpl->init(); #endif // INPUTBROKER_MATRIX_TYPE +#ifdef INPUTBROKER_SERIAL_TYPE + aSerialKeyboardImpl = new SerialKeyboardImpl(); + aSerialKeyboardImpl->init(); +#endif // INPUTBROKER_MATRIX_TYPE #endif // HAS_BUTTON #if ARCH_PORTDUINO && !HAS_TFT aLinuxInputImpl = new LinuxInputImpl(); @@ -192,7 +205,9 @@ void setupModules() #endif #endif } else { +#if !MESHTASTIC_EXCLUDE_ADMIN adminModule = new AdminModule(); +#endif #if HAS_TELEMETRY new DeviceTelemetryModule(); #endif diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index 774b42d7bd..fb12490297 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -108,7 +108,7 @@ void NeighborInfoModule::sendNeighborInfo(NodeNum dest, bool wantReplies) p->to = dest; p->decoded.want_response = wantReplies; printNeighborInfo("SENDING", &neighborInfo); - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); } /* diff --git a/src/modules/NodeInfoModule.cpp b/src/modules/NodeInfoModule.cpp index 78af7099a5..62cf9d2a1f 100644 --- a/src/modules/NodeInfoModule.cpp +++ b/src/modules/NodeInfoModule.cpp @@ -26,7 +26,7 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes // if user has changed while packet was not for us, inform phone if (hasChanged && !wasBroadcast && mp.to != nodeDB->getNodeNum()) - service.sendToPhone(packetPool.allocCopy(mp)); + service->sendToPhone(packetPool.allocCopy(mp)); // LOG_DEBUG("did handleReceived\n"); return false; // Let others look at this message also if they want @@ -36,7 +36,7 @@ void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t cha { // cancel any not yet sent (now stale) position packets if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal) - service.cancelSending(prevPacketId); + service->cancelSending(prevPacketId); meshtastic_MeshPacket *p = allocReply(); if (p) { // Check whether we didn't ignore it @@ -52,7 +52,7 @@ void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t cha prevPacketId = p->id; - service.sendToMesh(p); + service->sendToMesh(p); } } @@ -98,4 +98,4 @@ int32_t NodeInfoModule::runOnce() sendOurNodeInfo(NODENUM_BROADCAST, requestReplies); // Send our info (don't request replies) } return Default::getConfiguredOrDefaultMs(config.device.node_info_broadcast_secs, default_node_info_broadcast_secs); -} +} \ No newline at end of file diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 228929e963..5da9180490 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -141,7 +141,7 @@ meshtastic_MeshPacket *PositionModule::allocReply() return nullptr; } - meshtastic_NodeInfoLite *node = service.refreshLocalMeshNode(); // should guarantee there is now a position + meshtastic_NodeInfoLite *node = service->refreshLocalMeshNode(); // should guarantee there is now a position assert(node->has_position); // configuration of POSITION packet @@ -280,7 +280,7 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha { // cancel any not yet sent (now stale) position packets if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal) - service.cancelSending(prevPacketId); + service->cancelSending(prevPacketId); // Set's the class precision value for this particular packet if (channels.getByIndex(channel).settings.has_module_settings) { @@ -309,7 +309,7 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha if (channel > 0) p->channel = channel; - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); if ((config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) && @@ -359,7 +359,7 @@ int32_t PositionModule::runOnce() } } } else if (config.position.position_broadcast_smart_enabled) { - const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position + const meshtastic_NodeInfoLite *node2 = service->refreshLocalMeshNode(); // should guarantee there is now a position if (hasValidPosition(node2)) { // The minimum time (in seconds) that would pass before we are able to send a new position packet. @@ -398,7 +398,7 @@ void PositionModule::sendLostAndFoundText() p->decoded.payload.size = strlen(message); memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size); - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); delete[] message; } @@ -437,7 +437,7 @@ struct SmartPosition PositionModule::getDistanceTraveledSinceLastSend(meshtastic void PositionModule::handleNewPosition() { meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); - const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position + const meshtastic_NodeInfoLite *node2 = service->refreshLocalMeshNode(); // should guarantee there is now a position // We limit our GPS broadcasts to a max rate if (hasValidPosition(node2)) { auto smartPosition = getDistanceTraveledSinceLastSend(node->position); @@ -458,4 +458,4 @@ void PositionModule::handleNewPosition() } } -#endif +#endif \ No newline at end of file diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index a66a0513ea..8154a661ee 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -27,10 +27,6 @@ RangeTestModule::RangeTestModule() : concurrency::OSThread("RangeTestModule") {} uint32_t packetSequence = 0; -#define SEC_PER_DAY 86400 -#define SEC_PER_HOUR 3600 -#define SEC_PER_MIN 60 - int32_t RangeTestModule::runOnce() { #if defined(ARCH_ESP32) || defined(ARCH_NRF52) @@ -124,7 +120,7 @@ void RangeTestModuleRadio::sendPayload(NodeNum dest, bool wantReplies) p->decoded.payload.size = strlen(heartbeatString); // You must specify how many bytes are in the reply memcpy(p->decoded.payload.bytes, heartbeatString, p->decoded.payload.size); - service.sendToMesh(p); + service->sendToMesh(p); // TODO: Handle this better. We want to keep the phone awake otherwise it stops sending. powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); diff --git a/src/modules/RemoteHardwareModule.cpp b/src/modules/RemoteHardwareModule.cpp index 8e64b9a9ca..d999e75cc7 100644 --- a/src/modules/RemoteHardwareModule.cpp +++ b/src/modules/RemoteHardwareModule.cpp @@ -131,7 +131,7 @@ int32_t RemoteHardwareModule::runOnce() r.type = meshtastic_HardwareMessage_Type_GPIOS_CHANGED; r.gpio_value = curVal; meshtastic_MeshPacket *p = allocDataProtobuf(r); - service.sendToMesh(p); + service->sendToMesh(p); } } } else { diff --git a/src/modules/RoutingModule.cpp b/src/modules/RoutingModule.cpp index fe1abab05d..87015032db 100644 --- a/src/modules/RoutingModule.cpp +++ b/src/modules/RoutingModule.cpp @@ -1,4 +1,5 @@ #include "RoutingModule.h" +#include "Default.h" #include "MeshService.h" #include "NodeDB.h" #include "Router.h" @@ -16,7 +17,7 @@ bool RoutingModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mesh // Note: we are careful not to send back packets that started with the phone back to the phone if ((mp.to == NODENUM_BROADCAST || mp.to == nodeDB->getNodeNum()) && (mp.from != 0)) { printPacket("Delivering rx packet", &mp); - service.handleFromRadio(&mp); + service->handleFromRadio(&mp); } return false; // Let others look at this message also if they want @@ -50,12 +51,15 @@ uint8_t RoutingModule::getHopLimitForResponse(uint8_t hopStart, uint8_t hopLimit // Hops used by the request. If somebody in between running modified firmware modified it, ignore it uint8_t hopsUsed = hopStart < hopLimit ? config.lora.hop_limit : hopStart - hopLimit; if (hopsUsed > config.lora.hop_limit) { +// In event mode, we never want to send packets with more than our default 3 hops. +#if !(EVENTMODE) // This falls through to the default. return hopsUsed; // If the request used more hops than the limit, use the same amount of hops +#endif } else if ((uint8_t)(hopsUsed + 2) < config.lora.hop_limit) { return hopsUsed + 2; // Use only the amount of hops needed with some margin as the way back may be different } } - return config.lora.hop_limit; // Use the default hop limit + return Default::getConfiguredOrDefaultHopLimit(config.lora.hop_limit); // Use the default hop limit } RoutingModule::RoutingModule() : ProtobufModule("routing", meshtastic_PortNum_ROUTING_APP, &meshtastic_Routing_msg) diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 4b8a4d2284..f0ba64f65a 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -236,7 +236,7 @@ void SerialModule::sendTelemetry(meshtastic_Telemetry m) p->to = NODENUM_BROADCAST; p->decoded.want_response = false; p->priority = meshtastic_MeshPacket_Priority_RELIABLE; - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); } /** @@ -272,7 +272,7 @@ void SerialModuleRadio::sendPayload(NodeNum dest, bool wantReplies) p->decoded.payload.size = serialPayloadSize; // You must specify how many bytes are in the reply memcpy(p->decoded.payload.bytes, serialBytes, p->decoded.payload.size); - service.sendToMesh(p); + service->sendToMesh(p); } /** diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index 6d2bf5e015..d07296710d 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -54,7 +54,7 @@ int32_t AirQualityTelemetryModule::runOnce() airTime->isTxAllowedAirUtil()) { sendTelemetry(); lastSentToMesh = now; - } else if (service.isToPhoneQueueEmpty()) { + } else if (service->isToPhoneQueueEmpty()) { // Just send to phone when it's not our time to send to mesh yet // Only send while queue is empty (phone assumed connected) sendTelemetry(NODENUM_BROADCAST, true); @@ -162,10 +162,10 @@ bool AirQualityTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) lastMeasurementPacket = packetPool.allocCopy(*p); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); - service.sendToPhone(p); + service->sendToPhone(p); } else { LOG_INFO("Sending packet to mesh\n"); - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); } return true; } diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 9c1ac289ca..4bde73f412 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -25,7 +25,7 @@ int32_t DeviceTelemetryModule::runOnce() config.device.role != meshtastic_Config_DeviceConfig_Role_CLIENT_HIDDEN) { sendTelemetry(); lastSentToMesh = uptimeLastMs; - } else if (service.isToPhoneQueueEmpty()) { + } else if (service->isToPhoneQueueEmpty()) { // Just send to phone when it's not our time to send to mesh yet // Only send while queue is empty (phone assumed connected) sendTelemetry(NODENUM_BROADCAST, true); @@ -113,10 +113,10 @@ bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) nodeDB->updateTelemetry(nodeDB->getNodeNum(), telemetry, RX_SRC_LOCAL); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); - service.sendToPhone(p); + service->sendToPhone(p); } else { LOG_INFO("Sending packet to mesh\n"); - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); } return true; } \ No newline at end of file diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index fec1ee4619..a100d1ef54 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -161,7 +161,7 @@ int32_t EnvironmentTelemetryModule::runOnce() sendTelemetry(); lastSentToMesh = now; } else if (((lastSentToPhone == 0) || ((now - lastSentToPhone) >= sendToPhoneIntervalMs)) && - (service.isToPhoneQueueEmpty())) { + (service->isToPhoneQueueEmpty())) { // Just send to phone when it's not our time to send to mesh yet // Only send while queue is empty (phone assumed connected) sendTelemetry(NODENUM_BROADCAST, true); @@ -449,10 +449,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) lastMeasurementPacket = packetPool.allocCopy(*p); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); - service.sendToPhone(p); + service->sendToPhone(p); } else { LOG_INFO("Sending packet to mesh\n"); - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR && config.power.is_power_saving) { LOG_DEBUG("Starting next execution in 5 seconds and then going to sleep.\n"); diff --git a/src/modules/Telemetry/PowerTelemetry.cpp b/src/modules/Telemetry/PowerTelemetry.cpp index a6f922e563..90371780f6 100644 --- a/src/modules/Telemetry/PowerTelemetry.cpp +++ b/src/modules/Telemetry/PowerTelemetry.cpp @@ -78,7 +78,7 @@ int32_t PowerTelemetryModule::runOnce() sendTelemetry(); lastSentToMesh = now; } else if (((lastSentToPhone == 0) || ((now - lastSentToPhone) >= sendToPhoneIntervalMs)) && - (service.isToPhoneQueueEmpty())) { + (service->isToPhoneQueueEmpty())) { // Just send to phone when it's not our time to send to mesh yet // Only send while queue is empty (phone assumed connected) sendTelemetry(NODENUM_BROADCAST, true); @@ -244,10 +244,10 @@ bool PowerTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) lastMeasurementPacket = packetPool.allocCopy(*p); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); - service.sendToPhone(p); + service->sendToPhone(p); } else { LOG_INFO("Sending packet to mesh\n"); - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR && config.power.is_power_saving) { LOG_DEBUG("Starting next execution in 5 seconds and then going to sleep.\n"); diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index 2e2e4f5287..8a29f9a2e3 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -266,7 +266,7 @@ void AudioModule::sendPayload(NodeNum dest, bool wantReplies) p->decoded.payload.size = tx_encode_frame_index; memcpy(p->decoded.payload.bytes, tx_encode_frame, p->decoded.payload.size); - service.sendToMesh(p); + service->sendToMesh(p); } ProcessMessage AudioModule::handleReceived(const meshtastic_MeshPacket &mp) diff --git a/src/modules/esp32/PaxcounterModule.cpp b/src/modules/esp32/PaxcounterModule.cpp index 8953282345..71810df076 100644 --- a/src/modules/esp32/PaxcounterModule.cpp +++ b/src/modules/esp32/PaxcounterModule.cpp @@ -52,7 +52,7 @@ bool PaxcounterModule::sendInfo(NodeNum dest) p->decoded.want_response = false; p->priority = meshtastic_MeshPacket_Priority_BACKGROUND; - service.sendToMesh(p, RX_SRC_LOCAL, true); + service->sendToMesh(p, RX_SRC_LOCAL, true); paxcounterModule->reportedDataSent = true; diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index ff0f796a1b..7581bbc386 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -211,7 +211,7 @@ bool StoreForwardModule::sendPayload(NodeNum dest, uint32_t last_time) meshtastic_MeshPacket *p = preparePayload(dest, last_time); if (p) { LOG_INFO("*** Sending S&F Payload\n"); - service.sendToMesh(p); + service->sendToMesh(p); this->requestCount++; return true; } @@ -293,7 +293,7 @@ void StoreForwardModule::sendMessage(NodeNum dest, const meshtastic_StoreAndForw p->want_ack = false; p->decoded.want_response = false; - service.sendToMesh(p); + service->sendToMesh(p); } /** @@ -336,7 +336,7 @@ void StoreForwardModule::sendErrorTextMessage(NodeNum dest, bool want_response) if (want_response) { ignoreRequest = true; // This text message counts as response. } - service.sendToMesh(pr); + service->sendToMesh(pr); } /** diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index a7085dffe3..4bb9cd5ebe 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -19,6 +19,8 @@ #include #endif #include "Default.h" +#include "serialization/JSON.h" +#include "serialization/MeshPacketSerializer.h" #include const int reconnectMax = 5; @@ -81,7 +83,7 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) if (jsonPayloadStr.length() <= sizeof(p->decoded.payload.bytes)) { memcpy(p->decoded.payload.bytes, jsonPayloadStr.c_str(), jsonPayloadStr.length()); p->decoded.payload.size = jsonPayloadStr.length(); - service.sendToMesh(p, RX_SRC_LOCAL); + service->sendToMesh(p, RX_SRC_LOCAL); } else { LOG_WARN("Received MQTT json payload too long, dropping\n"); } @@ -112,7 +114,7 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Position_msg, &pos); // make the Data protobuf from position - service.sendToMesh(p, RX_SRC_LOCAL); + service->sendToMesh(p, RX_SRC_LOCAL); } else { LOG_DEBUG("JSON Ignoring downlink message with unsupported type.\n"); } @@ -243,7 +245,7 @@ bool MQTT::publish(const char *topic, const char *payload, bool retained) strcpy(msg->topic, topic); strcpy(msg->payload_variant.text, payload); msg->retained = retained; - service.sendMqttMessageToClientProxy(msg); + service->sendMqttMessageToClientProxy(msg); return true; } #if HAS_NETWORKING @@ -263,7 +265,7 @@ bool MQTT::publish(const char *topic, const uint8_t *payload, size_t length, boo msg->payload_variant.data.size = length; memcpy(msg->payload_variant.data.bytes, payload, length); msg->retained = retained; - service.sendMqttMessageToClientProxy(msg); + service->sendMqttMessageToClientProxy(msg); return true; } #if HAS_NETWORKING @@ -459,7 +461,7 @@ void MQTT::publishQueuedMessages() #ifndef ARCH_NRF52 // JSON is not supported on nRF52, see issue #2804 if (moduleConfig.mqtt.json_enabled) { // handle json topic - auto jsonString = this->meshPacketToJson(env->packet); + auto jsonString = MeshPacketSerializer::JsonSerialize(env->packet); if (jsonString.length() != 0) { std::string topicJson = jsonTopic + env->channel_id + "/" + owner.id; LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(), @@ -520,7 +522,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, const meshtastic_MeshPacket & #ifndef ARCH_NRF52 // JSON is not supported on nRF52, see issue #2804 if (moduleConfig.mqtt.json_enabled) { // handle json topic - auto jsonString = this->meshPacketToJson((meshtastic_MeshPacket *)&mp_decoded); + auto jsonString = MeshPacketSerializer::JsonSerialize((meshtastic_MeshPacket *)&mp_decoded); if (jsonString.length() != 0) { std::string topicJson = jsonTopic + channelId + "/" + owner.id; LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(), @@ -621,304 +623,6 @@ void MQTT::perhapsReportToMap() } } -// converts a downstream packet into a json message -std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) -{ - // the created jsonObj is immutable after creation, so - // we need to do the heavy lifting before assembling it. - std::string msgType; - JSONObject jsonObj; - - if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { - JSONObject msgPayload; - switch (mp->decoded.portnum) { - case meshtastic_PortNum_TEXT_MESSAGE_APP: { - msgType = "text"; - // convert bytes to string - LOG_DEBUG("got text message of size %u\n", mp->decoded.payload.size); - char payloadStr[(mp->decoded.payload.size) + 1]; - memcpy(payloadStr, mp->decoded.payload.bytes, mp->decoded.payload.size); - payloadStr[mp->decoded.payload.size] = 0; // null terminated string - // check if this is a JSON payload - JSONValue *json_value = JSON::Parse(payloadStr); - if (json_value != NULL) { - LOG_INFO("text message payload is of type json\n"); - // if it is, then we can just use the json object - jsonObj["payload"] = json_value; - } else { - // if it isn't, then we need to create a json object - // with the string as the value - LOG_INFO("text message payload is of type plaintext\n"); - msgPayload["text"] = new JSONValue(payloadStr); - jsonObj["payload"] = new JSONValue(msgPayload); - } - break; - } - case meshtastic_PortNum_TELEMETRY_APP: { - msgType = "telemetry"; - meshtastic_Telemetry scratch; - meshtastic_Telemetry *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Telemetry_msg, &scratch)) { - decoded = &scratch; - if (decoded->which_variant == meshtastic_Telemetry_device_metrics_tag) { - msgPayload["battery_level"] = new JSONValue((unsigned int)decoded->variant.device_metrics.battery_level); - msgPayload["voltage"] = new JSONValue(decoded->variant.device_metrics.voltage); - msgPayload["channel_utilization"] = new JSONValue(decoded->variant.device_metrics.channel_utilization); - msgPayload["air_util_tx"] = new JSONValue(decoded->variant.device_metrics.air_util_tx); - msgPayload["uptime_seconds"] = new JSONValue((unsigned int)decoded->variant.device_metrics.uptime_seconds); - } else if (decoded->which_variant == meshtastic_Telemetry_environment_metrics_tag) { - msgPayload["temperature"] = new JSONValue(decoded->variant.environment_metrics.temperature); - msgPayload["relative_humidity"] = new JSONValue(decoded->variant.environment_metrics.relative_humidity); - msgPayload["barometric_pressure"] = new JSONValue(decoded->variant.environment_metrics.barometric_pressure); - msgPayload["gas_resistance"] = new JSONValue(decoded->variant.environment_metrics.gas_resistance); - msgPayload["voltage"] = new JSONValue(decoded->variant.environment_metrics.voltage); - msgPayload["current"] = new JSONValue(decoded->variant.environment_metrics.current); - msgPayload["lux"] = new JSONValue(decoded->variant.environment_metrics.lux); - msgPayload["white_lux"] = new JSONValue(decoded->variant.environment_metrics.white_lux); - msgPayload["iaq"] = new JSONValue((uint)decoded->variant.environment_metrics.iaq); - msgPayload["wind_speed"] = new JSONValue(decoded->variant.environment_metrics.wind_speed); - msgPayload["wind_direction"] = new JSONValue((uint)decoded->variant.environment_metrics.wind_direction); - msgPayload["wind_gust"] = new JSONValue(decoded->variant.environment_metrics.wind_gust); - msgPayload["wind_lull"] = new JSONValue(decoded->variant.environment_metrics.wind_lull); - } else if (decoded->which_variant == meshtastic_Telemetry_power_metrics_tag) { - msgPayload["voltage_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_voltage); - msgPayload["current_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_current); - msgPayload["voltage_ch2"] = new JSONValue(decoded->variant.power_metrics.ch2_voltage); - msgPayload["current_ch2"] = new JSONValue(decoded->variant.power_metrics.ch2_current); - msgPayload["voltage_ch3"] = new JSONValue(decoded->variant.power_metrics.ch3_voltage); - msgPayload["current_ch3"] = new JSONValue(decoded->variant.power_metrics.ch3_current); - } - jsonObj["payload"] = new JSONValue(msgPayload); - } else { - LOG_ERROR("Error decoding protobuf for telemetry message!\n"); - } - break; - } - case meshtastic_PortNum_NODEINFO_APP: { - msgType = "nodeinfo"; - meshtastic_User scratch; - meshtastic_User *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_User_msg, &scratch)) { - decoded = &scratch; - msgPayload["id"] = new JSONValue(decoded->id); - msgPayload["longname"] = new JSONValue(decoded->long_name); - msgPayload["shortname"] = new JSONValue(decoded->short_name); - msgPayload["hardware"] = new JSONValue(decoded->hw_model); - jsonObj["payload"] = new JSONValue(msgPayload); - } else { - LOG_ERROR("Error decoding protobuf for nodeinfo message!\n"); - } - break; - } - case meshtastic_PortNum_POSITION_APP: { - msgType = "position"; - meshtastic_Position scratch; - meshtastic_Position *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Position_msg, &scratch)) { - decoded = &scratch; - if ((int)decoded->time) { - msgPayload["time"] = new JSONValue((unsigned int)decoded->time); - } - if ((int)decoded->timestamp) { - msgPayload["timestamp"] = new JSONValue((unsigned int)decoded->timestamp); - } - msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i); - msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i); - if ((int)decoded->altitude) { - msgPayload["altitude"] = new JSONValue((int)decoded->altitude); - } - if ((int)decoded->ground_speed) { - msgPayload["ground_speed"] = new JSONValue((unsigned int)decoded->ground_speed); - } - if (int(decoded->ground_track)) { - msgPayload["ground_track"] = new JSONValue((unsigned int)decoded->ground_track); - } - if (int(decoded->sats_in_view)) { - msgPayload["sats_in_view"] = new JSONValue((unsigned int)decoded->sats_in_view); - } - if ((int)decoded->PDOP) { - msgPayload["PDOP"] = new JSONValue((int)decoded->PDOP); - } - if ((int)decoded->HDOP) { - msgPayload["HDOP"] = new JSONValue((int)decoded->HDOP); - } - if ((int)decoded->VDOP) { - msgPayload["VDOP"] = new JSONValue((int)decoded->VDOP); - } - if ((int)decoded->precision_bits) { - msgPayload["precision_bits"] = new JSONValue((int)decoded->precision_bits); - } - jsonObj["payload"] = new JSONValue(msgPayload); - } else { - LOG_ERROR("Error decoding protobuf for position message!\n"); - } - break; - } - case meshtastic_PortNum_WAYPOINT_APP: { - msgType = "position"; - meshtastic_Waypoint scratch; - meshtastic_Waypoint *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Waypoint_msg, &scratch)) { - decoded = &scratch; - msgPayload["id"] = new JSONValue((unsigned int)decoded->id); - msgPayload["name"] = new JSONValue(decoded->name); - msgPayload["description"] = new JSONValue(decoded->description); - msgPayload["expire"] = new JSONValue((unsigned int)decoded->expire); - msgPayload["locked_to"] = new JSONValue((unsigned int)decoded->locked_to); - msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i); - msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i); - jsonObj["payload"] = new JSONValue(msgPayload); - } else { - LOG_ERROR("Error decoding protobuf for position message!\n"); - } - break; - } - case meshtastic_PortNum_NEIGHBORINFO_APP: { - msgType = "neighborinfo"; - meshtastic_NeighborInfo scratch; - meshtastic_NeighborInfo *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_NeighborInfo_msg, - &scratch)) { - decoded = &scratch; - msgPayload["node_id"] = new JSONValue((unsigned int)decoded->node_id); - msgPayload["node_broadcast_interval_secs"] = new JSONValue((unsigned int)decoded->node_broadcast_interval_secs); - msgPayload["last_sent_by_id"] = new JSONValue((unsigned int)decoded->last_sent_by_id); - msgPayload["neighbors_count"] = new JSONValue(decoded->neighbors_count); - JSONArray neighbors; - for (uint8_t i = 0; i < decoded->neighbors_count; i++) { - JSONObject neighborObj; - neighborObj["node_id"] = new JSONValue((unsigned int)decoded->neighbors[i].node_id); - neighborObj["snr"] = new JSONValue((int)decoded->neighbors[i].snr); - neighbors.push_back(new JSONValue(neighborObj)); - } - msgPayload["neighbors"] = new JSONValue(neighbors); - jsonObj["payload"] = new JSONValue(msgPayload); - } else { - LOG_ERROR("Error decoding protobuf for neighborinfo message!\n"); - } - break; - } - case meshtastic_PortNum_TRACEROUTE_APP: { - if (mp->decoded.request_id) { // Only report the traceroute response - msgType = "traceroute"; - meshtastic_RouteDiscovery scratch; - meshtastic_RouteDiscovery *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_RouteDiscovery_msg, - &scratch)) { - decoded = &scratch; - JSONArray route; // Route this message took - // Lambda function for adding a long name to the route - auto addToRoute = [](JSONArray *route, NodeNum num) { - char long_name[40] = "Unknown"; - meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(num); - bool name_known = node ? node->has_user : false; - if (name_known) - memcpy(long_name, node->user.long_name, sizeof(long_name)); - route->push_back(new JSONValue(long_name)); - }; - addToRoute(&route, mp->to); // Started at the original transmitter (destination of response) - for (uint8_t i = 0; i < decoded->route_count; i++) { - addToRoute(&route, decoded->route[i]); - } - addToRoute(&route, mp->from); // Ended at the original destination (source of response) - - msgPayload["route"] = new JSONValue(route); - jsonObj["payload"] = new JSONValue(msgPayload); - } else { - LOG_ERROR("Error decoding protobuf for traceroute message!\n"); - } - } - break; - } - case meshtastic_PortNum_DETECTION_SENSOR_APP: { - msgType = "detection"; - char payloadStr[(mp->decoded.payload.size) + 1]; - memcpy(payloadStr, mp->decoded.payload.bytes, mp->decoded.payload.size); - payloadStr[mp->decoded.payload.size] = 0; // null terminated string - msgPayload["text"] = new JSONValue(payloadStr); - jsonObj["payload"] = new JSONValue(msgPayload); - break; - } -#ifdef ARCH_ESP32 - case meshtastic_PortNum_PAXCOUNTER_APP: { - msgType = "paxcounter"; - meshtastic_Paxcount scratch; - meshtastic_Paxcount *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Paxcount_msg, &scratch)) { - decoded = &scratch; - msgPayload["wifi_count"] = new JSONValue((unsigned int)decoded->wifi); - msgPayload["ble_count"] = new JSONValue((unsigned int)decoded->ble); - msgPayload["uptime"] = new JSONValue((unsigned int)decoded->uptime); - jsonObj["payload"] = new JSONValue(msgPayload); - } else { - LOG_ERROR("Error decoding protobuf for Paxcount message!\n"); - } - break; - } -#endif - case meshtastic_PortNum_REMOTE_HARDWARE_APP: { - meshtastic_HardwareMessage scratch; - meshtastic_HardwareMessage *decoded = NULL; - memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_HardwareMessage_msg, - &scratch)) { - decoded = &scratch; - if (decoded->type == meshtastic_HardwareMessage_Type_GPIOS_CHANGED) { - msgType = "gpios_changed"; - msgPayload["gpio_value"] = new JSONValue((unsigned int)decoded->gpio_value); - jsonObj["payload"] = new JSONValue(msgPayload); - } else if (decoded->type == meshtastic_HardwareMessage_Type_READ_GPIOS_REPLY) { - msgType = "gpios_read_reply"; - msgPayload["gpio_value"] = new JSONValue((unsigned int)decoded->gpio_value); - msgPayload["gpio_mask"] = new JSONValue((unsigned int)decoded->gpio_mask); - jsonObj["payload"] = new JSONValue(msgPayload); - } - } else { - LOG_ERROR("Error decoding protobuf for RemoteHardware message!\n"); - } - break; - } - // add more packet types here if needed - default: - break; - } - } else { - LOG_WARN("Couldn't convert encrypted payload of MeshPacket to JSON\n"); - } - - jsonObj["id"] = new JSONValue((unsigned int)mp->id); - jsonObj["timestamp"] = new JSONValue((unsigned int)mp->rx_time); - jsonObj["to"] = new JSONValue((unsigned int)mp->to); - jsonObj["from"] = new JSONValue((unsigned int)mp->from); - jsonObj["channel"] = new JSONValue((unsigned int)mp->channel); - jsonObj["type"] = new JSONValue(msgType.c_str()); - jsonObj["sender"] = new JSONValue(owner.id); - if (mp->rx_rssi != 0) - jsonObj["rssi"] = new JSONValue((int)mp->rx_rssi); - if (mp->rx_snr != 0) - jsonObj["snr"] = new JSONValue((float)mp->rx_snr); - if (mp->hop_start != 0 && mp->hop_limit <= mp->hop_start) { - jsonObj["hops_away"] = new JSONValue((unsigned int)(mp->hop_start - mp->hop_limit)); - jsonObj["hop_start"] = new JSONValue((unsigned int)(mp->hop_start)); - } - - // serialize and write it to the stream - JSONValue *value = new JSONValue(jsonObj); - std::string jsonStr = value->Stringify(); - - LOG_INFO("serialized json message: %s\n", jsonStr.c_str()); - - delete value; - return jsonStr; -} - bool MQTT::isValidJsonEnvelope(JSONObject &json) { // if "sender" is provided, avoid processing packets we uplinked diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index d68f1b88d7..ba09877839 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -5,7 +5,7 @@ #include "concurrency/OSThread.h" #include "mesh/Channels.h" #include "mesh/generated/meshtastic/mqtt.pb.h" -#include "mqtt/JSON.h" +#include "serialization/JSON.h" #if HAS_WIFI #include #if !defined(ARCH_PORTDUINO) @@ -106,9 +106,6 @@ class MQTT : private concurrency::OSThread /// Called when a new publish arrives from the MQTT server void onReceive(char *topic, byte *payload, size_t length); - /// Called when a new publish arrives from the MQTT server - std::string meshPacketToJson(meshtastic_MeshPacket *mp); - void publishQueuedMessages(); void publishNodeInfo(); diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 3910f718f1..6bce498aba 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -195,16 +195,16 @@ void cpuDeepSleep(uint32_t msecToWake) button(s), maybe we should not include any other GPIOs... */ #if SOC_RTCIO_HOLD_SUPPORTED - static const uint8_t rtcGpios[] = {/* 0, */ 2, - /* 4, */ + static const uint8_t rtcGpios[] = { +#ifndef HELTEC_VISION_MASTER_E213 + // For this variant, >20mA leaks through the display if pin 2 held + // Todo: check if it's safe to remove this pin for all variants + 2, +#endif #ifndef USE_JTAG - 13, - /* 14, */ /* 15, */ + 13, #endif - /* 25, */ /* 26, */ /* 27, */ - /* 32, */ /* 33, */ 34, 35, - /* 36, */ 37 - /* 38, 39 */}; + 34, 35, 37}; for (int i = 0; i < sizeof(rtcGpios); i++) rtc_gpio_isolate((gpio_num_t)rtcGpios[i]); diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index b66552a284..2b285ec2e2 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -60,6 +60,8 @@ #define HW_VENDOR meshtastic_HardwareModel_NRF52_PROMICRO_DIY #elif defined(WIO_WM1110) #define HW_VENDOR meshtastic_HardwareModel_WIO_WM1110 +#elif defined(TRACKER_T1000_E) +#define HW_VENDOR meshtastic_HardwareModel_TRACKER_T1000_E #elif defined(PRIVATE_HW) || defined(FEATHER_DIY) #define HW_VENDOR meshtastic_HardwareModel_PRIVATE_HW #else @@ -86,10 +88,6 @@ #endif -#ifndef TTGO_T_ECHO -#define GPS_UBLOX -#endif - #define LED_PIN PIN_LED1 // LED1 on nrf52840-DK #ifdef PIN_BUTTON1 @@ -118,4 +116,4 @@ #if !defined(PIN_SERIAL_RX) && !defined(NRF52840_XXAA) // No serial ports on this board - ONLY use segger in memory console #define USE_SEGGER -#endif \ No newline at end of file +#endif diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 95261bd22d..f1204c5cff 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -17,6 +17,7 @@ std::map settingsMap; std::map settingsStrings; +std::ofstream traceFile; char *configPath = nullptr; // FIXME - move setBluetoothEnable into a HALPlatform class @@ -97,6 +98,7 @@ void portduinoSetup() settingsStrings[webserverrootpath] = ""; settingsStrings[spidev] = ""; settingsStrings[displayspidev] = ""; + settingsMap[spiSpeed] = 2000000; YAML::Node yamlConfig; @@ -135,7 +137,9 @@ void portduinoSetup() try { if (yamlConfig["Logging"]) { - if (yamlConfig["Logging"]["LogLevel"].as("info") == "debug") { + if (yamlConfig["Logging"]["LogLevel"].as("info") == "trace") { + settingsMap[logoutputlevel] = level_trace; + } else if (yamlConfig["Logging"]["LogLevel"].as("info") == "debug") { settingsMap[logoutputlevel] = level_debug; } else if (yamlConfig["Logging"]["LogLevel"].as("info") == "info") { settingsMap[logoutputlevel] = level_info; @@ -144,6 +148,7 @@ void portduinoSetup() } else if (yamlConfig["Logging"]["LogLevel"].as("info") == "error") { settingsMap[logoutputlevel] = level_error; } + settingsStrings[traceFilename] = yamlConfig["Logging"]["TraceFile"].as(""); } if (yamlConfig["Lora"]) { settingsMap[use_sx1262] = false; @@ -170,6 +175,7 @@ void portduinoSetup() settingsMap[rxen] = yamlConfig["Lora"]["RXen"].as(RADIOLIB_NC); settingsMap[gpiochip] = yamlConfig["Lora"]["gpiochip"].as(0); settingsMap[ch341Quirk] = yamlConfig["Lora"]["ch341_quirk"].as(false); + settingsMap[spiSpeed] = yamlConfig["Lora"]["spiSpeed"].as(2000000); gpioChipName += std::to_string(settingsMap[gpiochip]); settingsStrings[spidev] = "/dev/" + yamlConfig["Lora"]["spidev"].as("spidev0.0"); @@ -280,6 +286,8 @@ void portduinoSetup() } settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(200); + settingsMap[maxtophone] = (yamlConfig["General"]["MaxMessageQueue"]).as(100); + } catch (YAML::Exception &e) { std::cout << "*** Exception " << e.what() << std::endl; exit(EXIT_FAILURE); @@ -349,6 +357,14 @@ void portduinoSetup() if (settingsStrings[spidev] != "") { SPI.begin(settingsStrings[spidev].c_str()); } + if (settingsStrings[traceFilename] != "") { + try { + traceFile.open(settingsStrings[traceFilename], std::ios::out | std::ios::app); + } catch (std::ofstream::failure &e) { + std::cout << "*** traceFile Exception " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + } return; } diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 57b0e25641..c0777aa514 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -1,4 +1,5 @@ #pragma once +#include #include enum configNames { @@ -18,6 +19,7 @@ enum configNames { user, gpiochip, spidev, + spiSpeed, i2cdev, has_gps, touchscreenModule, @@ -47,15 +49,18 @@ enum configNames { keyboardDevice, pointerDevice, logoutputlevel, + traceFilename, webserver, webserverport, webserverrootpath, + maxtophone, maxnodes }; enum { no_screen, x11, st7789, st7735, st7735s, st7796, ili9341, ili9486, ili9488, hx8357d }; enum { no_touchscreen, xpt2046, stmpe610, gt911, ft5x06 }; -enum { level_error, level_warn, level_info, level_debug }; +enum { level_error, level_warn, level_info, level_debug, level_trace }; extern std::map settingsMap; extern std::map settingsStrings; +extern std::ofstream traceFile; int initGPIOPin(int pinNum, std::string gpioChipname); \ No newline at end of file diff --git a/src/platform/portduino/SimRadio.cpp b/src/platform/portduino/SimRadio.cpp index d0072cf35e..12757fe6ba 100644 --- a/src/platform/portduino/SimRadio.cpp +++ b/src/platform/portduino/SimRadio.cpp @@ -199,8 +199,8 @@ void SimRadio::startSend(meshtastic_MeshPacket *txp) pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Compressed_msg, &c); p->decoded.portnum = meshtastic_PortNum_SIMULATOR_APP; - service.sendQueueStatusToPhone(router->getQueueStatus(), 0, p->id); - service.sendToPhone(p); // Sending back to simulator + service->sendQueueStatusToPhone(router->getQueueStatus(), 0, p->id); + service->sendToPhone(p); // Sending back to simulator } void SimRadio::startReceive(meshtastic_MeshPacket *p) diff --git a/src/platform/stm32wl/InternalFileSystem.cpp b/src/platform/stm32wl/InternalFileSystem.cpp deleted file mode 100644 index d42a646a56..0000000000 --- a/src/platform/stm32wl/InternalFileSystem.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 hathach for Adafruit Industries - * - * 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 "InternalFileSystem.h" -#include - -//--------------------------------------------------------------------+ -// LFS Disk IO -//--------------------------------------------------------------------+ - -static inline uint32_t lba2addr(uint32_t block) -{ - return ((uint32_t)LFS_FLASH_ADDR) + block * LFS_BLOCK_SIZE; -} - -static int _internal_flash_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) -{ - (void)c; - - uint32_t addr = lba2addr(block) + off; - uint8_t prom; - - for (int i = 0; i < size; i++) { - prom = EEPROM.read(addr + i); - memcpy((char *)buffer + i, &prom, 1); - } - return 0; -} - -// Program a region in a block. The block must have previously -// been erased. Negative error codes are propagated to the user. -// May return LFS_ERR_CORRUPT if the block should be considered bad. -static int _internal_flash_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) -{ - (void)c; - - uint32_t addr = lba2addr(block) + off; - uint8_t prom; - - for (int i = 0; i < size; i++) { - memcpy(&prom, (char *)buffer + i, 1); - EEPROM.update(addr + i, prom); - } - return 0; -} - -// Erase a block. A block must be erased before being programmed. -// The state of an erased block is undefined. Negative error codes -// are propagated to the user. -// May return LFS_ERR_CORRUPT if the block should be considered bad. -static int _internal_flash_erase(const struct lfs_config *c, lfs_block_t block) -{ - (void)c; - - uint32_t addr = lba2addr(block); - - // implement as write 0xff to whole block address - for (int i = 0; i < LFS_BLOCK_SIZE; i++) { - EEPROM.update(addr, 0xff); - } - - return 0; -} - -// Sync the state of the underlying block device. Negative error codes -// are propagated to the user. -static int _internal_flash_sync(const struct lfs_config *c) -{ - // we don't use a ram cache, this is a noop - return 0; -} - -static struct lfs_config _InternalFSConfig = {.context = NULL, - - .read = _internal_flash_read, - .prog = _internal_flash_prog, - .erase = _internal_flash_erase, - .sync = _internal_flash_sync, - - .read_size = LFS_CACHE_SIZE, - .prog_size = LFS_CACHE_SIZE, - .block_size = LFS_BLOCK_SIZE, - .block_count = LFS_FLASH_TOTAL_SIZE / LFS_BLOCK_SIZE, - .block_cycles = - 500, // protection against wear leveling (suggested values between 100-1000) - .cache_size = LFS_CACHE_SIZE, - .lookahead_size = LFS_CACHE_SIZE, - - .read_buffer = lfs_read_buffer, - .prog_buffer = lfs_prog_buffer, - .lookahead_buffer = lfs_lookahead_buffer}; - -InternalFileSystem InternalFS; - -//--------------------------------------------------------------------+ -// -//--------------------------------------------------------------------+ - -InternalFileSystem::InternalFileSystem(void) : LittleFS(&_InternalFSConfig) {} - -bool InternalFileSystem::begin(void) -{ - // failed to mount, erase all sector then format and mount again - if (!LittleFS::begin()) { - // Erase all sectors of internal flash region for Filesystem. - // implement as write 0xff to whole block address - for (uint32_t addr = LFS_FLASH_ADDR; addr < (LFS_FLASH_ADDR + LFS_FLASH_TOTAL_SIZE); addr++) { - EEPROM.update(addr, 0xff); - } - - // lfs format - this->format(); - - // mount again if still failed, give up - if (!LittleFS::begin()) - return false; - } - - return true; -} diff --git a/src/platform/stm32wl/InternalFileSystem.h b/src/platform/stm32wl/InternalFileSystem.h deleted file mode 100644 index 66344194e1..0000000000 --- a/src/platform/stm32wl/InternalFileSystem.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 hathach for Adafruit Industries - * - * 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 INTERNALFILESYSTEM_H_ -#define INTERNALFILESYSTEM_H_ - -#include "LittleFS.h" - -// The EEPROM Library assumes our usable flash area starts at logical 0 -#define LFS_FLASH_ADDR 0 - -// use the built in EEPROM emulation. Total Size is 2Kbyte -#define LFS_BLOCK_SIZE 128 // min. block size is 128 to fit CTZ pointers -#define LFS_CACHE_SIZE 16 - -#define LFS_FLASH_TOTAL_SIZE FLASH_PAGE_SIZE - -static uint8_t lfs_read_buffer[LFS_CACHE_SIZE] = {0}; -static uint8_t lfs_prog_buffer[LFS_CACHE_SIZE] = {0}; -static uint8_t lfs_lookahead_buffer[LFS_CACHE_SIZE] = {0}; - -class InternalFileSystem : public LittleFS -{ - public: - InternalFileSystem(void); - - // overwrite to also perform low level format (sector erase of whole flash region) - bool begin(void); -}; - -extern InternalFileSystem InternalFS; - -#endif /* INTERNALFILESYSTEM_H_ */ diff --git a/src/platform/stm32wl/LittleFS.cpp b/src/platform/stm32wl/LittleFS.cpp deleted file mode 100644 index b1267d88a6..0000000000 --- a/src/platform/stm32wl/LittleFS.cpp +++ /dev/null @@ -1,258 +0,0 @@ -#include -#include - -#include "LittleFS.h" - -using namespace LittleFS_Namespace; - -//--------------------------------------------------------------------+ -// Implementation -//--------------------------------------------------------------------+ - -LittleFS::LittleFS(void) : LittleFS(NULL) {} - -LittleFS::LittleFS(struct lfs_config *cfg) -{ - memset(&_lfs, 0, sizeof(_lfs)); - _lfs_cfg = cfg; - _mounted = false; - _mutex = xSemaphoreCreateMutexStatic(&this->_MutexStorageSpace); -} - -LittleFS::~LittleFS() {} - -// Initialize and mount the file system -// Return true if mounted successfully else probably corrupted. -// User should format the disk and try again -bool LittleFS::begin(struct lfs_config *cfg) -{ - _lockFS(); - - bool ret; - // not a loop, just an quick way to short-circuit on error - do { - if (_mounted) { - ret = true; - break; - } - if (cfg) { - _lfs_cfg = cfg; - } - if (nullptr == _lfs_cfg) { - ret = false; - break; - } - // actually attempt to mount, and log error if one occurs - int err = lfs_mount(&_lfs, _lfs_cfg); - PRINT_LFS_ERR(err); - _mounted = (err == LFS_ERR_OK); - ret = _mounted; - } while (0); - - _unlockFS(); - return ret; -} - -// Tear down and unmount file system -void LittleFS::end(void) -{ - _lockFS(); - - if (_mounted) { - _mounted = false; - int err = lfs_unmount(&_lfs); - PRINT_LFS_ERR(err); - (void)err; - } - - _unlockFS(); -} - -bool LittleFS::format(void) -{ - _lockFS(); - - int err = LFS_ERR_OK; - bool attemptMount = _mounted; - // not a loop, just an quick way to short-circuit on error - do { - // if already mounted: umount first -> format -> remount - if (_mounted) { - _mounted = false; - err = lfs_unmount(&_lfs); - if (LFS_ERR_OK != err) { - PRINT_LFS_ERR(err); - break; - } - } - err = lfs_format(&_lfs, _lfs_cfg); - if (LFS_ERR_OK != err) { - PRINT_LFS_ERR(err); - break; - } - - if (attemptMount) { - err = lfs_mount(&_lfs, _lfs_cfg); - if (LFS_ERR_OK != err) { - PRINT_LFS_ERR(err); - break; - } - _mounted = true; - } - // success! - } while (0); - - _unlockFS(); - return LFS_ERR_OK == err; -} - -// Open a file or folder -LittleFS_Namespace::File LittleFS::open(char const *filepath, uint8_t mode) -{ - // No lock is required here ... the File() object will synchronize with the mutex provided - return LittleFS_Namespace::File(filepath, mode, *this); -} - -// Check if file or folder exists -bool LittleFS::exists(char const *filepath) -{ - struct lfs_info info; - _lockFS(); - - bool ret = (0 == lfs_stat(&_lfs, filepath, &info)); - - _unlockFS(); - return ret; -} - -// Create a directory, create intermediate parent if needed -bool LittleFS::mkdir(char const *filepath) -{ - bool ret = true; - const char *slash = filepath; - if (slash[0] == '/') - slash++; // skip root '/' - - _lockFS(); - - // make intermediate parent directory(ies) - while (NULL != (slash = strchr(slash, '/'))) { - char parent[slash - filepath + 1] = {0}; - memcpy(parent, filepath, slash - filepath); - - int rc = lfs_mkdir(&_lfs, parent); - if (rc != LFS_ERR_OK && rc != LFS_ERR_EXIST) { - PRINT_LFS_ERR(rc); - ret = false; - break; - } - slash++; - } - // make the final requested directory - if (ret) { - int rc = lfs_mkdir(&_lfs, filepath); - if (rc != LFS_ERR_OK && rc != LFS_ERR_EXIST) { - PRINT_LFS_ERR(rc); - ret = false; - } - } - - _unlockFS(); - return ret; -} - -// Remove a file -bool LittleFS::remove(char const *filepath) -{ - _lockFS(); - - int err = lfs_remove(&_lfs, filepath); - PRINT_LFS_ERR(err); - - _unlockFS(); - return LFS_ERR_OK == err; -} - -// Rename a file -bool LittleFS::rename(char const *oldfilepath, char const *newfilepath) -{ - _lockFS(); - - int err = lfs_rename(&_lfs, oldfilepath, newfilepath); - PRINT_LFS_ERR(err); - - _unlockFS(); - return LFS_ERR_OK == err; -} - -// Remove a folder -bool LittleFS::rmdir(char const *filepath) -{ - _lockFS(); - - int err = lfs_remove(&_lfs, filepath); - PRINT_LFS_ERR(err); - - _unlockFS(); - return LFS_ERR_OK == err; -} - -// Remove a folder recursively -bool LittleFS::rmdir_r(char const *filepath) -{ - /* adafruit: lfs is modified to remove non-empty folder, - According to below issue, comment these 2 line won't corrupt filesystem - at least when using LFS v1. If moving to LFS v2, see tracked issue - to see if issues (such as the orphans in threaded linked list) are resolved. - https://github.com/ARMmbed/littlefs/issues/43 - */ - _lockFS(); - - int err = lfs_remove(&_lfs, filepath); - PRINT_LFS_ERR(err); - - _unlockFS(); - return LFS_ERR_OK == err; -} - -//------------- Debug -------------// -#if CFG_DEBUG - -const char *dbg_strerr_lfs(int32_t err) -{ - switch (err) { - case LFS_ERR_OK: - return "LFS_ERR_OK"; - case LFS_ERR_IO: - return "LFS_ERR_IO"; - case LFS_ERR_CORRUPT: - return "LFS_ERR_CORRUPT"; - case LFS_ERR_NOENT: - return "LFS_ERR_NOENT"; - case LFS_ERR_EXIST: - return "LFS_ERR_EXIST"; - case LFS_ERR_NOTDIR: - return "LFS_ERR_NOTDIR"; - case LFS_ERR_ISDIR: - return "LFS_ERR_ISDIR"; - case LFS_ERR_NOTEMPTY: - return "LFS_ERR_NOTEMPTY"; - case LFS_ERR_BADF: - return "LFS_ERR_BADF"; - case LFS_ERR_INVAL: - return "LFS_ERR_INVAL"; - case LFS_ERR_NOSPC: - return "LFS_ERR_NOSPC"; - case LFS_ERR_NOMEM: - return "LFS_ERR_NOMEM"; - - default: - static char errcode[10]; - sprintf(errcode, "%ld", err); - return errcode; - } - - return NULL; -} - -#endif diff --git a/src/platform/stm32wl/LittleFS.h b/src/platform/stm32wl/LittleFS.h deleted file mode 100644 index 4a0b01af2b..0000000000 --- a/src/platform/stm32wl/LittleFS.h +++ /dev/null @@ -1,85 +0,0 @@ - -#ifndef LITTLEFS_H_ -#define LITTLEFS_H_ - -#include - -#include "lfs.h" - -#include "LittleFS_File.h" - -#include "FreeRTOS.h" // tied to FreeRTOS for serialization -#include "semphr.h" - -class LittleFS -{ - public: - LittleFS(void); - explicit LittleFS(struct lfs_config *cfg); - virtual ~LittleFS(); - - bool begin(struct lfs_config *cfg = NULL); - void end(void); - - // Open the specified file/directory with the supplied mode (e.g. read or - // write, etc). Returns a File object for interacting with the file. - // Note that currently only one file can be open at a time. - LittleFS_Namespace::File open(char const *filename, uint8_t mode = LittleFS_Namespace::FILE_O_READ); - - // Methods to determine if the requested file path exists. - bool exists(char const *filepath); - - // Create the requested directory hierarchy--if intermediate directories - // do not exist they will be created. - bool mkdir(char const *filepath); - - // Delete the file. - bool remove(char const *filepath); - - // Rename the file. - bool rename(char const *oldfilepath, char const *newfilepath); - - // Delete a folder (must be empty) - bool rmdir(char const *filepath); - - // Delete a folder (recursively) - bool rmdir_r(char const *filepath); - - // format file system - bool format(void); - - /*------------------------------------------------------------------*/ - /* INTERNAL USAGE ONLY - * Although declare as public, it is meant to be invoked by internal - * code. User should not call these directly - *------------------------------------------------------------------*/ - lfs_t *_getFS(void) { return &_lfs; } - void _lockFS(void) { xSemaphoreTake(_mutex, portMAX_DELAY); } - void _unlockFS(void) { xSemaphoreGive(_mutex); } - - protected: - bool _mounted; - struct lfs_config *_lfs_cfg; - lfs_t _lfs; - SemaphoreHandle_t _mutex; - - private: - StaticSemaphore_t _MutexStorageSpace; -}; - -#if !CFG_DEBUG -#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, NULL) -#define PRINT_LFS_ERR(_err) -#else -#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, dbg_strerr_lfs) -#define PRINT_LFS_ERR(_err) \ - do { \ - if (_err) { \ - VERIFY_MESS((long int)_err, dbg_strerr_lfs); \ - } \ - } while (0) // LFS_ERR are of type int, VERIFY_MESS expects long_int - -const char *dbg_strerr_lfs(int32_t err); -#endif - -#endif /* LITTLEFS_H_ */ diff --git a/src/platform/stm32wl/LittleFS_File.cpp b/src/platform/stm32wl/LittleFS_File.cpp deleted file mode 100644 index 548a3d3009..0000000000 --- a/src/platform/stm32wl/LittleFS_File.cpp +++ /dev/null @@ -1,362 +0,0 @@ -#include - -#include "LittleFS.h" - -#include - -//--------------------------------------------------------------------+ -// MACRO TYPEDEF CONSTANT ENUM DECLARATION -//--------------------------------------------------------------------+ - -using namespace LittleFS_Namespace; - -File::File(LittleFS &fs) -{ - _fs = &fs; - _is_dir = false; - _name[0] = 0; - _dir_path = NULL; - - _dir = NULL; - _file = NULL; -} - -File::File(char const *filename, uint8_t mode, LittleFS &fs) : File(fs) -{ - // public constructor calls public API open(), which will obtain the mutex - this->open(filename, mode); -} - -bool File::_open_file(char const *filepath, uint8_t mode) -{ - int flags = (mode == FILE_O_READ) ? LFS_O_RDONLY : (mode == FILE_O_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0; - - if (flags) { - _file = (lfs_file_t *)malloc(sizeof(lfs_file_t)); - if (!_file) - return false; - - int rc = lfs_file_open(_fs->_getFS(), _file, filepath, flags); - - if (rc) { - // failed to open - PRINT_LFS_ERR(rc); - return false; - } - - // move to end of file - if (mode == FILE_O_WRITE) - lfs_file_seek(_fs->_getFS(), _file, 0, LFS_SEEK_END); - - _is_dir = false; - } - - return true; -} - -bool File::_open_dir(char const *filepath) -{ - _dir = (lfs_dir_t *)malloc(sizeof(lfs_dir_t)); - if (!_dir) - return false; - - int rc = lfs_dir_open(_fs->_getFS(), _dir, filepath); - - if (rc) { - // failed to open - PRINT_LFS_ERR(rc); - return false; - } - - _is_dir = true; - - _dir_path = (char *)malloc(strlen(filepath) + 1); - strcpy(_dir_path, filepath); - - return true; -} - -bool File::open(char const *filepath, uint8_t mode) -{ - bool ret = false; - _fs->_lockFS(); - - ret = this->_open(filepath, mode); - - _fs->_unlockFS(); - return ret; -} - -bool File::_open(char const *filepath, uint8_t mode) -{ - bool ret = false; - - // close if currently opened - if (this->isOpen()) - _close(); - - struct lfs_info info; - int rc = lfs_stat(_fs->_getFS(), filepath, &info); - - if (LFS_ERR_OK == rc) { - // file existed, open file or directory accordingly - ret = (info.type == LFS_TYPE_REG) ? _open_file(filepath, mode) : _open_dir(filepath); - } else if (LFS_ERR_NOENT == rc) { - // file not existed, only proceed with FILE_O_WRITE mode - if (mode == FILE_O_WRITE) - ret = _open_file(filepath, mode); - } else { - PRINT_LFS_ERR(rc); - } - - // save bare file name - if (ret) { - char const *splash = strrchr(filepath, '/'); - strncpy(_name, splash ? (splash + 1) : filepath, LFS_NAME_MAX); - } - return ret; -} - -size_t File::write(uint8_t ch) -{ - return write(&ch, 1); -} - -size_t File::write(uint8_t const *buf, size_t size) -{ - lfs_ssize_t wrcount = 0; - _fs->_lockFS(); - - if (!this->_is_dir) { - wrcount = lfs_file_write(_fs->_getFS(), _file, buf, size); - if (wrcount < 0) { - wrcount = 0; - } - } - - _fs->_unlockFS(); - return wrcount; -} - -int File::read(void) -{ - // this thin wrapper relies on called function to synchronize - int ret = -1; - uint8_t ch; - if (read(&ch, 1) > 0) { - ret = static_cast(ch); - } - return ret; -} - -int File::read(void *buf, uint16_t nbyte) -{ - int ret = 0; - _fs->_lockFS(); - - if (!this->_is_dir) { - ret = lfs_file_read(_fs->_getFS(), _file, buf, nbyte); - } - - _fs->_unlockFS(); - return ret; -} - -int File::peek(void) -{ - int ret = -1; - _fs->_lockFS(); - - if (!this->_is_dir) { - uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); - uint8_t ch = 0; - if (lfs_file_read(_fs->_getFS(), _file, &ch, 1) > 0) { - ret = static_cast(ch); - } - (void)lfs_file_seek(_fs->_getFS(), _file, pos, LFS_SEEK_SET); - } - - _fs->_unlockFS(); - return ret; -} - -int File::available(void) -{ - int ret = 0; - _fs->_lockFS(); - - if (!this->_is_dir) { - uint32_t fsize = lfs_file_size(_fs->_getFS(), _file); - uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); - ret = fsize - pos; - } - - _fs->_unlockFS(); - return ret; -} - -bool File::seek(uint32_t pos) -{ - bool ret = false; - _fs->_lockFS(); - - if (!this->_is_dir) { - ret = lfs_file_seek(_fs->_getFS(), _file, pos, LFS_SEEK_SET) >= 0; - } - - _fs->_unlockFS(); - return ret; -} - -uint32_t File::position(void) -{ - uint32_t ret = 0; - _fs->_lockFS(); - - if (!this->_is_dir) { - ret = lfs_file_tell(_fs->_getFS(), _file); - } - - _fs->_unlockFS(); - return ret; -} - -uint32_t File::size(void) -{ - uint32_t ret = 0; - _fs->_lockFS(); - - if (!this->_is_dir) { - ret = lfs_file_size(_fs->_getFS(), _file); - } - - _fs->_unlockFS(); - return ret; -} - -bool File::truncate(uint32_t pos) -{ - int32_t ret = LFS_ERR_ISDIR; - _fs->_lockFS(); - if (!this->_is_dir) { - ret = lfs_file_truncate(_fs->_getFS(), _file, pos); - } - _fs->_unlockFS(); - return (ret == 0); -} - -bool File::truncate(void) -{ - int32_t ret = LFS_ERR_ISDIR; - _fs->_lockFS(); - if (!this->_is_dir) { - uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); - ret = lfs_file_truncate(_fs->_getFS(), _file, pos); - } - _fs->_unlockFS(); - return (ret == 0); -} - -void File::flush(void) -{ - _fs->_lockFS(); - - if (!this->_is_dir) { - lfs_file_sync(_fs->_getFS(), _file); - } - - _fs->_unlockFS(); - return; -} - -void File::close(void) -{ - _fs->_lockFS(); - this->_close(); - _fs->_unlockFS(); -} - -void File::_close(void) -{ - if (this->isOpen()) { - if (this->_is_dir) { - lfs_dir_close(_fs->_getFS(), _dir); - free(_dir); - _dir = NULL; - - if (this->_dir_path) - free(_dir_path); - _dir_path = NULL; - } else { - lfs_file_close(this->_fs->_getFS(), _file); - free(_file); - _file = NULL; - } - } -} - -File::operator bool(void) -{ - return isOpen(); -} - -bool File::isOpen(void) -{ - return (_file != NULL) || (_dir != NULL); -} - -// WARNING -- although marked as `const`, the values pointed -// to may change. For example, if the same File -// object has `open()` called with a different -// file or directory name, this same pointer will -// suddenly (unexpectedly?) have different values. -char const *File::name(void) -{ - return this->_name; -} - -bool File::isDirectory(void) -{ - return this->_is_dir; -} - -File File::openNextFile(uint8_t mode) -{ - _fs->_lockFS(); - - File ret(*_fs); - if (this->_is_dir) { - struct lfs_info info; - int rc; - - // lfs_dir_read returns 0 when reaching end of directory, 1 if found an entry - // Skip the "." and ".." entries ... - do { - rc = lfs_dir_read(_fs->_getFS(), _dir, &info); - } while (rc == 1 && (!strcmp(".", info.name) || !strcmp("..", info.name))); - - if (rc == 1) { - // string cat name with current folder - char filepath[strlen(_dir_path) + 1 + strlen(info.name) + 1]; // potential for significant stack usage - strcpy(filepath, _dir_path); - if (!(_dir_path[0] == '/' && _dir_path[1] == 0)) - strcat(filepath, "/"); // only add '/' if cwd is not root - strcat(filepath, info.name); - - (void)ret._open(filepath, mode); // return value is ignored ... caller is expected to check isOpened() - } else if (rc < 0) { - PRINT_LFS_ERR(rc); - } - } - _fs->_unlockFS(); - return ret; -} - -void File::rewindDirectory(void) -{ - _fs->_lockFS(); - if (this->_is_dir) { - lfs_dir_rewind(_fs->_getFS(), _dir); - } - _fs->_unlockFS(); -} diff --git a/src/platform/stm32wl/LittleFS_File.h b/src/platform/stm32wl/LittleFS_File.h deleted file mode 100644 index e88a2790d8..0000000000 --- a/src/platform/stm32wl/LittleFS_File.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef LITTLEFS_FILE_H_ -#define LITTLEFS_FILE_H_ - -// Forward declaration -class LittleFS; - -namespace LittleFS_Namespace -{ - -// avoid conflict with other FileSystem FILE_READ/FILE_WRITE -enum { - FILE_O_READ = 0, - FILE_O_WRITE = 1, -}; - -class File : public Stream -{ - public: - explicit File(LittleFS &fs); - File(char const *filename, uint8_t mode, LittleFS &fs); - - public: - bool open(char const *filename, uint8_t mode); - - //------------- Stream API -------------// - virtual size_t write(uint8_t ch); - virtual size_t write(uint8_t const *buf, size_t size); - size_t write(const char *str) - { - if (str == NULL) - return 0; - return write((const uint8_t *)str, strlen(str)); - } - size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); } - - virtual int read(void); - int read(void *buf, uint16_t nbyte); - - virtual int peek(void); - virtual int available(void); - virtual void flush(void); - - bool seek(uint32_t pos); - uint32_t position(void); - uint32_t size(void); - - bool truncate(uint32_t pos); - bool truncate(void); - - void close(void); - - operator bool(void); - - bool isOpen(void); - char const *name(void); - - bool isDirectory(void); - File openNextFile(uint8_t mode = FILE_O_READ); - void rewindDirectory(void); - - private: - LittleFS *_fs; - - bool _is_dir; - - union { - lfs_file_t *_file; - lfs_dir_t *_dir; - }; - - char *_dir_path; - char _name[LFS_NAME_MAX + 1]; - - bool _open(char const *filepath, uint8_t mode); - bool _open_file(char const *filepath, uint8_t mode); - bool _open_dir(char const *filepath); - void _close(void); -}; - -} // namespace LittleFS_Namespace - -#endif /* LITTLEFS_FILE_H_ */ diff --git a/src/platform/stm32wl/STM32WLCryptoEngine.cpp b/src/platform/stm32wl/STM32WLCryptoEngine.cpp index 7367a2bc03..4debdf78e1 100644 --- a/src/platform/stm32wl/STM32WLCryptoEngine.cpp +++ b/src/platform/stm32wl/STM32WLCryptoEngine.cpp @@ -1,33 +1,64 @@ +#undef RNG +#include "AES.h" +#include "CTR.h" #include "CryptoEngine.h" -#include "aes.hpp" #include "configuration.h" class STM32WLCryptoEngine : public CryptoEngine { + + CTRCommon *ctr = NULL; + public: STM32WLCryptoEngine() {} ~STM32WLCryptoEngine() {} + virtual void setKey(const CryptoKey &k) override + { + CryptoEngine::setKey(k); + LOG_DEBUG("Installing AES%d key!\n", key.length * 8); + if (ctr) { + delete ctr; + ctr = NULL; + } + if (key.length != 0) { + if (key.length == 16) + ctr = new CTR(); + else + ctr = new CTR(); + + ctr->setKey(key.bytes, key.length); + } + } /** * Encrypt a packet * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - AES_ctx ctx; - initNonce(fromNode, packetNum); - AES_init_ctx_iv(&ctx, key.bytes, nonce); - AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); + initNonce(fromNode, packetId); + if (numBytes <= MAX_BLOCKSIZE) { + static uint8_t scratch[MAX_BLOCKSIZE]; + memcpy(scratch, bytes, numBytes); + memset(scratch + numBytes, 0, + sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) + + ctr->setIV(nonce, sizeof(nonce)); + ctr->setCounterSize(4); + ctr->encrypt(bytes, scratch, numBytes); + } else { + LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); + } } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetNum, numBytes, bytes); + encrypt(fromNode, packetId, numBytes, bytes); } private: diff --git a/src/platform/stm32wl/main-stm32wl.cpp b/src/platform/stm32wl/main-stm32wl.cpp index 60c3cce107..3eddbb3cfb 100644 --- a/src/platform/stm32wl/main-stm32wl.cpp +++ b/src/platform/stm32wl/main-stm32wl.cpp @@ -26,11 +26,3 @@ void getMacAddr(uint8_t *dmac) } void cpuDeepSleep(uint32_t msecToWake) {} - -/* pacify libc_nano */ -extern "C" { -int _gettimeofday(struct timeval *tv, void *tzvp) -{ - return -1; -} -} \ No newline at end of file diff --git a/src/mqtt/JSON.cpp b/src/serialization/JSON.cpp similarity index 100% rename from src/mqtt/JSON.cpp rename to src/serialization/JSON.cpp diff --git a/src/mqtt/JSON.h b/src/serialization/JSON.h similarity index 100% rename from src/mqtt/JSON.h rename to src/serialization/JSON.h diff --git a/src/mqtt/JSONValue.cpp b/src/serialization/JSONValue.cpp similarity index 100% rename from src/mqtt/JSONValue.cpp rename to src/serialization/JSONValue.cpp diff --git a/src/mqtt/JSONValue.h b/src/serialization/JSONValue.h similarity index 100% rename from src/mqtt/JSONValue.h rename to src/serialization/JSONValue.h diff --git a/src/serialization/MeshPacketSerializer.cpp b/src/serialization/MeshPacketSerializer.cpp new file mode 100644 index 0000000000..a42bb867ae --- /dev/null +++ b/src/serialization/MeshPacketSerializer.cpp @@ -0,0 +1,349 @@ +#include "MeshPacketSerializer.h" +#include "JSON.h" +#include "NodeDB.h" +#include "mesh/generated/meshtastic/mqtt.pb.h" +#include "mesh/generated/meshtastic/telemetry.pb.h" +#include "modules/RoutingModule.h" +#include +#include +#if defined(ARCH_ESP32) +#include "../mesh/generated/meshtastic/paxcount.pb.h" +#endif +#include "mesh/generated/meshtastic/remote_hardware.pb.h" + +std::string MeshPacketSerializer::JsonSerialize(const meshtastic_MeshPacket *mp, bool shouldLog) +{ + // the created jsonObj is immutable after creation, so + // we need to do the heavy lifting before assembling it. + std::string msgType; + JSONObject jsonObj; + + if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { + JSONObject msgPayload; + switch (mp->decoded.portnum) { + case meshtastic_PortNum_TEXT_MESSAGE_APP: { + msgType = "text"; + // convert bytes to string + if (shouldLog) + LOG_DEBUG("got text message of size %u\n", mp->decoded.payload.size); + + char payloadStr[(mp->decoded.payload.size) + 1]; + memcpy(payloadStr, mp->decoded.payload.bytes, mp->decoded.payload.size); + payloadStr[mp->decoded.payload.size] = 0; // null terminated string + // check if this is a JSON payload + JSONValue *json_value = JSON::Parse(payloadStr); + if (json_value != NULL) { + if (shouldLog) + LOG_INFO("text message payload is of type json\n"); + + // if it is, then we can just use the json object + jsonObj["payload"] = json_value; + } else { + // if it isn't, then we need to create a json object + // with the string as the value + if (shouldLog) + LOG_INFO("text message payload is of type plaintext\n"); + + msgPayload["text"] = new JSONValue(payloadStr); + jsonObj["payload"] = new JSONValue(msgPayload); + } + break; + } + case meshtastic_PortNum_TELEMETRY_APP: { + msgType = "telemetry"; + meshtastic_Telemetry scratch; + meshtastic_Telemetry *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Telemetry_msg, &scratch)) { + decoded = &scratch; + if (decoded->which_variant == meshtastic_Telemetry_device_metrics_tag) { + msgPayload["battery_level"] = new JSONValue((unsigned int)decoded->variant.device_metrics.battery_level); + msgPayload["voltage"] = new JSONValue(decoded->variant.device_metrics.voltage); + msgPayload["channel_utilization"] = new JSONValue(decoded->variant.device_metrics.channel_utilization); + msgPayload["air_util_tx"] = new JSONValue(decoded->variant.device_metrics.air_util_tx); + msgPayload["uptime_seconds"] = new JSONValue((unsigned int)decoded->variant.device_metrics.uptime_seconds); + } else if (decoded->which_variant == meshtastic_Telemetry_environment_metrics_tag) { + msgPayload["temperature"] = new JSONValue(decoded->variant.environment_metrics.temperature); + msgPayload["relative_humidity"] = new JSONValue(decoded->variant.environment_metrics.relative_humidity); + msgPayload["barometric_pressure"] = new JSONValue(decoded->variant.environment_metrics.barometric_pressure); + msgPayload["gas_resistance"] = new JSONValue(decoded->variant.environment_metrics.gas_resistance); + msgPayload["voltage"] = new JSONValue(decoded->variant.environment_metrics.voltage); + msgPayload["current"] = new JSONValue(decoded->variant.environment_metrics.current); + msgPayload["lux"] = new JSONValue(decoded->variant.environment_metrics.lux); + msgPayload["white_lux"] = new JSONValue(decoded->variant.environment_metrics.white_lux); + msgPayload["iaq"] = new JSONValue((uint)decoded->variant.environment_metrics.iaq); + msgPayload["wind_speed"] = new JSONValue(decoded->variant.environment_metrics.wind_speed); + msgPayload["wind_direction"] = new JSONValue((uint)decoded->variant.environment_metrics.wind_direction); + msgPayload["wind_gust"] = new JSONValue(decoded->variant.environment_metrics.wind_gust); + msgPayload["wind_lull"] = new JSONValue(decoded->variant.environment_metrics.wind_lull); + } else if (decoded->which_variant == meshtastic_Telemetry_power_metrics_tag) { + msgPayload["voltage_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_voltage); + msgPayload["current_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_current); + msgPayload["voltage_ch2"] = new JSONValue(decoded->variant.power_metrics.ch2_voltage); + msgPayload["current_ch2"] = new JSONValue(decoded->variant.power_metrics.ch2_current); + msgPayload["voltage_ch3"] = new JSONValue(decoded->variant.power_metrics.ch3_voltage); + msgPayload["current_ch3"] = new JSONValue(decoded->variant.power_metrics.ch3_current); + } + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for telemetry message!\n"); + } + break; + } + case meshtastic_PortNum_NODEINFO_APP: { + msgType = "nodeinfo"; + meshtastic_User scratch; + meshtastic_User *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_User_msg, &scratch)) { + decoded = &scratch; + msgPayload["id"] = new JSONValue(decoded->id); + msgPayload["longname"] = new JSONValue(decoded->long_name); + msgPayload["shortname"] = new JSONValue(decoded->short_name); + msgPayload["hardware"] = new JSONValue(decoded->hw_model); + msgPayload["role"] = new JSONValue((int)decoded->role); + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for nodeinfo message!\n"); + } + break; + } + case meshtastic_PortNum_POSITION_APP: { + msgType = "position"; + meshtastic_Position scratch; + meshtastic_Position *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Position_msg, &scratch)) { + decoded = &scratch; + if ((int)decoded->time) { + msgPayload["time"] = new JSONValue((unsigned int)decoded->time); + } + if ((int)decoded->timestamp) { + msgPayload["timestamp"] = new JSONValue((unsigned int)decoded->timestamp); + } + msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i); + msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i); + if ((int)decoded->altitude) { + msgPayload["altitude"] = new JSONValue((int)decoded->altitude); + } + if ((int)decoded->ground_speed) { + msgPayload["ground_speed"] = new JSONValue((unsigned int)decoded->ground_speed); + } + if (int(decoded->ground_track)) { + msgPayload["ground_track"] = new JSONValue((unsigned int)decoded->ground_track); + } + if (int(decoded->sats_in_view)) { + msgPayload["sats_in_view"] = new JSONValue((unsigned int)decoded->sats_in_view); + } + if ((int)decoded->PDOP) { + msgPayload["PDOP"] = new JSONValue((int)decoded->PDOP); + } + if ((int)decoded->HDOP) { + msgPayload["HDOP"] = new JSONValue((int)decoded->HDOP); + } + if ((int)decoded->VDOP) { + msgPayload["VDOP"] = new JSONValue((int)decoded->VDOP); + } + if ((int)decoded->precision_bits) { + msgPayload["precision_bits"] = new JSONValue((int)decoded->precision_bits); + } + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for position message!\n"); + } + break; + } + case meshtastic_PortNum_WAYPOINT_APP: { + msgType = "position"; + meshtastic_Waypoint scratch; + meshtastic_Waypoint *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Waypoint_msg, &scratch)) { + decoded = &scratch; + msgPayload["id"] = new JSONValue((unsigned int)decoded->id); + msgPayload["name"] = new JSONValue(decoded->name); + msgPayload["description"] = new JSONValue(decoded->description); + msgPayload["expire"] = new JSONValue((unsigned int)decoded->expire); + msgPayload["locked_to"] = new JSONValue((unsigned int)decoded->locked_to); + msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i); + msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i); + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for position message!\n"); + } + break; + } + case meshtastic_PortNum_NEIGHBORINFO_APP: { + msgType = "neighborinfo"; + meshtastic_NeighborInfo scratch; + meshtastic_NeighborInfo *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_NeighborInfo_msg, + &scratch)) { + decoded = &scratch; + msgPayload["node_id"] = new JSONValue((unsigned int)decoded->node_id); + msgPayload["node_broadcast_interval_secs"] = new JSONValue((unsigned int)decoded->node_broadcast_interval_secs); + msgPayload["last_sent_by_id"] = new JSONValue((unsigned int)decoded->last_sent_by_id); + msgPayload["neighbors_count"] = new JSONValue(decoded->neighbors_count); + JSONArray neighbors; + for (uint8_t i = 0; i < decoded->neighbors_count; i++) { + JSONObject neighborObj; + neighborObj["node_id"] = new JSONValue((unsigned int)decoded->neighbors[i].node_id); + neighborObj["snr"] = new JSONValue((int)decoded->neighbors[i].snr); + neighbors.push_back(new JSONValue(neighborObj)); + } + msgPayload["neighbors"] = new JSONValue(neighbors); + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for neighborinfo message!\n"); + } + break; + } + case meshtastic_PortNum_TRACEROUTE_APP: { + if (mp->decoded.request_id) { // Only report the traceroute response + msgType = "traceroute"; + meshtastic_RouteDiscovery scratch; + meshtastic_RouteDiscovery *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_RouteDiscovery_msg, + &scratch)) { + decoded = &scratch; + JSONArray route; // Route this message took + // Lambda function for adding a long name to the route + auto addToRoute = [](JSONArray *route, NodeNum num) { + char long_name[40] = "Unknown"; + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(num); + bool name_known = node ? node->has_user : false; + if (name_known) + memcpy(long_name, node->user.long_name, sizeof(long_name)); + route->push_back(new JSONValue(long_name)); + }; + addToRoute(&route, mp->to); // Started at the original transmitter (destination of response) + for (uint8_t i = 0; i < decoded->route_count; i++) { + addToRoute(&route, decoded->route[i]); + } + addToRoute(&route, mp->from); // Ended at the original destination (source of response) + + msgPayload["route"] = new JSONValue(route); + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for traceroute message!\n"); + } + } + break; + } + case meshtastic_PortNum_DETECTION_SENSOR_APP: { + msgType = "detection"; + char payloadStr[(mp->decoded.payload.size) + 1]; + memcpy(payloadStr, mp->decoded.payload.bytes, mp->decoded.payload.size); + payloadStr[mp->decoded.payload.size] = 0; // null terminated string + msgPayload["text"] = new JSONValue(payloadStr); + jsonObj["payload"] = new JSONValue(msgPayload); + break; + } +#ifdef ARCH_ESP32 + case meshtastic_PortNum_PAXCOUNTER_APP: { + msgType = "paxcounter"; + meshtastic_Paxcount scratch; + meshtastic_Paxcount *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Paxcount_msg, &scratch)) { + decoded = &scratch; + msgPayload["wifi_count"] = new JSONValue((unsigned int)decoded->wifi); + msgPayload["ble_count"] = new JSONValue((unsigned int)decoded->ble); + msgPayload["uptime"] = new JSONValue((unsigned int)decoded->uptime); + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for Paxcount message!\n"); + } + break; + } +#endif + case meshtastic_PortNum_REMOTE_HARDWARE_APP: { + meshtastic_HardwareMessage scratch; + meshtastic_HardwareMessage *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_HardwareMessage_msg, + &scratch)) { + decoded = &scratch; + if (decoded->type == meshtastic_HardwareMessage_Type_GPIOS_CHANGED) { + msgType = "gpios_changed"; + msgPayload["gpio_value"] = new JSONValue((unsigned int)decoded->gpio_value); + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (decoded->type == meshtastic_HardwareMessage_Type_READ_GPIOS_REPLY) { + msgType = "gpios_read_reply"; + msgPayload["gpio_value"] = new JSONValue((unsigned int)decoded->gpio_value); + msgPayload["gpio_mask"] = new JSONValue((unsigned int)decoded->gpio_mask); + jsonObj["payload"] = new JSONValue(msgPayload); + } + } else if (shouldLog) { + LOG_ERROR("Error decoding protobuf for RemoteHardware message!\n"); + } + break; + } + // add more packet types here if needed + default: + break; + } + } else if (shouldLog) { + LOG_WARN("Couldn't convert encrypted payload of MeshPacket to JSON\n"); + } + + jsonObj["id"] = new JSONValue((unsigned int)mp->id); + jsonObj["timestamp"] = new JSONValue((unsigned int)mp->rx_time); + jsonObj["to"] = new JSONValue((unsigned int)mp->to); + jsonObj["from"] = new JSONValue((unsigned int)mp->from); + jsonObj["channel"] = new JSONValue((unsigned int)mp->channel); + jsonObj["type"] = new JSONValue(msgType.c_str()); + jsonObj["sender"] = new JSONValue(owner.id); + if (mp->rx_rssi != 0) + jsonObj["rssi"] = new JSONValue((int)mp->rx_rssi); + if (mp->rx_snr != 0) + jsonObj["snr"] = new JSONValue((float)mp->rx_snr); + if (mp->hop_start != 0 && mp->hop_limit <= mp->hop_start) { + jsonObj["hops_away"] = new JSONValue((unsigned int)(mp->hop_start - mp->hop_limit)); + jsonObj["hop_start"] = new JSONValue((unsigned int)(mp->hop_start)); + } + + // serialize and write it to the stream + JSONValue *value = new JSONValue(jsonObj); + std::string jsonStr = value->Stringify(); + + if (shouldLog) + LOG_INFO("serialized json message: %s\n", jsonStr.c_str()); + + delete value; + return jsonStr; +} + +std::string MeshPacketSerializer::JsonSerializeEncrypted(const meshtastic_MeshPacket *mp) +{ + JSONObject jsonObj; + + jsonObj["id"] = new JSONValue((unsigned int)mp->id); + jsonObj["time_ms"] = new JSONValue((double)millis()); + jsonObj["timestamp"] = new JSONValue((unsigned int)mp->rx_time); + jsonObj["to"] = new JSONValue((unsigned int)mp->to); + jsonObj["from"] = new JSONValue((unsigned int)mp->from); + jsonObj["channel"] = new JSONValue((unsigned int)mp->channel); + jsonObj["want_ack"] = new JSONValue(mp->want_ack); + + if (mp->rx_rssi != 0) + jsonObj["rssi"] = new JSONValue((int)mp->rx_rssi); + if (mp->rx_snr != 0) + jsonObj["snr"] = new JSONValue((float)mp->rx_snr); + if (mp->hop_start != 0 && mp->hop_limit <= mp->hop_start) { + jsonObj["hops_away"] = new JSONValue((unsigned int)(mp->hop_start - mp->hop_limit)); + jsonObj["hop_start"] = new JSONValue((unsigned int)(mp->hop_start)); + } + jsonObj["size"] = new JSONValue((unsigned int)mp->encrypted.size); + auto encryptedStr = bytesToHex(mp->encrypted.bytes, mp->encrypted.size); + jsonObj["bytes"] = new JSONValue(encryptedStr.c_str()); + + // serialize and write it to the stream + JSONValue *value = new JSONValue(jsonObj); + std::string jsonStr = value->Stringify(); + + delete value; + return jsonStr; +} \ No newline at end of file diff --git a/src/serialization/MeshPacketSerializer.h b/src/serialization/MeshPacketSerializer.h new file mode 100644 index 0000000000..03860ab354 --- /dev/null +++ b/src/serialization/MeshPacketSerializer.h @@ -0,0 +1,23 @@ +#include +#include + +static const char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + +class MeshPacketSerializer +{ + public: + static std::string JsonSerialize(const meshtastic_MeshPacket *mp, bool shouldLog = true); + static std::string JsonSerializeEncrypted(const meshtastic_MeshPacket *mp); + + private: + static std::string bytesToHex(const uint8_t *bytes, int len) + { + std::string result = ""; + for (int i = 0; i < len; ++i) { + char const byte = bytes[i]; + result += hexChars[(byte & 0xF0) >> 4]; + result += hexChars[(byte & 0x0F) >> 0]; + } + return result; + } +}; \ No newline at end of file diff --git a/src/xmodem.cpp b/src/xmodem.cpp index 852ff34531..de73e86684 100644 --- a/src/xmodem.cpp +++ b/src/xmodem.cpp @@ -50,6 +50,8 @@ #include "xmodem.h" +#ifdef FSCom + XModemAdapter xModem; XModemAdapter::XModemAdapter() {} @@ -248,4 +250,5 @@ void XModemAdapter::handlePacket(meshtastic_XModem xmodemPacket) // Unknown control character break; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/xmodem.h b/src/xmodem.h index 2ba0bb39f1..4cfcb43e18 100644 --- a/src/xmodem.h +++ b/src/xmodem.h @@ -38,6 +38,8 @@ #define MAXRETRANS 25 +#ifdef FSCom + class XModemAdapter { public: @@ -75,3 +77,4 @@ class XModemAdapter }; extern XModemAdapter xModem; +#endif // FSCom \ No newline at end of file diff --git a/userPrefs.h b/userPrefs.h new file mode 100644 index 0000000000..b365e8c6f8 --- /dev/null +++ b/userPrefs.h @@ -0,0 +1,36 @@ +#ifndef _USERPREFS_ +#define _USERPREFS_ + +// Uncomment and modify to set device defaults + +// #define EVENT_MODE 1 + +// #define CONFIG_LORA_REGION_USERPREFS meshtastic_Config_LoRaConfig_RegionCode_US +// #define LORACONFIG_MODEM_PRESET_USERPREFS meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST +// #define LORACONFIG_CHANNEL_NUM_USERPREFS 31 +// #define CONFIG_LORA_IGNORE_MQTT_USERPREFS true +/* +#define CHANNEL_0_PSK_USERPREFS \ + { \ + 0x38, 0x4b, 0xbc, 0xc0, 0x1d, 0xc0, 0x22, 0xd1, 0x81, 0xbf, 0x36, 0xb8, 0x61, 0x21, 0xe1, 0xfb, 0x96, 0xb7, 0x2e, 0x55, \ + 0xbf, 0x74, 0x22, 0x7e, 0x9d, 0x6a, 0xfb, 0x48, 0xd6, 0x4c, 0xb1, 0xa1 \ + } +*/ +// #define CHANNEL_0_NAME_USERPREFS "DEFCONnect" +// #define CHANNEL_0_PRECISION_USERPREFS 13 + +// #define SPLASH_TITLE_USERPREFS "DEFCONtastic" +// #define icon_width 34 +// #define icon_height 29 +// #define HAS_USERPREFS_SPLASH +/* +static unsigned char icon_bits[] = { + 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xF8, 0x7F, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, + 0x9E, 0xE7, 0x00, 0x00, 0x00, 0x0E, 0xC7, 0x01, 0x00, 0x1C, 0x0F, 0xC7, 0x01, 0x00, 0x1C, 0xDF, 0xE7, 0x63, 0x00, 0x1C, 0xFF, + 0xBF, 0xE1, 0x00, 0x3C, 0xF3, 0xBF, 0xE3, 0x00, 0x7F, 0xF7, 0xBF, 0xF1, 0x00, 0xFF, 0xF7, 0xBF, 0xF9, 0x03, 0xFF, 0xE7, 0x9F, + 0xFF, 0x03, 0xC0, 0xCF, 0xEF, 0xDF, 0x03, 0x00, 0xDF, 0xE3, 0x8F, 0x00, 0x00, 0x7C, 0xFB, 0x03, 0x00, 0x00, 0xF8, 0xFF, 0x00, + 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0x78, 0x3F, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0x00, 0x00, + 0x98, 0x3F, 0xF0, 0x23, 0x00, 0xFC, 0x0F, 0xE0, 0x7F, 0x00, 0xFC, 0x03, 0x80, 0xFF, 0x01, 0xFC, 0x00, 0x00, 0x3E, 0x00, 0x70, + 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00, 0x70, 0x00, 0x00, 0x1C, 0x00}; +*/ +#endif \ No newline at end of file diff --git a/variants/chatter2/variant.h b/variants/chatter2/variant.h index 90faa1d7ba..70438e52ac 100644 --- a/variants/chatter2/variant.h +++ b/variants/chatter2/variant.h @@ -34,7 +34,7 @@ // Buzzer #define PIN_BUZZER 19 // Buttons -#define BUTTON_PIN 36 // Use the WAKE button as the user button +// #define BUTTON_PIN 36 // Use the WAKE button as the user button // I2C // #define I2C_SCL 27 // #define I2C_SDA 26 @@ -91,6 +91,13 @@ #define GPS_TX_PIN 13 #define GPS_RX_PIN 2 +// keyboard +#define INPUTBROKER_SERIAL_TYPE 1 +#define KB_LOAD 21 // load values from the switch and store in shift register +#define KB_CLK 22 // clock pin for serial data out +#define KB_DATA 23 // data pin +#define CANNED_MESSAGE_MODULE_ENABLE 1 + ///////////////////////////////////////////////////////////////////////////////// // // // You should have no need to modify the code below, nor in pins_arduino.h // diff --git a/variants/diy/nrf52_promicro_diy_tcxo/variant.h b/variants/diy/nrf52_promicro_diy_tcxo/variant.h index 8b957fe128..bacc0796dc 100644 --- a/variants/diy/nrf52_promicro_diy_tcxo/variant.h +++ b/variants/diy/nrf52_promicro_diy_tcxo/variant.h @@ -115,6 +115,8 @@ NRF52 PRO MICRO PIN ASSIGNMENT // LORA MODULES #define USE_LLCC68 #define USE_SX1262 +#define USE_RF95 +#define USE_SX1268 // LORA CONFIG #define SX126X_CS (32 + 13) // P1.13 FIXME - we really should define LORA_CS instead diff --git a/variants/diy/nrf52_promicro_diy_xtal/variant.h b/variants/diy/nrf52_promicro_diy_xtal/variant.h index fd0b216813..c00c424cc9 100644 --- a/variants/diy/nrf52_promicro_diy_xtal/variant.h +++ b/variants/diy/nrf52_promicro_diy_xtal/variant.h @@ -114,6 +114,8 @@ NRF52 PRO MICRO PIN ASSIGNMENT // LORA MODULES #define USE_LLCC68 #define USE_SX1262 +#define USE_RF95 +#define USE_SX1268 // LORA CONFIG #define SX126X_CS (32 + 13) // P1.13 FIXME - we really should define LORA_CS instead diff --git a/variants/heltec_mesh_node_t114/variant.h b/variants/heltec_mesh_node_t114/variant.h index b233069c63..615526b22b 100644 --- a/variants/heltec_mesh_node_t114/variant.h +++ b/variants/heltec_mesh_node_t114/variant.h @@ -126,8 +126,8 @@ No longer populated on PCB #define LORA_CS (0 + 24) #define SX126X_DIO1 (0 + 20) // Note DIO2 is attached internally to the module to an analog switch for TX/RX switching -// #define SX1262_DIO3 \ -// (0 + 21) // This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not drive from the +// #define SX1262_DIO3 (0 + 21) +// This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not drive from the // main // CPU? #define SX126X_BUSY (0 + 17) diff --git a/variants/heltec_v3/variant.h b/variants/heltec_v3/variant.h index 2417b873d8..4f1d91db81 100644 --- a/variants/heltec_v3/variant.h +++ b/variants/heltec_v3/variant.h @@ -1,5 +1,7 @@ #define LED_PIN LED +#define USE_SSD1306 // Heltec_v3 has a SSD1306 display + #define RESET_OLED RST_OLED #define I2C_SDA SDA_OLED // I2C pins for this board #define I2C_SCL SCL_OLED diff --git a/variants/heltec_vision_master_e213/variant.h b/variants/heltec_vision_master_e213/variant.h index 99bc1d138d..bbc697f09b 100644 --- a/variants/heltec_vision_master_e213/variant.h +++ b/variants/heltec_vision_master_e213/variant.h @@ -15,9 +15,9 @@ // SPI #define SPI_INTERFACES_COUNT 2 -#define PIN_SPI_MISO 10 // MISO -#define PIN_SPI_MOSI 11 // MOSI -#define PIN_SPI_SCK 9 // SCK +#define PIN_SPI_MISO 11 +#define PIN_SPI_MOSI 10 +#define PIN_SPI_SCK 9 // Power #define VEXT_ENABLE 18 // Powers the E-Ink display, and the 3.3V supply to the I2C QuickLink connector @@ -29,11 +29,12 @@ #define ADC_CHANNEL ADC1_GPIO7_CHANNEL #define ADC_MULTIPLIER 4.9 * 1.03 #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 +#define HAS_32768HZ // LoRa #define USE_SX1262 -#define LORA_DIO0 -1 // a No connect on the SX1262 module +#define LORA_DIO0 RADIOLIB_NC // a No connect on the SX1262 module #define LORA_RESET 12 #define LORA_DIO1 14 // SX1262 IRQ #define LORA_DIO2 13 // SX1262 BUSY diff --git a/variants/heltec_vision_master_e290/pins_arduino.h b/variants/heltec_vision_master_e290/pins_arduino.h index e5d5078463..77cf3176a4 100644 --- a/variants/heltec_vision_master_e290/pins_arduino.h +++ b/variants/heltec_vision_master_e290/pins_arduino.h @@ -3,15 +3,15 @@ #include -static const uint8_t LED_BUILTIN = 35; +static const uint8_t LED_BUILTIN = -1; #define BUILTIN_LED LED_BUILTIN // backward compatibility #define LED_BUILTIN LED_BUILTIN static const uint8_t TX = 43; static const uint8_t RX = 44; -static const uint8_t SDA = 41; -static const uint8_t SCL = 42; +static const uint8_t SDA = 39; +static const uint8_t SCL = 38; static const uint8_t SS = 8; static const uint8_t MOSI = 10; @@ -56,6 +56,6 @@ static const uint8_t T14 = 14; static const uint8_t RST_LoRa = 12; static const uint8_t BUSY_LoRa = 13; -static const uint8_t DIO0 = 14; +static const uint8_t DIO1 = 14; #endif /* Pins_Arduino_h */ diff --git a/variants/heltec_vision_master_e290/platformio.ini b/variants/heltec_vision_master_e290/platformio.ini index 60ff60036a..e1ba100ae5 100644 --- a/variants/heltec_vision_master_e290/platformio.ini +++ b/variants/heltec_vision_master_e290/platformio.ini @@ -1,25 +1,25 @@ [env:heltec-vision-master-e290] -board_level = extra extends = esp32s3_base -board = heltec_wifi_lora_32_V3 +board = heltec_vision_master_e290 build_flags = ${esp32s3_base.build_flags} - -Ivariants/heltec_vision_master_e290 - -DHELTEC_VISION_MASTER_E290 - -DEINK_DISPLAY_MODEL=GxEPD2_290_BS - -DEINK_WIDTH=296 - -DEINK_HEIGHT=128 -; -D USE_EINK_DYNAMICDISPLAY ; Enable Dynamic EInk -; -D EINK_LIMIT_FASTREFRESH=10 ; How many consecutive fast-refreshes are permitted -; -D EINK_LIMIT_RATE_BACKGROUND_SEC=1 ; Minimum interval between BACKGROUND updates -; -D EINK_LIMIT_RATE_RESPONSIVE_SEC=1 ; Minimum interval between RESPONSIVE updates -; -D EINK_LIMIT_GHOSTING_PX=2000 ; (Optional) How much image ghosting is tolerated -; -D EINK_BACKGROUND_USES_FAST ; (Optional) Use FAST refresh for both BACKGROUND and RESPONSIVE, until a limit is reached. -; -D EINK_HASQUIRK_GHOSTING ; Display model is identified as "prone to ghosting" -; -D EINK_HASQUIRK_WEAKFASTREFRESH ; Pixels set with fast-refresh are easy to clear, disrupted by sunlight + -I variants/heltec_vision_master_e290 + -D HELTEC_VISION_MASTER_E290 + -D BUTTON_CLICK_MS=200 + -D EINK_DISPLAY_MODEL=GxEPD2_290_BN8 + -D EINK_WIDTH=296 + -D EINK_HEIGHT=128 + -D USE_EINK_DYNAMICDISPLAY ; Enable Dynamic EInk + -D EINK_LIMIT_FASTREFRESH=10 ; How many consecutive fast-refreshes are permitted + -D EINK_LIMIT_RATE_BACKGROUND_SEC=30 ; Minimum interval between BACKGROUND updates + -D EINK_LIMIT_RATE_RESPONSIVE_SEC=1 ; Minimum interval between RESPONSIVE updates + -D EINK_HASQUIRK_GHOSTING ; Display model is identified as "prone to ghosting" + -D EINK_HASQUIRK_WEAKFASTREFRESH ; Pixels set with fast-refresh are easy to clear, disrupted by sunlight +; -D EINK_LIMIT_GHOSTING_PX=2000 ; How much image ghosting is tolerated +; -D EINK_BACKGROUND_USES_FAST ; (If enabled) don't redraw RESPONSIVE frames at next BACKGROUND update lib_deps = ${esp32s3_base.lib_deps} - https://github.com/meshtastic/GxEPD2#b202ebfec6a4821e098cf7a625ba0f6f2400292d + https://github.com/meshtastic/GxEPD2#448c8538129fde3d02a7cb5e6fc81971ad92547f lewisxhe/PCF8563_Library@^1.0.1 upload_speed = 115200 \ No newline at end of file diff --git a/variants/heltec_vision_master_e290/variant.h b/variants/heltec_vision_master_e290/variant.h index a8ec5485b7..6af4b06a58 100644 --- a/variants/heltec_vision_master_e290/variant.h +++ b/variants/heltec_vision_master_e290/variant.h @@ -1,48 +1,42 @@ -// #define LED_PIN 18 +#define BUTTON_PIN 0 -// Enable bus for external periherals +// I2C #define I2C_SDA SDA #define I2C_SCL SCL +// Display (E-Ink) #define USE_EINK - -/* - * eink display pins - */ #define PIN_EINK_CS 3 -#define PIN_EINK_BUSY 5 +#define PIN_EINK_BUSY 6 #define PIN_EINK_DC 4 #define PIN_EINK_RES 5 #define PIN_EINK_SCLK 2 #define PIN_EINK_MOSI 1 -/* - * SPI interfaces - */ +// SPI #define SPI_INTERFACES_COUNT 2 +#define PIN_SPI_MISO 11 +#define PIN_SPI_MOSI 10 +#define PIN_SPI_SCK 9 -#define PIN_SPI_MISO 10 // MISO -#define PIN_SPI_MOSI 11 // MOSI -#define PIN_SPI_SCK 9 // SCK - -#define VEXT_ENABLE 18 // powers the e-ink display -#define VEXT_ON_VALUE 1 -#define BUTTON_PIN 0 - +// Power +#define VEXT_ENABLE 18 // Powers the E-Ink display only +#define VEXT_ON_VALUE HIGH #define ADC_CTRL 46 #define ADC_CTRL_ENABLED HIGH #define BATTERY_PIN 7 #define ADC_CHANNEL ADC1_GPIO7_CHANNEL #define ADC_MULTIPLIER 4.9 * 1.03 -#define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // Voltage divider output is quite high +#define ADC_ATTENUATION ADC_ATTEN_DB_2_5 +#define HAS_32768HZ +// LoRa #define USE_SX1262 -#define LORA_DIO0 -1 // a No connect on the SX1262 module +#define LORA_DIO0 RADIOLIB_NC // a No connect on the SX1262 module #define LORA_RESET 12 #define LORA_DIO1 14 // SX1262 IRQ #define LORA_DIO2 13 // SX1262 BUSY -#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled #define LORA_SCK 9 #define LORA_MISO 11 diff --git a/variants/heltec_wireless_paper/variant.h b/variants/heltec_wireless_paper/variant.h index c41d6d9dfe..a7bd460f79 100644 --- a/variants/heltec_wireless_paper/variant.h +++ b/variants/heltec_wireless_paper/variant.h @@ -16,9 +16,9 @@ // SPI #define SPI_INTERFACES_COUNT 2 -#define PIN_SPI_MISO 10 // MISO -#define PIN_SPI_MOSI 11 // MOSI -#define PIN_SPI_SCK 9 // SCK +#define PIN_SPI_MISO 11 +#define PIN_SPI_MOSI 10 +#define PIN_SPI_SCK 9 // Power #define VEXT_ENABLE 45 // Active low, powers the E-Ink display @@ -28,11 +28,12 @@ #define ADC_MULTIPLIER 2 // Voltage divider is roughly 1:1 #define BAT_MEASURE_ADC_UNIT 2 // Use ADC2 #define ADC_ATTENUATION ADC_ATTEN_DB_12 // Voltage divider output is quite high +#define HAS_32768HZ // LoRa #define USE_SX1262 -#define LORA_DIO0 -1 // a No connect on the SX1262 module +#define LORA_DIO0 RADIOLIB_NC // a No connect on the SX1262 module #define LORA_RESET 12 #define LORA_DIO1 14 // SX1262 IRQ #define LORA_DIO2 13 // SX1262 BUSY diff --git a/variants/heltec_wireless_paper_v1/variant.h b/variants/heltec_wireless_paper_v1/variant.h index c41d6d9dfe..a7bd460f79 100644 --- a/variants/heltec_wireless_paper_v1/variant.h +++ b/variants/heltec_wireless_paper_v1/variant.h @@ -16,9 +16,9 @@ // SPI #define SPI_INTERFACES_COUNT 2 -#define PIN_SPI_MISO 10 // MISO -#define PIN_SPI_MOSI 11 // MOSI -#define PIN_SPI_SCK 9 // SCK +#define PIN_SPI_MISO 11 +#define PIN_SPI_MOSI 10 +#define PIN_SPI_SCK 9 // Power #define VEXT_ENABLE 45 // Active low, powers the E-Ink display @@ -28,11 +28,12 @@ #define ADC_MULTIPLIER 2 // Voltage divider is roughly 1:1 #define BAT_MEASURE_ADC_UNIT 2 // Use ADC2 #define ADC_ATTENUATION ADC_ATTEN_DB_12 // Voltage divider output is quite high +#define HAS_32768HZ // LoRa #define USE_SX1262 -#define LORA_DIO0 -1 // a No connect on the SX1262 module +#define LORA_DIO0 RADIOLIB_NC // a No connect on the SX1262 module #define LORA_RESET 12 #define LORA_DIO1 14 // SX1262 IRQ #define LORA_DIO2 13 // SX1262 BUSY diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index e114fac589..5c26091053 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -3,5 +3,6 @@ #endif #define CANNED_MESSAGE_MODULE_ENABLE 1 #define HAS_GPS 1 +#define MAX_RX_TOPHONE settingsMap[maxtophone] #define MAX_NUM_NODES settingsMap[maxnodes] #define RADIOLIB_GODMODE 1 diff --git a/variants/radiomaster_900_bandit_nano/variant.h b/variants/radiomaster_900_bandit_nano/variant.h index bd66877333..39c1bc06f3 100644 --- a/variants/radiomaster_900_bandit_nano/variant.h +++ b/variants/radiomaster_900_bandit_nano/variant.h @@ -50,7 +50,7 @@ #define BUTTON_PIN 39 #define BUTTON_NEED_PULLUP -#define SCREEN_ROTATE +#define DISPLAY_FLIP_SCREEN /* No External notification. @@ -81,4 +81,4 @@ */ #define RF95_PA_EN 26 #define RF95_PA_DAC_EN -#define RF95_PA_LEVEL 90 \ No newline at end of file +#define RF95_PA_LEVEL 90 diff --git a/variants/rak3172/platformio.ini b/variants/rak3172/platformio.ini new file mode 100644 index 0000000000..d1bd55e832 --- /dev/null +++ b/variants/rak3172/platformio.ini @@ -0,0 +1,31 @@ +[env:rak3172] +extends = stm32_base +board = wiscore_rak3172 +build_flags = + ${stm32_base.build_flags} + -Ivariants/rak3172 + -DSERIAL_UART_INSTANCE=1 + -DPIN_SERIAL_RX=PB7 + -DPIN_SERIAL_TX=PB6 + -DHAL_DAC_MODULE_ONLY + -DHAL_ADC_MODULE_DISABLED + -DHAL_COMP_MODULE_DISABLED + -DHAL_CRC_MODULE_DISABLED + -DHAL_CRYP_MODULE_DISABLED + -DHAL_GTZC_MODULE_DISABLED + -DHAL_HSEM_MODULE_DISABLED + -DHAL_I2C_MODULE_DISABLED + -DHAL_I2S_MODULE_DISABLED + -DHAL_IPCC_MODULE_DISABLED + -DHAL_IRDA_MODULE_DISABLED + -DHAL_IWDG_MODULE_DISABLED + -DHAL_LPTIM_MODULE_DISABLED + -DHAL_PKA_MODULE_DISABLED + -DHAL_RNG_MODULE_DISABLED + -DHAL_RTC_MODULE_DISABLED + -DHAL_SMARTCARD_MODULE_DISABLED + -DHAL_SMBUS_MODULE_DISABLED + -DHAL_TIM_MODULE_DISABLED + -DHAL_WWDG_MODULE_DISABLED + -DHAL_EXTI_MODULE_DISABLED +upload_port = stlink \ No newline at end of file diff --git a/variants/rak3172/variant.h b/variants/rak3172/variant.h new file mode 100644 index 0000000000..21de65b2cd --- /dev/null +++ b/variants/rak3172/variant.h @@ -0,0 +1,12 @@ +/* +This variant is a work in progress. +Do not expect a working Meshtastic device with this target. +*/ + +#ifndef _VARIANT_RAK3172_ +#define _VARIANT_RAK3172_ + +#define USE_STM32WLx +#define MAX_NUM_NODES 10 + +#endif \ No newline at end of file diff --git a/variants/trackerd/platformio.ini b/variants/trackerd/platformio.ini index 23868ffb41..6fba190f39 100644 --- a/variants/trackerd/platformio.ini +++ b/variants/trackerd/platformio.ini @@ -4,10 +4,10 @@ extends = esp32_base platform = espressif32 board = pico32 board_build.f_flash = 80000000L -board_level = extra + build_flags = ${esp32_base.build_flags} -D PRIVATE_HW -I variants/trackerd -D BSFILE=\"boards/dragino_lbt2.h\" ;board_build.partitions = no_ota.csv ;platform_packages = ; platformio/framework-arduinoespressif32@3 -;platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1-RC1 \ No newline at end of file +;platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.1-RC1 diff --git a/variants/wio-e5/platformio.ini b/variants/wio-e5/platformio.ini index 07f6efa6df..51591d5696 100644 --- a/variants/wio-e5/platformio.ini +++ b/variants/wio-e5/platformio.ini @@ -1,11 +1,33 @@ [env:wio-e5] -extends = stm32wl5e_base -board_level = extra +extends = stm32_base +board = lora_e5_dev_board build_flags = - ${stm32wl5e_base.build_flags} + ${stm32_base.build_flags} -Ivariants/wio-e5 - -DHAL_DAC_MODULE_ONLY -DSERIAL_UART_INSTANCE=1 -DPIN_SERIAL_RX=PB7 -DPIN_SERIAL_TX=PB6 + -DHAL_DAC_MODULE_ONLY + -DHAL_ADC_MODULE_DISABLED + -DHAL_COMP_MODULE_DISABLED + -DHAL_CRC_MODULE_DISABLED + -DHAL_CRYP_MODULE_DISABLED + -DHAL_GTZC_MODULE_DISABLED + -DHAL_HSEM_MODULE_DISABLED + -DHAL_I2C_MODULE_DISABLED + -DHAL_I2S_MODULE_DISABLED + -DHAL_IPCC_MODULE_DISABLED + -DHAL_IRDA_MODULE_DISABLED + -DHAL_IWDG_MODULE_DISABLED + -DHAL_LPTIM_MODULE_DISABLED + -DHAL_PKA_MODULE_DISABLED + -DHAL_RNG_MODULE_DISABLED + -DHAL_RTC_MODULE_DISABLED + -DHAL_SMARTCARD_MODULE_DISABLED + -DHAL_SMBUS_MODULE_DISABLED + -DHAL_TIM_MODULE_DISABLED + -DHAL_WWDG_MODULE_DISABLED + -DHAL_EXTI_MODULE_DISABLED +; -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + upload_port = stlink \ No newline at end of file diff --git a/variants/wio-e5/variant.h b/variants/wio-e5/variant.h index 86e58bcb2e..b4345a530e 100644 --- a/variants/wio-e5/variant.h +++ b/variants/wio-e5/variant.h @@ -13,5 +13,6 @@ Do not expect a working Meshtastic device with this target. #define _VARIANT_WIOE5_ #define USE_STM32WLx +#define MAX_NUM_NODES 10 #endif \ No newline at end of file diff --git a/version.properties b/version.properties index 4c87608d0a..b8bb5e67d6 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 4 -build = 1 +build = 2