public void LoadFromStream(BinaryReader br) { Clear(); int cnt = br.ReadInt32(); if ((cnt > MAX_ITEMS_COUNT) || (cnt < 0)) { throw new Exception("Ошибка формата файла"); } for (int i = 0; i < cnt; i++) { DpkWordItem dp = new DpkWordItem(); dp.LoadFromStream(br); data_buf.Add(dp); } }
private void ParseData() { UInt32 u32; byte flags, mask; int cnt = raw_buf.Length; isOkData = false; dpk_buf.Clear(); try { using (BinaryReader br = new BinaryReader(new MemoryStream(raw_buf))) { code_msg = br.ReadByte(); switch (code_msg) { case CODES_MSG_ARINC.CODE_MSG_ERR: if (cnt < 5) { return; } { DpkWordItem dpk = new DpkWordItem(); u32 = br.ReadUInt32(); dpk.Time = new TimeSpan(u32 * 10000); dpk.Flags = DpkDataConstants.ERROR_FLAG; dpk_buf.Add(dpk); } return; case CODES_MSG_ARINC.CODE_MSG_DATA: { flags = br.ReadByte(); cnt = (cnt - 2) / 8; // количество слов ДПК mask = 1; for (int i = 0; i < cnt; i++) { DpkWordItem dpk = new DpkWordItem(); u32 = br.ReadUInt32(); dpk.Time = new TimeSpan(u32 * 10000); u32 = br.ReadUInt32(); dpk.ADR = (int)(u32 & 0xFF); dpk.DATA = (int)((u32 >> 8) & 0xFFFFFF); dpk.Flags = ((mask & flags) != 0) ? 1 : 0; mask <<= 1; dpk_buf.Add(dpk); } } break; case CODES_MSG_ARINC.CODE_MSG_ANSWER: if (cnt < 2) { return; } { DpkWordItem dpk = new DpkWordItem(); dpk.ADR = br.ReadByte(); if (cnt == 3) { dpk.DATA = br.ReadByte(); } dpk.Time = new TimeSpan(0); dpk_buf.Add(dpk); } break; case CODES_MSG_ARINC.CODE_MSG_OVER: if (cnt < 5) { return; } { DpkWordItem dpk = new DpkWordItem(); u32 = br.ReadUInt32(); dpk.Time = new TimeSpan(u32 * 10000); dpk.Flags = DpkDataConstants.OVERFLOW_FLAG; dpk_buf.Add(dpk); } break; default: return; } } isOkData = true; } catch { isOkData = false; } }
public DpkWord(DpkWordItem dpk) { adr = (uint)dpk.ADR; data = (uint)dpk.DATA; }