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); }
/// <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 ReceiveCommand2Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("ALLOFF"); ConreteProtocolEventArgs event1 = _nuvoProtocolEventArgs; // save return argument Assert.IsTrue(_eventRaisedCount == 1); Assert.AreEqual(ENuvoEssentiaCommands.TurnALLZoneOFF, event1.Command.Command); }
/// <summary> /// Private method to send notification 'onZoneStatusUpdate' /// </summary> /// <param name="e">Parameters received from underlying layer.</param> private void notifyZoneStatusUpdate(ConreteProtocolEventArgs e) { if (onZoneStatusUpdate != null) { try { ZoneState zoneState = new ZoneState(new Address(e.DeviceId, (int)e.Command.SourceId), (e.Command.PowerStatus == EZonePowerStatus.ZoneStatusON ? true : false), NuvoEssentiaCommand.calcVolume2NuvoControl(e.Command.VolumeLevel), ZoneQuality.Online); onZoneStatusUpdate(this, new ProtocolZoneUpdatedEventArgs(new Address(e.DeviceId, (int)e.Command.ZoneId), zoneState, e)); } catch (Exception ex) { _log.Fatal(m => m("Exception occured at forwarding event 'onZoneStatusUpdate' to Device {0} and Zone {1} (Command='{2}')! Exception={3}", e.DeviceId, e.Command.ZoneId, e.Command.ToString(), ex.ToString())); } } }
public void ReceiveCommand1Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("Z02PWRON,SRC3,GRP0,VOL-50"); ConreteProtocolEventArgs event1 = _nuvoProtocolEventArgs; // save return argument // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("Z03PWRON,SRC3,GRP0,VOL-50"); ConreteProtocolEventArgs event2 = _nuvoProtocolEventArgs; // save return argument Assert.IsTrue(_eventRaisedCount == 2); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event1.Command.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event2.Command.Command); }
public void MyTestInitialize() { _eventRaisedCount = 0; _nuvoProtocolEventArgs = null; }
// callback function for receiving data from telegram layer void serialPort_CommandReceived(object sender, ConreteProtocolEventArgs e) { _eventRaisedCount++; _nuvoProtocolEventArgs = e; }
/// <summary> /// Event handler of the Essentia Protocol layer, to receive commands /// from the Nuvo Essentia device. /// </summary> /// <param name="sender">This pointer, to the sender of this event.</param> /// <param name="e">Event argument, containing the Nuvo Essentia command.</param> void _essentiaProtocol_onCommandReceived(object sender, ConreteProtocolEventArgs e) { bool bNotifyCommandReceived = false; bool bNotifyZoneStatusUpdate = false; // first search the device list ... // (with 'lock') lock (_deviceList) { if (_deviceList.ContainsKey(e.DeviceId)) { // Update 'LastUpdated' marker for this device _deviceList[e.DeviceId].LastTimeCommandReceived = DateTime.Now; bNotifyCommandReceived = true; //raise the zone status changed event, and pass data to next layer if (e.Command.ZoneId != ENuvoEssentiaZones.NoZone && e.Command.PowerStatus != EZonePowerStatus.ZoneStatusUnknown && e.Command.VolumeLevel != ZoneState.VALUE_UNDEFINED && e.Command.SourceId != ENuvoEssentiaSources.NoSource && checkRunningCommands(e.Command)) { bNotifyZoneStatusUpdate = true; } } else { _log.Warn(m => m("Cannot find corresponding protocol layer associated to this device id {0}", e.DeviceId)); } } // release lock // Notify 'Command Received' ... if (bNotifyCommandReceived) { //raise the command received event, and pass data to next layer if (onCommandReceived != null) { try { onCommandReceived(this, new ProtocolCommandReceivedEventArgs(new Address(e.DeviceId, (int)e.Command.ZoneId), e)); } catch (Exception ex) { _log.Fatal(m => m("Exception occured at forwarding event 'onCommandReceived' to Device {0} and Zone {1}! Exception={2}", e.DeviceId, e.Command.ZoneId, ex.ToString())); } } } // Notify 'Zone Status Update' ... if (bNotifyZoneStatusUpdate) { notifyZoneStatusUpdate(e); } // Notify all zones for this device, after 'ALLOFF' ... if (bNotifyCommandReceived && (e.Command.Command == ENuvoEssentiaCommands.TurnALLZoneOFF)) { notifyZoneStatusAllOff(e); } }