Пример #1
0
        public byte[] CreateTestPacket()
        {
            try
            {
                LIVE_VIEW_COMBINED_PACKET_STRUCT pkt = new LIVE_VIEW_COMBINED_PACKET_STRUCT();

                pkt.InfoString             = "kjhaksjdfhalksjdfhlaksjdf";
                pkt.header.PACKET_TYPE     = (int)PACKET_TYPES.SEND_LIVE_VIEW;
                pkt.header.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                pkt.header.PasswordHash    = "502834750293845";
                pkt.header.START_OF_PACKET = 0xaa55aa55;

                byte[] bytes = new byte[Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT))];

                GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                Marshal.StructureToPtr(pkt, handle.AddrOfPinnedObject(), true);
                handle.Free();

                return(bytes);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
Пример #2
0
        public byte[] CreatePacket(string remoteHostIP, PACKET_TYPES type, string ViewerPassword, string jpegInfo)
        {
            if (remoteHostIP == null)
            {
                remoteHostIP = " ";
            }
            if (ViewerPassword == null)
            {
                ViewerPassword = "******";
            }

            try
            {
                byte[] bytes = null;

                switch (type)
                {
                case PACKET_TYPES.REQUEST_LIVE_VIEW:
                {
                    LIVE_VIEW_COMBINED_PACKET_STRUCT pkt = new LIVE_VIEW_COMBINED_PACKET_STRUCT();

                    pkt.InfoString         = jpegInfo;
                    pkt.header.PACKET_TYPE = (uint)type;
                    pkt.header.PACKET_LEN  = (uint)(Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT)) - Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT)));

                    pkt.header.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;

                    byte   seqNum  = (byte)(pkt.header.SEQUENCE_NUMBER & 0xff);
                    string seqNumS = seqNum.ToString();
                    pkt.header.PasswordHash    = EncyptGetHostPassword(ViewerPassword + "," + seqNumS);
                    pkt.header.START_OF_PACKET = 0xaa55aa55;



                    bytes = new byte[Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(pkt, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.REQUEST_HOST_NAME:
                {
                    REQUEST_HOST_NAME pkt = new REQUEST_HOST_NAME();


                    pkt.header.PACKET_TYPE     = (int)PACKET_TYPES.REQUEST_HOST_NAME;
                    pkt.header.PACKET_LEN      = (uint)0;
                    pkt.header.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    byte   seqNum  = (byte)(pkt.header.SEQUENCE_NUMBER & 0xff);
                    string seqNumS = seqNum.ToString();
                    pkt.header.PasswordHash    = EncyptGetHostPassword(remoteHostIP + "," + seqNumS);
                    pkt.header.START_OF_PACKET = 0xaa55aa55;

                    bytes = new byte[Marshal.SizeOf(typeof(REQUEST_HOST_NAME))];

                    GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(pkt, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;
                }
                return(bytes);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
Пример #3
0
        public byte[] CreatePacket(PACKET_TYPES type, byte[] data, string jpegInfo)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.SEND_LIVE_VIEW:
                {
                    LIVE_VIEW_COMBINED_PACKET_STRUCT pkt = new LIVE_VIEW_COMBINED_PACKET_STRUCT();         // live view packet includes the common header

                    pkt.InfoString         = jpegInfo;
                    pkt.header.PACKET_TYPE = (uint)type;

                    pkt.header.START_OF_PACKET = 0xaa55aa55;

                    pkt.header.PACKET_LEN = (uint)(Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT)) - Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))); // just the live view specific header bytes

                    pkt.JPEG_LENGTH = (uint)data.Length;                                                                                                     // the rest of the payload after the live view specific header bytes

                    //     pkt.header.PACKET_LEN = (uint)(data.Length + Marshal.SizeOf(typeof(LIVE_VIEW_PACKET)) - Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT)));

                    pkt.header.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;

                    byte   seqNum  = (byte)(pkt.header.SEQUENCE_NUMBER & 0xff);
                    string seqNumS = seqNum.ToString();
                    pkt.header.PasswordHash = " ";         // no outbound pw


                    // copy the combined headers  to the bytes array

                    hdrBytes = new byte[Marshal.SizeOf(typeof(LIVE_VIEW_COMBINED_PACKET_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(pkt, handle.AddrOfPinnedObject(), true);
                    handle.Free();

                    packet = new byte[hdrBytes.Length + data.Length];

                    int i = 0;
                    for (i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }

                    for (i = hdrBytes.Length; i < hdrBytes.Length + data.Length; i++)
                    {
                        packet[i] = data[i - hdrBytes.Length];
                    }
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }