include
ublox
checksum.h
Go to the documentation of this file.
1
//==============================================================================
2
// Copyright (c) 2012, Johannes Meyer, TU Darmstadt
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
// * Redistributions of source code must retain the above copyright
8
// notice, this list of conditions and the following disclaimer.
9
// * Redistributions in binary form must reproduce the above copyright
10
// notice, this list of conditions and the following disclaimer in the
11
// documentation and/or other materials provided with the distribution.
12
// * Neither the name of the Flight Systems and Automatic Control group,
13
// TU Darmstadt, nor the names of its contributors may be used to
14
// endorse or promote products derived from this software without
15
// specific prior written permission.
16
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
//==============================================================================
28
29
#ifndef UBLOX_MSGS_CHECKSUM_H
30
#define UBLOX_MSGS_CHECKSUM_H
31
32
#include <stdint.h>
33
34
namespace
ublox
{
35
43
static
inline
void
calculateChecksum
(
const
uint8_t *data,
44
uint32_t size,
45
uint8_t &ck_a,
46
uint8_t &ck_b) {
47
ck_a = 0; ck_b = 0;
48
for
(uint32_t i = 0; i < size; ++i)
49
{
50
ck_a = ck_a + data[i];
51
ck_b = ck_b + ck_a;
52
}
53
}
54
62
static
inline
uint16_t
calculateChecksum
(
const
uint8_t *data,
63
uint32_t size,
64
uint16_t &checksum) {
65
uint8_t *
byte
=
reinterpret_cast<
uint8_t *
>
(&checksum);
66
calculateChecksum
(data, size,
byte
[0],
byte
[1]);
67
return
checksum;
68
}
69
70
}
// namespace ublox
71
72
#endif // UBLOX_MSGS_CHECKSUM_H
ublox
Definition:
checksum.h:34
ublox::calculateChecksum
static void calculateChecksum(const uint8_t *data, uint32_t size, uint8_t &ck_a, uint8_t &ck_b)
calculate the checksum of a u-blox_message
Definition:
checksum.h:43
ublox_serialization
Author(s): Johannes Meyer
autogenerated on Wed Dec 7 2022 03:47:50