Commit 240ebb67 by 叶立庆

[+]修改协议实现类

1 parent 35e05da1
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.Ocpp16Helper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpCallback;
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.base.TcpRsp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineRespData; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineRespData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineResp; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineResp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server.ProxyHelper;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import java.util.Objects;
/** /**
* @Description 远程停止充电命令回复处理类 * @Description 远程停止充电命令回复处理类
* @Author yelq * @Author yelq
...@@ -16,12 +21,19 @@ public class ShutdownMachineRespHandler implements TcpHandler<ShutdownMachineRes ...@@ -16,12 +21,19 @@ public class ShutdownMachineRespHandler implements TcpHandler<ShutdownMachineRes
@Override @Override
public ShutdownMachineResp handle(Channel channel, ShutdownMachineResp shutdownMachineResp) { public ShutdownMachineResp handle(Channel channel, ShutdownMachineResp shutdownMachineResp) {
System.out.println("客户端已经收到消息了");
ShutdownMachineRespData data = shutdownMachineResp.getData(); ShutdownMachineRespData data = shutdownMachineResp.getData();
log.info("桩编号:{}", Ocpp16Helper.bcdToStr(data.getPileId())); log.info("桩编号:{}", Ocpp16Helper.bcdToStr(data.getPileId()));
log.info("枪号:{}", data.getGunNumber()); log.info("枪号:{}", data.getGunNumber());
log.info("停止结果:{}", data.getShutdownResult()); log.info("停止结果:{}", data.getShutdownResult());
log.info("失败原因:{}", data.getFailureReason()); log.info("失败原因:{}", data.getFailureReason());
System.out.println("客户端已经收到消息了"); String key = ProxyHelper.getCallbackKey(shutdownMachineResp, channel);
TcpCallback<TcpRsp> callback = ProxyHelper.getCallback(key);
if (Objects.nonNull(callback)) {
callback.callback(shutdownMachineResp);
} else {
log.info("callback为空===StartMachineRespHandler");
}
return null; return null;
} }
} }
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.TcpCallback;
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.base.TcpRsp;
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.StartMachineResp; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineResp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server.ProxyHelper;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import java.util.Objects;
/** /**
* @Description 远程启动充电命令回复处理类 * @Description 远程启动充电命令回复处理类
* @Author yelq * @Author yelq
...@@ -27,6 +31,13 @@ public class StartMachineRespHandler implements TcpHandler<StartMachineResp, Sta ...@@ -27,6 +31,13 @@ public class StartMachineRespHandler implements TcpHandler<StartMachineResp, Sta
data.setGunNumber((byte) 1); data.setGunNumber((byte) 1);
data.setFailureReason((byte) 0); data.setFailureReason((byte) 0);
resp.setData(data); resp.setData(data);
String key = ProxyHelper.getCallbackKey(startMachineResp, channel);
TcpCallback<TcpRsp> callback = ProxyHelper.getCallback(key);
if (Objects.nonNull(callback)) {
callback.callback(startMachineResp);
} else {
log.info("callback为空===StartMachineRespHandler");
}
return null; return null;
} }
} }
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol; 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.TcpMapper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpReq; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpRsp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineRespData; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineRespData;
/** /**
...@@ -10,7 +10,7 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineRespData; ...@@ -10,7 +10,7 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineRespData;
* @Date 2023/11/7-16:21 * @Date 2023/11/7-16:21
* @Version 1.0 * @Version 1.0
*/ */
public class ShutdownMachineResp extends TcpReq<ShutdownMachineRespData> { public class ShutdownMachineResp extends TcpRsp<ShutdownMachineRespData> {
public ShutdownMachineResp() { public ShutdownMachineResp() {
super(TcpMapper.CMD_RSP_STOP_CHARGING.getType()); super(TcpMapper.CMD_RSP_STOP_CHARGING.getType());
} }
......
...@@ -2,6 +2,7 @@ package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol; ...@@ -2,6 +2,7 @@ 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.TcpMapper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpReq; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpRsp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsRespData; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsRespData;
/** /**
...@@ -13,7 +14,7 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsRespDa ...@@ -13,7 +14,7 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsRespDa
* @Date 2023/11/7-17:38 * @Date 2023/11/7-17:38
* @Version 1.0 * @Version 1.0
*/ */
public class TransactionRecordsResp extends TcpReq<TransactionRecordsRespData> { public class TransactionRecordsResp extends TcpRsp<TransactionRecordsRespData> {
public TransactionRecordsResp() { public TransactionRecordsResp() {
super(TcpMapper.CMD_RSP_TRADE_UPLOAD.getType()); super(TcpMapper.CMD_RSP_TRADE_UPLOAD.getType());
} }
......
...@@ -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.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.server.TcpServer; import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server.TcpServer;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
...@@ -32,11 +33,11 @@ public class RemoteChargingTest { ...@@ -32,11 +33,11 @@ public class RemoteChargingTest {
@Before @Before
public void beforeTest() throws InterruptedException { public void beforeTest() throws InterruptedException {
// Ocpp16Helper.scan(); Ocpp16Helper.scan();
// String host = "localhost"; String host = "localhost";
// int port = 8888; int port = 8888;
// server = ServerMain.start(host,port); server = ServerMain.start(host,port);
// Thread.sleep(10000); Thread.sleep(20000);
} }
@After @After
...@@ -47,7 +48,7 @@ public class RemoteChargingTest { ...@@ -47,7 +48,7 @@ public class RemoteChargingTest {
/** /**
* 远程关闭充电桩 * 运营平台远程停机 运营平台->充电桩
* @throws Exception * @throws Exception
*/ */
@Test @Test
...@@ -60,7 +61,7 @@ public class RemoteChargingTest { ...@@ -60,7 +61,7 @@ public class RemoteChargingTest {
server.sendSync(req); server.sendSync(req);
} }
//远程启动充电桩 //运营平台远程控制启机 运营平台->充电桩
@Test @Test
public void startMachineReqTest() throws Exception { public void startMachineReqTest() throws Exception {
StartMachineReq req = new StartMachineReq(); StartMachineReq req = new StartMachineReq();
...@@ -74,13 +75,8 @@ public class RemoteChargingTest { ...@@ -74,13 +75,8 @@ public class RemoteChargingTest {
byte[] accountBytes = Ocpp16Helper.binToBytes(Ocpp16Helper.hexToBinStr("A0860100")); byte[] accountBytes = Ocpp16Helper.binToBytes(Ocpp16Helper.hexToBinStr("A0860100"));
data.setAccountBalance(accountBytes); data.setAccountBalance(accountBytes);
req.setData(data); req.setData(data);
Ocpp16Helper.scan();
String host = "localhost";
int port = 8888;
server = ServerMain.start(host,port);
Thread.sleep(10000);
TcpCallback<TcpRsp> callback = server.sendSync(req); TcpCallback<TcpRsp> callback = server.sendSync(req);
TcpRsp tcpRsp = callback.get(); TcpRsp tcpRsp = callback.get();
log.info("callback:{}",tcpRsp); log.info("callback:{}", JSON.toJSONString(tcpRsp));
} }
} }
...@@ -43,10 +43,15 @@ public class TransactionRecordsTest { ...@@ -43,10 +43,15 @@ public class TransactionRecordsTest {
@After @After
public void afterTest() throws InterruptedException { public void afterTest() throws InterruptedException {
Thread.sleep(30000); Thread.sleep(300000);
System.out.println("========================="); System.out.println("=========================");
} }
/**
* 充电桩->运营平台
* 交易记录
* @throws Exception
*/
@Test @Test
public void transactionRecordsTest() throws Exception { public void transactionRecordsTest() throws Exception {
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!