From 382766d7c45f06a7910d0287ffbd865ebe752ca0 Mon Sep 17 00:00:00 2001 From: skarg Date: Mon, 16 Jul 2007 14:19:49 +0000 Subject: [PATCH] Modified the API between mstp and dlmstp to better handler multiple MS/TP ports. --- bacnet-stack/dlmstp.h | 14 -------------- bacnet-stack/mstp.c | 19 +++++++------------ bacnet-stack/mstp.h | 13 +++++++++++++ bacnet-stack/ports/linux/dlmstp.c | 23 +++++++++++++++-------- bacnet-stack/ports/win32/dlmstp.c | 28 +++++++++++++++++++--------- 5 files changed, 54 insertions(+), 43 deletions(-) diff --git a/bacnet-stack/dlmstp.h b/bacnet-stack/dlmstp.h index 3c9ee66a..2021901e 100644 --- a/bacnet-stack/dlmstp.h +++ b/bacnet-stack/dlmstp.h @@ -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 */ diff --git a/bacnet-stack/mstp.c b/bacnet-stack/mstp.c index a0310fb9..374f5f3d 100644 --- a/bacnet-stack/mstp.c +++ b/bacnet-stack/mstp.c @@ -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, diff --git a/bacnet-stack/mstp.h b/bacnet-stack/mstp.h index 235ba88e..078bcaa6 100644 --- a/bacnet-stack/mstp.h +++ b/bacnet-stack/mstp.h @@ -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 */ diff --git a/bacnet-stack/ports/linux/dlmstp.c b/bacnet-stack/ports/linux/dlmstp.c index 6e9420ae..6e8a0e2d 100644 --- a/bacnet-stack/ports/linux/dlmstp.c +++ b/bacnet-stack/ports/linux/dlmstp.c @@ -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 */ diff --git a/bacnet-stack/ports/win32/dlmstp.c b/bacnet-stack/ports/win32/dlmstp.c index cf60c8a5..205c788e 100644 --- a/bacnet-stack/ports/win32/dlmstp.c +++ b/bacnet-stack/ports/win32/dlmstp.c @@ -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 */