mirror of
https://github.com/meshtastic/firmware.git
synced 2025-07-31 02:45:41 +00:00
loopback test support
This commit is contained in:
parent
47d278b3b9
commit
9481d9e95b
@ -120,6 +120,34 @@ MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
|
|||||||
return mp;
|
return mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeshService::handleFromRadio(MeshPacket *mp)
|
||||||
|
{
|
||||||
|
mp->rx_time = gps.getTime() / 1000; // store the arrival timestamp for the phone
|
||||||
|
|
||||||
|
if (mp->has_payload && mp->payload.which_variant == SubPacket_user_tag)
|
||||||
|
{
|
||||||
|
mp = handleFromRadioUser(mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we veto a received User packet, we don't put it into the DB or forward it to the phone (to prevent confusing it)
|
||||||
|
if (mp)
|
||||||
|
{
|
||||||
|
nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio
|
||||||
|
|
||||||
|
fromNum++;
|
||||||
|
|
||||||
|
if (toPhoneQueue.numFree() == 0)
|
||||||
|
{
|
||||||
|
DEBUG_MSG("NOTE: tophone queue is full, discarding oldest\n");
|
||||||
|
MeshPacket *d = toPhoneQueue.dequeuePtr(0);
|
||||||
|
if (d)
|
||||||
|
releaseToPool(d);
|
||||||
|
}
|
||||||
|
assert(toPhoneQueue.enqueue(mp, 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DEBUG_MSG("Dropping vetoed User message\n");
|
||||||
|
}
|
||||||
|
|
||||||
void MeshService::handleFromRadio()
|
void MeshService::handleFromRadio()
|
||||||
{
|
{
|
||||||
@ -127,31 +155,7 @@ void MeshService::handleFromRadio()
|
|||||||
uint32_t oldFromNum = fromNum;
|
uint32_t oldFromNum = fromNum;
|
||||||
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL)
|
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL)
|
||||||
{
|
{
|
||||||
mp->rx_time = gps.getTime() / 1000; // store the arrival timestamp for the phone
|
handleFromRadio(mp);
|
||||||
|
|
||||||
if (mp->has_payload && mp->payload.which_variant == SubPacket_user_tag)
|
|
||||||
{
|
|
||||||
mp = handleFromRadioUser(mp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we veto a received User packet, we don't put it into the DB or forward it to the phone (to prevent confusing it)
|
|
||||||
if (mp)
|
|
||||||
{
|
|
||||||
nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio
|
|
||||||
|
|
||||||
fromNum++;
|
|
||||||
|
|
||||||
if (toPhoneQueue.numFree() == 0)
|
|
||||||
{
|
|
||||||
DEBUG_MSG("NOTE: tophone queue is full, discarding oldest\n");
|
|
||||||
MeshPacket *d = toPhoneQueue.dequeuePtr(0);
|
|
||||||
if (d)
|
|
||||||
releaseToPool(d);
|
|
||||||
}
|
|
||||||
assert(toPhoneQueue.enqueue(mp, 0) == pdTRUE); // FIXME, instead of failing for full queue, delete the oldest mssages
|
|
||||||
}
|
|
||||||
else
|
|
||||||
DEBUG_MSG("Dropping vetoed User message\n");
|
|
||||||
}
|
}
|
||||||
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);
|
bluetoothNotifyFromNum(fromNum);
|
||||||
@ -192,9 +196,18 @@ void MeshService::handleToRadio(std::string s)
|
|||||||
switch (r.which_variant)
|
switch (r.which_variant)
|
||||||
{
|
{
|
||||||
case ToRadio_packet_tag:
|
case ToRadio_packet_tag:
|
||||||
|
{
|
||||||
sendToMesh(packetPool.allocCopy(r.variant.packet));
|
sendToMesh(packetPool.allocCopy(r.variant.packet));
|
||||||
break;
|
|
||||||
|
|
||||||
|
bool loopback = false; // if true send any packet the phone sends back itself (for testing)
|
||||||
|
if (loopback)
|
||||||
|
{
|
||||||
|
MeshPacket *mp = packetPool.allocCopy(r.variant.packet);
|
||||||
|
handleFromRadio(mp);
|
||||||
|
bluetoothNotifyFromNum(fromNum); // tell the phone a new packet arrived
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
DEBUG_MSG("Error: unexpected ToRadio variant\n");
|
DEBUG_MSG("Error: unexpected ToRadio variant\n");
|
||||||
break;
|
break;
|
||||||
|
@ -78,9 +78,12 @@ private:
|
|||||||
|
|
||||||
virtual void onNotify(Observable *o);
|
virtual void onNotify(Observable *o);
|
||||||
|
|
||||||
/// handle packets that just arrived from the mesh radio
|
/// handle all the packets that just arrived from the mesh radio
|
||||||
void handleFromRadio();
|
void handleFromRadio();
|
||||||
|
|
||||||
|
/// Handle a packet that just arrived from the radio
|
||||||
|
void handleFromRadio(MeshPacket *p);
|
||||||
|
|
||||||
/// handle a user packet that just arrived on the radio, return NULL if we should not process this packet at all
|
/// handle a user packet that just arrived on the radio, return NULL if we should not process this packet at all
|
||||||
MeshPacket *handleFromRadioUser(MeshPacket *mp);
|
MeshPacket *handleFromRadioUser(MeshPacket *mp);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user