Commit 4c9a95df authored by Lenard Nagy's avatar Lenard Nagy
Browse files

Serial Port first stable version


Signed-off-by: Lenard Nagy's avatarLenard Nagy <lenard.nagy@ericsson.com>
parent fbe79793
......@@ -7,3 +7,43 @@ https://projects.eclipse.org/projects/tools.titan
The source code of the TTCN-3 compiler and executor:
https://github.com/eclipse/titan.core
## Usage
- clone this repo to your computer in a folder (home_folder from now on)
- Create a "bin" directory and cd into it
`
$ mkdir bin
$ cd ./bin
`
- Create symlinks to all files in src and demo directory here
`
$ ln -s ../src/* .
$ ln -s ../demo/* .
`
- Create the makefile
`
$ makefilegen -e "SerialPortTests" ./*
`
- Compile the project
`
$ make
`
- Adjust serial port properties in SerialPort.cfg
- Run the tests
`
$ ttcn3_start SerialPortTests SerialPort.cfg
`
## End
\ No newline at end of file
......@@ -13,6 +13,8 @@ module SerialPortTests {
import from SerialPortTypes all;
const charstring str := "hello world\n";
type component SPSend {
port SerialPort SerialPort1;
timer t_short;
......@@ -28,9 +30,8 @@ type component SP {
function f_send() runs on SPSend {
map(self:SerialPort1, system:SerialPort1);
var octetstring os := '616263'O;
log("Sending octetstring: %s", os);
SerialPort1.send(os);
log("Sending charstring: %s", str);
SerialPort1.send(str);
timer t; t.start(6.0); t.timeout;
unmap(self:SerialPort1, system:SerialPort1);
......@@ -40,13 +41,19 @@ function f_receive() runs on SPReceive {
map(self:SerialPort2, system:SerialPort2);
log("Waiting for input...")
var octetstring os_incoming;
t_short.start(5.0);
var charstring os_incoming;
t_short.start(6.0);
alt {
[] SerialPort2.receive(octetstring:?) -> value os_incoming {
setverdict(pass,"message received on port: %s", os_incoming);
}
[] SerialPort2.receive(charstring:?) -> value os_incoming {
if (os_incoming == str) {
setverdict(pass,"message received on port: ", os_incoming);
} else {
log(os_incoming);
repeat;
//setverdict(fail,"message differs: %s", os_incoming);
}
}
[] t_short.timeout {
log("Timeout while waiting for input");
setverdict(inconc);
......@@ -62,7 +69,7 @@ testcase TC_SerialPortTestSend() runs on SP {
log("Starting SerialPort port tests");
var SPReceive c_receiver;
var SPSend c_sender;
var SPSend c_sender;
c_receiver := SPReceive.create;
c_sender := SPSend.create;
......
......@@ -30,7 +30,7 @@ namespace SerialPortTypes {
if (strcmp(parameter_name, "deviceFileName") == 0) {
param_device_file = (char*) malloc(strlen(parameter_value));
strcpy(param_device_file, parameter_value);
printf("Parameter %s set to %s\n", parameter_name, param_device_file);
//printf("Parameter %s set to %s\n", parameter_name, param_device_file);
} else if (strcmp(parameter_name, "deviceSpeed") == 0) {
if (strcmp(parameter_value, "B0") == 0) {
speed = B0;
......@@ -77,8 +77,7 @@ namespace SerialPortTypes {
} else {
TTCN_error("Invalid %s value: %s\n", parameter_name, parameter_value);
}
printf("Parameter %s set to %s (int: %u)\n",
parameter_name, parameter_value, speed);
//printf("Parameter %s set to %s (int: %u)\n", parameter_name, parameter_value, speed);
} else if (strcmp(parameter_name, "deviceParity") == 0) {
if (strcmp(parameter_value, "none") == 0) {
parity = 0;
......@@ -94,8 +93,7 @@ namespace SerialPortTypes {
TTCN_error("Invalid %s value: %s\n", parameter_name, parameter_value);
}
printf("Parameter %s set to %s (int: %d)\n",
parameter_name, parameter_value, parity);
//printf("Parameter %s set to %s (int: %d)\n", parameter_name, parameter_value, parity);
} else if (strcmp(parameter_name, "deviceBlocking") == 0) {
if (strcmp(parameter_value, "no") == 0) {
blocking = 0;
......@@ -105,8 +103,10 @@ namespace SerialPortTypes {
TTCN_error("Invalid %s value: %s\n", parameter_name, parameter_value);
}
printf("Parameter %s set to %s (int: %d)\n",
parameter_name, parameter_value, blocking);
//printf("Parameter %s set to %s (int: %d)\n", parameter_name, parameter_value, blocking);
} 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);
}
......@@ -123,22 +123,35 @@ namespace SerialPortTypes {
void SerialPort::Handle_Fd_Event_Writable(int fd)
{
printf("Message received w\n");
//printf("Message received w\n");
Handle_Fd_Event_Readable(fd);
}
void SerialPort::Handle_Fd_Event_Readable(int fd)
{
printf("Message received r\n");
//printf("Message received r\n");
OCTETSTRING ret_val;
char input_buffer[255];
char input_buffer[1];
char* pointer = input_buffer;
int read_bytes = read(fd, pointer, sizeof(input_buffer));
int read_bytes = read(fd, pointer, 1); //sizeof(input_buffer));
if (read_bytes > 0) {
ret_val = OCTETSTRING(read_bytes, (const unsigned char*)pointer);
incoming_message(ret_val);
//printf("Incoming: %s (%d)\n",input_buffer, input_buffer[0]);
if (ret_buffer.is_bound()) { //already bound, concatenate
//printf ("already bound, concatenate");
ret_buffer += input_buffer[0];
} else { //ret_buffer not bound, create new
//printf("ret_buffer not bound, create new");
ret_buffer = CHARSTRING(read_bytes, (const char*)pointer);
}
if (input_buffer[0] == eolChar) { //EOL received, returning
//printf("EOL received, returning");
CHARSTRING ret_val = CHARSTRING(ret_buffer);
ret_buffer = CHARSTRING("");
incoming_message(ret_val);
}
}
}
......@@ -155,6 +168,7 @@ namespace SerialPortTypes {
set_interface_attribs (device_fd, speed, parity);
set_blocking (device_fd, blocking);
Handler_Add_Fd_Read(device_fd);
ret_buffer = CHARSTRING("");
}
} else {
TTCN_error("No device file set in configuration file!");
......@@ -177,14 +191,14 @@ namespace SerialPortTypes {
}
void SerialPort::outgoing_send(const OCTETSTRING& send_par)
void SerialPort::outgoing_send(const CHARSTRING& send_par)
{
const unsigned char* data = (const unsigned char*)send_par;
const char* data = (const char*)send_par;
if (data != NULL) {
long data_length = send_par.lengthof();
printf("Sending message: %s\n", data);
//printf("Sending message: %s\n", data);
int n = write(device_fd, data, data_length);
printf("Sent message: %s\n", data);
//printf("Sent message: %s\n", data);
if (n < data_length) {
TTCN_error("Error while sending data on port %s", param_device_file);
}
......@@ -212,8 +226,6 @@ namespace SerialPortTypes {
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
......@@ -243,7 +255,7 @@ namespace SerialPortTypes {
}
tty.c_cc[VMIN] = should_block ? 1 : 0;
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_cc[VTIME] = 0; // 0.5 seconds read timeout
if (tcsetattr (fd, TCSANOW, &tty) != 0)
TTCN_error ("error %d setting term attributes", errno);
......
......@@ -38,8 +38,8 @@ LogEntityName := Yes
# B9600 B19200 B38400 B57600 B115200
# B230400 B460800
##
*.SerialPort1.deviceSpeed := "B115200"
*.SerialPort2.deviceSpeed := "B115200"
*.SerialPort1.deviceSpeed := "B9600"
*.SerialPort2.deviceSpeed := "B9600"
## Parity setting
# Valid values: none, even, odd, mark, space
......@@ -56,8 +56,13 @@ LogEntityName := Yes
# characters are available without waiting
# for more, up to the buffer limit.
##
*.SerialPort1.deviceBlocking := "no"
*.SerialPort2.deviceBlocking := "no"
*.SerialPort1.deviceBlocking := "yes"
*.SerialPort2.deviceBlocking := "yes"
## EOL character
*.SerialPort1.EOLChar := "\n"
*.SerialPort2.EOLChar := "\n"
[DEFINE]
......
......@@ -42,7 +42,7 @@ namespace SerialPortTypes {
void user_unmap(const char *system_port);
void user_start();
void user_stop();
void outgoing_send(const OCTETSTRING& send_par);
void outgoing_send(const CHARSTRING& send_par);
int set_interface_attribs (int fd, speed_t speed, int parity);
void set_blocking (int fd, int should_block);
......@@ -52,6 +52,8 @@ namespace SerialPortTypes {
speed_t speed;
int parity;
int blocking;
char eolChar;
CHARSTRING ret_buffer;
};
} /* end of namespace */
......
......@@ -13,7 +13,7 @@ module SerialPortTypes {
const charstring PARAM_DEVFILENAME := "";
type octetstring SerialPortMessage;
type charstring SerialPortMessage;
type port SerialPort message {
out
......
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