|
GPS Device
|
Public utility functions available to all modules. More...

Functions | |
| uint32_t | get_str_len (char const *str) |
| Returns the length of a string, excluding the null terminator. | |
| void | int_to_str (int num, char *str) |
| Converts an integer to its decimal string representation. | |
| int | str_to_int (const char *str) |
| Converts a decimal string to an integer. | |
| 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. | |
| void | hex_byte_to_str (uint8_t byte, char *str) |
| Converts a single byte to a two-character uppercase hexadecimal string. | |
| 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. | |
| int32_t | get_pow (int32_t base, int32_t exponent) |
| Computes an integer power. | |
| void | arr_cmprs (char *arr, uint8_t len) |
| Compresses an array by removing null bytes and shifting remaining elements left. | |
| bool | str_cmp (const char *str1, const char *str2) |
| Compares two null-terminated strings for equality. | |
| uint8_t | ascii_hex_to_byte (char high, char low) |
| Converts two ASCII hex characters into a single byte value. | |
| 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. | |
| bool | str_to_bool (char const *str) |
| Converts a string representation of a boolean to a bool value. | |
| int | str_cpy (char *str_to, const char *str_from, uint32_t len) |
| Copies a null-terminated string into a destination buffer. | |
| int | txt_cpy (char *txt_to, const char *txt_from, uint32_t len) |
| Copies a fixed-length block of text into a destination buffer. | |
| bool | is_pow (uint32_t num) |
| Checks whether a number is a power of two. | |
| 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. | |
Public utility functions available to all modules.
| uint32_t get_str_len | ( | char const * | str | ) |
Returns the length of a string, excluding the null terminator.
| [in] | str | Pointer to a null-terminated string. |
Definition at line 22 of file common.c.

| void int_to_str | ( | int | num, |
| char * | str ) |
Converts an integer to its decimal string representation.
Handles negative values. The result is written into str, which must be large enough to hold the digits, an optional leading '-', and the null terminator.
| [in] | num | The integer to convert. |
| [out] | str | Pointer to the destination buffer. |
Definition at line 33 of file common.c.

| int str_to_int | ( | const char * | str | ) |
Converts a decimal string to an integer.
Handles an optional leading '-' for negative values. Non-digit characters after the sign are not validated.
| [in] | str | Pointer to a null-terminated decimal string. |
Definition at line 69 of file common.c.

| 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.
Handles negative values, including values in the range (-1, 0). Leading zeros in the fractional part are preserved.
| [in] | num | The double value to convert. |
| [out] | str | Pointer to the destination buffer. Must be large enough for the integer part, '.', fractional digits, and null terminator. |
| [in] | frac_digits | Number of digits to include after the decimal point. |
Definition at line 102 of file common.c.


| void hex_byte_to_str | ( | uint8_t | byte, |
| char * | str ) |
Converts a single byte to a two-character uppercase hexadecimal string.
Does not append a null terminator. The caller must ensure str points to a buffer of at least 2 bytes.
| [in] | byte | The byte to convert. |
| [out] | str | Pointer to a buffer that will receive the two hex characters. |
Definition at line 175 of file common.c.
| 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.
Copies host_str_len characters from host_str into target_str starting at byte offset pos. No null terminator is written.
| [in,out] | target_str | Pointer to the string to modify. |
| [in] | host_str | Pointer to the source string. |
| [in] | host_str_len | Number of characters to copy from host_str. |
| [in] | pos | Byte offset in target_str at which to begin writing. |
Definition at line 195 of file common.c.

| int32_t get_pow | ( | int32_t | base, |
| int32_t | exponent ) |
Computes an integer power.
| [in] | base | The base value. |
| [in] | exponent | The exponent value. Must be non-negative. |
base raised to the power of exponent.Definition at line 220 of file common.c.

| void arr_cmprs | ( | char * | arr, |
| uint8_t | len ) |
Compresses an array by removing null bytes and shifting remaining elements left.
All non-null characters are packed to the front of the array. Trailing positions are filled with null bytes.
| [in,out] | arr | Pointer to the character array to compress. |
| [in] | len | Total length of the array in bytes. |
Definition at line 231 of file common.c.

| bool str_cmp | ( | const char * | str1, |
| const char * | str2 ) |
Compares two null-terminated strings for equality.
| [in] | str1 | Pointer to the first string. |
| [in] | str2 | Pointer to the second string. |
Definition at line 248 of file common.c.

| uint8_t ascii_hex_to_byte | ( | char | high, |
| char | low ) |
Converts two ASCII hex characters into a single byte value.
Accepts uppercase hex digits (0–9, A–F). Lowercase is not handled.
| [in] | high | The most significant nibble as an ASCII character (e.g. 'A'). |
| [in] | low | The least significant nibble as an ASCII character (e.g. 'F'). |
Definition at line 265 of file common.c.

| 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.
Modifies str in place by replacing delimiter characters with null bytes. Leading spaces before each token are skipped. Pointers to the start of each token are stored in tokens.
| [in,out] | str | Pointer to the null-terminated input string. Modified in place. |
| [in] | separator | Null-terminated string containing the delimiter character(s). |
| [in] | max_tokens | Maximum number of tokens to extract. |
| [out] | tokens | Array of pointers that will be set to the start of each token. |
| [out] | num_tokens | Pointer to a variable that will receive the number of tokens found. |
Definition at line 287 of file common.c.

| bool str_to_bool | ( | char const * | str | ) |
Converts a string representation of a boolean to a bool value.
Recognizes the strings "true" and "false" (case-sensitive). Any other input returns false.
| [in] | str | Pointer to a null-terminated string. |
str equals "true", false otherwise.Definition at line 320 of file common.c.

| int str_cpy | ( | char * | str_to, |
| const char * | str_from, | ||
| uint32_t | len ) |
Copies a null-terminated string into a destination buffer.
Copies at most len - 1 characters from str_from into str_to and always null-terminates the result. Stops early if the source string ends before len - 1 characters are copied.
| [out] | str_to | Pointer to the destination buffer. |
| [in] | str_from | Pointer to the null-terminated source string. |
| [in] | len | Total size of the destination buffer in bytes, including space for the null terminator. |
len is 0.Definition at line 333 of file common.c.

| int txt_cpy | ( | char * | txt_to, |
| const char * | txt_from, | ||
| uint32_t | len ) |
Copies a fixed-length block of text into a destination buffer.
Unlike str_cpy, this function copies exactly len bytes and does not append a null terminator. It stops early if the source ends.
| [out] | txt_to | Pointer to the destination buffer. |
| [in] | txt_from | Pointer to the source text. |
| [in] | len | Number of bytes to copy. |
len is 0.Definition at line 350 of file common.c.

| bool is_pow | ( | uint32_t | num | ) |
| 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.
Bit numbering follows big-endian convention: bit 0 of the array is the most significant bit of the first byte. Extracted bits are assembled into the result with the first extracted bit as the MSB.
| [in] | data | Pointer to the byte array to extract from. |
| [in] | start_bit | Index of the first bit to extract (0 = MSB of data[0]). |
| [in] | num_bits | Number of consecutive bits to extract. |
Definition at line 369 of file common.c.
