mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-02 21:18:05 +08:00
update 电单车协议
This commit is contained in:
@@ -83,7 +83,7 @@ public class TempController extends BaseController {
|
|||||||
public RestApiResponse<?> tempStartCharging(@RequestBody QueryOrderDTO dto) {
|
public RestApiResponse<?> tempStartCharging(@RequestBody QueryOrderDTO dto) {
|
||||||
RestApiResponse<?> response = null;
|
RestApiResponse<?> response = null;
|
||||||
try {
|
try {
|
||||||
eBikeSendCommandService.startCharging(dto.getPileSn());
|
eBikeSendCommandService.startCharging(dto.getPileSn(), dto.getConnectorCode());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("电单车开始充电 error", e);
|
logger.error("电单车开始充电 error", e);
|
||||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_FAILED);
|
response = new RestApiResponse<>(ReturnCodeEnum.CODE_FAILED);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.jsowell.common;
|
package com.jsowell.common;
|
||||||
|
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
|
import com.jsowell.common.util.YKCUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -87,4 +88,49 @@ public class YouDianUtils {
|
|||||||
int calculatedChecksum = calculateCheckField(bytes);
|
int calculatedChecksum = calculateCheckField(bytes);
|
||||||
return BytesUtil.intToBytesLittle(calculatedChecksum);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ package com.jsowell.pile.service;
|
|||||||
public interface EBikeSendCommandService {
|
public interface EBikeSendCommandService {
|
||||||
// void send(String pileSn, AbsEBikeMessage msg);
|
// void send(String pileSn, AbsEBikeMessage msg);
|
||||||
|
|
||||||
void startCharging(String pileSn);
|
void startCharging(String pileSn, String connectorCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.jsowell.pile.service.impl;
|
|||||||
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
import com.jsowell.common.util.RandomUtil;
|
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.AbsEBikeMessage;
|
||||||
import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82;
|
import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82;
|
||||||
import com.jsowell.pile.service.EBikeSendCommandService;
|
import com.jsowell.pile.service.EBikeSendCommandService;
|
||||||
@@ -15,20 +16,31 @@ import java.util.Objects;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
|
public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startCharging(String pileSn) {
|
public void startCharging(String pileSn, String connectorCode) {
|
||||||
EBikeMessageCmd82 message = new EBikeMessageCmd82();
|
EBikeMessageCmd82 message = new EBikeMessageCmd82();
|
||||||
message.setHeader("DNY");
|
message.setHeader("DNY");
|
||||||
message.setPhysicalId(Integer.parseInt(pileSn));
|
message.setPhysicalId(Integer.parseInt(pileSn));
|
||||||
message.setMessageId(RandomUtil.getRandomNumber(4));
|
message.setMessageId(RandomUtil.getRandomNumber(4));
|
||||||
message.setCommand("82");
|
message.setCommand("82");
|
||||||
|
|
||||||
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
|
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
|
||||||
|
// 充电模式
|
||||||
data.setRateMode("3");
|
data.setRateMode("3");
|
||||||
|
// 余额或有效期
|
||||||
data.setBalanceOrValidity("0");
|
data.setBalanceOrValidity("0");
|
||||||
|
// 端口号
|
||||||
data.setPortNumber("0");
|
data.setPortNumber("0");
|
||||||
|
// 充电命令
|
||||||
data.setChargeCommand("1");
|
data.setChargeCommand("1");
|
||||||
|
// 充电时长/功率
|
||||||
data.setChargeDurationOrPower("0");
|
data.setChargeDurationOrPower("0");
|
||||||
data.setOrderNumber("0");
|
|
||||||
|
// 订单编号
|
||||||
|
String orderNumber = IdUtils.generateTransactionCode(pileSn, connectorCode);
|
||||||
|
data.setOrderNumber(orderNumber);
|
||||||
|
|
||||||
data.setMaxChargeDuration("0");
|
data.setMaxChargeDuration("0");
|
||||||
data.setOverloadPower("0");
|
data.setOverloadPower("0");
|
||||||
data.setQrCodeLight("0");
|
data.setQrCodeLight("0");
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
|
|||||||
CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(Double.parseDouble(pileStationInfo.getStationLng()), Double.parseDouble(pileStationInfo.getStationLat()));
|
CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(Double.parseDouble(pileStationInfo.getStationLng()), Double.parseDouble(pileStationInfo.getStationLat()));
|
||||||
vo.setStationLat(String.format("%.6f", coordinate.getLat()));
|
vo.setStationLat(String.format("%.6f", coordinate.getLat()));
|
||||||
vo.setStationLng(String.format("%.6f", coordinate.getLng()));
|
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());
|
vo.setCountryCode(pileStationInfo.getCountryCode());
|
||||||
|
|||||||
Reference in New Issue
Block a user