コード例 #1
0
ファイル: Vehicle.Functions.cs プロジェクト: cowzon90/GCS
        /// <summary>
        /// Set Parameter Async
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <bool> SetParameterAsync(string id, float value)
        {
            VehicleParameter pa;

            if (!this.Parameters.TryGetValue(id, out pa))
            {
                return(false);
            }

            byte[]            ids = VehicleParameter.ConvertTo16Bytes(id);
            Message_PARAM_SET m   = new Message_PARAM_SET(value, (byte)this.SystemId, (byte)this.ComponentId, ids, pa.Type);

            float oldValue = pa.Value;

            this.SendMessage(m);

            bool result = false;
            //Debug.WriteLine($"run checker");
            var checker = Task.Run(() =>
            {
                DateTime timeout = DateTime.Now.AddMilliseconds(1.5 * 1000);

                while (true)
                {
                    if (timeout < DateTime.Now)
                    {
                        //Debug.WriteLine("Checker out with timeout");
                        result = false;
                        return;
                    }

                    if (this.Parameters[id].Value == value)
                    {
                        //Debug.WriteLine("Cheker out with same value.");
                        result = true;
                        return;
                    }
                }
            });

            //Debug.WriteLine($"wait checker");
            checker.Wait();
            //Debug.WriteLine($"get checker");
            return(result);
        }
コード例 #2
0
ファイル: VehicleParameter.cs プロジェクト: cowzon90/GCS
        /// <summary>
        /// Parameter Message to Parameter instance.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static VehicleParameter ConvertToParameter(Message_PARAM_VALUE message)
        {
            if (!message.IsValid)
            {
                return(null);
            }

            try
            {
                VehicleParameter temp = new VehicleParameter();
                temp.Id    = message.param_id;
                temp.Index = message.param_index;
                temp.Type  = message.param_type;
                temp.Value = message.param_value;
                return(temp);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #3
0
        private void Receive_Param_Value(Message message)
        {
            try
            {
                var param_value = (Message_PARAM_VALUE)message;
                this.ParameterCount = param_value.param_count;

                VehicleParameter parameter = VehicleParameter.ConvertToParameter(param_value);

                if (parameter.Index >= this.ParameterCount)
                {
                    /// for when known parameter has index over total parameter count.
                    if (this.Parameters.ContainsKey(parameter.StringId))
                    {
                        this.Parameters[parameter.StringId].Value = parameter.Value;
                        return;
                    }

                    if (this.unknown.ContainsKey(parameter.StringId))
                    {
                        this.unknown[parameter.StringId].Value = parameter.Value;
                        return;
                    }
                    this.unknown[parameter.StringId] = parameter;
                    return;
                }

                if (this.Parameters.ContainsKey(parameter.StringId))
                {
                    this.Parameters[parameter.StringId].Value = parameter.Value;
                    return;
                }

                this.Parameters.Add(parameter.StringId, parameter);
            }
            catch (Exception e)
            {
                throw;
            }
        }