Exemplo n.º 1
0
String BLE::readIncoming(){ 
  int i=0;
  char stringBase[CHARS_TO_READ];
	for (int i=0; i<CHARS_TO_READ; i++){
    stringBase[i] = 1;
  }
  String finalString="";
  if (ble_available()){
    while (ble_available()){
      int carrier = ble_read();
      Serial.write (carrier);
      if (i<CHARS_TO_READ){
        stringBase [i] = carrier;
      }
      i++;
    }
    for (i=0;i<CHARS_TO_READ;i++){
      finalString = finalString + stringBase[i];
    }
    Serial.println("");
    Serial.println (finalString);
    return finalString;
  }
  ble_do_events();
}
Exemplo n.º 2
0
void rs_ble_process(void)
{
    while (ble_available())
    {
        byte cmd;
        cmd = ble_read();
        Serial.write(cmd);

        // Parse data here
        switch (cmd)
        {
        case 'V': // query protocol version
        {
            byte buf[] = {'V', PROTOCOL_MAJOR, PROTOCOL_MINOR, PROTOCOL_BUGFIX};
            ble_write_string(buf, 4);
        }
        break;

            // send out any outstanding data
        ble_do_events();
        buf_len = 0;

        return; // only do this task in this loop
        }

        // process text data
        if (Serial.available())
        {
            byte d = 'Z';
            ble_write(d);

            delay(5);
            while (Serial.available())
            {
                d = Serial.read();
                ble_write(d);
            }

            ble_do_events();
            buf_len = 0;

            return;
        }

        ble_do_events();
        buf_len = 0;
    }
}
Exemplo n.º 3
0
uint16_t readPacket(uint16_t timeout) {
	uint16_t origtimeout = timeout;
	uint16_t replyidx = 0;

	memset(packetbuffer, 0, READ_BUFF_LEN);

	while (timeout--) {
		if (replyidx >= READ_BUFF_LEN) break;
		if ((packetbuffer[1] == 'A') && (replyidx == PACKET_ACC_LEN))
		  break;
		if ((packetbuffer[1] == 'G') && (replyidx == PACKET_GYRO_LEN))
		  break;
		if ((packetbuffer[1] == 'M') && (replyidx == PACKET_MAG_LEN))
		  break;
		if ((packetbuffer[1] == 'Q') && (replyidx == PACKET_QUAT_LEN))
		  break;
		if ((packetbuffer[1] == 'B') && (replyidx == PACKET_BUTTON_LEN))
		  break;
		if ((packetbuffer[1] == 'C') && (replyidx == PACKET_COLOR_LEN))
		  break;
		if ((packetbuffer[1] == 'L') && (replyidx == PACKET_LOCATION_LEN))
		  break;

		while (ble_available()) {
		  char c = ble_read();
		  if (c == '!') {
			replyidx = 0;
		  }
		  packetbuffer[replyidx] = c;
		  replyidx++;
		  timeout = origtimeout;
		}
	}

	packetbuffer[replyidx] = '\0';

	return replyidx;
}