![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.cpp@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 | #include "STMClientResponse.h" |
ShaneKirkbride | 0:70a6082c1bf7 | 2 | |
ShaneKirkbride | 0:70a6082c1bf7 | 3 | STMClientResponse::STMClientResponse(STMClientPacket* packet) { |
ShaneKirkbride | 0:70a6082c1bf7 | 4 | _cmd = packet; |
ShaneKirkbride | 0:70a6082c1bf7 | 5 | _arg_ptr = _cmd->args; |
ShaneKirkbride | 0:70a6082c1bf7 | 6 | _arg_num = 0; |
ShaneKirkbride | 0:70a6082c1bf7 | 7 | } |
ShaneKirkbride | 0:70a6082c1bf7 | 8 | |
ShaneKirkbride | 0:70a6082c1bf7 | 9 | STMClientResponse::STMClientResponse(void* packet) { |
ShaneKirkbride | 0:70a6082c1bf7 | 10 | _cmd = (STMClientPacket *)packet; |
ShaneKirkbride | 0:70a6082c1bf7 | 11 | _arg_ptr = _cmd->args; |
ShaneKirkbride | 0:70a6082c1bf7 | 12 | _arg_num = 0; |
ShaneKirkbride | 0:70a6082c1bf7 | 13 | } |
ShaneKirkbride | 0:70a6082c1bf7 | 14 | |
ShaneKirkbride | 0:70a6082c1bf7 | 15 | int16_t STMClientResponse::popArgPtr(void **data) { |
ShaneKirkbride | 0:70a6082c1bf7 | 16 | if (_arg_num >= _cmd->argc) return -1; |
ShaneKirkbride | 0:70a6082c1bf7 | 17 | |
ShaneKirkbride | 0:70a6082c1bf7 | 18 | uint16_t len = *(uint16_t*)_arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 19 | uint16_t pad = (4-((len+2)&3))&3; // pad to next multiple of 4, including length |
ShaneKirkbride | 0:70a6082c1bf7 | 20 | _arg_ptr += 2; |
ShaneKirkbride | 0:70a6082c1bf7 | 21 | _arg_num++; |
ShaneKirkbride | 0:70a6082c1bf7 | 22 | |
ShaneKirkbride | 0:70a6082c1bf7 | 23 | *data = _arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 24 | _arg_ptr += len + pad; |
ShaneKirkbride | 0:70a6082c1bf7 | 25 | return len; |
ShaneKirkbride | 0:70a6082c1bf7 | 26 | } |
ShaneKirkbride | 0:70a6082c1bf7 | 27 | |
ShaneKirkbride | 0:70a6082c1bf7 | 28 | int16_t STMClientResponse::popArg(void* d, uint16_t maxLen) { |
ShaneKirkbride | 0:70a6082c1bf7 | 29 | if (_arg_num >= _cmd->argc) return -1; |
ShaneKirkbride | 0:70a6082c1bf7 | 30 | |
ShaneKirkbride | 0:70a6082c1bf7 | 31 | uint16_t len = *(uint16_t*)_arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 32 | uint16_t pad = (4-((len+2)&3))&3; // pad to next multiple of 4, including length |
ShaneKirkbride | 0:70a6082c1bf7 | 33 | _arg_ptr += 2; |
ShaneKirkbride | 0:70a6082c1bf7 | 34 | _arg_num++; |
ShaneKirkbride | 0:70a6082c1bf7 | 35 | |
ShaneKirkbride | 0:70a6082c1bf7 | 36 | uint8_t *data = (uint8_t *)d; |
ShaneKirkbride | 0:70a6082c1bf7 | 37 | uint16_t l = len > maxLen ? maxLen : len; |
ShaneKirkbride | 0:70a6082c1bf7 | 38 | uint8_t *p = _arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 39 | while (l--) |
ShaneKirkbride | 0:70a6082c1bf7 | 40 | *data++ = *p++; |
ShaneKirkbride | 0:70a6082c1bf7 | 41 | |
ShaneKirkbride | 0:70a6082c1bf7 | 42 | _arg_ptr += len + pad; |
ShaneKirkbride | 0:70a6082c1bf7 | 43 | return len; |
ShaneKirkbride | 0:70a6082c1bf7 | 44 | } |
ShaneKirkbride | 0:70a6082c1bf7 | 45 | |
ShaneKirkbride | 0:70a6082c1bf7 | 46 | void STMClientResponse::popChar(char* buffer) { |
ShaneKirkbride | 0:70a6082c1bf7 | 47 | uint16_t len = *(uint16_t*)_arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 48 | uint16_t pad = (4-((len+2)&3))&3; // pad to next multiple of 4, including length |
ShaneKirkbride | 0:70a6082c1bf7 | 49 | _arg_ptr += 2; |
ShaneKirkbride | 0:70a6082c1bf7 | 50 | _arg_num++; |
ShaneKirkbride | 0:70a6082c1bf7 | 51 | |
ShaneKirkbride | 0:70a6082c1bf7 | 52 | uint8_t i; |
ShaneKirkbride | 0:70a6082c1bf7 | 53 | for (i = 0; i < len; i++) { |
ShaneKirkbride | 0:70a6082c1bf7 | 54 | buffer[i] = (char)*_arg_ptr++; |
ShaneKirkbride | 0:70a6082c1bf7 | 55 | } |
ShaneKirkbride | 0:70a6082c1bf7 | 56 | buffer[i] = '\0'; |
ShaneKirkbride | 0:70a6082c1bf7 | 57 | |
ShaneKirkbride | 0:70a6082c1bf7 | 58 | _arg_ptr += pad; |
ShaneKirkbride | 0:70a6082c1bf7 | 59 | } |
ShaneKirkbride | 0:70a6082c1bf7 | 60 | |
ShaneKirkbride | 0:70a6082c1bf7 | 61 | string STMClientResponse::popString() { |
ShaneKirkbride | 0:70a6082c1bf7 | 62 | string ret; |
ShaneKirkbride | 0:70a6082c1bf7 | 63 | uint16_t len = *(uint16_t*)_arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 64 | uint16_t pad = (4-((len+2)&3))&3; // pad to next multiple of 4, including length |
ShaneKirkbride | 0:70a6082c1bf7 | 65 | _arg_ptr += 2; |
ShaneKirkbride | 0:70a6082c1bf7 | 66 | _arg_num++; |
ShaneKirkbride | 0:70a6082c1bf7 | 67 | |
ShaneKirkbride | 0:70a6082c1bf7 | 68 | while (len--) |
ShaneKirkbride | 0:70a6082c1bf7 | 69 | ret += (char)*_arg_ptr++; |
ShaneKirkbride | 0:70a6082c1bf7 | 70 | |
ShaneKirkbride | 0:70a6082c1bf7 | 71 | _arg_ptr += pad; |
ShaneKirkbride | 0:70a6082c1bf7 | 72 | return ret; |
ShaneKirkbride | 0:70a6082c1bf7 | 73 | } |
ShaneKirkbride | 0:70a6082c1bf7 | 74 | |
ShaneKirkbride | 0:70a6082c1bf7 | 75 | void STMClientResponse::popString(string* data) { |
ShaneKirkbride | 0:70a6082c1bf7 | 76 | uint16_t len = *(uint16_t*)_arg_ptr; |
ShaneKirkbride | 0:70a6082c1bf7 | 77 | uint16_t pad = (4-((len+2)&3))&3; // pad to next multiple of 4, including length |
ShaneKirkbride | 0:70a6082c1bf7 | 78 | _arg_ptr += 2; |
ShaneKirkbride | 0:70a6082c1bf7 | 79 | _arg_num++; |
ShaneKirkbride | 0:70a6082c1bf7 | 80 | |
ShaneKirkbride | 0:70a6082c1bf7 | 81 | while (len--) |
ShaneKirkbride | 0:70a6082c1bf7 | 82 | //string.append((char)*_arg_ptr++); |
ShaneKirkbride | 0:70a6082c1bf7 | 83 | //strcat (data,(char)*_arg_ptr++); |
ShaneKirkbride | 0:70a6082c1bf7 | 84 | data += (char)*_arg_ptr++; |
ShaneKirkbride | 0:70a6082c1bf7 | 85 | |
ShaneKirkbride | 0:70a6082c1bf7 | 86 | _arg_ptr += pad; |
ShaneKirkbride | 0:70a6082c1bf7 | 87 | } |