Compare commits

...

144 Commits

Author SHA1 Message Date
d69c74bc8f update version 2018-07-06 17:03:40 +02:00
e09506c2bb always enable error messages when loading protocol files 2018-07-06 17:02:34 +02:00
343eef324b bugfix: in quoted strings do not mis-interpret double backslash before quote or $ as escape char 2018-07-06 16:48:15 +02:00
a798cf2f21 buxfix: in regsub continue scanning only after last substitution 2018-07-06 14:37:18 +02:00
23f3e806e2 removed unfiltered debug message 2018-06-08 10:54:21 +02:00
56b6c9a627 fix for 3.16+ 2018-06-06 10:51:18 +02:00
2830f07324 update version number 2017-11-03 13:46:08 +01:00
abd8daafc3 escape all non-ascii chars to avoid problems with UTF terminals 2017-11-03 13:41:38 +01:00
489e783872 Don't change EOS if not necessary. And some improved diagnostics 2017-11-03 13:40:47 +01:00
10d1fa8b02 do not run exceprion handlers from @init 2017-11-02 09:18:24 +01:00
c8bffebfc6 fix version number 2017-11-02 09:17:47 +01:00
0a90eb3d9c fix ai/ao conversion when using LINR=NO CONVERSION together with ASLO or AOFF 2017-01-18 16:03:02 +01:00
0936ac7840 version update 2016-08-05 12:04:07 +02:00
704ece6231 Disable error messages by default in order to prevent filling the log. Set variable streamDebug to 1 to enable error messages. 2016-08-05 12:03:50 +02:00
5c6e98127e typo fixed 2016-08-05 12:01:52 +02:00
8805437c68 remove unneeded file 2016-08-02 11:18:15 +02:00
3acf791409 make docu for %r converer more specific about %.2r versus %2r 2016-07-01 10:56:46 +02:00
0ba674a341 workaround for mbboDirect bug 2016-07-01 10:38:38 +02:00
40c33abac7 workaround for mbboDirect bug 2016-07-01 10:18:34 +02:00
bc67317b0b change the meaning of pre for regsub slightly 2016-06-15 14:52:45 +02:00
06e212c66e version macros updated 2016-06-14 12:06:30 +02:00
7b314ccffd bugfix in regsub 2016-06-14 12:00:02 +02:00
1d84986ee8 do not fill log files with lock errors 2016-06-14 11:43:30 +02:00
2ca8a129f7 regsub converter added 2016-06-14 11:36:36 +02:00
126da8c499 "No reply from device" error message removed because it only fills the log files 2016-06-08 15:15:12 +02:00
ea110d5047 improved error message 2016-04-28 11:58:23 +02:00
b37fad41c6 use local variable for fieldBuffer because on some arch (Moxa ARM5) 64 bit (double) values are corrupted otherwise 2016-04-07 11:05:51 +02:00
74775996db find clean way to create dbd file 2015-12-07 17:22:40 +01:00
74426aab66 provide local strncasecmp for 3.13 2015-12-07 17:21:44 +01:00
690bbb13d4 version macros updated 2015-12-07 15:15:06 +01:00
871fbed2b0 checksums updated 2015-10-19 13:58:06 +02:00
85c68d2ae6 uppercase 2015-10-19 13:58:06 +02:00
8870611d4d modbus checksum added 2015-10-19 13:58:06 +02:00
67af7fc1bf links updated 2015-10-19 13:58:06 +02:00
93bea174e4 highlinting of new featured removed 2015-10-19 13:58:06 +02:00
84fc6aabc8 fixed witdth flag ! added 2015-10-19 13:58:06 +02:00
38c4f5bcb6 renamed to make Windows happy 2015-09-17 14:13:01 +02:00
e2af7e3149 typo fixed 2015-09-15 07:21:41 +00:00
950d75ba43 Split long_format into signed_format and unsigned_format to hangle sign extension from EPICS LONG or ULONG to long or unsigned long correctly on systems with 64 bit long. 2015-08-31 15:25:23 +00:00
e651c99697 fix tests 2015-08-18 14:34:11 +00:00
9694628d3f limit number of significant half bytes in %x formats to avoid problems on 64 bit machines 2015-08-18 14:33:48 +00:00
046582d1a0 add default choice in enum output 2015-08-18 14:32:24 +00:00
f6f0ea9ae5 fix redirection of strings to char arrays 2015-08-18 14:30:54 +00:00
018547cdf3 allow and document direct conversion from VAL/OVAL to integer to get more bits on 64 bit systems 2015-08-18 14:28:26 +00:00
d763a64f03 fix for 64 bit machines 2015-08-17 13:34:00 +00:00
cefa460a0d find correct object code 2015-08-17 13:33:35 +00:00
cc5948ad0b If ai uses no conversion, transport long i/o to and from val directly. This preverves more bits on 64 bit systems than going through the 32 bit rval field. 2015-07-17 13:24:37 +00:00
be1943a66d fix for version check 2015-06-25 16:06:39 +00:00
d9acb47afe make it work with old and new version of driver.makefile 2015-06-25 16:03:49 +00:00
b721d26fb8 avoid buffer overflow 2015-04-08 09:35:00 +00:00
7530c7c67d check for error condifiton 2015-04-08 09:34:46 +00:00
824cd4d283 debug message improved 2015-04-02 13:16:22 +00:00
2e30e7aee6 fix message when INP/OUT link is empty
fix bug with formatting arrays of char as strings in redirect
2015-04-02 13:15:46 +00:00
3a5a3e22b9 Stupid error: Minutes and seconds start from 0, not 1. 2015-02-10 16:48:39 +00:00
51bd766ba6 Fix or rather workaround for MinGW and maybe other systems without localtime_r function 2014-06-24 13:20:19 +00:00
0ab0d6db07 function pointer type problem fixed 2014-06-24 13:19:36 +00:00
a12de614d6 script to make a pdf from the hrml pages 2014-05-02 15:10:18 +00:00
240abd2788 new logo and design cleanup, printing improved 2014-05-02 15:09:49 +00:00
e131fcb32f new logo, png instead of gif, better quality 2014-05-02 15:08:36 +00:00
f88f594e87 shorter header, better for printing 2014-05-02 15:07:06 +00:00
56ef0651f2 fix for BSD Linux 2014-04-07 11:55:36 +00:00
9b9726b800 patchlevel fixed 2013-11-06 13:29:42 +00:00
b139221f0b error messages improved 2013-11-06 10:22:51 +00:00
b0ab8a7a8b write error message on write timeout 2013-11-06 09:52:39 +00:00
ddac589676 newline in report output fixed 2013-11-06 09:44:18 +00:00
5b380cdaad No connection checking before locking device. Multi-devices (GPIB) behave strangely. Get an error when device is disconnected. 2013-11-05 14:48:53 +00:00
cc9adc77fa patchlevel updated 2013-10-23 14:38:28 +00:00
2b38f7bcfa . 2013-10-23 14:36:35 +00:00
0ceada70b5 status information added 2013-10-23 14:35:08 +00:00
7bf91b403d status information added
error messages improved
dont mark device as BusOwner when locking fails
2013-10-23 14:34:53 +00:00
bf5c359649 status information added
use class for status strings to make array overrun impossible
2013-10-23 14:33:15 +00:00
c41ac44bd1 typo in comment 2013-10-23 14:31:35 +00:00
e36013d64e error messages improved
Do not queue lock request when not connected
Do not call lock callback when unlock fails
2013-10-23 14:31:00 +00:00
9e48ad3e61 typo 2013-10-02 13:09:17 +00:00
054e74d04a Do not connect unrequested.
Do not register for int/uint interrupts without need.
2013-09-20 12:06:56 +00:00
5f6319ed3d stay at version 2.6 2013-09-20 09:52:43 +00:00
2f39622a57 Error Message improved 2013-09-20 09:44:26 +00:00
7801119215 fix for cygwin 2013-06-13 15:21:12 +00:00
a6696cae49 fixes for windows 2013-06-13 15:13:53 +00:00
40b52167aa lock timeout error message added 2013-06-13 15:12:06 +00:00
814e3d53a3 version update 2013-05-16 08:49:30 +00:00
6bd46e0470 *** empty log message *** 2013-05-16 08:47:16 +00:00
d5cda13f6f version updated 2013-05-16 08:45:49 +00:00
bfc8e6a9cd Handle inverted and negative checksums generically.
Get rid of ulong and uchar typedefs. use unsigned int unstead of ulolg for return types.
2013-05-16 08:31:33 +00:00
73cba130c3 use ssize_t for signed index types. Win has no ssize_t, use ptrdiff_t instead.
use P instead of S as shortcut for PRINTF_SIZE_T_PREFIX because some OK already use S.
2013-05-16 08:28:34 +00:00
c09bc44aa4 use ssize_t for signed index types. Win has no ssize_t, use ptrdiff_t instead. 2013-05-16 08:27:24 +00:00
b907e3f469 changed shortcut for PRINTF_SIZE_T_PREFIX from S to P. Some OS use S already. 2013-05-16 08:26:01 +00:00
8c3bed09e4 more debug
init I/O Intr scanning only if init_record did not fail
2013-05-16 08:24:40 +00:00
4c99b82bb7 make name() public 2013-05-16 08:22:56 +00:00
a6d72761b9 more debug 2013-05-16 08:22:13 +00:00
6c504d30cf use size_t and ssize_t in streamBuffer 2013-04-26 12:21:51 +00:00
1c814a451b new format: %-<> prints "poor man's hex": 0x30 - 0x3f characters 2013-04-26 09:56:39 +00:00
daafc125c3 bug in debug output fixed 2013-04-26 09:56:04 +00:00
63f680bdc1 allow selecting asyn version 2013-04-24 14:27:39 +00:00
e88a327957 *** empty log message *** 2013-04-24 14:27:09 +00:00
223c71bc68 fix the fake flush: break early when no bytes are left 2013-04-24 14:25:52 +00:00
14a04fd200 handle errors in flushing read correctly 2013-04-15 07:03:49 +00:00
dc85511fe9 missing space ckeck in event command 2013-01-21 10:03:27 +00:00
d0b8d3f585 problems with 3.13 solved 2012-11-20 10:51:40 +00:00
97652917c9 Can't poll GPIB. 2012-11-08 09:27:21 +00:00
c171a62f93 Fixes for 3.15 2012-11-08 09:26:57 +00:00
c7c28e7fa2 compiler warning removed 2012-10-08 12:32:44 +00:00
79a17788f2 application developper's guide link updated 2012-09-13 13:00:06 +00:00
9f0a2d2fb6 record reference manual link updated 2012-09-13 12:23:10 +00:00
66f6ce9bd2 version release 2012-09-13 11:47:28 +00:00
e5dfe7b816 version update 2012-08-30 13:41:24 +00:00
6efb17be64 remove warning 2012-08-30 13:39:05 +00:00
0310b30446 Fixes for 3.15 2012-08-30 13:37:25 +00:00
863cdf3d7f avoid multiple inclusion of asyn.dbd 2012-08-22 12:33:20 +00:00
e51bb2555e Adjustments for 3.15: test for 3.13 instead of 3.14 2012-08-22 11:49:43 +00:00
9e0157d679 link pointer is const 2012-08-09 12:22:50 +00:00
3e91eb4fc1 Link parsing in a separate function 2012-08-09 12:22:32 +00:00
caf811c23a Improved debug message, more digits in debug timestamp. 2012-08-09 08:38:05 +00:00
de116c9e5a Dummy-read stale input instead of flushing it in order to make it available for I/O Intr records. 2012-08-09 08:37:08 +00:00
eef38b0557 check if businterface exists before calling its methods 2012-08-08 09:44:18 +00:00
0057899476 missing header 2012-08-07 14:19:51 +00:00
0148e6e27e version update 2012-08-07 14:17:46 +00:00
c6af859f9d no eol translation 2012-07-06 11:19:06 +00:00
01f0761ca8 Fixes for Windows: dll import and export 2012-07-02 16:25:55 +00:00
d7770846aa fixes for asyn 4.11+ (queueRequest fails on disconnected ports) 2012-06-19 13:45:38 +00:00
0e76ba6464 reading web pages 2012-05-16 15:53:06 +00:00
fcb44ec845 anchor for redirections 2012-05-16 15:52:43 +00:00
cec8195e5e always escape special chars and bytes 2012-05-16 14:24:21 +00:00
6c0eb32d75 Print helpful message when matching string is too long 2012-05-16 14:23:43 +00:00
9ae5f1d583 Use disconnect by server as a regular terminator (e.g. web pages) 2012-05-16 14:23:15 +00:00
3b60bb9420 put patchlevel into version string 2012-05-16 09:59:48 +00:00
db50c35ad6 get correct version of stream library 2012-05-15 15:52:29 +00:00
4f05d4e254 added constant "%" test 2012-05-15 15:51:47 +00:00
c5a17b217d high PRIO for command records 2012-05-15 15:50:59 +00:00
fdccb0c5a9 add "binary" command, update help, GUI with exit button. 2012-05-15 15:49:41 +00:00
ccbafef55a rework number parsing. make sure '%' in any numeric format gets escaped. 2012-05-15 15:37:21 +00:00
c594134317 more debug 2012-05-15 13:58:03 +00:00
11cfaf44ee use perl script instead of bash commands to create dbd file 2012-05-15 13:37:19 +00:00
a34678cbcc for 3.13 don't create variable and registrar entries 2012-05-15 13:36:14 +00:00
26fd99823c use a StreamBuffer to hold format string for later error and debug messages 2012-05-15 11:44:41 +00:00
42c305c79b Skip leading whitespaces only if neither 0 nor 1 are whitespaces. 2012-05-15 09:20:22 +00:00
9585506644 debug messages improved 2012-05-15 09:14:34 +00:00
4317ae0f75 forgot to update minot version 2012-03-21 08:45:31 +00:00
6e6c79f5ea implement decimal checksum output 2012-02-17 10:28:02 +00:00
8da0014091 need to rename StreamBuffer method printf to print because on cris architecture printf is a macro. 2012-01-04 15:49:53 +00:00
60d292b3ea calcout support was missing 2011-10-18 14:54:35 +00:00
5ce9b737cf remove compiler warning 2011-10-13 15:42:00 +00:00
7bcb494044 allow checksums in decimal ascii 2011-10-13 15:39:41 +00:00
13758eb08e bugfix: too high array index 2011-10-13 15:37:28 +00:00
90 changed files with 2869 additions and 1127 deletions

View File

@ -1,12 +1,11 @@
# Remove this file if not using the PSI build system
include /ioc/tools/driver.makefile include /ioc/tools/driver.makefile
EXCLUDE_VERSIONS = 3.13.2 EXCLUDE_VERSIONS = 3.13.2
PROJECT=stream2 PROJECT=stream
BUILDCLASSES += Linux BUILDCLASSES += Linux
#DOCUDIR = doc #DOCUDIR = doc
DBDS = stream.dbd
BUSSES += AsynDriver BUSSES += AsynDriver
BUSSES += Dummy BUSSES += Dummy
@ -34,22 +33,24 @@ SOURCES += $(FORMATS:%=src/%Converter.cc)
SOURCES += $(BUSSES:%=src/%Interface.cc) SOURCES += $(BUSSES:%=src/%Interface.cc)
SOURCES += $(wildcard src/Stream*.cc) SOURCES += $(wildcard src/Stream*.cc)
SOURCES += src/StreamVersion.c SOURCES += src/StreamVersion.c
SOURCES_3.14 += src/devcalcoutStream.c
HEADERS += devStream.h
HEADERS += StreamFormat.h HEADERS += StreamFormat.h
HEADERS += StreamFormatConverter.h HEADERS += StreamFormatConverter.h
HEADERS += StreamBuffer.h HEADERS += StreamBuffer.h
HEADERS += StreamError.h HEADERS += StreamError.h
ifeq (${EPICS_BASETYPE},3.13) ifneq (${EPICS_BASETYPE},3.13)
USR_INCLUDES += -include $(INSTALL_INCLUDE)/compat3_13.h RECORDTYPES += calcout
endif endif
StreamCore.o: streamReferences StreamCore.o StreamCore.d: streamReferences
streamReferences: streamReferences:
perl ../src/makeref.pl Interface $(BUSSES) > $@ perl ../src/makeref.pl Interface $(BUSSES) > $@
perl ../src/makeref.pl Converter $(FORMATS) >> $@ perl ../src/makeref.pl Converter $(FORMATS) >> $@
stream.dbd: export DBDFILES = streamSup.dbd
streamSup.dbd:
@echo Creating $@
perl ../src/makedbd.pl $(RECORDTYPES) > $@ perl ../src/makedbd.pl $(RECORDTYPES) > $@

5
MODULE
View File

@ -1,5 +0,0 @@
# Please change the following email with yours.
Email: dirk.zimoch@psi.ch
Module-Name: StreamDevice2
Description: StreamDevice2
Project-Name:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

