Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found the solution. I needed the exact number of bytes that my sensor was sending + the way my sensor is sending the information. </p> <p>I will put the part of the class that parse the data for my blood pressure monitor.</p> <pre><code> public String byte2hex(byte[] b) { // String Buffer can be used instead String hs = ""; String stmp = ""; for (int n = 0; n &lt; b.length; n++) { stmp = (java.lang.Integer.toHexString(b[n] &amp; 0XFF)); if (stmp.length() == 1) { hs = hs + "0" + stmp; } else { hs = hs + stmp; } if (n &lt; b.length - 1) { hs = hs + ""; } } return hs; } public static int byteToUnsignedInt(byte b) { return 0x00 &lt;&lt; 24 | b &amp; 0xff; } // Thread to read incoming data received from the HDP device. This sample application merely // reads the raw byte from the incoming file descriptor. The data should be interpreted using // a health manager which implements the IEEE 11073-xxxxx specifications. private class ReadThread extends Thread { private ParcelFileDescriptor mFd; public ReadThread(ParcelFileDescriptor fd) { super(); mFd = fd; } @Override public void run() { FileInputStream fis = new FileInputStream(mFd.getFileDescriptor()); byte data[] = new byte[300]; try { while(fis.read(data) &gt; -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. if (data[0] != (byte) 0x00) { String test = byte2hex(data); Log.i(TAG, test); if(data[0] == (byte) 0xE2){ Log.i(TAG, "E2"); 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"); //work for legacy device... if (data[18] == (byte) 0x0d &amp;&amp; data[19] == (byte) 0x1d) //fixed report { count = 3; //set invoke id so get correct response invoke = new byte[] { data[6], data[7] }; //write back response (new WriteThread(mFd)).start(); //parse data!! int length = data[21]; Log.i(TAG, "length is " + length); // check data-req-id int report_no = data[22+3]; int number_of_data_packets = data[22+5]; //packet_start starts from handle 0 byte int packet_start = 30; final int SYS_DIA_MAP_DATA = 1; final int PULSE_DATA = 2; final int ERROR_CODE_DATA = 3; for (int i = 0; i &lt; number_of_data_packets; i++) { int obj_handle = data[packet_start+1]; switch (obj_handle) { case SYS_DIA_MAP_DATA: int sys = byteToUnsignedInt(data[packet_start+9]); int dia = byteToUnsignedInt(data[packet_start+11]); int map = byteToUnsignedInt(data[packet_start+13]); //create team string... 9+13~9+20 Log.i(TAG, "sys is "+ sys); sendMessage(RECEIVED_SYS, sys); Log.i(TAG, "dia is "+ dia); sendMessage(RECEIVED_DIA, dia); Log.i(TAG, "map is "+ map); //test // sendMessage(RECEIVED_MAP, map); break; case PULSE_DATA: //parse int pulse = byteToUnsignedInt(data[packet_start+5]); Log.i(TAG, "pulse is " + pulse); sendMessage(RECEIVED_PUL, pulse); break; case ERROR_CODE_DATA: //need more signal break; } packet_start += 4 + data[packet_start+3]; //4 = ignore beginning four bytes } } else { count = 2; } } else if (data[0] == (byte) 0xE4) { count = 4; (new WriteThread(mFd)).start(); // sendMessage(); } //zero out the data for (int i = 0; i &lt; 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()); // FileInputStream fis = new FileInputStream(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) invoke[0], (byte) invoke[1], (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 }; final byte data_RRQ[] = new byte[] { (byte) 0xE4, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00 }; final byte data_ABORT[] = new byte[] { (byte) 0xE6, (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 Responsed!"); } else if (count == 2) { fos.write(get_MDS); Log.i(TAG, "Get MDS object attributes!"); // fos.write(data_ABORT); } 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) {} } } </code></pre> <p>In order to understand this code you have to read the IEEE 11073 specifications also. Every kind of sensor has his own number of bytes. </p> <p>I didn't do this code, someone gave it to me. If he asks me to remove it, I will :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload