def _control_fgsc_power(self): """If not in commanded state, send command to hw_mgr""" #self._log.info('Entering ControlFGSCPower._control_fgsc_power') [fg_power_state, self._hw_mgr_server ] = utils.get_hw_status('fg_pwr', self._hw_mgr_server, self._hw_mgr_lock, self._log) if fg_power_state is not None: #self._log.info(' fg_power_state is %d' % fg_power_state) if fg_power_state != self.fg_power_setting: if self.fg_power_setting == 1: self._hw_mgr_server = utils.set_power_state( 'fg', 'on', self._hw_mgr_server, self._hw_mgr_lock, self._log) else: self._hw_mgr_server = utils.set_power_state( 'fg', 'off', self._hw_mgr_server, self._hw_mgr_lock, self._log) [sc_power_state, self._hw_mgr_server ] = utils.get_hw_status('sc_pwr', self._hw_mgr_server, self._hw_mgr_lock, self._log) if sc_power_state is not None: #self._log.info(' sc_power_state is %d' % sc_power_state) if sc_power_state != self.sc_power_setting: if self.sc_power_setting == 1: self._hw_mgr_server = utils.set_power_state( 'sc', 'on', self._hw_mgr_server, self._hw_mgr_lock, self._log) else: self._hw_mgr_server = utils.set_power_state( 'sc', 'off', self._hw_mgr_server, self._hw_mgr_lock, self._log)
def _control_gps_power(self): [sync_age, self._hw_mgr_server ] = utils.get_hw_status('sync_age', self._hw_mgr_server, self._hw_mgr_lock, self._log) if sync_age is None: self._log.error('Could not get sync_age from hw_mgr') return if sync_age < self._max_sync_age: # gps power should be off [status, self._hw_mgr_server ] = utils.get_hw_status('gps_pwr', self._hw_mgr_server, self._hw_mgr_lock, self._log) if (status is not None) and (status == 1): self._hw_mgr_server = utils.set_power_state( 'gps', 'off', self._hw_mgr_server, self._hw_mgr_lock, self._log) if sync_age > self._max_sync_age: # gps power should be on [status, self._hw_mgr_server ] = utils.get_hw_status('gps_pwr', self._hw_mgr_server, self._hw_mgr_lock, self._log) if (status is not None) and (status == 0): self._hw_mgr_server = utils.set_power_state( 'gps', 'on', self._hw_mgr_server, self._hw_mgr_lock, self._log)
def _control_temp(self): [temp, self._hw_mgr_server ] = utils.get_hw_status('router_temp', self._hw_mgr_server, self._hw_mgr_lock, self._log) if temp is None: self._log.error('Could not get router board temp from hw_mgr') return if temp > (self.setpoint + self._hysteresis): self._htr_desired_state = 0 if temp < (self.setpoint - self._hysteresis): self._htr_desired_state = 1 [htr_state, self._hw_mgr_server ] = utils.get_hw_status('htr_pwr', self._hw_mgr_server, self._hw_mgr_lock, self._log) if htr_state is None: self._log.error('Could not get heater power status from hw_mgr') return if htr_state != self._htr_desired_state: if self._htr_desired_state == 1: self._hw_mgr_server = utils.set_power_state( 'htr', 'on', self._hw_mgr_server, self._hw_mgr_lock, self._log) else: self._hw_mgr_server = utils.set_power_state( 'htr', 'off', self._hw_mgr_server, self._hw_mgr_lock, self._log)
def _get_temp(self): """ Set self._temp. Return True if the temp is known. """ [self._temp, self._hw_mgr_svr_proxy] = \ utils.get_hw_status('router_temp', self._hw_mgr_svr_proxy, self._hw_mgr_lock, self._log) return self._temp != None
def _get_power_state(self): """ Set self._power_state. Return True if the power state is known. """ [self._power_state, self._hw_mgr_svr_proxy] = \ utils.get_hw_status('cases_pwr', self._hw_mgr_svr_proxy, self._hw_mgr_lock, self._log) return self._power_state != None
def _modem_is_powered_up(self): [status, self._hw_mgr_server ] = utils.get_hw_status('irid_pwr', self._hw_mgr_server, self._hw_mgr_lock, self._log) if status is None: return False return status == 1
def _hf_power_is_on(self): """ Return True if HF power is on. """ [power_state, self._hw_mgr_svr_proxy] = \ utils.get_hw_status('hf_pwr', self._hw_mgr_svr_proxy, self._hw_mgr_lock, self._log) if power_state == None: self._log.error('Could not get the HF power state') return False return power_state == 1
def _get_fg_electronics_temp(self): """ Return the FG electronics temp. Return 30.0 if the temp is unknown. """ [temp, self._hw_mgr_svr_proxy] = \ utils.get_hw_status('fg_elec_temp', self._hw_mgr_svr_proxy, self._hw_mgr_lock, self._log) if temp == None: self._log.error('Could not get the fluxgate electronics temp') return 30.0 # A reasonable default return temp
def _wait_for_UTC_sync(self): hw_mgr_server = None dummy_lock = utils.Lock(self._log) while not self._stop_event.isSet(): [utc_sync_age, hw_mgr_server] = utils.get_hw_status('sync_age', hw_mgr_server, dummy_lock, self._log) if (utc_sync_age is not None) and (utc_sync_age < 10000): break utils.wait(0.5)
def run(self): """The actual thread code""" self._log.debug('Starting %s ' % self.name) self._running = True self._started = True self._open_serial_port() if not self._serial_port_open: self._stop_event.set() self._log.info('Waiting for UTC synchronization') hw_mgr_server = None dummy_lock = utils.Lock(self._log) while not self._stop_event.isSet(): [utc_sync_age, hw_mgr_server] = utils.get_hw_status('sync_age', hw_mgr_server, dummy_lock, self._log) # 3 Lines Added Jan2018 by SEC to bypass UTC sync in case of GPS fault if (utc_sync_age is not None) and (utc_sync_age > 10000): self._log.info('SYNC_AGE_FAULT: Bypassing UTC Synchronization') break if (utc_sync_age is not None) and (utc_sync_age < 10000): break utils.wait(0.5) if not self._stop_event.isSet(): self._log.info('Synchronized with UTC') self._port.flushInput() while not self._stop_event.isSet(): bytes_avail = self._port.inWaiting() if bytes_avail > 0: self._process_rx_bytes(self._port.read(bytes_avail)) utils.wait(0.05) self._running = False self._close_data_file() if self._data_file_path is not None: self._close_data_file() save_file_thread = SaveFileThread(self._data_file_path, True, self._log) save_file_thread.join() if self._serial_port_open: self._port.close() #self._log.debug('Stopping %s ' % self.name) if self._exit_callback: self._exit_callback(self) self._log.debug('Exiting %s ' % self.name)
def _wait_for_hw_mgr(log): """hw_mgr takes a while before it is ready to accept XMLRPC commands. Wait here until it accepts a command. Return True if successful. """ start_time = time.time() hw_mgr_server = None dummy_lock = utils.Lock(log) while True: if (time.time() - start_time) > super_config.xmlrpc_conn_timeout: log.error('Timed out connecting to hw_mgr XMLRPC server.') return False [status, hw_mgr_server] = utils.get_hw_status('fg_pwr', hw_mgr_server, dummy_lock, log) if status is None: utils.wait(1) else: break return True