Robotics Library  0.7.0
Endian.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_HAL_ENDIAN_H
28 #define RL_HAL_ENDIAN_H
29 
30 #include <cstdint>
31 
32 namespace rl
33 {
34  namespace hal
35  {
36  class Endian
37  {
38  public:
39  static ::std::uint32_t bigDoubleWord(const ::std::uint16_t& highWord, const ::std::uint16_t& lowWord);
40 
41  static ::std::uint8_t bigHighByte(const ::std::uint16_t& word);
42 
43  static ::std::uint32_t bigHighDoubleWord(const ::std::uint64_t& quadWord);
44 
45  static ::std::uint16_t bigHighWord(const ::std::uint32_t& doubleWord);
46 
47  static ::std::uint8_t bigLowByte(const ::std::uint16_t& word);
48 
49  static ::std::uint32_t bigLowDoubleWord(const ::std::uint64_t& quadWord);
50 
51  static ::std::uint16_t bigLowWord(const ::std::uint32_t& doubleWord);
52 
53  static ::std::uint64_t bigQuadWord(const ::std::uint32_t& highDoubleWord, const ::std::uint32_t& lowDoubleWord);
54 
55  static void bigToHost(::std::int8_t& character)
56  {
57  }
58 
59  static void bigToHost(::std::uint8_t& character)
60  {
61  }
62 
63  static void bigToHost(::std::int16_t& word);
64 
65  static void bigToHost(::std::uint16_t& word);
66 
67  static void bigToHost(::std::int32_t& doubleWord);
68 
69  static void bigToHost(::std::uint32_t& doubleWord);
70 
71  static void bigToHost(float& real32);
72 
73  static void bigToHost(::std::int64_t& quadWord);
74 
75  static void bigToHost(::std::uint64_t& quadWord);
76 
77  static void bigToHost(double& real64);
78 
79  static ::std::uint16_t bigWord(const ::std::uint8_t& highByte, const ::std::uint8_t& lowByte);
80 
81  static ::std::uint32_t hostDoubleWord(const ::std::uint16_t& highWord, const ::std::uint16_t& lowWord)
82  {
83  return (highWord << 16) | lowWord;
84  }
85 
86  static ::std::uint8_t hostHighByte(const ::std::uint16_t& word)
87  {
88  return (word >> 8);
89  }
90 
91  static ::std::uint16_t hostHighWord(const ::std::uint32_t& doubleWord)
92  {
93  return (doubleWord >> 16);
94  }
95 
96  static ::std::uint32_t hostHighDoubleWord(const ::std::uint64_t& quadWord)
97  {
98  return (quadWord >> 32);
99  }
100 
101  static ::std::uint8_t hostLowByte(const ::std::uint16_t& word)
102  {
103  return (word & 0xFF);
104  }
105 
106  static ::std::uint16_t hostLowWord(const ::std::uint32_t& doubleWord)
107  {
108  return (doubleWord & 0xFFFF);
109  }
110 
111  static ::std::uint32_t hostLowDoubleWord(const ::std::uint64_t& quadWord)
112  {
113  return (quadWord & 0xFFFFFFFF);
114  }
115 
116  static ::std::uint64_t hostQuadWord(const ::std::uint32_t& highDoubleWord, const ::std::uint32_t& lowDoubleWord)
117  {
118  return (static_cast< ::std::uint64_t>(highDoubleWord) << 32) | lowDoubleWord;
119  }
120 
121  static void hostToBig(::std::int8_t& character)
122  {
123  }
124 
125  static void hostToBig(::std::uint8_t& character)
126  {
127  }
128 
129  static void hostToBig(::std::int16_t& word);
130 
131  static void hostToBig(::std::uint16_t& word);
132 
133  static void hostToBig(::std::int32_t& doubleWord);
134 
135  static void hostToBig(::std::uint32_t& doubleWord);
136 
137  static void hostToBig(float& real32);
138 
139  static void hostToBig(::std::int64_t& quadWord);
140 
141  static void hostToBig(::std::uint64_t& quadWord);
142 
143  static void hostToBig(double& real64);
144 
145  static void hostToLittle(::std::int8_t& character)
146  {
147  }
148 
149  static void hostToLittle(::std::uint8_t& character)
150  {
151  }
152 
153  static void hostToLittle(::std::int16_t& word);
154 
155  static void hostToLittle(::std::uint16_t& word);
156 
157  static void hostToLittle(::std::int32_t& doubleWord);
158 
159  static void hostToLittle(::std::uint32_t& doubleWord);
160 
161  static void hostToLittle(float& real32);
162 
163  static void hostToLittle(::std::int64_t& quadWord);
164 
165  static void hostToLittle(::std::uint64_t& quadWord);
166 
167  static void hostToLittle(double& real64);
168 
169  static ::std::uint16_t hostWord(const ::std::uint8_t& highByte, const ::std::uint8_t& lowByte)
170  {
171  return (highByte << 8) | lowByte;
172  }
173 
174  static ::std::uint32_t littleDoubleWord(const ::std::uint16_t& highWord, const ::std::uint16_t& lowWord);
175 
176  static ::std::uint8_t littleHighByte(const ::std::uint16_t& word);
177 
178  static ::std::uint32_t littleHighDoubleWord(const ::std::uint64_t& quadWord);
179 
180  static ::std::uint16_t littleHighWord(const ::std::uint32_t& doubleWord);
181 
182  static ::std::uint8_t littleLowByte(const ::std::uint16_t& word);
183 
184  static ::std::uint32_t littleLowDoubleWord(const ::std::uint64_t& quadWord);
185 
186  static ::std::uint16_t littleLowWord(const ::std::uint32_t& doubleWord);
187 
188  static ::std::uint64_t littleQuadWord(const ::std::uint32_t& highDoubleWord, const ::std::uint32_t& lowDoubleWord);
189 
190  static void littleToHost(::std::int8_t& character)
191  {
192  }
193 
194  static void littleToHost(::std::uint8_t& character)
195  {
196  }
197 
198  static void littleToHost(::std::int16_t& word);
199 
200  static void littleToHost(::std::uint16_t& word);
201 
202  static void littleToHost(::std::int32_t& doubleWord);
203 
204  static void littleToHost(::std::uint32_t& doubleWord);
205 
206  static void littleToHost(float& real32);
207 
208  static void littleToHost(::std::int64_t& quadWord);
209 
210  static void littleToHost(::std::uint64_t& quadWord);
211 
212  static void littleToHost(double& real64);
213 
214  static ::std::uint16_t littleWord(const ::std::uint8_t& highByte, const ::std::uint8_t& lowByte);
215 
216  static void reverse(::std::int8_t& character)
217  {
218  }
219 
220  static void reverse(::std::uint8_t& character)
221  {
222  }
223 
224  static void reverse(::std::int16_t& word)
225  {
226  word = (word >> 8) | (word << 8);
227  }
228 
229  static void reverse(::std::uint16_t& word)
230  {
231  word = (word >> 8) | (word << 8);
232  }
233 
234  static void reverse(::std::int32_t& doubleWord)
235  {
236  doubleWord = ((doubleWord & 0x000000FF) << 24) | ((doubleWord & 0x0000FF00) << 8) |
237  ((doubleWord & 0xFF000000) >> 24) | ((doubleWord & 0x00FF0000) >> 8);
238  }
239 
240  static void reverse(::std::uint32_t& doubleWord)
241  {
242  doubleWord = ((doubleWord & 0x000000FF) << 24) | ((doubleWord & 0x0000FF00) << 8) |
243  ((doubleWord & 0xFF000000) >> 24) | ((doubleWord & 0x00FF0000) >> 8);
244  }
245 
246  static void reverse(float& real32)
247  {
248  reverse(*reinterpret_cast< ::std::uint32_t*>(&real32));
249  }
250 
251  static void reverse(::std::int64_t& quadWord)
252  {
253  quadWord = ((quadWord & 0x00000000000000FF) << 56) | ((quadWord & 0x000000000000FF00) << 40) | ((quadWord & 0x0000000000FF0000) << 24) | ((quadWord & 0x00000000FF000000) << 8) |
254  ((quadWord & 0xFF00000000000000) >> 56) | ((quadWord & 0x00FF000000000000) >> 40) | ((quadWord & 0x0000FF0000000000) >> 24) | ((quadWord & 0x000000FF00000000) >> 8);
255  }
256 
257  static void reverse(::std::uint64_t& quadWord)
258  {
259  quadWord = ((quadWord & 0x00000000000000FF) << 56) | ((quadWord & 0x000000000000FF00) << 40) | ((quadWord & 0x0000000000FF0000) << 24) | ((quadWord & 0x00000000FF000000) << 8) |
260  ((quadWord & 0xFF00000000000000) >> 56) | ((quadWord & 0x00FF000000000000) >> 40) | ((quadWord & 0x0000FF0000000000) >> 24) | ((quadWord & 0x000000FF00000000) >> 8);
261  }
262 
263  static void reverse(double& real64)
264  {
265  reverse(*reinterpret_cast< ::std::uint64_t*>(&real64));
266  }
267 
268  protected:
269 
270  private:
272  {
273  }
274 
275  virtual ~Endian()
276  {
277  }
278  };
279  }
280 }
281 
282 #endif // RL_HAL_ENDIAN_H
rl::hal::Endian::reverse
static void reverse(::std::int8_t &character)
Definition: Endian.h:216
rl::hal::Endian::bigToHost
static void bigToHost(::std::uint8_t &character)
Definition: Endian.h:59
rl::hal::Endian::bigHighWord
::std::uint16_t bigHighWord(const ::std::uint32_t &doubleWord)
Definition: Endian.cpp:68
rl::hal::Endian::hostWord
::std::uint16_t hostWord(const ::std::uint8_t &highByte, const ::std::uint8_t &lowByte)
Definition: Endian.h:169
rl::hal::Endian::hostToBig
static void hostToBig(::std::uint8_t &character)
Definition: Endian.h:125
rl::hal::Endian::bigWord
::std::uint16_t bigWord(const ::std::uint8_t &highByte, const ::std::uint8_t &lowByte)
Definition: Endian.cpp:182
rl::hal::Endian::hostHighWord
::std::uint16_t hostHighWord(const ::std::uint32_t &doubleWord)
Definition: Endian.h:91
rl::hal::Endian::reverse
static void reverse(::std::int64_t &quadWord)
Definition: Endian.h:251
rl::hal::Endian::reverse
static void reverse(::std::int32_t &doubleWord)
Definition: Endian.h:234
rl::hal::Endian::hostLowDoubleWord
::std::uint32_t hostLowDoubleWord(const ::std::uint64_t &quadWord)
Definition: Endian.h:111
rl::hal::Endian::littleLowWord
::std::uint16_t littleLowWord(const ::std::uint32_t &doubleWord)
Definition: Endian.cpp:380
rl::hal::Endian::littleHighDoubleWord
::std::uint32_t littleHighDoubleWord(const ::std::uint64_t &quadWord)
Definition: Endian.cpp:340
rl::hal::Endian::bigDoubleWord
::std::uint32_t bigDoubleWord(const ::std::uint16_t &highWord, const ::std::uint16_t &lowWord)
Definition: Endian.cpp:38
rl::hal::Endian::littleToHost
static void littleToHost(::std::int8_t &character)
Definition: Endian.h:190
rl::hal::Endian::bigLowByte
::std::uint8_t bigLowByte(const ::std::uint16_t &word)
Definition: Endian.cpp:78
rl::hal::Endian::hostHighByte
::std::uint8_t hostHighByte(const ::std::uint16_t &word)
Definition: Endian.h:86
rl::hal::Endian::littleDoubleWord
::std::uint32_t littleDoubleWord(const ::std::uint16_t &highWord, const ::std::uint16_t &lowWord)
Definition: Endian.cpp:320
rl::hal::Endian::Endian
Endian()
Definition: Endian.h:271
rl::hal::Endian::hostDoubleWord
::std::uint32_t hostDoubleWord(const ::std::uint16_t &highWord, const ::std::uint16_t &lowWord)
Definition: Endian.h:81
rl::hal::Endian::bigLowDoubleWord
::std::uint32_t bigLowDoubleWord(const ::std::uint64_t &quadWord)
Definition: Endian.cpp:88
rl::hal::Endian::reverse
static void reverse(::std::uint16_t &word)
Definition: Endian.h:229
rl::hal::Endian::bigLowWord
::std::uint16_t bigLowWord(const ::std::uint32_t &doubleWord)
Definition: Endian.cpp:98
rl::hal::Endian::hostLowByte
::std::uint8_t hostLowByte(const ::std::uint16_t &word)
Definition: Endian.h:101
rl::hal::Endian::littleWord
::std::uint16_t littleWord(const ::std::uint8_t &highByte, const ::std::uint8_t &lowByte)
Definition: Endian.cpp:464
rl::hal::Endian::littleHighWord
::std::uint16_t littleHighWord(const ::std::uint32_t &doubleWord)
Definition: Endian.cpp:350
rl::hal::Endian::reverse
static void reverse(::std::uint8_t &character)
Definition: Endian.h:220
rl::hal::Endian::littleLowDoubleWord
::std::uint32_t littleLowDoubleWord(const ::std::uint64_t &quadWord)
Definition: Endian.cpp:370
rl::hal::Endian::littleQuadWord
::std::uint64_t littleQuadWord(const ::std::uint32_t &highDoubleWord, const ::std::uint32_t &lowDoubleWord)
Definition: Endian.cpp:390
rl::hal::Endian::hostLowWord
::std::uint16_t hostLowWord(const ::std::uint32_t &doubleWord)
Definition: Endian.h:106
rl::hal::Endian::littleHighByte
::std::uint8_t littleHighByte(const ::std::uint16_t &word)
Definition: Endian.cpp:330
rl::hal::Endian::reverse
static void reverse(::std::uint32_t &doubleWord)
Definition: Endian.h:240
rl::hal::Endian::littleToHost
static void littleToHost(::std::uint8_t &character)
Definition: Endian.h:194
rl::hal::Endian::bigQuadWord
::std::uint64_t bigQuadWord(const ::std::uint32_t &highDoubleWord, const ::std::uint32_t &lowDoubleWord)
Definition: Endian.cpp:108
rl::hal::Endian::bigHighByte
::std::uint8_t bigHighByte(const ::std::uint16_t &word)
Definition: Endian.cpp:48
rl::hal::Endian::hostToBig
static void hostToBig(::std::int8_t &character)
Definition: Endian.h:121
rl::hal::Endian::reverse
static void reverse(float &real32)
Definition: Endian.h:246
rl::hal::Endian::bigToHost
static void bigToHost(::std::int8_t &character)
Definition: Endian.h:55
rl::hal::Endian::reverse
static void reverse(::std::uint64_t &quadWord)
Definition: Endian.h:257
rl::hal::Endian::~Endian
virtual ~Endian()
Definition: Endian.h:275
rl::hal::Endian::hostToLittle
static void hostToLittle(::std::int8_t &character)
Definition: Endian.h:145
rl::hal::Endian::reverse
static void reverse(double &real64)
Definition: Endian.h:263
rl::hal::Endian::bigHighDoubleWord
::std::uint32_t bigHighDoubleWord(const ::std::uint64_t &quadWord)
Definition: Endian.cpp:58
rl::hal::Endian::hostHighDoubleWord
::std::uint32_t hostHighDoubleWord(const ::std::uint64_t &quadWord)
Definition: Endian.h:96
rl::hal::Endian::hostToLittle
static void hostToLittle(::std::uint8_t &character)
Definition: Endian.h:149
rl::hal::Endian
Definition: Endian.h:37
rl::hal::Endian::hostQuadWord
::std::uint64_t hostQuadWord(const ::std::uint32_t &highDoubleWord, const ::std::uint32_t &lowDoubleWord)
Definition: Endian.h:116
rl::hal::Endian::reverse
static void reverse(::std::int16_t &word)
Definition: Endian.h:224
rl::hal::Endian::littleLowByte
::std::uint8_t littleLowByte(const ::std::uint16_t &word)
Definition: Endian.cpp:360
rl
Robotics Library.
Definition: AnalogInput.cpp:30