bladeRF/host/common/include/conversions.h
Jon Szymaniak dce050890d bladeRF-cli: rx/tx now use async interface, libbladeRF: USB dev speed API call
The rx and tx CLI commands now use the asynchronous stream interface to
yield more acceptable performance, and this code has been overhauled for
better readability. Command parameters have been added to allow for
configuration of the stream.

Although a bit overzealous, as "lock it if you use it" approach is taken
here. Optimizations may follow later..

Some rx/tx parameters now support K/M/G suffixes, where relevant.

To support sample rate sanity checks, an API function to check the
current USB speed has been added to libbladeRF. This speed is now
reported in the CLI 'info' command.
2013-10-14 22:42:19 -04:00

119 lines
4.2 KiB
C

/**
* @file conversions.h
*
* @brief Miscellaneous conversion routines
*/
#ifndef CONVERSIONS_H__
#define CONVERSIONS_H__
#include <stdint.h>
#include <libbladeRF.h>
#include "host_config.h"
/**
* Represents an association between a string suffix for a numeric value and
* its multiplier. For example, "k" might correspond to 1000.
*/
typedef struct numeric_suffix {
const char *suffix;
int multiplier;
} numeric_suffix;
/**
* String to integer conversion with range and error checking
*
* @param str String to convert
* @param min Inclusive minimum allowed value
* @param max Inclusive maximum allowed value
* @param ok If non-NULL, this will be set to true to denote that
* the conversion succeeded. If this value is not true,
* then the return value should not be used.
*
* @return 0 on success, undefined on failure
*/
int str2int(const char *str, int min, int max, bool *ok);
/**
* Convert a string to an unsigned inteager with range and error checking
*
* @param[in] str String to conver
* @param[in] min Minimum allowed value (inclusive)
* @param[in] max Maximum allowed value (inclusive)
* @param[out] ok If non-NULL, this is set to true if the conversion was
* successful, and false for an invalid or out of range
* value.
*
* @return Converted value on success, 0 on failure
*/
unsigned int str2uint(const char *str,
unsigned int min, unsigned int max, bool *ok);
/**
* Convert a string to an unsigned 64-bit integer with range and error checking
*
* @param[in] str String to conver
* @param[in] min Minimum allowed value (inclusive)
* @param[in] max Maximum allowed value (inclusive)
* @param[out] ok If non-NULL, this is set to true if the conversion was
* successful, and false for an invalid or out of range
* value.
*
* @return Converted value on success, 0 on failure
*/
uint64_t str2uint64(const char *str, uint64_t min, uint64_t max, bool *ok);
/**
* Convert a string to a double with range and error checking
*
* @param[in] str String to conver
* @param[in] min Minimum allowed value (inclusive)
* @param[in] max Maximum allowed value (inclusive)
* @param[out] ok If non-NULL, this is set to true if the conversion was
* successful, and false for an invalid or out of range
* value.
*
* @return Converted value on success, 0 on failure
*/
double str2double(const char *str, double min, double max, bool *ok);
/**
* Convert a string to an unsigned integer with range and error checking.
* Supports the use of decimal representations and suffixes in the string.
* For example, a string "2.4G" might be converted to 2400000000.
*
* @param[in] str String to convert
* @param[in] min Minimum allowed value (inclusive)
* @param[in] max Maximum allowed value (inclusive)
* @param[in] suffixes List of allowed suffixes and their multipliers
* @param[in] num_suffixes Number of suffixes in the list
* @param[out] ok If non-NULL, this is set to true if the conversion was
* successful, and false for an invalid or out of range
* value.
*
* @return Converted value on success, 0 on failure
*/
unsigned int str2uint_suffix(const char *str, unsigned int min,
unsigned int max, const struct numeric_suffix suffixes[],
int num_suffixes, bool *ok);
/**
* Convert a string to a bladerf_version
*
* Accepted inputs are in the form: X.Y.Z or X.Y.Z-<extra text>
*
* @param[in] string Version string to convert
* @param[out] version Version structure to populate. For a valid string,
* the describe member will point to the provided
* string argument. The contents of this structure
* are undefined when this function returns -1.
*
* @return 0 on success, -1 if provided string is invalid
*/
int str2version(const char *str, struct bladerf_version *version);
/**
* Convert a bladerf_dev_speed to a string suitable for printing
*/
const char * devspeed2str(bladerf_dev_speed speed);
#endif