update 电单车协议

This commit is contained in:
Guoqs
2024-09-19 14:58:48 +08:00
parent 0ca737e195
commit 6f46dfff4a
3 changed files with 68 additions and 1 deletions

View File

@@ -0,0 +1,52 @@
package com.jsowell.common.enums.ebike;
public enum EBikeChargeCommandResponse {
SUCCESS(0, "执行成功(启动或停止充电)"),
NO_CHARGER_PLUGGED(1, "端口未插充电器(不执行)"),
SAME_PORT_STATE(2, "端口状态和充电命令相同(不执行)"),
PORT_FAULT(3, "端口故障(执行)"),
INVALID_PORT_NUMBER(4, "无此端口号(不执行)"),
// 响应FF充电命令不执行只针对双路双路设备的二维码只有一个且端口号为FF当2个口都插了充电器服务器下发充电端口为FF时设备检测到有2个口待充电不知道充哪个就会返回此应答
MULTIPLE_PENDING_PORTS(5, "有多个待充端口"),
POWER_EXCEEDED(6, "多路设备功率超标(不执行)");
private final int code;
private final String description;
EBikeChargeCommandResponse(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static EBikeChargeCommandResponse fromCode(int code) {
for (EBikeChargeCommandResponse response : values()) {
if (response.getCode() == code) {
return response;
}
}
throw new IllegalArgumentException("Invalid code: " + code);
}
public static String getDescriptionByCode(int code) {
try {
EBikeChargeCommandResponse response = fromCode(code);
return response.getDescription();
} catch (IllegalArgumentException e) {
return "未知应答码: " + code;
}
}
}