WIP phone api changes for dev1.2

This commit is contained in:
Kevin Hester
2021-02-17 19:04:41 +08:00
parent 60a01567d9
commit 69a11e7375
18 changed files with 82 additions and 63 deletions

View File

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