public PIRDevices(ILoggerFactory loggerFactory, IControlledAreas controlledAreas, ISlaveCollection slaveCollection) { _logger = loggerFactory.CreateLogger <PIRDevices>(); _detects = new List <PIRDevice>(); _controlledAreas = controlledAreas; _slaveCollection = slaveCollection as SlaveColection; // bool startFresh = !System.IO.File.Exists(_xmlPath); //load(startFresh, loggerFactory); foreach (var rpi in _slaveCollection.zeros) { foreach (var rpiDevice in rpi.PirDevices) { PIRDevice pir = new PIRDevice((Enums.ControlledAreas)rpiDevice.area, rpiDevice.deviceName, rpi.ipAddress); pir.mcu.port = rpi.port; _detects.Add(pir); } } foreach (var nodeMcu in _slaveCollection.nodeMCUs) { foreach (var nodeMcuDevice in nodeMcu.PirDevices) { PIRDevice pir = new PIRDevice((Enums.ControlledAreas)nodeMcuDevice.area, nodeMcuDevice.deviceName, nodeMcu.ipAddress); pir.mcu.port = nodeMcu.port; _detects.Add(pir); } } _detects.ForEach(d => d.createLogger(loggerFactory)); _detects.ForEach(d => d.controlledAreas = _controlledAreas.controlledAreas); return; }
public RelayDevices(ILoggerFactory loggerFactory, IControlledAreas controlledAreas, ISlaveCollection slaveCollection) { _logger = loggerFactory.CreateLogger <RelayDevices>(); _relays = new List <RelayDevice>(); _controlledAreas = controlledAreas; //_piCollection = piCollection as PiCollection; _slaveCollection = slaveCollection as SlaveColection; //bool startFresh = !System.IO.File.Exists(_xmlPath); //load(startFresh, loggerFactory); foreach (var rpi in _slaveCollection.zeros.Where(z => z.Relays.Count > 0)) { rpi.Relays.ForEach(r => { RelayDevice relay = new RelayDevice((Enums.ControlledAreas)r.area, r.deviceName, r.state == 1, rpi.ipAddress); relay.mcu.port = rpi.port; _relays.Add(relay); }); //foreach (var rpiDevice in rpi.Relays) //{ // RelayDevice relay = new RelayDevice((Enums.ControlledAreas)rpiDevice.area, // rpiDevice.deviceName, // rpiDevice.state == 1, // rpi.ipAddress); // relay.mcu.port = rpi.port; // _relays.Add(relay); //} } foreach (var nodeMcu in _slaveCollection.nodeMCUs.Where(z => z.Relays.Count > 0)) { nodeMcu.Relays.ForEach(r => { RelayDevice relay = new RelayDevice((Enums.ControlledAreas)r.area, r.deviceName, r.state == 1, nodeMcu.ipAddress); relay.mcu.port = nodeMcu.port; _relays.Add(relay); }); //foreach (var rpiDevice in rpi.Relays) //{ // RelayDevice relay = new RelayDevice((Enums.ControlledAreas)rpiDevice.area, // rpiDevice.deviceName, // rpiDevice.state == 1, // rpi.ipAddress); // relay.mcu.port = rpi.port; // _relays.Add(relay); //} } _relays.ForEach(d => d.createLogger(loggerFactory)); _relays.ForEach(d => d.controlledAreas = _controlledAreas.controlledAreas); return; }
public RFSwitches(ILoggerFactory loggerFactory, IControlledAreas controlledAreas, ISlaveCollection slaveCollection) { _logger = loggerFactory.CreateLogger <RFSwitches>(); _switches = new List <RFSwitchDevice>(); _controlledAreas = controlledAreas; //_piCollection = piCollection as PiCollection; _slaveCollection = slaveCollection as SlaveColection; // bool startFresh = !System.IO.File.Exists(_xmlPath); //load(startFresh, loggerFactory); foreach (var rpi in _slaveCollection.zeros) { foreach (var rfDevice in rpi.RFSwitches) { RFSwitchDevice sw = new RFSwitchDevice((Enums.ControlledAreas)rfDevice.area, rfDevice.deviceName, rfDevice.bitLength); sw.mcu.ipAddress = rpi.ipAddress; sw.mcu.port = rpi.port; rfDevice.onCodes.Skip(1).ToList().ForEach(c => sw.addCode(true, (Convert.ToInt64(c)))); rfDevice.offCodes.Skip(1).ToList().ForEach(c => sw.addCode(false, (Convert.ToInt32(c)))); _switches.Add(sw); } } foreach (var nodeMcu in _slaveCollection.nodeMCUs) { foreach (var rfDevice in nodeMcu.RFSwitches) { RFSwitchDevice sw = new RFSwitchDevice((Enums.ControlledAreas)rfDevice.area, rfDevice.deviceName, rfDevice.bitLength); sw.mcu.ipAddress = nodeMcu.ipAddress; sw.mcu.port = nodeMcu.port; rfDevice.onCodes.Skip(1).ToList().ForEach(c => sw.addCode(true, (Convert.ToInt64(c)))); rfDevice.offCodes.Skip(1).ToList().ForEach(c => sw.addCode(false, (Convert.ToInt32(c)))); _switches.Add(sw); } } _switches.ForEach(d => d.createLogger(loggerFactory)); _switches.ForEach(d => d.controlledAreas = _controlledAreas.controlledAreas); return; }