This is a SLIP interface for the STM32F446RE Nucleo Board. It is designed to work specifically with the esp-link software for the ESP8266. The program is an example of a rest command.
STMClientResponse.h@0:70a6082c1bf7, 2016-07-14 (annotated)
- Committer:
- ShaneKirkbride
- Date:
- Thu Jul 14 20:38:18 2016 +0000
- Revision:
- 0:70a6082c1bf7
first commit. Rest example working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ShaneKirkbride | 0:70a6082c1bf7 | 1 | #ifndef _STM_CLIENT_RESPONSE_H_ |
ShaneKirkbride | 0:70a6082c1bf7 | 2 | #define _STM_CLIENT_RESPONSE_H_ |
ShaneKirkbride | 0:70a6082c1bf7 | 3 | |
ShaneKirkbride | 0:70a6082c1bf7 | 4 | #if _MSC_VER |
ShaneKirkbride | 0:70a6082c1bf7 | 5 | #define PACKED |
ShaneKirkbride | 0:70a6082c1bf7 | 6 | #else |
ShaneKirkbride | 0:70a6082c1bf7 | 7 | #define PACKED __attribute__ ((__packed__)) |
ShaneKirkbride | 0:70a6082c1bf7 | 8 | #endif |
ShaneKirkbride | 0:70a6082c1bf7 | 9 | |
ShaneKirkbride | 0:70a6082c1bf7 | 10 | #include <mbed.h> |
ShaneKirkbride | 0:70a6082c1bf7 | 11 | #include <string> |
ShaneKirkbride | 0:70a6082c1bf7 | 12 | |
ShaneKirkbride | 0:70a6082c1bf7 | 13 | typedef struct PACKED { |
ShaneKirkbride | 0:70a6082c1bf7 | 14 | uint16_t cmd; // command to execute |
ShaneKirkbride | 0:70a6082c1bf7 | 15 | uint16_t argc; // number of arguments |
ShaneKirkbride | 0:70a6082c1bf7 | 16 | uint32_t value; // callback to invoke, NULL if none; or response value |
ShaneKirkbride | 0:70a6082c1bf7 | 17 | uint8_t args[0]; |
ShaneKirkbride | 0:70a6082c1bf7 | 18 | } STMClientPacket; |
ShaneKirkbride | 0:70a6082c1bf7 | 19 | |
ShaneKirkbride | 0:70a6082c1bf7 | 20 | class STMClientResponse { |
ShaneKirkbride | 0:70a6082c1bf7 | 21 | public: |
ShaneKirkbride | 0:70a6082c1bf7 | 22 | // Create a response from a packet, this is done internally in STMClient |
ShaneKirkbride | 0:70a6082c1bf7 | 23 | STMClientResponse(STMClientPacket* packet); |
ShaneKirkbride | 0:70a6082c1bf7 | 24 | STMClientResponse(void *packet); |
ShaneKirkbride | 0:70a6082c1bf7 | 25 | |
ShaneKirkbride | 0:70a6082c1bf7 | 26 | // Accessors to the response fields |
ShaneKirkbride | 0:70a6082c1bf7 | 27 | uint16_t argc() { return _cmd->argc; } |
ShaneKirkbride | 0:70a6082c1bf7 | 28 | uint16_t cmd() { return _cmd->cmd; } |
ShaneKirkbride | 0:70a6082c1bf7 | 29 | uint32_t value() { return _cmd->value; } |
ShaneKirkbride | 0:70a6082c1bf7 | 30 | |
ShaneKirkbride | 0:70a6082c1bf7 | 31 | // Return the length of the next argument |
ShaneKirkbride | 0:70a6082c1bf7 | 32 | uint16_t argLen() { return *(uint16_t*)_arg_ptr; } |
ShaneKirkbride | 0:70a6082c1bf7 | 33 | // Pop one argument from the response, returns the actual length. Returns -1 if there is |
ShaneKirkbride | 0:70a6082c1bf7 | 34 | // no arg left. |
ShaneKirkbride | 0:70a6082c1bf7 | 35 | int16_t popArg(void* data, uint16_t maxLen); |
ShaneKirkbride | 0:70a6082c1bf7 | 36 | // Pop one argument as a poiner from the response, returns the actual length. |
ShaneKirkbride | 0:70a6082c1bf7 | 37 | int16_t popArgPtr(void **data); |
ShaneKirkbride | 0:70a6082c1bf7 | 38 | // Pop one argument into a string buffer and append a null character. The buffer needs to |
ShaneKirkbride | 0:70a6082c1bf7 | 39 | // be large enough (argLen()+1) |
ShaneKirkbride | 0:70a6082c1bf7 | 40 | void popChar(char* buffer); |
ShaneKirkbride | 0:70a6082c1bf7 | 41 | // Pop one argument into a String buffer |
ShaneKirkbride | 0:70a6082c1bf7 | 42 | string popString(); |
ShaneKirkbride | 0:70a6082c1bf7 | 43 | // Pop one argument into a String buffer |
ShaneKirkbride | 0:70a6082c1bf7 | 44 | void popString(string* data); |
ShaneKirkbride | 0:70a6082c1bf7 | 45 | |
ShaneKirkbride | 0:70a6082c1bf7 | 46 | private: |
ShaneKirkbride | 0:70a6082c1bf7 | 47 | uint16_t _arg_num; |
ShaneKirkbride | 0:70a6082c1bf7 | 48 | uint8_t* _arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 49 | STMClientPacket* _cmd; |
ShaneKirkbride | 0:70a6082c1bf7 | 50 | }; |
ShaneKirkbride | 0:70a6082c1bf7 | 51 | |
ShaneKirkbride | 0:70a6082c1bf7 | 52 | #endif // _STM_CLIENT_RESPONSE_H_ |