RocketLogger 2.1.1
util.c File Reference
#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,...)
 

Function Documentation

◆ count_channels()

int count_channels ( bool const  channels[RL_CHANNEL_COUNT])

Counts the number of channels enabled.

Parameters
channelsChannel enable array
Returns
The number of enabled channels

Definition at line 72 of file util.c.

References RL_CHANNEL_COUNT.

Referenced by hw_init(), and rl_file_setup_data_lead_in().

◆ create_time_stamp()

void create_time_stamp ( rl_timestamp_t *const  time_realtime,
rl_timestamp_t *const  time_monotonic 
)

Create time stamps (real-time and monotonic).

Parameters
timestamp_realtimeTimestamp data structure to store the time value read from the real-time clock to
timestamp_monotonicTimestamp 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:

◆ div_ceil()

int div_ceil ( int  n,
int  d 
)

Integer division with ceiling.

Parameters
nNumerator
dDenominator
Returns
Division result rounded up to next integer

Definition at line 82 of file util.c.

Referenced by pru_sample().

◆ fs_space_free()

int64_t fs_space_free ( char const *const  path)

Get free disk space in a directory in bytes.

Parameters
pathPath to selected directory
Returns
Free disk space in bytes

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:

◆ fs_space_total()

int64_t fs_space_total ( char const *const  path)

Get total disk space in a directory in bytes.

Parameters
pathPath to selected directory
Returns
Total disk space in bytes

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:

◆ get_mac_addr()

void get_mac_addr ( uint8_t  mac_address[MAC_ADDRESS_LENGTH])

Get MAC address of network device.

Parameters
mac_addressArray 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().

◆ is_current()

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:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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().

◆ is_empty_string()

bool is_empty_string ( char const *  str)

Check whether a string is empty, i.e. does not contain visible characters.

Validates to true if none of the characters belongs to either isgraph()

Parameters
strThe string to validate
Returns
True if string is empty, false otherwise

Definition at line 149 of file util.c.

◆ is_low_current()

bool is_low_current ( int  index)

Checks whether a channel is a low range current channel.

Parameters
indexIndex of channel in array
Returns
Returns true if channel is a low range current, false otherwise

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().

◆ is_printable_string()

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()

Parameters
strThe string to validate
Returns
True if string is printable, false otherwise

Definition at line 158 of file util.c.

Referenced by rl_config_validate().

◆ is_voltage()

bool is_voltage ( int  index)

Checks whether a channel is a voltage channel.

Parameters
indexIndex of channel in array
Returns
Returns true if channel is a voltage, false otherwise

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().

◆ print_json_bool()

void print_json_bool ( bool const *const  data,
const int  length 
)

Print a boolean array in JSON format.

Parameters
dataData array to print
lengthLength of array

Definition at line 169 of file util.c.

References data.

◆ print_json_int64()

void print_json_int64 ( int64_t const *const  data,
const int  length 
)

Print a 64-bit integer array in JSON format.

Parameters
dataData array to print
lengthLength of array

Definition at line 180 of file util.c.

References data.

◆ snprintfcat()

int snprintfcat ( char *const  buffer,
size_t  length,
char const *  format,
  ... 
)

Append formatted string to setting line with formated string value.

Parameters
bufferThe string buffer to append the formatted string to
lengthMaximum length of the buffer
formatFormatting 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().