Commit 46365e7a by 叶立庆

[+]测试用例完善、协议转换完善

1 parent b6c62fce
...@@ -25,10 +25,10 @@ public class ShutdownMachineReqHandler implements TcpHandler<ShutdownMachineReq, ...@@ -25,10 +25,10 @@ public class ShutdownMachineReqHandler implements TcpHandler<ShutdownMachineReq,
/**请求日志打印*/ /**请求日志打印*/
ShutdownMachineResp resp = new ShutdownMachineResp(); ShutdownMachineResp resp = new ShutdownMachineResp();
ShutdownMachineRespData data = new ShutdownMachineRespData(); ShutdownMachineRespData data = new ShutdownMachineRespData();
data.setPileId(Ocpp16Helper.strToBcd("32010200000001", data.getPileId())); data.setPileId(shutdownMachineReq.getData().getPileId());
data.setGunNumber((byte) 1); data.setGunNumber(shutdownMachineReq.getData().getGunNumber());
data.setShutdownResult((byte) 1); data.setShutdownResult((byte) 1);
data.setFailureReason((byte) 0); data.setFailureReason((byte) 0x00);
resp.setData(data); resp.setData(data);
return resp; return resp;
} }
......
...@@ -9,6 +9,7 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData; ...@@ -9,6 +9,7 @@ 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.data.StartMachineRspData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq; 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.modules.gbt.ocpp16.tcp.protocol.StartMachineResp;
import cn.com.glsx.charging.util.ByteUtils;
import io.netty.channel.Channel; import io.netty.channel.Channel;
/** /**
...@@ -23,28 +24,26 @@ public class StartMachineReqHandler implements TcpHandler<StartMachineReq, Start ...@@ -23,28 +24,26 @@ public class StartMachineReqHandler implements TcpHandler<StartMachineReq, Start
/**请求参数打印*/ /**请求参数打印*/
StartMachineReqData reqData = startMachineReq.getData(); StartMachineReqData reqData = startMachineReq.getData();
String transactionSerialNumber = Ocpp16Helper.bcdToStr(reqData.getTransactionSerialNumber()); String transactionSerialNumber = Ocpp16Helper.bcdToStr(reqData.getTransactionSerialNumber());
System.out.println("交易流水号"+transactionSerialNumber); log.info("交易流水号:{}",transactionSerialNumber);
String pileNumber = Ocpp16Helper.bcdToStr(reqData.getPileId()); String pileId = Ocpp16Helper.bcdToStr(reqData.getPileId());
System.out.println("桩编号"+pileNumber); log.info("桩编号:{}",pileId);
byte gunNumber = reqData.getGunNumber(); byte gunNumber = reqData.getGunNumber();
System.out.println("枪号"+gunNumber); log.info("枪号:{}",gunNumber);
String logicalCardNumber = Ocpp16Helper.bcdToStr(reqData.getLogicalCardNumber()); String logicalCardNumber = Ocpp16Helper.bcdToStr(reqData.getLogicalCardNumber());
System.out.println("逻辑卡号"+logicalCardNumber); log.info("逻辑卡号:{}",logicalCardNumber);
String physicalCardNumber = Ocpp16Helper.bcdToStr(reqData.getPhysicalCardNumber()); String physicalCardNumber = ByteUtils.toHex(reqData.getPhysicalCardNumber());
System.out.println("物理卡号"+physicalCardNumber); log.info("物理卡号:{}",physicalCardNumber);
String accountBalance = Ocpp16Helper.bcdToStr(reqData.getAccountBalance()); String accountBalance = ByteUtils.toHex(reqData.getAccountBalance());
long aLong = Ocpp16Helper.binaryStringToLong(Ocpp16Helper.hexToBinaryString(accountBalance)); log.info("账户余额:{}",accountBalance);
BigDecimal divide = new BigDecimal(String.valueOf(aLong)).divide(new BigDecimal("100"), 2, RoundingMode.HALF_DOWN);
System.out.println("账户余额"+divide);
// TODO: 2023/11/7 业务代码 // TODO: 2023/11/7 业务代码
/**请求参数打印*/ /**请求参数打印*/
StartMachineResp resp = new StartMachineResp(); StartMachineResp resp = new StartMachineResp();
StartMachineRspData data = new StartMachineRspData(); StartMachineRspData data = new StartMachineRspData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350260", data.getTransactionSerialNumber())); data.setTransactionSerialNumber(Ocpp16Helper.strToBcd(transactionSerialNumber, data.getTransactionSerialNumber()));
data.setPileId(Ocpp16Helper.strToBcd("32010200000001", data.getPileId())); data.setPileId(Ocpp16Helper.strToBcd(pileId, data.getPileId()));
data.setGunNumber((byte) 1); data.setGunNumber((byte) 1);
data.setFailureReason((byte) 0);
data.setStartResult((byte) 1); data.setStartResult((byte) 1);
data.setFailureReason((byte) 0x00);
resp.setData(data); resp.setData(data);
return resp; return resp;
} }
......
...@@ -20,22 +20,46 @@ import io.netty.channel.Channel; ...@@ -20,22 +20,46 @@ import io.netty.channel.Channel;
public class TransactionRecordsReqHandler implements TcpHandler<TransactionRecordsReq, TransactionRecordsResp> { public class TransactionRecordsReqHandler implements TcpHandler<TransactionRecordsReq, TransactionRecordsResp> {
@Override @Override
public TransactionRecordsResp handle(Channel channel, TransactionRecordsReq transactionRecordsReq) { public TransactionRecordsResp handle(Channel channel, TransactionRecordsReq transactionRecordsReq) {
TransactionRecordsReqData reqData = transactionRecordsReq.getData(); TransactionRecordsReqData data = transactionRecordsReq.getData();
/** 解析参数日志打印 */ /** 解析参数日志打印 */
log.info("交易流水号:{}", Ocpp16Helper.bcdToStr(reqData.getTransactionSerialNumber())); log.info("交易流水号:{}", Ocpp16Helper.bcdToStr(data.getTransactionSerialNumber()));
String pileNumber = Ocpp16Helper.bcdToStr(reqData.getPileId()); log.info("桩编号:{}", Ocpp16Helper.bcdToStr(data.getPileId()));
log.info("桩编号:{}", pileNumber); log.info("枪号:{}", data.getGunNumber());
log.info("开始时间:{}", ByteUtils.parseCp56Time2aStr(reqData.getStartTime())); log.info("开始时间:{}", ByteUtils.toHex(data.getStartTime()));
log.info("结束时间:{}", ByteUtils.parseCp56Time2aStr(reqData.getEndTime())); log.info("结束时间:{}", ByteUtils.toHex(data.getEndTime()));
log.info("电动汽车唯一标识:{}", Ocpp16Helper.bcdToStr(reqData.getVehicleIdentifier())); log.info("尖单价:{}", ByteUtils.toHex(data.getPeakUnitPrice()));
log.info("峰单价:{}", Ocpp16Helper.bcdToStr(reqData.getTopUnitPrice())); log.info("尖电量:{}", ByteUtils.toHex(data.getPeakElectricity()));
log.info("计损尖电量:{}", ByteUtils.toHex(data.getPeakElectricityLoss()));
log.info("尖金额:{}", ByteUtils.toHex(data.getPeakAmount()));
log.info("峰单价:{}", ByteUtils.toHex(data.getTopUnitPrice()));
log.info("峰电量:{}", ByteUtils.toHex(data.getTopElectricity()));
log.info("计损峰电量:{}", ByteUtils.toHex(data.getTopElectricityLoss()));
log.info("峰金额:{}", ByteUtils.toHex(data.getTopAmount()));
log.info("平单价:{}", ByteUtils.toHex(data.getFlatUnitPrice()));
log.info("平电量:{}", ByteUtils.toHex(data.getFlatElectricity()));
log.info("计损平电量:{}", ByteUtils.toHex(data.getFlatElectricityLoss()));
log.info("平金额:{}", ByteUtils.toHex(data.getFlatAmount()));
log.info("谷单价:{}", ByteUtils.toHex(data.getValleyUnitPrice()));
log.info("谷电量:{}", ByteUtils.toHex(data.getValleyElectricity()));
log.info("计损谷电量:{}", ByteUtils.toHex(data.getValleyElectricityLoss()));
log.info("谷金额:{}", ByteUtils.toHex(data.getValleyAmount()));
log.info("电表总起值:{}", ByteUtils.toHex(data.getTotalStartValue()));
log.info("电表总止值:{}", ByteUtils.toHex(data.getTotalEndValue()));
log.info("总电量:{}", ByteUtils.toHex(data.getTotalElectricity()));
log.info("计损总电量:{}", ByteUtils.toHex(data.getTotalElectricityLoss()));
log.info("消费金额:{}", ByteUtils.toHex(data.getTotalAmount()));
log.info("电动汽车唯一标识:{}", ByteUtils.toHex(data.getVehicleIdentifier()));
log.info("交易标识:{}", data.getTransactionIdentifier());
log.info("交易日期、时间:{}", ByteUtils.toHex(data.getTransactionDateTime()));
log.info("停止原因:{}", data.getStopReason());
log.info("物理卡号:{}", ByteUtils.toHex(data.getPhysicalCardNumber()));
/** 解析参数日志打印 */ /** 解析参数日志打印 */
TransactionRecordsResp resp = new TransactionRecordsResp(); TransactionRecordsResp resp = new TransactionRecordsResp();
TransactionRecordsRespData data = new TransactionRecordsRespData(); TransactionRecordsRespData respData = new TransactionRecordsRespData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("55031412782305012018061910262392", data.getTransactionSerialNumber())); respData.setTransactionSerialNumber(data.getTransactionSerialNumber());
data.setConfirmResult((byte) 0); respData.setConfirmResult((byte) 0);
resp.setData(data); resp.setData(respData);
return resp; return resp;
} }
} }
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler; 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.base.TcpHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsResp; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsResp;
import io.netty.channel.Channel; import io.netty.channel.Channel;
...@@ -17,7 +18,8 @@ public class TransactionRecordsRespHandler implements TcpHandler<TransactionReco ...@@ -17,7 +18,8 @@ public class TransactionRecordsRespHandler implements TcpHandler<TransactionReco
@Override @Override
public TransactionRecordsResp handle(Channel channel, TransactionRecordsResp transactionRecordsResp) { public TransactionRecordsResp handle(Channel channel, TransactionRecordsResp transactionRecordsResp) {
log.info("交易流水号:{}", Ocpp16Helper.bcdToStr(transactionRecordsResp.getData().getTransactionSerialNumber()));
log.info("确认结果:{}",transactionRecordsResp.getData().getConfirmResult());
log.info("客户端已经收到返回"); log.info("客户端已经收到返回");
return null; return null;
} }
......
...@@ -9,6 +9,10 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsReqDat ...@@ -9,6 +9,10 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsReqDat
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineReq; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsReq; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsReq;
import cn.com.glsx.charging.util.ByteUtils;
import cn.com.glsx.charging.util.DateUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
...@@ -23,11 +27,23 @@ import org.mockito.junit.MockitoJUnitRunner; ...@@ -23,11 +27,23 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class InteractiveTest { public class InteractiveTest {
@Test private TcpClient client;
public void transactionRecordsTest() throws Exception {
@Before
public void beforeTest() throws InterruptedException {
Ocpp16Helper.scan(); Ocpp16Helper.scan();
TcpClient client = ClientMain.getInstance("localhost", 8888); this.client = ClientMain.getInstance("localhost", 8888);
Thread.sleep(3000);
}
@After
public void afterTest() throws InterruptedException {
Thread.sleep(3000); Thread.sleep(3000);
System.out.println("=========================");
}
@Test
public void transactionRecordsTest() throws Exception {
/** /**
* 样例报文 68 (起始标志) A2 (数据长度) 8001 (序列号域) 00 (加密标志) 3B (类型) * 样例报文 68 (起始标志) A2 (数据长度) 8001 (序列号域) 00 (加密标志) 3B (类型)
* 55031412782305012018061910262392(交易流水号)55031412782305(桩编码)01(枪号:1 * 55031412782305012018061910262392(交易流水号)55031412782305(桩编码)01(枪号:1
...@@ -44,46 +60,64 @@ public class InteractiveTest { ...@@ -44,46 +60,64 @@ public class InteractiveTest {
TransactionRecordsReq req = new TransactionRecordsReq(); TransactionRecordsReq req = new TransactionRecordsReq();
TransactionRecordsReqData data = new TransactionRecordsReqData(); TransactionRecordsReqData data = new TransactionRecordsReqData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("55031412782305012018061910262392",data.getTransactionSerialNumber())); data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("55031412782305012018061910262392",data.getTransactionSerialNumber()));
data.setPileId(Ocpp16Helper.strToBcd("55031412782305",data.getPileId()));
data.setGunNumber((byte) 1); data.setGunNumber((byte) 1);
data.setPileId(Ocpp16Helper.strToBcd("32010200000001",data.getPileId())); data.setStartTime(ByteUtils.fromHex("98B70E11100314"));
data.setTopUnitPrice(Ocpp16Helper.strToBcd("D0FB0100",data.getTopUnitPrice())); data.setEndTime(ByteUtils.fromHex("98B70E11100314"));
data.setVehicleIdentifier(Ocpp16Helper.strToBcd("0000000000000000000000000000000001",data.getVehicleIdentifier())); data.setPeakUnitPrice(ByteUtils.fromHex("D0FB0100"));
data.setPeakElectricity(ByteUtils.fromHex("00000000"));
data.setPeakElectricityLoss(ByteUtils.fromHex("00000000"));
data.setPeakAmount(ByteUtils.fromHex("00000000"));
data.setTopUnitPrice(ByteUtils.fromHex("D0FB0100"));
data.setTopElectricity(ByteUtils.fromHex("00000000"));
data.setTopElectricityLoss(ByteUtils.fromHex("00000000"));
data.setTopAmount(ByteUtils.fromHex("00000000"));
data.setFlatUnitPrice(ByteUtils.fromHex("D0FB0100"));
data.setFlatElectricity(ByteUtils.fromHex("00000000"));
data.setFlatElectricityLoss(ByteUtils.fromHex("00000000"));
data.setFlatAmount(ByteUtils.fromHex("00000000"));
data.setValleyUnitPrice(ByteUtils.fromHex("D0FB0100"));
data.setFlatElectricity(ByteUtils.fromHex("00000000"));
data.setValleyElectricityLoss(ByteUtils.fromHex("00000000"));
data.setValleyAmount(ByteUtils.fromHex("00000000"));
data.setTotalStartValue(ByteUtils.fromHex("00000000"));
data.setTotalEndValue(ByteUtils.fromHex("00000000"));
data.setTotalElectricity(ByteUtils.fromHex("00000000"));
data.setTotalElectricityLoss(ByteUtils.fromHex("00000000"));
data.setTotalAmount(ByteUtils.fromHex("00000000"));
data.setVehicleIdentifier(Ocpp16Helper.strToAscii("0000000000000000000000000000000001",data.getVehicleIdentifier()));
data.setTransactionIdentifier((byte) 0x01);
data.setTransactionDateTime(ByteUtils.fromHex("98B70E11100314"));
data.setStopReason((byte) 0x00);
data.setPhysicalCardNumber(ByteUtils.fromHex("00000000D14B0A54"));
req.setData(data); req.setData(data);
client.sendSync(req); client.sendSync(req);
Thread.sleep(3000);
System.out.println("=========================");
} }
@Test @Test
public void shutdownMachineTest() throws Exception { public void shutdownMachineTest() throws Exception {
Ocpp16Helper.scan();
TcpClient client = ClientMain.getInstance("localhost", 8888);
Thread.sleep(3000);
ShutdownMachineReq req = new ShutdownMachineReq(); ShutdownMachineReq req = new ShutdownMachineReq();
ShutdownMachineReqData data = new ShutdownMachineReqData(); ShutdownMachineReqData data = new ShutdownMachineReqData();
data.setGunNumber((byte) 1); data.setGunNumber((byte) 1);
data.setPileId(Ocpp16Helper.strToBcd("32010200000001",data.getPileId())); data.setPileId(Ocpp16Helper.strToBcd("32010200000001",data.getPileId()));
req.setData(data); req.setData(data);
client.sendSync(req); client.sendSync(req);
Thread.sleep(3000);
System.out.println("=========================");
} }
@Test @Test
public void startMachineReqTest() throws Exception { public void startMachineReqTest() throws Exception {
Ocpp16Helper.scan();
TcpClient client = ClientMain.getInstance("localhost", 8888);
Thread.sleep(3000);
StartMachineReq req = new StartMachineReq(); StartMachineReq req = new StartMachineReq();
StartMachineReqData data = new StartMachineReqData(); StartMachineReqData data = new StartMachineReqData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350261", data.getTransactionSerialNumber())); data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350261", data.getTransactionSerialNumber()));
data.setPileId(Ocpp16Helper.strToBcd("32010200000001",data.getPileId())); data.setPileId(Ocpp16Helper.strToBcd("32010200000001",data.getPileId()));
data.setGunNumber((byte) 1); data.setGunNumber((byte) 1);
data.setLogicalCardNumber(Ocpp16Helper.strToBcd("1000000573",data.getLogicalCardNumber())); data.setLogicalCardNumber(Ocpp16Helper.strToBcd("0000001000000573",data.getLogicalCardNumber()));
data.setPhysicalCardNumber(Ocpp16Helper.strToBcd("D14B0A54",data.getPhysicalCardNumber())); byte[] bytes = Ocpp16Helper.binToBytes(Ocpp16Helper.hexToBinaryString("00000000D14B0A54"));
data.setAccountBalance(Ocpp16Helper.strToBcd("00000064",data.getAccountBalance())); data.setPhysicalCardNumber(bytes);
byte[] accountBytes = Ocpp16Helper.binToBytes(Ocpp16Helper.hexToBinaryString("A0860100"));
data.setAccountBalance(accountBytes);
req.setData(data); req.setData(data);
client.sendSync(req); client.sendSync(req);
System.out.println("=========================");
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!