LibItsCam_Functions.ttcn 10.4 KB
Newer Older
 *    @author     ETSI / STF405
 *    @version    $URL$
 *                $Id$
reinaortega's avatar
reinaortega committed
 *    @desc       Module containing common functions for ITS CAM
module LibItsCam_Functions {
    // LibCommon
    import from LibCommon_Sync all;
    import from LibCommon_VerdictControl all;
    
reinaortega's avatar
reinaortega committed
    import from LibItsCam_TestSystem all;
    import from LibItsCam_Templates all;
    import from LibItsCam_Pixits all;
fischer's avatar
fischer committed
    import from LibItsCam_TypesAndValues all;
    import from LibItsCommon_Functions all;
    import from CAM_PDU_Descriptions language "ASN.1:1997" all;
    import from DENM_PDU_Descriptions language "ASN.1:1997" all;    
reinaortega's avatar
reinaortega committed

    group utFuntions { 
            
        /**
         * @desc    Requests to bring the IUT in an initial state
         * @param   p_init The initialisation to trigger.
         */
        function f_utInitializeIut(template (value) UtInitialize p_init) runs on ItsCam {
            
            utPort.send(p_init);
            tc_wait.start;
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT initialized ***");
                }
                [] utPort.receive {
                    tc_wait.stop;
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized ***");
                    f_selfOrClientSyncAndVerdict("error", e_error);
                }
                [] tc_wait.timeout {
                    log("*** f_utInitializeIut: INFO: IUT could not be initialized in time ***");
                    f_selfOrClientSyncAndVerdict("error", e_timeout);
                }
                [else] { // Shortcut defaults
                    repeat; 
                }
            }
            
        }
        
        /**
         * @desc    Triggers event from the application layer
         * @param   p_event The event to trigger.
         */
        function f_utTriggerEvent(template (value) UtEvent p_event) runs on ItsCam {
            var template (value) UtTrigger v_utMsg := { p_event };
            
            utPort.send(v_utMsg);
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                }
                [] utPort.receive {
                    tc_wait.stop;
                }
                [] tc_wait.timeout {
                }
                [else] { // Shortcut defaults
                    repeat; 
                }
            }
        }
        
        /**
         * @desc Checks that the event was indicated at the application layer
         * @param p_event The event to check.
         * @param   p_discard The event should not appear. Default value: FALSE.
         */
        function f_utCheckEvent(template (value) UtEvent p_event, boolean p_discard) runs on ItsCam {
            var template (value) UtCheck v_utMsg := { p_event };
            
            utPort.send(v_utMsg);
            tc_wait.start;
            alt {
                [] utPort.receive(UtResult:true) {
                    tc_wait.stop;
                    if (p_discard == false) {
                        log("*** f_utCheckEvent: INFO: Event correctly indicated at application layer ***");
                    }
                    else {
                        log("*** f_utCheckEvent: ERROR: Event indicated at application layer where it should be discarded ***");
                        f_selfOrClientSyncAndVerdict("error", e_error);
                    }
                }
                [] utPort.receive(UtResult:false) {
                    tc_wait.stop;
                    if (p_discard == false) {
                        log("*** f_utCheckEvent: ERROR: Event not correctly indicated at application layer ***");
                        f_selfOrClientSyncAndVerdict("error", e_error);
                    }
                    else {
                        log("*** f_utCheckEvent: INFO: Event not indicated at application layer***");
                    }
                }
                [] tc_wait.timeout {
                    log("*** f_utCheckEvent: ERROR: Timeout while waiting for event check result ***");
                    f_selfOrClientSyncAndVerdict("error", e_timeout);                    
                }
                [else] { // Shortcut defaults
                    repeat; 
                }
            }
        }
                    
    } // End of group utFunctions
