an old afLib which supports both SPI and UART
Embed:
(wiki syntax)
Show/hide line numbers
Command.h
00001 /** 00002 * Copyright 2015 Afero, Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef COMMAND_H__ 00018 #define COMMAND_H__ 00019 00020 #include "mbed.h" 00021 #define Stream Serial 00022 00023 #include "msg_types.h" 00024 00025 #define SPI_CMD_MAX_LEN 256 00026 00027 class Command { 00028 public: 00029 Command(Stream *,uint16_t len, uint8_t *bytes); 00030 00031 Command(Stream *,uint8_t requestId, const char *str); 00032 00033 Command(Stream *,uint8_t requestId, uint8_t cmd, uint16_t attrId); 00034 00035 Command(Stream *,uint8_t requestId, uint8_t cmd, uint16_t attrId, uint16_t valueLen, uint8_t *value); 00036 00037 Command(Stream *,uint8_t requestId, uint8_t cmd, uint16_t attrId, uint8_t status, uint8_t reason, uint16_t valueLen, 00038 uint8_t *value); 00039 00040 Command(Stream *); 00041 00042 ~Command(); 00043 00044 uint8_t getCommand(); 00045 00046 uint8_t getReqId(); 00047 00048 uint16_t getAttrId(); 00049 00050 uint16_t getValueLen(); 00051 00052 void getValue(uint8_t *value); 00053 00054 uint8_t *getValueP(); 00055 00056 uint16_t getSize(); 00057 00058 uint16_t getBytes(uint8_t *bytes); 00059 00060 uint8_t getReason(); 00061 00062 bool isValid(); 00063 00064 void dump(); 00065 00066 void dumpBytes(); 00067 00068 private: 00069 uint8_t getVal(char c); 00070 int strToValue(char *valueStr, uint8_t *value); 00071 00072 uint8_t strToCmd(char *cmdStr); 00073 00074 uint16_t strToAttrId(char *attrIdStr); 00075 00076 Serial *_serial ; /* Stream *_serial; // Arduino */ 00077 00078 uint16_t _len; 00079 uint8_t _cmd; 00080 uint8_t _requestId; 00081 uint16_t _attrId; 00082 uint8_t _status; 00083 uint8_t _reason; 00084 uint16_t _valueLen; 00085 uint8_t *_value; 00086 00087 char _printBuf[256]; 00088 00089 }; 00090 00091 #endif // COMMAND_H__ 00092
Generated on Wed Jul 13 2022 19:00:06 by
1.7.2