Skip to content

Commit

Permalink
fix way to generate defraw
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMochizuki committed Feb 7, 2023
1 parent ed199b1 commit dbcbd2b
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,31 @@ private void SetValue(Telemetry tlm, byte[] packet)
else
{
// int bytenum = (tlm.TelemetryInfo.BitPos + tlm.TelemetryInfo.BitLen - 1) / 8 + 1;
Byte octetNum = (Byte)((tlm.TelemetryInfo.BitPos + tlm.TelemetryInfo.BitLen + 7) / 8);
uint mask = (uint)(((1 << tlm.TelemetryInfo.BitLen) - 1) << (octetNum * 8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
if (tlm.TelemetryInfo.BitLen < 9)
{
Byte mask = (Byte)(((1 << tlm.TelemetryInfo.BitLen) - 1) << (8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
Byte defraw = (Byte)((Byte)(packet[tlm.TelemetryInfo.OctetPos + tlm.TelemetryInfo.BitPos / 8] & mask) >> (8 + (tlm.TelemetryInfo.BitPos / 8) * 8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
UInt16 raw = (octetNum > (tlm.TelemetryInfo.BitPos + 7) / 8) ?
(UInt16)(packet[tlm.TelemetryInfo.OctetPos + octetNum - 2] << 8 | packet[tlm.TelemetryInfo.OctetPos + octetNum - 1]) :
(UInt16)(packet[tlm.TelemetryInfo.OctetPos + octetNum - 1]);
Byte defraw = (Byte)((uint)(raw & mask) >> (octetNum * 8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
tlm.TelemetryValue.Value = ConvertValue(defraw, tlm, tlm.TelemetryInfo.BitLen);
tlm.TelemetryValue.RawValue = defraw.ToString();
}
else if (tlm.TelemetryInfo.BitLen < 17)
{
UInt16 mask = (UInt16)(((1 << tlm.TelemetryInfo.BitLen) - 1) << (16 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
UInt16 raw = (UInt16)(packet[tlm.TelemetryInfo.OctetPos + tlm.TelemetryInfo.BitPos / 8] << 8 | packet[tlm.TelemetryInfo.OctetPos + tlm.TelemetryInfo.BitPos / 8 + 1]);
UInt16 defraw = (UInt16)((UInt16)(raw & mask) >> (16 + (tlm.TelemetryInfo.BitPos / 8) * 8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
uint raw = (octetNum > (tlm.TelemetryInfo.BitPos + 7) / 8) ?
(uint)(packet[tlm.TelemetryInfo.OctetPos + octetNum - 3] << 16 | packet[tlm.TelemetryInfo.OctetPos + octetNum - 2] << 8 | packet[tlm.TelemetryInfo.OctetPos + octetNum - 1]) :
(uint)(packet[tlm.TelemetryInfo.OctetPos + octetNum - 2] << 8 | packet[tlm.TelemetryInfo.OctetPos + octetNum - 1]);
UInt16 defraw = (UInt16)((uint)(raw & mask) >> (octetNum * 8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
tlm.TelemetryValue.Value = ConvertValue(defraw, tlm, tlm.TelemetryInfo.BitLen);
tlm.TelemetryValue.RawValue = defraw.ToString();
}
else
{
UInt32 mask = (UInt32)(((1 << tlm.TelemetryInfo.BitLen) - 1) << (32 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
UInt32 raw = (UInt32)(packet[tlm.TelemetryInfo.OctetPos + tlm.TelemetryInfo.BitPos / 8] << 24 | packet[tlm.TelemetryInfo.OctetPos + tlm.TelemetryInfo.BitPos / 8 + 1] << 16
| packet[tlm.TelemetryInfo.OctetPos + tlm.TelemetryInfo.BitPos / 8 + 2] << 8 | packet[tlm.TelemetryInfo.OctetPos + tlm.TelemetryInfo.BitPos / 8 + 3]);
UInt32 defraw = (UInt32)((UInt32)(raw & mask) >> (32 + (tlm.TelemetryInfo.BitPos / 8) * 8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
uint raw = (uint)(packet[tlm.TelemetryInfo.OctetPos + octetNum - 4] << 24 | packet[tlm.TelemetryInfo.OctetPos + octetNum - 3] << 16
| packet[tlm.TelemetryInfo.OctetPos + octetNum - 2] << 8 | packet[tlm.TelemetryInfo.OctetPos + octetNum - 1]);
UInt32 defraw = (UInt32)((uint)(raw & mask) >> (octetNum * 8 - tlm.TelemetryInfo.BitPos - tlm.TelemetryInfo.BitLen));
tlm.TelemetryValue.Value = ConvertValue(defraw, tlm, tlm.TelemetryInfo.BitLen);
tlm.TelemetryValue.RawValue = defraw.ToString();
}
Expand Down

0 comments on commit dbcbd2b

Please sign in to comment.