2 Copyright 2020 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
35 struct timespec delayTime;
36 delayTime.tv_sec = a / 1000;
37 delayTime.tv_nsec = (a % 1000) * 1000000;
38 nanosleep(&delayTime, NULL);
44 std::string tp2str(const std::chrono::time_point<std::chrono::system_clock>& tp)
46 auto tms = std::chrono::time_point_cast<std::chrono::milliseconds>(tp);
47 std::chrono::milliseconds e = tms.time_since_epoch();
48 long long c = e.count();
49 time_t tt = static_cast<long>(c / 1000); // when are we going longlong for time_t ?
50 int ttm = toi4(c % 1000);
51 auto stm = std::localtime(&tt);
53 ss << std::put_time(stm, "%T") << "." << std::setfill('0') << std::setw(3) << ttm;
57 void dump(void* vdata, int remaining)
59 u1* data = reinterpret_cast<u1*>(vdata);
60 int pos{}, ntp, spaces;
61 std::stringstream ascii;
65 ascii.str(std::string());
67 if (ntp > remaining) ntp = remaining;
68 std::cout << " " << std::hex << std::setfill('0');
69 for (int i = 0; i < ntp; i++)
71 std::cout << std::setw(2) << int(data[pos + i]) << " " << (i == 7 ? " " : "");
72 if (std::isspace(data[pos + i])) ascii << " ";
73 else if (std::isprint(data[pos + i])) ascii << data[pos + i];
76 spaces = (16 - ntp) * 3 + 3;
77 if (ntp < 8) spaces += 2;
78 std::cout << std::setfill(' ') << std::setw(spaces) << "" << ascii.str() << std::endl;
82 std::cout << std::endl << std::endl;
88 return (((u8)htonl((u4)((a<<32)>> 32))<<32)
89 |(u4)htonl(((u4) (a >> 32))));
99 #if BYTE_ORDER == BIG_ENDIAN
104 b = ((a << 56) & 0xFF00000000000000ULL)
105 | ((a << 40) & 0x00FF000000000000ULL)
106 | ((a << 24) & 0x0000FF0000000000ULL)
107 | ((a << 8) & 0x000000FF00000000ULL)
108 | ((a >> 8) & 0x00000000FF000000ULL)
109 | ((a >> 24) & 0x0000000000FF0000ULL)
110 | ((a >> 40) & 0x000000000000FF00ULL)
111 | ((a >> 56) & 0x00000000000000FFULL) ;
127 clock_gettime(VOMP_LINUX_CLOCK, &ts);
128 return ts.tv_sec * 1000 + ts.tv_nsec / 1000000LL;