-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
指的是:串口直接发送,非客户端请求的数据
- Loading branch information
sunxudong
committed
Apr 12, 2020
1 parent
9e037fe
commit f55edea
Showing
5 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
/** | ||
* 串口Call,用于触发串口调度 | ||
* | ||
* @Author: sheedon | ||
* @Email: [email protected] | ||
* @Date: 2020/2/23 22:27 | ||
|
@@ -74,6 +75,90 @@ public void publishNotCallback() { | |
enqueue(null); | ||
} | ||
|
||
@Override | ||
public void addBindCallback(final Callback<T> callback) { | ||
org.sheedon.serial.Call call; | ||
Throwable failure; | ||
|
||
synchronized (this) { | ||
|
||
call = rawCall; | ||
failure = creationFailure; | ||
if (call == null && failure == null) { | ||
try { | ||
call = rawCall = createRawCall(); | ||
} catch (Throwable t) { | ||
failure = creationFailure = t; | ||
} | ||
} | ||
} | ||
|
||
if (failure != null) { | ||
dealWithCallback(callback, SerialCall.this, null, failure, false); | ||
return; | ||
} | ||
|
||
if (canceled) { | ||
call.cancel(); | ||
} | ||
|
||
if (callback == null) | ||
return; | ||
|
||
call.addBindCallback(new org.sheedon.serial.Callback<org.sheedon.serial.Response>() { | ||
@Override | ||
public void onFailure(Throwable e) { | ||
try { | ||
dealWithCallback(callback, SerialCall.this, null, e, false); | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onResponse(org.sheedon.serial.Response rawResponse) { | ||
Response<T> response; | ||
try { | ||
response = parseResponse(rawResponse); | ||
} catch (Throwable e) { | ||
callFailure(e); | ||
return; | ||
} | ||
callSuccess(response); | ||
} | ||
|
||
private void callFailure(Throwable e) { | ||
try { | ||
dealWithCallback(callback, SerialCall.this, null, e, false); | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
|
||
private void callSuccess(Response<T> response) { | ||
try { | ||
dealWithCallback(callback, SerialCall.this, response, null, true); | ||
} catch (Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void unBindCallback() { | ||
org.sheedon.serial.Call call; | ||
|
||
synchronized (this) { | ||
call = rawCall; | ||
} | ||
|
||
if (call == null) | ||
return; | ||
|
||
call.removeBindCallback(); | ||
} | ||
|
||
@Override | ||
public void enqueue(final Callback callback) { | ||
|
||
|
@@ -178,7 +263,7 @@ private org.sheedon.serial.Call createRawCall() throws IOException { | |
return call; | ||
} | ||
|
||
Response<T> parseResponse(org.sheedon.serial.Response rawResponse) throws IOException { | ||
Response<T> parseResponse(org.sheedon.serial.Response rawResponse) { | ||
ResponseBody rawBody = rawResponse.body(); | ||
|
||
try { | ||
|