LibItsCommon_Functions.ttcn 11.1 KB
Newer Older
/**
garciay's avatar
garciay committed
 *    @author     ETSI / STF405 / STF449 / STF484 / STF517
garciay's avatar
garciay committed
 *    @version    $Url: https://oldforge.etsi.org/svn/LibIts/tags/20170222_STF527_Final/ttcn/Common/LibItsCommon_Functions.ttcn $
 *                $Id: LibItsCommon_Functions.ttcn 1318 2017-01-26 10:20:53Z filatov $
 *    @desc       Module containing common functions for ITS
garciay's avatar
garciay committed
 *    @copyright   ETSI Copyright Notification
 *                 No part may be reproduced except as authorized by written permission.
 *                 The copyright and the foregoing restriction extend to reproduction in all media.
 *                 All rights reserved.
module LibItsCommon_Functions {

    // LibCommon
filatov's avatar
filatov committed
//    import from LibCommon_Sync all;
//    import from LibCommon_VerdictControl all;
    import from LibCommon_BasicTypesAndValues all;
    import from LibItsCommon_Pixits all;
    import from ITS_Container language "ASN.1:1997" all;
ASN.1 Documenter's avatar
ASN.1 Documenter committed
//    import from DSRC language "ASN.1:1997" all;
        /** 
         * @desc    function to generate integer random values
         *            
         * @see        ttcn-3 - rnd()
         * @param     p_lowerbound lowest number in range
         * @param     p_upperbound highest number in range
         * @return     random integer
         *
        */
        function f_random(    in integer p_lowerbound,
                            in integer p_upperbound )
        return integer {
            //Variables
            var integer v_random := 0;
            v_random := float2int(int2float(p_upperbound - p_lowerbound +1)*rnd()) + p_lowerbound;
    
            log("*** f_random: INFO: OK - random value = " & int2str(v_random) & " ***");
        } // end function f_random
