ROSaic
crc.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // © Copyright 2020, Septentrio NV/SA.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // 3. Neither the name of the copyright holder nor the names of its
14 // contributors may be used to endorse or promote products derived
15 // from this software without 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 OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 // *****************************************************************************
30 
31 #ifndef CRC_H
32 #define CRC_H
33 
34 // ROSaic includes
35 // The following imports structs into which SBF blocks can be unpacked then shipped to handler functions
37 // C++ libary includes
38 #include <stddef.h>
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 // By wrapping the C code with extern "C" the C++ compiler will not mangle the C code's names (official term: name
47 // mangling, allows C++ function overloading),
48 // Therefore, !all! generic C style header files (stdio.h for e.g. printf(...), string.h, .. etc) have their declarations
49 // in extern “C” block, do the same for your C style header files!!
50 // extern "C" doesn't really change the way that the compiler reads the code. If your code is in a .c file, it will be
51 // compiled as C, if it is in a .cpp file, it will be compiled as C++ (unless you do something strange to your configuration).
52 // What extern "C" does is affect linkage. C++ functions, when compiled, have their names mangled -- this is what makes
53 // overloading possible. The function name gets modified based on the types and number of parameters, so that two functions
54 // with the same name will have different symbol names.
55 // Code inside an extern "C" is still C++ code. There are limitations on what you can do in an extern "C" block, but they're
56 // all about linkage. You can't define any new symbols that can't be built with C linkage. That means no classes or
57 // templates, for example.
58 
71 uint16_t FW_EXPORT compute16CCITT(const void * buf, size_t buf_length);
72 
78 bool FW_EXPORT isValid(const void *block);
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif //CRC_H
#define FW_EXPORT
Definition: ssn_types.hpp:60
uint16_t FW_EXPORT compute16CCITT(const void *buf, size_t buf_length)
This function computes the CRC-8-CCITT (Cyclic Redundancy Check) of a buffer "buf" of "buf_length" by...
Definition: crc.c:43
Declares and defines structs into which SBF blocks are unpacked then shipped to handler functions...
bool FW_EXPORT isValid(const void *block)
Validates whether the calculated CRC of the SBF block at hand matches the CRC field of the streamed S...
Definition: crc.c:68