M1M3 Support System
Loading...
Searching...
No Matches
U8ArrayUtilities.h
1/*
2 * This file is part of LSST M1M3 support system package.
3 *
4 * Developed for the Vera C. Rubin Telescope and Site System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef U8ARRAYUTILITIES_H_
25#define U8ARRAYUTILITIES_H_
26
27#include <cRIO/DataTypes.h>
28#include <cstring>
29#include <string>
30
31namespace LSST {
32namespace M1M3 {
33namespace SS {
34
36public:
37 virtual ~U8ArrayUtilities();
38
39 inline static int8_t I8(uint8_t *buffer, int32_t index) { return (int8_t)buffer[index]; }
40
41 inline static int16_t I16(uint8_t *buffer, int32_t index) {
42 return ((int16_t)buffer[index] << 8) | (int16_t)buffer[index + 1];
43 }
44
45 inline static int32_t I32(uint8_t *buffer, int32_t index) {
46 return ((int32_t)buffer[index] << 24) | ((int32_t)buffer[index + 1] << 16) |
47 ((int32_t)buffer[index + 2] << 8) | (int32_t)buffer[index + 3];
48 }
49
50 inline static int64_t I64(uint8_t *buffer, int32_t index) {
51 return ((int64_t)buffer[index] << 54) | ((int64_t)buffer[index + 1] << 48) |
52 ((int64_t)buffer[index + 2] << 40) | ((int64_t)buffer[index + 3] << 32) |
53 ((int64_t)buffer[index + 4] << 24) | ((int64_t)buffer[index + 5] << 16) |
54 ((int64_t)buffer[index + 6] << 8) | (int64_t)buffer[index + 7];
55 }
56
57 inline static uint8_t U8(uint8_t *buffer, int32_t index) { return buffer[index]; }
58
59 inline static uint16_t U16(uint8_t *buffer, int32_t index) {
60 return ((uint16_t)buffer[index] << 8) | (uint16_t)buffer[index + 1];
61 }
62
63 inline static uint32_t U32(uint8_t *buffer, int32_t index) {
64 return ((uint32_t)buffer[index] << 24) | ((uint32_t)buffer[index + 1] << 16) |
65 ((uint32_t)buffer[index + 2] << 8) | (uint32_t)buffer[index + 3];
66 }
67
68 inline static uint64_t U64(uint8_t *buffer, int32_t index) {
69 return ((uint64_t)buffer[index] << 56) | ((uint64_t)buffer[index + 1] << 48) |
70 ((uint64_t)buffer[index + 2] << 40) | ((uint64_t)buffer[index + 3] << 32) |
71 ((uint64_t)buffer[index + 4] << 24) | ((uint64_t)buffer[index + 5] << 16) |
72 ((uint64_t)buffer[index + 6] << 8) | ((uint64_t)buffer[index + 7]);
73 }
74
75 inline static float SGL(uint8_t *buffer, int32_t index) {
76 uint8_t tempBuffer[4] = {buffer[index + 3], buffer[index + 2], buffer[index + 1], buffer[index]};
77 float value = 0;
78 memcpy(&value, tempBuffer, 4);
79 return value;
80 }
81
82 static std::string toString(uint8_t *buffer, int32_t index, int32_t length) {
83 char tmp[256];
84 memset(tmp, 0, 256);
85 memcpy(tmp, buffer + index, length);
86 return std::string(tmp, length);
87 }
88};
89
90} /* namespace SS */
91} /* namespace M1M3 */
92} /* namespace LSST */
93
94#endif /* U8ARRAYUTILITIES_H_ */
Definition U8ArrayUtilities.h:35