Coverage Report

Created: 2026-01-10 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gpsd/gpsd-3.27.4~dev/drivers/driver_greis_checksum.c
Line
Count
Source
1
/*
2
 * Checksum for the GNSS Receiver External Interface Specification (GREIS).
3
 *
4
 * This file is Copyright 2017 Virgin Orbit
5
 * This file is Copyright 2017 the GPSD project
6
 * SPDX-License-Identifier: BSD-2-clause
7
 */
8
9
#include "../include/gpsd_config.h"  // must be before all includes
10
11
#include <limits.h>
12
13
#include "../include/driver_greis.h"
14
15
/* This algorithm is right out of the:
16
 *  "GREIS GNSS Receiver External Interface Specification" Version 4.1.00
17
 * Section a.1.1 Computing 8-bit checksum
18
 */
19
20
static inline unsigned char greis_rotate_left(unsigned char val)
21
48.0k
{
22
    // left circular rotation by two bits
23
48.0k
    return (val << 2) | (val >> (CHAR_BIT - 2));
24
48.0k
}
25
26
unsigned char greis_checksum(const unsigned char *src, int count)
27
2.35k
{
28
2.35k
    unsigned char res = 0;
29
30
48.0k
    while (count--) {
31
45.6k
        res = greis_rotate_left(res) ^ *src++;
32
45.6k
    }
33
2.35k
    return greis_rotate_left(res);
34
2.35k
}
35
// vim: set expandtab shiftwidth=4