driver_greis_checksum.c 727 B

1234567891011121314151617181920212223242526272829
  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. #include "gpsd_config.h" /* must be before all includes */
  9. #include <limits.h>
  10. #include "driver_greis.h"
  11. static inline unsigned char greis_rotate_left(unsigned char val)
  12. {
  13. /* left circular rotation by two bits */
  14. return (val << 2) | (val >> (CHAR_BIT - 2));
  15. }
  16. unsigned char greis_checksum(const unsigned char *src, int count)
  17. {
  18. unsigned char res = 0;
  19. while (count--)
  20. res = greis_rotate_left(res) ^ *src++;
  21. return greis_rotate_left(res);
  22. }
  23. // vim: set expandtab shiftwidth=4