修复蓝牙添加数据问题

This commit is contained in:
魏少阳 2023-12-20 11:54:54 +08:00
parent e258d9b49c
commit febbab97da
3 changed files with 11 additions and 10 deletions

View File

@ -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);

View File

@ -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,

View File

@ -35,6 +35,7 @@ class NearbyLockLogic extends BaseGetXController{
// IoSenderManage.getPublicKey(lockId: deviceName);
// }
// }, isShowLoading: true);
BlueManage().disconnect("");
BlueManage().connect(lockId, deviceName, isFrist: true, isShowLoading: true);
}