Browse Source

修改版定逻辑,待完善

weicu
fdp 1 year ago
parent
commit
31e3105c28
  1. 1
      .vercel/project.json
  2. 4
      ios/Podfile.lock
  3. 9
      lib/data/models/user_Info.dart
  4. 70
      lib/modules/pairing/controllers/pairing_controller.dart
  5. 25
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt
  6. 9
      local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift

1
.vercel/project.json

@ -0,0 +1 @@
{"projectName":"trae_deep_voice_k3cu"}

4
ios/Podfile.lock

@ -80,7 +80,7 @@ PODS:
- SDWebImage/Core (~> 5.17)
- spotify_sdk (0.0.1):
- Flutter
- tencentcloud_cos_sdk_plugin (1.2.4):
- tencentcloud_cos_sdk_plugin (1.2.3):
- Flutter
- QCloudCOSXML (= 6.4.7)
- WechatOpenSDK-XCFramework (2.0.4)
@ -192,7 +192,7 @@ SPEC CHECKSUMS:
SDWebImage: f84b0feeb08d2d11e6a9b843cb06d75ebf5b8868
SDWebImageWebPCoder: e38c0a70396191361d60c092933e22c20d5b1380
spotify_sdk: a48400bb29f70c4fe251ebfdc9135c37097ac5ca
tencentcloud_cos_sdk_plugin: 7bed564dbe72df23e7b5cacb1e51b1a20cb1639c
tencentcloud_cos_sdk_plugin: c3d78b2c3bae42b5a20009dc047f3f1621e6272b
WechatOpenSDK-XCFramework: 36fb2bea0754266c17184adf4963d7e6ff98b69f
wifi_iot: f645260a2be8608517b2a9bf4c39b98e97003acc

9
lib/data/models/user_Info.dart

