修复蓝牙添加数据问题
This commit is contained in:
parent
e258d9b49c
commit
febbab97da
@ -26,7 +26,6 @@ class BlueManage{
|
||||
Uuid characteristicIdWrite = Uuid.parse("fff2");// 用来写入的特征id
|
||||
String connectDeviceMacAddress = "";
|
||||
String connectDeviceName = "";
|
||||
|
||||
// final int _limitLen = 20;
|
||||
|
||||
// 监听发送事件
|
||||
@ -302,23 +301,23 @@ class BlueManage{
|
||||
|
||||
// 听上报来的数据,参数来自前面扫描到的结果
|
||||
var allData = <int>[];
|
||||
int? dataLen;
|
||||
_subScribeToCharacteristic(QualifiedCharacteristic characteristic) {
|
||||
_flutterReactiveBle!.subscribeToCharacteristic(characteristic).listen((data) {
|
||||
// code to handle incoming data
|
||||
print("subscribeToCharacteristic: deviceId = ${characteristic.deviceId} characteristicId =${characteristic.characteristicId}---上报来的数据data = $data");
|
||||
var dataLen = 0;// 高16位用来指示后面数据块内容的长度
|
||||
|
||||
if((data[0] == 0xEF)&&(data[1] == 0x01)&&(data[2] == 0xEE)&&(data[3] == 0x02)){
|
||||
// 当包有头时
|
||||
// 判断是否需要分包
|
||||
dataLen = data[8] * 256 + data[9];
|
||||
// print("dataLen1111:$dataLen getDataLength:${data.length}");
|
||||
if(dataLen + 12 > data.length){
|
||||
dataLen = data[8] * 256 + data[9]; // 高16位用来指示后面数据块内容的长度
|
||||
print("dataLen1111:$dataLen getDataLength:${data.length}");
|
||||
if(dataLen! + 12 > data.length){
|
||||
// 当前包的长度小于实际的包时 分包添加 不解析
|
||||
allData.addAll(data);
|
||||
}else{
|
||||
// 当前包的长度小于实际的包时 不分包 解析
|
||||
allData.addAll(data);
|
||||
print("dataLen2222:$dataLen getDataLength:${data.length}");
|
||||
CommandReciverManager.appDataReceive(allData);
|
||||
// 发送完解析初始化数组
|
||||
allData = <int>[];
|
||||
@ -327,8 +326,9 @@ class BlueManage{
|
||||
// 当包没有头时 是分包的包 直接添加
|
||||
allData.addAll(data);
|
||||
// var len = allData[8] * 256 + allData[9];
|
||||
// print("dataLen222:$dataLen");
|
||||
if(dataLen <= (allData.length - 14)){
|
||||
print("dataLen3333:$dataLen");
|
||||
if((dataLen! + 14) <= allData.length){
|
||||
print("44444数据被解析了");
|
||||
// 当长度小于等于当前包的数据时 直接解析数据
|
||||
CommandReciverManager.appDataReceive(allData);
|
||||
// 发送完解析初始化数组
|
||||
@ -346,7 +346,7 @@ class BlueManage{
|
||||
QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: characteristicIdWrite, serviceId: serviceId, deviceId: connectDeviceMacAddress);
|
||||
print('Write with characteristicId:${characteristic.characteristicId} serviceId:${characteristic.serviceId} deviceId:${characteristic.deviceId} value : $value \nhexStr:${radixHex16String(value)}');
|
||||
int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 250);
|
||||
print("mtuLength:$mtuLength");
|
||||
// print("mtuLength:$mtuLength");
|
||||
try {
|
||||
List<int> valueList = value;
|
||||
List subData = splitList(valueList, mtuLength);
|
||||
|
||||
@ -48,7 +48,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(30.h)),
|
||||
borderRadius: BorderRadius.circular(25.h)),
|
||||
padding: EdgeInsets.all(10.w),
|
||||
child: Image(
|
||||
width: 40.w,
|
||||
|
||||
@ -35,6 +35,7 @@ class NearbyLockLogic extends BaseGetXController{
|
||||
// IoSenderManage.getPublicKey(lockId: deviceName);
|
||||
// }
|
||||
// }, isShowLoading: true);
|
||||
BlueManage().disconnect("");
|
||||
BlueManage().connect(lockId, deviceName, isFrist: true, isShowLoading: true);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user