|
RocketLogger
2.0.2
|
#include <ctype.h>#include <errno.h>#include <signal.h>#include <stdarg.h>#include <stdbool.h>#include <stdint.h>#include <stdio.h>#include <string.h>#include <sys/statvfs.h>#include <time.h>#include "log.h"#include "rl.h"#include "util.h"
Include dependency graph for util.c:Go to the source code of this file.
Functions | |
| bool | is_current (int index) |
| bool | is_low_current (int index) |
| bool | is_voltage (int index) |
| int | count_channels (bool const channels[RL_CHANNEL_COUNT]) |
| int | div_ceil (int n, int d) |
| void | create_time_stamp (rl_timestamp_t *const timestamp_realtime, rl_timestamp_t *const timestamp_monotonic) |
| void | get_mac_addr (uint8_t mac_address[MAC_ADDRESS_LENGTH]) |
| int64_t | fs_space_free (char const *const path) |
| int64_t | fs_space_total (char const *const path) |
| bool | is_empty_string (char const *str) |
| bool | is_printable_string (char const *str) |
| void | print_json_bool (bool const *const data, const int length) |
| void | print_json_int64 (int64_t const *const data, const int length) |
| int | snprintfcat (char *const buffer, size_t length, char const *format,...) |
| int count_channels | ( | bool const | channels[RL_CHANNEL_COUNT] | ) |
Counts the number of channels enabled.
| channels | Channel enable array |
Definition at line 72 of file util.c.
References RL_CHANNEL_COUNT.
Referenced by hw_init(), and rl_file_setup_data_lead_in().
| void create_time_stamp | ( | rl_timestamp_t *const | time_realtime, |
| rl_timestamp_t *const | time_monotonic | ||
| ) |
Create time stamps (real-time and monotonic).
| timestamp_realtime | Timestamp data structure to store the time value read from the real-time clock to |
| timestamp_monotonic | Timestamp data structure to store the time value read from the monotonic clock to |
Definition at line 90 of file util.c.
References rl_timestamp::nsec, rl_log(), RL_LOG_ERROR, and rl_timestamp::sec.
Referenced by pru_sample(), rl_file_setup_ambient_lead_in(), and rl_file_setup_data_lead_in().
Here is the call graph for this function:| int div_ceil | ( | int | n, |
| int | d | ||
| ) |
Integer division with ceiling.
| n | Numerator |
| d | Denominator |
Definition at line 82 of file util.c.
Referenced by pru_sample().
| int64_t fs_space_free | ( | char const *const | path | ) |
Get free disk space in a directory in bytes.
| path | Path to selected directory |
Definition at line 125 of file util.c.
References rl_log(), and RL_LOG_WARNING.
Referenced by rl_get_status(), and rl_status_write().
Here is the call graph for this function:| int64_t fs_space_total | ( | char const *const | path | ) |
Get total disk space in a directory in bytes.
| path | Path to selected directory |
Definition at line 137 of file util.c.
References rl_log(), and RL_LOG_WARNING.
Referenced by rl_get_status(), and rl_status_write().
Here is the call graph for this function:| void get_mac_addr | ( | uint8_t | mac_address[MAC_ADDRESS_LENGTH] | ) |
Get MAC address of network device.
| mac_address | Array to write the MAC address to |
Definition at line 112 of file util.c.
References MAC_ADDRESS_FILE, and MAC_ADDRESS_LENGTH.
Referenced by rl_file_setup_ambient_lead_in(), and rl_file_setup_data_lead_in().
| bool is_current | ( | int | index | ) |
Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition at line 49 of file util.c.
References RL_CONFIG_CHANNEL_I1H, RL_CONFIG_CHANNEL_I1L, RL_CONFIG_CHANNEL_I2H, and RL_CONFIG_CHANNEL_I2L.
Referenced by meter_print_buffer(), rl_file_setup_data_channels(), and rl_socket_metadata().
| bool is_empty_string | ( | char const * | str | ) |
| bool is_low_current | ( | int | index | ) |
Checks whether a channel is a low range current channel.
| index | Index of channel in array |
Definition at line 57 of file util.c.
References RL_CONFIG_CHANNEL_I1L, and RL_CONFIG_CHANNEL_I2L.
Referenced by rl_file_setup_data_channels(), and rl_socket_metadata().
| bool is_printable_string | ( | char const * | str | ) |
Check whether a string is printable.
Validates to true if all characters belong to either isspace() or isprint()
| str | The string to validate |
Definition at line 158 of file util.c.
Referenced by rl_config_validate().
| bool is_voltage | ( | int | index | ) |
Checks whether a channel is a voltage channel.
| index | Index of channel in array |
Definition at line 64 of file util.c.
References RL_CONFIG_CHANNEL_V1, RL_CONFIG_CHANNEL_V2, RL_CONFIG_CHANNEL_V3, and RL_CONFIG_CHANNEL_V4.
Referenced by rl_file_setup_data_channels(), and rl_socket_metadata().
| void print_json_bool | ( | bool const *const | data, |
| const int | length | ||
| ) |
| void print_json_int64 | ( | int64_t const *const | data, |
| const int | length | ||
| ) |
| int snprintfcat | ( | char *const | buffer, |
| size_t | length, | ||
| char const * | format, | ||
| ... | |||
| ) |
Append formatted string to setting line with formated string value.
| buffer | The string buffer to append the formatted string to |
| length | Maximum length of the buffer |
| format | Formatting string passed to snprintf() |
| ... | Variables used to format string |
Definition at line 191 of file util.c.
Referenced by rl_config_get_json(), rl_socket_metadata(), and rl_status_get_json().