从hdp设备获取关联请求数据for android

时间:2013-11-05 12:18:03

标签: android android-bluetooth

我正在尝试从a& amp; d UA-767PBT-C血压监测仪,由连续健康联盟认证。我正在关注此示例Bluetooth Example。我使用此示例连接到设备并以字节格式检索数据但我不知道如何在关联响应数组中设置系统和配置ID。我正在尝试关注IEEE 11073 - 10407

这是代码。

@Override
    public void run() {
        Log.e("TEST", "Read Data 1");
        FileInputStream fis = new FileInputStream(mFd.getFileDescriptor());
        final byte data[] = new byte[8192];
        Log.i(TAG, "Read Data 2");
        try {
                   while(fis.read(data) > -1) {
                // At this point, the application can pass the raw data to a parser that
                // has implemented the IEEE 11073-xxxxx specifications.  Instead, this sample
                // simply indicates that some data has been received.                

                 Log.i(TAG, "INBOUND");
                 String test = byte2hex(data);
                 Log.i(TAG, test);

                  if (data[0] != (byte) 0x00)
                  {

                      if(data[0] == (byte) 0xE2){
                          Log.i(TAG, "E2 - Association Request");

                          count = 1;

                          (new WriteThread(mFd)).start();
                          try {
                              sleep(100);
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }
                          count = 2;
                          (new WriteThread(mFd)).start();
                      }
                      else if (data[0] == (byte)0xE7){
                          Log.i(TAG, "E7 - Data Given");
                          System.out.println("Total file size to read (in bytes) : "+ fis.available());
                         if(data[3] != (byte)0xda){

                              invoke[0] = data[6];
                              invoke[1] = data[7];

                                 Log.i(TAG, "E7 - Reading?");
                                 ByteBuffer sys = ByteBuffer.allocate(2);
                                  sys.order(ByteOrder.LITTLE_ENDIAN);
                                  sys.put(data[45]);
                                  sys.put(data[46]);
                                  short sysVal = sys.getShort(0);
                                  Log.i(TAG, " Sys - "+sysVal);

                                 ByteBuffer dia = ByteBuffer.allocate(2);
                                  dia.order(ByteOrder.LITTLE_ENDIAN);
                                  dia.put(data[47]);
                                  dia.put(data[48]);
                                  short diaVal = dia.getShort(0);
                                  Log.i(TAG, " Dia - "+diaVal);

                                  sendMessage(9919, diaVal);
                                  sendMessage(9920, sysVal);

                                for(int i=0; i<(data.length-2); i++){
                                  ByteBuffer bb = ByteBuffer.allocate(2);
                                  bb.order(ByteOrder.LITTLE_ENDIAN);
                                  bb.put(data[i]);
                                  bb.put(data[i+1]);
                                  short shortVal = bb.getShort(0);
                                 // Log.i(TAG, i+" Short Val - "+shortVal);

                              }

                                count = 3; 
                                //set invoke id so get correct response 
                                (new WriteThread(mFd)).start();                              
                          }

                          //parse data!!
                      }
                      else if (data[0] == (byte) 0xE4)
                      {
                          //count = 4;
                         // (new WriteThread(mFd)).start();
                      }
                      //zero out the data
                      for (int i = 0; i < data.length; i++){
                          data[i] = (byte) 0x00;
                      }
                  }
                  sendMessage(STATUS_READ_DATA, 0);
             }
         } catch(IOException ioe) {}
         if (mFd != null) {
             try {
                 mFd.close();
             } catch (IOException e) { /* Do nothing. */ }
         }
         sendMessage(STATUS_READ_DATA_DONE, 0);
     }
 }

 private class WriteThread extends Thread {
     private ParcelFileDescriptor mFd;

     public WriteThread(ParcelFileDescriptor fd) {
         super();
         mFd = fd;
     }

     @Override
     public void run() {
         FileOutputStream fos = new FileOutputStream(mFd.getFileDescriptor());
         final byte data_AR[] = new byte[] {         (byte) 0xE3, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x2C, 
                                                     (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x50, (byte) 0x79,
                                                     (byte) 0x00, (byte) 0x26,
                                                     (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x80, (byte) 0x00,
                                                     (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x08,  //bt add for phone, can be automate in the future
                                                     (byte) 0x3C, (byte) 0x5A, (byte) 0x37, (byte) 0xFF, 
                                                     (byte) 0xFE, (byte) 0x95, (byte) 0xEE, (byte) 0xE3,


                                                     (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x00, 
                                                     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};

         final byte data_DR[] = new byte[] {         (byte) 0xE7, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x12,
                                                     (byte) 0x00, (byte) 0x10,
                                                     (byte) 0x00, (byte) 0x24,
                                                     (byte) 0x02, (byte) 0x01,
                                                     (byte) 0x00, (byte) 0x0A,
                                                     (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x0D, (byte) 0x1D,
                                                     (byte) 0x00, (byte) 0x00 };

         final byte get_MDS[] = new byte[] {         (byte) 0xE7, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x0E,
                                                     (byte) 0x00, (byte) 0x0C,
                                                     (byte) 0x00, (byte) 0x24,
                                                     (byte) 0x01, (byte) 0x03,
                                                     (byte) 0x00, (byte) 0x06,
                                                     (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x00 };

         final byte data_RR[] = new byte[] {         (byte) 0xE5, (byte) 0x00,
                                                     (byte) 0x00, (byte) 0x02,
                                                     (byte) 0x00, (byte) 0x00 };


         try {
             Log.i(TAG, String.valueOf(count));
             if (count == 1)
             {
                 fos.write(data_AR);
                 Log.i(TAG, "Association Responded!");
             }  
             else if (count == 2)
             {
                 fos.write(get_MDS);
                 Log.i(TAG, "Get MDS object attributes!");
             }
             else if (count == 3) 
             {
                 fos.write(data_DR);
                 Log.i(TAG, "Data Responsed!");
             }
             else if (count == 4)
             {
                 fos.write(data_RR);
                 Log.i(TAG, "Data Released!");
             }
         } catch(IOException ioe) {}
     }
}

我收到此请求

e2 00 00 32 80 00 00 00 00 01 00 2a 50 79
00 26 80 00 00 00 80 00
80 00 00 00 00 00 00 00 00 80 00 00 00 08 00 09 1f ff fe 80 36 b7 公元前02年 00 81 01 00 00 00 00 00

我认为“00 09 1f ff fe 80 36 b7”这是Manufaturer - 以及设备特定的ID,因此如何在关联响应中设置设备特定。

提前致谢

1 个答案:

答案 0 :(得分:0)

在E3消息中,您应该使用经理的系统ID进行回复。大多数代理都会接受一个随机或假的经理系统ID,如11:22:33:44:55:66:77:88。

理想情况下,您应将系统ID作为蓝牙MAC地址的基础,因为它保证是唯一的。将MAC转换为EUI-64(基本上11:22:33:44:55:66变为11:22:33:ff:ff:44:55:66)。其他独特的MAC例如网络接口也可以。