添加支持备用电池功能

This commit is contained in:
魏少阳 2024-04-30 16:16:06 +08:00
parent 06c41eb130
commit ab254a8fd9
12 changed files with 114 additions and 57 deletions

View File

@ -41,7 +41,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
} }
GetMaterialApp _initMaterialApp() => GetMaterialApp( GetMaterialApp _initMaterialApp() => GetMaterialApp(
enableLog: false, // enableLog: false,
title: F.navTitle, title: F.navTitle,
navigatorObservers: [AppRouteObserver().routeObserver], navigatorObservers: [AppRouteObserver().routeObserver],
translations: TranslationMessage(), translations: TranslationMessage(),

View File

@ -1,4 +1,5 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'dart:io'; import 'dart:io';
import 'package:star_lock/debug/debug_console.dart'; import 'package:star_lock/debug/debug_console.dart';
@ -20,7 +21,7 @@ class AppLog {
msg = '----->>> $msg'; msg = '----->>> $msg';
} }
DebugConsole.info(msg); DebugConsole.info(msg);
print(msg); Get.log(msg);
} }
} }

View File

@ -69,6 +69,7 @@ class LockDetailLogic extends BaseGetXController {
case 0x00: case 0x00:
// //
// _showFullScreenOverlay(Get.context!); // _showFullScreenOverlay(Get.context!);
cancelBlueConnetctToastTimer();
state.iSClosedUnlockSuccessfulPopup.value = true; state.iSClosedUnlockSuccessfulPopup.value = true;
if (state.closedUnlockSuccessfulTimer != null) { if (state.closedUnlockSuccessfulTimer != null) {
@ -86,7 +87,14 @@ class LockDetailLogic extends BaseGetXController {
int power = reply.data[7]; int power = reply.data[7];
state.electricQuantity.value = power; state.electricQuantity.value = power;
cancelBlueConnetctToastTimer(); //
if(state.keyInfos.value.lockFeature!.isSupportBackupBattery == 1){
int powerStandby = reply.data[9];
state.electricQuantityStandby.value = powerStandby;
}
//
uploadElectricQuantityRequest();
getLockRecordLastUploadDataTime(); getLockRecordLastUploadDataTime();
state.openLockBtnState.value = 0; state.openLockBtnState.value = 0;
@ -431,6 +439,20 @@ class LockDetailLogic extends BaseGetXController {
} }
} }
//
Future<void> uploadElectricQuantityRequest() async {
KeyOperationRecordEntity entity = await ApiRepository.to.uploadElectricQuantity(
electricQuantity:state.electricQuantity.value.toString(),
electricQuantityStandby: state.electricQuantityStandby.value.toString(),
lockId: state.keyInfos.value.lockId.toString()
);
if (entity.errorCode!.codeIsSuccessful) {
SchedulerBinding.instance.addPostFrameCallback((_) {
eventBus.fire(RefreshLockListInfoDataEvent());
});
}
}
// NO // NO
// void _updateLockUserNo() async { // void _updateLockUserNo() async {
// LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo( // LockNetTokenEntity entity = await ApiRepository.to.updateLockUserNo(

View File

@ -529,30 +529,33 @@ class _LockDetailPageState extends State<LockDetailPage>
], ],
), ),
), ),
Row( Visibility(
mainAxisAlignment: MainAxisAlignment.end, visible: state.keyInfos.value.lockFeature!.isSupportBackupBattery == 1,
children: [ child: Row(
FlavorsImg( mainAxisAlignment: MainAxisAlignment.end,
child: Image.asset( children: [
showElectricIcon(state.electricQuantity.value), FlavorsImg(
width: 30.w, child: Image.asset(
height: 24.w), showElectricIcon(state.electricQuantityStandby.value),
), width: 30.w,
SizedBox(width: 2.w), height: 24.w),
Text("--%",
style: TextStyle(
fontSize: 18.sp,
color: AppColors.darkGrayTextColor)),
SizedBox(width: 2.w),
FlavorsImg(
child: Icon(
Icons.info, // 使 warning
color: AppColors.mainColor, //
size: 25.w, // 30
), ),
), SizedBox(width: 2.w),
SizedBox(width: 20.w), Text("${state.electricQuantityStandby.value}%",
], style: TextStyle(
fontSize: 18.sp,
color: AppColors.darkGrayTextColor)),
SizedBox(width: 2.w),
FlavorsImg(
child: Icon(
Icons.info, // 使 warning
color: AppColors.mainColor, //
size: 25.w, // 30
),
),
SizedBox(width: 20.w),
],
),
), ),
], ],
)) ))

