blob: 3acc1f5fcabd8798c2f676eaa7f1ad1f826f94b3 [file] [log] [blame]
/////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017-2018 Ericsson AB
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
/////////////////////////////////////////////////////////////////////////////////////
// Contributors:
// Akos Makovics
//
// File: UpcUa_Functions.ttcn
// Rev: <RnXnn>
// Prodnr: CNL113861
/////////////////////////////////////////////////////////////////////////////////////
module OpcUa_Functions {
import from IPL4asp_Types all;
import from IPL4asp_PortType all;
type record ConnectionData {
charstring host, // host name [string]
integer portNumber // port number [integer]
}
function CreateConnection (
IPL4asp_PT testPort,
ConnectionData local,
ConnectionData remote
) return integer {
var Result connectionResult;
var integer returnValue;
// connect to the socket and check result
connectionResult := f_IPL4_connect(
testPort,
remote.host, remote.portNumber,
local.host, local.portNumber,
-1,
{ tcp := {}},
{
{ reuseAddress := {enable := true} }
});
if (ispresent(connectionResult.errorCode)) {
log(" [!!] TCP port connection error: ", connectionResult);
returnValue := -1;
} else {
log(" [::] TCP port [", remote.host, "/", remote.portNumber, "] connected.");
returnValue := connectionResult.connId;
}
return returnValue;
}
function CloseConnection (
IPL4asp_PT testPort,
integer connId
) return boolean {
var Result closingResult;
closingResult := f_IPL4_close(testPort, connId, { unspecified := {} });
if (ispresent(closingResult.errorCode)) {
return false;
} else {
return true;
}
}
function SendMessage (
IPL4asp_PT testPort,
ConnectionData remote,
integer connId,
in octetstring messageToSend
) {
// send and receive TCP message
var ASP_SendTo tcp_msg_send;
// set up TCP message
tcp_msg_send := { connId, remote.host, remote.portNumber, { tcp := {} }, messageToSend }
// send out TCP message to the given port
testPort.send(tcp_msg_send);
log("Message sent");
}
function ReceiveMessage (
IPL4asp_PT testPort,
inout octetstring receivedMsg
) return boolean {
var ASP_RecvFrom tcp_msg_received;
timer T := 0.1;
T.start;
alt
{
[] testPort.receive(ASP_RecvFrom : ?) -> value tcp_msg_received {
log("TCP message received");
receivedMsg := tcp_msg_received.msg;
return true;
}
[] T.timeout {
log("Timeout, no response");
}
}
return false;
}
}