dedicated reponse and error handling for each board
This commit is contained in:
parent
638f6b5939
commit
6a2450d94f
@ -26,4 +26,10 @@ namespace Board {
|
|||||||
void loop() {
|
void loop() {
|
||||||
ts.execute();
|
ts.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void publishResponse(JsonDocument& jsonDoc) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleJsonError(JsonDocument& jsonError) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include <SerialReader.h>
|
#include <SerialReader.h>
|
||||||
|
#include "output.h"
|
||||||
|
|
||||||
#define RESET_PIN 10
|
#define RESET_PIN 10
|
||||||
#define SEND_PIN 11
|
#define SEND_PIN 11
|
||||||
@ -10,6 +11,7 @@ namespace Board {
|
|||||||
void setup() {
|
void setup() {
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
|
Serial.begin(9600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void readCommand() {
|
void readCommand() {
|
||||||
@ -28,4 +30,14 @@ namespace Board {
|
|||||||
void loop() {
|
void loop() {
|
||||||
readCommand();
|
readCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void publishResponse(JsonDocument& jsonDoc) {
|
||||||
|
serializeJson(jsonDoc, Serial);
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleJsonError(JsonDocument& jsonError) {
|
||||||
|
serializeJson(jsonError, Serial);
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
#include "Dht.h"
|
#include "Dht.h"
|
||||||
#include "Protocol_1.h"
|
#include "Protocol_1.h"
|
||||||
#include "Protocol_2.h"
|
#include "Protocol_2.h"
|
||||||
#include "output.h"
|
|
||||||
|
|
||||||
RCSwitch mySwitch;
|
RCSwitch mySwitch;
|
||||||
void runJsonCommand(char* cmd);
|
void runJsonCommand(char* cmd);
|
||||||
@ -16,8 +15,6 @@ void runJsonCommand(char* cmd);
|
|||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
|
||||||
|
|
||||||
mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN));
|
mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN));
|
||||||
mySwitch.enableTransmit(SEND_PIN);
|
mySwitch.enableTransmit(SEND_PIN);
|
||||||
mySwitch.setRepeatTransmit(10);
|
mySwitch.setRepeatTransmit(10);
|
||||||
@ -55,8 +52,7 @@ void readRcSwitch() {
|
|||||||
p->toJson(value, jsonDoc);
|
p->toJson(value, jsonDoc);
|
||||||
delete p;
|
delete p;
|
||||||
if (!jsonDoc.isNull()) {
|
if (!jsonDoc.isNull()) {
|
||||||
serializeJson(jsonDoc, Serial);
|
Board::publishResponse(jsonDoc);
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -67,8 +63,7 @@ void handleJsonError(DeserializationError err, const char* cmd) {
|
|||||||
JsonObject error = jsonError.createNestedObject("error");
|
JsonObject error = jsonError.createNestedObject("error");
|
||||||
error["msg"] = err.c_str();
|
error["msg"] = err.c_str();
|
||||||
error["orig_cmd"] = cmd;
|
error["orig_cmd"] = cmd;
|
||||||
serializeJson(jsonError, Serial);
|
Board::handleJsonError(jsonError);
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void runJsonCommand(char* cmd) {
|
void runJsonCommand(char* cmd) {
|
||||||
@ -80,8 +75,7 @@ void runJsonCommand(char* cmd) {
|
|||||||
Protocol* p = findProtocol(rcSwitch["protocol"]);
|
Protocol* p = findProtocol(rcSwitch["protocol"]);
|
||||||
p->fromJson(rcSwitch, mySwitch);
|
p->fromJson(rcSwitch, mySwitch);
|
||||||
delete p;
|
delete p;
|
||||||
serializeJson(jsonDoc, Serial);
|
Board::publishResponse(jsonDoc);
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleJsonError(err, cmd);
|
handleJsonError(err, cmd);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user