Merge branch 'refactor-network' into 'develop'

layer basic com

See merge request wirelos/sprocket-core!9
This commit is contained in:
2018-07-12 07:14:08 +00:00
7 changed files with 20 additions and 16 deletions

View File

@@ -35,7 +35,9 @@ firmware-build:
image: python:2.7-stretch
script:
- pio run -t clean
- pio run
- pio run --environment basic
- pio run --environment mesh
- pio run --environment meshMqttBridge
artifacts:
paths:
- .pioenvs/*/firmware.*

View File

@@ -36,6 +36,7 @@
"type_traits": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp"
"utility": "cpp",
"bitset": "cpp"
}
}

View File

@@ -11,7 +11,6 @@ Network* MeshNet::init(){
mesh.setDebugMsgTypes( config.debugTypes );
mesh.init( config.meshSSID, config.meshPassword, scheduler, config.meshPort, WIFI_AP_STA, config.channel );
//mesh.onReceive(bind(&MeshNet::receivedCallback,this, _1, _2));
mesh.onNewConnection(bind(&MeshNet::newConnectionCallback, this, _1));
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
@@ -36,8 +35,8 @@ void MeshNet::update(){
// only needed when no scheduler was passed to mesh.init
mesh.update();
}
void MeshNet::receivedCallback( uint32_t from, String &msg ) {
Serial.printf("--> Received from %u msg=%s\n", from, msg.c_str());
void MeshNet::onReceive( std::function<void(uint32_t from, String &msg)> cb) {
mesh.onReceive(cb);
}
void MeshNet::newConnectionCallback(uint32_t nodeId) {

View File

@@ -28,13 +28,13 @@ class MeshNet : public Network {
MeshNet(MeshConfig cfg);
Network* init();
void broadcast(String msg);
void sendTo(uint32_t target, String msg);
void update(); // only needed when no scheduler was passed to mesh.init
void receivedCallback( uint32_t from, String &msg );
void newConnectionCallback(uint32_t nodeId);
void changedConnectionCallback();
void nodeTimeAdjustedCallback(int32_t offset);
void broadcast(String msg);
void sendTo(uint32_t target, String msg);
void onReceive(std::function<void(uint32_t from, String &msg)>);
};
#endif

View File

@@ -4,6 +4,8 @@
#include <Arduino.h>
#include <TaskSchedulerDeclarations.h>
typedef std::function<void(uint32_t from, String &msg)> msgReceived_cb;
class Network {
public:
uint32_t id = 0;
@@ -13,9 +15,9 @@ class Network {
virtual Network* init(Scheduler* s) { scheduler = s; return init(); };
virtual Network* connect() { return this; };
virtual void update() {};
virtual void broadcast(String msg){
Serial.println("no-broadcast");
};
virtual void broadcast(String msg){};
virtual void sendTo(uint32_t target, String msg) {};
virtual void onReceive(std::function<void(uint32_t from, String &msg)>);
Network* setScheduler(Scheduler* s) {
scheduler = s;
return this;

View File

@@ -15,7 +15,7 @@ class MeshApp : public Sprocket {
MeshApp(SprocketConfig cfg) : Sprocket(cfg) {}
Sprocket* activate(Scheduler* scheduler, Network* network) {
net = static_cast<MeshNet*>(network);
net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2));
net->onReceive(bind(&MeshApp::onReceive,this, _1, _2));
// add a task that sends stuff to the mesh
someTask.set(TASK_SECOND * 5, TASK_FOREVER,
bind(&MeshApp::heartbeat, this, net));
@@ -28,8 +28,8 @@ class MeshApp : public Sprocket {
network->broadcast(msg);
}
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
void onReceive( uint32_t from, String &msg ) {
Serial.printf("MeshApp: received from %u msg=%s\n", from, msg.c_str());
// respond in receive callback can cause an endless loop when all nodes run the same firmware
//String foo = String("cheerz back to ") + String(from);
//net->broadcast(foo);

View File

@@ -13,11 +13,11 @@
#define STATION_MODE 0
#define WIFI_CHANNEL 11
#define MESH_PORT 5555
#define MESH_PREFIX "WirelosContraption"
#define MESH_PREFIX "whateverYouLike"
#define MESH_PASSWORD "somethingSneaky"
#define STATION_SSID "Th1ngs4P"
#define STATION_PASSWORD "th3r31sn0sp00n"
#define HOSTNAME "mesh-node"
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
#define MESH_DEBUG_TYPES ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE
#endif