fix: 调整第三方平台设置

This commit is contained in:
liyi 2025-10-22 09:37:26 +08:00
parent 4f1b1dd02f
commit e1011688de
7 changed files with 192 additions and 82 deletions

View File

@ -46,7 +46,7 @@ class BlueManage {
StreamSubscription<BluetoothConnectionState>? _connectionStateSubscription;
StreamSubscription<int>? _mtuSubscription;
int? _mtuSize = 20;
int? _mtuSize = 30;
//
String connectDeviceName = '';
@ -813,30 +813,33 @@ class BlueManage {
///
Future<void> writeCharacteristicWithResponse(List<int> value) async {
// MTU还是默认值
if (_mtuSize == 23 && bluetoothConnectDevice != null) {
try {
if (Platform.isAndroid) {
await bluetoothConnectDevice!.requestMtu(512);
}
} catch (e) {
AppLog.log('重新请求MTU失败: $e');
}
}
final List<BluetoothService> services = await bluetoothConnectDevice!.discoverServices();
for (final BluetoothService service in services) {
if (service.uuid == _serviceIdConnect) {
for (final BluetoothCharacteristic characteristic in service.characteristics) {
if (characteristic.characteristicUuid == _characteristicIdWrite) {
try {
_initGetMtuSubscription();
// MTU还是默认值
if ((_mtuSize == 23 || _mtuSize == 20) && bluetoothConnectDevice != null) {
try {
if (Platform.isAndroid) {
await bluetoothConnectDevice!.requestMtu(512);
}
} catch (e) {
AppLog.log('重新请求MTU失败: $e');
}
}
//
int retryCount = 0;
const int maxRetries = 3;
const int retryDelayMs = 500;
final List<int> valueList = value;
AppLog.log('发送数据时当前的mtuSize是:${_mtuSize}');
final List subData = splitList(valueList, _mtuSize!);
for (int i = 0; i < subData.length; i++) {
//
bool packetSent = false;

View File

@ -1,24 +1,109 @@
import 'dart:convert';
class ActivateInfoResponse {
ActivateInfoResponse({
this.description,
this.errorCode,
this.data, // List<ActivateInfo>
this.data, // List<ActivateInfo>
this.errorMsg,
});
ActivateInfoResponse.fromJson(dynamic json) {
description = json['description'];
errorCode = json['errorCode'];
// json['data'] List<ActivateInfo>
data = json['data'] != null
? (json['data'] as List).map((item) => ActivateInfo.fromJson(item)).toList()
: [];
// ActivateInfo
data = json['data'] != null ? ActivateInfo.fromJson(json['data']) : null;
errorMsg = json['errorMsg'];
}
String? description;
int? errorCode;
List<ActivateInfo>? data; // List<ActivateInfo>
ActivateInfo? data; // List<ActivateInfo>
String? errorMsg;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['description'] = description;
map['errorCode'] = errorCode;
if (data != null) {
// ActivateInfo JSON
map['data'] = data!.toJson();
}
map['errorMsg'] = errorMsg;
return map;
}
@override
String toString() {
return 'ActivateInfoResponse{description: $description, errorCode: $errorCode, data: $data, errorMsg: $errorMsg}';
}
}
class ActivateInfo {
String? authCode;
String? activatedAt;
Map<String, dynamic>? extraParams; // Map
ActivateInfo({
this.authCode,
this.activatedAt,
this.extraParams,
});
ActivateInfo.fromJson(dynamic json) {
authCode = json['auth_code'] ?? '';
activatedAt = json['activated_at'] ?? '';
// extraParams Map
if (json['extra_params'] != null) {
if (json['extra_params'] is Map) {
extraParams = json['extra_params'];
} else if (json['extra_params'] is String) {
// JSON
try {
extraParams = jsonDecode(json['extra_params']);
} catch (e) {
// null map
extraParams = {};
}
}
} else {
extraParams = {};
}
}
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['authCode'] = authCode;
map['activatedAt'] = activatedAt;
map['extraParams'] = extraParams;
return map;
}
@override
String toString() {
return 'ActivateInfo{authCode: $authCode, activatedAt: $activatedAt, extraParams: $extraParams}';
}
}
class TppSupportResponse {
TppSupportResponse({
this.description,
this.errorCode,
this.data, // List<ActivateInfo>
this.errorMsg,
});
TppSupportResponse.fromJson(dynamic json) {
description = json['description'];
errorCode = json['errorCode'];
// json['data'] List<ActivateInfo>
data = json['data'] != null ? (json['data'] as List).map((item) => TppSupportInfo.fromJson(item)).toList() : [];
errorMsg = json['errorMsg'];
}
String? description;
int? errorCode;
List<TppSupportInfo>? data; // List<ActivateInfo>
String? errorMsg;
Map<String, dynamic> toJson() {
@ -35,33 +120,28 @@ class ActivateInfoResponse {
@override
String toString() {
return 'ActivateInfoResponse{description: $description, errorCode: $errorCode, data: $data, errorMsg: $errorMsg}';
return 'TppSupportResponse{description: $description, errorCode: $errorCode, data: $data, errorMsg: $errorMsg}';
}
}
class ActivateInfo {
String? platformName;
class TppSupportInfo {
int? platform;
String? platformName;
ActivateInfo({
this.platformName,
TppSupportInfo({
this.platform,
this.platformName,
});
ActivateInfo.fromJson(dynamic json) {
platformName = json['platformName'] ?? '';
platform = json['platform'] ?? '';
TppSupportInfo.fromJson(dynamic json) {
platform = json['platform'] as int? ?? -1;
platformName = json['platform_name'] as String? ?? '';
}
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['platformName'] = platformName;
map['platform'] = platform;
map['platform_name'] = platformName;
return map;
}
@override
String toString() {
return 'ActivateInfo{platformName: $platformName, platform: $platform}';
}
}

View File

@ -658,6 +658,7 @@ class LockDetailLogic extends BaseGetXController {
if (list.isEmpty) {
return;
}
AppLog.log('list:${list}');
final KeyOperationRecordEntity entity =
await ApiRepository.to.lockRecordUploadData(lockId: state.keyInfos.value.lockId.toString(), records: list);
if (entity.errorCode!.codeIsSuccessful) {

View File

@ -29,7 +29,24 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
super.onReady();
await getActivateInfo();
_initReplySubscription();
getServerDatetime();
await getServerDatetime();
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
BlueManage().blueSendData(
BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) {
IoSenderManage.readRegisterKey(
lockID: BlueManage().connectDeviceName,
);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
}
},
);
}
@override
@ -57,6 +74,7 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
Future<void> getServerDatetime() async {
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading: true);
if (entity.errorCode!.codeIsSuccessful) {
state.serverTime = entity.data!.date! ~/ 1000;
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000;
}
}
@ -72,7 +90,6 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
return;
}
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
AppLog.log('输出了listen${_replySubscription.hashCode}');
if (reply is SenderReadRegisterKeyCommandReply) {
_handleReadRegisterKeyReply(reply);
}
@ -158,7 +175,7 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
uuid: response.data?.extraParams?['uuid'],
key: response.data?.authCode,
mac: response.data?.extraParams?['mac'],
platform: 1,
platform: state.selectPlatFormIndex.value,
utcTimeStamp: getUTCNetTime(),
);
} else if (connectionState == BluetoothConnectionState.disconnected) {
@ -191,25 +208,11 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
void savePlatFormSetting() {
if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) {
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
BlueManage().blueSendData(
BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) {
IoSenderManage.readRegisterKey(
lockID: BlueManage().connectDeviceName,
);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
}
},
);
if (state.registerKey.isNotEmpty) {
_requestAuthorizationCode();
}
} else {
showToast('目前只支持切换至涂鸦智能协议'.tr);
showToast('目前只支持切换至涂鸦智能、锁通通协议'.tr);
}
}
@ -232,15 +235,14 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
switch (status) {
case 0x00:
final platform = reply.data[7];
// RegisterKey (740)
final List<int> registerKeyBytes = reply.data.sublist(7, 47);
final List<int> registerKeyBytes = reply.data.sublist(8, 48);
final String registerKey = String.fromCharCodes(registerKeyBytes);
state.selectPlatFormIndex.value = platform;
print('platform: $platform');
print('Register Key: $registerKey');
state.registerKey.value = registerKey;
if (registerKey.isNotEmpty) {
_requestAuthorizationCode();
}
//
cancelBlueConnetctToastTimer();
dismissEasyLoading();
@ -265,8 +267,8 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(),
utcTimeStamp: 0,
unixTimeStamp: 0,
utcTimeStamp: state.serverTime,
unixTimeStamp: getLocalTime2(),
isBeforeAddUser: false,
privateKey: getPrivateKeyList,
);
@ -278,6 +280,18 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
});
}
int getLocalTime() {
final DateTime now = DateTime.now();
final Duration timeZoneOffset = now.timeZoneOffset;
return state.differentialTime + timeZoneOffset.inSeconds;
}
int getLocalTime2() {
final DateTime now = DateTime.now();
final Duration timeZoneOffset = now.timeZoneOffset;
return state.serverTime + timeZoneOffset.inSeconds;
}
void _handleAuthorizationCodeReply(SenderAuthorizationCodeCommandReply reply) {
final int status = reply.data[6];
switch (status) {
@ -285,7 +299,12 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
//
cancelBlueConnetctToastTimer();
dismissEasyLoading();
showToast('操作成功请在24小时内用涂鸦APP添加门锁否则将过期'.tr);
if (state.selectPlatFormIndex.value == 1) {
showSuccess('操作成功,请尽快用"涂鸦”APP配置如不使用请关闭该设置支持'.tr);
} else if (state.selectPlatFormIndex.value == 0) {
showSuccess('操作成功'.tr);
}
break;
default:
//

View File

@ -128,25 +128,27 @@ class _ThirdPartyPlatformPageState extends State<ThirdPartyPlatformPage> {
// 线
isHaveDirection: false,
isHaveRightWidget: true,
rightWidget: Radio<String>(
// Radio 使 id
value: platform,
// selectPlatFormIndex id
groupValue: state.platFormSet.value[state.selectPlatFormIndex.value],
//
activeColor: AppColors.mainColor,
// Radio
onChanged: (value) {
if (value != null) {
setState(() {
// id
final newIndex = state.platFormSet.value.indexWhere((p) => p == value);
if (newIndex != -1) {
state.selectPlatFormIndex.value = newIndex;
}
});
}
},
rightWidget: Obx(
() => Radio<String>(
// Radio 使 id
value: platform,
// selectPlatFormIndex id
groupValue: state.platFormSet.value[state.selectPlatFormIndex.value],
//
activeColor: AppColors.mainColor,
// Radio
onChanged: (value) {
if (value != null) {
setState(() {
// id
final newIndex = state.platFormSet.value.indexWhere((p) => p == value);
if (newIndex != -1) {
state.selectPlatFormIndex.value = newIndex;
}
});
}
},
),
),
action: () {
setState(() {

View File

@ -13,7 +13,7 @@ class ThirdPartyPlatformState {
}
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
int differentialTime = 0;// UTC+0
int differentialTime = 0; // UTC+0
// UI
final RxList<String> platFormSet = List.of({
@ -25,8 +25,11 @@ class ThirdPartyPlatformState {
// UI
final RxList<TppSupportInfo> tppSupportList = RxList<TppSupportInfo>([]);
RxInt selectPlatFormIndex = 1.obs;
RxInt selectPlatFormIndex = (-1).obs;
RxBool openNumber = false.obs;
RxString registerKey = ''.obs;
Map lockInfo = {};
int serverTime = 0; // UTC+0
}

View File

@ -305,6 +305,8 @@ abstract class Api {
'/lockSetting/updateLockSetting'; //
final String reportBuyRequestURL =
'/service/reportBuyRequest'; //
final String getActivateInfoURL =
final String getTppSupportURL =
'/api/authCode/getTppSupport'; // ttp
final String getActivateInfoURL =
'/api/authCode/getActivateInfo'; // ttp
}