15#include "uhal/ValMem.hpp"
18#include "boost/foreach.hpp"
19#include <boost/filesystem/operations.hpp>
20#include <boost/filesystem/path.hpp>
45 std::map<string, uhal::ValWord<uint32_t>> value_words;
47 for (
string n : node.getNodes()) {
48 value_words.insert(make_pair(n, node.getNode(n).read()));
50 node.getClient().dispatch();
53 std::map<string, uhal::ValWord<uint32_t>>::iterator it;
54 for (it = value_words.begin(); it != value_words.end(); ++it)
55 vals.insert(make_pair(it->first, it->second.value()));
63snapshot(
const uhal::Node& node,
const std::string& regex)
65 std::map<string, uhal::ValWord<uint32_t>> value_words;
67 for (
string n : node.getNodes(regex)) {
68 value_words.insert(make_pair(n, node.getNode(n).read()));
70 node.getClient().dispatch();
73 std::map<string, uhal::ValWord<uint32_t>>::iterator it;
74 for (it = value_words.begin(); it != value_words.end(); ++it)
75 vals.insert(make_pair(it->first, it->second.value()));
87 double time_in_seconds(time_in_milliseconds / 1e3);
88 int integer_part(
static_cast<int>(time_in_seconds));
89 double fractional_part(time_in_seconds -
static_cast<double>(integer_part));
90 struct timespec sleep_time, return_time;
91 sleep_time.tv_sec = integer_part;
92 sleep_time.tv_nsec =
static_cast<long>(fractional_part * 1e9);
93 nanosleep(&sleep_time, &return_time);
104 vasprintf(&ret, fmt, ap);
106 std::string str(ret);
113std::vector<std::string>
117 std::vector<std::string> paths;
118 wordexp_t substituted_path;
119 int code = wordexp(path.c_str(), &substituted_path, WRDE_NOCMD);
121 throw runtime_error(
"Failed expanding path: " + path);
123 for (std::size_t i = 0; i != substituted_path.we_wordc; i++)
124 paths.push_back(substituted_path.we_wordv[i]);
126 wordfree(&substituted_path);
138 if (paths.size() > 1)
139 throw runtime_error(
"Failed to expand: multiple matches found");
151 namespace fs = boost::filesystem;
154 fs::path cfgFile(path);
155 if (!fs::exists(cfgFile)) {
157 }
else if (fs::is_directory(cfgFile)) {
158 throw FileIsDirectory(
ERS_HERE, path);
167dec_rng(uint8_t word, uint8_t ibit, uint8_t nbits)
169 return (word >> ibit) & ((1 << nbits) - 1);
177 return (uint64_t)raw_timestamp[0] + ((uint64_t)raw_timestamp[1] << 32);
186 const auto now = std::chrono::system_clock::now();
189 const auto epoch =
now.time_since_epoch();
192 const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(epoch);
195 return seconds.count();
204 const auto now = std::chrono::system_clock::now();
207 const auto epoch =
now.time_since_epoch();
210 const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
213 return milliseconds.count();
221 std::time_t sec_from_epoch = raw_timestamp / clock_frequency_hz;
223 struct tm* time = localtime(&sec_from_epoch);
224 char time_buffer[32];
226 strftime(time_buffer,
sizeof time_buffer,
"%a, %d %b %Y %H:%M:%S +0000", time);
235 uint64_t timestamp =
tstamp2int(raw_timestamp);
244 uint32_t mantissa_shift = is_double_precision ? 52 : 23;
245 uint64_t exponent_mask = is_double_precision ? 0x7FF0000000000000 : 0x7f800000;
246 uint32_t bias = is_double_precision ? 1023 : 127;
247 uint32_t sign_shift = is_double_precision ? 63 : 31;
249 int32_t sign = (bits >> sign_shift) & 0x01;
250 uint32_t exponent_biased = ((bits & exponent_mask) >> mantissa_shift);
251 int32_t exponent = exponent_biased - bias;
254 double mantissa = 0.0;
255 for (uint32_t i = 0; i < mantissa_shift; ++i) {
256 uint64_t mantissa_bit = (bits >> (mantissa_shift - i - 1)) & 0x01;
257 mantissa += mantissa_bit * pow(2.0, power);
261 if (exponent_biased == 0) {
268 return (sign ? -1 : 1) * pow(2.0, exponent) * mantissa;
280 return static_cast<BoardType>(board_type);
318locate(
float xx[],
unsigned long n,
float x)
320 uint32_t j, ju, jm, jl;
324 ascnd = (xx[n] >= xx[1]);
330 if ((x >= xx[jm]) == ascnd)
340 }
else if (x == xx[n]) {
354 int major_firmware_version = (firmware_version >> 16) & 0xff;
355 int minor_firmware_version = (firmware_version >> 8) & 0xff;
356 int patch_firmware_version = (firmware_version >> 0) & 0xff;
358 std::stringstream firmware_version_stream;
359 firmware_version_stream <<
"v" << major_firmware_version <<
"." << minor_firmware_version <<
"." << patch_firmware_version;
360 return firmware_version_stream.str();
int64_t get_seconds_since_epoch()
CarrierType convert_value_to_carrier_type(uint32_t darrier_type)
int64_t get_milliseconds_since_epoch()
std::string format_firmware_version(uint32_t firmware_version)
BoardType convert_value_to_board_type(uint32_t Board_type)
std::string vec_fmt(const std::vector< T > &vec)
std::string format_timestamp(uhal::ValVector< uint32_t > raw_timestamp, uint32_t clock_frequency_hz)
std::string strprintf(const char *fmt,...)
double convert_bits_to_float(uint64_t bits, bool is_double_precision=false)
std::vector< std::string > shell_expand_paths(const std::string &path)
DesignType convert_value_to_design_type(uint32_t design_type)
uint64_t tstamp2int(uhal::ValVector< uint32_t > raw_timestamp)
uint8_t dec_rng(uint8_t word, uint8_t ibit, uint8_t nbits=1)
uint32_t locate(float xx[], unsigned long n, float x)
std::map< std::string, uint32_t > Snapshot
std::string shellExpandPath(const std::string &path)
void throw_if_not_file(const std::string &path)
std::string short_vec_fmt(const std::vector< T > &vec)
std::string format_reg_value(T reg_value, uint32_t base)
void millisleep(const double &time_in_milliseconds)
Snapshot snapshot(const uhal::Node &node)
Walk & read the node structure.