sw值解析bug修复
This commit is contained in:
parent
5cfb6858ca
commit
19877b00f0
@ -2,8 +2,6 @@ package com.cdzy.common.model;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author attiya
|
* @author attiya
|
||||||
* @since 2025-03-20
|
* @since 2025-03-20
|
||||||
|
|||||||
@ -13,8 +13,6 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.data.geo.Point;
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author attiya
|
* @author attiya
|
||||||
@ -46,7 +44,9 @@ public class ReoprtHandler {
|
|||||||
|
|
||||||
public void gpsMsgHandler(JSONObject param, String deviceId) {
|
public void gpsMsgHandler(JSONObject param, String deviceId) {
|
||||||
Integer number = param.getInteger("sw");
|
Integer number = param.getInteger("sw");
|
||||||
String binary = BinaryUtil.to28BitBinary(number);
|
String binary = BinaryUtil.to32BitBinary(number);
|
||||||
|
//修复高低bug
|
||||||
|
binary = new StringBuilder(binary).reverse().toString();
|
||||||
char helmet = binary.charAt(BitSwitch.IS_HELMET_EXIT);
|
char helmet = binary.charAt(BitSwitch.IS_HELMET_EXIT);
|
||||||
char acc = binary.charAt(BitSwitch.ACC_ON);
|
char acc = binary.charAt(BitSwitch.ACC_ON);
|
||||||
char wheelLocked = binary.charAt(BitSwitch.IS_WHEEL_LOCKED);
|
char wheelLocked = binary.charAt(BitSwitch.IS_WHEEL_LOCKED);
|
||||||
|
|||||||
@ -6,19 +6,18 @@ package com.cdzy.ebikereport.utils;
|
|||||||
*/
|
*/
|
||||||
public class BinaryUtil {
|
public class BinaryUtil {
|
||||||
/**
|
/**
|
||||||
* 将整数转换为28位二进制字符串,高位补零
|
* 将整数转换为32位二进制字符串
|
||||||
* @param number 输入数字(范围0 ~ 2^28-1)
|
* @param number 输入数字
|
||||||
* @return 28位二进制字符串
|
* @return 32位二进制字符串
|
||||||
* @throws IllegalArgumentException 输入超出范围时抛出异常
|
|
||||||
*/
|
*/
|
||||||
public static String to28BitBinary(int number) {
|
public static String to32BitBinary(int number) {
|
||||||
// 验证范围:0 ≤ number ≤ 268,435,455 (即2^28 -1)
|
String binaryStr = Integer.toBinaryString(number);
|
||||||
if (number < 0 || number > 0x1FFFFFFF) {
|
|
||||||
throw new IllegalArgumentException("输入数值超出28位无符号范围: " + number);
|
// 补零到32位
|
||||||
|
if (binaryStr.length() < 32) {
|
||||||
|
return "0".repeat(32 - binaryStr.length()) + binaryStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换为二进制并补零至28位
|
return binaryStr;
|
||||||
String binaryStr = Integer.toBinaryString(number);
|
|
||||||
return "0".repeat(29 - binaryStr.length()) + binaryStr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user