feat:增加网关初始化发送指令和接收指令的处理
This commit is contained in:
parent
2429a107e1
commit
5054f2a68a
@ -246,6 +246,15 @@ class _StarLockLoginPageState extends State<StarLockLoginPage> {
|
||||
ToPeerId: '3phX8Ng2cZHz5NtP8xAf6nYy2z1BYytoejgjoHrWMGhH');
|
||||
},
|
||||
),
|
||||
SubmitBtn(
|
||||
btnName: '发送网关初始化消息',
|
||||
onClick: () {
|
||||
StartChartManage().sendGatewayResetMessage(
|
||||
ToPeerId: '3phX8Ng2cZHz5NtP8xAf6nYy2z1BYytoejgjoHrWMGhH',
|
||||
gatewayId: 1,
|
||||
);
|
||||
},
|
||||
),
|
||||
SizedBox(height: 50.w),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
||||
@ -3,6 +3,7 @@ import 'package:star_lock/talk/startChart/constant/message_type_constant.dart';
|
||||
import 'package:star_lock/talk/startChart/constant/payload_type_constant.dart';
|
||||
import 'package:star_lock/talk/startChart/constant/protocol_flag_constant.dart';
|
||||
import 'package:star_lock/talk/startChart/entity/scp_message.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/gateway_reset.pb.dart';
|
||||
|
||||
class MessageCommand {
|
||||
/// 客户端去中继上线命令
|
||||
@ -71,6 +72,35 @@ class MessageCommand {
|
||||
return _hexToBytes(serializedBytesString);
|
||||
}
|
||||
|
||||
// 网关初始化
|
||||
static List<int> gatewayReset({
|
||||
required int gatewayId,
|
||||
required String FromPeerId,
|
||||
required String ToPeerId,
|
||||
required int time,
|
||||
}) {
|
||||
final gatewayResetReq = GatewayResetReq(
|
||||
iD: gatewayId,
|
||||
time: time,
|
||||
);
|
||||
final payloadLength = gatewayResetReq.writeToBuffer().length;
|
||||
ScpMessage message = ScpMessage(
|
||||
ProtocolFlag: ProtocolFlagConstant.scp01,
|
||||
MessageType: MessageTypeConstant.Req,
|
||||
MessageId: 1,
|
||||
SpTotal: 0,
|
||||
SpIndex: 0,
|
||||
FromPeerId: FromPeerId,
|
||||
ToPeerId: ToPeerId,
|
||||
Payload: gatewayResetReq,
|
||||
PayloadCRC: 55230,
|
||||
PayloadLength: payloadLength,
|
||||
PayloadType: PayloadTypeConstant.gatewayReset,
|
||||
);
|
||||
String serializedBytesString = message.serialize();
|
||||
return _hexToBytes(serializedBytesString);
|
||||
}
|
||||
|
||||
// 辅助方法:将16进制字符串转换为字节列表
|
||||
static List<int> _hexToBytes(String hex) {
|
||||
final bytes = <int>[];
|
||||
|
||||
@ -13,6 +13,46 @@ class PayloadTypeConstant {
|
||||
|
||||
// 登录成功
|
||||
static const int loginSuccessResponse = 110;
|
||||
|
||||
// 心跳响应成功
|
||||
static const int heartHeatSuccessResponse = 0;
|
||||
|
||||
// 网关初始化
|
||||
static const int gatewayReset = 1521;
|
||||
|
||||
// 网关转移
|
||||
static const int gatewayTransfer = 1523;
|
||||
|
||||
// 蓝牙透传
|
||||
static const int blePassthrough = 1531;
|
||||
|
||||
// 远程开锁
|
||||
static const int remoteUnlock = 1533;
|
||||
|
||||
// 对讲接听者转移
|
||||
static const int talkReceiverTransfer = 1620;
|
||||
|
||||
// 呼叫请求
|
||||
static const int callRequest = 1650;
|
||||
|
||||
// 委托推送
|
||||
static const int talkPush = 1652;
|
||||
|
||||
// 拒绝接听
|
||||
static const int talkReject = 1654;
|
||||
|
||||
// 同意接听
|
||||
static const int talkAccept = 1660;
|
||||
|
||||
// 呼叫保持
|
||||
static const int talkPing = 1662;
|
||||
|
||||
// 预期接收
|
||||
static const int talkExpect = 1664;
|
||||
|
||||
// 音视频数据
|
||||
static const int talkData = 1666;
|
||||
|
||||
// 通话中挂断
|
||||
static const int talkHangup = 1668;
|
||||
}
|
||||
|
||||
@ -5,6 +5,10 @@ import 'package:star_lock/app_settings/app_settings.dart';
|
||||
import 'package:star_lock/talk/startChart/constant/payload_type_constant.dart';
|
||||
import 'package:star_lock/talk/startChart/entity/heartbeat_response.dart';
|
||||
import 'package:star_lock/talk/startChart/entity/login_response.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/ble_message.pb.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/gateway_reset.pb.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/generic.pb.dart';
|
||||
import 'package:star_lock/talk/startChart/proto/remote_unlock.pb.dart';
|
||||
|
||||
class ScpMessage {
|
||||
ScpMessage({
|
||||
@ -134,7 +138,7 @@ class ScpMessage {
|
||||
}
|
||||
|
||||
// Payload (字符串,转换为字节)
|
||||
if (Payload != null) {
|
||||
if (Payload != null && Payload is String) {
|
||||
bytes.addAll(utf8.encode(Payload!));
|
||||
}
|
||||
|
||||
@ -286,6 +290,48 @@ class ScpMessage {
|
||||
// 回声测试
|
||||
String payload = utf8.decode(byte);
|
||||
return payload;
|
||||
case PayloadTypeConstant.gatewayReset:
|
||||
// 初始化网关
|
||||
final GatewayResetResp gatewayResetResp =
|
||||
GatewayResetResp.fromBuffer(byte);
|
||||
return gatewayResetResp;
|
||||
case PayloadTypeConstant.callRequest:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.talkAccept:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.gatewayTransfer:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.blePassthrough:
|
||||
final BleResp bleResp = BleResp.fromBuffer(byte);
|
||||
return bleResp;
|
||||
case PayloadTypeConstant.remoteUnlock:
|
||||
final RemoteUnlockResp remoteUnlockResp =
|
||||
RemoteUnlockResp.fromBuffer(byte);
|
||||
return remoteUnlockResp;
|
||||
case PayloadTypeConstant.talkReceiverTransfer:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.talkPush:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.talkReject:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.talkPing:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.talkExpect:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.talkData:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
case PayloadTypeConstant.talkHangup:
|
||||
final GenericResp genericResp = GenericResp.fromBuffer(byte);
|
||||
return genericResp;
|
||||
default:
|
||||
print('❌未知的payloadType类型,按照字符串解析');
|
||||
String payload = utf8.decode(byte);
|
||||
|
||||
@ -150,7 +150,7 @@ class StartChartManage {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
_log(text: '❌ Udp ----> $e');
|
||||
_log(text: '❌ Udp result data error ----> $e');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -216,6 +216,18 @@ class StartChartManage {
|
||||
await _sendMessage(message: message);
|
||||
}
|
||||
|
||||
// 发送网关初始化消息
|
||||
void sendGatewayResetMessage(
|
||||
{required String ToPeerId, required int gatewayId}) async {
|
||||
final message = MessageCommand.gatewayReset(
|
||||
ToPeerId: ToPeerId,
|
||||
FromPeerId: FromPeerId,
|
||||
gatewayId: gatewayId,
|
||||
time: DateTime.now().microsecond ~/ 1000,
|
||||
);
|
||||
await _sendMessage(message: message);
|
||||
}
|
||||
|
||||
// 重新上线
|
||||
Future<void> _reStartOnlineStartChartServer() async {
|
||||
if (_isOnlineStartChartServer) {
|
||||
@ -253,7 +265,7 @@ class StartChartManage {
|
||||
var result = await _udpSocket?.send(
|
||||
message, InternetAddress(remoteHost), remotePort);
|
||||
if (result != message.length) {
|
||||
AppLog.log('❌Udp ----> send data error $result ${message.length}');
|
||||
AppLog.log('❌Udp send data error----> $result ${message.length}');
|
||||
_udpSocket = null;
|
||||
}
|
||||
}
|
||||
@ -537,13 +549,6 @@ class StartChartManage {
|
||||
);
|
||||
}
|
||||
|
||||
/// 使用 RSA 私钥进行 PKCS#1 v1.5 签名
|
||||
Uint8List rsaSign(pc.RSAPrivateKey privateKey, List<int> data) {
|
||||
final signer = pc.RSASigner(pc.SHA256Digest(), '06052b24030203')
|
||||
..init(true, pc.PrivateKeyParameter<pc.RSAPrivateKey>(privateKey));
|
||||
return signer.generateSignature(Uint8List.fromList(data)).bytes;
|
||||
}
|
||||
|
||||
Future<String> getPublicKey() async {
|
||||
// 从缓存中获取星图注册节点信息
|
||||
final StarChartRegisterNodeEntity? starChartRegisterNodeInfo =
|
||||
@ -571,7 +576,70 @@ class StartChartManage {
|
||||
case PayloadTypeConstant.echoTest:
|
||||
_handleUdpEchoTestResultData(scpMessage);
|
||||
break;
|
||||
case PayloadTypeConstant.gatewayReset:
|
||||
// TODO: 处理网关初始化消息
|
||||
print('Handling Gateway Reset message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.callRequest:
|
||||
// TODO: 处理收到呼叫请求消息
|
||||
print('Handling Call Request message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkAccept:
|
||||
// TODO: 处理同意接听消息
|
||||
print('Handling Talk Accept message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.gatewayTransfer:
|
||||
// TODO: 处理网关转移消息
|
||||
print('Handling Gateway Transfer message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.blePassthrough:
|
||||
// TODO: 处理蓝牙透传消息
|
||||
print('Handling BLE Passthrough message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.remoteUnlock:
|
||||
// TODO: 处理远程开锁消息
|
||||
print('Handling Remote Unlock message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkReceiverTransfer:
|
||||
// TODO: 处理对讲接听者转移消息
|
||||
print('Handling Talk Receiver Transfer message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkPush:
|
||||
// TODO: 处理委托推送消息
|
||||
print('Handling Talk Push message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkReject:
|
||||
// TODO: 处理拒绝接听消息
|
||||
print('Handling Talk Reject message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkPing:
|
||||
// TODO: 处理呼叫保持消息
|
||||
print('Handling Talk Ping message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkExpect:
|
||||
// TODO: 处理预期接收消息
|
||||
print('Handling Talk Expect message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkData:
|
||||
// TODO: 处理音视频数据消息
|
||||
print('Handling Talk Data message.');
|
||||
break;
|
||||
|
||||
case PayloadTypeConstant.talkHangup:
|
||||
// TODO: 处理通话中挂断消息
|
||||
print('Handling Talk Hangup message.');
|
||||
break;
|
||||
default:
|
||||
_log(text: '❌未知的payloadType类型');
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user