Esempio n. 1
0
        // Interaction Received
        public override void FdAmb_InteractionReceivedHandler(object sender, HlaInteractionEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_InteractionReceivedHandler(sender, data);

            #region User Code
            // Which interaction class?
            if (data.Interaction.ClassHandle == Som.RadioMessageIC.Handle)
            {
                string sentBy = "";
                string msg    = "";
                var    ts     = new DateTime();

                // Get parameter values
                // 1st Method: Check which parameter is updated
                if (data.IsValueUpdated(Som.RadioMessageIC.Callsign))
                {
                    sentBy = data.GetParameterValue <string>(Som.RadioMessageIC.Callsign);
                }
                if (data.IsValueUpdated(Som.RadioMessageIC.Message))
                {
                    msg = data.GetParameterValue <string>(Som.RadioMessageIC.Message);
                }
                if (data.IsValueUpdated(Som.RadioMessageIC.TimeStamp))
                {
                    ts = data.GetParameterValue <DateTime>(Som.RadioMessageIC.TimeStamp);
                }

                // 2nd method: iterate through parameter set
                //foreach (var item in data.Interaction.Parameters)
                //{
                //  if (Som.RadioMessageIC.Callsign.Handle == item.Handle) sentBy = item.GetValue<string>();
                //  else if (Som.RadioMessageIC.Message.Handle == item.Handle) msg = item.GetValue<string>();
                //  else if (Som.RadioMessageIC.TimeStamp.Handle == item.Handle) ts = item.GetValue<DateTime>(); // must match with AddValue() type
                //}
                // TSO message - additional properties
                double timestamp        = data.Time;                                            // timestamp in case of a message sent with a timestamp
                var    handle           = data.SupplementalReceiveInfo.ProducingFederateHandle; // returns the federate handle of the federate, which produces this message
                var    retractionHandle = data.RetractionHandle;                                // returns event retraction handle in acse of a TSO message

                Report($"RadioMessage: From: {sentBy} > {msg} at {ts} with logical timestamp {timestamp}" + Environment.NewLine);
            }
            #endregion //User Code
        }
        // FdAmb_InteractionReceivedHandler
        public override void FdAmb_InteractionReceivedHandler(object sender, HlaInteractionEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_InteractionReceivedHandler(sender, data);

            #region User Code
            string con = data.GetParameterValue <string>(Som.MessageIC.Content);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("RECEIVED>" + con);
            #endregion //User Code
        }
Esempio n. 3
0
        // Interaction Received
        public override void FdAmb_InteractionReceivedHandler(object sender, HlaInteractionEventArgs data)
        {
            // Call the base class handler
            base.FdAmb_InteractionReceivedHandler(sender, data);

            #region User Code
            // Which interaction class?
            if (data.Interaction.ClassHandle == Som.RadioMessageIC.Handle)
            {
                string sentBy = "";
                string msg    = "";
                var    ts     = new DateTime();

                // Get parameter values
                // 1st Method: Check which parameter is updated
                if (data.IsValueUpdated(Som.RadioMessageIC.Callsign))
                {
                    sentBy = data.GetParameterValue <string>(Som.RadioMessageIC.Callsign);
                }
                if (data.IsValueUpdated(Som.RadioMessageIC.Message))
                {
                    msg = data.GetParameterValue <string>(Som.RadioMessageIC.Message);
                }
                if (data.IsValueUpdated(Som.RadioMessageIC.TimeStamp))
                {
                    ts = data.GetParameterValue <DateTime>(Som.RadioMessageIC.TimeStamp);
                }

                // 2nd method: iterate through parameter set
                //foreach (var item in data.Interaction.Parameters)
                //{
                //  if (Som.RadioMessageIC.Callsign.Handle == item.Handle) sentBy = item.GetValue<string>();
                //  else if (Som.RadioMessageIC.Message.Handle == item.Handle) msg = item.GetValue<string>();
                //  else if (Som.RadioMessageIC.TimeStamp.Handle == item.Handle) ts = item.GetValue<DateTime>(); // must match with AddValue() type
                //}
                Report($"RadioMessage: From: {sentBy} > {msg} at {ts}" + Environment.NewLine);
            }
            #endregion //User Code
        }