#pragma once #include "server.h" #include "servo.h" #include "message.h" #include "storage.h" #include class SesameController: public ServerConnectionCallbacks { public: SesameController(ServerConnection* server, ServoController* servo, AsyncWebServer* local, uint8_t remoteDeviceCount); void configure(); private: ServerConnection* server; ServoController* servo; AsyncWebServer* local; Storage storage; // The buffer to hold a received message while it is read uint8_t receivedMessageBuffer[AUTHENTICATED_MESSAGE_SIZE]; // The buffer to hold a response while it is sent uint8_t responseBuffer[AUTHENTICATED_MESSAGE_SIZE+1]; SesameEvent* responseStatus; AuthenticatedMessage* responseMessage; uint16_t responseSize = 0; void handleLocalMessage(AsyncWebServerRequest *request); // Based on https://stackoverflow.com/a/23898449/266720 bool convertHexMessageToBinary(const char* str); void handleServerMessage(uint8_t* payload, size_t length); void sendServerError(SesameEvent event); void processMessage(AuthenticatedMessage* message); SesameEvent verifyAndProcessReceivedMessage(AuthenticatedMessage* message); uint16_t prepareResponseBuffer(SesameEvent event, uint8_t deviceId = 0); void sendPreparedLocalResponse(AsyncWebServerRequest *request); void sendPreparedServerResponse(); };