Copernicus  1.0
An Arduino module for the Trimble Copernicus GPS receiver
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Groups
chunk.h
Go to the documentation of this file.
1 /*
2  * File: chunk.h
3  * Author: tbabb
4  *
5  * Code for copying bytes from a big-endian stream.
6  *
7  * Created on October 7, 2013, 1:44 AM
8  */
9 
10 #ifndef CHUNK_H
11 #define CHUNK_H
12 
13 #include "gpstype.h"
14 
16 
17 inline void copy_network_order(uint16_t *i, uint8_t bytes[2]) {
18  *i = ((uint16_t)(bytes[0]) << 8) | bytes[1];
19 }
20 inline void copy_network_order(uint32_t *i, uint8_t bytes[4]) {
21  *i = (uint32_t)(bytes[0]) << 24;
22  *i |= (uint32_t)(bytes[1]) << 16;
23  *i |= (uint32_t)(bytes[2]) << 8;
24  *i |= (uint32_t)(bytes[3]);
25 }
26 
27 inline void copy_network_order(uint64_t *i, uint8_t bytes[8]) {
28  *i = (uint64_t)(bytes[0]) << 56;
29  *i |= (uint64_t)(bytes[1]) << 48;
30  *i |= (uint64_t)(bytes[2]) << 40;
31  *i |= (uint64_t)(bytes[3]) << 32;
32  *i |= (uint64_t)(bytes[4]) << 24;
33  *i |= (uint64_t)(bytes[5]) << 16;
34  *i |= (uint64_t)(bytes[6]) << 8;
35  *i |= (uint64_t)(bytes[7]);
36 }
37 
39 
40 inline void copy_network_order(int16_t *i, uint8_t bytes[2]) {
41  copy_network_order(reinterpret_cast<uint16_t*>(i), bytes);
42 }
43 
44 inline void copy_network_order(int32_t *i, uint8_t bytes[4]) {
45  copy_network_order(reinterpret_cast<uint32_t*>(i), bytes);
46 }
47 
48 inline void copy_network_order(int64_t *i, uint8_t bytes[8]) {
49  copy_network_order(reinterpret_cast<uint64_t*>(i), bytes);
50 }
51 
53 
54 inline void copy_network_order(Float32 *f, uint8_t bytes[4]) {
55  copy_network_order(&f->bits, bytes);
56 }
57 
58 inline void copy_network_order(Float64 *f, uint8_t bytes[8]) {
59  copy_network_order(&f->bits, bytes);
60 }
61 
62 #endif /* CHUNK_H */
63