Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP ATAK plugin message handling #3169

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/mesh/MeshModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ meshtastic_MeshPacket *MeshModule::allocErrorResponse(meshtastic_Routing_Error e
return r;
}

void MeshModule::callPlugins(const meshtastic_MeshPacket &mp, RxSource src)
void MeshModule::callPlugins(meshtastic_MeshPacket &mp, RxSource src)
{
// LOG_DEBUG("In call modules\n");
bool moduleFound = false;
Expand Down Expand Up @@ -124,9 +124,10 @@ void MeshModule::callPlugins(const meshtastic_MeshPacket &mp, RxSource src)
} else
printPacket("packet on wrong channel, but can't respond", &mp);
} else {

ProcessMessage handled = pi.handleReceived(mp);

pi.alterReceived(mp);

// Possibly send replies (but only if the message was directed to us specifically, i.e. not for promiscious
// sniffing) also: we only let the one module send a reply, once that happens, remaining modules are not
// considered
Expand Down
27 changes: 10 additions & 17 deletions src/mesh/MeshModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,15 @@ class MeshModule

/** For use only by MeshService
*/
static void callPlugins(const meshtastic_MeshPacket &mp, RxSource src = RX_SRC_RADIO);
static void callPlugins(meshtastic_MeshPacket &mp, RxSource src = RX_SRC_RADIO);

static std::vector<MeshModule *> GetMeshModulesWithUIFrames();
static void observeUIEvents(Observer<const UIFrameEvent *> *observer);
static AdminMessageHandleResult handleAdminMessageForAllPlugins(const meshtastic_MeshPacket &mp,
meshtastic_AdminMessage *request,
meshtastic_AdminMessage *response);
#if HAS_SCREEN
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
return;
}
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { return; }
#endif
protected:
const char *name;
Expand Down Expand Up @@ -135,10 +132,12 @@ class MeshModule
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for
it
*/
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp)
{
return ProcessMessage::CONTINUE;
}
virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) { return ProcessMessage::CONTINUE; }

/** Called to change a particular incoming message
This allows the module to change the message before it is passed through the rest of the call-chain.
*/
virtual void alterReceived(meshtastic_MeshPacket &mp) {}

/** Messages can be received that have the want_response bit set. If set, this callback will be invoked
* so that subclasses can (optionally) send a response back to the original sender.
Expand All @@ -151,14 +150,8 @@ class MeshModule
/***
* @return true if you want to be alloced a UI screen frame
*/
virtual bool wantUIFrame()
{
return false;
}
virtual Observable<const UIFrameEvent *> *getUIFrameObservable()
{
return NULL;
}
virtual bool wantUIFrame() { return false; }
virtual Observable<const UIFrameEvent *> *getUIFrameObservable() { return NULL; }

meshtastic_MeshPacket *allocAckNak(meshtastic_Routing_Error err, NodeNum to, PacketId idFrom, ChannelIndex chIndex);

Expand Down
26 changes: 26 additions & 0 deletions src/mesh/ProtobufModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ template <class T> class ProtobufModule : protected SinglePortModule
*/
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, T *decoded) = 0;

/** Called to make changes to a particular incoming message
*/
virtual void alterReceivedProtobuf(meshtastic_MeshPacket &mp, T *decoded){};

/**
* Return a mesh packet which has been preinited with a particular protobuf data payload and port number.
* You can then send this packet (after customizing any of the payload fields you might need) with
Expand Down Expand Up @@ -86,4 +90,26 @@ template <class T> class ProtobufModule : protected SinglePortModule

return handleReceivedProtobuf(mp, decoded) ? ProcessMessage::STOP : ProcessMessage::CONTINUE;
}

/** Called to alter a particular incoming message
*/
virtual void alterReceived(meshtastic_MeshPacket &mp) override
{
auto &p = mp.decoded;

T scratch;
T *decoded = NULL;
if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.decoded.portnum == ourPortNum) {
memset(&scratch, 0, sizeof(scratch));
if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, fields, &scratch)) {
decoded = &scratch;
} else {
LOG_ERROR("Error decoding protobuf module!\n");
// if we can't decode it, nobody can process it!
return;
}
}

return alterReceivedProtobuf(mp, decoded);
}
};
29 changes: 29 additions & 0 deletions src/mesh/generated/meshtastic/atak.pb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.7 */

#include "meshtastic/atak.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
#endif

PB_BIND(meshtastic_TAKPacket, meshtastic_TAKPacket, 2)


PB_BIND(meshtastic_GeoChat, meshtastic_GeoChat, AUTO)


PB_BIND(meshtastic_Group, meshtastic_Group, AUTO)


PB_BIND(meshtastic_Status, meshtastic_Status, AUTO)


PB_BIND(meshtastic_Contact, meshtastic_Contact, AUTO)


PB_BIND(meshtastic_PLI, meshtastic_PLI, AUTO)





Loading
Loading