mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-04 10:00:11 +08:00
update 电单车协议
This commit is contained in:
@@ -4,29 +4,32 @@ package com.jsowell.common.enums.ebike;
|
||||
* 电单车端口状态
|
||||
*/
|
||||
public enum PortStatusEnum {
|
||||
IDLE(0, "空闲"),
|
||||
CHARGING(1, "充电中"),
|
||||
CHARGER_CONNECTED_NOT_CHARGING_USER(2, "有充电器但未充电(用户未启动充电)"),
|
||||
CHARGER_CONNECTED_NOT_CHARGING_FULL(3, "有充电器但未充电(已充满电)"),
|
||||
UNMEASURABLE(4, "该路无法计量"),
|
||||
FLOAT_CHARGE(5, "浮充"),
|
||||
MEMORY_DAMAGE(6, "存储器损坏"),
|
||||
SOCKET_SPRING_STUCK(7, "插座弹片卡住故障"),
|
||||
CONTACT_BAD_OR_FUSE_BLOWN(8, "接触不良或保险丝烧断故障"),
|
||||
RELAY_GLUE(9, "算法-继电器粘连"),
|
||||
HALL_SWITCH_DAMAGE(10, "霍尔开关损坏(即插入检测传感器)"),
|
||||
PRE_INSPECTION_RELAY_OR_FUSE_BAD(11, "预检-继电器坏或保险丝断"),
|
||||
PRE_INSPECTION_LOAD_SHORT_CIRCUIT(13, "预检-负载短路"),
|
||||
FILTERED_PRE_INSPECTION_RELAY_GLUE(14, "过滤性预检-继电器粘连"),
|
||||
CARD_CHIP_DAMAGE(15, "刷卡芯片损坏故障"),
|
||||
DETECTION_CIRCUIT_FAULT(16, "检测电路故障");
|
||||
IDLE(0, "空闲", "1"),
|
||||
CHARGING(1, "充电中", "3"),
|
||||
CHARGER_CONNECTED_NOT_CHARGING_USER(2, "有充电器但未充电(用户未启动充电)", "2"),
|
||||
CHARGER_CONNECTED_NOT_CHARGING_FULL(3, "有充电器但未充电(已充满电)", "2"),
|
||||
UNMEASURABLE(4, "该路无法计量", "255"),
|
||||
FLOAT_CHARGE(5, "浮充", "3"),
|
||||
MEMORY_DAMAGE(6, "存储器损坏", "255"),
|
||||
SOCKET_SPRING_STUCK(7, "插座弹片卡住故障", "255"),
|
||||
CONTACT_BAD_OR_FUSE_BLOWN(8, "接触不良或保险丝烧断故障", "255"),
|
||||
RELAY_GLUE(9, "算法-继电器粘连", "255"),
|
||||
HALL_SWITCH_DAMAGE(10, "霍尔开关损坏(即插入检测传感器)", "255"),
|
||||
PRE_INSPECTION_RELAY_OR_FUSE_BAD(11, "预检-继电器坏或保险丝断", "255"),
|
||||
PRE_INSPECTION_LOAD_SHORT_CIRCUIT(13, "预检-负载短路", "255"),
|
||||
FILTERED_PRE_INSPECTION_RELAY_GLUE(14, "过滤性预检-继电器粘连", "255"),
|
||||
CARD_CHIP_DAMAGE(15, "刷卡芯片损坏故障", "255"),
|
||||
DETECTION_CIRCUIT_FAULT(16, "检测电路故障", "255");
|
||||
|
||||
private final int value;
|
||||
private final String description;
|
||||
// 状态 0:离网 (默认);1:空闲;2:占用(未充电);3:占用(充电中);4:占用(预约锁定) ;255:故障
|
||||
private final String dbStatus;
|
||||
|
||||
PortStatusEnum(int value, String description) {
|
||||
PortStatusEnum(int value, String description, String dbStatus) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
this.dbStatus = dbStatus;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
@@ -37,6 +40,10 @@ public enum PortStatusEnum {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getDbStatus() {
|
||||
return dbStatus;
|
||||
}
|
||||
|
||||
// 新增方法: 根据 value 获取描述
|
||||
public static String getDescriptionByValue(int value) {
|
||||
for (PortStatusEnum status : values()) {
|
||||
@@ -46,4 +53,14 @@ public enum PortStatusEnum {
|
||||
}
|
||||
return "未知状态";
|
||||
}
|
||||
|
||||
// 根据value 获取枚举对象
|
||||
public static PortStatusEnum getEnumByValue(int value) {
|
||||
for (PortStatusEnum status : values()) {
|
||||
if (status.getValue() == value) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,21 @@ 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.common.enums.ebike.PortStatusEnum;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
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.EBikeMessageCmd21;
|
||||
import com.jsowell.pile.service.PileBasicInfoService;
|
||||
import com.jsowell.pile.service.PileConnectorInfoService;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备心跳包
|
||||
*/
|
||||
@@ -21,6 +26,12 @@ import org.springframework.stereotype.Component;
|
||||
public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
private final String type = EBikeCommandEnum.HEARTBEAT_2.getCode();
|
||||
|
||||
@Autowired
|
||||
private PileBasicInfoService pileBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileConnectorInfoService pileConnectorInfoService;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
EBikeOperateFactory.register(type, this);
|
||||
@@ -42,6 +53,44 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
|
||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||
log.info("设备心跳包:{}", JSON.toJSONString(message));
|
||||
|
||||
updatePileStatus(message);
|
||||
|
||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新充电桩状态
|
||||
* @param message
|
||||
*/
|
||||
private void updatePileStatus(EBikeMessageCmd21 message) {
|
||||
String pileSn = message.getPhysicalId() + "";
|
||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||
int portNumber = deviceHeartbeat.getPortNumber();
|
||||
List<String> portStatus = deviceHeartbeat.getPortStatus();
|
||||
for (int i = 0; i < portNumber; i++) {
|
||||
// 组装pile_connector_info表数据
|
||||
String connectorCode = String.format("%1$02d", i + 1);
|
||||
String pileConnectorCode = pileSn + connectorCode;
|
||||
// 电单车协议状态
|
||||
String eBikeStatus = portStatus.get(i);
|
||||
pileConnectorInfoService.updateConnectorStatus(pileConnectorCode, eBikeStatusTransformDBStatus(eBikeStatus));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 电单车协议状态转换为数据库状态
|
||||
* @param eBikeStatus
|
||||
* @return
|
||||
*/
|
||||
private String eBikeStatusTransformDBStatus(String eBikeStatus) {
|
||||
String dbStatus = Constants.ZERO; // 默认0-离网
|
||||
if (StringUtils.isNotBlank(eBikeStatus)) {
|
||||
PortStatusEnum enumByValue = PortStatusEnum.getEnumByValue(Integer.parseInt(eBikeStatus));
|
||||
if (enumByValue != null) {
|
||||
dbStatus = enumByValue.getDbStatus();
|
||||
}
|
||||
}
|
||||
return dbStatus;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,8 @@ public class EBikeMessageCmd21 extends AbsEBikeMessage {
|
||||
*/
|
||||
private List<String> portStatus;
|
||||
|
||||
private List<String> statusDescList;
|
||||
|
||||
/**
|
||||
* 信号强度:指分机与主机之间的无线信号强度,如LORA信号。00则为有线组网或无信号强度功能
|
||||
*/
|
||||
@@ -79,11 +81,14 @@ public class EBikeMessageCmd21 extends AbsEBikeMessage {
|
||||
|
||||
byte[] statusBytes = BytesUtil.copyBytes(dataBytes, 3, this.portNumber);
|
||||
List<String> statusList = Lists.newArrayList();
|
||||
List<String> statusDescList = Lists.newArrayList();
|
||||
for (byte statusByte : statusBytes) {
|
||||
int status = BytesUtil.bytesToIntLittle(new byte[]{statusByte});
|
||||
statusList.add(PortStatusEnum.getDescriptionByValue(status));
|
||||
statusList.add(String.valueOf(status));
|
||||
statusDescList.add(PortStatusEnum.getDescriptionByValue(status));
|
||||
}
|
||||
this.portStatus = statusList;
|
||||
this.statusDescList = statusDescList;
|
||||
this.rssi = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 2, dataBytes.length - 1)) + "";
|
||||
//
|
||||
int i = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 1, dataBytes.length));
|
||||
|
||||
Reference in New Issue
Block a user