完成添加用户蓝牙协议调试,添加其他逻辑
This commit is contained in:
parent
d91f59db48
commit
796cd3a0f6
@ -4,6 +4,7 @@ import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
|||||||
import 'package:star_lock/blue/sender_manage.dart';
|
import 'package:star_lock/blue/sender_manage.dart';
|
||||||
|
|
||||||
import '../app_settings/app_settings.dart';
|
import '../app_settings/app_settings.dart';
|
||||||
|
import 'io_tool/io_manager.dart';
|
||||||
import 'io_tool/io_tool.dart';
|
import 'io_tool/io_tool.dart';
|
||||||
import 'io_tool/manager_event_bus.dart';
|
import 'io_tool/manager_event_bus.dart';
|
||||||
import 'reciver_data.dart';
|
import 'reciver_data.dart';
|
||||||
@ -52,7 +53,6 @@ class BlueManage{
|
|||||||
} else {
|
} else {
|
||||||
_scanDevices.add(device);
|
_scanDevices.add(device);
|
||||||
}
|
}
|
||||||
// EventBusManager().eventBusFir(_scanDevices);
|
|
||||||
scanResultCallBack(_scanDevices);
|
scanResultCallBack(_scanDevices);
|
||||||
}
|
}
|
||||||
// _pushState();
|
// _pushState();
|
||||||
@ -62,13 +62,15 @@ class BlueManage{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 连接监听状态
|
/// 连接监听状态
|
||||||
Future<void> connect(String deviceMAC) async {
|
Future<void> connect(String deviceMAC, String deviceName) async {
|
||||||
print("connect:$deviceMAC");
|
print("connect:$deviceMAC");
|
||||||
_flutterReactiveBle!.connectToDevice(id: deviceMAC).listen((connectionStateUpdate) {
|
_flutterReactiveBle!.connectToDevice(id: deviceMAC).listen((connectionStateUpdate) {
|
||||||
print('ConnectionState for device $deviceMAC : ${connectionStateUpdate.connectionState}');
|
print('ConnectionState for device $deviceMAC : ${connectionStateUpdate.connectionState}');
|
||||||
// EventBusManager().eventBusFir(connectionStateUpdate);
|
// EventBusManager().eventBusFir(connectionStateUpdate);
|
||||||
if(connectionStateUpdate.connectionState == DeviceConnectionState.connected){
|
if(connectionStateUpdate.connectionState == DeviceConnectionState.connected){
|
||||||
// getPublicKey(update.deviceId);
|
// getPublicKey(update.deviceId);
|
||||||
|
// 先配置lockId
|
||||||
|
IoManager().configCurrentDeviceLockId(deviceName);
|
||||||
// 如果状态是连接的开始发现服务
|
// 如果状态是连接的开始发现服务
|
||||||
discoverServices(deviceMAC);
|
discoverServices(deviceMAC);
|
||||||
}
|
}
|
||||||
@ -137,7 +139,7 @@ class BlueManage{
|
|||||||
_flutterReactiveBle!.subscribeToCharacteristic(characteristic).listen((data) {
|
_flutterReactiveBle!.subscribeToCharacteristic(characteristic).listen((data) {
|
||||||
// code to handle incoming data
|
// code to handle incoming data
|
||||||
print("subscribeToCharacteristic: deviceId = ${characteristic.deviceId} characteristicId =${characteristic.characteristicId}---上报来的数据data = $data");
|
print("subscribeToCharacteristic: deviceId = ${characteristic.deviceId} characteristicId =${characteristic.characteristicId}---上报来的数据data = $data");
|
||||||
CommandReciverManager.appDataReceive(data, "");
|
CommandReciverManager.appDataReceive(data);
|
||||||
}, onError: (dynamic error) {
|
}, onError: (dynamic error) {
|
||||||
print("subscribeToCharacteristic error:$error");
|
print("subscribeToCharacteristic error:$error");
|
||||||
});
|
});
|
||||||
@ -145,7 +147,7 @@ class BlueManage{
|
|||||||
|
|
||||||
// 写入
|
// 写入
|
||||||
Future<void> writeCharacteristicWithResponse(QualifiedCharacteristic characteristic, List<int> value) async {
|
Future<void> writeCharacteristicWithResponse(QualifiedCharacteristic characteristic, List<int> value) async {
|
||||||
print('Write with characteristicId:${characteristic.characteristicId} serviceId:${characteristic.serviceId} deviceId:${characteristic.deviceId} value : $value \nhexStr:${radixString(value)}');
|
print('Write with characteristicId:${characteristic.characteristicId} serviceId:${characteristic.serviceId} deviceId:${characteristic.deviceId} value : $value \nhexStr:${radixHex16String(value)}');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<int> valueList = value;
|
List<int> valueList = value;
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import '../../tools/storage.dart';
|
||||||
|
import '../io_tool/io_manager.dart';
|
||||||
import '../io_tool/io_tool.dart';
|
import '../io_tool/io_tool.dart';
|
||||||
import '../sm4Encipher/sm4.dart';
|
import '../sm4Encipher/sm4.dart';
|
||||||
import 'io_reply.dart';
|
import 'io_reply.dart';
|
||||||
@ -22,8 +24,9 @@ class AddUserCommand extends SenderProtocol {
|
|||||||
int? role;
|
int? role;
|
||||||
String? password;
|
String? password;
|
||||||
int? needAuthor;
|
int? needAuthor;
|
||||||
List<int>? userPperationToken;
|
List<int>? publicKey;
|
||||||
List<int>? publicKeyData;
|
List<int>? privateKey;
|
||||||
|
List<int>? token;
|
||||||
AddUserCommand({
|
AddUserCommand({
|
||||||
this.lockID,
|
this.lockID,
|
||||||
this.authUserID,
|
this.authUserID,
|
||||||
@ -36,8 +39,9 @@ class AddUserCommand extends SenderProtocol {
|
|||||||
this.role,
|
this.role,
|
||||||
this.password,
|
this.password,
|
||||||
this.needAuthor,
|
this.needAuthor,
|
||||||
this.userPperationToken,
|
this.publicKey,
|
||||||
this.publicKeyData
|
this.privateKey,
|
||||||
|
this.token
|
||||||
}) : super(CommandType.addUser);
|
}) : super(CommandType.addUser);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -111,13 +115,13 @@ class AddUserCommand extends SenderProtocol {
|
|||||||
if(needAuthor == 0){
|
if(needAuthor == 0){
|
||||||
// 当token失效或者第一次发送的时候token为0
|
// 当token失效或者第一次发送的时候token为0
|
||||||
//Token 4
|
//Token 4
|
||||||
data.addAll([0, 0, 0, 0]);
|
data.addAll(token!);
|
||||||
|
|
||||||
//AuthCodeLen 1
|
//AuthCodeLen 1
|
||||||
data.add(0);
|
data.add(0);
|
||||||
} else {
|
} else {
|
||||||
// token 长度4 首次请求 Token 填 0,如果锁需要鉴权 操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
// token 长度4 首次请求 Token 填 0,如果锁需要鉴权 操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
||||||
data.addAll(userPperationToken!);
|
data.addAll(token!);
|
||||||
|
|
||||||
List<int> authCodeData = [];
|
List<int> authCodeData = [];
|
||||||
|
|
||||||
@ -127,22 +131,13 @@ class AddUserCommand extends SenderProtocol {
|
|||||||
//authUserID
|
//authUserID
|
||||||
authCodeData.addAll(utf8.encode(authUserID!));
|
authCodeData.addAll(utf8.encode(authUserID!));
|
||||||
|
|
||||||
//token 4
|
//token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
||||||
authCodeData.addAll(userPperationToken!);
|
data.addAll([0, 0, 0, 0]);
|
||||||
|
|
||||||
// String pubKey = "";
|
authCodeData.addAll(publicKey!);
|
||||||
// Storage.getData("bluePublicKey").then((res) => {
|
|
||||||
// pubKey = res
|
|
||||||
// });
|
|
||||||
// var pubKey = "ovOvAHuL5+dBCw7L3Qt7IQ==";
|
|
||||||
// print("pubKey:$pubKey");
|
|
||||||
// List<int> pubKeyData = base64.decode(pubKey.toString());
|
|
||||||
// print("pubKeyData:$pubKeyData");
|
|
||||||
authCodeData.addAll(publicKeyData!);
|
|
||||||
|
|
||||||
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
||||||
var authCode = crypto.md5.convert(authCodeData);
|
var authCode = crypto.md5.convert(authCodeData);
|
||||||
// print("authCodeData:$authCodeData \nauthCode:$authCode \nauthCodeBytes:${authCode.bytes}");
|
|
||||||
|
|
||||||
data.add(authCode.bytes.length);
|
data.add(authCode.bytes.length);
|
||||||
data.addAll(authCode.bytes);
|
data.addAll(authCode.bytes);
|
||||||
@ -154,22 +149,16 @@ class AddUserCommand extends SenderProtocol {
|
|||||||
data.add(0);
|
data.add(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("SM4Data:$data");
|
print("addUserSM4Data:$data");
|
||||||
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
||||||
String key = SM4.createHexKey(key: 'TMH_c3570480da8d');
|
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
||||||
ebcData = SM4.encrypt(data, key: key, mode: SM4CryptoMode.ECB);
|
return ebcData;
|
||||||
ebcData.removeRange(ebcData.length - 16, ebcData.length);
|
|
||||||
// ebcData = utf8.encode(getSM4Str(data, "TMH_c3570480da8d"));
|
|
||||||
print("ebcData:$ebcData");
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddUserReply extends Reply {
|
class AddUserReply extends Reply {
|
||||||
AddUserReply.parseData(CommandType commandType, List<int> dataDetail)
|
AddUserReply.parseData(CommandType commandType, List<int> dataDetail)
|
||||||
: super.parseData(commandType, dataDetail) {
|
: super.parseData(commandType, dataDetail) {
|
||||||
int index = 0;
|
data = dataDetail;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,13 +3,17 @@ import 'dart:convert';
|
|||||||
import 'package:star_lock/blue/sm4Encipher/sm4.dart';
|
import 'package:star_lock/blue/sm4Encipher/sm4.dart';
|
||||||
|
|
||||||
import '../../tools/storage.dart';
|
import '../../tools/storage.dart';
|
||||||
|
import '../io_tool/io_manager.dart';
|
||||||
import '../io_tool/io_tool.dart';
|
import '../io_tool/io_tool.dart';
|
||||||
|
import '../sender_manage.dart';
|
||||||
import 'io_reply.dart';
|
import 'io_reply.dart';
|
||||||
import 'io_sender.dart';
|
import 'io_sender.dart';
|
||||||
import 'io_type.dart';
|
import 'io_type.dart';
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart' as crypto;
|
import 'package:crypto/crypto.dart' as crypto;
|
||||||
|
|
||||||
|
List<int>publicKeyDataList = [];
|
||||||
|
|
||||||
class GetPrivateKeyCommand extends SenderProtocol {
|
class GetPrivateKeyCommand extends SenderProtocol {
|
||||||
String? lockID;
|
String? lockID;
|
||||||
String? keyID; // 钥匙ID
|
String? keyID; // 钥匙ID
|
||||||
@ -28,6 +32,7 @@ class GetPrivateKeyCommand extends SenderProtocol {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<int> messageDetail() {
|
List<int> messageDetail() {
|
||||||
|
publicKeyDataList = publicKeyData!;
|
||||||
List<int> data = [];
|
List<int> data = [];
|
||||||
List<int> ebcData = [];
|
List<int> ebcData = [];
|
||||||
// print("lockID:${lockID!} lockID.utf8.encode${utf8.encode(lockID!)}");
|
// print("lockID:${lockID!} lockID.utf8.encode${utf8.encode(lockID!)}");
|
||||||
@ -87,22 +92,10 @@ class GetPrivateKeyCommand extends SenderProtocol {
|
|||||||
authCodeData.add((d1 & 0xff00) >> 8);
|
authCodeData.add((d1 & 0xff00) >> 8);
|
||||||
authCodeData.add((d1 & 0xff));
|
authCodeData.add((d1 & 0xff));
|
||||||
|
|
||||||
List<int> getIntList;
|
|
||||||
Storage.getStringList("bluePublicKey").then((res) {
|
|
||||||
print("getStrList:$res");
|
|
||||||
getIntList = changeStringListToIntList(res!);
|
|
||||||
print("getIntList:$getIntList");
|
|
||||||
});
|
|
||||||
|
|
||||||
// List<String> getStrList = Storage.getLocalStorage("bluePublicKey") as List<String>;
|
|
||||||
// List<int> getIntList = changeStringListToIntList(getStrList);
|
|
||||||
|
|
||||||
// print("getIntList:$getIntList");
|
|
||||||
authCodeData.addAll(publicKeyData!);
|
authCodeData.addAll(publicKeyData!);
|
||||||
|
|
||||||
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
||||||
var authCode = crypto.md5.convert(authCodeData);
|
var authCode = crypto.md5.convert(authCodeData);
|
||||||
// print("authCodeData:$authCodeData \nauthCode:$authCode \nauthCodeBytes:${authCode.bytes}");
|
|
||||||
|
|
||||||
data.add(authCode.bytes.length);
|
data.add(authCode.bytes.length);
|
||||||
data.addAll(authCode.bytes);
|
data.addAll(authCode.bytes);
|
||||||
@ -114,13 +107,10 @@ class GetPrivateKeyCommand extends SenderProtocol {
|
|||||||
data.add(0);
|
data.add(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("SM4Data:$data");
|
// print("SM4Data:$data");
|
||||||
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
||||||
String key = SM4.createHexKey(key: 'TMH_c3570480da8d');
|
ebcData = SM4.encrypt(data, key: utf8.encode(IoManager().getCurrentDeviceLockId), mode: SM4CryptoMode.ECB);
|
||||||
ebcData = SM4.encrypt(data, key: key, mode: SM4CryptoMode.ECB);
|
|
||||||
ebcData.removeRange(ebcData.length - 16, ebcData.length);
|
|
||||||
// ebcData = utf8.encode(getSM4Str(data, "TMH_c3570480da8d"));
|
|
||||||
print("ebcData:$ebcData");
|
|
||||||
return ebcData;
|
return ebcData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,32 +118,8 @@ class GetPrivateKeyCommand extends SenderProtocol {
|
|||||||
class GetPrivateKeyReply extends Reply {
|
class GetPrivateKeyReply extends Reply {
|
||||||
GetPrivateKeyReply.parseData(CommandType commandType, List<int> dataDetail)
|
GetPrivateKeyReply.parseData(CommandType commandType, List<int> dataDetail)
|
||||||
: super.parseData(commandType, dataDetail) {
|
: super.parseData(commandType, dataDetail) {
|
||||||
var getData = dataDetail.sublist(2);
|
data = dataDetail.sublist(2);
|
||||||
|
status = data[0];
|
||||||
// print("getData:$getData");
|
// print("getData:$getData");
|
||||||
switch(getData[0]){
|
|
||||||
case 0x00:
|
|
||||||
//成功
|
|
||||||
print('获取私钥成功');
|
|
||||||
getData.removeAt(0);
|
|
||||||
List commKey = getData.sublist(0, 16);
|
|
||||||
List signKey = getData.sublist(16);
|
|
||||||
print("commKey:$commKey signKey:$signKey");
|
|
||||||
break;
|
|
||||||
case 0x07:
|
|
||||||
//无权限
|
|
||||||
print('获取私钥无权限');
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 0x0f:
|
|
||||||
//用户已存在
|
|
||||||
print('获取私钥:用户已存在');
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//失败
|
|
||||||
print('获取私钥失败');
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import '../../tools/storage.dart';
|
import '../../tools/storage.dart';
|
||||||
|
import '../io_tool/io_manager.dart';
|
||||||
import '../io_tool/io_tool.dart';
|
import '../io_tool/io_tool.dart';
|
||||||
import '../sender_manage.dart';
|
import '../sender_manage.dart';
|
||||||
import 'io_reply.dart';
|
import 'io_reply.dart';
|
||||||
@ -42,33 +43,7 @@ class GetPublicKeyCommand extends SenderProtocol {
|
|||||||
class GetPublicKeyReply extends Reply {
|
class GetPublicKeyReply extends Reply {
|
||||||
GetPublicKeyReply.parseData(CommandType commandType, List<int> dataDetail)
|
GetPublicKeyReply.parseData(CommandType commandType, List<int> dataDetail)
|
||||||
: super.parseData(commandType, dataDetail) {
|
: super.parseData(commandType, dataDetail) {
|
||||||
var tokenData = dataDetail.sublist(3);
|
status = dataDetail[2];
|
||||||
print('获取公钥:dataDetail:$dataDetail tokenData:$tokenData');
|
data = dataDetail;
|
||||||
switch(dataDetail[2]){
|
|
||||||
case 0x00:
|
|
||||||
//成功
|
|
||||||
String stringEncoded = base64.encode(tokenData);
|
|
||||||
print('获取公钥成功 publickey:$stringEncoded');
|
|
||||||
// 储存公钥
|
|
||||||
var saveStrList = changeIntListToStringList(tokenData);
|
|
||||||
// Storage.setStringList("bluePublicKey", saveStrList);
|
|
||||||
Storage.setStringList("bluePublicKey", saveStrList);
|
|
||||||
// List<String> getStrList = Storage.getLocalStorage("bluePublicKey") as List<String>;
|
|
||||||
// print('获取储存的公钥 getStrList:$getStrList');
|
|
||||||
IoSenderManage.getPrivateKey("TMH_c3570480da8d", "1", "1", 1, tokenData, 1);
|
|
||||||
break;
|
|
||||||
case 0x07:
|
|
||||||
//无权限
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 0x0f:
|
|
||||||
//用户已存在
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//失败
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,22 +1,13 @@
|
|||||||
import 'io_type.dart';
|
import 'io_type.dart';
|
||||||
|
|
||||||
abstract class Reply{
|
abstract class Reply{
|
||||||
//value字节长度
|
|
||||||
int? packetHeader = 4; // 包头4个字节
|
|
||||||
int? packetType = 1; // 包类型1个字节
|
|
||||||
int? packetNumber = 1; // 包序号
|
|
||||||
int? packetIdentifier = 1; // 包标识
|
|
||||||
int? packetLength = 4; // 包标识
|
|
||||||
CommandType? commandType;
|
CommandType? commandType;
|
||||||
int? packetMcrc = 2; // 校验位
|
|
||||||
|
|
||||||
//command key flag
|
//command key flag
|
||||||
int commandKey = 0;
|
int status = 0;
|
||||||
|
List<int> data = [];
|
||||||
Reply.parseData(this.commandType, List<int> dataDetail);
|
Reply.parseData(this.commandType, List<int> dataDetail);
|
||||||
// Reply({this.result});
|
|
||||||
|
|
||||||
|
|
||||||
// bool get isSuccessfully => packetHeader == EF01EE02;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -48,17 +48,9 @@ abstract class SenderProtocol extends IOData {
|
|||||||
// print("_commandIndex:$_commandIndex commandIndexChang1$commandIndexChang1 commandIndexChang2:$commandIndexChang2");
|
// print("_commandIndex:$_commandIndex commandIndexChang1$commandIndexChang1 commandIndexChang2:$commandIndexChang2");
|
||||||
|
|
||||||
// 包标识
|
// 包标识
|
||||||
// 指令类型
|
// 指令类型 高 4 位表示包版本,低 4 位用来指示后面数据的加密类型,长度为 1 字节,加密类型取值说明,0:明文,1:AES128,2:SM4(事先约定密钥),3:SM4(设备指定密钥)
|
||||||
int type = commandType!.typeValue;
|
commandList.add(commandType!.identifierValue);
|
||||||
if(type == 0x3090){
|
print("commandType!.identifierValue:${commandType!.identifierValue}");
|
||||||
// 不加密
|
|
||||||
identifier = 0x20;
|
|
||||||
}else if(type == 0x3091){
|
|
||||||
// 不加密
|
|
||||||
identifier = 0x22;
|
|
||||||
}
|
|
||||||
commandList.add(identifier);
|
|
||||||
// print("identifier:$identifier");
|
|
||||||
|
|
||||||
// 数据长度
|
// 数据长度
|
||||||
int dataLen = dataSourceLength();
|
int dataLen = dataSourceLength();
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
//TODO:发送指令类型
|
//TODO:发送指令类型
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
enum CommandType {
|
enum CommandType {
|
||||||
addUser, //增加用户 = 0x3001
|
addUser, //增加用户 = 0x3001
|
||||||
deletUser , //删除用户 = 0x3002
|
deletUser , //删除用户 = 0x3002
|
||||||
@ -164,6 +166,22 @@ extension ExtensionCommandType on CommandType {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get identifierValue {
|
||||||
|
int type = 0x23;
|
||||||
|
switch(this){
|
||||||
|
case CommandType.getLockPublicKey:
|
||||||
|
type = 0x20;
|
||||||
|
break;
|
||||||
|
case CommandType.getLockPrivateKey:
|
||||||
|
type = 0x22;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
type = 0x23;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
String get typeName {
|
String get typeName {
|
||||||
String t = '';
|
String t = '';
|
||||||
switch(typeValue){
|
switch(typeValue){
|
||||||
|
|||||||
@ -3,6 +3,11 @@ enum DataTransmissionMode {
|
|||||||
ble,
|
ble,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const saveBluePublicKey = "BluePublicKey";
|
||||||
|
const saveBluePrivateKey = "BluePrivateKey";
|
||||||
|
const saveBlueSignKey = "BlueSignKey";
|
||||||
|
const saveBlueToken = "BlueToken";
|
||||||
|
|
||||||
class IoManager {
|
class IoManager {
|
||||||
|
|
||||||
static IoManager? _ioManager;
|
static IoManager? _ioManager;
|
||||||
@ -21,18 +26,20 @@ class IoManager {
|
|||||||
///蓝牙传输协议
|
///蓝牙传输协议
|
||||||
void bleTransmission() => _dataTransmissionMode = DataTransmissionMode.ble;
|
void bleTransmission() => _dataTransmissionMode = DataTransmissionMode.ble;
|
||||||
|
|
||||||
int _commandIndex = 1; //割草机协议帧序号
|
///割草机协议帧序号
|
||||||
|
int _commandIndex = 1;
|
||||||
configCommandIdx(int idx) => _commandIndex = idx;
|
configCommandIdx(int idx) => _commandIndex = idx;
|
||||||
Future<void> increaseCommandIndex() async {
|
Future<void> increaseCommandIndex() async {
|
||||||
_commandIndex < 255 ? _commandIndex++ : _commandIndex = 0;
|
_commandIndex < 255 ? _commandIndex++ : _commandIndex = 0;
|
||||||
}
|
}
|
||||||
|
void resetCommandIndex() => _commandIndex = 0;
|
||||||
void resetCommandIndex(){
|
|
||||||
_commandIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get commandIndex => _commandIndex;
|
int get commandIndex => _commandIndex;
|
||||||
|
|
||||||
|
/// 当前设备连接的lockId
|
||||||
|
String _currentDeviceLockId = "";
|
||||||
|
configCurrentDeviceLockId(String lockId) => _currentDeviceLockId = lockId;
|
||||||
|
String get getCurrentDeviceLockId => _currentDeviceLockId;
|
||||||
|
|
||||||
void resetAllFlags() {
|
void resetAllFlags() {
|
||||||
resetCommandIndex();
|
resetCommandIndex();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -254,7 +254,7 @@ List<List<T>> splitList<T>(List<T> list, int len) {
|
|||||||
//TODO:int->两个字节 List 高字节在前,低字节在后(小端存储) 本工程只有配置 WiFi用到的!!!!
|
//TODO:int->两个字节 List 高字节在前,低字节在后(小端存储) 本工程只有配置 WiFi用到的!!!!
|
||||||
List<int> intToByte2ListLow(int value) => [value >> 8, value];
|
List<int> intToByte2ListLow(int value) => [value >> 8, value];
|
||||||
|
|
||||||
String radixString(List<int> codeUnits) {
|
String radixHex16String(List<int> codeUnits) {
|
||||||
String result = '';
|
String result = '';
|
||||||
codeUnits.forEach((value) {
|
codeUnits.forEach((value) {
|
||||||
result += value.toRadixString(16).padLeft(2, '0');
|
result += value.toRadixString(16).padLeft(2, '0');
|
||||||
|
|||||||
@ -1,18 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import '../tools/storage.dart';
|
||||||
import 'io_protocol/io_addUser.dart';
|
import 'io_protocol/io_addUser.dart';
|
||||||
import 'io_protocol/io_getPrivateKey.dart';
|
import 'io_protocol/io_getPrivateKey.dart';
|
||||||
import 'io_protocol/io_getPublicKey.dart';
|
import 'io_protocol/io_getPublicKey.dart';
|
||||||
import 'io_protocol/io_openDoor.dart';
|
import 'io_protocol/io_openDoor.dart';
|
||||||
import 'io_protocol/io_reply.dart';
|
import 'io_protocol/io_reply.dart';
|
||||||
import 'io_protocol/io_type.dart';
|
import 'io_protocol/io_type.dart';
|
||||||
|
import 'io_tool/io_manager.dart';
|
||||||
import 'io_tool/io_tool.dart';
|
import 'io_tool/io_tool.dart';
|
||||||
import 'io_tool/manager_event_bus.dart';
|
import 'io_tool/manager_event_bus.dart';
|
||||||
import 'sm4Encipher/sm4.dart';
|
import 'sm4Encipher/sm4.dart';
|
||||||
|
|
||||||
class CommandReciverManager {
|
class CommandReciverManager {
|
||||||
|
|
||||||
static void appDataReceive(List<int> data, String lockId) async {
|
static void appDataReceive(List<int> data) async {
|
||||||
///解析数据
|
///解析数据
|
||||||
if(data.isEmpty){
|
if(data.isEmpty){
|
||||||
return;
|
return;
|
||||||
@ -46,28 +50,26 @@ class CommandReciverManager {
|
|||||||
// SM4(事先约定密钥)
|
// SM4(事先约定密钥)
|
||||||
// 获取的加密数组
|
// 获取的加密数组
|
||||||
var getDataList = data.sublist(12, 12 + dataLen);
|
var getDataList = data.sublist(12, 12 + dataLen);
|
||||||
String key = SM4.createHexKey(key: 'TMH_c3570480da8d');
|
|
||||||
// 解密
|
// 解密
|
||||||
oriDataList = SM4.decrypt(getDataList, key: key, mode: SM4CryptoMode.ECB);
|
// String key = SM4.createHexKey(key: IoManager().getCurrentDeviceLockId);
|
||||||
|
oriDataList = SM4.decrypt(getDataList, key: utf8.encode(IoManager().getCurrentDeviceLockId), mode: SM4CryptoMode.ECB);
|
||||||
oriDataList = oriDataList.sublist(0, oriLen);
|
oriDataList = oriDataList.sublist(0, oriLen);
|
||||||
print("SM4 oriDataList:$oriDataList");
|
print("SM4 oriDataList:$oriDataList");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
//SM4(设备指定密钥)
|
//SM4(设备指定密钥)
|
||||||
// for (var i = 0; i < dataLen ; i++) {
|
// 获取的加密数组
|
||||||
// dataView[i] = uint8Recv[12 + i];
|
var getDataList = data.sublist(12, 12 + dataLen);
|
||||||
// }
|
|
||||||
// console.log("dataView.length = ", dataView.length);
|
var res = await Storage.getStringList(saveBluePrivateKey);
|
||||||
// console.log("currCommStru.pairCommKey = ", currCommStru.pairCommKey);
|
List<int> getPrivateKeyList = changeStringListToIntList(res!);
|
||||||
// var commKey1 = base64js.toByteArray(currCommStru.pairCommKey);
|
|
||||||
// console.log("commKey1 = ", commKey1);
|
// 解密
|
||||||
// var d_cbc = cbc.decrypt_ecb(dataView, commKey1, false, "nobase64");
|
// String key = SM4.createHexKey(key: radixHex16String(getPrivateKeyList!));
|
||||||
// console.log("d_cbc = ", d_cbc);
|
oriDataList = SM4.decrypt(getDataList, key: getPrivateKeyList, mode: SM4CryptoMode.ECB);
|
||||||
// console.log("oriLen = ", oriLen);
|
oriDataList = oriDataList.sublist(0, oriLen);
|
||||||
// for (var i = 0; i < oriLen ; i++) {
|
print("SM4 oriDataList:$oriDataList");
|
||||||
// oriDataView[i] = d_cbc[i];
|
|
||||||
// }
|
|
||||||
// console.log("oriDataView = ", oriDataView);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -82,6 +84,7 @@ class CommandReciverManager {
|
|||||||
if(data.isNotEmpty){
|
if(data.isNotEmpty){
|
||||||
var cmd = data[0] * 256 + data[1];
|
var cmd = data[0] * 256 + data[1];
|
||||||
CommandType commandType = ExtensionCommandType.getCommandType(cmd);
|
CommandType commandType = ExtensionCommandType.getCommandType(cmd);
|
||||||
|
await IoManager().increaseCommandIndex();
|
||||||
// data.removeRange(0, 2);
|
// data.removeRange(0, 2);
|
||||||
print("111111data cmd:$cmd commandType:$commandType data:$data");
|
print("111111data cmd:$cmd commandType:$commandType data:$data");
|
||||||
var reply;
|
var reply;
|
||||||
|
|||||||
@ -24,9 +24,9 @@ class CommandSenderManager {
|
|||||||
bool canSendControlCommand = false;
|
bool canSendControlCommand = false;
|
||||||
|
|
||||||
//TODO:发送常规数据
|
//TODO:发送常规数据
|
||||||
void managerSendData ({
|
Future<void> managerSendData ({
|
||||||
required SenderProtocol command,
|
required SenderProtocol command,
|
||||||
CommandSendCallBack? callBack}) {
|
CommandSendCallBack? callBack}) async {
|
||||||
if (callBack != null) {
|
if (callBack != null) {
|
||||||
// if (!BluetoothManager().connected) {
|
// if (!BluetoothManager().connected) {
|
||||||
print('❌ 蓝牙断开了');
|
print('❌ 蓝牙断开了');
|
||||||
@ -38,7 +38,7 @@ class CommandSenderManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> value = command.packageData();
|
List<int> value = await command.packageData();
|
||||||
// print("sendData:${value}");
|
// print("sendData:${value}");
|
||||||
_sendNormalData(value);
|
_sendNormalData(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,50 +8,66 @@ import 'sender_data.dart';
|
|||||||
class IoSenderManage {
|
class IoSenderManage {
|
||||||
|
|
||||||
//todo:获取公钥
|
//todo:获取公钥
|
||||||
static void getPublicKey(String lockId ,{CommandSendCallBack? callBack}) {
|
static void getPublicKey({String? lockId ,CommandSendCallBack? callBack}) {
|
||||||
CommandSenderManager().managerSendData(command: GetPublicKeyCommand(
|
CommandSenderManager().managerSendData(command: GetPublicKeyCommand(
|
||||||
lockID: lockId,
|
lockID: lockId,
|
||||||
), callBack:callBack);
|
), callBack:callBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo:获取私钥
|
//todo:获取私钥
|
||||||
static void getPrivateKey(
|
static void getPrivateKey({
|
||||||
String? lockId,
|
String? lockId,
|
||||||
String? keyID, // 钥匙ID
|
String? keyID, // 钥匙ID
|
||||||
String? authUserID,// 钥匙授权人ID
|
String? authUserID,// 钥匙授权人ID
|
||||||
int? nowTime,
|
int? nowTime,
|
||||||
List<int>? publicKeyData,
|
List<int>? publicKeyData,
|
||||||
int? needAuthor, {CommandSendCallBack? callBack}) {
|
int? needAuthor,
|
||||||
|
CommandSendCallBack? callBack}) {
|
||||||
CommandSenderManager().managerSendData(command: GetPrivateKeyCommand(
|
CommandSenderManager().managerSendData(command: GetPrivateKeyCommand(
|
||||||
lockID: lockId,
|
lockID: lockId,
|
||||||
keyID: keyID,
|
keyID: keyID,
|
||||||
authUserID: authUserID,
|
authUserID: authUserID,
|
||||||
nowTime: nowTime,
|
nowTime: nowTime,
|
||||||
publicKeyData:publicKeyData,
|
publicKeyData:publicKeyData,
|
||||||
needAuthor: needAuthor,
|
needAuthor: needAuthor,
|
||||||
), callBack:callBack);
|
), callBack:callBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo:添加用户
|
//todo:添加用户
|
||||||
// static void senderAddUser({CommandSendCallBack? callBack}) {
|
static void senderAddUser({
|
||||||
// CommandSenderManager().managerSendData(
|
String? lockID,
|
||||||
// command: AddUserCommand(
|
String? authUserID,
|
||||||
// cmdID: 0,
|
String? keyID,
|
||||||
// lockID: "",
|
String? userID,
|
||||||
// authUserID: "",
|
int? openMode,
|
||||||
// keyID: "",
|
int? keyType,
|
||||||
// userID: "",
|
int? startDate,
|
||||||
// openMode: 0,
|
int? expireDate,
|
||||||
// keyType: 0,
|
int? role,
|
||||||
// startDate: 0,
|
String? password,
|
||||||
// expireDate: 0,
|
int? needAuthor,
|
||||||
// role: 0,
|
List<int>? publicKey,
|
||||||
// password: "",
|
List<int>? privateKey,
|
||||||
// token: 0,
|
List<int>? token,
|
||||||
// authCodeLen: 0,
|
CommandSendCallBack? callBack}) {
|
||||||
// authCode: "",
|
CommandSenderManager().managerSendData(
|
||||||
// ), callBack:callBack);
|
command: AddUserCommand(
|
||||||
// }
|
lockID: lockID,
|
||||||
|
authUserID: authUserID,
|
||||||
|
keyID: keyID,
|
||||||
|
userID: userID,
|
||||||
|
openMode: openMode,
|
||||||
|
keyType: keyType,
|
||||||
|
startDate: startDate,
|
||||||
|
expireDate: expireDate,
|
||||||
|
role: role,
|
||||||
|
password: password,
|
||||||
|
needAuthor: needAuthor,
|
||||||
|
publicKey: publicKey,
|
||||||
|
privateKey: privateKey,
|
||||||
|
token: token
|
||||||
|
), callBack:callBack);
|
||||||
|
}
|
||||||
|
|
||||||
//todo:开锁
|
//todo:开锁
|
||||||
// static void senderOpenDoor({CommandSendCallBack? callBack}) {
|
// static void senderOpenDoor({CommandSendCallBack? callBack}) {
|
||||||
|
|||||||
@ -359,8 +359,8 @@ class SM4 {
|
|||||||
return roundKey;
|
return roundKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setKey(String key) {
|
static void setKey(List<int> key) {
|
||||||
List<int> keyBytes = SMUtils.hexStringToBytes(key);
|
List<int> keyBytes = key;
|
||||||
List<int> intermediateKeys = List<int>.filled(36, 0);
|
List<int> intermediateKeys = List<int>.filled(36, 0);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
intermediateKeys[i] = _readUint32BE(keyBytes, i * 4) ^ FK[i];
|
intermediateKeys[i] = _readUint32BE(keyBytes, i * 4) ^ FK[i];
|
||||||
@ -520,7 +520,7 @@ class SM4 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static List<int> encrypt(List<int> data,
|
static List<int> encrypt(List<int> data,
|
||||||
{String? key, SM4CryptoMode mode = SM4CryptoMode.ECB, String? iv}) {
|
{List<int>? key, SM4CryptoMode mode = SM4CryptoMode.ECB, String? iv}) {
|
||||||
if (key != null) setKey(key);
|
if (key != null) setKey(key);
|
||||||
List<int> input = data;
|
List<int> input = data;
|
||||||
List<int> output = _crypto(input, SM4_ENCRYPT, mode, iv);
|
List<int> output = _crypto(input, SM4_ENCRYPT, mode, iv);
|
||||||
@ -536,7 +536,7 @@ class SM4 {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
static decrypt(List<int> data,
|
static decrypt(List<int> data,
|
||||||
{String? key, SM4CryptoMode mode = SM4CryptoMode.ECB, String? iv}) {
|
{List<int>? key, SM4CryptoMode mode = SM4CryptoMode.ECB, String? iv}) {
|
||||||
if (key != null) setKey(key);
|
if (key != null) setKey(key);
|
||||||
List<int> input = data;
|
List<int> input = data;
|
||||||
List<int> output = _crypto(input, SM4_DECRYPT, mode, iv);
|
List<int> output = _crypto(input, SM4_DECRYPT, mode, iv);
|
||||||
|
|||||||
@ -2,12 +2,20 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
|
||||||
|
import 'package:get_storage/get_storage.dart';
|
||||||
|
import 'package:star_lock/blue/io_protocol/io_getPrivateKey.dart';
|
||||||
|
import 'package:star_lock/blue/io_protocol/io_getPublicKey.dart';
|
||||||
import 'package:star_lock/tools/baseGetXController.dart';
|
import 'package:star_lock/tools/baseGetXController.dart';
|
||||||
|
|
||||||
import '../../../blue/blue_manage.dart';
|
import '../../../blue/blue_manage.dart';
|
||||||
|
import '../../../blue/io_protocol/io_addUser.dart';
|
||||||
|
import '../../../blue/io_protocol/io_reply.dart';
|
||||||
|
import '../../../blue/io_tool/io_manager.dart';
|
||||||
import '../../../blue/io_tool/io_model.dart';
|
import '../../../blue/io_tool/io_model.dart';
|
||||||
|
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 '../../../tools/storage.dart';
|
||||||
import 'nearbyLock_state.dart';
|
import 'nearbyLock_state.dart';
|
||||||
|
|
||||||
class NearbyLockLogic extends BaseGetXController{
|
class NearbyLockLogic extends BaseGetXController{
|
||||||
@ -15,26 +23,18 @@ class NearbyLockLogic extends BaseGetXController{
|
|||||||
final NearbyLockState state = NearbyLockState();
|
final NearbyLockState state = NearbyLockState();
|
||||||
|
|
||||||
// 点击复合要求的设备之后 连接
|
// 点击复合要求的设备之后 连接
|
||||||
void connect(String lockId){
|
void connect(String lockId, String deviceName){
|
||||||
BlueManage().connect(lockId);
|
BlueManage().connect(lockId, deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听蓝牙连接的状态
|
// 监听蓝牙连接的状态
|
||||||
late StreamSubscription _streamSubscription;
|
late StreamSubscription _streamSubscription;
|
||||||
void _startListenIO(){
|
void _startListenIO(){
|
||||||
_streamSubscription = EventBusManager().eventBus!.on<QualifiedCharacteristic>().listen((event) async {
|
_streamSubscription = EventBusManager().eventBus!.on<QualifiedCharacteristic>().listen((event) async {
|
||||||
IoSenderManage.getPublicKey(state.seletLockName.value);
|
IoSenderManage.getPublicKey(lockId:state.seletLockName.value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 状态在线之后发现服务
|
|
||||||
// Future<void> scanDiscoverServices(String lockId) async {
|
|
||||||
// // 获取特征值 处理特征值
|
|
||||||
// List<DiscoveredService> list = await BlueManage().discoverServices(lockId);
|
|
||||||
// // 发送获取公钥
|
|
||||||
// IoSenderManage.getPublicKey(state.seletLockName.value);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 获取公钥
|
// 获取公钥
|
||||||
// void getPublicKey(String lockId){
|
// void getPublicKey(String lockId){
|
||||||
// // print("seletGetPublicKey:${lockId}");
|
// // print("seletGetPublicKey:${lockId}");
|
||||||
@ -57,6 +57,146 @@ class NearbyLockLogic extends BaseGetXController{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
late StreamSubscription<Reply> _replySubscription;
|
||||||
|
void _initReplySubscription() {
|
||||||
|
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((reply) {
|
||||||
|
if(reply is GetPublicKeyReply) {
|
||||||
|
_replyGetPublicKey(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reply is GetPrivateKeyReply) {
|
||||||
|
_replyGetPrivateKeyKey(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(reply is AddUserReply) {
|
||||||
|
_replyAddUserKey(reply);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _replyGetPublicKey(Reply reply){
|
||||||
|
// 获取公钥
|
||||||
|
switch(reply.status){
|
||||||
|
case 0x00:
|
||||||
|
//成功
|
||||||
|
// 储存公钥
|
||||||
|
var tokenData = reply.data.sublist(3);
|
||||||
|
var saveStrList = changeIntListToStringList(tokenData);
|
||||||
|
Storage.setStringList(saveBluePublicKey, saveStrList);
|
||||||
|
IoSenderManage.getPrivateKey(
|
||||||
|
lockId:IoManager().getCurrentDeviceLockId,
|
||||||
|
keyID:"1",
|
||||||
|
authUserID:"1",
|
||||||
|
nowTime:1,
|
||||||
|
publicKeyData:tokenData,
|
||||||
|
needAuthor:1);
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
//无权限
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x0f:
|
||||||
|
//用户已存在
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//失败
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _replyGetPrivateKeyKey(Reply reply){
|
||||||
|
switch(reply.status){
|
||||||
|
case 0x00:
|
||||||
|
//成功
|
||||||
|
print('获取私钥成功');
|
||||||
|
reply.data.removeAt(0);
|
||||||
|
|
||||||
|
// 私钥
|
||||||
|
List<int> privateKey = reply.data.sublist(0, 16);
|
||||||
|
var savePrivateKeyList = changeIntListToStringList(privateKey);
|
||||||
|
Storage.setStringList(saveBluePrivateKey, savePrivateKeyList);
|
||||||
|
|
||||||
|
// signKey
|
||||||
|
List<int> signKey = reply.data.sublist(16);
|
||||||
|
var savesignKeyList = changeIntListToStringList(signKey);
|
||||||
|
Storage.setStringList(saveBlueSignKey, savesignKeyList);
|
||||||
|
|
||||||
|
print("privateKey:$privateKey signKey:$signKey");
|
||||||
|
IoSenderManage.senderAddUser(
|
||||||
|
lockID:IoManager().getCurrentDeviceLockId,
|
||||||
|
authUserID:"100001",
|
||||||
|
keyID:"1",
|
||||||
|
userID:"100001",
|
||||||
|
openMode:1,
|
||||||
|
keyType:1,
|
||||||
|
startDate:0x11223344,
|
||||||
|
expireDate:0x11223344,
|
||||||
|
role:255,
|
||||||
|
password:"123456",
|
||||||
|
needAuthor:1,
|
||||||
|
publicKey:publicKeyDataList,
|
||||||
|
privateKey:privateKey,
|
||||||
|
token: [0,0,0,0]
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
//无权限
|
||||||
|
print('获取私钥无权限');
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x0f:
|
||||||
|
//用户已存在
|
||||||
|
print('获取私钥:用户已存在');
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//失败
|
||||||
|
print('获取私钥失败');
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _replyAddUserKey(Reply reply){
|
||||||
|
var lockId = reply.data.sublist(2, 42);
|
||||||
|
print("lockId:$lockId");
|
||||||
|
var token = reply.data.sublist(42, 46);
|
||||||
|
List<String> strTokenList = changeIntListToStringList(token);
|
||||||
|
Storage.setStringList(saveBlueToken, strTokenList);
|
||||||
|
print("token:$token");
|
||||||
|
int status = reply.data[46];
|
||||||
|
print("status:$status");
|
||||||
|
switch(status){
|
||||||
|
case 0x00:
|
||||||
|
//成功
|
||||||
|
print("添加用户数据解析成功");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x06:
|
||||||
|
//无权限
|
||||||
|
print("需要鉴权");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
//无权限
|
||||||
|
print("用户无权限");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 0x09:
|
||||||
|
// 权限校验错误
|
||||||
|
print("权限校验错误");
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//失败
|
||||||
|
print("领锁失败");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
// TODO: implement onReady
|
// TODO: implement onReady
|
||||||
@ -65,6 +205,7 @@ class NearbyLockLogic extends BaseGetXController{
|
|||||||
|
|
||||||
_startListenIO();
|
_startListenIO();
|
||||||
_initSendStreamSubscription();
|
_initSendStreamSubscription();
|
||||||
|
_initReplySubscription();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -75,10 +216,8 @@ class NearbyLockLogic extends BaseGetXController{
|
|||||||
|
|
||||||
// 进来第一步开始扫描
|
// 进来第一步开始扫描
|
||||||
BlueManage().startScan((v){
|
BlueManage().startScan((v){
|
||||||
bool isHave = state.devices.any((element) => element.id == v[0].id);
|
state.devices.clear();
|
||||||
if (isHave == false){
|
state.devices.addAll(v);
|
||||||
state.devices.addAll(v);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +227,7 @@ class NearbyLockLogic extends BaseGetXController{
|
|||||||
super.onClose();
|
super.onClose();
|
||||||
_streamSubscription.cancel();
|
_streamSubscription.cancel();
|
||||||
_sendStreamSubscription.cancel();
|
_sendStreamSubscription.cancel();
|
||||||
|
_replySubscription.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ class _NearbyLockPageState extends State<NearbyLockPage> {
|
|||||||
// Navigator.pushNamed(context, Routers.lockAddressPage);
|
// Navigator.pushNamed(context, Routers.lockAddressPage);
|
||||||
// logic.getPublicKey(state.devices[index].serviceUuids[0].toString());
|
// logic.getPublicKey(state.devices[index].serviceUuids[0].toString());
|
||||||
state.seletLockName.value = state.devices[index].name;
|
state.seletLockName.value = state.devices[index].name;
|
||||||
logic.connect(state.devices[index].id);
|
logic.connect(state.devices[index].id, state.devices[index].name);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
separatorBuilder: (BuildContext context, int index) {
|
separatorBuilder: (BuildContext context, int index) {
|
||||||
|
|||||||
@ -6,6 +6,6 @@ import 'package:get/get.dart';
|
|||||||
|
|
||||||
class NearbyLockState {
|
class NearbyLockState {
|
||||||
|
|
||||||
var devices = <DiscoveredDevice>[].obs;
|
RxList<DiscoveredDevice> devices = <DiscoveredDevice>[].obs;
|
||||||
var seletLockName = "".obs;
|
var seletLockName = "".obs;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user