private StartupArguments(string comPortName, WirelessNetworkAddress?oldAddress, WirelessNetworkAddress newAddress, DeviceCapabilities?capabilities)
 {
     ComPortName  = comPortName;
     OldAddress   = oldAddress;
     NewAddress   = newAddress;
     Capabilities = capabilities;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AlertOperation" /> class with required parameters.
        /// </summary>
        /// <param name="destinationAddress">
        /// The destination address of the device in the wireless network.
        /// </param>
        public AlertOperation([NotNull] WirelessNetworkAddress destinationAddress)
            : this()
        {
            Guard.NotNull(destinationAddress, nameof(destinationAddress));

            DestinationAddress = destinationAddress;
        }
Example #3
0
        private static IEnumerable <Operation> FormingLogicalNetwork()
        {
            var remote = new WirelessNetworkAddress("AAAAAA");
            var gate1  = new WirelessNetworkAddress("E1E1E1");
            var gate2  = new WirelessNetworkAddress("E2E2E2");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return(new LoginOperation());

            Console.WriteLine("<-- Keep Alive (login response)");
            yield return(new KeepAliveOperation(Version.Parse("1.2.34"), 0));

            Console.WriteLine("<-- Notify Status (remote control)");
            yield return(new NotifyStatusOperation(remote, false, DeviceCapabilities.ControlKeypad, DeviceRoles.None, 200));

            Console.WriteLine("<-- Notify Status (first gate)");
            yield return(new NotifyStatusOperation(gate1, false, DeviceCapabilities.TimeSensor, DeviceRoles.None, 150));

            Console.WriteLine("<-- Notify Status (second gate)");
            yield return(new NotifyStatusOperation(gate2, false, DeviceCapabilities.TimeSensor, DeviceRoles.None, 130));

            Console.WriteLine("--> Alert (first gate)");
            yield return(new AlertOperation(gate1));

            Console.WriteLine("--> Network Setup (remote control joins logical network)");
            yield return(new NetworkSetupOperation(remote, true, DeviceRoles.Keypad));

            Console.WriteLine("--> Network Setup (gate1 joins logical network as start timer)");
            yield return(new NetworkSetupOperation(gate1, true, DeviceRoles.StartTimer));

            Console.WriteLine("--> Network Setup (gate2 joins logical network as finish timer)");
            yield return(new NetworkSetupOperation(gate2, true, DeviceRoles.FinishTimer));
        }
        public void When_notify_action_operation_is_received_it_must_raise_event_for_action()
        {
            // Arrange
            var deviceAddress              = new WirelessNetworkAddress("AABBCC");
            const RawDeviceKeys inputKeys  = RawDeviceKeys.Key1OrPlaySoundA;
            TimeSpan            sensorTime = TimeSpan.FromMilliseconds(3456);

            using var testRunner = new CirceUsbLoopbackTestRunner <DeviceAction>();

            testRunner.RemoteSessionManager.ConnectionStateChanged += (_, e) =>
            {
                if (e.State == ControllerConnectionState.Connected)
                {
                    testRunner.Connection.Send(new NotifyActionOperation(deviceAddress)
                    {
                        InputKeys  = inputKeys,
                        SensorTime = sensorTime
                    });
                }
            };

            testRunner.RemoteSessionManager.DeviceActionReceived += (_, e) => testRunner.SignalSucceeded(e.Argument);

            // Act
            bool succeeded = testRunner.Start();

            // Assert
            succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
            testRunner.Result.ShouldNotBeNull();
            testRunner.Result.DeviceAddress.Should().Be(deviceAddress);
            testRunner.Result.InputKeys.Should().Be(inputKeys);
            testRunner.Result.SensorTime.Should().Be(sensorTime);
        }
        public void When_notify_status_operation_is_no_longer_received_it_must_raise_event_for_removed_device()
        {
            // Arrange
            var deviceAddress = new WirelessNetworkAddress("AABBCC");

            using var testRunner = new CirceUsbLoopbackTestRunner <WirelessNetworkAddress>();

            testRunner.RemoteSessionManager.ConnectionStateChanged += (_, e) =>
            {
                if (e.State == ControllerConnectionState.Connected)
                {
                    testRunner.Connection.Send(new NotifyStatusOperation(deviceAddress, true,
                                                                         DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor | DeviceCapabilities.FinishSensor |
                                                                         DeviceCapabilities.IntermediateSensor, DeviceRoles.StartTimer | DeviceRoles.FinishTimer, 25));
                }
            };

            testRunner.RemoteSessionManager.DeviceTracker.DeviceRemoved += (_, e) => testRunner.SignalSucceeded(e.Argument);

            testRunner.RunTimeout = TimeSpan.FromSeconds(5);

            // Act
            bool succeeded = testRunner.StartWithKeepAliveLoopInBackground();

            // Assert
            succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
            testRunner.Result.Should().Be(deviceAddress);
        }
        public void When_alert_is_requested_it_must_send_operation()
        {
            // Arrange
            var deviceAddress = new WirelessNetworkAddress("AABBCC");

            using var testRunner = new CirceUsbLoopbackTestRunner <AlertOperation>();

            testRunner.RemoteSessionManager.ConnectionStateChanged += (_, e) =>
            {
                if (e.State == ControllerConnectionState.Connected)
                {
                    testRunner.RemoteSessionManager.AlertAsync(deviceAddress);
                }
            };

            testRunner.OperationReceived += (_, e) =>
            {
                if (e.Operation is AlertOperation alertOperation)
                {
                    testRunner.SignalSucceeded(alertOperation);
                }
            };

            // Act
            bool succeeded = testRunner.Start();

            // Assert
            succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
            testRunner.Result.ShouldNotBeNull();
            testRunner.Result.DestinationAddress.Should().Be(deviceAddress);
        }
        public AlertEventArgs(WirelessNetworkAddress destinationAddress, CancellationToken cancelToken)
        {
            Guard.NotNull(destinationAddress, nameof(destinationAddress));

            DestinationAddress = destinationAddress;
            CancelToken        = cancelToken;
        }
        public void When_network_setup_is_requested_it_must_send_operation()
        {
            // Arrange
            var               deviceAddress = new WirelessNetworkAddress("AABBCC");
            const bool        setMembership = true;
            const DeviceRoles roles         = DeviceRoles.Keypad;

            using var testRunner = new CirceUsbLoopbackTestRunner <NetworkSetupOperation>();

            testRunner.RemoteSessionManager.ConnectionStateChanged += (_, e) =>
            {
                if (e.State == ControllerConnectionState.Connected)
                {
                    testRunner.RemoteSessionManager.NetworkSetupAsync(deviceAddress, setMembership, roles);
                }
            };

            testRunner.OperationReceived += (_, e) =>
            {
                if (e.Operation is NetworkSetupOperation networkSetupOperation)
                {
                    testRunner.SignalSucceeded(networkSetupOperation);
                }
            };

            // Act
            bool succeeded = testRunner.Start();

            // Assert
            succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
            testRunner.Result.ShouldNotBeNull();
            testRunner.Result.DestinationAddress.Should().Be(deviceAddress);
            testRunner.Result.SetMembership.Should().Be(setMembership);
            testRunner.Result.Roles.Should().Be(roles);
        }
        private static IEnumerable<Operation> AssigningUniqueNetworkAddresses()
        {
            var mediator = new WirelessNetworkAddress("123456");
            var device = new WirelessNetworkAddress("222222");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return new LoginOperation();

            Console.WriteLine("<-- Keep Alive (login response indicates unconfigured)");
            yield return new KeepAliveOperation(Version.Parse("1.2.34"), 1);

            Console.WriteLine("--> Device setup (assigns address 123456 to new mediator)");
            yield return new DeviceSetupOperation(mediator);

            Console.WriteLine("<-- Keep Alive (indicates configured mediator)");
            yield return new KeepAliveOperation(Version.Parse("1.2.34"), 0);

            Console.WriteLine(
                "--> Device setup (assigns address 222222 and capability TimeSensor to new wireless device)");
            yield return new DeviceSetupOperation(device) { Capabilities = DeviceCapabilities.TimeSensor };

            Console.WriteLine("<-- Notify Status (indicates configured wireless device)");
            yield return new NotifyStatusOperation(device, false, DeviceCapabilities.TimeSensor, DeviceRoles.None, 150);

            Console.WriteLine("--> Logout");
            yield return new LogoutOperation();
        }
        public void WirelessNetworkAddress()
        {
            // Arrange
            WirelessNetworkAddress?w0 = null;
            var w1 = new WirelessNetworkAddress("111111");
            var w2 = new WirelessNetworkAddress("222222");

            // Act and assert
            (w1 <= w2).Should().BeTrue();
            (w2 >= w1).Should().BeTrue();
            (!(w1 >= w2)).Should().BeTrue();
            (!(w2 <= w1)).Should().BeTrue();

            (w1 >= w0).Should().BeTrue();
            (w0 <= w1).Should().BeTrue();
            (!(w1 <= w0)).Should().BeTrue();
            (!(w0 >= w1)).Should().BeTrue();

#pragma warning disable CS1718 // Comparison made to same variable
            // ReSharper disable EqualExpressionComparison
            (w1 <= w1).Should().BeTrue();
            (w1 >= w1).Should().BeTrue();
            (!(w1 > w1)).Should().BeTrue();
            (!(w1 < w1)).Should().BeTrue();

            (w0 <= w0).Should().BeTrue();
            (w0 >= w0).Should().BeTrue();
            (!(w0 > w0)).Should().BeTrue();
            (!(w0 < w0)).Should().BeTrue();
            // ReSharper restore EqualExpressionComparison
#pragma warning restore CS1718 // Comparison made to same variable
        }
        private static IEnumerable<Operation> FormingLogicalNetwork()
        {
            var remote = new WirelessNetworkAddress("AAAAAA");
            var gate1 = new WirelessNetworkAddress("E1E1E1");
            var gate2 = new WirelessNetworkAddress("E2E2E2");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return new LoginOperation();

            Console.WriteLine("<-- Keep Alive (login response)");
            yield return new KeepAliveOperation(Version.Parse("1.2.34"), 0);

            Console.WriteLine("<-- Notify Status (remote control)");
            yield return
                new NotifyStatusOperation(remote, false, DeviceCapabilities.ControlKeypad, DeviceRoles.None, 200);

            Console.WriteLine("<-- Notify Status (first gate)");
            yield return new NotifyStatusOperation(gate1, false, DeviceCapabilities.TimeSensor, DeviceRoles.None, 150);

            Console.WriteLine("<-- Notify Status (second gate)");
            yield return new NotifyStatusOperation(gate2, false, DeviceCapabilities.TimeSensor, DeviceRoles.None, 130);

            Console.WriteLine("--> Alert (first gate)");
            yield return new AlertOperation(gate1);

            Console.WriteLine("--> Network Setup (remote control joins logical network)");
            yield return new NetworkSetupOperation(remote, true, DeviceRoles.Keypad);

            Console.WriteLine("--> Network Setup (gate1 joins logical network as start timer)");
            yield return new NetworkSetupOperation(gate1, true, DeviceRoles.StartTimer);

            Console.WriteLine("--> Network Setup (gate2 joins logical network as finish timer)");
            yield return new NetworkSetupOperation(gate2, true, DeviceRoles.FinishTimer);
        }
Example #12
0
        private static IEnumerable <Operation> AssigningUniqueNetworkAddresses()
        {
            var mediator = new WirelessNetworkAddress("123456");
            var device   = new WirelessNetworkAddress("222222");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return(new LoginOperation());

            Console.WriteLine("<-- Keep Alive (login response indicates unconfigured)");
            yield return(new KeepAliveOperation(Version.Parse("1.2.34"), 1));

            Console.WriteLine("--> Device setup (assigns address 123456 to new mediator)");
            yield return(new DeviceSetupOperation(mediator));

            Console.WriteLine("<-- Keep Alive (indicates configured mediator)");
            yield return(new KeepAliveOperation(Version.Parse("1.2.34"), 0));

            Console.WriteLine("--> Device setup (assigns address 222222 and capability TimeSensor to new wireless device)");

            yield return(new DeviceSetupOperation(device)
            {
                Capabilities = DeviceCapabilities.TimeSensor
            });

            Console.WriteLine("<-- Notify Status (indicates configured wireless device)");
            yield return(new NotifyStatusOperation(device, false, DeviceCapabilities.TimeSensor, DeviceRoles.None, 150));

            Console.WriteLine("--> Logout");
            yield return(new LogoutOperation());
        }
Example #13
0
        public void RemoveDevice(WirelessNetworkAddress address)
        {
            Guard.NotNull(address, nameof(address));

            GateSettingsXml?gateToRemove = GatesOrEmpty.FirstOrDefault(gate => gate.DeviceAddressNotNull == address);

            if (gateToRemove != null)
            {
                GatesOrEmpty.Remove(gateToRemove);
                return;
            }

            RemoteSettingsXml?remoteToRemove = RemotesOrEmpty.FirstOrDefault(remote => remote.DeviceAddressNotNull == address);

            if (remoteToRemove != null)
            {
                RemotesOrEmpty.Remove(remoteToRemove);
                return;
            }

            DisplaySettingsXml?displayToRemove = DisplaysOrEmpty.FirstOrDefault(display => display.DeviceAddressNotNull == address);

            if (displayToRemove != null)
            {
                DisplaysOrEmpty.Remove(displayToRemove);
            }
        }
Example #14
0
            public bool Contains(WirelessNetworkAddress deviceAddress)
            {
                Guard.NotNull(deviceAddress, nameof(deviceAddress));

                Dictionary <WirelessNetworkAddress, int> table = EnsureRowCache();

                return(table.ContainsKey(deviceAddress));
            }
Example #15
0
 void IWirelessDevice.ChangeAddress(WirelessNetworkAddress newAddress)
 {
     this.EnsureOnMainThread(() =>
     {
         settings.DeviceAddress = newAddress;
         UpdateControlsFromSettings();
     });
 }
Example #16
0
        public DeviceAction(WirelessNetworkAddress deviceAddress, RawDeviceKeys?inputKeys, TimeSpan?sensorTime)
        {
            Guard.NotNull(deviceAddress, nameof(deviceAddress));

            DeviceAddress = deviceAddress;
            InputKeys     = inputKeys;
            SensorTime    = sensorTime;
        }
        private NetworkComplianceMismatch([NotNull] string name, [NotNull] string message,
            [CanBeNull] WirelessNetworkAddress deviceAddress = null)
        {
            Guard.NotNullNorEmpty(name, nameof(name));
            Guard.NotNullNorEmpty(message, nameof(message));

            Name = name;
            Message = message;
            DeviceAddress = deviceAddress;
        }
        public void When_notify_status_operation_is_received_it_must_raise_event_for_added_device()
        {
            // Arrange
            var        deviceAddress = new WirelessNetworkAddress("AABBCC");
            const bool getMembership = true;

            const DeviceCapabilities capabilities = DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor |
                                                    DeviceCapabilities.FinishSensor | DeviceCapabilities.IntermediateSensor;

            const DeviceRoles roles          = DeviceRoles.StartTimer | DeviceRoles.FinishTimer;
            const int         signalStrength = 25;
            const int         batteryStatus  = 83;
            const bool        isAligned      = true;
            const ClockSynchronizationStatus clockSynchronization = ClockSynchronizationStatus.RequiresSync;
            const bool hasVersionMismatch = false;

            using var testRunner = new CirceUsbLoopbackTestRunner <DeviceStatus>();

            testRunner.RemoteSessionManager.ConnectionStateChanged += (_, e) =>
            {
                if (e.State == ControllerConnectionState.Connected)
                {
                    testRunner.Connection.Send(new NotifyStatusOperation(deviceAddress, getMembership, capabilities, roles, signalStrength)
                    {
                        BatteryStatus        = batteryStatus,
                        IsAligned            = isAligned,
                        ClockSynchronization = clockSynchronization,
                        HasVersionMismatch   = false
                    });
                }
            };

            testRunner.RemoteSessionManager.DeviceTracker.DeviceAdded += (_, e) => testRunner.SignalSucceeded(e.Argument);

            // Act
            bool succeeded = testRunner.Start();

            // Assert
            succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
            testRunner.Result.ShouldNotBeNull();
            testRunner.Result.DeviceAddress.Should().Be(deviceAddress);
            testRunner.Result.IsInNetwork.Should().Be(getMembership);
            testRunner.Result.Capabilities.Should().Be(capabilities);
            testRunner.Result.Roles.Should().Be(roles);
            testRunner.Result.SignalStrength.Should().Be(signalStrength);
            testRunner.Result.BatteryStatus.Should().Be(batteryStatus);
            testRunner.Result.IsAligned.Should().Be(isAligned);
            testRunner.Result.ClockSynchronization.Should().Be(clockSynchronization);
            testRunner.Result.HasVersionMismatch.Should().Be(hasVersionMismatch);
        }
        public DeviceStatus(WirelessNetworkAddress deviceAddress, bool isInNetwork, DeviceCapabilities capabilities, DeviceRoles roles, int signalStrength,
                            int?batteryStatus, bool?isAligned, ClockSynchronizationStatus?clockSynchronization, bool?hasVersionMismatch)
        {
            Guard.NotNull(deviceAddress, nameof(deviceAddress));

            DeviceAddress        = deviceAddress;
            IsInNetwork          = isInNetwork;
            Capabilities         = capabilities;
            Roles                = ReduceRolesToComplyWith(capabilities, roles);
            SignalStrength       = signalStrength;
            BatteryStatus        = batteryStatus;
            IsAligned            = isAligned;
            ClockSynchronization = clockSynchronization;
            HasVersionMismatch   = hasVersionMismatch;
        }
Example #20
0
        private static IEnumerable <Operation> SynchronizingClocks()
        {
            var remote = new WirelessNetworkAddress("AAAAAA");
            var gate1  = new WirelessNetworkAddress("E1E1E1");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return(new LoginOperation());

            Console.WriteLine("<-- Keep Alive (login response)");
            yield return(new KeepAliveOperation(Version.Parse("1.2.34"), 0));

            Console.WriteLine("<-- Notify Status (remote control)");

            yield return(new NotifyStatusOperation(remote, false,
                                                   DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor | DeviceCapabilities.FinishSensor |
                                                   DeviceCapabilities.IntermediateSensor, DeviceRoles.Keypad | DeviceRoles.StartTimer, 200));

            Console.WriteLine("<-- Notify Status (gate, asking for sync)");

            yield return(new NotifyStatusOperation(gate1, false, DeviceCapabilities.TimeSensor, DeviceRoles.FinishTimer, 150)
            {
                ClockSynchronization = ClockSynchronizationStatus.RequiresSync
            });

            Console.WriteLine("--> Synchronize clocks");
            yield return(new SynchronizeClocksOperation());

            Console.WriteLine("<-- Notify Status (remote control, synced)");

            yield return(new NotifyStatusOperation(remote, false,
                                                   DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor | DeviceCapabilities.FinishSensor |
                                                   DeviceCapabilities.IntermediateSensor, DeviceRoles.Keypad | DeviceRoles.StartTimer, 200)
            {
                ClockSynchronization = ClockSynchronizationStatus.SyncSucceeded
            });

            Console.WriteLine("<-- Notify Status (gate, synced)");

            yield return(new NotifyStatusOperation(gate1, false, DeviceCapabilities.TimeSensor, DeviceRoles.FinishTimer, 150)
            {
                ClockSynchronization = ClockSynchronizationStatus.SyncSucceeded
            });
        }
Example #21
0
        private static IEnumerable <Operation> ReportingEventsDuringACompetitionRun()
        {
            var remote = new WirelessNetworkAddress("AAAAAA");
            var gate1  = new WirelessNetworkAddress("E1E1E1");
            var gate2  = new WirelessNetworkAddress("E2E2E2");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return(new LoginOperation());

            Console.WriteLine("<-- Keep Alive (login response)");
            yield return(new KeepAliveOperation(Version.Parse("1.2.34"), 0));

            Console.WriteLine("<-- Notify Action (Ready key pressed)");

            yield return(new NotifyActionOperation(remote)
            {
                InputKeys = RawDeviceKeys.Ready
            });

            yield return(new NotifyActionOperation(remote)
            {
                InputKeys = RawDeviceKeys.None
            });

            Console.WriteLine("<-- Notify Action (gate1 start timer)");

            yield return(new NotifyActionOperation(gate1)
            {
                SensorTime = TimeSpan.FromSeconds(5)
            });

            Console.WriteLine("<-- Notify Action (gate2 finish timer)");

            yield return(new NotifyActionOperation(gate2)
            {
                SensorTime = TimeSpan.FromSeconds(32)
            });
        }
Example #22
0
            public int this[WirelessNetworkAddress deviceAddress]
            {
                get
                {
                    Guard.NotNull(deviceAddress, nameof(deviceAddress));

                    Dictionary <WirelessNetworkAddress, int> table = EnsureRowCache();

                    if (!table.ContainsKey(deviceAddress))
                    {
                        throw new InvalidOperationException($"No row found for device {deviceAddress}.");
                    }

                    return(table[deviceAddress]);
                }
                set
                {
                    Guard.NotNull(deviceAddress, nameof(deviceAddress));

                    Dictionary <WirelessNetworkAddress, int> table = EnsureRowCache();
                    table[deviceAddress] = value;
                }
            }
        public void WirelessNetworkAddress()
        {
            // Arrange
            WirelessNetworkAddress w0 = null;
            var w1 = new WirelessNetworkAddress("111111");
            var w2 = new WirelessNetworkAddress("222222");

            // Act and assert
            (w1 <= w2).Should().BeTrue();
            (w2 >= w1).Should().BeTrue();
            (!(w1 >= w2)).Should().BeTrue();
            (!(w2 <= w1)).Should().BeTrue();

            // ReSharper disable ExpressionIsAlwaysNull
            (w1 >= w0).Should().BeTrue();
            (w0 <= w1).Should().BeTrue();
            (!(w1 <= w0)).Should().BeTrue();
            (!(w0 >= w1)).Should().BeTrue();
            // ReSharper restore ExpressionIsAlwaysNull

#pragma warning disable CS1718 // Comparison made to same variable
            // ReSharper disable EqualExpressionComparison
            (w1 <= w1).Should().BeTrue();
            (w1 >= w1).Should().BeTrue();
            (!(w1 > w1)).Should().BeTrue();
            (!(w1 < w1)).Should().BeTrue();

            // ReSharper disable ExpressionIsAlwaysNull
            (w0 <= w0).Should().BeTrue();
            (w0 >= w0).Should().BeTrue();
            (!(w0 > w0)).Should().BeTrue();
            (!(w0 < w0)).Should().BeTrue();
            // ReSharper restore ExpressionIsAlwaysNull
            // ReSharper restore EqualExpressionComparison
#pragma warning restore CS1718 // Comparison made to same variable
        }
Example #24
0
        public static void ShouldBeModifierKeyUpFor(this EventArgsWithName <RemoteKeyTracker> eventArgsWithName, WirelessNetworkAddress source,
                                                    RemoteKeyModifier modifier)
        {
            Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName));
            Guard.NotNull(source, nameof(source));

            eventArgsWithName.Name.Should().Be("ModifierKeyUp");
            eventArgsWithName.EventArgs.Should().BeOfType <RemoteKeyModifierEventArgs>();

            var remoteKeyModifierEventArgs = (RemoteKeyModifierEventArgs)eventArgsWithName.EventArgs;

            remoteKeyModifierEventArgs.Source.Should().Be(source);
            remoteKeyModifierEventArgs.Modifier.Should().Be(modifier);
        }
        protected DeviceEventArgs(WirelessNetworkAddress source)
        {
            Guard.NotNull(source, nameof(source));

            Source = source;
        }
 public DeviceCommandEventArgs(WirelessNetworkAddress source, DeviceCommand command)
     : base(source)
 {
     Command = command;
 }
 public NetworkCompositionBuilder WithDeviceInRoles(WirelessNetworkAddress deviceAddress, DeviceCapabilities capabilities, DeviceRoles roles)
 {
     composition = composition.ChangeRolesFor(deviceAddress, capabilities, roles);
     return(this);
 }
        public void When_notify_action_operation_is_received_it_must_raise_event_for_action()
        {
            // Arrange
            var deviceAddress = new WirelessNetworkAddress("AABBCC");
            const RawDeviceKeys inputKeys = RawDeviceKeys.Key1OrPlaySoundA;
            TimeSpan sensorTime = TimeSpan.FromMilliseconds(3456);

            using (var testRunner = new CirceUsbLoopbackTestRunner<DeviceAction>())
            {
                testRunner.RemoteSessionManager.ConnectionStateChanged += (s, e) =>
                {
                    if (e.State == ControllerConnectionState.Connected)
                    {
                        testRunner.Connection.Send(new NotifyActionOperation(deviceAddress)
                        {
                            InputKeys = inputKeys,
                            SensorTime = sensorTime
                        });
                    }
                };

                testRunner.RemoteSessionManager.DeviceActionReceived +=
                    (s, e) => { testRunner.SignalSucceeded(e.Argument); };

                // Act
                bool succeeded = testRunner.Start();

                // Assert
                succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
                DeviceAction deviceActionNotNull = testRunner.Result.ShouldNotBeNull();
                deviceActionNotNull.DeviceAddress.Should().Be(deviceAddress);
                deviceActionNotNull.InputKeys.Should().Be(inputKeys);
                deviceActionNotNull.SensorTime.Should().Be(sensorTime);
            }
        }
        protected DeviceEventArgs([NotNull] WirelessNetworkAddress source)
        {
            Guard.NotNull(source, nameof(source));

            Source = source;
        }
 void IWirelessDevice.ChangeAddress(WirelessNetworkAddress newAddress)
 {
     this.EnsureOnMainThread(() =>
     {
         settings.DeviceAddress = newAddress;
         UpdateControlsFromSettings();
     });
 }
