Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
20dde4c1d8 | |||
f61e6404f5 | |||
9080d6ca8e | |||
13e7f2d3dc | |||
e87e093c84 | |||
7debc86514 | |||
2b3e4189c1 |
@ -485,6 +485,12 @@ than 9.
|
|||||||
<p>
|
<p>
|
||||||
This is not a normal "converter", because no user data is converted.
|
This is not a normal "converter", because no user data is converted.
|
||||||
Instead, a checksum is calculated from the input or output.
|
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
|
The <em>width</em> field is the byte number from which to start
|
||||||
calculating the checksum.
|
calculating the checksum.
|
||||||
Default is 0, i.e. the first byte of the input or output of the current
|
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>
|
avoid matching the same empty string again.</span>
|
||||||
</p>
|
</p>
|
||||||
<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.
|
following converters read it.
|
||||||
Converters preceding this one will read unmodified input.
|
Converters preceding this one will read unmodified input.
|
||||||
Thus place this converter before those whose input should be pre-processed.
|
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>
|
||||||
<p>
|
<p>
|
||||||
In output it post-processes data already formatted by preceding converters
|
In output it post-processes data already formatted by preceding converters
|
||||||
|
@ -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
|
ASYN=/home/epics/asyn4-30
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h4>Support for <em>sCalcout</em> record</h4>
|
<h4 id="scalcout">Support for <em>sCalcout</em> record</h4>
|
||||||
<p>
|
<p>
|
||||||
The <a
|
The <a
|
||||||
href="https://htmlpreview.github.io/?https://raw.githubusercontent.com/epics-modules/calc/R3-6-1/documentation/sCalcoutRecord.html"
|
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>
|
||||||
<p>
|
<p>
|
||||||
Support for the <em>sCalcout</em> is optional. <em>StreamDevice</em> works
|
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>
|
</p>
|
||||||
|
|
||||||
<h4>Support for regular expression matching</h4>
|
<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
|
Go to the <em>StreamDevice</em> directory
|
||||||
and run <code>make</code> (or <code>gmake</code>).
|
and run <code>make</code> (or <code>gmake</code>).
|
||||||
This will create and install the <em>stream</em> library and the
|
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>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To use <em>StreamDevice</em>, your own application must be built with the
|
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
|
<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>
|
||||||
<p>
|
<p>
|
||||||
Include the following lines in your application <kbd>Makefile</kbd>:
|
Include the following lines in your application <kbd>Makefile</kbd>:
|
||||||
|
@ -616,6 +616,16 @@ static uint32_t hexlrc(const uint8_t* data, size_t len, uint32_t sum)
|
|||||||
return 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
|
struct checksum
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
@ -665,19 +675,20 @@ static checksum checksumMap[] =
|
|||||||
{"bitsum8", bitsum, 0x00, 0x00, 1}, // 0x21
|
{"bitsum8", bitsum, 0x00, 0x00, 1}, // 0x21
|
||||||
{"bitsum16",bitsum, 0x0000, 0x0000, 2}, // 0x0021
|
{"bitsum16",bitsum, 0x0000, 0x0000, 2}, // 0x0021
|
||||||
{"bitsum32",bitsum, 0x00000000, 0x00000000, 4}, // 0x00000021
|
{"bitsum32",bitsum, 0x00000000, 0x00000000, 4}, // 0x00000021
|
||||||
|
{"hv_mps", hv_mps, 0xFF, 0x00, 1} // 0x63
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint32_t mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};
|
static uint32_t mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};
|
||||||
|
|
||||||
class ChecksumConverter : public StreamFormatConverter
|
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&);
|
bool printPseudo(const StreamFormat&, StreamBuffer&);
|
||||||
ssize_t scanPseudo(const StreamFormat&, StreamBuffer&, size_t& cursor);
|
ssize_t scanPseudo(const StreamFormat&, StreamBuffer&, size_t& cursor);
|
||||||
};
|
};
|
||||||
|
|
||||||
int ChecksumConverter::
|
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, '>');
|
const char* p = strchr(source, '>');
|
||||||
if (!p)
|
if (!p)
|
||||||
@ -731,7 +742,7 @@ parse(const StreamFormat&, StreamBuffer& info, const char*& source, bool)
|
|||||||
info.append(&xorout, sizeof(xorout));
|
info.append(&xorout, sizeof(xorout));
|
||||||
info.append(fnum);
|
info.append(fnum);
|
||||||
source = p+1;
|
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;
|
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)());
|
checksumMap[fnum].name, input.expand(start,length)());
|
||||||
|
|
||||||
uint8_t nDigits =
|
uint8_t nDigits =
|
||||||
@ -848,8 +859,8 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
|
|||||||
|
|
||||||
if ((ssize_t)( input.length() - cursor ) < expectedLength)
|
if ((ssize_t)( input.length() - cursor ) < expectedLength)
|
||||||
{
|
{
|
||||||
debug("ChecksumConverter %s: Input '%s' too short for checksum\n",
|
debug("ChecksumConverter %s: Input '%s' too short (%zu-%zu<%zu) for checksum\n",
|
||||||
checksumMap[fnum].name, input.expand(cursor)());
|
checksumMap[fnum].name, input.expand(cursor)(), input.length(), cursor, expectedLength);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1132,7 +1132,7 @@ readCallback(StreamIoStatus status,
|
|||||||
inputBuffer.remove(end + termlen);
|
inputBuffer.remove(end + termlen);
|
||||||
if (inputBuffer)
|
if (inputBuffer)
|
||||||
{
|
{
|
||||||
debug("StreamCore::readCallback(%s) unpared input left: \"%s\"\n",
|
debug("StreamCore::readCallback(%s) unparsed input left: \"%s\"\n",
|
||||||
name(), inputBuffer.expand()());
|
name(), inputBuffer.expand()());
|
||||||
unparsedInput = true;
|
unparsedInput = true;
|
||||||
}
|
}
|
||||||
@ -1184,6 +1184,7 @@ matchInput()
|
|||||||
char command;
|
char command;
|
||||||
const char* fieldName = NULL;
|
const char* fieldName = NULL;
|
||||||
StreamBuffer formatstring;
|
StreamBuffer formatstring;
|
||||||
|
ssize_t delta = 0;
|
||||||
|
|
||||||
consumedInput = 0;
|
consumedInput = 0;
|
||||||
|
|
||||||
@ -1218,7 +1219,7 @@ normal_format:
|
|||||||
debug("StreamCore::matchInput(%s): format = \"%%%s\"\n",
|
debug("StreamCore::matchInput(%s): format = \"%%%s\"\n",
|
||||||
name(), formatstring());
|
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;
|
long ldummy;
|
||||||
double ddummy;
|
double ddummy;
|
||||||
@ -1240,9 +1241,20 @@ normal_format:
|
|||||||
scanString(fmt, inputLine(consumedInput), NULL, size);
|
scanString(fmt, inputLine(consumedInput), NULL, size);
|
||||||
break;
|
break;
|
||||||
case pseudo_format:
|
case pseudo_format:
|
||||||
// pass complete input
|
// pass complete input line for scan and/or re-write
|
||||||
|
size = inputLine.length();
|
||||||
consumed = StreamFormatConverter::find(fmt.conv)->
|
consumed = StreamFormatConverter::find(fmt.conv)->
|
||||||
scanPseudo(fmt, inputLine, consumedInput);
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
error("INTERNAL ERROR (%s): illegal format.type 0x%02x\n",
|
error("INTERNAL ERROR (%s): illegal format.type 0x%02x\n",
|
||||||
|
@ -42,7 +42,8 @@ typedef enum {
|
|||||||
enum_format,
|
enum_format,
|
||||||
double_format,
|
double_format,
|
||||||
string_format,
|
string_format,
|
||||||
pseudo_format
|
pseudo_format,
|
||||||
|
needs_original_format
|
||||||
} StreamFormatType;
|
} StreamFormatType;
|
||||||
|
|
||||||
extern const char* StreamFormatTypeStr[];
|
extern const char* StreamFormatTypeStr[];
|
||||||
|
@ -42,10 +42,12 @@ PROD_SRCS_vxWorks = -nil-
|
|||||||
PROD_LIBS = stream
|
PROD_LIBS = stream
|
||||||
|
|
||||||
ifdef ASYN
|
ifdef ASYN
|
||||||
# edit asynRegistrars.dbd if necessary
|
streamApp_DBD += asyn.dbd
|
||||||
streamApp_DBD += asynRegistrars.dbd
|
streamApp_DBD += drvAsynIPPort.dbd
|
||||||
# add asynRecord.dbd if you like
|
streamApp_DBD += drvAsynSerialPort.dbd
|
||||||
streamApp_DBD += asynRecord.dbd
|
# vxi11 support is optional in recent asyn versions
|
||||||
|
#streamApp_DBD += drvVxi11.dbd
|
||||||
|
|
||||||
PROD_LIBS += asyn
|
PROD_LIBS += asyn
|
||||||
# cygwin needs separate RPC library for asyn
|
# cygwin needs separate RPC library for asyn
|
||||||
PROD_SYS_LIBS_cygwin32 += $(CYGWIN_RPC_LIB)
|
PROD_SYS_LIBS_cygwin32 += $(CYGWIN_RPC_LIB)
|
||||||
|
@ -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)
|
|
@ -256,6 +256,9 @@ set protocol {
|
|||||||
out "bitsum8 %s %#-9.1<bitsum8>"; in "bitsum8 %=s %#-9.1<bitsum8>";
|
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 "bitsum16 %s %#-9.1<bitsum16>"; in "bitsum16 %=s %#-9.1<bitsum16>";
|
||||||
out "bitsum32 %s %#-9.1<bitsum32>"; in "bitsum32 %=s %#-9.1<bitsum32>";
|
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";
|
out "DONE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -740,6 +743,12 @@ assure "bitsum16 123456789 \x32\x31\x30\x30\n"
|
|||||||
send "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"
|
assure "bitsum32 123456789 \x32\x31\x30\x30\x30\x30\x30\x30\n"
|
||||||
send "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"
|
assure "DONE\n"
|
||||||
|
|
||||||
finish
|
finish
|
||||||
|
Reference in New Issue
Block a user