update 电单车

This commit is contained in:
Guoqs
2024-09-14 16:07:59 +08:00
parent 83bd5f9071
commit e85e630282
4 changed files with 33 additions and 82 deletions

View File

@@ -2,10 +2,7 @@ package com.jsowell.pile.service.impl;
import com.jsowell.common.enums.ykc.PileChannelEntity;
import com.jsowell.common.protocol.SyncPromise;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.RandomUtil;
import com.jsowell.common.util.RpcUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.*;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82;
@@ -141,6 +138,8 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
private byte[] send(AbsEBikeMessage msg, long timeout, TimeUnit unit) throws Exception {
String pileSn = msg.getPhysicalId() + "";
byte[] messageBytes = msg.getMessageBytes();
String command = YKCUtils.frameType2Str(msg.getCommand());
// PileChannelEntity.output();
log.info("发送电单车send命令, pileSn:{}, messageBytes:{}", pileSn, BytesUtil.binary(messageBytes, 16));
// 获取桩的channel
@@ -153,7 +152,7 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
// 创造一个容器用于存放当前线程与rpcClient中的线程交互
SyncPromise syncPromise = new SyncPromise();
// 消息id = channelId + 帧类型(例如: "0x34")
String msgId = ctx.channel().id().toString() + "_" + msg.getCommand();
String msgId = ctx.channel().id().toString() + "_" + command;
log.info("同步获取响应数据-发送消息, msgId:{}", msgId);
RpcUtil.getSyncPromiseMap().put(msgId, syncPromise);
@@ -163,12 +162,12 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
// 检查操作的状态
if (channelFutureListener.isSuccess()) {
log.info("【电单车send结果===>成功】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), msg.getCommand(), BytesUtil.binary(messageBytes, 16));
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), command, BytesUtil.binary(messageBytes, 16));
} else {
// 如果发生错误则访问描述原因的Throwable
Throwable cause = channelFutureListener.cause();
log.info("【电单车send结果===>失败】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), msg.getCommand(), BytesUtil.binary(messageBytes, 16));
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), command, BytesUtil.binary(messageBytes, 16));
log.error("电单车send发送命令失败, pileSn:{}", pileSn, cause);
}
});
@@ -178,9 +177,9 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
if(rpcResponse == null) {
if(syncPromise.isTimeout()) {
// throw new TimeoutException("等待响应结果超时");
log.error("发送[{}]指令后, 等待响应结果超时", msg.getCommand());
log.error("发送[{}]指令后, 等待响应结果超时", command);
} else{
log.error("发送[{}]指令后, 发生其他异常", msg.getCommand());
log.error("发送[{}]指令后, 发生其他异常", command);
}
}
// 移除容器

View File

@@ -44,9 +44,6 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
@Autowired
private PileModelInfoService pileModelInfoService;
@Autowired
private PileBasicInfoService pileBasicInfoService;
@Autowired
private PileStationInfoService pileStationInfoService;
@@ -64,75 +61,6 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
YKCUtils.frameType2Str(YKCFrameTypeCode.RESERVATION_CHARGING_SETUP_CODE.getBytes())
);
/**
* 发送push消息
*
* @param msg
* @param pileSn
* @param frameTypeCode
* @return
*/
// public boolean push(byte[] msg, String pileSn, Enum<YKCFrameTypeCode> frameTypeCode) {
// // 通过桩编号获取channel
// ChannelHandlerContext ctx = PileChannelEntity.getChannelByPileSn(pileSn);
// String value = ((YKCFrameTypeCode) frameTypeCode).getValue();
// if (Objects.isNull(ctx)) {
// log.error("push命令[{}]失败, 桩号:{}无法获取到长连接, 请检查充电桩连接状态!", value, pileSn);
// return false;
// }
// /*
// 拼接报文
// */
// // 起始标志
// byte[] head = new byte[]{0x68};
//
// // 序列号域
// byte[] serialNumber = new byte[]{0x00, 0x00};
//
// // 加密标志
// byte[] encryptFlag = new byte[]{0x00};
//
// // 帧类型标志
// byte[] frameType = new byte[]{(byte) ((YKCFrameTypeCode) frameTypeCode).getCode()};
//
// // 序列号域+加密标志+帧类型标志+消息体
// byte[] temp = Bytes.concat(serialNumber, encryptFlag, frameType, msg);
//
// // 数据长度
// byte[] length = BytesUtil.intToBytes(temp.length, 1);
//
// // 帧校验域
// byte[] crc = BytesUtil.intToBytes(CRC16Util.calcCrc16(temp));
//
// // 返回报文
// byte[] writeMsg = Bytes.concat(head, length, temp, crc);
//
// // 返回完整的报文 string类型
// String wholeMsg = BytesUtil.binary(writeMsg, 16);
// ByteBuf byteBuf = ctx.channel().alloc().buffer().writeBytes(writeMsg);
// ChannelFuture channelFuture = ctx.channel().writeAndFlush(byteBuf);
// channelFuture.addListener((ChannelFutureListener) channelFutureListener -> {
// // 检查操作的状态
// if (channelFutureListener.isSuccess()) {
// log.info("【push结果===>成功】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
// pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), value, wholeMsg);
// } else {
// // 如果发生错误则访问描述原因的Throwable
// Throwable cause = channelFutureListener.cause();
// log.info("【push结果===>失败】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
// pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), value, wholeMsg);
// log.error("push发送命令失败, pileSn:{}", pileSn, cause);
// }
// });
//
// // 保存报文
// String frameTypeStr = YKCUtils.frameType2Str(((YKCFrameTypeCode) frameTypeCode).getBytes());
// if (frameTypeList.contains(frameTypeStr)) {
// pileMsgRecordService.save(pileSn, null, frameTypeStr, null, wholeMsg);
// }
// return true;
// }
public byte[] send(byte[] msg, String pileSn, Enum<YKCFrameTypeCode> frameTypeCode) throws Exception {
return this.send(msg, pileSn, frameTypeCode, 5, TimeUnit.SECONDS);
}