we now send owner at boot

This commit is contained in:
geeksville
2020-02-06 10:58:19 -08:00
parent 241e262f5c
commit 2792e2148f
5 changed files with 44 additions and 7 deletions

View File

@@ -68,7 +68,7 @@ bool MeshRadio::init()
ErrorCode MeshRadio::send(MeshPacket *p)
{
DEBUG_MSG("enquing packet for sending on mesh\n");
DEBUG_MSG("enquing packet for send from=%d, to=%d\n", p->from, p->to);
return txQueue.enqueue(p, 0); // nowait
}

View File

@@ -43,6 +43,18 @@ void MeshService::init()
DEBUG_MSG("radio init failed\n");
gps.addObserver(this);
sendOurOwner();
}
void MeshService::sendOurOwner(NodeNum dest)
{
MeshPacket *p = allocForSending();
p->to = dest;
p->payload.which_variant = SubPacket_user_tag;
User &u = p->payload.variant.user;
u = owner;
sendToMesh(p);
}
/// Do idle processing (mostly processing messages which have been queued from the radio)
@@ -89,13 +101,20 @@ void MeshService::sendToMesh(MeshPacket *p)
assert(radio.send(p) == pdTRUE);
}
void MeshService::onGPSChanged()
MeshPacket *MeshService::allocForSending()
{
MeshPacket *p = packetPool.allocZeroed();
p->has_payload = true;
p->from = nodeDB.getNodeNum();
p->to = NODENUM_BROADCAST;
return p;
}
void MeshService::onGPSChanged()
{
MeshPacket *p = allocForSending();
p->payload.which_variant = SubPacket_position_tag;
Position &pos = p->payload.variant.position;
if (gps.altitude.isValid())

View File

@@ -57,6 +57,11 @@ public:
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
void reloadOwner() { DEBUG_MSG("FIXME implement reloadOwner\n"); }
/// Allocate and return a meshpacket which defaults as send to broadcast from the current node.
MeshPacket *allocForSending();
/// Send our owner info to a particular node
void sendOurOwner(NodeNum dest = NODENUM_BROADCAST);
private:
/// Send a packet into the mesh - note p must have been allocated from packetPool. We will return it to that pool after sending.

View File

@@ -31,7 +31,7 @@ static NodeNum getDesiredNodeNum()
// FIXME not the right way to guess node numes
uint8_t r = ourMacAddr[5];
assert(r != 0xff); // It better not be the broadcast address
assert(r != 0xff && r != 0); // It better not be the broadcast address or zero
return r;
}
@@ -50,6 +50,8 @@ void NodeDB::init() {
ourMacAddr[1], ourMacAddr[2], ourMacAddr[3], ourMacAddr[4], ourMacAddr[5]);
memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr));
sprintf(owner.long_name, "Unknown %02x%02x", ourMacAddr[4], ourMacAddr[5]);
sprintf(owner.short_name, "?%02X", ourMacAddr[5]);
// FIXME, read owner info from flash
// Include our owner in the node db under our nodenum
@@ -74,7 +76,7 @@ void NodeDB::updateFrom(const MeshPacket &mp)
if (mp.has_payload)
{
const SubPacket &p = mp.payload;
DEBUG_MSG("Update DB node %x for %d\n", mp.from, p.which_variant);
DEBUG_MSG("Update DB node %x for variant %d\n", mp.from, p.which_variant);
if (p.which_variant != SubPacket_want_node_tag) // we don't create nodeinfo records for someone that is just trying to claim a nodenum
{
int oldNumNodes = numNodes;