Commit 23225511 authored by Elemer Lelik's avatar Elemer Lelik
Browse files

source added

parent 07ad6a11
/******************************************************************************
* Copyright (c) 2017 Ericsson AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lenard Nagy
******************************************************************************/
module SerialPortTests {
import from SerialPortTypes all;
type component SPSend {
port SerialPort SerialPort1;
timer t_short;
}
type component SPReceive {
port SerialPort SerialPort2;
timer t_short;
}
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);
timer t; t.start(6.0); t.timeout;
unmap(self:SerialPort1, system:SerialPort1);
}
function f_receive() runs on SPReceive {
map(self:SerialPort2, system:SerialPort2);
log("Waiting for input...")
var octetstring os_incoming;
t_short.start(5.0);
alt {
[] SerialPort2.receive(octetstring:?) -> value os_incoming {
setverdict(pass,"message received on port: %s", os_incoming);
}
[] t_short.timeout {
log("Timeout while waiting for input");
setverdict(inconc);
}
}
unmap(self:SerialPort2, system:SerialPort2);
}
testcase TC_SerialPortTestSend() runs on SP {
log("Starting SerialPort port tests");
var SPReceive c_receiver;
var SPSend c_sender;
c_receiver := SPReceive.create;
c_sender := SPSend.create;
c_receiver.start(f_receive());
c_sender.start( f_send());
timer t; t.start(6.0); t.timeout;
c_receiver.stop;
c_sender.stop;
}
control {
execute(TC_SerialPortTestSend());
}
}
/******************************************************************************
* Copyright (c) 2017 Ericsson AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lenard Nagy
******************************************************************************/
#include "SerialPort.hh"
namespace SerialPortTypes {
SerialPort::SerialPort(const char *par_port_name)
: SerialPort_BASE(par_port_name)
{
}
SerialPort::~SerialPort()
{
}
void SerialPort::set_parameter(const char * parameter_name,
const char * parameter_value)
{
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);
}
}
/*void SerialPort::Handle_Fd_Event(int fd, boolean is_readable,
boolean is_writable, boolean is_error) {}*/
void SerialPort::Handle_Fd_Event_Error(int /*fd*/)
{
//printf("===ELNRNAG=== Message received e\n");
}
void SerialPort::Handle_Fd_Event_Writable(int fd)
{
printf("Message received w\n");
Handle_Fd_Event_Readable(fd);
}
void SerialPort::Handle_Fd_Event_Readable(int fd)
{
printf("Message received r\n");
OCTETSTRING ret_val;
char input_buffer[255];
char* pointer = input_buffer;
int read_bytes = read(fd, pointer, sizeof(input_buffer));
if (read_bytes > 0) {
ret_val = OCTETSTRING(read_bytes, (const unsigned char*)pointer);
incoming_message(ret_val);
}
}
/*void SerialPort::Handle_Timeout(double time_since_last_call) {}*/
void SerialPort::user_map(const char * system_port)
{
if (param_device_file != NULL && param_device_file[0] != '\0'){
device_fd = open(param_device_file, O_RDWR | O_NOCTTY | O_NDELAY);
if (device_fd == -1)
{
TTCN_error("Unable to open port %s", param_device_file);
} else {
Handler_Add_Fd_Read(device_fd);
}
} else {
TTCN_error("No device file set in configuration file!");
}
}
void SerialPort::user_unmap(const char * /*system_port*/)
{
Handler_Remove_Fd_Read(device_fd);
close(device_fd);
}
void SerialPort::user_start()
{
}
void SerialPort::user_stop()
{
}
void SerialPort::outgoing_send(const OCTETSTRING& send_par)
{
const unsigned char* data = (const unsigned char*)send_par;
if (data != NULL) {
long data_length = send_par.lengthof();
printf("Sending message: %s\n", data);
int n = write(device_fd, data, data_length);
printf("Sent message: %s\n", data);
if (n < data_length) {
TTCN_error("Error while sending data on port %s", param_device_file);
}
}
}
} /* end of namespace */
####################################################################################
# Copyright (c) 2017 Ericsson AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Lenard Nagy
####################################################################################
[MODULE_PARAMETERS]
# This section shall contain the values of all parameters that are defined in your TTCN-3 modules.
[LOGGING]
# In this section you can specify the name of the log file and the classes of events
# you want to log into the file or display on console (standard error).
LogFile := "logs/%e.%h-%r.%s"
FileMask := LOG_ALL | DEBUG | MATCHING
ConsoleMask := ERROR | WARNING | TESTCASE | STATISTICS | PORTEVENT
LogSourceInfo := Yes
AppendFile := No
TimeStampFormat := DateTime
LogEventTypes := Yes
SourceInfoFormat := Single
LogEntityName := Yes
[TESTPORT_PARAMETERS]
# In this section you can specify parameters that are passed to Test Ports.
*.SerialPort1.deviceFileName := "/dev/ttyUSB0"
*.SerialPort2.deviceFileName := "/dev/ttyUSB1"
[DEFINE]
# In this section you can create macro definitions,
# that can be used in other configuration file sections except [INCLUDE] and [ORDERED_INCLUDE].
[INCLUDE]
# To use configuration settings given in other configuration files,
# the configuration files just need to be listed in this section, with their full or relative pathnames.
[ORDERED_INCLUDE]
# To use configuration settings given in other configuration files,
# the configuration files just need to be listed in this section, with their full or relative pathnames.
[EXTERNAL_COMMANDS]
# This section can define external commands (shell scripts) to be executed by the ETS
# whenever a control part or test case is started or terminated.
#BeginTestCase := ""
#EndTestCase := ""
#BeginControlPart := ""
#EndControlPart := ""
[EXECUTE]
# In this section you can specify what parts of your test suite you want to execute.
SerialPortTests.TC_SerialPortTestSend
#SerialPortTests.TC_SerialPortTestReceive
[GROUPS]
# In this section you can specify groups of hosts. These groups can be used inside the
# [COMPONENTS] section to restrict the creation of certain PTCs to a given set of hosts.
[COMPONENTS]
# This section consists of rules restricting the location of created PTCs.
[MAIN_CONTROLLER]
# The options herein control the behavior of MC.
TCPPort := 0
KillTimer := 10.0
# NumHCs := 0
# LocalAddress :=
/******************************************************************************
* Copyright (c) 2017 Ericsson AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lenard Nagy
******************************************************************************/
#ifndef SerialPort_HH
#define SerialPort_HH
#include "SerialPortTypes.hh"
#include <string.h>
#include <fcntl.h> /* File control definitions */
#include <unistd.h> /* UNIX standard function definitions */
namespace SerialPortTypes {
class SerialPort : public SerialPort_BASE {
public:
SerialPort(const char *par_port_name = NULL);
~SerialPort();
void set_parameter(const char *parameter_name,
const char *parameter_value);
private:
/* void Handle_Fd_Event(int fd, boolean is_readable,
boolean is_writable, boolean is_error); */
void Handle_Fd_Event_Error(int fd);
void Handle_Fd_Event_Writable(int fd);
void Handle_Fd_Event_Readable(int fd);
/* void Handle_Timeout(double time_since_last_call); */
protected:
void user_map(const char *system_port);
void user_unmap(const char *system_port);
void user_start();
void user_stop();
void outgoing_send(const OCTETSTRING& send_par);
char *param_device_file;
int device_fd;
};
} /* end of namespace */
#endif
/******************************************************************************
* Copyright (c) 2017 Ericsson AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lenard Nagy
******************************************************************************/
module SerialPortTypes {
const charstring PARAM_DEVFILENAME := "";
type octetstring SerialPortMessage;
type port SerialPort message {
out
SerialPortMessage;
in
SerialPortMessage;
}
}
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