AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/linux/dlmstp_linux.c
uint16_t MSTP_Get_Reply(
    volatile struct mstp_port_struct_t * mstp_port,
    unsigned timeout)
{       /* milliseconds to wait for a packet */
    uint16_t pdu_len = 0;       /* return value */
    bool matched = false;
    uint8_t frame_type = 0;
    struct mstp_pdu_packet *pkt;
    SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;

    if (!poSharedData) {
        return 0;
    }

    if (Ringbuf_Empty(&poSharedData->PDU_Queue)) {
        return 0;
    }
    pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue);
    /* is this the reply to the DER? */
    matched =
        dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
        mstp_port->DataLength, mstp_port->SourceAddress,
        (uint8_t *) & pkt->buffer[0], pkt->length, pkt->destination_mac);
    if (!matched) {
        return 0;
    }
    if (pkt->data_expecting_reply) {
        frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
    } else {
        frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
    }
    /* convert the PDU into the MSTP Frame */
    pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0],    /* <-- loading this */
        mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
        mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
    (void) Ringbuf_Pop(&poSharedData->PDU_Queue, NULL);

    return pdu_len;
}
/* Get the reply to a DATA_EXPECTING_REPLY frame, or nothing */
Get the reply to a DATA_EXPECTING_REPLY frame, or nothing
Get the reply to a DATA_EXPECTING_REPLY frame or nothing
uint16_t MSTP_Get_Reply(
    volatile struct mstp_port_struct_t * mstp_port,
    unsigned timeout)
{       
    uint16_t pdu_len = 0;       
    bool matched = false;
    uint8_t frame_type = 0;
    struct mstp_pdu_packet *pkt;
    SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
    if (!poSharedData) {
        return 0;
    }
    if (Ringbuf_Empty(&poSharedData->PDU_Queue)) {
        return 0;
    }
    pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue);
    matched =
        dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
        mstp_port->DataLength, mstp_port->SourceAddress,
        (uint8_t *) & pkt->buffer[0], pkt->length, pkt->destination_mac);
    if (!matched) {
        return 0;
    }
    if (pkt->data_expecting_reply) {
        frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
    } else {
        frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
    }
    pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0],    
        mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
        mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
    (void) Ringbuf_Pop(&poSharedData->PDU_Queue, NULL);
    return pdu_len;
}
uint16_t MSTP_Get_Reply ( volatile struct mstp_port_struct_t * mstp_port , unsigned timeout ) { uint16_t pdu_len = 0 ; bool matched = false ; uint8_t frame_type = 0 ; struct mstp_pdu_packet * pkt ; SHARED_MSTP_DATA * poSharedData = ( SHARED_MSTP_DATA * ) mstp_port -> UserData ; if ( ! poSharedData ) { return 0 ; } if ( Ringbuf_Empty ( & poSharedData -> PDU_Queue ) ) { return 0 ; } pkt = ( struct mstp_pdu_packet * ) Ringbuf_Peek ( & poSharedData -> PDU_Queue ) ; matched = dlmstp_compare_data_expecting_reply ( & mstp_port -> InputBuffer [ 0 ] , mstp_port -> DataLength , mstp_port -> SourceAddress , ( uint8_t * ) & pkt -> buffer [ 0 ] , pkt -> length , pkt -> destination_mac ) ; if ( ! matched ) { return 0 ; } if ( pkt -> data_expecting_reply ) { frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY ; } else { frame_type = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY ; } pdu_len = MSTP_Create_Frame ( & mstp_port -> OutputBuffer [ 0 ] , mstp_port -> OutputBufferSize , frame_type , pkt -> destination_mac , mstp_port -> This_Station , ( uint8_t * ) & pkt -> buffer [ 0 ] , pkt -> length ) ; ( void ) Ringbuf_Pop ( & poSharedData -> PDU_Queue , NULL ) ; return pdu_len ; }
Get the reply to a DATA_EXPECTING_REPLY frame, or nothing
Get the reply to a DATA_EXPECTING_REPLY frame or nothing
/* milliseconds to wait for a packet */ /* return value */ /* is this the reply to the DER? */ /* convert the PDU into the MSTP Frame */ /* <-- loading this */