public static int DSerializeData(byte[] buffers, List <CustomSyncMsg> customSyncMsgs) { var ms = new MemoryStream(buffers); var br = new BinaryReader(ms); List <DS_protocol.p_IdToFrames> idtofreames = new List <DS_protocol.p_IdToFrames>(); int nArea_id = br.ReadChar(); // int Frameindex = br.ReadInt16(); int msgCount = br.ReadInt16(); for (int nLoop = 0; nLoop < msgCount; nLoop++) { DS_protocol.p_IdToFrames TIdToFrame = new DS_protocol.p_IdToFrames(); var tms = DSerializeData(br, nArea_id); if (tms != null) { customSyncMsgs.Add(tms); } } br.Close(); ms.Close(); return(nArea_id); }
public static List <DS_protocol.p_IdToFrames> DSerializeData(byte[] buffers) { var ms = new MemoryStream(buffers); var br = new BinaryReader(ms); List <DS_protocol.p_IdToFrames> idtofreames = new List <DS_protocol.p_IdToFrames>(); int nAreaCount = br.ReadChar(); for (int nLoop = 0; nLoop < nAreaCount; nLoop++) { DS_protocol.p_IdToFrames TIdToFrame = new DS_protocol.p_IdToFrames(); TIdToFrame.areaid = br.ReadChar(); int nSyncFrameCount = br.ReadInt16(); int nStartIndex = 0; for (int i = 0; i < nSyncFrameCount; i++) { DS_protocol.p_SyncFrame TFrame = new DS_protocol.p_SyncFrame(); //TFrame.frame_count = br.ReadInt16(); if (i == 0) { nStartIndex = br.ReadInt16(); } int nFrameMsgCount = br.ReadChar(); TFrame.frame_count = nStartIndex++; SyncFrame cur = new SyncFrame(TFrame.frame_count, TIdToFrame.areaid); for (int msgLoop = 0; msgLoop < nFrameMsgCount; msgLoop++) { var tt = DSerializeData(ms, br); if (tt != null) { cur.msg_list.Add(tt); } } Serialization.Buffer_SyncFrame_msg_list(cur.msg_list, TFrame.msg_list); TIdToFrame.frames.Add(TFrame); } idtofreames.Add(TIdToFrame); } br.Close(); ms.Close(); return(idtofreames); }
public static bool Commpare(List <DS_protocol.p_IdToFrames> T1, List <DS_protocol.p_IdToFrames> T2) { if (T1.Count != T2.Count) { return(false); } for (int nLoop = 0; nLoop < T1.Count; ++nLoop) { DS_protocol.p_IdToFrames T1area_to_Frames = T1[nLoop]; DS_protocol.p_IdToFrames T2area_to_Frames = T2[nLoop]; if (T1area_to_Frames.areaid != T2area_to_Frames.areaid) { return(false); } for (int nLoop2 = 0; nLoop2 < T1area_to_Frames.frames.Count; ++nLoop2) { DS_protocol.p_SyncFrame T1p_syncFrame = T1area_to_Frames.frames[nLoop2]; DS_protocol.p_SyncFrame T2p_syncFrame = T2area_to_Frames.frames[nLoop2]; if (T1p_syncFrame.frame_count != T2p_syncFrame.frame_count) { return(false); } if (T1p_syncFrame.msg_list.Count != T2p_syncFrame.msg_list.Count) { return(false); } for (int nLoop3 = 0; nLoop3 < T1p_syncFrame.msg_list.Count; ++nLoop3) { DS_protocol.p_CustomSyncMsg T1Msg = T1p_syncFrame.msg_list[nLoop3]; DS_protocol.p_CustomSyncMsg T2Msg = T2p_syncFrame.msg_list[nLoop3]; if (!Commpare(T1Msg, T2Msg)) { return(false); } } } } return(true); }
void RecordFrames(List <DS_protocol.p_IdToFrames> areas_to_frames) { bRecordFrame = true; for (int nLoop = 0; nLoop < areas_to_frames.Count; ++nLoop) { DS_protocol.p_IdToFrames area_to_Frames = areas_to_frames[nLoop]; List <DS_protocol.p_SyncFrame> framesInfo = area_to_Frames.frames; if (framesInfo != null && framesInfo.Count > 0) { // Console.WriteLine(" recieve areaID " + area_to_Frames.areaid + " Frame start - to " + framesInfo[0].frame_count +"~" + framesInfo[framesInfo.Count-1].frame_count); //单位毫秒 foreach (DS_protocol.p_SyncFrame p_syncFrame in framesInfo) { int frame_count = p_syncFrame.frame_count; SyncFrame syncFrame = new SyncFrame(frame_count, area_to_Frames.areaid); syncFrame.msg_list = NetCommon.extract_msg(p_syncFrame.msg_list); areaManager.received_sync_frame(area_to_Frames.areaid, syncFrame); } } } }