Example #1
0
        public WiFiDeviceGateway(string ovrDeviceHostname, bool scentActivationLogging = false, int localhostDebugPort = 0)
        {
            _socketSender      = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _ovrDeviceHostname = ovrDeviceHostname;
            _socketRecieveState.ovrHostname = _ovrDeviceHostname;
            _socketRecieveState.udpClient   = new UdpClient(0, AddressFamily.InterNetwork);

            var localIp = IPAddressExtensions.GetLocalIP();

            UnityEngine.Debug.LogFormat("<b>[OVR]</b> Local IP: {0}", localIp);

            if (scentActivationLogging)
            {
                _scentActivationLog = new NetworkLogging(localhostDebugPort);
            }

            _socketRecievePort = ((IPEndPoint)_socketRecieveState.udpClient.Client.LocalEndPoint).Port;

            // Setup for broadcasting hostname request from device
            MarshalHeader.Set(ref _checkConnectionPacket, MessageTypes.DEVICE_HOSTNAME_REQUEST, sizeof(ushort));
            _checkConnectionPacket[MarshalHeader.Size]     = (byte)_socketRecievePort;
            _checkConnectionPacket[MarshalHeader.Size + 1] = (byte)(_socketRecievePort >> 8);
            _onConnect    += OnConnect;
            _onDisconnect += OnDisconnect;
        }
Example #2
0
 public void OnConnect(IPEndPoint ip)
 {
     lock (_asyncLock)
     {
         _currentDeviceEndPoint = ip;
         MarshalHeader.Set(ref _packet, MessageTypes.DEVICE_DEBUGMODE_REQUEST);
         _socketSender.SendTo(_packet, MarshalHeader.Size, SocketFlags.None, _currentDeviceEndPoint);
     }
 }
Example #3
0
        public byte[] CommandsToPacket()
        {
            int index = MarshalHeader.Size;

            MarshalHeader.Set(ref _packet, MessageTypes.ODORANT_COMMANDS, (ushort)(_commands.Count * OdorantCommand.Size));

            foreach (var command in _commands)
            {
                Array.Copy(command.GetPacket(), 0, _packet, index, OdorantCommand.Size);
                index += OdorantCommand.Size;
            }

            return(_packet);
        }
Example #4
0
        public static void Set(ref byte[] buffer, MessageTypes messageType, ushort messageSize = 0)
        {
            MarshalHeader header = new MarshalHeader(messageType, messageSize);

            header.ToBytes(ref buffer);
        }