def collect(self, delay=None):
    if delay:
        time.sleep(delay)
    pdu_list = list()
    max_data = None
    with self.lock:
        active_sap_list = [sap for sap in self.sap if (sap is not None)]
        for sap in active_sap_list:
            pdu = sap.dequeue((max_data if max_data else 2179))
            if (pdu is not None):
                if (self.cfg['send-agf'] == False):
                    return pdu
                pdu_list.append(pdu)
                if (max_data is None):
                    max_data = (self.cfg['send-miu'] + 2)
                max_data -= len(pdu)
                if (max_data < (((bool((len(pdu_list) == 1)) * 2) + 2) + 2)):
                    break
        else:
            max_data = (self.cfg['send-miu'] + 2)
        for sap in active_sap_list:
            if (sap.mode == DATA_LINK_CONNECTION):
                pdu = sap.sendack(max_data)
                if (not (pdu is None)):
                    if (self.cfg['send-agf'] == False):
                        return pdu
                    pdu_list.append(pdu)
                    max_data -= len(pdu)
                    if (max_data < (((bool((len(pdu_list) == 1)) * 2) + 2) + 3)):
                        break
    if (len(pdu_list) > 1):
        return AggregatedFrame(aggregate=pdu_list)
    if (len(pdu_list) == 1):
        return pdu_list[0]
    return None
def collect(self, delay=None):
    if delay:
        time.sleep(delay)
    pdu_list = list()
    max_data = None
    with self.lock:
        active_sap_list = [sap for sap in self.sap if (sap is not None)]
        for sap in active_sap_list:
            pdu = sap.dequeue((max_data if max_data else 2179))
            if (pdu is not None):
                if (self.cfg['send-agf'] == False):
                    return pdu
                pdu_list.append(pdu)
                if (max_data is None):
                    max_data = (self.cfg['send-miu'] + 2)
                max_data -= len(pdu)
                if (max_data < (((bool((len(pdu_list) == 1)) * 2) + 2) + 2)):
                    break
        else:
            max_data = (self.cfg['send-miu'] + 2)
        for sap in active_sap_list:
            if (sap.mode == DATA_LINK_CONNECTION):
                pdu = sap.sendack(max_data)
                if (not (pdu is None)):
                    if (self.cfg['send-agf'] == False):
                        return pdu
                    pdu_list.append(pdu)
                    max_data -= len(pdu)
                    if (max_data < (((bool((len(pdu_list) == 1)) * 2) + 2) + 3)):
                        break
    if (len(pdu_list) > 1):
        return AggregatedFrame(aggregate=pdu_list)
    if (len(pdu_list) == 1):
        return pdu_list[0]
    return None