public void DeactivateTest() { LightSensor ls = new LightSensor(); FireSensor fs = new FireSensor(); DoorSensor ds = new DoorSensor(); ls.Activate(); fs.Activate(); ds.Activate(); Assert.IsNotNull(ls.alarm); Assert.IsNotNull(fs.alarm); Assert.IsNotNull(ds.alarm); bool lsStatus = ls.checkStatus(); bool fsStatus = fs.checkStatus(); bool dsStatus = ds.checkStatus(); Assert.IsTrue(lsStatus); Assert.IsTrue(fsStatus); Assert.IsTrue(dsStatus); ls.Deactivate(); fs.Deactivate(); ds.Deactivate(); Assert.IsNull(ls.alarm); Assert.IsNull(fs.alarm); Assert.IsNull(ds.alarm); }
/// <summary> /// Notifies the door that the specified sensor has been deleted. /// </summary> public void RemoveActiveSensorAll(DoorSensor sensor) { for (int i = m_activeSensors.Count - 1; i >= 0; i--) { if (m_activeSensors[i] == sensor) { m_activeSensors.RemoveAt(i); } } UpdateOpenState(); }
public void TestCreator() { LightSensor ls = new LightSensor(); Assert.IsNotNull(ls); FireSensor fs = new FireSensor(); Assert.IsNotNull(fs); DoorSensor ds = new DoorSensor(); Assert.IsNotNull(ds); }
public void GetUIDTest() { LightSensor ls = new LightSensor(); FireSensor fs = new FireSensor(); LightSensor ls2 = new LightSensor(); FireSensor fs2 = new FireSensor(); DoorSensor ds = new DoorSensor(); DoorSensor ds2 = new DoorSensor(); Assert.AreNotEqual(ls.getSensorUID(), ls2.getSensorUID()); Assert.AreNotEqual(fs.getSensorUID(), fs2.getSensorUID()); Assert.AreNotEqual(ds.getSensorUID(), ds2.getSensorUID()); }
public void CheckStatusTest() { LightSensor ls = new LightSensor(); FireSensor fs = new FireSensor(); DoorSensor ds = new DoorSensor(); bool lsStatus = ls.checkStatus(); bool fsStatus = fs.checkStatus(); bool dsStatus = ds.checkStatus(); Assert.IsFalse(lsStatus); Assert.IsFalse(fsStatus); Assert.IsFalse(dsStatus); }
/// <summary> /// Sets the right light according to the state of the sensor /// </summary> /// <param name="sensor"></param> private void SetLightIndicator(DoorSensor sensor) { if (sensor.IsClosed) { RedRect.Visibility = Visibility.Visible; GreenRect.Visibility = Visibility.Hidden; } else { RedRect.Visibility = Visibility.Hidden; GreenRect.Visibility = Visibility.Visible; } }
/// <summary> /// Starts a Timer for the updating of the sensor data /// </summary> /// <param name="sensor"></param> private void StartTimer(DoorSensor sensor) { var startTimeSpan = TimeSpan.Zero; var periodTimeSpan = TimeSpan.FromSeconds(sensor.PollingInterval); Timer = new System.Threading.Timer( async(e) => { await updadeSensor(sensor); Application.Current.Dispatcher.Invoke(() => SetLightIndicator(sensor)); }, null, startTimeSpan, periodTimeSpan); }
/// <summary> /// Adds sensor with the given "data" to the Sensors List /// </summary> /// <param name="data"></param> /// <param name="rangeBoundaries"></param> /// <returns>True if the sensor is added successfully, False otherwise</returns> public bool AddSensor(SensorData data, RangeBoundaries <string> rangeBoundaries) { bool success = true; Sensor sensor = null; try { switch (data.Type) { case "DoorSensor": sensor = new DoorSensor(data); break; case "ElPowerSensor": sensor = new ElPowerSensor(data, new RangeBoundaries <int>(int.Parse(rangeBoundaries.Min), int.Parse(rangeBoundaries.Max))); break; case "NoiseSensor": sensor = new NoiseSensor(data, new RangeBoundaries <int>(int.Parse(rangeBoundaries.Min), int.Parse(rangeBoundaries.Max))); break; case "HumiditySensor": sensor = new HumiditySensor(data, new RangeBoundaries <float>(float.Parse(rangeBoundaries.Min), float.Parse(rangeBoundaries.Max))); break; case "TemperatureSensor": sensor = new TemperatureSensor(data, new RangeBoundaries <double>(double.Parse(rangeBoundaries.Min), double.Parse(rangeBoundaries.Max))); break; default: break; } Sensors.Add(sensor); SaveState(); } catch (Exception) { MessageBox.Show("Failed to add the sensor!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); success = false; } return(success); }
public void SupressSensorTest() { LightSensor ls = new LightSensor(); FireSensor fs = new FireSensor(); DoorSensor ds = new DoorSensor(); Alarm lsA = ls.triggerSensor(); Alarm fsA = fs.triggerSensor(); Alarm dsA = ds.triggerSensor(); ls.Deactivate(); fs.Deactivate(); ds.Deactivate(); bool lsStatus = ls.checkStatus(); bool fsStatus = fs.checkStatus(); bool dsStatus = ds.checkStatus(); Assert.IsFalse(lsStatus); Assert.IsFalse(fsStatus); Assert.IsFalse(dsStatus); }
public ISensor CreateSensor(int inType) { ISensor sensor; switch ((SensorType)inType) { case SensorType.SmokeSensor: sensor = new FireSensor(); break; case SensorType.LightSensor: sensor = new LightSensor(); break; case SensorType.DoorSensor: sensor = new DoorSensor(); break; default: sensor = null; break; } return(sensor); }
static void Main(string[] args) { // configure Redis var redis = new RedisClient("127.0.0.1"); //*****TREVISO***** int idtreviso = 1; var d1 = new DoorSensor(idtreviso); // init sensors List <ISensor> sensors1 = new List <ISensor> { new GPSSensor(idtreviso, d1), d1, new PassCount(d1, 2, idtreviso) }; //*****PADOVA***** int idpadova = 2; var d2 = new DoorSensor(idpadova); // init sensors List <ISensor> sensors2 = new List <ISensor> { new GPSSensor(idpadova, d2), d2, new PassCount(d2, 2, idpadova) }; //*****VERONA***** int idverona = 3; var d3 = new DoorSensor(idverona); // init sensors List <ISensor> sensors3 = new List <ISensor> { new GPSSensor(idverona, d3), d3, new PassCount(d3, 2, idverona) }; //*****VICENZA***** int idvicenza = 4; var d4 = new DoorSensor(idvicenza); // init sensors List <ISensor> sensors4 = new List <ISensor> { new GPSSensor(idvicenza, d4), d4, new PassCount(d4, 2, idvicenza) }; while (true) { var data1 = ToJSON(idtreviso); var data2 = ToJSON(idpadova); var data3 = ToJSON(idverona); var data4 = ToJSON(idvicenza); foreach (Sensor sensor1 in sensors1) { data1 += sensor1.ToJson(); } foreach (Sensor sensor2 in sensors2) { data2 += sensor2.ToJson(); } foreach (Sensor sensor3 in sensors3) { data3 += sensor3.ToJson(); } foreach (Sensor sensor4 in sensors4) { data4 += sensor4.ToJson(); } Console.WriteLine(data1); Console.WriteLine(data2); Console.WriteLine(data3); Console.WriteLine(data4); //push to redis queue redis.LPush("sensors_data", data1); redis.LPush("sensors_data", data2); redis.LPush("sensors_data", data3); redis.LPush("sensors_data", data4); System.Threading.Thread.Sleep(500); } }
/// <summary> /// Notifies the door that the specified sensor has been deactivated. /// </summary> public void RemoveActiveSensor(DoorSensor sensor) { m_activeSensors.Remove(sensor); UpdateOpenState(); }
/// <summary> /// Notifies the door that the specified sensor has been activated. /// </summary> public void AddActiveSensor(DoorSensor sensor) { m_activeSensors.Add(sensor); UpdateOpenState(); }
public void Setup() { _uut = new DoorSensor(); }
public static int Main() => DoorSensor.RunAsync().Result;
/// <summary> /// Initializes the members of the class and the meter's data /// </summary> /// <param name="sensor"></param> /// <param name="update"></param> public void InitializeData(DoorSensor sensor, Func <Sensor, Task> update) { updadeSensor = update; StartTimer(sensor); }