Commit 976c3fb0 authored by Lenard Nagy's avatar Lenard Nagy
Browse files

data bits and stop bits made configurable


Signed-off-by: Lenard Nagy's avatarLenard Nagy <lenard.nagy@ericsson.com>
parent c36a266b
......@@ -17,7 +17,13 @@ namespace SerialPortTypes {
SerialPort::SerialPort(const char *par_port_name)
: SerialPort_BASE(par_port_name)
{
//Set default values
speed = B9600; //9600 baud
blocking = 1; //set blocking
eolChar = '\n'; //set line ending char
dataBits = CS8; //8 data bits
stopBit = ~CSTOPB; //1 stop bit
parity = 0; //parity: none
}
SerialPort::~SerialPort()
......@@ -108,10 +114,29 @@ namespace SerialPortTypes {
} else if (strcmp(parameter_name, "EOLChar") == 0) {
eolChar = parameter_value[0];
//printf("Parameter %s set to %s (int: %d)\n", parameter_name, parameter_value, eolChar);
} else if (strcmp(parameter_name, "dataBits") == 0) {
if (strcmp(parameter_value, "5") == 0) {
dataBits = CS5;
} else if (strcmp(parameter_value, "6") == 0) {
dataBits = CS6;
} else if (strcmp(parameter_value, "7") == 0) {
dataBits = CS7;
} else if (strcmp(parameter_value, "8") == 0) {
dataBits = CS8;
} else {
TTCN_error("Invalid %s value: %s\n", parameter_name, parameter_value);
}
//printf("Parameter %s set to %s (int: %d, hex: 0x%0)\n", parameter_name, parameter_value, dataBits);
} else if (strcmp(parameter_name, "stopBit") == 0) {
if (strcmp(parameter_value, "1") == 0) {
stopBit = ~CSTOPB;
} else if (strcmp(parameter_value, "2") == 0) {
stopBit = CSTOPB;
} else {
TTCN_error("Invalid %s value: %s\n", parameter_name, parameter_value);
}
//printf("Parameter %s set to %s (int: %d, hex: 0x%0)\n", parameter_name, parameter_value, stopBit);
}
}
/*void SerialPort::Handle_Fd_Event(int fd, boolean is_readable,
......@@ -166,7 +191,7 @@ namespace SerialPortTypes {
{
TTCN_error("Unable to open port %s", param_device_file);
} else {
set_interface_attribs (device_fd, speed, parity);
set_interface_attribs (device_fd, speed, parity, dataBits, stopBit);
set_blocking (device_fd, blocking);
Handler_Add_Fd_Read(device_fd);
ret_buffer = CHARSTRING("");
......@@ -209,7 +234,7 @@ namespace SerialPortTypes {
}
}
int SerialPort::set_interface_attribs (int fd, speed_t speed, int parity)
int SerialPort::set_interface_attribs (int fd, speed_t speed, int parity, int dataBits, int stopBit)
{
struct termios tty;
memset (&tty, 0, sizeof tty);
......
......@@ -64,6 +64,17 @@ LogEntityName := Yes
*.SerialPort1.EOLChar := "\n"
*.SerialPort2.EOLChar := "\n"
## Number of data bits
# Valid values: 5, 6, 7, 8
##
*.SerialPort1.dataBits := "8"
*.SerialPort2.dataBits := "8"
## Number of stop bit(s)
# Valid values: 1, 2
##
*.SerialPort1.stopBit := "1"
*.SerialPort2.stopBits := "1"
[DEFINE]
......
......@@ -45,7 +45,7 @@ namespace SerialPortTypes {
void user_stop();
void outgoing_send(const CHARSTRING& send_par);
int set_interface_attribs (int fd, speed_t speed, int parity);
int set_interface_attribs (int fd, speed_t speed, int parity, int dataBits, int stopBit);
void set_blocking (int fd, int should_block);
char *param_device_file;
......@@ -54,6 +54,8 @@ namespace SerialPortTypes {
int parity;
int blocking;
char eolChar;
int dataBits;
int stopBit;
CHARSTRING ret_buffer;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment