Updated README for new efergy_optical sensor and missing recent devices.
Added support for efergy_optical.c with crc checksum calculation. whilst the code does validate the checksum it does not reject data based on invalid checksum. New library added for checksum calculations. Changed code to output results on a good checksum. Added header file for lib_crc to include directory
This commit is contained in:
parent
501573dc09
commit
3a3317948f
7 changed files with 690 additions and 4 deletions
12
README.md
12
README.md
|
@ -122,8 +122,16 @@ Supported devices:
|
|||
[50] Proove
|
||||
[51] Bresser Thermo-/Hygro-Sensor 3CH
|
||||
[52] Springfield PreciseTemp Temperature and Soil Moisture
|
||||
[53] Oregon Scientific SL109H Temperature & Humidity Sensor
|
||||
[54] TFA Pool thermometer
|
||||
[53] Oregon Scientific SL109H Temperature & Humidity Sensor
|
||||
[54] Acurite 606TX Temperature Sensor
|
||||
[55] TFA pool temperature sensor
|
||||
[56] Kedsum Temperature & Humidity Sensor
|
||||
[57] blyss DC5-UK-WH (433.92 MHz)
|
||||
[58] Steelmate TPMS
|
||||
[59] Schraeder TPMS
|
||||
[60] LightwaveRF
|
||||
[61] Elro DB286A Doorbell
|
||||
[62] Efergy Optical
|
||||
```
|
||||
|
||||
|
||||
|
|
66
include/lib_crc.h
Normal file
66
include/lib_crc.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*******************************************************************\
|
||||
* *
|
||||
* Library : lib_crc *
|
||||
* File : lib_crc.h *
|
||||
* Author : Lammert Bies 1999-2008 *
|
||||
* E-mail : info@lammertbies.nl *
|
||||
* Language : ANSI C *
|
||||
* *
|
||||
* *
|
||||
* Description *
|
||||
* =========== *
|
||||
* *
|
||||
* The file lib_crc.h contains public definitions and proto- *
|
||||
* types for the CRC functions present in lib_crc.c. *
|
||||
* *
|
||||
* *
|
||||
* Dependencies *
|
||||
* ============ *
|
||||
* *
|
||||
* none *
|
||||
* *
|
||||
* *
|
||||
* Modification history *
|
||||
* ==================== *
|
||||
* *
|
||||
* Date Version Comment *
|
||||
* *
|
||||
* 2008-04-20 1.16 Added CRC-CCITT routine for Kermit *
|
||||
* *
|
||||
* 2007-04-01 1.15 Added CRC16 calculation for Modbus *
|
||||
* *
|
||||
* 2007-03-28 1.14 Added CRC16 routine for Sick devices *
|
||||
* *
|
||||
* 2005-12-17 1.13 Added CRC-CCITT with initial 0x1D0F *
|
||||
* *
|
||||
* 2005-02-14 1.12 Added CRC-CCITT with initial 0x0000 *
|
||||
* *
|
||||
* 2005-02-05 1.11 Fixed bug in CRC-DNP routine *
|
||||
* *
|
||||
* 2005-02-04 1.10 Added CRC-DNP routines *
|
||||
* *
|
||||
* 2005-01-07 1.02 Changes in tst_crc.c *
|
||||
* *
|
||||
* 1999-02-21 1.01 Added FALSE and TRUE mnemonics *
|
||||
* *
|
||||
* 1999-01-22 1.00 Initial source *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
|
||||
|
||||
#define CRC_VERSION "1.16"
|
||||
|
||||
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
|
||||
|
||||
unsigned short update_crc_16( unsigned short crc, char c );
|
||||
unsigned long update_crc_32( unsigned long crc, char c );
|
||||
unsigned short update_crc_ccitt( unsigned short crc, char c );
|
||||
unsigned short update_crc_dnp( unsigned short crc, char c );
|
||||
unsigned short update_crc_kermit( unsigned short crc, char c );
|
||||
unsigned short update_crc_sick( unsigned short crc, char c, char prev_byte );
|
|
@ -35,7 +35,7 @@
|
|||
#define DEFAULT_LEVEL_LIMIT 8000 // Theoretical high level at I/Q saturation is 128x128 = 16384 (above is ripple)
|
||||
#define MINIMAL_BUF_LENGTH 512
|
||||
#define MAXIMAL_BUF_LENGTH (256 * 16384)
|
||||
#define MAX_PROTOCOLS 60
|
||||
#define MAX_PROTOCOLS 61
|
||||
#define SIGNAL_GRABBER_BUFFER (12 * DEFAULT_BUF_LENGTH)
|
||||
|
||||
/* Supported modulation types */
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
DECL(schraeder) \
|
||||
DECL(lightwave_rf) \
|
||||
DECL(elro_db286a) \
|
||||
DECL(efergy_optical) \
|
||||
DECL(template)
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ add_executable(rtl_433
|
|||
pulse_detect.c
|
||||
rtl_433.c
|
||||
util.c
|
||||
devices/acurite.c
|
||||
lib_crc.c
|
||||
devices/acurite.c
|
||||
devices/alecto.c
|
||||
devices/ambient_weather.c
|
||||
devices/blyss.c
|
||||
|
@ -79,6 +80,7 @@ add_executable(rtl_433
|
|||
devices/steelmate.c
|
||||
devices/schraeder.c
|
||||
devices/elro_db286a.c
|
||||
devices/efergy_optical.c
|
||||
devices/new_template.c
|
||||
|
||||
)
|
||||
|
|
149
src/devices/efergy_optical.c
Normal file
149
src/devices/efergy_optical.c
Normal file
|
@ -0,0 +1,149 @@
|
|||
/* Efergy IR is a devices that periodically reports current power consumption
|
||||
* on frequency ~433.55 MHz. The data that is transmitted consists of 8
|
||||
* bytes:
|
||||
*
|
||||
* Byte 1-4: Start bits (0000), then static data (probably device id)
|
||||
* Byte 5-7: all zeros
|
||||
* Byte 8: Pulse Count
|
||||
* Byte 9: sample frequency (15 seconds)
|
||||
* Byte 10: seconds
|
||||
* Byte 11: bytes0-10 crc16 xmodem XOR with FF
|
||||
* Byte 12: ?crc16 xmodem
|
||||
* if pulse count <3 then energy =(( pulsecount/impulse-perkwh) * (3600/seconds))
|
||||
* else energy = ((pulsecount/n_imp) * (3600/seconds))
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include "rtl_433.h"
|
||||
#include "util.h"
|
||||
#include "data.h"
|
||||
#include "lib_crc.h"
|
||||
|
||||
static int efergy_optical_callback(bitbuffer_t *bitbuffer) {
|
||||
unsigned num_bits = bitbuffer->bits_per_row[0];
|
||||
uint8_t *bytes = bitbuffer->bb[0];
|
||||
double energy, n_imp;
|
||||
double pulsecount;
|
||||
double seconds;
|
||||
data_t *data;
|
||||
char time_str[LOCAL_TIME_BUFLEN];
|
||||
unsigned short crc_ccitt_0000;
|
||||
uint8_t calcsum;
|
||||
unsigned short csum1;
|
||||
uint8_t csum2;
|
||||
|
||||
if (num_bits < 64 || num_bits > 100){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (debug_output > 1){
|
||||
fprintf(stderr,"Possible Efergy Optical: ");
|
||||
bitbuffer_print(bitbuffer);
|
||||
}
|
||||
|
||||
// The bit buffer isn't always aligned to the transmitted data, so
|
||||
// search for data start and shift out the bits which aren't part
|
||||
// of the data. The data always starts with 0000 (or 1111 if
|
||||
// gaps/pulses are mixed up).
|
||||
while ((bytes[0] & 0xf0) != 0xf0 && (bytes[0] & 0xf0) != 0x00)
|
||||
{
|
||||
num_bits -= 1;
|
||||
if (num_bits < 64)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < (num_bits + 7) / 8; ++i)
|
||||
{
|
||||
bytes[i] <<= 1;
|
||||
bytes[i] |= (bytes[i + 1] & 0x80) >> 7;
|
||||
}
|
||||
}
|
||||
|
||||
// Sometimes pulses and gaps are mixed up. If this happens, invert
|
||||
// all bytes to get correct interpretation.
|
||||
if (bytes[0] & 0xf0){
|
||||
for (unsigned i = 0; i < 11; ++i)
|
||||
{
|
||||
bytes[i] = ~bytes[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate checksum for bytes[0..10]
|
||||
crc_ccitt_0000 = 0;
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[0] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[1] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[2] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[3] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[4] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[5] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[6] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[7] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[8] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[9] );
|
||||
crc_ccitt_0000 = update_crc_ccitt( crc_ccitt_0000, bytes[10] );
|
||||
|
||||
bytes[11] = (bytes[11] ^ 0xFF);
|
||||
csum1 = (bytes[11]<<8);
|
||||
|
||||
if (crc_ccitt_0000 == csum1)
|
||||
{
|
||||
printf ("Checksum OK :) :)\n");
|
||||
printf("Calculated crc_ccitt_0000 is 0x%02X\n", crc_ccitt_0000);
|
||||
printf("Received csum1 is 0x%02X\n", csum1);
|
||||
|
||||
n_imp = 3200;
|
||||
printf ("\nEfergy Optical\nPulse per KWH default is set to %2f \n", n_imp );
|
||||
|
||||
pulsecount = bytes[8];
|
||||
seconds = bytes[10];
|
||||
|
||||
//some logic for low pulse count not sure how I reached this formula
|
||||
if (pulsecount < 3)
|
||||
{
|
||||
energy = ((pulsecount/n_imp) * (3600/seconds));
|
||||
}
|
||||
else
|
||||
{
|
||||
energy = ((pulsecount/n_imp) * (3600/30));
|
||||
}
|
||||
/* Get time now */
|
||||
local_time_str(0, time_str);
|
||||
|
||||
data = data_make("time", "", DATA_STRING, time_str,
|
||||
"model", "", DATA_STRING, "Efergy Optical",
|
||||
"energy", "Energy KWh", DATA_FORMAT,"%.03f KWh", DATA_DOUBLE, energy,
|
||||
NULL);
|
||||
data_acquired_handler(data);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Checksum not OK !!!\n");
|
||||
printf("Calculated crc_ccitt_0000 is 0x%02X\n", crc_ccitt_0000);
|
||||
printf("Received csum1 is 0x%02X\n", csum1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *output_fields[] = {
|
||||
"time",
|
||||
"model",
|
||||
"energy",
|
||||
NULL
|
||||
};
|
||||
|
||||
r_device efergy_optical = {
|
||||
.name = "Efergy Optical",
|
||||
.modulation = FSK_PULSE_PWM_RAW,
|
||||
.short_limit = 92,
|
||||
.long_limit = 400,
|
||||
.reset_limit = 400,
|
||||
.json_callback = &efergy_optical_callback,
|
||||
.disabled = 0,
|
||||
.demod_arg = 0,
|
||||
};
|
460
src/lib_crc.c
Normal file
460
src/lib_crc.c
Normal file
|
@ -0,0 +1,460 @@
|
|||
#include "lib_crc.h"
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* Library : lib_crc *
|
||||
* File : lib_crc.c *
|
||||
* Author : Lammert Bies 1999-2008 *
|
||||
* E-mail : info@lammertbies.nl *
|
||||
* Language : ANSI C *
|
||||
* *
|
||||
* *
|
||||
* Description *
|
||||
* =========== *
|
||||
* *
|
||||
* The file lib_crc.c contains the private and public func- *
|
||||
* tions used for the calculation of CRC-16, CRC-CCITT and *
|
||||
* CRC-32 cyclic redundancy values. *
|
||||
* *
|
||||
* *
|
||||
* Dependencies *
|
||||
* ============ *
|
||||
* *
|
||||
* lib_crc.h CRC definitions and prototypes *
|
||||
* *
|
||||
* *
|
||||
* Modification history *
|
||||
* ==================== *
|
||||
* *
|
||||
* Date Version Comment *
|
||||
* *
|
||||
* 2008-04-20 1.16 Added CRC-CCITT calculation for Kermit *
|
||||
* *
|
||||
* 2007-04-01 1.15 Added CRC16 calculation for Modbus *
|
||||
* *
|
||||
* 2007-03-28 1.14 Added CRC16 routine for Sick devices *
|
||||
* *
|
||||
* 2005-12-17 1.13 Added CRC-CCITT with initial 0x1D0F *
|
||||
* *
|
||||
* 2005-05-14 1.12 Added CRC-CCITT with start value 0 *
|
||||
* *
|
||||
* 2005-02-05 1.11 Fixed bug in CRC-DNP routine *
|
||||
* *
|
||||
* 2005-02-04 1.10 Added CRC-DNP routines *
|
||||
* *
|
||||
* 1999-02-21 1.01 Added FALSE and TRUE mnemonics *
|
||||
* *
|
||||
* 1999-01-22 1.00 Initial source *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* #define P_xxxx *
|
||||
* *
|
||||
* The CRC's are computed using polynomials. The coefficients *
|
||||
* for the algorithms are defined by the following constants. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
#define P_16 0xA001
|
||||
#define P_32 0xEDB88320L
|
||||
#define P_CCITT 0x1021
|
||||
#define P_DNP 0xA6BC
|
||||
#define P_KERMIT 0x8408
|
||||
#define P_SICK 0x8005
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* static int crc_tab...init *
|
||||
* static unsigned ... crc_tab...[] *
|
||||
* *
|
||||
* The algorithms use tables with precalculated values. This *
|
||||
* speeds up the calculation dramaticaly. The first time the *
|
||||
* CRC function is called, the table for that specific calcu- *
|
||||
* lation is set up. The ...init variables are used to deter- *
|
||||
* mine if the initialization has taken place. The calculated *
|
||||
* values are stored in the crc_tab... arrays. *
|
||||
* *
|
||||
* The variables are declared static. This makes them invisi- *
|
||||
* ble for other modules of the program. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
static int crc_tab16_init = FALSE;
|
||||
static int crc_tab32_init = FALSE;
|
||||
static int crc_tabccitt_init = FALSE;
|
||||
static int crc_tabdnp_init = FALSE;
|
||||
static int crc_tabkermit_init = FALSE;
|
||||
|
||||
static unsigned short crc_tab16[256];
|
||||
static unsigned long crc_tab32[256];
|
||||
static unsigned short crc_tabccitt[256];
|
||||
static unsigned short crc_tabdnp[256];
|
||||
static unsigned short crc_tabkermit[256];
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* static void init_crc...tab(); *
|
||||
* *
|
||||
* Three local functions are used to initialize the tables *
|
||||
* with values for the algorithm. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
static void init_crc16_tab( void );
|
||||
static void init_crc32_tab( void );
|
||||
static void init_crcccitt_tab( void );
|
||||
static void init_crcdnp_tab( void );
|
||||
static void init_crckermit_tab( void );
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* unsigned short update_crc_ccitt( unsigned long crc, char c ); *
|
||||
* *
|
||||
* The function update_crc_ccitt calculates a new CRC-CCITT *
|
||||
* value based on the previous value of the CRC and the next *
|
||||
* byte of the data to be checked. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
unsigned short update_crc_ccitt( unsigned short crc, char c ) {
|
||||
|
||||
unsigned short tmp, short_c;
|
||||
|
||||
short_c = 0x00ff & (unsigned short) c;
|
||||
|
||||
if ( ! crc_tabccitt_init ) init_crcccitt_tab();
|
||||
|
||||
tmp = (crc >> 8) ^ short_c;
|
||||
crc = (crc << 8) ^ crc_tabccitt[tmp];
|
||||
|
||||
return crc;
|
||||
|
||||
} /* update_crc_ccitt */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* unsigned short update_crc_sick( *
|
||||
* unsigned long crc, char c, char prev_byte ); *
|
||||
* *
|
||||
* The function update_crc_sick calculates a new CRC-SICK *
|
||||
* value based on the previous value of the CRC and the next *
|
||||
* byte of the data to be checked. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
unsigned short update_crc_sick( unsigned short crc, char c, char prev_byte ) {
|
||||
|
||||
unsigned short short_c, short_p;
|
||||
|
||||
short_c = 0x00ff & (unsigned short) c;
|
||||
short_p = ( 0x00ff & (unsigned short) prev_byte ) << 8;
|
||||
|
||||
if ( crc & 0x8000 ) crc = ( crc << 1 ) ^ P_SICK;
|
||||
else crc = crc << 1;
|
||||
|
||||
crc &= 0xffff;
|
||||
crc ^= ( short_c | short_p );
|
||||
|
||||
return crc;
|
||||
|
||||
} /* update_crc_sick */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* unsigned short update_crc_16( unsigned short crc, char c ); *
|
||||
* *
|
||||
* The function update_crc_16 calculates a new CRC-16 value *
|
||||
* based on the previous value of the CRC and the next byte *
|
||||
* of the data to be checked. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
unsigned short update_crc_16( unsigned short crc, char c ) {
|
||||
|
||||
unsigned short tmp, short_c;
|
||||
|
||||
short_c = 0x00ff & (unsigned short) c;
|
||||
|
||||
if ( ! crc_tab16_init ) init_crc16_tab();
|
||||
|
||||
tmp = crc ^ short_c;
|
||||
crc = (crc >> 8) ^ crc_tab16[ tmp & 0xff ];
|
||||
|
||||
return crc;
|
||||
|
||||
} /* update_crc_16 */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* unsigned short update_crc_kermit( unsigned short crc, char c ); *
|
||||
* *
|
||||
* The function update_crc_kermit calculates a new CRC value *
|
||||
* based on the previous value of the CRC and the next byte *
|
||||
* of the data to be checked. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
unsigned short update_crc_kermit( unsigned short crc, char c ) {
|
||||
|
||||
unsigned short tmp, short_c;
|
||||
|
||||
short_c = 0x00ff & (unsigned short) c;
|
||||
|
||||
if ( ! crc_tabkermit_init ) init_crckermit_tab();
|
||||
|
||||
tmp = crc ^ short_c;
|
||||
crc = (crc >> 8) ^ crc_tabkermit[ tmp & 0xff ];
|
||||
|
||||
return crc;
|
||||
|
||||
} /* update_crc_kermit */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* unsigned short update_crc_dnp( unsigned short crc, char c ); *
|
||||
* *
|
||||
* The function update_crc_dnp calculates a new CRC-DNP value *
|
||||
* based on the previous value of the CRC and the next byte *
|
||||
* of the data to be checked. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
unsigned short update_crc_dnp( unsigned short crc, char c ) {
|
||||
|
||||
unsigned short tmp, short_c;
|
||||
|
||||
short_c = 0x00ff & (unsigned short) c;
|
||||
|
||||
if ( ! crc_tabdnp_init ) init_crcdnp_tab();
|
||||
|
||||
tmp = crc ^ short_c;
|
||||
crc = (crc >> 8) ^ crc_tabdnp[ tmp & 0xff ];
|
||||
|
||||
return crc;
|
||||
|
||||
} /* update_crc_dnp */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* unsigned long update_crc_32( unsigned long crc, char c ); *
|
||||
* *
|
||||
* The function update_crc_32 calculates a new CRC-32 value *
|
||||
* based on the previous value of the CRC and the next byte *
|
||||
* of the data to be checked. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
unsigned long update_crc_32( unsigned long crc, char c ) {
|
||||
|
||||
unsigned long tmp, long_c;
|
||||
|
||||
long_c = 0x000000ffL & (unsigned long) c;
|
||||
|
||||
if ( ! crc_tab32_init ) init_crc32_tab();
|
||||
|
||||
tmp = crc ^ long_c;
|
||||
crc = (crc >> 8) ^ crc_tab32[ tmp & 0xff ];
|
||||
|
||||
return crc;
|
||||
|
||||
} /* update_crc_32 */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* static void init_crc16_tab( void ); *
|
||||
* *
|
||||
* The function init_crc16_tab() is used to fill the array *
|
||||
* for calculation of the CRC-16 with values. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
static void init_crc16_tab( void ) {
|
||||
|
||||
int i, j;
|
||||
unsigned short crc, c;
|
||||
|
||||
for (i=0; i<256; i++) {
|
||||
|
||||
crc = 0;
|
||||
c = (unsigned short) i;
|
||||
|
||||
for (j=0; j<8; j++) {
|
||||
|
||||
if ( (crc ^ c) & 0x0001 ) crc = ( crc >> 1 ) ^ P_16;
|
||||
else crc = crc >> 1;
|
||||
|
||||
c = c >> 1;
|
||||
}
|
||||
|
||||
crc_tab16[i] = crc;
|
||||
}
|
||||
|
||||
crc_tab16_init = TRUE;
|
||||
|
||||
} /* init_crc16_tab */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* static void init_crckermit_tab( void ); *
|
||||
* *
|
||||
* The function init_crckermit_tab() is used to fill the array *
|
||||
* for calculation of the CRC Kermit with values. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
static void init_crckermit_tab( void ) {
|
||||
|
||||
int i, j;
|
||||
unsigned short crc, c;
|
||||
|
||||
for (i=0; i<256; i++) {
|
||||
|
||||
crc = 0;
|
||||
c = (unsigned short) i;
|
||||
|
||||
for (j=0; j<8; j++) {
|
||||
|
||||
if ( (crc ^ c) & 0x0001 ) crc = ( crc >> 1 ) ^ P_KERMIT;
|
||||
else crc = crc >> 1;
|
||||
|
||||
c = c >> 1;
|
||||
}
|
||||
|
||||
crc_tabkermit[i] = crc;
|
||||
}
|
||||
|
||||
crc_tabkermit_init = TRUE;
|
||||
|
||||
} /* init_crckermit_tab */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* static void init_crcdnp_tab( void ); *
|
||||
* *
|
||||
* The function init_crcdnp_tab() is used to fill the array *
|
||||
* for calculation of the CRC-DNP with values. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
static void init_crcdnp_tab( void ) {
|
||||
|
||||
int i, j;
|
||||
unsigned short crc, c;
|
||||
|
||||
for (i=0; i<256; i++) {
|
||||
|
||||
crc = 0;
|
||||
c = (unsigned short) i;
|
||||
|
||||
for (j=0; j<8; j++) {
|
||||
|
||||
if ( (crc ^ c) & 0x0001 ) crc = ( crc >> 1 ) ^ P_DNP;
|
||||
else crc = crc >> 1;
|
||||
|
||||
c = c >> 1;
|
||||
}
|
||||
|
||||
crc_tabdnp[i] = crc;
|
||||
}
|
||||
|
||||
crc_tabdnp_init = TRUE;
|
||||
|
||||
} /* init_crcdnp_tab */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* static void init_crc32_tab( void ); *
|
||||
* *
|
||||
* The function init_crc32_tab() is used to fill the array *
|
||||
* for calculation of the CRC-32 with values. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
static void init_crc32_tab( void ) {
|
||||
|
||||
int i, j;
|
||||
unsigned long crc;
|
||||
|
||||
for (i=0; i<256; i++) {
|
||||
|
||||
crc = (unsigned long) i;
|
||||
|
||||
for (j=0; j<8; j++) {
|
||||
|
||||
if ( crc & 0x00000001L ) crc = ( crc >> 1 ) ^ P_32;
|
||||
else crc = crc >> 1;
|
||||
}
|
||||
|
||||
crc_tab32[i] = crc;
|
||||
}
|
||||
|
||||
crc_tab32_init = TRUE;
|
||||
|
||||
} /* init_crc32_tab */
|
||||
|
||||
|
||||
|
||||
/*******************************************************************\
|
||||
* *
|
||||
* static void init_crcccitt_tab( void ); *
|
||||
* *
|
||||
* The function init_crcccitt_tab() is used to fill the array *
|
||||
* for calculation of the CRC-CCITT with values. *
|
||||
* *
|
||||
\*******************************************************************/
|
||||
|
||||
static void init_crcccitt_tab( void ) {
|
||||
|
||||
int i, j;
|
||||
unsigned short crc, c;
|
||||
|
||||
for (i=0; i<256; i++) {
|
||||
|
||||
crc = 0;
|
||||
c = ((unsigned short) i) << 8;
|
||||
|
||||
for (j=0; j<8; j++) {
|
||||
|
||||
if ( (crc ^ c) & 0x8000 ) crc = ( crc << 1 ) ^ P_CCITT;
|
||||
else crc = crc << 1;
|
||||
|
||||
c = c << 1;
|
||||
}
|
||||
|
||||
crc_tabccitt[i] = crc;
|
||||
}
|
||||
|
||||
crc_tabccitt_init = TRUE;
|
||||
|
||||
} /* init_crcccitt_tab */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue