mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
Improve USB disconnection handling and add payload length validation for USB frames
This commit is contained in:
parent
3542adad1d
commit
3cec3dc233
2 changed files with 13 additions and 2 deletions
|
|
@ -105,8 +105,12 @@ class MainActivity : FlutterActivity() {
|
|||
"connect" -> handleUsbConnect(call, result)
|
||||
"write" -> handleUsbWrite(call, result)
|
||||
"disconnect" -> {
|
||||
closeUsbConnection()
|
||||
result.success(null)
|
||||
usbIoExecutor.execute {
|
||||
closeUsbConnection()
|
||||
mainHandler.post {
|
||||
result.success(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,13 @@ const int usbSerialHeaderLength = 3;
|
|||
const int usbSerialMaxPayloadLength = 172;
|
||||
|
||||
Uint8List wrapUsbSerialTxFrame(Uint8List payload) {
|
||||
if (payload.length > usbSerialMaxPayloadLength) {
|
||||
throw ArgumentError.value(
|
||||
payload.length,
|
||||
'payload.length',
|
||||
'USB serial payload exceeds $usbSerialMaxPayloadLength bytes',
|
||||
);
|
||||
}
|
||||
final packet = Uint8List(usbSerialHeaderLength + payload.length);
|
||||
packet[0] = usbSerialTxFrameStart;
|
||||
packet[1] = payload.length & 0xff;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue