private void EnqueueDis(byte[] disPduData) { this.stevec++; PduProcessor disPduProcessor = new PduProcessor(); if (disPduData != null && disPduData.Length > 0) { try { List <object> disObjPDUs = disPduProcessor.ProcessPdu(disPduData, Endian.Big); foreach (object newObjPDU in disObjPDUs) { Pdu newPdu = newObjPDU as OpenDis.Dis1998.Pdu; if (newPdu != null) { lock (((ICollection)pduQueue).SyncRoot) { this.pduQueue.Enqueue(newPdu); } } } } catch (Exception err) { Debug.Log(err.ToString()); } } }
private static void ReceiveBroadcastMessages() { bool done = false; byte[] bytes = new Byte[10000]; int length = 0; PduProcessor pduProcessor = new PduProcessor(); //PduProcessor could use some work and move towards all static methods (PduXmlDecode is instance method) pduProcessor.Endian = Endian.Big; //DIS use Big Endian format List <object> pduList; try { while (!done) { Console.WriteLine("Waiting for packets......."); Console.WriteLine("Enter ^C to terminate."); length = mcastSocket.ReceiveFrom(bytes, ref remoteEP); Console.WriteLine("Received broadcast from {0} :\n Bytes:{1}\n", remoteEP.ToString(), length); Console.WriteLine("________________________________\n"); //Decode only 1 PDU //Pdu pdu = PduProcessor.ConvertByteArrayToPdu1998(bytes[2], bytes, Endian.Big); //Console.WriteLine("Received PDU Info {0} :\n ", pduProcessor.XmlDecodePdu(pdu)); //Console.WriteLine("*******************************\n"); //Could be many PDU received in datagram packet so be safe and get list pduList = pduProcessor.ProcessPdu(bytes, Endian.Big); Console.WriteLine("Received PDU List Size:[{0}]\n ", pduList.Count); Console.WriteLine("________________________________\n"); foreach (object pduObj in pduList) { //Both of below work fine //Console.WriteLine("Received PDU List Info {0} :\n ", PduProcessor.DecodePdu(pduObj).ToString()); Console.WriteLine("Received PDU List XML Info {0} :\n ", pduProcessor.XmlDecodePdu(pduObj)); Console.WriteLine("*******************************\n"); } } mcastSocket.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }