Ejemplo n.º 1
0
        public static ParamValueDTO createParamValueDTO(ParamValue source)
        {
            if (null == source)
            {
                return(null);
            }
            ParamValueDTO result = new ParamValueDTO();

            // lookup static metadata about result parameter
            ParameterMetadata      metadataLookup = new ParameterMetadata();
            ParameterMetadataEntry data           = metadataLookup.fetchMetadata(source.param_id);

            if (null != data)
            {
                result.DisplayName = data.DisplayName;
                result.Description = data.Description;
                result.Units       = data.Units;
                result.Upper       = data.Upper;
                result.Lower       = data.Lower;
            }
            result.param_type  = source.param_type.ToString();
            result.param_value = source.param_value;
            result.param_index = source.param_index;
            result.param_id    = source.param_id;
            result.param_count = source.param_count;

            return(result);
        }
Ejemplo n.º 2
0
        public IHttpActionResult putParameters(string id, [FromBody] ParametersDTO values)
        {
            logger.Debug("setting parameters for /drones/{0}", id);
            Drone target = droneMgr.getById(new Guid(id));

            if (null != target)
            {
                if (!target.isConnected())
                {
                    return(BadRequest("Target system is not connected, refusing request"));
                }
                Boolean result = true;
                foreach (String key in values.parameters.Keys)
                {
                    ParamValueDTO parameter          = values.parameters[key];
                    bool          parameterSetResult = target.setParameter(parameter.param_id, parameter.param_value, (MAVLink.MAV_PARAM_TYPE)Enum.Parse(typeof(MAVLink.MAV_PARAM_TYPE), parameter.param_type));
                    result = result && parameterSetResult;
                }
                Dictionary <String, ParamValue> parameters = target.Parameters;
                if ((null != parameters) && (result))
                {
                    return(Ok(DTOFactory.DTOFactory.createParametersDTO(parameters)));
                }
                else
                {
                    return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.RequestTimeout)));
                }
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 3
0
        public void CheckParameterValueObject()
        {
            MAVLink.mavlink_param_value_t data = new MAVLink.mavlink_param_value_t();
            data.param_count = 1;
            data.param_id    = Encoding.ASCII.GetBytes("foo");
            data.param_index = 3;
            data.param_type  = 4;
            data.param_value = 5;

            MavLinkMessage message = createSampleMessage(MAVLink.MAVLINK_MSG_ID.PARAM_VALUE, data);

            ParamValue obj = new ParamValue(message);

            Assert.AreEqual(obj.param_count, data.param_count);
            Assert.AreEqual(Encoding.ASCII.GetBytes(obj.param_id)[0], data.param_id[0]);
            Assert.AreEqual(obj.param_index, data.param_index);
            Assert.AreEqual((int)obj.param_type, data.param_type);
            Assert.AreEqual(obj.param_value, data.param_value);

            ParamValueDTO dto = DTOFactory.createParamValueDTO(obj);

            Assert.AreEqual(dto.param_count, obj.param_count);
            Assert.AreEqual(dto.param_id, obj.param_id);
            Assert.AreEqual(dto.param_index, obj.param_index);
            Assert.AreEqual(dto.param_type, obj.param_type.ToString());
            Assert.AreEqual(dto.param_value, obj.param_value);
        }