V1.0.1.8 -- 2025/12/20
* BMS History Function Improved
This commit is contained in:
@@ -208,6 +208,29 @@ namespace LFP_Manager.Utils
|
||||
byte[] StrByte = Encoding.UTF8.GetBytes(str); return StrByte;
|
||||
}
|
||||
|
||||
public static short[] ByteArrTo2ShortSafe(byte[] bytes)
|
||||
{
|
||||
if (bytes == null || bytes.Length < 5) return null; // addr+func+len+crc 최소
|
||||
int byteCount = bytes[2];
|
||||
|
||||
// byteCount가 짝수인지 확인(레지스터는 2바이트 단위)
|
||||
if ((byteCount % 2) != 0) return null;
|
||||
|
||||
// 데이터 영역 + CRC(2byte)까지 길이 확인
|
||||
int minLen = 3 + byteCount + 2;
|
||||
if (bytes.Length < minLen) return null;
|
||||
|
||||
int regCount = byteCount / 2;
|
||||
var result = new short[regCount];
|
||||
|
||||
for (int i = 0; i < regCount; i++)
|
||||
{
|
||||
int idx = 3 + i * 2;
|
||||
result[i] = (short)((bytes[idx] << 8) | bytes[idx + 1]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region OPERATING WARNING FUCTION
|
||||
|
||||
public static bool BitCheck(short rData, int pos)
|
||||
|
||||
Reference in New Issue
Block a user