/// <summary>
        /// Creates for the passed command string the expected incoming command string.
        /// It considers values like zone id, volume, etc. to build the expected string.
        /// It adds also the expected start and stop character.
        /// </summary>
        /// <param name="text">Outgoing command string, where all placeholders have been replaced.</param>
        /// <returns>Returns the expected incoming command string.</returns>
        public static string createIncomingCommand(string text)
        {
            char[] _charToRemove = { '*', '\r' };
            NuvoEssentiaSingleCommand command = createNuvoEssentiaSingleCommand(text.Trim(_charToRemove));

            return(createIncomingCommand(command));
        }
        public void SendMultipleCommandWithSpontaneousAdditionalAnswers1Test()
        {
            NuvoTelegramMock     nuvoTelegram = new NuvoTelegramMock();
            NuvoEssentiaProtocol target       = new NuvoEssentiaProtocol(1, nuvoTelegram);

            target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived);

            // Send ReadStatusCONNECT
            NuvoEssentiaSingleCommand command1 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone2);

            target.SendCommand(command1);
            // Send ReadStatusZONE
            NuvoEssentiaSingleCommand command2 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusZONE, ENuvoEssentiaZones.Zone2);

            target.SendCommand(command2);
            // Send ReadStatusCONNECT
            NuvoEssentiaSingleCommand command3 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone3);

            target.SendCommand(command3);
            // Send ReadStatusZONE
            NuvoEssentiaSingleCommand command4 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusZONE, ENuvoEssentiaZones.Zone3);

            target.SendCommand(command4);

            // Return command for ReadStatusCONNECT
            nuvoTelegram.passDataToTestClass("Z02PWRON,SRC3,GRP0,VOL-50");
            ConreteProtocolEventArgs event1 = _nuvoProtocolEventArgs;  // save return argument

            // Return command for ReadStatusZONE
            nuvoTelegram.passDataToTestClass("Z02OR0,BASS-00,TREB+00,GRP0,VRST0");
            ConreteProtocolEventArgs event2 = _nuvoProtocolEventArgs;  // save return argument

            // Return command for ReadStatusCONNECT
            nuvoTelegram.passDataToTestClass("Z03PWRON,SRC3,GRP0,VOL-50");
            ConreteProtocolEventArgs event3 = _nuvoProtocolEventArgs;  // save return argument

            // Additional command
            nuvoTelegram.passDataToTestClass("Z06PWRON,SRC6,GRP0,VOL-50");
            ConreteProtocolEventArgs eventx = _nuvoProtocolEventArgs;  // save return argument

            // Return command for ReadStatusZONE
            nuvoTelegram.passDataToTestClass("Z03OR0,BASS-00,TREB+00,GRP0,VRST0");
            ConreteProtocolEventArgs event4 = _nuvoProtocolEventArgs;  // save return argument

            Assert.IsTrue(_eventRaisedCount == 5);
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command1.Command);
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event1.Command.Command);
            Assert.AreEqual(command1.Guid, event1.Command.Guid); // return same instance of command
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, command2.Command);
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, event2.Command.Command);
            Assert.AreEqual(command2.Guid, event2.Command.Guid); // return same instance of command
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command3.Command);
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event3.Command.Command);
            Assert.AreEqual(command3.Guid, event3.Command.Guid); // return same instance of command
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, command4.Command);
            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, event4.Command.Command);
            Assert.AreEqual(command4.Guid, event4.Command.Guid); // return same instance of command

            Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, eventx.Command.Command);
        }
