Commit 441f341a authored by Giampaolo Tomassoni's avatar Giampaolo Tomassoni Committed by Davide Galassi

CRC-16 DNP implementation: crc test update

parent d25b3750
......@@ -23,6 +23,71 @@ static void crc16_ibm_test(void)
ASSERT_EQ(crc, CRC16_IBM);
}
#if 0
static const char *ar[] = {
"HelloWorld",
"Davy",
NULL
};
#endif
static const tsm_uint8_t en_60870_5_1_pattern[] = {
0x00, 0x00, 0x00, 0x28, 0x30, 0x00, 0x3B, 0xE1,
0x58, 0x0F, 0x12, 0xA7, 0x46, 0x1B, 0x01, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00
};
struct binary_test {
char* name,
tsm_uint8_t pattern;
tsm_size_t pattern_size;
tsm_uint16_t expected;
};
static const struct binary_test brs[] = {
{
"CEI EN 60870-5-1 ref pattern",
en_60870_5_1_pattern, sizeof(en_60870_5_1_pattern),
0xea02
}
};
static void crc16_dnp_test(void)
{
int i, t;
printf("\nCTR (DNP, CEI EN 60870-5-1)\n");
for(t = 0; t < sizeof(brs)/sizeof(*brs); ++t) {
printf("CRC16(%s) = 0x%x\n", brs[t].name,
tsc_crc16_dnp(brs[t].pattern, brs[t].pattern_size));
printf("CRC16(");
tsc_crc16_dnp_init(&crc);
for (i = 0; i < brs[t].pattern_size; i++) {
printf("%02x ", brs[t].pattern[i]);
tsc_crc16_update(&crc, &brs[t].pattern[i], 1);
}
printf(") = 0x%x\n", tsc_crc16_final(&crc));
}
}
static void crc32_eth_test(void)
{
uint32_t crc;
......@@ -38,5 +103,6 @@ void crc_test(void)
TRACE("msg: %s\n", MSG);
RUN(crc16_ccitt_test);
RUN(crc16_ibm_test);
RUN(crc16_dnp3_test);
RUN(crc32_eth_test);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment