新增 0x25报文数据存入缓存方法

This commit is contained in:
Lemon
2024-12-11 09:15:31 +08:00
parent 19f8aeb07a
commit 05cf609297
6 changed files with 191 additions and 114 deletions

View File

@@ -1,12 +1,15 @@
package com.jsowell.netty.handler.yunkuaichong;
import com.jsowell.common.core.domain.ykc.BMSChargeInfoData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.service.PileBasicInfoService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -19,6 +22,10 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class BMSInformationHandler extends AbstractYkcHandler {
@Autowired
private PileBasicInfoService pileBasicInfoService;
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.CHARGING_PROCESS_BMS_INFORMATION_CODE.getBytes());
@Override
@@ -26,113 +33,6 @@ public class BMSInformationHandler extends AbstractYkcHandler {
YKCOperateFactory.register(type, this);
}
public static void main(String[] args) {
String msg = "8823000000104502241209160539911188230000001045027c45043e080010";
byte[] msgBody = BytesUtil.str2Bcd(msg);
int startIndex = 0;
int length = 16;
// 交易流水号
byte[] serialNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(serialNumByteArr);
// 桩编码
startIndex += length;
length = 7;
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 枪号
startIndex += length;
length = 1;
byte[] pileConnectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(pileConnectorNumByteArr);
// BMS 最高单体动力蓄电池电压所在编号 1/位, 1 偏移量; 数据范围: 1~256
startIndex += length;
byte[] BMSMaxVoltageNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsMaxVoltageNum = String.valueOf(BytesUtil.bytesToIntLittle(BMSMaxVoltageNumByteArr));
// BMS 最高动力蓄电池温度 1ºC/位, -50 ºC 偏移量;数据范 围: -50 ºC ~+200 ºC
startIndex += length;
byte[] BMSMaxBatteryTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsMaxBatteryTemperature = String.valueOf(BytesUtil.bytesToIntLittle(BMSMaxBatteryTemperatureByteArr) - 50);
// 最高温度检测点编号 1/位, 1 偏移量; 数据范围: 1~128
startIndex += length;
byte[] maxTemperatureDetectionNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String maxTemperatureDetectionNum = String.valueOf(BytesUtil.bytesToIntLittle(maxTemperatureDetectionNumByteArr) + 1);
// 最低动力蓄电池温度 1ºC/位, -50 ºC 偏移量;数据范 围: -50 ºC ~+200 ºC
startIndex += length;
byte[] minBatteryTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String minBatteryTemperature = String.valueOf(BytesUtil.bytesToIntLittle(minBatteryTemperatureByteArr) - 50);
// 最低动力蓄电池温度检测点编号 1/位, 1 偏移量; 数据范围: 1~128
startIndex += length;
byte[] minTemperatureDetectionNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String minTemperatureDetectionNum = String.valueOf(BytesUtil.bytesToIntLittle(minTemperatureDetectionNumByteArr) + 1);
/**
* BMS 单体动力蓄电池电压过高 /过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
startIndex += length;
length = 2;
byte[] singleBMSVoltageStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String singleBMSVoltageStatus = BytesUtil.bcd2Str(singleBMSVoltageStatusByteArr);
/**
* BMS 整车动力蓄电池荷电状态 SOC 过高/过低 (<00> =正常 ; <01> =过高 ; <10> =过低)
*/
startIndex += length;
byte[] carBMSSocStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String carBMSSocStatus = BytesUtil.bcd2Str(carBMSSocStatusByteArr);
/**
* BMS 动力蓄电池充电过电流 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryChargeCurrentStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryChargeCurrentStatus = BytesUtil.bcd2Str(BMSBatteryChargeCurrentStatusByteArr);
/**
* BMS 动力蓄电池温度过高 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryTemperatureByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryTemperature = BytesUtil.bcd2Str(BMSBatteryTemperatureByteArr);
/**
* BMS 动力蓄电池绝缘状态 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryInsulationStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryInsulationStatus = BytesUtil.bcd2Str(BMSBatteryInsulationStatusByteArr);
/**
* BMS 动力蓄电池组输出连接器连接状态 (<00> =正常 ; <01> =过流 ; <10> =不可信状态)
*/
startIndex += length;
byte[] BMSBatteryOutputStatusByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String bmsBatteryOutputStatus = BytesUtil.bcd2Str(BMSBatteryOutputStatusByteArr);
/**
* 充电禁止 (<00> =禁止; <01> =允许)
*/
startIndex += length;
byte[] chargeProhibitByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String chargeProhibit = BytesUtil.bcd2Str(chargeProhibitByteArr);
/**
* 预留位
*/
startIndex += length;
byte[] noMeanPositionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
}
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext channel) {
// log.info("[===充电过程 BMS 信息===] param:{}, channel:{}", JSON.toJSONString(ykcDataProtocol), channel.toString());
@@ -242,6 +142,27 @@ public class BMSInformationHandler extends AbstractYkcHandler {
startIndex += length;
byte[] noMeanPositionByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
// 存入缓存缓存时间3天
BMSChargeInfoData data = BMSChargeInfoData.builder()
.transactionCode(transactionCode)
.pileSn(pileSn)
.connectorCode(connectorCode)
.bmsMaxVoltageNum(bmsMaxVoltageNum)
.bmsMaxBatteryTemperature(bmsMaxBatteryTemperature)
.maxTemperatureDetectionNum(maxTemperatureDetectionNum)
.minBatteryTemperature(minBatteryTemperature)
.minTemperatureDetectionNum(minTemperatureDetectionNum)
.singleBMSVoltageStatus(singleBMSVoltageStatus)
.carBMSSocStatus(carBMSSocStatus)
.bmsBatteryChargeCurrentStatus(bmsBatteryChargeCurrentStatus)
.bmsBatteryTemperature(bmsBatteryTemperature)
.bmsBatteryInsulationStatus(bmsBatteryInsulationStatus)
.bmsBatteryOutputStatus(bmsBatteryOutputStatus)
.chargeProhibit(chargeProhibit)
.build();
pileBasicInfoService.saveBMSChargeInfo2Redis(data);
return null;
}