Commit 23807629 by tiger

统一桩名称为pileId

1 parent 0c08c849
Showing 43 changed files with 149 additions and 116 deletions
package cn.com.glsx.charging.modules.gbt.ocpp16;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.client.TcpClient;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.LoginReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.LoginReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq;
import cn.com.glsx.charging.util.ByteUtils;
public class ClientMain {
......@@ -44,33 +41,33 @@ public class ClientMain {
Thread.sleep(3000);
// LoginReq req = new LoginReq();
// req.setData(new LoginReqData());
// req.getData().setPointId(Ocpp16Helper.strToBcd("55031412782305", req.getData().getPointId()));
// req.getData().setPointType((byte) 0);
// req.getData().setGunCount((byte) 2);
// req.getData().setSoftVersion(Ocpp16Helper.strToBcd("v4.1.50", req.getData().getSoftVersion()));
// req.getData().setProtocolVersion((byte) 10);
//
// client.sendSync(req);
//000100343201020000000011151116155535026032010200000001011000000573000000F1FFFF5400000000F0860100
// LoginReq req = new LoginReq();
// req.setData(new LoginReqData());
// req.getData().setPointId(Ocpp16Helper.strToBcd("55031412782305", req.getData().getPointId()));
// req.getData().setPointType((byte) 0);
// req.getData().setGunCount((byte) 2);
// req.getData().setSoftVersion(Ocpp16Helper.strToBcd("v4.1.50", req.getData().getSoftVersion()));
// req.getData().setProtocolVersion((byte) 10);
//
// client.sendSync(req);
// 000100343201020000000011151116155535026032010200000001011000000573000000F1FFFF5400000000F0860100
StartMachineReq req = new StartMachineReq();
StartMachineReqData data = new StartMachineReqData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350260", data.getTransactionSerialNumber()));
data.setPileNumber(Ocpp16Helper.strToBcd("32010200000001",data.getPileNumber()));
data.setPileId(Ocpp16Helper.strToBcd("32010200000001", data.getPileId()));
data.setGunNumber((byte) 1);
data.setLogicalCardNumber(Ocpp16Helper.strToBcd("1000000573",data.getLogicalCardNumber()));
data.setPhysicalCardNumber(Ocpp16Helper.strToBcd("D14B0A54",data.getPhysicalCardNumber()));
data.setAccountBalance(Ocpp16Helper.strToBcd("00000064",data.getAccountBalance()));
// Ocpp16Helper.binToBytes()
data.setLogicalCardNumber(Ocpp16Helper.strToBcd("1000000573", data.getLogicalCardNumber()));
data.setPhysicalCardNumber(Ocpp16Helper.strToBcd("D14B0A54", data.getPhysicalCardNumber()));
data.setAccountBalance(Ocpp16Helper.strToBcd("00000064", data.getAccountBalance()));
// Ocpp16Helper.binToBytes()
req.setData(data);
client.sendSync(req);
System.out.println("=========================");
// while (true) {
// Thread.sleep(300);
// client.sendSync(req);
// }
// while (true) {
// Thread.sleep(300);
// client.sendSync(req);
// }
// 定期心跳
......
......@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonIgnore;
import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import cn.com.glsx.charging.util.JacksonUtils;
/**
......@@ -21,4 +22,13 @@ public abstract class TcpData {
public String toString() {
return JacksonUtils.toJson(this);
}
public String getPileIdStr() {
byte[] pointId = getPileId();
return Ocpp16Helper.bcdToStr(pointId);
}
public byte[] getPileId() {
return new byte[7];
}
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.ModelSetRspHandler;
import java.util.Map;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req.TransactionRecordsReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.resp.TransactionRecordsRespHandler;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Maps;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.HeartbeatReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.LoginReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.ModelChargingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.ModelSetRspHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.ModelValReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.ParamSettingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.ParamSettingRspHandler;
......@@ -20,6 +18,8 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.StartMachineReqHandle
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.StartMachineRespHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.TimeSettingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.TimeSettingRspHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.TransactionRecordsReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.TransactionRecordsRespHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.UploadRealTimeReqHandler;
import lombok.AllArgsConstructor;
import lombok.Getter;
......
......@@ -99,8 +99,13 @@ public class TcpClient {
@SuppressWarnings({ "rawtypes" })
public <T extends TcpBase> void sendSync(T data) {
String ip = getIp(future.channel());
// TODO seq字段处理
data.setSeq(Ocpp16Helper.generateSeq(ip));
// seq字段处理
String seqKey = ip;
if (data.getData() != null) {
seqKey = data.getData().getPileIdStr();
}
data.setSeq(Ocpp16Helper.generateSeq(seqKey));
byte[] bs = Ocpp16Helper.build(data);
......
......@@ -19,7 +19,7 @@ public class HeartbeatReqData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 枪号 BCD 码 1
......
......@@ -19,7 +19,7 @@ public class HeartbeatRspData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 枪号 BCD 码 1
......
......@@ -21,7 +21,7 @@ public class LoginReqData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 0 表示直流桩,1 表示交流桩
......
......@@ -18,7 +18,7 @@ public class LoginRspData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 登陆结果: 0x00:登陆成功 0x01:登陆失败
......
......@@ -18,7 +18,7 @@ public class ModelChargingReqData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
}
......@@ -24,7 +24,7 @@ public class ModelChargingRspData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 计费模型编号:固定值:01 00
......
......@@ -20,7 +20,7 @@ public class ModelSetReqData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 计费模型编号:固定值:01 00
......
......@@ -19,7 +19,7 @@ public class ModelSetRspData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 0x00 失败 0x01 成功
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
......@@ -20,7 +19,7 @@ public class ModelValReqData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 计费模型编号:首次连接到平台时置零
......
......@@ -19,7 +19,7 @@ public class ModelValRspData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 计费模型编号
......
......@@ -21,7 +21,7 @@ public class ParamSettingReqData extends TcpData {
* 桩编号
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 是否允许工作
......
......@@ -21,7 +21,7 @@ public class ParamSettingRspData extends TcpData {
* 桩编号
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* 设置结果
......
......@@ -37,7 +37,7 @@ public class RealTimeReqData extends TcpData {
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
private byte[] pileId = new byte[7];
/**
* 枪号
......
......@@ -23,7 +23,7 @@ public class ShutdownMachineReqData extends TcpData {
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
private byte[] pileId = new byte[7];
/**
* 枪号
......
......@@ -23,7 +23,7 @@ public class ShutdownMachineRespData extends TcpData {
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
private byte[] pileId = new byte[7];
/**
* 枪号
......
......@@ -32,7 +32,7 @@ public class StartMachineReqData extends TcpData {
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
private byte[] pileId = new byte[7];
/**
* 枪号
......
......@@ -31,7 +31,7 @@ public class StartMachineRspData extends TcpData {
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
private byte[] pileId = new byte[7];
/**
* 枪号
......
......@@ -18,7 +18,7 @@ public class TimeNotifyData extends TcpData {
/**
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* BIN码,当前时间,CP56Time2a 格式
......
......@@ -20,7 +20,7 @@ public class TimeSettingReqData extends TcpData {
* 桩编号
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* BIN码,当前时间,CP56Time2a 格式
......
......@@ -21,7 +21,7 @@ public class TimeSettingRspData extends TcpData {
* 桩编号
* 充电桩id: BCD 码 ,不足 7 位补 0
*/
private byte[] pointId = new byte[7];
private byte[] pileId = new byte[7];
/**
* BIN码,当前时间,CP56Time2a 格式
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive;
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData;
import lombok.Getter;
......@@ -43,7 +43,7 @@ public class TransactionRecordsReqData extends TcpData {
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
private byte[] pileId = new byte[7];
/**
* 参数名称:枪号
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive;
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData;
import lombok.Getter;
......
......@@ -14,8 +14,8 @@ public class HeartbeatReqHandler implements TcpHandler<HeartbeatReq, HeartbeatRs
HeartbeatRsp rsp = new HeartbeatRsp();
HeartbeatRspData data = new HeartbeatRspData();
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPointId()));
data.setPointId(req.getData().getPointId());
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPileId()));
data.setPileId(req.getData().getPileId());
data.setGunNo(req.getData().getGunNo());
data.setResult((byte) 0);
......
......@@ -12,8 +12,8 @@ public class LoginReqHandler implements TcpHandler<LoginReq, LoginRsp> {
@Override
public LoginRsp handle(Channel channel, LoginReq req) {
LoginRspData data = new LoginRspData();
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPointId()));
data.setPointId(req.getData().getPointId());
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPileId()));
data.setPileId(req.getData().getPileId());
data.setResult((byte) 0);
LoginRsp trsp = new LoginRsp();
......
......@@ -20,8 +20,8 @@ public class ModelChargingReqHandler implements TcpHandler<ModelChargingReq, Mod
ModelChargingRsp rsp = new ModelChargingRsp();
ModelChargingRspData data = new ModelChargingRspData();
// 查业务系统
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPointId()));
data.setPointId(req.getData().getPointId());
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPileId()));
data.setPileId(req.getData().getPileId());
data.setModelCode((byte) 0100);
byte[] byteArray = new byte[]{(byte) 0x9C, 0x40, 0x00, 0x00};
data.setValleyDreRate(byteArray);
......
......@@ -19,7 +19,7 @@ public class ModelSetRspHandler implements TcpHandler<ModelSetRsp, ModelSetRsp>
public ModelSetRsp handle(Channel channel, ModelSetRsp req) {
//
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPointId()));
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPileId()));
log.info("设置的结果{}", req.getData().getSetResult());
return null;
......
......@@ -18,8 +18,8 @@ public class ModelValReqHandler implements TcpHandler<ModelValReq, ModelValRsp>
ModelValRsp rsp = new ModelValRsp();
ModelValRspData data = new ModelValRspData();
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPointId()));
data.setPointId(req.getData().getPointId());
log.info("请求验证的桩号{}", Ocpp16Helper.bcdToStr(req.getData().getPileId()));
data.setPileId(req.getData().getPileId());
log.info("请求验证的计费模型编号{}", Ocpp16Helper.bcdToStr(req.getData().getModelCode()));
data.setModelCode(req.getData().getModelCode());
data.setValidationRes((byte) 0x00);
......
......@@ -22,12 +22,12 @@ public class ParamSettingReqHandler implements TcpHandler<ParamSettingReq, Param
public ParamSettingRsp handle(Channel channel, ParamSettingReq paramSettingReq) {
ParamSettingReqData data = paramSettingReq.getData();
log.info("充电桩工作参数设置 pointId {}", Ocpp16Helper.bcdToStr(data.getPointId()));
log.info("充电桩工作参数设置 pointId {}", Ocpp16Helper.bcdToStr(data.getPileId()));
log.info("authStatus {}", data.getAuthStatus());
log.info("maxPower {}", data.getMaxPower());
ParamSettingRspData resultData = new ParamSettingRspData();
resultData.setPointId(data.getPointId());
resultData.setPileId(data.getPileId());
resultData.setResult((byte) 1);
ParamSettingRsp rsp = new ParamSettingRsp();
......
......@@ -22,11 +22,11 @@ public class ParamSettingRspHandler implements TcpHandler<ParamSettingRsp, Param
public ParamSettingRsp handle(Channel channel, ParamSettingRsp paramSettingRsp) {
ParamSettingRspData data = paramSettingRsp.getData();
log.info("充电桩工作参数设置应答 pointId {}", Ocpp16Helper.bcdToStr(data.getPointId()));
log.info("充电桩工作参数设置应答 pointId {}", Ocpp16Helper.bcdToStr(data.getPileId()));
log.info("result {}", data.getResult());
if (data.getResult() != 1) {
log.info("充电桩 {} 工作参数设置 失败!", Ocpp16Helper.bcdToStr(data.getPointId()));
log.info("充电桩 {} 工作参数设置 失败!", Ocpp16Helper.bcdToStr(data.getPileId()));
}
return null;
}
......
......@@ -20,12 +20,12 @@ public class ShutdownMachineReqHandler implements TcpHandler<ShutdownMachineReq,
@Override
public ShutdownMachineResp handle(Channel channel, ShutdownMachineReq shutdownMachineReq) {
/**请求日志打印*/
log.info("桩编号:{}", Ocpp16Helper.bcdToStr(shutdownMachineReq.getData().getPileNumber()));
log.info("桩编号:{}", Ocpp16Helper.bcdToStr(shutdownMachineReq.getData().getPileId()));
log.info("枪号:{}", shutdownMachineReq.getData().getGunNumber());
/**请求日志打印*/
ShutdownMachineResp resp = new ShutdownMachineResp();
ShutdownMachineRespData data = new ShutdownMachineRespData();
data.setPileNumber(Ocpp16Helper.strToBcd("32010200000001", data.getPileNumber()));
data.setPileId(Ocpp16Helper.strToBcd("32010200000001", data.getPileId()));
data.setGunNumber((byte) 1);
data.setShutdownResult((byte) 1);
data.setFailureReason((byte) 0);
......
......@@ -17,7 +17,7 @@ public class ShutdownMachineRespHandler implements TcpHandler<ShutdownMachineRes
@Override
public ShutdownMachineResp handle(Channel channel, ShutdownMachineResp shutdownMachineResp) {
ShutdownMachineRespData data = shutdownMachineResp.getData();
log.info("桩编号:{}", Ocpp16Helper.bcdToStr(data.getPileNumber()));
log.info("桩编号:{}", Ocpp16Helper.bcdToStr(data.getPileId()));
log.info("枪号:{}", data.getGunNumber());
log.info("停止结果:{}", data.getShutdownResult());
log.info("失败原因:{}", data.getFailureReason());
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler;
import java.math.BigDecimal;
import java.math.RoundingMode;
import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineRspData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineResp;
import cn.com.glsx.charging.util.ByteUtils;
import io.netty.channel.Channel;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* @Description 远程启动充电请求处理类
* @Author yelq
......@@ -25,7 +24,7 @@ public class StartMachineReqHandler implements TcpHandler<StartMachineReq, Start
StartMachineReqData reqData = startMachineReq.getData();
String transactionSerialNumber = Ocpp16Helper.bcdToStr(reqData.getTransactionSerialNumber());
System.out.println("交易流水号"+transactionSerialNumber);
String pileNumber = Ocpp16Helper.bcdToStr(reqData.getPileNumber());
String pileNumber = Ocpp16Helper.bcdToStr(reqData.getPileId());
System.out.println("桩编号"+pileNumber);
byte gunNumber = reqData.getGunNumber();
System.out.println("枪号"+gunNumber);
......@@ -42,7 +41,7 @@ public class StartMachineReqHandler implements TcpHandler<StartMachineReq, Start
StartMachineResp resp = new StartMachineResp();
StartMachineRspData data = new StartMachineRspData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350260", data.getTransactionSerialNumber()));
data.setPileNumber(Ocpp16Helper.strToBcd("32010200000001",data.getPileNumber()));
data.setPileId(Ocpp16Helper.strToBcd("32010200000001", data.getPileId()));
data.setGunNumber((byte) 1);
data.setFailureReason((byte) 0);
data.setStartResult((byte) 1);
......
......@@ -24,10 +24,10 @@ public class TimeSettingReqHandler implements TcpHandler<TimeSettingReq, TimeSet
public TimeSettingRsp handle(Channel channel, TimeSettingReq timeSettingReq) {
TimeSettingReqData reqData = timeSettingReq.getData();
byte[] time = reqData.getTime();
byte[] pointId = reqData.getPointId();
byte[] pointId = reqData.getPileId();
TimeSettingRspData data = new TimeSettingRspData();
data.setPointId(pointId);
data.setPileId(pointId);
data.setTime(time);
String hexStr = HexUtil.encodeHexStr(time);
......
......@@ -22,7 +22,7 @@ public class TimeSettingRspHandler implements TcpHandler<TimeSettingRsp, TimeSet
@Override
public TimeSettingRsp handle(Channel channel, TimeSettingRsp timeSettingRsp) {
TimeSettingRspData data = timeSettingRsp.getData();
log.info("对时设置响应 pointId {} time {}", Ocpp16Helper.bcdToStr(data.getPointId()), ByteUtils.parseCp56Time2aStr(data.getTime()) /*DateUtils.datetimeToStr(ByteUtils.parseCp56Time2a(timeSettingRsp.getData().getTime()))*/);
log.info("对时设置响应 pointId {} time {}", Ocpp16Helper.bcdToStr(data.getPileId()), ByteUtils.parseCp56Time2aStr(data.getTime()) /*DateUtils.datetimeToStr(ByteUtils.parseCp56Time2a(timeSettingRsp.getData().getTime()))*/);
return null;
}
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req;
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler;
import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsRespData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.TransactionRecordsReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.TransactionRecordsResp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsRespData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsResp;
import cn.com.glsx.charging.util.ByteUtils;
import io.netty.channel.Channel;
/**
* @Description 运营平台接收到结算账单上传后,都需回复此确认信息。若桩未收到回复帧,则 5 分钟后继续
* 上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
* 意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* 上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
* 意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* @Author yelq
* @Date 2023/11/7-17:37
* @Version 1.0
*/
public class TransactionRecordsReqHandler implements TcpHandler<TransactionRecordsReq, TransactionRecordsResp> {
@Override
public TransactionRecordsResp handle(Channel channel, TransactionRecordsReq transactionRecordsReq) {
TransactionRecordsReqData reqData = transactionRecordsReq.getData();
/**解析参数日志打印*/
log.info("交易流水号:{}",Ocpp16Helper.bcdToStr(reqData.getTransactionSerialNumber()));
String pileNumber = Ocpp16Helper.bcdToStr(reqData.getPileNumber());
log.info("桩编号:{}",pileNumber);
log.info("开始时间:{}", ByteUtils.parseCp56Time2aStr(reqData.getStartTime()));
log.info("结束时间:{}",ByteUtils.parseCp56Time2aStr(reqData.getEndTime()));
log.info("电动汽车唯一标识:{}",Ocpp16Helper.bcdToStr(reqData.getVehicleIdentifier()));
log.info("峰单价:{}",Ocpp16Helper.bcdToStr(reqData.getTopUnitPrice()));
/**解析参数日志打印*/
TransactionRecordsResp resp = new TransactionRecordsResp();
TransactionRecordsRespData data = new TransactionRecordsRespData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("55031412782305012018061910262392",data.getTransactionSerialNumber()));
data.setConfirmResult((byte) 0);
resp.setData(data);
return resp;
}
@Override
public TransactionRecordsResp handle(Channel channel, TransactionRecordsReq transactionRecordsReq) {
TransactionRecordsReqData reqData = transactionRecordsReq.getData();
/** 解析参数日志打印 */
log.info("交易流水号:{}", Ocpp16Helper.bcdToStr(reqData.getTransactionSerialNumber()));
String pileNumber = Ocpp16Helper.bcdToStr(reqData.getPileId());
log.info("桩编号:{}", pileNumber);
log.info("开始时间:{}", ByteUtils.parseCp56Time2aStr(reqData.getStartTime()));
log.info("结束时间:{}", ByteUtils.parseCp56Time2aStr(reqData.getEndTime()));
log.info("电动汽车唯一标识:{}", Ocpp16Helper.bcdToStr(reqData.getVehicleIdentifier()));
log.info("峰单价:{}", Ocpp16Helper.bcdToStr(reqData.getTopUnitPrice()));
/** 解析参数日志打印 */
TransactionRecordsResp resp = new TransactionRecordsResp();
TransactionRecordsRespData data = new TransactionRecordsRespData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("55031412782305012018061910262392", data.getTransactionSerialNumber()));
data.setConfirmResult((byte) 0);
resp.setData(data);
return resp;
}
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.resp;
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.TransactionRecordsResp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsResp;
import io.netty.channel.Channel;
/**
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req;
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpMapper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsReqData;
/**
* @Description 交易记录上报
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp;
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpMapper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsRespData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsRespData;
/**
* @Description 交易记录确认
......
......@@ -3,6 +3,9 @@ package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server;
import java.net.InetSocketAddress;
import java.util.concurrent.ScheduledFuture;
import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpBase;
import cn.com.glsx.charging.util.ByteUtils;
import cn.com.glsx.charging.util.Task;
import cn.com.glsx.charging.util.TaskExecutor;
import io.netty.bootstrap.ServerBootstrap;
......@@ -106,14 +109,34 @@ public class TcpServer {
log.info("【{}】关闭TCP服务器!!!!!!", port);
}
public void sendSync(String json) {
try {
future.channel().writeAndFlush(json);
@SuppressWarnings({ "rawtypes" })
public <T extends TcpBase> void sendSync(T data) {
String ip = getIp(future.channel());
// seq字段处理
String seqKey = ip;
if (data.getData() != null) {
seqKey = data.getData().getPileIdStr();
}
data.setSeq(Ocpp16Helper.generateSeq(seqKey));
byte[] bs = Ocpp16Helper.build(data);
sendSync(bs);
String ip = getIp(future.channel());
log.info("【{}】send: {}", ip, json);
log.info("【{}】【{}】send1: {} ", ip, data.getClass().getSimpleName(), ByteUtils.toHex(bs));
log.info("【{}】【{}】send2: {} ", ip, data.getClass().getSimpleName(), data);
}
private void sendSync(byte[] bytes) {
try {
if (future == null || future.channel() == null) {
log.info("future null ...");
return;
}
future.channel().writeAndFlush(bytes);
} catch (Exception e) {
log.error(json, e);
log.error("" + bytes, e);
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!