Gbox 4.20
Grow box automation and monitoring - <a href='https://sites.google.com/site/growboxguy/'>https://sites.google.com/site/growboxguy/</a>
 
Loading...
Searching...
No Matches
ELClientResponse.h
Go to the documentation of this file.
1
4#ifndef _EL_CLIENT_RESPONSE_H_
5#define _EL_CLIENT_RESPONSE_H_
6
7#if _MSC_VER
8#define PACKED
9#else
10#define PACKED __attribute__ ((__packed__))
11#endif
12
13#include <Arduino.h>
14
15#define VARIABLE_ARG_NUM 255
16
17typedef struct PACKED {
18 uint16_t cmd;
19 uint16_t argc;
20 uint32_t value;
21 uint8_t args[0];
24// ELClientResponse is a parser for responses. The constructor initializes the parser based on
25// a packet and the various pop functions consume one response argument at a time.
27 public:
28 // Create a response from a packet, this is done internally in ELClient
30 ELClientResponse(void *packet);
31
32 // Accessors to the response fields
33 uint16_t argc() { return _cmd->argc; }
34 uint16_t cmd() { return _cmd->cmd; }
35 uint32_t value() { return _cmd->value; }
37 // Return the length of the next argument
38 uint16_t argLen() { return *(uint16_t*)_arg_ptr; }
39 // Pop one argument from the response, returns the actual length. Returns -1 if there is
40 // no arg left.
41 int16_t popArg(void* data, uint16_t maxLen);
42 // Pop one argument as a poiner from the response, returns the actual length.
43 int16_t popArgPtr(void **data);
44 // Pop one argument into a string buffer and append a null character. The buffer needs to
45 // be large enough (argLen()+1)
46 void popChar(char* buffer);
47 // Pop one argument into a String buffer
48 String popString();
49 // Pop one argument into a String buffer
50 void popString(String* data);
51
52 private:
53 uint16_t _arg_num;
54 uint8_t* _arg_ptr;
55 ELClientPacket* _cmd;
56};
57
58#endif // _EL_CLIENT_RESPONSE_H_
struct PACKED ELClientPacket
void popChar(char *buffer)
Extract a character from the response packet.
String popString()
Extract a string from the response packet.
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 cmd
uint16_t argc
uint8_t args[0]
uint32_t value