a,领锁,点击+号时,如果获取网络时间失败,不进入下一页,提示必须联网 b. 开锁时:有网络时间则同步,无网络则不同步时间 c. 同步时间功能:必须有网才同步时间,确定和通通锁不一致 2、修改登录、注册、修改密码选择跟当前ip不是用一个国家的时候,弹窗提示
215 lines
6.9 KiB
Dart
Executable File
215 lines
6.9 KiB
Dart
Executable File
|
|
import 'dart:async';
|
|
|
|
import 'package:date_format/date_format.dart';
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
|
import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart';
|
|
|
|
import '../../../../blue/blue_manage.dart';
|
|
import '../../../../blue/io_protocol/io_getStarLockStatusInfo.dart';
|
|
import '../../../../blue/io_protocol/io_timing.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/dateTool.dart';
|
|
import '../../../../tools/storage.dart';
|
|
import 'lockTime_state.dart';
|
|
|
|
class LockTimeLogic extends BaseGetXController{
|
|
final LockTimeState state = LockTimeState();
|
|
|
|
// 获取解析后的数据
|
|
late StreamSubscription<Reply> _replySubscription;
|
|
void _initReplySubscription() {
|
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
|
if(reply is TimingReply) {
|
|
_replyTiming(reply);
|
|
}
|
|
|
|
// 获取锁状态
|
|
if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
|
|
_replyGetStarLockStatusInfo(reply);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 获取锁状态数据解析
|
|
Future<void> _replyGetStarLockStatusInfo(Reply reply) async {
|
|
final int status = reply.data[2];
|
|
switch (status) {
|
|
case 0x00:
|
|
//成功
|
|
cancelBlueConnetctToastTimer();
|
|
dismissEasyLoading();
|
|
|
|
// 有效时间
|
|
final List<int> indate = reply.data.sublist(150, 154);
|
|
final int indateValue = (0xff & indate[0]) << 24 |
|
|
(0xff & indate[1]) << 16 |
|
|
(0xff & indate[2]) << 8 |
|
|
(0xFF & indate[3]);
|
|
AppLog.log('indate:$indate indateValue:$indateValue');
|
|
state.dateTime.value = DateTool().dateToYMDHNString('$indateValue');
|
|
break;
|
|
case 0x06:
|
|
//需要鉴权
|
|
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
IoSenderManage.senderGetStarLockStatuInfo(
|
|
lockID: BlueManage().connectDeviceName,
|
|
userID: await Storage.getUid(),
|
|
utcTimeStamp: 0,
|
|
unixTimeStamp: 0,
|
|
isBeforeAddUser: false,
|
|
privateKey: getPrivateKeyList,
|
|
);
|
|
break;
|
|
default:
|
|
//失败
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 校时数据解析
|
|
Future<void> _replyTiming(Reply reply) async {
|
|
final int status = reply.data[2];
|
|
switch(status){
|
|
case 0x00:
|
|
//成功
|
|
final String dataEime = DateTool().dateToYMDHNString('${state.differentialTime}');
|
|
state.dateTime.value = dataEime;
|
|
|
|
state.sureBtnState.value = 0;
|
|
cancelBlueConnetctToastTimer();
|
|
dismissEasyLoading();
|
|
showToast('锁时间更新成功'.tr);
|
|
break;
|
|
case 0x06:
|
|
//无权限
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 校验时间
|
|
Future<void> sendTiming() 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) {
|
|
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>? signKey = await Storage.getStringList(saveBlueSignKey);
|
|
final List<int> getSignKeyList = changeStringListToIntList(signKey!);
|
|
|
|
IoSenderManage.senderTimingCommand(
|
|
lockID:BlueManage().connectDeviceName,
|
|
userID:await Storage.getUid(),
|
|
nowTime: state.differentialTime,
|
|
token:getTokenList,
|
|
needAuthor:1,
|
|
signKey:getSignKeyList,
|
|
privateKey:getPrivateKeyList,
|
|
);
|
|
} else if (connectionState == BluetoothConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
state.sureBtnState.value = 0;
|
|
if(state.ifCurrentScreen.value == true){
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 获取锁状态 更新时间
|
|
Future<void> getStarLockStatus() async {
|
|
showEasyLoading();
|
|
showBlueConnetctToastTimer(action: () {
|
|
dismissEasyLoading();
|
|
});
|
|
BlueManage().blueSendData(BlueManage().connectDeviceName,
|
|
(BluetoothConnectionState deviceConnectionState) async {
|
|
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
|
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
|
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
|
|
|
IoSenderManage.senderGetStarLockStatuInfo(
|
|
lockID: BlueManage().connectDeviceName,
|
|
userID: await Storage.getUid(),
|
|
utcTimeStamp: 0,
|
|
unixTimeStamp: 0,
|
|
isBeforeAddUser: false,
|
|
privateKey: getPrivateKeyList,
|
|
);
|
|
} else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
|
dismissEasyLoading();
|
|
cancelBlueConnetctToastTimer();
|
|
if (state.ifCurrentScreen.value == true) {
|
|
showBlueConnetctToast();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 从网关获取时间
|
|
Future<void> getLockTimeFromGateway() async{
|
|
final GetServerDatetimeEntity entity = await ApiRepository.to.getLockTimeFromGateway(
|
|
lockId: state.lockSetInfoData.value.lockId.toString(),
|
|
);
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
|
|
}
|
|
}
|
|
|
|
// 从服务器获取锁的时间 开锁时传入
|
|
Future<void> getServerDatetime() async{
|
|
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading:false);
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
state.differentialTime = entity.data!.date! ~/ 1000;
|
|
// AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}");
|
|
sendTiming();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
|
|
_initReplySubscription();
|
|
|
|
// getLockTimeFromGateway();
|
|
|
|
getStarLockStatus();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
_replySubscription.cancel();
|
|
}
|
|
} |