Skip to content

Commit 3b82224

Browse files
author
Scott Powell
committed
Merge branch 'rep-room-acl' into dev
2 parents 1257c6b + c8a10cc commit 3b82224

File tree

20 files changed

+1962
-1822
lines changed

20 files changed

+1962
-1822
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 701 additions & 0 deletions
Large diffs are not rendered by default.

examples/simple_repeater/MyMesh.h

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#pragma once
2+
3+
#include <Arduino.h>
4+
#include <Mesh.h>
5+
#include <helpers/CommonCLI.h>
6+
7+
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
8+
#include <InternalFileSystem.h>
9+
#elif defined(RP2040_PLATFORM)
10+
#include <LittleFS.h>
11+
#elif defined(ESP32)
12+
#include <SPIFFS.h>
13+
#endif
14+
15+
#include <helpers/ArduinoHelpers.h>
16+
#include <helpers/StaticPoolPacketManager.h>
17+
#include <helpers/SimpleMeshTables.h>
18+
#include <helpers/IdentityStore.h>
19+
#include <helpers/AdvertDataHelpers.h>
20+
#include <helpers/TxtDataHelpers.h>
21+
#include <RTClib.h>
22+
#include <target.h>
23+
24+
#ifdef WITH_RS232_BRIDGE
25+
#include "helpers/bridges/RS232Bridge.h"
26+
#define WITH_BRIDGE
27+
#endif
28+
29+
#ifdef WITH_ESPNOW_BRIDGE
30+
#include "helpers/bridges/ESPNowBridge.h"
31+
#define WITH_BRIDGE
32+
#endif
33+
34+
#ifdef WITH_BRIDGE
35+
extern AbstractBridge* bridge;
36+
#endif
37+
38+
struct RepeaterStats {
39+
uint16_t batt_milli_volts;
40+
uint16_t curr_tx_queue_len;
41+
int16_t noise_floor;
42+
int16_t last_rssi;
43+
uint32_t n_packets_recv;
44+
uint32_t n_packets_sent;
45+
uint32_t total_air_time_secs;
46+
uint32_t total_up_time_secs;
47+
uint32_t n_sent_flood, n_sent_direct;
48+
uint32_t n_recv_flood, n_recv_direct;
49+
uint16_t err_events; // was 'n_full_events'
50+
int16_t last_snr; // x 4
51+
uint16_t n_direct_dups, n_flood_dups;
52+
uint32_t total_rx_air_time_secs;
53+
};
54+
55+
struct ClientInfo {
56+
mesh::Identity id;
57+
uint32_t last_timestamp, last_activity;
58+
uint8_t secret[PUB_KEY_SIZE];
59+
bool is_admin;
60+
int8_t out_path_len;
61+
uint8_t out_path[MAX_PATH_SIZE];
62+
};
63+
64+
#ifndef MAX_CLIENTS
65+
#define MAX_CLIENTS 32
66+
#endif
67+
68+
struct NeighbourInfo {
69+
mesh::Identity id;
70+
uint32_t advert_timestamp;
71+
uint32_t heard_timestamp;
72+
int8_t snr; // multiplied by 4, user should divide to get float value
73+
};
74+
75+
#ifndef FIRMWARE_BUILD_DATE
76+
#define FIRMWARE_BUILD_DATE "1 Sep 2025"
77+
#endif
78+
79+
#ifndef FIRMWARE_VERSION
80+
#define FIRMWARE_VERSION "v1.8.1"
81+
#endif
82+
83+
#define FIRMWARE_ROLE "repeater"
84+
85+
#define PACKET_LOG_FILE "/packet_log"
86+
87+
class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
88+
FILESYSTEM* _fs;
89+
unsigned long next_local_advert, next_flood_advert;
90+
bool _logging;
91+
NodePrefs _prefs;
92+
CommonCLI _cli;
93+
uint8_t reply_data[MAX_PACKET_PAYLOAD];
94+
ClientInfo known_clients[MAX_CLIENTS];
95+
#if MAX_NEIGHBOURS
96+
NeighbourInfo neighbours[MAX_NEIGHBOURS];
97+
#endif
98+
CayenneLPP telemetry;
99+
unsigned long set_radio_at, revert_radio_at;
100+
float pending_freq;
101+
float pending_bw;
102+
uint8_t pending_sf;
103+
uint8_t pending_cr;
104+
int matching_peer_indexes[MAX_CLIENTS];
105+
#if defined(WITH_RS232_BRIDGE)
106+
RS232Bridge bridge;
107+
#elif defined(WITH_ESPNOW_BRIDGE)
108+
ESPNowBridge bridge;
109+
#endif
110+
111+
ClientInfo* putClient(const mesh::Identity& id);
112+
void putNeighbour(const mesh::Identity& id, uint32_t timestamp, float snr);
113+
int handleRequest(ClientInfo* sender, uint32_t sender_timestamp, uint8_t* payload, size_t payload_len);
114+
mesh::Packet* createSelfAdvert();
115+
116+
File openAppend(const char* fname);
117+
118+
protected:
119+
float getAirtimeBudgetFactor() const override {
120+
return _prefs.airtime_factor;
121+
}
122+
123+
bool allowPacketForward(const mesh::Packet* packet) override;
124+
const char* getLogDateTime() override;
125+
void logRxRaw(float snr, float rssi, const uint8_t raw[], int len) override;
126+
127+
void logRx(mesh::Packet* pkt, int len, float score) override;
128+
void logTx(mesh::Packet* pkt, int len) override;
129+
void logTxFail(mesh::Packet* pkt, int len) override;
130+
int calcRxDelay(float score, uint32_t air_time) const override;
131+
132+
uint32_t getRetransmitDelay(const mesh::Packet* packet) override;
133+
uint32_t getDirectRetransmitDelay(const mesh::Packet* packet) override;
134+
135+
int getInterferenceThreshold() const override {
136+
return _prefs.interference_threshold;
137+
}
138+
int getAGCResetInterval() const override {
139+
return ((int)_prefs.agc_reset_interval) * 4000; // milliseconds
140+
}
141+
uint8_t getExtraAckTransmitCount() const override {
142+
return _prefs.multi_acks;
143+
}
144+
145+
void onAnonDataRecv(mesh::Packet* packet, const uint8_t* secret, const mesh::Identity& sender, uint8_t* data, size_t len) override;
146+
int searchPeersByHash(const uint8_t* hash) override;
147+
void getPeerSharedSecret(uint8_t* dest_secret, int peer_idx) override;
148+
void onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id, uint32_t timestamp, const uint8_t* app_data, size_t app_data_len);
149+
void onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_idx, const uint8_t* secret, uint8_t* data, size_t len) override;
150+
bool onPeerPathRecv(mesh::Packet* packet, int sender_idx, const uint8_t* secret, uint8_t* path, uint8_t path_len, uint8_t extra_type, uint8_t* extra, uint8_t extra_len) override;
151+
152+
public:
153+
MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables);
154+
155+
void begin(FILESYSTEM* fs);
156+
157+
const char* getFirmwareVer() override { return FIRMWARE_VERSION; }
158+
const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; }
159+
const char* getRole() override { return FIRMWARE_ROLE; }
160+
const char* getNodeName() { return _prefs.node_name; }
161+
NodePrefs* getNodePrefs() {
162+
return &_prefs;
163+
}
164+
165+
void savePrefs() override {
166+
_cli.savePrefs(_fs);
167+
}
168+
169+
void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) override;
170+
bool formatFileSystem() override;
171+
void sendSelfAdvertisement(int delay_millis) override;
172+
void updateAdvertTimer() override;
173+
void updateFloodAdvertTimer() override;
174+
175+
void setLoggingOn(bool enable) override { _logging = enable; }
176+
177+
void eraseLogFile() override {
178+
_fs->remove(PACKET_LOG_FILE);
179+
}
180+
181+
void dumpLogFile() override;
182+
void setTxPower(uint8_t power_dbm) override;
183+
void formatNeighborsReply(char *reply) override;
184+
void removeNeighbor(const uint8_t* pubkey, int key_len) override;
185+
186+
mesh::LocalIdentity& getSelfId() override { return self_id; }
187+
188+
void saveIdentity(const mesh::LocalIdentity& new_id) override;
189+
void clearStats() override;
190+
void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
191+
void loop();
192+
};

0 commit comments

Comments
 (0)