-
-
Notifications
You must be signed in to change notification settings - Fork 839
Expand file tree
/
Copy pathCommonCLI.h
More file actions
147 lines (129 loc) · 4.92 KB
/
CommonCLI.h
File metadata and controls
147 lines (129 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma once
#include "Mesh.h"
#include <helpers/IdentityStore.h>
#include <helpers/SensorManager.h>
#if defined(WITH_RS232_BRIDGE) || defined(WITH_ESPNOW_BRIDGE)
#define WITH_BRIDGE
#endif
#define ADVERT_LOC_NONE 0
#define ADVERT_LOC_SHARE 1
#define ADVERT_LOC_PREFS 2
#ifndef MAX_LORA_TX_POWER
#define MAX_LORA_TX_POWER 30
#endif
struct PrefsLimits {
// Timing/delay factors
static constexpr float AF_MIN = 0.0f, AF_MAX = 9.0f;
static constexpr float RX_DELAY_MIN = 0.0f, RX_DELAY_MAX = 20.0f;
static constexpr float TX_DELAY_MIN = 0.0f, TX_DELAY_MAX = 2.0f;
static constexpr float DIRECT_TX_DELAY_MIN = 0.0f, DIRECT_TX_DELAY_MAX = 2.0f;
// Radio parameters
static constexpr float FREQ_MIN = 400.0f, FREQ_MAX = 2500.0f;
static constexpr float BW_MIN = 7.8f, BW_MAX = 500.0f;
static constexpr uint8_t SF_MIN = 5, SF_MAX = 12;
static constexpr uint8_t CR_MIN = 5, CR_MAX = 8;
static constexpr uint8_t TX_POWER_MIN = 1, TX_POWER_MAX = MAX_LORA_TX_POWER;
// Mesh settings
static constexpr uint8_t MULTI_ACKS_MIN = 0, MULTI_ACKS_MAX = 1;
static constexpr uint8_t FLOOD_MAX_MIN = 0, FLOOD_MAX_MAX = 64;
static constexpr uint8_t INT_THRESH_MIN = 0, INT_THRESH_MAX = 255;
// Advert intervals
static constexpr int ADVERT_INTERVAL_MIN = 60, ADVERT_INTERVAL_MAX = 240; // minutes
static constexpr int FLOOD_ADVERT_INTERVAL_MIN = 3, FLOOD_ADVERT_INTERVAL_MAX = 48; // hours
// Bridge settings
static constexpr uint16_t BRIDGE_DELAY_MIN = 0, BRIDGE_DELAY_MAX = 10000;
static constexpr uint32_t BRIDGE_BAUD_MIN = 9600, BRIDGE_BAUD_MAX = 115200;
static constexpr uint8_t BRIDGE_CHANNEL_MIN = 1, BRIDGE_CHANNEL_MAX = 14;
// ADC
static constexpr float ADC_MULT_MIN = 0.0f, ADC_MULT_MAX = 10.0f;
};
struct NodePrefs { // persisted to file
float airtime_factor;
char node_name[32];
double node_lat, node_lon;
char password[16];
float freq;
uint8_t tx_power_dbm;
uint8_t disable_fwd;
uint8_t advert_interval; // minutes / 2
uint8_t flood_advert_interval; // hours
float rx_delay_base;
float tx_delay_factor;
char guest_password[16];
float direct_tx_delay_factor;
uint32_t guard;
uint8_t sf;
uint8_t cr;
uint8_t allow_read_only;
uint8_t multi_acks;
float bw;
uint8_t flood_max;
uint8_t interference_threshold;
uint8_t agc_reset_interval; // secs / 4
// Bridge settings
uint8_t bridge_enabled; // boolean
uint16_t bridge_delay; // milliseconds (default 500 ms)
uint8_t bridge_pkt_src; // 0 = logTx, 1 = logRx (default logTx)
uint32_t bridge_baud; // 9600, 19200, 38400, 57600, 115200 (default 115200)
uint8_t bridge_channel; // 1-14 (ESP-NOW only)
char bridge_secret[16]; // for XOR encryption of bridge packets (ESP-NOW only)
// Power setting
uint8_t powersaving_enabled; // boolean
// Gps settings
uint8_t gps_enabled;
uint32_t gps_interval; // in seconds
uint8_t advert_loc_policy;
uint32_t discovery_mod_timestamp;
float adc_multiplier;
char owner_info[120];
};
class CommonCLICallbacks {
public:
virtual void savePrefs() = 0;
virtual const char* getFirmwareVer() = 0;
virtual const char* getBuildDate() = 0;
virtual const char* getRole() = 0;
virtual bool formatFileSystem() = 0;
virtual void sendSelfAdvertisement(int delay_millis) = 0;
virtual void updateAdvertTimer() = 0;
virtual void updateFloodAdvertTimer() = 0;
virtual void setLoggingOn(bool enable) = 0;
virtual void eraseLogFile() = 0;
virtual void dumpLogFile() = 0;
virtual void setTxPower(uint8_t power_dbm) = 0;
virtual void formatNeighborsReply(char *reply) = 0;
virtual void removeNeighbor(const uint8_t* pubkey, int key_len) {
// no op by default
};
virtual void formatStatsReply(char *reply) = 0;
virtual void formatRadioStatsReply(char *reply) = 0;
virtual void formatPacketStatsReply(char *reply) = 0;
virtual mesh::LocalIdentity& getSelfId() = 0;
virtual void saveIdentity(const mesh::LocalIdentity& new_id) = 0;
virtual void clearStats() = 0;
virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;
virtual void setBridgeState(bool enable) {
// no op by default
};
virtual void restartBridge() {
// no op by default
};
};
class CommonCLI {
mesh::RTCClock* _rtc;
NodePrefs* _prefs;
CommonCLICallbacks* _callbacks;
mesh::MainBoard* _board;
SensorManager* _sensors;
char tmp[PRV_KEY_SIZE*2 + 4];
mesh::RTCClock* getRTCClock() { return _rtc; }
void savePrefs();
void loadPrefsInt(FILESYSTEM* _fs, const char* filename);
public:
CommonCLI(mesh::MainBoard& board, mesh::RTCClock& rtc, SensorManager& sensors, NodePrefs* prefs, CommonCLICallbacks* callbacks)
: _board(&board), _rtc(&rtc), _sensors(&sensors), _prefs(prefs), _callbacks(callbacks) { }
void loadPrefs(FILESYSTEM* _fs);
void savePrefs(FILESYSTEM* _fs);
void handleCommand(uint32_t sender_timestamp, const char* command, char* reply);
uint8_t buildAdvertData(uint8_t node_type, uint8_t* app_data);
};