Plumbing for the GroupPlugin

This commit is contained in:
Jm Casler 2022-02-19 23:43:32 -08:00
parent 701668804a
commit e34190b497
7 changed files with 103 additions and 14 deletions

View File

@ -103,7 +103,7 @@ extern const pb_msgdesc_t ChannelFile_msg;
#define ChannelFile_fields &ChannelFile_msg
/* Maximum encoded size of messages (where known) */
#define DeviceState_size 10985
#define DeviceState_size 10991
#define ChannelFile_size 832
#ifdef __cplusplus

View File

@ -27,6 +27,9 @@ PB_BIND(MeshPacket, MeshPacket, 2)
PB_BIND(NodeInfo, NodeInfo, AUTO)
PB_BIND(GroupInfo, GroupInfo, AUTO)
PB_BIND(MyNodeInfo, MyNodeInfo, 2)

View File

@ -140,8 +140,14 @@ typedef struct _Data {
uint32_t request_id;
uint32_t reply_id;
bool is_tapback;
uint8_t group_id;
} Data;
typedef struct _GroupInfo {
pb_size_t group_count;
char group[10][17];
} GroupInfo;
typedef struct _LogRecord {
char message[64];
uint32_t time;
@ -334,9 +340,10 @@ extern "C" {
#define User_init_default {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN, 0, 0, 0}
#define RouteDiscovery_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}}
#define Routing_init_default {0, {RouteDiscovery_init_default}}
#define Data_init_default {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0}
#define Data_init_default {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0, 0}
#define MeshPacket_init_default {0, 0, 0, 0, {Data_init_default}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN, 0, _MeshPacket_Delayed_MIN}
#define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0}
#define GroupInfo_init_default {0, {"", "", "", "", "", "", "", "", "", ""}}
#define MyNodeInfo_init_default {0, 0, "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, 0}
#define LogRecord_init_default {"", 0, "", _LogRecord_Level_MIN}
#define FromRadio_init_default {0, 0, {MyNodeInfo_init_default}}
@ -346,9 +353,10 @@ extern "C" {
#define User_init_zero {"", "", "", {0}, _HardwareModel_MIN, 0, _Team_MIN, 0, 0, 0}
#define RouteDiscovery_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}}
#define Routing_init_zero {0, {RouteDiscovery_init_zero}}
#define Data_init_zero {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0}
#define Data_init_zero {_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0, 0}
#define MeshPacket_init_zero {0, 0, 0, 0, {Data_init_zero}, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN, 0, _MeshPacket_Delayed_MIN}
#define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0}
#define GroupInfo_init_zero {0, {"", "", "", "", "", "", "", "", "", ""}}
#define MyNodeInfo_init_zero {0, 0, "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, 0}
#define LogRecord_init_zero {"", 0, "", _LogRecord_Level_MIN}
#define FromRadio_init_zero {0, 0, {MyNodeInfo_init_zero}}
@ -364,6 +372,8 @@ extern "C" {
#define Data_request_id_tag 6
#define Data_reply_id_tag 7
#define Data_is_tapback_tag 8
#define Data_group_id_tag 9
#define GroupInfo_group_tag 1
#define LogRecord_message_tag 1
#define LogRecord_time_tag 2
#define LogRecord_source_tag 3
@ -518,7 +528,8 @@ X(a, STATIC, SINGULAR, FIXED32, dest, 4) \
X(a, STATIC, SINGULAR, FIXED32, source, 5) \
X(a, STATIC, SINGULAR, FIXED32, request_id, 6) \
X(a, STATIC, SINGULAR, FIXED32, reply_id, 7) \
X(a, STATIC, SINGULAR, BOOL, is_tapback, 8)
X(a, STATIC, SINGULAR, BOOL, is_tapback, 8) \
X(a, STATIC, SINGULAR, UINT32, group_id, 9)
#define Data_CALLBACK NULL
#define Data_DEFAULT NULL
@ -551,6 +562,11 @@ X(a, STATIC, SINGULAR, FLOAT, snr, 7)
#define NodeInfo_user_MSGTYPE User
#define NodeInfo_position_MSGTYPE Position
#define GroupInfo_FIELDLIST(X, a) \
X(a, STATIC, REPEATED, STRING, group, 1)
#define GroupInfo_CALLBACK NULL
#define GroupInfo_DEFAULT NULL
#define MyNodeInfo_FIELDLIST(X, a) \
X(a, STATIC, SINGULAR, UINT32, my_node_num, 1) \
X(a, STATIC, SINGULAR, BOOL, has_gps, 2) \
@ -618,6 +634,7 @@ extern const pb_msgdesc_t Routing_msg;
extern const pb_msgdesc_t Data_msg;
extern const pb_msgdesc_t MeshPacket_msg;
extern const pb_msgdesc_t NodeInfo_msg;
extern const pb_msgdesc_t GroupInfo_msg;
extern const pb_msgdesc_t MyNodeInfo_msg;
extern const pb_msgdesc_t LogRecord_msg;
extern const pb_msgdesc_t FromRadio_msg;
@ -632,6 +649,7 @@ extern const pb_msgdesc_t ToRadio_PeerInfo_msg;
#define Data_fields &Data_msg
#define MeshPacket_fields &MeshPacket_msg
#define NodeInfo_fields &NodeInfo_msg
#define GroupInfo_fields &GroupInfo_msg
#define MyNodeInfo_fields &MyNodeInfo_msg
#define LogRecord_fields &LogRecord_msg
#define FromRadio_fields &FromRadio_msg
@ -643,13 +661,14 @@ extern const pb_msgdesc_t ToRadio_PeerInfo_msg;
#define User_size 97
#define RouteDiscovery_size 40
#define Routing_size 42
#define Data_size 267
#define MeshPacket_size 318
#define Data_size 270
#define MeshPacket_size 321
#define NodeInfo_size 271
#define GroupInfo_size 180
#define MyNodeInfo_size 434
#define LogRecord_size 81
#define FromRadio_size 443
#define ToRadio_size 321
#define ToRadio_size 324
#define ToRadio_PeerInfo_size 8
#ifdef __cplusplus

View File

@ -20,6 +20,7 @@ typedef enum _PortNum {
PortNum_ADMIN_APP = 6,
PortNum_REPLY_APP = 32,
PortNum_IP_TUNNEL_APP = 33,
PortNum_GROUP_APP = 34,
PortNum_SERIAL_APP = 64,
PortNum_STORE_FORWARD_APP = 65,
PortNum_RANGE_TEST_APP = 66,

View File

@ -0,0 +1,37 @@
#include "GroupPlugin.h"
#include "MeshService.h"
#include "Router.h"
#include "configuration.h"
GroupPlugin *groupPlugin;
GroupPlugin::GroupPlugin()
: ProtobufPlugin("group", PortNum_GROUP_APP, GroupInfo_fields), concurrency::OSThread("GroupPlugin")
{
//isPromiscuous = true; // We always want to update our nodedb, even if we are sniffing on others
//setIntervalFromNow(60 * 1000); // Send our initial position 60 seconds after we start (to give GPS time to setup)
}
bool GroupPlugin::handleReceivedProtobuf(const MeshPacket &mp, GroupInfo *pptr)
{
auto p = *pptr;
return false; // Let others look at this message also if they want
}
MeshPacket *GroupPlugin::allocReply()
{
return allocDataProtobuf(p);
}
int32_t GroupPlugin::runOnce()
{
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return 5000; // to save power only wake for our callback occasionally
}

29
src/plugins/GroupPlugin.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include "GroupPlugin.h"
#include "ProtobufPlugin.h"
#include "concurrency/OSThread.h"
/**
* Position plugin for sending/receiving positions into the mesh
*/
class GroupPlugin : private concurrency::OSThread, public ProtobufPlugin<GroupInfo>
{
public:
GroupPlugin();
protected:
/** Called to handle a particular incoming message
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceivedProtobuf(const MeshPacket &mp, GroupInfo *p) override;
/** 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. */
virtual MeshPacket *allocReply() override;
/** Does our periodic broadcast */
virtual int32_t runOnce() override;
};
extern GroupPlugin *groupPlugin;

View File

@ -1,22 +1,22 @@
#include "configuration.h"
#include "input/InputBroker.h"
#include "input/RotaryEncoderInterruptImpl1.h"
#include "plugins/AdminPlugin.h"
#include "plugins/CannedMessagePlugin.h"
#include "plugins/ExternalNotificationPlugin.h"
#include "plugins/GroupPlugin.h"
#include "plugins/NodeInfoPlugin.h"
#include "plugins/PositionPlugin.h"
#include "plugins/RemoteHardwarePlugin.h"
#include "plugins/ReplyPlugin.h"
#include "plugins/TextMessagePlugin.h"
#include "plugins/TextMessagePlugin.h"
#include "plugins/RoutingPlugin.h"
#include "plugins/AdminPlugin.h"
#include "plugins/CannedMessagePlugin.h"
#include "plugins/TextMessagePlugin.h"
#ifndef PORTDUINO
#include "plugins/EnvironmentalMeasurement/EnvironmentalMeasurementPlugin.h"
#endif
#ifndef NO_ESP32
#include "plugins/esp32/SerialPlugin.h"
#include "plugins/esp32/RangeTestPlugin.h"
#include "plugins/esp32/SerialPlugin.h"
#include "plugins/esp32/StoreForwardPlugin.h"
#endif
@ -30,14 +30,14 @@ void setupPlugins()
nodeInfoPlugin = new NodeInfoPlugin();
positionPlugin = new PositionPlugin();
textMessagePlugin = new TextMessagePlugin();
groupPlugin = new GroupPlugin();
// Note: if the rest of meshtastic doesn't need to explicitly use your plugin, you do not need to assign the instance
// to a global variable.
new RemoteHardwarePlugin();
new ReplyPlugin();
rotaryEncoderInterruptImpl1 =
new RotaryEncoderInterruptImpl1();
rotaryEncoderInterruptImpl1 = new RotaryEncoderInterruptImpl1();
rotaryEncoderInterruptImpl1->init();
cannedMessagePlugin = new CannedMessagePlugin();
#ifndef PORTDUINO