1

我正在尝试从经 continua 健康联盟认证的 a & d UA-767PBT-C 血压计读取数据。我正在关注这个示例蓝牙示例。我使用此示例连接到设备并以字节格式检索数据,但我不知道如何在关联响应数组中设置系统和配置 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 0 1 0 2 fe 80 0 8 1b6 00 00 00 00

我认为“00 09 1f ff fe 80 36 b7”这是制造商 - 和设备特定的 id,所以如何在关联响应中设置设备特定。

提前致谢

4

1 回答 1

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 例如网络接口也可以。

于 2014-02-03T16:21:29.673 回答