Skip to content

Commit

Permalink
Changed end splitter to "{e}" instead of "END" to make it more docume…
Browse files Browse the repository at this point in the history
…nted.

Made end splitter easily changable
  • Loading branch information
ajayyy committed Oct 25, 2018
1 parent 60973e9 commit 88bc71f
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class PullDataThread extends Thread{
int tries = 0;
int maxTries = 5;

final String endSplitter = "{e}";

public PullDataThread(MainActivity mainActivity, BluetoothDevice bluetoothDevice, View deviceMenu){
this.mainActivity = mainActivity;
this.device = bluetoothDevice;
Expand Down Expand Up @@ -77,7 +79,7 @@ public void run() {
}
});

out.write("REQUEST LABELSEND".getBytes(Charset.forName("UTF-8")));
out.write(("REQUEST LABELS" + endSplitter).getBytes(Charset.forName("UTF-8")));
String labels = waitForMessage();
labels = labels.substring(0, labels.length() - 3);

Expand Down Expand Up @@ -147,7 +149,7 @@ public void run() {
}

//this message has finished
scheduleMessage.append("END");
scheduleMessage.append(endSplitter);

out.write(scheduleMessage.toString().getBytes(Charset.forName("UTF-8")));
String receivedMessage = waitForMessage();
Expand All @@ -164,7 +166,7 @@ public void run() {
}
});

out.write("REQUEST DATAEND".getBytes(Charset.forName("UTF-8")));
out.write(("REQUEST DATA" + endSplitter).getBytes(Charset.forName("UTF-8")));
String message = waitForMessage();

message = message.substring(0, message.length() - 3);
Expand Down Expand Up @@ -214,7 +216,7 @@ public void run(){

}

out.write("RECEIVEDEND".getBytes(Charset.forName("UTF-8")));
out.write(("RECEIVED" + endSplitter).getBytes(Charset.forName("UTF-8")));

} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -284,7 +286,7 @@ public String waitForMessage(){
else continue;

String message = finalMessage + new String(bytes, Charset.forName("UTF-8"));
if(!message.endsWith("END")){
if(!message.endsWith("")){
finalMessage = message;
continue;
}
Expand Down

0 comments on commit 88bc71f

Please sign in to comment.