refactoring

This commit is contained in:
2018-08-19 16:10:56 +02:00
parent c127346394
commit 77f1b278f4
7 changed files with 146 additions and 23 deletions

View File

@@ -18,21 +18,31 @@ class OtaTcpPlugin : public Plugin {
private:
OtaConfig config;
Task otaTask;
MeshNet* network;
public:
OtaTcpPlugin(OtaConfig cfg){
config = cfg;
}
void enable(Scheduler* userScheduler, Network* network){
scheduler = userScheduler;
// connect to network
if(!network->isConnected()){
// TODO when config is refactored, cast is not necessary anymore
static_cast<MeshNet*>(network)->config.stationMode = 1;
network->connectStation();
// TODO set service message to mesh to announce station IP
}
void connectUpdateNetwork(Network* network) {
// if(!network->isConnected()){
// static_cast<MeshNet*>(network)->config.stationMode = 1;
// }
network->connectStation();
}
void enable() {
ArduinoOTA.begin();
otaTask.enable();
}
void onMessage(MeshMessage msg) {
//enable();
Serial.println("OTA msg received");
}
void setup(Scheduler* userScheduler, Network* network){
// connect done in network class
//connectUpdateNetwork(network);
// setup task
scheduler = userScheduler;
otaTask.set(TASK_MILLISECOND * 100, TASK_FOREVER, [](){
ArduinoOTA.handle();
});
@@ -62,8 +72,7 @@ class OtaTcpPlugin : public Plugin {
else if (error == OTA_RECEIVE_ERROR) Serial.println("OTA: Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("OTA: End Failed");
});
ArduinoOTA.begin();
otaTask.enable();
enable();
}
void disable(){
otaTask.disable();