1、修改上传锁时间、更新电量上传UTC时间问题。2、修改拍照头像上传比较慢问题
This commit is contained in:
parent
0e38550b94
commit
bc440ec377
@ -26,7 +26,7 @@ class GetStarLockStatuInfoCommand extends SenderProtocol {
|
||||
@override
|
||||
String toString() {
|
||||
return 'GetStarLockStatuInfoCommand{lockID: $lockID, '
|
||||
'utcTimeStamp:$utcTimeStamp utcTimeStamp: ${DateTool().dateIntToYMDHNString(utcTimeStamp)}, unixTimeStamp:unixTimeStamp unixTimeStamp: ${DateTool().dateIntToYMDHNString(unixTimeStamp)}, '
|
||||
'utcTimeStamp:$utcTimeStamp utcTimeStamp: ${DateTool().dateIntToYMDHNString(utcTimeStamp)}, unixTimeStamp:$unixTimeStamp unixTimeStamp: ${DateTool().dateIntToYMDHNString(unixTimeStamp)}, '
|
||||
'userID: $userID, privateKey: $privateKey}';
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,9 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart';
|
||||
|
||||
import '../../../../../app_settings/app_settings.dart';
|
||||
import '../../../../../blue/blue_manage.dart';
|
||||
import '../../../../../blue/io_protocol/io_getStarLockStatusInfo.dart';
|
||||
import '../../../../../blue/io_reply.dart';
|
||||
@ -11,6 +13,7 @@ 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/eventBusEventManage.dart';
|
||||
import '../../../../../tools/storage.dart';
|
||||
import '../../../lockOperatingRecord/keyOperationRecord_entity.dart';
|
||||
@ -54,13 +57,13 @@ class UploadElectricQuantityLogic extends BaseGetXController {
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
dismissEasyLoading();
|
||||
final privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
IoSenderManage.senderGetStarLockStatuInfo(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
utcTimeStamp: getUTCNetTime(),
|
||||
unixTimeStamp: getLocalNetTime(),
|
||||
utcTimeStamp: getUTCTime(),
|
||||
unixTimeStamp: getLocalTime(),
|
||||
isBeforeAddUser: false,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
@ -79,7 +82,7 @@ class UploadElectricQuantityLogic extends BaseGetXController {
|
||||
late StreamSubscription<Reply> _replySubscription;
|
||||
void _initReplySubscription() {
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
// 获取锁状态信息
|
||||
if (reply is GetStarLockStatuInfoReply) {
|
||||
_replyGetStarLockStatusInfo(reply);
|
||||
@ -98,11 +101,11 @@ class UploadElectricQuantityLogic extends BaseGetXController {
|
||||
cancelBlueConnetctToastTimer();
|
||||
|
||||
// 电池剩余电量
|
||||
final battRemCap = reply.data[132];
|
||||
final int battRemCap = reply.data[132];
|
||||
state.lockSetInfoData.value.lockBasicInfo!.electricQuantity = battRemCap;
|
||||
|
||||
// 备用电池剩余电量
|
||||
final battRemCapStandby = reply.data[133];
|
||||
final int battRemCapStandby = reply.data[133];
|
||||
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby = battRemCapStandby;
|
||||
|
||||
state.uploadElectricQuantityDate.value = DateTime.now().millisecondsSinceEpoch;
|
||||
@ -111,16 +114,18 @@ class UploadElectricQuantityLogic extends BaseGetXController {
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
final privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
IoSenderManage.senderGetStarLockStatuInfo(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
utcTimeStamp: getUTCNetTime(),
|
||||
unixTimeStamp: getLocalNetTime(),
|
||||
utcTimeStamp: getUTCTime(),
|
||||
unixTimeStamp: getLocalTime(),
|
||||
isBeforeAddUser: false,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
//失败
|
||||
@ -129,32 +134,29 @@ class UploadElectricQuantityLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
// 从服务器获取锁的时间 开锁时传入
|
||||
void getServerDatetime() async{
|
||||
final entity = await ApiRepository.to.getServerDatetimeData();
|
||||
Future<void> getServerDatetime() async{
|
||||
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData();
|
||||
if(entity.errorCode!.codeIsSuccessful){
|
||||
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
getLocalNetTime();
|
||||
// AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}");
|
||||
}
|
||||
}
|
||||
|
||||
int getUTCNetTime(){
|
||||
int getLocalTime(){
|
||||
return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime;
|
||||
}
|
||||
|
||||
int getLocalNetTime(){
|
||||
final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getUTCNetTime()*1000, isUtc: true);
|
||||
final DateTime localTime = utcTime.toLocal();
|
||||
int getUTCTime(){
|
||||
final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true);
|
||||
|
||||
// AppLog.log('getUTCNetTime: ${getUTCNetTime()}');
|
||||
// AppLog.log('UTC time: $utcTime');
|
||||
// AppLog.log('Local time: $localTime localTime.millisecondsSinceEpoch ~/ 1000:${localTime.millisecondsSinceEpoch ~/ 1000}');
|
||||
return localTime.millisecondsSinceEpoch ~/ 1000;
|
||||
final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1);
|
||||
final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1);
|
||||
AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue');
|
||||
return utcTimeValue ~/ 1000;
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
super.onReady();
|
||||
|
||||
_initReplySubscription();
|
||||
@ -163,13 +165,11 @@ class UploadElectricQuantityLogic extends BaseGetXController {
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// TODO: implement onInit
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
_replySubscription.cancel();
|
||||
}
|
||||
|
||||
@ -3,9 +3,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockSet/basicInformation/uploadElectricQuantity/uploadElectricQuantity_state.dart';
|
||||
|
||||
import '../../../../../app_settings/app_colors.dart';
|
||||
import '../../../../../blue/blue_manage.dart';
|
||||
import '../../../../../tools/appRouteObserver.dart';
|
||||
import '../../../../../tools/dateTool.dart';
|
||||
import '../../../../../tools/submitBtn.dart';
|
||||
@ -22,8 +22,8 @@ class UploadElectricQuantityPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage> with RouteAware {
|
||||
final logic = Get.put(UploadElectricQuantityLogic());
|
||||
final state = Get.find<UploadElectricQuantityLogic>().state;
|
||||
final UploadElectricQuantityLogic logic = Get.put(UploadElectricQuantityLogic());
|
||||
final UploadElectricQuantityState state = Get.find<UploadElectricQuantityLogic>().state;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -36,10 +36,10 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(30.w),
|
||||
child: Column(
|
||||
children: [
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
TranslationLoader.lanKeys!.updateElectricQuantityTip!.tr,
|
||||
@ -52,7 +52,7 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
|
||||
),
|
||||
Obx(() => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
"${"电池1".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantity ?? ""}%",
|
||||
@ -64,7 +64,7 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
|
||||
visible: state.lockSetInfoData.value.lockFeature!.isSupportBackupBattery == 1,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
"${"电池2".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantityStandby ?? ""}%",
|
||||
@ -76,7 +76,7 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
|
||||
SizedBox(height: 10.h),
|
||||
Obx(() => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
"${"电量更新时间".tr}:${DateTool().dateToYMDHNString(state.uploadElectricQuantityDate.value.toString())}",
|
||||
@ -104,7 +104,6 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
// TODO: implement didChangeDependencies
|
||||
super.didChangeDependencies();
|
||||
|
||||
/// 路由订阅
|
||||
@ -113,7 +112,6 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
/// 取消路由订阅
|
||||
AppRouteObserver().routeObserver.unsubscribe(this);
|
||||
super.dispose();
|
||||
@ -148,7 +146,9 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
|
||||
void didPushNext() {
|
||||
super.didPushNext();
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
|
||||
if (EasyLoading.isShow) {
|
||||
EasyLoading.dismiss(animation: true);
|
||||
}
|
||||
state.ifCurrentScreen.value = false;
|
||||
state.sureBtnState.value = 0;
|
||||
}
|
||||
|
||||
@ -3,24 +3,24 @@ import 'package:get/get.dart';
|
||||
|
||||
import '../../lockSet/lockSetInfo_entity.dart';
|
||||
|
||||
class UploadElectricQuantityState {
|
||||
var lockSetInfoData = LockSetInfoData().obs;
|
||||
var lockBasicInfo = LockBasicInfo().obs;
|
||||
var uploadElectricQuantityDate = 0.obs;
|
||||
int differentialTime = 0;
|
||||
|
||||
var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示
|
||||
var sureBtnState = 0.obs;// 0普通状态可用 1不可用
|
||||
class UploadElectricQuantityState {// 0普通状态可用 1不可用
|
||||
|
||||
UploadElectricQuantityState() {
|
||||
var map = Get.arguments;
|
||||
if(map["lockSetInfoData"]!=null){
|
||||
lockSetInfoData.value = map["lockSetInfoData"];
|
||||
final map = Get.arguments;
|
||||
if(map['lockSetInfoData']!=null){
|
||||
lockSetInfoData.value = map['lockSetInfoData'];
|
||||
if(lockSetInfoData.value.lockBasicInfo!=null){
|
||||
lockBasicInfo.value = lockSetInfoData.value.lockBasicInfo!;
|
||||
uploadElectricQuantityDate.value = lockSetInfoData.value.lockBasicInfo!.electricQuantityDate!;
|
||||
}
|
||||
}
|
||||
}
|
||||
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
|
||||
Rx<LockBasicInfo> lockBasicInfo = LockBasicInfo().obs;
|
||||
RxInt uploadElectricQuantityDate = 0.obs;
|
||||
int differentialTime = 0;
|
||||
|
||||
RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示
|
||||
RxInt sureBtnState = 0.obs;
|
||||
|
||||
}
|
||||
@ -1,8 +1,11 @@
|
||||
|
||||
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';
|
||||
@ -23,65 +26,69 @@ class LockTimeLogic extends BaseGetXController{
|
||||
// 获取解析后的数据
|
||||
late StreamSubscription<Reply> _replySubscription;
|
||||
void _initReplySubscription() {
|
||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
||||
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
if(reply is TimingReply) {
|
||||
_replyTiming(reply);
|
||||
}
|
||||
|
||||
// 获取锁状态
|
||||
// if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
|
||||
// _replyGetStarLockStatusInfo(reply);
|
||||
// }
|
||||
if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
|
||||
_replyGetStarLockStatusInfo(reply);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 获取锁状态数据解析
|
||||
// Future<void> _replyGetStarLockStatusInfo(Reply reply) async {
|
||||
// int status = reply.data[2];
|
||||
// switch (status) {
|
||||
// case 0x00:
|
||||
// //成功
|
||||
// cancelBlueConnetctToastTimer();
|
||||
// dismissEasyLoading();
|
||||
//
|
||||
// // 有效时间
|
||||
// var indate = reply.data.sublist(149, 153);
|
||||
// int indateValue = ((0xff & indate[(0)]) << 24 |
|
||||
// (0xff & indate[1]) << 16 |
|
||||
// (0xff & indate[2]) << 8 |
|
||||
// (0xFF & indate[3]));
|
||||
// state.dateTime.value = DateTool().dateToYMDHNString("$indateValue");
|
||||
// break;
|
||||
// case 0x06:
|
||||
// //需要鉴权
|
||||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
// IoSenderManage.senderGetStarLockStatuInfo(
|
||||
// lockID: BlueManage().connectDeviceName,
|
||||
// userID: await Storage.getUid(),
|
||||
// isBeforeAddUser: false,
|
||||
// privateKey: getPrivateKeyList,
|
||||
// );
|
||||
// break;
|
||||
// default:
|
||||
// //失败
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// 获取锁状态数据解析
|
||||
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 {
|
||||
int status = reply.data[2];
|
||||
final int status = reply.data[2];
|
||||
switch(status){
|
||||
case 0x00:
|
||||
//成功
|
||||
String dataEime = DateTool().dateToYMDHNString("${getUTCNetTime()}");
|
||||
final String dataEime = DateTool().dateToYMDHNString('${getLocalTime()}');
|
||||
state.dateTime.value = dataEime;
|
||||
|
||||
state.sureBtnState.value = 0;
|
||||
cancelBlueConnetctToastTimer();
|
||||
dismissEasyLoading();
|
||||
showToast("锁时间更新成功".tr);
|
||||
showToast('锁时间更新成功'.tr);
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
@ -105,20 +112,19 @@ class LockTimeLogic extends BaseGetXController{
|
||||
});
|
||||
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
|
||||
if (connectionState == BluetoothConnectionState.connected) {
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
var token = await Storage.getStringList(saveBlueToken);
|
||||
List<int> getTokenList = changeStringListToIntList(token!);
|
||||
final List<String>? token = await Storage.getStringList(saveBlueToken);
|
||||
final List<int> getTokenList = changeStringListToIntList(token!);
|
||||
|
||||
var signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
List<int> getSignKeyList = changeStringListToIntList(signKey!);
|
||||
final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
|
||||
final List<int> getSignKeyList = changeStringListToIntList(signKey!);
|
||||
|
||||
IoSenderManage.senderTimingCommand(
|
||||
lockID:BlueManage().connectDeviceName,
|
||||
userID:await Storage.getUid(),
|
||||
// nowTime:DateTime.now().millisecondsSinceEpoch~/1000,
|
||||
nowTime: getUTCNetTime(),
|
||||
nowTime: getLocalTime(),
|
||||
token:getTokenList,
|
||||
needAuthor:1,
|
||||
signKey:getSignKeyList,
|
||||
@ -135,37 +141,39 @@ class LockTimeLogic extends BaseGetXController{
|
||||
});
|
||||
}
|
||||
|
||||
// 获取锁状态 更新电量
|
||||
// Future<void> getStarLockStatus() async {
|
||||
// showEasyLoading();
|
||||
// showBlueConnetctToastTimer(action: () {
|
||||
// dismissEasyLoading();
|
||||
// });
|
||||
// BlueManage().bludSendData(BlueManage().connectDeviceName,
|
||||
// (BluetoothConnectionState deviceConnectionState) async {
|
||||
// if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
// dismissEasyLoading();
|
||||
// var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
// IoSenderManage.senderGetStarLockStatuInfo(
|
||||
// lockID: BlueManage().connectDeviceName,
|
||||
// userID: await Storage.getUid(),
|
||||
// isBeforeAddUser: false,
|
||||
// privateKey: getPrivateKeyList,
|
||||
// );
|
||||
// } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
|
||||
// dismissEasyLoading();
|
||||
// cancelBlueConnetctToastTimer();
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 从网关获取时间
|
||||
void getLockTimeFromGateway() async{
|
||||
var entity = await ApiRepository.to.getLockTimeFromGateway(
|
||||
Future<void> getLockTimeFromGateway() async{
|
||||
final GetServerDatetimeEntity entity = await ApiRepository.to.getLockTimeFromGateway(
|
||||
lockId: state.lockSetInfoData.value.lockId.toString(),
|
||||
);
|
||||
if(entity.errorCode!.codeIsSuccessful){
|
||||
@ -174,41 +182,45 @@ class LockTimeLogic extends BaseGetXController{
|
||||
}
|
||||
|
||||
// 从服务器获取锁的时间 开锁时传入
|
||||
void getServerDatetime() async{
|
||||
var entity = await ApiRepository.to.getServerDatetimeData();
|
||||
Future<void> getServerDatetime() async{
|
||||
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData();
|
||||
if(entity.errorCode!.codeIsSuccessful){
|
||||
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
// AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}");
|
||||
getStarLockStatus();
|
||||
}
|
||||
}
|
||||
|
||||
int getUTCNetTime(){
|
||||
int getLocalTime(){
|
||||
return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime;
|
||||
}
|
||||
|
||||
int getUTCTime(){
|
||||
final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true);
|
||||
|
||||
final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1);
|
||||
final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1);
|
||||
AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue');
|
||||
return utcTimeValue ~/ 1000;
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
super.onReady();
|
||||
|
||||
_initReplySubscription();
|
||||
|
||||
// getStarLockStatus();
|
||||
// getLockTimeFromGateway();
|
||||
getServerDatetime();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// TODO: implement onInit
|
||||
super.onInit();
|
||||
|
||||
// _getLockStatus();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
_replySubscription.cancel();
|
||||
}
|
||||
|
||||
@ -77,7 +77,6 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
// TODO: implement didChangeDependencies
|
||||
super.didChangeDependencies();
|
||||
|
||||
/// 路由订阅
|
||||
@ -86,7 +85,6 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
/// 取消路由订阅
|
||||
AppRouteObserver().routeObserver.unsubscribe(this);
|
||||
super.dispose();
|
||||
@ -104,7 +102,9 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
|
||||
void didPop() {
|
||||
super.didPop();
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
|
||||
if (EasyLoading.isShow) {
|
||||
EasyLoading.dismiss(animation: true);
|
||||
}
|
||||
state.ifCurrentScreen.value = false;
|
||||
state.sureBtnState.value = 0;
|
||||
}
|
||||
@ -121,7 +121,9 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
|
||||
void didPushNext() {
|
||||
super.didPushNext();
|
||||
logic.cancelBlueConnetctToastTimer();
|
||||
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
|
||||
if (EasyLoading.isShow) {
|
||||
EasyLoading.dismiss(animation: true);
|
||||
}
|
||||
state.ifCurrentScreen.value = false;
|
||||
state.sureBtnState.value = 0;
|
||||
}
|
||||
|
||||
@ -2,16 +2,16 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../lockSet/lockSetInfo_entity.dart';
|
||||
|
||||
class LockTimeState{
|
||||
var lockSetInfoData = LockSetInfoData().obs;
|
||||
var dateTime = "".obs;
|
||||
int differentialTime = 0;
|
||||
|
||||
var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示
|
||||
var sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用)
|
||||
class LockTimeState{// 0普通状态(可用) 1连接中(不可用)
|
||||
|
||||
LockTimeState() {
|
||||
var map = Get.arguments;
|
||||
lockSetInfoData.value = map["lockSetInfoData"];
|
||||
final map = Get.arguments;
|
||||
lockSetInfoData.value = map['lockSetInfoData'];
|
||||
}
|
||||
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
|
||||
RxString dateTime = ''.obs;
|
||||
int differentialTime = 0;
|
||||
|
||||
RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示
|
||||
RxInt sureBtnState = 0.obs;
|
||||
}
|
||||
@ -13,6 +13,7 @@ import 'package:star_lock/blue/io_protocol/io_getPrivateKey.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_getPublicKey.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_otaUpgrade.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_processOtaUpgrade.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart';
|
||||
import 'package:star_lock/mine/addLock/nearbyLock/nearbyLock_page.dart';
|
||||
import 'package:star_lock/tools/baseGetXController.dart';
|
||||
import 'package:star_lock/widget/permission/permission_dialog.dart';
|
||||
@ -26,6 +27,7 @@ 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/dateTool.dart';
|
||||
import '../../../tools/storage.dart';
|
||||
import 'nearbyLock_state.dart';
|
||||
|
||||
@ -68,7 +70,7 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
|
||||
void _initReplySubscription() {
|
||||
_replySubscription =
|
||||
EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
||||
EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
|
||||
if (reply is GetPublicKeyReply) {
|
||||
_replyGetPublicKey(reply);
|
||||
}
|
||||
@ -110,8 +112,8 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
//成功
|
||||
AppLog.log('获取公钥成功');
|
||||
// 储存公钥
|
||||
var publicKey = reply.data.sublist(3);
|
||||
var saveStrList = changeIntListToStringList(publicKey);
|
||||
final List<int> publicKey = reply.data.sublist(3);
|
||||
final List<String> saveStrList = changeIntListToStringList(publicKey);
|
||||
Storage.setStringList(saveBluePublicKey, saveStrList);
|
||||
|
||||
// 获取私钥
|
||||
@ -140,22 +142,21 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
reply.data.removeAt(0);
|
||||
|
||||
// 私钥
|
||||
List<int> privateKey = reply.data.sublist(0, 16);
|
||||
var savePrivateKeyList = changeIntListToStringList(privateKey);
|
||||
final List<int> privateKey = reply.data.sublist(0, 16);
|
||||
final List<String> savePrivateKeyList = changeIntListToStringList(privateKey);
|
||||
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
|
||||
|
||||
// signKey
|
||||
List<int> signKey = reply.data.sublist(16, 32);
|
||||
var saveSignKeyList = changeIntListToStringList(signKey);
|
||||
final List<int> signKey = reply.data.sublist(16, 32);
|
||||
final List<String> saveSignKeyList = changeIntListToStringList(signKey);
|
||||
Storage.setStringList(saveBlueSignKey, saveSignKeyList);
|
||||
|
||||
// 时间戳
|
||||
List<int> timestamp = reply.data.sublist(32, 36);
|
||||
state.timestampValue = ((0xff & timestamp[(0)]) << 24 |
|
||||
final List<int> timestamp = reply.data.sublist(32, 36);
|
||||
state.timestampValue = (0xff & timestamp[0]) << 24 |
|
||||
(0xff & timestamp[1]) << 16 |
|
||||
(0xff & timestamp[2]) << 8 |
|
||||
(0xFF & timestamp[3]));
|
||||
|
||||
(0xFF & timestamp[3]);
|
||||
showTitleEasyLoading('获取锁信息 3/3');
|
||||
_getStarLockStatus();
|
||||
break;
|
||||
@ -167,138 +168,138 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
|
||||
// 获取星锁状态
|
||||
Future<void> _replyGetStarLockStatusInfo(Reply reply) async {
|
||||
int status = reply.data[2];
|
||||
final int status = reply.data[2];
|
||||
switch (status) {
|
||||
case 0x00:
|
||||
//成功
|
||||
AppLog.log('获取锁状态成功');
|
||||
// 厂商名称
|
||||
var index = 3;
|
||||
var vendor = reply.data.sublist(index, index + 20);
|
||||
var vendorStr = utf8String(vendor);
|
||||
int index = 3;
|
||||
final List<int> vendor = reply.data.sublist(index, index + 20);
|
||||
final String vendorStr = utf8String(vendor);
|
||||
state.lockInfo['vendor'] = vendorStr;
|
||||
// state.lockInfo["vendor"] = "XL";
|
||||
index = index + 20;
|
||||
AppLog.log('厂商名称 vendorStr:$vendorStr');
|
||||
|
||||
// 锁设备类型
|
||||
var product = reply.data[index];
|
||||
final int product = reply.data[index];
|
||||
state.lockInfo['product'] = product;
|
||||
index = index + 1;
|
||||
AppLog.log('锁设备类型 product:$product');
|
||||
|
||||
// 产品名称
|
||||
var model = reply.data.sublist(index, index + 20);
|
||||
var modelStr = utf8String(model);
|
||||
final List<int> model = reply.data.sublist(index, index + 20);
|
||||
final String modelStr = utf8String(model);
|
||||
state.lockInfo['model'] = modelStr;
|
||||
// state.lockInfo["model"] = "JL-BLE-01";
|
||||
index = index + 20;
|
||||
AppLog.log('产品名称 mmodelStr:$modelStr');
|
||||
|
||||
// 软件版本
|
||||
var fwVersion = reply.data.sublist(index, index+20);
|
||||
var fwVersionStr = utf8String(fwVersion);
|
||||
final List<int> fwVersion = reply.data.sublist(index, index+20);
|
||||
final String fwVersionStr = utf8String(fwVersion);
|
||||
state.lockInfo['fwVersion'] = fwVersionStr;
|
||||
index = index + 20;
|
||||
AppLog.log('软件版本 fwVersionStr:$fwVersionStr');
|
||||
|
||||
// 硬件版本
|
||||
var hwVersion = reply.data.sublist(index, index+20);
|
||||
var hwVersionStr = utf8String(hwVersion);
|
||||
final List<int> hwVersion = reply.data.sublist(index, index+20);
|
||||
final String hwVersionStr = utf8String(hwVersion);
|
||||
state.lockInfo['hwVersion'] = hwVersionStr;
|
||||
index = index + 20;
|
||||
AppLog.log('硬件版本 hwVersionStr:$hwVersionStr');
|
||||
|
||||
// 厂商序列号
|
||||
var serialNum0 = reply.data.sublist(index, index + 16);
|
||||
var serialNum0Str = utf8String(serialNum0);
|
||||
final List<int> serialNum0 = reply.data.sublist(index, index + 16);
|
||||
final String serialNum0Str = utf8String(serialNum0);
|
||||
state.lockInfo['serialNum0'] = serialNum0Str;
|
||||
// state.lockInfo["serialNum0"] = "${DateTime.now().millisecondsSinceEpoch ~/ 10}";
|
||||
index = index + 16;
|
||||
AppLog.log('厂商序列号 serialNum0Str:${serialNum0Str.length}');
|
||||
|
||||
// 成品商序列号
|
||||
var serialNum1 = reply.data.sublist(index, index + 16);
|
||||
var serialNum1Str = utf8String(serialNum1);
|
||||
final List<int> serialNum1 = reply.data.sublist(index, index + 16);
|
||||
final String serialNum1Str = utf8String(serialNum1);
|
||||
state.lockInfo['serialNum1'] = serialNum1Str;
|
||||
index = index + 16;
|
||||
AppLog.log('成品商序列号 serialNum1Str:$serialNum1Str');
|
||||
|
||||
// 蓝牙名称
|
||||
var btDeviceName = reply.data.sublist(index, index + 16);
|
||||
var btDeviceNameStr = utf8String(btDeviceName);
|
||||
final List<int> btDeviceName = reply.data.sublist(index, index + 16);
|
||||
final String btDeviceNameStr = utf8String(btDeviceName);
|
||||
state.lockInfo['btDeviceName'] = btDeviceNameStr;
|
||||
index = index + 16;
|
||||
AppLog.log('蓝牙名称 btDeviceNameStr:$btDeviceNameStr');
|
||||
|
||||
// 电池剩余电量
|
||||
var battRemCap = reply.data[index];
|
||||
final int battRemCap = reply.data[index];
|
||||
state.lockInfo['electricQuantity'] = battRemCap;
|
||||
index = index + 1;
|
||||
AppLog.log('电池剩余电量 battRemCap:$battRemCap');
|
||||
|
||||
// 备用电池剩余电量
|
||||
var battRemCapStandby = reply.data[index];
|
||||
final int battRemCapStandby = reply.data[index];
|
||||
state.lockInfo['electricQuantityStandby'] = battRemCapStandby;
|
||||
index = index + 1;
|
||||
AppLog.log('电池剩余电量 battRemCap:$battRemCap');
|
||||
|
||||
// 重置次数
|
||||
var restoreCounter = reply.data.sublist(index, index + 2);
|
||||
final List<int> restoreCounter = reply.data.sublist(index, index + 2);
|
||||
state.lockInfo['restoreCount'] = restoreCounter[0] * 256 + restoreCounter[1];
|
||||
index = index + 2;
|
||||
AppLog.log('重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}');
|
||||
|
||||
// 重置时间
|
||||
var restoreDate = reply.data.sublist(index, index + 4);
|
||||
int restoreDateValue = ((0xff & restoreDate[(0)]) << 24 |
|
||||
final List<int> restoreDate = reply.data.sublist(index, index + 4);
|
||||
final int restoreDateValue = (0xff & restoreDate[0]) << 24 |
|
||||
(0xff & restoreDate[1]) << 16 |
|
||||
(0xff & restoreDate[2]) << 8 |
|
||||
(0xFF & restoreDate[3]));
|
||||
(0xFF & restoreDate[3]);
|
||||
// String restoreDateStr = DateTool().dateToYMDHNSString(restoreDateValue.toString());
|
||||
state.lockInfo['restoreDate'] = restoreDateValue * 1000;
|
||||
index = index + 4;
|
||||
AppLog.log('重置时间 restoreDateValue:$restoreDateValue');
|
||||
|
||||
// 主控芯片型号
|
||||
var icPartNo = reply.data.sublist(index, index + 10);
|
||||
var icPartNoStr = utf8String(icPartNo);
|
||||
final List<int> icPartNo = reply.data.sublist(index, index + 10);
|
||||
final String icPartNoStr = utf8String(icPartNo);
|
||||
state.lockInfo['icPartNo'] = icPartNoStr;
|
||||
index = index + 10;
|
||||
AppLog.log('主控芯片型号 icPartNoStr:$icPartNoStr');
|
||||
|
||||
// 有效时间
|
||||
var indate = reply.data.sublist(index, index + 4);
|
||||
int indateValue = ((0xff & indate[(0)]) << 24 |
|
||||
final List<int> indate = reply.data.sublist(index, index + 4);
|
||||
final int indateValue = (0xff & indate[0]) << 24 |
|
||||
(0xff & indate[1]) << 16 |
|
||||
(0xff & indate[2]) << 8 |
|
||||
(0xFF & indate[3]));
|
||||
(0xFF & indate[3]);
|
||||
// String indateStr = DateTool().dateToYMDHNSString("$indateValue");
|
||||
state.lockInfo['indate'] = indateValue * 1000;
|
||||
index = index + 4;
|
||||
AppLog.log('有效时间 indateValue:$indateValue');
|
||||
|
||||
// mac地址
|
||||
var macAddress = reply.data.sublist(index, index + 20);
|
||||
var macAddressStr = utf8String(macAddress);
|
||||
final List<int> macAddress = reply.data.sublist(index, index + 20);
|
||||
final String macAddressStr = utf8String(macAddress);
|
||||
state.lockInfo['mac'] = macAddressStr;
|
||||
index = index + 20;
|
||||
AppLog.log('mac地址 macAddressStr:$macAddressStr');
|
||||
|
||||
// 锁特征值字符串长度
|
||||
var featureValueLength = reply.data[index];
|
||||
final int featureValueLength = reply.data[index];
|
||||
index = index + 1;
|
||||
AppLog.log('锁特征值字符串长度 featureValueLength:$featureValueLength');
|
||||
|
||||
// 锁特征值说明(本机能支持的功能)
|
||||
// 获取到锁给的字符数组
|
||||
var featureNetxLength = index + featureValueLength;
|
||||
final int featureNetxLength = index + featureValueLength;
|
||||
if (reply.data.length < featureNetxLength) {
|
||||
showToast('锁数据异常,请重试');
|
||||
return;
|
||||
}
|
||||
var featureValue = reply.data.sublist(index, index + featureValueLength);
|
||||
String featureValueStr = asciiString(featureValue);
|
||||
final List<int> featureValue = reply.data.sublist(index, index + featureValueLength);
|
||||
final String featureValueStr = asciiString(featureValue);
|
||||
state.featureValue = featureValueStr;
|
||||
// List allFeatureValueTwoList = charListChangeIntList(featureValue);
|
||||
// AppLog.log("featureValueLength:$featureValueLength featureValue:$featureValue \n featureValueStr:$featureValueStr");
|
||||
@ -306,18 +307,18 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
AppLog.log('锁特征值字符串 featureValueStr:$featureValueStr');
|
||||
|
||||
// 使能特征值字符串长度
|
||||
var featureEnValLength = reply.data[index];
|
||||
final int featureEnValLength = reply.data[index];
|
||||
index = index + 1;
|
||||
AppLog.log('使能特征值字符串长度 featureEnValLength:$featureEnValLength');
|
||||
|
||||
// 使能锁特征值说明(本机启用的功能)
|
||||
var featureEnNextLength = index + featureEnValLength;
|
||||
final int featureEnNextLength = index + featureEnValLength;
|
||||
if (reply.data.length < featureEnNextLength) {
|
||||
showToast('锁数据异常,请重试');
|
||||
return;
|
||||
}
|
||||
var featureEnVal = reply.data.sublist(index, index + featureEnValLength);
|
||||
String featureEnValStr = asciiString(featureEnVal);
|
||||
final List<int> featureEnVal = reply.data.sublist(index, index + featureEnValLength);
|
||||
final String featureEnValStr = asciiString(featureEnVal);
|
||||
state.featureSettingValue = featureEnValStr;
|
||||
// List allFeatureEnValTwoList = charListChangeIntList(featureEnVal);
|
||||
// AppLog.log("featureEnValLength:$featureEnValLength featureEnVal:$featureEnVal \n featureEnValStr:$featureEnValStr");
|
||||
@ -327,11 +328,11 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
// 支持的带参数特征值的总条目数
|
||||
// var featureParaTotal = reply.data[index];
|
||||
|
||||
var featureParaTotalList = reply.data.sublist(index);
|
||||
final List<int> featureParaTotalList = reply.data.sublist(index);
|
||||
state.featureSettingParams = featureParaTotalList;
|
||||
AppLog.log('featureParaTotalList:$featureParaTotalList');
|
||||
|
||||
Get.toNamed(Routers.lockAddressGaoDePage, arguments: {
|
||||
Get.toNamed(Routers.lockAddressGaoDePage, arguments: <String, Object>{
|
||||
'pwdTimestamp': state.timestampValue * 1000,
|
||||
'lockInfo': state.lockInfo,
|
||||
'featureValue': state.featureValue,
|
||||
@ -342,8 +343,8 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
break;
|
||||
case 0x06:
|
||||
//无权限
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
// IoSenderManage.senderGetLockStatu(
|
||||
// lockID:BlueManage().connectDeviceName,
|
||||
// userID:await Storage.getUid(),
|
||||
@ -352,8 +353,8 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
IoSenderManage.senderGetStarLockStatuInfo(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
utcTimeStamp: getUTCNetTime(),
|
||||
unixTimeStamp: getLocalNetTime(),
|
||||
utcTimeStamp: getUTCTime(),
|
||||
unixTimeStamp: getLocalTime(),
|
||||
isBeforeAddUser: true,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
@ -373,14 +374,14 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
// dismissEasyLoading();
|
||||
|
||||
AppLog.log('开始获取锁状态');
|
||||
var privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
|
||||
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
|
||||
|
||||
IoSenderManage.senderGetStarLockStatuInfo(
|
||||
lockID: BlueManage().connectDeviceName,
|
||||
userID: await Storage.getUid(),
|
||||
utcTimeStamp: getUTCNetTime(),
|
||||
unixTimeStamp: getLocalNetTime(),
|
||||
utcTimeStamp: getUTCTime(),
|
||||
unixTimeStamp: getLocalTime(),
|
||||
isBeforeAddUser: true,
|
||||
privateKey: getPrivateKeyList,
|
||||
);
|
||||
@ -394,12 +395,12 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
BlueManage().startScan(2000, (List<ScanResult> list) {
|
||||
state.devices.clear();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
ScanResult device = list[i];
|
||||
if (((device.advertisementData.serviceUuids.isNotEmpty
|
||||
final ScanResult device = list[i];
|
||||
if ((device.advertisementData.serviceUuids.isNotEmpty
|
||||
? device.advertisementData.serviceUuids[0]
|
||||
: '')
|
||||
.toString()[31] !=
|
||||
'1')) {
|
||||
'1') {
|
||||
state.devices.add(list[i]);
|
||||
}
|
||||
}
|
||||
@ -431,16 +432,16 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
|
||||
//手动升级
|
||||
Future<void> otaUpdate() async {
|
||||
var status = await PermissionDialog.requestStorage();
|
||||
final bool status = await PermissionDialog.requestStorage();
|
||||
if (status != true) {
|
||||
return;
|
||||
}
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles();
|
||||
final FilePickerResult? result = await FilePicker.platform.pickFiles();
|
||||
if (result == null || result.files.single.path is! String) {
|
||||
return;
|
||||
}
|
||||
File file = File(result.files.single.path!);
|
||||
Uint8List data = await file.readAsBytes();
|
||||
final File file = File(result.files.single.path!);
|
||||
final Uint8List data = await file.readAsBytes();
|
||||
headJson = await getHeadFile(data);
|
||||
if (headJson is! Map) {
|
||||
return;
|
||||
@ -449,9 +450,9 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
if (otaBin == null) {
|
||||
return;
|
||||
}
|
||||
String md5Str = md5.convert(otaBin!).toString();
|
||||
final String md5Str = md5.convert(otaBin!).toString();
|
||||
headJson!['fwMd5'] = md5Str;
|
||||
blueOTAUpgrade(headJson!, [0, 0, 0, 0]);
|
||||
blueOTAUpgrade(headJson!, <int>[0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
//蓝牙操作 ota 升级
|
||||
@ -463,7 +464,7 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
BlueManage().blueSendData(deviceName!,
|
||||
(BluetoothConnectionState deviceConnectionState) async {
|
||||
if (deviceConnectionState == BluetoothConnectionState.connected) {
|
||||
String uid = await Storage.getUid() ?? '';
|
||||
final String uid = await Storage.getUid() ?? '';
|
||||
BlueManage().writeCharacteristicWithResponse(OTAUpgradeCommand(
|
||||
lockID: deviceName,
|
||||
userID: uid,
|
||||
@ -488,29 +489,29 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
if (!state.otaUpdateIng.value) {
|
||||
return;
|
||||
}
|
||||
int length = otaBin?.length ?? 0;
|
||||
final int length = otaBin?.length ?? 0;
|
||||
if (otaCount == 0) {
|
||||
//首次
|
||||
int difference = length % 240;
|
||||
final int difference = length % 240;
|
||||
otaCount = length ~/ 240 + (difference > 0 ? 1 : 0);
|
||||
startSecond = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
}
|
||||
if (otaCount <= otaIndex) {
|
||||
int now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
String msg =
|
||||
final int now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
final String msg =
|
||||
'传输完成 时间:${now - startSecond}秒 otaCount:$otaCount otaIndex:$otaIndex ';
|
||||
closeOTADAta();
|
||||
AppLog.log(msg);
|
||||
// showToast(msg);
|
||||
return;
|
||||
}
|
||||
int star = otaIndex * 240;
|
||||
final int star = otaIndex * 240;
|
||||
int end = (otaIndex + 1) * 240;
|
||||
if (end > length) {
|
||||
end = length;
|
||||
}
|
||||
int size = end - star;
|
||||
List<int> data = otaBin!.sublist(star, end);
|
||||
final int size = end - star;
|
||||
final List<int> data = otaBin!.sublist(star, end);
|
||||
state.otaProgress.value = otaIndex / otaCount;
|
||||
await BlueManage().writeCharacteristicWithResponse(
|
||||
ProcessOtaUpgradeCommand(index: otaIndex, size: size, data: data)
|
||||
@ -594,7 +595,7 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
return null;
|
||||
}
|
||||
AppLog.log(metaStr);
|
||||
var meta = jsonDecode(metaStr);
|
||||
final meta = jsonDecode(metaStr);
|
||||
if (meta is! Map) {
|
||||
showToast('解析元数据失败,请选择正确的文件'.tr);
|
||||
return null;
|
||||
@ -604,11 +605,11 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
|
||||
//检测升级文件并读取 bin
|
||||
Future<Uint8List?> checkFile(Uint8List data, Map meta) async {
|
||||
num binOffset = 16 + (meta['metaLen'] ?? 0);
|
||||
final num binOffset = 16 + (meta['metaLen'] ?? 0);
|
||||
// 获取固件数据部分
|
||||
Uint8List bin = data.sublist(binOffset.toInt(), data.length);
|
||||
final Uint8List bin = data.sublist(binOffset.toInt(), data.length);
|
||||
//md5 校验有问题,暂时不解析
|
||||
String md5Str = md5.convert(bin).toString().toUpperCase();
|
||||
final String md5Str = md5.convert(bin).toString().toUpperCase();
|
||||
// AppLog.log('---> $md5Str ${meta['fwMd5']}');
|
||||
if (md5Str != meta['fwMd5']) {
|
||||
showToast('文件校验失败 0x02'.tr);
|
||||
@ -622,27 +623,25 @@ class NearbyLockLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
// 从服务器获取锁的时间 开锁时传入
|
||||
void getServerDatetime() async{
|
||||
var entity = await ApiRepository.to.getServerDatetimeData();
|
||||
Future<void> getServerDatetime() async{
|
||||
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData();
|
||||
if(entity.errorCode!.codeIsSuccessful){
|
||||
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
getLocalNetTime();
|
||||
// AppLog.log("entity.data!.date! ~/ 1000:${entity.data!.date! ~/ 1000} DateTime.now().millisecondsSinceEpoch ~/ 1000:${DateTime.now().millisecondsSinceEpoch ~/ 1000} 服务器时间差:${state.differentialTime}");
|
||||
}
|
||||
}
|
||||
|
||||
int getUTCNetTime(){
|
||||
int getLocalTime(){
|
||||
return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime;
|
||||
}
|
||||
|
||||
int getLocalNetTime(){
|
||||
DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getUTCNetTime()*1000, isUtc: true);
|
||||
DateTime localTime = utcTime.toLocal();
|
||||
int getUTCTime(){
|
||||
final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true);
|
||||
|
||||
// AppLog.log('getUTCNetTime: ${getUTCNetTime()}');
|
||||
// AppLog.log('UTC time: $utcTime');
|
||||
// AppLog.log('Local time: $localTime localTime.millisecondsSinceEpoch ~/ 1000:${localTime.millisecondsSinceEpoch ~/ 1000}');
|
||||
return localTime.millisecondsSinceEpoch ~/ 1000;
|
||||
final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1);
|
||||
final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1);
|
||||
AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue');
|
||||
return utcTimeValue ~/ 1000;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -95,7 +95,6 @@ class MinePersonInfoLogic extends BaseGetXController {
|
||||
source: ImageSource.camera,
|
||||
maxHeight: 250,
|
||||
maxWidth: 250,
|
||||
imageQuality: 80
|
||||
);
|
||||
if (photo != null) {
|
||||
state.image = photo;
|
||||
|
||||
@ -116,6 +116,40 @@ class DateTool {
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
/// 根据传入的PDuration及时间类型获取时间字符串
|
||||
/// type 1: 年月日时分(2023-01-01 12:00) 2: 年月日(2023-01-01) 3: 时分(12:00)
|
||||
String getYMDHNDateStringWithDateTime(DateTime p, int type) {
|
||||
final int year = p.year == 0 ? DateTime.now().year : p.year;
|
||||
final int month = p.month == 0 ? DateTime.now().month : p.month;
|
||||
final int day = p.day == 0 ? DateTime.now().day : p.day;
|
||||
final int hour = p.hour;
|
||||
final int minute = p.minute;
|
||||
|
||||
String dateStr = '';
|
||||
switch (type) {
|
||||
case 1:
|
||||
// 年月日时分(2023-01-01 12:48)
|
||||
dateStr =
|
||||
'$year-${month!.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')} ${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}';
|
||||
break;
|
||||
case 2:
|
||||
// 年月日(2023-01-01)
|
||||
dateStr =
|
||||
'$year-${month!.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')}';
|
||||
break;
|
||||
case 3:
|
||||
// 时分(12:05)
|
||||
dateStr =
|
||||
'${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}';
|
||||
break;
|
||||
default:
|
||||
dateStr =
|
||||
'$year-${month!.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')} ${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}';
|
||||
break;
|
||||
}
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
/// 日期转化为时间戳
|
||||
/// type 0: 12:00 1: 其他
|
||||
int dateToTimestamp(String dateStr, int type) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user