feat(ch934x_serial): 添加串口写入功能的端口索引参数
- write方法新增可选的serialPortIndex参数,支持直接写入指定端口 - 传入端口索引时不会改变当前活跃端口,保持原有活跃端口行为 - 添加对负数端口索引的验证处理,直接返回零避免异常 - 更新文档说明多端口并发客户端应使用显式端口写入方式 - 增加相关单元测试覆盖新参数的各种使用场景 - 同步更新Android原生层实现以支持端口索引传递
This commit is contained in:
@@ -69,13 +69,39 @@ void main() {
|
||||
test('write 将数据写入原生层并回传字节数', () async {
|
||||
mockCall((call) async {
|
||||
expect(call.method, 'write');
|
||||
expect((call.arguments as Map)['data'], isA<Uint8List>());
|
||||
expect(call.arguments, <String, Object>{
|
||||
'data': Uint8List.fromList([9, 8, 7]),
|
||||
});
|
||||
return 3;
|
||||
});
|
||||
final written = await platform.write(Uint8List.fromList([9, 8, 7]));
|
||||
expect(written, 3);
|
||||
});
|
||||
|
||||
test('write 透传显式串口索引', () async {
|
||||
mockCall((call) async {
|
||||
expect(call.method, 'write');
|
||||
expect(call.arguments, <String, Object>{
|
||||
'data': Uint8List.fromList([9, 8, 7]),
|
||||
'serialPortIndex': 2,
|
||||
});
|
||||
return 3;
|
||||
});
|
||||
final written = await platform.write(
|
||||
Uint8List.fromList([9, 8, 7]),
|
||||
serialPortIndex: 2,
|
||||
);
|
||||
expect(written, 3);
|
||||
});
|
||||
|
||||
test('write 接收负串口索引直接返回零', () async {
|
||||
final written = await platform.write(
|
||||
Uint8List.fromList([9]),
|
||||
serialPortIndex: -1,
|
||||
);
|
||||
expect(written, 0);
|
||||
});
|
||||
|
||||
test('getModemStatus 默认回退到 0', () async {
|
||||
mockCall((_) async => null);
|
||||
expect(await platform.getModemStatus(), 0);
|
||||
|
||||
Reference in New Issue
Block a user