loopback test support

This commit is contained in:
geeksville 2020-02-17 17:47:01 -08:00
parent 47d278b3b9
commit 9481d9e95b
2 changed files with 43 additions and 27 deletions

View File

@ -120,12 +120,7 @@ MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
return mp; return mp;
} }
void MeshService::handleFromRadio(MeshPacket *mp)
void MeshService::handleFromRadio()
{
MeshPacket *mp;
uint32_t oldFromNum = fromNum;
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL)
{ {
mp->rx_time = gps.getTime() / 1000; // store the arrival timestamp for the phone mp->rx_time = gps.getTime() / 1000; // store the arrival timestamp for the phone
@ -153,6 +148,15 @@ void MeshService::handleFromRadio()
else else
DEBUG_MSG("Dropping vetoed User message\n"); DEBUG_MSG("Dropping vetoed User message\n");
} }
void MeshService::handleFromRadio()
{
MeshPacket *mp;
uint32_t oldFromNum = fromNum;
while ((mp = fromRadioQueue.dequeuePtr(0)) != NULL)
{
handleFromRadio(mp);
}
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;

View File

@ -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);
}; };