Merge branch 'talk_flutter' of gitee.com:starlock-cn/app-starlock into talk_flutter

This commit is contained in:
Daisy 2023-12-20 13:46:26 +08:00
commit c87d2f96b0
6 changed files with 29 additions and 17 deletions

View File

@ -26,7 +26,6 @@ class BlueManage{
Uuid characteristicIdWrite = Uuid.parse("fff2");// id Uuid characteristicIdWrite = Uuid.parse("fff2");// id
String connectDeviceMacAddress = ""; String connectDeviceMacAddress = "";
String connectDeviceName = ""; String connectDeviceName = "";
// final int _limitLen = 20; // final int _limitLen = 20;
// //
@ -302,23 +301,23 @@ class BlueManage{
// , // ,
var allData = <int>[]; var allData = <int>[];
int? dataLen;
_subScribeToCharacteristic(QualifiedCharacteristic characteristic) { _subScribeToCharacteristic(QualifiedCharacteristic characteristic) {
_flutterReactiveBle!.subscribeToCharacteristic(characteristic).listen((data) { _flutterReactiveBle!.subscribeToCharacteristic(characteristic).listen((data) {
// code to handle incoming data // code to handle incoming data
print("subscribeToCharacteristic: deviceId = ${characteristic.deviceId} characteristicId =${characteristic.characteristicId}---上报来的数据data = $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)){ if((data[0] == 0xEF)&&(data[1] == 0x01)&&(data[2] == 0xEE)&&(data[3] == 0x02)){
// //
// //
dataLen = data[8] * 256 + data[9]; dataLen = data[8] * 256 + data[9]; // 16
// print("dataLen1111:$dataLen getDataLength:${data.length}"); print("dataLen1111:$dataLen getDataLength:${data.length}");
if(dataLen + 12 > data.length){ if(dataLen! + 12 > data.length){
// //
allData.addAll(data); allData.addAll(data);
}else{ }else{
// //
allData.addAll(data); allData.addAll(data);
print("dataLen2222:$dataLen getDataLength:${data.length}");
CommandReciverManager.appDataReceive(allData); CommandReciverManager.appDataReceive(allData);
// //
allData = <int>[]; allData = <int>[];
@ -327,8 +326,9 @@ class BlueManage{
// //
allData.addAll(data); allData.addAll(data);
// var len = allData[8] * 256 + allData[9]; // var len = allData[8] * 256 + allData[9];
// print("dataLen222:$dataLen"); print("dataLen3333:$dataLen");
if(dataLen <= (allData.length - 14)){ if((dataLen! + 14) <= allData.length){
print("44444数据被解析了");
// //
CommandReciverManager.appDataReceive(allData); CommandReciverManager.appDataReceive(allData);
// //
@ -346,7 +346,7 @@ class BlueManage{
QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: characteristicIdWrite, serviceId: serviceId, deviceId: connectDeviceMacAddress); 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)}'); 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); int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 250);
print("mtuLength:$mtuLength"); // print("mtuLength:$mtuLength");
try { try {
List<int> valueList = value; List<int> valueList = value;
List subData = splitList(valueList, mtuLength); List subData = splitList(valueList, mtuLength);

View File

@ -48,7 +48,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.circular(30.h)), borderRadius: BorderRadius.circular(25.h)),
padding: EdgeInsets.all(10.w), padding: EdgeInsets.all(10.w),
child: Image( child: Image(
width: 40.w, width: 40.w,

View File

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

View File

@ -6,6 +6,7 @@ import 'dart:io';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../network/api_repository.dart'; import '../../network/api_repository.dart';
import '../../tools/storage.dart';
import 'udp_manage.dart'; import 'udp_manage.dart';
import 'udp_senderManage.dart'; import 'udp_senderManage.dart';
@ -38,9 +39,9 @@ class UdpHelp{
} }
} }
Timer timer = Timer.periodic(1.seconds, (timer) { Timer timer = Timer.periodic(1.seconds, (timer) async {
UDPSenderManage.sendHeart( UDPSenderManage.sendHeart(
userName: "15080825640", userName: await Storage.getMobile(),
ipList: serversList, ipList: serversList,
tokenStr: "b989fa15f75c2ac02718b7c9bb64f80e", tokenStr: "b989fa15f75c2ac02718b7c9bb64f80e",
); );

View File

@ -14,7 +14,7 @@ class CommandUDPReciverManager {
if (dataSize < 4) { if (dataSize < 4) {
return; return;
} }
print("appDataReceiveData:$data"); print("appDataReceiveUDPData:$data");
Uint8List data1 = Uint8List.fromList(data); Uint8List data1 = Uint8List.fromList(data);
if (data1.length == 1) { if (data1.length == 1) {

View File

@ -136,13 +136,23 @@ class Storage {
} }
static Future<String?> getUid() async { static Future<String?> getUid() async {
String? userId = ''; String? uid = '';
final data = await Storage.getString('userLoginData'); final data = await Storage.getString('userLoginData');
if (data != null && data.isNotEmpty) { if (data != null && data.isNotEmpty) {
userId = LoginData.fromJson(jsonDecode(data)).uid.toString(); uid = LoginData.fromJson(jsonDecode(data)).uid.toString();
} }
print("pubUserId:$userId"); print("pubUid:$uid");
return userId; return uid;
}
static Future<String?> getMobile() async {
String? mobile = '';
final data = await Storage.getString('userLoginData');
if (data != null && data.isNotEmpty) {
mobile = LoginData.fromJson(jsonDecode(data)).mobile.toString();
}
print("pubUserId:$mobile");
return mobile;
} }
static Future<LoginData?> getLoginData() async { static Future<LoginData?> getLoginData() async {