コード例 #1
0
        public void RegisterDeviceNetwork(IDeviceNetwork deviceNetwork, string deviceNetworkUniqueId)
        {
            deviceNetworks.Add(deviceNetwork, deviceNetworkUniqueId);
            deviceNetworksByName.Add(deviceNetworkUniqueId, deviceNetwork);

            deviceNetwork.Initialize(HomeAutomationSystem.DeviceNetworkHost);
        }
コード例 #2
0
        [NotNull] public static MachineState Execute2(int count, [NotNull] IDeviceNetwork network, [NotNull] params string[] lines)
        {
            var state = new MachineState(network);

            var pc = 0;

            while (pc < 20)
            {
                if (pc >= lines.Length || count-- <= 0)
                {
                    break;
                }

                var line   = lines[pc];
                var tokens = Tokenizer.TryTokenize(line);
                Assert.IsTrue(tokens.HasValue, tokens.FormatErrorMessageFragment());

                var parsed = Parser.TryParseLine(tokens.Value);
                Assert.IsTrue(parsed.HasValue, parsed.FormatErrorMessageFragment());

                try
                {
                    pc = parsed.Value.Evaluate(pc, state);
                }
                catch (ExecutionException)
                {
                    pc++;
                }
            }

            return(state);
        }
コード例 #3
0
        public void Setup()
        {
            MainApplication.Initialize("IntegrationTests/Config/MockConfig.json");

            serialPort = (MockXBeeSerialPort)MockXBeeDeviceNetworkFactory.SerialPort;
            xbeeNetwork = HomeAutomationSystem.DeviceNetworkRegistry.GetNetworkByName("xbee");
        }
コード例 #4
0
ファイル: TestExecutor.cs プロジェクト: martindevans/Yolol
        public static MachineState Execute2(int count, IDeviceNetwork network, params string[] lines)
        {
            var result = Parser.ParseProgram(string.Join("\n", lines));

            if (!result.IsOk)
            {
                Assert.Fail(result.Err.ToString());
            }

            var state = new MachineState(network);

            var pc = 0;

            while (pc < 20)
            {
                if (pc >= lines.Length || count-- <= 0)
                {
                    break;
                }

                var line = result.Ok.Lines[pc];
                try
                {
                    pc = line.Evaluate(pc, state);
                }
                catch (ExecutionException)
                {
                    pc++;
                }
            }

            return(state);
        }
コード例 #5
0
ファイル: TestExecutor.cs プロジェクト: martindevans/Yolol
        public static MachineState Execute(IDeviceNetwork network, params string[] lines)
        {
            var result = Parser.ParseProgram(string.Join("\n", lines) + "\n");

            if (!result.IsOk)
            {
                Assert.Fail(result.Err.ToString());
            }

            var state = new MachineState(network);

            var pc = 0;

            while (pc < 20)
            {
                if (pc >= lines.Length)
                {
                    break;
                }

                var line = result.Ok.Lines[pc];
                pc = line.Evaluate(pc, state);
            }

            return(state);
        }
コード例 #6
0
        public static MachineState Execute2(int count, [NotNull] IDeviceNetwork network, [NotNull] Program p)
        {
            var state = new MachineState(network);

            var pc = 0;

            while (pc < 20)
            {
                if (pc >= p.Lines.Count || count-- <= 0)
                {
                    break;
                }

                var line = p.Lines[pc];

                try
                {
                    pc = line.Evaluate(pc, state);
                }
                catch (ExecutionException)
                {
                    pc++;
                }
            }

            return(state);
        }
コード例 #7
0
ファイル: MachineState.cs プロジェクト: martindevans/Yolol
        public MachineState(IDeviceNetwork network, ushort maxLineNumber = 20, int maxStringLength = 1024)
        {
            MaxLineNumber   = maxLineNumber;
            MaxStringLength = maxStringLength;

            _network = network ?? throw new ArgumentNullException(nameof(network));
        }
コード例 #8
0
        /// <summary>
        /// Returns the device type by it's typeId.
        /// </summary>
        /// <param name="deviceNetwork"></param>
        /// <param name="deviceTypeId"></param>
        /// <returns></returns>
        public Type GetDeviceType(IDeviceNetwork deviceNetwork, int deviceTypeId)
        {
            string networkId = HomeAutomationSystem.DeviceNetworkRegistry.GetDeviceNetworkUniqueId(deviceNetwork);

            string key = $"{networkId}-{deviceTypeId}";

            return deviceTypes.ContainsKey(key) ? deviceTypes[key] : null;
        }
コード例 #9
0
        /// <summary>
        /// Returns the class type that handles all things related to the device with the specified address.
        /// </summary>
        /// <param name="deviceByteId"></param>
        /// <returns></returns>
        public IDevice GetDeviceById(IDeviceNetwork deviceNetwork, byte[] deviceByteId)
        {
            string deviceId = GetDeviceId(deviceNetwork, deviceByteId);

            IDevice device = deviceRegistry.ContainsKey(deviceId) ? (IDevice)deviceRegistry[deviceId] : null;

            return device;
        }