Example #31
0
        public static void ShouldBeKeyDownFor(this EventArgsWithName <RemoteKeyTracker> eventArgsWithName, WirelessNetworkAddress source, RemoteKey key)
        {
            Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName));
            Guard.NotNull(source, nameof(source));

            eventArgsWithName.Name.Should().Be("KeyDown");
            eventArgsWithName.EventArgs.Should().BeOfType <RemoteKeyEventArgs>();

            var remoteKeyModifierEventArgs = (RemoteKeyEventArgs)eventArgsWithName.EventArgs;

            remoteKeyModifierEventArgs.Source.Should().Be(source);
            remoteKeyModifierEventArgs.Key.Should().Be(key);
        }
        public PhaseWaitingForSetupResponse([NotNull] WirelessNetworkAddress newAddress)
        {
            Guard.NotNull(newAddress, nameof(newAddress));

            NewAddress = newAddress;
        }
        public void When_network_setup_is_requested_it_must_send_operation()
        {
            // Arrange
            var deviceAddress = new WirelessNetworkAddress("AABBCC");
            const bool setMembership = true;
            const DeviceRoles roles = DeviceRoles.Keypad;

            using (var testRunner = new CirceUsbLoopbackTestRunner<NetworkSetupOperation>())
            {
                testRunner.RemoteSessionManager.ConnectionStateChanged += (s, e) =>
                {
                    if (e.State == ControllerConnectionState.Connected)
                    {
                        testRunner.RemoteSessionManager.NetworkSetupAsync(deviceAddress, setMembership, roles);
                    }
                };

                testRunner.OperationReceived += (s, e) =>
                {
                    var networkSetupOperation = e.Operation as NetworkSetupOperation;
                    if (networkSetupOperation != null)
                    {
                        testRunner.SignalSucceeded(networkSetupOperation);
                    }
                };

                // Act
                bool succeeded = testRunner.Start();

                // Assert
                succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
                NetworkSetupOperation operationNotNull = testRunner.Result.ShouldNotBeNull();
                operationNotNull.DestinationAddress.Should().Be(deviceAddress);
                operationNotNull.SetMembership.Should().Be(setMembership);
                operationNotNull.Roles.Should().Be(roles);
            }
        }
