mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-10 15:37:17 +00:00
Let SimRadio start receive a packet if its PortNum is Simulator_App
This commit is contained in:
parent
5d464badc8
commit
ab282765d4
@ -123,6 +123,29 @@ void MeshService::reloadOwner()
|
|||||||
*/
|
*/
|
||||||
void MeshService::handleToRadio(MeshPacket &p)
|
void MeshService::handleToRadio(MeshPacket &p)
|
||||||
{
|
{
|
||||||
|
#ifdef ARCH_PORTDUINO
|
||||||
|
// Simulates device is receiving a packet via the LoRa chip
|
||||||
|
if (p.decoded.portnum == PortNum_SIMULATOR_APP) {
|
||||||
|
// Simulator packet (=Compressed packet) is encapsulated in a MeshPacket, so need to unwrap first
|
||||||
|
Compressed scratch;
|
||||||
|
Compressed *decoded = NULL;
|
||||||
|
if (p.which_payload_variant == MeshPacket_decoded_tag) {
|
||||||
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
|
p.decoded.payload.size = pb_decode_from_bytes(p.decoded.payload.bytes, p.decoded.payload.size, &Compressed_msg, &scratch);
|
||||||
|
if (p.decoded.payload.size) {
|
||||||
|
decoded = &scratch;
|
||||||
|
// Extract the original payload and replace
|
||||||
|
memcpy(&p.decoded.payload, &decoded->data, sizeof(decoded->data));
|
||||||
|
// Switch the port from PortNum_SIMULATOR_APP back to the original PortNum
|
||||||
|
p.decoded.portnum = decoded->portnum;
|
||||||
|
} else
|
||||||
|
DEBUG_MSG("Error decoding protobuf for simulator message!\n");
|
||||||
|
}
|
||||||
|
// Let SimRadio receive as if it did via its LoRa chip
|
||||||
|
SimRadio::instance->startReceive(&p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (p.from != 0) { // We don't let phones assign nodenums to their sent messages
|
if (p.from != 0) { // We don't let phones assign nodenums to their sent messages
|
||||||
DEBUG_MSG("Warning: phone tried to pick a nodenum, we don't allow that.\n");
|
DEBUG_MSG("Warning: phone tried to pick a nodenum, we don't allow that.\n");
|
||||||
p.from = 0;
|
p.from = 0;
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
#include "MeshTypes.h"
|
#include "MeshTypes.h"
|
||||||
#include "Observer.h"
|
#include "Observer.h"
|
||||||
#include "PointerQueue.h"
|
#include "PointerQueue.h"
|
||||||
|
#ifdef ARCH_PORTDUINO
|
||||||
|
#include "mesh/SimRadio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top level app for this service. keeps the mesh, the radio config and the queue of received packets.
|
* Top level app for this service. keeps the mesh, the radio config and the queue of received packets.
|
||||||
|
Loading…
Reference in New Issue
Block a user