34 FILE *fp = fopen(fileName.c_str(),
"wb");
39 size_t ret = fwrite(data, 1, size, fp);
46 string cmd =
"mkdir -p \"";
52 }
catch (std::runtime_error &e)
54 printf(
"mkdir error: %s\n", e.what());
58 printf(
"Utils::makeDir %s\n", errStr.c_str());
68 printf(
"CMD To be Run %s \n", cmd.c_str());
70 std::array<char, 128> buffer;
72 std::shared_ptr<FILE> pipe(popen((cmd +
" 2>&1").c_str(),
"r"), pclose);
75 throw std::runtime_error(
string(
"popen() failed for") + cmd);
77 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr)
79 result += buffer.data();
86 vector<uint8_t> extractedBytes;
87 numberOfBytes = numberOfBytes > 8 ? 8 : numberOfBytes;
88 for (uint8_t count = 0; count < numberOfBytes; count++)
90 uint8_t extractByte = (hexData >> ((numberOfBytes - 1 - count) * 8))
92 extractedBytes.push_back(extractByte);
94 return extractedBytes;
99 uint64_t combinedResult = 0;
100 for (uint8_t count = 0; count < byteArray.size(); count++)
102 combinedResult = ((combinedResult << 8) & 0xFFFFFFFFFFFFFF00)
105 return combinedResult;
110 return (value >= range.
m_min && value <= range.
m_max);
117 if (stat(path.c_str(), &info) != 0)
123 returnValue = S_ISDIR(info.st_mode) != 0;
132 if (stat(path.c_str(), &info) != 0)
138 returnValue = S_ISREG(info.st_mode) != 0;
144 std::string
const pattern)
146 if (pattern.empty()) {
150 std::string::const_iterator it = std::search(str.begin(), str.end(),
151 pattern.begin(), pattern.end(),
152 [](
unsigned char ch1,
unsigned char ch2)
153 { return std::toupper(ch1) == std::toupper(ch2);});
154 return (it != str.end());
159 string WHITESPACE =
" \n\r\t\f\v";
161 size_t first = str.find_first_not_of(WHITESPACE);
162 if (first == std::string::npos)
168 size_t last = str.find_last_not_of(WHITESPACE);
169 returnValue = str.substr(first, (last - first + 1));
174void Utils::getFilesInDirectoryRecursive(
const std::string &directoryPath,
175 std::vector<std::string> &fileList)
177 DIR *dir = opendir(directoryPath.c_str());
180 printf(
"Error opening directory: %s\n", directoryPath.c_str());
185 while ((entry = readdir(dir)) !=
nullptr)
187 if (std::string(entry->d_name) !=
"."
188 && std::string(entry->d_name) !=
"..")
190 std::string fullPath = directoryPath +
"/" + entry->d_name;
192 if (entry->d_type == DT_DIR)
194 getFilesInDirectoryRecursive(fullPath, fileList);
198 fileList.push_back(fullPath);
212 getFilesInDirectoryRecursive(path, files);
215 DIR *dir = opendir(path.c_str());
218 printf(
"Error opening directory: %s\n", path.c_str());
222 while ((entry = readdir(dir)) !=
nullptr)
224 if (entry->d_type == DT_REG)
226 files.push_back(entry->d_name);
241 inFile.open(filePath.c_str());
254 if (data.length() > 0)
262 uint16_t decVal = value;
263 uint16_t intVal = value;
264 value = value - intVal;
266 for (int16_t idx = 0; idx < 4; idx++)
272 value = value - intVal;
273 decVal = (decVal << 1) + 1;
277 decVal = decVal << 1;
286 uint16_t fractionValue = 0;
288 fractionValue = value & 0x000F;
291 for (int32_t idx = 3; idx >= 0; idx--)
293 temp += (fractionValue >> idx & 0x1) / twos;
296 returnValue = (decVal + temp);
301 uint16_t decVal = value;
302 uint16_t intVal = value;
303 value = value - intVal;
305 for (int16_t idx = 0; idx < 6; idx++)
311 value = value - intVal;
312 decVal = (decVal << 1) + 1;
316 decVal = decVal << 1;
326 uint16_t fractionValue = 0;
328 fractionValue = value & 0x0003F;
331 for (int32_t idx = 5; idx >= 0; idx--)
333 temp += (fractionValue >> idx & 0x1) / twos;
336 returnValue = (decVal + temp);
342 uint16_t decVal = value;
343 uint16_t intVal = value;
344 value = value - intVal;
346 for (int16_t idx = 0; idx < format; idx++)
352 value = value - intVal;
353 decVal = (decVal << 1) + 1;
357 decVal = decVal << 1;
367 uint16_t fractionValue = 0;
368 decVal = value >> format;
369 fractionValue = value & ((1 << format) - 1);
372 for (int32_t idx = (format - 1); idx >= 0; idx--)
374 temp += (fractionValue >> idx & 0x1) / twos;
377 returnValue = (decVal + temp);
382 uint64_t response = 0;
385 for (uint8_t cnt = 0; cnt < 8; cnt++)
387 uint64_t pushValue = bytes[cnt];
388 response |= pushValue << (8 * cnt);
398 for (uint8_t cnt = 0; cnt < 8; cnt++)
400 uint64_t extractedBytes = (timeInSec >> (8 * cnt));
401 bytes[cnt] = extractedBytes & 0xFF;
static uint16_t convertToUFormat(double value, uint8_t format)
static bool fileExists(const std::string &path)
static bool saveRawFile(string fileName, uint8_t *data, size_t size)
static string makeDir(string path)
static uint64_t mergefrom8Bytes(uint8_t *bytes)
static bool inRange(int64_t value, Range range)
static double convertFrom12p4(uint16_t value)
static void getFilesInDirectory(string path, vector< string > &files, bool recursive=true)
static double convertFromUFormat(uint16_t value, uint8_t format)
static uint16_t convertTo10p6(double value)
static string trim(string str)
static vector< uint8_t > extractBytes(uint64_t hexData, uint8_t numberOfBytes)
static uint64_t combineBytes(vector< uint8_t > byteArray)
static string exec(const string &cmd, bool debug=false)
static bool directoryExists(const std::string &path)
static uint16_t convertToU12p4(double value)
static string readTextFile(string filePath)
static bool caseInsensitiveSearch(std::string const str, std::string const pattern)
static double convertFrom10p6(uint16_t value)
static void extractTo8Bytes(uint64_t timeInSec, uint8_t *bytes)