Skip to content

Commit

Permalink
changed protocol buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
felHR85 committed Jan 27, 2019
1 parent d02adc6 commit b5863e2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions usbserial/src/main/java/com/felhr/utils/ProtocolBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public void setDelimiter(byte[] delimiter){
this.separator = delimiter;
}

public void appendData(byte[] data){
public synchronized void appendData(byte[] data){
// Ignore the frequent empty calls
if (data.length == 0) return;

if(mode.equals(TEXT)){
try {
String dataStr = new String(data, "UTF-8");
Expand All @@ -69,8 +72,7 @@ public void appendData(byte[] data){
index = stringBuffer.toString().indexOf(delimiter, prevIndex);
}

if(prevIndex < buffer.length()
&& prevIndex > 0){
if( /*prevIndex < buffer.length() &&*/ prevIndex > 0){
String tempStr = buffer.substring(prevIndex, buffer.length());
stringBuffer.setLength(0);
stringBuffer.append(tempStr);
Expand Down

0 comments on commit b5863e2

Please sign in to comment.