Example #1
0
        public GenericComm(DeviceConfig config)
            : base(config)
        {
            PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);

            CommPort = CommFactory.CreateCommForDevice(config);
        }
Example #2
0
        public CecPortController(string key, Func <EssentialsControlPropertiesConfig, ICec> postActivationFunc,
                                 EssentialsControlPropertiesConfig config) : base(key)
        {
            AddPostActivationAction(() =>
            {
                Port = postActivationFunc(config);

                Port.StreamCec.CecChange += StreamCec_CecChange;
            });
        }
Example #3
0
        public static ComPort GetComPort(EssentialsControlPropertiesConfig config)
        {
            var comPar = config.ComParams;
            var dev    = GetIComPortsDeviceFromManagedDevice(config.ControlPortDevKey);

            if (dev != null && config.ControlPortNumber <= dev.NumberOfComPorts)
            {
                return(dev.ComPorts[config.ControlPortNumber]);
            }
            Debug.Console(0, "GetComPort: Device '{0}' does not have com port {1}", config.ControlPortDevKey, config.ControlPortNumber);
            return(null);
        }
Example #4
0
        public ComPortController(string key, Func <EssentialsControlPropertiesConfig, ComPort> postActivationFunc,
                                 ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key)
        {
            Spec = spec;

            AddPostActivationAction(() =>
            {
                Port = postActivationFunc(config);

                RegisterAndConfigureComPort();
            });
        }
Example #5
0
 public void SetPortConfig(string portConfig)
 {
     // TODO: Deserialize new EssentialsControlPropertiesConfig and handle as necessary
     try
     {
         PropertiesConfig = JsonConvert.DeserializeObject <EssentialsControlPropertiesConfig>
                                (portConfig.ToString());
     }
     catch (Exception e)
     {
         Debug.Console(2, this, "Error deserializing port config: {0}", e);
     }
 }
Example #6
0
        public GenericComm(DeviceConfig config)
            : base(config)
        {
            PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);

            var commPort = CommFactory.CreateCommForDevice(config);

            //Fixing decision to require '-comPorts' in delcaration for DGE in order to get a device with comports included
            if (commPort == null)
            {
                config.Key = config.Key + "-comPorts";
                commPort   = CommFactory.CreateCommForDevice(config);
            }

            CommPort = commPort;
        }
Example #7
0
        /// <summary>
        /// Returns a comm method of either com port, TCP, SSH, and puts this into the DeviceManager
        /// </summary>
        /// <param name="deviceConfig">The Device config object</param>
        public static IBasicCommunication CreateCommForDevice(DeviceConfig deviceConfig)
        {
            EssentialsControlPropertiesConfig controlConfig = GetControlPropertiesConfig(deviceConfig);

            if (controlConfig == null)
            {
                return(null);
            }

            IBasicCommunication comm = null;

            try
            {
                var c = controlConfig.TcpSshProperties;
                switch (controlConfig.Method)
                {
                case eControlMethod.Com:
                    comm = new ComPortController(deviceConfig.Key + "-com", GetComPort(controlConfig), controlConfig.ComParams);
                    break;

                case eControlMethod.Cec:
                    comm = new CecPortController(deviceConfig.Key + "-cec", GetCecPort(controlConfig));
                    break;

                case eControlMethod.IR:
                    break;

                case eControlMethod.Ssh:
                {
                    var ssh = new GenericSshClient(deviceConfig.Key + "-ssh", c.Address, c.Port, c.Username, c.Password);
                    ssh.AutoReconnect = c.AutoReconnect;
                    if (ssh.AutoReconnect)
                    {
                        ssh.AutoReconnectIntervalMs = c.AutoReconnectIntervalMs;
                    }
                    comm = ssh;
                    break;
                }

                case eControlMethod.Tcpip:
                {
                    var tcp = new GenericTcpIpClient(deviceConfig.Key + "-tcp", c.Address, c.Port, c.BufferSize);
                    tcp.AutoReconnect = c.AutoReconnect;
                    if (tcp.AutoReconnect)
                    {
                        tcp.AutoReconnectIntervalMs = c.AutoReconnectIntervalMs;
                    }
                    comm = tcp;
                    break;
                }

                case eControlMethod.Udp:
                {
                    var udp = new GenericUdpServer(deviceConfig.Key + "-udp", c.Address, c.Port, c.BufferSize);
                    comm = udp;
                    break;
                }

                case eControlMethod.Telnet:
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                Debug.Console(0, "Cannot create communication from JSON:\r{0}\r\rException:\r{1}",
                              deviceConfig.Properties.ToString(), e);
            }

            // put it in the device manager if it's the right flavor
            var comDev = comm as Device;

            if (comDev != null)
            {
                DeviceManager.AddDevice(comDev);
            }
            return(comm);
        }
Example #8
0
        protected override void CustomSetConfig(DeviceConfig config)
        {
            PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);

            ConfigWriter.UpdateDeviceConfig(config);
        }