private void OnDeviceCommand(_WP.IncomingMessage msg, bool fReply) { if (!fReply) { switch (msg.Header.m_cmd) { case _WP.Commands.c_Profiling_Stream: _WP.Commands.Profiling_Stream pay = (_WP.Commands.Profiling_Stream)msg.Payload; //Some sort of packet ordering with 'pay.seqId' to gurantee packets are need to arrived in the correct order and aren't lost. if (m_firstPacket) { m_firstPacket = false; m_lastSeenStreamPacketID = pay.seqId; } else { if (pay.seqId == 0) { //Sometimes the device manages to send out a packet before the device restarts and manages to throw off sequence id checking. m_lastSeenStreamPacketID = 0; } else { System.Diagnostics.Debug.Assert(pay.seqId == m_lastSeenStreamPacketID + 1); m_lastSeenStreamPacketID = pay.seqId; } } m_bitsReceived += pay.bitLen; m_incomingStream.AppendChunk(pay.payload, 0, pay.bitLen); break; } } }