diff --git a/aspnetapp/WINGS/Services/TMTC/Processor/Abstracts/TmPacketAnalyzerBase.cs b/aspnetapp/WINGS/Services/TMTC/Processor/Abstracts/TmPacketAnalyzerBase.cs index 1fe6670..033ff6e 100644 --- a/aspnetapp/WINGS/Services/TMTC/Processor/Abstracts/TmPacketAnalyzerBase.cs +++ b/aspnetapp/WINGS/Services/TMTC/Processor/Abstracts/TmPacketAnalyzerBase.cs @@ -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(); }