Пример #1
0
        /// <summary>
        /// See description of INuvoEssentiaCommand
        /// </summary>
        public INuvoEssentiaSingleCommand getNextCommand(INuvoEssentiaSingleCommand prevCommand)
        {
            if (_commandList.Count <= 0)
            {
                throw new ProtocolDriverException(string.Format("The command list is empty, cannot return next command! {0}", prevCommand));
            }

            if (prevCommand != null)
            {
                if (_commandList.Contains(prevCommand))
                {
                    int index = _commandList.IndexOf(prevCommand);
                    if ((index >= 0) && (index + 1 < _commandList.Count))
                    {
                        // next command found
                        return(_commandList[index + 1]);
                    }
                    else
                    {
                        // next command not found, return null
                        return(null);
                    }
                }
                else
                {
                    throw new ProtocolDriverException(string.Format("The command is not part of the command list, cannot return next command! {0}", prevCommand));
                }
            }
            else
            {
                // return first command in list
                return(_commandList[0]);
            }
        }
Пример #2
0
        /// <summary>
        /// Check the running combined commands. Return true only in case
        /// all sub-commands of a combined command are returned.
        /// </summary>
        /// <param name="incomingCommand">Incoming command, used to find the corresponding combined command.</param>
        /// <returns>True in case, all sub-commands are finished of if no combined command is running.</returns>
        private bool checkRunningCommands(INuvoEssentiaSingleCommand incomingCommand)
        {
            bool allFinished = false;

            if (_runningCombinedCommands.Count > 0)
            {
                foreach (INuvoEssentiaCommand command in _runningCombinedCommands)
                {
                    for (INuvoEssentiaSingleCommand singleCommand = command.getNextCommand(null);
                         singleCommand != null;
                         singleCommand = command.getNextCommand(singleCommand))
                    {
                        if (singleCommand == incomingCommand)
                        {
                            allFinished = command.Finished;
                            if (allFinished)
                            {
                                // Remove command from queue
                                _runningCombinedCommands.Remove(command);
                            }
                            return(allFinished);
                        }
                    }
                }
            }
            else
            {
                allFinished = true;
            }

            return(allFinished);
        }
Пример #3
0
 /// <summary>
 /// Send method to send a combined command.
 /// </summary>
 /// <param name="command">Combined command to send.</param>
 public void SendCommand(INuvoEssentiaCommand command)
 {
     for (INuvoEssentiaSingleCommand singleCommand = command.getNextCommand(null);
          singleCommand != null;
          singleCommand = command.getNextCommand(singleCommand))
     {
         Send(singleCommand);
     }
 }
Пример #4
0
 private void sendCommandToDevice(Address zoneAddress, INuvoEssentiaSingleCommand command)
 {
     ThreadPool.QueueUserWorkItem(
         delegate(object obj)
     {
         lock (_deviceList)
         {
             _deviceList[zoneAddress.DeviceId].ProtocolStack.SendCommand(command);
         }
     }, null);
 }
Пример #5
0
        /// <summary>
        /// Public method - specific for Nuvo - to send a single command.
        /// </summary>
        /// <param name="zoneAddress">Zone Adress, containing device and zone id.</param>
        /// <param name="command">Command, to send to the device.</param>
        public void SendCommand(Address zoneAddress, INuvoEssentiaSingleCommand command)
        {
            checkZoneDeviceId(zoneAddress.DeviceId);

            if ((command.ZoneId != ENuvoEssentiaZones.NoZone) &&
                (convertAddressZone2EssentiaZone(zoneAddress) != command.ZoneId))
            {
                // The zoneAddress doesn't belong to the same zone as the command
                new ProtocolDriverException(string.Format("The Zone Address doesn't fit the zone used in the command. Cannot send this command!"));
            }

            sendCommandToDevice(zoneAddress, command);
            _runningSingleCommands.Add(command);
        }
Пример #6
0
        /// <summary>
        /// Send method for a single command.
        /// </summary>
        /// <param name="command">Command to send.</param>
        private void Send(INuvoEssentiaSingleCommand command)
        {
            int delaySinceLastCommand = 0;

            while ((delaySinceLastCommand = (DateTime.Now - _lastTimeACommandHasBeenSent).Milliseconds) < 50)
            {
                _log.Debug(m => m("Wait with command '{0}' execution, because the delay of {1}[ms] is too small.", command, delaySinceLastCommand));
                Thread.Sleep(50 - delaySinceLastCommand);
            }
            if (command.Command != ENuvoEssentiaCommands.NoCommand)
            {
                command.SendDateTime = DateTime.Now;
                _runningCommands.Enqueue(command);
                _serialPort.SendTelegram(command.OutgoingCommand);
                _lastTimeACommandHasBeenSent = DateTime.Now;
            }
            else
            {
                _log.Warn(m => m("Invalid command (NoCommand) received, not sent to the serial port!"));
            }
        }
Пример #7
0
        /// <summary>
        /// Method to check, if the incoming command is related to a previous send
        /// outgoing command.
        /// </summary>
        /// <param name="incomingCommand">Incoming command.</param>
        /// <returns>Return the running command.</returns>
        private INuvoEssentiaSingleCommand compareIncomingCommandWithRunningCommand(INuvoEssentiaSingleCommand incomingCommand)
        {
            INuvoEssentiaSingleCommand command = null;

            if (_runningCommands.Count > 0)
            {
                command = _runningCommands.Peek();
                //if (command != null && compareCommands(command, incomingCommand))
                if (command != null && NuvoEssentiaSingleCommand.compareCommandString(command.IncomingCommandTemplate, incomingCommand.IncomingCommand) &&
                    compareZoneIds(command.ZoneId, incomingCommand.ZoneId))
                {
                    // incoming command matches a previous outgoing command
                    command = _runningCommands.Dequeue();
                    command.IncomingCommand = incomingCommand.IncomingCommand;
                }
                else if (NuvoEssentiaSingleCommand.compareCommandString(_errorNuvoEssentiaCommand.IncomingCommandTemplate, incomingCommand.IncomingCommand))
                {
                    // incoming command indicates an error, assign them to the first command in queue
                    command = _runningCommands.Dequeue();
                    command.IncomingCommand = incomingCommand.IncomingCommand;
                    _log.Error(m => m("An error returned by Nuvo Essentia to the command '{0}'", command));
                }
                else
                {
                    // no outgoing command found. This command has been issued unsolicied
                    command = incomingCommand;
                }
            }
            else
            {
                // no outgoing command available. This command has been issued unsolicied
                command = incomingCommand;
            }

            return(command);
        }
Пример #8
0
 /// <summary>
 /// Send method to send a single command.
 /// </summary>
 /// <param name="command">Combined command to send.</param>
 public void SendCommand(INuvoEssentiaSingleCommand command)
 {
     Send(command);
 }
Пример #9
0
 public void SendCommand(Address zoneAddress, INuvoEssentiaSingleCommand command)
 {
     throw new System.NotImplementedException();
 }
Пример #10
0
 /// <summary>
 /// Constructor used in case a command has been received.
 /// </summary>
 /// <param name="deviceId">Received Device Id.</param>
 /// <param name="command">Received Command.</param>
 public ConreteProtocolEventArgs(int deviceId, INuvoEssentiaSingleCommand command)
 {
     _deviceId = deviceId;
     _command  = command;
 }