Feature/mstp valid frame not for us stats (#1053)

* Fixed ISO C90 forbids mixed declarations and code warning.

* Fixed the MS/TP invalid frame counter that was incremented for valid frames not for us.
This commit is contained in:
Steve Karg
2025-08-01 09:58:45 -05:00
committed by GitHub
parent 1bebd6ac81
commit 4095a7f335
15 changed files with 198 additions and 25 deletions
+26 -2
View File
@@ -71,6 +71,7 @@ static struct mstimer Valid_Frame_Timer;
/* callbacks for monitoring */
static dlmstp_hook_frame_rx_start_cb Preamble_Callback;
static dlmstp_hook_frame_rx_complete_cb Valid_Frame_Rx_Callback;
static dlmstp_hook_frame_rx_complete_cb Valid_Frame_Not_For_Us_Rx_Callback;
static dlmstp_hook_frame_rx_complete_cb Invalid_Frame_Rx_Callback;
static DLMSTP_STATISTICS DLMSTP_Statistics;
@@ -429,9 +430,10 @@ void MSTP_Send_Frame(
uint16_t MSTP_Put_Receive(struct mstp_port_struct_t *mstp_port)
{
uint16_t pdu_len = 0;
DLMSTP_PACKET *pkt;
pthread_mutex_lock(&Receive_Packet_Mutex);
DLMSTP_PACKET *pkt = (DLMSTP_PACKET *)Ringbuf_Data_Peek(&Receive_Queue);
pkt = (DLMSTP_PACKET *)Ringbuf_Data_Peek(&Receive_Queue);
if (!pkt) {
debug_printf("MS/TP: Dropped! Not Ready.\n");
} else {
@@ -519,6 +521,7 @@ static void *dlmstp_thread(void *pArg)
while (thread_alive) {
/* only do receive state machine while we don't have a frame */
if ((MSTP_Port.ReceivedValidFrame == false) &&
(MSTP_Port.ReceivedValidFrameNotForUs == false) &&
(MSTP_Port.ReceivedInvalidFrame == false)) {
RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
@@ -537,6 +540,17 @@ static void *dlmstp_thread(void *pArg)
MSTP_Port.DataLength);
}
run_master = true;
} else if (MSTP_Port.ReceivedValidFrameNotForUs) {
DLMSTP_Statistics.receive_valid_frame_not_for_us_counter++;
if (Valid_Frame_Not_For_Us_Rx_Callback) {
Valid_Frame_Not_For_Us_Rx_Callback(
MSTP_Port.SourceAddress, MSTP_Port.DestinationAddress,
MSTP_Port.FrameType, MSTP_Port.InputBuffer,
MSTP_Port.DataLength);
}
run_master = true;
/* we don't run the master state machine for this frame */
MSTP_Port.ReceivedValidFrameNotForUs = false;
} else if (MSTP_Port.ReceivedInvalidFrame) {
if (Invalid_Frame_Rx_Callback) {
DLMSTP_Statistics.receive_invalid_frame_counter++;
@@ -893,6 +907,16 @@ void dlmstp_set_frame_rx_complete_callback(
Valid_Frame_Rx_Callback = cb_func;
}
/**
* @brief Set the MS/TP Frame Complete callback
* @param cb_func - callback function to be called when a frame is received
*/
void dlmstp_set_frame_not_for_us_rx_complete_callback(
dlmstp_hook_frame_rx_complete_cb cb_func)
{
Valid_Frame_Not_For_Us_Rx_Callback = cb_func;
}
/**
* @brief Set the MS/TP Frame Complete callback
* @param cb_func - callback function to be called when a frame is received
@@ -1091,7 +1115,7 @@ bool dlmstp_init(char *ifname)
#endif
pthread_attr_init(&thread_attr);
// Set scheduling policy to SCHED_FIFO and priority
/* Set scheduling policy to SCHED_FIFO and priority */
rv = pthread_attr_setinheritsched(&thread_attr, PTHREAD_EXPLICIT_SCHED);
if (rv != 0) {
fprintf(