Example #1
0
def read_incoming_pdu(pdu):
    """Converts PDU binary to the correct type of PDU object

    Arguments:
        pdu:
            An encoded binary string representing a CFDP PDU
    """
    # Transform into bytearray because that is how we wrote it out
    # Will make it an array of integer bytes
    pdu_bytes = [b for b in bytearray(pdu)]
    return make_pdu_from_bytes(pdu_bytes)
Example #2
0
def read_pdus_from_socket(instance):
    """ Read PDUs from a socket over UDP """
    while True:
        gevent.sleep(0)
        try:
            all_bytes, addr = instance._rcvr_socket.recvfrom(4096)
            if all_bytes:
                # create PDUs from bytes received
                all_bytes = [b for b in bytearray(all_bytes)]
                for pdu_bytes in split_multiple_pdu_byte_array(all_bytes):
                    pdu = make_pdu_from_bytes(pdu_bytes)
                    pdu_filename = 'entity{0}_tx{1}_{2}.pdu'.format(
                        pdu.header.destination_entity_id,
                        pdu.header.transaction_id, instance.pdu_counter)
                    # cache file so that we know we read it
                    instance.received_pdu_files.append(pdu_filename)
                    # add to incoming so that receiving handler can deal with it
                    instance.incoming_pdu_queue.put(pdu_bytes)
            else:
                break
        except Exception as e:
            ait.core.log.warn("EXCEPTION: " + str(e))
            ait.core.log.warn(traceback.format_exc())