【问题标题】:Parsing data from hdp device for android (API 15)为 android (API 15) 从 hdp 设备解析数据
【发布时间】:2012-05-01 18:26:41
【问题描述】:

我正在使用 HDP 样本并且我有一个血压传感器 (http://www.andonline.com/medical/products/details.php?catname=&product_num=UA-767PBT-C)。我从中获取数据,但我不知道如何将其解析为人类可读的内容。

这是我到目前为止尝试过的类似:

while(fis.read(data) > -1) {
    String value = null;
    BigInteger bi = new BigInteger(data);
//  for(byte b:data){
//  value+=b;
//  }

Log.d("read data binary", "the data "+bi.toString(2));

Log.d("read data decimal", "the data "+bi.toString());

Log.d("read data hexa", "the data "+bi.toString(16));

Log.d("read data pure", "the data "+data);

//  Log.d("read data in for", "the data "+value);

我得到类似的东西:

05-01 20:17:56.208: D/读取数据 hexa(4760): 数据 -1dffffcd7ffffffffffeffd5af86ffd97fffffff7fff7fffffffffffffffff7ffffffff7fff6e000017fe6c9fd43ff7eff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000 05-01 20:17:56.208: D/read data pure(4760): data [B@40d67e70 05-01 20:18:04.626: D/读取数据二进制(4760): 数据 -110011111111111111111111111011111111111111101111111111111111111111111111111101111111111010101101011111000011011111111110110010111111111111111111111111111111101111111111111110111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111110111111111111111011011100000000000000000000101111111111001101100100111111101010000111111111101111110111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000 05-01 20:18:06.828: D/读取数据十进制(4760): 数据 -203483507623964781610218719833861340460918935320904849054826996973692212900285476197647499772786807984696267047422351406943162406714296923378646392438704818362867019189849993530103234365119577738544176433177364624068862392992901519284448514473688206404005826750478658059508398487180499949035108268573187011384599769615567388654196859225287363349524343271404878569910576038256974485069804030507396187288880142469615898657994598968032989468358701985707163618915752929600745406860961079452568357715196894572564385347417575611475027392430694878049004072567761218539330639315281572039366704383280261951128185977081937759030062219162664593674401060911385926104801976141725106633060178277874430092731819952568055910679400056160291437194725741498877422792177927866087804844748805287492049909591381910049388910000637113587878240402231324799724167595846428663821085411205761607676775977154803865471218818490321927526332605816114070118531572541219887175737348779691340524247685177555831457206317744836040630818 8043261097391951856669084073248391766969328193408087247264353820440933377209514919375454398130381686222660290093218573129121807834335990914182695052225998106597956582535377191830950390919540025027059209734614018025566132349868052584032158815617147418533481951314841544372823437950760035922909328107447324379068459903420819908868333845467762117448349119107435197135853702869031565309902860223223087190265613764383087728394617070088277592134524912445849688789334454153786117044615561891588915445731627993181088675874177846601581426666250232501925200827555296394941750552779057995067863069484735138592702326316967441877426926005406201859752313341431828171632110667601912597112032036967791582437329998137610049361593209658390573399893860488034420997950720738946188156666873056610593369750505312862648871480417856338695744176712735994665504506469735806155137102735528258021736665395368914921795726833582479473805755597382350595884770119090657200337921113157209955019412313340263710438956158906491725519433 4844269183378807442410026970212304915398750162342030862720562356574960395088223916289512342191699176716017309140213638536098383639091011729776310430620082118888497862622038695401701710387402100087840950940846152066514765108855402410952099725385450736354603210781118974198215554193785785859382435002755250153009251411946038850315108576684984106702193657963347897709677566091677495576556681656068507314031372074156531214767021895212919495909358260588291818568553609578646758938365326563499166628415041706131521582622947791012917744251071555344476280175567553030365868879087958701356749275597544555441192209535828193783528540378443653793007478915664994969246893177676787034473169357958664807853394146528881072611495728346161885141354339050534315795112871110590890270640490572109200167490678091854953195502952814139817930997734428369811037792170901222000605941722889749066363212792188473959033320542149557873698406208807103283915464017738102761293835485103233871320167686509199843523640244281618906825238 8704413636282358447484621331032763011748386630715517268803987946565620349685791872315647315974663120852929314016264250312193673728801056695240217037954879300746602696068528503485619431744810596830479390072102256014904786379885200942541768018547285509315725810721925773238012551233765684211428599316991837817953275466249315099369637182036791450816547726156761439504911564577098798332137708614741665500028938950045393781414044845143215012544251865843063173228201190800735212465830239288556807716748344594855471404581795834110005529467215574659415846075926847599736673285344205312003601250493931652499391254622736559430124527961987196078914467096385259391360413766722244649547657680034992096702577430954894595554850121644988549721985474054339838378401514140718491721345155113453203729983438697193186989951240978305861633125655220991083790883839070297950011795570337329258541064849259920462519944182465104446414261854674373272689594776034634115872550871119607276667510942677335656704702543291850668190493 47190875320805571892878980923324446702125088753

请问有人知道如何解析它吗?

PS:很抱歉把所有东西都放在了 logcat 中,但也许有人发现了任何联系

【问题讨论】:

  • 能否至少告诉我们血液传感器的品牌和型号?
  • 我刚刚在问题中添加了它。很抱歉没有意识到这是必要的:)
  • 看看这对你有没有好处:wiki.eclipse.org/OHF_SODA_Stepstone
  • 你好 Diana C,我也在开发相同的模块来从血压和脉搏信息医疗保健设备中检索信息。我能够与设备连接,但无法从设备中检索数据。我也使用过 BLE 和 GATT,所以它只适用于 Android 4.4+。如何从设备中检索信息以及如何使其与所有 android 设备兼容?你能帮我么?你能发给我任何演示吗?我也发布了问题。 stackoverflow.com/questions/29531224/…

标签: android parsing android-4.0-ice-cream-sandwich android-sensors health-monitoring


【解决方案1】:

我找到了解决方案。我需要传感器发送的确切字节数+传感器发送信息的方式。

我将把解析数据的部分用于我的血压计。

 public String byte2hex(byte[] b)
    {
     // String Buffer can be used instead
       String hs = "";
       String stmp = "";

       for (int n = 0; n < b.length; n++)
       {
          stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));

          if (stmp.length() == 1)
          {
             hs = hs + "0" + stmp;
          }
          else
          {
             hs = hs + stmp;
          }

          if (n < b.length - 1)
          {
             hs = hs + "";
          }
       }

       return hs;
    }

    public static int byteToUnsignedInt(byte b) {
        return 0x00 << 24 | b & 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) > -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 && 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 < 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 < 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) {}
        }
    }

为了理解此代码,您还必须阅读 IEEE 11073 规范。每种传感器都有自己的字节数。

这段代码不是我做的,有人给我的。如果他要求我删除它,我会:)

【讨论】:

  • 您能否详细解释您的答案,因为我一直在解析来自 hdp 设备的数据。请帮帮我,你是怎么解决的。
  • 非常感谢......我会用我的设备检查......并让你知道。
  • @Diana C 我也需要实现这个。你能告诉我 IEEE 11073 规范仅在 IEEE 网站或任何其他来源上可用。我的意思是它们是否可以作为开源提供?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-12
  • 1970-01-01
  • 1970-01-01
  • 2011-05-15
  • 1970-01-01
相关资源
最近更新 更多