berge's avatar
berge committed

        /**
         * @desc    Computes the absolute value of an integer 
         * @param   p_number    the number
         * @return  Absolute value of the number
         */
        function f_abs(in integer p_number) 
        return integer {
            
            if(p_number < 0) {
                return 0 - p_number;
            return p_number;    
        }

        /**
         * @desc    Computes the absolute value of an integer 
         * @param   p_number    the number
         * @return  Absolute value of the number
         */
        function ff_abs(in float p_number) 
        return float {
            
            if(p_number < 0.0) {
                return 0.0 - p_number;
            }
            return p_number;    
berge's avatar
berge committed
        /**
         * @desc    Compares two values and returns the lowest onde  
         * @param   p_a     First value
         * @param   p_b     Second value
         * @return  Lowest value
         */
        function f_min(in integer p_a, in integer p_b) 
        return integer {
            
            if(p_a < p_b) {
                return p_a;
            }
            return p_b;    
        }

berge's avatar
berge committed
        /** 
         * @desc    Removes unsignificant right-most 0 bits of a bitstring
         *            
         * @param     p_bitstring Bitstring to be reduced
         * @return    Reduced bitstring
         *
        */    
        function f_removeUnsignificantBits(in bitstring p_bitstring)
        return bitstring {
            var integer i, len;
            
            len := lengthof(p_bitstring);
            for(i:=len-1; i >=0 and p_bitstring[i] == '0'B; i:=i-1) {}
            return substr(p_bitstring, 0, i + 1);
berge's avatar
berge committed
        } 
         * @desc    Gets the current time since 01/01/2004
         * @return  TimestampIts - current time since 01/01/2004 in milliseconds
        function f_getCurrentTime() return TimestampIts {
            var TimestampIts v_timeStamp := 0;
//            log("*** f_getCurrentTime: INFO: calling fx_getCurrentTime() ***");
            v_timeStamp := fx_getCurrentTime();
            
            return v_timeStamp;
        }
           
        /**
         * @desc    Gets the current time since 01/01/1970 in UTC format
         * @return  The current time since 01/01/1970 in UTC format
         */
        function f_getCurrentTimeUtc() return UInt64 {
            var UInt64 v_time := 0;
            
//            log("*** f_getCurrentTimeUtc: INFO: calling fx_getCurrentTimeUtc() ***");
            v_time := fx_getCurrentTimeUtc();
            
            return v_time;
        }
           
        /**
         * @desc    Gets the current time since 01/01/2004
         * @return  TimeMark - tenths of a second in the current or next hour in units of 1/10th second from UTC time
         */
ASN.1 Documenter's avatar
ASN.1 Documenter committed
        function f_getCurrentTimeMark() return UInt32 {
            var UInt32 v_timeMark := 0;
            
//            log("*** f_getCurrentTimeMark: INFO: calling fx_getCurrentTimeMark() ***");
            v_timeMark := fx_getCurrentTimeMark();
            
            return v_timeMark;
        }
           
        /**
         * @desc    Gets the Minute of current UTC year
         * @return  MinuteOfTheYear - tenths of a second in the current or next hour in units of 1/10th second from UTC time
         */
ASN.1 Documenter's avatar
ASN.1 Documenter committed
        function f_getMinuteOfTheYear() return UInt16 {
            var UInt16 v_minuteOfTheYear := 0;
            
//            log("*** f_getMinuteOfTheYear: INFO: calling fx_getMinuteOfTheYear() ***");
            v_minuteOfTheYear := fx_getMinuteOfTheYear();
            
            return v_minuteOfTheYear;
        }
           
        /**
         * @desc    Gets the milliseconds point in the current UTC minute
         * @return  DSecond - The milliseconds point in the current UTC minute (0..60000)
         */
ASN.1 Documenter's avatar
ASN.1 Documenter committed
        function f_getDSecond() return UInt16 {
            var UInt16 v_dSecond := 0;
            
//            log("*** f_getDSecond: INFO: calling fx_getDSecond() ***");
            v_dSecond := fx_getDSecond();
            
            return v_dSecond;
        }
           
    } // end generalFunctions  
       
    group itsFunctions { 

        /** 
         * @desc    Gets the station identifier of implementation under test (IUT)
         * @return  IUT's station ID
         * @see     PX_IUT_STATION_ID
         */
        function f_getIutStationId()
        return StationID {
            
            return PX_IUT_STATION_ID;
                
        } // end f_getIutStationId
        
        function f_getIutStationType()
        return StationType {
            
            return PX_IUT_STATION_TYPE;
                
        } // end f_getIutStationType
        
        /** 
         * @desc    Gets the station identifier of test system
         * @return  Test system's station ID
         * @see     PX_TESTER_STATION_ID
         */
        function f_getTsStationId()
        return StationID {
            
            return PX_TESTER_STATION_ID;
                
        } // end f_getTsStationId
        
        function f_getTsStationType()
        return StationType {
            
            return PX_TESTER_STATION_TYPE;
                
        } // end f_getTsStationType
        
         * @desc    Gets the current latitude of test system
         * @return  Test system's latitude
         */
        function f_getTsLatitude() return Latitude {
            
            return PX_TS_LATITUDE;
            
        } // end f_getTsLatitude

        /**
         * @desc    Gets the current longitude of test system
         * @return  Test system's latitude
        function f_getTsLongitude() return Longitude {
            return PX_TS_LONGITUDE;
        } // end f_getTsLongitude
garciay's avatar
garciay committed
        function f_getTimeForGpsFix() return integer {
            
            return PX_TIME_FOR_GPS_FIX;
        }
        
    } // end itsFunctions       
  
    group externalFunctions {
        
         * @desc    This external function gets the current time
         * @return  Timestamp - current time since 01/01/2014 in milliseconds
        external function fx_getCurrentTime() return UInt64;
        /**
         * @desc    Gets the current time since 01/01/1970 in UTC format
         * @return  The current time since 01/01/1970 in UTC format
         */
        external function fx_getCurrentTimeUtc() return UInt64;
        
         * @desc    Gets the tenths of a second in the current or next hour in units of 1/10th second from UTC time
         * @return  TimeMark - tenths of a second in the current or next hour in units of 1/10th second from UTC time
         */
        external function fx_getCurrentTimeMark() return UInt32;
        
        /**
         * @desc    Gets the minutes of current UTC year
         * @return  MinuteOfTheYear - minutes of current UTC year
         */
        external function fx_getMinuteOfTheYear() return UInt16;
        
        /**
         * @desc    Gets the milliseconds point in the current UTC minute
         * @return  DSecond - the milliseconds point in the current UTC minute
         */
        external function fx_getDSecond() return UInt16;
        
        /**
         * @desc    External function to compute distance between two points
         * @param   p_latitudeA   Latitude of first point
         * @param   p_longitudeA  Longitude of first point
         * @param   p_latitudeB   Latitude of second point
         * @param   p_longitudeB  Longitude of second point
         * @return  Computed distance in meters
         */
        external function fx_computeDistance(
            in Int32 p_latitudeA, in Int32 p_longitudeA, 
            in Int32 p_latitudeB, in Int32 p_longitudeB
        ) return float;
        
        /**
         * @desc    External function to compute a position using a reference position, a distance and an orientation 
         * @param   p_iutLongPosVector  Reference position
         * @param   p_distance          Distance to the reference position (in meter)
         * @param   p_orientation       Direction of the computed position (0 to 359; 0 means North)
         * @param   p_latitude          Computed position's latitude
         * @param   p_longitude         Computed position's longitude
         */        
        external function fx_computePositionUsingDistance(
            in Int32 p_refLatitude, 
            in Int32 p_refLongitude, 
            in float p_distance, 
            in integer p_orientation,
            out Int32 p_latitude,
            out Int32 p_longitude
        );
        
tepelmann's avatar
tepelmann committed
        /**
         * @desc    External function to compute radius of a given circular area
         * @param   p_squareMeters  Square meters of an circular area
         * @return  Computed radius in meters
         */
        external function fx_computeRadiusFromCircularArea(
            in float p_squareMeters
        ) return float;
        
} // end of module