1

I am trying to read data from an a & d UA-767PBT-C Blood Pressure Monitor which is certified by the continua health alliance. I am following this example Bluetooth Example . I use this example to connect to the device and retrieve data in byte format but I don't know how to set system and config id in Association response array. I am trying to follow IEEE 11073 - 10407.

Here is the code.

@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) {}
     }
}

I am getting this Request

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  bc
00  81
01  00
00  00  00  00

I think 00 09 1f ff fe 80 36 b7 this has been Manufacturer - and device specific id, so how to set Device specific in Association Response.

phuclv
  • 37,963
  • 15
  • 156
  • 475
mari
  • 11
  • 3
  • Check this out: http://stackoverflow.com/questions/10402291/parsing-data-from-hdp-device-for-android-api-15 – longwalker Jan 08 '14 at 11:08

1 Answers1

0

In E3 message you should respond with manager's system ID. Most agents will accept a random or fake manager system ID like 11:22:33:44:55:66:77:88.

Ideally you should base your system ID in your Bluetooth MAC address, since it is guaranteed to be unique. Convert the MAC to EUI-64 (basically 11:22:33:44:55:66 becomes 11:22:33:ff:ff:44:55:66). Other unique MAC e.g network interface are ok, too.

epx
  • 1,066
  • 9
  • 17