Changed Ringbuf API: Ringbuf_Pop_Front is now Ringbuf_Pop, and now it copies the buffer into parameter and returns boolean. Original method was not safe since it returned a pointer to the element but freed the buffer element. Changed Ringbuf_Get_Front to Ringbuf_Peek with no change in functionality, to make names more consistent.

Updated all the MS/TP datalink layer implementations that use Ringbuf library.
This commit is contained in:
skarg
2013-01-08 20:48:34 +00:00
parent 3bc404dbe9
commit cf882642a8
8 changed files with 107 additions and 65 deletions
+5 -5
View File
@@ -379,7 +379,7 @@ static bool MSTP_Transmit_FSM(
if (!Ringbuf_Empty(&Transmit_Queue)) {
/* get the packet - but don't remove it from queue */
pkt = (struct mstp_tx_packet *)
Ringbuf_Get_Front(&Transmit_Queue);
Ringbuf_Peek(&Transmit_Queue);
state = MSTP_TX_STATE_SILENCE_WAIT;
}
break;
@@ -410,7 +410,7 @@ static bool MSTP_Transmit_FSM(
if (rs485_byte_sent() && rs485_frame_sent()) {
rs485_rts_enable(false);
/* remove the packet from the queue */
(void) Ringbuf_Pop_Front(&Transmit_Queue);
(void) Ringbuf_Pop(&Transmit_Queue, NULL);
state = MSTP_TX_STATE_IDLE;
}
break;
@@ -873,7 +873,7 @@ static bool MSTP_Master_Node_FSM(
transition_now = true;
} else {
uint8_t frame_type;
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&PDU_Queue);
if (pkt->data_expecting_reply) {
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
} else {
@@ -900,6 +900,7 @@ static bool MSTP_Master_Node_FSM(
Master_State = MSTP_MASTER_STATE_DONE_WITH_TOKEN;
break;
}
(void) Ringbuf_Pop(&PDU_Queue, NULL);
}
break;
case MSTP_MASTER_STATE_WAIT_FOR_REPLY:
@@ -1206,7 +1207,7 @@ static bool MSTP_Master_Node_FSM(
/* BACnet Data Expecting Reply, a Test_Request, or */
/* a proprietary frame that expects a reply is received. */
case MSTP_MASTER_STATE_ANSWER_DATA_REQUEST:
pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&PDU_Queue);
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&PDU_Queue);
if (pkt != NULL) {
matched =
dlmstp_compare_data_expecting_reply(&InputBuffer[0],
@@ -1224,7 +1225,6 @@ static bool MSTP_Master_Node_FSM(
/* then call MSTP_Send_Frame to transmit the reply frame */
/* and enter the IDLE state to wait for the next frame. */
uint8_t frame_type;
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
if (pkt->data_expecting_reply) {
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
} else {