169 lines
5.4 KiB
Dart
Executable File
169 lines
5.4 KiB
Dart
Executable File
import 'dart:async';
|
||
|
||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||
|
||
import '../../../../blue/blue_manage.dart';
|
||
import '../../../../blue/io_protocol/io_setSupportFunctionsNoParameters.dart';
|
||
import '../../../../blue/io_reply.dart';
|
||
import '../../../../blue/io_tool/io_tool.dart';
|
||
import '../../../../blue/io_tool/manager_event_bus.dart';
|
||
import '../../../../blue/sender_manage.dart';
|
||
import '../../../../network/api_repository.dart';
|
||
import '../../../../tools/baseGetXController.dart';
|
||
import '../../../../tools/eventBusEventManage.dart';
|
||
import '../../../../tools/storage.dart';
|
||
import 'motorPower_state.dart';
|
||
|
||
class MotorPowerLogic extends BaseGetXController {
|
||
final MotorPowerState state = MotorPowerState();
|
||
|
||
// 配置锁的常开模式设置 -> 电机功率设置
|
||
Future<void> _setLockSetGeneralSetting() async {
|
||
final LoginEntity entity = await ApiRepository.to.setMotorTorqueData(
|
||
lockId: state.lockSetInfoData.value.lockId!,
|
||
motorTorsion: state.motorTorsion.value, // // 1:小,2:中,3:大
|
||
);
|
||
if (entity.errorCode!.codeIsSuccessful) {
|
||
state.lockSetInfoData.value.lockSettingInfo!.openDirectionValue =
|
||
state.motorTorsion.value;
|
||
eventBus
|
||
.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value));
|
||
showToast('操作成功'.tr);
|
||
}
|
||
}
|
||
|
||
// 获取解析后的数据
|
||
late StreamSubscription<Reply> _replySubscription;
|
||
void _initReplySubscription() {
|
||
_replySubscription =
|
||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||
if (reply is SetSupportFunctionsNoParametersReply) {
|
||
_replySetSupportFunctionsWithParameters(reply);
|
||
}
|
||
|
||
// 读取支持功能(带参数)
|
||
// if(reply is ReadSupportFunctionsNoParametersReply) {
|
||
// _readSupportFunctionsWithParametersReply(reply);
|
||
// }
|
||
});
|
||
}
|
||
|
||
// 读取支持功能带参数数据解析
|
||
// Future<void> _readSupportFunctionsWithParametersReply(Reply reply) async {
|
||
// int status = reply.data[2];
|
||
// switch(status){
|
||
// case 0x00:
|
||
// //成功
|
||
// state.motorTorsion.value = reply.data[6];
|
||
// break;
|
||
// case 0x06:
|
||
// //无权限
|
||
// break;
|
||
// default:
|
||
// //失败
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// 设置自动落锁数据解析
|
||
Future<void> _replySetSupportFunctionsWithParameters(Reply reply) async {
|
||
final int status = reply.data[2];
|
||
switch (status) {
|
||
case 0x00:
|
||
//成功
|
||
_setLockSetGeneralSetting();
|
||
break;
|
||
case 0x06:
|
||
//无权限
|
||
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 读取支持功能-带参数
|
||
Future<void> _readSupportFunctionsNoParameters() async {
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||
(BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? privateKey =
|
||
await Storage.getStringList(saveBluePrivateKey);
|
||
final List<int> getPrivateKeyList =
|
||
changeStringListToIntList(privateKey!);
|
||
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
final List<String>? publicKey =
|
||
await Storage.getStringList(saveBluePublicKey);
|
||
final List<int> getPublicKeyList =
|
||
changeStringListToIntList(publicKey!);
|
||
|
||
IoSenderManage.readSupportFunctionsNoParametersCommand(
|
||
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
||
userID: await Storage.getUid(),
|
||
featureBit: 58,
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
publicKey: getPublicKeyList,
|
||
privateKey: getPrivateKeyList);
|
||
}
|
||
});
|
||
}
|
||
|
||
// 设置支持功能(带参数)
|
||
Future<void> sendOpenDoorDirection() async {
|
||
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
||
(BluetoothConnectionState connectionState) async {
|
||
if (connectionState == BluetoothConnectionState.connected) {
|
||
final List<String>? privateKey =
|
||
await Storage.getStringList(saveBluePrivateKey);
|
||
final List<int> getPrivateKeyList =
|
||
changeStringListToIntList(privateKey!);
|
||
|
||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||
|
||
final List<String>? publicKey =
|
||
await Storage.getStringList(saveBluePublicKey);
|
||
final List<int> getPublicKeyList =
|
||
changeStringListToIntList(publicKey!);
|
||
|
||
IoSenderManage.setSupportFunctionsWithParametersCommand(
|
||
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
||
userID: await Storage.getUid(),
|
||
featureBit: 58,
|
||
featureParaLength: 1,
|
||
featureData: <int>[state.motorTorsion.value],
|
||
token: getTokenList,
|
||
needAuthor: 1,
|
||
publicKey: getPublicKeyList,
|
||
privateKey: getPrivateKeyList);
|
||
}
|
||
});
|
||
}
|
||
|
||
@override
|
||
void onReady() {
|
||
super.onReady();
|
||
|
||
_initReplySubscription();
|
||
}
|
||
|
||
@override
|
||
void onInit() {
|
||
super.onInit();
|
||
|
||
_readSupportFunctionsNoParameters();
|
||
}
|
||
|
||
@override
|
||
void onClose() {
|
||
super.onClose();
|
||
_replySubscription.cancel();
|
||
}
|
||
}
|