diff --git a/src/ChecksumConverter.cc b/src/ChecksumConverter.cc index 8b50e48..8e718e0 100644 --- a/src/ChecksumConverter.cc +++ b/src/ChecksumConverter.cc @@ -2,7 +2,7 @@ * StreamDevice Support * * * * (C) 1999 Dirk Zimoch (zimoch@delta.uni-dortmund.de) * -* (C) 2006 Dirk Zimoch (dirk.zimoch@psi.ch) * +* (C) 2006-2018 Dirk Zimoch (dirk.zimoch@psi.ch) * * * * This is the checksum pseudo-converter of StreamDevice. * * Please refer to the HTML files in ../doc/ for a detailed * @@ -457,6 +457,36 @@ static unsigned int hexsum(const unsigned char* data, size_t len, unsigned int s return sum; } +// Special TRIUMF version for the CPI RF Amplifier +static unsigned int CPI(const unsigned char * data, size_t len, unsigned int init) +{ + unsigned long i = len * 32; + while (len--) + { + init += *data++; + } + init -= i; + init %= 95; + init += 32; + return init; +} + +// Leybold Graphix uses a strange sum (= notsum + fix): +// "CRC = 255 - [(Byte sum of all preceding characters) mod 256] +// If this value is lower than 32 (control character of the ASCII code), +// then 32 must be added." + +static unsigned int leybold(const unsigned char* data, size_t len, unsigned int sum) +{ + while (len--) + { + sum += *data++; + } + sum = ~sum; + if (sum < 32) sum+=32; + return sum; +} + struct checksum { const char* name; @@ -491,7 +521,9 @@ static checksum checksumMap[] = {"crc32r", crc_0x04C11DB7_r, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xCBF43926 {"jamcrc", crc_0x04C11DB7_r, 0xFFFFFFFF, 0x00000000, 4}, // 0x340BC6D9 {"adler32", adler32, 0x00000001, 0x00000000, 4}, // 0x091E01DE - {"hexsum8", hexsum, 0x00, 0x00, 1} // 0x2D + {"hexsum8", hexsum, 0x00, 0x00, 1}, // 0x2D + {"cpi", CPI, 0x00, 0x00, 1}, // 0x7E + {"leybold", leybold, 0x00, 0x00, 1}, // 0x22 }; static unsigned int mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF}; diff --git a/streamApp/checksums.cmd b/streamApp/checksums.cmd new file mode 100755 index 0000000..2c3ed77 --- /dev/null +++ b/streamApp/checksums.cmd @@ -0,0 +1,15 @@ +#!/bin/sh +exec O.$EPICS_HOST_ARCH/streamApp $0 +dbLoadDatabase "O.Common/streamApp.dbd" +streamApp_registerRecordDeviceDriver + +drvAsynIPPortConfigure "terminal", "localhost:40000" + +dbLoadRecords checksums.db + +#log debug output to file +#streamSetLogfile StreamDebug.log +var streamError 1 + +iocInit +#var streamDebug 1 diff --git a/streamApp/checksums.db b/streamApp/checksums.db new file mode 100644 index 0000000..9cbfa95 --- /dev/null +++ b/streamApp/checksums.db @@ -0,0 +1,7 @@ +record (stringout, "DZ:checksums") +{ + field (DTYP, "stream") + field (OUT, "@checksums.proto write terminal") + field (VAL, "123456789") + field (PINI, "YES") +} diff --git a/streamApp/checksums.proto b/streamApp/checksums.proto new file mode 100644 index 0000000..7897d0d --- /dev/null +++ b/streamApp/checksums.proto @@ -0,0 +1,37 @@ +Terminator = NL; + +# Output string, checksum name and checksum value +# Format checksums as ascii hex (%0 flag) +# Ignore the 12 chars (.12) between the sting (%s) and the checksum (%<...) + +write { + out "%s sum %0.12"; + out "%s sum8 %0.12"; + out "%s ~sum %0.12<~sum>"; + out "%s notsum %0.12"; + out "%s -sum %0.12<-sum>"; + out "%s negsum %0.12"; + out "%s sum16 %0.12"; + out "%s sum32 %0.12"; + out "%s xor %0.12"; + out "%s xor8 %0.12"; + out "%s xor7 %0.12"; + out "%s crc8 %0.12"; + out "%s ccitt8 %0.12"; + out "%s crc16 %0.12"; + out "%s crc16r %0.12"; + out "%s modbus %0.12"; + out "%s ccitt16 %0.12"; + out "%s ccitt16a %0.12"; + out "%s ccitt16x %0.12"; + out "%s crc16c %0.12"; + out "%s xmodem %0.12"; + out "%s crc32 %0.12"; + out "%s crc32r %0.12"; + out "%s jamcrc %0.12"; + out "%s adler32 %0.12"; + out "%s adler32b %0.12"; + out "%s hexsum8 %0.12"; + out "%s cpi %0.12"; + out "%s leybold %0.12"; +} diff --git a/streamApp/test.db b/streamApp/test.db index 283ca82..3423554 100644 --- a/streamApp/test.db +++ b/streamApp/test.db @@ -20,6 +20,11 @@ record (stringout, "$(P):request") record (stringin, "$(P):reply") { } +record (stringout, "$(P):checksum") +{ + field (DTYP, "stream") + field (OUT, "@test.proto checksum($(CHKSUM=sum)) terminal") +} record (stringin, "$(P):spy") { field (DTYP, "stream") @@ -134,3 +139,4 @@ record (waveform, "$(P):spybin") field (NELM, "2000") field (SCAN, "I/O Intr") } + diff --git a/streamApp/test.proto b/streamApp/test.proto index 4e0964f..9cae40d 100644 --- a/streamApp/test.proto +++ b/streamApp/test.proto @@ -23,3 +23,6 @@ spybin { extraInput=ignore; in "%r"; } +checksum { + out "%s %0.1<\$1>"; +}