示例#3
0
        public void OutgoingCommandTest()
        {
            NuvoEssentiaSingleCommand target = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.RampVolumeUP, ENuvoEssentiaZones.Zone9);

            Assert.AreEqual("ZxxVOL+", target.OutgoingCommandTemplate);
            Assert.AreEqual("Z09VOL+", target.OutgoingCommand);
        }
        public void SendCommand6Test()
        {
            NuvoTelegramMock     nuvoTelegram = new NuvoTelegramMock();
            NuvoEssentiaProtocol target       = new NuvoEssentiaProtocol(1, nuvoTelegram);

            target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived);

            // Command: SetSOURCEIR56
            {
                NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.SetSOURCEIR56, ENuvoEssentiaSources.Source3);
                target.SendCommand(command);
                nuvoTelegram.passDataToTestClass("IRSET:56,38,56,38,56,88");

                Assert.IsTrue(_eventRaisedCount == 1);                                                        // event has been raised 1 times
                Assert.AreEqual(ENuvoEssentiaCommands.SetSOURCEIR56, command.Command);
                Assert.AreEqual(ENuvoEssentiaCommands.SetSOURCEIR56, _nuvoProtocolEventArgs.Command.Command); // return same command
                Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid);                           // return same instance of command
                Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source1));
                Assert.AreEqual(EIRCarrierFrequency.IR38kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source2));
                Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source3));
                Assert.AreEqual(EIRCarrierFrequency.IR38kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source4));
                Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source5));
                Assert.AreEqual(EIRCarrierFrequency.IRUnknown, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source6));
            }

            // Command: MuteON
            {
                NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.MuteON, ENuvoEssentiaZones.Zone11);
                target.SendCommand(command);
                nuvoTelegram.passDataToTestClass("Z11PWRON,SRC6,GRP0,VOL-34");     // return value for ReadStatusCONNECT

                Assert.IsTrue(_eventRaisedCount == 2);
                Assert.AreEqual(ENuvoEssentiaCommands.MuteON, command.Command);
                Assert.AreEqual(ENuvoEssentiaCommands.MuteON, _nuvoProtocolEventArgs.Command.Command);   // return same command
                Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid);                      // return same instance of command
                Assert.AreEqual(ENuvoEssentiaZones.Zone11, _nuvoProtocolEventArgs.Command.ZoneId);
                Assert.AreEqual(ENuvoEssentiaSources.Source6, _nuvoProtocolEventArgs.Command.SourceId);
                Assert.AreEqual(-34, _nuvoProtocolEventArgs.Command.VolumeLevel);
                Assert.AreEqual(EZonePowerStatus.ZoneStatusON, _nuvoProtocolEventArgs.Command.PowerStatus);
                Assert.AreEqual(ESourceGroupStatus.SourceGroupOFF, _nuvoProtocolEventArgs.Command.SourceGrupStatus);
            }

            // Command: SetBassLevel
            {
                NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.SetBassLevel, ENuvoEssentiaZones.Zone8, 4, 0);
                target.SendCommand(command);
                nuvoTelegram.passDataToTestClass("Z08OR0,BASS+04,TREB+00,GRP0,VRST1");    // return value for ReadStatusZONE

                Assert.IsTrue(_eventRaisedCount == 3);
                Assert.AreEqual(ENuvoEssentiaCommands.SetBassLevel, command.Command);
                Assert.AreEqual(ENuvoEssentiaCommands.SetBassLevel, _nuvoProtocolEventArgs.Command.Command);
                Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid);
                Assert.AreEqual(ENuvoEssentiaZones.Zone8, _nuvoProtocolEventArgs.Command.ZoneId);
                Assert.AreEqual(4, _nuvoProtocolEventArgs.Command.BassLevel);
                Assert.AreEqual(0, _nuvoProtocolEventArgs.Command.TrebleLevel);
                Assert.AreEqual(EVolumeResetStatus.VolumeResetON, _nuvoProtocolEventArgs.Command.VolumeResetStatus);
                Assert.AreEqual(EDIPSwitchOverrideStatus.DIPSwitchOverrideOFF, _nuvoProtocolEventArgs.Command.DIPSwitchOverrideStatus);
                Assert.AreEqual(ESourceGroupStatus.SourceGroupOFF, _nuvoProtocolEventArgs.Command.SourceGrupStatus);
            }
        }
        /// <summary>
        /// Creates for the passed command the expected incoming command string.
        /// It considers values like zone id, volume, etc. to build the expected string.
        /// It adds also the expected start and stop character.
        /// </summary>
        /// <param name="command">Outgoing command</param>
        /// <returns>Returns the expected incoming command string.</returns>
        public static string createIncomingCommand(NuvoEssentiaSingleCommand command)
        {
            EIRCarrierFrequency[] ircf = { command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source1), command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source2), command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source3), command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source4), command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source5), command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source6) };
            string msg = NuvoEssentiaSingleCommand.replacePlaceholders(command.IncomingCommandTemplate, command.ZoneId, command.SourceId, command.VolumeLevel, command.BassLevel, command.TrebleLevel, command.PowerStatus, ircf, command.SourceGrupStatus, command.VolumeResetStatus, command.DIPSwitchOverrideStatus, command.FirmwareVersion);

            return(string.Format("#{0}\r", msg));
        }
