Fixed Linux MS/TP 76800 bitrate for Linux 2.6.20+ circa 2007 and added get/set API for config. (#1007)
This commit is contained in:
+14
-11
@@ -12,11 +12,9 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
/* BACnet Stack defines - first */
|
||||
#include "bacnet/bacdef.h"
|
||||
/* BACnet Stack API */
|
||||
#include "bacnet/bacdef.h"
|
||||
#include "bacnet/bacaddr.h"
|
||||
#include "bacnet/npdu.h"
|
||||
#include "bacnet/datalink/mstp.h"
|
||||
@@ -99,7 +97,8 @@ void dlmstp_cleanup(void *poPort)
|
||||
}
|
||||
|
||||
/* restore the old port settings */
|
||||
tcsetattr(poSharedData->RS485_Handle, TCSANOW, &poSharedData->RS485_oldtio);
|
||||
termios2_tcsetattr(
|
||||
poSharedData->RS485_Handle, TCSANOW, &poSharedData->RS485_oldtio2);
|
||||
close(poSharedData->RS485_Handle);
|
||||
|
||||
pthread_cond_destroy(&poSharedData->Received_Frame_Flag);
|
||||
@@ -770,7 +769,7 @@ bool dlmstp_init(void *poPort, char *ifname)
|
||||
unsigned long hThread = 0;
|
||||
int rv = 0;
|
||||
SHARED_MSTP_DATA *poSharedData;
|
||||
struct termios newtio;
|
||||
struct termios2 newtio;
|
||||
struct mstp_port_struct_t *mstp_port = (struct mstp_port_struct_t *)poPort;
|
||||
if (!mstp_port) {
|
||||
return false;
|
||||
@@ -819,18 +818,22 @@ bool dlmstp_init(void *poPort, char *ifname)
|
||||
fcntl(poSharedData->RS485_Handle, F_SETFL, 0);
|
||||
#endif
|
||||
/* save current serial port settings */
|
||||
tcgetattr(poSharedData->RS485_Handle, &poSharedData->RS485_oldtio);
|
||||
termios2_tcgetattr(
|
||||
poSharedData->RS485_Handle, &poSharedData->RS485_oldtio2);
|
||||
/* clear struct for new port settings */
|
||||
bzero(&newtio, sizeof(newtio));
|
||||
memset(&newtio, 0, sizeof(newtio));
|
||||
/*
|
||||
BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed.
|
||||
BOTHER: Set bps rate.
|
||||
https://man7.org/linux/man-pages/man2/TCSETS.2const.html
|
||||
CRTSCTS : output hardware flow control (only used if the cable has
|
||||
all necessary lines. See sect. 7 of Serial-HOWTO)
|
||||
CLOCAL : local connection, no modem contol
|
||||
CLOCAL : local connection, no modem control
|
||||
CREAD : enable receiving characters
|
||||
*/
|
||||
newtio.c_cflag =
|
||||
poSharedData->RS485_Baud | poSharedData->RS485MOD | CLOCAL | CREAD;
|
||||
poSharedData->RS485MOD | CLOCAL | CREAD | BOTHER | (BOTHER << IBSHIFT);
|
||||
newtio.c_ispeed = poSharedData->RS485_Baud;
|
||||
newtio.c_ospeed = poSharedData->RS485_Baud;
|
||||
/* Raw input */
|
||||
newtio.c_iflag = 0;
|
||||
/* Raw output */
|
||||
@@ -838,10 +841,10 @@ bool dlmstp_init(void *poPort, char *ifname)
|
||||
/* no processing */
|
||||
newtio.c_lflag = 0;
|
||||
/* activate the settings for the port after flushing I/O */
|
||||
tcsetattr(poSharedData->RS485_Handle, TCSAFLUSH, &newtio);
|
||||
termios2_tcsetattr(poSharedData->RS485_Handle, TCSAFLUSH, &newtio);
|
||||
/* flush any data waiting */
|
||||
usleep(200000);
|
||||
tcflush(poSharedData->RS485_Handle, TCIOFLUSH);
|
||||
termios2_tcflush(poSharedData->RS485_Handle, TCIOFLUSH);
|
||||
/* ringbuffer */
|
||||
FIFO_Init(
|
||||
&poSharedData->Rx_FIFO, poSharedData->Rx_Buffer,
|
||||
|
||||
Reference in New Issue
Block a user