def _run_mgr(log): """ Run the HF manager until terminated """ log.info('') log.info('****** Starting HF manager ******') try: hf_mgr_thread = HFMgrThread(log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) while True: try: utils.wait(1) if not hf_mgr_thread.is_running(): log.error('Data thread died unexpectedly') break except KeyboardInterrupt: if hf_mgr_config.accept_sigint: log.info('Got SIGINT, shutting down') break else: log.info('Got SIGINT, ignored') except: # handle all unexpected application exceptions exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) hf_mgr_thread.stop() utils.wait_for_child_threads() log.info('****** Exiting HF manager ******')
def _run_wd(log): """ Run the watchdog until terminated """ global gv log.info('') log.info('****** Starting CPU load watchdog ******') try: wd_thread = WDThread(log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) while True: try: utils.wait(0.5) if not wd_thread.is_running(): log.error('Watchdog thread died unexpectedly') break except KeyboardInterrupt: if cpu_load_wd_config.accept_sigint: log.info('Got SIGINT (shutting down)') break else: log.info('Got SIGINT (ignored)') except: sys.exit(1) wd_thread.stop() utils.wait_for_child_threads() log.info('****** Exiting CPU load watchdog ******')
def _runTest(log): """Run basic modem module tests""" irid = RudicsModem(log) # Test dialup method log.debug('') log.debug(' ****** Starting modem module test ******') print 'Testing dialup method' if irid.dialup(): print 'Connected to RUDICS server' msg_ID = 1 while True: test_msg = 'Msg %s:' % str(msg_ID) msg_ID += 1 irid.write(test_msg) print 'sent %s' % test_msg data = irid.read() if data is None: print 'Serial port closed' break else: print 'received %s' % data if not irid.isConnected(): print 'Connection dropped' break utils.wait(2) else: print 'dialup method failed' print 'hanging up' irid.hangup() utils.wait_for_child_threads() print 'All done'
def _run_mgr(log): """ Run the instrument manager until terminated """ global gv log.info('') log.info('****** Starting fluxgate instrument manager ******') try: gv.console = SockConsole('localhost', fg_mgr_config.console_port, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: data_thread = DataThread(gv.console, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: xmlrpc_thread = XMLRPCThread('localhost', fg_mgr_config.XMLRPC_port, data_thread, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) while True: try: utils.wait(0.5) if not gv.console.is_running(): log.error('Console thread died unexpectedly') break if not xmlrpc_thread.is_running(): log.error('XMLRPC server thread died unexpectedly') break if not data_thread.is_running(): log.error('Data thread died unexpectedly') break except KeyboardInterrupt: if fg_mgr_config.accept_sigint: log.info('Got SIGINT (shutting down)') break else: log.info('Got SIGINT (ignored)') except: # handle all unexpected application exceptions exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) data_thread.stop() gv.console.stop() xmlrpc_thread.stop() utils.wait_for_child_threads() log.info('****** Exiting fluxgate instrument manager ******')
def _run_mgr(log): """ Run the instrument manager until terminated via XMLRPC command """ log.info('') log.info('****** Starting USB manager ******') try: console = SockConsole('localhost', usb_mgr_config.console_port, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: dispatcher = Dispatcher(log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: xmlrpc_thread = XMLRPCThread('localhost', usb_mgr_config.XMLRPC_port, console, dispatcher, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) while True: try: utils.wait(0.5) if not console.is_running(): log.error('Console thread died unexpectedly') break if not xmlrpc_thread.is_running(): log.error('XMLRPC server thread died unexpectedly') break if not dispatcher.is_running(): log.error('Dispatcher thread died unexpectedly') break except KeyboardInterrupt: if usb_mgr_config.accept_sigint: log.info('Got SIGINT (shutting down)') break else: log.info('Got SIGINT (ignored)') except: # handle all unexpected application exceptions exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) xmlrpc_thread.stop() dispatcher.stop() console.stop() utils.wait_for_child_threads() log.info('****** Exiting USB manager ******')
def _run_proxy(log): """ Run the server proxy until terminated via KeyboardInterrupt or XMLRPC command """ log.info('') log.info('****** Starting server proxy ******') xfer_rec = XferRec(log) try: modem_svr_connector = ModemSvrConnector(xfer_rec, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: xmlrpc_thread = XMLRPCThread('localhost', svr_proxy_config.XMLRPC_port, xfer_rec, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) while True: try: utils.wait(0.5) if not modem_svr_connector.is_running(): break if not xmlrpc_thread.is_running(): log.error('XMLRPC server thread died unexpectedly') break except KeyboardInterrupt: if svr_proxy_config.accept_sigint: log.info('Got SIGINT (shutting down)') break else: log.info('Got SIGINT ignored)') except: # handle all unexpected application exceptions exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) modem_svr_connector.stop() xmlrpc_thread.stop() utils.wait_for_child_threads() log.info('****** Exiting server proxy ******')
def run_server(log, use_modem): """ Run the modem server until terminated via KeyboardInterrupt or XMLRPC command """ log.info('') log.info('****** Starting modem server ******') try: xmlrpc_thread = XMLRPCThread('localhost', modem_svr_config.XMLRPC_port, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: rudics_conn = RUDICSSvrProxyConnector(log, xmlrpc_thread) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) while True: try: utils.wait(0.5) if not rudics_conn.is_running(): break if not xmlrpc_thread.is_running(): log.error('XMLRPC thread died unexpectedly') break except KeyboardInterrupt: if modem_svr_config.accept_sigint: log.info('Got SIGINT (shutting down)') break else: log.info('Got SIGINT (ignored)') except: # handle all unexpected application exceptions exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) rudics_conn.stop() xmlrpc_thread.stop() utils.wait_for_child_threads() log.info('****** Exiting modem server ******')
def _run_svr(log): """ Run the file server until terminated """ log.info('') log.info('****** Starting File Server ******') try: lan_client_connector = ClientConnector(global_config.our_lan_ip_addr, log) rudics_client_connector = ClientConnector('localhost', log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) while True: try: utils.wait(1) if not lan_client_connector.is_running(): log.error('lan_client_connector died unexpectedly') break if not rudics_client_connector.is_running(): log.error('rudics_client_connector died unexpectedly') break except KeyboardInterrupt: if file_svr_config.accept_sigint: log.info('Got SIGINT, shutting down') break else: log.info('Got SIGINT, ignored') except: # handle all unexpected application exceptions exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) lan_client_connector.stop() rudics_client_connector.stop() utils.wait_for_child_threads() log.info('****** Exiting File Server ******')
def _run_mgr(log, test=False): """ Run the instrument manager until terminated """ log.info('') log.info('****** Starting CASES manager ******') """Open the instrument serial port""" try: serial_port = serial.Serial(port=cases_mgr_config.serial_device, baudrate=cases_mgr_config.baud_rate, rtscts=0, timeout=0, writeTimeout=0, stopbits=serial.STOPBITS_ONE) except serial.SerialException: pass if serial_port.isOpen(): log.info('Serial port %s opened' % serial_port.portstr) else: log.error('Serial port %s failed to open' % serial_port.portstr) sys.exit(1) log.debug(serial_port) try: console = SockConsole('localhost', cases_mgr_config.console_port, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: tx_data_thread = TxDataThread(log, serial_port) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: rx_data_thread = RxDataThread(log, serial_port) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) try: xmlrpc_thread = XMLRPCThread('localhost', cases_mgr_config.XMLRPC_port, tx_data_thread, rx_data_thread, console, log) except: exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) i = 1 while True: try: """ i += 1 if (i % 8) == 0: data_buf = '0123456789ABCDEF' * 128 # 2K data buffer pkt = CASESPkt.CASESPkt() pkt.build(CASESPkt.CASESPkt.UPLOAD_DSP_IMAGE_CMD, data_buf[:2037]) tx_data_thread.enqueue_pkt(pkt) """ utils.wait(0.5) if not console.is_running(): log.error('Console thread died unexpectedly') break if not xmlrpc_thread.is_running(): log.error('XMLRPC server thread died unexpectedly') break if not tx_data_thread.is_running(): log.error('Tx data thread died unexpectedly') break if not rx_data_thread.is_running(): log.error('Rx data thread died unexpectedly') break except KeyboardInterrupt: if cases_mgr_config.accept_sigint: log.info('Got SIGINT (shutting down)') break else: log.info('Got SIGINT (ignored)') except: # handle all unexpected application exceptions exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) break tx_data_thread.stop() rx_data_thread.stop() console.stop() serial_port.close() xmlrpc_thread.stop() utils.wait_for_child_threads() log.info('****** Exiting CASES manager ******')
if hw_mgr_config.accept_sigint: log.info('Got SIGINT (shutting down)') break else: log.info('Got SIGINT (ignored)') except Exception, e: # handle all unexpected application exceptions print '*** Unexpected exception in hw_mgr: %s' % e exc_type, exc_value, exc_traceback = sys.exc_info() utils.log_exc_traceback(exc_type, exc_value, exc_traceback, log) sys.exit(1) break _stop_dig_io() console.stop() xmlrpc_thread.stop() utils.wait_for_child_threads() log.info('****** Exiting hardware manager ******') if __name__ == '__main__': sys.setcheckinterval(global_config.check_interval) if hw_mgr_config.daemonize: utils.daemonize() log = logs.open(hw_mgr_config.log_name, hw_mgr_config.log_dir, hw_mgr_config.log_level, file_max_bytes=hw_mgr_config.log_file_max_bytes, num_backup_files=hw_mgr_config.log_files_backup_files) _run_mgr(log)