an old afLib which supports both SPI and UART
Command.h@1:112741fe45d1, 2018-04-23 (annotated)
- Committer:
- Rhyme
- Date:
- Mon Apr 23 06:15:05 2018 +0000
- Revision:
- 1:112741fe45d1
- Parent:
- 0:6f371c791202
afLib1.3 first mbed version with working UART
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Rhyme | 0:6f371c791202 | 1 | /** |
| Rhyme | 0:6f371c791202 | 2 | * Copyright 2015 Afero, Inc. |
| Rhyme | 0:6f371c791202 | 3 | * |
| Rhyme | 0:6f371c791202 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| Rhyme | 0:6f371c791202 | 5 | * you may not use this file except in compliance with the License. |
| Rhyme | 0:6f371c791202 | 6 | * You may obtain a copy of the License at |
| Rhyme | 0:6f371c791202 | 7 | * |
| Rhyme | 0:6f371c791202 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Rhyme | 0:6f371c791202 | 9 | * |
| Rhyme | 0:6f371c791202 | 10 | * Unless required by applicable law or agreed to in writing, software |
| Rhyme | 0:6f371c791202 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| Rhyme | 0:6f371c791202 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| Rhyme | 0:6f371c791202 | 13 | * See the License for the specific language governing permissions and |
| Rhyme | 0:6f371c791202 | 14 | * limitations under the License. |
| Rhyme | 0:6f371c791202 | 15 | */ |
| Rhyme | 0:6f371c791202 | 16 | |
| Rhyme | 0:6f371c791202 | 17 | #ifndef COMMAND_H__ |
| Rhyme | 0:6f371c791202 | 18 | #define COMMAND_H__ |
| Rhyme | 0:6f371c791202 | 19 | |
| Rhyme | 0:6f371c791202 | 20 | #include "mbed.h" |
| Rhyme | 0:6f371c791202 | 21 | #define Stream Serial |
| Rhyme | 0:6f371c791202 | 22 | |
| Rhyme | 0:6f371c791202 | 23 | #include "msg_types.h" |
| Rhyme | 0:6f371c791202 | 24 | |
| Rhyme | 0:6f371c791202 | 25 | #define SPI_CMD_MAX_LEN 256 |
| Rhyme | 0:6f371c791202 | 26 | |
| Rhyme | 0:6f371c791202 | 27 | class Command { |
| Rhyme | 0:6f371c791202 | 28 | public: |
| Rhyme | 0:6f371c791202 | 29 | Command(Stream *,uint16_t len, uint8_t *bytes); |
| Rhyme | 0:6f371c791202 | 30 | |
| Rhyme | 0:6f371c791202 | 31 | Command(Stream *,uint8_t requestId, const char *str); |
| Rhyme | 0:6f371c791202 | 32 | |
| Rhyme | 0:6f371c791202 | 33 | Command(Stream *,uint8_t requestId, uint8_t cmd, uint16_t attrId); |
| Rhyme | 0:6f371c791202 | 34 | |
| Rhyme | 0:6f371c791202 | 35 | Command(Stream *,uint8_t requestId, uint8_t cmd, uint16_t attrId, uint16_t valueLen, uint8_t *value); |
| Rhyme | 0:6f371c791202 | 36 | |
| Rhyme | 0:6f371c791202 | 37 | Command(Stream *,uint8_t requestId, uint8_t cmd, uint16_t attrId, uint8_t status, uint8_t reason, uint16_t valueLen, |
| Rhyme | 0:6f371c791202 | 38 | uint8_t *value); |
| Rhyme | 0:6f371c791202 | 39 | |
| Rhyme | 0:6f371c791202 | 40 | Command(Stream *); |
| Rhyme | 0:6f371c791202 | 41 | |
| Rhyme | 0:6f371c791202 | 42 | ~Command(); |
| Rhyme | 0:6f371c791202 | 43 | |
| Rhyme | 0:6f371c791202 | 44 | uint8_t getCommand(); |
| Rhyme | 0:6f371c791202 | 45 | |
| Rhyme | 0:6f371c791202 | 46 | uint8_t getReqId(); |
| Rhyme | 0:6f371c791202 | 47 | |
| Rhyme | 0:6f371c791202 | 48 | uint16_t getAttrId(); |
| Rhyme | 0:6f371c791202 | 49 | |
| Rhyme | 0:6f371c791202 | 50 | uint16_t getValueLen(); |
| Rhyme | 0:6f371c791202 | 51 | |
| Rhyme | 0:6f371c791202 | 52 | void getValue(uint8_t *value); |
| Rhyme | 0:6f371c791202 | 53 | |
| Rhyme | 0:6f371c791202 | 54 | uint8_t *getValueP(); |
| Rhyme | 0:6f371c791202 | 55 | |
| Rhyme | 0:6f371c791202 | 56 | uint16_t getSize(); |
| Rhyme | 0:6f371c791202 | 57 | |
| Rhyme | 0:6f371c791202 | 58 | uint16_t getBytes(uint8_t *bytes); |
| Rhyme | 0:6f371c791202 | 59 | |
| Rhyme | 0:6f371c791202 | 60 | uint8_t getReason(); |
| Rhyme | 0:6f371c791202 | 61 | |
| Rhyme | 0:6f371c791202 | 62 | bool isValid(); |
| Rhyme | 0:6f371c791202 | 63 | |
| Rhyme | 0:6f371c791202 | 64 | void dump(); |
| Rhyme | 0:6f371c791202 | 65 | |
| Rhyme | 0:6f371c791202 | 66 | void dumpBytes(); |
| Rhyme | 0:6f371c791202 | 67 | |
| Rhyme | 0:6f371c791202 | 68 | private: |
| Rhyme | 0:6f371c791202 | 69 | uint8_t getVal(char c); |
| Rhyme | 0:6f371c791202 | 70 | int strToValue(char *valueStr, uint8_t *value); |
| Rhyme | 0:6f371c791202 | 71 | |
| Rhyme | 0:6f371c791202 | 72 | uint8_t strToCmd(char *cmdStr); |
| Rhyme | 0:6f371c791202 | 73 | |
| Rhyme | 0:6f371c791202 | 74 | uint16_t strToAttrId(char *attrIdStr); |
| Rhyme | 0:6f371c791202 | 75 | |
| Rhyme | 0:6f371c791202 | 76 | Serial *_serial ; /* Stream *_serial; // Arduino */ |
| Rhyme | 0:6f371c791202 | 77 | |
| Rhyme | 0:6f371c791202 | 78 | uint16_t _len; |
| Rhyme | 0:6f371c791202 | 79 | uint8_t _cmd; |
| Rhyme | 0:6f371c791202 | 80 | uint8_t _requestId; |
| Rhyme | 0:6f371c791202 | 81 | uint16_t _attrId; |
| Rhyme | 0:6f371c791202 | 82 | uint8_t _status; |
| Rhyme | 0:6f371c791202 | 83 | uint8_t _reason; |
| Rhyme | 0:6f371c791202 | 84 | uint16_t _valueLen; |
| Rhyme | 0:6f371c791202 | 85 | uint8_t *_value; |
| Rhyme | 0:6f371c791202 | 86 | |
| Rhyme | 0:6f371c791202 | 87 | char _printBuf[256]; |
| Rhyme | 0:6f371c791202 | 88 | |
| Rhyme | 0:6f371c791202 | 89 | }; |
| Rhyme | 0:6f371c791202 | 90 | |
| Rhyme | 0:6f371c791202 | 91 | #endif // COMMAND_H__ |
| Rhyme | 0:6f371c791202 | 92 |