Commit 875c75c4 authored by Robert Lubos's avatar Robert Lubos Committed by Christopher Friedt
Browse files

net: lwm2m: Replace float32_value_t with double



Replace the custom float32_value_t LwM2M type with native double, to
facilitate LwM2M API and improve floating point precission.

Signed-off-by: default avatarRobert Lubos <robert.lubos@nordicsemi.no>
parent 3a3e3c04
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ Changes in this release
  * :c:func:`uart_tx`
  * :c:func:`uart_rx_enable`

* Replaced custom LwM2M :c:struct:`float32_value` type with a native double type.

==========================

Removed APIs in this release
+6 −27
Original line number Diff line number Diff line
@@ -357,27 +357,6 @@ struct coap_block_context *lwm2m_firmware_get_block_context();
#endif
#endif

/**
 * @brief Data structure used to represent the LwM2M float type:
 * val1 is the whole number portion of the decimal
 * val2 is the decimal portion *1000000 for 32bit, *1000000000 for 64bit
 * Example: 123.456 == val1: 123, val2:456000
 * Example: 123.000456 = val1: 123, val2:456
 */

/**
 * @brief Maximum precision value for 32-bit LwM2M float val2
 */
#define LWM2M_FLOAT32_DEC_MAX 1000000

/**
 * @brief 32-bit variant of the LwM2M float structure
 */
typedef struct float32_value {
	int32_t val1;
	int32_t val2;
} float32_value_t;

/**
 * @brief Maximum value for ObjLnk resource fields
 */
@@ -557,14 +536,14 @@ int lwm2m_engine_set_s64(char *pathstr, int64_t value);
int lwm2m_engine_set_bool(char *pathstr, bool value);

/**
 * @brief Set resource (instance) value (32-bit float structure)
 * @brief Set resource (instance) value (double)
 *
 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)"
 * @param[in] value 32-bit float value
 * @param[in] value double value
 *
 * @return 0 for success or negative in case of error.
 */
int lwm2m_engine_set_float32(char *pathstr, float32_value_t *value);
int lwm2m_engine_set_float(char *pathstr, double *value);

/**
 * @brief Set resource (instance) value (ObjLnk)
@@ -689,14 +668,14 @@ int lwm2m_engine_get_s64(char *pathstr, int64_t *value);
int lwm2m_engine_get_bool(char *pathstr, bool *value);

/**
 * @brief Get resource (instance) value (32-bit float structure)
 * @brief Get resource (instance) value (double)
 *
 * @param[in] pathstr LwM2M path string "obj/obj-inst/res(/res-inst)"
 * @param[out] buf 32-bit float buffer to copy data into
 * @param[out] buf double buffer to copy data into
 *
 * @return 0 for success or negative in case of error.
 */
int lwm2m_engine_get_float32(char *pathstr, float32_value_t *buf);
int lwm2m_engine_get_float(char *pathstr, double *buf);

/**
 * @brief Get resource (instance) value (ObjLnk)
+1 −0
Original line number Diff line number Diff line
CONFIG_FPU=y
+9 −5
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ static void *temperature_get_buf(uint16_t obj_inst_id, uint16_t res_id,
				 uint16_t res_inst_id, size_t *data_len)
{
	/* Last read temperature value, will use 25.5C if no sensor available */
	static struct float32_value v = { 25, 500000 };
	static double v = 25.5;
	const struct device *dev = NULL;

#if defined(CONFIG_FXOS8700_TEMP)
@@ -198,17 +198,21 @@ static void *temperature_get_buf(uint16_t obj_inst_id, uint16_t res_id,
#endif

	if (dev != NULL) {
		struct sensor_value val;

		if (sensor_sample_fetch(dev)) {
			LOG_ERR("temperature data update failed");
		}

		sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP,
				  (struct sensor_value *) &v);
		LOG_DBG("LWM2M temperature set to %d.%d", v.val1, v.val2);
		sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP, &val);

		v = sensor_value_to_double(&val);

		LOG_DBG("LWM2M temperature set to %f", v);
	}

	/* echo the value back through the engine to update min/max values */
	lwm2m_engine_set_float32("3303/0/5700", &v);
	lwm2m_engine_set_float("3303/0/5700", &v);
	*data_len = sizeof(v);
	return &v;
}
+5 −5
Original line number Diff line number Diff line
@@ -42,11 +42,11 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

/* resource state */
struct ipso_accel_data {
	float32_value_t x_value;
	float32_value_t y_value;
	float32_value_t z_value;
	float32_value_t min_range;
	float32_value_t max_range;
	double x_value;
	double y_value;
	double z_value;
	double min_range;
	double max_range;
};

static struct ipso_accel_data accel_data[MAX_INSTANCE_COUNT];
Loading