The BERG Cloud connection library for mbed. This works in conjunction with the BERG Cloud Devshield available via http://bergcloud.com/platform/devkit/
Dependents: LittleCounter-Example
BERGCloudBase.h
00001 /* 00002 00003 BERGCloud library common API 00004 00005 Copyright (c) 2013 BERG Cloud Ltd. http://bergcloud.com/ 00006 00007 Permission is hereby granted, free of charge, to any person obtaining a copy 00008 of this software and associated documentation files (the "Software"), to deal 00009 in the Software without restriction, including without limitation the rights 00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 copies of the Software, and to permit persons to whom the Software is 00012 furnished to do so, subject to the following conditions: 00013 00014 The above copyright notice and this permission notice shall be included in 00015 all copies or substantial portions of the Software. 00016 00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 THE SOFTWARE. 00024 00025 */ 00026 00027 00028 #ifndef BERGCLOUDBASE_H 00029 #define BERGCLOUDBASE_H 00030 00031 #include "BERGCloudConfig.h" 00032 #include "BERGCloudConst.h" 00033 #include "BERGCloudLogPrint.h" 00034 00035 #ifdef BERGCLOUD_PACK_UNPACK 00036 #include "BERGCloudMessageBuffer.h" 00037 #endif 00038 00039 #define BERGCLOUD_LIB_VERSION (0x0200) 00040 00041 #define _TX_GROUPS (2) 00042 #define _RX_GROUPS (2) 00043 00044 typedef struct { 00045 uint8_t *buffer; 00046 uint16_t dataSize; 00047 } _BC_TX_GROUP; 00048 00049 typedef struct { 00050 uint8_t *buffer; 00051 uint16_t bufferSize; 00052 uint16_t *dataSize; 00053 } _BC_RX_GROUP; 00054 00055 typedef struct { 00056 uint8_t command; 00057 _BC_TX_GROUP tx[_TX_GROUPS]; 00058 _BC_RX_GROUP rx[_RX_GROUPS]; 00059 } _BC_SPI_TRANSACTION; 00060 00061 class BERGCloudBase 00062 { 00063 public: 00064 /* Check for a command */ 00065 bool pollForCommand(uint8_t *commandBuffer, uint16_t commandBufferSize, uint16_t& commandSize, uint8_t& commandID); 00066 bool pollForCommand(uint8_t *commandBuffer, uint16_t commandBufferSize, uint16_t& commandSize, char *commandName, uint8_t commandNameMaxSize); 00067 #ifdef BERGCLOUD_PACK_UNPACK 00068 bool pollForCommand(BERGCloudMessageBuffer& buffer, uint8_t& commandID); 00069 bool pollForCommand(BERGCloudMessageBuffer& buffer, char *commandName, uint8_t commandNameMaxSize); 00070 #endif 00071 /* Send an event */ 00072 bool sendEvent(uint8_t eventCode, uint8_t *eventBuffer, uint16_t eventSize, bool packed = true); 00073 bool sendEvent(const char *eventName, uint8_t *eventBuffer, uint16_t eventSize, bool packed = true); 00074 #ifdef BERGCLOUD_PACK_UNPACK 00075 bool sendEvent(uint8_t eventCode, BERGCloudMessageBuffer& buffer); 00076 bool sendEvent(const char *eventName, BERGCloudMessageBuffer& buffer); 00077 #endif 00078 /* Get the connection state */ 00079 bool getConnectionState(uint8_t& state); 00080 /* Get the last-hop signal quality */ 00081 bool getSignalQuality(int8_t& rssi, uint8_t& lqi); 00082 /* Connect */ 00083 virtual bool connect(const uint8_t (&key)[BC_KEY_SIZE_BYTES] = nullKey, uint16_t version = 0, bool waitForConnected = false); 00084 virtual bool connect(const char *key = NULL, uint16_t version = 0, bool waitForConnected = false); 00085 /* Check if the device has been claimed */ 00086 bool getClaimingState(uint8_t& state); 00087 /* Get the current claimcode */ 00088 virtual bool getClaimcode(const char (&claimcode)[BC_CLAIMCODE_SIZE_BYTES]); 00089 /* Get the EUI64 identifier for this node, its parent or the network coordinator */ 00090 virtual bool getEUI64(uint8_t type, uint8_t (&eui64)[BC_EUI64_SIZE_BYTES]); 00091 /* Get the Device Address */ 00092 virtual bool getDeviceAddress(uint8_t (&address)[BC_ADDRESS_SIZE_BYTES]); 00093 /* Set the display style for the OLED display. This also clears the display. */ 00094 bool setDisplayStyle(uint8_t style); 00095 /* Clear the OLED display */ 00096 bool clearDisplay(void); 00097 /* Display a line of text on the OLED display */ 00098 bool display(const char *text); 00099 00100 /* Internal methods */ 00101 public: 00102 uint8_t lastResponse; 00103 static uint8_t nullKey[BC_KEY_SIZE_BYTES]; 00104 protected: 00105 void begin(void); 00106 void end(void); 00107 uint16_t Crc16(uint8_t data, uint16_t crc); 00108 virtual uint16_t SPITransaction(uint8_t *dataOut, uint8_t *dataIn, uint16_t dataSize, bool finalCS) = 0; 00109 virtual void timerReset(void) = 0; 00110 virtual uint32_t timerRead_mS(void) = 0; 00111 virtual uint16_t getHostType(void) = 0; 00112 private: 00113 uint8_t SPITransaction(uint8_t data, bool finalCS); 00114 void initTransaction(_BC_SPI_TRANSACTION *tr); 00115 bool _transaction(_BC_SPI_TRANSACTION *tr); 00116 bool transaction(_BC_SPI_TRANSACTION *tr); 00117 bool _sendEvent(uint8_t eventCode, uint8_t *eventBuffer, uint16_t eventSize, uint8_t command); 00118 void bytecpy(uint8_t *dst, uint8_t *src, uint16_t size); 00119 void lockTake(void); 00120 void lockRelease(void); 00121 bool synced; 00122 }; 00123 00124 #endif // #ifndef BERGCLOUDBASE_H 00125
Generated on Sun Jul 17 2022 20:45:26 by
1.7.2
BERG Cloud


