From 7cb88688ff698c577ea812bd389e9baaeba24fd9 Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Mon, 14 Aug 2023 19:39:25 +0200
Subject: [PATCH] feat: introduce extenal sensors dummy

---
 Python_script/external_sensors.py | 26 ++++++++++++++++++++++++++
 Python_script/prototype.py        |  4 ++--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/Python_script/external_sensors.py b/Python_script/external_sensors.py
index 6a46c15..b73b0a4 100644
--- a/Python_script/external_sensors.py
+++ b/Python_script/external_sensors.py
@@ -2,6 +2,32 @@ from almemo710 import almemo710
 from almemo2490 import almemo2490
 
 import pandas as pd
+import climate_chamber_dummy
+
+
+class ExternalSensorsDummy:
+    def __init__(self):
+        self.climate_chamber_dummy = climate_chamber_dummy.get_climate_chamber_dummy([0.2, 0.1])
+
+    def get_sensor_values(self):
+        # FIXME: Do we have to run the simulation here or do we piggy-back on the chamber probably also being dummy?
+        temp = self.climate_chamber_dummy.read_temperature()[0]
+        humidity = self.climate_chamber_dummy.read_humidity()[0]
+        # half a degree thermal cycle of 10 minutes from the room's air conditioning
+        room_temp = 22.97 + abs((self.climate_chamber_dummy.last_simulation_time % 600)-300)/600
+        # Use the same DUT chamber values as the simulation, but constant measurement instrument chamber and room
+        # temp_dut, temp_room, temp_meas_instr, hum_dut, hum_room, hum_meas_instr, air_press_room
+        return temp, room_temp, 23.0, humidity, 62.2, 45.0, 1013
+
+    def close(self):
+        pass
+
+
+def create_sensors(logger_model, logger_address, ext_sensor_channels):
+    if logger_address == 'localhost':
+        return ExternalSensorsDummy()
+    else:
+        return ExternalSensors(logger_model, logger_address, ext_sensor_channels)
 
 
 class ExternalSensors:
diff --git a/Python_script/prototype.py b/Python_script/prototype.py
index 5419ee6..305b887 100755
--- a/Python_script/prototype.py
+++ b/Python_script/prototype.py
@@ -75,8 +75,8 @@ class Measurements:
         self.vna = VNA.create_vna(vna_address, target_accuracy)
 
         # data logger for external sensors
-        self.ext_sensors = external_sensors.ExternalSensors(config_data['logger_model'], logger_address,
-                                                            ext_sensor_channels)
+        self.ext_sensors = external_sensors.create_sensors(config_data['logger_model'], logger_address,
+                                                           ext_sensor_channels)
 
         self.standby = standby
         self.output_basename = output_basename
-- 
GitLab