mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
update 电单车协议
This commit is contained in:
@@ -16,8 +16,8 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class GetServerTimeHandler extends AbstractEBikeHandler {
|
||||
private final String type = EBikeCommandEnum.GET_SERVER_TIME.getCode();
|
||||
public class DeviceGetServerTimeHandler extends AbstractEBikeHandler {
|
||||
private final String type = EBikeCommandEnum.DEVICE_GET_SERVER_TIME.getCode();
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@@ -35,7 +35,7 @@ public class GetServerTimeHandler extends AbstractEBikeHandler {
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd22 message = (EBikeMessageCmd22) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
log.info("设备获取服务器时间:{}", JSON.toJSONString(message));
|
||||
log.info("设备 获取服务器时间:{}", JSON.toJSONString(message));
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
|
||||
@@ -40,15 +40,6 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
|
||||
try {
|
||||
byte[] serialize = SerializationUtil.serialize(message);
|
||||
log.info("心跳包序列化:{}", BytesUtil.binary(serialize, 16));
|
||||
EBikeMessageCmd21 deserialize = SerializationUtil.deserialize(EBikeMessageCmd21.class, serialize);
|
||||
log.info("心跳包反序列化:{}", JSON.toJSONString(deserialize));
|
||||
} catch (Exception e) {
|
||||
log.info("error", e);
|
||||
}
|
||||
|
||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||
log.info("设备心跳包:{}", JSON.toJSONString(message));
|
||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.jsowell.netty.handler.electricbicycles;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd12;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 设备获取服务器时间
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class HostGetServerTimeHandler extends AbstractEBikeHandler {
|
||||
private final String type = EBikeCommandEnum.HOST_GET_SERVER_TIME.getCode();
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
EBikeOperateFactory.register(type, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行逻辑
|
||||
* 有应答
|
||||
*
|
||||
* @param dataProtocol
|
||||
* @param ctx
|
||||
*/
|
||||
@Override
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd12 message = (EBikeMessageCmd12) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
log.info("主机 获取服务器时间:{}", JSON.toJSONString(message));
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
|
||||
// 获取当前服务器10位时间戳
|
||||
byte[] timeBytes = BytesUtil.getIntBytes((int) (System.currentTimeMillis() / 1000));
|
||||
// System.out.println("data: " + BytesUtil.bytesToIntLittle(timeBytes));
|
||||
return getResult(dataProtocol, timeBytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user