本文整理汇总了C++中crc8函数的典型用法代码示例。如果您正苦于以下问题:C++ crc8函数的具体用法?C++ crc8怎么用?C++ crc8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了crc8函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
fprintf(stderr, "util:: test\n");
uint8_t msg[] = {0x08, 0x0a, 0xe8, 0x80};
fprintf(stderr, "util::crc8(): odd parity: %02X\n", crc8(msg, 3, 0x80));
fprintf(stderr, "util::crc8(): even parity: %02X\n", crc8(msg, 4, 0x80));
return 0;
}
开发者ID:beowulf573,项目名称:rtl_433,代码行数:10,代码来源:util.c
示例2: receiveMedtronicMessage
uint8_t receiveMedtronicMessage( uint8_t *message, uint16_t *length ) {
uint16_t i = 0;
uint8_t calcCRC = 0;
uint16_t calcCRC16 = 0;
RFST = RFST_SIDLE;
RFST = RFST_SRX;
PKTLEN = 0xFF;
lastData = 0xFF;
for( i = 0; i < 500 && lastData != 0x00; i++ ) {
while( !RFTXRXIF ) {
// TODO Add generic rx/tx uart code
//usbUartProcess( );
//usbReceiveData( );
}
rfMessage[i] = RFD;
lastData = rfMessage[i];
TCON &= ~0x02;
}
rfLength = i - 1;
RFST = RFST_SIDLE;
decode4b6b( rfMessage, rfLength, message, length );
calcCRC = crc8( message, (*length) - 1 );
if( calcCRC == message[(*length) - 1] ) {
return 0;
}
calcCRC16 = crc16( message, (*length) - 2 );
if( ((uint8_t)(calcCRC16 & 0x00FFu) == message[(*length) - 1]) &&
((uint8_t)((calcCRC16 >> 8) & 0x00FFu) == message[(*length) - 2]) ) {
return 0;
}
calcCRC = crc8( message, (*length) - 2 );
if( calcCRC == message[(*length) - 2] ) {
(*length) = (*length) - 1;
return 0;
}
calcCRC16 = crc16( message, (*length) - 3 );
if( ((uint8_t)(calcCRC16 & 0x00FFu) == message[(*length) - 2]) &&
((uint8_t)((calcCRC16 >> 8) & 0x00FFu) == message[(*length) - 3]) ) {
(*length) = (*length) - 1;
return 0;
}
crc16Init( );
return 1;
}
开发者ID:StephenBlackWasAlreadyTaken,项目名称:mmcommander_serial,代码行数:53,代码来源:medtronicRF.c
示例3: _nvram_commit
/* Regenerate NVRAM. Should be locked. */
int _nvram_commit(struct nvram_header *header)
{
// char *init, *config, *refresh, *ncdl;
char *ptr, *end;
int i;
struct nvram_tuple *t;
struct nvram_header tmp;
uint8 crc;
/* Regenerate header */
header->magic = NVRAM_MAGIC;
header->crc_ver_init = NVRAM_DEFAULT << NVRAM_OPT_SHIFT | NVRAM_VERSION << NVRAM_VER_SHIFT;
/* Clear data area */
ptr = (char *)header + sizeof(struct nvram_header);
bzero(ptr, NVRAM_SPACE - sizeof(struct nvram_header));
/* Leave space for a double NUL at the end */
end = (char *)header + NVRAM_SPACE - 2;
/* Write out all tuples */
for (i = 0; i < ARRAYSIZE(nvram_hash); i++) {
for (t = nvram_hash[i]; t; t = t->next) {
if ((ptr + strlen(t->name) + 1 + strlen(t->value) + 1) > end)
break;
ptr += sprintf(ptr, "%s=%s", t->name, t->value) + 1;
}
}
/* End with a double NUL */
ptr += 2;
/* Set new length */
header->len = ROUNDUP(ptr - (char *)header, 4);
/* Little-endian CRC8 over the last 11 bytes of the header */
tmp.crc_ver_init = htol32(header->crc_ver_init);
tmp.config_refresh = htol32(header->config_refresh);
tmp.config_ncdl = htol32(header->config_ncdl);
crc = crc8((char *)&tmp + 12, sizeof(struct nvram_header) - 12, CRC8_INIT_VALUE);
/* Continue CRC8 over data bytes */
crc = crc8((char *)&header[1], header->len - sizeof(struct nvram_header), crc);
/* Set new CRC8 */
header->crc_ver_init |= crc;
/* Reinitialize hash table */
return nvram_rehash(header);
}
开发者ID:janfj,项目名称:dd-wrt,代码行数:51,代码来源:nvram.c
示例4: crc8
//-------------------------------------------------------
bool t_tera_ranger_one_controller::check_echo(void)
{
if (trigger_started) {
if (Wire.available() == 3) {
byte buf[3];
buf[0] = Wire.read();
buf[1] = Wire.read();
buf[2] = Wire.read();
int distance = (buf[0] << 8) + buf[1]; // Calculate distance in mm
int crc = crc8(buf, 2); // Calculate checksum
if ((crc - buf[2]) == 0)
last_read_distance = distance;
else
last_read_distance = -1;
trigger_started = false;
return true;
}
else
return false;
}
else
return false;
}
开发者ID:jenny5-robot,项目名称:jenny5-firmware,代码行数:28,代码来源:tera_ranger_one.cpp
示例5: ccodelte_encode
void
ccodelte_encode (int32_t numbits,
uint8_t add_crc,
uint8_t *inPtr,
uint8_t *outPtr,
uint16_t rnti)
{
uint32_t state;
uint8_t c, out, first_bit;
int8_t shiftbit=0;
uint16_t c16;
uint16_t next_last_byte=0;
uint32_t crc=0;
#ifdef DEBUG_CCODE
uint32_t dummy=0;
#endif //DEBUG_CCODE
/* The input bit is shifted in position 8 of the state.
Shiftbit will take values between 1 and 8 */
state = 0;
if (add_crc == 1) {
crc = crc8(inPtr,numbits);
first_bit = 2;
c = (uint8_t)(crc>>24);
} else if (add_crc == 2) {
开发者ID:awesome-security,项目名称:openairinterface5g,代码行数:28,代码来源:ccoding_byte_lte.c
示例6: DEBUG_LOG
void ErrorControl::re_transmit(int promptFactor)
{
for( char f = send_head; f != send_tail; inc_frame_id(f) )
{
if( !are_all_acked(f) && need_re_send(f, promptFactor) )
{
// count no. of remote player to re_send
int resendSuccess = 0;
int resendFail = 0;
char *ecMsg = send_queue[f].queue_buf;
DWORD ecMsgLen = send_queue[f].length();
for( char ecPlayerId = 1; ecPlayerId <= MAX_PLAYER; ++ecPlayerId )
{
// resend to specific remote player
if( dp_id[ecPlayerId-1] && !ack_flag[f][ecPlayerId-1] )
{
#if (defined(DEBUG) && DEBUG_LOG_LEVEL >= 2)
debugStr = "ec.remote : time-out retransmit frame ";
debugStr += f;
debugStr += " to ";
debugStr += ecPlayerId;
DEBUG_LOG(debugStr);
#endif
if( mp_ptr->send(dp_id[ecPlayerId-1], ecMsg, ecMsgLen))
resendSuccess++;
else
resendFail++;
}
if( resendSuccess > 0)
{
if( resendFail > 0)
{
// some resend fail, mark short resend time
mark_send_time(f, SHORT_TIME_OUT);
}
else
{
// all resend success, mark longer resend time
mark_send_time(f, TIME_OUT );
}
// mark the func_id of the message RE_SEND
((EcMsgHeader *)ecMsg)->func_id = RE_SEND;
// recalculate CRC
*((CRC_TYPE *) (ecMsg + ecMsgLen - CRC_LEN )) = crc8((unsigned char *)ecMsg, ecMsgLen - CRC_LEN);
}
else if( resendFail > 0)
{
// all fail, mark a shorter time
// mark send time, mark a shorter time
mark_send_time(f, SHORT_TIME_OUT);
}
}
}
}
}
开发者ID:LibreGames,项目名称:7kaa,代码行数:60,代码来源:OERRCTRL.cpp
示例7: crc8
bool Keys::isCRCOK()
{
uint8_t crc = crc8( (uint8_t*)data, sizeof(KeysCRCed), CRC8INIT );
Serial.println (data->crc8); // added by eqiglii
Serial.println (crc);
return (crc == data->crc8);
}
开发者ID:pipoop,项目名称:hobby-device,代码行数:7,代码来源:Keys.cpp
示例8: occ_read_device_info_cmd
/*==============================================
*
* 函数名称:static void occ_read_device_info_cmd(void)
* 函数功能:
* 入口参数:
* 出口参数:
* 修改日期:2015-12-08
* 修改作者:zhuchengzhi
*
* ============================================*/
static void occ_read_device_info_cmd(void)
{
int uuid_fd = 0,cfg_fd = 0,size = 0;
uuid_fd = open("/yaffs/uuid.bin",O_RDONLY);
if(uuid_fd < 0){
printf("open file error \n");
}
size = read(uuid_fd,board_info.uuid,16);
close(uuid_fd);
cfg_fd = open("/yaffs/dev_config.bin",O_RDONLY);
if(cfg_fd < 0){
printf("open file error \n");
}
size = read(cfg_fd,board_info.name,104);
close(cfg_fd);
memcpy(&uart485_data.uartx_txbuf[5],&board_info.uuid[0],16);
memcpy(&uart485_data.uartx_txbuf[21],&board_info.name[1],103);
uart485_data.uartx_txbuf[0] = 0x7E;
uart485_data.uartx_txbuf[1] = 0x00;
uart485_data.uartx_txbuf[2] = 0x7C;
uart485_data.uartx_txbuf[3] = 0x01;
uart485_data.uartx_txbuf[4] = board_info.name[0];
uart485_data.uartx_txbuf[124] = crc8(uart485_data.uartx_txbuf,(uart485_data.uartx_txbuf[1] << 8) | uart485_data.uartx_txbuf[2]);
uart485_data.uartx_txbuf[125] = 0x5A;
send_data_tty(com1_fd,uart485_data.uartx_txbuf,(((uart485_data.uartx_txbuf[1] << 8) | uart485_data.uartx_txbuf[2]) + 2));
}
开发者ID:zhucz,项目名称:mylinux,代码行数:41,代码来源:cmd_analysis.c
示例9: occ_write_device_uuid_info
/*==============================================
*
* 函数名称:static void occ_write_device_uuid_info(uint8_t *src)
* 函数功能:
* 入口参数:
* 出口参数:
* 修改日期:2015-12-04
* 修改作者:zhuchengzhi
*
* ============================================*/
static void occ_write_device_uuid_info(uint8_t *src)
{
int uuid_fd = 0 ,size = 0,ret = 0;
uint8_t buffer[80];
uuid_fd = open("/yaffs/uuid.bin",O_RDWR | O_CREAT);
if(uuid_fd < 0){
printf("open file error \n");
}
write(uuid_fd,&src[4],16);
close(uuid_fd);
uuid_fd = open("/yaffs/uuid.bin",O_RDONLY);
if(uuid_fd < 0){
printf("open file error \n");
}
size = read(uuid_fd,buffer,sizeof(buffer));
close(uuid_fd);
ret = memcmp(buffer,&src[4],16);
if(!ret){
uart485_data.uartx_txbuf[4] = 0x00;
}else{
uart485_data.uartx_txbuf[4] = 0x01;
}
uart485_data.uartx_txbuf[0] = 0x7E;
uart485_data.uartx_txbuf[1] = 0x00;
uart485_data.uartx_txbuf[2] = 0x05;
uart485_data.uartx_txbuf[3] = 0x14;
uart485_data.uartx_txbuf[5] = crc8(uart485_data.uartx_txbuf,(((uart485_data.uartx_txbuf[1] << 8) | uart485_data.uartx_txbuf[2])));
uart485_data.uartx_txbuf[6] = 0x5A;
send_data_tty(com1_fd,uart485_data.uartx_txbuf,(((uart485_data.uartx_txbuf[1] << 8) | uart485_data.uartx_txbuf[2]) + 2));
}
开发者ID:zhucz,项目名称:mylinux,代码行数:44,代码来源:cmd_analysis.c
示例10: ds18x20_read_temp
uint8_t ds18x20_read_temp(int16_t *t, int8_t *e)
{
uint8_t i;
if(ow_command(COMMAND_CONVERT_T,NULL) == RES_FAULT) return RES_FAULT;
//ow_strong_pullup_line();
_delay_ms(200); //
//ow_normal_line();
if(ow_command(COMMAND_READ_SP,NULL) == RES_FAULT) return RES_FAULT;
for (i=0; i<9; i++)
ds18x20_sp[i] = ow_byte_read();
if(crc8(ds18x20_sp,9) == CRC_OK)
{
*t = ((ds18x20_sp[1] << 8) | (ds18x20_sp[0])) / 16;
*e = ((ds18x20_sp[0] & M00001111) * 10) / 16;
return RES_OK;
}
else
{
//*t = 127;
//*e = 0;
return RES_FAULT;
}
}
开发者ID:wapacz,项目名称:Termostat,代码行数:28,代码来源:ds18x20.c
示例11: to_alpus_dec
int to_alpus_dec(const struct tag *tag, char *output)
{
uint8_t cust_id = mirror_nibbles(tag->cust_id);
uint32_t data = mirror_nibbles(tag->data);
uint64_t code = ((uint64_t)cust_id << 8 * sizeof(data)) | data;
// Collect ID from data by bytes and conv them to DEC
uint8_t *code_bytes = (uint8_t*)&code;
char data_str[20 + 1] = "";
for (int i = 4; i >= 0; i--)
{
char byte[4 + 1];
snprintf(byte, 4 + 1, "%i:", code_bytes[i]);
strncat(data_str, byte, 4 + 1);
}
// Compute parity nibble and CRC byte
uint8_t parity = comp_parity(code);
uint8_t crc = crc8(code, parity);
// Print result
snprintf(output, OUTPUT_MAX_LEN, "255:%i:%s%i", 0xF0 + parity, data_str, crc);
return 0;
}
开发者ID:Hrubon,项目名称:rfidconv,代码行数:25,代码来源:alpus.c
示例12: sendTagCellShield
void sendTagCellShield(char *mem, const char* tag, const char* data)
{
long int tsize = strlen(tag);
long int dsize = strlen(data);
unsigned char checksum = crc8(tag, 0);
checksum = crc8(data, checksum);
//Get hex of checksum
char hex1 = getHexOfNibble(checksum >> 4);
char hex2 = getHexOfNibble(checksum);
memcpy(mem, tag, strlen(tag));
mem[tsize] = '^';
memcpy(mem + tsize + 1, data, dsize);
mem[tsize + 1 + dsize] = ':';
mem[tsize + 2 + dsize] = hex1;
mem[tsize + 3 + dsize] = hex2;
}
开发者ID:YUAA,项目名称:toaster,代码行数:16,代码来源:cAkpParser.c
示例13: sprom_read_pci
/*
* Read in and validate sprom.
* Return 0 on success, nonzero on error.
*/
static int
sprom_read_pci(uint16 *sprom, uint byteoff, uint16 *buf, uint nbytes, bool check_crc)
{
int off, nw;
uint8 chk8;
int i;
off = byteoff / 2;
nw = ROUNDUP(nbytes, 2) / 2;
/* read the sprom */
for (i = 0; i < nw; i++)
buf[i] = R_REG(&sprom[off + i]);
if (check_crc) {
/* fixup the endianness so crc8 will pass */
htol16_buf(buf, nw * 2);
if ((chk8 = crc8((uchar*)buf, nbytes, CRC8_INIT_VALUE)) != CRC8_GOOD_VALUE)
return (1);
/* now correct the endianness of the byte array */
ltoh16_buf(buf, nw * 2);
}
return (0);
}
开发者ID:BackupTheBerlios,项目名称:tuxap,代码行数:29,代码来源:bcmsrom.c
示例14: ds_read_temp
ICACHE_FLASH_ATTR
static void ds_read_temp(uint8_t *addr) {
uint8_t data[12];
ds_reset();
select(addr);
write( DS1820_READ_SCRATCHPAD, 0);
uint8_t i;
for (i = 0; i < 9; i++) {
data[i] = read();
}
if(data[8] != crc8(data, 8)) {
os_printf("ERROR - DS18B20 - CRC mismatch\n");
mqttPublishError(&mqttClient, "CRC mismatch");
// return;
}
// float arithmetic isn't really necessary, tVal and tFract are in 1/10 �C
uint16_t tVal, tFract;
char tSign;
tVal = (data[1] << 8) | data[0];
if (tVal & 0x8000) {
tVal = (tVal ^ 0xffff) + 1; // 2's complement
tSign = '-';
} else
tSign = ' ';
// datasize differs between DS18S20 and DS18B20 - 9bit vs 12bit
if (addr[0] == DS18S20) {
tFract = (tVal & 0x01) ? 50 : 0; // 1bit Fract for DS18S20
tVal >>= 1;
} else {
开发者ID:markoknez,项目名称:myThermo,代码行数:35,代码来源:ds1820.c
示例15: extract_master_key
uint8_t *
extract_master_key(const char *s, int len)
{
uint8_t *mkey = NULL; /** Master key. */
int res;
uint8_t crc;
mkey = malloc(33);
if (mkey == NULL)
return NULL;
res = pem64_decode_bytes(s, len, mkey);
if (res == 33) {
/* 33 bytes in pem - last byte should be crc8 checksum */
crc = crc8(mkey, 32);
if (crc != mkey[32]) {
fprintf(stderr,
"The provided master key's check digit is incorrect.\n"
"Please check for typing errors and character substitution.\n");
free(mkey);
return NULL;
}
} else if (res != 32) {
fprintf(stderr,
"The key given did not decode to the correct length. (%d/32)\n",
res);
free(mkey);
return NULL;
}
return mkey;
}
开发者ID:CodeOmar,项目名称:ekeyd,代码行数:31,代码来源:ekey-setkey.c
示例16: crc8
void DS1820::setScratchpad(QByteArray data)
{
scratchpad = data;
scratchpad[SCRATCHPAD_CRC] = crc8((uint8_t *)scratchpad.data(), SCRATCHPAD_COUNT - 1);
emit scratchpadChanged(scratchpad);
}
开发者ID:schuay,项目名称:qsimavr,代码行数:7,代码来源:ds1820.cpp
示例17: ParsePacket
void ParsePacket()
{
if (crc8(XBusBuffer, nXBusIndex-1) == XBusBuffer[nXBusIndex-1])
{
if (XBusBuffer[0] == 0xA4)
{
ExtractChannels();
}
if (XBusBuffer[0] == 0xD1)
{
ExtractDMX();
}
if (XBusBuffer[0] == 0x20)
{
PerformCommand(XBusBuffer);
}
if (XBusBuffer[0] == 0x21)
{
PerformStatus(XBusBuffer);
}
}
memset(XBusBuffer, 0, sizeof(XBusBuffer));
nXBusIndex = 0;
nNewPacket = 0;
}
开发者ID:simonwood,项目名称:MSP430G,代码行数:25,代码来源:XBus.c
示例18: build_data_packet_1way
static void build_data_packet_1way()
{
packet[0] = 0x0e;
packet[1] = fixed_id & 0xff;
packet[2] = fixed_id >> 8;
packet[3] = seed & 0xff;
packet[4] = seed >> 8;
if (state == FRSKY_DATA1 || state == FRSKY_DATA3)
packet[5] = 0x0f;
else if(state == FRSKY_DATA2 || state == FRSKY_DATA4)
packet[5] = 0xf0;
else
packet[5] = 0x00;
int idx = 0; //= (state == FRSKY_DATA1) ? 4 : 0;
for(int i = 0; i < 4; i++) {
if(idx + i >= Model.num_channels) {
packet[2*i + 6] = 0xc8;
packet[2*i + 7] = 0x08;
} else {
s32 value = (s32)Channels[i + idx + 6] * 0x600 / CHAN_MAX_VALUE + 0x8c8;
packet[2*i + 6] = value & 0xff;
packet[2*i + 7] = value >> 8;
}
}
packet[14] = crc8(0xa6, packet, 14);
//for(int i = 0; i < 15; i++) printf("%02x ", packet[i]); printf("\n");
}
开发者ID:caoqing32,项目名称:deviation,代码行数:27,代码来源:frsky1way_cc2500.c
示例19: while
//------------------------------------------
// Function to initialize DS18X20 sensors
void DS18B20Bus::SetupTempSensors() {
byte i, j;
byte addr[8];
byte data[9];
boolean scratchPadReaded;
//while we find some devices
while (search(addr)) {
//if ROM received is incorrect or not a DS1822 or DS18B20 THEN continue to next device
if ((crc8(addr, 7) != addr[7]) || (addr[0] != 0x22 && addr[0] != 0x28)) continue;
scratchPadReaded = ReadScratchPad(addr, data);
//if scratchPad read failed then continue to next 1-Wire device
if (!scratchPadReaded) continue;
//if config is not correct
if (data[2] != 0x50 || data[3] != 0x00 || data[4] != 0x5F) {
//write ScratchPad with Th=80°C, Tl=0°C, Config 11bit resolution
WriteScratchPad(addr, 0x50, 0x00, 0x5F);
scratchPadReaded = ReadScratchPad(addr, data);
//if scratchPad read failed then continue to next 1-Wire device
if (!scratchPadReaded) continue;
//so we finally can copy scratchpad to memory
CopyScratchPad(addr);
}
}
}
开发者ID:J6B,项目名称:Jeedom-ESP8266-Wireless-DS18B20,代码行数:34,代码来源:WebDS18B20.cpp
示例20: grclJSON
//------------------------------------------
// List DS18X20 sensor ROMCode and return it in JSON list
String DS18B20Bus::GetRomCodeListJSON() {
bool first = true;
uint8_t romCode[8];
//prepare JSON structure
String grclJSON(F("{\"TemperatureSensorList\": [\r\n"));
reset_search();
while (search(romCode)) {
//if ROM received is incorrect or not a Temperature sensor THEN continue to next device
if ((crc8(romCode, 7) != romCode[7]) || (romCode[0] != 0x10 && romCode[0] != 0x22 && romCode[0] != 0x28)) continue;
//increase grclJSON size to limit heap fragment
grclJSON.reserve(grclJSON.length() + 22);
//populate JSON answer with romCode found
if (!first) grclJSON += F(",\r\n");
else first = false;
grclJSON += '"';
for (byte i = 0; i < 8; i++) {
if (romCode[i] < 16)grclJSON += '0';
grclJSON += String(romCode[i], HEX);
}
grclJSON += '"';
}
//Finalize JSON structure
grclJSON += F("\r\n]}");
return grclJSON;
}
开发者ID:J6B,项目名称:Jeedom-ESP8266-Wireless-DS18B20,代码行数:35,代码来源:WebDS18B20.cpp
注:本文中的crc8函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论