Felícito Manzano
/
DTK_Guaria2_ABInBev
Proyecto ABInBev para la tarjeta Guaria 1/2.
Embed:
(wiki syntax)
Show/hide line numbers
teltonika_crc.cpp
Go to the documentation of this file.
00001 /** 00002 * @file teltonika_crc.cpp 00003 * @author Felícito Manzano (felicito.manzano@detektor.com.sv) 00004 * @brief 00005 * @version 0.1 00006 * @date 2020-11-25 00007 * 00008 * @copyright Copyright (c) 2020 00009 * 00010 */ 00011 00012 int teltonika_crc16(char buffer[], int bufLen) 00013 { 00014 int offset = 0; 00015 int preset = 0; 00016 int polynom = 0xA001; 00017 preset &= 0xFFFF; 00018 polynom &= 0xFFFF; 00019 00020 int crc = preset; 00021 00022 for (int i = 0; i < bufLen; i++) { 00023 int data = buffer[(i + offset) % bufLen] & 0xFF; 00024 crc ^= data; 00025 for (int j = 0; j < 8; j++) { 00026 if ((crc & 0x0001) != 0) { 00027 crc = (crc >> 1) ^ polynom; 00028 } else { 00029 crc = crc >> 1; 00030 } 00031 } 00032 } 00033 return crc & 0xFFFF; 00034 }
Generated on Thu Jul 28 2022 19:27:02 by 1.7.2