Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » type port as parameter
type port as parameter [message #1749593] Thu, 08 December 2016 13:19 Go to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Hi All,

I would like to wrap the sending and receiving into a function. This function should run on my test component, which has two test ports. Thats why I have to determine on which port the send and receive should be performed.

see below a more easy example which describe what I want to do:


type component tester {
  port testPort device_1;
  port testPort device_2;
}

function f_send( in testport port ,in OCTETSTRING msg) runs on tester {
    port.send( msg);
}
   


Any Idea how to implement this in TTCN-3 ?

Thanks,

Johannes
Re: type port as parameter [message #1749596 is a reply to message #1749593] Thu, 08 December 2016 13:39 Go to previous messageGo to next message
Naum Spaseski is currently offline Naum SpaseskiFriend
Messages: 81
Registered: February 2016
Location: Sophia Antipolis
Member

Hello Johannes,

One option is to use boolean/integer with a switch to detect on which port you will send the message. Like this:

function f_send( in integer p_portN ,in OCTETSTRING msg) runs on tester {
    if (p_portN == 1){
        device_1.send(msg);
    }else{
         device_2.send(msg);
    }
}


Best regards,
Naum
Re: type port as parameter [message #1749599 is a reply to message #1749593] Thu, 08 December 2016 13:57 Go to previous messageGo to next message
roland gecse is currently offline roland gecseFriend
Messages: 9
Registered: December 2015
Junior Member
You can use port types as formal function parameters with TITAN, which makes it possible to pass port instances as actual parameters to functions. Nevertheless, you cannot pass the port instance as a value parameter.

Here's a small sample to demonstrate:

module test
{

type port testPort message {
    inout octetstring;
} 

type component tester {
  port testPort device_1;
  port testPort device_2;
}

function f_send( testPort p ,in octetstring m) runs on tester {
    p.send( m);
}

testcase tc() runs on tester
{
    map(mtc:device_1, system:device_1);
    map(mtc:device_2, system:device_2);
    f_send(device_1, '0123'O);
    f_send(device_2, '2345'O);
}

control
{
    execute(tc());
}

}


Please note the changes compared to your initial code snippet!

R
Re: type port as parameter [message #1749602 is a reply to message #1749599] Thu, 08 December 2016 14:09 Go to previous message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Thanks a lot roland, that is exactly that what I searched for.
Previous Topic:Titan Architecture Internals: On the difference between the bool and boolean types
Next Topic:Titan has been presented at several 2016 autumn conferences
Goto Forum:
  


Current Time: Sun Sep 23 20:42:43 GMT 2018

Powered by FUDForum. Page generated in 0.02034 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top