39void ELClientSocket::socketCallback(
void *res)
46 int argNum = resp->
argc();
47 Serial.println(
"Number of arguments: "+String(argNum));
48 uint16_t _cmd = resp->
cmd();
49 Serial.println(
"Command: "+String(_cmd));
50 uint16_t _value = resp->
value();
51 Serial.println(
"Value: "+String(_value));
54 resp->
popArg(&_resp_type, 1);
55 resp->
popArg(&_client_num, 1);
62 Serial.print(
" size: "+String(_len));
67 int argLen = resp->
argLen();
68 Serial.print(
" data length: "+String(argLen));
73 Serial.print(
" data: "+String(_data));
82 _userCb(_resp_type, _client_num, _len, _data);
121int ELClientSocket::begin(
const char* host, uint16_t port, uint8_t sock_mode,
void (*userCb)(uint8_t resp_type, uint8_t client_num, uint16_t len,
char *data))
129 socketCb.
attach(
this, &ELClientSocket::socketCallback);
132 _elc->
Request(host, strlen(host));
139 if (pkt && (int32_t)pkt->
value >= 0)
144 return (
int)pkt->
value;
165 _elc->
Request(data, strlen(data));
166 if (data != NULL && len > 0)
186 send(data, strlen(data));
238 if (_status == 0)
return 0;
239 memcpy(data, _data, _len>maxLen?maxLen:_len);
240 *resp_type = _resp_type;
241 *client_num = _client_num;
308 uint32_t
wait = millis();
309 while (_status == 0) {
310 if ( millis() -
wait < timeout)
317 return getResponse(resp_type, client_num, data, maxLen);
Definitions for ELClientSocket.
int16_t popArg(void *data, uint16_t maxLen)
Extract an argument from the response packet.
int16_t popArgPtr(void **data)
Extract pointer to an argument from the response packet.
uint16_t getResponse(uint8_t *resp_type, uint8_t *client_num, char *data, uint16_t maxLen)
Retrieve response.
void send(const char *data)
Send null-terminated data to the remote server.
uint16_t waitResponse(uint8_t *resp_type, uint8_t *client_num, char *data, uint16_t maxLen, uint32_t timeout=DEFAULT_SOCKET_TIMEOUT)
Wait for the response.
int begin(const char *host, uint16_t port, uint8_t sock_mode, void(*userCb)(uint8_t resp_type, uint8_t client_num, uint16_t len, char *data)=0)
Initialize communication to a remote server.
ELClientSocket(ELClient *e)
Class to send/receive data.
ELClientPacket * Process(void)
Handle serial input.
void Request(uint16_t cmd, uint32_t value, uint16_t argc)
Start a request.
ELClientPacket * WaitReturn(uint32_t timeout=ESP_TIMEOUT)
Wait for a response from ESP for a given timeout.
void attach(T *item, retT(T::*method)(argT))