mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 电单车协议
This commit is contained in:
@@ -3,6 +3,8 @@ package com.jsowell.netty.handler.electricbicycles;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.bean.SerializationUtil;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
@@ -37,6 +39,16 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
EBikeMessageCmd21 message = (EBikeMessageCmd21) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
// 保存时间
|
||||
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);
|
||||
|
||||
@@ -52,7 +52,6 @@ public abstract class AbsEBikeMessage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static AbsEBikeMessage parseMessage(byte[] messageBytes) {
|
||||
if (messageBytes == null || messageBytes.length < 14 || messageBytes.length > 256) {
|
||||
throw new IllegalArgumentException("Invalid message bytes");
|
||||
@@ -101,6 +100,8 @@ public abstract class AbsEBikeMessage {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract byte[] getMessageBytes();
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "44 4e 59 00 0d 3b 37 ab 04 b9 00 22 54 33 cc 66 03 7b".replace(" ", "");
|
||||
byte[] messageBytes = BytesUtil.hexStringToByteArray(s);
|
||||
|
||||
@@ -26,6 +26,11 @@ public class EBikeMessageCmd02 extends AbsEBikeMessage {
|
||||
this.creditCardInfo = new CreditCardInfo(dataBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CreditCardInfo getCreditCardInfo() {
|
||||
return creditCardInfo;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import lombok.Data;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 结算消费信息上传(03指令)
|
||||
*/
|
||||
public class EBikeMessageCmd03 extends AbsEBikeMessage {
|
||||
|
||||
private SettlementInfo settlementInfo;
|
||||
@@ -20,6 +23,11 @@ public class EBikeMessageCmd03 extends AbsEBikeMessage {
|
||||
this.settlementInfo = new SettlementInfo(dataBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public SettlementInfo getSettlementInfo() {
|
||||
return settlementInfo;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ public class EBikeMessageCmd04 extends AbsEBikeMessage {
|
||||
this.confirmOrder = new ConfirmOrder(dataBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public ConfirmOrder getSettlementInfo() {
|
||||
return confirmOrder;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ public class EBikeMessageCmd06 extends AbsEBikeMessage {
|
||||
this.powerHeartbeat = new PowerHeartbeat(dataBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public PowerHeartbeat getPowerHeartbeat() {
|
||||
return powerHeartbeat;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ public class EBikeMessageCmd20 extends AbsEBikeMessage {
|
||||
this.deviceRegister = new DeviceRegister(dataBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public DeviceRegister getDeviceRegister() {
|
||||
return deviceRegister;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ public class EBikeMessageCmd21 extends AbsEBikeMessage {
|
||||
this.deviceHeartbeat = new DeviceHeartbeat(dataBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 此为心跳包,间隔时间默认为3分钟,方便服务器管理SocketIP
|
||||
* 设备如2次收不到服务器应答,则进入离线状态
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsowell.pile.domain.ebike.deviceupload;
|
||||
|
||||
import com.jsowell.common.util.bean.SerializationUtil;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -22,4 +23,10 @@ public class EBikeMessageCmd22 extends AbsEBikeMessage {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
byte[] serialize = SerializationUtil.serialize(this);
|
||||
return serialize;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,4 +18,9 @@ public class EBikeMessageCmd81 extends AbsEBikeMessage {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,11 @@ public class EBikeMessageCmd82 extends AbsEBikeMessage {
|
||||
this.specificData = new SpecificData(dataBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMessageBytes() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public SpecificData getSpecificData() {
|
||||
return specificData;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.jsowell.pile.service.impl;
|
||||
|
||||
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 电单车发送指令service
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EBikeSendCommandService {
|
||||
|
||||
/**
|
||||
* 公共方法发送指令
|
||||
* @param pileSn 装编号
|
||||
* @param msg 消息
|
||||
* @param timeout 超时时间
|
||||
* @param unit 时间单位
|
||||
*/
|
||||
private void sendCommand(String pileSn, Class<? extends AbsEBikeMessage> msg, long timeout, TimeUnit unit) {
|
||||
// 通过桩编号获取channel
|
||||
ChannelHandlerContext ctx = PileChannelEntity.getChannelByPileSn(pileSn);
|
||||
if (Objects.isNull(ctx)) {
|
||||
log.error("push命令[{}]失败, 桩号:{}无法获取到长连接, 请检查充电桩连接状态!", "value", pileSn);
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user