Horizon Official Technical Documentation
Utility.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_UTILITIES_UTILITY_HPP
31#define HORIZON_UTILITIES_UTILITY_HPP
32
33#include <cstdint>
34#include <ctime>
35#include <chrono>
36#include <cstring>
37
38uint32_t getMSTime();
39uint32_t getMSTimeDiff(uint32_t oldMSTime, uint32_t newMSTime);
40uint32_t GetMSTimeDiffToNow(uint32_t oldMSTime);
41
42int64_t get_sys_time();
43
44uint32_t rgb2bgr(uint32_t rgb);
45
46const char *TimeStamp2String(char *str, size_t size, time_t timestamp, const char *format);
47// Reorders bytes from network to little endian (Windows).
48// Necessary for sending port numbers to the RO client until Gravity notices that they forgot ntohs() calls.
49uint16_t ntows(uint16_t netshort);
50
51// client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
52void PackPosition(int8_t *p, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t sx0, uint8_t sy0);
53void PackPosition(int8_t *p, uint16_t x, uint16_t y, uint8_t dir);
54void UnpackPosition(const uint8_t *p, uint16_t *x, uint16_t *y, uint8_t *dir);
55
56// little endian char array to uint conversion
57unsigned int GetULong(unsigned char* p);
58
59// Reads a float (32 bits) from the buffer
60float GetFloat(const unsigned char* buf);
61
62// Converts an int16 from current machine order to little-endian
63int16_t MakeShortLE(int16_t val);
64
65// Converts an int32 from current machine order to little-endian
66int32_t MakeLongLE(int32_t val);
67
68// Reads an uint16 in little-endian from the buffer
69uint16_t GetUShort(const unsigned char* buf);
70
71// Reads an uint32 in little-endian from the buffer
72uint32_t GetULong(const unsigned char* buf);
73
74// Reads an uint64 in little-endian from the buffer
75uint64_t GetULongLong(const unsigned char* buf);
76
77// Reads an int32 in little-endian from the buffer
78int32_t GetLong(const unsigned char *buf);
79
80// Reads an int64 in little-endian from the buffer
81int64_t GetLongLong(const unsigned char *buf);
82
83uint32_t Concatenate(uint32_t a, uint32_t b);
84#endif // HORIZON_UTILITIES_UTILITY_HPP
void UnpackPosition(const uint8_t *p, uint16_t *x, uint16_t *y, uint8_t *dir)
Definition: Utility.cpp:148
uint32_t getMSTime()
Definition: Utility.cpp:39
float GetFloat(const unsigned char *buf)
Definition: Utility.cpp:175
uint32_t GetMSTimeDiffToNow(uint32_t oldMSTime)
Definition: Utility.cpp:62
uint32_t Concatenate(uint32_t a, uint32_t b)
Definition: Utility.cpp:239
int64_t GetLongLong(const unsigned char *buf)
Definition: Utility.cpp:234
uint16_t ntows(uint16_t netshort)
Definition: Utility.cpp:136
uint32_t rgb2bgr(uint32_t rgb)
Definition: Utility.cpp:57
uint32_t getMSTimeDiff(uint32_t oldMSTime, uint32_t newMSTime)
Definition: Utility.cpp:48
int16_t MakeShortLE(int16_t val)
Definition: Utility.cpp:182
int64_t get_sys_time()
Definition: Utility.cpp:68
unsigned int GetULong(unsigned char *p)
Definition: Utility.cpp:169
uint64_t GetULongLong(const unsigned char *buf)
Definition: Utility.cpp:216
int32_t MakeLongLE(int32_t val)
Definition: Utility.cpp:191
const char * TimeStamp2String(char *str, size_t size, time_t timestamp, const char *format)
Definition: Utility.cpp:120
int32_t GetLong(const unsigned char *buf)
Definition: Utility.cpp:229
uint16_t GetUShort(const unsigned char *buf)
Definition: Utility.cpp:202
void PackPosition(int8_t *p, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t sx0, uint8_t sy0)
Definition: Utility.cpp:159