Library for Bluetooth Low Energy Module ble 4.0 HM-11

Revision:
3:d32bdfd04d82
Parent:
1:abf1462d47a0
Child:
4:65cc8bd09b18
--- a/hm11.h	Sun Nov 01 21:35:35 2015 +0000
+++ b/hm11.h	Mon Nov 23 00:18:45 2015 +0000
@@ -40,6 +40,7 @@
 
 
 //DEMO - HOW TO USE:
+//compiled and built under mbed
 /*
 ---------------------------------------- DEMO: 1st version -simple polling ----------------------------------------
 #include "mbed.h"
@@ -206,6 +207,51 @@
 }ConnectionStatus_t;
 
 
+typedef struct ScanResult{
+    char* addr;
+    char*name;
+    uint8_t nr; //0-5
+}ScanResult_t;
+
+
+typedef enum DeployMode{
+    _BROAD_AND_SCAN=1, //Allowed to broadcast and scanning
+    _ONLY_BROAD,      //Only allow broadcast 
+    _INVALID_DEPLOY_MODE
+}DeployMode_t; 
+
+
+typedef enum FilterOfHmModules{
+    _ALL_BLE_MODULES=0, //Will find all BLE modules 
+    _ONLY_HM_MODULES, //Only find HM Modules 
+    _INVALID_FILTER
+}FilterOfHmModules_t;
+
+
+typedef enum ModuleWorkType{
+    _WAIT_UNTIL_AT_START_RECEIVED=0, //Will find all BLE modules 
+    _WORK_IMMEDIATELY, //Only find HM Modules 
+    _INVALID_MODULE_WORK_TYPE
+}ModuleWorkType_t;
+
+
+typedef enum ModuleWorkMode{
+    _TRANSM_MODE=0, 
+    _PIO_COLLECTION_MODE,  
+    _REMOTE_CONTROL_MODE
+}ModuleWorkMode_t;
+
+
+
+
+typedef enum ParityBit{
+    _NONE=0, 
+    _EVEN,  
+    _ODD
+}ParityBit_t;
+
+
+
 class HM11{
     
 public:    
@@ -219,6 +265,7 @@
     bool isCorrectCommand(const char* command, HM11CommandType cmdType);
     
     int sendDataToDevice(const char* data);
+    int sendDataToDevice(uint8_t * byteData,uint8_t dataLength);
     
     int isRxDataAvailable();
     
@@ -435,7 +482,325 @@
     ConnectionStatus_t connectToAnAddress(const char* address); 
     
     
+    /**Query PIO04~PIO11 input(output) state 
+     * @return
+     *  in/out state: 0x00~0xFF 
+     * 
+     * This command is added since V515 version. 
+    */   
+    uint8_t queryInputOutputState(void); 
     
