Skip to content

Commit 963290e

Browse files
author
Scott Powell
committed
* repeater: various "region" CLI changes
* transport codes 0000 and FFFF reserved
1 parent 2e63499 commit 963290e

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ void MyMesh::clearStats() {
892892

893893
void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply) {
894894
if (region_load_active) {
895-
if (*command == 0) { // empty line, signal to terminate 'load' operation
895+
if (StrHelper::isBlank(command)) { // empty/blank line, signal to terminate 'load' operation
896896
region_map = temp_map; // copy over the temp instance as new current map
897897
region_load_active = false;
898898

@@ -908,7 +908,7 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
908908

909909
while (*ep && *ep != 'F') ep++; // look for (optional) flags
910910

911-
if (indent > 0 && indent < 8) {
911+
if (indent > 0 && indent < 8 && strlen(np) > 0) {
912912
auto parent = load_stack[indent - 1];
913913
if (parent) {
914914
auto old = region_map.findByName(np);
@@ -985,15 +985,15 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
985985
bool success = region_map.save(_fs);
986986
strcpy(reply, success ? "OK" : "Err - save failed");
987987
} else if (n >= 3 && strcmp(parts[1], "allowf") == 0) {
988-
auto region = strcmp(parts[2], "*") == 0 ? &region_map.getWildcard() : region_map.findByNamePrefix(parts[2]);
988+
auto region = region_map.findByNamePrefix(parts[2]);
989989
if (region) {
990990
region->flags &= ~REGION_DENY_FLOOD;
991991
strcpy(reply, "OK");
992992
} else {
993993
strcpy(reply, "Err - unknown region");
994994
}
995995
} else if (n >= 3 && strcmp(parts[1], "denyf") == 0) {
996-
auto region = strcmp(parts[2], "*") == 0 ? &region_map.getWildcard() : region_map.findByNamePrefix(parts[2]);
996+
auto region = region_map.findByNamePrefix(parts[2]);
997997
if (region) {
998998
region->flags |= REGION_DENY_FLOOD;
999999
strcpy(reply, "OK");
@@ -1003,12 +1003,17 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
10031003
} else if (n >= 3 && strcmp(parts[1], "get") == 0) {
10041004
auto region = region_map.findByNamePrefix(parts[2]);
10051005
if (region) {
1006-
sprintf(reply, " %s %s", region->name, (region->flags & REGION_DENY_FLOOD) ? "" : "F");
1006+
auto parent = region_map.findById(region->parent);
1007+
if (parent && parent->id != 0) {
1008+
sprintf(reply, " %s (%s) %s", region->name, parent->name, (region->flags & REGION_DENY_FLOOD) ? "" : "F");
1009+
} else {
1010+
sprintf(reply, " %s %s", region->name, (region->flags & REGION_DENY_FLOOD) ? "" : "F");
1011+
}
10071012
} else {
10081013
strcpy(reply, "Err - unknown region");
10091014
}
10101015
} else if (n >= 3 && strcmp(parts[1], "home") == 0) {
1011-
auto home = strcmp(parts[2], "*") == 0 ? &region_map.getWildcard() : region_map.findByNamePrefix(parts[2]);
1016+
auto home = region_map.findByNamePrefix(parts[2]);
10121017
if (home) {
10131018
region_map.setHomeRegion(home);
10141019
sprintf(reply, " home is now %s", home->name);

src/helpers/RegionMap.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ RegionEntry* RegionMap::findMatch(mesh::Packet* packet, uint8_t mask) {
144144
}
145145

146146
RegionEntry* RegionMap::findByName(const char* name) {
147+
if (strcmp(name, "*") == 0) return &wildcard;
148+
147149
for (int i = 0; i < num_regions; i++) {
148150
auto region = &regions[i];
149151
if (strcmp(name, region->name) == 0) return region;
@@ -152,6 +154,8 @@ RegionEntry* RegionMap::findByName(const char* name) {
152154
}
153155

154156
RegionEntry* RegionMap::findByNamePrefix(const char* prefix) {
157+
if (strcmp(prefix, "*") == 0) return &wildcard;
158+
155159
RegionEntry* partial = NULL;
156160
for (int i = 0; i < num_regions; i++) {
157161
auto region = &regions[i];

src/helpers/TransportKeyStore.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ uint16_t TransportKey::calcTransportCode(const mesh::Packet* packet) const {
99
sha.update(&type, 1);
1010
sha.update(packet->payload, packet->payload_len);
1111
sha.finalizeHMAC(key, sizeof(key), &code, 2);
12+
if (code == 0) { // reserve codes 0000 and FFFF
13+
code++;
14+
} else if (code == 0xFFFF) {
15+
code--;
16+
}
1217
return code;
1318
}
1419

src/helpers/TxtDataHelpers.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ void StrHelper::strzcpy(char* dest, const char* src, size_t buf_sz) {
1919
}
2020
}
2121

22+
bool StrHelper::isBlank(const char* str) {
23+
while (*str) {
24+
if (*str++ != ' ') return false;
25+
}
26+
return true;
27+
}
28+
2229
#include <Arduino.h>
2330

2431
union int32_Float_t

src/helpers/TxtDataHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ class StrHelper {
1212
static void strncpy(char* dest, const char* src, size_t buf_sz);
1313
static void strzcpy(char* dest, const char* src, size_t buf_sz); // pads with trailing nulls
1414
static const char* ftoa(float f);
15+
static bool isBlank(const char* str);
1516
};

0 commit comments

Comments
 (0)