mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* companion radio: new command frames: CMD_SET_ADVERT_LATLON, CMD_REMOVE_CONTACT
This commit is contained in:
parent
5d4a5dce36
commit
eb7fec6f1d
3 changed files with 44 additions and 1 deletions
|
|
@ -101,6 +101,8 @@ static uint32_t _atoi(const char* sp) {
|
||||||
#define CMD_SET_RADIO_PARAMS 11
|
#define CMD_SET_RADIO_PARAMS 11
|
||||||
#define CMD_SET_RADIO_TX_POWER 12
|
#define CMD_SET_RADIO_TX_POWER 12
|
||||||
#define CMD_RESET_PATH 13
|
#define CMD_RESET_PATH 13
|
||||||
|
#define CMD_SET_ADVERT_LATLON 14
|
||||||
|
#define CMD_REMOVE_CONTACT 15
|
||||||
|
|
||||||
#define RESP_CODE_OK 0
|
#define RESP_CODE_OK 0
|
||||||
#define RESP_CODE_ERR 1
|
#define RESP_CODE_ERR 1
|
||||||
|
|
@ -564,6 +566,21 @@ public:
|
||||||
_prefs.node_name[nlen] = 0; // null terminator
|
_prefs.node_name[nlen] = 0; // null terminator
|
||||||
savePrefs();
|
savePrefs();
|
||||||
writeOKFrame();
|
writeOKFrame();
|
||||||
|
} else if (cmd_frame[0] == CMD_SET_ADVERT_LATLON && len >= 9) {
|
||||||
|
int32_t lat, lon, alt = 0;
|
||||||
|
memcpy(&lat, &cmd_frame[1], 4);
|
||||||
|
memcpy(&lon, &cmd_frame[5], 4);
|
||||||
|
if (len >= 13) {
|
||||||
|
memcpy(&alt, &cmd_frame[9], 4); // for FUTURE support
|
||||||
|
}
|
||||||
|
if (lat <= 90*1E6 && lat >= -90*1E6 && lon <= 180*1E6 && lon >= -180*1E6) {
|
||||||
|
_prefs.node_lat = ((double)lat) / 1000000.0;
|
||||||
|
_prefs.node_lon = ((double)lon) / 1000000.0;
|
||||||
|
savePrefs();
|
||||||
|
writeOKFrame();
|
||||||
|
} else {
|
||||||
|
writeErrFrame(); // invalid geo coordinate
|
||||||
|
}
|
||||||
} else if (cmd_frame[0] == CMD_GET_DEVICE_TIME) {
|
} else if (cmd_frame[0] == CMD_GET_DEVICE_TIME) {
|
||||||
uint8_t reply[5];
|
uint8_t reply[5];
|
||||||
reply[0] = RESP_CODE_CURR_TIME;
|
reply[0] = RESP_CODE_CURR_TIME;
|
||||||
|
|
@ -581,7 +598,7 @@ public:
|
||||||
writeErrFrame();
|
writeErrFrame();
|
||||||
}
|
}
|
||||||
} else if (cmd_frame[0] == CMD_SEND_SELF_ADVERT) {
|
} else if (cmd_frame[0] == CMD_SEND_SELF_ADVERT) {
|
||||||
auto pkt = createSelfAdvert(_prefs.node_name);
|
auto pkt = createSelfAdvert(_prefs.node_name, _prefs.node_lat, _prefs.node_lon);
|
||||||
if (pkt) {
|
if (pkt) {
|
||||||
if (len >= 2 && cmd_frame[1] == 1) { // optional param (1 = flood, 0 = zero hop)
|
if (len >= 2 && cmd_frame[1] == 1) { // optional param (1 = flood, 0 = zero hop)
|
||||||
sendFlood(pkt);
|
sendFlood(pkt);
|
||||||
|
|
@ -622,6 +639,15 @@ public:
|
||||||
writeErrFrame(); // table is full!
|
writeErrFrame(); // table is full!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (cmd_frame[0] == CMD_REMOVE_CONTACT) {
|
||||||
|
uint8_t* pub_key = &cmd_frame[1];
|
||||||
|
ContactInfo* recipient = lookupContactByPubKey(pub_key, PUB_KEY_SIZE);
|
||||||
|
if (recipient && removeContact(*recipient)) {
|
||||||
|
saveContacts();
|
||||||
|
writeOKFrame();
|
||||||
|
} else {
|
||||||
|
writeErrFrame(); // not found, or unable to remove
|
||||||
|
}
|
||||||
} else if (cmd_frame[0] == CMD_SYNC_NEXT_MESSAGE) {
|
} else if (cmd_frame[0] == CMD_SYNC_NEXT_MESSAGE) {
|
||||||
int out_len;
|
int out_len;
|
||||||
if ((out_len = getFromOfflineQueue(out_frame)) > 0) {
|
if ((out_len = getFromOfflineQueue(out_frame)) > 0) {
|
||||||
|
|
|
||||||
|
|
@ -281,6 +281,22 @@ bool BaseChatMesh::addContact(const ContactInfo& contact) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BaseChatMesh::removeContact(ContactInfo& contact) {
|
||||||
|
int idx = 0;
|
||||||
|
while (idx < num_contacts && !contacts[idx].id.matches(contact.id)) {
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
if (idx >= num_contacts) return false; // not found
|
||||||
|
|
||||||
|
// remove from contacts array
|
||||||
|
num_contacts--;
|
||||||
|
while (idx < num_contacts) {
|
||||||
|
contacts[idx] = contacts[idx + 1];
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
return true; // Success
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MAX_GROUP_CHANNELS
|
#ifdef MAX_GROUP_CHANNELS
|
||||||
#include <base64.hpp>
|
#include <base64.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ public:
|
||||||
void scanRecentContacts(int last_n, ContactVisitor* visitor);
|
void scanRecentContacts(int last_n, ContactVisitor* visitor);
|
||||||
ContactInfo* searchContactsByPrefix(const char* name_prefix);
|
ContactInfo* searchContactsByPrefix(const char* name_prefix);
|
||||||
ContactInfo* lookupContactByPubKey(const uint8_t* pub_key, int prefix_len);
|
ContactInfo* lookupContactByPubKey(const uint8_t* pub_key, int prefix_len);
|
||||||
|
bool removeContact(ContactInfo& contact);
|
||||||
bool addContact(const ContactInfo& contact);
|
bool addContact(const ContactInfo& contact);
|
||||||
int getNumContacts() const { return num_contacts; }
|
int getNumContacts() const { return num_contacts; }
|
||||||
ContactsIterator startContactsIterator();
|
ContactsIterator startContactsIterator();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue