AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/linux/dlmstp_linux.c
int dlmstp_send_pdu(
    void *poPort,
    BACNET_ADDRESS * dest,      /* destination address */
    uint8_t * pdu,      /* any data to be sent - may be null */
    unsigned pdu_len)
{       /* number of bytes of data */
    int bytes_sent = 0;
    struct mstp_pdu_packet *pkt;
    unsigned i = 0;
    SHARED_MSTP_DATA *poSharedData;
    struct mstp_port_struct_t *mstp_port =
        (struct mstp_port_struct_t *) poPort;
    if (!mstp_port) {
        return 0;
    }
    poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
    if (!poSharedData) {
        return 0;
    }

    pkt = (struct mstp_pdu_packet *) Ringbuf_Data_Peek(&poSharedData->PDU_Queue);
    if (pkt) {
        pkt->data_expecting_reply =
            BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]);
        for (i = 0; i < pdu_len; i++) {
            pkt->buffer[i] = pdu[i];
        }
        pkt->length = pdu_len;
        pkt->destination_mac = dest->mac[0];
        if (Ringbuf_Data_Put(&PDU_Queue, (uint8_t *)pkt)) {
            bytes_sent = pdu_len;
        }
    }

    return bytes_sent;
}
/* returns number of bytes sent on success, zero on failure */
returns number of bytes sent on success, zero on failure
returns number of bytes sent on success zero on failure
int dlmstp_send_pdu(
    void *poPort,
    BACNET_ADDRESS * dest,      
    uint8_t * pdu,      
    unsigned pdu_len)
{       
    int bytes_sent = 0;
    struct mstp_pdu_packet *pkt;
    unsigned i = 0;
    SHARED_MSTP_DATA *poSharedData;
    struct mstp_port_struct_t *mstp_port =
        (struct mstp_port_struct_t *) poPort;
    if (!mstp_port) {
        return 0;
    }
    poSharedData = (SHARED_MSTP_DATA *) mstp_port->UserData;
    if (!poSharedData) {
        return 0;
    }
    pkt = (struct mstp_pdu_packet *) Ringbuf_Data_Peek(&poSharedData->PDU_Queue);
    if (pkt) {
        pkt->data_expecting_reply =
            BACNET_DATA_EXPECTING_REPLY(pdu[BACNET_PDU_CONTROL_BYTE_OFFSET]);
        for (i = 0; i < pdu_len; i++) {
            pkt->buffer[i] = pdu[i];
        }
        pkt->length = pdu_len;
        pkt->destination_mac = dest->mac[0];
        if (Ringbuf_Data_Put(&PDU_Queue, (uint8_t *)pkt)) {
            bytes_sent = pdu_len;
        }
    }
    return bytes_sent;
}
int dlmstp_send_pdu ( void * poPort , BACNET_ADDRESS * dest , uint8_t * pdu , unsigned pdu_len ) { int bytes_sent = 0 ; struct mstp_pdu_packet * pkt ; unsigned i = 0 ; SHARED_MSTP_DATA * poSharedData ; struct mstp_port_struct_t * mstp_port = ( struct mstp_port_struct_t * ) poPort ; if ( ! mstp_port ) { return 0 ; } poSharedData = ( SHARED_MSTP_DATA * ) mstp_port -> UserData ; if ( ! poSharedData ) { return 0 ; } pkt = ( struct mstp_pdu_packet * ) Ringbuf_Data_Peek ( & poSharedData -> PDU_Queue ) ; if ( pkt ) { pkt -> data_expecting_reply = BACNET_DATA_EXPECTING_REPLY ( pdu [ BACNET_PDU_CONTROL_BYTE_OFFSET ] ) ; for ( i = 0 ; i < pdu_len ; i ++ ) { pkt -> buffer [ i ] = pdu [ i ] ; } pkt -> length = pdu_len ; pkt -> destination_mac = dest -> mac [ 0 ] ; if ( Ringbuf_Data_Put ( & PDU_Queue , ( uint8_t * ) pkt ) ) { bytes_sent = pdu_len ; } } return bytes_sent ; }
returns number of bytes sent on success, zero on failure
returns number of bytes sent on success zero on failure
/* destination address */ /* any data to be sent - may be null */ /* number of bytes of data */