示例#6
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     if (cmbComSelect.Text.Contains("private"))
     {
         // Open a MSMQ queue
         _msgQueue = SerialPortQueue.GetQueue(".\\" + cmbComSelect.Text);
         if (chkReceive.Checked)
         {
             _msgQueue.ReceiveCompleted += new ReceiveCompletedEventHandler(_msgQueue_ReceiveCompleted);
             _msgQueue.BeginReceive();
         }
         DisplayData(MessageType.Normal, string.Format("Open connection to Queue '{0}'", cmbComSelect.Text));
     }
     else
     {
         // Open a protocol stack (using a class implementing IProtocol)
         DisplayData(MessageType.Normal, string.Format("Open connection to Port '{0}'", cmbComSelect.Text));
         _nuvoServer = new NuvoEssentiaProtocolDriver();
         if (chkReceive.Checked)
         {
             _nuvoServer.onCommandReceived  += new ProtocolCommandReceivedEventHandler(nuvoServer_onCommandReceived);
             _nuvoServer.onZoneStatusUpdate += new ProtocolZoneUpdatedEventHandler(_nuvoServer_onZoneStatusUpdate);
         }
         _nuvoServer.Open(ENuvoSystem.NuVoEssentia, 1, new Communication(cmbComSelect.Text, 9600, 8, 1, "None"));
         if (chkSend.Checked)
         {
             DisplayData(MessageType.Normal, "Read version ...");
             NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion);
             DisplayData(MessageType.Outgoing, command.OutgoingCommand);
             _nuvoServer.SendCommand(_address, command);
         }
     }
 }
示例#7
0
        public void IncomingCommandTest()
        {
            //Properties.Settings.Default.NuvoEssentiaProfileFile = "NuvoEssentiaProfile.xml";
            NuvoEssentiaSingleCommand target = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.RampVolumeUP, ENuvoEssentiaZones.Zone3);
            string actual = target.IncomingCommandTemplate;

            Assert.IsTrue(actual.CompareTo("ZxxPWRppp,SRCs,GRPq,VOL-yy") == 0);
        }
示例#8
0
        /// <summary>
        /// Reset keypad lock in a zone.
        /// </summary>
        /// <param name="zoneAddress">Zone address, to reset keypad lock.</param>
        public void CommandSetKeypadLockOFF(Address zoneAddress)
        {
            checkZoneDeviceId(zoneAddress.DeviceId);
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
                ENuvoEssentiaCommands.SetKeypadLockOFF,
                convertAddressZone2EssentiaZone(zoneAddress));

            sendCommandToDevice(zoneAddress, command);
        }
示例#9
0
        /// <summary>
        /// Set treble level in a zone.
        /// </summary>
        /// <param name="zoneAddress">Zone address, to set the treble level.</param>
        /// <param name="trebleLevel">Treble level to set.</param>
        public void CommandSetTrebleLevel(Address zoneAddress, int trebleLevel)
        {
            checkZoneDeviceId(zoneAddress.DeviceId);
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
                ENuvoEssentiaCommands.SetTrebleLevel,
                convertAddressZone2EssentiaZone(zoneAddress), -1, trebleLevel);

            sendCommandToDevice(zoneAddress, command);
        }
示例#10
0
        /// <summary>
        /// Mute zone.
        /// </summary>
        /// <param name="zoneAddress">Zone address, to mute.</param>
        public void CommandMuteON(Address zoneAddress)
        {
            checkZoneDeviceId(zoneAddress.DeviceId);
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
                ENuvoEssentiaCommands.MuteON,
                convertAddressZone2EssentiaZone(zoneAddress));

            sendCommandToDevice(zoneAddress, command);
        }
示例#11
0
        /// <summary>
        /// Stops any volume up/down command in the specified zone.
        /// </summary>
        /// <param name="zoneAddress">Zone address, where to stop any volume up/down command.</param>
        public void CommandStopRampVolume(Address zoneAddress)
        {
            checkZoneDeviceId(zoneAddress.DeviceId);
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
                ENuvoEssentiaCommands.StopRampVolume,
                convertAddressZone2EssentiaZone(zoneAddress));

            sendCommandToDevice(zoneAddress, command);
        }
        public void SendCommand8Test()
        {
            NuvoTelegramMock           nuvoTelegram = new NuvoTelegramMock();
            NuvoEssentiaProtocol       target       = new NuvoEssentiaProtocol(1, nuvoTelegram);
            INuvoEssentiaSingleCommand command      = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.NoCommand);

            target.SendCommand(command);

            // not supported anymore; quick-fix, uncomment unit test -> Assert.AreEqual(0, target._runningCommands.Count);
        }
