You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

driver_greis_checksum.c 646B

1234567891011121314151617181920212223242526
  1. /*
  2. * Checksum for the GNSS Receiver External Interface Specification (GREIS).
  3. *
  4. * This file is Copyright (c) 2017-2018 Virgin Orbit
  5. * SPDX-License-Identifier: BSD-2-clause
  6. */
  7. #include "gpsd_config.h" /* must be before all includes */
  8. #include <limits.h>
  9. #include "driver_greis.h"
  10. static inline unsigned char greis_rotate_left(unsigned char val)
  11. {
  12. /* left circular rotation by two bits */
  13. return (val << 2) | (val >> (CHAR_BIT - 2));
  14. }
  15. unsigned char greis_checksum(const unsigned char *src, int count)
  16. {
  17. unsigned char res = 0;
  18. while (count--)
  19. res = greis_rotate_left(res) ^ *src++;
  20. return greis_rotate_left(res);
  21. }