From c67b53b96993eeaa4b3910deecac7a122f551f5a Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 23 Apr 2020 10:30:14 -0700 Subject: [PATCH] remove owner from ToRadio --- proto | 2 +- src/PhoneAPI.cpp | 20 ++++++-------------- src/PhoneAPI.h | 8 ++++++-- src/mesh.pb.h | 4 ---- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/proto b/proto index 083ba793..79b2cf72 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 083ba793108c34044e6abc8c94a5f250343b4f32 +Subproject commit 79b2cf728c08007284542b32d9d075d01e8153d8 diff --git a/src/PhoneAPI.cpp b/src/PhoneAPI.cpp index 5649d916..4776cd96 100644 --- a/src/PhoneAPI.cpp +++ b/src/PhoneAPI.cpp @@ -34,6 +34,7 @@ void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) state = STATE_SEND_MY_INFO; DEBUG_MSG("Reset nodeinfo read pointer\n"); + nodeInfoForPhone = NULL; // Don't keep returning old nodeinfos nodeDB.resetReadPointer(); // FIXME, this read pointer should be moved out of nodeDB and into this class - because // this will break once we have multiple instances of PhoneAPI running independently break; @@ -62,10 +63,9 @@ void PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) * * We assume buf is at least FromRadio_size bytes long. * - * Our sending states progress in the following sequence: + * 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_RADIO, - STATE_SEND_OWNER, STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client STATE_SEND_COMPLETE_ID, STATE_SEND_PACKETS // send packets or debug strings @@ -92,17 +92,11 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) case STATE_SEND_RADIO: fromRadioScratch.which_variant = FromRadio_radio_tag; fromRadioScratch.variant.radio = radioConfig; - state = STATE_SEND_OWNER; - break; - - case STATE_SEND_OWNER: - fromRadioScratch.which_variant = FromRadio_owner_tag; - fromRadioScratch.variant.owner = owner; state = STATE_SEND_NODEINFO; break; case STATE_SEND_NODEINFO: { - const NodeInfo *info = nodeDB.readNextInfo(); + const NodeInfo *info = nodeInfoForPhone; if (info) { DEBUG_MSG("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->position.time, info->user.id, @@ -168,10 +162,9 @@ bool PhoneAPI::available() return true; case STATE_SEND_NODEINFO: - return true; - - case STATE_SEND_OWNER: - return true; + if (!nodeInfoForPhone) + nodeInfoForPhone = nodeDB.readNextInfo(); + return true; // Always say we have something, because we might need to advance our state machine case STATE_SEND_RADIO: return true; @@ -225,7 +218,6 @@ void PhoneAPI::handleSetRadio(const RadioConfig &r) service.reloadConfig(); } - /** * Handle a packet that the phone wants us to send. It is our responsibility to free the packet to the pool */ diff --git a/src/PhoneAPI.h b/src/PhoneAPI.h index 8f9af78d..56eac067 100644 --- a/src/PhoneAPI.h +++ b/src/PhoneAPI.h @@ -22,7 +22,7 @@ class PhoneAPI STATE_SEND_NOTHING, // (Eventual) Initial state, don't send anything until the client starts asking for config STATE_SEND_MY_INFO, // send our my info record STATE_SEND_RADIO, - STATE_SEND_OWNER, + // STATE_SEND_OWNER, no need to send Owner specially, it is just part of the nodedb STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client STATE_SEND_COMPLETE_ID, STATE_SEND_PACKETS // send packets or debug strings @@ -35,9 +35,13 @@ class PhoneAPI */ uint32_t fromRadioNum = 0; - /// We temporarily keep the packet here between the call to available and getFromRadio + /// We temporarily keep the packet here between the call to available and getFromRadio. We will free it after the phone + /// downloads it MeshPacket *packetForPhone = NULL; + /// We temporarily keep the nodeInfo here between the call to available and getFromRadio + const NodeInfo *nodeInfoForPhone = NULL; + /// Our fromradio packet while it is being assembled FromRadio fromRadioScratch; diff --git a/src/mesh.pb.h b/src/mesh.pb.h index 67ca1622..f18b5c4f 100644 --- a/src/mesh.pb.h +++ b/src/mesh.pb.h @@ -156,7 +156,6 @@ typedef struct _FromRadio { MeshPacket packet; MyNodeInfo my_info; NodeInfo node_info; - User owner; RadioConfig radio; DebugString debug_string; uint32_t config_complete_id; @@ -287,7 +286,6 @@ typedef struct _ToRadio { #define FromRadio_packet_tag 2 #define FromRadio_my_info_tag 3 #define FromRadio_node_info_tag 4 -#define FromRadio_owner_tag 5 #define FromRadio_radio_tag 6 #define FromRadio_debug_string_tag 7 #define FromRadio_config_complete_id_tag 8 @@ -432,7 +430,6 @@ X(a, STATIC, SINGULAR, UINT32, num, 1) \ X(a, STATIC, ONEOF, MESSAGE, (variant,packet,variant.packet), 2) \ X(a, STATIC, ONEOF, MESSAGE, (variant,my_info,variant.my_info), 3) \ X(a, STATIC, ONEOF, MESSAGE, (variant,node_info,variant.node_info), 4) \ -X(a, STATIC, ONEOF, MESSAGE, (variant,owner,variant.owner), 5) \ X(a, STATIC, ONEOF, MESSAGE, (variant,radio,variant.radio), 6) \ X(a, STATIC, ONEOF, MESSAGE, (variant,debug_string,variant.debug_string), 7) \ X(a, STATIC, ONEOF, UINT32, (variant,config_complete_id,variant.config_complete_id), 8) @@ -441,7 +438,6 @@ X(a, STATIC, ONEOF, UINT32, (variant,config_complete_id,variant.config_co #define FromRadio_variant_packet_MSGTYPE MeshPacket #define FromRadio_variant_my_info_MSGTYPE MyNodeInfo #define FromRadio_variant_node_info_MSGTYPE NodeInfo -#define FromRadio_variant_owner_MSGTYPE User #define FromRadio_variant_radio_MSGTYPE RadioConfig #define FromRadio_variant_debug_string_MSGTYPE DebugString