def read_from_gnuradio(): logger.info('Started gnuradio listener process') while True: conn = backend_listener_sock.recv() buf_in = bytearray(conn[0]) ecss_dict = {} ret = packet.deconstruct_packet(buf_in, ecss_dict, "gnuradio") ecss_dict = ret[0] pickled = cPickle.dumps(ecss_dict) if len(ecss_dict) == 0: logger.error( 'Ecss Dictionary not properly constructed. Error occured') continue try: if ecss_dict['ser_type'] == packet_settings.TC_LARGE_DATA_SERVICE: if ecss_dict[ 'ser_subtype'] <= 8: # 8 is sthe maximum service subtype corresponding to Large Data downlink ld_downlink_socket.sendto( pickled, ('127.0.0.1', client_settings.LD_DOWNLINK_LISTEN_PORT)) else: ld_uplink_socket.sendto( pickled, ('127.0.0.1', client_settings.LD_UPLINK_LISTEN_PORT)) else: ecss_feeder_sock.sendto( pickled, ('127.0.0.1', client_settings.ECSS_FEEDER_UDP_PORT)) except KeyError: logger.error( 'Ecss Dictionary not properly constructed. Error occured. Key \'ser_type\' not in dictionary' )
def decode_and_send(buf_in): ecss_dict = {} ret = packet.deconstruct_packet(buf_in, ecss_dict, "gnuradio") ecss_dict = ret[0] data = ecss_logic_utils.ecss_logic(ecss_dict) socketio.emit('backend_msg', data, namespace='/control_rx', callback=success_message_to_frontend())
def read_from_serial(): global port global ecss_feeder_sock global ui_listener_sock global ld_socket logger.info('Started serial listener process') buf_in = bytearray(0) while True: try: if port != 0: c = port.read() else: logger.info('Serial port is closed') except serial.SerialException as e: logger.error('Could not read from serial port. Error occured') logger.error(e) return if len(c) != 0: buf_in.append(c) if len(buf_in) == 1 and buf_in[0] != 0x7E: buf_in = bytearray(0) elif len(buf_in) > 1 and buf_in[len(buf_in) - 1] == 0x7E: logger_packet = ''.join('{:02x}'.format(x) for x in buf_in) logger.info('Received packet from serial.') logger.debug('From serial: %s', logger_packet) ecss_dict = {} ret = packet.deconstruct_packet(buf_in, ecss_dict, "serial") ecss_dict = ret[0] pickled = cPickle.dumps(ecss_dict) logger.debug('Sending to UDP: %s', ecss_dict) if len(ecss_dict) == 0: logger.error( 'Ecss Dictionary not properly constructed. Error occured' ) continue try: if not ecss_dict and ecss_dict[ 'ser_type'] == packet_settings.TC_LARGE_DATA_SERVICE: ld_socket.sendto( pickled, ('127.0.0.1', client_settings.LD_UPLINK_LISTEN_PORT)) else: ecss_feeder_sock.sendto( pickled, ('127.0.0.1', client_settings.ECSS_FEEDER_UDP_PORT)) except KeyError: logger.error( 'Ecss Dictionary not properly constructed. Error occured. Key \'ser_type\' not in dictionary' ) buf_in = bytearray(0)
def read_from_serial(): global port global ecss_feeder_sock global ui_listener_sock global ld_socket logger.info('Started serial listener process') buf_in = bytearray(0) while True: try: if port != 0: c = port.read() else: logger.info('Serial port is closed') except serial.SerialException as e: logger.error('Could not read from serial port. Error occured') logger.error(e) return if len(c) != 0: buf_in.append(c) if len(buf_in) == 1 and buf_in[0] != 0x7E: buf_in = bytearray(0) elif len(buf_in) > 1 and buf_in[len(buf_in) - 1] == 0x7E: logger_packet = ''.join('{:02x}'.format(x) for x in buf_in) logger.info('Received packet from serial.') logger.debug('From serial: %s', logger_packet) ecss_dict = {} ret = packet.deconstruct_packet(buf_in, ecss_dict, "serial") ecss_dict = ret[0] pickled = cPickle.dumps(ecss_dict) logger.debug('Sending to UDP: %s', ecss_dict) if len(ecss_dict) == 0: logger.error('Ecss Dictionary not properly constructed. Error occured') continue try: if not ecss_dict and ecss_dict['ser_type'] == packet_settings.TC_LARGE_DATA_SERVICE: ld_socket.sendto(pickled, ('127.0.0.1', client_settings.LD_UPLINK_LISTEN_PORT)) else: ecss_feeder_sock.sendto(pickled, ('127.0.0.1', client_settings.ECSS_FEEDER_UDP_PORT)) except KeyError: logger.error('Ecss Dictionary not properly constructed. Error occured. Key \'ser_type\' not in dictionary') buf_in = bytearray(0)
def read_from_gnuradio(): logger.info('Started gnuradio listener process') while True: conn = backend_listener_sock.recv() buf_in = bytearray(conn[0]) ecss_dict = {} ret = packet.deconstruct_packet(buf_in, ecss_dict, "gnuradio") ecss_dict = ret[0] pickled = cPickle.dumps(ecss_dict) if len(ecss_dict) == 0: logger.error('Ecss Dictionary not properly constructed. Error occured') continue try: if ecss_dict['ser_type'] == packet_settings.TC_LARGE_DATA_SERVICE: if ecss_dict['ser_subtype'] <= 8: # 8 is sthe maximum service subtype corresponding to Large Data downlink ld_downlink_socket.sendto(pickled, ('127.0.0.1', client_settings.LD_DOWNLINK_LISTEN_PORT)) else: ld_uplink_socket.sendto(pickled, ('127.0.0.1', client_settings.LD_UPLINK_LISTEN_PORT)) else: ecss_feeder_sock.sendto(pickled, ('127.0.0.1', client_settings.ECSS_FEEDER_UDP_PORT)) except KeyError: logger.error('Ecss Dictionary not properly constructed. Error occured. Key \'ser_type\' not in dictionary')