Example #34
0
        public static void ShouldBeMissingKeyFor(this EventArgsWithName <RemoteKeyTracker> eventArgsWithName, WirelessNetworkAddress source,
                                                 TimeSpan?sensorTime)
        {
            Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName));
            Guard.NotNull(source, nameof(source));

            eventArgsWithName.Name.Should().Be("MissingKey");
            eventArgsWithName.EventArgs.Should().BeOfType <DeviceTimeEventArgs>();

            var deviceTimeEventArgs = (DeviceTimeEventArgs)eventArgsWithName.EventArgs;

            deviceTimeEventArgs.Source.Should().Be(source);
            deviceTimeEventArgs.SensorTime.Should().Be(sensorTime);
        }
Example #35
0
 public GatePassageEventArgs(WirelessNetworkAddress source, TimeSpan?sensorTime, GatePassage gatePassage)
     : base(source, sensorTime)
 {
     GatePassage = gatePassage;
 }
Example #36
0
 public DeviceTimeEventArgs(WirelessNetworkAddress source, TimeSpan?sensorTime)
     : base(source)
 {
     SensorTime = sensorTime;
 }
        public void When_notify_status_operation_is_received_twice_it_must_raise_event_for_changed_device()
        {
            // Arrange
            var deviceAddress = new WirelessNetworkAddress("AABBCC");
            const bool getMembership = true;
            const DeviceCapabilities capabilities =
                DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor |
                    DeviceCapabilities.FinishSensor | DeviceCapabilities.IntermediateSensor;
            const DeviceRoles roles = DeviceRoles.StartTimer | DeviceRoles.FinishTimer;
            const int signalStrength = 99;
            const int batteryStatus = 83;
            const bool isAligned = true;
            const ClockSynchronizationStatus clockSynchronization = ClockSynchronizationStatus.RequiresSync;

            using (var testRunner = new CirceUsbLoopbackTestRunner<DeviceStatus>())
            {
                testRunner.RemoteSessionManager.ConnectionStateChanged += (s, e) =>
                {
                    if (e.State == ControllerConnectionState.Connected)
                    {
                        testRunner.Connection.Send(new NotifyStatusOperation(deviceAddress, getMembership,
                            capabilities, roles, 25));

                        testRunner.Connection.Send(new NotifyStatusOperation(deviceAddress, getMembership,
                            capabilities, roles, signalStrength)
                        {
                            BatteryStatus = batteryStatus,
                            IsAligned = isAligned,
                            ClockSynchronization = clockSynchronization
                        });
                    }
                };

                testRunner.RemoteSessionManager.DeviceTracker.DeviceChanged +=
                    (s, e) => { testRunner.SignalSucceeded(e.Argument); };

                // Act
                bool succeeded = testRunner.Start();

                // Assert
                succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
                DeviceStatus deviceStatusNotNull = testRunner.Result.ShouldNotBeNull();
                deviceStatusNotNull.DeviceAddress.Should().Be(deviceAddress);
                deviceStatusNotNull.IsInNetwork.Should().Be(getMembership);
                deviceStatusNotNull.Capabilities.Should().Be(capabilities);
                deviceStatusNotNull.Roles.Should().Be(roles);
                deviceStatusNotNull.SignalStrength.Should().Be(signalStrength);
                deviceStatusNotNull.BatteryStatus.Should().Be(batteryStatus);
                deviceStatusNotNull.IsAligned.Should().Be(isAligned);
                deviceStatusNotNull.ClockSynchronization.Should().Be(clockSynchronization);
            }
        }
        private static IEnumerable<Operation> ReportingEventsDuringACompetitionRun()
        {
            var remote = new WirelessNetworkAddress("AAAAAA");
            var gate1 = new WirelessNetworkAddress("E1E1E1");
            var gate2 = new WirelessNetworkAddress("E2E2E2");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return new LoginOperation();

            Console.WriteLine("<-- Keep Alive (login response)");
            yield return new KeepAliveOperation(Version.Parse("1.2.34"), 0);

            Console.WriteLine("<-- Notify Action (Ready key pressed)");
            yield return new NotifyActionOperation(remote) { InputKeys = RawDeviceKeys.Ready };
            yield return new NotifyActionOperation(remote) { InputKeys = RawDeviceKeys.None };

            Console.WriteLine("<-- Notify Action (gate1 start timer)");
            yield return new NotifyActionOperation(gate1) { SensorTime = TimeSpan.FromSeconds(5) };

            Console.WriteLine("<-- Notify Action (gate2 finish timer)");
            yield return new NotifyActionOperation(gate2) { SensorTime = TimeSpan.FromSeconds(32) };
        }
        public void When_notify_status_operation_is_no_longer_received_it_must_raise_event_for_removed_device()
        {
            // Arrange
            var deviceAddress = new WirelessNetworkAddress("AABBCC");

            using (var testRunner = new CirceUsbLoopbackTestRunner<WirelessNetworkAddress>())
            {
                testRunner.RemoteSessionManager.ConnectionStateChanged += (s, e) =>
                {
                    if (e.State == ControllerConnectionState.Connected)
                    {
                        testRunner.Connection.Send(new NotifyStatusOperation(deviceAddress, true,
                            DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad |
                                DeviceCapabilities.StartSensor | DeviceCapabilities.FinishSensor |
                                DeviceCapabilities.IntermediateSensor, DeviceRoles.StartTimer | DeviceRoles.FinishTimer,
                            25));
                    }
                };

                testRunner.RemoteSessionManager.DeviceTracker.DeviceRemoved +=
                    (s, e) => { testRunner.SignalSucceeded(e.Argument); };

                testRunner.RunTimeout = TimeSpan.FromSeconds(5);

                // Act
                bool succeeded = testRunner.StartWithKeepAliveLoopInBackground();

                // Assert
                succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
                testRunner.Result.Should().Be(deviceAddress);
            }
        }
        public void When_adding_devices_in_role_intermediate_timer_they_must_be_stored()
        {
            // Arrange
            var timer1 = new WirelessNetworkAddress("AAAAAA");
            var timer2 = new WirelessNetworkAddress("BBBBBB");
            var timer3 = new WirelessNetworkAddress("CCCCCC");
            NetworkComposition composition = new NetworkCompositionBuilder().Build();

            // Act
            composition = composition.ChangeRolesFor(timer1, DeviceCapabilities.IntermediateSensor,
                DeviceRoles.IntermediateTimer1);
            composition = composition.ChangeRolesFor(timer2, DeviceCapabilities.IntermediateSensor,
                DeviceRoles.IntermediateTimer2);
            composition = composition.ChangeRolesFor(timer3, DeviceCapabilities.IntermediateSensor,
                DeviceRoles.IntermediateTimer3);

            // Assert
            composition.IsInRoleIntermediateTimer1(timer1).Should().BeTrue();
            composition.IsInRoleIntermediateTimer2(timer2).Should().BeTrue();
            composition.IsInRoleIntermediateTimer3(timer3).Should().BeTrue();
        }
        public void When_alert_is_requested_it_must_send_operation()
        {
            // Arrange
            var deviceAddress = new WirelessNetworkAddress("AABBCC");

            using (var testRunner = new CirceUsbLoopbackTestRunner<AlertOperation>())
            {
                testRunner.RemoteSessionManager.ConnectionStateChanged += (s, e) =>
                {
                    if (e.State == ControllerConnectionState.Connected)
                    {
                        testRunner.RemoteSessionManager.AlertAsync(deviceAddress);
                    }
                };

                testRunner.OperationReceived += (s, e) =>
                {
                    var alertOperation = e.Operation as AlertOperation;
                    if (alertOperation != null)
                    {
                        testRunner.SignalSucceeded(alertOperation);
                    }
                };

                // Act
                bool succeeded = testRunner.Start();

                // Assert
                succeeded.Should().Be(true, "<USB loopback cable must be connected and COM port must be correct.>");
                AlertOperation operationNotNull = testRunner.Result.ShouldNotBeNull();
                operationNotNull.DestinationAddress.Should().Be(deviceAddress);
            }
        }
 public UnknownDeviceActionEventArgs(WirelessNetworkAddress source, TimeSpan?sensorTime, RemoteKey?key)
     : base(source, sensorTime)
 {
     Key = key;
 }
