示例#1
0
        /// <summary>
        /// Copy Constructor
        /// </summary>
        /// <param name="oscDeviceId">The Id of this osc device.</param>
        /// <param name="oscDevice">The osc device configuration of this osc device.</param>
        /// <param name="oscDeviceController">Controller to copy.</param>
        public OscDeviceController(Address oscDeviceId, OSCDevice oscDevice, OscDeviceController oscDeviceController)
        {
            this._oscDeviceId    = oscDeviceId;
            this._oscDevice      = oscDevice;
            this._protocolDriver = oscDeviceController._protocolDriver;
            this._protocolDriver.onZoneStatusUpdate   += new ProtocolZoneUpdatedEventHandler(_protocolDriver_onZoneStatusUpdate);
            this._protocolDriver.onDeviceStatusUpdate += new ProtocolDeviceUpdatedEventHandler(_protocolDriver_onDeviceStatusUpdate);
            this._oscDriver = new TouchOscDriver(oscDevice);
            this._oscDriver.onOscNuvoEventReceived += new OscEventReceivedEventHandler(_oscDriver_onOscNuvoEventReceived);
            this._zones   = oscDeviceController._zones;
            this._sources = oscDeviceController._sources;

            // Init "static" text (configuration data)
            updateConfigurationDataOnOscClient();
        }
示例#2
0
        /// <summary>
        /// Event method, to receive nuvo control messages from osc devices.
        /// This method sends updates to all connected clients.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OscServer_onOscNuvoEventReceived(object sender, ProtocolDriver.Interface.OscEventReceivedEventArgs e)
        {
            sNuvoMessagesReceivedCount++;
            _log.Trace(m => m("OSCS: Device (id={0}) nuvo control event ({1}) from {2}: {3}", e.OscDevice, sNuvoMessagesReceivedCount, e.SourceEndPoint, e.OscEvent.ToString()));
            _oscDeviceLastUpdate[e.SourceEndPoint.Address] = DateTime.Now;

            bool bKnown = false;

            foreach (OscDeviceController oscDeviceController in _oscDeviceControllers.Values)
            {
                // forward message to clients
                oscDeviceController.processOscNuvoEventForClients(new Address(e.OscDeviceId, e.OscEvent.getZoneId), e.OscEvent);
                // forward (debug) message to clients
                //oscDeviceController.GetOscDriver().SendMessage("/NuvoControl/message", String.Format("Notify {0}/{1}: {2}", sMessagesReceivedCount, oscDeviceController.OscDeviceId, e.OscEvent.ToString()));
                // Check if client is "known"
                if (String.Compare(oscDeviceController.OscDevice.IpAddress.ToString(), e.SourceEndPoint.Address.ToString()) == 0)
                {
                    bKnown = true;
                }
            }

            // If client was/is not known ...
            if (!bKnown)
            {
                // ... create "ad-hoc" controller, to start updating this client, assuming the client listen to port 9000
                _log.Trace(m => m("OSCS.onOscNuvoEventReceived: Client {0} not known, add with id={1}!", e.SourceEndPoint, adhocDeviceIdCounter));
                lock (_oscDeviceControllers)
                {
                    Address             address   = new Address(e.OscDeviceId, adhocDeviceIdCounter);
                    OSCDevice           oscDevice = new OSCDevice(address, eOSCDeviceType.OSCClient, address, String.Format("AdHocClient{0}", adhocDeviceIdCounter), e.SourceEndPoint.Address, 8000, 9000, null);
                    OscDeviceController adhocOscDeviceController = new OscDeviceController(address, oscDevice, _oscDeviceControllers[e.OscDevice]);
                    _oscDeviceControllers.Add(address, adhocOscDeviceController);
                    adhocDeviceIdCounter--;
                }
            }
        }