-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decode v2021 frames #52
Open
syssi
wants to merge
1
commit into
main
Choose a base branch
from
decode-v2021-frames
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syssi
force-pushed
the
decode-v2021-frames
branch
from
March 7, 2023 13:42
a7e26ad
to
3358a9c
Compare
syssi
force-pushed
the
decode-v2021-frames
branch
from
March 7, 2023 20:46
f084d0a
to
66c94f1
Compare
This a proper way to decode new style frames, maybe you will find it useful: public static RegisterData AntProtocol_FixedParse(byte[] dataBuf)
{
RegisterData registerData = new RegisterData();
registerData.MsgType = 1;
registerData.SysOperationAuth = dataBuf[6];
registerData.SystemState = dataBuf[7];
registerData.Temperature_Num = dataBuf[8];
registerData.PACK_Cell_Num = dataBuf[9];
registerData.ProtectMack_Bit = BitConverter.ToUInt64(dataBuf, 10);
registerData.WarningMack_Bit = BitConverter.ToUInt64(dataBuf, 18);
registerData.PushMack_Bit = BitConverter.ToUInt64(dataBuf, 26);
int index = 34; // Starting index
for (byte i = 0; i < registerData.PACK_Cell_Num; ++i)
{
registerData.Voltage_Cell_Value[i] = BitConverter.ToUInt16(dataBuf, index);
index += 2;
}
for (byte i = 0; i < registerData.Temperature_Num; ++i)
{
registerData.Temperature_Value[i] = BitConverter.ToInt16(dataBuf, index);
index += 2;
}
registerData.Temperature_MOS = BitConverter.ToInt16(dataBuf, index); index += 2;
registerData.Temperature_Balance = BitConverter.ToInt16(dataBuf, index); index += 2;
registerData.Voltage_Pack = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Current_Value = BitConverter.ToInt16(dataBuf, index); index += 2;
registerData.Pack_SOC = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Pack_SOH = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.DIS_MOS_State = dataBuf[index++];
registerData.CH_MOS_State = dataBuf[index++];
registerData.Balance_State = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Pack_Physics_AH = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.Pack_Remain_AH = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.Pack_All_AH = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.Pack_Power = BitConverter.ToInt32(dataBuf, index); index += 4;
registerData.All_Timer_ms = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.Balance_State_Bit = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.Voltage_Cell_Max_Value = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_Cell_Max_Pos = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_Cell_Min_Value = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_Cell_Min_Pos = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_Cell_Difference = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_Cell_Average_Value = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_DS_Value = BitConverter.ToInt16(dataBuf, index); index += 2;
registerData.Voltage_DIS_MOS_Value = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_CH_MOS_Value = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Voltage_NH_MOS_Value = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.PackCellType = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.Pack_All_DisAH = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.Pack_All_ChAH = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.All_DisTimer_s = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.All_ChTimer_s = BitConverter.ToUInt32(dataBuf, index); index += 4;
if (dataBuf[5] > registerData.PACK_Cell_Num * 2 + registerData.Temperature_Num * 2 + 106)
{
registerData.CHG_duration = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.CHG_interval = BitConverter.ToUInt32(dataBuf, index); index += 4;
registerData.CT_remaining = BitConverter.ToUInt16(dataBuf, index); index += 2;
registerData.RT_discharge = BitConverter.ToUInt16(dataBuf, index); index += 2;
}
else if (dataBuf[2] == 18 || dataBuf[2] == 66) {
registerData.MsgType = 2;
byte[] numArray123 = new byte[16];
byte num324 = dataBuf[2];
ushort num325 = (ushort) (((uint) (ushort) dataBuf[4] << 8) + (uint) dataBuf[3]);
byte num326 = dataBuf[5];
ushort[] numArray124 = new ushort[256];
for (int newIndex = 0; newIndex < (int) num326; newIndex += 2)
{
ushort num327 = (ushort) ((uint) (ushort) ((uint) (ushort) dataBuf[newIndex + 7] << 8) + (uint) dataBuf[newIndex + 6]);
numArray124[(newIndex + (int) num325) / 2] = num327;
}
registerData.MsgData = numArray124;
}
if (dataBuf[2] == byte.MaxValue) {
ushort num328 = (ushort) (((uint) (ushort) dataBuf[11] << 8) + (uint) dataBuf[12]);
byte[] numArray = new byte[16]
{
(byte) ((uint) dataBuf[2] >> 4),
(byte) ((uint) dataBuf[2] & 15U),
(byte) ((uint) dataBuf[3] >> 4),
(byte) ((uint) dataBuf[3] & 15U),
(byte) ((uint) dataBuf[4] >> 4),
(byte) ((uint) dataBuf[4] & 15U),
(byte) ((uint) dataBuf[5] >> 4),
(byte) ((uint) dataBuf[5] & 15U),
(byte) ((uint) dataBuf[6] >> 4),
(byte) ((uint) dataBuf[6] & 15U),
(byte) ((uint) dataBuf[7] >> 4),
(byte) ((uint) dataBuf[7] & 15U),
(byte) ((uint) dataBuf[8] >> 4),
(byte) ((uint) dataBuf[8] & 15U),
(byte) ((uint) dataBuf[9] >> 4),
(byte) ((uint) dataBuf[9] & 15U)
};
registerData.Warning = (int) num328;
}
return registerData;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Battery types
Battery status
Charge Mosfet Status
Discharge Mosfet Status