我正在尝试从经 continua 健康联盟认证的 Omron 708-BT 血压计读取数据。我正在关注这个蓝牙 HDP 应用程序的示例。我正在设法连接到设备并以字节格式检索数据,但无法解析数据以获取所需的值。我正在尝试遵循本PDF第 19 页指定的 IEEE 血压规范。
这是已添加到上面链接的示例代码中的代码。
//Variables in the class
private int count;
private byte[] invoke = {0x00, 0x00};
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());
final byte data[] = new byte[300];
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.e("Test", data.toString());
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();
}
Log.i(TAG, "Seconds Write Thread");
count = 2;
(new WriteThread(mFd)).start();
}
else if (data[0] == (byte)0xE7){
Log.i(TAG, "E7");
count = 3;
//set invoke id so get correct response
invoke = new byte[] { data[6], data[7] };
(new WriteThread(mFd)).start();
//parse data!!
int number_of_data_packets = data[25];
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 < number_of_data_packets; i++){
Log.e("TEST", Integer.toString(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.e("RESULT", "sys is "+ sys);
sendMessage(RECEIVED_SYS, sys);
Log.e("RESULT", "dia is "+ dia);
sendMessage(RECEIVED_DIA, dia);
Log.e("RESULT", "map is "+ map);
break;
case PULSE_DATA:
//parse
int pulse = byteToUnsignedInt(data[packet_start+5]);
Log.e("RESULT", "pulse is " + pulse);
sendMessage(RECEIVED_PUL, pulse);
break;
case ERROR_CODE_DATA:
//need more signal
break;
}
packet_start += 1;//4 + data[packet_start+3]; //4 = ignore beginning four bytes
}
}
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) 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 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) {}
}
数据的十六进制表示如下。我相信这些数据包含血压值的值,但可能是错误的。我相信这是因为在上面链接的 PDF 中,数据将以十六进制值 e7 开头。
03-23 20:14:44.186: I/BluetoothHDPService(23652):