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:
+26
-2
@@ -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(
|
||||
|
||||
@@ -210,11 +210,13 @@ static void *dlmstp_receive_fsm_task(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)) {
|
||||
do {
|
||||
RS485_Check_UART_Data(mstp_port);
|
||||
MSTP_Receive_Frame_FSM((struct mstp_port_struct_t *)pArg);
|
||||
received_frame = mstp_port->ReceivedValidFrame ||
|
||||
mstp_port->ReceivedValidFrameNotForUs ||
|
||||
mstp_port->ReceivedInvalidFrame;
|
||||
if (received_frame) {
|
||||
pthread_cond_signal(&poSharedData->Received_Frame_Flag);
|
||||
@@ -245,11 +247,13 @@ static void *dlmstp_master_fsm_task(void *pArg)
|
||||
|
||||
for (;;) {
|
||||
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);
|
||||
}
|
||||
if (mstp_port->ReceivedValidFrame || mstp_port->ReceivedInvalidFrame) {
|
||||
if (mstp_port->ReceivedValidFrame || mstp_port->ReceivedInvalidFrame ||
|
||||
mstp_port->ReceivedValidFrameNotForUs) {
|
||||
run_master = true;
|
||||
} else {
|
||||
silence = mstp_port->SilenceTimer(NULL);
|
||||
|
||||
@@ -283,6 +283,11 @@ int main(int argc, char *argv[])
|
||||
mstp_port->ReceivedValidFrame = false;
|
||||
snap_received_packet(mstp_port, sockfd);
|
||||
packet_count++;
|
||||
} else if (mstp_port->ReceivedValidFrameNotForUs) {
|
||||
mstp_port->ReceivedValidFrameNotForUs = false;
|
||||
fprintf(stderr, "ReceivedValidFrameNotForUs\n");
|
||||
snap_received_packet(mstp_port, sockfd);
|
||||
packet_count++;
|
||||
} else if (mstp_port->ReceivedInvalidFrame) {
|
||||
mstp_port->ReceivedInvalidFrame = false;
|
||||
fprintf(stderr, "ReceivedInvalidFrame\n");
|
||||
|
||||
+3
-3
@@ -248,16 +248,16 @@ void RS485_Check_UART_Data(struct mstp_port_struct_t *mstp_port)
|
||||
uint8_t buf[2048];
|
||||
ssize_t n;
|
||||
int handle = RS485_Handle;
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
FIFO_BUFFER *fifo = &Rx_FIFO;
|
||||
|
||||
waiter.tv_sec = 0;
|
||||
waiter.tv_usec = 5000;
|
||||
|
||||
SHARED_MSTP_DATA *poSharedData = (SHARED_MSTP_DATA *)mstp_port->UserData;
|
||||
poSharedData = (SHARED_MSTP_DATA *)mstp_port->UserData;
|
||||
if (poSharedData) {
|
||||
handle = poSharedData->RS485_Handle;
|
||||
fifo = &poSharedData->Rx_FIFO;
|
||||
}
|
||||
|
||||
if (mstp_port->ReceiveError == true) {
|
||||
/* do nothing but wait for state machine to clear the error */
|
||||
} else if (mstp_port->DataAvailable == false) {
|
||||
|
||||
Reference in New Issue
Block a user