Exemplo n.º 1
0
        public HeatingController(CommandHandler cmd)
        {
            _cmd          = new PluginsCommandHandler(cmd);
            _cmdUnwrapped = cmd;

            var heatersConfigs = IOconfFile.GetHeater().ToList();

            if (!heatersConfigs.Any())
            {
                return;
            }

            var ovens = IOconfFile.GetOven().ToList();

            foreach (var heater in heatersConfigs)
            {
                _heaters.Add(new HeaterElement(
                                 heater,
                                 ovens.SingleOrDefault(x => x.HeatingElement.Name == heater.Name)));
            }

            cmd.AddCommand("emergencyshutdown", EmergencyShutdown);
            cmd.AddSubsystem(this);
            _heaterCmd = new HeaterCommand(_heaters);
            _heaterCmd.Initialize(new PluginsCommandHandler(cmd), new PluginsLogger("heater"));
            _ovenCmd = new OvenCommand(_heaters, !ovens.Any());
            _ovenCmd.Initialize(new PluginsCommandHandler(cmd), new PluginsLogger("oven"));
            _switchboardController = SwitchBoardController.GetOrCreate(cmd);
        }
Exemplo n.º 2
0
        /// <summary>Sends a command and receives a status in response</summary>
        private static async Task <OvenStatus> SendStatusCommand(OvenCommand command)
        {
            var buffer = await SendReceive(command);

            if (buffer?.Count != 1)
            {
                return(OvenStatus.NotConnected);
            }
            return((OvenStatus)buffer[0]);
        }
Exemplo n.º 3
0
 /// <summary>Overload to allow automatic conversion of command to byte[]</summary>
 private static async Task <List <byte> > SendReceive(OvenCommand command, bool skipReceive = false) => await SendReceive(new byte[] { (byte)command }, skipReceive);