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:
@@ -316,7 +316,7 @@ uint16_t MSTP_Get_Send(
|
||||
if (Ringbuf_Empty(&PDU_Queue)) {
|
||||
return 0;
|
||||
}
|
||||
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 {
|
||||
@@ -326,6 +326,7 @@ uint16_t MSTP_Get_Send(
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
|
||||
mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
|
||||
(void) Ringbuf_Pop(&PDU_Queue, NULL);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
@@ -498,7 +499,7 @@ uint16_t MSTP_Get_Reply(
|
||||
if (Ringbuf_Empty(&PDU_Queue)) {
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&PDU_Queue);
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&PDU_Queue);
|
||||
/* is this the reply to the DER? */
|
||||
matched =
|
||||
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
|
||||
@@ -507,7 +508,6 @@ uint16_t MSTP_Get_Reply(
|
||||
if (!matched) {
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
@@ -517,6 +517,7 @@ uint16_t MSTP_Get_Reply(
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
|
||||
mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
|
||||
(void) Ringbuf_Pop(&PDU_Queue, NULL);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ uint16_t MSTP_Get_Send(
|
||||
if (Ringbuf_Empty(&poSharedData->PDU_Queue)) {
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&poSharedData->PDU_Queue);
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue);
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
@@ -397,6 +397,7 @@ uint16_t MSTP_Get_Send(
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
|
||||
mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
|
||||
(void) Ringbuf_Pop(&poSharedData->PDU_Queue, NULL);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
@@ -574,7 +575,7 @@ uint16_t MSTP_Get_Reply(
|
||||
if (Ringbuf_Empty(&poSharedData->PDU_Queue)) {
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&poSharedData->PDU_Queue);
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Peek(&poSharedData->PDU_Queue);
|
||||
/* is this the reply to the DER? */
|
||||
matched =
|
||||
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
|
||||
@@ -583,7 +584,6 @@ uint16_t MSTP_Get_Reply(
|
||||
if (!matched) {
|
||||
return 0;
|
||||
}
|
||||
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&poSharedData->PDU_Queue);
|
||||
if (pkt->data_expecting_reply) {
|
||||
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
|
||||
} else {
|
||||
@@ -593,6 +593,7 @@ uint16_t MSTP_Get_Reply(
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0], /* <-- loading this */
|
||||
mstp_port->OutputBufferSize, frame_type, pkt->destination_mac,
|
||||
mstp_port->This_Station, (uint8_t *) & pkt->buffer[0], pkt->length);
|
||||
(void) Ringbuf_Pop(&poSharedData->PDU_Queue, NULL);
|
||||
|
||||
return pdu_len;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user