fischer's avatar
fischer committed

    group camConfigurationFunctions {
        
        /**
         * @desc    Setups default configuration   
         */
reinaortega's avatar
reinaortega committed
        function f_cfUp() runs on ItsCam {
            
            map(self:utPort, system:utPort);
            map(self:camPort, system:camPort);
            f_connect4SelfOrClientSync();
            
        } // end f_cfUp
        
        /**
         * @desc    Deletes default configuration 
         */
reinaortega's avatar
reinaortega committed
        function f_cfDown() runs on ItsCam {
            
            unmap(self:utPort, system:utPort);
            unmap(self:camPort, system:camPort);
            f_disconnect4SelfOrClientSync();
            
        } // end f_cfDown
        
    } // end of camConfigurationFunctions
    
    group defaults {
fischer's avatar
fischer committed
    
        /**
         * @desc    basic default behaviour handling
         */    
reinaortega's avatar
reinaortega committed
        altstep a_default() runs on ItsCam {
fischer's avatar
fischer committed
    
            [] camPort.receive(mw_camInd ( mw_camMsg_any )){ 
                log("*** a_default: INFO: CAM message received in default ***");
berge's avatar
berge committed
                vc_camReceived := true;
                repeat;
            }
            [] camPort.receive {
                log("*** a_default: ERROR: event received on CAM port in default ***");
berge's avatar
berge committed
                f_selfOrClientSyncAndVerdict("error", e_error);
berge's avatar
berge committed
            [] any timer.timeout {
                log("*** a_default: INCONC: a timer expired in default ***"); 
berge's avatar
berge committed
                f_selfOrClientSyncAndVerdict("error", e_timeout);
tepelmann's avatar
tepelmann committed
            [] a_shutdown() {
                f_poDefault();
                f_cfDown();
                log("*** a_default: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***");
                stop;   
            }
        }//end altstep a_basicDefault
         
         
         
    } // end of defaults  
    group preambles {
        /**
         * @desc    Initialize the IUT
         * @remark  No specific actions specified in the base standard
         */    
reinaortega's avatar
reinaortega committed
        function f_prInitialState() runs on ItsCam {
            f_utInitializeIut(m_camInitialize);
			// basic default altstep
			activate(a_default());
            
        } // end f_prInitialState
    } // end of preambles
    group postambles {
tepelmann's avatar
tepelmann committed
         * @desc The default postamble.
         */
reinaortega's avatar
reinaortega committed
        function f_poDefault() runs on ItsCam {
tepelmann's avatar
tepelmann committed
            //empty
        }
    } // end group postambles

    group otherFunctions {
            
        /** @desc   function to generate a random bitstring value 
         *          corresponding to 1 bit position set to 1 (eg '00010000', '01000000', ...)
         *  @see    f_random
berge's avatar
berge committed
         *  @param  p_length bitstring length - max 15
         *  @return bitstring
         *
         */
        function f_bitPositionRandom( in integer p_length )
        return bitstring {
berge's avatar
berge committed
            //Variables            
            var bitstring v_random := '1'B;
            var integer i := 0;
berge's avatar
berge committed
            for(i:=0; i < (p_length - 1); i:=i+1) {
            	v_random := '0'B & v_random;
            }
            v_random := v_random << f_random(0, (p_length - 1));
            log("*** f_bitPositionRandom: INFO: OK - random value = " & bit2str(v_random) & " ***");
            return v_random;
        } // end function f_bitPositionRandom
    } // end group otherFunctions
berge's avatar
berge committed
    group getIutFunctions {
          
berge's avatar
berge committed
         * @desc    Function to get the PT Line Description
         * @see     PX_PTLINE_COURSE, PX_PTLINE_REF, PX_PTLINE_ROUTE
         */
berge's avatar
berge committed
        function f_getIutPtLineDescription()
        return PTLineDescription {
berge's avatar
berge committed

            var PTLineDescription v_ptLineDescription := {"", "", ""};
berge's avatar
berge committed
            v_ptLineDescription := {PX_PTLINE_COURSE, PX_PTLINE_REF, PX_PTLINE_ROUTE}; 

            return v_ptLineDescription ;
berge's avatar
berge committed
        } // end function f_getIutPtLineDescription
    
    } // end getIutFunctions
berge's avatar
berge committed
    group getTesterFunctions {
berge's avatar
berge committed
         * @desc    Gets tester's station characteristics
         * @return  Station characteristics
berge's avatar
berge committed
         * @see     PX_TESTER_IS_MOBILE, PX_TESTER_IS_PRIVATE, PX_TESTER_IS_PHYSICAL_RELEVANT    
berge's avatar
berge committed
        function f_getTesterStationCharacteristics()
        return CoopAwareness.stationCharacteristics {
berge's avatar
berge committed

            var CoopAwareness.stationCharacteristics v_stationCharacteristics := { true, true, true };
berge's avatar
berge committed

berge's avatar
berge committed
            v_stationCharacteristics := {PX_TESTER_IS_MOBILE, PX_TESTER_IS_PRIVATE, PX_TESTER_IS_PHYSICAL_RELEVANT};
            
            return v_stationCharacteristics ;
berge's avatar
berge committed
        } // end f_getTesterStationCharacteristics
berge's avatar
berge committed
        /**
         * @desc    Creates a valid CAM for tester
         */
        function f_getTesterValidCam()
        return template (value) CamPdu {
            
            var CoopAwareness.stationCharacteristics v_stationCharacteristics;
            
            if(PX_TESTER_IS_MOBILE == false) {
                // basic IRS
                v_stationCharacteristics := {false, PX_TESTER_IS_PRIVATE, PX_TESTER_IS_PHYSICAL_RELEVANT};
                return m_camMsg_irs(
                    f_getCurrentTime(),
                    f_getTsStationId(),
                    v_stationCharacteristics,
berge's avatar
berge committed
                );
            }
            else {
                // Vehicle
                v_stationCharacteristics := {true, PX_TESTER_IS_PRIVATE, PX_TESTER_IS_PHYSICAL_RELEVANT};
                return m_camMsg_vehicle(
                    f_getCurrentTime(),
                    f_getTsStationId(),
                    v_stationCharacteristics,
berge's avatar
berge committed
                );
            }
        } // end f_getTesterValidCam
        
berge's avatar
berge committed
    } // end getTesterFunctions
fischer's avatar
fischer committed

} // end LibItsCam_Functions