rename message type

This commit is contained in:
2018-09-10 01:01:45 +02:00
parent 58232bdacf
commit 622074df2c
7 changed files with 15 additions and 15 deletions

View File

@@ -3,14 +3,14 @@
#include <TaskSchedulerDeclarations.h> #include <TaskSchedulerDeclarations.h>
#include <Network.h> #include <Network.h>
#include <base/MeshMessage.h> #include <base/SprocketMessage.h>
class Plugin { class Plugin {
public: public:
virtual void activate(Scheduler*, Network*); virtual void activate(Scheduler*, Network*);
virtual void enable(){}; virtual void enable(){};
virtual void disable(){}; virtual void disable(){};
virtual void onMessage(MeshMessage msg){}; virtual void onMessage(SprocketMessage msg){};
}; };
#endif #endif

View File

@@ -43,7 +43,7 @@ void Sprocket::loop(){
} }
void Sprocket::dispatch( uint32_t from, String &msg ) { void Sprocket::dispatch( uint32_t from, String &msg ) {
MeshMessage mMsg; SprocketMessage mMsg;
if(mMsg.fromJsonString(msg)){ if(mMsg.fromJsonString(msg)){
dispatchMessageToPlugins(mMsg); dispatchMessageToPlugins(mMsg);
} }
@@ -60,8 +60,8 @@ void Sprocket::activatePlugins(Scheduler* scheduler, Network* network){
} }
} }
void Sprocket::dispatchMessageToPlugins(MeshMessage msg){ void Sprocket::dispatchMessageToPlugins(SprocketMessage msg){
if(msg.type != MeshMessage::NONE){ // baaaa if(msg.type != SprocketMessage::NONE){ // baaaa
for(Plugin* p : plugins){ for(Plugin* p : plugins){
Serial.println("dispatch to plugins"); Serial.println("dispatch to plugins");
p->onMessage(msg); p->onMessage(msg);

View File

@@ -37,7 +37,7 @@ class Sprocket {
void addPlugin(Plugin* p); void addPlugin(Plugin* p);
void activatePlugins(Scheduler* scheduler, Network* network); void activatePlugins(Scheduler* scheduler, Network* network);
void dispatchMessageToPlugins(MeshMessage msg); void dispatchMessageToPlugins(SprocketMessage msg);
}; };
#endif #endif

View File

@@ -6,7 +6,7 @@
#include <painlessMesh.h> #include <painlessMesh.h>
#include <Sprocket.h> #include <Sprocket.h>
#include <MeshNet.h> #include <MeshNet.h>
#include <base/MeshMessage.h> #include <base/SprocketMessage.h>
#include <base/MeshSprocketConfig.h> #include <base/MeshSprocketConfig.h>
#include "config.h" #include "config.h"
#include "utils_print.h" #include "utils_print.h"

View File

@@ -10,12 +10,12 @@
#define JSON_MSG "msg" #define JSON_MSG "msg"
#define JSON_TYPE "type" #define JSON_TYPE "type"
struct MeshMessage { struct SprocketMessage {
String domain; String domain;
String to; String to;
String from; String from;
String msg; String msg;
enum MeshMessageType { NONE, SYSTEM, APP, OTA } type; enum SprocketMessageType { NONE, SYSTEM, APP, OTA } type;
int valid = 0; int valid = 0;
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
//void init() { //void init() {
@@ -57,7 +57,7 @@ struct MeshMessage {
// Map a json object to this struct. // Map a json object to this struct.
int fromJsonObject(JsonObject& json){ int fromJsonObject(JsonObject& json){
if(!verifyJsonObject(json)){ if(!verifyJsonObject(json)){
Serial.println("ERROR: cannot parse MeshMessage JSON object"); Serial.println("ERROR: cannot parse SprocketMessage JSON object");
valid = 0; valid = 0;
return valid; return valid;
} }
@@ -65,7 +65,7 @@ struct MeshMessage {
to = getAttrFromJson(json, JSON_TO); to = getAttrFromJson(json, JSON_TO);
from = getAttrFromJson(json, JSON_FROM); from = getAttrFromJson(json, JSON_FROM);
msg = getAttrFromJson(json, JSON_MSG); msg = getAttrFromJson(json, JSON_MSG);
type = (MeshMessageType) getIntAttrFromJson(json, JSON_TYPE); type = (SprocketMessageType) getIntAttrFromJson(json, JSON_TYPE);
valid = 1; valid = 1;
return valid; return valid;
}; };

View File

@@ -45,11 +45,11 @@ class MeshApp : public MeshSprocket {
} }
void heartbeat(MeshNet* network){ void heartbeat(MeshNet* network){
MeshMessage msg; // = { "wirelos", "broadcast", "local", "alive", 0, }; SprocketMessage msg; // = { "wirelos", "broadcast", "local", "alive", 0, };
msg.domain = "wirelos"; msg.domain = "wirelos";
msg.to = "broadcast"; msg.to = "broadcast";
msg.msg = "alive"; msg.msg = "alive";
msg.type = MeshMessage::APP; msg.type = SprocketMessage::APP;
String msgStr = msg.toJsonString(); String msgStr = msg.toJsonString();
network->mesh.sendBroadcast(msgStr/* , true */); network->mesh.sendBroadcast(msgStr/* , true */);
//String mMsg = String("hoi"); //String mMsg = String("hoi");

View File

@@ -33,8 +33,8 @@ class OtaTcpPlugin : public Plugin {
ArduinoOTA.begin(); ArduinoOTA.begin();
otaTask.enable(); otaTask.enable();
} }
void onMessage(MeshMessage msg) { void onMessage(SprocketMessage msg) {
if(msg.type == MeshMessage::OTA){ if(msg.type == SprocketMessage::OTA){
Serial.println("OTA msg received"); Serial.println("OTA msg received");
WiFi.disconnect(); WiFi.disconnect();
net->mesh.stop(); net->mesh.stop();