BIN
doc/PSI.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: aai Records</h1> <h1>aai Records</h1>
<p> <p>
<b>Note:</b> aai record support is disabled per default. <b>Note:</b> aai record support is disabled per default.
Enable it in <code>src/CONFIG_STREAM</code>. Enable it in <code>src/CONFIG_STREAM</code>.

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: aao Records</h1> <h1>aao Records</h1>
<p> <p>
<b>Note:</b> aao record support is disabled per default. <b>Note:</b> aao record support is disabled per default.
Enable it in <code>src/CONFIG_STREAM</code>. Enable it in <code>src/CONFIG_STREAM</code>.

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: ai Records</h1> <h1>ai Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>
@ -41,6 +41,12 @@ written or read value.
(=20.0/0xFFFF) maps 0x0000 to -10.0, 0x7FFF to 0.0 and 0xFFFF to 10.0. (=20.0/0xFFFF) maps 0x0000 to -10.0, 0x7FFF to 0.0 and 0xFFFF to 10.0.
Using unsigned formats with values &ge; 0x800000 gives different results Using unsigned formats with values &ge; 0x800000 gives different results
on 64 bit machines. on 64 bit machines.
<p>
If <code>LINR=="NO CONVERSION"</code> (the default), <code>VAL</code>
is directly converted from and to <code>long</code> without going through
<code>RVAL</code>. This allows for more bits on 64 bit machines.
To get the old behavior, use <code>LINR=="LINEAR"</code>.
</p>
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -78,6 +84,6 @@ written or read value.
<a href="calcout.html">calcout</a> <a href="calcout.html">calcout</a>
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2015</small></p>
</body> </body>
</html> </html>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: ao Records</h1> <h1>ao Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>
@ -40,6 +40,12 @@ written or read value.
(=20.0/0xFFFF) maps -10.0 to 0x0000, 0.0 to 0x7FFF and 10.0 to 0xFFFF. (=20.0/0xFFFF) maps -10.0 to 0x0000, 0.0 to 0x7FFF and 10.0 to 0xFFFF.
Using unsigned formats with values &ge; 0x800000 gives different results Using unsigned formats with values &ge; 0x800000 gives different results
on 64 bit machines. on 64 bit machines.
<p>
If <code>LINR=="NO CONVERSION"</code> (the default), <code>OVAL</code>
is directly converted to <code>long</code> without going through
<code>RVAL</code>. This allows for more bits on 64 bit machines.
To get the old behavior, use <code>LINR=="LINEAR"</code>.
</p>
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -79,6 +85,6 @@ written or read value.
<a href="calcout.html">calcout</a> <a href="calcout.html">calcout</a>
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2015</small></p>
</body> </body>
</html> </html>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: bi Records</h1> <h1>bi Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: bo Records</h1> <h1>bo Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: calcout Records</h1> <h1>calcout Records</h1>
<p> <p>
<b>Note:</b> Device support for calcout records is only available for <b>Note:</b> Device support for calcout records is only available for

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Using EPICS 3.13</h1> <h1>Using EPICS 3.13</h1>
<a name="pre"></a> <a name="pre"></a>
<h2>1. Prerequisites</h2> <h2>1. Prerequisites</h2>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Format Converter API</h1> <h1>Format Converter API</h1>
<a name="class"></a> <a name="class"></a>
<h2>Converter Class</h2> <h2>Converter Class</h2>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Format Converters</h1> <h1>Format Converters</h1>
<a name="syntax"></a> <a name="syntax"></a>
<h2>1. Format Syntax</h2> <h2>1. Format Syntax</h2>
@ -28,8 +28,8 @@ A format converter consists of
</p> </p>
<ul> <ul>
<li>The <code>%</code> character</li> <li>The <code>%</code> character</li>
<li>Optionally a field <span class="new">or record</span> name in <code>()</code></li> <li>Optionally a field or record name in <code>()</code></li>
<li>Optionally flags out of the characters <code>*# +0-<span class="new">?=</span></code></li> <li>Optionally flags out of the characters <code>*# +0-?=!</code></li>
<li>Optionally an integer <em>width</em> field</li> <li>Optionally an integer <em>width</em> field</li>
<li>Optionally a period character (<code>.</code>) followed <li>Optionally a period character (<code>.</code>) followed
by an integer <em>precision</em> field (input ony for most formats)</li> by an integer <em>precision</em> field (input ony for most formats)</li>
@ -40,7 +40,7 @@ A format converter consists of
<p> <p>
The flags <code>*# +0-</code> work like in the C functions The flags <code>*# +0-</code> work like in the C functions
<em>printf()</em> and <em>scanf()</em>. <em>printf()</em> and <em>scanf()</em>.
The flags <code>?</code> and <code>=</code> are extensions. The flags <code>?</code>, <code>=</code> and <code>!</code> are extensions.
</p> </p>
<p> <p>
The <code>*</code> flag skips data in input formats. The <code>*</code> flag skips data in input formats.
@ -67,16 +67,24 @@ The <code>0</code> flag says that numbers should be left padded with
The <code>-</code> flag specifies that output is left justified if The <code>-</code> flag specifies that output is left justified if
<em>width</em> is larger than required. <em>width</em> is larger than required.
</p> </p>
<p class="new"> <p>
The <code>?</code> flag makes failing input conversions succeed with The <code>?</code> flag makes failing input conversions succeed with
a default zero value (0, 0.0, or "", depending on the format type). a default zero value (0, 0.0, or "", depending on the format type).
</p> </p>
<p class="new"> <p>
The <code>=</code> flag allows to compare input with current values. The <code>=</code> flag allows to compare input with current values.
It is only allowed in input formats. It is only allowed in input formats.
Instead of reading a new value from input, the current value is Instead of reading a new value from input, the current value is
formatted (like for output) and then compared to the input. formatted (like for output) and then compared to the input.
</p> </p>
<p>
The <code>!</code> flag demands that input is exactly <em>width</em>
bytes long (normally <em>width</em> defines the maximum number of
bytes read in many formats).
For example <code>in "%!5d";</code> expects exactly 5 digits.
Fewer digits are considered loss of data and make the format fail.
This feature has been added by Klemen Vodopivec, SNS.
</p>
<h3>Examples:</h3> <h3>Examples:</h3>
<table> <table>
@ -132,6 +140,7 @@ Thus, data type modifiers like <code>l</code> or <code>h</code> do not
exist in <em>StreamDevice</em> formats. exist in <em>StreamDevice</em> formats.
</p> </p>
<a name="redirection"></a>
<h3>Redirection</h3> <h3>Redirection</h3>
<p> <p>
To use other fields of the record or even fields of other records on the To use other fields of the record or even fields of other records on the
@ -142,11 +151,8 @@ field formatted as a string.
Use <code>in&nbsp;"%(<i>otherrecord</i>.RVAL)f";</code> to write the floating Use <code>in&nbsp;"%(<i>otherrecord</i>.RVAL)f";</code> to write the floating
point input value into the <code>RVAL</code> field of point input value into the <code>RVAL</code> field of
<code><i>otherrecord</i></code>. <code><i>otherrecord</i></code>.
<span class="new">
If no field is given for an other record .VAL is assumed. If no field is given for an other record .VAL is assumed.
When a record name conflicts with a field name use .VAL explicitly. When a record name conflicts with a field name use .VAL explicitly.
</span>
</p> </p>
<p> <p>
This feature is very useful when one line of input contains many values that should This feature is very useful when one line of input contains many values that should
@ -157,6 +163,9 @@ attribute (see
target="ex">Record Reference Manual</a>), the record will be processed. target="ex">Record Reference Manual</a>), the record will be processed.
It is your responsibility that the data type of the record field is It is your responsibility that the data type of the record field is
compatible to the the data type of the converter. compatible to the the data type of the converter.
STRING formats are compatible with arrays of CHAR or UCHAR.
</p>
<p>
Note that using this syntax is by far not as efficient as using the Note that using this syntax is by far not as efficient as using the
default field. default field.
At the moment it is not possible to set <code>otherrecord</code> to an alarm At the moment it is not possible to set <code>otherrecord</code> to an alarm
@ -188,13 +197,13 @@ With the <code>#</code> flag, output always contains a period character.
<p> <p>
<b>Input:</b> All these formats are equivalent. Leading whitespaces are skipped. <b>Input:</b> All these formats are equivalent. Leading whitespaces are skipped.
</p> </p>
<p class="new"> <p>
With the <code>#</code> flag additional whitespace between sign and number With the <code>#</code> flag additional whitespace between sign and number
is accepted. is accepted.
</p> </p>
<p class="new"> <p>
When a maximum field width is given, leading whitespace only counts to the When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is given. field witdth when the space flag is used.
</p> </p>
<a name="stdl"></a> <a name="stdl"></a>
@ -209,6 +218,10 @@ field witdth when the space flag is given.
<p> <p>
With the <code>#</code> flag, octal values are prefixed with <code>0</code> With the <code>#</code> flag, octal values are prefixed with <code>0</code>
and hexadecimal values with <code>0x</code> or <code>0X</code>. and hexadecimal values with <code>0x</code> or <code>0X</code>.
<p>
Unlike printf, <code>%x</code> and <code>%X</code> truncate the
output to the the given width (number of least significant half bytes).
</p>
</p> </p>
<p> <p>
<b>Input:</b> <code>%d</code> matches signed decimal, <code>%u</code> matches <b>Input:</b> <code>%d</code> matches signed decimal, <code>%u</code> matches
@ -220,16 +233,16 @@ Octal and hexadecimal values can optionally be prefixed.
hexadecimal notation. hexadecimal notation.
Leading whitespaces are skipped. Leading whitespaces are skipped.
</p> </p>
<p class="new"> <p>
With the <code>-</code> negative octal and hexadecimal values are accepted. With the <code>-</code> negative octal and hexadecimal values are accepted.
</p> </p>
<p class="new"> <p>
With the <code>#</code> flag additional whitespace between sign and number With the <code>#</code> flag additional whitespace between sign and number
is accepted. is accepted.
</p> </p>
<p class="new"> <p>
When a maximum field width is given, leading whitespace only counts to the When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is given. field witdth when the space flag is used.
</p> </p>
<a name="stds"></a> <a name="stds"></a>
@ -245,13 +258,11 @@ and <code>%c</code> matches a sequence of not-null characters.
The maximum string length is given by <em>width</em>. The maximum string length is given by <em>width</em>.
The default <em>width</em> is infinite for <code>%s</code> and The default <em>width</em> is infinite for <code>%s</code> and
1 for <code>%c</code>. 1 for <code>%c</code>.
Leading whitespaces are skipped with <code>%s</code> Leading whitespaces are skipped with <code>%s</code> except when
<span class="new"> the space flag is used but not with <code>%c</code>.
except when the space flag is given</span>
but not with <code>%c</code>.
The empty string matches. The empty string matches.
</p> </p>
<p class="new"> <p>
With the <code>#</code> flag <code>%s</code> matches a sequence of not-null With the <code>#</code> flag <code>%s</code> matches a sequence of not-null
characters instead of non-whitespace characters. characters instead of non-whitespace characters.
</p> </p>
@ -285,9 +296,20 @@ to the value 0, <code>STANDBY</code> to 1 and <code>ON</code> to 2.
<p> <p>
When using the <code>#</code> flag it is allowed to assign integer values When using the <code>#</code> flag it is allowed to assign integer values
to the strings using <code>=</code>. to the strings using <code>=</code>.
Unassigned strings increment their values by 1 as usual.
</p> </p>
<p> <p>
Example: <code>%#{neg=-1|stop=0|pos=1|fast=10}</code>. If one string is the initial substing of another, the substing must come
later to ensure correct matching.
In particular if one string is the emptry string, it must be the last one.
Use <code>#</code> and <code>=</code> to renumber if necessary.
</p>
<p>
Use the assignment <code>=?</code> for the last string to make it the
default value for output formats.
</p>
<p>
Example: <code>%#{neg=-1|stop|pos|fast=10|rewind=-10}</code>.
</p> </p>
<p> <p>
If one of the strings contains <code>|</code> or <code>}</code> If one of the strings contains <code>|</code> or <code>}</code>
@ -295,10 +317,11 @@ If one of the strings contains <code>|</code> or <code>}</code>
a <code>\</code> must be used to escape the character. a <code>\</code> must be used to escape the character.
</p> </p>
<p> <p>
In output, depending on the value, one of the strings is printed. <b>Output:</b> Depending on the value, one of the strings is printed,
or the default if no value matches.
</p> </p>
<p> <p>
In input, if any of the strings matches the value is set accordingly. <b>Input:</b> If any of the strings matches, the value is set accordingly.
</p> </p>
<a name="bin"></a> <a name="bin"></a>
@ -344,9 +367,12 @@ endian</em>, i.e. least significant byte first.
With the <code>0</code> flag, the value is unsigned, otherwise signed. With the <code>0</code> flag, the value is unsigned, otherwise signed.
</p> </p>
<p> <p>
In output, the <em>prec</em> (or sizeof(long) whatever is less) least In output, the <em>precision</em> (or sizeof(long) whatever is less) least
significant bytes of the value are sign extended or zero extended significant bytes of the value are sign extended or zero extended
(depending on the <code>0</code> flag) to <em>width</em> bytes. (depending on the <code>0</code> flag) to <em>width</em> bytes.
The default for <em>precision</em> is 1. Thus if you do not specify
the <em>precision</em>, only the least significant byte is written!
It is common error to write <code>out "%2r";</code> instead of <code>out "%.2r";</code>.
</p> </p>
<p> <p>
In input, <em>width</em> bytes are read and put into the value. In input, <em>width</em> bytes are read and put into the value.
@ -357,7 +383,7 @@ the value is sign extended or zero extended, depending on the
<code>0</code> flag. <code>0</code> flag.
</p> </p>
<p> <p>
Example: <code>out "%.2r"</code> Examples: <code>out "%.2r"; in "%02r";</code>
</p> </p>
<a name="rawdouble"></a> <a name="rawdouble"></a>
@ -411,7 +437,7 @@ 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
command. command.
The last byte is <em>prec</em> bytes before the checksum (default 0). The last byte is <em>precision</em> bytes before the checksum (default 0).
For example in <code>"abcdefg%&lt;xor&gt;"</code> the checksum is calculated For example in <code>"abcdefg%&lt;xor&gt;"</code> the checksum is calculated
from <code>abcdefg</code>, from <code>abcdefg</code>,
but in <code>"abcdefg%2.1&lt;xor&gt;"</code> only from <code>cdef</code>. but in <code>"abcdefg%2.1&lt;xor&gt;"</code> only from <code>cdef</code>.
@ -465,21 +491,24 @@ In input, the next byte or bytes must match the checksum.
(poly=0x07, init=0x00, xorout=0x00).</dd> (poly=0x07, init=0x00, xorout=0x00).</dd>
<dt><code>%&lt;ccitt8&gt;</code></dt> <dt><code>%&lt;ccitt8&gt;</code></dt>
<dd>One byte. The CCITT standard 8 bit crc checksum <dd>One byte. The CCITT standard 8 bit crc checksum
(poly=0x31, init=0x00, xorout=0x00).</dd> (poly=0x31, init=0x00, xorout=0x00, reflected).</dd>
<dt><code>%&lt;crc16&gt;</code></dt> <dt><code>%&lt;crc16&gt;</code></dt>
<dd>Two bytes. An often used 16 bit crc checksum <dd>Two bytes. An often used 16 bit crc checksum
(poly=0x8005, init=0x0000, xorout=0x0000).</dd> (poly=0x8005, init=0x0000, xorout=0x0000).</dd>
<dt><code>%&lt;crc16r&gt;</code></dt> <dt><code>%&lt;crc16r&gt;</code></dt>
<dd>Two bytes. An often used reflected 16 bit crc checksum <dd>Two bytes. An often used reflected 16 bit crc checksum
(poly=0x8005, init=0x0000, xorout=0x0000).</dd> (poly=0x8005, init=0x0000, xorout=0x0000, reflected).</dd>
<dt><code>%&lt;modbus&gt;</code></dt>
<dd>Two bytes. The modbus 16 bit crc checksum
(poly=0x8005, init=0xffff, xorout=0x0000, reflected)</dd>
<dt><code>%&lt;ccitt16&gt;</code></dt> <dt><code>%&lt;ccitt16&gt;</code></dt>
<dd>Two bytes. The usual (but <a target="ex" <dd>Two bytes. The usual (but <a target="ex"
href="http://www.joegeluso.com/software/articles/ccitt.htm">wrong?</a>) href="http://srecord.sourceforge.net/crc16-ccitt.html">wrong?</a>)
implementation of the CCITT standard 16 bit crc checksum implementation of the CCITT standard 16 bit crc checksum
(poly=0x1021, init=0xFFFF, xorout=0x0000).</dd> (poly=0x1021, init=0xFFFF, xorout=0x0000).</dd>
<dt><code>%&lt;ccitt16a&gt;</code></dt> <dt><code>%&lt;ccitt16a&gt;</code></dt>
<dd>Two bytes. The unusual (but <a target="ex" <dd>Two bytes. The unusual (but <a target="ex"
href="http://www.joegeluso.com/software/articles/ccitt.htm">correct?</a>) href="http://srecord.sourceforge.net/crc16-ccitt.html">correct?</a>)
implementation of the CCITT standard 16 bit crc checksum with augment. implementation of the CCITT standard 16 bit crc checksum with augment.
(poly=0x1021, init=0x1D0F, xorout=0x0000).</dd> (poly=0x1021, init=0x1D0F, xorout=0x0000).</dd>
<dt><code>%&lt;ccitt16x&gt;</code> or <code>%&lt;crc16c&gt;</code> or <code>%&lt;xmodem&gt;</code></dt> <dt><code>%&lt;ccitt16x&gt;</code> or <code>%&lt;crc16c&gt;</code> or <code>%&lt;xmodem&gt;</code></dt>
@ -490,10 +519,10 @@ In input, the next byte or bytes must match the checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd> (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd>
<dt><code>%&lt;crc32r&gt;</code></dt> <dt><code>%&lt;crc32r&gt;</code></dt>
<dd>Four bytes. The standard reflected 32 bit crc checksum. <dd>Four bytes. The standard reflected 32 bit crc checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd> (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF, reflected).</dd>
<dt><code>%&lt;jamcrc&gt;</code></dt> <dt><code>%&lt;jamcrc&gt;</code></dt>
<dd>Four bytes. Another reflected 32 bit crc checksum. <dd>Four bytes. Another reflected 32 bit crc checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0x00000000).</dd> (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0x00000000, reflected).</dd>
<dt><code>%&lt;adler32&gt;</code></dt> <dt><code>%&lt;adler32&gt;</code></dt>
<dd>Four bytes. The Adler32 checksum according to <a target="ex" <dd>Four bytes. The Adler32 checksum according to <a target="ex"
href="http://www.ietf.org/rfc/rfc1950.txt">RFC 1950</a>.</dd> href="http://www.ietf.org/rfc/rfc1950.txt">RFC 1950</a>.</dd>
@ -502,41 +531,44 @@ In input, the next byte or bytes must match the checksum.
</dl> </dl>
<a name="regex"></a> <a name="regex"></a>
<h2>12. Regular Expresion STRING Converter (<code>%/<em>regex</em>/</code>)</h2> <h2>13. Regular Expresion STRING Converter (<code>%/<em>regex</em>/</code>)</h2>
<p> <p>
This input-only format matches <a target="ex" This input-only format matches <a target="ex"
href="http://www.pcre.org/" >Perl compatible regular expressions (PCRE)</a>. href="http://www.pcre.org/" >Perl compatible regular expressions (PCRE)</a>.
It is only available if a PCRE library is installed. It is only available if a PCRE library is installed.
</p> </p>
<div class="box">
<p> <p>
If PCRE is not available for your host or cross architecture, download If PCRE is not available for your host or cross architecture, download
the sourcecode from <a target="ex" href="http://www.pcre.org/">www.pcre.org</a> the sourcecode from <a target="ex" href="http://www.pcre.org/">www.pcre.org</a>
and try my EPICS compatible <a target="ex" and try my EPICS compatible <a target="ex"
href="http://epics.web.psi.ch/software/streamdevice/pcre/Makefile">Makefile</a> href="http://epics.web.psi.ch/software/streamdevice/pcre/Makefile">Makefile</a>
to compile it like a normal EPICS application. to compile it like a normal EPICS support module.
The Makefile is known to work with EPICS 3.14.8 and PCRE 7.2. The Makefile is known to work with EPICS 3.14.8 and PCRE 7.2.
In your RELEASE file define the variable <code>PCRE</code> so that In your RELEASE file define the variable <code>PCRE</code> so that
it points to the install location of PCRE. it points to the install location of PCRE.
</p> </p>
<p> <p>
If PCRE is already installed on your system, use the variables If PCRE is already installed on (some of) your systems, you may add
<code>PCRE_INCLUDE</code> and <code>PCRE_LIB</code> instead to provide architectures where PCRE can be found in standard include and library
the install directories of <code>pcre.h</code> and the library. locations to the variable <code>WITH_SYSTEM_PCRE</code>.
</p> If either the header file or the library are in a non-standard place,
<p> set in your RELEASE file the variables <code>PCRE_INCLUDE_<em>arch</em></code>
If you have PCRE installed in different locations for different (cross) and/or <code>PCRE_LIB_<em>arch</em></code> for the respective architectures
architectures, define the variables in RELEASE.Common.&lt;architecture&gt; to the correct directories or set
instead of the global RELEASE file. <code>PCRE_INCLUDE</code> and/or <code>PCRE_LIB</code>
in architecture specific RELEASE.Common.<em>arch</em> files.
</p> </p>
</div>
<p> <p>
If the regular expression is not anchored, i.e. does not start with If the regular expression is not anchored, i.e. does not start with
<code>^</code>, leading non-matching input is skipped. <code>^</code>, leading non-matching input is skipped.
A maximum of <em>width</em> bytes is matched, if specified. A maximum of <em>width</em> bytes is matched, if specified.
If <em>prec</em> is given, it specifies the sub-expression whose match If <em>precision</em> is given, it specifies the sub-expression whose match
is retuned. is retuned.
Otherwise the complete match is returned. Otherwise the complete match is returned.
In any case, the complete match is consumed from the input buffer. In any case, the complete match is consumed from the input buffer.
If the expression contains a <code>/</code> it must be escaped. If the expression contains a <code>/</code> it must be escaped like <code>\/</code>.
</p> </p>
<p> <p>
Example: <code>%.1/&lt;title&gt;(.*)&lt;\/title&gt;/</code> returns Example: <code>%.1/&lt;title&gt;(.*)&lt;\/title&gt;/</code> returns
@ -544,8 +576,74 @@ the title of an HTML page, skipps anything before the
<code>&lt;title&gt</code> tag and leaves anything after the <code>&lt;title&gt</code> tag and leaves anything after the
<code>&lt;/title&gt;</code> tag in the input buffer. <code>&lt;/title&gt;</code> tag in the input buffer.
</p> </p>
<a name="regsub"></a>
<h2>14. Regular Expresion Substitution Pseudo-Converter (<code>%#/<em>regex</em>/<em>subst</em>/</code>)</h2>
<p>
This is a variant of the previous converter (note the <code>#</code>)
but instead of returning the matching string,
it can be used as a pre-processor for input or
as a post-processor for output.
</p>
<p>
Matches of the <em>regex</em> are replaced by the string <em>subst</em> with all
<code>&</code> or <code>\0</code> in <em>subst</em> replaced with the match itself and all
<code>\1</code> through <code>\9</code> replaced with the match of the corresponding sub-expression.
To get a literal <code>&</code> or <code>\</code> or <code>/</code> in the substitution write
<code>\&</code> or <code>\\</code> or <code>\/</code>.
There is no way to specify literal bytes with values less or equal to 9 in the
substitution!
</p>
<p>
If <em>width</em> is specified, it limits the number of characters processed.
If the <code>-</code> flag is used (i.e. <em>width</em> looks like a negative number)
only the last <em>width</em> characters are processed, else the first.
Without <em>width</em> (or 0) all available characters are processed.
</p>
<p>
If <em>precision</em> is specified, it indicates which matches to replace.
With the <code>+</code> flag given, <em>precision</em> is the maximum
number of matches to replace.
Otherwise <em>precision</em> is the index (counting from 1) of the match to replace.
Without <em>precision</em> (or 0), all matches are replaced.
</p>
<p>
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.
</p>
<p>
In output it post-processes data already formatted by preceding converters
before sending it to the device.
Converters following this one will send their output unmodified.
Thus place this converter after those whose output should be post-processed.
</p>
<p>
Examples:
<div class="indent">
<code>%#+-10.2/ab/X/</code> replaces the string <code>ab</code> with <code>X</code>
maximal 2 times in the last 10 characters.
(<code>abcabcabcabc</code> becomes <code>abcXcXcabc</code>)
</div>
<div class="indent">
<code>%#/\\/\//</code> replaces all <code>\</code> with <code>/</code>
(<code>\dir\file</code> becomes <code>/dir/file</code>)
</div>
<div class="indent">
<code>%#/..\B/&:/</code> inserts <code>:</code> after every second character
which is not at the end of a word.
(<code>0b19353134</code> becomes <code>0b:19:35:31:34</code>)
</div>
<div class="indent">
<code>%#/://</code> removes all <code>:</code> characters.
(<code>0b:19:35:31:34</code> becomes <code>0b19353134</code>)
</div>
<div class="indent">
<code>%#/([^+-])*([+-])/\2\1/</code> moves a postfix sign to the front.
(<code>1.23-</code> becomes <code>-1.23</code>)<br>
</div>
<a name="mantexp"></a> <a name="mantexp"></a>
<h2>13. MantissaExponent DOUBLE converter (<code>%m</code>)</h2> <h2>15. MantissaExponent DOUBLE converter (<code>%m</code>)</h2>
<p> <p>
This exotic and experimental format matches numbers in the format This exotic and experimental format matches numbers in the format
<i>[sign] mantissa sign exponent</i>, e.g <code>+123-4</code> meaning <i>[sign] mantissa sign exponent</i>, e.g <code>+123-4</code> meaning
@ -564,9 +662,8 @@ Format flags <code>+</code>, <code>-</code>, and space are supported in
the usual way (always sign, left justified, space instead of + sign). the usual way (always sign, left justified, space instead of + sign).
Flags <code>#</code> and <code>0</code> are unsupported. Flags <code>#</code> and <code>0</code> are unsupported.
</p> </p>
<div class="new">
<a name="timestamp"></a> <a name="timestamp"></a>
<h2>14. Timestamp DOUBLE converter (<code>%T(<em>timeformat</em>)</code>)</h2> <h2>16. Timestamp DOUBLE converter (<code>%T(<em>timeformat</em>)</code>)</h2>
<p> <p>
This format reads or writes timestamps and converts them to a double number. This format reads or writes timestamps and converts them to a double number.
The value represents the number of seconds since 1970 (the UNIX epoch). The value represents the number of seconds since 1970 (the UNIX epoch).
@ -603,7 +700,7 @@ In output, the system function <em>strftime()</em> is used to format the time.
There may be differences in the implementation between operating systems. There may be differences in the implementation between operating systems.
</p> </p>
<p> <p>
In input, <em>StreamDevice</em> used its own implementation because many In input, <em>StreamDevice</em> uses its own implementation because many
systems are missing the <em>strptime()</em> function and additional formats systems are missing the <em>strptime()</em> function and additional formats
are supported. are supported.
</p> </p>
@ -617,9 +714,8 @@ Because of the complexity of the problem, locales are not supported.
Thus, only the English month names can be used (week day names are Thus, only the English month names can be used (week day names are
ignored anyway). ignored anyway).
</p> </p>
</div>
<hr> <hr>
<p align="right"><a href="processing.html">Next: Record Processing</a></p> <p align="right"><a href="processing.html">Next: Record Processing</a></p>
<p><small>Dirk Zimoch, 2011</small></p> <p><small>Dirk Zimoch, 2015</small></p>
</body> </body>
</html> </html>

View File

@ -88,11 +88,11 @@ many process variables distributed over many records.
<h2>Recommended Readings</h2> <h2>Recommended Readings</h2>
<p> <p>
<a href="http://www.aps.anl.gov/epics/base/R3-14/8-docs/AppDevGuide.pdf" <a href="http://www.aps.anl.gov/epics/base/R3-14/12-docs/AppDevGuide"
target="ex">IOC Application Developer's Guide (PDF)</a> target="ex">IOC Application Developer's Guide</a>
</p> </p>
<p> <p>
<a href="http://www.aps.anl.gov/asd/controls/epics/EpicsDocumentation/AppDevManuals/RecordRef/Recordref-1.html" <a href="https://wiki-ext.aps.anl.gov/epics/index.php/RRM_3-14"
target="ex">EPICS Record Reference Manual</a> target="ex">EPICS Record Reference Manual</a>
</p> </p>
@ -104,13 +104,8 @@ This marks text you typically type in configuration files etc.
<pre> <pre>
Longer code segments are often set in a box. Longer code segments are often set in a box.
</pre> </pre>
<p>
Important modifications and new features are
<span class="new">highlighted with a yellow background</span>.
Obsolete features are <strike class="new">highlighted and crossed out</strike>.
</p>
<hr> <hr>
<p align="right"><a href="setup.html">Next: Setup</a></p> <p align="right"><a href="setup.html">Next: Setup</a></p>
<p><small>Dirk Zimoch, 2011</small></p> <p><small>Dirk Zimoch, 2015</small></p>
</body> </body>
</html> </html>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: longin Records</h1> <h1>longin Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: longout Records</h1> <h1>longout Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

35
doc/makepdf Executable file
View File

@ -0,0 +1,35 @@
PAGES="
index.html
setup.html
epics3_13.html
protocol.html
formats.html
processing.html
recordtypes.html
aai.html
aao.html
ai.html
ao.html
bi.html
bo.html
mbbi.html
mbbo.html
mbbiDirect.html
mbboDirect.html
stringin.html
stringout.html
longin.html
longout.html
waveform.html
calcout.html
scalcout.html
tipsandtricks.html
recordinterface.html
businterface.html
formatconverter.html
osinterface.html
"
rm -f stream.pdf
wkhtmltopdf --print-media-type --dpi 1200 --zoom 0.85 --page-size Letter \
$PAGES stream.pdf

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbbi Records</h1> <h1>mbbi Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbbiDirect Records</h1> <h1>mbbiDirect Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbbo Records</h1> <h1>mbbo Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbboDirect Records</h1> <h1>mbboDirect Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -132,6 +132,7 @@ div div div a {list-style-type:circle;}
<a target="_parent" href="formats.html#bcd" title="Binary coded decimal LONG converter">%D</a> <a target="_parent" href="formats.html#bcd" title="Binary coded decimal LONG converter">%D</a>
<a target="_parent" href="formats.html#chksum" title="Checksum pseudo converter">%&lt;<em>checksum</em>&gt;</a> <a target="_parent" href="formats.html#chksum" title="Checksum pseudo converter">%&lt;<em>checksum</em>&gt;</a>
<a target="_parent" href="formats.html#regex" title="Perl regular expression STRING converter">%/<em>regex</em>/</a> <a target="_parent" href="formats.html#regex" title="Perl regular expression STRING converter">%/<em>regex</em>/</a>
<a target="_parent" href="formats.html#regsub" title="Perl regular expression substitution pseudo converter">%#/<em>regex</em>/<em>subst</em>/</a>
<a target="_parent" href="formats.html#mantexp" title="MantissaExponent DOUBLE converter">%m</a> <a target="_parent" href="formats.html#mantexp" title="MantissaExponent DOUBLE converter">%m</a>
<a target="_parent" href="formats.html#timestamp" title="Timestamp DOUBLE converter">%T</a> <a target="_parent" href="formats.html#timestamp" title="Timestamp DOUBLE converter">%T</a>
</div> </div>
@ -178,6 +179,7 @@ div div div a {list-style-type:circle;}
<a target="_parent" href="tipsandtricks.html#writemany">Write more than one value in one message</a> <a target="_parent" href="tipsandtricks.html#writemany">Write more than one value in one message</a>
<a target="_parent" href="tipsandtricks.html#readmany">Read more than one value from one message</a> <a target="_parent" href="tipsandtricks.html#readmany">Read more than one value from one message</a>
<a target="_parent" href="tipsandtricks.html#mixed">Read values of mixed data type</a> <a target="_parent" href="tipsandtricks.html#mixed">Read values of mixed data type</a>
<a target="_parent" href="tipsandtricks.html#web">Read a web page</a>
</div> </div>
</div> </div>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Operating System API</h1> <h1>Operating System API</h1>
<h2>Sorry, this documentation is still missing.</h2> <h2>Sorry, this documentation is still missing.</h2>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Record Processing</h1> <h1>Record Processing</h1>
<a name="proc"></a> <a name="proc"></a>
<h2>1. Normal Processing</h2> <h2>1. Normal Processing</h2>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Protocol Files</h1> <h1>Protocol Files</h1>
<a name="gen"></a> <a name="gen"></a>
<h2>1. General Information</h2> <h2>1. General Information</h2>
<p> <p>
@ -261,7 +261,7 @@ number in the range of <code>-128</code> to <code>255</code>,
or <code>-0200</code> to <code>0377</code>, respectively. or <code>-0200</code> to <code>0377</code>, respectively.
</p> </p>
<p> <p>
<em>StreamDevice</em> also recordgnizes the ASCII symbolic names <em>StreamDevice</em> also recognizes the ASCII symbolic names
(not case sensitive) for several byte codes:<br> (not case sensitive) for several byte codes:<br>
<code>NUL </code>(= <code>0x00</code>) <em>null</em><br> <code>NUL </code>(= <code>0x00</code>) <em>null</em><br>
<code>SOH </code>(= <code>0x01</code>) <em>start of heading</em><br> <code>SOH </code>(= <code>0x01</code>) <em>start of heading</em><br>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Record API</h1> <h1>Record API</h1>
<h2>Sorry, this documentation is still missing.</h2> <h2>Sorry, this documentation is still missing.</h2>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Record Types</h1> <h1>Record Types</h1>
<h2>Supported Record Types</h2> <h2>Supported Record Types</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: scalcout Records</h1> <h1>scalcout Records</h1>
<p> <p>
<b>Note:</b> The scalcout record is part of the <i>calc</i> module of <b>Note:</b> The scalcout record is part of the <i>calc</i> module of

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Setup</h1> <h1>Setup</h1>
<a name="pre"></a> <a name="pre"></a>
<h2>1. Prerequisites</h2> <h2>1. Prerequisites</h2>

View File

@ -5,8 +5,9 @@ a:hover {color: #FF0000;}
body { body {
margin-right:1em; margin-right:1em;
margin-left:15em; margin-left:15em;
margin-top:11ex; margin-top:70px;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; padding-top:1px;
font-family: Helvetica, Arial, sans-serif;
font-size:14px; font-size:14px;
background-color:#ffffff; background-color:#ffffff;
} }
@ -30,26 +31,26 @@ dt {
} }
h1 { h1 {
font-size:225%; font-size:250%;
margin-top:0; margin-top:0;
font-style:italic; font-style:italic;
font-family:serif; font-weight:bold;
font-family:"Times New Roman", serif;
text-align:center; text-align:center;
position:fixed; position:fixed;
top:0; top:0;
left:0; left:0;
width:100%; width:100%;
min-height:60px;
height: 4ex;
line-height:190%; line-height:190%;
background-color:white; background-color:white;
border-top:6px solid #1b4486; border-width:0;
border-bottom:4px solid #1b4486; border-bottom:3px solid #1b4486;
white-space:nowrap; white-space:nowrap;
background-image:url(PSI.gif); background-image:url(PSI.png);
background-repeat:no-repeat; background-repeat:no-repeat;
background-position:10px 2px; background-position:10px 5px;
text-shadow: .1em .1em .1em lightgray; text-shadow:.1em .1em .1em darkgray;
box-shadow:0 .3em .1em -.2em darkgray;
} }
h2 { h2 {
@ -87,11 +88,21 @@ code {
text-align:left; text-align:left;
} }
.box {
margin-left:1ex;
margin-right:1ex;
margin-top:0.5ex;
padding: 0 1ex;
border: 1px solid black;
text-align:left;
background-color:#f0f0f0;
}
#navleft { #navleft {
position:fixed; position:fixed;
left:0; left:0;
top:0; top:0;
padding-top:9ex; padding-top:70px;
width:14em; width:14em;
height:100%; height:100%;
border-style:solid; border-style:solid;
@ -115,13 +126,9 @@ a[target=ex]:hover:after {
} }
@media print { @media print {
a:link {color: black; text-decoration:none;} a:link {text-decoration:none;}
a:visited {color: black; text-decoration:none;}
a:hover {color: black; text-decoration:none;}
a[target=ex] {text-decoration:underline;}
a[target=ex]:after {content:" [" attr(href) "]";} a[target=ex]:after {content:" [" attr(href) "]";}
code {color: black; } body {margin:0 4em;}
body {margin-left:10px;} h1 {position:relative; background-position:0 0;}
h1 {position:absolute;}
#navleft {display:none;} #navleft {display:none;}
} }

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: stringin Records</h1> <h1>stringin Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: stringout Records</h1> <h1>stringout Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Tips and Tricks</h1> <h1>Tips and Tricks</h1>
<a name="argvar"></a> <a name="argvar"></a>
<h2>I have many almost identical protocols</h2> <h2>I have many almost identical protocols</h2>
@ -103,7 +103,7 @@ an array: (3.14, 17.30, -12.34)
<h3>B) We have up to 12 numeric values</h3> <h3>B) We have up to 12 numeric values</h3>
<p> <p>
Use a <a href="calcout.html">calcout</a> record and Use a <a href="calcout.html">calcout</a> record and
<a href="formats.html#types">field references</a> in the format. <a href="formats.html#redirection">redirection to fields</a>.
</p> </p>
<p> <p>
<code> <code>
@ -128,7 +128,7 @@ record (calcout, "$(RECORD)") {<br>
</p> </p>
<h3>C) Values are in other records on the same IOC</h3> <h3>C) Values are in other records on the same IOC</h3>
<p> <p>
Use <a href="formats.html#types">record references</a> in the format. Use <a href="formats.html#redirection">redirection to records</a>.
</p> </p>
<p> <p>
<code> <code>
@ -216,7 +216,7 @@ Any non-matching input is ignored by record B.
</p> </p>
<h3>C) Values should be stored in other records on the same IOC</h3> <h3>C) Values should be stored in other records on the same IOC</h3>
<p> <p>
Use <a href="formats.html#types">record references</a> in the format. Use <a href="formats.html#redirection">redirection to records</a>.
To avoid record names in protocol files, use To avoid record names in protocol files, use
<a href="protocol.html#argvar">protocol arguments</a>. <a href="protocol.html#argvar">protocol arguments</a>.
</p> </p>
@ -244,11 +244,11 @@ processes record B.
</p> </p>
<a name="mixed"></a> <a name="mixed"></a>
<h2>I have a device that sends mixed data types: numbers and strings</h2> <h2>I have a device that sends mixed data types: numbers or strings</h2>
<p> <p>
Use a <code>@mismatch</code> Use a <code>@mismatch</code>
<a href="protocol.html#except">exception handler</a> and <a href="protocol.html#except">exception handler</a> and
<a href="formats.html#types">record references</a> in the format. <a href="formats.html#redirection">redirection to records</a>.
To avoid record names in protocol files, use To avoid record names in protocol files, use
<a href="protocol.html#argvar">protocol arguments</a>. <a href="protocol.html#argvar">protocol arguments</a>.
</p> </p>
@ -281,7 +281,7 @@ With some more records, you can clean the message record if SEVR is not INVALID.
<code> <code>
record (calcout, "$(DEVICE):clean_1") {<br> record (calcout, "$(DEVICE):clean_1") {<br>
&nbsp;&nbsp;field (INPA, "$(DEVICE):readcurrent.SEVR CP")<br> &nbsp;&nbsp;field (INPA, "$(DEVICE):readcurrent.SEVR CP")<br>
&nbsp;&nbsp;field (CALC, "A!=2")<br> &nbsp;&nbsp;field (CALC, "A#3")<br>
&nbsp;&nbsp;field (OOPT, "When Non-zero")<br> &nbsp;&nbsp;field (OOPT, "When Non-zero")<br>
&nbsp;&nbsp;field (OUT, "$(DEVICE):clean_2.PROC")<br> &nbsp;&nbsp;field (OUT, "$(DEVICE):clean_2.PROC")<br>
}<br> }<br>
@ -289,9 +289,124 @@ record (stringout, "$(DEVICE):clean_2") {<br>
&nbsp;&nbsp;field (VAL, "OK")<br> &nbsp;&nbsp;field (VAL, "OK")<br>
&nbsp;&nbsp;field (OUT, "$(DEVICE):message PP")<br> &nbsp;&nbsp;field (OUT, "$(DEVICE):message PP")<br>
}<br> }<br>
</code> </code>
<a name="web"></a>
<h2>I need to read a web page</h2>
<p>
First you have to send a correctly formatted HTML request.
Note that this request must contain the full URL like
"http://server/page" and must be terminated with <u>two</u> newlines.
The server should be the same as in the
<a href="setup.html#sta"><code>drvAsynIPPortConfigure</code></a>
command (if not using a http proxy).
The web page you get often contains much more information than you need.
<a href="formats.html#regex">Regular expressions</a> are great
to find what you are looking for.
</p>
<h3>Example 1</h3>
<p>
Read the title of a web page.
</p>
<p>
<code>
get_title {<br>
&nbsp;&nbsp;extrainput = ignore;<br>
&nbsp;&nbsp;replyTimeout = 1000;<br>
&nbsp;&nbsp;out "GET http://\$1\n\n";<br>
&nbsp;&nbsp;in "%+.1/(?im)&lt;title&gt(.*)&lt\/title&gt;/";<br>
}
</code>
</p>
<p>
Terminate the request with two newlines, either explicit like here
<u>or</u> using an
<a href="protocol.html#sysvar"><code>outTerminator</code></a>.
The URI (without http:// but including the web server host name)
is passed as <a href="protocol.html#argvar">argument</a> 1 to <code>\$1</code>.
Note that web servers may be slow, so allow some
<a href="protocol.html#argvar"><code>replyTimeout</code></a>.
</p>
<p>
If you don't use an <code>inTerminator</code> then the whole page is
read as one "line" to the <code>in</code> command and can be parsed easily
with a regular expression.
We want to see the string between <code>&lt;title&gt</code> and
<code>&lt;/title&gt;</code>, so we put it into a subexpression in
<code>()</code> and request the first subexpression with <code>.1</code>.
Note that the <code>/</code> in the closing tag has be be escaped
to avoid a misinterpretation as the closing <code>/</code> of the regular
expression.
</p>
<p>
The tags may be upper or lower case like <code>&lt;TITLE&gt;</code> or
<code>&lt;Title&gt;</code>, so we ask for case insensitive matching with
<code>(?i)</code>.
</p>
<p>
The string should be terminated with the first closing
<code>&lt;/title&gt;</code>, not the last one in the file.
(There should not be more than one title but you never know.)
Thus we ask not to be greedy with <code>(?m)</code>.
<code>(?i)</code> and <code>(?m)</code> can be combined to <code>(?im)</code>.
See the PCRE documentation for more regexp syntax.
</p>
<p>
The regular expression matcher ignores and discards any content before the
matching section.
Content after the match is discarded with <code>extrainput = ignore</code>
so that it does not trigger errors reporting "surplus input".
</p>
<p>
Finally, the title may be too long for the record.
The <code>+</code> tells the format matcher not to fail in this case
but to truncate the string instead.
You can read the string with a stringin record or for longer strings with
a waveform record with data type CHAR.
</p>
<p>
<code>
record (stringin, "$(DEVICE):title") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (INP, "@$(DEVICETYPE).proto get_title($(PAGE)) $(BUS)")<br>
}<br>
record (waveform, "$(DEVICE):longtitle") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (INP, "@$(DEVICETYPE).proto get_title($(PAGE)) $(BUS)")<br>
&nbsp;&nbsp;field (FTVL, "CHAR")<br>
&nbsp;&nbsp;field (NELM, "100")<br>
}<br>
</code>
</p>
<h3>Example 2</h3>
<p>
Read a number from a web page. First we have to locate the number.
For that we match against any known string right before the number
(and <a href="formats.html#syntax">discard the match</a> with <code>*</code>).
Then we read the number.
</p>
<code>
get_title {<br>
&nbsp;&nbsp;extrainput = ignore;<br>
&nbsp;&nbsp;replyTimeout = 1000;<br>
&nbsp;&nbsp;out "GET http://\$1\n\n";<br>
&nbsp;&nbsp;in "%*/Interesting value:/%f more text";<br>
}
</code>
<p>
When using <code>extrainput = ignore;</code>, it is always a good idea to
match a few bytes after the value, too.
This catches errors where loading of the page is interrupted in the middle
of the number. (You don't want to miss the exponent from something like 1.23E-14).
</p>
<p>
You can read more than one value from a file with successive regular expressions
and <a href="formats.html#redirection">redirections</a>.
But this only works if the order of the values is predictible.
<i>StreamDevice</i> is not an XML parser! It always reads sequentially.
</p>
<hr> <hr>
<p><small>Dirk Zimoch, 2007</small></p> <p><small>Dirk Zimoch, 2012</small></p>
</body> </body>
</html> </html>

View File

@ -10,7 +10,7 @@
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe> <iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: waveform Records</h1> <h1>waveform Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>

View File

@ -22,14 +22,14 @@
#include "StreamError.h" #include "StreamError.h"
#include "StreamBuffer.h" #include "StreamBuffer.h"
#ifdef EPICS_3_14 #ifdef EPICS_3_13
#include <epicsAssert.h>
#include <epicsTime.h>
#include <epicsTimer.h>
#else
#include <assert.h> #include <assert.h>
#include <wdLib.h> #include <wdLib.h>
#include <sysLib.h> #include <sysLib.h>
#else
#include <epicsAssert.h>
#include <epicsTime.h>
#include <epicsTimer.h>
extern "C" { extern "C" {
#include <callback.h> #include <callback.h>
} }
@ -126,7 +126,7 @@ static const char* ioActionStr[] = {
}; };
static const char* asynStatusStr[] = { static const char* asynStatusStr[] = {
"asynSuccess", "asynTimeout", "asynOverflow", "asynError" "asynSuccess", "asynTimeout", "asynOverflow", "asynError", "asynDisconnected", "asynDisabled"
}; };
static const char* eomReasonStr[] = { static const char* eomReasonStr[] = {
@ -134,7 +134,7 @@ static const char* eomReasonStr[] = {
}; };
class AsynDriverInterface : StreamBusInterface class AsynDriverInterface : StreamBusInterface
#ifdef EPICS_3_14 #ifndef EPICS_3_13
, epicsTimerNotify , epicsTimerNotify
#endif #endif
{ {
@ -164,12 +164,12 @@ class AsynDriverInterface : StreamBusInterface
const char* outputBuffer; const char* outputBuffer;
size_t outputSize; size_t outputSize;
int peeksize; int peeksize;
#ifdef EPICS_3_14 #ifdef EPICS_3_13
epicsTimerQueueActive* timerQueue;
epicsTimer* timer;
#else
WDOG_ID timer; WDOG_ID timer;
CALLBACK timeoutCallback; CALLBACK timeoutCallback;
#else
epicsTimerQueueActive* timerQueue;
epicsTimer* timer;
#endif #endif
AsynDriverInterface(Client* client); AsynDriverInterface(Client* client);
@ -189,16 +189,16 @@ class AsynDriverInterface : StreamBusInterface
bool disconnectRequest(); bool disconnectRequest();
void finish(); void finish();
#ifdef EPICS_3_14 #ifdef EPICS_3_13
static void expire(CALLBACK *pcallback);
#else
// epicsTimerNotify methods // epicsTimerNotify methods
epicsTimerNotify::expireStatus expire(const epicsTime &); epicsTimerNotify::expireStatus expire(const epicsTime &);
#else
static void expire(CALLBACK *pcallback);
#endif #endif
// local methods // local methods
void timerExpired(); void timerExpired();
bool connectToBus(const char* busname, int addr); bool connectToBus(const char* portname, int addr);
void lockHandler(); void lockHandler();
void writeHandler(); void writeHandler();
void readHandler(); void readHandler();
@ -211,20 +211,22 @@ class AsynDriverInterface : StreamBusInterface
(StreamBusInterface::priority()); (StreamBusInterface::priority());
} }
void startTimer(double timeout) { void startTimer(double timeout) {
#ifdef EPICS_3_14 #ifdef EPICS_3_13
timer->start(*this, timeout);
#else
callbackSetPriority(priority(), &timeoutCallback); callbackSetPriority(priority(), &timeoutCallback);
wdStart(timer, (int)((timeout+1)*sysClkRateGet())-1, wdStart(timer, (int)((timeout+1)*sysClkRateGet())-1,
reinterpret_cast<FUNCPTR>(callbackRequest), reinterpret_cast<FUNCPTR>(callbackRequest),
reinterpret_cast<int>(&timeoutCallback)); reinterpret_cast<int>(&timeoutCallback));
#else
timer->start(*this, timeout
+epicsThreadSleepQuantum()*0.5
);
#endif #endif
} }
void cancelTimer() { void cancelTimer() {
#ifdef EPICS_3_14 #ifdef EPICS_3_13
timer->cancel();
#else
wdCancel(timer); wdCancel(timer);
#else
timer->cancel();
#endif #endif
} }
@ -240,7 +242,7 @@ class AsynDriverInterface : StreamBusInterface
public: public:
// static creator method // static creator method
static StreamBusInterface* getBusInterface(Client* client, static StreamBusInterface* getBusInterface(Client* client,
const char* busname, int addr, const char* param); const char* portname, int addr, const char* param);
}; };
RegisterStreamBusInterface(AsynDriverInterface); RegisterStreamBusInterface(AsynDriverInterface);
@ -248,6 +250,7 @@ RegisterStreamBusInterface(AsynDriverInterface);
AsynDriverInterface:: AsynDriverInterface::
AsynDriverInterface(Client* client) : StreamBusInterface(client) AsynDriverInterface(Client* client) : StreamBusInterface(client)
{ {
debug ("AsynDriverInterface(%s)\n", client->name());
pasynCommon = NULL; pasynCommon = NULL;
pasynOctet = NULL; pasynOctet = NULL;
intrPvtOctet = NULL; intrPvtOctet = NULL;
@ -259,20 +262,25 @@ AsynDriverInterface(Client* client) : StreamBusInterface(client)
eventMask = 0; eventMask = 0;
receivedEvent = 0; receivedEvent = 0;
peeksize = 1; peeksize = 1;
debug ("AsynDriverInterface(%s) createAsynUser\n", client->name());
pasynUser = pasynManager->createAsynUser(handleRequest, pasynUser = pasynManager->createAsynUser(handleRequest,
handleTimeout); handleTimeout);
assert(pasynUser); assert(pasynUser);
pasynUser->userPvt = this; pasynUser->userPvt = this;
#ifdef EPICS_3_14 #ifdef EPICS_3_13
timerQueue = &epicsTimerQueueActive::allocate(true); debug ("AsynDriverInterface(%s) wdCreate()\n", client->name());
assert(timerQueue);
timer = &timerQueue->createTimer();
assert(timer);
#else
timer = wdCreate(); timer = wdCreate();
callbackSetCallback(expire, &timeoutCallback); callbackSetCallback(expire, &timeoutCallback);
callbackSetUser(this, &timeoutCallback); callbackSetUser(this, &timeoutCallback);
#else
debug ("AsynDriverInterface(%s) epicsTimerQueueActive::allocate(true)\n", client->name());
timerQueue = &epicsTimerQueueActive::allocate(true);
assert(timerQueue);
debug ("AsynDriverInterface(%s) timerQueue->createTimer()\n", client->name());
timer = &timerQueue->createTimer();
assert(timer);
#endif #endif
debug ("AsynDriverInterface(%s) done\n", client->name());
} }
AsynDriverInterface:: AsynDriverInterface::
@ -306,11 +314,11 @@ AsynDriverInterface::
} }
// Now, no handler is running any more and none will start. // Now, no handler is running any more and none will start.
#ifdef EPICS_3_14 #ifdef EPICS_3_13
wdDelete(timer);
#else
timer->destroy(); timer->destroy();
timerQueue->release(); timerQueue->release();
#else
wdDelete(timer);
#endif #endif
pasynManager->disconnect(pasynUser); pasynManager->disconnect(pasynUser);
pasynManager->freeAsynUser(pasynUser); pasynManager->freeAsynUser(pasynUser);
@ -318,17 +326,19 @@ AsynDriverInterface::
} }
// interface function getBusInterface(): // interface function getBusInterface():
// do we have this bus/addr ? // do we have this port/addr ?
StreamBusInterface* AsynDriverInterface:: StreamBusInterface* AsynDriverInterface::
getBusInterface(Client* client, getBusInterface(Client* client,
const char* busname, int addr, const char*) const char* portname, int addr, const char*)
{ {
debug ("AsynDriverInterface::getBusInterface(%s, %s, %d)\n",
client->name(), portname, addr);
AsynDriverInterface* interface = new AsynDriverInterface(client); AsynDriverInterface* interface = new AsynDriverInterface(client);
if (interface->connectToBus(busname, addr)) if (interface->connectToBus(portname, addr))
{ {
debug ("AsynDriverInterface::getBusInterface(%s, %d): " debug ("AsynDriverInterface::getBusInterface(%s, %d): "
"new Interface allocated\n", "new interface allocated\n",
busname, addr); portname, addr);
return interface; return interface;
} }
delete interface; delete interface;
@ -340,7 +350,66 @@ getBusInterface(Client* client,
bool AsynDriverInterface:: bool AsynDriverInterface::
supportsEvent() supportsEvent()
{ {
return (pasynInt32 != NULL) || (pasynUInt32 != NULL); if (intrPvtInt32 || intrPvtUInt32) return true;
// look for interfaces for events
asynInterface* pasynInterface;
pasynInterface = pasynManager->findInterface(pasynUser,
asynInt32Type, true);
if (pasynInterface)
{
pasynInt32 = static_cast<asynInt32*>(pasynInterface->pinterface);
pvtInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL; // required for GPIB
if (pasynInt32->registerInterruptUser(pvtInt32, pasynUser,
intrCallbackInt32, this, &intrPvtInt32) == asynSuccess)
{
printf ("%s: AsynDriverInterface::supportsEvent: "
"pasynInt32->registerInterruptUser(%p, %p, %p, %p, %p)\n",
clientName(), pvtInt32, pasynUser,
intrCallbackInt32, this, &intrPvtInt32);
return true;
}
const char *portname;
pasynManager->getPortName(pasynUser, &portname);
error("%s: port %s does not allow to register for "
"Int32 interrupts: %s\n",
clientName(), portname, pasynUser->errorMessage);
pasynInt32 = NULL;
intrPvtInt32 = NULL;
}
// no asynInt32 available, thus try asynUInt32
pasynInterface = pasynManager->findInterface(pasynUser,
asynUInt32DigitalType, true);
if (pasynInterface)
{
pasynUInt32 =
static_cast<asynUInt32Digital*>(pasynInterface->pinterface);
pvtUInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL;
if (pasynUInt32->registerInterruptUser(pvtUInt32,
pasynUser, intrCallbackUInt32, this, 0xFFFFFFFF,
&intrPvtUInt32) == asynSuccess)
{
printf ("%s: AsynDriverInterface::supportsEvent: "
"pasynUInt32->registerInterruptUser(%p, %p, %p, %p, %#X, %p)\n",
clientName(), pvtUInt32, pasynUser,
intrCallbackUInt32, this, 0xFFFFFFFF, &intrPvtInt32);
return true;
}
const char *portname;
pasynManager->getPortName(pasynUser, &portname);
error("%s: port %s does not allow to register for "
"UInt32 interrupts: %s\n",
clientName(), portname, pasynUser->errorMessage);
pasynUInt32 = NULL;
intrPvtUInt32 = NULL;
}
// no event interface available
return false;
} }
bool AsynDriverInterface:: bool AsynDriverInterface::
@ -352,20 +421,32 @@ supportsAsyncRead()
if (pasynOctet->registerInterruptUser(pvtOctet, pasynUser, if (pasynOctet->registerInterruptUser(pvtOctet, pasynUser,
intrCallbackOctet, this, &intrPvtOctet) != asynSuccess) intrCallbackOctet, this, &intrPvtOctet) != asynSuccess)
{ {
error("%s: bus does not support asynchronous input: %s\n", const char *portname;
clientName(), pasynUser->errorMessage); int addr;
pasynManager->getPortName(pasynUser, &portname);
pasynManager->getAddr(pasynUser, &addr);
if (addr >= 0)
error("%s: asyn port %s addr %d does not support asynchronous input: %s\n",
clientName(), portname, addr, pasynUser->errorMessage);
else
error("%s: asyn port %s does not support asynchronous input: %s\n",
clientName(), portname, pasynUser->errorMessage);
return false; return false;
} }
return true; return true;
} }
bool AsynDriverInterface:: bool AsynDriverInterface::
connectToBus(const char* busname, int addr) connectToBus(const char* portname, int addr)
{ {
if (pasynManager->connectDevice(pasynUser, busname, addr) != asynStatus status = pasynManager->connectDevice(pasynUser, portname, addr);
asynSuccess) debug("%s: AsynDriverInterface::connectToBus(%s, %d): "
"pasynManager->connectDevice(%p, %s, %d) = %s\n",
clientName(), portname, addr, pasynUser,portname, addr,
asynStatusStr[status]);
if (status != asynSuccess)
{ {
// asynDriver does not know this busname/address // asynDriver does not know this portname/address
return false; return false;
} }
@ -374,10 +455,10 @@ connectToBus(const char* busname, int addr)
// find the asynCommon interface // find the asynCommon interface
pasynInterface = pasynManager->findInterface(pasynUser, pasynInterface = pasynManager->findInterface(pasynUser,
asynCommonType, true); asynCommonType, true);
if(!pasynInterface) if (!pasynInterface)
{ {
error("%s: bus %s does not support asynCommon interface\n", error("%s: asyn port %s does not support asynCommon interface\n",
clientName(), busname); clientName(), portname);
return false; return false;
} }
pasynCommon = static_cast<asynCommon*>(pasynInterface->pinterface); pasynCommon = static_cast<asynCommon*>(pasynInterface->pinterface);
@ -386,10 +467,10 @@ connectToBus(const char* busname, int addr)
// find the asynOctet interface // find the asynOctet interface
pasynInterface = pasynManager->findInterface(pasynUser, pasynInterface = pasynManager->findInterface(pasynUser,
asynOctetType, true); asynOctetType, true);
if(!pasynInterface) if (!pasynInterface)
{ {
error("%s: bus %s does not support asynOctet interface\n", error("%s: asyn port %s does not support asynOctet interface\n",
clientName(), busname); clientName(), portname);
return false; return false;
} }
pasynOctet = static_cast<asynOctet*>(pasynInterface->pinterface); pasynOctet = static_cast<asynOctet*>(pasynInterface->pinterface);
@ -398,7 +479,7 @@ connectToBus(const char* busname, int addr)
// is it a GPIB interface ? // is it a GPIB interface ?
pasynInterface = pasynManager->findInterface(pasynUser, pasynInterface = pasynManager->findInterface(pasynUser,
asynGpibType, true); asynGpibType, true);
if(pasynInterface) if (pasynInterface)
{ {
pasynGpib = static_cast<asynGpib*>(pasynInterface->pinterface); pasynGpib = static_cast<asynGpib*>(pasynInterface->pinterface);
pvtGpib = pasynInterface->drvPvt; pvtGpib = pasynInterface->drvPvt;
@ -406,50 +487,6 @@ connectToBus(const char* busname, int addr)
// (read only one byte first). // (read only one byte first).
peeksize = inputBuffer.capacity(); peeksize = inputBuffer.capacity();
} }
// look for interfaces for events
pasynInterface = pasynManager->findInterface(pasynUser,
asynInt32Type, true);
if(pasynInterface)
{
pasynInt32 = static_cast<asynInt32*>(pasynInterface->pinterface);
pvtInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL; // required for GPIB
if (pasynInt32->registerInterruptUser(pvtInt32, pasynUser,
intrCallbackInt32, this, &intrPvtInt32) == asynSuccess)
{
return true;
}
error("%s: bus %s does not allow to register for "
"Int32 interrupts: %s\n",
clientName(), busname, pasynUser->errorMessage);
pasynInt32 = NULL;
intrPvtInt32 = NULL;
}
// no asynInt32 available, thus try asynUInt32
pasynInterface = pasynManager->findInterface(pasynUser,
asynUInt32DigitalType, true);
if(pasynInterface)
{
pasynUInt32 =
static_cast<asynUInt32Digital*>(pasynInterface->pinterface);
pvtUInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL;
if (pasynUInt32->registerInterruptUser(pvtUInt32,
pasynUser, intrCallbackUInt32, this, 0xFFFFFFFF,
&intrPvtUInt32) == asynSuccess)
{
return true;
}
error("%s: bus %s does not allow to register for "
"UInt32 interrupts: %s\n",
clientName(), busname, pasynUser->errorMessage);
pasynUInt32 = NULL;
intrPvtUInt32 = NULL;
}
// no event interface available, never mind
return true; return true;
} }
@ -458,23 +495,14 @@ connectToBus(const char* busname, int addr)
bool AsynDriverInterface:: bool AsynDriverInterface::
lockRequest(unsigned long lockTimeout_ms) lockRequest(unsigned long lockTimeout_ms)
{ {
int connected;
asynStatus status; asynStatus status;
debug("AsynDriverInterface::lockRequest(%s, %ld msec)\n", debug("AsynDriverInterface::lockRequest(%s, %ld msec)\n",
clientName(), lockTimeout_ms); clientName(), lockTimeout_ms);
lockTimeout = lockTimeout_ms ? lockTimeout_ms*0.001 : -1.0; lockTimeout = lockTimeout_ms ? lockTimeout_ms*0.001 : -1.0;
ioAction = Lock; ioAction = Lock;
status = pasynManager->isConnected(pasynUser, &connected);
if (status != asynSuccess)
{
error("%s: pasynManager->isConnected() failed: %s\n",
clientName(), pasynUser->errorMessage);
return false;
}
status = pasynManager->queueRequest(pasynUser, status = pasynManager->queueRequest(pasynUser,
connected ? priority() : asynQueuePriorityConnect, priority(), lockTimeout);
lockTimeout);
if (status != asynSuccess) if (status != asynSuccess)
{ {
error("%s lockRequest: pasynManager->queueRequest() failed: %s\n", error("%s lockRequest: pasynManager->queueRequest() failed: %s\n",
@ -496,9 +524,13 @@ connectToAsynPort()
debug("AsynDriverInterface::connectToAsynPort(%s)\n", debug("AsynDriverInterface::connectToAsynPort(%s)\n",
clientName()); clientName());
status = pasynManager->isConnected(pasynUser, &connected); status = pasynManager->isConnected(pasynUser, &connected);
debug("%s: AsynDriverInterface::connectToAsynPort: "
"pasynManager->isConnected(%p, %p) = %s => %s\n",
clientName(), pasynUser, &connected, asynStatusStr[status],
connected ? "yes" : "no");
if (status != asynSuccess) if (status != asynSuccess)
{ {
error("%s: pasynManager->isConnected() failed: %s\n", error("%s connectToAsynPort: pasynManager->isConnected() failed: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
return false; return false;
} }
@ -516,7 +548,7 @@ connectToAsynPort()
status = pasynOctet->read(pvtOctet, pasynUser, status = pasynOctet->read(pvtOctet, pasynUser,
buffer, 0, &received, &eomReason); buffer, 0, &received, &eomReason);
debug("AsynDriverInterface::connectToAsynPort(%s): " debug("AsynDriverInterface::connectToAsynPort(%s): "
"read(..., 0, ...) [timeout=%f seconds] = %s\n", "read(..., 0, ...) [timeout=%g sec] = %s\n",
clientName(), pasynUser->timeout, clientName(), pasynUser->timeout,
asynStatusStr[status]); asynStatusStr[status]);
pasynManager->isConnected(pasynUser, &connected); pasynManager->isConnected(pasynUser, &connected);
@ -536,7 +568,7 @@ connectToAsynPort()
clientName(), asynStatusStr[status]); clientName(), asynStatusStr[status]);
if (status != asynSuccess) if (status != asynSuccess)
{ {
error("%s: pasynCommon->connect() failed: %s\n", error("%s connectToAsynPort: pasynCommon->connect() failed: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
return false; return false;
} }
@ -554,21 +586,37 @@ connectToAsynPort()
void AsynDriverInterface:: void AsynDriverInterface::
lockHandler() lockHandler()
{ {
int connected; asynStatus status;
debug("AsynDriverInterface::lockHandler(%s)\n", debug("AsynDriverInterface::lockHandler(%s)\n",
clientName()); clientName());
pasynManager->blockProcessCallback(pasynUser, false);
connected = connectToAsynPort(); status = pasynManager->blockProcessCallback(pasynUser, false);
lockCallback(connected ? StreamIoSuccess : StreamIoFault); if (status != asynSuccess)
{
error("%s lockHandler: pasynManager->blockProcessCallback() failed: %s\n",
clientName(), pasynUser->errorMessage);
lockCallback(StreamIoFault);
return;
}
lockCallback(StreamIoSuccess);
} }
// interface function: we don't need exclusive access any more // interface function: we don't need exclusive access any more
bool AsynDriverInterface:: bool AsynDriverInterface::
unlock() unlock()
{ {
asynStatus status;
debug("AsynDriverInterface::unlock(%s)\n", debug("AsynDriverInterface::unlock(%s)\n",
clientName()); clientName());
pasynManager->unblockProcessCallback(pasynUser, false); status = pasynManager->unblockProcessCallback(pasynUser, false);
if (status != asynSuccess)
{
error("%s unlock: pasynManager->unblockProcessCallback() failed: %s\n",
clientName(), pasynUser->errorMessage);
return false;
}
return true; return true;
} }
@ -610,19 +658,39 @@ writeHandler()
clientName()); clientName());
asynStatus status; asynStatus status;
size_t written = 0; size_t written = 0;
pasynUser->timeout = writeTimeout;
// discard any early input or early events pasynUser->timeout = 0;
status = pasynOctet->flush(pvtOctet, pasynUser); if (!pasynGpib)
receivedEvent = 0; // discard any early input, but forward it to potential async records
// thus do not use pasynOctet->flush()
if (status != asynSuccess) // unfortunately we cannot do this with GPIB because addressing a device as talker
// when it has nothing to say is an error. Also timeout=0 does not help here (would need
// a change in asynGPIB), thus use flush() for GPIB.
do {
char buffer [256];
size_t received = 0;
int eomReason = 0;
debug("AsynDriverInterface::writeHandler(%s): reading old input\n",
clientName());
status = pasynOctet->read(pvtOctet, pasynUser,
buffer, sizeof(buffer), &received, &eomReason);
if (status == asynError || received == 0) break;
#ifndef NO_TEMPORARY
if (received) debug("AsynDriverInterface::writeHandler(%s): flushing %ld bytes: \"%s\"\n",
clientName(), (long)received, StreamBuffer(buffer, received).expand()());
#endif
} while (status == asynSuccess);
else
{ {
error("%s: pasynOctet->flush() failed: %s\n", debug("AsynDriverInterface::writeHandler(%s): flushing old input\n",
clientName(), pasynUser->errorMessage); clientName());
writeCallback(StreamIoFault); pasynOctet->flush(pvtOctet, pasynUser);
return;
} }
// discard any early events
receivedEvent = 0;
pasynUser->timeout = writeTimeout;
// has stream already added a terminator or should // has stream already added a terminator or should
// asyn do so? // asyn do so?
@ -644,14 +712,26 @@ writeHandler()
pasynOctet->setOutputEos(pvtOctet, pasynUser, pasynOctet->setOutputEos(pvtOctet, pasynUser,
NULL, 0); NULL, 0);
} }
pasynUser->errorMessage[0] = 0;
status = pasynOctet->write(pvtOctet, pasynUser, status = pasynOctet->write(pvtOctet, pasynUser,
outputBuffer, outputSize, &written); outputBuffer, outputSize, &written);
#ifndef NO_TEMPORARY
debug("AsynDriverInterface::writeHandler(%s): " debug("AsynDriverInterface::writeHandler(%s): "
"write(..., outputSize=%ld, written=%ld) " "write(..., \"%s\", outputSize=%ld, written=%ld) "
"[timeout=%f seconds] = %s\n", "[timeout=%g sec] = %s (%s)\n",
clientName(), (long)outputSize, (long)written, clientName(),
pasynUser->timeout, asynStatusStr[status]); StreamBuffer(outputBuffer, outputSize).expand()(),
(long)outputSize, (long)written,
pasynUser->timeout, asynStatusStr[status],
pasynUser->errorMessage);
#endif
if (oldeoslen >= 0) // restore asyn terminator
{
pasynOctet->setOutputEos(pvtOctet, pasynUser,
oldeos, oldeoslen);
}
// Up to asyn 4.17 I can't see when the server has disconnected. Why? // Up to asyn 4.17 I can't see when the server has disconnected. Why?
int connected; int connected;
pasynManager->isConnected(pasynUser, &connected); pasynManager->isConnected(pasynUser, &connected);
@ -659,17 +739,12 @@ writeHandler()
"device is %sconnected\n", "device is %sconnected\n",
clientName(),connected?"":"dis"); clientName(),connected?"":"dis");
if (!connected) { if (!connected) {
error("%s: connection closed in write\n", error("%s: write failed because connection was closed by device\n",
clientName()); clientName());
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
} }
if (oldeoslen >= 0) // restore asyn terminator
{
pasynOctet->setOutputEos(pvtOctet, pasynUser,
oldeos, oldeoslen);
}
switch (status) switch (status)
{ {
case asynSuccess: case asynSuccess:
@ -694,32 +769,34 @@ writeHandler()
writeCallback(StreamIoSuccess); writeCallback(StreamIoSuccess);
return; return;
case asynTimeout: case asynTimeout:
error("%s: asynTimeout (%g sec) in write. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->timeout, pasynUser->errorMessage);
writeCallback(StreamIoTimeout); writeCallback(StreamIoTimeout);
return; return;
case asynOverflow: case asynOverflow:
error("%s: asynOverflow in write: %s\n", error("%s: asynOverflow in write. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
case asynError: case asynError:
error("%s: asynError in write: %s\n", error("%s: asynError in write. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
#ifdef ASYN_VERSION // asyn >= 4.14 #ifdef ASYN_VERSION // asyn >= 4.14
case asynDisconnected: case asynDisconnected:
error("%s: asynDisconnected in write: %s\n", error("%s: asynDisconnected in write. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
case asynDisabled: case asynDisabled:
error("%s: asynDisconnected in write: %s\n", error("%s: asynDisconnected in write. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
#endif #endif
default: default:
error("%s: unknown asyn error in write: %s\n", error("%s: unknown asyn error in write. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
@ -732,7 +809,7 @@ readRequest(unsigned long replyTimeout_ms, unsigned long readTimeout_ms,
long _expectedLength, bool async) long _expectedLength, bool async)
{ {
debug("AsynDriverInterface::readRequest(%s, %ld msec reply, " debug("AsynDriverInterface::readRequest(%s, %ld msec reply, "
"%ld msec read, expect %ld bytes, asyn=%s)\n", "%ld msec read, expect %ld bytes, async=%s)\n",
clientName(), replyTimeout_ms, readTimeout_ms, clientName(), replyTimeout_ms, readTimeout_ms,
_expectedLength, async?"yes":"no"); _expectedLength, async?"yes":"no");
@ -756,8 +833,20 @@ readRequest(unsigned long replyTimeout_ms, unsigned long readTimeout_ms,
} }
status = pasynManager->queueRequest(pasynUser, status = pasynManager->queueRequest(pasynUser,
priority(), queueTimeout); priority(), queueTimeout);
if (status != asynSuccess && !async) debug("AsynDriverInterface::readRequest %s: "
"queueRequest(..., priority=%d, queueTimeout=%g sec) = %s [async=%s] %s\n",
clientName(), priority(), queueTimeout,
asynStatusStr[status], async? "true" : "false",
status!=asynSuccess ? pasynUser->errorMessage : "");
if (status != asynSuccess)
{ {
// Not queued for some reason (e.g. disconnected / already queued)
if (async)
{
// silently try again later
startTimer(replyTimeout);
return true;
}
error("%s readRequest: pasynManager->queueRequest() failed: %s\n", error("%s readRequest: pasynManager->queueRequest() failed: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
return false; return false;
@ -798,6 +887,11 @@ readHandler()
oldeoslen = -1; oldeoslen = -1;
} else do { } else do {
// device (e.g. GPIB) might not accept full eos length // device (e.g. GPIB) might not accept full eos length
if ((int)deveoslen == oldeoslen && strcmp(deveos, oldeos) == 0)
{
// nothing to do: old and new eos are the same
break;
}
if (pasynOctet->setInputEos(pvtOctet, pasynUser, if (pasynOctet->setInputEos(pvtOctet, pasynUser,
deveos, deveoslen) == asynSuccess) deveos, deveoslen) == asynSuccess)
{ {
@ -805,8 +899,9 @@ readHandler()
if (ioAction != AsyncRead) if (ioAction != AsyncRead)
{ {
debug("AsynDriverInterface::readHandler(%s) " debug("AsynDriverInterface::readHandler(%s) "
"input EOS set to %s\n", "input EOS changed from \"%s\" to \"%s\"\n",
clientName(), clientName(),
StreamBuffer(oldeos, oldeoslen).expand()(),
StreamBuffer(deveos, deveoslen).expand()()); StreamBuffer(deveos, deveoslen).expand()());
} }
#endif #endif
@ -862,28 +957,29 @@ readHandler()
readMore = 0; readMore = 0;
received = 0; received = 0;
eomReason = 0; eomReason = 0;
pasynUser->errorMessage[0] = 0;
debug("AsynDriverInterface::readHandler(%s): ioAction=%s "
"read(..., bytesToRead=%ld, ...) "
"[timeout=%g sec]\n",
clientName(), ioActionStr[ioAction],
bytesToRead, pasynUser->timeout);
status = pasynOctet->read(pvtOctet, pasynUser, status = pasynOctet->read(pvtOctet, pasynUser,
buffer, bytesToRead, &received, &eomReason); buffer, bytesToRead, &received, &eomReason);
if (ioAction == Read || status != asynTimeout) #ifndef NO_TEMPORARY
{ debug("AsynDriverInterface::readHandler(%s): "
debug("AsynDriverInterface::readHandler(%s): " "read returned %s: ioAction=%s received=%ld, eomReason=%s, buffer=\"%s\"\n",
"read(..., bytesToRead=%ld, received=%ld...) " clientName(), asynStatusStr[status], ioActionStr[ioAction],
"[timeout=%f seconds] = %s\n", (long)received,eomReasonStr[eomReason&0x7],
clientName(), bytesToRead, (long)received, StreamBuffer(buffer, received).expand()());
pasynUser->timeout, asynStatusStr[status]); #endif
}
pasynManager->isConnected(pasynUser, &connected); pasynManager->isConnected(pasynUser, &connected);
debug("AsynDriverInterface::readHandler(%s): " debug("AsynDriverInterface::readHandler(%s): "
"device is %sconnected\n", "device is now %sconnected\n",
clientName(),connected?"":"dis"); clientName(),connected?"":"dis");
if (!connected) { // asyn 4.16 sets reason to ASYN_EOM_END when device disconnects.
error("%s: connection closed in read\n", // What about earlier versions?
clientName()); if (!connected) eomReason |= ASYN_EOM_END;
readCallback(StreamIoFault);
return;
}
// pasynOctet->read() has already cut off terminator.
if (status == asynTimeout && if (status == asynTimeout &&
pasynUser->timeout == 0.0 && pasynUser->timeout == 0.0 &&
@ -910,6 +1006,7 @@ readHandler()
#endif #endif
// ignore what we got from here. // ignore what we got from here.
// input was already handeled by asynReadHandler() // input was already handeled by asynReadHandler()
// read until no more input is available // read until no more input is available
readMore = -1; readMore = -1;
break; break;
@ -959,6 +1056,9 @@ readHandler()
// reply timeout // reply timeout
if (ioAction == AsyncRead) if (ioAction == AsyncRead)
{ {
debug("AsynDriverInterface::readHandler(%s): "
"no async input, retry in in %g seconds\n",
clientName(), replyTimeout);
// start next poll after timer expires // start next poll after timer expires
if (replyTimeout != 0.0) startTimer(replyTimeout); if (replyTimeout != 0.0) startTimer(replyTimeout);
// continues with: // continues with:
@ -975,7 +1075,7 @@ readHandler()
// read timeout // read timeout
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("AsynDriverInterface::readHandler(%s): " debug("AsynDriverInterface::readHandler(%s): "
"ioAction=%s, timeout [%f seconds] " "ioAction=%s, timeout [%g sec] "
"after %ld of %ld bytes \"%s\"\n", "after %ld of %ld bytes \"%s\"\n",
clientName(), ioActionStr[ioAction], pasynUser->timeout, clientName(), ioActionStr[ioAction], pasynUser->timeout,
(long)received, bytesToRead, (long)received, bytesToRead,
@ -1002,29 +1102,29 @@ readHandler()
} }
peeksize = inputBuffer.capacity(); peeksize = inputBuffer.capacity();
// deliver whatever we could save // deliver whatever we could save
error("%s: asynOverflow in read: %s\n", error("%s: asynOverflow in read. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault, buffer, received); readCallback(StreamIoFault, buffer, received);
break; break;
case asynError: case asynError:
error("%s: asynError in read: %s\n", error("%s: asynError in read. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault, buffer, received); readCallback(StreamIoFault, buffer, received);
break; break;
#ifdef ASYN_VERSION // asyn >= 4.14 #ifdef ASYN_VERSION // asyn >= 4.14
case asynDisconnected: case asynDisconnected:
error("%s: asynDisconnected in read: %s\n", error("%s: asynDisconnected in read. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault); readCallback(StreamIoFault);
return; return;
case asynDisabled: case asynDisabled:
error("%s: asynDisconnected in read: %s\n", error("%s: asynDisconnected in read. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault); readCallback(StreamIoFault);
return; return;
#endif #endif
default: default:
error("%s: unknown asyn error in read: %s\n", error("%s: unknown asyn error in read. Asyn driver says: \"%s\"\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault); readCallback(StreamIoFault);
return; return;
@ -1046,10 +1146,16 @@ readHandler()
} }
// restore original EOS // restore original EOS
if (oldeoslen >= 0) if (oldeoslen >= 0 && oldeoslen != (int)deveoslen && strcmp(deveos, oldeos) != 0)
{ {
pasynOctet->setInputEos(pvtOctet, pasynUser, pasynOctet->setInputEos(pvtOctet, pasynUser,
oldeos, oldeoslen); oldeos, oldeoslen);
#ifndef NO_TEMPORARY
debug("AsynDriverInterface::readHandler(%s) "
"input EOS restored to \"%s\"\n",
clientName(),
StreamBuffer(oldeos, oldeoslen).expand()());
#endif
} }
} }
@ -1187,7 +1293,7 @@ acceptEvent(unsigned long mask, unsigned long replytimeout_ms)
} }
eventMask = mask; eventMask = mask;
ioAction = ReceiveEvent; ioAction = ReceiveEvent;
startTimer(replytimeout_ms*0.001); if (replytimeout_ms) startTimer(replytimeout_ms*0.001);
return true; return true;
} }
@ -1236,6 +1342,9 @@ timerExpired()
int autoconnect, connected; int autoconnect, connected;
switch (ioAction) switch (ioAction)
{ {
case None:
// Timeout of async poll crossed with parasitic input
return;
case ReceiveEvent: case ReceiveEvent:
// timeout while waiting for event // timeout while waiting for event
ioAction = None; ioAction = None;
@ -1254,6 +1363,8 @@ timerExpired()
// queueRequest might fail if another request was just queued // queueRequest might fail if another request was just queued
pasynManager->isAutoConnect(pasynUser, &autoconnect); pasynManager->isAutoConnect(pasynUser, &autoconnect);
pasynManager->isConnected(pasynUser, &connected); pasynManager->isConnected(pasynUser, &connected);
debug("%s: polling for I/O Intr: autoconnected: %d, connect: %d\n",
clientName(), autoconnect, connected);
if (autoconnect && !connected) if (autoconnect && !connected)
{ {
// has explicitely been disconnected // has explicitely been disconnected
@ -1264,8 +1375,14 @@ timerExpired()
else else
{ {
// queue for read poll (no timeout) // queue for read poll (no timeout)
pasynManager->queueRequest(pasynUser, asynStatus status = pasynManager->queueRequest(pasynUser,
asynQueuePriorityLow, -1.0); asynQueuePriorityLow, -1.0);
// if this fails, we are already queued by another thread
debug("AsynDriverInterface::timerExpired %s: "
"queueRequest(..., priority=Low, queueTimeout=-1) = %s %s\n",
clientName(), asynStatusStr[status],
status!=asynSuccess ? pasynUser->errorMessage : "");
if (status != asynSuccess) startTimer(replyTimeout);
// continues with: // continues with:
// handleRequest() -> readHandler() -> readCallback() // handleRequest() -> readHandler() -> readCallback()
} }
@ -1277,14 +1394,7 @@ timerExpired()
} }
} }
#ifdef EPICS_3_14 #ifdef EPICS_3_13
epicsTimerNotify::expireStatus AsynDriverInterface::
expire(const epicsTime &)
{
timerExpired();
return noRestart;
}
#else
void AsynDriverInterface:: void AsynDriverInterface::
expire(CALLBACK *pcallback) expire(CALLBACK *pcallback)
{ {
@ -1292,6 +1402,13 @@ expire(CALLBACK *pcallback)
static_cast<AsynDriverInterface*>(pcallback->user); static_cast<AsynDriverInterface*>(pcallback->user);
interface->timerExpired(); interface->timerExpired();
} }
#else
epicsTimerNotify::expireStatus AsynDriverInterface::
expire(const epicsTime &)
{
timerExpired();
return noRestart;
}
#endif #endif
bool AsynDriverInterface:: bool AsynDriverInterface::
@ -1390,6 +1507,7 @@ void handleRequest(asynUser* pasynUser)
{ {
AsynDriverInterface* interface = AsynDriverInterface* interface =
static_cast<AsynDriverInterface*>(pasynUser->userPvt); static_cast<AsynDriverInterface*>(pasynUser->userPvt);
interface->cancelTimer();
debug("AsynDriverInterface::handleRequest(%s) %s\n", debug("AsynDriverInterface::handleRequest(%s) %s\n",
interface->clientName(), ioActionStr[interface->ioAction]); interface->clientName(), ioActionStr[interface->ioAction]);
switch (interface->ioAction) switch (interface->ioAction)

View File

@ -31,9 +31,9 @@ class BCDConverter : public StreamFormatConverter
}; };
int BCDConverter:: int BCDConverter::
parse(const StreamFormat&, StreamBuffer&, const char*&, bool) parse(const StreamFormat& fmt, StreamBuffer&, const char*&, bool)
{ {
return long_format; return (fmt.flags & sign_flag) ? signed_format : unsigned_format;
} }
bool BCDConverter:: bool BCDConverter::

View File

@ -19,6 +19,7 @@
***************************************************************/ ***************************************************************/
#include <ctype.h> #include <ctype.h>
#include <limits.h>
#include "StreamFormatConverter.h" #include "StreamFormatConverter.h"
#include "StreamError.h" #include "StreamError.h"
@ -32,51 +33,59 @@ class BinaryConverter : public StreamFormatConverter
}; };
int BinaryConverter:: int BinaryConverter::
parse(const StreamFormat& format, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool) const char*& source, bool)
{ {
if (format.conv == 'B') if (fmt.conv == 'b')
{ {
// user defined characters for %B (next 2 in source) // default characters 0 and 1 for %b
info.append("01");
return unsigned_format;
}
// user defined characters for %B (next 2 in source)
if (*source)
{
if (*source == esc) source++;
info.append(*source++);
if (*source) if (*source)
{ {
if (*source == esc) source++; if (*source == esc) source++;
info.append(*source++); info.append(*source++);
if (*source) return unsigned_format;
{
if (*source == esc) source++;
info.append(*source++);
return long_format;
}
} }
error("Missing characters after %%B format conversion\n");
return false;
} }
// default characters for %b error("Missing characters after %%B format conversion\n");
info.append("01"); return false;
return long_format;
} }
bool BinaryConverter:: bool BinaryConverter::
printLong(const StreamFormat& format, StreamBuffer& output, long value) printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
int prec = format.prec; int prec = fmt.prec;
if (prec == -1) if (prec == -1)
{ {
// find number of significant bits // Find number of significant bits is nothing is specified.
prec = sizeof (value) * 8; unsigned long x = (unsigned long) value;
while (prec && (value & (1L << (prec - 1))) == 0) prec--; prec = 32;
#if (LONG_BIT > 32)
if (x > 0xFFFFFFFF) { prec = 64; x >>=32; }
#endif
if (x <= 0x0000FFFF) { prec -= 16; x <<=16; }
if (x <= 0x00FFFFFF) { prec -= 8; x <<=8; }
if (x <= 0x0FFFFFFF) { prec -= 4; x <<=4; }
if (x <= 0x3FFFFFFF) { prec -= 2; x <<=2; }
if (x <= 0x7FFFFFFF) { prec -= 1; }
} }
if (prec == 0) prec++; // print at least one bit
int width = prec; int width = prec;
if (format.width > width) width = format.width; if (fmt.width > width) width = fmt.width;
char zero = format.info[0]; char zero = fmt.info[0];
char one = format.info[1]; char one = fmt.info[1];
char fill = (format.flags & zero_flag) ? zero : ' '; char fill = (fmt.flags & zero_flag) ? zero : ' ';
if (format.flags & alt_flag) if (fmt.flags & alt_flag)
{ {
// little endian (least significant bit first) // little endian (least significant bit first)
if (!(format.flags & left_flag)) if (!(fmt.flags & left_flag))
{ {
// pad left // pad left
while (width > prec) while (width > prec)
@ -100,7 +109,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
else else
{ {
// big endian (most significant bit first) // big endian (most significant bit first)
if (!(format.flags & left_flag)) if (!(fmt.flags & left_flag))
{ {
// pad left // pad left
while (width > prec) while (width > prec)
@ -124,17 +133,18 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
} }
int BinaryConverter:: int BinaryConverter::
scanLong(const StreamFormat& format, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
long val = 0; long val = 0;
int width = format.width; int width = fmt.width;
if (width == 0) width = -1; if (width == 0) width = -1;
int length = 0; int length = 0;
while (isspace(input[length])) length++; // skip whitespaces char zero = fmt.info[0];
char zero = format.info[0]; char one = fmt.info[1];
char one = format.info[1]; if (!isspace(zero) && !isspace(one))
while (isspace(input[length])) length++; // skip whitespaces
if (input[length] != zero && input[length] != one) return -1; if (input[length] != zero && input[length] != one) return -1;
if (format.flags & alt_flag) if (fmt.flags & alt_flag)
{ {
// little endian (least significan bit first) // little endian (least significan bit first)
long mask = 1; long mask = 1;

View File

@ -22,17 +22,26 @@
#include "StreamError.h" #include "StreamError.h"
#if defined(__vxworks) || defined(vxWorks) || defined(_WIN32) || defined(__rtems__) #if defined(__vxworks) || defined(vxWorks) || defined(_WIN32) || defined(__rtems__)
// These systems have no strncasecmp // These systems have no strncasecmp
#include <epicsVersion.h>
#ifdef BASE_VERSION
// 3.13
#include <ctype.h>
static int strncasecmp(const char *s1, const char *s2, size_t n)
{
int r=0;
while (n && (r = toupper(*s1)-toupper(*s2)) == 0) { n--; s1++; s2++; };
return r;
}
#else
#include <epicsString.h> #include <epicsString.h>
#define strncasecmp epicsStrnCaseCmp #define strncasecmp epicsStrnCaseCmp
#endif #endif
#endif
#include <ctype.h> #include <ctype.h>
typedef unsigned long ulong; typedef unsigned int (*checksumFunc)(const unsigned char* data, unsigned int len, unsigned int init);
typedef unsigned char uchar;
typedef ulong (*checksumFunc)(const uchar* data, ulong len, ulong init); static unsigned int sum(const unsigned char* data, unsigned int len, unsigned int sum)
static ulong sum(const uchar* data, ulong len, ulong sum)
{ {
while (len--) while (len--)
{ {
@ -41,7 +50,7 @@ static ulong sum(const uchar* data, ulong len, ulong sum)
return sum; return sum;
} }
static ulong xor8(const uchar* data, ulong len, ulong sum) static unsigned int xor8(const unsigned char* data, unsigned int len, unsigned int sum)
{ {
while (len--) while (len--)
{ {
@ -50,15 +59,15 @@ static ulong xor8(const uchar* data, ulong len, ulong sum)
return sum; return sum;
} }
static ulong xor7(const uchar* data, ulong len, ulong sum) static unsigned int xor7(const unsigned char* data, unsigned int len, unsigned int sum)
{ {
return xor8(data, len, sum) & 0x7F; return xor8(data, len, sum) & 0x7F;
} }
static ulong crc_0x07(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x07(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^8 + x^2 + x^1 + x^0 (0x07) // x^8 + x^2 + x^1 + x^0 (0x07)
const static uchar table[256] = { const static unsigned char table[256] = {
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
@ -96,10 +105,10 @@ static ulong crc_0x07(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x31(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x31(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^8 + x^5 + x^4 + x^0 (0x31) // x^8 + x^5 + x^4 + x^0 (0x31)
const static uchar table[256] = { const static unsigned char table[256] = {
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83,
0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e,
@ -137,90 +146,90 @@ static ulong crc_0x31(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x8005(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x8005(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^16 + x^15 + x^2 + x^0 (0x8005) // x^16 + x^15 + x^2 + x^0 (0x8005)
const static unsigned short table[256] = { const static unsigned short table[256] = {
0x0000,0x8005,0x800f,0x000a,0x801b,0x001e,0x0014,0x8011, 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
0x8033,0x0036,0x003c,0x8039,0x0028,0x802d,0x8027,0x0022, 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
0x8063,0x0066,0x006c,0x8069,0x0078,0x807d,0x8077,0x0072, 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
0x0050,0x8055,0x805f,0x005a,0x804b,0x004e,0x0044,0x8041, 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
0x80c3,0x00c6,0x00cc,0x80c9,0x00d8,0x80dd,0x80d7,0x00d2, 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
0x00f0,0x80f5,0x80ff,0x00fa,0x80eb,0x00ee,0x00e4,0x80e1, 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
0x00a0,0x80a5,0x80af,0x00aa,0x80bb,0x00be,0x00b4,0x80b1, 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
0x8093,0x0096,0x009c,0x8099,0x0088,0x808d,0x8087,0x0082, 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
0x8183,0x0186,0x018c,0x8189,0x0198,0x819d,0x8197,0x0192, 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
0x01b0,0x81b5,0x81bf,0x01ba,0x81ab,0x01ae,0x01a4,0x81a1, 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
0x01e0,0x81e5,0x81ef,0x01ea,0x81fb,0x01fe,0x01f4,0x81f1, 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
0x81d3,0x01d6,0x01dc,0x81d9,0x01c8,0x81cd,0x81c7,0x01c2, 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
0x0140,0x8145,0x814f,0x014a,0x815b,0x015e,0x0154,0x8151, 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
0x8173,0x0176,0x017c,0x8179,0x0168,0x816d,0x8167,0x0162, 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
0x8123,0x0126,0x012c,0x8129,0x0138,0x813d,0x8137,0x0132, 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
0x0110,0x8115,0x811f,0x011a,0x810b,0x010e,0x0104,0x8101, 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
0x8303,0x0306,0x030c,0x8309,0x0318,0x831d,0x8317,0x0312, 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
0x0330,0x8335,0x833f,0x033a,0x832b,0x032e,0x0324,0x8321, 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
0x0360,0x8365,0x836f,0x036a,0x837b,0x037e,0x0374,0x8371, 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
0x8353,0x0356,0x035c,0x8359,0x0348,0x834d,0x8347,0x0342, 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
0x03c0,0x83c5,0x83cf,0x03ca,0x83db,0x03de,0x03d4,0x83d1, 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
0x83f3,0x03f6,0x03fc,0x83f9,0x03e8,0x83ed,0x83e7,0x03e2, 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
0x83a3,0x03a6,0x03ac,0x83a9,0x03b8,0x83bd,0x83b7,0x03b2, 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
0x0390,0x8395,0x839f,0x039a,0x838b,0x038e,0x0384,0x8381, 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
0x0280,0x8285,0x828f,0x028a,0x829b,0x029e,0x0294,0x8291, 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
0x82b3,0x02b6,0x02bc,0x82b9,0x02a8,0x82ad,0x82a7,0x02a2, 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
0x82e3,0x02e6,0x02ec,0x82e9,0x02f8,0x82fd,0x82f7,0x02f2, 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
0x02d0,0x82d5,0x82df,0x02da,0x82cb,0x02ce,0x02c4,0x82c1, 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
0x8243,0x0246,0x024c,0x8249,0x0258,0x825d,0x8257,0x0252, 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
0x0270,0x8275,0x827f,0x027a,0x826b,0x026e,0x0264,0x8261, 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
0x0220,0x8225,0x822f,0x022a,0x823b,0x023e,0x0234,0x8231, 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
0x8213,0x0216,0x021c,0x8219,0x0208,0x820d,0x8207,0x0202 }; 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202 };
while (len--) crc = table[((crc>>8) ^ *data++) & 0xFF] ^ (crc << 8); while (len--) crc = table[((crc>>8) ^ *data++) & 0xFF] ^ (crc << 8);
return crc; return crc;
} }
static ulong crc_0x8005_r(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x8005_r(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^16 + x^15 + x^2 + x^0 (0x8005) // x^16 + x^15 + x^2 + x^0 (0x8005)
// reflected // reflected
const static unsigned short table[256] = { const static unsigned short table[256] = {
0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241, 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40, 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00,0xCAC1,0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,0x1A40, 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400,0xD4C1,0xD581,0x1540,0xD701,0x17C0,0x1680,0xD641, 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240, 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41, 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
0xFA01,0x3AC0,0x3B80,0xFB41,0x3900,0xF9C1,0xF881,0x3840, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41, 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401,0x24C0,0x2580,0xE541,0x2700,0xE7C1,0xE681,0x2640, 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001,0x60C0,0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240, 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,0xA441, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41, 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
0xAA01,0x6AC0,0x6B80,0xAB41,0x6900,0xA9C1,0xA881,0x6840, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41, 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01,0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,0xB681,0x7640, 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000,0x90C1,0x9181,0x5140,0x9301,0x53C0,0x5280,0x9241, 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40, 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,0x59C0,0x5880,0x9841, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40, 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
0x4E00,0x8EC1,0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,0x8641, 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040 }; 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 };
while (len--) crc = table[(crc ^ *data++) & 0xFF] ^ (crc >> 8); while (len--) crc = table[(crc ^ *data++) & 0xFF] ^ (crc >> 8);
return crc; return crc;
} }
static ulong crc_0x1021(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x1021(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^16 + x^12 + x^5 + x^0 (0x1021) // x^16 + x^12 + x^5 + x^0 (0x1021)
const static unsigned short table[256] = { const static unsigned short table[256] = {
@ -261,11 +270,11 @@ static ulong crc_0x1021(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x04C11DB7(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x04C11DB7(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 +
// x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7) // x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7)
const static ulong table[] = { const static unsigned int table[] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
@ -335,12 +344,12 @@ static ulong crc_0x04C11DB7(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x04C11DB7_r(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x04C11DB7_r(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 +
// x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7) // x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7)
// reflected // reflected
const static ulong table[] = { const static unsigned int table[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@ -410,13 +419,13 @@ static ulong crc_0x04C11DB7_r(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong adler32(const uchar* data, ulong len, ulong init) static unsigned int adler32(const unsigned char* data, unsigned int len, unsigned int init)
{ {
ulong a = init & 0xFFFF; unsigned int a = init & 0xFFFF;
ulong b = (init >> 16) & 0xFFFF; unsigned int b = (init >> 16) & 0xFFFF;
while (len) { while (len) {
ulong tlen = len > 5550 ? 5550 : len; unsigned int tlen = len > 5550 ? 5550 : len;
len -= tlen; len -= tlen;
do { do {
a += *data++; a += *data++;
@ -431,10 +440,10 @@ static ulong adler32(const uchar* data, ulong len, ulong init)
return b << 16 | a; return b << 16 | a;
} }
static ulong hexsum(const uchar* data, ulong len, ulong sum) static unsigned int hexsum(const unsigned char* data, unsigned int len, unsigned int sum)
{ {
// Add all hex digits, ignore all other bytes. // Add all hex digits, ignore all other bytes.
ulong d; unsigned int d;
while (len--) while (len--)
{ {
d = toupper(*data++); d = toupper(*data++);
@ -452,8 +461,8 @@ struct checksum
{ {
const char* name; const char* name;
checksumFunc func; checksumFunc func;
ulong init; unsigned int init;
ulong xorout; unsigned int xorout;
signed char bytes; signed char bytes;
}; };
@ -465,20 +474,6 @@ static checksum checksumMap[] =
{"sum8", sum, 0x00, 0x00, 1}, // 0xDD {"sum8", sum, 0x00, 0x00, 1}, // 0xDD
{"sum16", sum, 0x0000, 0x0000, 2}, // 0x01DD {"sum16", sum, 0x0000, 0x0000, 2}, // 0x01DD
{"sum32", sum, 0x00000000, 0x00000000, 4}, // 0x000001DD {"sum32", sum, 0x00000000, 0x00000000, 4}, // 0x000001DD
{"nsum", sum, 0xFF, 0xFF, 1}, // 0x23
{"negsum", sum, 0xFF, 0xFF, 1}, // 0x23
{"-sum", sum, 0xFF, 0xFF, 1}, // 0x23
{"nsum8", sum, 0xFF, 0xFF, 1}, // 0x23
{"negsum8", sum, 0xFF, 0xFF, 1}, // 0x23
{"-sum8", sum, 0xFF, 0xFF, 1}, // 0x23
{"nsum16", sum, 0xFFFF, 0xFFFF, 2}, // 0xFE23
{"negsum16",sum, 0xFFFF, 0xFFFF, 2}, // 0xFE23
{"-sum16", sum, 0xFFFF, 0xFFFF, 2}, // 0xFE23
{"nsum32", sum, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFFFFFE23
{"negsum32",sum, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFFFFFE23
{"-sum32", sum, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFFFFFE23
{"notsum", sum, 0x00, 0xFF, 1}, // 0x22
{"~sum", sum, 0x00, 0xFF, 1}, // 0x22
{"xor", xor8, 0x00, 0x00, 1}, // 0x31 {"xor", xor8, 0x00, 0x00, 1}, // 0x31
{"xor8", xor8, 0x00, 0x00, 1}, // 0x31 {"xor8", xor8, 0x00, 0x00, 1}, // 0x31
{"xor7", xor7, 0x00, 0x00, 1}, // 0x31 {"xor7", xor7, 0x00, 0x00, 1}, // 0x31
@ -486,6 +481,7 @@ static checksum checksumMap[] =
{"ccitt8", crc_0x31, 0x00, 0x00, 1}, // 0xA1 {"ccitt8", crc_0x31, 0x00, 0x00, 1}, // 0xA1
{"crc16", crc_0x8005, 0x0000, 0x0000, 2}, // 0xFEE8 {"crc16", crc_0x8005, 0x0000, 0x0000, 2}, // 0xFEE8
{"crc16r", crc_0x8005_r, 0x0000, 0x0000, 2}, // 0xBB3D {"crc16r", crc_0x8005_r, 0x0000, 0x0000, 2}, // 0xBB3D
{"modbus", crc_0x8005_r, 0xFFFF, 0x0000, 2}, // 0x4B37
{"ccitt16", crc_0x1021, 0xFFFF, 0x0000, 2}, // 0x29B1 {"ccitt16", crc_0x1021, 0xFFFF, 0x0000, 2}, // 0x29B1
{"ccitt16a",crc_0x1021, 0x1D0F, 0x0000, 2}, // 0xE5CC {"ccitt16a",crc_0x1021, 0x1D0F, 0x0000, 2}, // 0xE5CC
{"ccitt16x",crc_0x1021, 0x0000, 0x0000, 2}, // 0x31C3 {"ccitt16x",crc_0x1021, 0x0000, 0x0000, 2}, // 0x31C3
@ -498,7 +494,7 @@ static checksum checksumMap[] =
{"hexsum8", hexsum, 0x00, 0x00, 1} // 0x2D {"hexsum8", hexsum, 0x00, 0x00, 1} // 0x2D
}; };
static ulong mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF}; static unsigned int mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};
class ChecksumConverter : public StreamFormatConverter class ChecksumConverter : public StreamFormatConverter
{ {
@ -517,44 +513,94 @@ parse(const StreamFormat&, StreamBuffer& info, const char*& source, bool)
return false; return false;
} }
size_t fnum; bool negflag=false;
bool notflag=false;
if (*source == '-')
{
source++;
negflag = true;
}
if (strncasecmp(source, "neg", 3) == 0)
{
source+=3;
negflag = true;
}
if (*source == '~')
{
source++;
notflag = true;
}
if (strncasecmp(source, "not", 3) == 0)
{
source+=3;
notflag = true;
}
unsigned fnum;
int len = p-source;
unsigned int init, xorout;
for (fnum = 0; fnum < sizeof(checksumMap)/sizeof(checksum); fnum++) for (fnum = 0; fnum < sizeof(checksumMap)/sizeof(checksum); fnum++)
{ {
if (strncasecmp(source, checksumMap[fnum].name, p-source) == 0) if ((strncasecmp(source, checksumMap[fnum].name, len) == 0) ||
(*source == 'n' && len > 1 && strncasecmp(source+1, checksumMap[fnum].name, len-1) == 0 && (negflag = true)))
{ {
init = checksumMap[fnum].init;
xorout = checksumMap[fnum].xorout;
if (negflag)
{
init = ~init;
xorout = ~xorout;
}
if (notflag)
{
xorout = ~xorout;
}
info.append(&init, sizeof(init));
info.append(&xorout, sizeof(xorout));
info.append(fnum); info.append(fnum);
source = p+1; source = p+1;
return pseudo_format; return pseudo_format;
} }
} }
error ("Unknown checksum algorithm \"%.*s\"\n", error ("Unknown checksum algorithm \"%.*s\"\n", len, source);
static_cast<int>(p-source), source);
return false; return false;
} }
bool ChecksumConverter:: bool ChecksumConverter::
printPseudo(const StreamFormat& format, StreamBuffer& output) printPseudo(const StreamFormat& format, StreamBuffer& output)
{ {
ulong sum; unsigned int sum;
int fnum = format.info[0]; const char* info = format.info;
unsigned int init = extract<unsigned int>(info);
unsigned int xorout = extract<unsigned int>(info);
int fnum = extract<char>(info);
int start = format.width; int start = format.width;
int length = output.length()-format.width; int length = output.length()-format.width;
if (format.prec > 0) length -= format.prec; if (format.prec > 0) length -= format.prec;
debug("ChecksumConverter %s: output to check: \"%s\"\n", debug("ChecksumConverter %s: output to check: \"%s\"\n",
checksumMap[fnum].name, output.expand(start,length)()); checksumMap[fnum].name, output.expand(start,length)());
sum = (xorout ^ checksumMap[fnum].func(
reinterpret_cast<unsigned char*>(output(start)), length, init))
& mask[checksumMap[fnum].bytes];
sum = checksumMap[fnum].xorout ^ checksumMap[fnum].func( debug("ChecksumConverter %s: output checksum is 0x%X\n",
reinterpret_cast<uchar*>(output(start)), length,
checksumMap[fnum].init) & mask[checksumMap[fnum].bytes];
debug("ChecksumConverter %s: output checksum is 0x%lX\n",
checksumMap[fnum].name, sum); checksumMap[fnum].name, sum);
int i; int i;
unsigned outchar; unsigned outchar;
if (format.flags & sign_flag) // decimal
{
// get number of decimal digits from number of bytes: ceil(xbytes*2.5)
i = (checksumMap[fnum].bytes+1)*25/10-2;
output.print("%0*d", i, sum);
debug("ChecksumConverter %s: decimal appending %0*d\n",
checksumMap[fnum].name, i, sum);
}
else
if (format.flags & alt_flag) // lsb first (little endian) if (format.flags & alt_flag) // lsb first (little endian)
{ {
for (i = 0; i < checksumMap[fnum].bytes; i++) for (i = 0; i < checksumMap[fnum].bytes; i++)
@ -563,7 +609,11 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
debug("ChecksumConverter %s: little endian appending 0x%X\n", debug("ChecksumConverter %s: little endian appending 0x%X\n",
checksumMap[fnum].name, outchar); checksumMap[fnum].name, outchar);
if (format.flags & zero_flag) // ASCII if (format.flags & zero_flag) // ASCII
output.printf("%02X", outchar); output.print("%02X", outchar);
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
output.print("%c%c",
((outchar>>4)&0x0f)|0x30, (outchar&0x0f)|0x30);
else // binary else // binary
output.append(outchar); output.append(outchar);
sum >>= 8; sum >>= 8;
@ -578,7 +628,11 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
debug("ChecksumConverter %s: big endian appending 0x%X\n", debug("ChecksumConverter %s: big endian appending 0x%X\n",
checksumMap[fnum].name, outchar); checksumMap[fnum].name, outchar);
if (format.flags & zero_flag) // ASCII if (format.flags & zero_flag) // ASCII
output.printf("%02X", outchar); output.print("%02X", outchar);
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
output.print("%c%c",
((outchar>>4)&0x0f)|0x30, (outchar&0x0f)|0x30);
else // binary else // binary
output.append(outchar); output.append(outchar);
sum <<= 8; sum <<= 8;
@ -590,39 +644,88 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
int ChecksumConverter:: int ChecksumConverter::
scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor) scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
{ {
int fnum = format.info[0]; unsigned int sum;
ulong sum; const char* info = format.info;
unsigned int init = extract<unsigned int>(info);
unsigned int xorout = extract<unsigned int>(info);
int start = format.width; int start = format.width;
int fnum = extract<char>(info);
int length = cursor-format.width; int length = cursor-format.width;
if (format.prec > 0) length -= format.prec; if (format.prec > 0) length -= format.prec;
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)());
if (input.length() - cursor < int expectedLength =
(format.flags & zero_flag ? 2 : 1) * checksumMap[fnum].bytes) // get number of decimal digits from number of bytes: ceil(bytes*2.5)
format.flags & sign_flag ? (checksumMap[fnum].bytes + 1) * 25 / 10 - 2 :
format.flags & (zero_flag|left_flag) ? 2 * checksumMap[fnum].bytes :
checksumMap[fnum].bytes;
if (input.length() - cursor < expectedLength)
{ {
error("Input too short for checksum\n"); debug("ChecksumConverter %s: Input '%s' too short for checksum\n",
checksumMap[fnum].name, input.expand(cursor)());
return -1; return -1;
} }
sum = checksumMap[fnum].xorout ^ checksumMap[fnum].func( sum = (xorout ^ checksumMap[fnum].func(
reinterpret_cast<uchar*>(input(start)), length, reinterpret_cast<unsigned char*>(input(start)), length, init))
checksumMap[fnum].init) & mask[checksumMap[fnum].bytes]; & mask[checksumMap[fnum].bytes];
debug("ChecksumConverter %s: input checksum is 0x%0*lX\n", debug("ChecksumConverter %s: input checksum is 0x%0*X\n",
checksumMap[fnum].name, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, 2*checksumMap[fnum].bytes, sum);
int i,j; int i, j;
unsigned inchar; unsigned inchar;
if (format.flags & sign_flag) // decimal
{
unsigned int sumin = 0;
for (i = 0; i < expectedLength; i++)
{
inchar = input[cursor+i];
if (isdigit(inchar)) sumin = sumin*10+inchar-'0';
else break;
}
if (sumin != sum)
{
debug("ChecksumConverter %s: Input %0*u does not match checksum %0*u\n",
checksumMap[fnum].name, i, sumin, expectedLength, sum);
return -1;
}
}
else
if (format.flags & alt_flag) // lsb first (little endian) if (format.flags & alt_flag) // lsb first (little endian)
{ {
for (i = 0; i < checksumMap[fnum].bytes; i++) for (i = 0; i < checksumMap[fnum].bytes; i++)
{ {
if (format.flags & zero_flag) // ASCII if (format.flags & zero_flag) // ASCII
{ {
sscanf(input(cursor+2*i), "%2X", &inchar); if (sscanf(input(cursor+2*i), "%2X", &inchar) != 1)
{
debug("ChecksumConverter %s: Input byte '%s' is not a hex byte\n",
checksumMap[fnum].name, input.expand(cursor+2*i,2)());
return -1;
}
}
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
{
if ((input[cursor+2*i] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i]);
return -1;
}
if ((input[cursor+2*i+1] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i+1]);
return -1;
}
inchar = ((input[cursor+2*i] & 0x0f) << 4) | (input[cursor+2*i+1] & 0x0f);
} }
else // binary else // binary
{ {
@ -630,8 +733,8 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
} }
if (inchar != ((sum >> 8*i) & 0xff)) if (inchar != ((sum >> 8*i) & 0xff))
{ {
error("Input byte 0x%02X does not match checksum 0x%0*lX\n", debug("ChecksumConverter %s: Input byte 0x%02X does not match checksum 0x%0*X\n",
inchar, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, inchar, 2*checksumMap[fnum].bytes, sum);
return -1; return -1;
} }
} }
@ -644,21 +747,36 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
{ {
sscanf(input(cursor+2*i), "%2x", &inchar); sscanf(input(cursor+2*i), "%2x", &inchar);
} }
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
{
if ((input[cursor+2*i] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i]);
return -1;
}
if ((input[cursor+2*i+1] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i+1]);
return -1;
}
inchar = ((input[cursor+2*i] & 0x0f) << 4) | (input[cursor+2*i+1] & 0x0f);
}
else // binary else // binary
{ {
inchar = input[cursor+i] & 0xff; inchar = input[cursor+i] & 0xff;
} }
if (inchar != ((sum >> 8*j) & 0xff)) if (inchar != ((sum >> 8*j) & 0xff))
{ {
error("Input byte 0x%02X does not match checksum 0x%0*lX\n", debug("ChecksumConverter %s: Input byte 0x%02X does not match checksum 0x%0*X\n",
inchar, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, inchar, 2*checksumMap[fnum].bytes, sum);
return -1; return -1;
} }
} }
} }
if (format.flags & zero_flag) // ASCII return expectedLength;
return 2*checksumMap[fnum].bytes;
return checksumMap[fnum].bytes;
} }
RegisterConverter (ChecksumConverter, "<"); RegisterConverter (ChecksumConverter, "<");

View File

@ -36,7 +36,7 @@ class EnumConverter : public StreamFormatConverter
int EnumConverter:: int EnumConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool) const char*& source, bool scanFormat)
{ {
if (fmt.flags & (left_flag|sign_flag|space_flag|zero_flag)) if (fmt.flags & (left_flag|sign_flag|space_flag|zero_flag))
{ {
@ -56,7 +56,30 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
if (*source == '=' && (fmt.flags & alt_flag)) if (*source == '=' && (fmt.flags & alt_flag))
{ {
char* p; char* p;
index = strtol(++source, &p, 0);
if (*++source == '?')
{
// default choice
if (scanFormat)
{
error("Default value only allowed in output formats\n");
return false;
}
if (*++source != '}')
{
error("Default value must be last\n");
return false;
}
source++;
numEnums = -(numEnums+1);
info.append('\0');
memcpy(info(n), &numEnums, sizeof(numEnums));
debug("EnumConverter::parse %ld choices with default: %s\n",
-numEnums, info.expand()());
return enum_format;
}
index = strtol(source, &p, 0);
if (p == source || (*p != '|' && *p != '}')) if (p == source || (*p != '|' && *p != '}'))
{ {
error("Integer expected after '=' " error("Integer expected after '=' "
@ -99,6 +122,9 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
const char* s = fmt.info; const char* s = fmt.info;
long numEnums = extract<long>(s); long numEnums = extract<long>(s);
long index = extract<long>(s); long index = extract<long>(s);
bool noDefault = numEnums >= 0;
if (numEnums < 0) numEnums=-numEnums-1;
while (numEnums-- && (value != index)) while (numEnums-- && (value != index))
{ {
while(*s) while(*s)
@ -109,7 +135,7 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
s++; s++;
index = extract<long>(s); index = extract<long>(s);
} }
if (numEnums == -1) if (numEnums == -1 && noDefault)
{ {
error("Value %li not found in enum set\n", value); error("Value %li not found in enum set\n", value);
return false; return false;

View File

@ -79,12 +79,11 @@ include $(TOP)/configure/RULES
# Update version string (contains __DATE__ and __TIME__) # Update version string (contains __DATE__ and __TIME__)
# each time make runs. # each time make runs.
StreamVersion$(OBJ): FORCE StreamVersion$(OBJ): ../*.c ../*.h ../*.cc ../CONFIG_STREAM ../Makefile
FORCE:
# Add references to all registrars to main file to avoid # Add references to all registrars to main file to avoid
# missing initialization. # missing initialization.
StreamCore$(OBJ): streamReferences StreamCore$(OBJ) StreamCore$(DEP): streamReferences
streamReferences: ../CONFIG_STREAM streamReferences: ../CONFIG_STREAM
$(PERL) ../makeref.pl Interface $(BUSSES) > $@ $(PERL) ../makeref.pl Interface $(BUSSES) > $@
@ -94,4 +93,7 @@ streamReferences: ../CONFIG_STREAM
$(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM $(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM
$(PERL) ../makedbd.pl $(RECORDS) > $@ $(PERL) ../makedbd.pl $(RECORDS) > $@
$(LIBRARY_DEFAULT).dbd$(DEP): ../CONFIG_STREAM
echo $(LIBRARY_DEFAULT).dbd: $< > $@
endif endif

View File

@ -39,7 +39,4 @@ include $(TOP)/config/RULES.Host
# create stream.dbd from all RECORDS # create stream.dbd from all RECORDS
stream.dbd: ../CONFIG_STREAM stream.dbd: ../CONFIG_STREAM
@for r in $(RECORDS_3_13); \ $(PERL) ../makedbd.pl -3.13 $(RECORDS_3_13) > $@
do echo "device($$r,INST_IO,dev$${r}Stream,\"stream\")"; \
done > $@
@echo "driver(stream)" >> $@

View File

@ -75,7 +75,7 @@ printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
int prec = fmt.prec; int prec = fmt.prec;
if (prec < 1) prec = 6; if (prec < 1) prec = 6;
buf.printf("%.*e", prec-1, fabs(value)/pow(10.0, prec-1)); buf.print("%.*e", prec-1, fabs(value)/pow(10.0, prec-1));
buf.remove(1,1); buf.remove(1,1);
buf.remove(buf.find('e'),1); buf.remove(buf.find('e'),1);

View File

@ -31,23 +31,23 @@ class RawConverter : public StreamFormatConverter
}; };
int RawConverter:: int RawConverter::
parse(const StreamFormat&, StreamBuffer&, parse(const StreamFormat& fmt, StreamBuffer&,
const char*&, bool) const char*&, bool)
{ {
return long_format; return (fmt.flags & (sign_flag|zero_flag)) ? signed_format : unsigned_format;
} }
bool RawConverter:: bool RawConverter::
printLong(const StreamFormat& format, StreamBuffer& output, long value) printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
int prec = format.prec; // number of bytes from value int prec = fmt.prec; // number of bytes from value
if (prec == -1) prec = 1; // default: 1 byte if (prec == -1) prec = 1; // default: 1 byte
int width = prec; // number of bytes in output int width = prec; // number of bytes in output
if (prec > (int)sizeof(long)) prec=sizeof(long); if (prec > (int)sizeof(long)) prec=sizeof(long);
if (format.width > width) width = format.width; if (fmt.width > width) width = fmt.width;
char byte = 0; char byte = 0;
if (format.flags & alt_flag) // little endian (lsb first) if (fmt.flags & alt_flag) // little endian (lsb first)
{ {
while (prec--) while (prec--)
{ {
@ -56,7 +56,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
value >>= 8; value >>= 8;
width--; width--;
} }
if (format.flags & zero_flag) if (fmt.flags & zero_flag)
{ {
// fill with zero // fill with zero
byte = 0; byte = 0;
@ -73,7 +73,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
} }
else // big endian (msb first) else // big endian (msb first)
{ {
if (format.flags & zero_flag) if (fmt.flags & zero_flag)
{ {
// fill with zero // fill with zero
byte = 0; byte = 0;
@ -97,17 +97,17 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
} }
int RawConverter:: int RawConverter::
scanLong(const StreamFormat& format, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
long length = 0; long length = 0;
long val = 0; long val = 0;
int width = format.width; int width = fmt.width;
if (width == 0) width = 1; // default: 1 byte if (width == 0) width = 1; // default: 1 byte
if (format.flags & skip_flag) if (fmt.flags & skip_flag)
{ {
return width; // just skip input return width; // just skip input
} }
if (format.flags & alt_flag) if (fmt.flags & alt_flag)
{ {
// little endian (lsb first) // little endian (lsb first)
unsigned int shift = 0; unsigned int shift = 0;
@ -118,7 +118,7 @@ scanLong(const StreamFormat& format, const char* input, long& value)
} }
if (width == 0) if (width == 0)
{ {
if (format.flags & zero_flag) if (fmt.flags & zero_flag)
{ {
// fill with zero // fill with zero
val |= ((unsigned char) input[length++]) << shift; val |= ((unsigned char) input[length++]) << shift;
@ -134,7 +134,7 @@ scanLong(const StreamFormat& format, const char* input, long& value)
else else
{ {
// big endian (msb first) // big endian (msb first)
if (format.flags & zero_flag) if (fmt.flags & zero_flag)
{ {
// fill with zero // fill with zero
val = (unsigned char) input[length++]; val = (unsigned char) input[length++];

View File

@ -23,7 +23,7 @@
#include "string.h" #include "string.h"
#include "pcre.h" #include "pcre.h"
// Perl regular expressions (PCRE) %/regexp/ // Perl regular expressions (PCRE) %/regexp/ and %#/regexp/subst/
/* Notes: /* Notes:
- Memory for compiled regexp is allocated in parse but never freed. - Memory for compiled regexp is allocated in parse but never freed.
@ -37,15 +37,17 @@
class RegexpConverter : public StreamFormatConverter class RegexpConverter : public StreamFormatConverter
{ {
int parse (const StreamFormat&, StreamBuffer&, const char*&, bool); int parse (const StreamFormat& fmt, StreamBuffer&, const char*&, bool);
int scanString(const StreamFormat&, const char*, char*, size_t); int scanString(const StreamFormat& fmt, const char*, char*, size_t);
int scanPseudo(const StreamFormat& fmt, StreamBuffer& input, long& cursor);
bool printPseudo(const StreamFormat& fmt, StreamBuffer& output);
}; };
int RegexpConverter:: int RegexpConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool scanFormat) const char*& source, bool scanFormat)
{ {
if (!scanFormat) if (!scanFormat && !(fmt.flags & alt_flag))
{ {
error("Format conversion %%/regexp/ is only allowed in input formats\n"); error("Format conversion %%/regexp/ is only allowed in input formats\n");
return false; return false;
@ -55,28 +57,31 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
error("Subexpression index %d too big (>9)\n", fmt.prec); error("Subexpression index %d too big (>9)\n", fmt.prec);
return false; return false;
} }
if (fmt.flags & (left_flag|space_flag|zero_flag|alt_flag))
{
error("Use of modifiers '-', ' ', '0', '#'"
"not allowed with %%/regexp/ conversion\n");
return false;
}
StreamBuffer pattern; StreamBuffer pattern;
while (*source != '/') while (*source != '/')
{ {
if (!*source) { if (!*source) {
error("Missing closing '/' after %%/ format conversion\n"); error("Missing closing '/' after %%/%s format conversion\n", pattern());
return false; return false;
} }
if (*source == esc) { if (*source == esc) { // handle escaped chars
source++; if (*++source != '/') // just un-escape /
pattern.printf("\\x%02x", *source++ & 0xFF); {
continue; pattern.append('\\');
if ((*source & 0x7f) < 0x30) // handle control chars
{
pattern.print("x%02x", *source++);
continue;
}
// fall through for PCRE codes like \B
}
} }
pattern.append(*source++); pattern.append(*source++);
} }
source++; source++;
debug("regexp = \"%s\"\n", pattern()); debug("regexp = \"%s\"\n", pattern.expand()());
const char* errormsg; const char* errormsg;
int eoffset; int eoffset;
pcre* code = pcre_compile(pattern(), 0, pcre* code = pcre_compile(pattern(), 0,
@ -87,6 +92,26 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
return false; return false;
} }
info.append(&code, sizeof(code)); info.append(&code, sizeof(code));
if (fmt.flags & alt_flag)
{
StreamBuffer subst;
debug("check for subst in \"%s\"\n", StreamBuffer(source).expand()());
while (*source != '/')
{
if (!*source) {
error("Missing closing '/' after %%#/%s/%s format conversion\n", pattern(), subst());
return false;
}
if (*source == esc)
subst.append(*source++);
subst.append(*source++);
}
source++;
debug("subst = \"%s\"\n", subst.expand()());
info.append(subst).append('\0');
return pseudo_format;
}
return string_format; return string_format;
} }
@ -94,32 +119,130 @@ int RegexpConverter::
scanString(const StreamFormat& fmt, const char* input, scanString(const StreamFormat& fmt, const char* input,
char* value, size_t maxlen) char* value, size_t maxlen)
{ {
pcre* code;
size_t len;
int ovector[30]; int ovector[30];
int rc; int rc;
int subexpr = 0; unsigned int l;
memcpy (&code, fmt.info, sizeof(code)); const char* info = fmt.info;
pcre* code = extract<pcre*>(info);
int length = fmt.width > 0 ? fmt.width : strlen(input);
int subexpr = fmt.prec > 0 ? fmt.prec : 0;
len = fmt.width > 0 ? fmt.width : strlen(input); debug("input = \"%s\"\n", input);
subexpr = fmt.prec > 0 ? fmt.prec : 0; debug("length=%d\n", length);
rc = pcre_exec(code, NULL, input, len, 0, 0, ovector, 30);
if (rc < 1) return -1; rc = pcre_exec(code, NULL, input, length, 0, 0, ovector, 30);
if (fmt.flags & skip_flag) return ovector[1]; debug("pcre_exec match \"%.*s\" result = %d\n", length, input, rc);
len = ovector[subexpr*2+1] - ovector[subexpr*2]; if ((subexpr && rc <= subexpr) || rc < 0)
if (len >= maxlen) { {
// error or no match or not enough sub-expressions
return -1;
}
if (fmt.flags & skip_flag) return ovector[subexpr*2+1];
l = ovector[subexpr*2+1] - ovector[subexpr*2];
if (l >= maxlen) {
if (!(fmt.flags & sign_flag)) { if (!(fmt.flags & sign_flag)) {
debug("Matching string \"%s\" too long (%d>%d bytes)\n", error("Regexp: Matching string \"%s\" too long (%d>%ld bytes). You may want to try the + flag: \"%%+/.../\"\n",
StreamBuffer(input+ovector[subexpr*2], len).expand()(), StreamBuffer(input + ovector[subexpr*2],l).expand()(),
(int)len, (int)maxlen-1); l, (long)maxlen-1);
return -1; return -1;
} }
len = maxlen-1; l = maxlen-1;
} }
memcpy(value, input+ovector[subexpr*2], len); memcpy(value, input + ovector[subexpr*2], l);
value[len]=0; value[l] = '\0';
return ovector[1]; return ovector[1]; // consume input until end of match
}
static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, long start)
{
const char* subst = fmt.info;
pcre* code = extract<pcre*>(subst);
long length;
int rc, l, c, r, rl, n;
int ovector[30];
StreamBuffer s;
length = buffer.length() - start;
if (fmt.width && fmt.width < length)
length = fmt.width;
if (fmt.flags & sign_flag)
start = buffer.length() - length;
debug("regsubst buffer=\"%s\", start=%ld, length=%ld, subst = \"%s\"\n",
buffer.expand()(), start, length, subst);
for (c = 0, n = 1; c < length; n++)
{
rc = pcre_exec(code, NULL, buffer(start+c), length-c, 0, 0, ovector, 30);
debug("pcre_exec match \"%.*s\" result = %d\n", (int)length-c, buffer(start+c), rc);
if (rc < 0) // no match
return;
if (!(fmt.flags & sign_flag) && n < fmt.prec) // without + flag
{
// do not yet replace this match
c += ovector[1];
continue;
}
// replace & by match in subst
l = ovector[1] - ovector[0];
debug("start = \"%s\"\n", buffer(start+c));
debug("match = \"%.*s\"\n", l, buffer(start+c+ovector[0]));
for (r = 1; r < rc; r++)
debug("sub%d = \"%.*s\"\n", r, ovector[r*2+1]-ovector[r*2], buffer(start+c+ovector[r*2]));
debug("rest = \"%s\"\n", buffer(start+c+ovector[1]));
s = subst;
debug("subs = \"%s\"\n", s.expand()());
for (r = 0; r < s.length(); r++)
{
debug("check \"%s\"\n", s.expand(r)());
if (s[r] == esc)
{
unsigned char ch = s[r+1];
if (ch < 9) // escaped 0 - 9 : replace with subexpr
{
ch *= 2;
rl = ovector[ch+1] - ovector[ch];
debug("replace \\%d: \"%.*s\"\n", ch/2, rl, buffer(start+c+ovector[ch]));
s.replace(r, 2, buffer(start+c+ovector[ch]), rl);
r += rl - 1;
}
else
s.remove(r, 1); // just remove escape
}
else if (s[r] == '&') // unescaped & : replace with match
{
debug("replace &: \"%.*s\"\n", l, buffer(start+c+ovector[0]));
s.replace(r, 1, buffer(start+c+ovector[0]), l);
r += l - 1;
}
else continue;
debug("subs = \"%s\"\n", s());
}
buffer.replace(start+c+ovector[0], l, s);
length += s.length() - l;
c += ovector[0] + s.length();
if (n == fmt.prec) // max match reached
return;
}
}
int RegexpConverter::
scanPseudo(const StreamFormat& fmt, StreamBuffer& input, long& cursor)
{
/* re-write input buffer */
regsubst(fmt, input, cursor);
return 0;
}
bool RegexpConverter::
printPseudo(const StreamFormat& fmt, StreamBuffer& output)
{
/* re-write output buffer */
regsubst(fmt, output, 0);
return true;
} }
RegisterConverter (RegexpConverter, "/"); RegisterConverter (RegexpConverter, "/");

View File

@ -30,15 +30,17 @@
#define vsnprintf epicsVsnprintf #define vsnprintf epicsVsnprintf
#endif #endif
#define P PRINTF_SIZE_T_PREFIX
void StreamBuffer:: void StreamBuffer::
init(const void* s, long minsize) init(const void* s, ssize_t minsize)
{ {
len = 0; len = 0;
offs = 0; offs = 0;
buffer = local; buffer = local;
cap = sizeof(local); cap = sizeof(local);
if (minsize < 0) minsize = 0; if (minsize < 0) minsize = 0;
if (minsize >= cap) if ((size_t)minsize >= cap)
{ {
// use allocated buffer // use allocated buffer
grow(minsize); grow(minsize);
@ -55,18 +57,18 @@ init(const void* s, long minsize)
} }
// How the buffer looks like: // How the buffer looks like:
// |----free-----|####used####|-------free-------| // |----free-----|####used####|--------00--------|
///|<--- offs -->|<-- len --->|<- cap-offs-len ->| ///|<--- offs -->|<-- len --->|<- cap-offs-len ->|
// 0 offs offs+len cap // 0 offs offs+len cap
// |<-------------- minsize ---------------> // |<-------------- minsize --------------->
void StreamBuffer:: void StreamBuffer::
grow(long minsize) grow(size_t minsize)
{ {
// make space for minsize + 1 (for termination) bytes // make space for minsize + 1 (for termination) bytes
char* newbuffer; char* newbuffer;
long newcap; size_t newcap;
#ifdef EXPLODE #ifdef EXPLODE
if (minsize > 1000000) if (minsize > 1000000)
{ {
@ -117,12 +119,12 @@ grow(long minsize)
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
append(const void* s, long size) append(const void* s, ssize_t size)
{ {
if (size <= 0) if (size <= 0)
{ {
// append negative number of bytes? let's delete some // append negative number of bytes? let's delete some
if (size < -len) size = -len; if (size < -(ssize_t)len) size = -(ssize_t)len;
memset (buffer+offs+len+size, 0, -size); memset (buffer+offs+len+size, 0, -size);
} }
else else
@ -134,8 +136,8 @@ append(const void* s, long size)
return *this; return *this;
} }
long int StreamBuffer:: ssize_t StreamBuffer::
find(const void* m, long size, long start) const find(const void* m, size_t size, ssize_t start) const
{ {
if (start < 0) if (start < 0)
{ {
@ -147,7 +149,7 @@ find(const void* m, long size, long start) const
const char* s = static_cast<const char*>(m); const char* s = static_cast<const char*>(m);
char* b = buffer+offs; char* b = buffer+offs;
char* p = b+start; char* p = b+start;
long i; size_t i;
while ((p = static_cast<char*>(memchr(p, s[0], b-p+len-size+1)))) while ((p = static_cast<char*>(memchr(p, s[0], b-p+len-size+1))))
{ {
for (i = 1; i < size; i++) for (i = 1; i < size; i++)
@ -161,7 +163,7 @@ next: p++;
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
replace(long remstart, long remlen, const void* ins, long inslen) replace(ssize_t remstart, ssize_t remlen, const void* ins, ssize_t inslen)
{ {
if (remstart < 0) if (remstart < 0)
{ {
@ -187,12 +189,12 @@ replace(long remstart, long remlen, const void* ins, long inslen)
remlen += remstart; remlen += remstart;
remstart = 0; remstart = 0;
} }
if (remstart > len) if ((size_t)remstart > len)
{ {
// remove begins after bufferend // remove begins after bufferend
remstart = len; remstart = len;
} }
if (remlen >= len-remstart) if ((size_t)remlen >= len-remstart)
{ {
// truncate remove after bufferend // truncate remove after bufferend
remlen = len-remstart; remlen = len-remstart;
@ -205,12 +207,12 @@ replace(long remstart, long remlen, const void* ins, long inslen)
return *this; return *this;
} }
if (inslen < 0) inslen = 0; if (inslen < 0) inslen = 0;
long remend = remstart+remlen; size_t remend = remstart+remlen;
long newlen = len+inslen-remlen; size_t newlen = len+inslen-remlen;
if (cap <= newlen) if (cap <= newlen)
{ {
// buffer too short // buffer too short
long newcap; size_t newcap;
for (newcap = sizeof(local)*2; newcap <= newlen; newcap *= 2); for (newcap = sizeof(local)*2; newcap <= newlen; newcap *= 2);
char* newbuffer = new char[newcap]; char* newbuffer = new char[newcap];
memcpy(newbuffer, buffer+offs, remstart); memcpy(newbuffer, buffer+offs, remstart);
@ -248,16 +250,16 @@ replace(long remstart, long remlen, const void* ins, long inslen)
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
printf(const char* fmt, ...) print(const char* fmt, ...)
{ {
va_list va; va_list va;
int printed; ssize_t printed;
while (1) while (1)
{ {
va_start(va, fmt); va_start(va, fmt);
printed = vsnprintf(buffer+offs+len, cap-offs-len, fmt, va); printed = vsnprintf(buffer+offs+len, cap-offs-len, fmt, va);
va_end(va); va_end(va);
if (printed > -1 && printed < (int)(cap-offs-len)) if (printed > -1 && printed < (ssize_t)(cap-offs-len))
{ {
len += printed; len += printed;
return *this; return *this;
@ -267,9 +269,9 @@ printf(const char* fmt, ...)
} }
} }
StreamBuffer StreamBuffer::expand(long start, long length) const StreamBuffer StreamBuffer::expand(ssize_t start, ssize_t length) const
{ {
long end; size_t end;
if (start < 0) if (start < 0)
{ {
start += len; start += len;
@ -289,14 +291,14 @@ StreamBuffer StreamBuffer::expand(long start, long length) const
StreamBuffer result((end-start)*2); StreamBuffer result((end-start)*2);
start += offs; start += offs;
end += offs; end += offs;
long i; size_t i;
char c; char c;
for (i = start; i < end; i++) for (i = start; i < end; i++)
{ {
c = buffer[i]; c = buffer[i];
if ((c & 0x7f) < 0x20 || (c & 0x7f) == 0x7f) if (c < 0x20 || c >= 0x7f)
{ {
result.printf("<%02x>", c & 0xff); result.print("<%02x>", c & 0xff);
} }
else else
{ {
@ -311,18 +313,18 @@ dump() const
{ {
StreamBuffer result(256+cap*5); StreamBuffer result(256+cap*5);
result.append("\033[0m"); result.append("\033[0m");
long i; size_t i;
result.printf("%ld,%ld,%ld:\033[37m", offs, len, cap); result.print("%"P"d,%"P"d,%"P"d:\033[37m", offs, len, cap);
for (i = 0; i < cap; i++) for (i = 0; i < cap; i++)
{ {
if (i == offs) result.append("\033[34m[\033[0m"); if (i == offs) result.append("\033[34m[\033[0m");
if ((buffer[i] & 0x7f) < 0x20 || (buffer[i] & 0x7f) == 0x7f) if ((buffer[i] & 0x7f) < 0x20 || (buffer[i] & 0x7f) == 0x7f)
{ {
if (i < offs || i >= offs+len) if (i < offs || i >= offs+len)
result.printf( result.print(
"<%02x>", buffer[i] & 0xff); "<%02x>", buffer[i] & 0xff);
else else
result.printf( result.print(
"\033[34m<%02x>\033[37m", buffer[i] & 0xff); "\033[34m<%02x>\033[37m", buffer[i] & 0xff);
} }
else else

View File

@ -21,30 +21,34 @@
#define StreamBuffer_h #define StreamBuffer_h
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdlib.h>
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(x) #define __attribute__(x)
#endif #endif
#ifdef _WIN32
#define ssize_t ptrdiff_t
#endif
class StreamBuffer class StreamBuffer
{ {
char local[64]; char local[64];
long len; size_t len;
long cap; size_t cap;
long offs; size_t offs;
char* buffer; char* buffer;
void init(const void* s, long minsize); void init(const void* s, ssize_t minsize);
void check(long size) void check(size_t size)
{if (len+offs+size >= cap) grow(len+size);} {if (len+offs+size >= cap) grow(len+size);}
void grow(long minsize); void grow(size_t minsize);
public: public:
// Hints: // Hints:
// * Any index parameter (long) can be negative // * Any index parameter (ssize_t) can be negative
// meaning "count from end" (-1 is the last byte) // meaning "count from end" (-1 is the last byte)
// * Appending negative count deletes from end // * Appending negative count deletes from end
// * Any returned char* pointer becomes invalid when // * Any returned char* pointer becomes invalid when
@ -55,7 +59,7 @@ public:
StreamBuffer() StreamBuffer()
{init(NULL, 0);} {init(NULL, 0);}
StreamBuffer(const void* s, long size) StreamBuffer(const void* s, ssize_t size)
{init(s, size);} {init(s, size);}
StreamBuffer(const char* s) StreamBuffer(const char* s)
@ -64,24 +68,24 @@ public:
StreamBuffer(const StreamBuffer& s) StreamBuffer(const StreamBuffer& s)
{init(s.buffer+s.offs, s.len);} {init(s.buffer+s.offs, s.len);}
StreamBuffer(long size) StreamBuffer(ssize_t size)
{init(NULL, size);} {init(NULL, size);}
~StreamBuffer() ~StreamBuffer()
{if (buffer != local) delete buffer;} {if (buffer != local) delete buffer;}
// operator (): get char* pointing to index // operator (): get char* pointing to index
const char* operator()(long index=0) const const char* operator()(ssize_t index=0) const
{return buffer+offs+(index<0?index+len:index);} {return buffer+offs+(index<0?index+len:index);}
char* operator()(long index=0) char* operator()(ssize_t index=0)
{return buffer+offs+(index<0?index+len:index);} {return buffer+offs+(index<0?index+len:index);}
// operator []: get byte at index // operator []: get byte at index
char operator[](long index) const char operator[](ssize_t index) const
{return buffer[offs+(index<0?index+len:index)];} {return buffer[offs+(index<0?index+len:index)];}
char& operator[](long index) char& operator[](ssize_t index)
{return buffer[offs+(index<0?index+len:index)];} {return buffer[offs+(index<0?index+len:index)];}
// cast to bool: not empty? // cast to bool: not empty?
@ -89,11 +93,11 @@ public:
{return len>0;} {return len>0;}
// length: get current data length // length: get current data length
long length() const ssize_t length() const
{return len;} {return len;}
// capacity: get current max data length (spare one byte for end) // capacity: get current max data length (spare one byte for end)
long capacity() const ssize_t capacity() const
{return cap-1;} {return cap-1;}
// end: get pointer to byte after last data byte // end: get pointer to byte after last data byte
@ -106,19 +110,19 @@ public:
// reserve: reserve size bytes of memory and return // reserve: reserve size bytes of memory and return
// pointer to that memory (for copying something to it) // pointer to that memory (for copying something to it)
char* reserve(long size) char* reserve(size_t size)
{check(size); char* p=buffer+offs+len; len+=size; return p;} {check(size); char* p=buffer+offs+len; len+=size; return p;}
// append: append data at the end of the buffer // append: append data at the end of the buffer
StreamBuffer& append(char c) StreamBuffer& append(char c)
{check(1); buffer[offs+len++]=c; return *this;} {check(1); buffer[offs+len++]=c; return *this;}
StreamBuffer& append(char c, long count) StreamBuffer& append(char c, ssize_t count)
{if (count < 0) truncate(count); {if (count < 0) truncate(count);
else {check(count); memset(buffer+offs+len, c, count); len+=count;} else {check(count); memset(buffer+offs+len, c, count); len+=count;}
return *this;} return *this;}
StreamBuffer& append(const void* s, long size); StreamBuffer& append(const void* s, ssize_t size);
StreamBuffer& append(const char* s) StreamBuffer& append(const char* s)
{return append(s, s?strlen(s):0);} {return append(s, s?strlen(s):0);}
@ -126,7 +130,7 @@ public:
StreamBuffer& append(const StreamBuffer& s) StreamBuffer& append(const StreamBuffer& s)
{return append(s.buffer+s.offs, s.len);} {return append(s.buffer+s.offs, s.len);}
// operator += alias for set // operator += alias for append
StreamBuffer& operator+=(char c) StreamBuffer& operator+=(char c)
{return append(c);} {return append(c);}
@ -137,7 +141,7 @@ public:
{return append(s);} {return append(s);}
// set: clear buffer and fill with new data // set: clear buffer and fill with new data
StreamBuffer& set(const void* s, long size) StreamBuffer& set(const void* s, size_t size)
{clear(); return append(s, size);} {clear(); return append(s, size);}
StreamBuffer& set(const char* s) StreamBuffer& set(const char* s)
@ -155,61 +159,61 @@ public:
// replace: delete part of buffer (pos/length) and insert new data // replace: delete part of buffer (pos/length) and insert new data
StreamBuffer& replace( StreamBuffer& replace(
long pos, long length, const void* s, long size); ssize_t pos, ssize_t length, const void* s, ssize_t size);
StreamBuffer& replace(long pos, long length, const char* s) StreamBuffer& replace(ssize_t pos, ssize_t length, const char* s)
{return replace(pos, length, s, s?strlen(s):0);} {return replace(pos, length, s, s?strlen(s):0);}
StreamBuffer& replace(long pos, long length, const StreamBuffer& s) StreamBuffer& replace(ssize_t pos, ssize_t length, const StreamBuffer& s)
{return replace(pos, length, s.buffer+s.offs, s.len);} {return replace(pos, length, s.buffer+s.offs, s.len);}
// remove: delete from start/pos // remove: delete from start/pos
StreamBuffer& remove(long pos, long length) StreamBuffer& remove(ssize_t pos, ssize_t length)
{return replace(pos, length, NULL, 0);} {return replace(pos, length, NULL, 0);}
// remove from start: no memset, no function call, fast! // remove from start: no memset, no function call, fast!
StreamBuffer& remove(long length) StreamBuffer& remove(size_t length)
{if (length>len) length=len; {if (length>len) length=len;
offs+=length; len-=length; return *this;} offs+=length; len-=length; return *this;}
// truncate: delete end of buffer // truncate: delete end of buffer
StreamBuffer& truncate(long pos) StreamBuffer& truncate(ssize_t pos)
{return replace(pos, len, NULL, 0);} {return replace(pos, len, NULL, 0);}
// insert: insert new data into buffer // insert: insert new data into buffer
StreamBuffer& insert(long pos, const void* s, long size) StreamBuffer& insert(ssize_t pos, const void* s, ssize_t size)
{return replace(pos, 0, s, size);} {return replace(pos, 0, s, size);}
StreamBuffer& insert(long pos, const char* s) StreamBuffer& insert(ssize_t pos, const char* s)
{return replace(pos, 0, s, s?strlen(s):0);} {return replace(pos, 0, s, s?strlen(s):0);}
StreamBuffer& insert(long pos, const StreamBuffer& s) StreamBuffer& insert(ssize_t pos, const StreamBuffer& s)
{return replace(pos, 0, s.buffer+s.offs, s.len);} {return replace(pos, 0, s.buffer+s.offs, s.len);}
StreamBuffer& insert(long pos, char c) StreamBuffer& insert(ssize_t pos, char c)
{return replace(pos, 0, &c, 1);} {return replace(pos, 0, &c, 1);}
StreamBuffer& printf(const char* fmt, ...) StreamBuffer& print(const char* fmt, ...)
__attribute__ ((format(printf,2,3))); __attribute__ ((format(printf,2,3)));
// find: get index of data in buffer or -1 // find: get index of data in buffer or -1
long find(char c, long start=0) const ssize_t find(char c, ssize_t start=0) const
{char* p; {char* p;
return (p = static_cast<char*>( return (p = static_cast<char*>(
memchr(buffer+offs+(start<0?start+len:start), memchr(buffer+offs+(start<0?start+len:start),
c, start<0?-start:len-start)))? c, start<0?-start:len-start)))?
p-(buffer+offs) : -1;} p-(buffer+offs) : -1;}
long find(const void* s, long size, long start=0) const; ssize_t find(const void* s, size_t size, ssize_t start=0) const;
long find(const char* s, long start=0) const ssize_t find(const char* s, ssize_t start=0) const
{return find(s, s?strlen(s):0, start);} {return find(s, s?strlen(s):0, start);}
long int find(const StreamBuffer& s, long start=0) const ssize_t find(const StreamBuffer& s, ssize_t start=0) const
{return find(s.buffer+s.offs, s.len, start);} {return find(s.buffer+s.offs, s.len, start);}
// startswith: returns true if first size bytes are equal // startswith: returns true if first size bytes are equal
bool startswith(const void* s, long size) const bool startswith(const void* s, size_t size) const
{return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;} {return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;}
// startswith: returns true if first string is equal (empty string matches) // startswith: returns true if first string is equal (empty string matches)
@ -218,9 +222,9 @@ public:
// expand: create copy of StreamBuffer where all nonprintable characters // expand: create copy of StreamBuffer where all nonprintable characters
// are replaced by <xx> with xx being the hex code of the characters // are replaced by <xx> with xx being the hex code of the characters
StreamBuffer expand(long start, long length) const; StreamBuffer expand(ssize_t start, ssize_t length) const;
StreamBuffer expand(long start=0) const StreamBuffer expand(ssize_t start=0) const
{return expand(start, len);} {return expand(start, len);}
// dump: debug function, like expand but also show the 'hidden' memory // dump: debug function, like expand but also show the 'hidden' memory
@ -228,4 +232,13 @@ public:
StreamBuffer dump() const; StreamBuffer dump() const;
}; };
// printf size prefix for size_t and ssize_t
#if defined (__GNUC__) && __GNUC__ >= 3
#define PRINTF_SIZE_T_PREFIX "z"
#elif defined (_WIN32)
#define PRINTF_SIZE_T_PREFIX "I"
#else
#define PRINTF_SIZE_T_PREFIX ""
#endif
#endif #endif

View File

@ -18,14 +18,9 @@
***************************************************************/ ***************************************************************/
#include "StreamBusInterface.h" #include "StreamBusInterface.h"
#include "StreamError.h"
const char* StreamIoStatusStr[] = { StreamIoStatusStrClass StreamIoStatusStr;
"StreamIoSuccess",
"StreamIoTimeout",
"StreamIoNoReply",
"StreamIoEnd",
"StreamIoFault"
};
StreamBusInterfaceRegistrarBase* StreamBusInterfaceRegistrarBase::first; StreamBusInterfaceRegistrarBase* StreamBusInterfaceRegistrarBase::first;
@ -64,11 +59,17 @@ supportsAsyncRead()
StreamBusInterface* StreamBusInterface:: StreamBusInterface* StreamBusInterface::
find(Client* client, const char* busname, int addr, const char* param) find(Client* client, const char* busname, int addr, const char* param)
{ {
debug("StreamBusInterface::find(%s, %s, %d, \"%s\")\n",
client->name(), busname, addr, param);
StreamBusInterfaceRegistrarBase* r; StreamBusInterfaceRegistrarBase* r;
StreamBusInterface* bus; StreamBusInterface* bus;
for (r = r->first; r; r = r->next) for (r = StreamBusInterfaceRegistrarBase::first; r; r = r->next)
{ {
debug("StreamBusInterface::find %s check %s\n",
client->name(), r->name);
bus = r->find(client, busname, addr, param); bus = r->find(client, busname, addr, param);
debug("StreamBusInterface::find %s %s\n",
r->name, bus ? "matches" : "does not match");
if (bus) return bus; if (bus) return bus;
} }
return NULL; return NULL;

View File

@ -21,13 +21,26 @@
#define StreamBusInterface_h #define StreamBusInterface_h
#include <stddef.h> #include <stddef.h>
#include <StreamBuffer.h>
enum StreamIoStatus { enum StreamIoStatus {
StreamIoSuccess, StreamIoTimeout, StreamIoNoReply, StreamIoSuccess, StreamIoTimeout, StreamIoNoReply,
StreamIoEnd, StreamIoFault StreamIoEnd, StreamIoFault
}; };
extern const char* StreamIoStatusStr[]; class StreamIoStatusStrClass {
public:
const char* operator [] (int index) {
switch (index) {
case StreamIoSuccess: return "StreamIoSuccess";
case StreamIoTimeout: return "StreamIoTimeout";
case StreamIoNoReply: return "StreamIoNoReply";
case StreamIoEnd: return "StreamIoEnd";
case StreamIoFault: return "StreamIoFault";
default: return "illegal status";
}
}
} extern StreamIoStatusStr;
class StreamBusInterface class StreamBusInterface
{ {
@ -44,50 +57,53 @@ public:
virtual void connectCallback(StreamIoStatus status); virtual void connectCallback(StreamIoStatus status);
virtual void disconnectCallback(StreamIoStatus status); virtual void disconnectCallback(StreamIoStatus status);
virtual long priority(); virtual long priority();
virtual const char* name() = 0;
virtual const char* getInTerminator(size_t& length) = 0; virtual const char* getInTerminator(size_t& length) = 0;
virtual const char* getOutTerminator(size_t& length) = 0; virtual const char* getOutTerminator(size_t& length) = 0;
public: public:
virtual const char* name() = 0;
virtual ~Client(); virtual ~Client();
protected: protected:
StreamBusInterface* businterface; StreamBusInterface* businterface;
bool busSupportsEvent() { bool busSupportsEvent() {
return businterface->supportsEvent(); return businterface && businterface->supportsEvent();
} }
bool busSupportsAsyncRead() { bool busSupportsAsyncRead() {
return businterface->supportsAsyncRead(); return businterface && businterface->supportsAsyncRead();
} }
bool busAcceptEvent(unsigned long mask, bool busAcceptEvent(unsigned long mask,
unsigned long replytimeout_ms) { unsigned long replytimeout_ms) {
return businterface->acceptEvent(mask, replytimeout_ms); return businterface && businterface->acceptEvent(mask, replytimeout_ms);
} }
void busRelease() { void busRelease() {
businterface->release(); if (businterface) businterface->release();
} }
bool busLockRequest(unsigned long timeout_ms) { bool busLockRequest(unsigned long timeout_ms) {
return businterface->lockRequest(timeout_ms); return businterface && businterface->lockRequest(timeout_ms);
} }
bool busUnlock() { bool busUnlock() {
return businterface->unlock(); return businterface && businterface->unlock();
} }
bool busWriteRequest(const void* output, size_t size, bool busWriteRequest(const void* output, size_t size,
unsigned long timeout_ms) { unsigned long timeout_ms) {
return businterface->writeRequest(output, size, timeout_ms); return businterface && businterface->writeRequest(output, size, timeout_ms);
} }
bool busReadRequest(unsigned long replytimeout_ms, bool busReadRequest(unsigned long replytimeout_ms,
unsigned long readtimeout_ms, long expectedLength, unsigned long readtimeout_ms, long expectedLength,
bool async) { bool async) {
return businterface->readRequest(replytimeout_ms, return businterface && businterface->readRequest(replytimeout_ms,
readtimeout_ms, expectedLength, async); readtimeout_ms, expectedLength, async);
} }
void busFinish() { void busFinish() {
businterface->finish(); if (businterface) businterface->finish();
} }
bool busConnectRequest(unsigned long timeout_ms) { bool busConnectRequest(unsigned long timeout_ms) {
return businterface->connectRequest(timeout_ms); return businterface && businterface->connectRequest(timeout_ms);
} }
bool busDisconnect() { bool busDisconnect() {
return businterface->disconnectRequest(); return businterface && businterface->disconnectRequest();
}
void busPrintStatus(StreamBuffer& buffer) {
if (businterface) businterface->printStatus(buffer);
} }
}; };
@ -137,6 +153,7 @@ protected:
virtual bool connectRequest(unsigned long connecttimeout_ms); virtual bool connectRequest(unsigned long connecttimeout_ms);
virtual bool disconnectRequest(); virtual bool disconnectRequest();
virtual void finish(); virtual void finish();
virtual void printStatus(StreamBuffer& buffer) {};
// pure virtual // pure virtual
virtual bool lockRequest(unsigned long timeout_ms) = 0; virtual bool lockRequest(unsigned long timeout_ms) = 0;

View File

@ -23,6 +23,8 @@
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#define P PRINTF_SIZE_T_PREFIX
enum Commands { end_cmd, in_cmd, out_cmd, wait_cmd, event_cmd, exec_cmd, enum Commands { end_cmd, in_cmd, out_cmd, wait_cmd, event_cmd, exec_cmd,
connect_cmd, disconnect_cmd }; connect_cmd, disconnect_cmd };
const char* commandStr[] = { "end", "in", "out", "wait", "event", "exec", const char* commandStr[] = { "end", "in", "out", "wait", "event", "exec",
@ -57,12 +59,12 @@ static char* printCommands(StreamBuffer& buffer, const char* c)
break; break;
case wait_cmd: case wait_cmd:
timeout = extract<unsigned long>(c); timeout = extract<unsigned long>(c);
buffer.printf(" wait %ld;\n # ms", timeout); buffer.print(" wait %ld; # ms\n", timeout);
break; break;
case event_cmd: case event_cmd:
eventnumber = extract<unsigned long>(c); eventnumber = extract<unsigned long>(c);
timeout = extract<unsigned long>(c); timeout = extract<unsigned long>(c);
buffer.printf(" event(%ld) %ld; # ms\n", eventnumber, timeout); buffer.print(" event(%ld) %ld; # ms\n", eventnumber, timeout);
break; break;
case exec_cmd: case exec_cmd:
buffer.append(" exec \""); buffer.append(" exec \"");
@ -71,7 +73,7 @@ static char* printCommands(StreamBuffer& buffer, const char* c)
break; break;
case connect_cmd: case connect_cmd:
timeout = extract<unsigned long>(c); timeout = extract<unsigned long>(c);
buffer.printf(" connect %ld; # ms\n", timeout); buffer.print(" connect %ld; # ms\n", timeout);
break; break;
case disconnect_cmd: case disconnect_cmd:
buffer.append(" disconnect;\n"); buffer.append(" disconnect;\n");
@ -118,7 +120,6 @@ printProtocol()
if (onMismatch) if (onMismatch)
printf(" @Mismatch {\n%s }\n", printf(" @Mismatch {\n%s }\n",
printCommands(buffer.clear(), onMismatch())); printCommands(buffer.clear(), onMismatch()));
debug("StreamCore::printProtocol: commands=%s\n", commands.expand()());
printf("\n%s}\n", printf("\n%s}\n",
printCommands(buffer.clear(), commands())); printCommands(buffer.clear(), commands()));
} }
@ -164,7 +165,7 @@ attachBus(const char* busname, int addr, const char* param)
businterface = StreamBusInterface::find(this, busname, addr, param); businterface = StreamBusInterface::find(this, busname, addr, param);
if (!businterface) if (!businterface)
{ {
error("Businterface '%s' not found for '%s'\n", error("Cannot find a bus named '%s' for '%s'\n",
busname, name()); busname, name());
return false; return false;
} }
@ -342,6 +343,7 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
return false; return false;
} }
args++; args++;
while (isspace(*args)) args++;
} }
buffer.append(&eventmask, sizeof(eventmask)); buffer.append(&eventmask, sizeof(eventmask));
if (*args) if (*args)
@ -458,7 +460,7 @@ finishProtocol(ProtocolResult status)
status = Fault; status = Fault;
} }
//// flags &= ~(AcceptInput|AcceptEvent); //// flags &= ~(AcceptInput|AcceptEvent);
if (runningHandler) if (runningHandler || flags & InitRun)
{ {
// get original error status // get original error status
if (status == Success) status = runningHandler; if (status == Success) status = runningHandler;
@ -747,7 +749,7 @@ printSeparator()
bool StreamCore:: bool StreamCore::
printValue(const StreamFormat& fmt, long value) printValue(const StreamFormat& fmt, long value)
{ {
if (fmt.type != long_format && fmt.type != enum_format) if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format)
{ {
error("%s: printValue(long) called with %%%c format\n", error("%s: printValue(long) called with %%%c format\n",
name(), fmt.conv); name(), fmt.conv);
@ -761,8 +763,8 @@ printValue(const StreamFormat& fmt, long value)
name(), value); name(), value);
return false; return false;
} }
debug("StreamCore::printValue(%s, long): \"%s\"\n", debug("StreamCore::printValue %s %%%c long %ld (%lx): \"%s\"\n",
name(), outputLine.expand()()); name(), fmt.conv, value, value, outputLine.expand()());
return true; return true;
} }
@ -783,8 +785,8 @@ printValue(const StreamFormat& fmt, double value)
name(), value); name(), value);
return false; return false;
} }
debug("StreamCore::printValue(%s, double): \"%s\"\n", debug("StreamCore::printValue %s %%%c double %#g: \"%s\"\n",
name(), outputLine.expand()()); name(), fmt.conv, value, outputLine.expand()());
return true; return true;
} }
@ -806,8 +808,8 @@ printValue(const StreamFormat& fmt, char* value)
name(), buffer.expand()()); name(), buffer.expand()());
return false; return false;
} }
debug("StreamCore::printValue(%s, char*): \"%s\"\n", debug("StreamCore::printValue %s %%%c char* \"%s\"): \"%s\"\n",
name(), outputLine.expand()()); name(), fmt.conv, value, outputLine.expand()());
return true; return true;
} }
@ -816,7 +818,7 @@ lockCallback(StreamIoStatus status)
{ {
MutexLock lock(this); MutexLock lock(this);
debug("StreamCore::lockCallback(%s, status=%s)\n", debug("StreamCore::lockCallback(%s, status=%s)\n",
name(), status ? "Timeout" : "Success"); name(), StreamIoStatusStr[status]);
if (!(flags & LockPending)) if (!(flags & LockPending))
{ {
error("StreamCore::lockCallback(%s) called unexpectedly\n", error("StreamCore::lockCallback(%s) called unexpectedly\n",
@ -830,9 +832,21 @@ lockCallback(StreamIoStatus status)
case StreamIoSuccess: case StreamIoSuccess:
break; break;
case StreamIoTimeout: case StreamIoTimeout:
debug("%s: Cannot lock device within %ld ms, device seems to be busy\n",
name(), lockTimeout);
flags &= ~BusOwner;
finishProtocol(LockTimeout);
return;
case StreamIoFault:
error("%s: Locking failed because of a device fault\n",
name());
flags &= ~BusOwner;
finishProtocol(LockTimeout); finishProtocol(LockTimeout);
return; return;
default: default:
error("StreamCore::lockCallback(%s) unexpected status %s\n",
name(), StreamIoStatusStr[status]);
flags &= ~BusOwner;
finishProtocol(Fault); finishProtocol(Fault);
return; return;
} }
@ -977,13 +991,13 @@ readCallback(StreamIoStatus status,
evalIn(); evalIn();
return 0; return 0;
} }
error("%s: No reply from device within %ld ms\n", debug("StreamCore::readCallback(%s): No reply from device within %ld ms\n",
name(), replyTimeout); name(), replyTimeout);
inputBuffer.clear(); inputBuffer.clear();
finishProtocol(ReplyTimeout); finishProtocol(ReplyTimeout);
return 0; return 0;
case StreamIoFault: case StreamIoFault:
error("%s: I/O error after reading %ld byte%s: \"%s%s\"\n", error("%s: I/O error after reading %"P"d byte%s: \"%s%s\"\n",
name(), name(),
inputBuffer.length(), inputBuffer.length()==1 ? "" : "s", inputBuffer.length(), inputBuffer.length()==1 ? "" : "s",
inputBuffer.length() > 20 ? "..." : "", inputBuffer.length() > 20 ? "..." : "",
@ -992,7 +1006,7 @@ readCallback(StreamIoStatus status,
return 0; return 0;
} }
inputBuffer.append(input, size); inputBuffer.append(input, size);
debug("StreamCore::readCallback(%s) inputBuffer=\"%s\", size %ld\n", debug("StreamCore::readCallback(%s) inputBuffer=\"%s\", size %"P"d\n",
name(), inputBuffer.expand()(), inputBuffer.length()); name(), inputBuffer.expand()(), inputBuffer.length());
if (*activeCommand != in_cmd) if (*activeCommand != in_cmd)
{ {
@ -1159,8 +1173,7 @@ matchInput()
*/ */
char command; char command;
const char* fieldName = NULL; const char* fieldName = NULL;
const char* formatstring; StreamBuffer formatstring;
int formatstringlen;
consumedInput = 0; consumedInput = 0;
@ -1186,22 +1199,15 @@ normal_format:
int consumed; int consumed;
// code layout: // code layout:
// formatstring <eos> StreamFormat [info] // formatstring <eos> StreamFormat [info]
formatstring = commandIndex; formatstring.clear();
// jump after <eos> commandIndex = StreamProtocolParser::printString(formatstring, commandIndex);
while (*commandIndex)
{
if (*commandIndex == esc) commandIndex++;
commandIndex++;
}
formatstringlen = commandIndex-formatstring;
commandIndex++;
StreamFormat fmt = extract<StreamFormat>(commandIndex); StreamFormat fmt = extract<StreamFormat>(commandIndex);
fmt.info = commandIndex; // point to info string fmt.info = commandIndex; // point to info string
commandIndex += fmt.infolen; commandIndex += fmt.infolen;
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("StreamCore::matchInput(%s): format = %%%s\n", debug("StreamCore::matchInput(%s): format = \"%%%s\"\n",
name(), StreamBuffer(formatstring, formatstringlen).expand()()); name(), formatstring());
#endif #endif
if (fmt.flags & skip_flag || fmt.type == pseudo_format) if (fmt.flags & skip_flag || fmt.type == pseudo_format)
@ -1210,7 +1216,8 @@ normal_format:
double ddummy; double ddummy;
switch (fmt.type) switch (fmt.type)
{ {
case long_format: case unsigned_format:
case signed_format:
case enum_format: case enum_format:
consumed = StreamFormatConverter::find(fmt.conv)-> consumed = StreamFormatConverter::find(fmt.conv)->
scanLong(fmt, inputLine(consumedInput), ldummy); scanLong(fmt, inputLine(consumedInput), ldummy);
@ -1243,10 +1250,10 @@ normal_format:
{ {
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
error("%s: Input \"%s%s\" does not match format %%%s\n", error("%s: Input \"%s%s\" does not match format \"%%%s\"\n",
name(), inputLine.expand(consumedInput, 20)(), name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "", inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring); formatstring());
} }
return false; return false;
} }
@ -1260,13 +1267,12 @@ normal_format:
flags &= ~Separator; flags &= ~Separator;
if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL)) if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL))
{ {
StreamBuffer formatstr(formatstring, formatstringlen);
if (fieldAddress) if (fieldAddress)
error("%s: Cannot format field '%s' with '%%%s'\n", error("%s: Cannot format variable \"%s\" with \"%%%s\"\n",
name(), fieldName, formatstr.expand()()); name(), fieldName, formatstring());
else else
error("%s: Cannot format value with '%%%s'\n", error("%s: Cannot format value with \"%%%s\"\n",
name(), formatstr.expand()()); name(), formatstring());
return false; return false;
} }
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
@ -1279,11 +1285,11 @@ normal_format:
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
error("%s: Input \"%s%s\" too short." error("%s: Input \"%s%s\" too short."
" No match for format %%%s (\"%s\")\n", " No match for format \"%%%s\" (\"%s\")\n",
name(), name(),
inputLine.length() > 20 ? "..." : "", inputLine.length() > 20 ? "..." : "",
inputLine.expand(-20)(), inputLine.expand(-20)(),
formatstring, formatstring(),
outputLine.expand()()); outputLine.expand()());
} }
return false; return false;
@ -1292,11 +1298,10 @@ normal_format:
{ {
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
error("%s: Input \"%s%s\" does not match" error("%s: Input \"%s%s\" does not match format \"%%%s\" (\"%s\")\n",
" format %%%s (\"%s\")\n",
name(), inputLine.expand(consumedInput, 20)(), name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "", inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring, formatstring(),
outputLine.expand()()); outputLine.expand()());
} }
return false; return false;
@ -1310,13 +1315,13 @@ normal_format:
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
if (flags & ScanTried) if (flags & ScanTried)
error("%s: Input \"%s%s\" does not match format %%%s\n", error("%s: Input \"%s%s\" does not match format \"%%%s\"\n",
name(), inputLine.expand(consumedInput, 20)(), name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "", inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring); formatstring());
else else
error("%s: Format %%%s has data type %s which does not match this variable.\n", error("%s: Format \"%%%s\" has data type %s which does not match the type of \"%s\".\n",
name(), formatstring, StreamFormatTypeStr[fmt.type] ); name(), formatstring(), StreamFormatTypeStr[fmt.type], fieldAddress ? fieldName : name());
} }
return false; return false;
} }
@ -1453,7 +1458,7 @@ matchSeparator()
long StreamCore:: long StreamCore::
scanValue(const StreamFormat& fmt, long& value) scanValue(const StreamFormat& fmt, long& value)
{ {
if (fmt.type != long_format && fmt.type != enum_format) if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format)
{ {
error("%s: scanValue(long&) called with %%%c format\n", error("%s: scanValue(long&) called with %%%c format\n",
name(), fmt.conv); name(), fmt.conv);
@ -1474,6 +1479,7 @@ scanValue(const StreamFormat& fmt, long& value)
} }
else return -1; else return -1;
} }
if (fmt.flags & fix_width_flag && consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1; if (consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %li\n", debug("StreamCore::scanValue(%s) scanned %li\n",
name(), value); name(), value);
@ -1505,6 +1511,7 @@ scanValue(const StreamFormat& fmt, double& value)
} }
else return -1; else return -1;
} }
if (fmt.flags & fix_width_flag && (consumed != (fmt.width + fmt.prec + 1))) return -1;
if (consumed > inputLine.length()-consumedInput) return -1; if (consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %#g\n", debug("StreamCore::scanValue(%s) scanned %#g\n",
name(), value); name(), value);
@ -1537,6 +1544,7 @@ scanValue(const StreamFormat& fmt, char* value, long maxlen)
} }
else return -1; else return -1;
} }
if (fmt.flags & fix_width_flag && consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1; if (consumed > inputLine.length()-consumedInput) return -1;
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("StreamCore::scanValue(%s) scanned \"%s\"\n", debug("StreamCore::scanValue(%s) scanned \"%s\"\n",
@ -1746,4 +1754,25 @@ disconnectCallback(StreamIoStatus status)
} }
} }
void StreamCore::
printStatus(StreamBuffer& buffer)
{
buffer.print("active command=%s ",
activeCommand ? commandName(*activeCommand) : "NULL");
buffer.print("flags=0x%04lx ", flags);
if (flags & IgnoreExtraInput) buffer.append("IgnoreExtraInput ");
if (flags & InitRun) buffer.append("InitRun ");
if (flags & AsyncMode) buffer.append("AsyncMode ");
if (flags & GotValue) buffer.append("GotValue ");
if (flags & BusOwner) buffer.append("BusOwner ");
if (flags & Separator) buffer.append("Separator ");
if (flags & ScanTried) buffer.append("ScanTried ");
if (flags & AcceptInput) buffer.append("AcceptInput ");
if (flags & AcceptEvent) buffer.append("AcceptEvent ");
if (flags & LockPending) buffer.append("LockPending ");
if (flags & WritePending) buffer.append("WritePending ");
if (flags & WaitPending) buffer.append("WaitPending ");
busPrintStatus(buffer);
}
#include "streamReferences" #include "streamReferences"

View File

@ -219,6 +219,7 @@ public:
bool parse(const char* filename, const char* protocolname); bool parse(const char* filename, const char* protocolname);
void printProtocol(); void printProtocol();
const char* name() { return streamname; } const char* name() { return streamname; }
void printStatus(StreamBuffer& buffer);
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,10 @@
#include "StreamError.h" #include "StreamError.h"
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <stdio.h>
int streamDebug = 0; int streamDebug = 0;
int streamError = 1;
extern "C" { extern "C" {
#ifdef _WIN32 #ifdef _WIN32
__declspec(dllexport) __declspec(dllexport)
@ -73,6 +75,7 @@ void StreamError(int line, const char* file, const char* fmt, ...)
void StreamVError(int line, const char* file, const char* fmt, va_list args) void StreamVError(int line, const char* file, const char* fmt, va_list args)
{ {
char timestamp[40]; char timestamp[40];
if (!streamError) return; // Error logging disabled
StreamPrintTimestampFunction(timestamp, 40); StreamPrintTimestampFunction(timestamp, 40);
#ifdef va_copy #ifdef va_copy
if (StreamDebugFile) if (StreamDebugFile)

View File

@ -20,14 +20,15 @@
#ifndef StreamError_h #ifndef StreamError_h
#define StreamError_h #define StreamError_h
#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(x) #define __attribute__(x)
#endif #endif
extern int streamDebug; extern int streamDebug;
extern int streamError;
extern void (*StreamPrintTimestampFunction)(char* buffer, int size); extern void (*StreamPrintTimestampFunction)(char* buffer, int size);
void StreamError(int line, const char* file, const char* fmt, ...) void StreamError(int line, const char* file, const char* fmt, ...)

View File

@ -30,15 +30,17 @@ typedef enum {
zero_flag = 0x10, zero_flag = 0x10,
skip_flag = 0x20, skip_flag = 0x20,
default_flag = 0x40, default_flag = 0x40,
compare_flag = 0x80 compare_flag = 0x80,
fix_width_flag = 0x100,
} StreamFormatFlag; } StreamFormatFlag;
typedef enum { typedef enum {
long_format = 1, unsigned_format = 1,
enum_format = 2, signed_format,
double_format = 3, enum_format,
string_format = 4, double_format,
pseudo_format = 5 string_format,
pseudo_format
} StreamFormatType; } StreamFormatType;
extern const char* StreamFormatTypeStr[]; extern const char* StreamFormatTypeStr[];
@ -47,7 +49,7 @@ typedef struct StreamFormat
{ {
char conv; char conv;
StreamFormatType type; StreamFormatType type;
unsigned char flags; unsigned short flags;
short prec; short prec;
unsigned short width; unsigned short width;
unsigned short infolen; unsigned short infolen;

View File

@ -21,6 +21,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h>
#include "StreamFormatConverter.h" #include "StreamFormatConverter.h"
#include "StreamError.h" #include "StreamError.h"
@ -37,7 +38,7 @@ parseFormat(const char*& source, FormatType formatType, StreamFormat& streamForm
{ {
/* /*
source := [flags] [width] ['.' prec] conv [extra] source := [flags] [width] ['.' prec] conv [extra]
flags := '-' | '+' | ' ' | '#' | '0' | '*' | '?' | '=' flags := '-' | '+' | ' ' | '#' | '0' | '*' | '?' | '=' | '!'
width := integer width := integer
prec := integer prec := integer
conv := character conv := character
@ -84,6 +85,15 @@ parseFormat(const char*& source, FormatType formatType, StreamFormat& streamForm
} }
streamFormat.flags |= default_flag; streamFormat.flags |= default_flag;
break; break;
case '!':
if (formatType != ScanFormat)
{
error("Use of fixed width modifier '!' "
"only allowed in input formats\n");
return false;
}
streamFormat.flags |= fix_width_flag;
break;
case '=': case '=':
if (formatType != ScanFormat) if (formatType != ScanFormat)
{ {
@ -310,13 +320,17 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
info.append('l'); info.append('l');
info.append(fmt.conv); info.append(fmt.conv);
} }
return long_format; if (fmt.conv == 'd' || fmt.conv == 'i') return signed_format;
return unsigned_format;
} }
bool StdLongConverter:: bool StdLongConverter::
printLong(const StreamFormat& fmt, StreamBuffer& output, long value) printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
output.printf(fmt.info, value); // limits %x/%X formats to number of half bytes in width.
if (fmt.width && (fmt.conv == 'x' || fmt.conv == 'X') && fmt.width < 2*sizeof(long))
value &= ~(-1L << (fmt.width*4));
output.print(fmt.info, value);
return true; return true;
} }
@ -327,6 +341,7 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
int length; int length;
bool neg; bool neg;
int base; int base;
long v;
length = prepareval(fmt, input, neg); length = prepareval(fmt, input, neg);
if (length < 0) return -1; if (length < 0) return -1;
@ -336,14 +351,11 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
base = 10; base = 10;
break; break;
case 'o': case 'o':
base = 8;
goto signcheck;
case 'x': case 'x':
case 'X': case 'X':
base = 16; // allow negative hex and oct numbers with - flag
signcheck:
// allow negative hex and oct numbers with - flag
if (neg && !(fmt.flags & left_flag)) return -1; if (neg && !(fmt.flags & left_flag)) return -1;
base = (fmt.conv == 'o') ? 8 : 16;
break; break;
case 'u': case 'u':
if (neg) return -1; if (neg) return -1;
@ -352,10 +364,10 @@ signcheck:
default: default:
base = 0; base = 0;
} }
value = strtoul(input, &end, base); v = strtoul(input, &end, base);
if (neg) value = -value;
if (end == input) return -1; if (end == input) return -1;
length += end-input; length += end-input;
value = neg ? -v : v;
return length; return length;
} }
@ -395,7 +407,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
bool StdDoubleConverter:: bool StdDoubleConverter::
printDouble(const StreamFormat& fmt, StreamBuffer& output, double value) printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
{ {
output.printf(fmt.info, value); output.print(fmt.info, value);
return true; return true;
} }
@ -451,7 +463,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
bool StdStringConverter:: bool StdStringConverter::
printString(const StreamFormat& fmt, StreamBuffer& output, const char* value) printString(const StreamFormat& fmt, StreamBuffer& output, const char* value)
{ {
output.printf(fmt.info, value); output.print(fmt.info, value);
return true; return true;
} }
@ -543,13 +555,13 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
info.append("%n"); info.append("%n");
return string_format; return string_format;
} }
return long_format; return unsigned_format;
} }
bool StdCharsConverter:: bool StdCharsConverter::
printLong(const StreamFormat& fmt, StreamBuffer& output, long value) printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
output.printf(fmt.info, value); output.print(fmt.info, value);
return true; return true;
} }

View File

@ -26,7 +26,8 @@
#include "StreamError.h" #include "StreamError.h"
const char* StreamFormatTypeStr[] = { const char* StreamFormatTypeStr[] = {
"none", "long", "enum", "double", "string", "pseudo" // must match the order in StreamFormat.h
"none", "unsigned", "signed", "enum", "double", "string", "pseudo"
}; };
class StreamProtocolParser::Protocol::Variable class StreamProtocolParser::Protocol::Variable
@ -511,20 +512,31 @@ Each time newline is read, line is incremented.
buffer(token)); buffer(token));
return false; return false;
} }
if (c == '$' && buffer[-1] == '\\')
{
// quoted variable reference
// terminate string here and do variable in next pass
buffer[-1] = quote;
ungetc(c, file);
break;
}
buffer.append(c); buffer.append(c);
if (c == quote && buffer[-2] != '\\') if (c == quote)
{ {
quote = false; quote = false;
break; break;
} }
if (c == '\\')
{
c = getc(file);
if (c == '$')
{
// quoted variable reference
// terminate string here and do variable in next pass
buffer[-1] = quote;
ungetc(c, file);
break;
}
if (c == EOF || c == '\n')
{
error(line, filename(), "Backslash at end of line: %s\n",
buffer(token));
return false;
}
buffer.append(c);
}
c = getc(file); c = getc(file);
} }
buffer.append('\0').append(&l, sizeof(l)); // append line number buffer.append('\0').append(&l, sizeof(l)); // append line number
@ -634,7 +646,7 @@ printString(StreamBuffer& buffer, const char* s)
switch (*s) switch (*s)
{ {
case esc: case esc:
buffer.printf("\\x%02x", (*++s) & 0xff); buffer.print("\\x%02x", (*++s) & 0xff);
break; break;
case '\r': case '\r':
buffer.append("\\r"); buffer.append("\\r");
@ -655,7 +667,7 @@ printString(StreamBuffer& buffer, const char* s)
buffer.append("\\\\"); buffer.append("\\\\");
break; break;
case format_field: case format_field:
buffer.printf("%%(%s)", ++s); buffer.print("%%(%s)", ++s);
while (*s++); while (*s++);
s += extract<unsigned short>(s); // skip fieldaddress s += extract<unsigned short>(s); // skip fieldaddress
goto format; goto format;
@ -670,7 +682,7 @@ format: {
continue; continue;
default: default:
if ((*s & 0x7f) < 0x20 || (*s & 0x7f) == 0x7f) if ((*s & 0x7f) < 0x20 || (*s & 0x7f) == 0x7f)
buffer.printf("\\x%02x", *s & 0xff); buffer.print("\\x%02x", *s & 0xff);
else else
buffer.append(*s); buffer.append(*s);
} }
@ -742,7 +754,7 @@ Protocol(const Protocol& p, StreamBuffer& name, int _line)
int i; int i;
const char* nextparameter; const char* nextparameter;
parameter[0] = protocolname(); parameter[0] = protocolname();
for (i = 0; i < 10; i++) for (i = 0; i < 9; i++)
{ {
debug("StreamProtocolParser::Protocol::Protocol $%d=\"%s\"\n", debug("StreamProtocolParser::Protocol::Protocol $%d=\"%s\"\n",
i, parameter[i]); i, parameter[i]);
@ -1037,7 +1049,7 @@ compileNumber(unsigned long& number, const char*& source, unsigned long max)
"Garbage after numeric value: %s\n", buffer()); "Garbage after numeric value: %s\n", buffer());
return false; return false;
} }
if (n < 0 || n > max) if (n > max)
{ {
debug("StreamProtocolParser::Protocol::compileNumber: %s\n", debug("StreamProtocolParser::Protocol::compileNumber: %s\n",
buffer.expand()()); buffer.expand()());
@ -1059,7 +1071,6 @@ compileString(StreamBuffer& buffer, const char*& source,
FormatType formatType, Client* client, int quoted) FormatType formatType, Client* client, int quoted)
{ {
bool escaped = false; bool escaped = false;
int n;
int newline = 0; int newline = 0;
StreamBuffer formatbuffer; StreamBuffer formatbuffer;
int formatpos = buffer.length(); int formatpos = buffer.length();
@ -1136,7 +1147,8 @@ compileString(StreamBuffer& buffer, const char*& source,
if (escaped) // char after \ in quoted text if (escaped) // char after \ in quoted text
{ {
escaped = false; escaped = false;
unsigned int temp; unsigned int c;
int n=1;
switch (*source) switch (*source)
{ {
case '$': // can't be: readToken would have made a token from this case '$': // can't be: readToken would have made a token from this
@ -1145,61 +1157,50 @@ compileString(StreamBuffer& buffer, const char*& source,
return false; return false;
case '?': case '?':
buffer.append(skip); buffer.append(skip);
break; source++;
continue;
case '_': case '_':
buffer.append(whitespace); buffer.append(whitespace);
break; source++;
continue;
case 'a': case 'a':
buffer.append(7); c=7;
break; break;
case 'b': case 'b':
buffer.append(8); c=8;
break; break;
case 't': case 't':
buffer.append(9); c=9;
break; break;
case 'n': case 'n':
buffer.append('\n'); c='\n';
break; break;
case 'r': case 'r':
buffer.append('\r'); c='\r';
break; break;
case 'e': case 'e':
buffer.append(esc).append(esc); c=esc;
break; break;
case '0': // octal numbers (max 3 digits after 0) case '0': // octal numbers (max 4 digits)
sscanf (source, "%3o%n", &temp, &n); sscanf (source, "%4o%n", &c, &n); //cannot fail
if (temp > 0xFF) if (c > 0xFF)
{ {
error(line, filename(), error(line, filename(),
"Octal source %#o does not fit in byte: %s\n", "Octal number %#o does not fit in byte: \"%s\"\n",
temp, source-1); c, source-1);
return false; return false;
} }
if (formatType != NoFormat && break;
(temp < last_function_code || temp == esc)) case 'x': // hex numbers (max 2 digits after x)
{ if (sscanf (source+1, "%2x%n", &c, &n) < 1)
buffer.append(esc);
}
buffer.append(temp);
source += n;
continue;
case 'x': // hex numbers (max 2 digits after 0)
if (sscanf (source+1, "%2x%n", &temp, &n) < 1)
{ {
error(line, filename(), error(line, filename(),
"Hex digit expected after \\x: %s\n", "Hex digit expected after \\x: \"%s\"\n",
source-1); source-1);
return false; return false;
} }
if (formatType != NoFormat && n++;
(temp < last_function_code || temp == esc)) break;
{
buffer.append(esc);
}
buffer.append(temp);
source += n+1;
continue;
case '1': // decimal numbers (max 3 digits) case '1': // decimal numbers (max 3 digits)
case '2': case '2':
case '3': case '3':
@ -1209,26 +1210,24 @@ compileString(StreamBuffer& buffer, const char*& source,
case '7': case '7':
case '8': case '8':
case '9': case '9':
sscanf (source, "%3u%n", &temp, &n); sscanf (source, "%3u%n", &c, &n); //cannot fail
if (temp > 0xFF) if (c > 0xFF)
{ {
error(line, filename(), error(line, filename(),
"Decimal source %d does not fit in byte: %s\n", "Decimal number %d does not fit in byte: \"%s\"\n",
temp, source-1); c, source-1);
return false; return false;
} }
if (formatType != NoFormat && break;
(temp < last_function_code || temp == esc))
{
buffer.append(esc);
}
buffer.append(temp);
source += n;
continue;
default: // escaped literals default: // escaped literals
buffer.append(esc).append(*source); c=*source;
} }
source++; source+=n;
if (formatType != NoFormat)
{
buffer.append(esc);
}
buffer.append(c);
continue; continue;
} }
if (quoted) // look for ending quotes and escapes if (quoted) // look for ending quotes and escapes
@ -1281,7 +1280,7 @@ compileString(StreamBuffer& buffer, const char*& source,
} }
// try numeric byte value // try numeric byte value
char* p; char* p;
int temp = strtol(source, &p, 0); int c = strtol(source, &p, 0);
if (p != source) if (p != source)
{ {
if (*p != 0) if (*p != 0)
@ -1290,18 +1289,17 @@ compileString(StreamBuffer& buffer, const char*& source,
"Garbage after numeric source: %s", source); "Garbage after numeric source: %s", source);
return false; return false;
} }
if (temp > 0xFF || temp < -0x80) if (c > 0xFF || c < -0x80)
{ {
error(line, filename(), error(line, filename(),
"Value %s does not fit in byte\n", source); "Value %s does not fit in byte\n", source);
return false; return false;
} }
if (formatType != NoFormat && if (formatType != NoFormat)
(temp < last_function_code || temp == esc))
{ {
buffer.append(esc); buffer.append(esc);
} }
buffer.append(temp); buffer.append(c);
source = p+1+sizeof(int); source = p+1+sizeof(int);
continue; continue;
} }
@ -1348,7 +1346,7 @@ compileString(StreamBuffer& buffer, const char*& source,
{"del", 0x7f} {"del", 0x7f}
}; };
size_t i; size_t i;
char c = 0; c=-1;
for (i = 0; i < sizeof(codes)/sizeof(*codes); i++) for (i = 0; i < sizeof(codes)/sizeof(*codes); i++)
{ {
if (strcmp(source, codes[i].name) == 0) if (strcmp(source, codes[i].name) == 0)
@ -1361,8 +1359,7 @@ compileString(StreamBuffer& buffer, const char*& source,
source); source);
return false; return false;
} }
if (formatType != NoFormat && if (formatType != NoFormat)
(temp < last_function_code || temp == esc))
{ {
buffer.append(esc); buffer.append(esc);
} }
@ -1371,10 +1368,10 @@ compileString(StreamBuffer& buffer, const char*& source,
break; break;
} }
} }
if (c) continue; if (c >= 0) continue;
// source may contain a function name // source may contain a function name
error(line, filename(), error(line, filename(),
"Unexpected word: %s\n", source); "Unexpected word: \"%s\"\n", source);
return false; return false;
} }
debug("StreamProtocolParser::Protocol::compileString buffer=%s\n", buffer.expand()()); debug("StreamProtocolParser::Protocol::compileString buffer=%s\n", buffer.expand()());
@ -1453,7 +1450,7 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
// parsing failed // parsing failed
return false; return false;
} }
if (type < long_format && type > pseudo_format) if (type < 1 && type > pseudo_format)
{ {
error(line, filename(), error(line, filename(),
"Illegal format type %d returned from '%%%c' converter\n", "Illegal format type %d returned from '%%%c' converter\n",
@ -1493,8 +1490,10 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
buffer.append(&streamFormat, sizeof(streamFormat)); buffer.append(&streamFormat, sizeof(streamFormat));
buffer.append(infoString); buffer.append(infoString);
debug("StreamProtocolParser::Protocol::compileFormat: format.type=%s, infolen=%d\n", debug("StreamProtocolParser::Protocol::compileFormat: format.type=%s, "
StreamFormatTypeStr[streamFormat.type], streamFormat.infolen); "infolen=%d infostring=\"%s\"\n",
StreamFormatTypeStr[streamFormat.type],
streamFormat.infolen, infoString.expand()());
formatstr = source; // move pointer after parsed format formatstr = source; // move pointer after parsed format
return true; return true;
} }

View File

@ -23,6 +23,7 @@
#define STR2(x) #x #define STR2(x) #x
#define STR(x) STR2(x) #define STR(x) STR2(x)
const char StreamVersion [] = const char StreamVersion [] =
"StreamDevice " STR(STREAM_MAJOR) "." STR(STREAM_MINOR) "StreamDevice " STR(STREAM_MAJOR)
"." STR(STREAM_MINOR)
"." STR(STREAM_PATCHLEVEL)
" built " __DATE__ " " __TIME__; " built " __DATE__ " " __TIME__;

View File

@ -26,6 +26,24 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
/* timezone in UNIX contains the seconds between UTC and local time,
but not in Free-BSD! Here timezone() is a function delivering
the time zone abbreviation (e.g. CET). Alternatively, the timezone
value can also be gained from tm_gmtoff of the tm-structure.
HJK, 4.4.14 */
/* The same seems to be true for other BSDs. DZ. */
#if defined(__FreeBSD__) || \
defined(__NetBSD__) || \
defined(__OpenBSD__) || \
defined(__bsdi__ ) || \
defined(__DragonFly__)
static int timezone_bsd=0;
#define timezone timezone_bsd
#define tzset() { struct tm tm; time_t timet; tzset(); time(&timet); \
localtime_r(&timet, &tm); timezone=tm.tm_gmtoff; }
#endif
#ifdef _WIN32 #ifdef _WIN32
#define tzset() _tzset() #define tzset() _tzset()
#define timezone _timezone #define timezone _timezone
@ -46,6 +64,13 @@ int timezone = 0;
} while (0) } while (0)
#endif #endif
#if defined(__MINGW32__)
/* MinGW has no re-entrant localtime. How about other environments? */
/* Just let's hope for the best */
#undef localtime_r
#define localtime_r(timet,tm) (*(tm)=*localtime(timet))
#endif
class TimestampConverter : public StreamFormatConverter class TimestampConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
@ -82,14 +107,14 @@ parse(const StreamFormat&, StreamBuffer& info,
if (*c == 'f') if (*c == 'f')
{ {
source = c; source = c;
info.printf("%%0%uf", n); info.print("%%0%uf", n);
break; break;
} }
} }
/* look for nanoseconds %N of %f */ /* look for nanoseconds %N of %f */
if (*source == 'N' || *source == 'f') if (*source == 'N' || *source == 'f')
{ {
info.printf("%%09f"); info.print("%%09f");
break; break;
} }
/* look for seconds with fractions like %.3S */ /* look for seconds with fractions like %.3S */
@ -100,7 +125,7 @@ parse(const StreamFormat&, StreamBuffer& info,
if (toupper(*c) == 'S') if (toupper(*c) == 'S')
{ {
source = c; source = c;
info.printf("%%%c.%%0%uf", *c, n); info.print("%%%c.%%0%uf", *c, n);
break; break;
} }
} }
@ -366,7 +391,7 @@ startover:
debug ("TimestampConverter::scantime: %s hour = %d\n", pm?"PM":"AM", tm->tm_hour); debug ("TimestampConverter::scantime: %s hour = %d\n", pm?"PM":"AM", tm->tm_hour);
break; break;
case 'M': /* minute */ case 'M': /* minute */
i = nummatch(input, 1, 59); i = nummatch(input, 0, 59);
if (i < 0) if (i < 0)
{ {
error ("error parsing minute: '%.20s'\n", input); error ("error parsing minute: '%.20s'\n", input);
@ -376,7 +401,7 @@ startover:
debug ("TimestampConverter::scantime: min = %d\n", tm->tm_min); debug ("TimestampConverter::scantime: min = %d\n", tm->tm_min);
break; break;
case 'S': /* second */ case 'S': /* second */
i = nummatch(input, 1, 60); i = nummatch(input, 0, 60);
if (i < 0) if (i < 0)
{ {
error ("error parsing week second: '%.20s'\n", input); error ("error parsing week second: '%.20s'\n", input);

View File

@ -22,7 +22,8 @@
#define devStream_h #define devStream_h
#define STREAM_MAJOR 2 #define STREAM_MAJOR 2
#define STREAM_MINOR 4 #define STREAM_MINOR 7
#define STREAM_PATCHLEVEL 12
#if defined(__vxworks) || defined(vxWorks) #if defined(__vxworks) || defined(vxWorks)
#include <vxWorks.h> #include <vxWorks.h>
@ -40,22 +41,31 @@
#define INIT_RUN (!interruptAccept) #define INIT_RUN (!interruptAccept)
#include <epicsVersion.h> #include <epicsVersion.h>
#if (EPICS_VERSION == 3 && EPICS_REVISION == 14) #ifdef BASE_VERSION
#define EPICS_3_14 #define EPICS_3_13
#endif #endif
#if defined(__cplusplus) && !defined(EPICS_3_14) #if defined(__cplusplus) && defined(EPICS_3_13)
extern "C" { extern "C" {
#endif #endif
#ifdef epicsExportSharedSymbols
# define devStream_epicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <stdio.h> #include <stdio.h>
#include <dbCommon.h> #include <dbCommon.h>
#include <dbScan.h> #include <dbScan.h>
#include <devSup.h> #include <devSup.h>
/* #include <dbFldTypes.h> */
#include <dbAccess.h> #include <dbAccess.h>
#if defined(__cplusplus) && !defined(EPICS_3_14) #ifdef devStream_epicsExportSharedSymbols
# define epicsExportSharedSymbols
# include "shareLib.h"
#endif
#if defined(__cplusplus) && defined(EPICS_3_13)
} }
#endif #endif
@ -69,23 +79,22 @@ typedef const struct format_s {
extern "C" { extern "C" {
#endif #endif
#ifdef _WIN32 epicsShareExtern FILE* StreamDebugFile;
__declspec(dllimport)
#endif
extern FILE* StreamDebugFile;
extern const char StreamVersion []; extern const char StreamVersion [];
typedef long (*streamIoFunction) (dbCommon*, format_t*); typedef long (*streamIoFunction) (dbCommon*, format_t*);
long streamInit(int after); epicsShareFunc long streamInit(int after);
long streamInitRecord(dbCommon *record, struct link *ioLink, epicsShareFunc long streamInitRecord(dbCommon *record,
const struct link *ioLink,
streamIoFunction readData, streamIoFunction writeData); streamIoFunction readData, streamIoFunction writeData);
long streamReport(int interest); epicsShareFunc long streamReport(int interest);
long streamReadWrite(dbCommon *record); epicsShareFunc long streamReadWrite(dbCommon *record);
long streamGetIointInfo(int cmd, dbCommon *record, IOSCANPVT *ppvt); epicsShareFunc long streamGetIointInfo(int cmd,
long streamPrintf(dbCommon *record, format_t *format, ...); dbCommon *record, IOSCANPVT *ppvt);
long streamScanfN(dbCommon *record, format_t *format, epicsShareFunc long streamPrintf(dbCommon *record, format_t *format, ...);
epicsShareFunc long streamScanfN(dbCommon *record, format_t *format,
void*, size_t maxStringSize); void*, size_t maxStringSize);
/* backward compatibility stuff */ /* backward compatibility stuff */

View File

@ -20,9 +20,9 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "devStream.h"
#include <aaiRecord.h>
#include <errlog.h> #include <errlog.h>
#include <aaiRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -57,6 +57,7 @@ static long readData (dbCommon *record, format_t *format)
} }
break; break;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
{ {
@ -191,6 +192,7 @@ static long writeData (dbCommon *record, format_t *format)
return ERROR; return ERROR;
break; break;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
{ {

View File

@ -20,9 +20,9 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "devStream.h"
#include <aaoRecord.h>
#include <errlog.h> #include <errlog.h>
#include <aaoRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -57,6 +57,7 @@ static long readData (dbCommon *record, format_t *format)
} }
break; break;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
{ {
@ -191,6 +192,7 @@ static long writeData (dbCommon *record, format_t *format)
return ERROR; return ERROR;
break; break;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
{ {

View File

@ -18,10 +18,18 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h" #include <math.h>
#include <menuConvert.h>
#include <aiRecord.h> #include <aiRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
#ifdef vxWorks
#include <private/mathP.h>
#define isinf(x) isInf(x)
#define isnan(x) isNan(x)
#endif
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
{ {
aiRecord *ai = (aiRecord *) record; aiRecord *ai = (aiRecord *) record;
@ -32,20 +40,31 @@ static long readData (dbCommon *record, format_t *format)
{ {
double val; double val;
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
if (ai->aslo != 0.0) val *= ai->aslo; if (ai->aslo != 0.0 && ai->aslo != 1.0) val *= ai->aslo;
val += ai->aoff; val += ai->aoff;
if (!INIT_RUN && ai->smoo != 0.0) if (!(ai->smoo == 0.0 || ai->init || ai->udf || isinf(ai->val) || isnan(ai->val)))
{
val = ai->val * ai->smoo + val * (1.0 - ai->smoo); val = ai->val * ai->smoo + val * (1.0 - ai->smoo);
}
ai->val = val; ai->val = val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
long rval; long rval;
if (streamScanf (record, format, &rval)) return ERROR; if (streamScanf (record, format, &rval)) return ERROR;
ai->rval = rval; ai->rval = rval;
if (ai->linr == menuConvertNO_CONVERSION)
{
/* allow integers with more than 32 bits */
double val;
if (format->type == DBF_ULONG)
val = (unsigned long)rval;
else
val = rval;
if (ai->aslo != 0.0 && ai->aslo != 1.0) val *= ai->aslo;
ai->val = val + ai->aoff;
return DO_NOT_CONVERT;
}
return OK; return OK;
} }
} }
@ -55,19 +74,32 @@ static long readData (dbCommon *record, format_t *format)
static long writeData (dbCommon *record, format_t *format) static long writeData (dbCommon *record, format_t *format)
{ {
aiRecord *ai = (aiRecord *) record; aiRecord *ai = (aiRecord *) record;
double val;
switch (format->type) switch (format->type)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
{ {
val = ai->val - ai->aoff; double val = ai->val - ai->aoff;
if (ai->aslo != 0) val /= ai->aslo; if (ai->aslo != 0.0 && ai->aslo != 1.0) val /= ai->aslo;
return streamPrintf (record, format, val); return streamPrintf (record, format, val);
} }
case DBF_ULONG:
{
if (ai->linr == menuConvertNO_CONVERSION)
{
/* allow more bits than 32 */
return streamPrintf (record, format, (unsigned long)ai->val);
}
return streamPrintf (record, format, (unsigned long)ai->rval);
}
case DBF_LONG: case DBF_LONG:
{ {
return streamPrintf (record, format, (long) ai->rval); if (ai->linr == menuConvertNO_CONVERSION)
{
/* allow more bits than 32 */
return streamPrintf (record, format, (long)ai->val);
}
return streamPrintf (record, format, (long)ai->rval);
} }
} }
return ERROR; return ERROR;

View File

@ -18,8 +18,9 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h" #include <menuConvert.h>
#include <aoRecord.h> #include <aoRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -32,16 +33,29 @@ static long readData (dbCommon *record, format_t *format)
{ {
double val; double val;
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
if (ao->aslo != 0) val *= ao->aslo; if (ao->aslo != 0.0 && ao->aslo != 1.0) val *= ao->aslo;
ao->val = val + ao->aoff; ao->val = val + ao->aoff;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
long rval; long rval;
if (streamScanf (record, format, &rval)) return ERROR; if (streamScanf (record, format, &rval)) return ERROR;
ao->rbv = rval; ao->rbv = rval;
if (INIT_RUN) ao->rval = rval; ao->rval = rval;
if (ao->linr == menuConvertNO_CONVERSION)
{
/* allow integers with more than 32 bits */
double val;
if (format->type == DBF_ULONG)
val = (unsigned long)rval;
else
val = rval;
if (ao->aslo != 0.0 && ao->aslo != 1.0) val *= ao->aslo;
ao->val = val + ao->aoff;
return DO_NOT_CONVERT;
}
return OK; return OK;
} }
} }
@ -52,20 +66,32 @@ static long writeData (dbCommon *record, format_t *format)
{ {
aoRecord *ao = (aoRecord *) record; aoRecord *ao = (aoRecord *) record;
double val = (INIT_RUN ? ao->val : ao->oval) - ao->aoff;
if (ao->aslo != 0.0 && ao->aslo != 1.0) val /= ao->aslo;
switch (format->type) switch (format->type)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
{ {
double val;
if (INIT_RUN) val = ao->val;
else val = ao->oval;
val -= ao->aoff;
if (ao->aslo != 0) val /= ao->aslo;
return streamPrintf (record, format, val); return streamPrintf (record, format, val);
} }
case DBF_ULONG:
{
if (ao->linr == menuConvertNO_CONVERSION)
{
/* allow integers with more than 32 bits */
return streamPrintf (record, format, (unsigned long)val);
}
return streamPrintf (record, format, (unsigned long)ao->rval);
}
case DBF_LONG: case DBF_LONG:
{ {
return streamPrintf (record, format, (long) ao->rval); if (ao->linr == menuConvertNO_CONVERSION)
{
/* allow integers with more than 32 bits */
return streamPrintf (record, format, (long)val);
}
return streamPrintf (record, format, (long)ao->rval);
} }
} }
return ERROR; return ERROR;

View File

@ -18,9 +18,9 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <biRecord.h>
#include <string.h> #include <string.h>
#include <biRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -30,6 +30,7 @@ static long readData (dbCommon *record, format_t *format)
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
@ -69,13 +70,14 @@ static long writeData (dbCommon *record, format_t *format)
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
return streamPrintf (record, format, bi->rval); return streamPrintf (record, format, bi->rval);
} }
case DBF_ENUM: case DBF_ENUM:
{ {
return streamPrintf (record, format, (long) bi->val); return streamPrintf (record, format, (long)bi->val);
} }
case DBF_STRING: case DBF_STRING:
{ {

View File

@ -18,9 +18,9 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <boRecord.h>
#include <string.h> #include <string.h>
#include <boRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -30,6 +30,7 @@ static long readData (dbCommon *record, format_t *format)
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
@ -70,13 +71,14 @@ static long writeData (dbCommon *record, format_t *format)
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
return streamPrintf (record, format, bo->rval); return streamPrintf (record, format, bo->rval);
} }
case DBF_ENUM: case DBF_ENUM:
{ {
return streamPrintf (record, format, (long) bo->val); return streamPrintf (record, format, (long)bo->val);
} }
case DBF_STRING: case DBF_STRING:
{ {

View File

@ -17,9 +17,9 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <postfix.h> #include <postfix.h>
#include <calcoutRecord.h> #include <calcoutRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -32,13 +32,17 @@ static long readData (dbCommon *record, format_t *format)
{ {
return streamScanf (record, format, &co->val); return streamScanf (record, format, &co->val);
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
{ {
long lval; long lval;
if (streamScanf (record, format, &lval)) return ERROR; if (streamScanf (record, format, &lval)) return ERROR;
co->val = lval; if (format->type == DBF_LONG)
co->val = lval;
else
co->val = (unsigned long)lval;
return OK; return OK;
} }
} }
@ -55,8 +59,12 @@ static long writeData (dbCommon *record, format_t *format)
{ {
return streamPrintf (record, format, co->oval); return streamPrintf (record, format, co->oval);
} }
case DBF_LONG: case DBF_ULONG:
case DBF_ENUM: case DBF_ENUM:
{
return streamPrintf (record, format, (unsigned long)co->oval);
}
case DBF_LONG:
{ {
return streamPrintf (record, format, (long)co->oval); return streamPrintf (record, format, (long)co->oval);
} }

View File

@ -18,20 +18,25 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <longinRecord.h> #include <longinRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
{ {
longinRecord *li = (longinRecord *) record; longinRecord *li = (longinRecord *) record;
if (format->type == DBF_LONG || format->type == DBF_ENUM) switch (format->type)
{ {
long val; case DBF_ULONG:
if (streamScanf (record, format, &val)) return ERROR; case DBF_LONG:
li->val = val; case DBF_ENUM:
return OK; {
long val;
if (streamScanf (record, format, &val)) return ERROR;
li->val = val;
return OK;
}
} }
return ERROR; return ERROR;
} }
@ -40,9 +45,13 @@ static long writeData (dbCommon *record, format_t *format)
{ {
longinRecord *li = (longinRecord *) record; longinRecord *li = (longinRecord *) record;
if (format->type == DBF_LONG || format->type == DBF_ENUM) switch (format->type)
{ {
return streamPrintf (record, format, (long) li->val); case DBF_ULONG:
case DBF_ENUM:
return streamPrintf (record, format, (unsigned long)li->val);
case DBF_LONG:
return streamPrintf (record, format, (long)li->val);
} }
return ERROR; return ERROR;
} }

View File

@ -19,20 +19,25 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <longoutRecord.h> #include <longoutRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
{ {
longoutRecord *lo = (longoutRecord *) record; longoutRecord *lo = (longoutRecord *) record;
if (format->type == DBF_LONG || format->type == DBF_ENUM) switch (format->type)
{ {
long val; case DBF_ULONG:
if (streamScanf (record, format, &val)) return ERROR; case DBF_LONG:
lo->val = val; case DBF_ENUM:
return OK; {
long val;
if (streamScanf (record, format, &val)) return ERROR;
lo->val = val;
return OK;
}
} }
return ERROR; return ERROR;
} }
@ -41,9 +46,13 @@ static long writeData (dbCommon *record, format_t *format)
{ {
longoutRecord *lo = (longoutRecord *) record; longoutRecord *lo = (longoutRecord *) record;
if (format->type == DBF_LONG || format->type == DBF_ENUM) switch (format->type)
{ {
return streamPrintf (record, format, (long) lo->val); case DBF_ULONG:
case DBF_ENUM:
return streamPrintf (record, format, (unsigned long)lo->val);
case DBF_LONG:
return streamPrintf (record, format, (long)lo->val);
} }
return ERROR; return ERROR;
} }

View File

@ -19,16 +19,16 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <mbbiDirectRecord.h> #include <mbbiDirectRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
{ {
mbbiDirectRecord *mbbiD = (mbbiDirectRecord *) record; mbbiDirectRecord *mbbiD = (mbbiDirectRecord *) record;
long val; unsigned long val;
if (format->type == DBF_LONG) if (format->type == DBF_ULONG || format->type == DBF_LONG)
{ {
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
if (mbbiD->mask) if (mbbiD->mask)
@ -40,7 +40,7 @@ static long readData (dbCommon *record, format_t *format)
else else
{ {
/* No MASK, (NOBT = 0): use VAL field */ /* No MASK, (NOBT = 0): use VAL field */
mbbiD->val = (short)val; mbbiD->val = (unsigned short)val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
} }
@ -50,9 +50,9 @@ static long readData (dbCommon *record, format_t *format)
static long writeData (dbCommon *record, format_t *format) static long writeData (dbCommon *record, format_t *format)
{ {
mbbiDirectRecord *mbbiD = (mbbiDirectRecord *) record; mbbiDirectRecord *mbbiD = (mbbiDirectRecord *) record;
long val; unsigned long val;
if (format->type == DBF_LONG) if (format->type == DBF_ULONG || format->type == DBF_LONG)
{ {
if (mbbiD->mask) val = mbbiD->rval & mbbiD->mask; if (mbbiD->mask) val = mbbiD->rval & mbbiD->mask;
else val = mbbiD->val; else val = mbbiD->val;

View File

@ -19,19 +19,20 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <mbbiRecord.h>
#include <string.h> #include <string.h>
#include <mbbiRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
{ {
mbbiRecord *mbbi = (mbbiRecord *) record; mbbiRecord *mbbi = (mbbiRecord *) record;
long val; unsigned long val;
int i; int i;
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;

View File

@ -19,16 +19,17 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <mbboDirectRecord.h> #include <mbboDirectRecord.h>
#include "alarm.h"
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
{ {
mbboDirectRecord *mbboD = (mbboDirectRecord *) record; mbboDirectRecord *mbboD = (mbboDirectRecord *) record;
long val; unsigned long val;
if (format->type == DBF_LONG) if (format->type == DBF_ULONG || format->type == DBF_LONG)
{ {
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
if (mbboD->mask) if (mbboD->mask)
@ -53,7 +54,7 @@ static long writeData (dbCommon *record, format_t *format)
mbboDirectRecord *mbboD = (mbboDirectRecord *) record; mbboDirectRecord *mbboD = (mbboDirectRecord *) record;
long val; long val;
if (format->type == DBF_LONG) if (format->type == DBF_ULONG || format->type == DBF_LONG)
{ {
if (mbboD->mask) val = mbboD->rval & mbboD->mask; if (mbboD->mask) val = mbboD->rval & mbboD->mask;
else val = mbboD->val; else val = mbboD->val;
@ -67,9 +68,27 @@ static long initRecord (dbCommon *record)
mbboDirectRecord *mbboD = (mbboDirectRecord *) record; mbboDirectRecord *mbboD = (mbboDirectRecord *) record;
mbboD->mask <<= mbboD->shft; mbboD->mask <<= mbboD->shft;
/* Workaround for bug in mbboDirect record:
Put to VAL overwrites value to 0 if SEVR is INVALID_ALARM
Thus first write may send a wrong value.
*/
mbboD->sevr = 0;
return streamInitRecord (record, &mbboD->out, readData, writeData); return streamInitRecord (record, &mbboD->out, readData, writeData);
} }
/* Unfortunately the bug also corrupts the next write to VAL after an I/O error.
Thus make sure the record is never left in INVALID_ALARM status.
*/
static long write(dbCommon *record)
{
long status = streamWrite(record);
if (record->nsev == INVALID_ALARM) record->nsev = MAJOR_ALARM;
return status;
}
struct { struct {
long number; long number;
DEVSUPFUN report; DEVSUPFUN report;
@ -83,7 +102,7 @@ struct {
streamInit, streamInit,
initRecord, initRecord,
streamGetIointInfo, streamGetIointInfo,
streamWrite write
}; };
epicsExportAddress(dset,devmbboDirectStream); epicsExportAddress(dset,devmbboDirectStream);

View File

@ -19,19 +19,20 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <mbboRecord.h>
#include <string.h> #include <string.h>
#include <mbboRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
{ {
mbboRecord *mbbo = (mbboRecord *) record; mbboRecord *mbbo = (mbboRecord *) record;
long val; unsigned long val;
int i; int i;
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
@ -76,11 +77,12 @@ static long readData (dbCommon *record, format_t *format)
static long writeData (dbCommon *record, format_t *format) static long writeData (dbCommon *record, format_t *format)
{ {
mbboRecord *mbbo = (mbboRecord *) record; mbboRecord *mbbo = (mbboRecord *) record;
long val; unsigned long val;
int i; int i;
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
/* print VAL or RVAL ? */ /* print VAL or RVAL ? */

View File

@ -18,8 +18,8 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <stringinRecord.h> #include <stringinRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)

View File

@ -18,8 +18,8 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <stringoutRecord.h> #include <stringoutRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)

View File

@ -18,10 +18,10 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h"
#include <waveformRecord.h>
#include <string.h> #include <string.h>
#include <errlog.h> #include <errlog.h>
#include <waveformRecord.h>
#include "devStream.h"
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -57,6 +57,7 @@ static long readData (dbCommon *record, format_t *format)
} }
break; break;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
{ {

View File

@ -1,6 +1,11 @@
if (@ARGV[0] == "-3.13") {
shift;
} else {
print "variable(streamDebug, int)\n";
print "variable(streamError, int)\n";
print "registrar(streamRegistrar)\n";
}
print "driver(stream)\n";
for (@ARGV) { for (@ARGV) {
print "device($_,INST_IO,dev${_}Stream,\"stream\")\n"; print "device($_,INST_IO,dev${_}Stream,\"stream\")\n";
} }
print "driver(stream)\n";
print "variable(streamDebug, int)\n";
print "registrar(streamRegistrar)\n";

View File

@ -29,18 +29,13 @@ PROD_SRCS_vxWorks = -nil-
PROD_LIBS = stream PROD_LIBS = stream
ifdef ASYN ifdef ASYN
# Which types of asyn busses do you have? # edit asynRegistrars.dbd if necessary
streamApp_DBD += asynRegistrars.dbd
# asynDriver up to version 4-16 does not support serial port for Windows! # add asynRecord.dbd if you like
#ifneq ($(OS_CLASS), WIN32) streamApp_DBD += asynRecord.dbd
streamApp_DBD += drvAsynSerialPort.dbd
#endif
streamApp_DBD += drvAsynIPPort.dbd
#streamApp_DBD += drvGsIP488.dbd
#streamApp_DBD += drvNi1014.dbd
streamApp_DBD += drvVxi11.dbd
PROD_LIBS += asyn PROD_LIBS += asyn
# cygwin needs separate RPC library for asyn
PROD_SYS_LIBS_cygwin32 += $(CYGWIN_RPC_LIB)
endif endif
ifneq ($(words $(CALC) $(SYNAPPS)), 0) ifneq ($(words $(CALC) $(SYNAPPS)), 0)
@ -56,7 +51,7 @@ endif
streamApp_DBD += stream.dbd streamApp_DBD += stream.dbd
ifdef PCRE ifdef PCRE
LIB_LIBS += pcre PROD_LIBS += pcre
else else
ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0) ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0)
PROD_SYS_LIBS_DEFAULT += pcre PROD_SYS_LIBS_DEFAULT += pcre
@ -73,7 +68,11 @@ CPPFLAGS += -DDEBUGFILE=StreamDebug.log
include $(TOP)/configure/RULES include $(TOP)/configure/RULES
ifeq ($(BASE_3_14), YES)
clean:: myclean clean:: myclean
else
clean: myclean
endif
myclean: myclean:
$(RM) core* StreamDebug.log $(RM) core* StreamDebug.log

View File

@ -0,0 +1,9 @@
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

@ -1,7 +1,5 @@
#!/usr/bin/env wish #!/usr/bin/env wish
wm iconify .
proc createTerm {sock} { proc createTerm {sock} {
global socket port global socket port
toplevel .$sock toplevel .$sock
@ -19,16 +17,8 @@ proc createTerm {sock} {
wm title .$sock "port $port <-> [fconfigure $sock -peername]" wm title .$sock "port $port <-> [fconfigure $sock -peername]"
} }
set port [lindex $argv 0]
if {$port == ""} { set port 40000 }
if [catch {
socket -server connect $port
} msg ] {
return -code error "$msg (port $port)"
}
proc connect {sock addr port} { proc connect {sock addr port} {
fconfigure $sock -blocking 0 -buffering none fconfigure $sock -blocking 0 -buffering none -translation binary
createTerm $sock createTerm $sock
fileevent $sock readable "receiveHandler $sock" fileevent $sock readable "receiveHandler $sock"
} }
@ -50,11 +40,13 @@ proc escape {string} {
} }
proc sendReply {sock text} { proc sendReply {sock text} {
.$sock.t mark set insert end catch {
.$sock.t insert end $text # ignore that socket may already be closed
.$sock.t see end .$sock.t mark set insert end
puts -nonewline $sock $text .$sock.t insert end $text
# puts "sending \"[escape $text]\"\n" .$sock.t see end
puts -nonewline $sock $text
}
} }
proc checkNum {n} { proc checkNum {n} {
@ -84,6 +76,10 @@ proc receiveHandler {sock} {
"echo" { "echo" {
sendReply $sock [string range $a 5 end] sendReply $sock [string range $a 5 end]
} }
"binary" {
set x [checkNum [lindex $l 1]]
sendReply $sock [format %c $x]
}
"longmsg" { "longmsg" {
set length [checkNum [lindex $l 1]] set length [checkNum [lindex $l 1]]
sendReply $sock "[string range x[string repeat 0123456789abcdefghijklmnopqrstuvwxyz [expr $length / 36 + 1]] 1 $length]\n" sendReply $sock "[string range x[string repeat 0123456789abcdefghijklmnopqrstuvwxyz [expr $length / 36 + 1]] 1 $length]\n"
@ -95,7 +91,7 @@ proc receiveHandler {sock} {
"start" { "start" {
set wait [checkNum [lindex $l 1]] set wait [checkNum [lindex $l 1]]
set ::counter 0 set ::counter 0
after $wait sendAsync $wait [list [lindex $l 2]] after $wait [list sendAsync $wait "[string range $a [string wordend $a 7] end]"]
sendReply $sock "Started\n" sendReply $sock "Started\n"
} }
"stop" { "stop" {
@ -116,12 +112,16 @@ proc receiveHandler {sock} {
"help" { "help" {
sendReply $sock "help this text\n" sendReply $sock "help this text\n"
sendReply $sock "echo string reply string\n" sendReply $sock "echo string reply string\n"
sendReply $sock "wait msec reply Done after some time\n" sendReply $sock "binary number reply byte with value number\n"
sendReply $sock "longmsg length reply string with length characters\n"
sendReply $sock "wait msec reply \"Done\" after some time\n"
sendReply $sock "start msec start sending messages priodically\n" sendReply $sock "start msec start sending messages priodically\n"
sendReply $sock "stop stop sending messages\n" sendReply $sock "stop stop sending messages\n"
sendReply $sock "set key value set a value\n" sendReply $sock "set key value store a value into variable key\n"
sendReply $sock "get key reply value\n" sendReply $sock "get key reply previously stored value from key\n"
sendReply $sock "disconnect close connection\n" sendReply $sock "disconnect close connection\n"
sendReply $sock "exit kill terminal server\n"
} }
} }
} msg] { } msg] {
@ -133,7 +133,7 @@ proc receiveHandler {sock} {
proc sendAsync {wait message} { proc sendAsync {wait message} {
if {$::counter < 0} return if {$::counter < 0} return
foreach term [array names ::socket] { foreach term [array names ::socket] {
sendReply $::socket($term) "Message number [incr ::counter] $message\n"; sendReply $::socket($term) "Message number [incr ::counter]$message";
} }
after $wait sendAsync $wait [list $message] after $wait sendAsync $wait [list $message]
} }
@ -153,7 +153,6 @@ rename $paste tkTextPaste_org
rename $pastesel tkTextPasteSel_org rename $pastesel tkTextPasteSel_org
proc $insert {w s} { proc $insert {w s} {
puts [list insert $w $s]
global socket global socket
if {[string equal $s ""] || [string equal [$w cget -state] "disabled"]} { if {[string equal $s ""] || [string equal [$w cget -state] "disabled"]} {
return return
@ -191,8 +190,20 @@ for {set ascii 0x61} {$ascii <= 0x7a} {incr ascii} {
bind Text <Control-[format %c $ascii]> "" bind Text <Control-[format %c $ascii]> ""
} }
#remove bindings on symbolic tags #remove bindings on symbolic tags
foreach tag {Clear Paste Copy Cut } { foreach tag {Clear Paste Copy Cut} {
bind Text <<$tag>> "" bind Text <<$tag>> ""
} }
bind Text <Control-Key> [list $insert %W %A] bind Text <Control-Key> [list $insert %W %A]
set port [lindex $argv 0]
if {$port == ""} { set port 40000 }
if [catch {
socket -server connect $port
} msg ] {
return -code error "$msg (port $port)"
}
label .info -text "Accepting connections on port $port"
button .exit -text "Exit" -command exit
pack .info .exit -expand yes -fill x

View File

@ -2,17 +2,20 @@ record (stringout, "$(P):cmd")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (OUT, "@test.proto command terminal") field (OUT, "@test.proto command terminal")
field (PRIO, "HIGH")
field (VAL, "") field (VAL, "")
} }
record (stringout, "$(P):info") record (stringout, "$(P):info")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (OUT, "@test.proto info terminal") field (OUT, "@test.proto info terminal")
field (PRIO, "HIGH")
} }
record (stringout, "$(P):request") record (stringout, "$(P):request")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (OUT, "@test.proto request($(P):reply.VAL) terminal") field (OUT, "@test.proto request($(P):reply.VAL) terminal")
field (PRIO, "HIGH")
} }
record (stringin, "$(P):reply") record (stringin, "$(P):reply")
{ {

View File

@ -1,5 +1,5 @@
terminator = CR LF; terminator = LF;
readtimeout = 1000; readtimeout = 10;
pollperiod = 10; pollperiod = 10;
replytimeout = 1000; replytimeout = 1000;
command { command {

View File

@ -41,7 +41,7 @@ proc receiveHandler {sock} {
} }
proc startioc {} { proc startioc {} {
global debug records protocol startup port sock ioc testname env streamversion global debug records protocol startup port sock ioc testname env streamversion asynversion
set fd [open test.db w] set fd [open test.db w]
puts $fd $records puts $fd $records
close $fd close $fd
@ -52,6 +52,9 @@ proc startioc {} {
if [info exists streamversion] { if [info exists streamversion] {
puts $fd "#!/usr/local/bin/iocsh" puts $fd "#!/usr/local/bin/iocsh"
if [info exists asynversion] {
puts $fd "require asyn,$asynversion"
}
puts $fd "require stream,$streamversion" puts $fd "require stream,$streamversion"
} else { } else {
puts $fd "#!../O.$env(EPICS_HOST_ARCH)/streamApp" puts $fd "#!../O.$env(EPICS_HOST_ARCH)/streamApp"
@ -74,7 +77,9 @@ proc startioc {} {
} }
fconfigure $ioc -blocking yes -buffering none fconfigure $ioc -blocking yes -buffering none
debugmsg "waiting to connect" debugmsg "waiting to connect"
set timer [after 1000 {puts stderr "\033\[31;7mCannot start IOC.\033\[0m"; exit 1}]
vwait sock vwait sock
after cancel $timer
} }
set lastcommand "" set lastcommand ""
@ -202,3 +207,7 @@ if {[lindex $argv 0] == "-sls"} {
set streamversion [lindex $argv 1] set streamversion [lindex $argv 1]
set argv [lrange $argv 2 end] set argv [lrange $argv 2 end]
} }
if {[lindex $argv 0] == "-asyn"} {
set asynversion [lindex $argv 1]
set argv [lrange $argv 2 end]
}

View File

@ -7,7 +7,7 @@ source streamtestlib.tcl
# Send commands to the ioc shell with ioccmd # Send commands to the ioc shell with ioccmd
set records { set records {
record (ao, "DZ:test1") record (stringout, "DZ:test1")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (OUT, "@test.proto test1 device") field (OUT, "@test.proto test1 device")
@ -15,7 +15,225 @@ set records {
} }
set protocol { set protocol {
test1 {out 0x55 0x40 0x04 0x00 0x00 'z;' "%<sum>";} Terminator="\n";
test1 {
out "sum %s %9.1<sum>"; in "sum %=s %9.1<sum>";
out "sum8 %s %9.1<sum8>"; in "sum8 %=s %9.1<sum8>";
out "sum16 %s %9.1<sum16>"; in "sum16 %=s %9.1<sum16>";
out "sum32 %s %9.1<sum32>"; in "sum32 %=s %9.1<sum32>";
out "nsum %s %9.1<nsum>"; in "nsum %=s %9.1<nsum>";
out "negsum %s %9.1<negsum>"; in "negsum %=s %9.1<negsum>";
out "-sum %s %9.1<-sum>"; in "-sum %=s %9.1<-sum>";
out "nsum8 %s %9.1<nsum8>"; in "nsum8 %=s %9.1<nsum8>";
out "negsum8 %s %9.1<negsum8>"; in "negsum8 %=s %9.1<negsum8>";
out "-sum8 %s %9.1<-sum8>"; in "-sum8 %=s %9.1<-sum8>";
out "nsum16 %s %9.1<nsum16>"; in "nsum16 %=s %9.1<nsum16>";
out "negsum16 %s %9.1<negsum1>"; in "negsum16 %=s %9.1<negsum1>";
out "-sum16 %s %9.1<-sum16>"; in "-sum16 %=s %9.1<-sum16>";
out "nsum32 %s %9.1<nsum32>"; in "nsum32 %=s %9.1<nsum32>";
out "negsum32 %s %9.1<negsum3>"; in "negsum32 %=s %9.1<negsum3>";
out "-sum32 %s %9.1<-sum32>"; in "-sum32 %=s %9.1<-sum32>";
out "notsum %s %9.1<notsum>"; in "notsum %=s %9.1<notsum>";
out "~sum %s %9.1<~sum>"; in "~sum %=s %9.1<~sum>";
out "xor %s %9.1<xor>"; in "xor %=s %9.1<xor>";
out "xor8 %s %9.1<xor8>"; in "xor8 %=s %9.1<xor8>";
out "xor7 %s %9.1<xor7>"; in "xor7 %=s %9.1<xor7>";
out "crc8 %s %9.1<crc8>"; in "crc8 %=s %9.1<crc8>";
out "ccitt8 %s %9.1<ccitt8>"; in "ccitt8 %=s %9.1<ccitt8>";
out "crc16 %s %9.1<crc16>"; in "crc16 %=s %9.1<crc16>";
out "crc16r %s %9.1<crc16r>"; in "crc16r %=s %9.1<crc16r>";
out "ccitt16 %s %9.1<ccitt16>"; in "ccitt16 %=s %9.1<ccitt16>";
out "ccitt16a %s %9.1<ccitt16a>"; in "ccitt16a %=s %9.1<ccitt16a>";
out "ccitt16x %s %9.1<ccitt16x>"; in "ccitt16x %=s %9.1<ccitt16x>";
out "crc16c %s %9.1<crc16c>"; in "crc16c %=s %9.1<crc16c>";
out "xmodem %s %9.1<xmodem>"; in "xmodem %=s %9.1<xmodem>";
out "crc32 %s %9.1<crc32>"; in "crc32 %=s %9.1<crc32>";
out "crc32r %s %9.1<crc32r>"; in "crc32r %=s %9.1<crc32r>";
out "jamcrc %s %9.1<jamcrc>"; in "jamcrc %=s %9.1<jamcrc>";
out "adler32 %s %9.1<adler32>"; in "adler32 %=s %9.1<adler32>";
out "hexsum8 %s %9.1<hexsum8>"; in "hexsum8 %=s %9.1<hexsum8>";
out "sum %s %09.1<sum>"; in "sum %=s %09.1<sum>";
out "sum8 %s %09.1<sum8>"; in "sum8 %=s %09.1<sum8>";
out "sum16 %s %09.1<sum16>"; in "sum16 %=s %09.1<sum16>";
out "sum32 %s %09.1<sum32>"; in "sum32 %=s %09.1<sum32>";
out "nsum %s %09.1<nsum>"; in "nsum %=s %09.1<nsum>";
out "negsum %s %09.1<negsum>"; in "negsum %=s %09.1<negsum>";
out "-sum %s %09.1<-sum>"; in "-sum %=s %09.1<-sum>";
out "nsum8 %s %09.1<nsum8>"; in "nsum8 %=s %09.1<nsum8>";
out "negsum8 %s %09.1<negsum8>"; in "negsum8 %=s %09.1<negsum8>";
out "-sum8 %s %09.1<-sum8>"; in "-sum8 %=s %09.1<-sum8>";
out "nsum16 %s %09.1<nsum16>"; in "nsum16 %=s %09.1<nsum16>";
out "negsum16 %s %09.1<negsum1>"; in "negsum16 %=s %09.1<negsum1>";
out "-sum16 %s %09.1<-sum16>"; in "-sum16 %=s %09.1<-sum16>";
out "nsum32 %s %09.1<nsum32>"; in "nsum32 %=s %09.1<nsum32>";
out "negsum32 %s %09.1<negsum3>"; in "negsum32 %=s %09.1<negsum3>";
out "-sum32 %s %09.1<-sum32>"; in "-sum32 %=s %09.1<-sum32>";
out "notsum %s %09.1<notsum>"; in "notsum %=s %09.1<notsum>";
out "~sum %s %09.1<~sum>"; in "~sum %=s %09.1<~sum>";
out "xor %s %09.1<xor>"; in "xor %=s %09.1<xor>";
out "xor8 %s %09.1<xor8>"; in "xor8 %=s %09.1<xor8>";
out "xor7 %s %09.1<xor7>"; in "xor7 %=s %09.1<xor7>";
out "crc8 %s %09.1<crc8>"; in "crc8 %=s %09.1<crc8>";
out "ccitt8 %s %09.1<ccitt8>"; in "ccitt8 %=s %09.1<ccitt8>";
out "crc16 %s %09.1<crc16>"; in "crc16 %=s %09.1<crc16>";
out "crc16r %s %09.1<crc16r>"; in "crc16r %=s %09.1<crc16r>";
out "ccitt16 %s %09.1<ccitt16>"; in "ccitt16 %=s %09.1<ccitt16>";
out "ccitt16a %s %09.1<ccitt16a>"; in "ccitt16a %=s %09.1<ccitt16a>";
out "ccitt16x %s %09.1<ccitt16x>"; in "ccitt16x %=s %09.1<ccitt16x>";
out "crc16c %s %09.1<crc16c>"; in "crc16c %=s %09.1<crc16c>";
out "xmodem %s %09.1<xmodem>"; in "xmodem %=s %09.1<xmodem>";
out "crc32 %s %09.1<crc32>"; in "crc32 %=s %09.1<crc32>";
out "crc32r %s %09.1<crc32r>"; in "crc32r %=s %09.1<crc32r>";
out "jamcrc %s %09.1<jamcrc>"; in "jamcrc %=s %09.1<jamcrc>";
out "adler32 %s %09.1<adler32>"; in "adler32 %=s %09.1<adler32>";
out "hexsum8 %s %09.1<hexsum8>"; in "hexsum8 %=s %09.1<hexsum8>";
out "sum %s %-9.1<sum>"; in "sum %=s %-9.1<sum>";
out "sum8 %s %-9.1<sum8>"; in "sum8 %=s %-9.1<sum8>";
out "sum16 %s %-9.1<sum16>"; in "sum16 %=s %-9.1<sum16>";
out "sum32 %s %-9.1<sum32>"; in "sum32 %=s %-9.1<sum32>";
out "nsum %s %-9.1<nsum>"; in "nsum %=s %-9.1<nsum>";
out "negsum %s %-9.1<negsum>"; in "negsum %=s %-9.1<negsum>";
out "-sum %s %-9.1<-sum>"; in "-sum %=s %-9.1<-sum>";
out "nsum8 %s %-9.1<nsum8>"; in "nsum8 %=s %-9.1<nsum8>";
out "negsum8 %s %-9.1<negsum8>"; in "negsum8 %=s %-9.1<negsum8>";
out "-sum8 %s %-9.1<-sum8>"; in "-sum8 %=s %-9.1<-sum8>";
out "nsum16 %s %-9.1<nsum16>"; in "nsum16 %=s %-9.1<nsum16>";
out "negsum16 %s %-9.1<negsum1>"; in "negsum16 %=s %-9.1<negsum1>";
out "-sum16 %s %-9.1<-sum16>"; in "-sum16 %=s %-9.1<-sum16>";
out "nsum32 %s %-9.1<nsum32>"; in "nsum32 %=s %-9.1<nsum32>";
out "negsum32 %s %-9.1<negsum3>"; in "negsum32 %=s %-9.1<negsum3>";
out "-sum32 %s %-9.1<-sum32>"; in "-sum32 %=s %-9.1<-sum32>";
out "notsum %s %-9.1<notsum>"; in "notsum %=s %-9.1<notsum>";
out "~sum %s %-9.1<~sum>"; in "~sum %=s %-9.1<~sum>";
out "xor %s %-9.1<xor>"; in "xor %=s %-9.1<xor>";
out "xor8 %s %-9.1<xor8>"; in "xor8 %=s %-9.1<xor8>";
out "xor7 %s %-9.1<xor7>"; in "xor7 %=s %-9.1<xor7>";
out "crc8 %s %-9.1<crc8>"; in "crc8 %=s %-9.1<crc8>";
out "ccitt8 %s %-9.1<ccitt8>"; in "ccitt8 %=s %-9.1<ccitt8>";
out "crc16 %s %-9.1<crc16>"; in "crc16 %=s %-9.1<crc16>";
out "crc16r %s %-9.1<crc16r>"; in "crc16r %=s %-9.1<crc16r>";
out "ccitt16 %s %-9.1<ccitt16>"; in "ccitt16 %=s %-9.1<ccitt16>";
out "ccitt16a %s %-9.1<ccitt16a>"; in "ccitt16a %=s %-9.1<ccitt16a>";
out "ccitt16x %s %-9.1<ccitt16x>"; in "ccitt16x %=s %-9.1<ccitt16x>";
out "crc16c %s %-9.1<crc16c>"; in "crc16c %=s %-9.1<crc16c>";
out "xmodem %s %-9.1<xmodem>"; in "xmodem %=s %-9.1<xmodem>";
out "crc32 %s %-9.1<crc32>"; in "crc32 %=s %-9.1<crc32>";
out "crc32r %s %-9.1<crc32r>"; in "crc32r %=s %-9.1<crc32r>";
out "jamcrc %s %-9.1<jamcrc>"; in "jamcrc %=s %-9.1<jamcrc>";
out "adler32 %s %-9.1<adler32>"; in "adler32 %=s %-9.1<adler32>";
out "hexsum8 %s %-9.1<hexsum8>"; in "hexsum8 %=s %-9.1<hexsum8>";
out "sum %s %#9.1<sum>"; in "sum %=s %#9.1<sum>";
out "sum8 %s %#9.1<sum8>"; in "sum8 %=s %#9.1<sum8>";
out "sum16 %s %#9.1<sum16>"; in "sum16 %=s %#9.1<sum16>";
out "sum32 %s %#9.1<sum32>"; in "sum32 %=s %#9.1<sum32>";
out "nsum %s %#9.1<nsum>"; in "nsum %=s %#9.1<nsum>";
out "negsum %s %#9.1<negsum>"; in "negsum %=s %#9.1<negsum>";
out "-sum %s %#9.1<-sum>"; in "-sum %=s %#9.1<-sum>";
out "nsum8 %s %#9.1<nsum8>"; in "nsum8 %=s %#9.1<nsum8>";
out "negsum8 %s %#9.1<negsum8>"; in "negsum8 %=s %#9.1<negsum8>";
out "-sum8 %s %#9.1<-sum8>"; in "-sum8 %=s %#9.1<-sum8>";
out "nsum16 %s %#9.1<nsum16>"; in "nsum16 %=s %#9.1<nsum16>";
out "negsum16 %s %#9.1<negsum1>"; in "negsum16 %=s %#9.1<negsum1>";
out "-sum16 %s %#9.1<-sum16>"; in "-sum16 %=s %#9.1<-sum16>";
out "nsum32 %s %#9.1<nsum32>"; in "nsum32 %=s %#9.1<nsum32>";
out "negsum32 %s %#9.1<negsum3>"; in "negsum32 %=s %#9.1<negsum3>";
out "-sum32 %s %#9.1<-sum32>"; in "-sum32 %=s %#9.1<-sum32>";
out "notsum %s %#9.1<notsum>"; in "notsum %=s %#9.1<notsum>";
out "~sum %s %#9.1<~sum>"; in "~sum %=s %#9.1<~sum>";
out "xor %s %#9.1<xor>"; in "xor %=s %#9.1<xor>";
out "xor8 %s %#9.1<xor8>"; in "xor8 %=s %#9.1<xor8>";
out "xor7 %s %#9.1<xor7>"; in "xor7 %=s %#9.1<xor7>";
out "crc8 %s %#9.1<crc8>"; in "crc8 %=s %#9.1<crc8>";
out "ccitt8 %s %#9.1<ccitt8>"; in "ccitt8 %=s %#9.1<ccitt8>";
out "crc16 %s %#9.1<crc16>"; in "crc16 %=s %#9.1<crc16>";
out "crc16r %s %#9.1<crc16r>"; in "crc16r %=s %#9.1<crc16r>";
out "ccitt16 %s %#9.1<ccitt16>"; in "ccitt16 %=s %#9.1<ccitt16>";
out "ccitt16a %s %#9.1<ccitt16a>"; in "ccitt16a %=s %#9.1<ccitt16a>";
out "ccitt16x %s %#9.1<ccitt16x>"; in "ccitt16x %=s %#9.1<ccitt16x>";
out "crc16c %s %#9.1<crc16c>"; in "crc16c %=s %#9.1<crc16c>";
out "xmodem %s %#9.1<xmodem>"; in "xmodem %=s %#9.1<xmodem>";
out "crc32 %s %#9.1<crc32>"; in "crc32 %=s %#9.1<crc32>";
out "crc32r %s %#9.1<crc32r>"; in "crc32r %=s %#9.1<crc32r>";
out "jamcrc %s %#9.1<jamcrc>"; in "jamcrc %=s %#9.1<jamcrc>";
out "adler32 %s %#9.1<adler32>"; in "adler32 %=s %#9.1<adler32>";
out "hexsum8 %s %#9.1<hexsum8>"; in "hexsum8 %=s %#9.1<hexsum8>";
out "sum %s %#09.1<sum>"; in "sum %=s %#09.1<sum>";
out "sum8 %s %#09.1<sum8>"; in "sum8 %=s %#09.1<sum8>";
out "sum16 %s %#09.1<sum16>"; in "sum16 %=s %#09.1<sum16>";
out "sum32 %s %#09.1<sum32>"; in "sum32 %=s %#09.1<sum32>";
out "nsum %s %#09.1<nsum>"; in "nsum %=s %#09.1<nsum>";
out "negsum %s %#09.1<negsum>"; in "negsum %=s %#09.1<negsum>";
out "-sum %s %#09.1<-sum>"; in "-sum %=s %#09.1<-sum>";
out "nsum8 %s %#09.1<nsum8>"; in "nsum8 %=s %#09.1<nsum8>";
out "negsum8 %s %#09.1<negsum8>"; in "negsum8 %=s %#09.1<negsum8>";
out "-sum8 %s %#09.1<-sum8>"; in "-sum8 %=s %#09.1<-sum8>";
out "nsum16 %s %#09.1<nsum16>"; in "nsum16 %=s %#09.1<nsum16>";
out "negsum16 %s %#09.1<negsum1>"; in "negsum16 %=s %#09.1<negsum1>";
out "-sum16 %s %#09.1<-sum16>"; in "-sum16 %=s %#09.1<-sum16>";
out "nsum32 %s %#09.1<nsum32>"; in "nsum32 %=s %#09.1<nsum32>";
out "negsum32 %s %#09.1<negsum3>"; in "negsum32 %=s %#09.1<negsum3>";
out "-sum32 %s %#09.1<-sum32>"; in "-sum32 %=s %#09.1<-sum32>";
out "notsum %s %#09.1<notsum>"; in "notsum %=s %#09.1<notsum>";
out "~sum %s %#09.1<~sum>"; in "~sum %=s %#09.1<~sum>";
out "xor %s %#09.1<xor>"; in "xor %=s %#09.1<xor>";
out "xor8 %s %#09.1<xor8>"; in "xor8 %=s %#09.1<xor8>";
out "xor7 %s %#09.1<xor7>"; in "xor7 %=s %#09.1<xor7>";
out "crc8 %s %#09.1<crc8>"; in "crc8 %=s %#09.1<crc8>";
out "ccitt8 %s %#09.1<ccitt8>"; in "ccitt8 %=s %#09.1<ccitt8>";
out "crc16 %s %#09.1<crc16>"; in "crc16 %=s %#09.1<crc16>";
out "crc16r %s %#09.1<crc16r>"; in "crc16r %=s %#09.1<crc16r>";
out "ccitt16 %s %#09.1<ccitt16>"; in "ccitt16 %=s %#09.1<ccitt16>";
out "ccitt16a %s %#09.1<ccitt16a>"; in "ccitt16a %=s %#09.1<ccitt16a>";
out "ccitt16x %s %#09.1<ccitt16x>"; in "ccitt16x %=s %#09.1<ccitt16x>";
out "crc16c %s %#09.1<crc16c>"; in "crc16c %=s %#09.1<crc16c>";
out "xmodem %s %#09.1<xmodem>"; in "xmodem %=s %#09.1<xmodem>";
out "crc32 %s %#09.1<crc32>"; in "crc32 %=s %#09.1<crc32>";
out "crc32r %s %#09.1<crc32r>"; in "crc32r %=s %#09.1<crc32r>";
out "jamcrc %s %#09.1<jamcrc>"; in "jamcrc %=s %#09.1<jamcrc>";
out "adler32 %s %#09.1<adler32>"; in "adler32 %=s %#09.1<adler32>";
out "hexsum8 %s %#09.1<hexsum8>"; in "hexsum8 %=s %#09.1<hexsum8>";
out "sum %s %#-9.1<sum>"; in "sum %=s %#-9.1<sum>";
out "sum8 %s %#-9.1<sum8>"; in "sum8 %=s %#-9.1<sum8>";
out "sum16 %s %#-9.1<sum16>"; in "sum16 %=s %#-9.1<sum16>";
out "sum32 %s %#-9.1<sum32>"; in "sum32 %=s %#-9.1<sum32>";
out "nsum %s %#-9.1<nsum>"; in "nsum %=s %#-9.1<nsum>";
out "negsum %s %#-9.1<negsum>"; in "negsum %=s %#-9.1<negsum>";
out "-sum %s %#-9.1<-sum>"; in "-sum %=s %#-9.1<-sum>";
out "nsum8 %s %#-9.1<nsum8>"; in "nsum8 %=s %#-9.1<nsum8>";
out "negsum8 %s %#-9.1<negsum8>"; in "negsum8 %=s %#-9.1<negsum8>";
out "-sum8 %s %#-9.1<-sum8>"; in "-sum8 %=s %#-9.1<-sum8>";
out "nsum16 %s %#-9.1<nsum16>"; in "nsum16 %=s %#-9.1<nsum16>";
out "negsum16 %s %#-9.1<negsum1>"; in "negsum16 %=s %#-9.1<negsum1>";
out "-sum16 %s %#-9.1<-sum16>"; in "-sum16 %=s %#-9.1<-sum16>";
out "nsum32 %s %#-9.1<nsum32>"; in "nsum32 %=s %#-9.1<nsum32>";
out "negsum32 %s %#-9.1<negsum3>"; in "negsum32 %=s %#-9.1<negsum3>";
out "-sum32 %s %#-9.1<-sum32>"; in "-sum32 %=s %#-9.1<-sum32>";
out "notsum %s %#-9.1<notsum>"; in "notsum %=s %#-9.1<notsum>";
out "~sum %s %#-9.1<~sum>"; in "~sum %=s %#-9.1<~sum>";
out "xor %s %#-9.1<xor>"; in "xor %=s %#-9.1<xor>";
out "xor8 %s %#-9.1<xor8>"; in "xor8 %=s %#-9.1<xor8>";
out "xor7 %s %#-9.1<xor7>"; in "xor7 %=s %#-9.1<xor7>";
out "crc8 %s %#-9.1<crc8>"; in "crc8 %=s %#-9.1<crc8>";
out "ccitt8 %s %#-9.1<ccitt8>"; in "ccitt8 %=s %#-9.1<ccitt8>";
out "crc16 %s %#-9.1<crc16>"; in "crc16 %=s %#-9.1<crc16>";
out "crc16r %s %#-9.1<crc16r>"; in "crc16r %=s %#-9.1<crc16r>";
out "ccitt16 %s %#-9.1<ccitt16>"; in "ccitt16 %=s %#-9.1<ccitt16>";
out "ccitt16a %s %#-9.1<ccitt16a>"; in "ccitt16a %=s %#-9.1<ccitt16a>";
out "ccitt16x %s %#-9.1<ccitt16x>"; in "ccitt16x %=s %#-9.1<ccitt16x>";
out "crc16c %s %#-9.1<crc16c>"; in "crc16c %=s %#-9.1<crc16c>";
out "xmodem %s %#-9.1<xmodem>"; in "xmodem %=s %#-9.1<xmodem>";
out "crc32 %s %#-9.1<crc32>"; in "crc32 %=s %#-9.1<crc32>";
out "crc32r %s %#-9.1<crc32r>"; in "crc32r %=s %#-9.1<crc32r>";
out "jamcrc %s %#-9.1<jamcrc>"; in "jamcrc %=s %#-9.1<jamcrc>";
out "adler32 %s %#-9.1<adler32>"; in "adler32 %=s %#-9.1<adler32>";
out "hexsum8 %s %#-9.1<hexsum8>"; in "hexsum8 %=s %#-9.1<hexsum8>";
out "DONE";
}
} }
set startup { set startup {
@ -24,7 +242,432 @@ set startup {
set debug 0 set debug 0
startioc startioc
ioccmd {dbpf DZ:test1 "1"} ioccmd {dbpf DZ:test1 "123456789"}
assure "\x55\x40\x04\x00\x00z;\x4e" assure "sum 123456789 \xDD\n"
send "sum 123456789 \xDD\n"
assure "sum8 123456789 \xDD\n"
send "sum8 123456789 \xDD\n"
assure "sum16 123456789 \x01\xDD\n"
send "sum16 123456789 \x01\xDD\n"
assure "sum32 123456789 \x00\x00\x01\xDD\n"
send "sum32 123456789 \x00\x00\x01\xDD\n"
assure "nsum 123456789 \x23\n"
send "nsum 123456789 \x23\n"
assure "negsum 123456789 \x23\n"
send "negsum 123456789 \x23\n"
assure "-sum 123456789 \x23\n"
send "-sum 123456789 \x23\n"
assure "nsum8 123456789 \x23\n"
send "nsum8 123456789 \x23\n"
assure "negsum8 123456789 \x23\n"
send "negsum8 123456789 \x23\n"
assure "-sum8 123456789 \x23\n"
send "-sum8 123456789 \x23\n"
assure "nsum16 123456789 \xFE\x23\n"
send "nsum16 123456789 \xFE\x23\n"
assure "negsum16 123456789 \xFE\x23\n"
send "negsum16 123456789 \xFE\x23\n"
assure "-sum16 123456789 \xFE\x23\n"
send "-sum16 123456789 \xFE\x23\n"
assure "nsum32 123456789 \xFF\xFF\xFE\x23\n"
send "nsum32 123456789 \xFF\xFF\xFE\x23\n"
assure "negsum32 123456789 \xFF\xFF\xFE\x23\n"
send "negsum32 123456789 \xFF\xFF\xFE\x23\n"
assure "-sum32 123456789 \xFF\xFF\xFE\x23\n"
send "-sum32 123456789 \xFF\xFF\xFE\x23\n"
assure "notsum 123456789 \x22\n"
send "notsum 123456789 \x22\n"
assure "~sum 123456789 \x22\n"
send "~sum 123456789 \x22\n"
assure "xor 123456789 \x31\n"
send "xor 123456789 \x31\n"
assure "xor8 123456789 \x31\n"
send "xor8 123456789 \x31\n"
assure "xor7 123456789 \x31\n"
send "xor7 123456789 \x31\n"
assure "crc8 123456789 \xF4\n"
send "crc8 123456789 \xF4\n"
assure "ccitt8 123456789 \xA1\n"
send "ccitt8 123456789 \xA1\n"
assure "crc16 123456789 \xFE\xE8\n"
send "crc16 123456789 \xFE\xE8\n"
assure "crc16r 123456789 \xBB\x3D\n"
send "crc16r 123456789 \xBB\x3D\n"
assure "ccitt16 123456789 \x29\xB1\n"
send "ccitt16 123456789 \x29\xB1\n"
assure "ccitt16a 123456789 \xE5\xCC\n"
send "ccitt16a 123456789 \xE5\xCC\n"
assure "ccitt16x 123456789 \x31\xC3\n"
send "ccitt16x 123456789 \x31\xC3\n"
assure "crc16c 123456789 \x31\xC3\n"
send "crc16c 123456789 \x31\xC3\n"
assure "xmodem 123456789 \x31\xC3\n"
send "xmodem 123456789 \x31\xC3\n"
assure "crc32 123456789 \xFC\x89\x19\x18\n"
send "crc32 123456789 \xFC\x89\x19\x18\n"
assure "crc32r 123456789 \xCB\xF4\x39\x26\n"
send "crc32r 123456789 \xCB\xF4\x39\x26\n"
assure "jamcrc 123456789 \x34\x0B\xC6\xD9\n"
send "jamcrc 123456789 \x34\x0B\xC6\xD9\n"
assure "adler32 123456789 \x09\x1E\x01\xDE\n"
send "adler32 123456789 \x09\x1E\x01\xDE\n"
assure "hexsum8 123456789 \x2D\n"
send "hexsum8 123456789 \x2D\n"
assure "sum 123456789 DD\n"
send "sum 123456789 DD\n"
assure "sum8 123456789 DD\n"
send "sum8 123456789 DD\n"
assure "sum16 123456789 01DD\n"
send "sum16 123456789 01DD\n"
assure "sum32 123456789 000001DD\n"
send "sum32 123456789 000001DD\n"
assure "nsum 123456789 23\n"
send "nsum 123456789 23\n"
assure "negsum 123456789 23\n"
send "negsum 123456789 23\n"
assure "-sum 123456789 23\n"
send "-sum 123456789 23\n"
assure "nsum8 123456789 23\n"
send "nsum8 123456789 23\n"
assure "negsum8 123456789 23\n"
send "negsum8 123456789 23\n"
assure "-sum8 123456789 23\n"
send "-sum8 123456789 23\n"
assure "nsum16 123456789 FE23\n"
send "nsum16 123456789 FE23\n"
assure "negsum16 123456789 FE23\n"
send "negsum16 123456789 FE23\n"
assure "-sum16 123456789 FE23\n"
send "-sum16 123456789 FE23\n"
assure "nsum32 123456789 FFFFFE23\n"
send "nsum32 123456789 FFFFFE23\n"
assure "negsum32 123456789 FFFFFE23\n"
send "negsum32 123456789 FFFFFE23\n"
assure "-sum32 123456789 FFFFFE23\n"
send "-sum32 123456789 FFFFFE23\n"
assure "notsum 123456789 22\n"
send "notsum 123456789 22\n"
assure "~sum 123456789 22\n"
send "~sum 123456789 22\n"
assure "xor 123456789 31\n"
send "xor 123456789 31\n"
assure "xor8 123456789 31\n"
send "xor8 123456789 31\n"
assure "xor7 123456789 31\n"
send "xor7 123456789 31\n"
assure "crc8 123456789 F4\n"
send "crc8 123456789 F4\n"
assure "ccitt8 123456789 A1\n"
send "ccitt8 123456789 A1\n"
assure "crc16 123456789 FEE8\n"
send "crc16 123456789 FEE8\n"
assure "crc16r 123456789 BB3D\n"
send "crc16r 123456789 BB3D\n"
assure "ccitt16 123456789 29B1\n"
send "ccitt16 123456789 29B1\n"
assure "ccitt16a 123456789 E5CC\n"
send "ccitt16a 123456789 E5CC\n"
assure "ccitt16x 123456789 31C3\n"
send "ccitt16x 123456789 31C3\n"
assure "crc16c 123456789 31C3\n"
send "crc16c 123456789 31C3\n"
assure "xmodem 123456789 31C3\n"
send "xmodem 123456789 31C3\n"
assure "crc32 123456789 FC891918\n"
send "crc32 123456789 FC891918\n"
assure "crc32r 123456789 CBF43926\n"
send "crc32r 123456789 CBF43926\n"
assure "jamcrc 123456789 340BC6D9\n"
send "jamcrc 123456789 340BC6D9\n"
assure "adler32 123456789 091E01DE\n"
send "adler32 123456789 091E01DE\n"
assure "hexsum8 123456789 2D\n"
send "hexsum8 123456789 2D\n"
assure "sum 123456789 \x3D\x3D\n"
send "sum 123456789 \x3D\x3D\n"
assure "sum8 123456789 \x3D\x3D\n"
send "sum8 123456789 \x3D\x3D\n"
assure "sum16 123456789 \x30\x31\x3D\x3D\n"
send "sum16 123456789 \x30\x31\x3D\x3D\n"
assure "sum32 123456789 \x30\x30\x30\x30\x30\x31\x3D\x3D\n"
send "sum32 123456789 \x30\x30\x30\x30\x30\x31\x3D\x3D\n"
assure "nsum 123456789 \x32\x33\n"
send "nsum 123456789 \x32\x33\n"
assure "negsum 123456789 \x32\x33\n"
send "negsum 123456789 \x32\x33\n"
assure "-sum 123456789 \x32\x33\n"
send "-sum 123456789 \x32\x33\n"
assure "nsum8 123456789 \x32\x33\n"
send "nsum8 123456789 \x32\x33\n"
assure "negsum8 123456789 \x32\x33\n"
send "negsum8 123456789 \x32\x33\n"
assure "-sum8 123456789 \x32\x33\n"
send "-sum8 123456789 \x32\x33\n"
assure "nsum16 123456789 \x3F\x3E\x32\x33\n"
send "nsum16 123456789 \x3F\x3E\x32\x33\n"
assure "negsum16 123456789 \x3F\x3E\x32\x33\n"
send "negsum16 123456789 \x3F\x3E\x32\x33\n"
assure "-sum16 123456789 \x3F\x3E\x32\x33\n"
send "-sum16 123456789 \x3F\x3E\x32\x33\n"
assure "nsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
send "nsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
assure "negsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
send "negsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
assure "-sum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
send "-sum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
assure "notsum 123456789 \x32\x32\n"
send "notsum 123456789 \x32\x32\n"
assure "~sum 123456789 \x32\x32\n"
send "~sum 123456789 \x32\x32\n"
assure "xor 123456789 \x33\x31\n"
send "xor 123456789 \x33\x31\n"
assure "xor8 123456789 \x33\x31\n"
send "xor8 123456789 \x33\x31\n"
assure "xor7 123456789 \x33\x31\n"
send "xor7 123456789 \x33\x31\n"
assure "crc8 123456789 \x3F\x34\n"
send "crc8 123456789 \x3F\x34\n"
assure "ccitt8 123456789 \x3A\x31\n"
send "ccitt8 123456789 \x3A\x31\n"
assure "crc16 123456789 \x3F\x3E\x3E\x38\n"
send "crc16 123456789 \x3F\x3E\x3E\x38\n"
assure "crc16r 123456789 \x3B\x3B\x33\x3D\n"
send "crc16r 123456789 \x3B\x3B\x33\x3D\n"
assure "ccitt16 123456789 \x32\x39\x3B\x31\n"
send "ccitt16 123456789 \x32\x39\x3B\x31\n"
assure "ccitt16a 123456789 \x3E\x35\x3C\x3C\n"
send "ccitt16a 123456789 \x3E\x35\x3C\x3C\n"
assure "ccitt16x 123456789 \x33\x31\x3C\x33\n"
send "ccitt16x 123456789 \x33\x31\x3C\x33\n"
assure "crc16c 123456789 \x33\x31\x3C\x33\n"
send "crc16c 123456789 \x33\x31\x3C\x33\n"
assure "xmodem 123456789 \x33\x31\x3C\x33\n"
send "xmodem 123456789 \x33\x31\x3C\x33\n"
assure "crc32 123456789 \x3F\x3C\x38\x39\x31\x39\x31\x38\n"
send "crc32 123456789 \x3F\x3C\x38\x39\x31\x39\x31\x38\n"
assure "crc32r 123456789 \x3C\x3B\x3F\x34\x33\x39\x32\x36\n"
send "crc32r 123456789 \x3C\x3B\x3F\x34\x33\x39\x32\x36\n"
assure "jamcrc 123456789 \x33\x34\x30\x3B\x3C\x36\x3D\x39\n"
send "jamcrc 123456789 \x33\x34\x30\x3B\x3C\x36\x3D\x39\n"
assure "adler32 123456789 \x30\x39\x31\x3E\x30\x31\x3D\x3E\n"
send "adler32 123456789 \x30\x39\x31\x3E\x30\x31\x3D\x3E\n"
assure "hexsum8 123456789 \x32\x3D\n"
send "hexsum8 123456789 \x32\x3D\n"
assure "sum 123456789 \xDD\n"
send "sum 123456789 \xDD\n"
assure "sum8 123456789 \xDD\n"
send "sum8 123456789 \xDD\n"
assure "sum16 123456789 \xDD\x01\n"
send "sum16 123456789 \xDD\x01\n"
assure "sum32 123456789 \xDD\x01\x00\x00\n"
send "sum32 123456789 \xDD\x01\x00\x00\n"
assure "nsum 123456789 \x23\n"
send "nsum 123456789 \x23\n"
assure "negsum 123456789 \x23\n"
send "negsum 123456789 \x23\n"
assure "-sum 123456789 \x23\n"
send "-sum 123456789 \x23\n"
assure "nsum8 123456789 \x23\n"
send "nsum8 123456789 \x23\n"
assure "negsum8 123456789 \x23\n"
send "negsum8 123456789 \x23\n"
assure "-sum8 123456789 \x23\n"
send "-sum8 123456789 \x23\n"
assure "nsum16 123456789 \x23\xFE\n"
send "nsum16 123456789 \x23\xFE\n"
assure "negsum16 123456789 \x23\xFE\n"
send "negsum16 123456789 \x23\xFE\n"
assure "-sum16 123456789 \x23\xFE\n"
send "-sum16 123456789 \x23\xFE\n"
assure "nsum32 123456789 \x23\xFE\xFF\xFF\n"
send "nsum32 123456789 \x23\xFE\xFF\xFF\n"
assure "negsum32 123456789 \x23\xFE\xFF\xFF\n"
send "negsum32 123456789 \x23\xFE\xFF\xFF\n"
assure "-sum32 123456789 \x23\xFE\xFF\xFF\n"
send "-sum32 123456789 \x23\xFE\xFF\xFF\n"
assure "notsum 123456789 \x22\n"
send "notsum 123456789 \x22\n"
assure "~sum 123456789 \x22\n"
send "~sum 123456789 \x22\n"
assure "xor 123456789 \x31\n"
send "xor 123456789 \x31\n"
assure "xor8 123456789 \x31\n"
send "xor8 123456789 \x31\n"
assure "xor7 123456789 \x31\n"
send "xor7 123456789 \x31\n"
assure "crc8 123456789 \xF4\n"
send "crc8 123456789 \xF4\n"
assure "ccitt8 123456789 \xA1\n"
send "ccitt8 123456789 \xA1\n"
assure "crc16 123456789 \xE8\xFE\n"
send "crc16 123456789 \xE8\xFE\n"
assure "crc16r 123456789 \x3D\xBB\n"
send "crc16r 123456789 \x3D\xBB\n"
assure "ccitt16 123456789 \xB1\x29\n"
send "ccitt16 123456789 \xB1\x29\n"
assure "ccitt16a 123456789 \xCC\xE5\n"
send "ccitt16a 123456789 \xCC\xE5\n"
assure "ccitt16x 123456789 \xC3\x31\n"
send "ccitt16x 123456789 \xC3\x31\n"
assure "crc16c 123456789 \xC3\x31\n"
send "crc16c 123456789 \xC3\x31\n"
assure "xmodem 123456789 \xC3\x31\n"
send "xmodem 123456789 \xC3\x31\n"
assure "crc32 123456789 \x18\x19\x89\xFC\n"
send "crc32 123456789 \x18\x19\x89\xFC\n"
assure "crc32r 123456789 \x26\x39\xF4\xCB\n"
send "crc32r 123456789 \x26\x39\xF4\xCB\n"
assure "jamcrc 123456789 \xD9\xC6\x0B\x34\n"
send "jamcrc 123456789 \xD9\xC6\x0B\x34\n"
assure "adler32 123456789 \xDE\x01\x1E\x09\n"
send "adler32 123456789 \xDE\x01\x1E\x09\n"
assure "hexsum8 123456789 \x2D\n"
send "hexsum8 123456789 \x2D\n"
assure "sum 123456789 DD\n"
send "sum 123456789 DD\n"
assure "sum8 123456789 DD\n"
send "sum8 123456789 DD\n"
assure "sum16 123456789 DD01\n"
send "sum16 123456789 DD01\n"
assure "sum32 123456789 DD010000\n"
send "sum32 123456789 DD010000\n"
assure "nsum 123456789 23\n"
send "nsum 123456789 23\n"
assure "negsum 123456789 23\n"
send "negsum 123456789 23\n"
assure "-sum 123456789 23\n"
send "-sum 123456789 23\n"
assure "nsum8 123456789 23\n"
send "nsum8 123456789 23\n"
assure "negsum8 123456789 23\n"
send "negsum8 123456789 23\n"
assure "-sum8 123456789 23\n"
send "-sum8 123456789 23\n"
assure "nsum16 123456789 23FE\n"
send "nsum16 123456789 23FE\n"
assure "negsum16 123456789 23FE\n"
send "negsum16 123456789 23FE\n"
assure "-sum16 123456789 23FE\n"
send "-sum16 123456789 23FE\n"
assure "nsum32 123456789 23FEFFFF\n"
send "nsum32 123456789 23FEFFFF\n"
assure "negsum32 123456789 23FEFFFF\n"
send "negsum32 123456789 23FEFFFF\n"
assure "-sum32 123456789 23FEFFFF\n"
send "-sum32 123456789 23FEFFFF\n"
assure "notsum 123456789 22\n"
send "notsum 123456789 22\n"
assure "~sum 123456789 22\n"
send "~sum 123456789 22\n"
assure "xor 123456789 31\n"
send "xor 123456789 31\n"
assure "xor8 123456789 31\n"
send "xor8 123456789 31\n"
assure "xor7 123456789 31\n"
send "xor7 123456789 31\n"
assure "crc8 123456789 F4\n"
send "crc8 123456789 F4\n"
assure "ccitt8 123456789 A1\n"
send "ccitt8 123456789 A1\n"
assure "crc16 123456789 E8FE\n"
send "crc16 123456789 E8FE\n"
assure "crc16r 123456789 3DBB\n"
send "crc16r 123456789 3DBB\n"
assure "ccitt16 123456789 B129\n"
send "ccitt16 123456789 B129\n"
assure "ccitt16a 123456789 CCE5\n"
send "ccitt16a 123456789 CCE5\n"
assure "ccitt16x 123456789 C331\n"
send "ccitt16x 123456789 C331\n"
assure "crc16c 123456789 C331\n"
send "crc16c 123456789 C331\n"
assure "xmodem 123456789 C331\n"
send "xmodem 123456789 C331\n"
assure "crc32 123456789 181989FC\n"
send "crc32 123456789 181989FC\n"
assure "crc32r 123456789 2639F4CB\n"
send "crc32r 123456789 2639F4CB\n"
assure "jamcrc 123456789 D9C60B34\n"
send "jamcrc 123456789 D9C60B34\n"
assure "adler32 123456789 DE011E09\n"
send "adler32 123456789 DE011E09\n"
assure "hexsum8 123456789 2D\n"
send "hexsum8 123456789 2D\n"
assure "sum 123456789 \x3D\x3D\n"
send "sum 123456789 \x3D\x3D\n"
assure "sum8 123456789 \x3D\x3D\n"
send "sum8 123456789 \x3D\x3D\n"
assure "sum16 123456789 \x3D\x3D\x30\x31\n"
send "sum16 123456789 \x3D\x3D\x30\x31\n"
assure "sum32 123456789 \x3D\x3D\x30\x31\x30\x30\x30\x30\n"
send "sum32 123456789 \x3D\x3D\x30\x31\x30\x30\x30\x30\n"
assure "nsum 123456789 \x32\x33\n"
send "nsum 123456789 \x32\x33\n"
assure "negsum 123456789 \x32\x33\n"
send "negsum 123456789 \x32\x33\n"
assure "-sum 123456789 \x32\x33\n"
send "-sum 123456789 \x32\x33\n"
assure "nsum8 123456789 \x32\x33\n"
send "nsum8 123456789 \x32\x33\n"
assure "negsum8 123456789 \x32\x33\n"
send "negsum8 123456789 \x32\x33\n"
assure "-sum8 123456789 \x32\x33\n"
send "-sum8 123456789 \x32\x33\n"
assure "nsum16 123456789 \x32\x33\x3F\x3E\n"
send "nsum16 123456789 \x32\x33\x3F\x3E\n"
assure "negsum16 123456789 \x32\x33\x3F\x3E\n"
send "negsum16 123456789 \x32\x33\x3F\x3E\n"
assure "-sum16 123456789 \x32\x33\x3F\x3E\n"
send "-sum16 123456789 \x32\x33\x3F\x3E\n"
assure "nsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
send "nsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
assure "negsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
send "negsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
assure "-sum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
send "-sum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
assure "notsum 123456789 \x32\x32\n"
send "notsum 123456789 \x32\x32\n"
assure "~sum 123456789 \x32\x32\n"
send "~sum 123456789 \x32\x32\n"
assure "xor 123456789 \x33\x31\n"
send "xor 123456789 \x33\x31\n"
assure "xor8 123456789 \x33\x31\n"
send "xor8 123456789 \x33\x31\n"
assure "xor7 123456789 \x33\x31\n"
send "xor7 123456789 \x33\x31\n"
assure "crc8 123456789 \x3F\x34\n"
send "crc8 123456789 \x3F\x34\n"
assure "ccitt8 123456789 \x3A\x31\n"
send "ccitt8 123456789 \x3A\x31\n"
assure "crc16 123456789 \x3E\x38\x3F\x3E\n"
send "crc16 123456789 \x3E\x38\x3F\x3E\n"
assure "crc16r 123456789 \x33\x3D\x3B\x3B\n"
send "crc16r 123456789 \x33\x3D\x3B\x3B\n"
assure "ccitt16 123456789 \x3B\x31\x32\x39\n"
send "ccitt16 123456789 \x3B\x31\x32\x39\n"
assure "ccitt16a 123456789 \x3C\x3C\x3E\x35\n"
send "ccitt16a 123456789 \x3C\x3C\x3E\x35\n"
assure "ccitt16x 123456789 \x3C\x33\x33\x31\n"
send "ccitt16x 123456789 \x3C\x33\x33\x31\n"
assure "crc16c 123456789 \x3C\x33\x33\x31\n"
send "crc16c 123456789 \x3C\x33\x33\x31\n"
assure "xmodem 123456789 \x3C\x33\x33\x31\n"
send "xmodem 123456789 \x3C\x33\x33\x31\n"
assure "crc32 123456789 \x31\x38\x31\x39\x38\x39\x3F\x3C\n"
send "crc32 123456789 \x31\x38\x31\x39\x38\x39\x3F\x3C\n"
assure "crc32r 123456789 \x32\x36\x33\x39\x3F\x34\x3C\x3B\n"
send "crc32r 123456789 \x32\x36\x33\x39\x3F\x34\x3C\x3B\n"
assure "jamcrc 123456789 \x3D\x39\x3C\x36\x30\x3B\x33\x34\n"
send "jamcrc 123456789 \x3D\x39\x3C\x36\x30\x3B\x33\x34\n"
assure "adler32 123456789 \x3D\x3E\x30\x31\x31\x3E\x30\x39\n"
send "adler32 123456789 \x3D\x3E\x30\x31\x31\x3E\x30\x39\n"
assure "hexsum8 123456789 \x32\x3D\n"
send "hexsum8 123456789 \x32\x3D\n"
assure "DONE\n"
finish finish

View File

@ -41,12 +41,10 @@ set protocol {
set startup { set startup {
} }
set debug 0
startioc startioc
set inf [format %f inf] set inf [format %f inf]
set nan [format %f nan] if [catch {set nan [format %f nan]}] {set nan nan}
ioccmd {dbpf DZ:test1.PROC 1} ioccmd {dbpf DZ:test1.PROC 1}
send "3.14159265359\n" send "3.14159265359\n"

View File

@ -50,7 +50,7 @@ set protocol {
in {in "%{zero|one|two}bla"; out "%d";} in {in "%{zero|one|two}bla"; out "%d";}
out1 {out "%#{zero|one|two}bla";} out1 {out "%#{zero|one|two}bla";}
in1 {in "%#{zero|one|two}bla"; out "%d";} in1 {in "%#{zero|one|two}bla"; out "%d";}
out2 {out "%#{zero=-1|one|two=5}bla";} out2 {out "%#{zero=-1|one|two=5|default=?}bla";}
in2 {in "%#{zero=-1|one|two=5}bla"; out "%d";} in2 {in "%#{zero=-1|one|two=5}bla"; out "%d";}
in3 {in "%{\x00|\r|}bla"; out "%d";} in3 {in "%{\x00|\r|}bla"; out "%d";}
} }
@ -81,6 +81,8 @@ ioccmd {dbpf DZ:testout2 0}
assure "onebla\n" assure "onebla\n"
ioccmd {dbpf DZ:testout2 5} ioccmd {dbpf DZ:testout2 5}
assure "twobla\n" assure "twobla\n"
ioccmd {dbpf DZ:testout2 17}
assure "defaultbla\n"
ioccmd {dbpf DZ:testin.PROC 1} ioccmd {dbpf DZ:testin.PROC 1}
send "zerobla\n" send "zerobla\n"

View File

@ -7,6 +7,11 @@ source streamtestlib.tcl
# Send commands to the ioc shell with ioccmd # Send commands to the ioc shell with ioccmd
set records { set records {
record (bo, "DZ:percent")
{
field (DTYP, "stream")
field (OUT, "@test.proto percent device")
}
record (ao, "DZ:ao") record (ao, "DZ:ao")
{ {
field (DTYP, "stream") field (DTYP, "stream")
@ -25,25 +30,14 @@ set records {
field (DTYP, "stream") field (DTYP, "stream")
field (OUT, "@test.proto bcd device") field (OUT, "@test.proto bcd device")
} }
record (stringout, "DZ:chksum")
{
field (DTYP, "stream")
field (OUT, "@test.proto chksum device")
}
} }
set protocol { set protocol {
Terminator = LF; Terminator = LF;
percent {out "\%\x25\37\045" 0x25 37 045;}
ao {out "%.2f %.2e %.2E %.2g %.2G %i %d %u %o %04x %#.2f %#.2e %#.2E %#.2g %#.2G %#i %#d %#u %#o %#06x";} ao {out "%.2f %.2e %.2E %.2g %.2G %i %d %u %o %04x %#.2f %#.2e %#.2E %#.2g %#.2G %#i %#d %#u %#o %#06x";}
lo {out "%d %(VAL)d %06d %x %06X %b %06b %.6b %B.! %06B.!";} lo {out "%d %(VAL)d %06d %x %06X %b %06b %.6b %B.! %06B.!";}
bcd {out "%D %6D %.2D %.4D %.6D %.8D %#D %#6D %#.2D %#.4D %#.6D";} bcd {out "%D %6D %.2D %.4D %.6D %.8D %#D %#6D %#.2D %#.4D %#.6D";}
chksum {out "%s%<xor>";
out "%s%0<sum>";
out "%s%0<crc8>";
out "%s%0<crc16>";
out "%s%0<crc32>";
out "%s%0<adler32>";
}
} }
set startup { set startup {
@ -58,6 +52,8 @@ startioc
# This is normal. E.g. -1 HAS a different number of 1 bits. # This is normal. E.g. -1 HAS a different number of 1 bits.
# Specify the width field in the format if this is a problem. # Specify the width field in the format if this is a problem.
ioccmd {dbpf DZ:percent 1}
assure "%%%%%%%\n"
ioccmd {dbpf DZ:ao 0} ioccmd {dbpf DZ:ao 0}
assure "0.00 0.00e+00 0.00E+00 0 0 32767 32767 32767 77777 7fff 0.00 0.00e+00 0.00E+00 0.0 0.0 32767 32767 32767 077777 0x7fff\n" assure "0.00 0.00e+00 0.00E+00 0 0 32767 32767 32767 77777 7fff 0.00 0.00e+00 0.00E+00 0.0 0.0 32767 32767 32767 077777 0x7fff\n"
ioccmd {dbpf DZ:ao 10} ioccmd {dbpf DZ:ao 10}
@ -72,15 +68,15 @@ ioccmd {dbpf DZ:lo 12345}
assure "12345 12345 012345 3039 003039 11000000111001 11000000111001 111001 !!......!!!..! !!......!!!..!\n" assure "12345 12345 012345 3039 003039 11000000111001 11000000111001 111001 !!......!!!..! !!......!!!..!\n"
ioccmd {dbpf DZ:lo -1} ioccmd {dbpf DZ:lo -1}
if {$tcl_platform(machine) == "x86_64"} { if {$tcl_platform(machine) == "x86_64"} {
assure "-1 -1 -00001 ffffffffffffffff FFFFFFFFFFFFFFFF 1111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" assure "-1 -1 -00001 ffffffffffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
} else { } else {
assure "-1 -1 -00001 ffffffff FFFFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" assure "-1 -1 -00001 ffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
} }
ioccmd {dbpf DZ:lo -1234} ioccmd {dbpf DZ:lo -1234}
if {$tcl_platform(machine) == "x86_64"} { if {$tcl_platform(machine) == "x86_64"} {
assure "-1234 -1234 -01234 fffffffffffffb2e FFFFFFFFFFFFFB2E 1111111111111111111111111111111111111111111111111111101100101110 1111111111111111111111111111111111111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n" assure "-1234 -1234 -01234 fffffffffffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
} else { } else {
assure "-1234 -1234 -01234 fffffb2e FFFFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n" assure "-1234 -1234 -01234 fffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
} }
ioccmd {dbpf DZ:lo 255} ioccmd {dbpf DZ:lo 255}
assure "255 255 000255 ff 0000FF 11111111 11111111 111111 !!!!!!!! !!!!!!!!\n" assure "255 255 000255 ff 0000FF 11111111 11111111 111111 !!!!!!!! !!!!!!!!\n"
@ -92,11 +88,4 @@ assure "\0\0\0\0\1\2\3\4 \0\0\0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1\0\0\0
} else { } else {
assure "\1\2\3\4 \0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1 \4\3\2\1\0\0 \4 \4\3 \4\3\2\n" assure "\1\2\3\4 \0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1 \4\3\2\1\0\0 \4 \4\3 \4\3\2\n"
} }
ioccmd {dbpf DZ:chksum "123456789"}
assure "1234567891\n"
assure "123456789DD\n"
assure "123456789F4\n"
assure "123456789FEE8\n"
assure "123456789FC891918\n"
assure "123456789091E01DE\n"
finish finish

View File

@ -10,16 +10,19 @@ set records {
record (ai, "DZ:test1") record (ai, "DZ:test1")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test1 device") field (INP, "@test.proto test1 device")
} }
record (ai, "DZ:test2") record (ai, "DZ:test2")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test2 device") field (INP, "@test.proto test2 device")
} }
record (ai, "DZ:test3") record (ai, "DZ:test3")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test3 device") field (INP, "@test.proto test3 device")
} }
record (ai, "DZ:test4") record (ai, "DZ:test4")
@ -30,26 +33,31 @@ set records {
record (ai, "DZ:test5") record (ai, "DZ:test5")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test5 device") field (INP, "@test.proto test5 device")
} }
record (ai, "DZ:test6") record (ai, "DZ:test6")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test6 device") field (INP, "@test.proto test6 device")
} }
record (ai, "DZ:test7") record (ai, "DZ:test7")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test7 device") field (INP, "@test.proto test7 device")
} }
record (ai, "DZ:test8") record (ai, "DZ:test8")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test8 device") field (INP, "@test.proto test8 device")
} }
record (ai, "DZ:test9") record (ai, "DZ:test9")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (LINR, "LINEAR")
field (INP, "@test.proto test9 device") field (INP, "@test.proto test9 device")
} }
record (ai, "DZ:test10") record (ai, "DZ:test10")

33
streamApp/tests/testStrangesum Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env tclsh
source streamtestlib.tcl
# Define records, protocol and startup (text goes to files)
# The asynPort "device" is connected to a network TCP socket
# Talk to the socket with send/receive/assure
# Send commands to the ioc shell with ioccmd
set records {
record (stringout, "DZ:test1")
{
field (DTYP, "stream")
field (OUT, "@test.proto test1 device")
}
}
set protocol {
Terminator="\r\n";
test1 {
out ":%s%01<-hexsum8>";
}
}
set startup {
}
set debug 0
startioc
ioccmd {dbpf DZ:test1 "010304010001"}
assure ":010304010001F6\r\n"
finish

View File

@ -53,13 +53,22 @@ int main () {
} }
EOF EOF
g++ -I ../../src ../../src/O.$EPICS_HOST_ARCH/StreamBuffer.o test.cc -o test.exe if [ "$1" = "-sls" ]
test.exe
if [ $? != 0 ]
then then
echo -e "\033[31;7mTest failed.\033[0m" O=../../O.*_$EPICS_HOST_ARCH/StreamBuffer.o
exit 1 else
O=../../src/O.$EPICS_HOST_ARCH/StreamBuffer.o
fi fi
for o in $O
do
g++ -I ../../src $o test.cc -o test.exe
test.exe
if [ $? != 0 ]
then
echo -e "\033[31;7mTest failed.\033[0m"
exit 1
fi
done
rm test.* rm test.*
echo -e "\033[32mTest passed.\033[0m" echo -e "\033[32mTest passed.\033[0m"