示例#13
0
        public void NuvoEssentiaSingleCommandConstructorTest()
        {
            NuvoEssentiaSingleCommand target = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.NoCommand);

            Assert.AreEqual(ENuvoEssentiaCommands.NoCommand, target.Command);
            //Assert.IsNull(target.OutgoingCommand);
            Assert.IsNull(target.OutgoingCommandTemplate);
            Assert.IsNull(target.IncomingCommand);
            Assert.IsNull(target.IncomingCommandTemplate);
        }
示例#14
0
        public void SendCommand8Test()
        {
            NuvoTelegramMock nuvoTelegram         = new NuvoTelegramMock();
            NuvoEssentiaProtocol_Accessor target  = new NuvoEssentiaProtocol_Accessor(1, nuvoTelegram);
            INuvoEssentiaSingleCommand    command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.NoCommand);

            target.SendCommand(command);

            Assert.AreEqual(0, target._runningCommands.Count);
        }
示例#15
0
        public void CompareToTest()
        {
            NuvoEssentiaSingleCommand commandold = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion);
            NuvoEssentiaSingleCommand command    = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion);
            NuvoEssentiaSingleCommand commandnew = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion);

            Assert.AreEqual(0, command.CompareTo(command));
            Assert.IsTrue(command.CompareTo(commandold) != 0);
            Assert.IsTrue(command.CompareTo(commandnew) != 0);
        }
示例#16
0
        /// <summary>
        /// Public method to set the volume of a zone.
        /// </summary>
        /// <param name="zoneAddress">Zone Adress, containing device and zone id.</param>
        /// <param name="volumeLevel">Volume level.</param>
        public void CommandSetVolume(Address zoneAddress, int volumeLevel)
        {
            checkZoneDeviceId(zoneAddress.DeviceId);
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
                ENuvoEssentiaCommands.SetVolume,
                convertAddressZone2EssentiaZone(zoneAddress),
                NuvoEssentiaCommand.calcVolume2NuvoEssentia(volumeLevel));

            sendCommandToDevice(zoneAddress, command);
        }
示例#17
0
        /// <summary>
        /// Public method to set the Source of a zone.
        /// </summary>
        /// <param name="zoneAddress">Zone Adress, containing device and zone id.</param>
        /// <param name="sourceAddress">Source Adress, containing device and source id.</param>
        public void CommandSetSource(Address zoneAddress, Address sourceAddress)
        {
            checkZoneDeviceId(zoneAddress.DeviceId);
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
                ENuvoEssentiaCommands.SetSource,
                convertAddressZone2EssentiaZone(zoneAddress),
                convertAddressSource2EssentiaSource(sourceAddress));

            sendCommandToDevice(zoneAddress, command);
        }
示例#18
0
        public void SendCommandTest()
        {
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.MuteALLZoneOFF);
            Address zoneAddress = new Address(_deviceId, 0);    // Zone x -> not used

            _protDriver.SendCommand(zoneAddress, command);
            Thread.Sleep(2000); // give control to worker thread

            Assert.IsTrue(_nuvoTelegramMock.TelegramList.Count >= 1);
            Assert.AreEqual(true, _nuvoTelegramMock.TelegramList.Contains("ALLMOFF"));
        }
