Skip to content

Commit 339ee03

Browse files
author
Scott Powell
committed
* simple_sensor: handleCustomCommand() hook
1 parent ced14d6 commit 339ee03

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

examples/simple_sensor/SensorMesh.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ uint8_t SensorMesh::handleRequest(uint16_t perms, uint32_t sender_timestamp, uin
257257
memcpy(&start_secs_ago, &payload[0], 4);
258258
memcpy(&end_secs_ago, &payload[4], 4);
259259
uint8_t res1 = payload[8]; // reserved for future (extra query params)
260-
uint8_t res2 = payload[8];
260+
uint8_t res2 = payload[9];
261261

262262
MinMaxAvg data[8];
263263
int n;
@@ -460,6 +460,11 @@ void SensorMesh::handleCommand(uint32_t sender_timestamp, char* command, char* r
460460
command += 3;
461461
}
462462

463+
// first, see if this is a custom-handled CLI command (ie. in main.cpp)
464+
if (handleCustomCommand(sender_timestamp, command, reply)) {
465+
return; // command has been handled
466+
}
467+
463468
// handle sensor-specific CLI commands
464469
if (memcmp(command, "setperm ", 8) == 0) { // format: setperm {pubkey-hex} {permissions-int16}
465470
char* hex = &command[8];

examples/simple_sensor/SensorMesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class SensorMesh : public mesh::Mesh, public CommonCLICallbacks {
118118

119119
virtual void onSensorDataRead() = 0; // for app to implement
120120
virtual int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) = 0; // for app to implement
121+
virtual bool handleCustomCommand(uint32_t sender_timestamp, char* command, char* reply) { return false; }
121122

122123
// Mesh overrides
123124
float getAirtimeBudgetFactor() const override;

examples/simple_sensor/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ class MyMesh : public SensorMesh {
3030
battery_data.calcMinMaxAvg(getRTCClock(), start_secs_ago, end_secs_ago, &dest[0], TELEM_CHANNEL_SELF, LPP_VOLTAGE);
3131
return 1;
3232
}
33+
34+
bool handleCustomCommand(uint32_t sender_timestamp, char* command, char* reply) override {
35+
if (strcmp(command, "magic") == 0) { // example 'custom' command handling
36+
strcpy(reply, "**Magic now done**");
37+
return true; // handled
38+
}
39+
return false; // not handled
40+
}
3341
/* ======================================================================= */
3442
};
3543

0 commit comments

Comments
 (0)