Commit 83bf3dc3 authored by dkubischlu1's avatar dkubischlu1
Browse files

Adding option to change CR to NL conversion


Signed-off-by: default avatardkubischlu1 <daniel.kubisch@sigmatechnology.se>
parent f7e17e84
......@@ -23,6 +23,7 @@ namespace SerialPortTypes {
dataBits = CS8; //8 data bits
stopBit = ~CSTOPB; //1 stop bit
parity = 0; //parity: none
CRtoNL = false; // convert NL to CR: false
}
SerialPort::~SerialPort()
......@@ -33,8 +34,11 @@ namespace SerialPortTypes {
// Implementation of the external function <set_parameter>.
void set__port__parameter(const CHARSTRING& parameter_name, const CHARSTRING& parameter_value, SerialPort& serial_port) {
serial_port.set_parameter(parameter_name, parameter_value);
const char* device_file_name = serial_port.get_device_file_name();
printf("Device File Name: %s\n", device_file_name);
if (strcmp(parameter_name, "deviceFileName") == 0) {
const char* device_file_name = serial_port.get_device_file_name();
printf("Device File Name: %s\n", device_file_name);
}
}
char* SerialPort::get_device_file_name(){
......@@ -123,7 +127,7 @@ namespace SerialPortTypes {
//printf("Parameter %s set to %s (int: %d)\n", parameter_name, parameter_value, blocking);
} else if (strncmp(parameter_name, "EOLChar", 7) == 0) {
eolChars.push_back(parameter_value[0]);
printf("Parameter %s set to %s (int: %d)\n", parameter_name, parameter_value, eolChars.back());
//printf("Parameter %s set to %s (int: %d)\n", parameter_name, parameter_value, eolChars.back());
} else if (strcmp(parameter_name, "dataBits") == 0) {
if (strcmp(parameter_value, "5") == 0) {
dataBits = CS5;
......@@ -146,6 +150,12 @@ namespace SerialPortTypes {
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);
}else if (strcmp(parameter_name, "CRtoNL") == 0) {
if (strcmp(parameter_value, "no") == 0){
CRtoNL = false;
} else if (strcmp(parameter_value, "yes") == 0){
CRtoNL = true;
}
}
}
......@@ -190,7 +200,7 @@ namespace SerialPortTypes {
incoming_message(ret_val);
}
}
}
}
}
/*void SerialPort::Handle_Timeout(double time_since_last_call) {}*/
......@@ -203,7 +213,7 @@ namespace SerialPortTypes {
{
TTCN_error("Unable to open port %s", param_device_file);
} else {
set_interface_attribs (device_fd, speed, parity, dataBits, stopBit);
set_interface_attribs (device_fd, speed, parity, dataBits, stopBit, CRtoNL);
set_blocking (device_fd, blocking);
Handler_Add_Fd_Read(device_fd);
ret_buffer = CHARSTRING("");
......@@ -246,7 +256,7 @@ namespace SerialPortTypes {
}
}
int SerialPort::set_interface_attribs (int fd, speed_t speed, int parity, int dataBits, int stopBit)
int SerialPort::set_interface_attribs (int fd, speed_t speed, int parity, int dataBits, int stopBit, bool CRtoNL)
{
struct termios tty;
memset (&tty, 0, sizeof tty);
......@@ -259,6 +269,8 @@ namespace SerialPortTypes {
cfsetospeed (&tty, speed);
cfsetispeed (&tty, speed);
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
......@@ -266,7 +278,15 @@ namespace SerialPortTypes {
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
if(CRtoNL){
tty.c_iflag |= ICRNL;
//printf("now iflag: %u ",tty.c_iflag);
} else {
tty.c_iflag &= ~ICRNL;
//printf("iflag: %u ",tty.c_iflag);
}
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
......@@ -275,7 +295,7 @@ namespace SerialPortTypes {
tty.c_cflag |= parity;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
if (tcsetattr (fd, TCSANOW, &tty) != 0)
{
TTCN_error ("error %d from tcsetattr", errno);
......@@ -304,3 +324,4 @@ namespace SerialPortTypes {
} /* end of namespace */
......@@ -50,7 +50,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 dataBits, int stopBit);
int set_interface_attribs (int fd, speed_t speed, int parity, int dataBits, int stopBit, bool CRtoNL);
void set_blocking (int fd, int should_block);
char *param_device_file;
......@@ -61,9 +61,11 @@ namespace SerialPortTypes {
std::vector<char> eolChars;
int dataBits;
int stopBit;
bool CRtoNL;
CHARSTRING ret_buffer;
};
} /* end of namespace */
#endif
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