View File

@ -22,6 +22,7 @@ class LockDetailState {
var isAttendance = 0.obs; // var isAttendance = 0.obs; //
var isOpenLockNeedOnline = 0.obs; // APP开锁时是否需联网 var isOpenLockNeedOnline = 0.obs; // APP开锁时是否需联网
var electricQuantity = 0.obs; // var electricQuantity = 0.obs; //
var electricQuantityStandby = 0.obs; //
var isOpenPassageMode = 0.obs; // var isOpenPassageMode = 0.obs; //
var lockAlias = "".obs; // var lockAlias = "".obs; //

View File

@ -21,10 +21,12 @@ class UploadElectricQuantityLogic extends BaseGetXController {
final UploadElectricQuantityState state = UploadElectricQuantityState(); final UploadElectricQuantityState state = UploadElectricQuantityState();
// //
Future<void> uploadElectricQuantityRequest(String electricQuantity) async { Future<void> uploadElectricQuantityRequest(String electricQuantity, String electricQuantityStandby) async {
KeyOperationRecordEntity entity = await ApiRepository.to KeyOperationRecordEntity entity = await ApiRepository.to.uploadElectricQuantity(
.uploadElectricQuantity( electricQuantity:electricQuantity,
electricQuantity, state.lockSetInfoData.value.lockId.toString()); electricQuantityStandby: electricQuantityStandby,
lockId: state.lockSetInfoData.value.lockId.toString()
);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
showToast("锁电量更新成功".tr, something: () { showToast("锁电量更新成功".tr, something: () {
eventBus eventBus
@ -95,13 +97,15 @@ class UploadElectricQuantityLogic extends BaseGetXController {
// //
var battRemCap = reply.data[132]; var battRemCap = reply.data[132];
state.lockSetInfoData.value.lockBasicInfo!.electricQuantity = state.lockSetInfoData.value.lockBasicInfo!.electricQuantity = battRemCap;
battRemCap;
state.uploadElectricQuantityDate.value = //
DateTime.now().millisecondsSinceEpoch; var battRemCapStandby = reply.data[133];
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityDate = state.lockSetInfoData.value.lockBasicInfo!.electricQuantityStandby = battRemCapStandby;
DateTime.now().millisecondsSinceEpoch;
uploadElectricQuantityRequest(battRemCap.toString()); state.uploadElectricQuantityDate.value = DateTime.now().millisecondsSinceEpoch;
state.lockSetInfoData.value.lockBasicInfo!.electricQuantityDate = DateTime.now().millisecondsSinceEpoch;
uploadElectricQuantityRequest(battRemCap.toString(), battRemCapStandby.toString());
break; break;
case 0x06: case 0x06:
// //

View File

@ -55,20 +55,23 @@ class _UploadElectricQuantityPageState extends State<UploadElectricQuantityPage>
children: [ children: [
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 ?? ""}%",
style: TextStyle(fontSize: 20.sp), style: TextStyle(fontSize: 20.sp),
)), )),
], ],
)), )),
Row( Visibility(
mainAxisAlignment: MainAxisAlignment.start, visible: state.lockSetInfoData.value.lockFeature!.isSupportBackupBattery == 1,
children: [ child: Row(
Expanded( mainAxisAlignment: MainAxisAlignment.start,
child: Text( children: [
"${"电池2".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:--%", Expanded(
style: TextStyle(fontSize: 20.sp), child: Text(
)), "${"电池2".tr}:${TranslationLoader.lanKeys!.electricQuantity!.tr}:${state.lockBasicInfo.value.electricQuantityStandby ?? ""}%",
], style: TextStyle(fontSize: 20.sp),
)),
],
),
), ),
SizedBox(height: 10.h), SizedBox(height: 10.h),
Obx(() => Row( Obx(() => Row(

View File

@ -145,6 +145,7 @@ class LockFeature {
int? motorTorsion; int? motorTorsion;
int? stayWarn; int? stayWarn;
int? abnormalWarn; int? abnormalWarn;
int? isSupportBackupBattery; // 0: 1:
LockFeature({ LockFeature({
this.password, this.password,
@ -200,6 +201,7 @@ class LockFeature {
this.motorTorsion, this.motorTorsion,
this.stayWarn, this.stayWarn,
this.abnormalWarn, this.abnormalWarn,
this.isSupportBackupBattery,
}); });
LockFeature.fromJson(Map<String, dynamic> json) { LockFeature.fromJson(Map<String, dynamic> json) {
@ -256,6 +258,7 @@ class LockFeature {
motorTorsion = json['motorTorsion']; motorTorsion = json['motorTorsion'];
stayWarn = json['stayWarn']; stayWarn = json['stayWarn'];
abnormalWarn = json['abnormalWarn']; abnormalWarn = json['abnormalWarn'];
isSupportBackupBattery = json['isSupportBackupBattery'];
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -313,6 +316,7 @@ class LockFeature {
data['motorTorsion'] = motorTorsion; data['motorTorsion'] = motorTorsion;
data['stayWarn'] = stayWarn; data['stayWarn'] = stayWarn;
data['abnormalWarn'] = abnormalWarn; data['abnormalWarn'] = abnormalWarn;
data['isSupportBackupBattery'] = isSupportBackupBattery;
return data; return data;
} }
} }
@ -323,6 +327,7 @@ class LockBasicInfo {
int? keyId; int? keyId;
String? model; String? model;
int? electricQuantity; int? electricQuantity;
int? electricQuantityStandby;
int? indate; int? indate;
int? isLockOwner; int? isLockOwner;
String? lockAlias; String? lockAlias;
@ -349,6 +354,7 @@ class LockBasicInfo {
this.keyId, this.keyId,
this.model, this.model,
this.electricQuantity, this.electricQuantity,
this.electricQuantityStandby,
this.indate, this.indate,
this.isLockOwner, this.isLockOwner,
this.lockAlias, this.lockAlias,
@ -375,6 +381,7 @@ class LockBasicInfo {
keyId = json['keyId']; keyId = json['keyId'];
model = json['model']; model = json['model'];
electricQuantity = json['electricQuantity']; electricQuantity = json['electricQuantity'];
electricQuantityStandby = json['electricQuantityStandby'];
indate = json['indate']; indate = json['indate'];
isLockOwner = json['isLockOwner']; isLockOwner = json['isLockOwner'];
lockAlias = json['lockAlias']; lockAlias = json['lockAlias'];
@ -408,6 +415,7 @@ class LockBasicInfo {
data['keyId'] = keyId; data['keyId'] = keyId;
data['model'] = model; data['model'] = model;
data['electricQuantity'] = electricQuantity; data['electricQuantity'] = electricQuantity;
data['electricQuantityStandby'] = electricQuantityStandby;
data['indate'] = indate; data['indate'] = indate;
data['isLockOwner'] = isLockOwner; data['isLockOwner'] = isLockOwner;
data['lockAlias'] = lockAlias; data['lockAlias'] = lockAlias;

View File

@ -290,6 +290,7 @@ class LockFeature {
int? bluetoothRemoteControl; int? bluetoothRemoteControl;
int? videoIntercom; int? videoIntercom;
int? isSupportCatEye; int? isSupportCatEye;
int? isSupportBackupBattery;
LockFeature( LockFeature(
{this.password, {this.password,
this.icCard, this.icCard,
@ -300,7 +301,8 @@ class LockFeature {
this.d3Face, this.d3Face,
this.bluetoothRemoteControl, this.bluetoothRemoteControl,
this.videoIntercom, this.videoIntercom,
this.isSupportCatEye}); this.isSupportCatEye,
this.isSupportBackupBattery});
LockFeature.fromJson(Map<String, dynamic> json) { LockFeature.fromJson(Map<String, dynamic> json) {
password = json['password']; password = json['password'];
@ -313,6 +315,7 @@ class LockFeature {
bluetoothRemoteControl = json['bluetoothRemoteControl']; bluetoothRemoteControl = json['bluetoothRemoteControl'];
videoIntercom = json['videoIntercom']; videoIntercom = json['videoIntercom'];
isSupportCatEye = json['isSupportCatEye']; isSupportCatEye = json['isSupportCatEye'];
isSupportBackupBattery = json['isSupportBackupBattery'];
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -327,6 +330,7 @@ class LockFeature {
data['bluetoothRemoteControl'] = bluetoothRemoteControl; data['bluetoothRemoteControl'] = bluetoothRemoteControl;
data['videoIntercom'] = videoIntercom; data['videoIntercom'] = videoIntercom;
data['isSupportCatEye'] = isSupportCatEye; data['isSupportCatEye'] = isSupportCatEye;
data['isSupportBackupBattery'] = isSupportBackupBattery;
return data; return data;
} }
} }

View File

@ -190,13 +190,18 @@ class NearbyLockLogic extends BaseGetXController {
state.lockInfo["electricQuantity"] = battRemCap; state.lockInfo["electricQuantity"] = battRemCap;
AppLog.log("电池剩余电量 battRemCap:$battRemCap"); AppLog.log("电池剩余电量 battRemCap:$battRemCap");
//
var battRemCapStandby = reply.data[133];
state.lockInfo["electricQuantityStandby"] = battRemCapStandby;
AppLog.log("电池剩余电量 battRemCap:$battRemCap");
// //
var restoreCounter = reply.data.sublist(133, 135); var restoreCounter = reply.data.sublist(134, 136);
state.lockInfo["restoreCount"] = restoreCounter[0] * 256 + restoreCounter[1]; state.lockInfo["restoreCount"] = restoreCounter[0] * 256 + restoreCounter[1];
AppLog.log("重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}"); AppLog.log("重置次数 restoreCounter:${restoreCounter[0] * 256 + restoreCounter[1]}");
// //
var restoreDate = reply.data.sublist(135, 139); var restoreDate = reply.data.sublist(136, 140);
int restoreDateValue = ((0xff & restoreDate[(0)]) << 24 | int restoreDateValue = ((0xff & restoreDate[(0)]) << 24 |
(0xff & restoreDate[1]) << 16 | (0xff & restoreDate[1]) << 16 |
(0xff & restoreDate[2]) << 8 | (0xff & restoreDate[2]) << 8 |
@ -206,13 +211,13 @@ class NearbyLockLogic extends BaseGetXController {
AppLog.log("重置时间 restoreDateValue:$restoreDateValue"); AppLog.log("重置时间 restoreDateValue:$restoreDateValue");
// //
var icPartNo = reply.data.sublist(139, 149); var icPartNo = reply.data.sublist(140, 150);
var icPartNoStr = utf8String(icPartNo); var icPartNoStr = utf8String(icPartNo);
state.lockInfo["icPartNo"] = icPartNoStr; state.lockInfo["icPartNo"] = icPartNoStr;
AppLog.log("主控芯片型号 icPartNoStr:$icPartNoStr"); AppLog.log("主控芯片型号 icPartNoStr:$icPartNoStr");
// //
var indate = reply.data.sublist(149, 153); var indate = reply.data.sublist(150, 154);
int indateValue = ((0xff & indate[(0)]) << 24 | int indateValue = ((0xff & indate[(0)]) << 24 |
(0xff & indate[1]) << 16 | (0xff & indate[1]) << 16 |
(0xff & indate[2]) << 8 | (0xff & indate[2]) << 8 |
@ -222,14 +227,14 @@ class NearbyLockLogic extends BaseGetXController {
AppLog.log("有效时间 indateValue:$indateValue"); AppLog.log("有效时间 indateValue:$indateValue");
// mac地址 // mac地址
var macAddress = reply.data.sublist(153, 173); var macAddress = reply.data.sublist(154, 174);
var macAddressStr = utf8String(macAddress); var macAddressStr = utf8String(macAddress);
state.lockInfo["mac"] = macAddressStr; state.lockInfo["mac"] = macAddressStr;
AppLog.log("mac地址 macAddressStr:$macAddressStr"); AppLog.log("mac地址 macAddressStr:$macAddressStr");
var index = 173; var index = 174;
// //
var featureValueLength = reply.data[173]; var featureValueLength = reply.data[174];
AppLog.log("锁特征值字符串长度 featureValueLength:$featureValueLength"); AppLog.log("锁特征值字符串长度 featureValueLength:$featureValueLength");
// () // ()

View File

@ -169,12 +169,14 @@ class ApiProvider extends BaseProvider {
Future<Response> uploadElectricQuantity( Future<Response> uploadElectricQuantity(
String electricQuantity, String electricQuantity,
String electricQuantityStandby,
String lockId, String lockId,
) => ) =>
post( post(
uploadElectricQuantityURL.toUrl, uploadElectricQuantityURL.toUrl,
jsonEncode({ jsonEncode({
'electricQuantity': electricQuantity, 'electricQuantity': electricQuantity,
'electricQuantityStandby': electricQuantityStandby,
'lockId': lockId, 'lockId': lockId,
})); }));

View File

@ -317,9 +317,13 @@ class ApiRepository {
// //
Future<KeyOperationRecordEntity> uploadElectricQuantity( Future<KeyOperationRecordEntity> uploadElectricQuantity(
String electricQuantity, String lockId) async { {
String? electricQuantity,
String? electricQuantityStandby,
String? lockId
}) async {
final res = final res =
await apiProvider.uploadElectricQuantity(electricQuantity, lockId); await apiProvider.uploadElectricQuantity(electricQuantity!, electricQuantityStandby!, lockId!);
return KeyOperationRecordEntity.fromJson(res.body); return KeyOperationRecordEntity.fromJson(res.body);
} }