-
Notifications
You must be signed in to change notification settings - Fork 23
/
BaseStickPackageHelper.java
39 lines (33 loc) · 1.07 KB
/
BaseStickPackageHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.kongqw.serialportlibrary.stick;
import android.os.SystemClock;
import android.util.Log;
import com.kongqw.serialportlibrary.SerialUtils;
import java.io.IOException;
import java.io.InputStream;
/**
* The simplest thing to do is not to deal with sticky packets,
* read directly and return as much as InputStream.available() reads
*/
public class BaseStickPackageHelper implements AbsStickPackageHelper {
public BaseStickPackageHelper() {
}
@Override
public byte[] execute(InputStream is) {
try {
int available = is.available();
if (available > 0) {
byte[] buffer = new byte[available];
int size = is.read(buffer);
if (size > 0) {
return buffer;
}
Log.i("tag","原始数据:"+ buffer);
} else {
SystemClock.sleep( SerialUtils.getInstance().getmSerialConfig().getIntervalSleep());
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}