Change state order to send node info before config (#1606)

* Change state order to send node info before config

* Kill groups
This commit is contained in:
Ben Meadors 2022-08-07 16:03:58 -05:00 committed by GitHub
parent de47cc55a0
commit 591ae7a803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 37 deletions

View File

@ -81,18 +81,15 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength)
switch (toRadioScratch.which_payloadVariant) { switch (toRadioScratch.which_payloadVariant) {
case ToRadio_packet_tag: case ToRadio_packet_tag:
return handleToRadioPacket(toRadioScratch.packet); return handleToRadioPacket(toRadioScratch.packet);
case ToRadio_want_config_id_tag: case ToRadio_want_config_id_tag:
config_nonce = toRadioScratch.want_config_id; config_nonce = toRadioScratch.want_config_id;
DEBUG_MSG("Client wants config, nonce=%u\n", config_nonce); DEBUG_MSG("Client wants config, nonce=%u\n", config_nonce);
handleStartConfig(); handleStartConfig();
break; break;
case ToRadio_disconnect_tag: case ToRadio_disconnect_tag:
close(); close();
break; break;
default: default:
// Ignore nop messages // Ignore nop messages
// DEBUG_MSG("Error: unexpected ToRadio variant\n"); // DEBUG_MSG("Error: unexpected ToRadio variant\n");
@ -112,9 +109,8 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength)
* *
* Our sending states progress in the following sequence (the client app ASSUMES THIS SEQUENCE, DO NOT CHANGE IT): * Our sending states progress in the following sequence (the client app ASSUMES THIS SEQUENCE, DO NOT CHANGE IT):
* STATE_SEND_MY_INFO, // send our my info record * STATE_SEND_MY_INFO, // send our my info record
* STATE_SEND_GROUPS * STATE_SEND_NODEINFO, // states progress in this order as the device sends to the client
STATE_SEND_CONFIG, STATE_SEND_CONFIG,
STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client
STATE_SEND_COMPLETE_ID, STATE_SEND_COMPLETE_ID,
STATE_SEND_PACKETS // send packets or debug strings STATE_SEND_PACKETS // send packets or debug strings
*/ */
@ -141,11 +137,30 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
myNodeInfo.has_gps = gps && gps->isConnected(); // Update with latest GPS connect info myNodeInfo.has_gps = gps && gps->isConnected(); // Update with latest GPS connect info
fromRadioScratch.which_payloadVariant = FromRadio_my_info_tag; fromRadioScratch.which_payloadVariant = FromRadio_my_info_tag;
fromRadioScratch.my_info = myNodeInfo; fromRadioScratch.my_info = myNodeInfo;
state = STATE_SEND_CONFIG; state = STATE_SEND_NODEINFO;
service.refreshMyNodeInfo(); // Update my NodeInfo because the client will be asking for it soon. service.refreshMyNodeInfo(); // Update my NodeInfo because the client will be asking for it soon.
break; break;
case STATE_SEND_NODEINFO: {
const NodeInfo *info = nodeInfoForPhone;
nodeInfoForPhone = NULL; // We just consumed a nodeinfo, will need a new one next time
if (info) {
DEBUG_MSG("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->last_heard, info->user.id,
info->user.long_name);
fromRadioScratch.which_payloadVariant = FromRadio_node_info_tag;
fromRadioScratch.node_info = *info;
// Stay in current state until done sending nodeinfos
} else {
DEBUG_MSG("Done sending nodeinfos\n");
state = STATE_SEND_CONFIG;
// Go ahead and send that ID right now
return getFromRadio(buf);
}
break;
}
case STATE_SEND_CONFIG: case STATE_SEND_CONFIG:
fromRadioScratch.which_payloadVariant = FromRadio_config_tag; fromRadioScratch.which_payloadVariant = FromRadio_config_tag;
switch (config_state) { switch (config_state) {
@ -220,28 +235,10 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
config_state++; config_state++;
// Advance when we have sent all of our ModuleConfig objects // Advance when we have sent all of our ModuleConfig objects
if (config_state > ModuleConfig_canned_message_tag) { if (config_state > ModuleConfig_canned_message_tag) {
state = STATE_SEND_NODEINFO; state = STATE_SEND_COMPLETE_ID;
config_state = Config_device_tag; config_state = Config_device_tag;
} }
break; break;
case STATE_SEND_NODEINFO: {
const NodeInfo *info = nodeInfoForPhone;
nodeInfoForPhone = NULL; // We just consumed a nodeinfo, will need a new one next time
if (info) {
DEBUG_MSG("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->last_heard, info->user.id,
info->user.long_name);
fromRadioScratch.which_payloadVariant = FromRadio_node_info_tag;
fromRadioScratch.node_info = *info;
// Stay in current state until done sending nodeinfos
} else {
DEBUG_MSG("Done sending nodeinfos\n");
state = STATE_SEND_COMPLETE_ID;
// Go ahead and send that ID right now
return getFromRadio(buf);
}
break;
}
case STATE_SEND_COMPLETE_ID: case STATE_SEND_COMPLETE_ID:
fromRadioScratch.which_payloadVariant = FromRadio_config_complete_id_tag; fromRadioScratch.which_payloadVariant = FromRadio_config_complete_id_tag;

View File

@ -22,10 +22,9 @@ class PhoneAPI
enum State { enum State {
STATE_SEND_NOTHING, // Initial state, don't send anything until the client starts asking for config STATE_SEND_NOTHING, // Initial state, don't send anything until the client starts asking for config
STATE_SEND_MY_INFO, // send our my info record STATE_SEND_MY_INFO, // send our my info record
STATE_SEND_GROUPS, // new in 1.3? STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client
STATE_SEND_CONFIG, // Replacement for the old Radioconfig STATE_SEND_CONFIG, // Replacement for the old Radioconfig
STATE_SEND_MODULECONFIG, // Send Module specific config STATE_SEND_MODULECONFIG, // Send Module specific config
STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client
STATE_SEND_COMPLETE_ID, STATE_SEND_COMPLETE_ID,
STATE_SEND_PACKETS // send packets or debug strings STATE_SEND_PACKETS // send packets or debug strings
}; };