1 /* 2 * Copyright (c) 2018-2019 Foundries.io 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef LWM2M_UTIL_H_ 8 #define LWM2M_UTIL_H_ 9 10 #include <zephyr/net/lwm2m.h> 11 12 /* convert float to binary format */ 13 int lwm2m_float_to_b32(double *in, uint8_t *b32, size_t len); 14 int lwm2m_float_to_b64(double *in, uint8_t *b64, size_t len); 15 16 /* convert binary format to float */ 17 int lwm2m_b32_to_float(uint8_t *b32, size_t len, double *out); 18 int lwm2m_b64_to_float(uint8_t *b64, size_t len, double *out); 19 20 /* convert string to float */ 21 int lwm2m_atof(const char *input, double *out); 22 /* convert float to string */ 23 int lwm2m_ftoa(double *input, char *out, size_t outlen, int8_t dec_limit); 24 25 uint16_t lwm2m_atou16(const uint8_t *buf, uint16_t buflen, uint16_t *len); 26 27 int lwm2m_string_to_path(const char *pathstr, struct lwm2m_obj_path *path, char delim); 28 29 bool lwm2m_obj_path_equal(const struct lwm2m_obj_path *a, const struct lwm2m_obj_path *b); 30 31 /** 32 * @brief Used for debugging to print ip addresses. 33 * 34 * @param addr sockaddr for socket using ipv4 or ipv6 35 * @return ip address in readable form 36 */ 37 char *lwm2m_sprint_ip_addr(const struct sockaddr *addr); 38 39 /** 40 * @brief Converts the token to a printable format. 41 * 42 * @param[in] token Token to be printed 43 * @param[in] tkl Lengths of token 44 * @return char buffer with the string representation of the token 45 */ 46 char *sprint_token(const uint8_t *token, uint8_t tkl); 47 48 #endif /* LWM2M_UTIL_H_ */ 49