Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"--privileged",
"--network=host",
"--device=/dev/bus/usb",
// arch linux tty* is owned by uucp (986)
"--group-add=986",
// arch linux tty* is owned by uucp (984)
"--group-add=984",
// debian tty* is owned by dialout (20)
"--group-add=20"
],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ compile_commands.json
.venv/
venv/
platformio.local.ini
.devcontainer/devcontainer-lock.json
2 changes: 2 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"pioarduino.pioarduino-ide",
"platformio.platformio-ide"
Expand Down
4 changes: 4 additions & 0 deletions examples/companion_radio/AbstractUITask.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ class AbstractUITask {
void setHasConnection(bool connected) { _connected = connected; }
bool hasConnection() const { return _connected; }
uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); }
bool isExternalPowered() const { return _board->isExternalPowered(); }
bool isSerialEnabled() const { return _serial->isEnabled(); }
void enableSerial() { _serial->enable(); }
void disableSerial() { _serial->disable(); }
bool isPairingAllowed() const { return _serial->isPairingAllowed(); }
void setPairingAllowed(bool a) { _serial->setPairingAllowed(a); }
virtual void onClientActivity(const char* text) { }
virtual void msgRead(int msgcount) = 0;
virtual void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) = 0;
virtual void notify(UIEventType t = UIEventType::none) = 0;
Expand Down
2 changes: 2 additions & 0 deletions examples/companion_radio/DataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
file.read((uint8_t *)&_prefs.rx_boosted_gain, sizeof(_prefs.rx_boosted_gain)); // 89
file.read((uint8_t *)_prefs.default_scope_name, sizeof(_prefs.default_scope_name)); // 90
file.read((uint8_t *)_prefs.default_scope_key, sizeof(_prefs.default_scope_key)); // 121
file.read((uint8_t *)&_prefs.pairing_locked, sizeof(_prefs.pairing_locked)); // 137

file.close();
}
Expand Down Expand Up @@ -273,6 +274,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
file.write((uint8_t *)&_prefs.rx_boosted_gain, sizeof(_prefs.rx_boosted_gain)); // 89
file.write((uint8_t *)_prefs.default_scope_name, sizeof(_prefs.default_scope_name)); // 90
file.write((uint8_t *)_prefs.default_scope_key, sizeof(_prefs.default_scope_key)); // 121
file.write((uint8_t *)&_prefs.pairing_locked, sizeof(_prefs.pairing_locked)); // 137

file.close();
}
Expand Down
37 changes: 25 additions & 12 deletions examples/companion_radio/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
#endif
}

#ifdef DISPLAY_CLASS
if (_ui && is_new) {
char act[40];
snprintf(act, sizeof(act), "New: %s", contact.name);
_ui->onClientActivity(act);
}
#endif

// add inbound-path to mem cache
if (path && mesh::Packet::isValidPathLen(path_len)) { // check path is valid
AdvertPath* p = advert_paths;
Expand Down Expand Up @@ -940,19 +948,21 @@ void MyMesh::begin(bool has_display) {
_prefs.gps_interval = constrain(_prefs.gps_interval, 0, 86400); // Max 24 hours

#ifdef BLE_PIN_CODE // 123456 by default
if (_prefs.ble_pin == 0) {
if (_prefs.ble_pin != 0) {
_active_ble_pin = _prefs.ble_pin; // pin configured via app
} else if (BLE_PIN_CODE != 123456) {
_active_ble_pin = BLE_PIN_CODE; // pin configured at build time
} else {
#ifdef DISPLAY_CLASS
if (has_display && BLE_PIN_CODE == 123456) {
if (has_display) {
StdRNG rng;
_active_ble_pin = rng.nextInt(100000, 999999); // random pin each session
_active_ble_pin = rng.nextInt(100000, 999999); // generated each session, shown on screen
} else {
_active_ble_pin = BLE_PIN_CODE; // otherwise static pin
_active_ble_pin = BLE_PIN_CODE;
}
#else
_active_ble_pin = BLE_PIN_CODE; // otherwise static pin
_active_ble_pin = BLE_PIN_CODE;
#endif
} else {
_active_ble_pin = _prefs.ble_pin;
}
#else
_active_ble_pin = 0;
Expand Down Expand Up @@ -2230,19 +2240,22 @@ void MyMesh::loop() {
#endif
}

bool MyMesh::advert() {
bool MyMesh::advert(bool flood) {
mesh::Packet* pkt;
if (_prefs.advert_loc_policy == ADVERT_LOC_NONE) {
pkt = createSelfAdvert(_prefs.node_name);
} else {
pkt = createSelfAdvert(_prefs.node_name, sensors.node_lat, sensors.node_lon);
}
if (pkt) {
sendZeroHop(pkt);
return true;
if (!pkt) return false;
if (flood) {
TransportKey default_scope;
memcpy(&default_scope.key, _prefs.default_scope_key, sizeof(default_scope.key));
sendFloodScoped(default_scope, pkt, 0);
} else {
return false;
sendZeroHop(pkt);
}
return true;
}

// To check if there is pending work
Expand Down
2 changes: 1 addition & 1 deletion examples/companion_radio/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class MyMesh : public BaseChatMesh, public DataStoreHost {

void loop();
void handleCmdFrame(size_t len);
bool advert();
bool advert(bool flood = false);
void enterCLIRescue();

int getRecentlyHeard(AdvertPath dest[], int max_num);
Expand Down
1 change: 1 addition & 0 deletions examples/companion_radio/NodePrefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ struct NodePrefs { // persisted to file
uint8_t autoadd_max_hops; // 0 = no limit, 1 = direct (0 hops), N = up to N-1 hops (max 64)
char default_scope_name[31];
uint8_t default_scope_key[16];
uint8_t pairing_locked; // 0 = BLE pairing allowed; 1 = BLE pairing locked (no new pairs allowed)
};
1 change: 1 addition & 0 deletions examples/companion_radio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void setup() {
serial_interface.begin(Serial);
#endif
the_mesh.startInterface(serial_interface);
serial_interface.setPairingAllowed(!the_mesh.getNodePrefs()->pairing_locked);
#elif defined(RP2040_PLATFORM)
LittleFS.begin();
store.begin();
Expand Down
Loading