GPS Device
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1
21
27
28#ifndef COMMON_H_
29#define COMMON_H_
30
31#include <stdint.h>
32#include <stdbool.h>
33
40
47#define BCD_TO_DEC(BCD) (((BCD) >> 4) * 10 + ((BCD) & 0x0F))
48
54#define DEC_TO_BCD(DEC) (((DEC / 10) << 4) | (DEC % 10))
55
65#define DELAY(ms) \
66 do { \
67 uint32_t delay_start_time = systick_get_ms(); \
68 while ((systick_get_ms() - delay_start_time) < (ms)) { \
69 } \
70 } while (0)
71
73
80
84typedef enum {
87
91
95typedef enum {
98
102
106typedef enum {
109
113
115
122
130uint32_t get_str_len(char const *str);
131
143void int_to_str(int num, char *str);
144
156int str_to_int(const char *str);
157
170void double_to_str(double num, char *str, int8_t frac_digits);
171
182void hex_byte_to_str(uint8_t byte, char *str);
183
196void str_set(char *target_str, char const *host_str, uint32_t host_str_len, uint32_t pos);
197
206int32_t get_pow(int32_t base, int32_t exponent);
207
218void arr_cmprs(char *arr, uint8_t len);
219
228bool str_cmp(const char *str1, const char *str2);
229
241uint8_t ascii_hex_to_byte(char high, char low);
242
259int str_tokenize(char *str, const char *separator, uint16_t max_tokens, char **tokens, uint16_t *num_tokens);
260
272bool str_to_bool(char const *str);
273
289int str_cpy(char *str_to, const char *str_from, uint32_t len);
290
304int txt_cpy(char *txt_to, const char *txt_from, uint32_t len);
305
313bool is_pow(uint32_t num);
314
329uint32_t extract_bits(const uint8_t *data, uint16_t start_bit, uint8_t num_bits);
330
332
333#endif
334
bool str_cmp(const char *str1, const char *str2)
Compares two null-terminated strings for equality.
Definition common.c:248
int str_to_int(const char *str)
Converts a decimal string to an integer.
Definition common.c:69
int str_cpy(char *str_to, const char *str_from, uint32_t len)
Copies a null-terminated string into a destination buffer.
Definition common.c:333
uint32_t extract_bits(const uint8_t *data, uint16_t start_bit, uint8_t num_bits)
Extracts a range of bits from a big-endian byte array.
Definition common.c:369
void hex_byte_to_str(uint8_t byte, char *str)
Converts a single byte to a two-character uppercase hexadecimal string.
Definition common.c:175
void str_set(char *target_str, char const *host_str, uint32_t host_str_len, uint32_t pos)
Overwrites a region of a target string with the contents of a source string.
Definition common.c:195
uint8_t ascii_hex_to_byte(char high, char low)
Converts two ASCII hex characters into a single byte value.
Definition common.c:265
uint32_t get_str_len(char const *str)
Returns the length of a string, excluding the null terminator.
Definition common.c:22
void double_to_str(double num, char *str, int8_t frac_digits)
Converts a double to a decimal string with a fixed number of fractional digits.
Definition common.c:102
bool str_to_bool(char const *str)
Converts a string representation of a boolean to a bool value.
Definition common.c:320
bool is_pow(uint32_t num)
Checks whether a number is a power of two.
Definition common.c:364
int str_tokenize(char *str, const char *separator, uint16_t max_tokens, char **tokens, uint16_t *num_tokens)
Splits a string into tokens separated by a given delimiter.
Definition common.c:287
int txt_cpy(char *txt_to, const char *txt_from, uint32_t len)
Copies a fixed-length block of text into a destination buffer.
Definition common.c:350
void int_to_str(int num, char *str)
Converts an integer to its decimal string representation.
Definition common.c:33
int32_t get_pow(int32_t base, int32_t exponent)
Computes an integer power.
Definition common.c:220
void arr_cmprs(char *arr, uint8_t len)
Compresses an array by removing null bytes and shifting remaining elements left.
Definition common.c:231
PIN_STATUS_te
Represents the logical level of a GPIO pin.
Definition common.h:84
VERTICAL_DIR_te
Represents a vertical movement direction.
Definition common.h:106
EN_STATUS_te
Represents an enabled or disabled state.
Definition common.h:95
@ HIGH
Definition common.h:89
@ LOW
Definition common.h:86
@ DOWN
Definition common.h:108
@ UP
Definition common.h:111
@ ENABLE
Definition common.h:100
@ DISABLE
Definition common.h:97