示例#1
0
 bool Client::canDecode(char data[],int start, int end)
 {
     int len = end-start;
     if (data[start]==MessageType::response && len >=9)
     {
         
         int payLoadSize = 0;
         payLoadSize = bytesToInteger(data,start+5);
         if ((payLoadSize+9)>len)
         {
             return false;
         }
     }
     else if(data[start]==MessageType::update  && len >=8)
     {
         int payLoadSize = 0;
         payLoadSize = bytesToInteger(data,start+4);
         if ((payLoadSize+8)>len)
         {
             return false;
         }
     }
     else
     {
         return false;
     }
     return true;
 }
示例#2
0
		notify* buildNotify(char *data, int index)
		{
			notify *res = new notify;
			res->messageType = data[index+0];
			res->updateType = data[index+1];
			res->reserved = data[index+2];
			res->payLoadType = data[index+3];
			res->payLoadSize = bytesToInteger(data,index+4);
			res->payLoad = new byte[res->payLoadSize];
			for(int i=0; i<res->payLoadSize; ++i)
				res->payLoad[i] = data[8+index+i];

			return res;
		}
void TimeState::incomingMessageCallback(const struct ble_msg_attributes_value_evt_t *msg) {
    isWaitingForResponse = false;
    if(msg -> value.data[0] == 0x02)//Time return
    {
      byte b[4] = {
        msg -> value.data[4], msg -> value.data[3], msg -> value.data[2], msg -> value.data[1] };
      long timeStamp = bytesToInteger(b);
      Serial.print(F("TimeStamp: "));
      Serial.println(timeStamp);
      setTime(timeStamp);
      long timeZoneOffset = 60*60*TIME_ZONE_OFFSET;
      adjustTime(timeZoneOffset);//Adjusting time zone . . . 
      renderClockType1();
    }
}
示例#4
0
		response * buildResponse(char *data, int index)
		{
			response *res = new response;
			res->messageType = data[index+0];
			res->requestType = data[index+1];
			res->resultCode = data[index+2];
			res->reserved = data[index+3];
			res->payLoadType = data[index+4];
			res->payLoadSize = bytesToInteger(data,index+5);
			res->payLoad = new byte[res->payLoadSize];
			for(int i=0; i<res->payLoadSize; ++i)
				res->payLoad[i] = data[9+index+i];

			return res;
		}