Commit 240ebb67 by 叶立庆

[+]修改协议实现类

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