interface.h (1243B)
1 #pragma once 2 3 #include <Arduino_JSON.h> 4 5 6 typedef JSONVar json; 7 8 extern json null_response; 9 10 struct interface { 11 enum method { 12 METHOD_GET, 13 METHOD_POST 14 }; 15 16 enum command_status { 17 STATUS_OK = 0, // command succeed 18 STATUS_ERROR = 1, // command returned an error 19 STATUS_TIMEOUT = 2, // command timed out 20 STATUS_NOT_READY = 3, // interface is not ready 21 }; 22 23 enum command_flags { 24 COMMAND_NONE, // none of them underneath 25 COMMAND_FORCE = 1 << 0, // ignore modemReady/remoteReady 26 COMMAND_BLOCK = 1 << 1, // no time-out (for waiting commands) 27 COMMAND_IGNORE = 1 << 2, // don't wait for response, just wait $ignoreDelay secounds 28 }; 29 30 protected: 31 bool remoteReady = false; 32 bool modemReady = false; 33 34 void beginModem(); 35 36 void beginRemote(); 37 void endRemote(); 38 39 public: 40 char token[17]; 41 42 json request, response; 43 44 void begin(); 45 46 int send(method method, const char* endpoint); 47 48 void sendToken(); 49 50 command_status remote(const char* command, json params = nullptr, json& response = null_response, command_flags flags = COMMAND_NONE); 51 52 command_status modem(const char* request, char* response, command_flags flags = COMMAND_NONE); 53 command_status modem(const char* request, command_flags flags = COMMAND_NONE); 54 };