mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 10:42:49 +00:00
WIP phone api changes for dev1.2
This commit is contained in:
@@ -25,8 +25,11 @@ template <class T> class ProtobufPlugin : protected SinglePortPlugin
|
||||
|
||||
/**
|
||||
* Handle a received message, the data field in the message is already decoded and is provided
|
||||
*
|
||||
* In general decoded will always be !NULL. But in some special applications (where you have handling packets
|
||||
* for multiple port numbers, decoding will ONLY be attempted for packets where the portnum matches our expected ourPortNum.
|
||||
*/
|
||||
virtual bool handleReceivedProtobuf(const MeshPacket &mp, const T &decoded) = 0;
|
||||
virtual bool handleReceivedProtobuf(const MeshPacket &mp, const T *decoded) = 0;
|
||||
|
||||
/**
|
||||
* Return a mesh packet which has been preinited with a particular protobuf data payload and port number.
|
||||
@@ -58,9 +61,14 @@ template <class T> class ProtobufPlugin : protected SinglePortPlugin
|
||||
DEBUG_MSG("Received %s from=0x%0x, id=0x%x, payloadlen=%d\n", name, mp.from, mp.id, p.payload.size);
|
||||
|
||||
T scratch;
|
||||
if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, fields, &scratch))
|
||||
return handleReceivedProtobuf(mp, scratch);
|
||||
T *decoded = NULL;
|
||||
if(mp.decoded.portnum == ourPortNum) {
|
||||
if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, fields, &scratch))
|
||||
decoded = &scratch;
|
||||
else
|
||||
DEBUG_MSG("Error decoding protobuf plugin!\n");
|
||||
}
|
||||
|
||||
return false; // Let others look at this message also if they want
|
||||
return handleReceivedProtobuf(mp, decoded);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user