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,13 +120,8 @@ MeshPacket *MeshService::handleFromRadioUser(MeshPacket *mp)
return mp;
}
void MeshService::handleFromRadio()
void MeshService::handleFromRadio(MeshPacket *mp)
{
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
if (mp->has_payload && mp->payload.which_variant == SubPacket_user_tag)
@ -152,6 +147,15 @@ void MeshService::handleFromRadio()
}
else
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
bluetoothNotifyFromNum(fromNum);
@ -192,9 +196,18 @@ void MeshService::handleToRadio(std::string s)
switch (r.which_variant)
{
case ToRadio_packet_tag:
{
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:
DEBUG_MSG("Error: unexpected ToRadio variant\n");
break;

View File

@ -78,9 +78,12 @@ private:
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();
/// 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
MeshPacket *handleFromRadioUser(MeshPacket *mp);
};