Commit 32460bdd by chenxi

实现功能:读取实时监测数据

1 parent 106426f6
package cn.com.glsx.charging.modules.controller;
import cn.com.glsx.charging.modules.BaseController;
import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import cn.com.glsx.charging.modules.gbt.ocpp16.ServerMain;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpCallback;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpRsp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.RealTimeDataReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.RealTimeReq;
import com.glsx.plat.core.annotation.ResponseResultBody;
import com.glsx.plat.core.web.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author: chenxi
* @Date: 2023/11/10
*/
@Slf4j
@Tag(name = "")
@RestController
@RequestMapping(value = "/getdata")
@ResponseResultBody
public class GetDataController extends BaseController {
@Operation(summary = "读取实时监测数据", description = "读取实时监测数据")
@GetMapping("/realtime")
public R<Boolean> getRealTimeData(@Param("pileId") String pileId, @Param("gunNumber") String gunNumber) {
log.info("读取实时监测数据,充电桩编号:{}", pileId);
log.info("读取实时监测数据,枪号:{}", gunNumber);
RealTimeReq req = new RealTimeReq();
RealTimeDataReqData data = new RealTimeDataReqData();
data.setPileId(Ocpp16Helper.strToBcd(pileId, data.getPileId()));
data.setPileId(Ocpp16Helper.strToBcd(pileId, new byte[] {data.getGunNumber()} ));
TcpCallback<TcpRsp> tcpRspTcpCallback = ServerMain.getServer().sendSync(req);
TcpRsp tcpRsp = tcpRspTcpCallback.get();
return R.ok().data(tcpRsp);
}
}
......@@ -42,7 +42,9 @@ public final class TcpMapper {
public static TcpMapper CMD_RSP_MODEL_QUERY = regist(0x0A, "计费模型请求应答", null);
public static TcpMapper CMD_REQ_UPLOAD_REAL_TIME_DATA = regist(0x13, "读取实时检测数据", UploadRealTimeReqHandler.class);
public static TcpMapper CMD_REQ_GET_REAL_TIME_DATA = regist(0x12, "读取实时检测数据", RealTimeDataReqHandler.class);
public static TcpMapper CMD_REQ_UPLOAD_REAL_TIME_DATA = regist(0x13, "上传实时检测数据", UploadRealTimeReqHandler.class);
public static TcpMapper CMD_REQ_CHARGING_HAND_SHAKE = regist(0x15, "充电握手", ChargingHandshakeReqHandler.class);
......
package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData;
import lombok.Data;
/**
* @Author: chenx
* @Description: 读取实时监测数据请求类
* @Date: 2023/11/10 16:29
* @Version: 1.0
*/
@Data
public class RealTimeDataReqData extends TcpData {
/**
* 桩编号
* 数据类型:byte[] (BCD码)
* 长度(Byte):7
* 备注:不足7位补0
*/
private byte[] pileId = new byte[7];
/**
* 枪号
* 数据类型:byte[] (BCD码)
* 长度(Byte):1
* 备注:
*/
private byte gunNumber;
}
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.RealTimeReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.UploadRealtimeDataReq;
import io.netty.channel.Channel;
/**
* @Author: chenx
* @Description:
* @Date: 2023/11/10 16:31
* @Version: 1.0
*/
public class RealTimeDataReqHandler implements TcpHandler<RealTimeReq, UploadRealtimeDataReq> {
@Override
public UploadRealtimeDataReq handle(Channel channel, RealTimeReq realTimeReq) {
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.TcpRsp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.RealTimeDataReqData;
/**
* @Author: chenx
* @Description:
* @Date: 2023/11/10 16:45
* @Version: 1.0
*/
public class RealTimeReq extends TcpRsp<RealTimeDataReqData> {
public RealTimeReq() {
super(TcpMapper.CMD_REQ_GET_REAL_TIME_DATA.getType());
}
}
package cn.com.glsx.charging.gbt.ocpp16;
import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import cn.com.glsx.charging.modules.gbt.ocpp16.ServerMain;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpCallback;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpRsp;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.RealTimeDataReqData;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.RealTimeReq;
import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server.TcpServer;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
/**
* @Author: chenx
* @Description: 读取实时监测数据
* @Date: 2023/11/10 17:06
* @Version: 1.0
*/
@Slf4j
public class GetDataTest {
String host = "localhost";
int port = 8888;
private TcpServer serverStart() throws Exception {
// 启动服务端
TcpServer start = ServerMain.start(host, port);
Thread.sleep(15000);
return start;
}
@Test
public void test() throws Exception {
TcpServer tcpServer = serverStart();
RealTimeDataReqData data = new RealTimeDataReqData();
data.setPileId(Ocpp16Helper.strToBcd("32010200000001", data.getPileId()));
data.setGunNumber((byte)01);
RealTimeReq req = new RealTimeReq();
req.setData(data);
Thread.sleep(20000);
TcpCallback<TcpRsp> callback = tcpServer.sendSync(req);
Thread.sleep(10000);
TcpRsp rsp = callback.get();
log.info("callback{}",rsp.getData());
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!