@ -23,6 +23,7 @@ class User {
String phonemac;
String password;
int viplv = 0; //添加会员等级字段,0表示普通用户
List<UserDevice> devices;
// 私有构造函数
@ -43,7 +44,7 @@ class User {
factory User.fromJson(Map<String, dynamic> json) {
// 修复1:安全获取嵌套的 user 字段
final userData = json['user'] as Map<String, dynamic>?; // 允许空值
final devicesData = json['devices'] as Map<String, dynamic>?; // 允许空值
final devicesData = json['devices'] as List<dynamic>?; // 允许空值
//final token = json['data']['token'] as String? ?? '';
//final token = '';
// 更新单例实例
@ -61,7 +62,7 @@ class User {
phonemac: (userData?['phonemac'] as String?) ?? '',
password: (userData?['password'] as String?) ?? '',
viplv: (userData?['viplv'] as int?) ?? 0, // 提供默认值
devices: (devicesData as List<dynamic>?)
devices: devicesData
?.map((e) => UserDevice.fromJson(e as Map<String, dynamic>))
.toList() ??
[], // 处理设备列表
@ -70,7 +71,7 @@ class User {
factory User.fronTokenJson(Map<String, dynamic> json) {
// 修复1:安全获取嵌套的 user 字段
final userData = json['user'] as Map<String, dynamic>?; // 允许空值
final devicesData = json['devices'] as Map<String, dynamic>?; // 允许空值
final devicesData = json['devices'] as List<dynamic>?; // 允许空值
print("数据获取fronTokenJson${userData} ${devicesData}");
// 更新单例实例
return _instance = User._(
@ -86,7 +87,7 @@ class User {
password: (userData?['password'] as String?) ?? '',
viplv: (userData?['viplv'] as int?) ?? 0, // 提供默认值
devices: devicesData != null
? (devicesData as List<dynamic>)
? (devicesData)
.map((e) => UserDevice.fromJson(e as Map<String, dynamic>))
.toList()
: [], // 处理设备列表

70
lib/modules/pairing/controllers/pairing_controller.dart

@ -76,6 +76,9 @@ class PairingController extends GetxController {
bool isShowSkipButton = false; //是否显示跳过按钮
final availableDevices = <BluetoothDevice>[].obs; // 可用设备列表
final selectedDevice = Rx<BluetoothDevice?>(null); // 用户选中的设备
// ========== 监听器管理 ==========
final List<Worker> _workers = [];
Timer? _bleTimeoutTimer;
@ -601,13 +604,23 @@ class PairingController extends GetxController {
}
}
//自动绑定设备 0 未合作商 1 合作商 2,已绑定
//自动绑定设备 0 未合作商 1 合作商 9经典蓝牙已绑定 10,ble蓝牙已绑定
Future<int> authbindingDevice(BluetoothDevice device) async {
// if (User.instance.earphoneauthcode != "" &&
// User.instance.earphonemac == device.address) {
// // 已经绑定
// return 9;
// }
// 检查是否已有绑定的设备
final existingDevice = User.instance.devices.firstWhere(
(d) => d.devicetype == 0 && d.devicemac == device.address,
orElse: () => UserDevice(
id: -1,
uid: '',
devicetype: -1,
devicename: '',
devicemac: '',
license: ''),
);
if (existingDevice.id != -1) {
// 已经绑定
return 9;
}
// 检查设备名称是否包含 DeepSound 或 DeapSound
final deviceName = device.name;
@ -663,14 +676,26 @@ class PairingController extends GetxController {
_bleManager.stopScan();
deviceCode.value = code;
_verifiedDeviceAddress = device.address;
// 检查是否已经绑定
// if (User.instance.earphonelicense != "" &&
// User.instance.earphonemac == device.address) {
// // 已经绑定
// return 10;
// } else {
return 1;
// }
//检查是否已经绑定
final existingDevice = User.instance.devices.firstWhere(
(d) =>
d.devicetype == 2 &&
d.license != "" &&
d.devicemac == device.address,
orElse: () => UserDevice(
id: -1,
uid: '',
devicetype: -1,
devicename: '',
devicemac: '',
license: ''),
);
if (existingDevice.id != -1) {
// 已经绑定
return 10;
} else {
return 1;
}
}
} else {
break;
@ -681,9 +706,13 @@ class PairingController extends GetxController {
}
await Future.delayed(Duration(seconds: 1));
}
return 0;
} else {
return 0;
}
//可以跳转1
else {
return 1;
}
}
@ -919,4 +948,13 @@ class PairingController extends GetxController {
Logger.e(_tag, '清除设备关联失败: $e');
}
}
// 用户选择设备后调用
void onDeviceSelected(BluetoothDevice device) {
Logger.i(_tag, '用户选择了设备: ${device.name} (${device.address})');
selectedDevice.value = device;
_currentClassicDevice = device;
_transition(PairingState.verifying);
_verifyDevice(device);
}
}

25
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt

@ -357,17 +357,34 @@ object BleService {
}
return null;
}
fun getDeviceInfos(deviceName: String): List<Map<String, Any>>? {
fun getDeviceInfos(deviceName: String): List<Map<String, Any>> {
// 更新缓存
val matchedResults = scanResults.filter {
it.device.name == deviceName
}
Log.d(TAG, "找到 ${matchedResults.size} 个名称为 $deviceName 的设备")
if (matchedResults.isEmpty()) {
return emptyList()
val ret = mutableListOf<Map<String, Any>>()
// 如果找到匹配设备名的结果,返回匹配设备的信息
if (matchedResults.isNotEmpty()) {
for (result in matchedResults) {
val info = printDeviceInfo(result)
if (info != null) {
ret.add(info)
}
}
} else {
// 如果没找到匹配设备名的结果,返回所有扫描到的设备信息
for (result in scanResults) {
val info = printDeviceInfo(result)
if (info != null) {
ret.add(info)
}
}
}
return null;
return ret
}
/**
* 打印设备信息和服务UUID

9
local_plugins/ble_service/ios/ble_service/Sources/ble_service/BleService.swift

@ -230,11 +230,14 @@ private var cmdReplyType: UInt8 = 0
isScanning = true
// 移除服务UUID过滤,扫描所有设备
manager.scanForPeripherals(withServices: nil, options: [
// manager.scanForPeripherals(withServices: nil, options: [
// CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据
// ])
let serviceUUIDs = [BleConst.SERVICE_UUID]
manager.scanForPeripherals(withServices: serviceUUIDs, options: [
CBCentralManagerScanOptionAllowDuplicatesKey: true // 允许重复以获取更新的广播数据
])
os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout)
// os_log("🔍 开始扫描所有BLE设备(无过滤),超时时间: %.1f秒", log: logger, type: .info, timeout)
// 设置扫描超时
scanTimer?.invalidate()

Loading…
Cancel
Save