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