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
+2
View File
@@ -165,11 +165,13 @@ static void dlmstp_receive_fsm_task(void *pArg)
while (TRUE) {
/* 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)) {
do {
RS485_Check_UART_Data(&MSTP_Port);
MSTP_Receive_Frame_FSM(&MSTP_Port);
received_frame = MSTP_Port.ReceivedValidFrame ||
MSTP_Port.ReceivedValidFrameNotForUs ||
MSTP_Port.ReceivedInvalidFrame;
if (received_frame) {
ReleaseSemaphore(Received_Frame_Flag, 1, NULL);
+21
View File
@@ -60,6 +60,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;
@@ -430,6 +431,7 @@ static void dlmstp_thread(void *pArg)
for (;;) {
/* 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)) {
/* note: RS485 waits up to 1ms for data to arrive */
RS485_Check_UART_Data(&MSTP_Port);
@@ -449,6 +451,15 @@ 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;
} else if (MSTP_Port.ReceivedInvalidFrame) {
if (Invalid_Frame_Rx_Callback) {
DLMSTP_Statistics.receive_invalid_frame_counter++;
@@ -793,6 +804,16 @@ void dlmstp_set_frame_rx_complete_callback(
Valid_Frame_Rx_Callback = cb_func;
}
/**
* @brief Set the MS/TP Frame Not For Us 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