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); void dlmstp_set_baud_rate(uint32_t baud);
uint32_t dlmstp_baud_rate(void); 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 #ifdef __cplusplus
} }
#endif /* __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; break;
case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY: case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY:
/* indicate successful reception to the higher layers */ /* indicate successful reception to the higher layers */
dlmstp_put_receive(mstp_port->SourceAddress, MSTP_Put_Receive(mstp_port);
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
break; break;
case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY: case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY:
/*mstp_port->ReplyPostponedTimer = 0; */ /*mstp_port->ReplyPostponedTimer = 0; */
/* indicate successful reception to the higher layers */ /* indicate successful reception to the higher layers */
dlmstp_put_receive(mstp_port->SourceAddress, MSTP_Put_Receive(mstp_port);
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
/* broadcast DER just remains IDLE */ /* broadcast DER just remains IDLE */
if (mstp_port->DestinationAddress != if (mstp_port->DestinationAddress !=
MSTP_BROADCAST_ADDRESS) { 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 */ /* more data frames. These may be BACnet Data frames or */
/* proprietary frames. */ /* proprietary frames. */
case MSTP_MASTER_STATE_USE_TOKEN: case MSTP_MASTER_STATE_USE_TOKEN:
length = dlmstp_get_send( length = MSTP_Get_Send(
mstp_port->This_Station, mstp_port->This_Station,
(uint8_t *)&mstp_port->OutputBuffer[0], (uint8_t *)&mstp_port->OutputBuffer[0],
mstp_port->OutputBufferSize, mstp_port->OutputBufferSize,
@@ -836,9 +832,7 @@ bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t * mstp_port)
/* ReceivedReply */ /* ReceivedReply */
/* or a proprietary type that indicates a reply */ /* or a proprietary type that indicates a reply */
/* indicate successful reception to the higher layers */ /* indicate successful reception to the higher layers */
dlmstp_put_receive(mstp_port->SourceAddress, /* source MS/TP address */ MSTP_Put_Receive(mstp_port);
(uint8_t *) & mstp_port->InputBuffer[0],
mstp_port->DataLength);
mstp_port->master_state = mstp_port->master_state =
MSTP_MASTER_STATE_DONE_WITH_TOKEN; MSTP_MASTER_STATE_DONE_WITH_TOKEN;
break; 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. */ /* a proprietary frame that expects a reply is received. */
case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST: case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST:
#if 0 #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 /* FIXME: if we knew the APDU type received, we could
see if the next message was that same APDU type see if the next message was that same APDU type
along with the matching src/dest and invoke ID */ 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) && if ((mstp_port->SilenceTimer <= Treply_delay) &&
mstp_port->TxReady) { mstp_port->TxReady) {
/* Reply */ /* 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), */ /* (the mechanism used to determine this is a local matter), */
/* then call MSTP_Create_And_Send_Frame to transmit the reply frame */ /* then call MSTP_Create_And_Send_Frame to transmit the reply frame */
/* and enter the IDLE state to wait for the next frame. */ /* and enter the IDLE state to wait for the next frame. */
length = dlmstp_get_send( length = MSTP_Get_Send(
mstp_port->This_Station, mstp_port->This_Station,
(uint8_t *)&mstp_port->OutputBuffer[0], (uint8_t *)&mstp_port->OutputBuffer[0],
mstp_port->OutputBufferSize, mstp_port->OutputBufferSize,
+13
View File
@@ -215,6 +215,19 @@ extern "C" {
uint8_t * data, /* any data to be sent - may be null */ uint8_t * data, /* any data to be sent - may be null */
uint16_t data_len); 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 #ifdef __cplusplus
} }
#endif /* __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 */ /* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */ uint16_t MSTP_Put_Receive(
uint8_t * pdu, /* PDU data */ volatile struct mstp_port_struct_t *mstp_port)
uint16_t pdu_len) {
{ /* amount of PDU data */
DLMSTP_PACKET packet; 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) { if (pdu_len) {
MSTP_Packets++; MSTP_Packets++;
memmove(&packet.pdu[0], pdu, pdu_len); memmove(&packet.pdu[0],
dlmstp_fill_bacnet_address(&packet.address, src); (void *) & mstp_port->InputBuffer[0],
pdu_len);
dlmstp_fill_bacnet_address(&packet.address,
mstp_port->SourceAddress);
packet.pdu_len = pdu_len; 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)); 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 */ /* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */ /* 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 src, /* source MS/TP address for creating packet */
uint8_t * pdu, /* data to send */ uint8_t * pdu, /* data to send */
uint16_t max_pdu, /* amount of space available */ 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 */ /* for the MS/TP state machine to use for putting received data */
uint16_t dlmstp_put_receive(uint8_t src, /* source MS/TP address */ uint16_t MSTP_Put_Receive(
uint8_t * pdu, /* PDU data */ volatile struct mstp_port_struct_t *mstp_port)
uint16_t pdu_len) {
{ /* amount of PDU data */ uint16_t pdu_len = 0;
/* PDU is already in the Receive_Packet */
dlmstp_fill_bacnet_address(&Receive_Packet.address, src); if (!Receive_Packet.ready) {
Receive_Packet.pdu_len = pdu_len; /* bounds check - maybe this should send an abort? */
Receive_Packet.ready = true; 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; return pdu_len;
} }
/* for the MS/TP state machine to use for getting data to send */ /* for the MS/TP state machine to use for getting data to send */
/* Return: amount of PDU data */ /* 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 src, /* source MS/TP address for creating packet */
uint8_t * pdu, /* data to send */ uint8_t * pdu, /* data to send */
uint16_t max_pdu, /* amount of space available */ uint16_t max_pdu, /* amount of space available */