Question

Hi Currently I am working on Android that communicates with Healthcare device through bluetooth. The Healthcare device can send data packets like this format enter image description here

Now I want to know, how can I identify the LSB , Acces code, Header , Msb and Payload separately. and how can I retrieve the data from this packets. Really I am new for this kind of data packets development. I have googled, but I got theoretical solutions only. Also I want to know, whether I can use Datagrampacket or someother 3rd party API. Kindly someone suggest me some ideas and tutorial for this. Thanks in advance.

Was it helpful?

Solution

Try to use the following method:

(2475 bits? it maybe should be 2472 or 2480, or if header is 54 bits, here should be 2474 bits) // read bytes

public byte[] readBytes(InputStream inputStream, int length)
        throws IOException {
    byte[] data = new byte[length];
    int len = inputStream.read(data);
    if (len != length) {
        throw new IOException("Read the end of stream.");
    }
    return data;
}


//Get Header data
byte[] headerData = readBytes(inputStream, 9);

// I think header data need to parse again, its structure should look like the following format:
// | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
// |  Version  | Type  | other values  |
// You can parse them to use headerData


// #######################################
// write bytes
public class ByteWriter {
    private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    public void writeBytes(byte[] data) {
        try {
            outputStream.write(data);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public byte[] getBytes() {
        return outputStream.toByteArray();
    }
}

OTHER TIPS

DataInputStream is your friend here. Wrap it around a ByteArrayInputStream wrapped around the DatagramPacket's data, offset, and length. Then use readBytes() into a 9-byte array to get the access code, readBytes() into a 7-byte array to get the header, and the rest is the payload.

EDIT:

Is the header really 54 bits? Surely that should be 56?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top