java - Android - receiving data via bluetooth -


i have little problem. i'm working on application control device bluetooth , receving data device.after recive, data present on real time graph. sending , presenting done have problem read data.

data :

'<' ch1 ch2 seq crc '>'

ch1,ch2 - uint16

seq, crc - uint8

entirety have 8 bytes

after recive need ch1 or ch2 "pack up" integer , show on graph.

commented fragment in code solution @ moment cant test that(i dont know if work) want ask if way that? maybe there better way do that?

here code :

class connectedthread extends thread { private static final string tag = "bluetoothcommandservice"; public static final int exit_cmd = -1;    private final bluetoothsocket mmsocket; private final inputstream mminstream; private final outputstream mmoutstream; public static int data;  public static void shiftright(byte[] list) {     if (list.length < 2) return;     byte last = list[list.length - 1];     for(int = list.length - 1; > 0; i--) {         list[i] = list[i - 1];     }     list[0] = last; }  public connectedthread(bluetoothsocket socket) {       mmsocket = socket;      inputstream tmpin = null;     outputstream tmpout = null;      try {         tmpin =  mmsocket.getinputstream();         tmpout =  mmsocket.getoutputstream();     } catch (ioexception e) {      }     mminstream = tmpin;     mmoutstream = tmpout; } public void run() {     byte [] buffer = new byte[8];     while (true) {         try {              /*             buffer[0] = (byte) mminstream.read();             shiftright(buffer);             if((buffer[7]=='<')&(buffer[1]=='>')){                 data = ((int) buffer[1] << 8) | ((int) buffer[2] & 0xff);              */             }         }catch (ioexception e) {              log.e(tag, "connection lost", e);             break;         }     } } 

shiftright()

 public static void shiftright(byte[] list) {     if (list.length < 2) return;     byte last = list[list.length - 1];     for(int = list.length - 1; > 0; i--) {         list[i] = list[i - 1];     }     list[0] = last; } 

thank time.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -