1 /*
2  * Copyright (c) 2023 Trackunit Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_GNSS_GNSS_PARSE_H_
8 #define ZEPHYR_DRIVERS_GNSS_GNSS_PARSE_H_
9 
10 #include <zephyr/types.h>
11 
12 /**
13  * @brief Parse decimal string to nano parts
14  *
15  * @example "-1231.3512" -> -1231351200000
16  *
17  * @param str The decimal string to be parsed
18  * @param nano Destination for parsed decimal
19  *
20  * @retval -EINVAL if str could not be parsed
21  * @retval 0 if str successfully parsed
22  */
23 int gnss_parse_dec_to_nano(const char *str, int64_t *nano);
24 
25 /**
26  * @brief Parse decimal string to micro parts
27  *
28  * @example "-1231.3512" -> -1231351200
29  *
30  * @param str The decimal string to be parsed
31  * @param milli Destination for parsed decimal
32  *
33  * @retval -EINVAL if str could not be parsed
34  * @retval 0 if str successfully parsed
35  */
36 int gnss_parse_dec_to_micro(const char *str, uint64_t *micro);
37 
38 /**
39  * @brief Parse decimal string to milli parts
40  *
41  * @example "-1231.3512" -> -1231351
42  *
43  * @param str The decimal string to be parsed
44  * @param milli Destination for parsed decimal
45  *
46  * @retval -EINVAL if str could not be parsed
47  * @retval 0 if str successfully parsed
48  */
49 int gnss_parse_dec_to_milli(const char *str, int64_t *milli);
50 
51 /**
52  * @brief Parse integer string of configurable base to integer
53  *
54  * @example "-1231" -> -1231
55  *
56  * @param str Decimal string to be parsed
57  * @param base Base of decimal string to be parsed
58  * @param integer Destination for parsed integer
59  *
60  * @retval -EINVAL if str could not be parsed
61  * @retval 0 if str successfully parsed
62  */
63 int gnss_parse_atoi(const char *str, uint8_t base, int32_t *integer);
64 
65 #endif /* ZEPHYR_DRIVERS_GNSS_GNSS_PARSE_H_ */
66