Library for Bluetooth Low Energy Module ble 4.0 HM-11

Committer:
igbt6
Date:
Thu Feb 25 02:44:30 2016 +0000
Revision:
7:aa4675590203
Parent:
6:16801af75937
more functions implemented

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igbt6 0:df4bd867616e 1 #include "hm11.h"
igbt6 0:df4bd867616e 2 #include "string.h"
igbt6 0:df4bd867616e 3
igbt6 5:9a00e7bb0275 4
igbt6 5:9a00e7bb0275 5 #define WAIT_FOR_DATA_TIMEOUT_MS 1000
igbt6 5:9a00e7bb0275 6 #define DEFAULT_WAIT_FOR_DATA_TIMEOUT_MS 50 //required to get correct data
igbt6 5:9a00e7bb0275 7
igbt6 0:df4bd867616e 8 HM11::HM11(PinName uartTx , PinName uartRx):mSerial(uartTx,uartRx){
igbt6 0:df4bd867616e 9
igbt6 0:df4bd867616e 10 mSerial.baud(HM11_SERIAL_DEFAULT_BAUD );
igbt6 0:df4bd867616e 11 }
igbt6 0:df4bd867616e 12
igbt6 0:df4bd867616e 13
igbt6 0:df4bd867616e 14
igbt6 0:df4bd867616e 15 bool HM11::sendSetCommand(const char* command, const int param){
igbt6 0:df4bd867616e 16
igbt6 0:df4bd867616e 17 if(!isCorrectCommand(command,HM11_SEND_COMMAND))
igbt6 0:df4bd867616e 18 return false;
igbt6 0:df4bd867616e 19 char dataBuf[12];
igbt6 0:df4bd867616e 20 memset(dataBuf,0,sizeof(dataBuf));
igbt6 0:df4bd867616e 21 snprintf(dataBuf,strlen(command)+4,"%s%s%d",hm11TestCommands[HM11_START_CMD],command,param); //TODO strlen +4 ? not all params are 1 char long
igbt6 0:df4bd867616e 22 sendDataToDevice(dataBuf);
igbt6 0:df4bd867616e 23 return true;
igbt6 0:df4bd867616e 24 }
igbt6 0:df4bd867616e 25
igbt6 0:df4bd867616e 26
igbt6 0:df4bd867616e 27 bool HM11::sendGetCommand(const char* command){
igbt6 0:df4bd867616e 28
igbt6 0:df4bd867616e 29 if(!isCorrectCommand(command,HM11_SEND_COMMAND))
igbt6 0:df4bd867616e 30 return false;
igbt6 0:df4bd867616e 31 char dataBuf[12];
igbt6 0:df4bd867616e 32 memset(dataBuf,0,sizeof(dataBuf));
igbt6 0:df4bd867616e 33 snprintf(dataBuf,strlen(hm11TestCommands[HM11_START_CMD])+strlen(command)+strlen(hm11TestCommands[HM11_QUERY_SIGN]+2),"%s%s%s\0",hm11TestCommands[HM11_START_CMD],command,hm11TestCommands[HM11_QUERY_SIGN]);
igbt6 0:df4bd867616e 34 sendDataToDevice(dataBuf);
igbt6 0:df4bd867616e 35 return true;
igbt6 0:df4bd867616e 36 }
igbt6 0:df4bd867616e 37
igbt6 0:df4bd867616e 38 //@param : cmdType - 0 test cmd
igbt6 0:df4bd867616e 39 bool HM11::isCorrectCommand(const char* command, HM11CommandType cmdType){
igbt6 0:df4bd867616e 40 int i = 0 ;
igbt6 0:df4bd867616e 41 const char**cmdPtr=NULL;
igbt6 0:df4bd867616e 42 if(cmdType>=HM11_NUM_OF_COMMAND_TYPE){
igbt6 0:df4bd867616e 43
igbt6 0:df4bd867616e 44 return false;
igbt6 0:df4bd867616e 45 }
igbt6 0:df4bd867616e 46 if(command==NULL)
igbt6 0:df4bd867616e 47 return false;
igbt6 0:df4bd867616e 48 switch(cmdType){
igbt6 0:df4bd867616e 49 case HM11_TEST_COMMAND:
igbt6 0:df4bd867616e 50 i = HM11_NUM_OF_TEST_COMMANDS ;
igbt6 0:df4bd867616e 51 cmdPtr=hm11TestCommands;
igbt6 0:df4bd867616e 52 break;
igbt6 0:df4bd867616e 53 case HM11_SEND_COMMAND:
igbt6 0:df4bd867616e 54 i = HM11_NUM_OF_COMMANDS;
igbt6 0:df4bd867616e 55 cmdPtr=hm11SendCommands;
igbt6 0:df4bd867616e 56 break;
igbt6 0:df4bd867616e 57 }
igbt6 0:df4bd867616e 58 while(i>0){
igbt6 0:df4bd867616e 59 if(strcmp(command,cmdPtr[i])==0){
igbt6 0:df4bd867616e 60 return true;
igbt6 0:df4bd867616e 61 }
igbt6 0:df4bd867616e 62 i--;
igbt6 0:df4bd867616e 63 }
igbt6 0:df4bd867616e 64 return false;
igbt6 0:df4bd867616e 65 }
igbt6 0:df4bd867616e 66 //comands
igbt6 5:9a00e7bb0275 67
igbt6 0:df4bd867616e 68
igbt6 0:df4bd867616e 69 bool HM11:: waitForData(int timeoutMs){
igbt6 5:9a00e7bb0275 70 int endTime;
igbt6 5:9a00e7bb0275 71 int startTime; // sometimes not needed 50ms
igbt6 0:df4bd867616e 72 Timer timer;
igbt6 5:9a00e7bb0275 73 timer.start() ;
igbt6 5:9a00e7bb0275 74 startTime=timer.read_ms();
igbt6 5:9a00e7bb0275 75 endTime= startTime+timeoutMs;
igbt6 5:9a00e7bb0275 76 while((timer.read_ms())<endTime){
igbt6 5:9a00e7bb0275 77 if(isRxDataAvailable()&&(timer.read_ms()-startTime)>DEFAULT_WAIT_FOR_DATA_TIMEOUT_MS)
igbt6 0:df4bd867616e 78 return true;
igbt6 0:df4bd867616e 79 }
igbt6 0:df4bd867616e 80 return false;
igbt6 0:df4bd867616e 81 }
igbt6 0:df4bd867616e 82
igbt6 0:df4bd867616e 83
igbt6 5:9a00e7bb0275 84 int HM11::sendDataToDevice(const char* data)
igbt6 5:9a00e7bb0275 85 {
igbt6 0:df4bd867616e 86
igbt6 0:df4bd867616e 87 return mSerial.printf(data);
igbt6 0:df4bd867616e 88 }
igbt6 0:df4bd867616e 89
igbt6 6:16801af75937 90 int HM11::sendDataToDevice(const uint8_t * byteData,uint8_t dataLength)
igbt6 5:9a00e7bb0275 91 {
igbt6 3:d32bdfd04d82 92
igbt6 3:d32bdfd04d82 93 return mSerial.write(byteData,dataLength);
igbt6 3:d32bdfd04d82 94 }
igbt6 5:9a00e7bb0275 95
igbt6 5:9a00e7bb0275 96 int HM11::isRxDataAvailable()
igbt6 5:9a00e7bb0275 97 {
igbt6 5:9a00e7bb0275 98 return mSerial.readable();
igbt6 5:9a00e7bb0275 99 }
igbt6 5:9a00e7bb0275 100
igbt6 7:aa4675590203 101 int HM11::copyAvailableDataToBuf(uint8_t *buf, uint8_t bufLength)
igbt6 5:9a00e7bb0275 102 {
igbt6 5:9a00e7bb0275 103 int lenCounter =0;
igbt6 5:9a00e7bb0275 104 if(buf==NULL||bufLength<1)
igbt6 7:aa4675590203 105 return -1;
igbt6 5:9a00e7bb0275 106 while(isRxDataAvailable()&&lenCounter<bufLength){
igbt6 5:9a00e7bb0275 107 buf[lenCounter++]=getDataFromRx();
igbt6 5:9a00e7bb0275 108 }
igbt6 7:aa4675590203 109 return lenCounter;
igbt6 5:9a00e7bb0275 110 }
igbt6 5:9a00e7bb0275 111
igbt6 7:aa4675590203 112 bool HM11:: hexToString(uint32_t hex, char*str,uint8_t nrOfNibblesInHex)
igbt6 5:9a00e7bb0275 113 {
igbt6 7:aa4675590203 114 if(nrOfNibblesInHex>8||nrOfNibblesInHex==0||str==NULL)
igbt6 7:aa4675590203 115 return false;
igbt6 7:aa4675590203 116 for(int i=0;i<nrOfNibblesInHex;i++){
igbt6 5:9a00e7bb0275 117 int temp =(hex>>(i*4))&0x0F;
igbt6 5:9a00e7bb0275 118 if(temp>=0&&temp<=9)
igbt6 5:9a00e7bb0275 119 {
igbt6 7:aa4675590203 120 str[nrOfNibblesInHex-i-1]=temp+'0';
igbt6 5:9a00e7bb0275 121 }
igbt6 5:9a00e7bb0275 122 else
igbt6 5:9a00e7bb0275 123 {
igbt6 7:aa4675590203 124 str[nrOfNibblesInHex-i-1]=temp+'A'-10;
igbt6 5:9a00e7bb0275 125 }
igbt6 5:9a00e7bb0275 126 }
igbt6 7:aa4675590203 127 return true;
igbt6 5:9a00e7bb0275 128 }
igbt6 5:9a00e7bb0275 129
igbt6 5:9a00e7bb0275 130
igbt6 5:9a00e7bb0275 131 //returns hex in reverse direction
igbt6 7:aa4675590203 132 uint32_t HM11::strToHex(char*const str,uint8_t len) //len - nr of nibbles in str
igbt6 5:9a00e7bb0275 133 {
igbt6 5:9a00e7bb0275 134 uint32_t ret=0;
igbt6 5:9a00e7bb0275 135 uint8_t temp;
igbt6 7:aa4675590203 136 if(len<1||len>8||str==NULL)
igbt6 7:aa4675590203 137 return 0xFFFFFFFF;
igbt6 5:9a00e7bb0275 138
igbt6 5:9a00e7bb0275 139 for(int i=0;i<len&&str[i]!='\0';i++)
igbt6 5:9a00e7bb0275 140 {
igbt6 5:9a00e7bb0275 141 if(str[i]>='0'&&str[i]<='9')
igbt6 5:9a00e7bb0275 142 {
igbt6 5:9a00e7bb0275 143 temp=str[i]-'0';
igbt6 5:9a00e7bb0275 144 ret|=temp<<(i*4);
igbt6 5:9a00e7bb0275 145 }
igbt6 5:9a00e7bb0275 146 else if(str[i]>='A'&&str[i]<='F')
igbt6 5:9a00e7bb0275 147 {
igbt6 5:9a00e7bb0275 148 temp=str[i]-'A'+10;
igbt6 5:9a00e7bb0275 149 ret|=temp<<(i*4);
igbt6 5:9a00e7bb0275 150 }
igbt6 5:9a00e7bb0275 151 else if(str[i]>='a'&&str[i]<='f')
igbt6 5:9a00e7bb0275 152 {
igbt6 5:9a00e7bb0275 153 temp=str[i]-'a'+10;
igbt6 5:9a00e7bb0275 154 ret|=temp<<(i*4);
igbt6 5:9a00e7bb0275 155 }
igbt6 5:9a00e7bb0275 156 else
igbt6 7:aa4675590203 157 return 0xFFFFFFFF; //-1 :-)
igbt6 5:9a00e7bb0275 158 }
igbt6 5:9a00e7bb0275 159 return ret;
igbt6 5:9a00e7bb0275 160 }
igbt6 5:9a00e7bb0275 161
igbt6 5:9a00e7bb0275 162 // public methods
igbt6 5:9a00e7bb0275 163 bool HM11::queryModuleAddress(char* addrBuf)
igbt6 5:9a00e7bb0275 164 {
igbt6 5:9a00e7bb0275 165 flushBuffers();
igbt6 5:9a00e7bb0275 166 sendDataToDevice("AT+ADDR?");
igbt6 5:9a00e7bb0275 167 char headerBuf[8];//for OK+ADDR:
igbt6 5:9a00e7bb0275 168 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 169 return false;
igbt6 5:9a00e7bb0275 170 else{
igbt6 5:9a00e7bb0275 171 copyAvailableDataToBuf((uint8_t*)headerBuf,sizeof(headerBuf));
igbt6 5:9a00e7bb0275 172 if(strncmp(headerBuf,"OK+ADDR:",sizeof(headerBuf)) == 0){
igbt6 5:9a00e7bb0275 173 if(copyAvailableDataToBuf((uint8_t*)addrBuf,12)){
igbt6 5:9a00e7bb0275 174 addrBuf[12]='\0';
igbt6 5:9a00e7bb0275 175 return true;
igbt6 5:9a00e7bb0275 176 }
igbt6 5:9a00e7bb0275 177 }
igbt6 5:9a00e7bb0275 178 return false;
igbt6 5:9a00e7bb0275 179 }
igbt6 5:9a00e7bb0275 180 }
igbt6 5:9a00e7bb0275 181
igbt6 5:9a00e7bb0275 182
igbt6 5:9a00e7bb0275 183 bool HM11::setAdvertisingInterval(AdvertisingInterval_t advInt)
igbt6 5:9a00e7bb0275 184 {
igbt6 5:9a00e7bb0275 185 flushBuffers();
igbt6 5:9a00e7bb0275 186 char buf[9]={"AT+ADVI"};
igbt6 5:9a00e7bb0275 187 hexToString((uint32_t)advInt, &buf[7],1);
igbt6 7:aa4675590203 188 buf[8]='\0';
igbt6 5:9a00e7bb0275 189 sendDataToDevice(buf);
igbt6 5:9a00e7bb0275 190 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 191 return false;
igbt6 5:9a00e7bb0275 192 else
igbt6 5:9a00e7bb0275 193 {
igbt6 5:9a00e7bb0275 194 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 5:9a00e7bb0275 195 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 5:9a00e7bb0275 196 if(strToHex(&buf[7],1)<_INVALID_ADV_INTERVAL){
igbt6 5:9a00e7bb0275 197 return true;
igbt6 5:9a00e7bb0275 198 }
igbt6 5:9a00e7bb0275 199 }
igbt6 5:9a00e7bb0275 200 return false;
igbt6 5:9a00e7bb0275 201 }
igbt6 5:9a00e7bb0275 202 }
igbt6 5:9a00e7bb0275 203
igbt6 5:9a00e7bb0275 204
igbt6 5:9a00e7bb0275 205 AdvertisingInterval_t HM11::queryAdvertisingInterval(void)
igbt6 5:9a00e7bb0275 206 {
igbt6 5:9a00e7bb0275 207 flushBuffers();
igbt6 5:9a00e7bb0275 208 AdvertisingInterval_t retVal=_INVALID_ADV_INTERVAL;
igbt6 5:9a00e7bb0275 209 char respBuf[8];
igbt6 5:9a00e7bb0275 210 sendDataToDevice("AT+ADVI?");
igbt6 5:9a00e7bb0275 211 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 212 {
igbt6 5:9a00e7bb0275 213 //nothing
igbt6 5:9a00e7bb0275 214 }
igbt6 5:9a00e7bb0275 215 else
igbt6 5:9a00e7bb0275 216 {
igbt6 5:9a00e7bb0275 217 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 5:9a00e7bb0275 218 if(strncmp(respBuf,"OK+Get:",sizeof(respBuf)-1) == 0){
igbt6 5:9a00e7bb0275 219 retVal=(AdvertisingInterval_t)strToHex(&respBuf[sizeof(respBuf)-1],1);
igbt6 5:9a00e7bb0275 220 }
igbt6 5:9a00e7bb0275 221
igbt6 5:9a00e7bb0275 222 }
igbt6 5:9a00e7bb0275 223 return retVal;
igbt6 5:9a00e7bb0275 224 }
igbt6 5:9a00e7bb0275 225
igbt6 5:9a00e7bb0275 226
igbt6 5:9a00e7bb0275 227 bool HM11::setAdvertisingType(AdvertisingType_t advInt)
igbt6 5:9a00e7bb0275 228 {
igbt6 5:9a00e7bb0275 229 flushBuffers();
igbt6 5:9a00e7bb0275 230 char buf[9]={"AT+ADTY"};
igbt6 5:9a00e7bb0275 231 hexToString((uint32_t)advInt, &buf[7],1);
igbt6 7:aa4675590203 232 buf[8]='\0';
igbt6 5:9a00e7bb0275 233 sendDataToDevice(buf);
igbt6 5:9a00e7bb0275 234 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 235 return false;
igbt6 5:9a00e7bb0275 236 else
igbt6 5:9a00e7bb0275 237 {
igbt6 5:9a00e7bb0275 238 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 5:9a00e7bb0275 239 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 5:9a00e7bb0275 240 if(strToHex(&buf[7],1)<_INVALID_ADV_TYPE){
igbt6 5:9a00e7bb0275 241 return true;
igbt6 5:9a00e7bb0275 242 }
igbt6 5:9a00e7bb0275 243 }
igbt6 5:9a00e7bb0275 244 return false;
igbt6 5:9a00e7bb0275 245 }
igbt6 5:9a00e7bb0275 246 }
igbt6 5:9a00e7bb0275 247
igbt6 5:9a00e7bb0275 248 AdvertisingType_t HM11::queryAdvertisingType(void)
igbt6 5:9a00e7bb0275 249 {
igbt6 5:9a00e7bb0275 250 flushBuffers();
igbt6 5:9a00e7bb0275 251 AdvertisingType_t retVal=_INVALID_ADV_TYPE;
igbt6 5:9a00e7bb0275 252 char respBuf[8];
igbt6 5:9a00e7bb0275 253 sendDataToDevice("AT+ADTY?");
igbt6 5:9a00e7bb0275 254 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 255 {
igbt6 5:9a00e7bb0275 256 //nothing
igbt6 5:9a00e7bb0275 257 }
igbt6 5:9a00e7bb0275 258 else
igbt6 5:9a00e7bb0275 259 {
igbt6 5:9a00e7bb0275 260 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 5:9a00e7bb0275 261 if(strncmp(respBuf,"OK+Get:",sizeof(respBuf)-1) == 0){
igbt6 5:9a00e7bb0275 262 retVal=(AdvertisingType_t)strToHex(&respBuf[sizeof(respBuf)-1],1);
igbt6 5:9a00e7bb0275 263 }
igbt6 5:9a00e7bb0275 264 }
igbt6 5:9a00e7bb0275 265 return retVal;
igbt6 5:9a00e7bb0275 266 }
igbt6 5:9a00e7bb0275 267
igbt6 5:9a00e7bb0275 268
igbt6 5:9a00e7bb0275 269
igbt6 5:9a00e7bb0275 270 bool HM11::setAncsSwitch(uint8_t enable)
igbt6 5:9a00e7bb0275 271 {
igbt6 5:9a00e7bb0275 272 flushBuffers();
igbt6 5:9a00e7bb0275 273 char buf[9]={"AT+ANCS"};
igbt6 5:9a00e7bb0275 274 hexToString(enable, &buf[7],1);
igbt6 7:aa4675590203 275 buf[8]='\0';
igbt6 5:9a00e7bb0275 276 sendDataToDevice(buf);
igbt6 5:9a00e7bb0275 277 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 278 return false;
igbt6 5:9a00e7bb0275 279 else
igbt6 5:9a00e7bb0275 280 {
igbt6 5:9a00e7bb0275 281 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 5:9a00e7bb0275 282 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 5:9a00e7bb0275 283 if(strToHex(&buf[7],1)<0x2){
igbt6 5:9a00e7bb0275 284 return true;
igbt6 5:9a00e7bb0275 285 }
igbt6 5:9a00e7bb0275 286 }
igbt6 5:9a00e7bb0275 287 return false;
igbt6 5:9a00e7bb0275 288 }
igbt6 5:9a00e7bb0275 289 }
igbt6 5:9a00e7bb0275 290
igbt6 5:9a00e7bb0275 291
igbt6 5:9a00e7bb0275 292
igbt6 5:9a00e7bb0275 293 uint8_t HM11::queryAncsSwitch(void)
igbt6 5:9a00e7bb0275 294 {
igbt6 5:9a00e7bb0275 295 flushBuffers();
igbt6 5:9a00e7bb0275 296 uint8_t retVal=0xFF;
igbt6 5:9a00e7bb0275 297 char respBuf[8];
igbt6 5:9a00e7bb0275 298 sendDataToDevice("AT+ANCS?");
igbt6 5:9a00e7bb0275 299 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 300 {
igbt6 5:9a00e7bb0275 301 retVal=0xFF;
igbt6 5:9a00e7bb0275 302 }
igbt6 5:9a00e7bb0275 303 else
igbt6 5:9a00e7bb0275 304 {
igbt6 5:9a00e7bb0275 305 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 5:9a00e7bb0275 306 if(strncmp(respBuf,"OK+Get:",sizeof(respBuf)-1) == 0){
igbt6 5:9a00e7bb0275 307 retVal=strToHex(&respBuf[sizeof(respBuf)-1],1);
igbt6 5:9a00e7bb0275 308 }
igbt6 5:9a00e7bb0275 309 }
igbt6 5:9a00e7bb0275 310 return retVal;
igbt6 5:9a00e7bb0275 311 }
igbt6 5:9a00e7bb0275 312
igbt6 5:9a00e7bb0275 313
igbt6 5:9a00e7bb0275 314 bool HM11::setWhitelistSwitch(uint8_t enable)
igbt6 5:9a00e7bb0275 315 {
igbt6 5:9a00e7bb0275 316 flushBuffers();
igbt6 5:9a00e7bb0275 317 char buf[9]={"AT+ALLO"};
igbt6 5:9a00e7bb0275 318 hexToString(enable, &buf[7],1);
igbt6 7:aa4675590203 319 buf[8]='\0';
igbt6 5:9a00e7bb0275 320 sendDataToDevice(buf);
igbt6 5:9a00e7bb0275 321 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 322 return false;
igbt6 5:9a00e7bb0275 323 else
igbt6 5:9a00e7bb0275 324 {
igbt6 5:9a00e7bb0275 325 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 5:9a00e7bb0275 326 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 5:9a00e7bb0275 327 if(strToHex(&buf[7],1)<0x2){
igbt6 5:9a00e7bb0275 328 return true;
igbt6 5:9a00e7bb0275 329 }
igbt6 5:9a00e7bb0275 330 }
igbt6 5:9a00e7bb0275 331 return false;
igbt6 5:9a00e7bb0275 332 }
igbt6 5:9a00e7bb0275 333 }
igbt6 5:9a00e7bb0275 334
igbt6 5:9a00e7bb0275 335
igbt6 5:9a00e7bb0275 336 uint8_t HM11::queryWhitelistSwitch(void)
igbt6 5:9a00e7bb0275 337 {
igbt6 5:9a00e7bb0275 338 flushBuffers();
igbt6 5:9a00e7bb0275 339 uint8_t retVal=0xFF;
igbt6 5:9a00e7bb0275 340 char respBuf[8];
igbt6 5:9a00e7bb0275 341 sendDataToDevice("AT+ALLO?");
igbt6 5:9a00e7bb0275 342 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 343 {
igbt6 5:9a00e7bb0275 344 retVal=0xFF;
igbt6 5:9a00e7bb0275 345 }
igbt6 5:9a00e7bb0275 346 else
igbt6 5:9a00e7bb0275 347 {
igbt6 5:9a00e7bb0275 348 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 5:9a00e7bb0275 349 if(strncmp(respBuf,"OK+Get:",sizeof(respBuf)-1) == 0){
igbt6 5:9a00e7bb0275 350 retVal=strToHex(&respBuf[sizeof(respBuf)-1],1);
igbt6 5:9a00e7bb0275 351 }
igbt6 5:9a00e7bb0275 352 }
igbt6 5:9a00e7bb0275 353 return retVal;
igbt6 5:9a00e7bb0275 354 }
igbt6 5:9a00e7bb0275 355
igbt6 7:aa4675590203 356
igbt6 7:aa4675590203 357 bool HM11::setWhitelistMacAddress (uint8_t nrOfMacAddrLinkedToModule, const char* const macAddress)
igbt6 7:aa4675590203 358 {
igbt6 7:aa4675590203 359 if(nrOfMacAddrLinkedToModule>3 ||macAddress ==NULL)
igbt6 7:aa4675590203 360 {
igbt6 7:aa4675590203 361 return false;
igbt6 7:aa4675590203 362 }
igbt6 7:aa4675590203 363 char buf[19]={"AT+AD"};
igbt6 7:aa4675590203 364 flushBuffers();
igbt6 7:aa4675590203 365 hexToString(nrOfMacAddrLinkedToModule, &buf[5],1);
igbt6 7:aa4675590203 366 memcpy(&buf[6],macAddress,12);
igbt6 7:aa4675590203 367 buf[18]='\0';
igbt6 7:aa4675590203 368 sendDataToDevice(buf);
igbt6 7:aa4675590203 369 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 370 return false;
igbt6 7:aa4675590203 371 else
igbt6 7:aa4675590203 372 {
igbt6 7:aa4675590203 373 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 374 if(strncmp(buf,"OK+AD",5) == 0){
igbt6 7:aa4675590203 375 return true;
igbt6 7:aa4675590203 376 }
igbt6 7:aa4675590203 377 return false;
igbt6 7:aa4675590203 378 }
igbt6 7:aa4675590203 379 }
igbt6 5:9a00e7bb0275 380
igbt6 7:aa4675590203 381 bool HM11::queryWhitelistMacAddress(uint8_t nrOfMacAddrLinkedToModule, char* const macAddrBuf, uint8_t macAddrBufLen)
igbt6 7:aa4675590203 382 {
igbt6 7:aa4675590203 383
igbt6 7:aa4675590203 384 if(macAddrBuf==NULL||nrOfMacAddrLinkedToModule>3||macAddrBufLen<12) //12 -len of macAddr eg. 001122334455
igbt6 7:aa4675590203 385 return false;
igbt6 7:aa4675590203 386 flushBuffers();
igbt6 7:aa4675590203 387 char buf[20]={"AT+ADx??"};
igbt6 7:aa4675590203 388 buf[8]='\0';
igbt6 7:aa4675590203 389 hexToString(nrOfMacAddrLinkedToModule, &buf[5],1);
igbt6 7:aa4675590203 390 sendDataToDevice(buf);
igbt6 7:aa4675590203 391 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 392 return false;
igbt6 7:aa4675590203 393 else
igbt6 7:aa4675590203 394 {
igbt6 7:aa4675590203 395 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 396 if(strncmp(buf,"OK+AD",5) == 0){
igbt6 7:aa4675590203 397 memcpy(macAddrBuf,&buf[8],12);
igbt6 7:aa4675590203 398 return true;
igbt6 7:aa4675590203 399 }
igbt6 7:aa4675590203 400 return false;
igbt6 7:aa4675590203 401 }
igbt6 7:aa4675590203 402
igbt6 7:aa4675590203 403 }
igbt6 5:9a00e7bb0275 404
igbt6 5:9a00e7bb0275 405
igbt6 5:9a00e7bb0275 406 bool HM11::setBatteryMonitorSwitch(uint8_t battSwitchEnable)
igbt6 5:9a00e7bb0275 407 {
igbt6 5:9a00e7bb0275 408 flushBuffers();
igbt6 7:aa4675590203 409 char buf[9]={"AT+BATCx"};
igbt6 7:aa4675590203 410 buf[8]='\0';
igbt6 5:9a00e7bb0275 411 hexToString(battSwitchEnable, &buf[7],1);
igbt6 5:9a00e7bb0275 412 sendDataToDevice(buf);
igbt6 5:9a00e7bb0275 413 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 414 return false;
igbt6 5:9a00e7bb0275 415 else
igbt6 5:9a00e7bb0275 416 {
igbt6 5:9a00e7bb0275 417 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 5:9a00e7bb0275 418 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 5:9a00e7bb0275 419 if(strToHex(&buf[7],1)<0x2){
igbt6 5:9a00e7bb0275 420 return true;
igbt6 5:9a00e7bb0275 421 }
igbt6 5:9a00e7bb0275 422 }
igbt6 5:9a00e7bb0275 423 return false;
igbt6 5:9a00e7bb0275 424 }
igbt6 5:9a00e7bb0275 425 }
igbt6 5:9a00e7bb0275 426
igbt6 5:9a00e7bb0275 427
igbt6 5:9a00e7bb0275 428 uint8_t HM11::queryBatteryMonitorSwitch(void)
igbt6 5:9a00e7bb0275 429 {
igbt6 5:9a00e7bb0275 430 flushBuffers();
igbt6 5:9a00e7bb0275 431 uint8_t retVal=0xFF;
igbt6 5:9a00e7bb0275 432 char respBuf[8];
igbt6 5:9a00e7bb0275 433 sendDataToDevice("AT+BATC?");
igbt6 5:9a00e7bb0275 434 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 5:9a00e7bb0275 435 {
igbt6 5:9a00e7bb0275 436 retVal=0xFF;
igbt6 5:9a00e7bb0275 437 }
igbt6 5:9a00e7bb0275 438 else
igbt6 5:9a00e7bb0275 439 {
igbt6 5:9a00e7bb0275 440 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 5:9a00e7bb0275 441 if(strncmp(respBuf,"OK+Get:",sizeof(respBuf)-1) == 0){
igbt6 5:9a00e7bb0275 442 retVal=strToHex(&respBuf[sizeof(respBuf)-1],1);
igbt6 5:9a00e7bb0275 443 }
igbt6 5:9a00e7bb0275 444 }
igbt6 5:9a00e7bb0275 445 return retVal;
igbt6 5:9a00e7bb0275 446 }
igbt6 5:9a00e7bb0275 447
igbt6 5:9a00e7bb0275 448
igbt6 7:aa4675590203 449
igbt6 7:aa4675590203 450 uint8_t HM11::queryBatteryInformation(void)
igbt6 7:aa4675590203 451 {
igbt6 7:aa4675590203 452 flushBuffers();
igbt6 7:aa4675590203 453 uint8_t retVal=0xFF;
igbt6 7:aa4675590203 454 char respBuf[12];
igbt6 7:aa4675590203 455 sendDataToDevice("AT+BATT?");
igbt6 7:aa4675590203 456 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 457 {
igbt6 7:aa4675590203 458 retVal=0xFF;
igbt6 7:aa4675590203 459 }
igbt6 7:aa4675590203 460 else
igbt6 7:aa4675590203 461 {
igbt6 7:aa4675590203 462 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 7:aa4675590203 463 if(strncmp(respBuf,"OK+BATT:",7) == 0){
igbt6 7:aa4675590203 464 retVal=strToHex(&respBuf[7],3);
igbt6 7:aa4675590203 465 }
igbt6 7:aa4675590203 466 }
igbt6 7:aa4675590203 467 return retVal;
igbt6 7:aa4675590203 468
igbt6 7:aa4675590203 469 }
igbt6 5:9a00e7bb0275 470
igbt6 5:9a00e7bb0275 471
igbt6 5:9a00e7bb0275 472
igbt6 7:aa4675590203 473 bool HM11::setIBeaconIntoServiceMode(void) //NOT USED ANYMORE
igbt6 7:aa4675590203 474 {
igbt6 7:aa4675590203 475 flushBuffers();
igbt6 7:aa4675590203 476 sendDataToDevice("AT+BUSHU");
igbt6 7:aa4675590203 477 char respBuf[10];
igbt6 7:aa4675590203 478 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 479 {
igbt6 7:aa4675590203 480 return false;
igbt6 7:aa4675590203 481 }
igbt6 7:aa4675590203 482 else
igbt6 7:aa4675590203 483 {
igbt6 7:aa4675590203 484 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 7:aa4675590203 485 if(strncmp(respBuf,"OK+BUSHU",7) == 0)
igbt6 7:aa4675590203 486 {
igbt6 7:aa4675590203 487 return true;
igbt6 7:aa4675590203 488 }
igbt6 7:aa4675590203 489 }
igbt6 7:aa4675590203 490 return false;
igbt6 7:aa4675590203 491
igbt6 7:aa4675590203 492 }
igbt6 5:9a00e7bb0275 493
igbt6 5:9a00e7bb0275 494
igbt6 5:9a00e7bb0275 495
igbt6 7:aa4675590203 496 bool HM11::setBitFormat(uint8_t bit7Format)
igbt6 7:aa4675590203 497 {
igbt6 7:aa4675590203 498 if(bit7Format>1)
igbt6 7:aa4675590203 499 return false;
igbt6 7:aa4675590203 500 flushBuffers();
igbt6 7:aa4675590203 501 char buf[9]={"AT+BIT7x"};
igbt6 7:aa4675590203 502 buf[8]='\0';
igbt6 7:aa4675590203 503 hexToString(bit7Format, &buf[7],1);
igbt6 7:aa4675590203 504 sendDataToDevice(buf);
igbt6 7:aa4675590203 505 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 506 return false;
igbt6 7:aa4675590203 507 else
igbt6 7:aa4675590203 508 {
igbt6 7:aa4675590203 509 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 510 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 7:aa4675590203 511 if(strToHex(&buf[7],1)<0x2){
igbt6 7:aa4675590203 512 return true;
igbt6 7:aa4675590203 513 }
igbt6 7:aa4675590203 514 }
igbt6 7:aa4675590203 515 return false;
igbt6 7:aa4675590203 516 }
igbt6 7:aa4675590203 517 }
igbt6 7:aa4675590203 518
igbt6 7:aa4675590203 519
igbt6 7:aa4675590203 520 uint8_t HM11::queryBitFormat(void)
igbt6 7:aa4675590203 521 {
igbt6 7:aa4675590203 522 flushBuffers();
igbt6 7:aa4675590203 523 uint8_t retVal=0xFF;
igbt6 7:aa4675590203 524 char respBuf[8];
igbt6 7:aa4675590203 525 sendDataToDevice("AT+BIT7?");
igbt6 7:aa4675590203 526 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 527 {
igbt6 7:aa4675590203 528 retVal=0xFF;
igbt6 7:aa4675590203 529 }
igbt6 7:aa4675590203 530 else
igbt6 7:aa4675590203 531 {
igbt6 7:aa4675590203 532 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 7:aa4675590203 533 if(strncmp(respBuf,"OK+Get:",7) == 0){
igbt6 7:aa4675590203 534 retVal=strToHex(&respBuf[7],1);
igbt6 7:aa4675590203 535 }
igbt6 7:aa4675590203 536 }
igbt6 7:aa4675590203 537 return retVal;
igbt6 7:aa4675590203 538 }
igbt6 7:aa4675590203 539
igbt6 7:aa4675590203 540
igbt6 7:aa4675590203 541
igbt6 7:aa4675590203 542 bool HM11::setBaudRate(BaudRate_t baud)
igbt6 7:aa4675590203 543 {
igbt6 7:aa4675590203 544 if(baud >=_INVALID_BAUDRATE)
igbt6 7:aa4675590203 545 return false;
igbt6 7:aa4675590203 546 flushBuffers();
igbt6 7:aa4675590203 547 char buf[9]={"AT+BAUDx"};
igbt6 7:aa4675590203 548 hexToString((uint32_t)baud, &buf[7],1);
igbt6 7:aa4675590203 549 buf[8]='\0';
igbt6 7:aa4675590203 550 sendDataToDevice(buf);
igbt6 7:aa4675590203 551 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 552 return false;
igbt6 7:aa4675590203 553 else
igbt6 7:aa4675590203 554 {
igbt6 7:aa4675590203 555 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 556 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 7:aa4675590203 557 if(strToHex(&buf[7],1)<_INVALID_BAUDRATE){
igbt6 7:aa4675590203 558 return true;
igbt6 7:aa4675590203 559 }
igbt6 7:aa4675590203 560 }
igbt6 7:aa4675590203 561 return false;
igbt6 7:aa4675590203 562 }
igbt6 7:aa4675590203 563 }
igbt6 7:aa4675590203 564
igbt6 7:aa4675590203 565
igbt6 7:aa4675590203 566 BaudRate_t HM11::queryBaudRate(void)
igbt6 7:aa4675590203 567 {
igbt6 7:aa4675590203 568 flushBuffers();
igbt6 7:aa4675590203 569 BaudRate_t retVal=_INVALID_BAUDRATE;
igbt6 7:aa4675590203 570 char respBuf[8];
igbt6 7:aa4675590203 571 sendDataToDevice("AT+BAUD?");
igbt6 7:aa4675590203 572 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 573 {
igbt6 7:aa4675590203 574 //nothing
igbt6 7:aa4675590203 575 }
igbt6 7:aa4675590203 576 else
igbt6 7:aa4675590203 577 {
igbt6 7:aa4675590203 578 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 7:aa4675590203 579 if(strncmp(respBuf,"OK+Get:",7) == 0){
igbt6 7:aa4675590203 580 retVal=(BaudRate_t)strToHex(&respBuf[7],1);
igbt6 7:aa4675590203 581 }
igbt6 7:aa4675590203 582
igbt6 7:aa4675590203 583 }
igbt6 7:aa4675590203 584 return retVal;
igbt6 7:aa4675590203 585 }
igbt6 7:aa4675590203 586
igbt6 7:aa4675590203 587
igbt6 7:aa4675590203 588 bool HM11::setCharacteristic(uint16_t chValue)
igbt6 7:aa4675590203 589 {
igbt6 7:aa4675590203 590 if(chValue <0x0001||chValue>0xFFFE)
igbt6 7:aa4675590203 591 return false;
igbt6 7:aa4675590203 592 flushBuffers();
igbt6 7:aa4675590203 593 char buf[14]={"AT+CHAR0xiiii"};
igbt6 7:aa4675590203 594 hexToString((uint32_t)chValue, &buf[9],4);
igbt6 7:aa4675590203 595 buf[13]='\0';
igbt6 7:aa4675590203 596 sendDataToDevice(buf);
igbt6 7:aa4675590203 597 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 598 return false;
igbt6 7:aa4675590203 599 else
igbt6 7:aa4675590203 600 {
igbt6 7:aa4675590203 601 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 602 if(strncmp(buf,"OK+Set:0x",9) == 0){
igbt6 7:aa4675590203 603 return true;
igbt6 7:aa4675590203 604
igbt6 7:aa4675590203 605 }
igbt6 7:aa4675590203 606 return false;
igbt6 7:aa4675590203 607 }
igbt6 7:aa4675590203 608 }
igbt6 5:9a00e7bb0275 609
igbt6 7:aa4675590203 610 uint16_t HM11::queryCharacteristic(void)
igbt6 7:aa4675590203 611 {
igbt6 7:aa4675590203 612 flushBuffers();
igbt6 7:aa4675590203 613 uint16_t retVal=0xFFFF;
igbt6 7:aa4675590203 614 char respBuf[14];
igbt6 7:aa4675590203 615 sendDataToDevice("AT+CHAR?");
igbt6 7:aa4675590203 616 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 617 {
igbt6 7:aa4675590203 618 //nothing
igbt6 7:aa4675590203 619 }
igbt6 7:aa4675590203 620 else
igbt6 7:aa4675590203 621 {
igbt6 7:aa4675590203 622 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 7:aa4675590203 623 if(strncmp(respBuf,"OK+Get:0x",9) == 0){
igbt6 7:aa4675590203 624 retVal=(uint16_t)strToHex(&respBuf[9],4);
igbt6 7:aa4675590203 625 }
igbt6 7:aa4675590203 626 }
igbt6 7:aa4675590203 627 return retVal;
igbt6 7:aa4675590203 628 }
igbt6 7:aa4675590203 629
igbt6 7:aa4675590203 630
igbt6 7:aa4675590203 631 ConnectionStatus_t HM11::connectToLastDevice(void)
igbt6 7:aa4675590203 632 {
igbt6 7:aa4675590203 633
igbt6 7:aa4675590203 634 ConnectionStatus_t retVal= _INVALID_CONECTIONSTATUS;
igbt6 7:aa4675590203 635 flushBuffers();
igbt6 7:aa4675590203 636 char buf[9]={"AT+CONNL"};
igbt6 7:aa4675590203 637 buf[8]='\0';
igbt6 7:aa4675590203 638 sendDataToDevice(buf);
igbt6 7:aa4675590203 639 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS*5))
igbt6 7:aa4675590203 640 {
igbt6 7:aa4675590203 641 //nothing
igbt6 7:aa4675590203 642 }
igbt6 7:aa4675590203 643 else
igbt6 7:aa4675590203 644 {
igbt6 7:aa4675590203 645 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 646 if(strncmp(buf,"OK+CONN",7) == 0){
igbt6 7:aa4675590203 647 for(int i=0; i<_INVALID_CONECTIONSTATUS ;++i){
igbt6 7:aa4675590203 648 if(strncmp(&buf[7],&ConnectionStatusArr[i],1) == 0)
igbt6 7:aa4675590203 649 retVal= ( ConnectionStatus_t)i;
igbt6 7:aa4675590203 650 }
igbt6 7:aa4675590203 651 }
igbt6 7:aa4675590203 652 }
igbt6 7:aa4675590203 653 return retVal;
igbt6 7:aa4675590203 654 }
igbt6 7:aa4675590203 655
igbt6 7:aa4675590203 656 ConnectionStatus_t HM11::connectToAnAddress(const char* const macAddress)
igbt6 7:aa4675590203 657 {
igbt6 7:aa4675590203 658 ConnectionStatus_t retVal= _INVALID_CONECTIONSTATUS;
igbt6 7:aa4675590203 659 if(macAddress ==NULL)
igbt6 7:aa4675590203 660 {
igbt6 7:aa4675590203 661 return retVal;
igbt6 7:aa4675590203 662 }
igbt6 7:aa4675590203 663 flushBuffers();
igbt6 7:aa4675590203 664 char buf[19]={"AT+CON"};
igbt6 7:aa4675590203 665 memcpy(&buf[6],macAddress,12);
igbt6 7:aa4675590203 666 buf[18]='\0';
igbt6 7:aa4675590203 667 sendDataToDevice(buf);
igbt6 7:aa4675590203 668 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS*5))
igbt6 7:aa4675590203 669 {
igbt6 7:aa4675590203 670 //nothing
igbt6 7:aa4675590203 671 }
igbt6 7:aa4675590203 672 else
igbt6 7:aa4675590203 673 {
igbt6 7:aa4675590203 674 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 675 if(strncmp(buf,"OK+CONN",7) == 0){
igbt6 7:aa4675590203 676 for(int i=0; i<_INVALID_CONECTIONSTATUS ;++i){
igbt6 7:aa4675590203 677 if(strncmp(&buf[7],&ConnectionStatusArr[i],1) == 0)
igbt6 7:aa4675590203 678 retVal= ( ConnectionStatus_t)i;
igbt6 7:aa4675590203 679 }
igbt6 7:aa4675590203 680 }
igbt6 7:aa4675590203 681 }
igbt6 7:aa4675590203 682 return retVal;
igbt6 7:aa4675590203 683 }
igbt6 7:aa4675590203 684
igbt6 7:aa4675590203 685
igbt6 7:aa4675590203 686 uint8_t HM11::queryInputOutputState(void)
igbt6 7:aa4675590203 687 {
igbt6 7:aa4675590203 688 flushBuffers();
igbt6 7:aa4675590203 689 uint8_t retVal=0xFF;
igbt6 7:aa4675590203 690 char respBuf[12];
igbt6 7:aa4675590203 691 sendDataToDevice("AT+COL??");
igbt6 7:aa4675590203 692 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 693 {
igbt6 7:aa4675590203 694 //nothing
igbt6 7:aa4675590203 695 }
igbt6 7:aa4675590203 696 else
igbt6 7:aa4675590203 697 {
igbt6 7:aa4675590203 698 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 7:aa4675590203 699 if(strncmp(respBuf,"OK+Col:0x",9) == 0){
igbt6 7:aa4675590203 700 retVal=(uint8_t)strToHex(&respBuf[9],2);
igbt6 7:aa4675590203 701 }
igbt6 7:aa4675590203 702 }
igbt6 7:aa4675590203 703 return retVal;
igbt6 7:aa4675590203 704
igbt6 7:aa4675590203 705
igbt6 7:aa4675590203 706 }
igbt6 7:aa4675590203 707
igbt6 7:aa4675590203 708
igbt6 7:aa4675590203 709 bool HM11::setPioCollectionRate (uint8_t colRateSec)
igbt6 7:aa4675590203 710 {
igbt6 7:aa4675590203 711 if(colRateSec>90)
igbt6 7:aa4675590203 712 return false;
igbt6 7:aa4675590203 713 flushBuffers();
igbt6 7:aa4675590203 714 char buf[9]={"AT+CYCxx"};
igbt6 7:aa4675590203 715 hexToString((uint32_t)colRateSec, &buf[6],2);
igbt6 7:aa4675590203 716 buf[8]='\0';
igbt6 7:aa4675590203 717 sendDataToDevice(buf);
igbt6 7:aa4675590203 718 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 719 return false;
igbt6 7:aa4675590203 720 else
igbt6 7:aa4675590203 721 {
igbt6 7:aa4675590203 722 copyAvailableDataToBuf((uint8_t*)buf,sizeof(buf));
igbt6 7:aa4675590203 723 if(strncmp(buf,"OK+Set:",7) == 0){
igbt6 7:aa4675590203 724 uint8_t secVal= (uint8_t)strToHex(&buf[7],2);
igbt6 7:aa4675590203 725 //if(secVal==colRateSec)
igbt6 7:aa4675590203 726 return true;
igbt6 7:aa4675590203 727 }
igbt6 7:aa4675590203 728 }
igbt6 7:aa4675590203 729 return false;
igbt6 7:aa4675590203 730 }
igbt6 7:aa4675590203 731
igbt6 7:aa4675590203 732
igbt6 7:aa4675590203 733 uint8_t HM11::queryPioCollectionRate(void)
igbt6 7:aa4675590203 734 {
igbt6 7:aa4675590203 735 flushBuffers();
igbt6 7:aa4675590203 736 uint8_t retVal=0xFF;
igbt6 7:aa4675590203 737 char respBuf[12];
igbt6 7:aa4675590203 738 sendDataToDevice("AT+CYC??");
igbt6 7:aa4675590203 739 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 740 {
igbt6 7:aa4675590203 741 //nothing
igbt6 7:aa4675590203 742 }
igbt6 7:aa4675590203 743 else
igbt6 7:aa4675590203 744 {
igbt6 7:aa4675590203 745 copyAvailableDataToBuf((uint8_t*)respBuf,sizeof(respBuf));
igbt6 7:aa4675590203 746 if(strncmp(respBuf,"OK+Get:",7) == 0){
igbt6 7:aa4675590203 747 retVal=(uint8_t)strToHex(&respBuf[7],2);
igbt6 7:aa4675590203 748 }
igbt6 7:aa4675590203 749 }
igbt6 7:aa4675590203 750 return retVal;
igbt6 7:aa4675590203 751 }
igbt6 7:aa4675590203 752
igbt6 7:aa4675590203 753
igbt6 7:aa4675590203 754 #if 0
igbt6 7:aa4675590203 755 bool HM11::startDeviceDiscoveryScan(ScanResult_t* scanRes)
igbt6 7:aa4675590203 756 {
igbt6 7:aa4675590203 757
igbt6 7:aa4675590203 758 }
igbt6 7:aa4675590203 759
igbt6 7:aa4675590203 760
igbt6 7:aa4675590203 761 bool HM11::connectToDiscoveryDevice(ScanResult_t* scanRes)
igbt6 7:aa4675590203 762 {
igbt6 7:aa4675590203 763
igbt6 7:aa4675590203 764 }
igbt6 5:9a00e7bb0275 765
igbt6 5:9a00e7bb0275 766
igbt6 5:9a00e7bb0275 767
igbt6 7:aa4675590203 768 bool HM11::setIBeaconDeployMode(DeployMode_t depMode)
igbt6 7:aa4675590203 769 {
igbt6 7:aa4675590203 770
igbt6 7:aa4675590203 771 }
igbt6 5:9a00e7bb0275 772
igbt6 5:9a00e7bb0275 773
igbt6 7:aa4675590203 774 bool HM11::setFilterOfHmModules(FilterOfHmModules_t filter)
igbt6 7:aa4675590203 775 {
igbt6 7:aa4675590203 776
igbt6 7:aa4675590203 777 }
igbt6 5:9a00e7bb0275 778
igbt6 5:9a00e7bb0275 779
igbt6 7:aa4675590203 780 FilterOfHmModules_t HM11::queryFilterOfHmModules(void)
igbt6 7:aa4675590203 781 {
igbt6 7:aa4675590203 782
igbt6 7:aa4675590203 783 }
igbt6 5:9a00e7bb0275 784
igbt6 5:9a00e7bb0275 785
igbt6 7:aa4675590203 786 bool HM11::removeBondInformation(void)
igbt6 7:aa4675590203 787 {
igbt6 7:aa4675590203 788
igbt6 7:aa4675590203 789 }
igbt6 5:9a00e7bb0275 790
igbt6 7:aa4675590203 791 bool HM11::getSystemHelpInformation(char* helpInformationBuf)
igbt6 7:aa4675590203 792 {
igbt6 7:aa4675590203 793
igbt6 7:aa4675590203 794 }
igbt6 5:9a00e7bb0275 795
igbt6 7:aa4675590203 796 bool HM11::setModuleWorkType(ModuleWorkType_t modWorkType)
igbt6 7:aa4675590203 797 {
igbt6 7:aa4675590203 798
igbt6 7:aa4675590203 799 }
igbt6 5:9a00e7bb0275 800
igbt6 5:9a00e7bb0275 801
igbt6 7:aa4675590203 802 ModuleWorkType_t HM11::queryModuleWorkType(void)
igbt6 7:aa4675590203 803 {
igbt6 7:aa4675590203 804
igbt6 7:aa4675590203 805 }
igbt6 5:9a00e7bb0275 806
igbt6 5:9a00e7bb0275 807
igbt6 5:9a00e7bb0275 808
igbt6 5:9a00e7bb0275 809
igbt6 7:aa4675590203 810 bool HM11::setModuleIBeaconSwitch (uint8_t turnOnOff)
igbt6 5:9a00e7bb0275 811
igbt6 5:9a00e7bb0275 812
igbt6 5:9a00e7bb0275 813 uint8_t HM11::queryModuleIBeaconSwitch (void);
igbt6 5:9a00e7bb0275 814
igbt6 5:9a00e7bb0275 815
igbt6 5:9a00e7bb0275 816
igbt6 5:9a00e7bb0275 817 bool HM11::setIBeaconUuid (uint32_t uuid0,uint32_t uuid1,uint32_t uuid2, uint32_t uuid3);
igbt6 5:9a00e7bb0275 818 bool HM11::setIBeaconUuid (uint32_t* uuid);
igbt6 5:9a00e7bb0275 819
igbt6 5:9a00e7bb0275 820
igbt6 5:9a00e7bb0275 821 uint32_t HM11::queryIBeaconUuid(uint32_t* nr_of_uuid);
igbt6 5:9a00e7bb0275 822
igbt6 5:9a00e7bb0275 823
igbt6 5:9a00e7bb0275 824
igbt6 5:9a00e7bb0275 825
igbt6 5:9a00e7bb0275 826 bool HM11::setIBeaconMajor(uint16_t mjrVersion);
igbt6 5:9a00e7bb0275 827
igbt6 5:9a00e7bb0275 828
igbt6 5:9a00e7bb0275 829 uint16_t HM11::queryIBeaconMajor(void);
igbt6 5:9a00e7bb0275 830
igbt6 5:9a00e7bb0275 831
igbt6 5:9a00e7bb0275 832
igbt6 5:9a00e7bb0275 833
igbt6 5:9a00e7bb0275 834 bool HM11::setIBeaconMinor(uint16_t mnrVersion);
igbt6 5:9a00e7bb0275 835
igbt6 5:9a00e7bb0275 836
igbt6 5:9a00e7bb0275 837 uint16_t HM11::queryIBeaconMinor(void);
igbt6 5:9a00e7bb0275 838
igbt6 5:9a00e7bb0275 839
igbt6 5:9a00e7bb0275 840
igbt6 5:9a00e7bb0275 841
igbt6 5:9a00e7bb0275 842 bool HM11::setIBeaconMeasuredPower(uint16_t measuredPwr);
igbt6 5:9a00e7bb0275 843
igbt6 5:9a00e7bb0275 844
igbt6 5:9a00e7bb0275 845
igbt6 5:9a00e7bb0275 846 uint16_t HM11::queryIBeaconMeasuredPower(void);
igbt6 5:9a00e7bb0275 847
igbt6 5:9a00e7bb0275 848
igbt6 5:9a00e7bb0275 849
igbt6 5:9a00e7bb0275 850 bool HM11::setModuleWorkMode(ModuleWorkMode_t workMode);
igbt6 5:9a00e7bb0275 851
igbt6 5:9a00e7bb0275 852
igbt6 5:9a00e7bb0275 853
igbt6 5:9a00e7bb0275 854 ModuleWorkMode_t HM11::queryModuleWorkMode(void);
igbt6 5:9a00e7bb0275 855
igbt6 5:9a00e7bb0275 856
igbt6 5:9a00e7bb0275 857
igbt6 5:9a00e7bb0275 858
igbt6 5:9a00e7bb0275 859 bool HM11::setModuleName(char* name, uint8_t nameLength);
igbt6 5:9a00e7bb0275 860
igbt6 5:9a00e7bb0275 861
igbt6 5:9a00e7bb0275 862 bool HM11::queryModuleName(char *name);
igbt6 5:9a00e7bb0275 863
igbt6 5:9a00e7bb0275 864
igbt6 5:9a00e7bb0275 865
igbt6 5:9a00e7bb0275 866
igbt6 5:9a00e7bb0275 867 bool HM11::setParityBit(ParityBit_t pBit);
igbt6 5:9a00e7bb0275 868
igbt6 5:9a00e7bb0275 869
igbt6 5:9a00e7bb0275 870
igbt6 5:9a00e7bb0275 871 ParityBit_t HM11::queryParityBit(void);
igbt6 5:9a00e7bb0275 872
igbt6 5:9a00e7bb0275 873
igbt6 5:9a00e7bb0275 874 bool HM11::setPio1OutputStatus(uint8_t status);
igbt6 5:9a00e7bb0275 875
igbt6 5:9a00e7bb0275 876
igbt6 5:9a00e7bb0275 877
igbt6 5:9a00e7bb0275 878 uint8_t HM11::queryPio1OutputStatus(void);
igbt6 5:9a00e7bb0275 879
igbt6 0:df4bd867616e 880
igbt6 0:df4bd867616e 881
igbt6 5:9a00e7bb0275 882
igbt6 5:9a00e7bb0275 883
igbt6 5:9a00e7bb0275 884 bool HM11::setPioPinsOutput(uint8_t nrOfPio, uint8_t val );
igbt6 5:9a00e7bb0275 885
igbt6 5:9a00e7bb0275 886
igbt6 5:9a00e7bb0275 887 uint8_t HM11::queryPioPinsOutput(uint8_t nrOfPio);
igbt6 5:9a00e7bb0275 888
igbt6 5:9a00e7bb0275 889
igbt6 5:9a00e7bb0275 890
igbt6 5:9a00e7bb0275 891
igbt6 5:9a00e7bb0275 892 bool HM11::setPinCode (uint32_t pinCode );
igbt6 5:9a00e7bb0275 893
igbt6 5:9a00e7bb0275 894
igbt6 5:9a00e7bb0275 895
igbt6 5:9a00e7bb0275 896 uint8_t HM11::queryPinCode (void);
igbt6 5:9a00e7bb0275 897
igbt6 5:9a00e7bb0275 898
igbt6 5:9a00e7bb0275 899
igbt6 5:9a00e7bb0275 900
igbt6 5:9a00e7bb0275 901 bool HM11::setModulePower(ModulePower_t modPower);
igbt6 5:9a00e7bb0275 902
igbt6 5:9a00e7bb0275 903
igbt6 5:9a00e7bb0275 904
igbt6 5:9a00e7bb0275 905 ModulePower_t HM11::queryModulePower (void);
igbt6 5:9a00e7bb0275 906
igbt6 5:9a00e7bb0275 907
igbt6 5:9a00e7bb0275 908
igbt6 5:9a00e7bb0275 909 bool HM11::setModuleSleepType(uint8_t modSleepType );
igbt6 5:9a00e7bb0275 910
igbt6 5:9a00e7bb0275 911
igbt6 5:9a00e7bb0275 912
igbt6 5:9a00e7bb0275 913 uint8_t HM11::queryModuleSleepType (void);
igbt6 5:9a00e7bb0275 914
igbt6 5:9a00e7bb0275 915
igbt6 5:9a00e7bb0275 916
igbt6 5:9a00e7bb0275 917
igbt6 5:9a00e7bb0275 918 bool HM11::restoreAll(void);
igbt6 5:9a00e7bb0275 919
igbt6 5:9a00e7bb0275 920
igbt6 5:9a00e7bb0275 921 bool HM11::restartModule(void);
igbt6 5:9a00e7bb0275 922
igbt6 5:9a00e7bb0275 923
igbt6 5:9a00e7bb0275 924
igbt6 5:9a00e7bb0275 925 bool HM11::setMasterAndSlaveRole(uint8_t role);
igbt6 5:9a00e7bb0275 926
igbt6 5:9a00e7bb0275 927
igbt6 5:9a00e7bb0275 928
igbt6 5:9a00e7bb0275 929 uint8_t HM11::queryMasterAndSlaveRole(void);
igbt6 5:9a00e7bb0275 930
igbt6 5:9a00e7bb0275 931
igbt6 5:9a00e7bb0275 932
igbt6 5:9a00e7bb0275 933
igbt6 5:9a00e7bb0275 934 uint8_t HM11::queryRssiValue(void);
igbt6 5:9a00e7bb0275 935
igbt6 5:9a00e7bb0275 936
igbt6 5:9a00e7bb0275 937
igbt6 5:9a00e7bb0275 938
igbt6 5:9a00e7bb0275 939 char* HM11::queryLastConnectedDeviceAddress(void);
igbt6 5:9a00e7bb0275 940
igbt6 5:9a00e7bb0275 941
igbt6 5:9a00e7bb0275 942
igbt6 5:9a00e7bb0275 943
igbt6 5:9a00e7bb0275 944 bool HM11::setModuleSensorWorkInterval(uint8_t interval);
igbt6 5:9a00e7bb0275 945
igbt6 5:9a00e7bb0275 946
igbt6 5:9a00e7bb0275 947
igbt6 5:9a00e7bb0275 948 uint8_t HM11::queryModuleSensorWorkInterval(void);
igbt6 5:9a00e7bb0275 949
igbt6 5:9a00e7bb0275 950
igbt6 5:9a00e7bb0275 951
igbt6 5:9a00e7bb0275 952 bool HM11::workImmediately(void);
igbt6 5:9a00e7bb0275 953
igbt6 5:9a00e7bb0275 954
igbt6 5:9a00e7bb0275 955
igbt6 5:9a00e7bb0275 956 bool HM11::queryModuleIntoSleepMode(void);
igbt6 5:9a00e7bb0275 957
igbt6 5:9a00e7bb0275 958
igbt6 5:9a00e7bb0275 959
igbt6 5:9a00e7bb0275 960 bool HM11::setModuleSaveConnectedAddressParam(uint8_t saveParam);
igbt6 5:9a00e7bb0275 961
igbt6 5:9a00e7bb0275 962
igbt6 5:9a00e7bb0275 963 uint8_t HM11::queryModuleSaveConnectedAddressParam(void);
igbt6 5:9a00e7bb0275 964
igbt6 5:9a00e7bb0275 965
igbt6 5:9a00e7bb0275 966
igbt6 5:9a00e7bb0275 967 bool HM11::setSensorTypeOnModulePio(SensorType_t sensorType);
igbt6 5:9a00e7bb0275 968
igbt6 5:9a00e7bb0275 969
igbt6 5:9a00e7bb0275 970
igbt6 7:aa4675590203 971 SensorType_t HM11::querySensorTypeOnModulePio(void);
igbt6 5:9a00e7bb0275 972
igbt6 5:9a00e7bb0275 973
igbt6 5:9a00e7bb0275 974 bool HM11::setDiscoveryParameter (SensorType_t discoverParam);
igbt6 5:9a00e7bb0275 975
igbt6 0:df4bd867616e 976
igbt6 5:9a00e7bb0275 977 uint8_t HM11::queryDiscoveryParameter (void);
igbt6 5:9a00e7bb0275 978
igbt6 5:9a00e7bb0275 979
igbt6 5:9a00e7bb0275 980
igbt6 5:9a00e7bb0275 981
igbt6 5:9a00e7bb0275 982 bool HM11::queryModuleSensorTempAndHumidity(uint8_t* temp, uint8_t* hum);
igbt6 5:9a00e7bb0275 983
igbt6 5:9a00e7bb0275 984
igbt6 5:9a00e7bb0275 985
igbt6 5:9a00e7bb0275 986 bool HM11::queryDS18B20SensorTemperature (uint8_t* temp);
igbt6 5:9a00e7bb0275 987
igbt6 5:9a00e7bb0275 988
igbt6 5:9a00e7bb0275 989
igbt6 5:9a00e7bb0275 990
igbt6 5:9a00e7bb0275 991 bool HM11::setModuleConnectRemoteDeviceTimeoutValue(uint32_t timeout);
igbt6 5:9a00e7bb0275 992
igbt6 5:9a00e7bb0275 993
igbt6 5:9a00e7bb0275 994
igbt6 5:9a00e7bb0275 995
igbt6 5:9a00e7bb0275 996 uint32_t HM11::queryModuleConnectRemoteDeviceTimeoutValue(void);
igbt6 5:9a00e7bb0275 997
igbt6 5:9a00e7bb0275 998
igbt6 5:9a00e7bb0275 999
igbt6 5:9a00e7bb0275 1000 bool HM11::setModuleBondMode(BondMode_t bondMode);
igbt6 5:9a00e7bb0275 1001
igbt6 5:9a00e7bb0275 1002
igbt6 5:9a00e7bb0275 1003
igbt6 5:9a00e7bb0275 1004 BondMode_t HM11::queryModuleBondMode(void);
igbt6 5:9a00e7bb0275 1005
igbt6 5:9a00e7bb0275 1006
igbt6 5:9a00e7bb0275 1007
igbt6 5:9a00e7bb0275 1008
igbt6 5:9a00e7bb0275 1009
igbt6 5:9a00e7bb0275 1010 bool HM11::setServiceUuid (uint16_t serviceUuid);
igbt6 5:9a00e7bb0275 1011
igbt6 5:9a00e7bb0275 1012
igbt6 5:9a00e7bb0275 1013
igbt6 5:9a00e7bb0275 1014 uint16_t HM11::queryServiceUuid(void);
igbt6 5:9a00e7bb0275 1015
igbt6 5:9a00e7bb0275 1016
igbt6 5:9a00e7bb0275 1017
igbt6 5:9a00e7bb0275 1018
igbt6 5:9a00e7bb0275 1019 bool HM11::setUartSleepType (uint8_t sleepType);
igbt6 5:9a00e7bb0275 1020
igbt6 5:9a00e7bb0275 1021
igbt6 5:9a00e7bb0275 1022
igbt6 5:9a00e7bb0275 1023 uint8_t HM11::queryUartSleepType(void);
igbt6 7:aa4675590203 1024 #endif
igbt6 7:aa4675590203 1025
igbt6 7:aa4675590203 1026 bool HM11::querySoftwareVersion(char* verBuf, uint8_t bufLen)
igbt6 7:aa4675590203 1027 {
igbt6 7:aa4675590203 1028 if(!verBuf)
igbt6 7:aa4675590203 1029 {
igbt6 7:aa4675590203 1030 return false;
igbt6 7:aa4675590203 1031 }
igbt6 7:aa4675590203 1032 flushBuffers();
igbt6 7:aa4675590203 1033 sendDataToDevice("AT+VERR?");
igbt6 7:aa4675590203 1034 if(!waitForData(WAIT_FOR_DATA_TIMEOUT_MS))
igbt6 7:aa4675590203 1035 return false;
igbt6 7:aa4675590203 1036 else
igbt6 7:aa4675590203 1037 {
igbt6 7:aa4675590203 1038 copyAvailableDataToBuf((uint8_t*)verBuf,bufLen);
igbt6 7:aa4675590203 1039 return true;
igbt6 7:aa4675590203 1040 }
igbt6 7:aa4675590203 1041
igbt6 7:aa4675590203 1042
igbt6 7:aa4675590203 1043 }
igbt6 5:9a00e7bb0275 1044