AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/bdk-atxx4-mstp/dlmstp.c
uint16_t dlmstp_receive(
    BACNET_ADDRESS * src,       /* source address */
    uint8_t * pdu,      /* PDU data */
    uint16_t max_pdu,   /* amount of space available in the PDU  */
    unsigned timeout)
{       /* milliseconds to wait for a packet */
    uint16_t pdu_len = 0;       /* return value */

    /* set the input buffer to the same data storage for zero copy */
    if (!InputBuffer) {
        InputBuffer = pdu;
        InputBufferSize = max_pdu;
    }
    while ((MSTP_Flag.ReceivedValidFrame == false) &&
        (MSTP_Flag.ReceivedValidFrameNotForUs == false) &&
        (MSTP_Flag.ReceivedInvalidFrame == false)) {
        /* only do receive state machine while we don't have a frame */
        MSTP_Receive_Frame_FSM();
        /* process another byte, if available */
        if (!rs485_byte_available(NULL)) {
            break;
        }
    }
    if (MSTP_Flag.ReceivedValidFrameNotForUs) {
        MSTP_Flag.ReceivedValidFrameNotForUs = false;
    }
    if (Receive_State == MSTP_RECEIVE_STATE_IDLE) {
        /* only do master or slave state machine while rx is idle */
        if (This_Station <= DEFAULT_MAX_MASTER) {
            while (MSTP_Master_Node_FSM()) {
                /* do nothing while some states fast transition */
            };
        }
#if SLEEP_ENABLED
        sleep_mode();
#endif
    }
    /* if there is a packet that needs processed, do it now. */
    if (MSTP_Flag.ReceivePacketPending) {
        MSTP_Flag.ReceivePacketPending = false;
        pdu_len = DataLength;
        src->mac_len = 1;
        src->mac[0] = SourceAddress;
        /* data is already in the pdu pointer */
    }

    return pdu_len;
}
/* Return the length of the packet */
Return the length of the packet
Return the length of the packet
uint16_t dlmstp_receive(
    BACNET_ADDRESS * src,       
    uint8_t * pdu,      
    uint16_t max_pdu,   
    unsigned timeout)
{       
    uint16_t pdu_len = 0;       
    if (!InputBuffer) {
        InputBuffer = pdu;
        InputBufferSize = max_pdu;
    }
    while ((MSTP_Flag.ReceivedValidFrame == false) &&
        (MSTP_Flag.ReceivedValidFrameNotForUs == false) &&
        (MSTP_Flag.ReceivedInvalidFrame == false)) {
        MSTP_Receive_Frame_FSM();
        if (!rs485_byte_available(NULL)) {
            break;
        }
    }
    if (MSTP_Flag.ReceivedValidFrameNotForUs) {
        MSTP_Flag.ReceivedValidFrameNotForUs = false;
    }
    if (Receive_State == MSTP_RECEIVE_STATE_IDLE) {
        if (This_Station <= DEFAULT_MAX_MASTER) {
            while (MSTP_Master_Node_FSM()) {
            };
        }
#if SLEEP_ENABLED
        sleep_mode();
#endif
    }
    if (MSTP_Flag.ReceivePacketPending) {
        MSTP_Flag.ReceivePacketPending = false;
        pdu_len = DataLength;
        src->mac_len = 1;
        src->mac[0] = SourceAddress;
    }
    return pdu_len;
}
uint16_t dlmstp_receive ( BACNET_ADDRESS * src , uint8_t * pdu , uint16_t max_pdu , unsigned timeout ) { uint16_t pdu_len = 0 ; if ( ! InputBuffer ) { InputBuffer = pdu ; InputBufferSize = max_pdu ; } while ( ( MSTP_Flag . ReceivedValidFrame == false ) && ( MSTP_Flag . ReceivedValidFrameNotForUs == false ) && ( MSTP_Flag . ReceivedInvalidFrame == false ) ) { MSTP_Receive_Frame_FSM ( ) ; if ( ! rs485_byte_available ( NULL ) ) { break ; } } if ( MSTP_Flag . ReceivedValidFrameNotForUs ) { MSTP_Flag . ReceivedValidFrameNotForUs = false ; } if ( Receive_State == MSTP_RECEIVE_STATE_IDLE ) { if ( This_Station <= DEFAULT_MAX_MASTER ) { while ( MSTP_Master_Node_FSM ( ) ) { } ; } #if SLEEP_ENABLED sleep_mode ( ) ; #endif } if ( MSTP_Flag . ReceivePacketPending ) { MSTP_Flag . ReceivePacketPending = false ; pdu_len = DataLength ; src -> mac_len = 1 ; src -> mac [ 0 ] = SourceAddress ; } return pdu_len ; }
Return the length of the packet
Return the length of the packet
/* source address */ /* PDU data */ /* amount of space available in the PDU  */ /* milliseconds to wait for a packet */ /* return value */ /* set the input buffer to the same data storage for zero copy */ /* only do receive state machine while we don't have a frame */ /* process another byte, if available */ /* only do master or slave state machine while rx is idle */ /* do nothing while some states fast transition */ /* if there is a packet that needs processed, do it now. */ /* data is already in the pdu pointer */