コード例 #10
0
        /// <summary>
        /// Registers a device into the system.
        /// </summary>
        /// <param name="deviceNetwork">The device network for this device.</param>
        /// <param name="device">The device instance that handles all things related to a device.</param>
        /// <param name="deviceByteId">The address/id of the device.</param>
        public void RegisterDevice(IDeviceNetwork deviceNetwork, IDevice device, byte[] deviceByteId)
        {
            string deviceId = GetDeviceId(deviceNetwork, deviceByteId);

            if (deviceRegistry.ContainsKey(deviceId))
            {
                Log.Debug("Replacing device for id: " + deviceId);
            }

            // make sure before we add this device to our network, we will
            // set the deviceNetwork for this device.
            ((DeviceBase)device).DeviceNetwork = deviceNetwork;

            deviceRegistry[deviceId] = device;

            stagingDevices.Remove(deviceId);
        }
コード例 #11
0
        [NotNull] public static MachineState Execute([NotNull] IDeviceNetwork network, [NotNull] Program p)
        {
            var state = new MachineState(network);

            var pc = 0;

            while (pc < 20)
            {
                if (pc >= p.Lines.Count)
                {
                    break;
                }

                var line = p.Lines[pc];
                pc = line.Evaluate(pc, state);
            }

            return(state);
        }
コード例 #12
0
        public void RegisterDeviceWithTypeID(IDeviceNetwork deviceNetwork, int deviceIdentification, byte[] address, byte[] networkAddress)
        {
            if (IsStagingDevice(deviceNetwork, address))
            {
                // get the device from the configuration based on this type id
                Type deviceType = HomeAutomationSystem.DeviceTypeRegistry.GetDeviceType(deviceNetwork, deviceIdentification);
                IDevice device = Activator.CreateInstance(deviceType) as IDevice;

                if (device != null)
                {
                    device.DeviceID = address;
                    device.NetworkAddress = networkAddress;

                    RegisterDevice(deviceNetwork, device, device.DeviceID);
                }
                else
                {
                    Log.Debug($"The device type specified by the sensor with ID {address.ToHexString()} is not know.");

                    RegisterDevice(deviceNetwork, new UnknownDevice(), address);
                }
            }
        }
コード例 #13
0
 internal void SendDeviceNetworkDiagnostics(IDeviceNetwork deviceNetwork, object diagnostics)
 {
     HomeAutomationSystem.ControllerHost.DeviceNetworkDiagnosticsReceived(deviceNetwork, diagnostics);
 }
コード例 #14
0
 internal void DeviceNetworkDiagnosticsReceived(IDeviceNetwork deviceNetwork, object diagnostics)
 {
     OnDeviceNetworkDiagnosticsReceived?.Invoke(deviceNetwork, new DeviceNetworkDiagnosticsEventArgs(diagnostics));
 }
コード例 #15
0
 private string GetDeviceId(IDeviceNetwork deviceNetwork, byte[] deviceId)
 {
     return HomeAutomationSystem.DeviceNetworkRegistry.GetDeviceNetworkUniqueId(deviceNetwork) + deviceId.ToHexString();
 }
コード例 #16
0
        public void RegisterStagingDevice(IDeviceNetwork deviceNetwork, byte[] deviceByteId)
        {
            string deviceId = GetDeviceId(deviceNetwork, deviceByteId);

            stagingDevices.Add(deviceId);
        }
コード例 #17
0
        public bool IsStagingDevice(IDeviceNetwork deviceNetwork, byte[] deviceByteId)
        {
            string deviceId = GetDeviceId(deviceNetwork, deviceByteId);

            return stagingDevices.Contains(deviceId);
        }
コード例 #18
0
ファイル: FakeDevice.cs プロジェクト: moszinet/HomeAutomation
 public FakeDevice(IDeviceNetwork network)
 {
     this.DeviceID = GetNextDeviceID();
     this.NetworkAddress = new byte[] { 0 };
     this.DeviceNetwork = network;
 }
コード例 #19
0
 public string GetDeviceNetworkUniqueId(IDeviceNetwork network)
 {
     return deviceNetworks[network];
 }
コード例 #20
0
        public override void Initialize()
        {
            base.Initialize();

            _network = IoCManager.Resolve <IDeviceNetwork>();
        }
コード例 #21
0
ファイル: MachineState.cs プロジェクト: thomasio101/Yolol
 public MachineState([NotNull] IDeviceNetwork network, ushort maxLineNumber = 20)
 {
     MaxLineNumber = maxLineNumber;
     _network      = network ?? throw new ArgumentNullException(nameof(network));
 }
コード例 #22
0
ファイル: MachineState.cs プロジェクト: Antr0py/Yolol
 public MachineState(IDeviceNetwork network, IReadOnlyDictionary <string, Func <Value, Value> > intrinsics)
 {
     _network    = network ?? throw new ArgumentNullException(nameof(network));
     _intrinsics = intrinsics;
 }