Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

A core logic error in receive data #42

Open
iamwent opened this issue Dec 9, 2015 · 0 comments
Open

A core logic error in receive data #42

iamwent opened this issue Dec 9, 2015 · 0 comments

Comments

@iamwent
Copy link

iamwent commented Dec 9, 2015

public void run() {
    byte[] buffer;
    ArrayList<Integer> arr_byte = new ArrayList<Integer>();

    // Keep listening to the InputStream while connected
    while (true) {
        try {
            int data = mmInStream.read();
            if(data == 0x0A) { 
            } else if(data == 0x0D) {
                buffer = new byte[arr_byte.size()];
                for(int i = 0 ; i < arr_byte.size() ; i++) {
                    buffer[i] = arr_byte.get(i).byteValue();
                }
                // Send the obtained bytes to the UI Activity
                mHandler.obtainMessage(BluetoothState.MESSAGE_READ
                        , buffer.length, -1, buffer).sendToTarget();
                arr_byte = new ArrayList<Integer>();
            } else {
                arr_byte.add(data);
            }
        } catch (IOException e) {
            connectionLost();
            // Start the service over to restart listening mode
            BluetoothService.this.start(BluetoothService.this.isAndroid);
            break;
        }
    }
}

data: 0A 0D 01 02 0A 03 0D
expected: 01 02 0A 03 0D
actual: 01 02 03

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant