This commit is contained in:
skarg
2006-08-29 10:48:04 +00:00
parent 0f851d57f0
commit 3d0abf778a
25 changed files with 487 additions and 525 deletions
+26 -28
View File
@@ -31,13 +31,13 @@
#include "dlmstp.h"
#include "rs485.h"
#include "npdu.h"
/* receive buffer */
static DLMSTP_PACKET Receive_Buffer;
/* receive buffer */
static DLMSTP_PACKET Receive_Buffer;
/* temp buffer for NPDU insertion */
static uint8_t PDU_Buffer[MAX_MPDU];
/* local MS/TP port data */
static volatile struct mstp_port_struct_t MSTP_Port;
/* local MS/TP port data */
static volatile struct mstp_port_struct_t MSTP_Port;
void dlmstp_init(void)
{
@@ -56,49 +56,47 @@ void dlmstp_cleanup(void)
/* returns number of bytes sent on success, zero on failure */
int dlmstp_send_pdu(BACNET_ADDRESS * dest, /* destination address */
BACNET_NPDU_DATA * npdu_data, /* network information */
BACNET_NPDU_DATA * npdu_data, /* network information */
uint8_t * pdu, /* any data to be sent - may be null */
unsigned pdu_len)
{ /* number of bytes of data */
bool status;
int bytes_sent = 0;
int npdu_len = 0;
int npdu_len = 0;
uint8_t frame_type = 0;
uint8_t destination = 0; /* destination address */
uint8_t destination = 0; /* destination address */
BACNET_ADDRESS src;
if (MSTP_Port.TxReady == false) {
if (npdu_data->confirmed_message)
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
else
MSTP_Port.TxFrameType = FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
MSTP_Port.TxFrameType =
FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY;
/* load destination MAC address */
if (dest && dest->mac_len == 1) {
destination = dest->mac[0];
} else {
#if PRINT_ENABLED
#if PRINT_ENABLED
fprintf(stderr, "mstp: invalid destination MAC address!\n");
#endif
#endif
return -2;
}
dlmstp_get_my_address(&src);
npdu_len = npdu_encode_pdu(&PDU_Buffer[0], dest, &src, npdu_data);
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
#if PRINT_ENABLED
if ((8 /* header len */ + npdu_len + pdu_len) > MAX_MPDU) {
#if PRINT_ENABLED
fprintf(stderr, "mstp: PDU is too big to send!\n");
#endif
#endif
return -4;
}
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
bytes_sent = MSTP_Create_Frame(
&MSTP_Port.TxBuffer[0],
}
memmove(&PDU_Buffer[npdu_len], pdu, pdu_len);
bytes_sent = MSTP_Create_Frame(&MSTP_Port.TxBuffer[0],
sizeof(MSTP_Port.TxBuffer),
MSTP_Port.TxFrameType,
destination,
MSTP_Port.This_Station,
&PDU_Buffer[0],
npdu_len + pdu_len);
MSTP_Port.This_Station, &PDU_Buffer[0], npdu_len + pdu_len);
MSTP_Port.TxLength = bytes_sent;
MSTP_Port.TxReady = true;
}
@@ -127,17 +125,17 @@ 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)
{
uint16_t pdu_len = 0;
{
uint16_t pdu_len = 0;
(void) timeout;
/* see if there is a packet available */
if (Receive_Buffer.ready)
{
memmove(src, &Receive_Buffer.address, sizeof(Receive_Buffer.address));
if (Receive_Buffer.ready) {
memmove(src, &Receive_Buffer.address,
sizeof(Receive_Buffer.address));
pdu_len = Receive_Buffer.pdu_len;
memmove(&pdu[0], &Receive_Buffer.pdu[0], max_pdu);
Receive_Buffer.ready = false;
Receive_Buffer.ready = false;
}
return pdu_len;
+4 -3
View File
@@ -95,7 +95,9 @@ void My_Read_Property_Handler(uint8_t * service_request,
data.application_data = &Temp_Buf[0];
data.application_data_len = len;
/* FIXME: probably need a length limitation sent with encode */
pdu_len = rp_ack_encode_apdu(&Handler_Transmit_Buffer[0], service_data->invoke_id, &data);
pdu_len =
rp_ack_encode_apdu(&Handler_Transmit_Buffer[0],
service_data->invoke_id, &data);
} else
error = true;
} else
@@ -112,8 +114,7 @@ void My_Read_Property_Handler(uint8_t * service_request,
SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code);
}
npdu_encode_confirmed_apdu(&npdu_data, MESSAGE_PRIORITY_NORMAL);
bytes_sent = datalink_send_pdu(src, &npdu_data,
&Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); /* number of bytes of data */
return;
}
+1 -1
View File
@@ -215,7 +215,7 @@ void RS485_Process_Tx_Message(void)
*****************************************************************************/
bool RS485_Tx_Complete(void)
{
return RS485_Flags.TransmitComplete;
return RS485_Flags.TransmitComplete;
}
/****************************************************************************