public static Tracking Parse(Byte[] input, Int32 offset) { var output = new Tracking(); output.GpsTime = TelematicsTime.Decode(BitConverter.ToUInt32(input, offset)); output.PositionLatitude = BitConverter.ToInt32(input, offset + 4) / 1e7; output.PositionLongitude = BitConverter.ToInt32(input, offset + 8) / 1e7; output.PositionAltitude = BitConverter.ToInt16(input, offset + 12); output.Speed = BitConverter.ToUInt16(input, offset + 14); output.SpeedAccuracy = input[16] * 10 / 100; output.Heading = input[17] * 2; output.PDOP = input[18] / 10; output.PositionAccuracy = input[19]; output.IsValidFix = (input[20] & 0b00000001) > 0; // TODO: check this is what is meant by "b0" output.Is3DFix = (input[20] & 0b00000010) > 0; // TODO: check this is what is meant by "b1" return(output); }
public static Record Parse(Byte[] input, ref Int32 position) { var output = new Record(); var recordLength = BitConverter.ToUInt16(input, position); output.Sequence = BitConverter.ToUInt32(input, position + 2); output.RTCTime = TelematicsTime.Decode(BitConverter.ToUInt32(input, position + 6)); output.Reason = (Reasons)input[position + 10]; position += 11; var recordUsed = 0; while (recordUsed < recordLength) { var fieldId = (Fields)input[position]; var fieldLength = (UInt16)input[position + 1]; position += 2; if (fieldLength == Byte.MaxValue) { fieldLength = BitConverter.ToUInt16(input, position); position += 2; } var position2 = position; position += fieldLength; switch (fieldId) { case Fields.Tracking: output.TrackingFields.Add(Tracking.Parse(input, position2)); break; default: // Unknown message ignored break; } } return(output); }