Modified the API between mstp and dlmstp to better handler multiple MS/TP ports.

This commit is contained in:
skarg
2007-07-16 14:19:49 +00:00
parent d9e1af4b2e
commit 382766d7c4
5 changed files with 54 additions and 43 deletions
-14
View File
@@ -151,20 +151,6 @@ extern "C" {
void dlmstp_set_baud_rate(uint32_t baud);
uint32_t dlmstp_baud_rate(void);
/* MS/TP state machine functions */
uint16_t dlmstp_put_receive(
uint8_t src, /* source MS/TP address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len);
/* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */
uint16_t dlmstp_get_send(
uint8_t src, /* source MS/TP address for creating packet */
uint8_t * pdu, /* data to send */
uint16_t max_pdu, /* amount of space available */
unsigned timeout); /* milliseconds to wait for a packet */
#ifdef __cplusplus
}
#endif /* __cplusplus */
+7 -12
View File
@@ -719,16 +719,12 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
break;
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
/* indicate successful reception to the higher layers */
dlmstp_put_receive(mstp_port->SourceAddress,
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
MSTP_Put_Receive(mstp_port);
break;
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
/*mstp_port->ReplyPostponedTimer = 0; */
/* indicate successful reception to the higher layers */
dlmstp_put_receive(mstp_port->SourceAddress,
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
MSTP_Put_Receive(mstp_port);
/* broadcast DER just remains IDLE */
if (mstp_port->DestinationAddress !=
MSTP_BROADCAST_ADDRESS) {
@@ -754,7 +750,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* more data frames. These may be BACnet Data frames or */
/* proprietary frames. */
case MSTP_MASTER_STATE_USE_TOKEN:
length = dlmstp_get_send(
length = MSTP_Get_Send(
mstp_port->This_Station,
(uint8_t *)&mstp_port->OutputBuffer[0],
mstp_port->OutputBufferSize,
@@ -836,9 +832,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* ReceivedReply */
/* or a proprietary type that indicates a reply */
/* indicate successful reception to the higher layers */
dlmstp_put_receive(mstp_port->SourceAddress, /* source MS/TP address */
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
MSTP_Put_Receive(mstp_port);
mstp_port->master_state =
MSTP_MASTER_STATE_DONE_WITH_TOKEN;
break;
@@ -1101,10 +1095,11 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* a proprietary frame that expects a reply is received. */
case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST:
#if 0
/* FIXME: we always defer the reply to be safe */
/* FIXME: we always defer the reply to be legal */
/* FIXME: if we knew the APDU type received, we could
see if the next message was that same APDU type
along with the matching src/dest and invoke ID */
/* FIXME: we could use 2 queues: one for DER and one for non-DER */
if ((mstp_port->SilenceTimer <= Treply_delay) &&
mstp_port->TxReady) {
/* Reply */
@@ -1114,7 +1109,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* (the mechanism used to determine this is a local matter), */
/* then call MSTP_Create_And_Send_Frame to transmit the reply frame */
/* and enter the IDLE state to wait for the next frame. */
length = dlmstp_get_send(
length = MSTP_Get_Send(
mstp_port->This_Station,
(uint8_t *)&mstp_port->OutputBuffer[0],
mstp_port->OutputBufferSize,
+13
View File
@@ -215,6 +215,19 @@ extern "C" {
uint8_t * data, /* any data to be sent - may be null */
uint16_t data_len);
/* functions used by the MS/TP state machine to put or get data */
/* FIXME: developer must implement these in their DLMSTP module */
uint16_t MSTP_Put_Receive(
volatile struct mstp_port_struct_t *mstp_port);
/* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */
uint16_t MSTP_Get_Send(
uint8_t src, /* source MS/TP address for creating packet */
uint8_t * pdu, /* data to send */
uint16_t max_pdu, /* amount of space available */
unsigned timeout); /* milliseconds to wait for a packet */
#ifdef __cplusplus
}
#endif /* __cplusplus */
+15 -8
View File
@@ -254,18 +254,25 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
}
/* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len)
{ /* amount of PDU data */
uint16_t MSTP_Put_Receive(
volatile struct mstp_port_struct_t *mstp_port)
{
DLMSTP_PACKET packet;
uint16_t pdu_len = mstp_port->DataLength;
/* bounds check - maybe this should send an abort? */
if (pdu_len > sizeof(packet.pdu))
pdu_len = sizeof(packet.pdu);
if (pdu_len) {
MSTP_Packets++;
memmove(&packet.pdu[0], pdu, pdu_len);
dlmstp_fill_bacnet_address(&packet.address, src);
memmove(&packet.pdu[0],
(void *) & mstp_port->InputBuffer[0],
pdu_len);
dlmstp_fill_bacnet_address(&packet.address,
mstp_port->SourceAddress);
packet.pdu_len = pdu_len;
packet.ready = true; /* not used in this scheme */
/* ready is not used in this scheme */
packet.ready = true;
write(Receive_Server_SockFD, &packet, sizeof(packet));
}
@@ -274,7 +281,7 @@ uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
/* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */
uint16_t dlmstp_get_send(
uint16_t MSTP_Get_Send(
uint8_t src, /* source MS/TP address for creating packet */
uint8_t * pdu, /* data to send */
uint16_t max_pdu, /* amount of space available */
+19 -9
View File
@@ -208,21 +208,31 @@ void dlmstp_fill_bacnet_address(BACNET_ADDRESS * src, uint8_t mstp_address)
}
/* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */
uint8_t * pdu, /* PDU data */
uint16_t pdu_len)
{ /* amount of PDU data */
/* PDU is already in the Receive_Packet */
dlmstp_fill_bacnet_address(&Receive_Packet.address, src);
Receive_Packet.pdu_len = pdu_len;
Receive_Packet.ready = true;
uint16_t MSTP_Put_Receive(
volatile struct mstp_port_struct_t *mstp_port)
{
uint16_t pdu_len = 0;
if (!Receive_Packet.ready) {
/* bounds check - maybe this should send an abort? */
pdu_len = mstp_port->DataLength;
if (pdu_len > sizeof(Receive_Packet.pdu))
pdu_len = sizeof(Receive_Packet.pdu);
memmove((void *) & Receive_Packet.pdu[0],
(void *) & mstp_port->InputBuffer[0],
pdu_len);
dlmstp_fill_bacnet_address(&Receive_Packet.address,
mstp_port->SourceAddress);
Receive_Packet.pdu_len = mstp_port->DataLength;
Receive_Packet.ready = true;
}
return pdu_len;
}
/* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */
uint16_t dlmstp_get_send(
uint16_t MSTP_Get_Send(
uint8_t src, /* source MS/TP address for creating packet */
uint8_t * pdu, /* data to send */
uint16_t max_pdu, /* amount of space available */