we now send gps locations into the mesh and update our nodedb

1.2-legacy
geeksville 2020-02-06 08:49:33 -08:00
rodzic 9625bcbd9e
commit 241e262f5c
6 zmienionych plików z 67 dodań i 28 usunięć

Wyświetl plik

@ -59,6 +59,7 @@ until the phone pulls those packets. Ever so often power on bluetooth just so w
# Low priority
* add a watchdog timer
* fix GPS.zeroOffset calculation it is wrong
* handle millis() rollover in GPS.getTime - otherwise we will break after 50 days
* reneable the bluetooth battely level service on the T-BEAM, because we can read battery level there

Wyświetl plik

@ -39,7 +39,7 @@ void GPS::loop()
24 * 60 * 60 * (date.month() * 31 + date.day() + 365 * (date.year() - 1970))) +
time.centisecond() * 10;
DEBUG_MSG("Setting time zero %lld", zeroOffset);
DEBUG_MSG("Setting time zero %lld\n", zeroOffset);
}
#endif
}

Wyświetl plik

@ -29,8 +29,17 @@ public:
delete[] buf;
}
/// Return a queable object which has been prefilled with zeros
T *allocZeroed(TickType_t maxWait = portMAX_DELAY) {
/// Return a queable object which has been prefilled with zeros. Panic if no buffer is available
T *allocZeroed() {
T *p = allocZeroed(0);
assert(p); // FIXME panic instead
return p;
}
/// Return a queable object which has been prefilled with zeros - allow timeout to wait for available buffers (you probably don't want this version)
T *allocZeroed(TickType_t maxWait) {
T *p = dead.dequeuePtr(maxWait);
if(p)

Wyświetl plik

@ -6,6 +6,7 @@
#include "MeshService.h"
#include "MeshBluetoothService.h"
#include "NodeDB.h"
#include "GPS.h"
/*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
@ -18,7 +19,6 @@ a node number and keeping the current nodedb.
*/
MeshService service;
#define MAX_PACKETS 32 // max number of packets which can be in flight (either queued from reception or queued for sending)
@ -41,6 +41,8 @@ void MeshService::init()
if (!radio.init())
DEBUG_MSG("radio init failed\n");
gps.addObserver(this);
}
/// Do idle processing (mostly processing messages which have been queued from the radio)
@ -50,14 +52,14 @@ void MeshService::loop()
MeshPacket *mp;
uint32_t oldFromNum = fromNum;
while((mp = fromRadioQueue.dequeuePtr(0)) != NULL) {
nodeDB.updateFrom(*mp);
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL)
{
nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio
fromNum++;
assert(toPhoneQueue.enqueue(mp , 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
assert(toPhoneQueue.enqueue(mp, 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
}
if(oldFromNum != fromNum) // We don't want to generate extra notifies for multiple new packets
if (oldFromNum != fromNum) // We don't want to generate extra notifies for multiple new packets
bluetoothNotifyFromNum(fromNum);
}
@ -71,7 +73,7 @@ void MeshService::handleToRadio(std::string s)
switch (r.which_variant)
{
case ToRadio_packet_tag:
sendToMesh(r.variant.packet);
sendToMesh(packetPool.allocCopy(r.variant.packet));
break;
default:
@ -81,12 +83,31 @@ void MeshService::handleToRadio(std::string s)
}
}
/// Send a packet into the mesh - note p is read only and should be copied into a pool based MeshPacket before
/// sending.
void MeshService::sendToMesh(const MeshPacket &pIn)
void MeshService::sendToMesh(MeshPacket *p)
{
MeshPacket *pOut = packetPool.allocCopy(pIn);
assert(pOut); // FIXME
assert(radio.send(pOut) == pdTRUE);
nodeDB.updateFrom(*p);
assert(radio.send(p) == pdTRUE);
}
void MeshService::onGPSChanged()
{
MeshPacket *p = packetPool.allocZeroed();
p->has_payload = true;
p->from = nodeDB.getNodeNum();
p->to = NODENUM_BROADCAST;
p->payload.which_variant = SubPacket_position_tag;
Position &pos = p->payload.variant.position;
if (gps.altitude.isValid())
pos.altitude = gps.altitude.value();
pos.latitude = gps.location.lat();
pos.longitude = gps.location.lng();
sendToMesh(p);
}
void MeshService::onNotify(Observable *o)
{
DEBUG_MSG("got gps notify\n");
onGPSChanged();
}

Wyświetl plik

@ -7,12 +7,13 @@
#include "MeshRadio.h"
#include "PointerQueue.h"
#include "MemoryPool.h"
#include "Observer.h"
/**
* Top level app for this service. keeps the mesh, the radio config and the queue of received packets.
*
*/
class MeshService
class MeshService: private Observer
{
MemoryPool<MeshPacket> packetPool;
@ -58,10 +59,14 @@ public:
private:
/// Send a packet into the mesh - note p is read only and should be copied into a pool based MeshPacket before
/// sending.
void sendToMesh(const MeshPacket &p);
/// Send a packet into the mesh - note p must have been allocated from packetPool. We will return it to that pool after sending.
/// This is the ONLY function you should use for sending messages into the mesh, because it also updates the nodedb cache
void sendToMesh(MeshPacket *p);
/// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh
void onGPSChanged();
virtual void onNotify(Observable *o);
};
extern MeshService service;

Wyświetl plik

@ -17,6 +17,9 @@ public:
void observe(Observable *o);
private:
friend class Observable;
virtual void onNotify(Observable *o) = 0;
};