protobuf changes as part of getting ready for mesh again

1.2-legacy
geeksville 2020-04-16 17:32:36 -07:00
rodzic 0d14b69a24
commit 6eb74415ab
5 zmienionych plików z 59 dodań i 62 usunięć

2
proto

@ -1 +1 @@
Subproject commit d13d741a985f75b953a9b7f8df6c8c61fcc4730d
Subproject commit fc4214e34dc90689b5efd4657bfdce63ca9add24

Wyświetl plik

@ -72,8 +72,8 @@ void MeshService::sendOurOwner(NodeNum dest, bool wantReplies)
MeshPacket *p = allocForSending();
p->to = dest;
p->payload.want_response = wantReplies;
p->payload.which_variant = SubPacket_user_tag;
User &u = p->payload.variant.user;
p->payload.has_user = true;
User &u = p->payload.user;
u = owner;
DEBUG_MSG("sending owner %s/%s/%s\n", u.id, u.long_name, u.short_name);
@ -87,7 +87,7 @@ MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
bool isCollision = mp->from == myNodeInfo.my_node_num;
// we win if we have a lower macaddr
bool weWin = memcmp(&owner.macaddr, &mp->payload.variant.user.macaddr, sizeof(owner.macaddr)) < 0;
bool weWin = memcmp(&owner.macaddr, &mp->payload.user.macaddr, sizeof(owner.macaddr)) < 0;
if (isCollision) {
if (weWin) {
@ -114,7 +114,7 @@ MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
sendOurOwner(mp->from);
String lcd = String("Joined: ") + mp->payload.variant.user.long_name + "\n";
String lcd = String("Joined: ") + mp->payload.user.long_name + "\n";
screen.print(lcd.c_str());
}
@ -123,12 +123,12 @@ MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
void MeshService::handleIncomingPosition(MeshPacket *mp)
{
if (mp->has_payload && mp->payload.which_variant == SubPacket_position_tag) {
DEBUG_MSG("handled incoming position time=%u\n", mp->payload.variant.position.time);
if (mp->has_payload && mp->payload.has_position) {
DEBUG_MSG("handled incoming position time=%u\n", mp->payload.position.time);
if (mp->payload.variant.position.time) {
if (mp->payload.position.time) {
struct timeval tv;
uint32_t secs = mp->payload.variant.position.time;
uint32_t secs = mp->payload.position.time;
tv.tv_sec = secs;
tv.tv_usec = 0;
@ -153,7 +153,7 @@ void MeshService::handleFromRadio(MeshPacket *mp)
DEBUG_MSG("Ignoring incoming time, because we have a GPS\n");
}
if (mp->has_payload && mp->payload.which_variant == SubPacket_user_tag) {
if (mp->has_payload && mp->payload.has_user) {
mp = handleFromRadioUser(mp);
}
@ -258,12 +258,12 @@ void MeshService::sendToMesh(MeshPacket *p)
// Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other
// nodes shouldn't trust it anyways) Note: for now, we allow a device with a local GPS to include the time, so that gpsless
// devices can get time.
if (p->has_payload && p->payload.which_variant == SubPacket_position_tag) {
if (p->has_payload && p->payload.has_position) {
if (!gps.isConnected) {
DEBUG_MSG("Stripping time %u from position send\n", p->payload.variant.position.time);
p->payload.variant.position.time = 0;
DEBUG_MSG("Stripping time %u from position send\n", p->payload.position.time);
p->payload.position.time = 0;
} else
DEBUG_MSG("Providing time to mesh %u\n", p->payload.variant.position.time);
DEBUG_MSG("Providing time to mesh %u\n", p->payload.position.time);
}
// If the phone sent a packet just to us, don't send it out into the network
@ -312,11 +312,10 @@ void MeshService::sendOurPosition(NodeNum dest, bool wantReplies)
// Update our local node info with our position (even if we don't decide to update anyone else)
MeshPacket *p = allocForSending();
p->to = dest;
p->payload.which_variant = SubPacket_position_tag;
p->payload.variant.position = node->position;
p->payload.has_position = true;
p->payload.position = node->position;
p->payload.want_response = wantReplies;
p->payload.variant.position.time =
gps.getValidTime(); // This nodedb timestamp might be stale, so update it if our clock is valid.
p->payload.position.time = gps.getValidTime(); // This nodedb timestamp might be stale, so update it if our clock is valid.
sendToMesh(p);
}
@ -326,9 +325,9 @@ int MeshService::onGPSChanged(void *unused)
// Update our local node info with our position (even if we don't decide to update anyone else)
MeshPacket *p = allocForSending();
p->payload.which_variant = SubPacket_position_tag;
p->payload.has_position = true;
Position &pos = p->payload.variant.position;
Position &pos = p->payload.position;
// !zero or !zero lat/long means valid
if (gps.latitude != 0 || gps.longitude != 0) {
if (gps.altitude != 0)

Wyświetl plik

@ -32,7 +32,7 @@ DeviceState versions used to be defined in the .proto file but really only this
#ifndef NO_ESP32
#define FS SPIFFS
#endif
#endif
// FIXME - move this somewhere else
extern void getMacAddr(uint8_t *dmac);
@ -269,7 +269,7 @@ void NodeDB::updateFrom(const MeshPacket &mp)
{
if (mp.has_payload) {
const SubPacket &p = mp.payload;
DEBUG_MSG("Update DB node 0x%x for variant %d, rx_time=%u\n", mp.from, p.which_variant, mp.rx_time);
DEBUG_MSG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time);
int oldNumNodes = *numNodes;
NodeInfo *info = getOrCreateNode(mp.from);
@ -282,22 +282,19 @@ void NodeDB::updateFrom(const MeshPacket &mp)
info->position.time = mp.rx_time;
}
switch (p.which_variant) {
case SubPacket_position_tag: {
if (p.has_position) {
// we carefully preserve the old time, because we always trust our local timestamps more
uint32_t oldtime = info->position.time;
info->position = p.variant.position;
info->position = p.position;
info->position.time = oldtime;
info->has_position = true;
updateGUIforNode = info;
break;
}
case SubPacket_data_tag: {
if (p.has_data) {
// Keep a copy of the most recent text message.
if (p.variant.data.typ == Data_Type_CLEAR_TEXT) {
DEBUG_MSG("Received text msg from=0%0x, msg=%.*s\n", mp.from, p.variant.data.payload.size,
p.variant.data.payload.bytes);
if (p.data.typ == Data_Type_CLEAR_TEXT) {
DEBUG_MSG("Received text msg from=0%0x, msg=%.*s\n", mp.from, p.data.payload.size, p.data.payload.bytes);
if (mp.to == NODENUM_BROADCAST || mp.to == nodeDB.getNodeNum()) {
// We only store/display messages destined for us.
devicestate.rx_text_message = mp;
@ -306,16 +303,15 @@ void NodeDB::updateFrom(const MeshPacket &mp)
powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG);
}
}
break;
}
case SubPacket_user_tag: {
if (p.has_user) {
DEBUG_MSG("old user %s/%s/%s\n", info->user.id, info->user.long_name, info->user.short_name);
bool changed = memcmp(&info->user, &p.variant.user,
bool changed = memcmp(&info->user, &p.user,
sizeof(info->user)); // Both of these blocks start as filled with zero so I think this is okay
info->user = p.variant.user;
info->user = p.user;
DEBUG_MSG("updating changed=%d user %s/%s/%s\n", changed, info->user.id, info->user.long_name, info->user.short_name);
info->has_user = true;
@ -327,11 +323,6 @@ void NodeDB::updateFrom(const MeshPacket &mp)
// We just changed something important about the user, store our DB
// saveToDisk();
}
break;
}
default:
break; // Ignore other packet types
}
}
}

Wyświetl plik

@ -106,12 +106,12 @@ typedef struct _RadioConfig {
} RadioConfig;
typedef struct _SubPacket {
pb_size_t which_variant;
union {
Position position;
Data data;
User user;
} variant;
bool has_position;
Position position;
bool has_data;
Data data;
bool has_user;
User user;
bool want_response;
} SubPacket;
@ -121,6 +121,8 @@ typedef struct _MeshPacket {
bool has_payload;
SubPacket payload;
uint32_t rx_time;
int32_t rx_snr;
uint32_t id;
} MeshPacket;
typedef struct _DeviceState {
@ -173,8 +175,8 @@ typedef struct _ToRadio {
#define Position_init_default {0, 0, 0, 0, 0}
#define Data_init_default {_Data_Type_MIN, {0, {0}}}
#define User_init_default {"", "", "", {0}}
#define SubPacket_init_default {0, {Position_init_default}, 0}
#define MeshPacket_init_default {0, 0, false, SubPacket_init_default, 0}
#define SubPacket_init_default {false, Position_init_default, false, Data_init_default, false, User_init_default, 0}
#define MeshPacket_init_default {0, 0, false, SubPacket_init_default, 0, 0, 0}
#define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0}, ""}
#define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default}
#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
@ -186,8 +188,8 @@ typedef struct _ToRadio {
#define Position_init_zero {0, 0, 0, 0, 0}
#define Data_init_zero {_Data_Type_MIN, {0, {0}}}
#define User_init_zero {"", "", "", {0}}
#define SubPacket_init_zero {0, {Position_init_zero}, 0}
#define MeshPacket_init_zero {0, 0, false, SubPacket_init_zero, 0}
#define SubPacket_init_zero {false, Position_init_zero, false, Data_init_zero, false, User_init_zero, 0}
#define MeshPacket_init_zero {0, 0, false, SubPacket_init_zero, 0, 0, 0}
#define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0}, ""}
#define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero}
#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
@ -250,6 +252,8 @@ typedef struct _ToRadio {
#define MeshPacket_to_tag 2
#define MeshPacket_payload_tag 3
#define MeshPacket_rx_time_tag 4
#define MeshPacket_rx_snr_tag 5
#define MeshPacket_id_tag 6
#define DeviceState_radio_tag 1
#define DeviceState_my_node_tag 2
#define DeviceState_owner_tag 3
@ -286,21 +290,23 @@ X(a, STATIC, SINGULAR, FIXED_LENGTH_BYTES, macaddr, 4)
#define User_DEFAULT NULL
#define SubPacket_FIELDLIST(X, a) \
X(a, STATIC, ONEOF, MESSAGE, (variant,position,variant.position), 1) \
X(a, STATIC, ONEOF, MESSAGE, (variant,data,variant.data), 3) \
X(a, STATIC, ONEOF, MESSAGE, (variant,user,variant.user), 4) \
X(a, STATIC, OPTIONAL, MESSAGE, position, 1) \
X(a, STATIC, OPTIONAL, MESSAGE, data, 3) \
X(a, STATIC, OPTIONAL, MESSAGE, user, 4) \
X(a, STATIC, SINGULAR, BOOL, want_response, 5)
#define SubPacket_CALLBACK NULL
#define SubPacket_DEFAULT NULL
#define SubPacket_variant_position_MSGTYPE Position
#define SubPacket_variant_data_MSGTYPE Data
#define SubPacket_variant_user_MSGTYPE User
#define SubPacket_position_MSGTYPE Position
#define SubPacket_data_MSGTYPE Data
#define SubPacket_user_MSGTYPE User
#define MeshPacket_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, INT32, from, 1) \
X(a, STATIC, SINGULAR, INT32, to, 2) \
X(a, STATIC, OPTIONAL, MESSAGE, payload, 3) \
X(a, STATIC, SINGULAR, UINT32, rx_time, 4)
X(a, STATIC, SINGULAR, UINT32, rx_time, 4) \
X(a, STATIC, SINGULAR, SINT32, rx_snr, 5) \
X(a, STATIC, SINGULAR, UINT32, id, 6)
#define MeshPacket_CALLBACK NULL
#define MeshPacket_DEFAULT NULL
#define MeshPacket_payload_MSGTYPE SubPacket
@ -425,16 +431,16 @@ extern const pb_msgdesc_t ToRadio_msg;
#define Position_size 46
#define Data_size 256
#define User_size 72
#define SubPacket_size 261
#define MeshPacket_size 292
#define SubPacket_size 383
#define MeshPacket_size 426
#define ChannelSettings_size 44
#define RadioConfig_size 120
#define RadioConfig_UserPreferences_size 72
#define NodeInfo_size 155
#define MyNodeInfo_size 85
#define DeviceState_size 15080
#define FromRadio_size 301
#define ToRadio_size 295
#define DeviceState_size 19502
#define FromRadio_size 435
#define ToRadio_size 429
#ifdef __cplusplus
} /* extern "C" */

Wyświetl plik

@ -96,7 +96,8 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
// the max length of this buffer is much longer than we can possibly print
static char tempBuf[96];
snprintf(tempBuf, sizeof(tempBuf), " %s", mp.payload.variant.data.payload.bytes);
assert(mp.payload.has_data);
snprintf(tempBuf, sizeof(tempBuf), " %s", mp.payload.data.payload.bytes);
display->drawStringMaxWidth(4 + x, 10 + y, 128, tempBuf);
}