Compare commits

...

7 Commits

Author SHA1 Message Date
20dde4c1d8 typo
Some checks failed
StreamDevice / Native Linux with 3.14 (push) Has been cancelled
StreamDevice / Native Linux with 3.15 (push) Has been cancelled
StreamDevice / Native Linux with clang (push) Has been cancelled
StreamDevice / OSX (push) Has been cancelled
StreamDevice / Native Linux (WError) (push) Has been cancelled
StreamDevice / Cross mingw64 DLL (push) Has been cancelled
StreamDevice / RTEMS 4.10 (push) Has been cancelled
StreamDevice / Cross mingw64 static (push) Has been cancelled
StreamDevice / vs2019 DLL (push) Has been cancelled
StreamDevice / vs2019 static (push) Has been cancelled
2025-05-27 17:09:16 +02:00
f61e6404f5 checksums after regsub must check original input 2025-05-27 16:57:58 +02:00
9080d6ca8e typo fixed 2025-05-23 15:28:52 +02:00
13e7f2d3dc Merge pull request #95 from henriquesimoes/scalcout-doc
Document stream-base.dbd usage when sCalcout is not needed
2025-05-22 18:42:22 +02:00
e87e093c84 in recent asyn versions vxi11 is optional 2025-05-06 14:48:59 +02:00
7debc86514 added checksum for Spellman High Voltage Supplies MPS series 2025-01-10 15:47:22 +01:00
2b3e4189c1 Document stream-base.dbd usage when scalcout is not needed
Having StreamDevice built with scalcout support does not require that
the application also depend on calc if it does not use this record
type. But this is only true if we load `stream-base.dbd` instead of
`stream.dbd`. Therefore, this alternative database definition should be
documented in the setup page.
2023-06-26 10:43:59 -03:00
8 changed files with 68 additions and 28 deletions

View File

@ -485,6 +485,12 @@ than 9.
<p>
This is not a normal "converter", because no user data is converted.
Instead, a checksum is calculated from the input or output.
<span class="new">
Any pre-processing of input, e.g. by the <a href="#regsub">regsub</a> converter
is ignored for the calculation of the checksum.
</span>
</p>
<p>
The <em>width</em> field is the byte number from which to start
calculating the checksum.
Default is 0, i.e. the first byte of the input or output of the current
@ -711,10 +717,14 @@ However if an empty string is matched, searching advances by 1 character in orde
avoid matching the same empty string again.</span>
</p>
<p>
In input this converter pre-processes data received from the device before
In input, this converter pre-processes data received from the device before
following converters read it.
Converters preceding this one will read unmodified input.
Thus place this converter before those whose input should be pre-processed.
<span class="new">
However, <a href="#chksum">checksum</a> converters will always use the unmodified
input as sent by the device because the modified input would not match the checksum.
</span>
</p>
<p>
In output it post-processes data already formatted by preceding converters

View File

@ -85,7 +85,7 @@ Make sure that the <em>asyn</em> library can be found by adding the path to the
ASYN=/home/epics/asyn4-30
</pre>
<h4>Support for <em>sCalcout</em> record</h4>
<h4 id="scalcout">Support for <em>sCalcout</em> record</h4>
<p>
The <a
href="https://htmlpreview.github.io/?https://raw.githubusercontent.com/epics-modules/calc/R3-6-1/documentation/sCalcoutRecord.html"
@ -109,7 +109,10 @@ modules. Release R2-8 or newer is recommended.
</p>
<p>
Support for the <em>sCalcout</em> is optional. <em>StreamDevice</em> works
as well without <em>sCalcout</em> or <em>SynApps</em>.
as well without <em>sCalcout</em> or <em>SynApps</em>. If your application does
not need this record support, you may load <kbd>stream-base.dbd</kbd> instead of
<kbd>stream.dbd</kbd>, making it optional to include <em>calc</em> as an
application dependency.
</p>
<h4>Support for regular expression matching</h4>
@ -185,13 +188,14 @@ Regular expressions are optional. If you don't want them, you don't need this.
Go to the <em>StreamDevice</em> directory
and run <code>make</code> (or <code>gmake</code>).
This will create and install the <em>stream</em> library and the
<kbd>stream.dbd</kbd> file and an example IOC application.
<em>StreamDevice</em> database definition files and an example IOC application.
</p>
<p>
To use <em>StreamDevice</em>, your own application must be built with the
<em>stream</em> and <em>asyn</em> (and optionally <em>pcre</em>) libraries
and must load <kbd>asyn.dbd</kbd> and <kbd>stream.dbd</kbd>.
and must load <kbd>asyn.dbd</kbd> and <kbd>stream.dbd</kbd> (or alternatively
<kbd>stream-base.dbd</kbd>; see <a href="#scalcout">Support for sCalcout record</a>).
</p>
<p>
Include the following lines in your application <kbd>Makefile</kbd>:

View File

@ -616,6 +616,16 @@ static uint32_t hexlrc(const uint8_t* data, size_t len, uint32_t sum)
return sum;
}
// Checksum used by Spellman High Voltage Supplies MPS
static uint32_t hv_mps(const uint8_t* data, size_t len, uint32_t sum)
{
while (len--)
{
sum += *data++;
}
return (~sum & 0x7F) | 0x40;
}
struct checksum
{
const char* name;
@ -665,19 +675,20 @@ static checksum checksumMap[] =
{"bitsum8", bitsum, 0x00, 0x00, 1}, // 0x21
{"bitsum16",bitsum, 0x0000, 0x0000, 2}, // 0x0021
{"bitsum32",bitsum, 0x00000000, 0x00000000, 4}, // 0x00000021
{"hv_mps", hv_mps, 0xFF, 0x00, 1} // 0x63
};
static uint32_t mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};
class ChecksumConverter : public StreamFormatConverter
{
int parse (const StreamFormat&, StreamBuffer&, const char*&, bool);
int parse (const StreamFormat&, StreamBuffer&, const char*&, bool scanFormat);
bool printPseudo(const StreamFormat&, StreamBuffer&);
ssize_t scanPseudo(const StreamFormat&, StreamBuffer&, size_t& cursor);
};
int ChecksumConverter::
parse(const StreamFormat&, StreamBuffer& info, const char*& source, bool)
parse(const StreamFormat&, StreamBuffer& info, const char*& source, bool scanFormat)
{
const char* p = strchr(source, '>');
if (!p)
@ -731,7 +742,7 @@ parse(const StreamFormat&, StreamBuffer& info, const char*& source, bool)
info.append(&xorout, sizeof(xorout));
info.append(fnum);
source = p+1;
return pseudo_format;
return scanFormat ? needs_original_format : pseudo_format;
}
}
@ -836,7 +847,7 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
else length = 0;
}
debug("ChecksumConverter %s: input to check: \"%s\n",
debug("ChecksumConverter %s: input to check: \"%s\"\n",
checksumMap[fnum].name, input.expand(start,length)());
uint8_t nDigits =
@ -848,8 +859,8 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
if ((ssize_t)( input.length() - cursor ) < expectedLength)
{
debug("ChecksumConverter %s: Input '%s' too short for checksum\n",
checksumMap[fnum].name, input.expand(cursor)());
debug("ChecksumConverter %s: Input '%s' too short (%zu-%zu<%zu) for checksum\n",
checksumMap[fnum].name, input.expand(cursor)(), input.length(), cursor, expectedLength);
return -1;
}

View File

@ -1132,7 +1132,7 @@ readCallback(StreamIoStatus status,
inputBuffer.remove(end + termlen);
if (inputBuffer)
{
debug("StreamCore::readCallback(%s) unpared input left: \"%s\"\n",
debug("StreamCore::readCallback(%s) unparsed input left: \"%s\"\n",
name(), inputBuffer.expand()());
unparsedInput = true;
}
@ -1184,6 +1184,7 @@ matchInput()
char command;
const char* fieldName = NULL;
StreamBuffer formatstring;
ssize_t delta = 0;
consumedInput = 0;
@ -1218,7 +1219,7 @@ normal_format:
debug("StreamCore::matchInput(%s): format = \"%%%s\"\n",
name(), formatstring());
if (fmt.flags & skip_flag || fmt.type == pseudo_format)
if (fmt.flags & skip_flag || fmt.type == pseudo_format || fmt.type == needs_original_format)
{
long ldummy;
double ddummy;
@ -1240,9 +1241,20 @@ normal_format:
scanString(fmt, inputLine(consumedInput), NULL, size);
break;
case pseudo_format:
// pass complete input
// pass complete input line for scan and/or re-write
size = inputLine.length();
consumed = StreamFormatConverter::find(fmt.conv)->
scanPseudo(fmt, inputLine, consumedInput);
delta += inputLine.length() - size; // track length changes
debug("after rewrite delta=%zi\n", delta);
break;
case needs_original_format:
// pass original input with adjusted current position
debug("before checksum delta=%zi\n", delta);
consumedInput -= delta; // correct for length changes
consumed = StreamFormatConverter::find(fmt.conv)->
scanPseudo(fmt, inputBuffer, consumedInput);
consumedInput += delta;
break;
default:
error("INTERNAL ERROR (%s): illegal format.type 0x%02x\n",

View File

@ -42,7 +42,8 @@ typedef enum {
enum_format,
double_format,
string_format,
pseudo_format
pseudo_format,
needs_original_format
} StreamFormatType;
extern const char* StreamFormatTypeStr[];

View File

@ -42,10 +42,12 @@ PROD_SRCS_vxWorks = -nil-
PROD_LIBS = stream
ifdef ASYN
# edit asynRegistrars.dbd if necessary
streamApp_DBD += asynRegistrars.dbd
# add asynRecord.dbd if you like
streamApp_DBD += asynRecord.dbd
streamApp_DBD += asyn.dbd
streamApp_DBD += drvAsynIPPort.dbd
streamApp_DBD += drvAsynSerialPort.dbd
# vxi11 support is optional in recent asyn versions
#streamApp_DBD += drvVxi11.dbd
PROD_LIBS += asyn
# cygwin needs separate RPC library for asyn
PROD_SYS_LIBS_cygwin32 += $(CYGWIN_RPC_LIB)

View File

@ -1,9 +0,0 @@
registrar(asynRegister)
registrar(asynInterposeFlushRegister)
registrar(asynInterposeEosRegister)
# asynDriver up to version 4-16 does not support serial port for Windows!
registrar(drvAsynSerialPortRegisterCommands)
registrar(drvAsynIPPortRegisterCommands)
registrar(drvAsynIPServerPortRegisterCommands)
registrar(vxi11RegisterCommands)

View File

@ -256,6 +256,9 @@ set protocol {
out "bitsum8 %s %#-9.1<bitsum8>"; in "bitsum8 %=s %#-9.1<bitsum8>";
out "bitsum16 %s %#-9.1<bitsum16>"; in "bitsum16 %=s %#-9.1<bitsum16>";
out "bitsum32 %s %#-9.1<bitsum32>"; in "bitsum32 %=s %#-9.1<bitsum32>";
# Check combination of regsub and checksum. Always check what the device sees.
out "crc8 %s%#/[0-9]{2}/&:/ %9.1<crc8>"; in "crc8 %#/[0-9]{2}/&:/%s %9.1<crc8>"; out "%s";
out "DONE";
}
}
@ -740,6 +743,12 @@ assure "bitsum16 123456789 \x32\x31\x30\x30\n"
send "bitsum16 123456789 \x32\x31\x30\x30\n"
assure "bitsum32 123456789 \x32\x31\x30\x30\x30\x30\x30\x30\n"
send "bitsum32 123456789 \x32\x31\x30\x30\x30\x30\x30\x30\n"
# check regsub and checksums
assure "crc8 12:34:56:78:9 \x07\n" ;# modified output string and checksum
send "crc8 123456789 \xF4\n" ;# original input string and checksum
assure "12:34:56:78:9\n" ;# modified input string
assure "DONE\n"
finish