Browse Source

Merge branch 'new_dev' of https://github.com/deepcloud2048/deep_voice into new_dev

weicu
liwei1dao 1 year ago
parent
commit
656f4b5cfd
  1. 2
      lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart
  2. 2
      local_plugins/ota/ios/Classes/BleManager/JLBleManager.h
  3. 22
      local_plugins/ota/ios/Classes/BleManager/JLBleManager.m
  4. 12
      local_plugins/ota/ios/Classes/OtaPlugin.swift
  5. 7
      local_plugins/ota/lib/ota.dart
  6. 10
      local_plugins/ota/lib/ota_method_channel.dart
  7. 6
      local_plugins/ota/lib/ota_platform_interface.dart

2
lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart

@ -368,7 +368,7 @@ class OtaUpgradeController extends GetxController {
// 开始升级 // 开始升级
void startUpgrading(String path) async { void startUpgrading(String path) async {
jlota.startUpgrading(path); jlota.startUpgrading(address: 'E9:09:05:E0:18:7A', filePath: path);
return; return;
// isUpgrade.value = false; // isUpgrade.value = false;
} }

2
local_plugins/ota/ios/Classes/BleManager/JLBleManager.h

@ -71,7 +71,7 @@ extern NSString *kFLT_BLE_DISCONNECTED; //断开连接
/** /**
开始搜索 开始搜索
*/ */
-(void)startScanBLE; -(void)startScanBLE:(NSString * _Nullable)address filePath:(NSString * _Nullable)filePath;
/** /**
停止搜索 停止搜索

22
local_plugins/ota/ios/Classes/BleManager/JLBleManager.m

@ -37,6 +37,9 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道
@property (strong, nonatomic) GET_DEVICE_CALLBACK getCallback; @property (strong, nonatomic) GET_DEVICE_CALLBACK getCallback;
@property (strong, nonatomic) NSString *lastAddress;
@property (strong, nonatomic) NSString *lastFilePath;
@end @end
@ -83,8 +86,10 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道
#pragma mark - 扫描设备相关 #pragma mark - 扫描设备相关
#pragma mark 开始扫描 #pragma mark 开始扫描
- (void)startScanBLE { - (void)startScanBLE:(NSString * _Nullable)address filePath:(NSString * _Nullable)filePath {
kJLLog(JLLOG_DEBUG, @"BLE ---> startScanBLE."); kJLLog(JLLOG_DEBUG, @"BLE ---> startScanBLE.");
self.lastAddress = address;
self.lastFilePath = filePath;
_blePeripheralArr = [NSMutableArray new]; _blePeripheralArr = [NSMutableArray new];
if (_bleManager) { if (_bleManager) {
if (_bleManager.state == CBManagerStatePoweredOn) { if (_bleManager.state == CBManagerStatePoweredOn) {
@ -135,7 +140,7 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道
- (void)connectPeripheralWithUUID:(NSString*)uuid { - (void)connectPeripheralWithUUID:(NSString*)uuid {
_connectByUUID = uuid; _connectByUUID = uuid;
[self startScanBLE]; [self startScanBLE:self.lastAddress filePath:self.lastFilePath];
} }
-(void)findHid:(NSString *)uuid{ -(void)findHid:(NSString *)uuid{
@ -198,12 +203,11 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道
NSString *ble_name = advertisementData[@"kCBAdvDataLocalName"]; NSString *ble_name = advertisementData[@"kCBAdvDataLocalName"];
NSData *ble_AD = advertisementData[@"kCBAdvDataManufacturerData"]; NSData *ble_AD = advertisementData[@"kCBAdvDataManufacturerData"];
NSDictionary *info = [JLAdvParse bluetoothAdvParse:self.pairKey AdvData:advertisementData];
if (ble_name.length == 0) return; if (ble_name.length == 0) return;
kJLLog(JLLOG_DEBUG, @"发现 ----> NAME:%@ RSSI:%@ AD:%@", ble_name,RSSI,ble_AD); kJLLog(JLLOG_DEBUG, @"发现 ----> NAME:%@ RSSI:%@ AD:%@", ble_name,RSSI,ble_AD);
[self addPeripheral:peripheral RSSI:RSSI Name:ble_name Info:info]; [self addPeripheral:peripheral RSSI:RSSI Name:ble_name Info:ble_AD];
[[NSNotificationCenter defaultCenter] postNotificationName:kFLT_BLE_FOUND object:_blePeripheralArr userInfo:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:kFLT_BLE_FOUND object:_blePeripheralArr userInfo:nil];
@ -213,11 +217,11 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道
} }
} }
- (void)addPeripheral:(CBPeripheral*)peripheral RSSI:(NSNumber *)rssi Name:(NSString*)name Info:(NSDictionary*)info{ - (void)addPeripheral:(CBPeripheral*)peripheral RSSI:(NSNumber *)rssi Name:(NSString*)name Info:(NSData*)blead{
if ([name isEqualToString:@"DeapSound"]) { // if ([name isEqualToString:@"DeapSound"]) {
[self stopScanBLE]; // [self stopScanBLE];
[self connectBLE:peripheral]; // [self connectBLE:peripheral];
} // }
} }
#pragma mark 设备连接回调 #pragma mark 设备连接回调

12
local_plugins/ota/ios/Classes/OtaPlugin.swift

@ -10,9 +10,13 @@ public class OtaPlugin: NSObject, FlutterPlugin {
} }
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let arguments = call.arguments as? [String: Any]
switch call.method { switch call.method {
case "startUpgrading": case "startUpgrading":
startUpgrading() let address = arguments?["address"] as? String
let filePath = arguments?["filePath"] as? String
startUpgrading(address: address, filePath: filePath)
result("") result("")
case "onOtaClose": case "onOtaClose":
onOtaClose() onOtaClose()
@ -22,10 +26,10 @@ public class OtaPlugin: NSObject, FlutterPlugin {
} }
} }
private func startUpgrading() { private func startUpgrading(address: String?, filePath: String?) {
if userManager.mBleManagerState == CBManagerState.poweredOn { if userManager.mBleManagerState == CBManagerState.poweredOn {
userManager.startScanBLE() userManager.startScanBLE(address, filePath: filePath)
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
self.userManager.stopScanBLE() self.userManager.stopScanBLE()
} }
} }

7
local_plugins/ota/lib/ota.dart

@ -132,8 +132,11 @@ class Ota {
// _isEventListenerSet = true; // _isEventListenerSet = true;
// } // }
Future<void> startUpgrading(String? filePath) { Future<void> startUpgrading({String? address, String? filePath}) {
return OtaPlatform.instance.startUpgrading(filePath); return OtaPlatform.instance.startUpgrading(
address: address,
filePath: filePath,
);
} }
Future<void> onOtaClose() { Future<void> onOtaClose() {

10
local_plugins/ota/lib/ota_method_channel.dart

@ -10,11 +10,11 @@ class MethodChannelOta extends OtaPlatform {
final methodChannel = const MethodChannel('ota'); final methodChannel = const MethodChannel('ota');
@override @override
Future<void> startUpgrading(String? filePath) async { Future<void> startUpgrading({String? address, String? filePath}) async {
await methodChannel.invokeMethod<String>( await methodChannel.invokeMethod<String>('startUpgrading', {
'startUpgrading', 'address': address,
{'filePath': filePath}, // 传递参数 'filePath': filePath,
); });
} }
@override @override

6
local_plugins/ota/lib/ota_platform_interface.dart

@ -23,11 +23,11 @@ abstract class OtaPlatform extends PlatformInterface {
_instance = instance; _instance = instance;
} }
Future<void> startUpgrading(String? filePath) { Future<void> startUpgrading({String? address, String? filePath}) {
throw UnimplementedError('platformVersion() has not been implemented.'); throw UnimplementedError('startUpgrading() has not been implemented.');
} }
Future<void> onOtaClose() { Future<void> onOtaClose() {
throw UnimplementedError('platformVersion() has not been implemented.'); throw UnimplementedError('onOtaClose() has not been implemented.');
} }
} }

Loading…
Cancel
Save