示例#19
0
 /// <summary>
 /// Private method to send notifications to each zone.
 /// </summary>
 /// <param name="e">Parameters received from underlying layer.</param>
 private void notifyZoneStatusAllOff(ConreteProtocolEventArgs e)
 {
     if (e.Command.Command == ENuvoEssentiaCommands.TurnALLZoneOFF)
     {
         for (int i = 1; i <= 12; i++)   // TODO replace hard-coded numbers ...
         {
             NuvoEssentiaSingleCommand cmdZoneOff = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.TurnZoneOFF, (ENuvoEssentiaZones)i);
             ConreteProtocolEventArgs  enew       = new ConreteProtocolEventArgs(e.DeviceId, cmdZoneOff);
             notifyZoneStatusUpdate(enew);
         }
     }
 }
 public void compareCommandStringTest()
 {
     Assert.AreEqual(true, NuvoEssentiaSingleCommand.compareCommandString("VER", "VER"));
     Assert.AreEqual(false, NuvoEssentiaSingleCommand.compareCommandString("VER", "VERX"));
     Assert.AreEqual(true, NuvoEssentiaSingleCommand.compareCommandString("MPU_E6Dvx.yy", "MPU_E6Dv1.23"));
     Assert.AreEqual(false, NuvoEssentiaSingleCommand.compareCommandString("MPU_E6Dvx.yy", "MPU_E6Dv1,23"));
     Assert.AreEqual(false, NuvoEssentiaSingleCommand.compareCommandString("MPU_E6Dvx.yy", "NUVO-E6D_v1.23"));
     Assert.AreEqual(true, NuvoEssentiaSingleCommand.compareCommandString("ZxxPWRppp,SRCs,GRPq,VOL-yy", "Z02PWRON,SRC2,GRP0,VOL-00"));
     Assert.AreEqual(true, NuvoEssentiaSingleCommand.compareCommandString("ZxxPWRppp,SRCs,GRPq,VOL-yy", "Z02PWROFF,SRC4,GRP1,VOL-79"));
     Assert.AreEqual(false, NuvoEssentiaSingleCommand.compareCommandString("ZxxPWRppp,SRCs,GRPq,VOL-yy", "Z02PWRON,SRC2.GRP0,VOL-00"));
     Assert.AreEqual(false, NuvoEssentiaSingleCommand.compareCommandString("ZxxPWRppp,SRCs,GRPq,VOL-yy", "Z02PWROFF,SRC4.GRP1,VOL-79"));
 }
示例#21
0
 public void NuvoEssentiaCommandConstructor5Test()
 {
     try
     {
         NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.SetZoneStatus, ENuvoEssentiaZones.Zone4, ENuvoEssentiaSources.Source4);
     }
     catch (ProtocolDriverException ex)
     {
         _log.DebugFormat("Correct, a ProtocolDriverException has to be thrown! {0}", ex.ToString());
         return;
     }
     Assert.Fail("Wrong, expected exception is not thrown!");
 }
