OpenHantek
printutils.h File Reference
#include <cerrno>
#include <QString>
#include <QTime>

Go to the source code of this file.

Macros

#define timestampDebug(ARG)
 Print debug information with timestamp. More...
 

Enumerations

enum  Unit {
  UNIT_VOLTS, UNIT_DECIBEL, UNIT_SECONDS, UNIT_HERTZ,
  UNIT_SAMPLES, UNIT_COUNT
}
 The various units supported by valueToString. More...
 

Functions

QString valueToString (double value, Unit unit, int precision=-1)
 Converts double to string containing value and (prefix+)unit (Counterpart to stringToValue). More...
 
double stringToValue (const QString &text, Unit unit, bool *ok=nullptr)
 Converts string containing value and (prefix+)unit to double (Counterpart to valueToString). More...
 
QString hexDump (unsigned char *data, unsigned int length)
 Returns the hex dump for the given data. More...
 
unsigned int hexParse (const QString dump, unsigned char *data, unsigned int length)
 Returns the hex dump for the given data. More...
 

Macro Definition Documentation

◆ timestampDebug

#define timestampDebug (   ARG)

Print debug information with timestamp.

Parameters
textText that will be output via qDebug.

Enumeration Type Documentation

◆ Unit

enum Unit

The various units supported by valueToString.

utils/printutils.h

Enumerator
UNIT_VOLTS 
UNIT_DECIBEL 
UNIT_SECONDS 
UNIT_HERTZ 
UNIT_SAMPLES 
UNIT_COUNT 

Function Documentation

◆ hexDump()

QString hexDump ( unsigned char *  data,
unsigned int  length 
)

Returns the hex dump for the given data.

Parameters
dataPointer to the data bytes that should be dumped.
lengthThe length of the data array in bytes.
Returns
String with the hex dump of the data.

◆ hexParse()

unsigned int hexParse ( const QString  dump,
unsigned char *  data,
unsigned int  length 
)

Returns the hex dump for the given data.

Parameters
dumpThe string with the hex dump of the data.
dataPointer to the address where the data bytes should be saved.
lengthThe maximum length of the data array in bytes.
Returns
The length of the saved data.

◆ stringToValue()

double stringToValue ( const QString &  text,
Unit  unit,
bool *  ok = nullptr 
)

Converts string containing value and (prefix+)unit to double (Counterpart to valueToString).

Parameters
textThe text containing the value and its unit.
unitThe base unit of the value.
okPointer to a success-flag, true on success, false on error.
Returns
Decoded value.

◆ valueToString()

QString valueToString ( double  value,
Unit  unit,
int  precision = -1 
)

Converts double to string containing value and (prefix+)unit (Counterpart to stringToValue).

Parameters
valueThe value in prefixless units.
unitThe unit for the value.
precisionSignificant digits, 0 for integer, -1 for auto.
Returns
String with the value and unit.