public void RegisterDeviceNetwork(IDeviceNetwork deviceNetwork, string deviceNetworkUniqueId) { deviceNetworks.Add(deviceNetwork, deviceNetworkUniqueId); deviceNetworksByName.Add(deviceNetworkUniqueId, deviceNetwork); deviceNetwork.Initialize(HomeAutomationSystem.DeviceNetworkHost); }
[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); }
public void Setup() { MainApplication.Initialize("IntegrationTests/Config/MockConfig.json"); serialPort = (MockXBeeSerialPort)MockXBeeDeviceNetworkFactory.SerialPort; xbeeNetwork = HomeAutomationSystem.DeviceNetworkRegistry.GetNetworkByName("xbee"); }
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); }
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); }
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); }
public MachineState(IDeviceNetwork network, ushort maxLineNumber = 20, int maxStringLength = 1024) { MaxLineNumber = maxLineNumber; MaxStringLength = maxStringLength; _network = network ?? throw new ArgumentNullException(nameof(network)); }
/// <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; }
/// <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; }
/// <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); }
[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); }
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); } } }
internal void SendDeviceNetworkDiagnostics(IDeviceNetwork deviceNetwork, object diagnostics) { HomeAutomationSystem.ControllerHost.DeviceNetworkDiagnosticsReceived(deviceNetwork, diagnostics); }
internal void DeviceNetworkDiagnosticsReceived(IDeviceNetwork deviceNetwork, object diagnostics) { OnDeviceNetworkDiagnosticsReceived?.Invoke(deviceNetwork, new DeviceNetworkDiagnosticsEventArgs(diagnostics)); }
private string GetDeviceId(IDeviceNetwork deviceNetwork, byte[] deviceId) { return HomeAutomationSystem.DeviceNetworkRegistry.GetDeviceNetworkUniqueId(deviceNetwork) + deviceId.ToHexString(); }
public void RegisterStagingDevice(IDeviceNetwork deviceNetwork, byte[] deviceByteId) { string deviceId = GetDeviceId(deviceNetwork, deviceByteId); stagingDevices.Add(deviceId); }
public bool IsStagingDevice(IDeviceNetwork deviceNetwork, byte[] deviceByteId) { string deviceId = GetDeviceId(deviceNetwork, deviceByteId); return stagingDevices.Contains(deviceId); }
public FakeDevice(IDeviceNetwork network) { this.DeviceID = GetNextDeviceID(); this.NetworkAddress = new byte[] { 0 }; this.DeviceNetwork = network; }
public string GetDeviceNetworkUniqueId(IDeviceNetwork network) { return deviceNetworks[network]; }
public override void Initialize() { base.Initialize(); _network = IoCManager.Resolve <IDeviceNetwork>(); }
public MachineState([NotNull] IDeviceNetwork network, ushort maxLineNumber = 20) { MaxLineNumber = maxLineNumber; _network = network ?? throw new ArgumentNullException(nameof(network)); }
public MachineState(IDeviceNetwork network, IReadOnlyDictionary <string, Func <Value, Value> > intrinsics) { _network = network ?? throw new ArgumentNullException(nameof(network)); _intrinsics = intrinsics; }