def wod_listener(): sock = Udpsocket(('127.0.0.1', settings.WOD_UDP_PORT)) while 1: try: conn, addr = sock.recv() except IOError: logger.info('WOD listerner is terminated or something bad happened to accept') return logger.debug("WOD received %s", conn) # Write to disk the binary packet timestr = time.strftime("%Y%m%d-%H%M%S") fwname = log_path + "WOD_RX/wod_" + timestr + ".hex" myfile = open(fwname, 'w') myfile.write(conn) myfile.close() data = wod_decode(conn) # Write to disk the decoded packet timestr = time.strftime("%Y%m%d-%H%M%S") fwname = log_path + "WOD_RX_DEC/wod_" + timestr + ".json" myfile = open(fwname, 'w') myfile.write(str(data['content'])) myfile.close() # Data must be sent to socket.io here socketio.emit('backend_msg', data, namespace='/control_rx', callback=success_message_to_frontend())
def ecss_feeder(port): sleep(1) logger.info('Started ecss feeder') sock = Udpsocket(('127.0.0.1', port)) while 1: try: conn = sock.recv() except IOError: logger.info('Ecss feeder is terminated or something bad happened to accept') return data = ecss_logic_utils.ecss_logic(cPickle.loads(conn[0])) # Data must be sent to socket.io here socketio.emit('backend_msg', data, namespace='/control_rx', callback=success_message_to_frontend())
def status_listener(): logger.info('Started upsat status listener') logger.info('Starting scheduler...') scheduler.start() scheduler.remove_all_jobs() interval = settings.SATNOGS_NETWORK_API_QUERY_INTERVAL scheduler.add_job(get_jobs, 'interval', minutes=interval) msg = 'Registering `get_jobs` periodic task ({0} min. interval)'.format(interval) logger.info(msg) interval = settings.SATNOGS_NETWORK_API_POST_INTERVAL msg = 'Registering `post_data` periodic task ({0} min. interval)'.format(interval) logger.info(msg) scheduler.add_job(post_data, 'interval', minutes=interval) tf = Process(target=task_feeder, args=(settings.TASK_FEEDER_TCP_PORT,)) tf.start() d = Process(target=downlink, args=()) d.daemon = True d.start() os.environ['TASK_FEEDER_PID'] = str(tf.pid) sock = Udpsocket(('127.0.0.1', settings.STATUS_LISTENER_PORT)) os.environ['BACKEND_TX_PID'] = '0' os.environ['BACKEND_RX_PID'] = '0' os.environ['BACKEND'] = "" os.environ['MODE'] = "network" os.environ['ECSS_FEEDER_PID'] = '0' os.environ['GNURADIO_SCRIPT_PID'] = '0' os.environ['SCHEDULER'] = 'ON' while 1: conn = sock.recv() dictionary = json.loads(conn[0]) if 'backend' in dictionary.keys(): if dictionary['backend'] == os.environ['BACKEND']: continue kill_cmd_ctrl_proc() if dictionary['backend'] == 'gnuradio': if os.environ['BACKEND'] == 'serial': serial_handler.close() os.environ['BACKEND'] = 'gnuradio' rx = Process(target=read_from_gnuradio, args=()) rx.daemon = True rx.start() logger.info('Started gnuradio rx process %d', rx.pid) os.environ['BACKEND_RX_PID'] = str(rx.pid) elif dictionary['backend'] == 'serial': os.environ['BACKEND'] = 'serial' serial_handler.init() rx = Process(target=serial_handler.read_from_serial, args=()) rx.daemon = True rx.start() os.environ['BACKEND_RX_PID'] = str(rx.pid) if 'mode' in dictionary.keys(): if dictionary['mode'] == os.environ['MODE']: continue logger.info('Changing mode') if dictionary['mode'] == 'cmd_ctrl': logger.info('Starting ecss feeder thread...') os.environ['MODE'] = 'cmd_ctrl' kill_netw_proc() ef = Process(target=ecss_feeder, args=(settings.ECSS_FEEDER_UDP_PORT,)) start_wod_thread() ef.start() os.environ['ECSS_FEEDER_PID'] = str(ef.pid) logger.info('Started ecss_feeder process %d', ef.pid) elif dictionary['mode'] == 'network': os.environ['MODE'] = 'network' kill_cmd_ctrl_proc() kill_wod_thread() if int(os.environ['ECSS_FEEDER_PID']) != 0: os.kill(int(os.environ['ECSS_FEEDER_PID']), signal.SIGTERM) os.environ['ECSS_FEEDER_PID'] = '0' os.environ['SCHEDULER'] = 'ON' scheduler.start() tf = Process(target=task_feeder, args=(settings.TASK_FEEDER_TCP_PORT,)) tf.start() os.environ['TASK_FEEDER_PID'] = str(tf.pid) logger.info('Started task feeder process %d', tf.pid)
def status_listener(): logger.info('Started upsat status listener') logger.info('Starting scheduler...') scheduler.start() scheduler.remove_all_jobs() interval = settings.NETWORK_API_QUERY_INTERVAL scheduler.add_job(get_jobs, 'interval', minutes=interval) msg = 'Registering `get_jobs` periodic task ({0} min. interval)'.format(interval) logger.info(msg) interval = settings.NETWORK_API_POST_INTERVAL msg = 'Registering `post_data` periodic task ({0} min. interval)'.format(interval) logger.info(msg) scheduler.add_job(post_data, 'interval', minutes=interval) tf = Process(target=task_feeder, args=(settings.TASK_FEEDER_TCP_PORT,)) tf.start() d = Process(target=downlink, args=()) d.daemon = True d.start() os.environ['TASK_FEEDER_PID'] = str(tf.pid) sock = Udpsocket(('127.0.0.1', settings.STATUS_LISTENER_PORT)) os.environ['BACKEND_TX_PID'] = '0' os.environ['BACKEND_RX_PID'] = '0' os.environ['BACKEND'] = "" os.environ['MODE'] = "network" os.environ['ECSS_FEEDER_PID'] = '0' os.environ['GNURADIO_SCRIPT_PID'] = '0' os.environ['SCHEDULER'] = 'ON' while 1: conn = sock.recv() dictionary = json.loads(conn[0]) if 'backend' in dictionary.keys(): if dictionary['backend'] == os.environ['BACKEND']: continue kill_cmd_ctrl_proc() if dictionary['backend'] == 'gnuradio': if os.environ['BACKEND'] == 'serial': serial_handler.close() os.environ['BACKEND'] = 'gnuradio' rx = Process(target=read_from_gnuradio, args=()) rx.daemon = True rx.start() logger.info('Started gnuradio rx process %d', rx.pid) os.environ['BACKEND_RX_PID'] = str(rx.pid) elif dictionary['backend'] == 'serial': os.environ['BACKEND'] = 'serial' serial_handler.init() rx = Process(target=serial_handler.read_from_serial, args=()) rx.daemon = True rx.start() os.environ['BACKEND_RX_PID'] = str(rx.pid) if 'mode' in dictionary.keys(): if dictionary['mode'] == os.environ['MODE']: continue logger.info('Changing mode') if dictionary['mode'] == 'cmd_ctrl': logger.info('Starting ecss feeder thread...') os.environ['MODE'] = 'cmd_ctrl' kill_netw_proc() ef = Process(target=ecss_feeder, args=(settings.ECSS_FEEDER_UDP_PORT,)) start_wod_thread() ef.start() os.environ['ECSS_FEEDER_PID'] = str(ef.pid) logger.info('Started ecss_feeder process %d', ef.pid) elif dictionary['mode'] == 'network': os.environ['MODE'] = 'network' kill_cmd_ctrl_proc() kill_wod_thread() if int(os.environ['ECSS_FEEDER_PID']) != 0: os.kill(int(os.environ['ECSS_FEEDER_PID']), signal.SIGTERM) os.environ['ECSS_FEEDER_PID'] = '0' os.environ['SCHEDULER'] = 'ON' scheduler.start() tf = Process(target=task_feeder, args=(settings.TASK_FEEDER_TCP_PORT,)) tf.start() os.environ['TASK_FEEDER_PID'] = str(tf.pid) logger.info('Started task feeder process %d', tf.pid)