+    
+    /**Set PIO collection rate 
+     * @param colRateSec (PIO collection rate): 00-99 unit[s]
+     * @return
+     *   1 success,
+     *   0 Error,
+     * 
+     * In mode 1, when PIO state is change, module will send OK+Col:[xx] to
+     * UART or remote side. This command is set send interval.
+     * This command is added since V515 version. 
+    */
+    bool setPioCollectionRate (uint8_t colRateSec);
+    
+    
+    
+    /**Query PIO collection rate 
+     * @return
+     *  PIO collection rate: 00-99 unit[s] 
+     *  error :0xFF
+    */   
+    uint8_t queryPioCollectionRate(void); 
+    
+    
+        
+    /**Start a device discovery scan
+     * @param [out] scanRes 
+     * @return
+     *   1 success,
+     *   0 Error,
+     
+        Please set AT+ROLE1 and AT+IMME1 first.
+        ---usage--:
+        Send: AT+DISC? 
+        Recv: OK+DISCS
+        Recv: OK+DISC:123456789012 (discovered device address information)
+        If AT+SHOW1 is setup, you will receive then Name information as follow
+        Recv: OK+NAME: xxx
+        After send Name value, will send two extra “\r\n” value ASCII byte
+        Recv: OK+DISC:234567890123
+        Recv: OK+NAME: xxx
+        After send Name value, will send two extra “\r\n” value ASCII byte  ...(Max results is 6, use array 0~5)
+        Recv: OK+DISCE
+        Connect to a discovered device: AT+CONN0, AT+CONN1……AT+CONN5 
+    */   
+    bool startDeviceDiscoveryScan(ScanResult_t* scanRes); 
+    
+    
+      
+    /**Connect to an Discovery device 
+     * @param [in] scanRes 
+     * @return
+     *   1 success,
+     *   0 Error,
+     
+        This command is use after execute AT+DISC?
+        This command will clear all discovery data. 
+    */   
+    bool connectToDiscoveryDevice(ScanResult_t* scanRes); 
+    
+    
+       
+    /**Set IBeaconDeployMode
+     * @param depMode - DeployMode_t
+     * @return
+     *   1 success,
+     *   0 Error,
+     * 
+     * After receive OK+DELO[para1], module will reset after 500ms.
+     * This command will let module into non-connectable status until next power on.
+    */
+    bool setIBeaconDeployMode(DeployMode_t depMode);
+    
+    
+   /**Set filter of HM modules 
+     * @param filter -FilterOfHmModules_t 
+     * @return
+     *   1 success,
+     *   0 Error,
+    */   
+    bool setFilterOfHmModules(FilterOfHmModules_t filter); 
+    
+    
+    /**Query filter of HM modules 
+     * @return
+     * Type of filter
+    */   
+    FilterOfHmModules_t queryFilterOfHmModules(void); 
+    
+   
+    
+   /**Remove bond information
+     * @return
+     *   1 success,
+     *   0 Error,
+     * Note1: Added in V524 version. 
+    */
+    bool removeBondInformation(void); 
+    
+    
+   /**System Help Information
+     * @param [in] char* helpInformation
+     * @return
+     *   1 success,
+     *   0 Error, 
+    */
+    bool getSystemHelpInformation(char* helpInformationBuf); 
+    
+       
+   /**Set Module work type 
+     * @param modWorkType -ModuleWorkType_t
+     * @return
+     *   1 success,
+     *   0 Error,
+     * This command is only used for Central role.
+    */   
+    bool setModuleWorkType(ModuleWorkType_t modWorkType); 
+    
+    
+    /**Query Module work type  
+     * @return
+     *      module Work Type -ModuleWorkType_t
+     * This command is only used for Central role. 
+    */   
+    ModuleWorkType_t queryModuleWorkType(void);
+    
+   
+   
+  
+        
+   /**Set Module iBeacon Switch
+     * @param turnOnOff
+            0: Turn off iBeacon
+     *      1: Turn on iBeacon 
+     * @return
+     *   1 success,
+     *   0 Error,
+     * This command is added since V517 version. 
+    */   
+    bool setModuleIBeaconSwitch (uint8_t turnOnOff); 
+    
+    
+    /**Query iBeacon switch  
+     * @return
+     *      0: Turn off iBeacon
+     *      1: Turn on iBeacon 
+     * This command is added since V517 version.  
+    */   
+    uint8_t queryModuleIBeaconSwitch (void);
+     
+   
+       
+   /**Set iBeacon UUID 
+     * @param:  iBeacon Uuid - 0x00000001~0xFFFFFFFE 
+     * @return
+     *   1 success,
+     *   0 Error,
+     * This command is added since V520 version. 
+     * Default: iBeacon UUID is: 74278BDA-B644-4520-8F0C-720EAF059935.  
+     * -  uuid1 is 74278BDA
+     * -  uuid2 is B644-4520
+     * -  uuid1 is 8F0C-720E
+     * -  uuid1 is AF059935
+     */   
+    bool setIBeaconUuid (uint32_t uuid0,uint32_t uuid1,uint32_t uuid2, uint32_t uuid3); 
+    bool setIBeaconUuid (uint32_t* uuid); 
+    
+    /**Query iBeacon Uuid 
+     * @param:  part of uuid - 0~3
+     * @return
+     *    iBeacon Uuid - 0x00000001~0xFFFFFFFE 
+     *    Error - 0x00
+     * This command is added since V520 version.  
+    */   
+    uint32_t queryIBeaconUuid(uint32_t* nr_of_uuid);
+     
+    
+    
+     
+    /**Set Module iBeacon major version
+     * @param:  major version- 0x0001~0xFFFE  
+     * @return
+     *   1 success,
+     *   0 Error,
+     ^ Default: 0xFFE0
+     * This command is added since V517 version. 
+     */   
+    bool setIBeaconMajor(uint16_t mjrVersion); 
+    
+    
+    /**Query Module iBeacon major 
+     * @return
+     *    iBeacon major version- 0x0001~0xFFFE  
+     *    Error - 0x0000
+     * This command is added since V517 version.  
+    */   
+    uint16_t queryIBeaconMajor(void);
+    
+    
+    
+    /**Set Module iBeacon minor version
+     * @param:  minorversion- 0x0001~0xFFFE  
+     * @return
+     *   1 success,
+     *   0 Error,
+     ^ Default: 0xFFE1
+     * This command is added since V517 version. 
+     */   
+    bool setIBeaconMinor(uint16_t mnrVersion); 
+    
+    
+    /**Query Module iBeacon minor
+     * @return
+     *    iBeacon minor version- 0x0001~0xFFFE  
+     *    Error - 0x0000
+     * This command is added since V517 version.  
+    */   
+    uint16_t queryIBeaconMinor(void);
+   
+   
+   
+   
+   /**Set Module iBeacon Measured power 
+     * @param:  measured Power 0x0001~0xFFFE  
+     * @return
+     *   1 success,
+     *   0 Error,
+     ^ Default: 0xFFE1
+     * This command is added since V519 version. 
+     */   
+    bool setIBeaconMeasuredPower(uint16_t measuredPwr); 
+    
+    
+    /**Query Module iBeacon Measured power 
+     * @return
+     *    iBeacon minor version- 0x0001~0xFFFE  
+     *    Error - 0x0000
+     * This command is added since V519 version.  
+    */   
+    uint16_t queryIBeaconMeasuredPower(void);
+   
+   
+   
+   
+    /**Set Module Work Mode 
+     * @param:  WorkMode_t
+     * @return
+     *   1 success,
+     *   0 Error,
+     ^ Default: 0xFFE1
+     * This command is added since V519 version. 
+     */   
+    bool setModuleWorkMode(ModuleWorkMode_t workMode); 
+    
+    
+    /**Query Module Work Mode  
+     * @return
+     *    iBeacon minor version- 0x0001~0xFFFE  
+     *    Error - 0x0000
+     * This command is added since V519 version.  
+    */   
+    ModuleWorkMode_t  queryModuleWorkMode(void);
+   
+ 
+ 
+  
+   /**Set Module name 
+     * @param:  name, length<12
+     * @return
+     *   1 success,
+     *   0 Error, 
+     */   
+    bool setModuleName(char* name, uint8_t nameLength); 
+    
+    
+    /**Query Module name 
+     * @param:  name -> ptr to response buffer
+     * @return
+     *   1 success,
+     *   0 Error, 
+    */   
+    bool queryModuleName(char *name);
+ 
+ 
+ 
+  
+   /**Set Module parity bit
+     * @param:  ParityBit_t pBit
+     * @return
+     *   1 success,
+     *   0 Error, 
+     */   
+    bool setParityBit(ParityBit_t pBit); 
+    
+    
+    /**Query Module parity bit
+     * @return
+     *    -ParityBit_t val
+     */   
+    ParityBit_t queryParityBit(void);
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
 private:
     
     bool waitForData(int timeoutMs);