示例#22
0
 private void btnSend_Click(object sender, EventArgs e)
 {
     if (_nuvoServer != null)
     {
         NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(txtboxSendText.Text);
         DisplayData(MessageType.Outgoing, command.OutgoingCommand);
         _nuvoServer.SendCommand(_address, command);
     }
     if (_msgQueue != null)
     {
         DisplayData(MessageType.Outgoing, btnSend.Text);
         _msgQueue.Send(btnSend.Text);
     }
 }
        /// <summary>
        /// Creates a Nuvo Essentia command object, using the command string to retrieve the
        /// correct command type. The comand string is checked against the incoming- and outgoing
        /// commands defined in the XML profiles.
        /// If the correct command type is retrieved, all non-initialized values are set to a useful
        /// value.
        /// </summary>
        /// <param name="commandString">Command string</param>
        /// <returns>Nuvo Essentia command</returns>
        public static NuvoEssentiaSingleCommand createNuvoEssentiaSingleCommand(string commandString)
        {
            char[] _charToRemove                  = { '*', '\r' };
            EIRCarrierFrequency[]     ircf        = { EIRCarrierFrequency.IR38kHz, EIRCarrierFrequency.IR38kHz, EIRCarrierFrequency.IR38kHz, EIRCarrierFrequency.IR38kHz, EIRCarrierFrequency.IR38kHz, EIRCarrierFrequency.IR38kHz };
            NuvoEssentiaSingleCommand rawCommand  = new NuvoEssentiaSingleCommand(commandString.Trim(_charToRemove));
            NuvoEssentiaSingleCommand fullCommand = new NuvoEssentiaSingleCommand(
                (rawCommand.Command == ENuvoEssentiaCommands.NoCommand ? ENuvoEssentiaCommands.ReadStatusCONNECT : rawCommand.Command),
                (rawCommand.ZoneId == ENuvoEssentiaZones.NoZone ? ENuvoEssentiaZones.Zone1 : rawCommand.ZoneId),
                (rawCommand.SourceId == ENuvoEssentiaSources.NoSource ? ENuvoEssentiaSources.Source1 : rawCommand.SourceId),
                (rawCommand.VolumeLevel == ZoneState.VALUE_UNDEFINED ? 50 : rawCommand.VolumeLevel),
                (rawCommand.BassLevel == ZoneState.VALUE_UNDEFINED ? 10 : rawCommand.BassLevel),
                (rawCommand.TrebleLevel == ZoneState.VALUE_UNDEFINED ? 10 : rawCommand.TrebleLevel),
                EZonePowerStatus.ZoneStatusON, ircf, EDIPSwitchOverrideStatus.DIPSwitchOverrideOFF, EVolumeResetStatus.VolumeResetOFF, ESourceGroupStatus.SourceGroupOFF, "1.1");

            return(fullCommand);
        }
        public void SendCommand1Test()
        {
            NuvoTelegramMock     nuvoTelegram = new NuvoTelegramMock();
            NuvoEssentiaProtocol target       = new NuvoEssentiaProtocol(1, nuvoTelegram);

            target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived);

            NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion);

            target.SendCommand(command);
            nuvoTelegram.passDataToTestClass("MPU_E6Dvx.yy");

            Assert.IsTrue(_eventRaisedCount == 1);                                                       // event has been raised 1 times
            Assert.AreEqual(command.Command, _nuvoProtocolEventArgs.Command.Command);                    // return same command
            Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, _nuvoProtocolEventArgs.Command.Command);  // return same command
        }
        /// <summary>
        /// Event method called in case a telegram has been received.
        /// </summary>
        /// <param name="sender">This point to the sender of this event.</param>
        /// <param name="e">Event parameters, passed by the sender.</param>
        void _serialPort_onTelegramReceived(object sender, TelegramEventArgs e)
        {
            INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(e.Message);

            command.IncomingCommand = e.Message;
            command = compareIncomingCommandWithRunningCommand(command);

            if (command.Valid)
            {
                //raise the event, and pass data to next layer
                if (onCommandReceived != null)
                {
                    onCommandReceived(this,
                                      new ConreteProtocolEventArgs(_deviceId, command));
                }
            }
        }
示例#26
0
        /// <summary>
        /// Sets the zoen state for this control base on the command passed into.
        /// Depending on the command the zone state is set.
        /// E.g. if the command is 'Turn Zone Off' (see <see cref="ENuvoEssentiaCommands"/>) the
        /// power state of the zone is set to off.
        /// </summary>
        /// <param name="command">Command, which changes the zone state.</param>
        public void updateZoneState(NuvoEssentiaSingleCommand command)
        {
            _log.Trace(m => m("Update Zone state in control {0}. Command='{1}'", this.Name, command));
            if (command.ZoneId != ENuvoEssentiaZones.NoZone)
            {
                // Select zone received by command string
                cmbZoneSelect.SelectedIndex = (int)command.ZoneId - 1;

                switch (command.Command)
                {
                case ENuvoEssentiaCommands.SetVolume:
                    // DOESN'T trigger the method trackVolume_Scroll()
                    trackVolume.Value = Math.Abs(NuvoEssentiaCommand.calcVolume2NuvoControl(command.VolumeLevel));
                    VolumeLevel_Changed();
                    break;

                case ENuvoEssentiaCommands.SetSource:
                    // triggers the method cmbSourceSelect_SelectedIndexChanged()
                    cmbSourceSelect.SelectedIndex = (int)command.SourceId - 1;
                    break;

                case ENuvoEssentiaCommands.TurnZoneON:
                    // triggers the method cmbPowerStatusSelect_SelectedIndexChanged()
                    cmbPowerStatusSelect.SelectedItem = EZonePowerStatus.ZoneStatusON.ToString();
                    break;

                case ENuvoEssentiaCommands.TurnZoneOFF:
                    // triggers the method cmbPowerStatusSelect_SelectedIndexChanged()
                    cmbPowerStatusSelect.SelectedItem = EZonePowerStatus.ZoneStatusOFF.ToString();
                    break;

                case ENuvoEssentiaCommands.TurnALLZoneOFF:
                    //TODO: Switch off all zones and send response
                    break;

                case ENuvoEssentiaCommands.ReadVersion:
                    // do nothing
                    break;

                case ENuvoEssentiaCommands.ReadStatusCONNECT:
                case ENuvoEssentiaCommands.ReadStatusZONE:
                    break;
                }
            }
        }
        public void SendCommand4Test()
        {
            NuvoTelegramMock     nuvoTelegram = new NuvoTelegramMock();
            NuvoEssentiaProtocol target       = new NuvoEssentiaProtocol(1, nuvoTelegram);

            target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived);

            // Command: ReadVersion
            {
                NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion);
                target.SendCommand(command);
                nuvoTelegram.passDataToTestClass("MPU_E6Dv1.23");

                Assert.IsTrue(_eventRaisedCount == 1);                                                        // event has been raised 1 times
                Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, command.Command);
                Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, _nuvoProtocolEventArgs.Command.Command);   // return same command
                Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid);                           // return same instance of command
            }

            // Command: ReadStatusCONNECT
            {
                NuvoEssentiaSingleCommand command2 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone2);
                target.SendCommand(command2);
                nuvoTelegram.passDataToTestClass("ZxxPWRppp,SRCs,GRPq,VOL-yy");

                Assert.IsTrue(_eventRaisedCount == 2);
                Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command2.Command);
                Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, _nuvoProtocolEventArgs.Command.Command);   // return same command
                Assert.AreEqual(command2.Guid, _nuvoProtocolEventArgs.Command.Guid);                                // return same instance of command
                Assert.AreEqual("Z02CONSR", nuvoTelegram.Telegram);
            }

            // Command: ReadStatusCONNECT
            {
                NuvoEssentiaSingleCommand command3 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone6);
                target.SendCommand(command3);
                nuvoTelegram.passDataToTestClass("Z06ORp,BASSuuu,TREBttt,GRPq,VRSTr");    // return value for ReadStatusZONE

                Assert.IsTrue(_eventRaisedCount == 3);
                Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command3.Command);
                Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, _nuvoProtocolEventArgs.Command.Command);
                Assert.AreNotEqual(command3.Guid, _nuvoProtocolEventArgs.Command.Guid);
            }
        }
