Commit ba7607ce by 谢海旭

Merge remote-tracking branch 'origin/master'

2 parents 4db36a7a 5d602426
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base;
import java.util.Map;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.param.ParamSettingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.param.ParamSettingRspHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.time.TimeSettingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.time.TimeSettingRspHandler;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Maps;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req.ShutdownMachineReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req.StartMachineReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.resp.ShutdownMachineRespHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.resp.StartMachineRespHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.notify.TimeNotifyHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.HeartbeatReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.LoginReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.ModelChargingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.ModelValReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.rsp.LoginRspHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.param.ParamSettingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.param.ParamSettingRspHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.time.TimeSettingReqHandler;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.time.TimeSettingRspHandler;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
/**
* 管理与server的交互
*
......@@ -62,9 +62,9 @@ public final class TcpMapper {
public static TcpMapper FTCD_REQ_REMOTE_CONTROL_STARTUP = regist(0x34, "运营平台远程控制启机", StartMachineReqHandler.class);
public static TcpMapper FTCD_RSP_REMOTE_SHUTDOWN = regist(0x35, "远程停机命令回复", null);
public static TcpMapper FTCD_RSP_REMOTE_SHUTDOWN = regist(0x35, "远程停机命令回复", ShutdownMachineRespHandler.class);
public static TcpMapper FTCD_REQ_REMOTE_SHUTDOWN = regist(0x36, "运营平台远程停机", null);
public static TcpMapper FTCD_REQ_REMOTE_SHUTDOWN = regist(0x36, "运营平台远程停机", ShutdownMachineReqHandler.class);
public static TcpMapper FTCD_REQ_TRANSACTION_RECORDS = regist(0x3B, "交易记录", null);
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData;
import lombok.Getter;
import lombok.Setter;
/**
* @Description 运营平台远程停机
* 功能 当用户通过远程停止充电时,发送本命令,如 APP 停止充电
* 样例报文 68(起始标志)0C(数据长度)0003(序列号域)00(加密标志)36(类型)32010200000001
* (桩编码)01(枪号:1 枪)C1A9(帧校验域)
* @Author yelq
* @Date 2023/11/7-16:10
* @Version 1.0
*/
@Getter
@Setter
public class ShutdownMachineReqData extends TcpData {
/**
* 桩编号
* 数据类型: (BCD码)
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
/**
* 枪号
* 数据类型: (BCD码)
* 长度(Byte):1
* 备注:
*/
private byte gunNumber;
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData;
import lombok.Getter;
import lombok.Setter;
/**
* @Description 远程停止充电命令回复
* 功能 远程停止充电命令回复,平台发送 0x36 后即关闭订单,接收到停机指令后设备务必保证停机。
* 样例报文 68(起始标志)0E(数据长度)0003(序列号域)00(加密标志)35(类型)32010200000001
* (桩编码)01(枪号:1 枪)01(停止结果:成功)00(失败原因:00)907E(帧校验域)
* @Author yelq
* @Date 2023/11/7-16:10
* @Version 1.0
*/
@Getter
@Setter
public class ShutdownMachineRespData extends TcpData {
/**
* 桩编号
* 数据类型:byte[] (BCD码)
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileNumber = new byte[7];
/**
* 枪号
* 数据类型:byte[] (BCD码)
* 长度(Byte):1
* 备注:
*/
private byte gunNumber;
/**
* 停止结果
* 数据类型:byte[] (BCD码)
* 长度(Byte):1
* 备注:0x00失败 0x01成功
*/
private byte shutdownResult;
/**
* 失败原因
* 数据类型:byte[] (BIN码)
* 长度(Byte):1
* 备注:
* 0x00 无
* 0x01 设备编号不匹配
* 0x02 枪未处于充电状态
* 0x03 其他
*/
private byte failureReason;
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req;
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.ShutdownMachineRespData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.ShutdownMachineReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.ShutdownMachineResp;
import io.netty.channel.Channel;
/**
* @Description 运营平台远程停机处理类
* @Author yelq
* @Date 2023/11/7-16:10
* @Version 1.0
*/
public class ShutdownMachineReqHandler implements TcpHandler<ShutdownMachineReq, ShutdownMachineResp> {
// * 功能 远程停止充电命令回复,平台发送 0x36 后即关闭订单,接收到停机指令后设备务必保证停机。
// * 样例报文 68(起始标志)0E(数据长度)0003(序列号域)00(加密标志)35(类型)32010200000001
// * (桩编码)01(枪号:1 枪)01(停止结果:成功)00(失败原因:00)907E(帧校验域)
@Override
public ShutdownMachineResp handle(Channel channel, ShutdownMachineReq shutdownMachineReq) {
/**请求日志打印*/
log.info("桩编号:" + Ocpp16Helper.bcdToStr(shutdownMachineReq.getData().getPileNumber()));
log.info("枪号:" + shutdownMachineReq.getData().getGunNumber());
/**请求日志打印*/
ShutdownMachineResp resp = new ShutdownMachineResp();
ShutdownMachineRespData data = new ShutdownMachineRespData();
data.setPileNumber(Ocpp16Helper.strToBcd("32010200000001", data.getPileNumber()));
data.setGunNumber((byte) 1);
data.setShutdownResult((byte) 1);
data.setFailureReason((byte) 0);
resp.setData(data);
return resp;
}
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.resp;
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.ShutdownMachineRespData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.ShutdownMachineResp;
import io.netty.channel.Channel;
/**
* @Description 远程停止充电命令回复处理类
* @Author yelq
* @Date 2023/11/7-16:10
* @Version 1.0
*/
public class ShutdownMachineRespHandler implements TcpHandler<ShutdownMachineResp, ShutdownMachineResp> {
@Override
public ShutdownMachineResp handle(Channel channel, ShutdownMachineResp shutdownMachineResp) {
ShutdownMachineRespData data = shutdownMachineResp.getData();
log.info("桩编号:{}", Ocpp16Helper.bcdToStr(data.getPileNumber()));
log.info("枪号:{}", data.getGunNumber());
log.info("停止结果:{}", data.getShutdownResult());
log.info("失败原因:{}", data.getFailureReason());
System.out.println("客户端已经收到消息了");
return null;
}
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req;
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.ShutdownMachineReqData;
/**
* @Description todo
* @Author yelq
* @Date 2023/11/7-16:21
* @Version 1.0
*/
public class ShutdownMachineReq extends TcpReq<ShutdownMachineReqData> {
public ShutdownMachineReq() {
super(TcpMapper.FTCD_REQ_REMOTE_SHUTDOWN.getType());
}
}
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp;
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.ShutdownMachineRespData;
/**
* @Description todo
* @Author yelq
* @Date 2023/11/7-16:21
* @Version 1.0
*/
public class ShutdownMachineResp extends TcpReq<ShutdownMachineRespData> {
public ShutdownMachineResp() {
super(TcpMapper.FTCD_RSP_REMOTE_SHUTDOWN.getType());
}
}
package cn.com.glsx.charging.gbt.ocpp16;
import cn.com.glsx.charging.modules.gbt.ocpp16.ClientMain;
import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.client.TcpClient;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.ShutdownMachineReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.StartMachineReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.ShutdownMachineReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
/**
* @Description 运营交互帧类型码数据定义协议测试类
* @Author yelq
* @Date 2023/11/7-15:19
* @Version 1.0
*/
@RunWith(MockitoJUnitRunner.class)
public class InteractiveTest {
@Test
public void shutdownMachineTest() throws Exception {
Ocpp16Helper.scan();
TcpClient client = ClientMain.getInstance("localhost", 8888);
Thread.sleep(3000);
ShutdownMachineReq req = new ShutdownMachineReq();
ShutdownMachineReqData data = new ShutdownMachineReqData();
data.setGunNumber((byte) 1);
data.setPileNumber(Ocpp16Helper.strToBcd("32010200000001",data.getPileNumber()));
req.setData(data);
client.sendSync(req);
Thread.sleep(3000);
System.out.println("=========================");
}
@Test
public void startMachineReqTest() throws Exception {
Ocpp16Helper.scan();
TcpClient client = ClientMain.getInstance("localhost", 8888);
Thread.sleep(3000);
StartMachineReq req = new StartMachineReq();
StartMachineReqData data = new StartMachineReqData();
data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350261", data.getTransactionSerialNumber()));
data.setPileNumber(Ocpp16Helper.strToBcd("32010200000001",data.getPileNumber()));
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()));
req.setData(data);
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!