def __init__(self, name, description, units, stype, device, proxy, *formatted_params): self.basename = name self.device = device stype = Sensor.parse_type(stype) params = Sensor.parse_params(stype, formatted_params) Sensor.__init__(self, stype, device.name + '.' + name, description, units, params=params)
def periodic_plot_snapshot(self): log.debug("Start periodic plot") passthrough = ["rxs.packetizer.systemstatus.snapshot.totalpwr.h", "rxs.packetizer.systemstatus.snapshot.totalpwr.v", "rxs.packetizer.1pps.length", "rxs.packetizer.1pps.last", "s-band.center-frequency", "s-band.bandwidth", "s-band.noise-diode", "s-band.sampling-rate", "s-band.time.synchronisation-epoch", "rxs.packetizer.1pps.length", "rxs.packetizer.40g.selected-filter", "rxs.packetizer.device-status"] self.__pass_through_sensors = {} if not self.has_sensor(passthrough[0]): # Checking first is enough log.debug("Adding pass-through sensors") yield self._client._client.until_synced() log.debug("Client synced through sensors") sensor_list = yield self._client._client.list_sensors() for st in sensor_list: if st.name not in passthrough: log.debug(" - ignoring {}".format(st[1])) continue log.debug(" - adding {}".format(st)) try: if st.type == "discrete": t = "string" else: t = st.type s = Sensor(Sensor.parse_type(t), st.name, st.description, st.units) self.__pass_through_sensors[st.name] = st.object except Exception as E: log.exception(E) self.add_sensor(s) else: log.debug("pass through sensors already added") log.debug("Starting periodic plot") with ProcessPoolExecutor(max_workers=1) as executor: try: while self.__plotting: for key in passthrough: sensor = self.get_sensor(key) v = yield self.__pass_through_sensors[key].get_reading() sensor.set_value(v.value, timestamp=v.timestamp) starttime = time.time() data = yield self._client.get_snapshot() plt = yield executor.submit(plot_script, data) log.debug("Setting bandpass sensor with timestamp %", v.timestamp) self._bandpass.set_value(plt[0]) self._level.set_value(plt[1]) duration = time.time() - starttime log.debug("Plot duration: {} s".format(duration)) if duration > self._config['snapshot_frequency']: log.warning("Plot duration {} larger than plot interval!".format(duration, self._config["nplot"])) else: yield sleep(self._config['snapshot_frequency'] - duration) except Exception as E: log.error("Error in periodic plot. Abandon plotting.") log.exception(E)
def add_sensors(self, sensor_infos): """Add fake sensors sensor_infos is a dict <sensor-name> : ( <description>, <unit>, <sensor-type>, <params>*) The sensor info is string-reprs of whatever they are, as they would be on the wire in a real KATCP connection. Values are passed to a katcp.Message object, so some automatic conversions are done, hence it is OK to pass numbers without stringifying them. """ # Check sensor validity. parse_type() and parse_params should raise if not OK for s_name, s_info in sensor_infos.items(): s_type = Sensor.parse_type(s_info[2]) s_params = Sensor.parse_params(s_type, s_info[3:]) self.fake_sensor_infos.update(sensor_infos) self._fic._interface_changed.set()
def __init__(self, name, sensor_type, description, units='', params=None, clock=time): self.name = name sensor_type = Sensor.parse_type(sensor_type) params = str(params).split(' ') if params else None self._sensor = Sensor(sensor_type, name, description, units, params) self.__doc__ = self.description = description self._clock = clock self._listeners = set() self._last_update = SensorUpdate(0.0, 0.0, 'unknown', None) self._strategy = None self._next_period = None self.set_strategy('none')