1、修改上传锁时间、更新电量上传UTC时间问题。2、修改拍照头像上传比较慢问题

This commit is contained in:
魏少阳 2024-06-04 09:12:41 +08:00
parent 0e38550b94
commit bc440ec377
10 changed files with 283 additions and 237 deletions

View File

@ -26,7 +26,7 @@ class GetStarLockStatuInfoCommand extends SenderProtocol {
@override @override
String toString() { String toString() {
return 'GetStarLockStatuInfoCommand{lockID: $lockID, ' 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}'; 'userID: $userID, privateKey: $privateKey}';
} }

View File

@ -2,7 +2,9 @@ import 'dart:async';
import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.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/blue_manage.dart';
import '../../../../../blue/io_protocol/io_getStarLockStatusInfo.dart'; import '../../../../../blue/io_protocol/io_getStarLockStatusInfo.dart';
import '../../../../../blue/io_reply.dart'; import '../../../../../blue/io_reply.dart';
@ -11,6 +13,7 @@ import '../../../../../blue/io_tool/manager_event_bus.dart';
import '../../../../../blue/sender_manage.dart'; import '../../../../../blue/sender_manage.dart';
import '../../../../../network/api_repository.dart'; import '../../../../../network/api_repository.dart';
import '../../../../../tools/baseGetXController.dart'; import '../../../../../tools/baseGetXController.dart';
import '../../../../../tools/dateTool.dart';
import '../../../../../tools/eventBusEventManage.dart'; import '../../../../../tools/eventBusEventManage.dart';
import '../../../../../tools/storage.dart'; import '../../../../../tools/storage.dart';
import '../../../lockOperatingRecord/keyOperationRecord_entity.dart'; import '../../../lockOperatingRecord/keyOperationRecord_entity.dart';
@ -54,13 +57,13 @@ class UploadElectricQuantityLogic extends BaseGetXController {
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
dismissEasyLoading(); dismissEasyLoading();
final privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
IoSenderManage.senderGetStarLockStatuInfo( IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
utcTimeStamp: getUTCNetTime(), utcTimeStamp: getUTCTime(),
unixTimeStamp: getLocalNetTime(), unixTimeStamp: getLocalTime(),
isBeforeAddUser: false, isBeforeAddUser: false,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
); );
@ -79,7 +82,7 @@ class UploadElectricQuantityLogic extends BaseGetXController {
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) { EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
// //
if (reply is GetStarLockStatuInfoReply) { if (reply is GetStarLockStatuInfoReply) {
_replyGetStarLockStatusInfo(reply); _replyGetStarLockStatusInfo(reply);
@ -98,11 +101,11 @@ class UploadElectricQuantityLogic extends BaseGetXController {
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
// //
final battRemCap = reply.data[132]; final int battRemCap = reply.data[132];
state.lockSetInfoData.value.lockBasicInfo!.electricQuantity = battRemCap; state.lockSetInfoData.value.lockBasicInfo!.electricQuantity = battRemCap;
// //
final battRemCapStandby = reply.data[133]; final int battRemCapStandby = reply.data[133];
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby = battRemCapStandby; state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby = battRemCapStandby;
state.uploadElectricQuantityDate.value = DateTime.now().millisecondsSinceEpoch; state.uploadElectricQuantityDate.value = DateTime.now().millisecondsSinceEpoch;
@ -111,16 +114,18 @@ class UploadElectricQuantityLogic extends BaseGetXController {
break; break;
case 0x06: case 0x06:
// //
final privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
IoSenderManage.senderGetStarLockStatuInfo( IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
utcTimeStamp: getUTCNetTime(), utcTimeStamp: getUTCTime(),
unixTimeStamp: getLocalNetTime(), unixTimeStamp: getLocalTime(),
isBeforeAddUser: false, isBeforeAddUser: false,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
); );
break; break;
default: default:
// //
@ -129,32 +134,29 @@ class UploadElectricQuantityLogic extends BaseGetXController {
} }
// //
void getServerDatetime() async{ Future<void> getServerDatetime() async{
final entity = await ApiRepository.to.getServerDatetimeData(); final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData();
if(entity.errorCode!.codeIsSuccessful){ if(entity.errorCode!.codeIsSuccessful){
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000; 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}"); // 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; return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime;
} }
int getLocalNetTime(){ int getUTCTime(){
final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getUTCNetTime()*1000, isUtc: true); final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true);
final DateTime localTime = utcTime.toLocal();
// AppLog.log('getUTCNetTime: ${getUTCNetTime()}'); final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1);
// AppLog.log('UTC time: $utcTime'); final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1);
// AppLog.log('Local time: $localTime localTime.millisecondsSinceEpoch ~/ 1000:${localTime.millisecondsSinceEpoch ~/ 1000}'); AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue');
return localTime.millisecondsSinceEpoch ~/ 1000; return utcTimeValue ~/ 1000;
} }
@override @override
void onReady() { void onReady() {
// TODO: implement onReady
super.onReady(); super.onReady();
_initReplySubscription(); _initReplySubscription();
@ -163,13 +165,11 @@ class UploadElectricQuantityLogic extends BaseGetXController {
@override @override
void onInit() { void onInit() {
// TODO: implement onInit
super.onInit(); super.onInit();
} }
@override @override
void onClose() { void onClose() {
// TODO: implement onClose
super.onClose(); super.onClose();
_replySubscription.cancel(); _replySubscription.cancel();
} }

View File

@ -3,9 +3,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.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 '../../../../../app_settings/app_colors.dart';
import '../../../../../blue/blue_manage.dart';
import '../../../../../tools/appRouteObserver.dart'; import '../../../../../tools/appRouteObserver.dart';
import '../../../../../tools/dateTool.dart'; import '../../../../../tools/dateTool.dart';
import '../../../../../tools/submitBtn.dart'; import '../../../../../tools/submitBtn.dart';
@ -22,8 +22,8 @@ class UploadElectricQuantityPage extends StatefulWidget {
} }
class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage> with RouteAware { class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage> with RouteAware {
final logic = Get.put(UploadElectricQuantityLogic()); final UploadElectricQuantityLogic logic = Get.put(UploadElectricQuantityLogic());
final state = Get.find<UploadElectricQuantityLogic>().state; final UploadElectricQuantityState state = Get.find<UploadElectricQuantityLogic>().state;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -36,10 +36,10 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
body: Container( body: Container(
padding: EdgeInsets.all(30.w), padding: EdgeInsets.all(30.w),
child: Column( child: Column(
children: [ children: <Widget>[
Row( Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: <Widget>[
Expanded( Expanded(
child: Text( child: Text(
TranslationLoader.lanKeys!.updateElectricQuantityTip!.tr, TranslationLoader.lanKeys!.updateElectricQuantityTip!.tr,
@ -52,7 +52,7 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
), ),
Obx(() => Row( Obx(() => Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: <Widget>[
Expanded( Expanded(
child: Text( child: Text(
"${"电池1".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantity ?? ""}%", "${"电池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, visible: state.lockSetInfoData.value.lockFeature!.isSupportBackupBattery == 1,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: <Widget>[
Expanded( Expanded(
child: Text( child: Text(
"${"电池2".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantityStandby ?? ""}%", "${"电池2".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantityStandby ?? ""}%",
@ -76,7 +76,7 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
SizedBox(height: 10.h), SizedBox(height: 10.h),
Obx(() => Row( Obx(() => Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: <Widget>[
Expanded( Expanded(
child: Text( child: Text(
"${"电量更新时间".tr}:${DateTool().dateToYMDHNString(state.uploadElectricQuantityDate.value.toString())}", "${"电量更新时间".tr}:${DateTool().dateToYMDHNString(state.uploadElectricQuantityDate.value.toString())}",
@ -104,7 +104,6 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
@override @override
void didChangeDependencies() { void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies(); super.didChangeDependencies();
/// ///
@ -113,7 +112,6 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
@override @override
void dispose() { void dispose() {
// TODO: implement dispose
/// ///
AppRouteObserver().routeObserver.unsubscribe(this); AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose(); super.dispose();
@ -148,7 +146,9 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
void didPushNext() { void didPushNext() {
super.didPushNext(); super.didPushNext();
logic.cancelBlueConnetctToastTimer(); logic.cancelBlueConnetctToastTimer();
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
state.ifCurrentScreen.value = false; state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
} }

View File

@ -3,24 +3,24 @@ import 'package:get/get.dart';
import '../../lockSet/lockSetInfo_entity.dart'; import '../../lockSet/lockSetInfo_entity.dart';
class UploadElectricQuantityState { class UploadElectricQuantityState {// 0 1
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
UploadElectricQuantityState() { UploadElectricQuantityState() {
var map = Get.arguments; final map = Get.arguments;
if(map["lockSetInfoData"]!=null){ if(map['lockSetInfoData']!=null){
lockSetInfoData.value = map["lockSetInfoData"]; lockSetInfoData.value = map['lockSetInfoData'];
if(lockSetInfoData.value.lockBasicInfo!=null){ if(lockSetInfoData.value.lockBasicInfo!=null){
lockBasicInfo.value = lockSetInfoData.value.lockBasicInfo!; lockBasicInfo.value = lockSetInfoData.value.lockBasicInfo!;
uploadElectricQuantityDate.value = lockSetInfoData.value.lockBasicInfo!.electricQuantityDate!; 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;
} }

View File

@ -1,8 +1,11 @@
import 'dart:async'; import 'dart:async';
import 'package:date_format/date_format.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.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/blue_manage.dart';
import '../../../../blue/io_protocol/io_getStarLockStatusInfo.dart'; import '../../../../blue/io_protocol/io_getStarLockStatusInfo.dart';
@ -23,65 +26,69 @@ class LockTimeLogic extends BaseGetXController{
// //
late StreamSubscription<Reply> _replySubscription; late StreamSubscription<Reply> _replySubscription;
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) { _replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
if(reply is TimingReply) { if(reply is TimingReply) {
_replyTiming(reply); _replyTiming(reply);
} }
// //
// if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) { if(reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) {
// _replyGetStarLockStatusInfo(reply); _replyGetStarLockStatusInfo(reply);
// } }
}); });
} }
// //
// Future<void> _replyGetStarLockStatusInfo(Reply reply) async { Future<void> _replyGetStarLockStatusInfo(Reply reply) async {
// int status = reply.data[2]; final int status = reply.data[2];
// switch (status) { switch (status) {
// case 0x00: case 0x00:
// // //
// cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
// dismissEasyLoading(); dismissEasyLoading();
//
// // //
// var indate = reply.data.sublist(149, 153); final List<int> indate = reply.data.sublist(150, 154);
// int indateValue = ((0xff & indate[(0)]) << 24 | final int indateValue = (0xff & indate[0]) << 24 |
// (0xff & indate[1]) << 16 | (0xff & indate[1]) << 16 |
// (0xff & indate[2]) << 8 | (0xff & indate[2]) << 8 |
// (0xFF & indate[3])); (0xFF & indate[3]);
// state.dateTime.value = DateTool().dateToYMDHNString("$indateValue"); AppLog.log('indate:$indate indateValue:$indateValue');
// break; state.dateTime.value = DateTool().dateToYMDHNString('$indateValue');
// case 0x06: break;
// // case 0x06:
// var privateKey = await Storage.getStringList(saveBluePrivateKey); //
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
// IoSenderManage.senderGetStarLockStatuInfo( final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
// lockID: BlueManage().connectDeviceName,
// userID: await Storage.getUid(), IoSenderManage.senderGetStarLockStatuInfo(
// isBeforeAddUser: false, lockID: BlueManage().connectDeviceName,
// privateKey: getPrivateKeyList, userID: await Storage.getUid(),
// ); utcTimeStamp: 0,
// break; unixTimeStamp: 0,
// default: isBeforeAddUser: false,
// // privateKey: getPrivateKeyList,
// break; );
// } break;
// } default:
//
break;
}
}
// //
Future<void> _replyTiming(Reply reply) async { Future<void> _replyTiming(Reply reply) async {
int status = reply.data[2]; final int status = reply.data[2];
switch(status){ switch(status){
case 0x00: case 0x00:
// //
String dataEime = DateTool().dateToYMDHNString("${getUTCNetTime()}"); final String dataEime = DateTool().dateToYMDHNString('${getLocalTime()}');
state.dateTime.value = dataEime; state.dateTime.value = dataEime;
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
dismissEasyLoading(); dismissEasyLoading();
showToast("锁时间更新成功".tr); showToast('锁时间更新成功'.tr);
break; break;
case 0x06: case 0x06:
// //
@ -105,20 +112,19 @@ class LockTimeLogic extends BaseGetXController{
}); });
BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) { if (connectionState == BluetoothConnectionState.connected) {
var privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
var token = await Storage.getStringList(saveBlueToken); final List<String>? token = await Storage.getStringList(saveBlueToken);
List<int> getTokenList = changeStringListToIntList(token!); final List<int> getTokenList = changeStringListToIntList(token!);
var signKey = await Storage.getStringList(saveBlueSignKey); final List<String>? signKey = await Storage.getStringList(saveBlueSignKey);
List<int> getSignKeyList = changeStringListToIntList(signKey!); final List<int> getSignKeyList = changeStringListToIntList(signKey!);
IoSenderManage.senderTimingCommand( IoSenderManage.senderTimingCommand(
lockID:BlueManage().connectDeviceName, lockID:BlueManage().connectDeviceName,
userID:await Storage.getUid(), userID:await Storage.getUid(),
// nowTime:DateTime.now().millisecondsSinceEpoch~/1000, nowTime: getLocalTime(),
nowTime: getUTCNetTime(),
token:getTokenList, token:getTokenList,
needAuthor:1, needAuthor:1,
signKey:getSignKeyList, signKey:getSignKeyList,
@ -135,37 +141,39 @@ class LockTimeLogic extends BaseGetXController{
}); });
} }
// //
// Future<void> getStarLockStatus() async { Future<void> getStarLockStatus() async {
// showEasyLoading(); showEasyLoading();
// showBlueConnetctToastTimer(action: () { showBlueConnetctToastTimer(action: () {
// dismissEasyLoading(); dismissEasyLoading();
// }); });
// BlueManage().bludSendData(BlueManage().connectDeviceName, BlueManage().blueSendData(BlueManage().connectDeviceName,
// (BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
// if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
// dismissEasyLoading(); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
// var privateKey = await Storage.getStringList(saveBluePrivateKey); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
// List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
// IoSenderManage.senderGetStarLockStatuInfo( IoSenderManage.senderGetStarLockStatuInfo(
// lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
// userID: await Storage.getUid(), userID: await Storage.getUid(),
// isBeforeAddUser: false, utcTimeStamp: 0,
// privateKey: getPrivateKeyList, unixTimeStamp: 0,
// ); isBeforeAddUser: false,
// } else if (deviceConnectionState == BluetoothConnectionState.disconnected) { privateKey: getPrivateKeyList,
// dismissEasyLoading(); );
// cancelBlueConnetctToastTimer(); } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
// if (state.ifCurrentScreen.value == true) { dismissEasyLoading();
// showBlueConnetctToast(); cancelBlueConnetctToastTimer();
// } if (state.ifCurrentScreen.value == true) {
// } showBlueConnetctToast();
// }); }
// } }
});
}
// //
void getLockTimeFromGateway() async{ Future<void> getLockTimeFromGateway() async{
var entity = await ApiRepository.to.getLockTimeFromGateway( final GetServerDatetimeEntity entity = await ApiRepository.to.getLockTimeFromGateway(
lockId: state.lockSetInfoData.value.lockId.toString(), lockId: state.lockSetInfoData.value.lockId.toString(),
); );
if(entity.errorCode!.codeIsSuccessful){ if(entity.errorCode!.codeIsSuccessful){
@ -174,41 +182,45 @@ class LockTimeLogic extends BaseGetXController{
} }
// //
void getServerDatetime() async{ Future<void> getServerDatetime() async{
var entity = await ApiRepository.to.getServerDatetimeData(); final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData();
if(entity.errorCode!.codeIsSuccessful){ if(entity.errorCode!.codeIsSuccessful){
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000; 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}"); // 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; 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 @override
void onReady() { void onReady() {
// TODO: implement onReady
super.onReady(); super.onReady();
_initReplySubscription(); _initReplySubscription();
// getStarLockStatus();
// getLockTimeFromGateway(); // getLockTimeFromGateway();
getServerDatetime(); getServerDatetime();
} }
@override @override
void onInit() { void onInit() {
// TODO: implement onInit
super.onInit(); super.onInit();
// _getLockStatus();
} }
@override @override
void onClose() { void onClose() {
// TODO: implement onClose
super.onClose(); super.onClose();
_replySubscription.cancel(); _replySubscription.cancel();
} }

View File

@ -77,7 +77,6 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
@override @override
void didChangeDependencies() { void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies(); super.didChangeDependencies();
/// ///
@ -86,7 +85,6 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
@override @override
void dispose() { void dispose() {
// TODO: implement dispose
/// ///
AppRouteObserver().routeObserver.unsubscribe(this); AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose(); super.dispose();
@ -104,7 +102,9 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
void didPop() { void didPop() {
super.didPop(); super.didPop();
logic.cancelBlueConnetctToastTimer(); logic.cancelBlueConnetctToastTimer();
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
state.ifCurrentScreen.value = false; state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
} }
@ -121,7 +121,9 @@ class _LockTimePageState extends State<LockTimePage> with RouteAware{
void didPushNext() { void didPushNext() {
super.didPushNext(); super.didPushNext();
logic.cancelBlueConnetctToastTimer(); logic.cancelBlueConnetctToastTimer();
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true); if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
state.ifCurrentScreen.value = false; state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0; state.sureBtnState.value = 0;
} }

View File

@ -2,16 +2,16 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../lockSet/lockSetInfo_entity.dart'; import '../lockSet/lockSetInfo_entity.dart';
class LockTimeState{ class LockTimeState{// 0() 1()
var lockSetInfoData = LockSetInfoData().obs;
var dateTime = "".obs;
int differentialTime = 0;
var ifCurrentScreen = true.obs; // ,
var sureBtnState = 0.obs;// 0() 1()
LockTimeState() { LockTimeState() {
var map = Get.arguments; final map = Get.arguments;
lockSetInfoData.value = map["lockSetInfoData"]; lockSetInfoData.value = map['lockSetInfoData'];
} }
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
RxString dateTime = ''.obs;
int differentialTime = 0;
RxBool ifCurrentScreen = true.obs; // ,
RxInt sureBtnState = 0.obs;
} }

View File

@ -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_getPublicKey.dart';
import 'package:star_lock/blue/io_protocol/io_otaUpgrade.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/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/mine/addLock/nearbyLock/nearbyLock_page.dart';
import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/baseGetXController.dart';
import 'package:star_lock/widget/permission/permission_dialog.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/io_tool/manager_event_bus.dart';
import '../../../blue/sender_manage.dart'; import '../../../blue/sender_manage.dart';
import '../../../network/api_repository.dart'; import '../../../network/api_repository.dart';
import '../../../tools/dateTool.dart';
import '../../../tools/storage.dart'; import '../../../tools/storage.dart';
import 'nearbyLock_state.dart'; import 'nearbyLock_state.dart';
@ -68,7 +70,7 @@ class NearbyLockLogic extends BaseGetXController {
void _initReplySubscription() { void _initReplySubscription() {
_replySubscription = _replySubscription =
EventBusManager().eventBus!.on<Reply>().listen((reply) { EventBusManager().eventBus!.on<Reply>().listen((Reply reply) {
if (reply is GetPublicKeyReply) { if (reply is GetPublicKeyReply) {
_replyGetPublicKey(reply); _replyGetPublicKey(reply);
} }
@ -110,8 +112,8 @@ class NearbyLockLogic extends BaseGetXController {
// //
AppLog.log('获取公钥成功'); AppLog.log('获取公钥成功');
// //
var publicKey = reply.data.sublist(3); final List<int> publicKey = reply.data.sublist(3);
var saveStrList = changeIntListToStringList(publicKey); final List<String> saveStrList = changeIntListToStringList(publicKey);
Storage.setStringList(saveBluePublicKey, saveStrList); Storage.setStringList(saveBluePublicKey, saveStrList);
// //
@ -140,22 +142,21 @@ class NearbyLockLogic extends BaseGetXController {
reply.data.removeAt(0); reply.data.removeAt(0);
// //
List<int> privateKey = reply.data.sublist(0, 16); final List<int> privateKey = reply.data.sublist(0, 16);
var savePrivateKeyList = changeIntListToStringList(privateKey); final List<String> savePrivateKeyList = changeIntListToStringList(privateKey);
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList); Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
// signKey // signKey
List<int> signKey = reply.data.sublist(16, 32); final List<int> signKey = reply.data.sublist(16, 32);
var saveSignKeyList = changeIntListToStringList(signKey); final List<String> saveSignKeyList = changeIntListToStringList(signKey);
Storage.setStringList(saveBlueSignKey, saveSignKeyList); Storage.setStringList(saveBlueSignKey, saveSignKeyList);
// //
List<int> timestamp = reply.data.sublist(32, 36); final List<int> timestamp = reply.data.sublist(32, 36);
state.timestampValue = ((0xff & timestamp[(0)]) << 24 | state.timestampValue = (0xff & timestamp[0]) << 24 |
(0xff & timestamp[1]) << 16 | (0xff & timestamp[1]) << 16 |
(0xff & timestamp[2]) << 8 | (0xff & timestamp[2]) << 8 |
(0xFF & timestamp[3])); (0xFF & timestamp[3]);
showTitleEasyLoading('获取锁信息 3/3'); showTitleEasyLoading('获取锁信息 3/3');
_getStarLockStatus(); _getStarLockStatus();
break; break;
@ -167,138 +168,138 @@ class NearbyLockLogic extends BaseGetXController {
// //
Future<void> _replyGetStarLockStatusInfo(Reply reply) async { Future<void> _replyGetStarLockStatusInfo(Reply reply) async {
int status = reply.data[2]; final int status = reply.data[2];
switch (status) { switch (status) {
case 0x00: case 0x00:
// //
AppLog.log('获取锁状态成功'); AppLog.log('获取锁状态成功');
// //
var index = 3; int index = 3;
var vendor = reply.data.sublist(index, index + 20); final List<int> vendor = reply.data.sublist(index, index + 20);
var vendorStr = utf8String(vendor); final String vendorStr = utf8String(vendor);
state.lockInfo['vendor'] = vendorStr; state.lockInfo['vendor'] = vendorStr;
// state.lockInfo["vendor"] = "XL"; // state.lockInfo["vendor"] = "XL";
index = index + 20; index = index + 20;
AppLog.log('厂商名称 vendorStr:$vendorStr'); AppLog.log('厂商名称 vendorStr:$vendorStr');
// //
var product = reply.data[index]; final int product = reply.data[index];
state.lockInfo['product'] = product; state.lockInfo['product'] = product;
index = index + 1; index = index + 1;
AppLog.log('锁设备类型 product:$product'); AppLog.log('锁设备类型 product:$product');
// //
var model = reply.data.sublist(index, index + 20); final List<int> model = reply.data.sublist(index, index + 20);
var modelStr = utf8String(model); final String modelStr = utf8String(model);
state.lockInfo['model'] = modelStr; state.lockInfo['model'] = modelStr;
// state.lockInfo["model"] = "JL-BLE-01"; // state.lockInfo["model"] = "JL-BLE-01";
index = index + 20; index = index + 20;
AppLog.log('产品名称 mmodelStr:$modelStr'); AppLog.log('产品名称 mmodelStr:$modelStr');
// //
var fwVersion = reply.data.sublist(index, index+20); final List<int> fwVersion = reply.data.sublist(index, index+20);
var fwVersionStr = utf8String(fwVersion); final String fwVersionStr = utf8String(fwVersion);
state.lockInfo['fwVersion'] = fwVersionStr; state.lockInfo['fwVersion'] = fwVersionStr;
index = index + 20; index = index + 20;
AppLog.log('软件版本 fwVersionStr:$fwVersionStr'); AppLog.log('软件版本 fwVersionStr:$fwVersionStr');
// //
var hwVersion = reply.data.sublist(index, index+20); final List<int> hwVersion = reply.data.sublist(index, index+20);
var hwVersionStr = utf8String(hwVersion); final String hwVersionStr = utf8String(hwVersion);
state.lockInfo['hwVersion'] = hwVersionStr; state.lockInfo['hwVersion'] = hwVersionStr;
index = index + 20; index = index + 20;
AppLog.log('硬件版本 hwVersionStr:$hwVersionStr'); AppLog.log('硬件版本 hwVersionStr:$hwVersionStr');
// //
var serialNum0 = reply.data.sublist(index, index + 16); final List<int> serialNum0 = reply.data.sublist(index, index + 16);
var serialNum0Str = utf8String(serialNum0); final String serialNum0Str = utf8String(serialNum0);
state.lockInfo['serialNum0'] = serialNum0Str; state.lockInfo['serialNum0'] = serialNum0Str;
// state.lockInfo["serialNum0"] = "${DateTime.now().millisecondsSinceEpoch ~/ 10}"; // state.lockInfo["serialNum0"] = "${DateTime.now().millisecondsSinceEpoch ~/ 10}";
index = index + 16; index = index + 16;
AppLog.log('厂商序列号 serialNum0Str:${serialNum0Str.length}'); AppLog.log('厂商序列号 serialNum0Str:${serialNum0Str.length}');
// //
var serialNum1 = reply.data.sublist(index, index + 16); final List<int> serialNum1 = reply.data.sublist(index, index + 16);
var serialNum1Str = utf8String(serialNum1); final String serialNum1Str = utf8String(serialNum1);
state.lockInfo['serialNum1'] = serialNum1Str; state.lockInfo['serialNum1'] = serialNum1Str;
index = index + 16; index = index + 16;
AppLog.log('成品商序列号 serialNum1Str:$serialNum1Str'); AppLog.log('成品商序列号 serialNum1Str:$serialNum1Str');
// //
var btDeviceName = reply.data.sublist(index, index + 16); final List<int> btDeviceName = reply.data.sublist(index, index + 16);
var btDeviceNameStr = utf8String(btDeviceName); final String btDeviceNameStr = utf8String(btDeviceName);
state.lockInfo['btDeviceName'] = btDeviceNameStr; state.lockInfo['btDeviceName'] = btDeviceNameStr;
index = index + 16; index = index + 16;
AppLog.log('蓝牙名称 btDeviceNameStr:$btDeviceNameStr'); AppLog.log('蓝牙名称 btDeviceNameStr:$btDeviceNameStr');
// //
var battRemCap = reply.data[index]; final int battRemCap = reply.data[index];
state.lockInfo['electricQuantity'] = battRemCap; state.lockInfo['electricQuantity'] = battRemCap;
index = index + 1; index = index + 1;
AppLog.log('电池剩余电量 battRemCap:$battRemCap'); AppLog.log('电池剩余电量 battRemCap:$battRemCap');
// //
var battRemCapStandby = reply.data[index]; final int battRemCapStandby = reply.data[index];
state.lockInfo['electricQuantityStandby'] = battRemCapStandby; state.lockInfo['electricQuantityStandby'] = battRemCapStandby;
index = index + 1; index = index + 1;
AppLog.log('电池剩余电量 battRemCap:$battRemCap'); 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]; state.lockInfo['restoreCount'] = restoreCounter[0] * 256 + restoreCounter[1];
index = index + 2; index = index + 2;
AppLog.log('重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}'); AppLog.log('重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}');
// //
var restoreDate = reply.data.sublist(index, index + 4); final List<int> restoreDate = reply.data.sublist(index, index + 4);
int restoreDateValue = ((0xff & restoreDate[(0)]) << 24 | final int restoreDateValue = (0xff & restoreDate[0]) << 24 |
(0xff & restoreDate[1]) << 16 | (0xff & restoreDate[1]) << 16 |
(0xff & restoreDate[2]) << 8 | (0xff & restoreDate[2]) << 8 |
(0xFF & restoreDate[3])); (0xFF & restoreDate[3]);
// String restoreDateStr = DateTool().dateToYMDHNSString(restoreDateValue.toString()); // String restoreDateStr = DateTool().dateToYMDHNSString(restoreDateValue.toString());
state.lockInfo['restoreDate'] = restoreDateValue * 1000; state.lockInfo['restoreDate'] = restoreDateValue * 1000;
index = index + 4; index = index + 4;
AppLog.log('重置时间 restoreDateValue:$restoreDateValue'); AppLog.log('重置时间 restoreDateValue:$restoreDateValue');
// //
var icPartNo = reply.data.sublist(index, index + 10); final List<int> icPartNo = reply.data.sublist(index, index + 10);
var icPartNoStr = utf8String(icPartNo); final String icPartNoStr = utf8String(icPartNo);
state.lockInfo['icPartNo'] = icPartNoStr; state.lockInfo['icPartNo'] = icPartNoStr;
index = index + 10; index = index + 10;
AppLog.log('主控芯片型号 icPartNoStr:$icPartNoStr'); AppLog.log('主控芯片型号 icPartNoStr:$icPartNoStr');
// //
var indate = reply.data.sublist(index, index + 4); final List<int> indate = reply.data.sublist(index, index + 4);
int indateValue = ((0xff & indate[(0)]) << 24 | final int indateValue = (0xff & indate[0]) << 24 |
(0xff & indate[1]) << 16 | (0xff & indate[1]) << 16 |
(0xff & indate[2]) << 8 | (0xff & indate[2]) << 8 |
(0xFF & indate[3])); (0xFF & indate[3]);
// String indateStr = DateTool().dateToYMDHNSString("$indateValue"); // String indateStr = DateTool().dateToYMDHNSString("$indateValue");
state.lockInfo['indate'] = indateValue * 1000; state.lockInfo['indate'] = indateValue * 1000;
index = index + 4; index = index + 4;
AppLog.log('有效时间 indateValue:$indateValue'); AppLog.log('有效时间 indateValue:$indateValue');
// mac地址 // mac地址
var macAddress = reply.data.sublist(index, index + 20); final List<int> macAddress = reply.data.sublist(index, index + 20);
var macAddressStr = utf8String(macAddress); final String macAddressStr = utf8String(macAddress);
state.lockInfo['mac'] = macAddressStr; state.lockInfo['mac'] = macAddressStr;
index = index + 20; index = index + 20;
AppLog.log('mac地址 macAddressStr:$macAddressStr'); AppLog.log('mac地址 macAddressStr:$macAddressStr');
// //
var featureValueLength = reply.data[index]; final int featureValueLength = reply.data[index];
index = index + 1; index = index + 1;
AppLog.log('锁特征值字符串长度 featureValueLength:$featureValueLength'); AppLog.log('锁特征值字符串长度 featureValueLength:$featureValueLength');
// () // ()
// //
var featureNetxLength = index + featureValueLength; final int featureNetxLength = index + featureValueLength;
if (reply.data.length < featureNetxLength) { if (reply.data.length < featureNetxLength) {
showToast('锁数据异常,请重试'); showToast('锁数据异常,请重试');
return; return;
} }
var featureValue = reply.data.sublist(index, index + featureValueLength); final List<int> featureValue = reply.data.sublist(index, index + featureValueLength);
String featureValueStr = asciiString(featureValue); final String featureValueStr = asciiString(featureValue);
state.featureValue = featureValueStr; state.featureValue = featureValueStr;
// List allFeatureValueTwoList = charListChangeIntList(featureValue); // List allFeatureValueTwoList = charListChangeIntList(featureValue);
// AppLog.log("featureValueLength:$featureValueLength featureValue:$featureValue \n featureValueStr:$featureValueStr"); // AppLog.log("featureValueLength:$featureValueLength featureValue:$featureValue \n featureValueStr:$featureValueStr");
@ -306,18 +307,18 @@ class NearbyLockLogic extends BaseGetXController {
AppLog.log('锁特征值字符串 featureValueStr:$featureValueStr'); AppLog.log('锁特征值字符串 featureValueStr:$featureValueStr');
// 使 // 使
var featureEnValLength = reply.data[index]; final int featureEnValLength = reply.data[index];
index = index + 1; index = index + 1;
AppLog.log('使能特征值字符串长度 featureEnValLength:$featureEnValLength'); AppLog.log('使能特征值字符串长度 featureEnValLength:$featureEnValLength');
// 使() // 使()
var featureEnNextLength = index + featureEnValLength; final int featureEnNextLength = index + featureEnValLength;
if (reply.data.length < featureEnNextLength) { if (reply.data.length < featureEnNextLength) {
showToast('锁数据异常,请重试'); showToast('锁数据异常,请重试');
return; return;
} }
var featureEnVal = reply.data.sublist(index, index + featureEnValLength); final List<int> featureEnVal = reply.data.sublist(index, index + featureEnValLength);
String featureEnValStr = asciiString(featureEnVal); final String featureEnValStr = asciiString(featureEnVal);
state.featureSettingValue = featureEnValStr; state.featureSettingValue = featureEnValStr;
// List allFeatureEnValTwoList = charListChangeIntList(featureEnVal); // List allFeatureEnValTwoList = charListChangeIntList(featureEnVal);
// AppLog.log("featureEnValLength:$featureEnValLength featureEnVal:$featureEnVal \n featureEnValStr:$featureEnValStr"); // AppLog.log("featureEnValLength:$featureEnValLength featureEnVal:$featureEnVal \n featureEnValStr:$featureEnValStr");
@ -327,11 +328,11 @@ class NearbyLockLogic extends BaseGetXController {
// //
// var featureParaTotal = reply.data[index]; // var featureParaTotal = reply.data[index];
var featureParaTotalList = reply.data.sublist(index); final List<int> featureParaTotalList = reply.data.sublist(index);
state.featureSettingParams = featureParaTotalList; state.featureSettingParams = featureParaTotalList;
AppLog.log('featureParaTotalList:$featureParaTotalList'); AppLog.log('featureParaTotalList:$featureParaTotalList');
Get.toNamed(Routers.lockAddressGaoDePage, arguments: { Get.toNamed(Routers.lockAddressGaoDePage, arguments: <String, Object>{
'pwdTimestamp': state.timestampValue * 1000, 'pwdTimestamp': state.timestampValue * 1000,
'lockInfo': state.lockInfo, 'lockInfo': state.lockInfo,
'featureValue': state.featureValue, 'featureValue': state.featureValue,
@ -342,8 +343,8 @@ class NearbyLockLogic extends BaseGetXController {
break; break;
case 0x06: case 0x06:
// //
var privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
// IoSenderManage.senderGetLockStatu( // IoSenderManage.senderGetLockStatu(
// lockID:BlueManage().connectDeviceName, // lockID:BlueManage().connectDeviceName,
// userID:await Storage.getUid(), // userID:await Storage.getUid(),
@ -352,8 +353,8 @@ class NearbyLockLogic extends BaseGetXController {
IoSenderManage.senderGetStarLockStatuInfo( IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
utcTimeStamp: getUTCNetTime(), utcTimeStamp: getUTCTime(),
unixTimeStamp: getLocalNetTime(), unixTimeStamp: getLocalTime(),
isBeforeAddUser: true, isBeforeAddUser: true,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
); );
@ -373,14 +374,14 @@ class NearbyLockLogic extends BaseGetXController {
// dismissEasyLoading(); // dismissEasyLoading();
AppLog.log('开始获取锁状态'); AppLog.log('开始获取锁状态');
var privateKey = await Storage.getStringList(saveBluePrivateKey); final List<String>? privateKey = await Storage.getStringList(saveBluePrivateKey);
List<int> getPrivateKeyList = changeStringListToIntList(privateKey!); final List<int> getPrivateKeyList = changeStringListToIntList(privateKey!);
IoSenderManage.senderGetStarLockStatuInfo( IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
utcTimeStamp: getUTCNetTime(), utcTimeStamp: getUTCTime(),
unixTimeStamp: getLocalNetTime(), unixTimeStamp: getLocalTime(),
isBeforeAddUser: true, isBeforeAddUser: true,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
); );
@ -394,12 +395,12 @@ class NearbyLockLogic extends BaseGetXController {
BlueManage().startScan(2000, (List<ScanResult> list) { BlueManage().startScan(2000, (List<ScanResult> list) {
state.devices.clear(); state.devices.clear();
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
ScanResult device = list[i]; final ScanResult device = list[i];
if (((device.advertisementData.serviceUuids.isNotEmpty if ((device.advertisementData.serviceUuids.isNotEmpty
? device.advertisementData.serviceUuids[0] ? device.advertisementData.serviceUuids[0]
: '') : '')
.toString()[31] != .toString()[31] !=
'1')) { '1') {
state.devices.add(list[i]); state.devices.add(list[i]);
} }
} }
@ -431,16 +432,16 @@ class NearbyLockLogic extends BaseGetXController {
// //
Future<void> otaUpdate() async { Future<void> otaUpdate() async {
var status = await PermissionDialog.requestStorage(); final bool status = await PermissionDialog.requestStorage();
if (status != true) { if (status != true) {
return; return;
} }
FilePickerResult? result = await FilePicker.platform.pickFiles(); final FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result == null || result.files.single.path is! String) { if (result == null || result.files.single.path is! String) {
return; return;
} }
File file = File(result.files.single.path!); final File file = File(result.files.single.path!);
Uint8List data = await file.readAsBytes(); final Uint8List data = await file.readAsBytes();
headJson = await getHeadFile(data); headJson = await getHeadFile(data);
if (headJson is! Map) { if (headJson is! Map) {
return; return;
@ -449,9 +450,9 @@ class NearbyLockLogic extends BaseGetXController {
if (otaBin == null) { if (otaBin == null) {
return; return;
} }
String md5Str = md5.convert(otaBin!).toString(); final String md5Str = md5.convert(otaBin!).toString();
headJson!['fwMd5'] = md5Str; headJson!['fwMd5'] = md5Str;
blueOTAUpgrade(headJson!, [0, 0, 0, 0]); blueOTAUpgrade(headJson!, <int>[0, 0, 0, 0]);
} }
// ota // ota
@ -463,7 +464,7 @@ class NearbyLockLogic extends BaseGetXController {
BlueManage().blueSendData(deviceName!, BlueManage().blueSendData(deviceName!,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
String uid = await Storage.getUid() ?? ''; final String uid = await Storage.getUid() ?? '';
BlueManage().writeCharacteristicWithResponse(OTAUpgradeCommand( BlueManage().writeCharacteristicWithResponse(OTAUpgradeCommand(
lockID: deviceName, lockID: deviceName,
userID: uid, userID: uid,
@ -488,29 +489,29 @@ class NearbyLockLogic extends BaseGetXController {
if (!state.otaUpdateIng.value) { if (!state.otaUpdateIng.value) {
return; return;
} }
int length = otaBin?.length ?? 0; final int length = otaBin?.length ?? 0;
if (otaCount == 0) { if (otaCount == 0) {
// //
int difference = length % 240; final int difference = length % 240;
otaCount = length ~/ 240 + (difference > 0 ? 1 : 0); otaCount = length ~/ 240 + (difference > 0 ? 1 : 0);
startSecond = DateTime.now().millisecondsSinceEpoch ~/ 1000; startSecond = DateTime.now().millisecondsSinceEpoch ~/ 1000;
} }
if (otaCount <= otaIndex) { if (otaCount <= otaIndex) {
int now = DateTime.now().millisecondsSinceEpoch ~/ 1000; final int now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
String msg = final String msg =
'传输完成 时间:${now - startSecond}秒 otaCount:$otaCount otaIndex:$otaIndex '; '传输完成 时间:${now - startSecond}秒 otaCount:$otaCount otaIndex:$otaIndex ';
closeOTADAta(); closeOTADAta();
AppLog.log(msg); AppLog.log(msg);
// showToast(msg); // showToast(msg);
return; return;
} }
int star = otaIndex * 240; final int star = otaIndex * 240;
int end = (otaIndex + 1) * 240; int end = (otaIndex + 1) * 240;
if (end > length) { if (end > length) {
end = length; end = length;
} }
int size = end - star; final int size = end - star;
List<int> data = otaBin!.sublist(star, end); final List<int> data = otaBin!.sublist(star, end);
state.otaProgress.value = otaIndex / otaCount; state.otaProgress.value = otaIndex / otaCount;
await BlueManage().writeCharacteristicWithResponse( await BlueManage().writeCharacteristicWithResponse(
ProcessOtaUpgradeCommand(index: otaIndex, size: size, data: data) ProcessOtaUpgradeCommand(index: otaIndex, size: size, data: data)
@ -594,7 +595,7 @@ class NearbyLockLogic extends BaseGetXController {
return null; return null;
} }
AppLog.log(metaStr); AppLog.log(metaStr);
var meta = jsonDecode(metaStr); final meta = jsonDecode(metaStr);
if (meta is! Map) { if (meta is! Map) {
showToast('解析元数据失败,请选择正确的文件'.tr); showToast('解析元数据失败,请选择正确的文件'.tr);
return null; return null;
@ -604,11 +605,11 @@ class NearbyLockLogic extends BaseGetXController {
// bin // bin
Future<Uint8List?> checkFile(Uint8List data, Map meta) async { 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 //md5
String md5Str = md5.convert(bin).toString().toUpperCase(); final String md5Str = md5.convert(bin).toString().toUpperCase();
// AppLog.log('---> $md5Str ${meta['fwMd5']}'); // AppLog.log('---> $md5Str ${meta['fwMd5']}');
if (md5Str != meta['fwMd5']) { if (md5Str != meta['fwMd5']) {
showToast('文件校验失败 0x02'.tr); showToast('文件校验失败 0x02'.tr);
@ -622,27 +623,25 @@ class NearbyLockLogic extends BaseGetXController {
} }
// //
void getServerDatetime() async{ Future<void> getServerDatetime() async{
var entity = await ApiRepository.to.getServerDatetimeData(); final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData();
if(entity.errorCode!.codeIsSuccessful){ if(entity.errorCode!.codeIsSuccessful){
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000; 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}"); // 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; return DateTime.now().millisecondsSinceEpoch ~/ 1000 + state.differentialTime;
} }
int getLocalNetTime(){ int getUTCTime(){
DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getUTCNetTime()*1000, isUtc: true); final DateTime utcTime = DateTime.fromMillisecondsSinceEpoch(getLocalTime()*1000, isUtc: true);
DateTime localTime = utcTime.toLocal();
// AppLog.log('getUTCNetTime: ${getUTCNetTime()}'); final String appointmentDate = DateTool().getYMDHNDateStringWithDateTime(utcTime, 1);
// AppLog.log('UTC time: $utcTime'); final int utcTimeValue = DateTool().dateToTimestamp(appointmentDate, 1);
// AppLog.log('Local time: $localTime localTime.millisecondsSinceEpoch ~/ 1000:${localTime.millisecondsSinceEpoch ~/ 1000}'); AppLog.log('appointmentDate: $appointmentDate utcTimeValue:$utcTimeValue');
return localTime.millisecondsSinceEpoch ~/ 1000; return utcTimeValue ~/ 1000;
} }
@override @override

View File

@ -95,7 +95,6 @@ class MinePersonInfoLogic extends BaseGetXController {
source: ImageSource.camera, source: ImageSource.camera,
maxHeight: 250, maxHeight: 250,
maxWidth: 250, maxWidth: 250,
imageQuality: 80
); );
if (photo != null) { if (photo != null) {
state.image = photo; state.image = photo;

View File

@ -116,6 +116,40 @@ class DateTool {
return dateStr; 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: /// type 0: 12:00 1:
int dateToTimestamp(String dateStr, int type) { int dateToTimestamp(String dateStr, int type) {