Example #43
0
 public RemoteKeyModifierEventArgs(WirelessNetworkAddress source, RemoteKeyModifier modifier, TimeSpan?sensorTime)
     : base(source, sensorTime)
 {
     Modifier = modifier;
 }
Example #44
0
 public RemoteKeyEventArgs(WirelessNetworkAddress source, RemoteKey key, TimeSpan?sensorTime)
     : base(source, sensorTime)
 {
     Key = key;
 }
Example #45
0
        public static void ShouldBeNotifyUnknownAction(this EventArgsWithName <NumberEntryFilter> eventArgsWithName, WirelessNetworkAddress source,
                                                       RemoteKey?key, TimeSpan?time)
        {
            Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName));
            Guard.NotNull(source, nameof(source));

            eventArgsWithName.Name.Should().Be("NotifyUnknownAction");
            eventArgsWithName.EventArgs.Should().BeOfType <UnknownDeviceActionEventArgs>();

            var unknownDeviceActionEventArgs = (UnknownDeviceActionEventArgs)eventArgsWithName.EventArgs;

            unknownDeviceActionEventArgs.Source.Should().Be(source);
            unknownDeviceActionEventArgs.Key.Should().Be(key);
            unknownDeviceActionEventArgs.SensorTime.Should().Be(time);
        }
        private static IEnumerable<Operation> SynchronizingClocks()
        {
            var remote = new WirelessNetworkAddress("AAAAAA");
            var gate1 = new WirelessNetworkAddress("E1E1E1");

            Console.WriteLine("Controller <-connect-> Mediator");
            Console.WriteLine("--> Login");
            yield return new LoginOperation();

            Console.WriteLine("<-- Keep Alive (login response)");
            yield return new KeepAliveOperation(Version.Parse("1.2.34"), 0);

            Console.WriteLine("<-- Notify Status (remote control)");
            yield return
                new NotifyStatusOperation(remote, false,
                    DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor |
                        DeviceCapabilities.FinishSensor | DeviceCapabilities.IntermediateSensor,
                    DeviceRoles.Keypad | DeviceRoles.StartTimer, 200);

            Console.WriteLine("<-- Notify Status (gate, asking for sync)");
            yield return
                new NotifyStatusOperation(gate1, false, DeviceCapabilities.TimeSensor, DeviceRoles.FinishTimer, 150)
                {
                    ClockSynchronization = ClockSynchronizationStatus.RequiresSync
                };

            Console.WriteLine("--> Synchronize clocks");
            yield return new SynchronizeClocksOperation();

            Console.WriteLine("<-- Notify Status (remote control, synced)");
            yield return
                new NotifyStatusOperation(remote, false,
                    DeviceCapabilities.ControlKeypad | DeviceCapabilities.NumericKeypad | DeviceCapabilities.StartSensor |
                        DeviceCapabilities.FinishSensor | DeviceCapabilities.IntermediateSensor,
                    DeviceRoles.Keypad | DeviceRoles.StartTimer, 200)
                {
                    ClockSynchronization = ClockSynchronizationStatus.SyncSucceeded
                };

            Console.WriteLine("<-- Notify Status (gate, synced)");
            yield return
                new NotifyStatusOperation(gate1, false, DeviceCapabilities.TimeSensor, DeviceRoles.FinishTimer, 150)
                {
                    ClockSynchronization = ClockSynchronizationStatus.SyncSucceeded
                };
        }