152 lines
4.7 KiB
Dart
152 lines
4.7 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/blue/io_gateway/io_gateway_configuringWifi.dart';
|
|
import 'package:star_lock/blue/io_gateway/io_gateway_getWifiList.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
import '../../../../../blue/io_tool/io_tool.dart';
|
|
import '../../../../blue/blue_manage.dart';
|
|
import '../../../../blue/io_reply.dart';
|
|
import '../../../../blue/io_tool/manager_event_bus.dart';
|
|
import '../../../../blue/sender_manage.dart';
|
|
import '../../../../tools/storage.dart';
|
|
import 'gatewayGetWifiList_state.dart';
|
|
|
|
class GatewayGetWifiListLogic extends BaseGetXController {
|
|
final GatewayGetWifiListState state = GatewayGetWifiListState();
|
|
|
|
// 获取解析后的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription =
|
|
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
|
if (reply is GatewayGetWifiReply) {
|
|
_replySendGetWifiParameters(reply);
|
|
}
|
|
|
|
if (reply is GatewayGetWifiListReply) {
|
|
_replyGetWifiListParameters(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 发送获取wifi列表数据解析
|
|
Future<void> _replySendGetWifiParameters(Reply reply) async {
|
|
final int status = reply.data[2];
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
showEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
Future.delayed(5.seconds, dismissEasyLoading);
|
|
break;
|
|
case 0x06:
|
|
// 需要鉴权
|
|
|
|
// var token = await Storage.getStringList(saveBlueToken);
|
|
// List<int> getTokenList = changeStringListToIntList(token!);
|
|
//
|
|
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
//
|
|
// var publicKey = await Storage.getStringList(saveBluePublicKey);
|
|
// List<int> publicKeyDataList = changeStringListToIntList(publicKey!);
|
|
//
|
|
// IoSenderManage.getWifiListCommand(
|
|
// keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
|
// userID: await Storage.getUid(),
|
|
// token: getTokenList,
|
|
// needAuthor: 1,
|
|
// publicKey: publicKeyDataList,
|
|
// privateKey: getPrivateKeyList,
|
|
// );
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 获取WiFi数据解析
|
|
Future<void> _replyGetWifiListParameters(Reply reply) async {
|
|
final int status = reply.data[2];
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
// showEasyLoading();
|
|
dismissEasyLoading();
|
|
state.sureBtnState.value = 0;
|
|
|
|
if (reply.data[3] > 0) {
|
|
reply.data.removeRange(0, 4);
|
|
// 把得到的数据按33位分割成数组 然后塞进一个新的数组里面
|
|
final List<List<int>> getList = splitList(reply.data, 33);
|
|
final List<Map<String, String>> uploadList = <Map<String, String>>[];
|
|
for (int i = 0; i < getList.length; i++) {
|
|
final List<int> indexList = getList[i];
|
|
final Map<String, String> indexMap = <String, String>{};
|
|
final List<int> wifiName = indexList.sublist(0, 32);
|
|
indexMap['wifiName'] = utf8String(wifiName);
|
|
indexMap['rssi'] = (indexList.last - 255).toString();
|
|
uploadList.add(indexMap);
|
|
state.wifiNameDataList.value = uploadList;
|
|
}
|
|
}
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 获取wifi列表
|
|
Future<void> senderGetWifiListWifiAction() async {
|
|
if (state.sureBtnState.value == 1) {
|
|
return;
|
|
}
|
|
state.sureBtnState.value = 1;
|
|
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(action: () {
|
|
dismissEasyLoading();
|
|
state.sureBtnState.value = 0;
|
|
});
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
|
(BluetoothConnectionState connectionState) async {
|
|
if (connectionState == BluetoothConnectionState.connected) {
|
|
IoSenderManage.gatewayGetWifiCommand(
|
|
userID: await Storage.getUid(),
|
|
);
|
|
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
state.sureBtnState.value = 0;
|
|
cancelBlueConnetctToastTimer();
|
|
if (state.ifCurrentScreen.value == true) {
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
}, isAddEquipment: true);
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
|
|
senderGetWifiListWifiAction();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
_replySubscription.cancel();
|
|
}
|
|
}
|