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 <Network.h>
#include <base/MeshMessage.h>
#include <base/SprocketMessage.h>
class Plugin {
public:
virtual void activate(Scheduler*, Network*);
virtual void enable(){};
virtual void disable(){};
virtual void onMessage(MeshMessage msg){};
virtual void onMessage(SprocketMessage msg){};
};
#endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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