Improve MSTP debug. Fix WhoIs app APDU timeout.

This commit is contained in:
Steve Karg
2023-06-19 09:35:28 -05:00
parent c8a6ea74b8
commit 9bb367982b
4 changed files with 16 additions and 7 deletions
+3 -1
View File
@@ -365,7 +365,6 @@ int main(int argc, char *argv[])
if (getenv("BACNET_DEBUG")) { if (getenv("BACNET_DEBUG")) {
BACnet_Debug_Enabled = true; BACnet_Debug_Enabled = true;
} }
timeout_milliseconds = apdu_timeout();
/* decode any command line parameters */ /* decode any command line parameters */
filename = filename_remove_path(argv[0]); filename = filename_remove_path(argv[0]);
for (argi = 1; argi < argc; argi++) { for (argi = 1; argi < argc; argi++) {
@@ -481,6 +480,9 @@ int main(int argc, char *argv[])
address_init(); address_init();
dlenv_init(); dlenv_init();
atexit(datalink_cleanup); atexit(datalink_cleanup);
if (timeout_milliseconds == 0) {
timeout_milliseconds = apdu_timeout() * apdu_retries();
}
mstimer_set(&apdu_timer, timeout_milliseconds); mstimer_set(&apdu_timer, timeout_milliseconds);
mstimer_set(&datalink_timer, 1000); mstimer_set(&datalink_timer, 1000);
/* send the request */ /* send the request */
+1
View File
@@ -773,6 +773,7 @@ bool dlmstp_init(char *ifname)
fprintf(stderr, "MS/TP MAC: %02X\n", MSTP_Port.This_Station); fprintf(stderr, "MS/TP MAC: %02X\n", MSTP_Port.This_Station);
fprintf(stderr, "MS/TP Max_Master: %02X\n", MSTP_Port.Nmax_master); fprintf(stderr, "MS/TP Max_Master: %02X\n", MSTP_Port.Nmax_master);
fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", MSTP_Port.Nmax_info_frames); fprintf(stderr, "MS/TP Max_Info_Frames: %u\n", MSTP_Port.Nmax_info_frames);
fflush(stderr);
#endif #endif
/* start the threads */ /* start the threads */
/* rv = pthread_create(&hThread, NULL, dlmstp_receive_fsm_task, NULL); */ /* rv = pthread_create(&hThread, NULL, dlmstp_receive_fsm_task, NULL); */
+9 -5
View File
@@ -547,7 +547,9 @@ void RS485_Initialize(void)
struct serial_struct newserial; struct serial_struct newserial;
float baud_error = 0.0; float baud_error = 0.0;
printf("RS485: Initializing %s", RS485_Port_Name); #if PRINT_ENABLED
fprintf(stdout, "RS485 Interface: %s\n", RS485_Port_Name);
#endif
/* /*
Open device for reading and writing. Open device for reading and writing.
Blocking mode - more CPU effecient Blocking mode - more CPU effecient
@@ -600,14 +602,17 @@ void RS485_Initialize(void)
76800); 76800);
if ((newserial.custom_divisor == 0) || (baud_error > 0.02)) { if ((newserial.custom_divisor == 0) || (baud_error > 0.02)) {
/* bad divisor */ /* bad divisor */
fprintf(stderr, "bad custom divisor %d, base baud %d\n", fprintf(stderr, "RS485 bad custom divisor %d, base baud %d\n",
newserial.custom_divisor, newserial.baud_base); newserial.custom_divisor, newserial.baud_base);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* if all goes well, set new divisor */ /* if all goes well, set new divisor */
ioctl(RS485_Handle, TIOCSSERIAL, &newserial); ioctl(RS485_Handle, TIOCSSERIAL, &newserial);
} }
printf(" at Baud Rate %u", RS485_Get_Baud_Rate()); #if PRINT_ENABLED
fprintf(stdout, "RS485 Baud Rate %u\n", RS485_Get_Baud_Rate());
fflush(stdout);
#endif
/* destructor */ /* destructor */
atexit(RS485_Cleanup); atexit(RS485_Cleanup);
/* flush any data waiting */ /* flush any data waiting */
@@ -615,7 +620,6 @@ void RS485_Initialize(void)
tcflush(RS485_Handle, TCIOFLUSH); tcflush(RS485_Handle, TCIOFLUSH);
/* ringbuffer */ /* ringbuffer */
FIFO_Init(&Rx_FIFO, Rx_Buffer, sizeof(Rx_Buffer)); FIFO_Init(&Rx_FIFO, Rx_Buffer, sizeof(Rx_Buffer));
printf("=success!\n");
} }
/* Print in a format for Wireshark ExtCap */ /* Print in a format for Wireshark ExtCap */
@@ -632,7 +636,7 @@ void RS485_Print_Ports(void)
bool valid_port = false; bool valid_port = false;
struct serial_struct serinfo; struct serial_struct serinfo;
/* Scan through /sys/class/tty - /* Scan through /sys/class/tty -
it contains all tty-devices in the system */ it contains all tty-devices in the system */
n = scandir(sysdir, &namelist, NULL, NULL); n = scandir(sysdir, &namelist, NULL, NULL);
if (n < 0) { if (n < 0) {
+3 -1
View File
@@ -266,7 +266,7 @@ void RS485_Initialize(void)
0, OPEN_EXISTING, 0, OPEN_EXISTING,
/*FILE_FLAG_OVERLAPPED */ 0, 0); /*FILE_FLAG_OVERLAPPED */ 0, 0);
if (RS485_Handle == INVALID_HANDLE_VALUE) { if (RS485_Handle == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Unable to open %s\n", RS485_Port_Name); fprintf(stderr, "RS485 unable to open %s\n", RS485_Port_Name);
RS485_Print_Error(); RS485_Print_Error();
exit(1); exit(1);
} }
@@ -276,6 +276,8 @@ void RS485_Initialize(void)
RS485_Configure_Status(); RS485_Configure_Status();
#if PRINT_ENABLED #if PRINT_ENABLED
fprintf(stdout, "RS485 Interface: %s\n", RS485_Port_Name); fprintf(stdout, "RS485 Interface: %s\n", RS485_Port_Name);
fprintf(stdout, "RS485 Baud Rate %u\n", RS485_Get_Baud_Rate());
fflush(stdout);
#endif #endif
atexit(RS485_Cleanup); atexit(RS485_Cleanup);