mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-12 21:07:19 +00:00
Compare commits
2 Commits
sfpp
...
pager-audi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83889a1c37 | ||
|
|
be024d8d4e |
@@ -20,7 +20,7 @@ ENV PIP_ROOT_USER_ACTION=ignore
|
||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
cmake git zip libgpiod-dev libbluetooth-dev libi2c-dev \
|
||||
libunistring-dev libmicrohttpd-dev libgnutls28-dev libgcrypt20-dev \
|
||||
libusb-1.0-0-dev libssl-dev pkg-config libsqlite3-dev && \
|
||||
libusb-1.0-0-dev libssl-dev pkg-config && \
|
||||
apt-get clean && rm -rf /var/lib/apt/lists/* && \
|
||||
pip install --no-cache-dir -U \
|
||||
platformio==6.1.16 \
|
||||
|
||||
314
.github/copilot-instructions.md
vendored
Normal file
314
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,314 @@
|
||||
# Meshtastic Firmware - Copilot Instructions
|
||||
|
||||
This document provides context and guidelines for AI assistants working with the Meshtastic firmware codebase.
|
||||
|
||||
## Project Overview
|
||||
|
||||
Meshtastic is an open-source LoRa mesh networking project for long-range, low-power communication without relying on internet or cellular infrastructure. The firmware enables text messaging, location sharing, and telemetry over a decentralized mesh network.
|
||||
|
||||
### Supported Hardware Platforms
|
||||
|
||||
- **ESP32** (ESP32, ESP32-S3, ESP32-C3) - Most common platform
|
||||
- **nRF52** (nRF52840, nRF52833) - Low power Nordic chips
|
||||
- **RP2040/RP2350** - Raspberry Pi Pico variants
|
||||
- **STM32WL** - STM32 with integrated LoRa
|
||||
- **Linux/Portduino** - Native Linux builds (Raspberry Pi, etc.)
|
||||
|
||||
### Supported Radio Chips
|
||||
|
||||
- **SX1262/SX1268** - Sub-GHz LoRa (868/915 MHz regions)
|
||||
- **SX1280** - 2.4 GHz LoRa
|
||||
- **LR1110/LR1120/LR1121** - Wideband radios (sub-GHz and 2.4 GHz capable, but not simultaneously)
|
||||
- **RF95** - Legacy RFM95 modules
|
||||
- **LLCC68** - Low-cost LoRa
|
||||
|
||||
### MQTT Integration
|
||||
|
||||
MQTT provides a bridge between Meshtastic mesh networks and the internet, enabling nodes with network connectivity to share messages with remote meshes or external services.
|
||||
|
||||
#### Key Components
|
||||
|
||||
- **`src/mqtt/MQTT.cpp`** - Main MQTT client singleton, handles connection and message routing
|
||||
- **`src/mqtt/ServiceEnvelope.cpp`** - Protobuf wrapper for mesh packets sent over MQTT
|
||||
- **`moduleConfig.mqtt`** - MQTT module configuration
|
||||
|
||||
#### MQTT Topic Structure
|
||||
|
||||
Messages are published/subscribed using a hierarchical topic format:
|
||||
|
||||
```
|
||||
{root}/{channel_id}/{gateway_id}
|
||||
```
|
||||
|
||||
- `root` - Configurable prefix (default: `msh`)
|
||||
- `channel_id` - Channel name/identifier
|
||||
- `gateway_id` - Node ID of the publishing gateway
|
||||
|
||||
#### Configuration Defaults (from `Default.h`)
|
||||
|
||||
```cpp
|
||||
#define default_mqtt_address "mqtt.meshtastic.org"
|
||||
#define default_mqtt_username "meshdev"
|
||||
#define default_mqtt_password "large4cats"
|
||||
#define default_mqtt_root "msh"
|
||||
#define default_mqtt_encryption_enabled true
|
||||
#define default_mqtt_tls_enabled false
|
||||
```
|
||||
|
||||
#### Key Concepts
|
||||
|
||||
- **Uplink** - Mesh packets sent TO the MQTT broker (controlled by `uplink_enabled` per channel)
|
||||
- **Downlink** - MQTT messages received and injected INTO the mesh (controlled by `downlink_enabled` per channel)
|
||||
- **Encryption** - When `encryption_enabled` is true, only encrypted packets are sent; plaintext JSON is disabled
|
||||
- **ServiceEnvelope** - Protobuf wrapper containing packet + channel_id + gateway_id for routing
|
||||
- **JSON Support** - Optional JSON encoding for integration with external systems (disabled on nRF52 by default)
|
||||
|
||||
#### PKI Messages
|
||||
|
||||
PKI (Public Key Infrastructure) messages have special handling:
|
||||
|
||||
- Accepted on a special "PKI" channel
|
||||
- Allow encrypted DMs between nodes that discovered each other on downlink-enabled channels
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
firmware/
|
||||
├── src/ # Main source code
|
||||
│ ├── main.cpp # Application entry point
|
||||
│ ├── mesh/ # Core mesh networking
|
||||
│ │ ├── NodeDB.* # Node database management
|
||||
│ │ ├── Router.* # Packet routing
|
||||
│ │ ├── Channels.* # Channel management
|
||||
│ │ ├── *Interface.* # Radio interface implementations
|
||||
│ │ └── generated/ # Protobuf generated code
|
||||
│ ├── modules/ # Feature modules (Position, Telemetry, etc.)
|
||||
│ ├── gps/ # GPS handling
|
||||
│ ├── graphics/ # Display drivers and UI
|
||||
│ ├── platform/ # Platform-specific code
|
||||
│ ├── input/ # Input device handling
|
||||
│ └── concurrency/ # Threading utilities
|
||||
├── variants/ # Hardware variant definitions
|
||||
│ ├── esp32/ # ESP32 variants
|
||||
│ ├── esp32s3/ # ESP32-S3 variants
|
||||
│ ├── nrf52/ # nRF52 variants
|
||||
│ └── rp2xxx/ # RP2040/RP2350 variants
|
||||
├── protobufs/ # Protocol buffer definitions
|
||||
├── boards/ # Custom PlatformIO board definitions
|
||||
└── bin/ # Build and utility scripts
|
||||
```
|
||||
|
||||
## Coding Conventions
|
||||
|
||||
### General Style
|
||||
|
||||
- Follow existing code style - run `trunk fmt` before commits
|
||||
- Prefer `LOG_DEBUG`, `LOG_INFO`, `LOG_WARN`, `LOG_ERROR` for logging
|
||||
- Use `assert()` for invariants that should never fail
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
- Classes: `PascalCase` (e.g., `PositionModule`, `NodeDB`)
|
||||
- Functions/Methods: `camelCase` (e.g., `sendOurPosition`, `getNodeNum`)
|
||||
- Constants/Defines: `UPPER_SNAKE_CASE` (e.g., `MAX_INTERVAL`, `ONE_DAY`)
|
||||
- Member variables: `camelCase` (e.g., `lastGpsSend`, `nodeDB`)
|
||||
- Config defines: `USERPREFS_*` for user-configurable options
|
||||
|
||||
### Key Patterns
|
||||
|
||||
#### Module System
|
||||
|
||||
Modules inherit from `MeshModule` or `ProtobufModule<T>` and implement:
|
||||
|
||||
- `handleReceivedProtobuf()` - Process incoming packets
|
||||
- `allocReply()` - Generate response packets
|
||||
- `runOnce()` - Periodic task execution (returns next run interval in ms)
|
||||
|
||||
```cpp
|
||||
class MyModule : public ProtobufModule<meshtastic_MyMessage>
|
||||
{
|
||||
protected:
|
||||
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_MyMessage *msg) override;
|
||||
virtual int32_t runOnce() override;
|
||||
};
|
||||
```
|
||||
|
||||
#### Configuration Access
|
||||
|
||||
- `config.*` - Device configuration (LoRa, position, power, etc.)
|
||||
- `moduleConfig.*` - Module-specific configuration
|
||||
- `channels.*` - Channel configuration and management
|
||||
|
||||
#### Default Values
|
||||
|
||||
Use the `Default` class helpers in `src/mesh/Default.h`:
|
||||
|
||||
- `Default::getConfiguredOrDefaultMs(configured, default)` - Returns ms, using default if configured is 0
|
||||
- `Default::getConfiguredOrMinimumValue(configured, min)` - Enforces minimum values
|
||||
- `Default::getConfiguredOrDefaultMsScaled(configured, default, numNodes)` - Scales based on network size
|
||||
|
||||
#### Thread Safety
|
||||
|
||||
- Use `concurrency::Lock` for mutex protection
|
||||
- Radio SPI access uses `SPILock`
|
||||
- Prefer `OSThread` for background tasks
|
||||
|
||||
### Hardware Variants
|
||||
|
||||
Each hardware variant has:
|
||||
|
||||
- `variant.h` - Pin definitions and hardware capabilities
|
||||
- `platformio.ini` - Build configuration
|
||||
- Optional: `pins_arduino.h`, `rfswitch.h`
|
||||
|
||||
Key defines in variant.h:
|
||||
|
||||
```cpp
|
||||
#define USE_SX1262 // Radio chip selection
|
||||
#define HAS_GPS 1 // Hardware capabilities
|
||||
#define LORA_CS 36 // Pin assignments
|
||||
#define SX126X_DIO1 14 // Radio-specific pins
|
||||
```
|
||||
|
||||
### Protobuf Messages
|
||||
|
||||
- Defined in `protobufs/meshtastic/*.proto`
|
||||
- Generated code in `src/mesh/generated/`
|
||||
- Regenerate with `bin/regen-protos.sh`
|
||||
- Message types prefixed with `meshtastic_`
|
||||
|
||||
### Conditional Compilation
|
||||
|
||||
```cpp
|
||||
#if !MESHTASTIC_EXCLUDE_GPS // Feature exclusion
|
||||
#ifdef ARCH_ESP32 // Architecture-specific
|
||||
#if defined(USE_SX1262) // Radio-specific
|
||||
#ifdef HAS_SCREEN // Hardware capability
|
||||
#if USERPREFS_EVENT_MODE // User preferences
|
||||
```
|
||||
|
||||
## Build System
|
||||
|
||||
Uses **PlatformIO** with custom scripts:
|
||||
|
||||
- `bin/platformio-pre.py` - Pre-build script
|
||||
- `bin/platformio-custom.py` - Custom build logic
|
||||
|
||||
Build commands:
|
||||
|
||||
```bash
|
||||
pio run -e tbeam # Build specific target
|
||||
pio run -e tbeam -t upload # Build and upload
|
||||
pio run -e native # Build native/Linux version
|
||||
```
|
||||
|
||||
## Common Tasks
|
||||
|
||||
### Adding a New Module
|
||||
|
||||
1. Create `src/modules/MyModule.cpp` and `.h`
|
||||
2. Inherit from appropriate base class
|
||||
3. Register in `src/modules/Modules.cpp`
|
||||
4. Add protobuf messages if needed in `protobufs/`
|
||||
|
||||
### Adding a New Hardware Variant
|
||||
|
||||
1. Create directory under `variants/<arch>/<name>/`
|
||||
2. Add `variant.h` with pin definitions
|
||||
3. Add `platformio.ini` with build config
|
||||
4. Reference common configs with `extends`
|
||||
|
||||
### Modifying Configuration Defaults
|
||||
|
||||
- Check `src/mesh/Default.h` for default value defines
|
||||
- Check `src/mesh/NodeDB.cpp` for initialization logic
|
||||
- Consider `isDefaultChannel()` checks for public channel restrictions
|
||||
|
||||
## Important Considerations
|
||||
|
||||
### Traffic Management
|
||||
|
||||
The mesh network has limited bandwidth. When modifying broadcast intervals:
|
||||
|
||||
- Respect minimum intervals on default/public channels
|
||||
- Use `Default::getConfiguredOrMinimumValue()` to enforce minimums
|
||||
- Consider `numOnlineNodes` scaling for congestion control
|
||||
|
||||
### Power Management
|
||||
|
||||
Many devices are battery-powered:
|
||||
|
||||
- Use `IF_ROUTER(routerVal, normalVal)` for role-based defaults
|
||||
- Check `config.power.is_power_saving` for power-saving modes
|
||||
- Implement proper `sleep()` methods in radio interfaces
|
||||
|
||||
### Channel Security
|
||||
|
||||
- `channels.isDefaultChannel(index)` - Check if using default/public settings
|
||||
- Default channels get stricter rate limits to prevent abuse
|
||||
- Private channels may have relaxed limits
|
||||
|
||||
## GitHub Actions CI/CD
|
||||
|
||||
The project uses GitHub Actions extensively for CI/CD. Key workflows are in `.github/workflows/`:
|
||||
|
||||
### Core CI Workflows
|
||||
|
||||
- **`main_matrix.yml`** - Main CI pipeline, runs on push to `master`/`develop` and PRs
|
||||
- Uses `bin/generate_ci_matrix.py` to dynamically generate build targets
|
||||
- Builds all supported hardware variants
|
||||
- PRs build a subset (`--level pr`) for faster feedback
|
||||
|
||||
- **`trunk_check.yml`** - Code quality checks on PRs
|
||||
- Runs Trunk.io for linting and formatting
|
||||
- Must pass before merge
|
||||
|
||||
- **`tests.yml`** - End-to-end and hardware tests
|
||||
- Runs daily on schedule
|
||||
- Includes native tests and hardware-in-the-loop testing
|
||||
|
||||
- **`test_native.yml`** - Native platform unit tests
|
||||
- Runs `pio test -e native`
|
||||
|
||||
### Release Workflows
|
||||
|
||||
- **`release_channels.yml`** - Triggered on GitHub release publish
|
||||
- Builds Docker images
|
||||
- Packages for PPA (Ubuntu), OBS (openSUSE), and COPR (Fedora)
|
||||
- Handles Alpha/Beta/Stable release channels
|
||||
|
||||
- **`nightly.yml`** - Nightly builds from develop branch
|
||||
|
||||
- **`docker_build.yml`** / **`docker_manifest.yml`** - Docker image builds
|
||||
|
||||
### Build Matrix Generation
|
||||
|
||||
The CI uses `bin/generate_ci_matrix.py` to dynamically select which targets to build:
|
||||
|
||||
```bash
|
||||
# Generate full build matrix
|
||||
./bin/generate_ci_matrix.py all
|
||||
|
||||
# Generate PR-level matrix (subset for faster builds)
|
||||
./bin/generate_ci_matrix.py all --level pr
|
||||
```
|
||||
|
||||
Variants can specify their support level in `platformio.ini`:
|
||||
|
||||
- `custom_meshtastic_support_level = 1` - Actively supported, built on every PR
|
||||
- `custom_meshtastic_support_level = 2` - Supported, built on merge to main branches
|
||||
- `board_level = extra` - Extra builds, only on full releases
|
||||
|
||||
### Running Workflows Locally
|
||||
|
||||
Most workflows can be triggered manually via `workflow_dispatch` for testing.
|
||||
|
||||
## Testing
|
||||
|
||||
- Unit tests in `test/` directory
|
||||
- Run with `pio test -e native`
|
||||
- Use `bin/test-simulator.sh` for simulation testing
|
||||
|
||||
## Resources
|
||||
|
||||
- [Documentation](https://meshtastic.org/docs/)
|
||||
@@ -14,7 +14,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
curl wget g++ zip git ca-certificates pkg-config \
|
||||
libgpiod-dev libyaml-cpp-dev libbluetooth-dev libi2c-dev libuv1-dev \
|
||||
libusb-1.0-0-dev libulfius-dev liborcania-dev libssl-dev \
|
||||
libx11-dev libinput-dev libxkbcommon-x11-dev libsqlite3-dev \
|
||||
libx11-dev libinput-dev libxkbcommon-x11-dev \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
|
||||
&& pip install --no-cache-dir -U platformio \
|
||||
&& mkdir /tmp/firmware
|
||||
|
||||
@@ -11,7 +11,7 @@ RUN apk --no-cache add \
|
||||
bash g++ libstdc++-dev linux-headers zip git ca-certificates libbsd-dev \
|
||||
libgpiod-dev yaml-cpp-dev bluez-dev \
|
||||
libusb-dev i2c-tools-dev libuv-dev openssl-dev pkgconf argp-standalone \
|
||||
libx11-dev libinput-dev libxkbcommon-dev sqlite-dev \
|
||||
libx11-dev libinput-dev libxkbcommon-dev \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& pip install --no-cache-dir -U platformio \
|
||||
&& mkdir /tmp/firmware
|
||||
|
||||
@@ -201,16 +201,6 @@ HostMetrics:
|
||||
# UserStringCommand: cat /sys/firmware/devicetree/base/serial-number # Command to execute, to send the results as the userString
|
||||
|
||||
|
||||
StoreAndForward:
|
||||
# Enabled: true # Enable Store and Forward++, true by default
|
||||
# DBPath: /var/lib/meshtasticd/ # Path to the S&F++ Sqlite DB
|
||||
# Stratum0: false # Specify if this node is a Stratum 0 node, the controller node.
|
||||
# InitialSync: 10 # Number of messages to
|
||||
# Hops: 3 # Number of hops to use for SF++ messages
|
||||
# AnnounceInterval: 5 # Interval in minutes between announcing tip of chain hash
|
||||
# MaxChainLength: 1000 # Maximum number of messages to store in a chain
|
||||
|
||||
|
||||
Config:
|
||||
# DisplayMode: TWOCOLOR # uncomment to force BaseUI
|
||||
# DisplayMode: COLOR # uncomment to force MUI
|
||||
|
||||
3
debian/control
vendored
3
debian/control
vendored
@@ -25,8 +25,7 @@ Build-Depends: debhelper-compat (= 13),
|
||||
liborcania-dev,
|
||||
libx11-dev,
|
||||
libinput-dev,
|
||||
libxkbcommon-x11-dev,
|
||||
libsqlite3-dev
|
||||
libxkbcommon-x11-dev
|
||||
Standards-Version: 4.6.2
|
||||
Homepage: https://github.com/meshtastic/firmware
|
||||
Rules-Requires-Root: no
|
||||
|
||||
@@ -39,7 +39,6 @@ BuildRequires: pkgconfig(bluez)
|
||||
BuildRequires: pkgconfig(libusb-1.0)
|
||||
BuildRequires: libi2c-devel
|
||||
BuildRequires: pkgconfig(libuv)
|
||||
BuildRequires: pkgconfig(sqlite3)
|
||||
# Web components:
|
||||
BuildRequires: pkgconfig(openssl)
|
||||
BuildRequires: pkgconfig(liborcania)
|
||||
|
||||
@@ -94,7 +94,7 @@ lib_deps =
|
||||
# renovate: datasource=custom.pio depName=NonBlockingRTTTL packageName=end2endzone/library/NonBlockingRTTTL
|
||||
end2endzone/NonBlockingRTTTL@1.4.0
|
||||
build_flags = ${env.build_flags} -Os
|
||||
build_src_filter = ${env.build_src_filter} -<platform/portduino/> -<graphics/niche/> -<modules/Native/>
|
||||
build_src_filter = ${env.build_src_filter} -<platform/portduino/> -<graphics/niche/>
|
||||
|
||||
; Common libs for communicating over TCP/IP networks such as MQTT
|
||||
[networking_base]
|
||||
|
||||
@@ -39,6 +39,7 @@ enum input_broker_event {
|
||||
#define INPUT_BROKER_MSG_FN_SYMBOL_ON 0xf1
|
||||
#define INPUT_BROKER_MSG_FN_SYMBOL_OFF 0xf2
|
||||
#define INPUT_BROKER_MSG_BLUETOOTH_TOGGLE 0xAA
|
||||
#define INPUT_BROKER_MSG_VOICEMEMO 0xAD
|
||||
#define INPUT_BROKER_MSG_TAB 0x09
|
||||
#define INPUT_BROKER_MSG_EMOTE_LIST 0x8F
|
||||
|
||||
|
||||
@@ -28,18 +28,18 @@ static unsigned char TCA8418TapMap[_TCA8418_NUM_KEYS][13] = {
|
||||
};
|
||||
|
||||
static unsigned char TCA8418LongPressMap[_TCA8418_NUM_KEYS] = {
|
||||
Key::ESC, // 1
|
||||
Key::UP, // 2
|
||||
Key::NONE, // 3
|
||||
Key::LEFT, // 4
|
||||
Key::NONE, // 5
|
||||
Key::RIGHT, // 6
|
||||
Key::NONE, // 7
|
||||
Key::DOWN, // 8
|
||||
Key::NONE, // 9
|
||||
Key::BSP, // *
|
||||
Key::NONE, // 0
|
||||
Key::NONE, // #
|
||||
Key::ESC, // 1
|
||||
Key::UP, // 2
|
||||
Key::NONE, // 3
|
||||
Key::LEFT, // 4
|
||||
Key::NONE, // 5
|
||||
Key::RIGHT, // 6
|
||||
Key::NONE, // 7
|
||||
Key::DOWN, // 8
|
||||
Key::NONE, // 9
|
||||
Key::BSP, // *
|
||||
Key::VOICEMEMO, // 0
|
||||
Key::NONE, // #
|
||||
};
|
||||
|
||||
TCA8418Keyboard::TCA8418Keyboard()
|
||||
|
||||
@@ -25,6 +25,7 @@ class TCA8418KeyboardBase
|
||||
BT_TOGGLE = 0xAA,
|
||||
GPS_TOGGLE = 0x9E,
|
||||
MUTE_TOGGLE = 0xAC,
|
||||
VOICEMEMO = 0xAD,
|
||||
SEND_PING = 0xAF,
|
||||
BL_TOGGLE = 0xAB
|
||||
};
|
||||
|
||||
@@ -56,8 +56,8 @@ static unsigned char TDeckProTapMap[_TCA8418_NUM_KEYS][5] = {
|
||||
{0x00, 0x00, 0x00}, // Ent, $, m, n, b, v, c, x, z, alt
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00},
|
||||
{0x20, 0x00, 0x00},
|
||||
{0x00, 0x00, '0'},
|
||||
{0x20, 0x00, Key::VOICEMEMO},
|
||||
{Key::VOICEMEMO, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00} // R_Shift, sym, space, mic, L_Shift
|
||||
};
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ static unsigned char TLoraPagerTapMap[_TCA8418_NUM_KEYS][3] = {{'q', 'Q', '1'},
|
||||
{'z', 'Z', '_'},
|
||||
{'x', 'X', '$'},
|
||||
{'c', 'C', ';'},
|
||||
{'v', 'V', '?'},
|
||||
{'v', 'V', Key::VOICEMEMO},
|
||||
{'b', 'B', '!'},
|
||||
{'n', 'N', ','},
|
||||
{'m', 'M', '.'},
|
||||
|
||||
@@ -163,6 +163,16 @@ int32_t KbI2cBase::runOnce()
|
||||
e.kbchar = key.key;
|
||||
}
|
||||
break;
|
||||
case 'v': // sym v - voice memo
|
||||
if (is_sym) {
|
||||
e.inputEvent = INPUT_BROKER_ANYKEY;
|
||||
e.kbchar = INPUT_BROKER_MSG_VOICEMEMO;
|
||||
is_sym = false; // reset sym state after second keypress
|
||||
} else {
|
||||
e.inputEvent = INPUT_BROKER_ANYKEY;
|
||||
e.kbchar = key.key;
|
||||
}
|
||||
break;
|
||||
case 0x13: // Code scanner says the SYM key is 0x13
|
||||
is_sym = !is_sym;
|
||||
e.inputEvent = INPUT_BROKER_ANYKEY;
|
||||
@@ -370,6 +380,10 @@ int32_t KbI2cBase::runOnce()
|
||||
|
||||
if (i2cBus->available()) {
|
||||
char c = i2cBus->read();
|
||||
// Debug: log every key press
|
||||
if (c != 0x00) {
|
||||
LOG_DEBUG("T-Deck KB: key=0x%02X ('%c'), is_sym=%d", (uint8_t)c, (c >= 0x20 && c < 0x7f) ? c : '?', is_sym);
|
||||
}
|
||||
InputEvent e = {};
|
||||
e.inputEvent = INPUT_BROKER_NONE;
|
||||
e.source = this->_originName;
|
||||
@@ -443,6 +457,17 @@ int32_t KbI2cBase::runOnce()
|
||||
e.kbchar = c;
|
||||
}
|
||||
break;
|
||||
case 0x76: // letter v. voice memo trigger
|
||||
if (is_sym) {
|
||||
is_sym = false;
|
||||
e.inputEvent = INPUT_BROKER_ANYKEY;
|
||||
e.kbchar = INPUT_BROKER_MSG_VOICEMEMO;
|
||||
LOG_DEBUG("T-Deck: Sym+V pressed, sending VOICEMEMO 0x%02X", INPUT_BROKER_MSG_VOICEMEMO);
|
||||
} else {
|
||||
e.inputEvent = INPUT_BROKER_ANYKEY;
|
||||
e.kbchar = c;
|
||||
}
|
||||
break;
|
||||
case 0x1b: // ESC
|
||||
e.inputEvent = INPUT_BROKER_CANCEL;
|
||||
break;
|
||||
@@ -466,9 +491,11 @@ int32_t KbI2cBase::runOnce()
|
||||
e.inputEvent = INPUT_BROKER_RIGHT;
|
||||
e.kbchar = 0;
|
||||
break;
|
||||
case 0xc: // Modifier key: 0xc is alt+c (Other options could be: 0xea = shift+mic button or 0x4 shift+$(speaker))
|
||||
case 0x3F: // Sym key on some T-Deck variants (sends '?')
|
||||
case 0xc: // Modifier key: 0xc is alt+c (Other options could be: 0xea = shift+mic button or 0x4 shift+$(speaker))
|
||||
// toggle moddifiers button.
|
||||
is_sym = !is_sym;
|
||||
LOG_DEBUG("T-Deck: Modifier key pressed, is_sym now=%d", is_sym);
|
||||
e.inputEvent = INPUT_BROKER_ANYKEY;
|
||||
e.kbchar = is_sym ? INPUT_BROKER_MSG_FN_SYMBOL_ON // send 0xf1 to tell CannedMessages to display that the
|
||||
: INPUT_BROKER_MSG_FN_SYMBOL_OFF; // modifier key is active
|
||||
|
||||
@@ -326,9 +326,9 @@ uint32_t RadioInterface::getTxDelayMsecWeighted(meshtastic_MeshPacket *p)
|
||||
void printPacket(const char *prefix, const meshtastic_MeshPacket *p)
|
||||
{
|
||||
#if defined(DEBUG_PORT) && !defined(DEBUG_MUTE)
|
||||
std::string out = DEBUG_PORT.mt_sprintf(
|
||||
"%s (id=0x%08x fr=0x%08x to=0x%08x, transport = %u, WantAck=%d, HopLim=%d HopStart=%d Ch=0x%x", prefix, p->id, p->from,
|
||||
p->to, p->transport_mechanism, p->want_ack, p->hop_limit, p->hop_start, p->channel);
|
||||
std::string out =
|
||||
DEBUG_PORT.mt_sprintf("%s (id=0x%08x fr=0x%08x to=0x%08x, transport = %u, WantAck=%d, HopLim=%d Ch=0x%x", prefix, p->id,
|
||||
p->from, p->to, p->transport_mechanism, p->want_ack, p->hop_limit, p->channel);
|
||||
if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) {
|
||||
auto &s = p->decoded;
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#endif
|
||||
#include "Default.h"
|
||||
#if ARCH_PORTDUINO
|
||||
#include "modules/Native/StoreForwardPlusPlus.h"
|
||||
#include "platform/portduino/PortduinoGlue.h"
|
||||
#endif
|
||||
#if ENABLE_JSON_LOGGING || ARCH_PORTDUINO
|
||||
@@ -360,12 +359,6 @@ ErrorCode Router::send(meshtastic_MeshPacket *p)
|
||||
abortSendAndNak(encodeResult, p);
|
||||
return encodeResult; // FIXME - this isn't a valid ErrorCode
|
||||
}
|
||||
#if ARCH_PORTDUINO
|
||||
if (p_decoded->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP &&
|
||||
(p->from == 0 || p->from == nodeDB->getNodeNum()) && storeForwardPlusPlusModule && portduino_config.sfpp_enabled) {
|
||||
storeForwardPlusPlusModule->handleEncrypted(p_decoded, p);
|
||||
}
|
||||
#endif
|
||||
#if !MESHTASTIC_EXCLUDE_MQTT
|
||||
// Only publish to MQTT if we're the original transmitter of the packet
|
||||
if (moduleConfig.mqtt.enabled && isFromUs(p) && mqtt) {
|
||||
@@ -742,29 +735,6 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src)
|
||||
cancelSending(p->from, p->id);
|
||||
skipHandle = true;
|
||||
}
|
||||
#if ARCH_PORTDUINO
|
||||
if (portduino_config.whitelist_enabled) {
|
||||
bool allowed = false;
|
||||
for (const auto &port : portduino_config.whitelist_ports) {
|
||||
if (port == p->decoded.portnum) {
|
||||
allowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!allowed) {
|
||||
LOG_DEBUG("Dropping packet not on Portduino Whitelist");
|
||||
cancelSending(p->from, p->id);
|
||||
skipHandle = true;
|
||||
}
|
||||
}
|
||||
for (const auto &port : portduino_config.nohop_ports) {
|
||||
if (port == p->decoded.portnum) {
|
||||
p->hop_start -= p->hop_limit;
|
||||
p->hop_limit = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
printPacket("packet decoding failed or skipped (no PSK?)", p);
|
||||
}
|
||||
|
||||
@@ -89,9 +89,8 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF
|
||||
void handleGetCannedMessageModuleMessages(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);
|
||||
void handleSetCannedMessageModuleMessages(const char *from_msg);
|
||||
|
||||
#ifdef RAK14014
|
||||
// Get current run state (used by VoiceMemoModule to avoid conflicts)
|
||||
cannedMessageModuleRunState getRunState() const { return runState; }
|
||||
#endif
|
||||
|
||||
// === Packet Interest Filter ===
|
||||
virtual bool wantPacket(const meshtastic_MeshPacket *p) override
|
||||
|
||||
@@ -61,7 +61,6 @@
|
||||
#if ARCH_PORTDUINO
|
||||
#include "input/LinuxInputImpl.h"
|
||||
#include "input/SeesawRotary.h"
|
||||
#include "modules/Native/StoreForwardPlusPlus.h"
|
||||
#include "modules/Telemetry/HostMetrics.h"
|
||||
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
|
||||
#include "modules/StoreForwardModule.h"
|
||||
@@ -88,6 +87,9 @@
|
||||
#if defined(USE_SX1280) && !MESHTASTIC_EXCLUDE_AUDIO
|
||||
#include "modules/esp32/AudioModule.h"
|
||||
#endif
|
||||
#if defined(HAS_I2S) && !MESHTASTIC_EXCLUDE_VOICEMEMO
|
||||
#include "modules/VoiceMemoModule.h"
|
||||
#endif
|
||||
#if !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
||||
#include "modules/esp32/PaxcounterModule.h"
|
||||
#endif
|
||||
@@ -244,11 +246,6 @@ void setupModules()
|
||||
#endif
|
||||
#if ARCH_PORTDUINO
|
||||
new HostMetricsModule();
|
||||
#if SFPP_ENABLED
|
||||
if (portduino_config.sfpp_enabled) {
|
||||
storeForwardPlusPlusModule = new StoreForwardPlusPlusModule();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_TELEMETRY
|
||||
new DeviceTelemetryModule();
|
||||
@@ -291,6 +288,9 @@ void setupModules()
|
||||
#if defined(USE_SX1280) && !MESHTASTIC_EXCLUDE_AUDIO
|
||||
audioModule = new AudioModule();
|
||||
#endif
|
||||
#if defined(HAS_I2S) && !MESHTASTIC_EXCLUDE_VOICEMEMO
|
||||
voiceMemoModule = new VoiceMemoModule();
|
||||
#endif
|
||||
#if !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
||||
if (moduleConfig.has_paxcounter && moduleConfig.paxcounter.enabled) {
|
||||
paxcounterModule = new PaxcounterModule();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,310 +0,0 @@
|
||||
#pragma once
|
||||
#if __has_include("sqlite3.h")
|
||||
#define SFPP_ENABLED 1
|
||||
#include "Channels.h"
|
||||
#include "ProtobufModule.h"
|
||||
#include "Router.h"
|
||||
#include "SinglePortModule.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
#define SFPP_HASH_SIZE 16
|
||||
#define SFPP_SHORT_HASH_SIZE 8
|
||||
|
||||
/**
|
||||
* Store and forward ++ module
|
||||
* There's an obvious need for a store-and-forward mechanism in Meshtastic.
|
||||
* This module takes heavy inspiration from Git, building a chain of messages that can be synced between nodes.
|
||||
* Each message is hashed, and the chain is built by hashing the previous commit hash and the current message hash.
|
||||
* Nodes can request missing messages by requesting the next message after a given commit hash.
|
||||
*
|
||||
* The current focus is text messages, limited to the primary channel.
|
||||
*
|
||||
* Each chain is identified by a root hash, which is derived from the channelHash, the local nodenum, and the timestamp when
|
||||
* created.
|
||||
*
|
||||
* Each message is also given a message hash, derived from the encrypted payload, the to, from, id.
|
||||
* Notably not the timestamp, as we want these to match across nodes, even if the timestamps differ.
|
||||
*
|
||||
* The authoritative node for the chain will generate a commit hash for each message when adding it to the chain.
|
||||
* The first message's commit hash is derived from the root hash and the message hash.
|
||||
* Subsequent messages' commit hashes are derived from the previous commit hash and the current message hash.
|
||||
* This allows a node to see only the last commit hash, and confirm it hasn't missed any messages.
|
||||
*
|
||||
* Nodes can request the next message in the chain by sending a LINK_REQUEST message with the root hash and the last known commit
|
||||
* hash. Any node that has the next message can respond with a LINK_PROVIDE message containing the next message.
|
||||
*
|
||||
* When a satellite node sees a new text message, it stores it in a scratch database.
|
||||
* These messages are periodically offered to the authoritative node for inclusion in the chain.
|
||||
*
|
||||
* The LINK_PROVIDE message does double-duty, sending both on-chain and off-chain messages.
|
||||
* The differentiator is whether the commit hash is set or left empty.
|
||||
*
|
||||
* When a satellite node receives a canonical link message, it checks if it has the message in scratch.
|
||||
* And evicts it when adding it to the canonical chain.
|
||||
*
|
||||
* This approach allows a node to know whether it has seen a given message before, or if it is new coming via SFPP.
|
||||
* If new, and the timestamp is within the rebroadcast timeout, it will process that message as if it were just received from the
|
||||
* mesh, allowing it to be decrypted, shown to the user, and rebroadcast.
|
||||
*/
|
||||
class StoreForwardPlusPlusModule : public ProtobufModule<meshtastic_StoreForwardPlusPlus>, private concurrency::OSThread
|
||||
{
|
||||
struct link_object {
|
||||
uint32_t to;
|
||||
uint32_t from;
|
||||
uint32_t id;
|
||||
uint32_t rx_time = 0;
|
||||
ChannelHash channel_hash;
|
||||
uint8_t encrypted_bytes[256] = {0};
|
||||
size_t encrypted_len;
|
||||
uint8_t message_hash[SFPP_HASH_SIZE] = {0};
|
||||
size_t message_hash_len = 0;
|
||||
uint8_t root_hash[SFPP_HASH_SIZE] = {0};
|
||||
size_t root_hash_len = 0;
|
||||
uint8_t commit_hash[SFPP_HASH_SIZE] = {0};
|
||||
size_t commit_hash_len = 0;
|
||||
uint32_t counter = 0;
|
||||
std::string payload;
|
||||
bool validObject = true; // set this false when a chain calulation fails, etc.
|
||||
};
|
||||
|
||||
public:
|
||||
/** Constructor
|
||||
*
|
||||
*/
|
||||
StoreForwardPlusPlusModule();
|
||||
|
||||
/*
|
||||
-Override the wantPacket method.
|
||||
*/
|
||||
virtual bool wantPacket(const meshtastic_MeshPacket *p) override
|
||||
{
|
||||
if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP ||
|
||||
p->decoded.portnum == (portduino_config.sfpp_steal_port ? meshtastic_PortNum_TEXT_MESSAGE_COMPRESSED_APP
|
||||
: meshtastic_PortNum_STORE_FORWARD_PLUSPLUS_APP)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void handleEncrypted(const meshtastic_MeshPacket *, const meshtastic_MeshPacket *);
|
||||
|
||||
protected:
|
||||
/** Called to handle a particular incoming message
|
||||
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for
|
||||
it
|
||||
*/
|
||||
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
||||
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_StoreForwardPlusPlus *t) override;
|
||||
|
||||
virtual int32_t runOnce() override;
|
||||
|
||||
private:
|
||||
sqlite3 *ppDb;
|
||||
sqlite3_stmt *chain_insert_stmt;
|
||||
sqlite3_stmt *scratch_insert_stmt;
|
||||
sqlite3_stmt *checkDupMessageHash;
|
||||
sqlite3_stmt *checkDupCommitHash;
|
||||
sqlite3_stmt *checkScratch;
|
||||
sqlite3_stmt *removeScratch;
|
||||
sqlite3_stmt *updatePayloadStmt;
|
||||
sqlite3_stmt *getPayloadFromScratchStmt;
|
||||
sqlite3_stmt *fromScratchStmt;
|
||||
sqlite3_stmt *fromScratchByHashStmt;
|
||||
sqlite3_stmt *getNextHashStmt;
|
||||
sqlite3_stmt *getChainEndStmt;
|
||||
sqlite3_stmt *getLinkStmt;
|
||||
sqlite3_stmt *getLinkFromMessageHashStmt;
|
||||
sqlite3_stmt *getHashFromRootStmt;
|
||||
sqlite3_stmt *addRootToMappingsStmt;
|
||||
sqlite3_stmt *getRootFromChannelHashStmt;
|
||||
sqlite3_stmt *getFullRootHashStmt;
|
||||
sqlite3_stmt *setChainCountStmt;
|
||||
sqlite3_stmt *getChainCountStmt;
|
||||
sqlite3_stmt *getScratchCountStmt;
|
||||
sqlite3_stmt *getRootCanonScratchCountStmt;
|
||||
sqlite3_stmt *pruneScratchQueueStmt;
|
||||
sqlite3_stmt *trimOldestLinkStmt;
|
||||
sqlite3_stmt *maybeAddPeerStmt;
|
||||
sqlite3_stmt *getPeerStmt;
|
||||
sqlite3_stmt *updatePeerStmt;
|
||||
sqlite3_stmt *clearChainStmt;
|
||||
sqlite3_stmt *canon_scratch_insert_stmt;
|
||||
sqlite3_stmt *getCanonScratchCountStmt;
|
||||
sqlite3_stmt *getCanonScratchStmt;
|
||||
sqlite3_stmt *removeCanonScratch;
|
||||
sqlite3_stmt *clearCanonScratchStmt;
|
||||
|
||||
// For a given Meshtastic ChannelHash, fills the root_hash buffer with a 32-byte root hash
|
||||
// returns true if the root hash was found
|
||||
bool getRootFromChannelHash(ChannelHash, uint8_t *);
|
||||
|
||||
// For a given root hash, returns the ChannelHash
|
||||
// can handle partial root hashes
|
||||
ChannelHash getChannelHashFromRoot(uint8_t *_root_hash, size_t);
|
||||
|
||||
// given a root hash and commit hash, returns the next commit hash in the chain
|
||||
// can handle partial root and commit hashes, always fills the buffer with 32 bytes
|
||||
// returns true if a next hash was found
|
||||
bool getNextHash(uint8_t *, size_t, uint8_t *, size_t, uint8_t *);
|
||||
|
||||
// For a given Meshtastic ChannelHash, fills the root_hash buffer with a 32-byte root hash
|
||||
// but this function will add the root hash if it is not already present
|
||||
// returns hash size or 0 if not found/added
|
||||
size_t getOrAddRootFromChannelHash(ChannelHash, uint8_t *);
|
||||
|
||||
// adds the ChannelHash and root_hash to the mappings table
|
||||
void addRootToMappings(ChannelHash, uint8_t *);
|
||||
|
||||
// requests the next message in the chain from the mesh network
|
||||
// Sends a LINK_REQUEST message
|
||||
void requestNextMessage(uint8_t *, size_t, uint8_t *, size_t);
|
||||
|
||||
// request the message X entries from the end.
|
||||
// used to bootstrap a chain, without downloading all of the history
|
||||
void requestMessageCount(uint8_t *, size_t, uint32_t);
|
||||
|
||||
// sends a LINK_PROVIDE message broadcasting the given link object
|
||||
void broadcastLink(uint8_t *, size_t);
|
||||
|
||||
// sends a LINK_PROVIDE message broadcasting the given link object
|
||||
void broadcastLink(link_object &, bool, bool = false);
|
||||
|
||||
// sends a LINK_PROVIDE message broadcasting the given link object from scratch message store
|
||||
bool sendFromScratch(uint8_t *);
|
||||
|
||||
// Adds the given link object to the canonical chain database
|
||||
bool addToChain(link_object &);
|
||||
|
||||
// Adds an incoming text message to the scratch database
|
||||
bool addToScratch(link_object &);
|
||||
|
||||
// sends a CANON_ANNOUNCE message, specifying the given root and commit hashes
|
||||
void canonAnnounce(link_object &);
|
||||
|
||||
// checks if the message hash is present in the canonical chain database
|
||||
bool isInDB(uint8_t *, size_t);
|
||||
|
||||
// checks if the commit hash is present in the canonical chain database
|
||||
bool isCommitInDB(uint8_t *, size_t);
|
||||
|
||||
// checks if the message hash is present in the scratch database
|
||||
bool isInScratch(uint8_t *, size_t);
|
||||
|
||||
// retrieves a link object from the scratch database
|
||||
link_object getFromScratch(uint8_t *, size_t);
|
||||
|
||||
// removes a link object from the scratch database
|
||||
void removeFromScratch(uint8_t *, size_t);
|
||||
|
||||
// iterate through our scratch database, and see if we can speculate a chain up to the given commit hash
|
||||
bool speculateScratchChain(uint8_t *, size_t, uint8_t *, uint8_t *);
|
||||
|
||||
// retrieves the next link object from scratch given a root hash
|
||||
link_object getNextScratchObject(uint8_t *);
|
||||
|
||||
// fills the payload section with the decrypted data for the given message hash
|
||||
// probably not needed for production, but useful for testing
|
||||
void updatePayload(uint8_t *, size_t, std::string);
|
||||
|
||||
// Takes the decrypted MeshPacket and the encrypted packet copy, and builds a link_object
|
||||
// Generates a message hash, but does not set the commit hash
|
||||
link_object ingestTextPacket(const meshtastic_MeshPacket &, const meshtastic_MeshPacket *);
|
||||
|
||||
// ingests a LINK_PROVIDE message and builds a link_object
|
||||
// confirms the root hash and commit hash
|
||||
link_object ingestLinkMessage(meshtastic_StoreForwardPlusPlus *);
|
||||
|
||||
// retrieves a link object from the canonical chain database given a commit hash
|
||||
link_object getLink(uint8_t *, size_t);
|
||||
|
||||
// retrieves a link object from the canonical chain database given a message hash
|
||||
link_object getLinkFromMessageHash(uint8_t *, size_t);
|
||||
|
||||
// puts the encrypted payload back into the queue as if it were just received
|
||||
void rebroadcastLinkObject(link_object &);
|
||||
|
||||
// Check if an incoming link object's commit hash matches the calculated commit hash
|
||||
bool checkCommitHash(link_object &lo, uint8_t *commit_hash_bytes, size_t hash_len);
|
||||
|
||||
// given a partial root hash, looks up the full 32-byte root hash
|
||||
// returns true if found
|
||||
bool lookUpFullRootHash(uint8_t *partial_root_hash, size_t partial_root_hash_len, uint8_t *full_root_hash);
|
||||
|
||||
// update the mappings table to set the chain count for the given root hash
|
||||
void setChainCount(uint8_t *, size_t, uint32_t);
|
||||
|
||||
// get the chain count for the given root hash
|
||||
uint32_t getChainCount(uint8_t *, size_t);
|
||||
|
||||
// get the scratch count for the given root hash
|
||||
uint32_t getScratchCount(uint8_t *, size_t);
|
||||
|
||||
// get the canon scratch count for the given root hash
|
||||
uint32_t getCanonScratchCount(uint8_t *, size_t);
|
||||
|
||||
link_object getLinkFromPositionFromTip(uint32_t, uint8_t *, size_t);
|
||||
|
||||
void pruneScratchQueue();
|
||||
|
||||
void trimOldestLink(uint8_t *, size_t);
|
||||
|
||||
void clearChain(uint8_t *, size_t);
|
||||
|
||||
void recalculateMessageHash(link_object &);
|
||||
|
||||
// given a link object with a payload and other fields, recalculates the message hash
|
||||
// returns true if a match
|
||||
bool recalculateHash(link_object &, uint8_t *, size_t, uint8_t *, size_t);
|
||||
|
||||
void updatePeers(const meshtastic_MeshPacket &, meshtastic_StoreForwardPlusPlus_SFPP_message_type);
|
||||
|
||||
void maybeMoveFromCanonScratch(uint8_t *, size_t);
|
||||
|
||||
void addToCanonScratch(link_object &);
|
||||
|
||||
link_object getfromCanonScratch(uint8_t *, size_t);
|
||||
void removeFromCanonScratch(uint8_t *, size_t);
|
||||
|
||||
void clearCanonScratch(uint8_t *, size_t, uint32_t);
|
||||
|
||||
bool isInCanonScratch(uint8_t *, size_t);
|
||||
|
||||
void logLinkObject(link_object &);
|
||||
|
||||
// Track if we have a scheduled runOnce pending
|
||||
// useful to not accudentally delay a scheduled runOnce
|
||||
bool pendingRun = false;
|
||||
|
||||
// Once we have multiple chain types, we can extend this
|
||||
enum chain_types {
|
||||
channel_chain = 0,
|
||||
};
|
||||
|
||||
uint32_t rebroadcastTimeout = 3600; // Messages older than this (in seconds) will not be rebroadcast
|
||||
bool doing_split_send = false;
|
||||
link_object split_link_out;
|
||||
|
||||
bool doing_split_receive = false;
|
||||
link_object split_link_in;
|
||||
|
||||
bool did_announce_last = false;
|
||||
|
||||
uint32_t texts_rebroadcast = 0;
|
||||
uint32_t links_speculated = 0;
|
||||
uint32_t canon_announces = 0;
|
||||
uint32_t links_requested = 0;
|
||||
uint32_t links_provided = 0;
|
||||
uint32_t links_added = 0;
|
||||
uint32_t links_from_canon_scratch = 0;
|
||||
uint32_t links_from_scratch = 0;
|
||||
uint32_t split_links_sent = 0;
|
||||
uint32_t split_links_received = 0;
|
||||
uint32_t links_pruned = 0;
|
||||
uint32_t scratch_timed_out = 0;
|
||||
uint32_t sent_from_scratch = 0;
|
||||
uint32_t received_from_scratch = 0;
|
||||
};
|
||||
|
||||
extern StoreForwardPlusPlusModule *storeForwardPlusPlusModule;
|
||||
#endif
|
||||
1205
src/modules/VoiceMemoModule.cpp
Normal file
1205
src/modules/VoiceMemoModule.cpp
Normal file
File diff suppressed because it is too large
Load Diff
180
src/modules/VoiceMemoModule.h
Normal file
180
src/modules/VoiceMemoModule.h
Normal file
@@ -0,0 +1,180 @@
|
||||
#pragma once
|
||||
|
||||
#include "SinglePortModule.h"
|
||||
#include "concurrency/OSThread.h"
|
||||
#include "configuration.h"
|
||||
#include "input/InputBroker.h"
|
||||
#include "mesh/generated/meshtastic/module_config.pb.h"
|
||||
|
||||
#if defined(ARCH_ESP32) && defined(HAS_I2S) && !MESHTASTIC_EXCLUDE_VOICEMEMO
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ButterworthFilter.h>
|
||||
#include <OLEDDisplay.h>
|
||||
#include <OLEDDisplayUi.h>
|
||||
#include <codec2.h>
|
||||
#include <driver/i2s.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
/**
|
||||
* VoiceMemoModule - Store and forward short codec2 encoded audio messages
|
||||
*
|
||||
* Unlike the existing AudioModule which is designed for real-time push-to-talk,
|
||||
* this module is designed for short voice memos that are:
|
||||
* - Recorded when the user holds Shift+Space
|
||||
* - Encoded with Codec2 for compression
|
||||
* - Sent over the mesh with hop_limit=0 (local only)
|
||||
* - Stored on receiving devices for later playback
|
||||
* - Played back when user long-presses on the notification
|
||||
*/
|
||||
|
||||
// Voice memo states
|
||||
enum class VoiceMemoState { IDLE, RECORDING, SENDING, RECEIVING, PLAYING };
|
||||
|
||||
// Codec2 magic header for voice memos
|
||||
const char VOICEMEMO_MAGIC[4] = {0xc0, 0xde, 0xc2, 0x4d}; // c0dec2M (M for Memo)
|
||||
|
||||
struct VoiceMemoHeader {
|
||||
char magic[4];
|
||||
uint8_t mode; // Codec2 mode
|
||||
uint8_t sequence; // Packet sequence number (for multi-packet memos)
|
||||
uint8_t totalParts; // Total number of packets in this memo (0 = unknown/streaming)
|
||||
uint8_t memoId; // Unique ID for this recording session (to identify related packets)
|
||||
};
|
||||
|
||||
// Maximum recording time in seconds
|
||||
#define VOICEMEMO_MAX_RECORD_SECS 10
|
||||
#define VOICEMEMO_ADC_BUFFER_SIZE 320 // Codec2 samples per frame
|
||||
#define VOICEMEMO_UPSAMPLE_BUFFER_SIZE 3600 // 320 * (44100/8000) * 2 (stereo) ≈ 3528, rounded up
|
||||
#define VOICEMEMO_I2S_PORT I2S_NUM_0
|
||||
// Codec2 mode - use protobuf enum minus 1 to get codec2 library mode
|
||||
#define VOICEMEMO_CODEC2_MODE (meshtastic_ModuleConfig_AudioConfig_Audio_Baud_CODEC2_700 - 1)
|
||||
|
||||
// Storage for received voice memos
|
||||
#define VOICEMEMO_MAX_STORED 5
|
||||
struct StoredVoiceMemo {
|
||||
NodeNum from;
|
||||
uint32_t timestamp;
|
||||
uint8_t data[meshtastic_Constants_DATA_PAYLOAD_LEN * 4]; // Allow up to 4 packets
|
||||
size_t dataLen;
|
||||
uint8_t codec2Mode;
|
||||
uint8_t memoId; // Memo ID from sender (to identify related packets)
|
||||
uint8_t receivedParts; // Bitmask of received packet sequences
|
||||
uint8_t expectedParts; // Total expected parts (0 = unknown)
|
||||
bool played;
|
||||
};
|
||||
|
||||
class VoiceMemoModule : public SinglePortModule, public Observable<const UIFrameEvent *>, private concurrency::OSThread
|
||||
{
|
||||
public:
|
||||
VoiceMemoModule();
|
||||
|
||||
/**
|
||||
* Check if we should draw the UI frame
|
||||
*/
|
||||
bool shouldDraw();
|
||||
|
||||
/**
|
||||
* Handle keyboard input for Shift+Space detection
|
||||
*/
|
||||
int handleInputEvent(const InputEvent *event);
|
||||
|
||||
/**
|
||||
* Play a stored voice memo
|
||||
*/
|
||||
void playStoredMemo(int index);
|
||||
|
||||
/**
|
||||
* Get number of unplayed memos
|
||||
*/
|
||||
int getUnplayedCount();
|
||||
|
||||
/**
|
||||
* Get stored memo info for UI
|
||||
*/
|
||||
const StoredVoiceMemo *getStoredMemo(int index);
|
||||
|
||||
protected:
|
||||
virtual int32_t runOnce() override;
|
||||
virtual meshtastic_MeshPacket *allocReply() override;
|
||||
virtual bool wantUIFrame() override { return shouldDraw(); }
|
||||
virtual Observable<const UIFrameEvent *> *getUIFrameObservable() override { return this; }
|
||||
|
||||
#if HAS_SCREEN
|
||||
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
|
||||
#endif
|
||||
|
||||
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override;
|
||||
|
||||
private:
|
||||
// State machine
|
||||
VoiceMemoState state = VoiceMemoState::IDLE;
|
||||
|
||||
// Codec2
|
||||
CODEC2 *codec2 = nullptr;
|
||||
int encodeCodecSize = 0;
|
||||
int adcBufferSize = 0;
|
||||
|
||||
// Audio buffers
|
||||
int16_t speechBuffer[VOICEMEMO_ADC_BUFFER_SIZE] = {};
|
||||
int16_t outputBuffer[VOICEMEMO_ADC_BUFFER_SIZE] = {};
|
||||
int16_t upsampleBuffer[VOICEMEMO_UPSAMPLE_BUFFER_SIZE] = {}; // For 8kHz->44.1kHz upsampling
|
||||
uint8_t encodedFrame[meshtastic_Constants_DATA_PAYLOAD_LEN] = {};
|
||||
size_t encodedFrameIndex = 0;
|
||||
|
||||
// Recording state
|
||||
uint32_t recordingStartMs = 0;
|
||||
uint32_t sendingCompleteMs = 0; // When sending completed (for "Sent!" display timeout)
|
||||
uint8_t currentMemoId = 0; // Unique ID for current recording session
|
||||
uint8_t currentSequence = 0; // Current packet sequence number
|
||||
|
||||
// I2S state
|
||||
bool i2sInitialized = false;
|
||||
|
||||
// Stored memos for playback
|
||||
StoredVoiceMemo storedMemos[VOICEMEMO_MAX_STORED];
|
||||
int storedMemoCount = 0;
|
||||
|
||||
// Playback state
|
||||
int playingMemoIndex = -1;
|
||||
size_t playbackPosition = 0;
|
||||
|
||||
// Filter for audio cleanup
|
||||
ButterworthFilter *hpFilter = nullptr;
|
||||
|
||||
// Codec2 task for encoding (needs large stack)
|
||||
TaskHandle_t codec2TaskHandle = nullptr;
|
||||
volatile bool codec2TaskRunning = false;
|
||||
volatile bool audioReady = false;
|
||||
|
||||
// Playback task (also needs large stack for Codec2 decoding)
|
||||
TaskHandle_t playbackTaskHandle = nullptr;
|
||||
volatile bool playbackTaskRunning = false;
|
||||
volatile bool playbackReady = false;
|
||||
const StoredVoiceMemo *currentPlaybackMemo = nullptr;
|
||||
|
||||
// Internal methods
|
||||
bool initES7210();
|
||||
bool initI2S();
|
||||
void deinitI2S();
|
||||
void startRecording();
|
||||
void stopRecording();
|
||||
void processRecordingBuffer();
|
||||
void sendEncodedPayload();
|
||||
void storeMemo(const meshtastic_MeshPacket &mp);
|
||||
void playMemo(const StoredVoiceMemo &memo);
|
||||
|
||||
public:
|
||||
// Called by the codec2 task - needs to be public for task function access
|
||||
void doCodec2Encode();
|
||||
void doCodec2Playback();
|
||||
|
||||
// Keyboard observer
|
||||
CallbackObserver<VoiceMemoModule, const InputEvent *> inputObserver =
|
||||
CallbackObserver<VoiceMemoModule, const InputEvent *>(this, &VoiceMemoModule::handleInputEvent);
|
||||
};
|
||||
|
||||
extern VoiceMemoModule *voiceMemoModule;
|
||||
|
||||
#endif // ARCH_ESP32 && HAS_I2S && !MESHTASTIC_EXCLUDE_VOICEMEMO
|
||||
@@ -177,7 +177,6 @@ void portduinoSetup()
|
||||
|
||||
if (portduino_config.force_simradio == true) {
|
||||
portduino_config.lora_module = use_simradio;
|
||||
portduino_config.sfpp_enabled = false;
|
||||
} else if (configPath != nullptr) {
|
||||
if (loadConfig(configPath)) {
|
||||
if (!yamlOnly)
|
||||
@@ -832,28 +831,6 @@ bool loadConfig(const char *configPath)
|
||||
}
|
||||
}
|
||||
|
||||
if (yamlConfig["StoreAndForward"]) {
|
||||
portduino_config.sfpp_stratum0 = (yamlConfig["StoreAndForward"]["Stratum0"]).as<bool>(false);
|
||||
portduino_config.sfpp_enabled = (yamlConfig["StoreAndForward"]["Enabled"]).as<bool>(true);
|
||||
portduino_config.sfpp_db_path = (yamlConfig["StoreAndForward"]["DBPath"]).as<std::string>("/var/lib/meshtasticd/");
|
||||
portduino_config.sfpp_initial_sync = (yamlConfig["StoreAndForward"]["InitialSync"]).as<int>(10);
|
||||
portduino_config.sfpp_hops = (yamlConfig["StoreAndForward"]["Hops"]).as<int>(3);
|
||||
portduino_config.sfpp_announce_interval = (yamlConfig["StoreAndForward"]["AnnounceInterval"]).as<int>(5);
|
||||
portduino_config.sfpp_max_chain = (yamlConfig["StoreAndForward"]["MaxChainLength"]).as<uint32_t>(1000);
|
||||
portduino_config.sfpp_backlog_limit = (yamlConfig["StoreAndForward"]["BacklogLimit"]).as<uint32_t>(100);
|
||||
portduino_config.sfpp_steal_port = (yamlConfig["StoreAndForward"]["StealPort"]).as<bool>(false);
|
||||
}
|
||||
if (yamlConfig["Routing"]) {
|
||||
if (yamlConfig["Routing"]["WhitelistPorts"]) {
|
||||
portduino_config.whitelist_ports = (yamlConfig["Routing"]["WhitelistPorts"]).as<std::vector<int>>();
|
||||
if (portduino_config.whitelist_ports.size() > 0) {
|
||||
portduino_config.whitelist_enabled = true;
|
||||
}
|
||||
}
|
||||
if (yamlConfig["Routing"]["NoHopPorts"]) {
|
||||
portduino_config.nohop_ports = (yamlConfig["Routing"]["NoHopPorts"]).as<std::vector<int>>();
|
||||
}
|
||||
}
|
||||
if (yamlConfig["General"]) {
|
||||
portduino_config.MaxNodes = (yamlConfig["General"]["MaxNodes"]).as<int>(200);
|
||||
portduino_config.maxtophone = (yamlConfig["General"]["MaxMessageQueue"]).as<int>(100);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "LR11x0Interface.h"
|
||||
#include "Module.h"
|
||||
@@ -170,26 +169,6 @@ extern struct portduino_config_struct {
|
||||
int configDisplayMode = 0;
|
||||
bool has_configDisplayMode = false;
|
||||
|
||||
// Store and Forward++
|
||||
std::string sfpp_db_path = "/var/lib/meshtasticd/";
|
||||
bool sfpp_stratum0 = false;
|
||||
bool sfpp_enabled = true;
|
||||
bool sfpp_steal_port = false;
|
||||
int sfpp_initial_sync = 10;
|
||||
int sfpp_hops = 3;
|
||||
int sfpp_announce_interval = 5; // minutes
|
||||
uint32_t sfpp_max_chain = 1000;
|
||||
uint32_t sfpp_backlog_limit = 100;
|
||||
// allowed root hashes
|
||||
// upstream node
|
||||
// Are we allowing unknown channel hashes? Does this even make sense?
|
||||
// Allow DMs
|
||||
|
||||
// Routing
|
||||
bool whitelist_enabled = false;
|
||||
std::vector<int> whitelist_ports = {};
|
||||
std::vector<int> nohop_ports = {};
|
||||
|
||||
// General
|
||||
std::string mac_address = "";
|
||||
bool mac_address_explicit = false;
|
||||
@@ -509,29 +488,6 @@ extern struct portduino_config_struct {
|
||||
out << YAML::EndMap; // Config
|
||||
}
|
||||
|
||||
// StoreAndForward
|
||||
if (sfpp_enabled) {
|
||||
out << YAML::Key << "StoreAndForward" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "Enabled" << YAML::Value << sfpp_enabled;
|
||||
out << YAML::Key << "DBPath" << YAML::Value << sfpp_db_path;
|
||||
out << YAML::Key << "Stratum0" << YAML::Value << sfpp_stratum0;
|
||||
out << YAML::Key << "InitialSync" << YAML::Value << sfpp_initial_sync;
|
||||
out << YAML::Key << "Hops" << YAML::Value << sfpp_hops;
|
||||
out << YAML::Key << "AnnounceInterval" << YAML::Value << sfpp_announce_interval;
|
||||
out << YAML::Key << "BacklogLimit" << YAML::Value << sfpp_backlog_limit;
|
||||
out << YAML::Key << "MaxChainLength" << YAML::Value << sfpp_max_chain;
|
||||
out << YAML::Key << "StealPort" << YAML::Value << sfpp_steal_port;
|
||||
out << YAML::EndMap; // StoreAndForward
|
||||
}
|
||||
|
||||
// Routing
|
||||
if (whitelist_enabled || nohop_ports.size() > 0) {
|
||||
out << YAML::Key << "Routing" << YAML::Value << YAML::BeginMap;
|
||||
out << YAML::Key << "WhitelistPorts" << YAML::Value << whitelist_ports;
|
||||
out << YAML::Key << "NoHopPorts" << YAML::Value << nohop_ports;
|
||||
out << YAML::EndMap; // Routing
|
||||
}
|
||||
|
||||
// General
|
||||
out << YAML::Key << "General" << YAML::Value << YAML::BeginMap;
|
||||
if (config_directory != "")
|
||||
|
||||
@@ -9,7 +9,7 @@ lib_deps =
|
||||
# renovate: datasource=custom.pio depName=Melopero RV3028 packageName=melopero/library/Melopero RV3028
|
||||
melopero/Melopero RV3028@1.2.0
|
||||
|
||||
build_src_filter = ${portduino_base.build_src_filter} +<modules/Native/>
|
||||
build_src_filter = ${portduino_base.build_src_filter}
|
||||
|
||||
[env:native]
|
||||
extends = native_base
|
||||
@@ -20,7 +20,6 @@ build_flags = ${native_base.build_flags}
|
||||
!pkg-config --libs openssl --silence-errors || :
|
||||
!pkg-config --cflags --libs sdl2 --silence-errors || :
|
||||
!pkg-config --cflags --libs libbsd-overlay --silence-errors || :
|
||||
!pkg-config --cflags --libs sqlite3 --silence-errors || :
|
||||
|
||||
[env:native-tft]
|
||||
extends = native_base
|
||||
@@ -47,7 +46,6 @@ build_flags = ${native_base.build_flags} -Os -lX11 -linput -lxkbcommon -ffunctio
|
||||
!pkg-config --libs openssl --silence-errors || :
|
||||
!pkg-config --cflags --libs sdl2 --silence-errors || :
|
||||
!pkg-config --cflags --libs libbsd-overlay --silence-errors || :
|
||||
!pkg-config --cflags --libs sqlite3 --silence-errors || :
|
||||
build_src_filter =
|
||||
${native_base.build_src_filter}
|
||||
|
||||
@@ -77,7 +75,6 @@ build_flags = ${native_base.build_flags} -Os -ffunction-sections -fdata-sections
|
||||
!pkg-config --libs libulfius --silence-errors || :
|
||||
!pkg-config --libs openssl --silence-errors || :
|
||||
!pkg-config --cflags --libs libbsd-overlay --silence-errors || :
|
||||
!pkg-config --cflags --libs sqlite3 --silence-errors || :
|
||||
build_src_filter =
|
||||
${native_base.build_src_filter}
|
||||
|
||||
@@ -111,7 +108,6 @@ build_flags = ${native_base.build_flags} -O0 -fsanitize=address -lX11 -linput -l
|
||||
!pkg-config --libs libulfius --silence-errors || :
|
||||
!pkg-config --libs openssl --silence-errors || :
|
||||
!pkg-config --cflags --libs libbsd-overlay --silence-errors || :
|
||||
!pkg-config --cflags --libs sqlite3 --silence-errors || :
|
||||
build_src_filter = ${env:native-tft.build_src_filter}
|
||||
|
||||
[env:coverage]
|
||||
|
||||
Reference in New Issue
Block a user