update 电单车协议

This commit is contained in:
Guoqs
2024-09-03 11:41:33 +08:00
parent 18de552bbc
commit f729431d7d
5 changed files with 63 additions and 5 deletions

View File

@@ -83,7 +83,7 @@ public class TempController extends BaseController {
public RestApiResponse<?> tempStartCharging(@RequestBody QueryOrderDTO dto) {
RestApiResponse<?> response = null;
try {
eBikeSendCommandService.startCharging(dto.getPileSn());
eBikeSendCommandService.startCharging(dto.getPileSn(), dto.getConnectorCode());
} catch (Exception e) {
logger.error("电单车开始充电 error", e);
response = new RestApiResponse<>(ReturnCodeEnum.CODE_FAILED);

View File

@@ -1,6 +1,7 @@
package com.jsowell.common;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
@@ -87,4 +88,49 @@ public class YouDianUtils {
int calculatedChecksum = calculateCheckField(bytes);
return BytesUtil.intToBytesLittle(calculatedChecksum);
}
// public static String convertPortNumberToHex(int portNumber) {
// if (portNumber < 1 || portNumber > 16) {
// throw new IllegalArgumentException("Port number must be between 1 and 16.");
// }
//
// // 端口号从1开始因此需要减去1
// int hexValue = portNumber - 1;
//
// // 转换为16进制字符串并确保长度为2位
// String hexString = String.format("0x%02X", hexValue);
//
// return hexString;
// }
public static byte[] convertPortNumberToBytes(int portNumber) {
if (portNumber < 1 || portNumber > 16) {
throw new IllegalArgumentException("Port number must be between 1 and 16.");
}
// 端口号从1开始因此需要减去1
int hexValue = portNumber - 1;
// 转换为字节数组
byte[] bytes = new byte[2];
bytes[0] = (byte) 0x00; // 前缀0x
bytes[1] = (byte) hexValue;
return bytes;
}
public static void main(String[] args) {
byte[] result1 = convertPortNumberToBytes(1); // 输出: [0, 0]
byte[] result2 = convertPortNumberToBytes(2); // 输出: [0, 1]
byte[] result10 = convertPortNumberToBytes(10); // 输出: [0, 9]
byte[] result11 = convertPortNumberToBytes(11); // 输出: [0, 10]
byte[] result16 = convertPortNumberToBytes(16); // 输出: [0, 15]
// 打印结果
System.out.println(YKCUtils.frameType2Str(result1));
System.out.println(YKCUtils.frameType2Str(result2));
System.out.println(YKCUtils.frameType2Str(result10));
System.out.println(YKCUtils.frameType2Str(result11));
System.out.println(YKCUtils.frameType2Str(result16));
}
}

View File

@@ -6,5 +6,5 @@ package com.jsowell.pile.service;
public interface EBikeSendCommandService {
// void send(String pileSn, AbsEBikeMessage msg);
void startCharging(String pileSn);
void startCharging(String pileSn, String connectorCode);
}

View File

@@ -3,6 +3,7 @@ package com.jsowell.pile.service.impl;
import com.jsowell.common.enums.ykc.PileChannelEntity;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.RandomUtil;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82;
import com.jsowell.pile.service.EBikeSendCommandService;
@@ -15,20 +16,31 @@ import java.util.Objects;
@Slf4j
@Service
public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
@Override
public void startCharging(String pileSn) {
public void startCharging(String pileSn, String connectorCode) {
EBikeMessageCmd82 message = new EBikeMessageCmd82();
message.setHeader("DNY");
message.setPhysicalId(Integer.parseInt(pileSn));
message.setMessageId(RandomUtil.getRandomNumber(4));
message.setCommand("82");
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
// 充电模式
data.setRateMode("3");
// 余额或有效期
data.setBalanceOrValidity("0");
// 端口号
data.setPortNumber("0");
// 充电命令
data.setChargeCommand("1");
// 充电时长/功率
data.setChargeDurationOrPower("0");
data.setOrderNumber("0");
// 订单编号
String orderNumber = IdUtils.generateTransactionCode(pileSn, connectorCode);
data.setOrderNumber(orderNumber);
data.setMaxChargeDuration("0");
data.setOverloadPower("0");
data.setQrCodeLight("0");

View File

@@ -193,7 +193,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(Double.parseDouble(pileStationInfo.getStationLng()), Double.parseDouble(pileStationInfo.getStationLat()));
vo.setStationLat(String.format("%.6f", coordinate.getLat()));
vo.setStationLng(String.format("%.6f", coordinate.getLng()));
log.info("高德坐标:{}, 转天地图坐标:{}", pileStationInfo.getStationLng() + ", " + pileStationInfo.getStationLat(), vo.getStationLng() + ", " + vo.getStationLat());
log.debug("高德坐标:{}, 转天地图坐标:{}", pileStationInfo.getStationLng() + ", " + pileStationInfo.getStationLat(), vo.getStationLng() + ", " + vo.getStationLat());
}
vo.setCountryCode(pileStationInfo.getCountryCode());