示例#28
0
 /// <summary>
 /// Public method to set a zone state, according to a zone state object passed in.
 /// </summary>
 /// <param name="zoneAddress">Zone Adress, containing device and zone id.</param>
 /// <param name="zoneState">Zone state, which shall be applied.</param>
 public void SetZoneState(Address zoneAddress, ZoneState zoneState)
 {
     if (zoneState.PowerStatus)
     {
         INuvoEssentiaCommand command = new NuvoEssentiaCommand(
             ENuvoEssentiaCommands.SetZoneStatus,
             convertAddressZone2EssentiaZone(zoneAddress),
             convertAddressSource2EssentiaSource(zoneState.Source),
             NuvoEssentiaCommand.calcVolume2NuvoEssentia(zoneState.Volume));
         sendCommandToDevice(zoneAddress, command);
     }
     else
     {
         INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
             ENuvoEssentiaCommands.TurnZoneOFF,
             convertAddressZone2EssentiaZone(zoneAddress));
         sendCommandToDevice(zoneAddress, command);
     }
 }
示例#29
0
        public void sendCommand(string strCommand, string strZone, string strSource, string strZoneStatus, int volume, int basslevel, int treblelevel)
        {
            //NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand( NuvoEssentiaProtocol.convertString2NuvoEssentiaCommand(strCommand).Command, ENuvoEssentiaSources.Source1);

            NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(
                (ENuvoEssentiaCommands)Enum.Parse(typeof(ENuvoEssentiaCommands), strCommand, true),
                (ENuvoEssentiaZones)Enum.Parse(typeof(ENuvoEssentiaZones), strZone, true),
                (ENuvoEssentiaSources)Enum.Parse(typeof(ENuvoEssentiaSources), strSource, true),
                (int)volume, (int)basslevel, (int)treblelevel,
                (EZonePowerStatus)Enum.Parse(typeof(EZonePowerStatus), strZoneStatus, true),
                new EIRCarrierFrequency[6],
                EDIPSwitchOverrideStatus.DIPSwitchOverrideOFF,
                EVolumeResetStatus.VolumeResetOFF,
                ESourceGroupStatus.SourceGroupOFF, "V1.0");

            LogHelper.Log(LogLevel.Info, String.Format("Send command: " + command.OutgoingCommand));
            if (_nuvoServer != null)
            {
                _nuvoServer.SendCommand(_address, command);
            }
        }
        /// <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);
        }