Compare commits

..

114 Commits

Author SHA1 Message Date
b9c26cb6f8 problem with connection handling workaround 2011-09-22 10:01:25 +00:00
e3dd0a319a updates 2011-09-19 09:30:00 +00:00
80b7ceea2d make stream.dbd in O directories 2011-09-19 08:35:58 +00:00
eabcce156a not needed 2011-09-19 08:30:02 +00:00
615beb7d02 ignore stream.dbd 2011-09-19 08:10:56 +00:00
78e6c9355c use perl scripts to generate files 2011-09-19 08:06:54 +00:00
20129ea341 build autimatically 2011-09-16 15:30:57 +00:00
388f950559 put in aai and aao, they are now standard parts in 3.14.12 2011-09-16 15:25:07 +00:00
96c93714a4 Modifications for new versions of base, asyn, calc 2011-09-16 15:23:19 +00:00
252eb44959 use perl script instead of shell script to allow for windows 2011-09-16 15:22:06 +00:00
0442e2ae4f dependency stuff added for 3.14.12 2011-09-16 15:16:40 +00:00
31dae22428 fix for 64 bit machines 2011-09-14 09:08:17 +00:00
1d5c7adb61 typo 2011-09-14 08:38:47 +00:00
c138442a95 fixes for 64 bit machines 2011-09-14 08:33:08 +00:00
a672ab1234 Improve re-connection handling in unexpectedly disconnecting IP ports. 2011-09-13 15:58:00 +00:00
c550cc01be bugfix: this could hang up the record in PACT=1 state 2011-09-13 15:52:24 +00:00
7db71589d8 no portable way to test this 2011-09-13 14:00:37 +00:00
910cf77d97 unfortunately we have to link PCRE here because otherwise static builds fail 2011-09-12 09:54:29 +00:00
807fe825d6 exit command added 2011-09-12 09:52:48 +00:00
ff46c9a4a7 fixes for 64 bit machines 2011-09-12 08:55:23 +00:00
a42fbc9c6c use correct delete operator 2011-09-12 08:46:58 +00:00
74d950ab2d Workaround for strange bug on xscale_be 2011-08-30 11:44:27 +00:00
9049baf730 report protocol name with original case 2011-07-28 12:39:11 +00:00
050a165a82 bugfix: had stale fieldAddress under some circumstances 2011-07-28 12:08:39 +00:00
1428b85a34 must find a way to generate this 2011-07-20 08:33:19 +00:00
e4f8a6ed40 fix endless loop when port does not support EOS 2011-07-20 08:32:09 +00:00
5a5b42cb67 test reserve() 2011-07-20 08:31:10 +00:00
e62553eca6 input tests added 2011-07-20 08:30:38 +00:00
0846c1dd5b don't link to PCRE here, that has been done in stream library already. 2011-05-06 12:17:02 +00:00
774e88241a compatibility problem with shell on solaris 2011-05-06 12:15:45 +00:00
03a04a51b6 *** empty log message *** 2011-05-06 12:15:20 +00:00
103e74be03 compatibility problem with "inf" and "Inf" on different archs 2011-05-06 12:15:01 +00:00
129cc61759 compatibility problem with old tcl version on solaris 2011-05-06 12:14:23 +00:00
70073e1b69 test to check locking and priorities 2011-03-29 15:18:07 +00:00
c94c1a1e70 Fixes for windows
Don't have a bash here so use perl.
Need to give the full path for PCRE (strange)
2011-03-29 12:36:42 +00:00
07026b03ae port locking sometimes deadlocks when used together with syncronous software and sometimes crashes the timer queue 2011-03-29 12:34:50 +00:00
5a6d293a5f windows patch 2011-03-10 10:13:52 +00:00
d51d6648e0 avoid compiler warnings 2011-03-10 10:13:36 +00:00
f521da8606 explicit cast to avoid compiler warning 2011-03-10 10:12:53 +00:00
b64d486925 xmodem alias added 2011-03-07 14:42:12 +00:00
7f1f1c1e65 Bugfix: escaped % in format did not work 2011-02-24 16:12:43 +00:00
2dc0918926 Bugfix: allow out formats in exec 2011-02-24 16:12:08 +00:00
37d412108a Add dummy interface 2011-02-24 16:11:21 +00:00
f03af416eb *** empty log message *** 2011-02-24 16:10:11 +00:00
82066af0e0 non-asyn interface without I/O 2011-02-24 14:29:19 +00:00
9c18afb178 Buggy old Tornado compiler (cygnus-2.7.2). Comment out some debug messages. 2011-02-08 13:59:30 +00:00
04c6cb50d7 allow record name without .VAL in redirection 2011-02-04 15:31:40 +00:00
382784526c make markbit small enough to be inlined on solaris 2011-02-04 15:11:57 +00:00
a91496884c don't mention unused parameters to avoid compiler warning 2011-02-04 15:07:02 +00:00
7cdec03dcb memguard shell fuction removed from here (may go to a separate file) 2011-02-03 16:39:10 +00:00
3e5e4b8375 avoid strange gcc warning 2011-02-03 16:28:17 +00:00
f8b944f325 I/O Intr bugfix: lines where lost when not read in one chunk 2011-02-03 16:27:14 +00:00
c7e7878d9e no memguard 2010-12-09 15:41:35 +00:00
5717dd6345 add NP byte code as alias for FF 2010-12-09 11:03:23 +00:00
2fe3b5c68d Bugfix: Infinite recursion with multi-line input and I/O Intr records 2010-12-07 17:02:52 +00:00
db88081fd7 print single space for "arbitrary whitespace" and nothing for "skip" 2010-12-07 13:23:46 +00:00
1230c01646 use _ to match arbitrary whitespace 2010-12-07 12:49:48 +00:00
8142dd27eb New special char: "_" means arbitrary amount of whitespace 2010-12-07 10:13:21 +00:00
19279b208a Separator re-work did not work 2010-12-07 10:12:17 +00:00
9619c359c1 separator pre-parsing did not work as expected. Problems with whitespace separators. Back to old soluton 2010-12-07 10:07:58 +00:00
6b948abc2d Fix for RTEMS 2010-12-03 08:18:39 +00:00
2c7391602a Bugfixes: escaped quotes in strings and multi-line format strings 2010-12-02 16:04:15 +00:00
fd0fccda46 *** empty log message *** 2010-12-02 16:03:19 +00:00
1164413bd2 fixes for new TCL version 2010-11-29 15:54:38 +00:00
7e1e038ecd *** empty log message *** 2010-11-29 15:53:41 +00:00
2a8b0aed56 wrong sign in time zone calculation 2010-11-29 15:50:20 +00:00
c856dec6dd Space handling in separartors and literal input:
Any amount of whitespace matches space character in litrals and if space is first character of a separator.
2010-11-29 15:30:59 +00:00
53bb235ff1 several bugfixes: time zone, windows, shortcut formats 2010-11-29 15:28:24 +00:00
29ac760f0e sscanf removed from %c and %[] 2010-11-29 15:26:05 +00:00
7836af6423 obsolete separator function removed 2010-11-29 15:24:18 +00:00
1af9c6ea55 fixes for new asyn version 2010-11-29 15:22:50 +00:00
8c619d3350 *** empty log message *** 2010-11-29 15:21:34 +00:00
0155d5ab69 handle new asyn status codes for asyn 4.11 2010-11-05 12:31:30 +00:00
8252b629f5 diamond version of port locking because of probplems with tpmac driver 2010-10-27 11:38:25 +00:00
494661c0e7 sscanf removed from %s 2010-10-27 11:36:07 +00:00
5b652abd25 re-work separator parsing. Now first byte of separator is replaced with a 0x00 byte to allow e.g. simple %s parsing for an element (instead of e.g. %[^,] ) 2010-10-20 13:23:50 +00:00
a3e68d7f7d ugly goto removed 2010-10-20 13:21:28 +00:00
7cc19d2614 allow for negative length (meaning left of start) in expand 2010-10-20 13:21:05 +00:00
318d0e389b changed from scanf to strto* for parsing 2010-10-15 09:47:21 +00:00
8dbe3abcdb sscans removed from integer and double scanning because of bad performance 2010-10-15 09:46:30 +00:00
649d775cd3 Preset buffer size removed (It was not the performance killer)
Bugfix: InTerminator search: distinguisch between long input line and multi-line input
StreamBuffer::equals renamed to startswith
2010-10-14 12:18:48 +00:00
a941061a29 StreamBuffer::equals renamed to startswith 2010-10-14 12:16:27 +00:00
100b7d4543 bugfix: reserve returned wrong pointer
optimized implementation to append 1 char
operator += aliases for append with 1 argument
equals renamed to startswith
2010-10-14 12:15:44 +00:00
1eb8a25432 bugfix: local buffer was not set to 0 at initialization 2010-10-14 12:13:51 +00:00
9b6f8b3386 test empty string enum choice 2010-10-12 08:49:53 +00:00
cc1bb004f2 allow SLS style module loading 2010-10-12 08:49:17 +00:00
ab6a6b730d %f default precision changed to 6 because of limited precision of a double. 2010-10-12 08:47:08 +00:00
3d928c49a0 Performance bug fixed: search for terminator was O(n^2) 2010-10-12 08:33:35 +00:00
8fe70f2e39 errlog.h required for epics 3.14.11 2010-10-12 08:32:14 +00:00
862686aeef made grow() public to allow to set initial buffer size 2010-09-29 07:21:44 +00:00
2fa54cdfb1 Initial buffer size added 2010-09-29 07:21:14 +00:00
d987a9abb9 crc16 xmodem added 2010-09-22 12:05:26 +00:00
d37c142d36 copy from other repository 2010-09-02 14:52:17 +00:00
35768cbfbb latest features added and bugs fixed:
compare %=
timestamp converter %T
error and debug messages
2010-09-02 14:50:33 +00:00
5494aae1ba have both, makebaseapp Makefile and PSI makefile 2010-09-02 14:19:11 +00:00
18ba904d6c timestamp converter added 2010-09-02 13:20:04 +00:00
2cd969d643 allow assigned enums: %#{one=1|two|neg=-1} 2010-06-09 13:12:00 +00:00
0c9d4dc4c0 %m format renamed from Exponential to MantissaExponent 2010-06-09 08:11:05 +00:00
ef3b2ec9fd allow formats in exec 2010-06-09 08:10:33 +00:00
1fb402e838 Allow optional input %? format 2010-06-09 08:05:05 +00:00
eae987e7f1 Find byte order at run-time because there is no standard how to do this at compile-time. 2010-06-09 08:03:49 +00:00
93906dd022 Bugfix: prec too long had corrupted output 2010-06-09 08:02:22 +00:00
7e717c564d *** empty log message *** 2010-06-09 08:01:03 +00:00
14b60c210a renamed %m from Exponention to MantissaExponent 2010-06-09 08:00:08 +00:00
8dae0afa30 take care of early input (race condition device reply and start of in command) 2010-06-09 07:54:47 +00:00
95bf2c78c2 install headers to allow plugins (formats) in other projects 2010-06-09 07:44:51 +00:00
8c10e5395c Initial Import 2009-05-20 10:12:59 +00:00
69de0b9f31 bugfix: find() did not find 1 char strings 2008-09-16 07:29:26 +00:00
22ae510dca comments fixed 2008-09-16 07:28:47 +00:00
5fdf3912c8 avoid compiler warning on 64 bit machines 2008-09-16 07:27:27 +00:00
b50aec424f increase minor version number 2008-09-16 07:26:41 +00:00
4a1033b6dc allow for 64 bit machines 2008-09-16 07:26:02 +00:00
68e178d41b Use long constant 1L to allow for 64 bit machines 2008-09-16 07:25:03 +00:00
e83ceda41c get rid of writeRaw for asyn 4.10 2008-09-16 07:24:24 +00:00
140 changed files with 9044 additions and 1400 deletions

5
MODULE Normal file
View File

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

View File

@ -1,65 +1,24 @@
include /ioc/tools/driver.makefile TOP = ..
EXCLUDE_VERSIONS = 3.13.2
PROJECT=stream2
BUILDCLASSES += Linux
#DOCUDIR = doc DIRS = src
streamApp_DEPEND_DIRS = src
DBDS = stream.dbd # Look if we have EPICS R3.13 or R3.14
ifeq ($(wildcard $(TOP)/configure),)
BUSSES += AsynDriver # EPICS R3.13
FORMATS += Enum include $(TOP)/config/CONFIG_APP
FORMATS += BCD CONFIG = $(TOP)/config
FORMATS += Raw
FORMATS += RawFloat
FORMATS += Binary
FORMATS += Checksum
FORMATS += Regexp
FORMATS += Exponential
RECORDTYPES += aai aao
RECORDTYPES += ao ai
RECORDTYPES += bo bi
RECORDTYPES += mbbo mbbi
RECORDTYPES += mbboDirect mbbiDirect
RECORDTYPES += longout longin
RECORDTYPES += stringout stringin
RECORDTYPES += waveform
SOURCES += $(RECORDTYPES:%=src/dev%Stream.c)
SOURCES += $(FORMATS:%=src/%Converter.cc)
SOURCES += $(BUSSES:%=src/%Interface.cc)
SOURCES += $(wildcard src/Stream*.cc)
SOURCES += src/StreamVersion.c
SOURCES_3.14 += src/devcalcoutStream.c
ifeq (${EPICS_BASETYPE},3.13)
USR_INCLUDES += -include $(INSTALL_INCLUDE)/compat3_13.h
endif
StreamCore.o: streamReferences
streamReferences:
@for i in $(BUSSES); \
do echo "extern void* ref_$${i}Interface;"; \
echo "void* p$$i = ref_$${i}Interface;"; \
done > $@
@for i in $(FORMATS); \
do echo "extern void* ref_$${i}Converter;"; \
echo "void* p$$i = ref_$${i}Converter;"; \
done >> $@
ifeq (${EPICS_BASETYPE},3.13)
stream.dbd:
@for r in $(RECORDTYPES); \
do echo "device($$r,INST_IO,dev$${r}Stream,\"stream\")"; \
done > $@
@echo "driver(stream)" >> $@
else else
stream.dbd: # EPICS R3.14
@for r in $(RECORDTYPES) calcout; \ include $(TOP)/configure/CONFIG
do echo "device($$r,INST_IO,dev$${r}Stream,\"stream\")"; \ ifneq ($(words $(CALC) $(SYNAPPS)), 0)
done > $@ # with synApps calc module (contains scalcout)
@echo "driver(stream)" >> $@ DIRS += srcSynApps
@echo "variable(streamDebug, int)" >> $@ srcSynApps_DEPEND_DIRS = src
@echo "registrar(streamRegistrar)" >> $@ streamApp_DEPEND_DIRS += srcSynApps
endif
endif endif
DIRS += streamApp
include $(CONFIG)/RULES_DIRS

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: aai Records</title> <title>StreamDevice: aai Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: aai Records</h1> <h1>StreamDevice: 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.
@ -123,6 +124,5 @@ the written or read value.
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: aao Records</title> <title>StreamDevice: aao Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: aao Records</h1> <h1>StreamDevice: 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.
@ -123,6 +124,5 @@ the written or read value.
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: ai Records</title> <title>StreamDevice: ai Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: ai Records</h1> <h1>StreamDevice: ai Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -38,6 +39,8 @@ written or read value.
definition. <em>StreamDevice</em> does not set it. For example, definition. <em>StreamDevice</em> does not set it. For example,
<code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code> <code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code>
(=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
on 64 bit machines.
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -76,6 +79,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: ao Records</title> <title>StreamDevice: ao Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: ao Records</h1> <h1>StreamDevice: ao Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -37,6 +38,8 @@ written or read value.
might be set in the record definition. <em>StreamDevice</em> does not set it. might be set in the record definition. <em>StreamDevice</em> does not set it.
For example, <code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code> For example, <code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code>
(=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
on 64 bit machines.
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -77,6 +80,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 868 B

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: bi Records</title> <title>StreamDevice: bi Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: bi Records</h1> <h1>StreamDevice: bi Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -72,6 +73,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: bo Records</title> <title>StreamDevice: bo Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: bo Records</h1> <h1>StreamDevice: bo Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -71,6 +72,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: Bus API</title> <title>StreamDevice: Bus API</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>Bus API</h1> <h1>Bus API</h1>
<a name="class"></a> <a name="class"></a>
@ -640,6 +641,5 @@ other request method like <code>writeRequest()</code>.
</p> </p>
<hr> <hr>
<p><small>Dirk Zimoch, 2007</small></p> <p><small>Dirk Zimoch, 2007</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: calcout Records</title> <title>StreamDevice: calcout Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: calcout Records</h1> <h1>StreamDevice: calcout Records</h1>
<p> <p>
@ -78,6 +79,5 @@ Different record fields are used for output and input. The variable
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: Using EPICS 3.13</title> <title>StreamDevice: Using EPICS 3.13</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Using EPICS 3.13</h1> <h1>StreamDevice: Using EPICS 3.13</h1>
<a name="pre"></a> <a name="pre"></a>
@ -219,6 +220,5 @@ asynSetOption ("PS1", 0, "stop", "1")
<hr> <hr>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

BIN
doc/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -3,18 +3,219 @@
<html> <html>
<head> <head>
<title>StreamDevice: Format Converter API</title> <title>StreamDevice: Format Converter API</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Format Converter API</h1> <h1>StreamDevice: Format Converter API</h1>
<h2>Sorry, this documentation is still missing.</h2> <a name="class"></a>
<h2>Converter Class</h2>
<p>
A user defined converter class inherits public from
<i>StreamFormatConverter</i> and handles one or more conversion characters.
It is not necessary that a given conversion character supports both,
printing and scanning.
But if it does, both must be handled by the same converter class.
</p>
<p>
Any conversion corresponds to one data type. The converter class must
implement print and/or scan methods for this data type. It must also
implement a parse method to analyse the format string.
</p>
<p>
A converter class must be registered with a call to RegisterConverter()
in the global file context.
</p>
<p>
The converter must not contain any class variables, because there will be
only one global instance for each conversion character - not one for each
format string!
</p>
<h3>Example: LONG converter for <code>%Q</code></h3>
<pre>
#include "StreamFormatConverter.h"
class MyConverter : public StreamFormatConverter
{
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printLong(const StreamFormat&, StreamBuffer&, long);
int scanLong(const StreamFormat&, const char*, long&);
};
RegisterConverter(MyConverter,"Q");
// ... (implementation)
</pre>
<a name="theory"></a>
<h2>Theroy of Operation</h2>
<a name="registration"></a>
<h3>Registration </h3>
<div class="indent"><code>
RegisterConverter(<i>converterClass</i>, "<i>characters</i>");
</code></div>
<p>
This macro registers the converter class for all given conversion
characters. In most cases, you will give only one character.
The macro must be called once for each class in the global file context.
</p>
<p>
HINT: Do not branch depending on the conversion character.
Provide multiple classes, that's more efficient.
</p>
<a name="parsing"></a>
<h3>Parsing</h3>
<div class="indent"><code>
int parse (const&nbsp;StreamFormat&&nbsp;fmt, StreamBuffer&&nbsp;info,
const&nbsp;char*&&nbsp;source, bool&nbsp;scanFormat);
</code></div>
<div class="indent"><code>
struct&nbsp;StreamFormat {
char&nbsp;conv;
StreamFormatType&nbsp;type;
unsigned&nbsp;char&nbsp;flags;
short&nbsp;prec;
unsigned&nbsp;short&nbsp;width;
unsigned&nbsp;short&nbsp;infolen;
const&nbsp;char*&nbsp;info;
};
</code></div>
<p>
During initialization, <code>parse()</code> is called whenever one of the
conversion characters handled by your converter class is found in a protocol.
The fields <code>fmt.conv</code>, <code>fmt.flags</code>,
<code>fmt.prec</code>, and <code>fmt.width</code> have
already been filled in. If a scan format is parsed, <code>scanFormat</code>
is <code>true</code>. If a print format is parsed, <code>scanFormat</code>
is <code>false</code>.
</p>
<p>
The <code>fmt.flags</code> field is a bitset and can have any of the following
flags set:
</p>
<ul>
<li><code>left_flag</code>: the format contained a <code>-</code>.
This is normaly used to indicate that the value should be printed
left-aligned.
</li>
<li><code>sign_flag</code>: the format contained a <code>+</code>.
This normaly requests to print a sign even for positive numbers.
</li>
<li><code>space_flag</code>: the format contained a '<code>&nbsp;</code>' (space).
This normaly requests to print a space instead of a sign for positive numbers.
</li>
<li><code>alt_flag</code>: the format contained a <code>#</code>.
This indicated the request to use an alternative format. For example in
<code>%#x</code> the hex number is preficed with <code>0x</code>.
</li>
<li><code>zero_flag</code>: the format contained a <code>0</code>.
This normaly requests to pad a numerical value with leading zeros
instead of leading spaces.
<li><code>skip_flag</code>: the format contained a <code>*</code>.
The value is parsed and checked but then discarded.
</ul>
<p>
It is not necessary that these flags have exactly the same meaning in your
formats, but a similar and intuitive meaning helpful for the user.
</p>
<p>
There are two additional flags, <code>default_flag</code> indicating a
<code>?</code> and <code>compare_flag</code> indicating a <code>=</code>
int the format, that are handled internally by <em>StreamDevice</em> and
are not of interest to the converter class.
</p>
<p>
The <code>source</code> pointer points to the character of the format string
just after the conversion character. You can parse additional characters if
they belong to the format string handled by your class.
Move the <code>source</code> pointer so that is points to the first character
after your format string.
This is done for example in the builtin formats
<code>%[charset]</code> or <code>%{enum0|enum1}</code>.
However, many formats don't need additional characters.
</p>
<h4>Example</h4>
<pre>
source source
before after
parse() parse()
| |
"%39[0-9a-zA-Z]constant text"
|
conversion
character
</pre>
<p>
You can write any data you may need later in <code>print*()</code> or
<code>scan*()</code> to the
<a href="streambuffer.html"><i>Streambuffer</i></a> <code>info</code>.
This will probably be necessary if you have parsed additional characters
from the format string as in the above example<br>
</p>
<p>
Return <code>long_format</code>, <em>double_format</em>,
<em>string_format</em>, or <code>enum_format</code> depending on the
datatype associated with the conversion character.
It is not necessary to return the same value for print and for scan
formats.
You can even return different values depending on the format string,
but I can't imagine why anyone should do that.
</p>
<p>
If the format is not a real data conversion but does other things with
the data (append or check a checksum, encode or decode the data,...),
return <code>pseudo_format</code>.
</p>
<p>
Return <code>false</code> if there is any parse error or if print or scan
is requested but not supported by this conversion.
</p>
<a name="printing_scanning"></a>
<h3>Printing and Scanning</h3>
<p>
Provide a <code>print[Long|Double|String|Pseudo]()</code> and/or
<code>scan[Long|Double|String|Pseudo]()</code> method appropriate
for the data type you have returned in the <code>parse()</code> method.
That method is called whenever the conversion appears in an output or input,
respectively.
You only need to implement the flavour of print and/or scan suitable for
the datatype returned by <code>parse()</code>.
</p>
<p>
Now, <code>fmt.type</code> contains the value returned by <code>parse()</code>.
With <code>fmt.info()</code> get access to the string you have written to
<code>info</code> in <code>parse()</code> (null terminated).
</p>
<p>
The length of the info string can be found in <code>fmt.infolen</code>.
</p>
<p>
In <code>print*()</code>, append the converted value to <code>output</code>.
Do not modify what is already in output (unless you really know what you're
doing).
Return <code>true</code> on success, <code>false</code> on failure.
</p>
<p>
In <code>scan*()</code>, read the value from input and return the number of
consumed bytes.
In the string version, don't write more bytes than <code>maxlen</code>!
If the <code>skip_flag</code> is set, you don't need to write to
<code>value</code>, since the value will be discarded anyway.
Return <code>-1</code> on failure.
</p>
<hr> <hr>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2007</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: Format Converters</title> <title>StreamDevice: Format Converters</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Format Converters</h1> <h1>StreamDevice: Format Converters</h1>
<a name="syntax"></a> <a name="syntax"></a>
@ -27,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 name in <code>()</code></li> <li>Optionally a field <span class="new">or record</span> name in <code>()</code></li>
<li>Optionally flags out of the characters <code>*# +0-</code></li> <li>Optionally flags out of the characters <code>*# +0-<span class="new">?=</span></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>
@ -36,6 +37,11 @@ A format converter consists of
<li>Additional information required by some converters</li> <li>Additional information required by some converters</li>
</ul> </ul>
<p>
The flags <code>*# +0-</code> work like in the C functions
<em>printf()</em> and <em>scanf()</em>.
The flags <code>?</code> and <code>=</code> are extensions.
</p>
<p> <p>
The <code>*</code> flag skips data in input formats. The <code>*</code> flag skips data in input formats.
Input is consumed and parsed, a mismatch is an error, but the read Input is consumed and parsed, a mismatch is an error, but the read
@ -61,6 +67,16 @@ 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">
The <code>?</code> flag makes failing input conversions succeed with
a default zero value (0, 0.0, or "", depending on the format type).
</p>
<p class="new">
The <code>=</code> flag allows to compare input with current values.
It is only allowed in input formats.
Instead of reading a new value from input, the current value is
formatted (like for output) and then compared to the input.
</p>
<h3>Examples:</h3> <h3>Examples:</h3>
<table> <table>
@ -84,6 +100,14 @@ The <code>-</code> flag specifies that output is left justified if
<td><code>in "%*i";</code></td> <td><code>in "%*i";</code></td>
<td>skipped integer number</td> <td>skipped integer number</td>
</tr> </tr>
<tr>
<td><code>in "%?d";</code></td>
<td>decimal number or nothing (read as 0)</td>
</tr>
<tr>
<td><code>in "%=.3f";</code></td>
<td>compare input to the current value formatted as a float with precision 3</td>
</tr>
</table> </table>
<a name="types"></a> <a name="types"></a>
@ -108,18 +132,24 @@ 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>
<h3>Accessing record fields directly</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
same IOC for the conversion, write the field name in parentheses directly same IOC for the conversion, write the field name in parentheses directly
after the <code>%</code>. after the <code>%</code>.
For example <code>out&nbsp;"%(EGU)s";</code> outputs the <code>EGU</code> For example <code>out&nbsp;"%(EGU)s";</code> outputs the <code>EGU</code>
field formatted as a string. field formatted as a string.
Use <code>in&nbsp;"%(<i>otherrecord</i>.VAL)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>VAL</code> field of point input value into the <code>RVAL</code> field of
<code><i>otherrecord</i></code>. <code><i>otherrecord</i></code>.
(You can't skip <code>.VAL</code> here.) <span class="new">
This is very useful when one line of input contains many values that should If no field is given for an other record .VAL is assumed.
When a record name conflicts with a field name use .VAL explicitly.
</span>
</p>
<p>
This feature is very useful when one line of input contains many values that should
be distributed to many records. be distributed to many records.
If <code><i>otherrecord</i></code> is passive and the field has the PP If <code><i>otherrecord</i></code> is passive and the field has the PP
attribute (see attribute (see
@ -129,6 +159,8 @@ 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.
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
state when anything fails.
</p> </p>
<h3>Pseudo-converters</h3> <h3>Pseudo-converters</h3>
@ -144,31 +176,42 @@ No data type corresponds to those <em>pseudo-converters</em> and the
<h2>3. Standard DOUBLE Converters (<code>%f</code>, <code>%e</code>, <h2>3. Standard DOUBLE Converters (<code>%f</code>, <code>%e</code>,
<code>%E</code>, <code>%g</code>, <code>%G</code>)</h2> <code>%E</code>, <code>%g</code>, <code>%G</code>)</h2>
<p> <p>
In output, <code>%f</code> prints fixed point, <code>%e</code> prints <b>Output:</b> <code>%f</code> prints fixed point, <code>%e</code> prints
exponential notation and <code>%g</code> prints either fixed point or exponential notation and <code>%g</code> prints either fixed point or
exponential depending on the magnitude of the value. exponential depending on the magnitude of the value.
<code>%E</code> and <code>%G</code> use <code>E</code> instead of <code>%E</code> and <code>%G</code> use <code>E</code> instead of
<code>e</code> to separate the exponent. <code>e</code> to separate the exponent.
</p>
<p>
With the <code>#</code> flag, output always contains a period character. With the <code>#</code> flag, output always contains a period character.
</p> </p>
<p> <p>
In input, all these formats are equivalent. <b>Input:</b> All these formats are equivalent. Leading whitespaces are skipped.
Leading whitespaces are skipped. </p>
<p class="new">
With the <code>#</code> flag additional whitespace between sign and number
is accepted.
</p>
<p class="new">
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is given.
</p> </p>
<a name="stdl"></a> <a name="stdl"></a>
<h2>4. Standard LONG Converters (<code>%d</code>, <code>%i</code>, <h2>4. Standard LONG Converters (<code>%d</code>, <code>%i</code>,
<code>%u</code>, <code>%o</code>, <code>%x</code>, <code>%X</code>)</h2> <code>%u</code>, <code>%o</code>, <code>%x</code>, <code>%X</code>)</h2>
<p> <p>
In output, <code>%d</code> and <code>%i</code> print signed decimal, <b>Output</b>: <code>%d</code> and <code>%i</code> print signed decimal,
<code>%u</code> unsigned decimal, <code>%o</code> unsigned octal, and <code>%u</code> unsigned decimal, <code>%o</code> unsigned octal, and
<code>%x</code> or <code>%X</code> unsigned hexadecimal. <code>%x</code> or <code>%X</code> unsigned hexadecimal.
<code>%X</code> uses upper case letters. <code>%X</code> uses upper case letters.
</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> </p>
<p> <p>
In input, <code>%d</code> matches signed decimal, <code>%u</code> matches <b>Input:</b> <code>%d</code> matches signed decimal, <code>%u</code> matches
unsigned decimal, <code>%o</code> unsigned octal. unsigned decimal, <code>%o</code> unsigned octal.
<code>%x</code> and <code>%X</code> both match upper or lower case unsigned <code>%x</code> and <code>%X</code> both match upper or lower case unsigned
hexadecimal. hexadecimal.
@ -177,23 +220,40 @@ 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">
With the <code>-</code> negative octal and hexadecimal values are accepted.
</p>
<p class="new">
With the <code>#</code> flag additional whitespace between sign and number
is accepted.
</p>
<p class="new">
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is given.
</p>
<a name="stds"></a> <a name="stds"></a>
<h2>5. Standard STRING Converters (<code>%s</code>, <code>%c</code>)</h2> <h2>5. Standard STRING Converters (<code>%s</code>, <code>%c</code>)</h2>
<p> <p>
In output, <code>%s</code> prints a string. <b>Output:</b> <code>%s</code> prints a string.
If <em>precision</em> is specified, this is the maximum string length. If <em>precision</em> is specified, this is the maximum string length.
<code>%c</code> is a LONG format in output, printing one character! <code>%c</code> is a LONG format in output, printing one character!
</p> </p>
<p> <p>
In input, <code>%s</code> matches a sequence of non-whitespace characters <b>Input:</b> <code>%s</code> matches a sequence of non-whitespace characters
and <code>%c</code> a sequence of not-null characters. 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> but not with Leading whitespaces are skipped with <code>%s</code>
<code>%c</code>. <span class="new">
The empty string matches. except when the space flag is given</span>
but not with <code>%c</code>.
The empty string matches.
</p>
<p class="new">
With the <code>#</code> flag <code>%s</code> matches a sequence of not-null
characters instead of non-whitespace characters.
</p> </p>
<a name="cset"></a> <a name="cset"></a>
@ -217,14 +277,24 @@ to <code>z</code>.
This format maps an unsigned integer value on a set of strings. This format maps an unsigned integer value on a set of strings.
The value 0 corresponds to <em>string0</em> and so on. The value 0 corresponds to <em>string0</em> and so on.
The strings are separated by <code>|</code>. The strings are separated by <code>|</code>.
If one of the strings contains <code>|</code> or <code>}</code>,
a <code>\</code> must be used to escape the character.
</p> </p>
<p> <p>
Example: <code>%{OFF|STANDBY|ON}</code> mapps the string <code>OFF</code> Example: <code>%{OFF|STANDBY|ON}</code> mapps the string <code>OFF</code>
to the value 0, <code>STANDBY</code> to 1 and <code>ON</code> to 2. to the value 0, <code>STANDBY</code> to 1 and <code>ON</code> to 2.
</p> </p>
<p> <p>
When using the <code>#</code> flag it is allowed to assign integer values
to the strings using <code>=</code>.
</p>
<p>
Example: <code>%#{neg=-1|stop=0|pos=1|fast=10}</code>.
</p>
<p>
If one of the strings contains <code>|</code> or <code>}</code>
(or <code>=</code> if the <code>#</code> flag is used)
a <code>\</code> must be used to escape the character.
</p>
<p>
In output, depending on the value, one of the strings is printed. In output, depending on the value, one of the strings is printed.
</p> </p>
<p> <p>
@ -248,12 +318,11 @@ Examples: <code>%B.!</code> or <code>%B\x00\xff</code>.
<code>%B01</code> is equivalent to <code>%b</code>. <code>%B01</code> is equivalent to <code>%b</code>.
</p> </p>
<p> <p>
If in output <em>width</em> is larger than the number of significant bits, In output, if <em>width</em> is larger than the number of significant bits,
then the flag <code>0</code> means that the value should be padded with then the flag <code>0</code> means that the value should be padded with
with the chosen zero character instead of spaces. with the chosen zero character instead of spaces.
If <em>precision</em> is set, it means the number of significant bits. If <em>precision</em> is set, it means the number of significant bits.
Otherwise, the highest 1 bit defines the number of significant bits. Otherwise, the highest 1 bit defines the number of significant bits.
There is no alternate format when <code>#</code> is used.
</p> </p>
<p> <p>
In input, leading spaces are skipped. In input, leading spaces are skipped.
@ -275,11 +344,9 @@ 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>width</em> least significant bytes of the value In output, the <em>prec</em> (or sizeof(long) whatever is less) least
are written. significant bytes of the value are sign extended or zero extended
If <em>width</em> is larger than the size of a <code>long</code>, (depending on the <code>0</code> flag) to <em>width</em> bytes.
the value is sign extended or zero extended, depending on the
<code>0</code> flag.
</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.
@ -289,9 +356,25 @@ If <em>width</em> is smaller than the size of a <code>long</code>,
the value is sign extended or zero extended, depending on the the value is sign extended or zero extended, depending on the
<code>0</code> flag. <code>0</code> flag.
</p> </p>
<p>
Example: <code>out "%.2r"</code>
</p>
<a name="rawdouble"></a>
<h2>10. Raw DOUBLE Converter (<code>%R</code>)</h2>
<p>
The raw converter does not really "convert".
A float or double value is written or read in the internal
(maybe IEEE) representation of the computer.
The normal byte order is <em>big endian</em>, i.e. most significant byte
first.
With the <code>#</code> flag, the byte order is changed to <em>little
endian</em>, i.e. least significant byte first.
The <em>width</em> must be 4 (float) or 8 (double). The default is 4.
</p>
<a name="bcd"></a> <a name="bcd"></a>
<h2>10. Packed BCD (Binary Coded Decimal) LONG Converter (<code>%D</code>)</h2> <h2>11. Packed BCD (Binary Coded Decimal) LONG Converter (<code>%D</code>)</h2>
<p> <p>
Packed BCD is a format where each byte contains two binary coded Packed BCD is a format where each byte contains two binary coded
decimal digits (<code>0</code> ... <code>9</code>). decimal digits (<code>0</code> ... <code>9</code>).
@ -320,7 +403,7 @@ than 9.
</p> </p>
<a name="chksum"></a> <a name="chksum"></a>
<h2>11. Checksum Pseudo-Converter (<code>%&lt;<em>checksum</em>&gt;</code>)</h2> <h2>12. Checksum Pseudo-Converter (<code>%&lt;<em>checksum</em>&gt;</code>)</h2>
<p> <p>
This is not a normal "converter", because no user data is converted. This is not a normal "converter", because no user data is converted.
Instead, a checksum is calculated from the input or output. Instead, a checksum is calculated from the input or output.
@ -399,6 +482,9 @@ In input, the next byte or bytes must match the checksum.
href="http://www.joegeluso.com/software/articles/ccitt.htm">correct?</a>) href="http://www.joegeluso.com/software/articles/ccitt.htm">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>
<dd>Two bytes. The XMODEM checksum.
(poly=0x1021, init=0x0000, xorout=0x0000).</dd>
<dt><code>%&lt;crc32&gt;</code></dt> <dt><code>%&lt;crc32&gt;</code></dt>
<dd>Four bytes. The standard 32 bit crc checksum. <dd>Four bytes. The standard 32 bit crc checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd> (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd>
@ -450,7 +536,7 @@ If <em>prec</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> is must be escaped. If the expression contains a <code>/</code> it must be escaped.
</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
@ -458,23 +544,82 @@ 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="exp"></a> <a name="mantexp"></a>
<h2>13. Exponential DOUBLE converter (<code>%m</code>)</h2> <h2>13. MantissaExponent DOUBLE converter (<code>%m</code>)</h2>
<p> <p>
This experimental input-only 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
123e-4 or 0.0123. Mantissa and exponent are integers. The sign of the 123e-4 or 0.0123. Mantissa and exponent are decimal integers.
mantissa is optional. Compared to the standard <code>%e</code> format, The sign of the mantissa is optional.
this format does not contain the characters <code>.</code> and <code>e</code>. Compared to the standard <code>%e</code> format, this format does not
contain the characters <code>.</code> and <code>e</code>.
</p> </p>
<p> <p>
Output formatting is ambigous (e.g. <code>123-4</code> versus Output formatting is ambigous (e.g. <code>123-4</code> versus
<code>1230-5</code>). Until it has been specified how to handle this, <code>1230-5</code>). I chose the following convention:
output is not supported. Format <em>precision</em> defines number of digits in mantissa.
No leading '0' in mantissa (except for 0.0 of course).
Number of digits in exponent is at least 2.
Format flags <code>+</code>, <code>-</code>, and space are supported in
the usual way (always sign, left justified, space instead of + sign).
Flags <code>#</code> and <code>0</code> are unsupported.
</p> </p>
<div class="new">
<a name="timestamp"></a>
<h2>14. Timestamp DOUBLE converter (<code>%T(<em>timeformat</em>)</code>)</h2>
<p>
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 precision of a double is large enough for microseconds (but not for
nanoseconds). This format is probably used best in combination with a
redirection to the <code>TIME</code> field. In this case, the value is
converted to EPICS timestamps (seconds since 1990 and nanoseconds).
The timestamp format understands the usual converters that the C function
<em>strftime()</em> understands. In addition, fractions of a second can
be specified and the time zone can be set in the format string.
</p>
<p>
Example: <code>%(TIME)T(%d %b %Y %H:%M:%.3S %z)</code> may print something like
<code> 3 Sep 2010 15:45:59 +0200</code>.
</p>
<p>
Fractions of a second can be specified as <code>%.<em>n</em>S</code>
(seconds with <em>n</em> fractional digits), as <code>%0<em>n</em>f</code>
or <code>%<em>n</em>f</code> (<em>n</em> fractional digits) or as
<code>%N</code> (nanoseconds).
In input, <em>n</em> is the maximum number of digits parsed, there may be
actually less digits in the input.
If <em>n</em> is not specified (<code>%.S</code> or <code>%f</code>) it uses
a default value of 6.
</p>
<p>
In input, the time zone can be specified in the format like
<code>%+<em>hhmm</em></code> or <code>%-<em>hhmm</em></code> for cases
where the parsed time stamp does not specify the time zone, where
<em>hhmm</em> is a 4 digit number specifying the offset in hours and minutes.
</p>
<p>
In output, the system function <em>strftime()</em> is used to format the time.
There may be differences in the implementation between operating systems.
</p>
<p>
In input, <em>StreamDevice</em> used its own implementation because many
systems are missing the <em>strptime()</em> function and additional formats
are supported.
</p>
<p>
Day of the week can be parsed but is ignored because the information is
redundant when used together with day, month and year and more or less
useless otherwise. No check is done for consistency.
</p>
<p>
Because of the complexity of the problem, locales are not supported.
Thus, only the English month names can be used (week day names are
ignored anyway).
</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, 2007</small></p> <p><small>Dirk Zimoch, 2011</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -1,32 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Headbar</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch">
<style type="text/css">
<!--
body {margin:0px 0px 0px 0px;}
big {font-size: 30px; font-family:serif;}
-->
</style>
</head>
<body bgcolor="white">
<table cellspacing=0 cellpadding=0 border=0 width="100%">
<tr><td bgcolor="#267ab8" colspan=6 valign="bottom" height=9 width="100%"></td></tr>
<tr><td bgcolor="#000000" colspan=6 valign="bottom" height=1 width="100%"></td></tr>
<tr>
<td><img src="space.gif" width=180 height=1 alt=""><center><a href="http://www.psi.ch" target="ex"><img src="PSI.gif" width=150 height=55 alt="PSI" border=0></a></center></td>
<td><img src="space.gif" width=1 height=65 alt=""></td>
<td><a href="http://www.aps.anl.gov/epics" target="ex"><img
src="EPICS.gif" border=0 width=50 height=50 alt="EPICS"></a></td>
<td width="100%" align="center" nowrap>
<big><b><em id="subtitle">StreamDevice</em></b></big></td>
<td><img src="space.gif" width=166 height=1 alt=""><center><a href="http://sls.web.psi.ch/view.php/about/index.html" target="ex"><img src="SLS.gif" width=146 height=55 alt="SLS" border=0></a></center></td>
</tr>
<tr><td bgcolor="#267ab8" colspan=6 valign="bottom" height=4 width="100%"></td></tr>
<tr><td bgcolor="#000000" colspan=6 valign="bottom" height=1 width="100%"></td></tr>
</table>
</body>
</html>

View File

@ -1,20 +1,116 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/frameset.dtd"> "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>
<head> <head>
<title>StreamDevice Documentation</title> <title>StreamDevice</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<frameset rows="80,*" framespacing=0 frameborder=0 border=0> <body>
<frame src="head.html" name="head" scrolling="no" noresize> <iframe src="nav.html" id="navleft"></iframe>
<frameset cols="180,*" > <h1>EPICS <em>StreamDevice</em></h1>
<frame src="nav.html" name="nav" noresize>
<frame src="stream.html" name="text"> <h2>What is <em>StreamDevice</em>?</h2>
</frameset> <p>
<noframes> <em>StreamDevice</em> is a generic
<a href="stream.html">Click here for no-frames version.</a> <a href="http://www.aps.anl.gov/epics" target="ex">EPICS</a>
</noframes> device support for devices with a "byte stream" based
</frameset> communication interface.
That means devices that can be controlled by sending and
receiving strings (in the broadest sense, including non-printable
characters and even null-bytes).
Examples for this type of communication interface are
serial line (RS-232, RS-485, ...),
IEEE-488 (also known as GPIB or HP-IB), and telnet-like TCP/IP.
</p>
<p>
<em>StreamDevice</em> is not limited to a specific device type or
manufacturer nor is it necessary to re-compile anything to support a
new device type.
Instead, it can be configured for any device type with
<a href="protocol.html"><em>protocol files</em></a> in plain ASCII text
which describes the commands a device understands and the replies it sends.
If the device can be controlled with strings like
"<kbd>RF:FREQ 499.655 MHZ</kbd>" <em>StreamDevice</em> can be used.
Formatting and parsing of values is done with
<a href="formats.html"><em>format converters</em></a> similar to those
known from the C functions <em>printf()</em> and <em>scanf()</em>.
To support other formats, it is possible to
<a href="formatconverter.html">write your own converters</a>.
</p>
<p>
Each record with <em>StreamDevice</em> support runs one protocol
from the protocol file to read or write its value.
Protocols can be as simple as just one output string or can
consist of many strings sent to and read from the device.
However, a protocol is linear.
That means it runs from start to end each time the record is
<a href="processing.html">processed</a>.
It does not provide loops or branches.
</p>
<p>
<em>StreamDevice</em> comes with an interface to<a target="ex"
href="http://www.aps.anl.gov/epics/modules/soft/asyn/">
<em>asynDriver</em></a>
but can be extended to
<a href="businterface.html">support other bus drivers</a>.
Note that <em>StreamDevice</em> is not an alternative or replacement
but a supplement for <em>asynDriver</em>.
<em>StreamDevice</em> converts record values to and from strings but
leaves it to <em>asynDriver</em> (or other bus interfaces) to exchange
these strings with the device.
Thus any bus type supported by <em>asynDriver</em> (to be exact by
<em>asynOctet</em>) can automatically be used with <em>StreamDevice</em>.
</p>
<p>
<em>StreamDevice</em> supports all
<a href="recordtypes.html">standard records</a> of EPICS base
which can have device support.
It is also possible to
<a href="recordinterface.html">write support for new record types</a>.
</p>
<h2>What is <em>StreamDevice</em> not?</h2>
<p>
It is not a programming language for a high-level application.
It is, for example, not possible to write a complete scanning program
in a protocol.
Use other tools for that and use <em>StreamDevice</em> only for the
primitive commands.
</p>
<p>
It is not a block oriented device support.
It is not possible to send or receive huge blocks of data that contain
many process variables distributed over many records.
</p>
<h2>Recommended Readings</h2>
<p>
<a href="http://www.aps.anl.gov/epics/base/R3-14/8-docs/AppDevGuide.pdf"
target="ex">IOC Application Developer's Guide (PDF)</a>
</p>
<p>
<a href="http://www.aps.anl.gov/asd/controls/epics/EpicsDocumentation/AppDevManuals/RecordRef/Recordref-1.html"
target="ex">EPICS Record Reference Manual</a>
</p>
<h2>Color and Style Conventions</h2>
<p>
In this document, code is witten in <code>green fixed width font</code>.
This marks text you typically type in configuration files etc.
</p>
<pre>
Longer code segments are often set in a box.
</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>
<p align="right"><a href="setup.html">Next: Setup</a></p>
<p><small>Dirk Zimoch, 2011</small></p>
</body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: longin Records</title> <title>StreamDevice: longin Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: longin Records</h1> <h1>StreamDevice: longin Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -25,6 +26,8 @@ written or read value.
<dd> <dd>
<u>Output:</u> <code><i>x</i>=VAL</code><br> <u>Output:</u> <code><i>x</i>=VAL</code><br>
<u>Input:</u> <code>VAL=<i>x</i></code> <u>Input:</u> <code>VAL=<i>x</i></code>
Using unsigned formats with values &ge; 0x800000 gives different results
on 64 bit machines.
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -63,6 +66,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: longout Records</title> <title>StreamDevice: longout Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: longout Records</h1> <h1>StreamDevice: longout Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -25,6 +26,8 @@ written or read value.
<dd> <dd>
<u>Output:</u> <code><i>x</i>=VAL</code><br> <u>Output:</u> <code><i>x</i>=VAL</code><br>
<u>Input:</u> <code>VAL=<i>x</i></code> <u>Input:</u> <code>VAL=<i>x</i></code>
Using unsigned formats with values &ge; 0x800000 gives different results
on 64 bit machines.
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -63,6 +66,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: mbbi Records</title> <title>StreamDevice: mbbi Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbbi Records</h1> <h1>StreamDevice: mbbi Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -89,6 +90,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: mbbiDirect Records</title> <title>StreamDevice: mbbiDirect Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbbiDirect Records</h1> <h1>StreamDevice: mbbiDirect Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -75,6 +76,5 @@ written or read value.
<a href="scalcout.html">calcout</a> <a href="scalcout.html">calcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: mbbo Records</title> <title>StreamDevice: mbbo Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbbo Records</h1> <h1>StreamDevice: mbbo Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -90,6 +91,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: mbboDirect Records</title> <title>StreamDevice: mbboDirect Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: mbboDirect Records</h1> <h1>StreamDevice: mbboDirect Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -77,6 +78,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -5,216 +5,209 @@
<title>Navbar</title> <title>Navbar</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
<script type="text/javascript">
<!--
active="";
function show(name) {
var m = document.getElementById(name);
var b = document.getElementById(name+"Button");
if (active != "") { hide(active); }
m.style.display = "block";
b.innerHTML="[&laquo;]";
b.href="javascript:hide(\'"+name+"\')"
active=name;
}
function hide(name) {
var m = document.getElementById(name);
var b = document.getElementById(name+"Button");
m.style.display = "none";
b.innerHTML="[&raquo;]";
b.href="javascript:show(\'"+name+"\')"
active="";
}
function printview() {
w = window.open(parent.text.location, "_parent", "dependent=yes,width=800,menubar=yes,toolbar=yes,location=yes");
}
-->
</script>
<style type="text/css"> <style type="text/css">
<!-- <!--
body {margin:0px 0px 0px 0px; body {margin:0 0 13ex 1em;
font-family:sans-serif; font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight:bold; font-weight:bold;
font-size:13px;} font-size:13px;
background-color:#e3eaf6;}
a {text-decoration:none;} a {text-decoration:none;}
a:link {color:#333333;} a:link {color:#333333;}
a:visited {color:#333333;} a:visited {color:#333333;}
a:hover {color:#FF0000;} a:hover {color:#FF0000;}
a:active {color:#FF0000;} a:active {color:#FF0000;}
.top {margin-bottom: 0px;
margin-top: 10px;
border-bottom: solid 1px black;}
.top ul {margin-left: 5px;
margin-top: 2px;
margin-bottom: 2px;
font-size:95%;
line-height:120%;
padding-left:1em;}
.subsub {margin-left: 15px;
line-height:120%;
font-size:80%;}
h1 {font-size:120%; h1 {font-size:120%;
margin-top: 20px; margin-top: 20px;
margin-right: 20px; margin-right: 20px;
margin-bottom: 10px; margin-bottom: 10px;
color:#267ab8;} color:#267ab8;}
div {border-bottom:1px solid black;
padding-top:1ex;}
div div, div div div, div:hover div div
{
padding-top:0;
margin-right:.1em;
border:none;
box-shadow: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;
padding 0;
display:block;
position:relative;
}
div div
{display:none;
margin-left:2em;
margin-right:1em;
background-color:#e3eaf6;
padding:0 .5em .5ex .5em;
border-width:0 thick thick 1px;
border-color:black;
border-style:solid;
}
:root *> div div
{border-width:0 1px 1px 1px;
box-shadow: 5px 5px 5px black;
-moz-box-shadow: 5px 5px 5px black;
-webkit-box-shadow: 5px 5px 5px black;
}
div:hover div {
position:absolute;
display:block;}
div div div {margin-left:0;}
a {display:block;
margin-top:.3ex;}
div div a {display:list-item;
margin-left:1em;
list-style-type:disc;
}
div div div a {list-style-type:circle;}
--> -->
</style> </style>
</head> </head>
<body background="bg.gif"> <body>
<p align="center"> <h1>User's Guide</h1>
</p> <div>
<div style="margin-left: 20px;"> <a target="_parent" href="index.html">Intro</a>
<h1>User's Guide</h1> </div>
<div class="top"> <div>
<a target="text" href="stream.html">Intro</a> <a target="_parent" href="setup.html">Setup</a>
</div> <a href="javascript:show('setup')" id="setupButton"></a>
<div class="top"> <div>
<a target="text" href="setup.html">Setup</a> <a target="_parent" href="setup.html#pre">Prerequisites</a>
<a href="javascript:show('setup')" id="setupButton"></a> <div>
<ul id="setup"> <a target="_parent" href="epics3_13.html">Using EPICS 3.13</a>
<li><a target="text" href="setup.html#pre">Prerequisites</a> </div>
<ul> <a target="_parent" href="setup.html#lib">Build Library</a>
<li><a target="text" href="epics3_13.html">Using EPICS 3.13</a></li> <a target="_parent" href="setup.html#app">Build Application</a>
</ul></li> <a target="_parent" href="setup.html#sta">Startup Script</a>
<li><a target="text" href="setup.html#lib">Build Library</a></li> <a target="_parent" href="setup.html#pro">Protocol File</a>
<li><a target="text" href="setup.html#app">Build Application</a></li> <div>
<li><a target="text" href="setup.html#sta">Startup Script</a></li> <a target="_parent" href="setup.html#reload">Reloading</a>
<li><a target="text" href="setup.html#pro">Protocol File</a> </div>
<ul> <a target="_parent" href="setup.html#rec">Records</a>
<li><a target="text" href="setup.html#reload">Reloading</a></li>
</ul></li>
<li><a target="text" href="setup.html#rec">Records</a></li>
</ul>
</div>
<div class="top">
<a target="text" href="protocol.html">Protocol Files</a>
<a href="javascript:show('protocol')" id="protocolButton"></a>
<ul id="protocol">
<li><a target="text" href="protocol.html#gen">General</a></li>
<li><a target="text" href="protocol.html#proto">Protocols</a></li>
<li><a target="text" href="protocol.html#cmd">Commands</a></li>
<li><a target="text" href="protocol.html#str">Strings</a></li>
<li><a target="text" href="protocol.html#var">Variables</a>
<ul>
<li><a target="text" href="protocol.html#sysvar">System variables</a></li>
<li><a target="text" href="protocol.html#argvar">Protocol Arguments</a></li>
<li><a target="text" href="protocol.html#usrvar">User variables</a></li>
</ul></li>
<li><a target="text" href="protocol.html#except">Exception Handlers</a></li>
</ul>
</div>
<div class="top">
<a target="text" href="formats.html">Format Converters</a>
<a href="javascript:show('formats')" id="formatsButton"></a>
<ul id="formats">
<li><a target="text" href="formats.html#syntax">Syntax</a></li>
<li><a target="text" href="formats.html#types">Types &amp; Fields</a></li>
<li><a target="text" href="formats.html#stdd">%f %e %g</a></li>
<li><a target="text" href="formats.html#stdl">%i %d %u %o %x</a></li>
<li><a target="text" href="formats.html#stds">%s %c</a></li>
<li><a target="text" href="formats.html#cset">%[<em>charset</em>]</a></li>
<li><a target="text" href="formats.html#enum">%{<em>s0</em>|<em>s1</em>|...}</a></li>
<li><a target="text" href="formats.html#bin">%b %B</a></li>
<li><a target="text" href="formats.html#raw">%r</a></li>
<li><a target="text" href="formats.html#bcd">%D</a></li>
<li><a target="text" href="formats.html#chksum">%&lt;<em>checksum</em>&gt;</a></li>
<li><a target="text" href="formats.html#regex">%/<em>regex</em>/</a></li>
<li><a target="text" href="formats.html#exp">%m</a></li>
</ul>
</div>
<div class="top">
<a target="text" href="processing.html">Record Processing</a>
<a href="javascript:show('proc')" id="procButton"></a>
<ul id="proc">
<li><a target="text" href="processing.html#proc">Normal Processing</a></li>
<li><a target="text" href="processing.html#init">Initialization</a></li>
<li><a target="text" href="processing.html#iointr">I/O Intr</a></li>
</ul>
</div>
<div class="top">
<a target="text" href="recordtypes.html">Record Types</a>
<a href="javascript:show('records')" id="recordsButton"></a>
<ul id="records" class="sub">
<li><a target="text" href="aai.html">aai</a></li>
<li><a target="text" href="aao.html">aao</a></li>
<li><a target="text" href="ai.html">ai</a></li>
<li><a target="text" href="ao.html">ao</a></li>
<li><a target="text" href="bi.html">bi</a></li>
<li><a target="text" href="bo.html">bo</a></li>
<li><a target="text" href="mbbi.html">mbbi</a></li>
<li><a target="text" href="mbbo.html">mbbo</a></li>
<li><a target="text" href="mbbiDirect.html">mbbiDirect</a></li>
<li><a target="text" href="mbboDirect.html">mbboDirect</a></li>
<li><a target="text" href="stringin.html">stringin</a></li>
<li><a target="text" href="stringout.html">stringout</a></li>
<li><a target="text" href="longin.html">longin</a></li>
<li><a target="text" href="longout.html">longout</a></li>
<li><a target="text" href="waveform.html">waveform</a></li>
<li><a target="text" href="calcout.html">calcout</a></li>
<li><a target="text" href="scalcout.html">scalcout</a></li>
</ul>
</div>
<div class="top">
<a target="text" href="tipsandtricks.html">Tips &amp; Tricks</a>
<a href="javascript:show('tipsandtricks')" id="tipsandtricksButton"></a>
<ul id="tipsandtricks">
<li><a target="text" href="tipsandtricks.html#argvar">Many almost identical protocols</a></li>
<li><a target="text" href="tipsandtricks.html#iointr">Read unsolicited input</a></li>
<li><a target="text" href="tipsandtricks.html#multiline">Read multi-line messages</a></li>
<li><a target="text" href="tipsandtricks.html#writemany">Write more than one value in one message</a></li>
<li><a target="text" href="tipsandtricks.html#readmany">Read more than one value from one message</a></li>
<li><a target="text" href="tipsandtricks.html#mixed">Read values of mixed data type</a></li>
</ul>
</div>
<h1>Programmer's Guide</h1>
<div class="top">
<a target="text" href="recordinterface.html">Record API</a>
</div>
<div class="top">
<a target="text" href="businterface.html">Bus API</a>
<a href="javascript:show('bus')" id="busButton"></a>
<ul id="bus">
<li><a target="text" href="businterface.html#class">Interface Class</a></li>
<li><a target="text" href="businterface.html#theory">Theory of Operation</a>
<ul>
<li><a target="text" href="businterface.html#registration">Registration</a></li>
<li><a target="text" href="businterface.html#create">Creation &amp; deletion</a></li>
<li><a target="text" href="businterface.html#connect">Connecting</a></li>
<li><a target="text" href="businterface.html#lock">Bus locking</a></li>
<li><a target="text" href="businterface.html#write">Writing output</a></li>
<li><a target="text" href="businterface.html#read">Reading input</a></li>
<li><a target="text" href="businterface.html#event">Handling events</a></li>
</ul></li>
</ul>
</div>
<div class="top">
<a target="text" href="formatconverter.html">Format Converter API</a>
</div>
<div class="top">
<a target="text" href="osinterface.html">Operating System API</a>
</div> </div>
</div> </div>
<p align="center" style="margin-top:20px;"> <div>
<script type="text/javascript"> <a target="_parent" href="protocol.html">Protocol Files</a>
<!-- <a href="javascript:show('protocol')" id="protocolButton"></a>
document.writeln('<a href="javascript:printview()">' + <div>
'<img src="printer.gif" alt="Printer friendly" border=0><br>' + <a target="_parent" href="protocol.html#gen">General</a>
'<small>Printer friendly<\/small><\/a>'); <a target="_parent" href="protocol.html#proto">Protocols</a>
hide('setup'); <a target="_parent" href="protocol.html#cmd">Commands</a>
hide('protocol'); <a target="_parent" href="protocol.html#str">Strings</a>
hide('formats'); <a target="_parent" href="protocol.html#var">Variables</a>
hide('proc'); <div>
hide('records'); <a target="_parent" href="protocol.html#sysvar">System variables</a>
hide('bus'); <a target="_parent" href="protocol.html#argvar">Protocol Arguments</a>
hide('tipsandtricks'); <a target="_parent" href="protocol.html#usrvar">User variables</a>
chapter=decodeURIComponent(parent.location.search.substr(1)); </div>
if (chapter) parent.text.location.href=chapter; <a target="_parent" href="protocol.html#except">Exception Handlers</a>
//--> </div>
</script> </div>
</p> <div>
<a target="_parent" href="formats.html">Format Converters</a>
<a href="javascript:show('formats')" id="formatsButton"></a>
<div>
<a target="_parent" href="formats.html#syntax">Syntax</a>
<a target="_parent" href="formats.html#types">Types &amp; Fields</a>
<a target="_parent" href="formats.html#stdd" title="Standard DOUBLE converters">%f %e %g</a>
<a target="_parent" href="formats.html#stdl" title="Standard LONG converters">%i %d %u %o %x</a>
<a target="_parent" href="formats.html#stds" title="Standard STRING converters">%s %c</a>
<a target="_parent" href="formats.html#cset" title="Character set STRING converter">%[<em>charset</em>]</a>
<a target="_parent" href="formats.html#enum" title="Enumeration LONG converter">%{<em>s0</em>|<em>s1</em>|...}</a>
<a target="_parent" href="formats.html#bin" title="Binary LONG converter">%b %B</a>
<a target="_parent" href="formats.html#raw" title="Raw LONG converter">%r</a>
<a target="_parent" href="formats.html#rawdouble" title="Raw DOUBLE converter">%R</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#regex" title="Perl regular expression STRING converter">%/<em>regex</em>/</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>
</div>
</div>
<div>
<a target="_parent" href="processing.html">Record Processing</a>
<a href="javascript:show('proc')" id="procButton"></a>
<div>
<a target="_parent" href="processing.html#proc">Normal Processing</a>
<a target="_parent" href="processing.html#init">Initialization</a>
<a target="_parent" href="processing.html#iointr">I/O Intr</a>
</div>
</div>
<div>
<a target="_parent" href="recordtypes.html">Record Types</a>
<a href="javascript:show('records')" id="recordsButton"></a>
<div>
<a target="_parent" href="aai.html">aai</a>
<a target="_parent" href="aao.html">aao</a>
<a target="_parent" href="ai.html">ai</a>
<a target="_parent" href="ao.html">ao</a>
<a target="_parent" href="bi.html">bi</a>
<a target="_parent" href="bo.html">bo</a>
<a target="_parent" href="mbbi.html">mbbi</a>
<a target="_parent" href="mbbo.html">mbbo</a>
<a target="_parent" href="mbbiDirect.html">mbbiDirect</a>
<a target="_parent" href="mbboDirect.html">mbboDirect</a>
<a target="_parent" href="stringin.html">stringin</a>
<a target="_parent" href="stringout.html">stringout</a>
<a target="_parent" href="longin.html">longin</a>
<a target="_parent" href="longout.html">longout</a>
<a target="_parent" href="waveform.html">waveform</a>
<a target="_parent" href="calcout.html">calcout</a>
<a target="_parent" href="scalcout.html">scalcout</a>
</div>
</div>
<div>
<a target="_parent" href="tipsandtricks.html">Tips &amp; Tricks</a>
<a href="javascript:show('tipsandtricks')" id="tipsandtricksButton"></a>
<div>
<a target="_parent" href="tipsandtricks.html#argvar">Many almost identical protocols</a>
<a target="_parent" href="tipsandtricks.html#iointr">Read unsolicited input</a>
<a target="_parent" href="tipsandtricks.html#multiline">Read multi-line messages</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#mixed">Read values of mixed data type</a>
</div>
</div>
<h1>Programmer's Guide</h1>
<div>
<a target="_parent" href="recordinterface.html">Record API</a>
</div>
<div>
<a target="_parent" href="businterface.html">Bus API</a>
<a href="javascript:show('bus')" id="busButton"></a>
<div>
<a target="_parent" href="businterface.html#class">Interface Class</a>
<a target="_parent" href="businterface.html#theory">Theory of Operation</a>
<div>
<a target="_parent" href="businterface.html#registration">Registration</a>
<a target="_parent" href="businterface.html#create">Creation &amp; deletion</a>
<a target="_parent" href="businterface.html#connect">Connecting</a>
<a target="_parent" href="businterface.html#lock">Bus locking</a>
<a target="_parent" href="businterface.html#write">Writing output</a>
<a target="_parent" href="businterface.html#read">Reading input</a>
<a target="_parent" href="businterface.html#event">Handling events</a>
</div>
</div>
</div>
<div>
<a target="_parent" href="formatconverter.html">Format Converter API</a>
</div>
<div>
<a target="_parent" href="osinterface.html">Operating System API</a>
</div>
</body> </body>
</html> </html>

View File

@ -3,18 +3,18 @@
<html> <html>
<head> <head>
<title>StreamDevice: Operating System API</title> <title>StreamDevice: Operating System API</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Operating System API</h1> <h1>StreamDevice: Operating System API</h1>
<h2>Sorry, this documentation is still missing.</h2> <h2>Sorry, this documentation is still missing.</h2>
<hr> <hr>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: Record Processing</title> <title>StreamDevice: Record Processing</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Record Processing</h1> <h1>StreamDevice: Record Processing</h1>
<a name="proc"></a> <a name="proc"></a>
@ -239,6 +240,5 @@ with "<code>ROI</code>", followed by two floating point numbers.
<hr> <hr>
<p align="right"><a href="recordtypes.html">Next: Supported Record Types</a></p> <p align="right"><a href="recordtypes.html">Next: Supported Record Types</a></p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: Protocol Files</title> <title>StreamDevice: Protocol Files</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Protocol Files</h1> <h1>StreamDevice: Protocol Files</h1>
<a name="gen"></a> <a name="gen"></a>
<h2>1. General Information</h2> <h2>1. General Information</h2>
@ -241,8 +242,12 @@ that hex value.<br>
that octal value.<br> that octal value.<br>
<code>\1</code> to <code>\9</code> followed by up to two more decimal <code>\1</code> to <code>\9</code> followed by up to two more decimal
digits means a byte with that decimal value.<br> digits means a byte with that decimal value.<br>
<code>\?</code> in the argument string of an <code>in</code> <code>\?</code> in input matches any byte, in output it does not print
<a href="#cmd">command</a> matches any input byte<br> anything.<br>
<span class="new">
<code>\_</code> in input matches any amount of white space (including none),
in output it prints a single space.<br>
</span>
<code>\$</code> followed by the name of a <code>\$</code> followed by the name of a
<a href="#var">protocol varible</a> is replaced by the contents of that <a href="#var">protocol varible</a> is replaced by the contents of that
variable. variable.
@ -251,29 +256,54 @@ variable.
For non-printable characters, it is often easier to write sequences of For non-printable characters, it is often easier to write sequences of
byte values instead of escaped quoted string literals. byte values instead of escaped quoted string literals.
A byte is written as an unquoted decimal, hexadecimal, or octal A byte is written as an unquoted decimal, hexadecimal, or octal
number in the range of -128 to 255 (-0x80 to 0xff, -0200 to 0377). number in the range of <code>-128</code> to <code>255</code>,
<em>StreamDevice</em> also defines some symbolic names for frequently <code>-0x80</code> to <code>0xff</code> (not case sesitive),
used byte codes as aliases for the numeric byte value:<br> or <code>-0200</code> to <code>0377</code>, respectively.
<code>EOT</code> means <em>end of transmission</em> (ASCII code 4).<br> </p>
<code>ACK</code> means <em>acknowledge</em> (ASCII code 6).<br> <p>
<code>BEL</code> means <em>bell</em> (ASCII code 7).<br> <em>StreamDevice</em> also recordgnizes the ASCII symbolic names
<code>BS</code> means <em>backspace</em> (ASCII code 8).<br> (not case sensitive) for several byte codes:<br>
<code>HT</code> or <code>TAB</code> mean <em>horizontal tabulator</em> <code>NUL </code>(= <code>0x00</code>) <em>null</em><br>
(ASCII code 9).<br> <code>SOH </code>(= <code>0x01</code>) <em>start of heading</em><br>
<code>LF</code> or <code>NL</code> mean <em>line feed</em> / <code>STX </code>(= <code>0x02</code>) <em>start of text</em><br>
<em>new line</em> (ASCII code 10).<br> <code>ETX </code>(= <code>0x03</code>) <em>end of text</em><br>
<code>CR</code> means <em>carriage return</em> (ASCII code 13).<br> <code>EOT </code>(= <code>0x04</code>) <em>end of transmission</em><br>
<code>ESC</code> means <em>escape</em> (ASCII code 27).<br> <code>ENQ </code>(= <code>0x05</code>) <em>enquiry</em><br>
<code>DEL</code> means <em>delete</em> (ASCII code 127).<br> <code>ACK </code>(= <code>0x06</code>) <em>acknowledge</em><br>
<code>SKIP</code> in the argument string of an <code>in</code> <code>BEL </code>(= <code>0x07</code>) <em>bell</em><br>
<a href="#cmd">command</a> matches any input byte. <code>BS&nbsp; </code>(= <code>0x08</code>) <em>backspace</em><br>
<code>HT</code> or <code>TAB</code> (= <code>0x09</code>) <em>horizontal tabulator</em><br>
<code>LF</code> or <code>NL</code> (= <code>0x0A</code> or <code>10</code>) <em>line feed / new line</em><br>
<code>VT&nbsp; </code>(= <code>0x0B</code> or <code>11</code>) <em>vertical tabulator</em><br>
<code>FF</code> or <code>NP</code> (= <code>0x0C</code> or <code>12</code>) <em>form feed / new page</em><br>
<code>CR&nbsp; </code>(= <code>0x0D</code> or <code>13</code>) <em>carriage return</em><br>
<code>SO&nbsp; </code>(= <code>0x0E</code> or <code>14</code>) <em>shift out</em><br>
<code>SI&nbsp; </code>(= <code>0x0F</code> or <code>15</code>) <em>shift in</em><br>
<code>DLE </code>(= <code>0x10</code> or <code>16</code>) <em>data link escape</em><br>
<code>DC1 </code>(= <code>0x11</code> or <code>17</code>) <em>device control 1</em><br>
<code>DC2 </code>(= <code>0x12</code> or <code>18</code>) <em>device control 2</em><br>
<code>DC3 </code>(= <code>0x13</code> or <code>19</code>) <em>device control 3</em><br>
<code>DC4 </code>(= <code>0x14</code> or <code>20</code>) <em>device control 4</em><br>
<code>NAK </code>(= <code>0x15</code> or <code>21</code>) <em>negative acknowledge</em><br>
<code>SYN </code>(= <code>0x16</code> or <code>22</code>) <em>synchronous idle</em><br>
<code>ETB </code>(= <code>0x17</code> or <code>23</code>) <em>end of transmission block</em><br>
<code>CAN </code>(= <code>0x18</code> or <code>24</code>) <em>cancel</em><br>
<code>EM&nbsp; </code>(= <code>0x19</code> or <code>25</code>) <em>end of medium</em><br>
<code>SUB </code>(= <code>0x1A</code> or <code>26</code>) <em></em>substitute<br>
<code>ESC </code>(= <code>0x1B</code> or <code>27</code>) <em>escape</em><br>
<code>FS&nbsp; </code>(= <code>0x1C</code> or <code>28</code>) <em>file separator</em><br>
<code>GS&nbsp; </code>(= <code>0x1D</code> or <code>29</code>) <em>group separator</em><br>
<code>RS&nbsp; </code>(= <code>0x1E</code> or <code>30</code>) <em>record separator</em><br>
<code>US&nbsp; </code>(= <code>0x1F</code> or <code>31</code>) <em>unit separator</em><br>
<code>DEL </code>(= <code>0x7F</code> or <code>127</code>) <em>delete</em><br>
<code>SKIP</code> or <code>?</code> matches any input byte
</p> </p>
<p> <p>
A single string can be built from several quoted literals and byte values A single string can be built from several quoted literals and byte values
by writing them separated by whitespaces or comma. by writing them separated by whitespaces or comma.
</p> </p>
<h3>Example:</h3> <h3>Examples:</h3>
<p> <p>
The following lines represent the same string:<br> The following lines represent the same string:<br>
<code>"Hello world\r\n"</code><br> <code>"Hello world\r\n"</code><br>
@ -408,9 +438,12 @@ what they influence.
(see <a href="formats.html">formats</a> and (see <a href="formats.html">formats</a> and
<a href="waveform.html">waveform record</a>), what string <a href="waveform.html">waveform record</a>), what string
to write or to expect between values? to write or to expect between values?
If the first character of the <code>Separator</code> is a <span class="new">
<strike>If the first character of the <code>Separator</code> is a
space, it matches any number of any whitespace characters in space, it matches any number of any whitespace characters in
an <code>in</code> command. an <code>in</code> command.</strike> To match arbitrary amount of
whitespace in input, use <code>"\_"</code>.
</span>
</dd> </dd>
<dt><code>ExtraInput = Error;</code></dt> <dt><code>ExtraInput = Error;</code></dt>
<dd> <dd>
@ -546,7 +579,6 @@ settings from the protocol in which the exception occurred.
</p> </p>
<hr> <hr>
<p align="right"><a href="formats.html">Next: Format Converters</a></p> <p align="right"><a href="formats.html">Next: Format Converters</a></p>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2011</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,18 +3,18 @@
<html> <html>
<head> <head>
<title>StreamDevice: Record API</title> <title>StreamDevice: Record API</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Record API</h1> <h1>StreamDevice: Record API</h1>
<h2>Sorry, this documentation is still missing.</h2> <h2>Sorry, this documentation is still missing.</h2>
<hr> <hr>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: Record Types</title> <title>StreamDevice: Record Types</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Record Types</h1> <h1>StreamDevice: Record Types</h1>
<h2>Supported Record Types</h2> <h2>Supported Record Types</h2>
@ -49,6 +50,5 @@ It is also possible to
<hr> <hr>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: scalcout Records</title> <title>StreamDevice: scalcout Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: scalcout Records</h1> <h1>StreamDevice: scalcout Records</h1>
<p> <p>
@ -96,6 +97,5 @@ Different record fields are used for output and input. The variable
<a href="calcout.html">calcout</a> <a href="calcout.html">calcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,79 +3,159 @@
<html> <html>
<head> <head>
<title>StreamDevice: Setup</title> <title>StreamDevice: Setup</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Setup</h1> <h1>StreamDevice: Setup</h1>
<a name="pre"></a> <a name="pre"></a>
<h2>1. Prerequisites</h2> <h2>1. Prerequisites</h2>
<p> <p>
<em>StreamDevice</em> requires either <em>StreamDevice</em> requires either
<a href="http://www.aps.anl.gov/epics/base/R3-14/index.php" <a href="http://www.aps.anl.gov/epics/base/R3-14/index.php"
target="ex">EPICS base R3.14.6 or higher</a> or target="ex">EPICS base R3.14.6 or higher</a> or
<a href="http://www.aps.anl.gov/epics/base/R3-13.php" <a href="http://www.aps.anl.gov/epics/base/R3-13.php"
target="ex">EPICS base R3.13.7 or higher</a>. target="ex">EPICS base R3.13.7 or higher</a>.
How to use <em>StreamDevice</em> on EPICS R3.13 is described on a How to use <em>StreamDevice</em> on EPICS R3.13 is described on a
<a href="epics3_13.html">separate page</a>. <a href="epics3_13.html">separate page</a>.
Because <em>StreamDevice</em> comes with an interface to
<a href="http://www.aps.anl.gov/epics/modules/soft/asyn/"
target="ex"><em>asynDriver</em> version R4-3 or higher</a> as the
underlying driver layer,
you should have <em>asynDriver</em> installed first.
</p>
<p>
<em>StreamDevice</em> has support for the
<a href="scalcout.html"><em>scalcout</em></a> record from the
<em>calc</em> module of <a target="ex"
href="http://www.aps.anl.gov/aod/bcda/synApps/index.php"
><em>synApps</em></a>.
Up to <em>calc</em> release R2-6 (<em>synApps</em> release R5_1),
the <em>scalcout</em> record needs a fix.
(See separate <a href="scalcout.html"><em>scalcout</em> page</a>.)
Support for the scalcout is optional. <em>StreamDevice</em> works
as well without scalcout or SynApps.
</p> </p>
<h3>Fix required for base R3.14.8.2 and earlier on Windows</h3>
<p> <p>
Up to release R3.14.8.2, a fix in EPICS base is required to build Up to release R3.14.8.2, a fix in EPICS base is required to build
<em>StreamDevice</em> on Windows (not cygwin). <em>StreamDevice</em> on Windows (not cygwin).
In <kbd>src/iocsh/iocsh.h</kbd>, add the following line Add the following line to <kbd>src/iocsh/iocsh.h</kbd>
and rebuild base. and rebuild base.
</p> </p>
<pre> <pre>
epicsShareFunc int epicsShareAPI iocshCmd(const char *command); epicsShareFunc int epicsShareAPI iocshCmd(const char *command);
</pre> </pre>
<h3>Configuration</h3>
<p> <p>
Make sure that the <em>asyn</em> library (and the <em>calc</em> module of <em>StreamDevice</em> does not come with its own <kbd>&lt;top&gt;</kbd>
<em>synApps</em>, if desired) can be found, e.g. by location and <kbd>&lt;top&gt;/configure</kbd> directory.
adding <code>ASYN</code> It expects to be put into an already existing <kbd>&lt;top&gt;</kbd>
and (if installed) <code>CALC</code> or <code>SYNAPPS</code> directory structure.
to your <kbd>&lt;top&gt;/configure/RELEASE</kbd> file: You can simply create one with <code>makeBaseApp.pl</code>
(which is part of EPICS base):
</p> </p>
<p>
<code>mkdir top</code><br>
<code>cd top</code><br>
<code>makeBaseApp.pl -t support</code>
</p>
<p>
When asked for "Application names" just hit Enter.
Then go to the newly created <kbd>configure</kbd> subdirectory and
edit the <kbd>RELEASE</kbd> file you find there according to the
instructions below.
</p>
<p>
After changing any configuration, you should run <code>make</code>
in this directory.
</p>
<p>
For details on <kbd>&lt;top&gt;</kbd> directories and <kbd>RELEASE</kbd>
files please refer to the
<a href="http://www.aps.anl.gov/epics/base/R3-14/8-docs/AppDevGuide.pdf"
target="ex"><em>IOC Application Developer's Guide</em></a> chapter 4:
EPICS Build Facility.
</p>
<h4>Support for <em>asynDriver</em></h4>
<p>
You most probably want <em>asynDriver</em> support included, because that is the
standard way for <em>StreamDevice</em> to talk to hardware.
First get and install <a href="http://www.aps.anl.gov/epics/modules/soft/asyn/"
target="ex"><em>asynDriver</em></a> version 4-3 or higher before you build <em>StreamDevice</em>.
I have tested <em>StreamDevice</em> with <em>asynDriver</em> versions up to 4-17.
Make sure that the <em>asyn</em> library can be found by adding the path to the
<em>&lt;top&gt;</em> directory of your <em>asyn</em> installation to the
<kbd>RELEASE</kbd> file:
<pre> <pre>
ASYN=/home/epics/asyn/4-5 ASYN=/home/epics/asyn4-17
CALC=/home/epics/synApps/calc/2-7 </pre>
<h4>Support for sCalcout record</h4>
<p>
The <a target="ex"
href="http://www.aps.anl.gov/bcda/synApps/calc/R2-8/sCalcoutRecord.html"
><em>sCalcout</em></a> record is part of <a target="ex"
href="http://www.aps.anl.gov/aod/bcda/synApps/index.php"
><em>synApps</em></a>.
If <em>streamDevice</em> should be built with support for this record,
you have to install the <em>calc</em> module from <em>SynApps</em> first.
Add references to the <kbd>RELEASE</kbd> file as shown here:
<pre>
CALC=/home/epics/synApps/calc-2-8
</pre> </pre>
<p> <p>
Up to <em>calc</em> release R2-6 (<em>synApps</em> release R5_1),
the <em>sCalcout</em> record needs a fix.
(See separate <a href="scalcout.html"><em>scalcout</em> page</a>.)
And the <em>calc</em> modue had dependencies on other <em>SynApps</em>
modules. Release R2-8 or newer is recommended.
</p>
<p>
Support for the scalcout is optional. <em>StreamDevice</em> works
as well without scalcout or SynApps.
</p>
<h4>Support for regular expression matching</h4>
<p>
If you want to enable regular expression matching, you need the <em>PCRE</em> package. If you want to enable regular expression matching, you need the <em>PCRE</em> package.
For most Linux systems, it is already installed. In that case add the locations For most Linux systems, it is already installed.
of the <em>PCRE</em> header and library to your <kbd>RELEASE</kbd> file: In that case add the locations you have to make the locations of the
<em>PCRE</em> header file and library known.
However, the pre-installed package can only by used for the host architecture.
Thus, add them not to <kbd>RELEASE</kbd> but to <kbd>RELEASE.Common.linux-x86</kbd>
(if linux-x86 is your EPICS_HOST_ARCH).
Note that different Linux distributions may locate the files in different directories.
</p> </p>
<pre> <pre>
PCRE_INCLUDE=/usr/include/pcre PCRE_INCLUDE=/usr/include/pcre
PCRE_LIB=/usr/lib PCRE_LIB=/usr/lib
</pre> </pre>
<p> <p>
If you want to build <em>StreamDevice</em> for platforms without <em>PCRE</em> support, A pre-compiled Windows version of <em>PCRE</em> is available at
it is the easiest to build <em>PCRE</em> as an EPICS application. <a href="http://sourceforge.net/projects/gnuwin32/files/pcre/7.0/pcre-7.0.exe/download"
Download the <em>PCRE</em> package from <a target=ex href="http://www.pcre.org">www.pcre.org</a> target="ex">sourceforge</a>
and compile it with my EPICS compatible </p>
<a target=ex href="http://epics.web.psi.ch/software/streamdevice/pcre/Makefile">Makefile</a>. <p>
Then define the location of the application in your RELEASE file. If you want to have <em>PCRE</em> support on platforms that don't support it natively,
e.g. vxWorks, it is probably the easiest to build <em>PCRE</em> as an EPICS application.
</p>
<p>
<h4>Building the <em>PCRE</em> package as an EPICS module</h4>
<p>
<ol>
<li>
Download the <em>PCRE</em> package from <a target=ex href="http://www.pcre.org">www.pcre.org</a>.
</li>
<li>
Extract the <em>PCRE</em> package in the <kbd>&lt;top&gt;</kbd> directory of
<em>StreamDevice</em> or create a separate <kbd>&lt;top&gt;</kbd> location using
<code>makeBaseApp.pl</code>.
</li>
<li>
Download this <a target=ex href="http://epics.web.psi.ch/software/streamdevice/pcre/Makefile"
>Makefile</a> and this
<a target=ex href="http://epics.web.psi.ch/software/streamdevice/pcre/fixforvxworks.pl"
>fixforvxworks.pl</a> script and save them to the extracted pcre directory.
</li>
<li>
Change into the pcre direcrory and run <code>perl fixforvxworks.pl</code>
</li>
<li>
Run <code>make</code> (or <code>gmake</code>)
</li>
</ol>
<p>
Define the location of the pcre <kbd>&lt;top&gt;</kbd> in the RELEASE file for <em>StreamDevice</em>.
</p> </p>
<pre> <pre>
PCRE=/home/epics/pcre PCRE=/home/epics/pcre
@ -84,25 +164,17 @@ PCRE=/home/epics/pcre
Regular expressions are optional. If you don't want them, you don't need this. Regular expressions are optional. If you don't want them, you don't need this.
</p> </p>
<p>
For details on <kbd>&lt;top&gt;</kbd> directories and RELEASE files,
please refer to the
<a href="http://www.aps.anl.gov/epics/base/R3-14/8-docs/AppDevGuide.pdf"
target="ex"><em>IOC Application Developer's Guide</em></a> chapter 4:
EPICS Build Facility.
</p>
<a name="lib"></a> <a name="lib"></a>
<h2>2. Build the <em>StreamDevice</em> Library</h2> <h2>2. Build the <em>StreamDevice</em> Library</h2>
<p> <p>
Unpack the Unpack the
<a href="http://epics.web.psi.ch/software/streamdevice/StreamDevice-2.tgz" <a href="http://epics.web.psi.ch/software/streamdevice/StreamDevice-2.tgz"
><em>StreamDevice</em> package</a> in a <kbd>&lt;top&gt;</kbd> directory ><em>StreamDevice</em> package</a> in the <kbd>&lt;top&gt;</kbd> directory
of your application build area. of your application build area.
(You might probably have done this already.) (You might probably have done this already.)
Go to the newly created <em>StreamDevice</em> directory Go to the newly created <em>StreamDevice</em> directory
and run <kbd>make</kbd> (or <kbd>gmake</kbd>). and run <code>make</code> (or <code>gmake</code>).
This will create and install the <em>stream</em> library and the This will create and install the <em>stream</em> library and the
<kbd>stream.dbd</kbd> file. <kbd>stream.dbd</kbd> file.
</p> </p>
<a name="app"></a> <a name="app"></a>
@ -121,7 +193,8 @@ PROD_LIBS += asyn
</pre> </pre>
<p> <p>
Include the following lines in your xxxAppInclude.dbd file to use Include the following lines in your xxxAppInclude.dbd file to use
<em>stream</em> and <em>asyn</em> with serial lines and IP sockets: <em>stream</em> and <em>asyn</em> with serial lines, IP sockets,
and vxi11 ("GPIB over ethernet") support.
</p> </p>
<pre> <pre>
include "base.dbd" include "base.dbd"
@ -129,6 +202,7 @@ include "stream.dbd"
include "asyn.dbd" include "asyn.dbd"
registrar(drvAsynIPPortRegisterCommands) registrar(drvAsynIPPortRegisterCommands)
registrar(drvAsynSerialPortRegisterCommands) registrar(drvAsynSerialPortRegisterCommands)
registrar(vxi11RegisterCommands)
</pre> </pre>
<p> <p>
You can find an example application in the <kbd>streamApp</kbd> You can find an example application in the <kbd>streamApp</kbd>
@ -151,7 +225,7 @@ i.e. the current directory.
<p> <p>
Also configure the buses (in <em>asynDriver</em> terms: ports) you want Also configure the buses (in <em>asynDriver</em> terms: ports) you want
to use with <em>StreamDevice</em>. to use with <em>StreamDevice</em>.
You can give the buses any name you want, like <kbd>COM1</kbd> or You can give the buses any name you want, like <kbd>COM1</kbd> or
<kbd>socket</kbd>, but I recommend to use names related to the <kbd>socket</kbd>, but I recommend to use names related to the
connected device. connected device.
</p> </p>
@ -189,7 +263,7 @@ drvAsynIPPortConfigure ("PS1", "192.168.164.10:23")
</pre> </pre>
<p> <p>
With a VXI11 (GPIB via TCP/IP) connection, e.g. a With a VXI11 (GPIB via TCP/IP) connection, e.g. a
HP E2050A on IP address 192.168.164.10, it would look like this: HP E2050A on IP address 192.168.164.10, it would look like this:
</p> </p>
<pre> <pre>
@ -211,7 +285,7 @@ During <code>iocInit</code>, <em>streamDevice</em> loads and parses
the required protocol files. the required protocol files.
If the files contain errors, they are printed on the IOC shell. If the files contain errors, they are printed on the IOC shell.
Put the protocol file in one of the directories listed in Put the protocol file in one of the directories listed in
<code>STREAM_PROTOCOL_PATH</code>. <code>STREAM_PROTOCOL_PATH</code>.
</p> </p>
<h3>Example:</h3> <h3>Example:</h3>
<p> <p>
@ -234,7 +308,7 @@ Terminator = CR LF;
setCurrent { setCurrent {
out "CURRENT %.2f"; out "CURRENT %.2f";
@init { @init {
out "CURRENT?"; out "CURRENT?";
in "CURRENT %f A"; in "CURRENT %f A";
} }
@ -270,19 +344,24 @@ See the <a href="protocol.html">next chapter</a> for protocol files in depth.
<p> <p>
To make a record use <em>StreamDevice</em>, set its <code>DTYP</code> field to To make a record use <em>StreamDevice</em>, set its <code>DTYP</code> field to
<code>"stream"</code>. <code>"stream"</code>.
</p>
<p>
The <code>INP</code> or <code>OUT</code> link has the form The <code>INP</code> or <code>OUT</code> link has the form
<code>"@<var>file&nbsp;protocol&nbsp;bus</var>&nbsp;[<var>address</var>&nbsp;[<var>parameters</var>]]"</code>. <code>"@<var>file&nbsp;protocol&nbsp;bus</var>&nbsp;[<var>address</var>&nbsp;[<var>parameters</var>]]"</code>.
</p> </p>
<p> <p>
Here, <code><var>file</var></code> is the name of the protocol file and Here, <code><var>file</var></code> is the name of the protocol file and
<code><var>protocol</var></code> is the name of a protocol defined in this file. <code><var>protocol</var></code> is the name of a protocol defined in this file.
(See the <a href="protocol.html">next chapter</a>.)
</p>
<p>
If the protocol requires <a href="protocol.html#argvar">arguments</a>, If the protocol requires <a href="protocol.html#argvar">arguments</a>,
specify them enclosed in parentheses: specify them enclosed in parentheses:
<code><var>protocol</var>(<var>arg1,arg2,...</var>)</code>. <code><var>protocol</var>(<var>arg1,arg2,...</var>)</code>.
</p> </p>
<p> <p>
The communication channel is specified with <code><var>bus</var></code> and The communication channel is specified with <code><var>bus</var></code>
<code><var>addr</var></code>. (aka <em>asynDriver</em> "port") and <code><var>addr</var></code>.
If the bus does not have addresses, <code><var>addr</var></code> is dispensable. If the bus does not have addresses, <code><var>addr</var></code> is dispensable.
Optional <code><var>parameters</var></code> are passed to the bus driver. Optional <code><var>parameters</var></code> are passed to the bus driver.
</p> </p>
@ -298,8 +377,8 @@ The bus is called <em>PS1</em> like the device.
record (ao, "PS1:I-set") record (ao, "PS1:I-set")
{ {
field (DESC, "Set current of PS1") field (DESC, "Set current of PS1")
field (DTYP, "stream") <b>field (DTYP, "stream")</b>
field (OUT, "@ExamplePS.proto setCurrent PS1") <b>field (OUT, "@ExamplePS.proto setCurrent PS1")</b>
field (EGU, "A") field (EGU, "A")
field (PREC, "2") field (PREC, "2")
field (DRVL, "0") field (DRVL, "0")
@ -311,7 +390,6 @@ record (ao, "PS1:I-set")
<hr> <hr>
<p align="right"><a href="protocol.html">Next: Protocol Files</a></p> <p align="right"><a href="protocol.html">Next: Protocol Files</a></p>
<p><small>Dirk Zimoch, 2007</small></p> <p><small>Dirk Zimoch, 2011</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 807 B

View File

@ -1,13 +1,17 @@
a:link {color: #0000D0; text-decoration:none;} a:link {color: #0000D0;}
a:visited {color: #0000D0; text-decoration:none;} a:visited {color: #0000D0;}
a:hover {color: #FF0000; text-decoration:none;} a:hover {color: #FF0000;}
body { body {
margin-right:20px; margin-right:1em;
font-family:sans-serif; margin-left:15em;
margin-top:11ex;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-size:14px; font-size:14px;
background-color:#ffffff; background-color:#ffffff;
} }
a[name] { position:relative; top:-11ex;}
pre { pre {
background-color:#f4f4f4; background-color:#f4f4f4;
@ -17,6 +21,10 @@ pre {
margin:2ex; margin:2ex;
} }
kbd {
font-weight:bold;
}
dt { dt {
margin-top:0.5ex; margin-top:0.5ex;
} }
@ -26,6 +34,22 @@ h1 {
margin-top:0; margin-top:0;
font-style:italic; font-style:italic;
font-family:serif; font-family:serif;
text-align:center;
position:fixed;
top:0;
left:0;
width:100%;
min-height:60px;
height: 4ex;
line-height:190%;
background-color:white;
border-top:6px solid #1b4486;
border-bottom:4px solid #1b4486;
white-space:nowrap;
background-image:url(PSI.gif);
background-repeat:no-repeat;
background-position:10px 2px;
text-shadow: .1em .1em .1em lightgray;
} }
h2 { h2 {
@ -34,6 +58,11 @@ h2 {
} }
h3 { h3 {
font-size:120%;
margin-bottom:0.25ex;
}
h4 {
font-size:100%; font-size:100%;
margin-bottom:0.25ex; margin-bottom:0.25ex;
} }
@ -58,22 +87,41 @@ code {
text-align:left; text-align:left;
} }
/* #navleft {
a[target=ex] { position:fixed;
background-image:url(ex.png); left:0;
background-repeat:no-repeat; top:0;
background-position:right center; padding-top:9ex;
padding-right: 12px; width:14em;
} height:100%;
border-style:solid;
border-color:black;
border-width:0 1px 0 0;
background-color:#e3eaf6;
overflow:hidden;
z-index:0;
}
a[target=ex]:hover { .new {
background-image:url(exr.png); background-color: #ffc;
} }
*/
a[target=ex]:after {
content:" " url(ex.png);
}
a[target=ex]:hover:after {
content: " " url(exr.png);
}
@media print { @media print {
a:link {color: black; text-decoration:none;} a:link {color: black; text-decoration:none;}
a:visited {color: black; text-decoration:none;} a:visited {color: black; text-decoration:none;}
a:hover {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) "]";}
code {color: black; } code {color: black; }
body {margin-left:10px;}
h1 {position:absolute;}
#navleft {display:none;}
} }

View File

@ -1,92 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>StreamDevice</title>
<link rel="shortcut icon" href="sls_icon.ico">
<link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch">
</head>
<body>
<h1>EPICS <em>StreamDevice</em> Documentation</h1>
<h2>What is <em>StreamDevice</em>?</h2>
<p>
<em>StreamDevice</em> is a generic
<a href="http://www.aps.anl.gov/epics" target="ex">EPICS</a>
device support for devices with a "byte stream" based
communication interface.
That means devices that can be controlled by sending and
receiving strings (in the broadest sense, including non-printable
characters and even null-bytes).
Examples for this type of communication interface are
serial line (RS-232, RS-485, ...),
IEEE-488 (also known as GPIB or HP-IB), and TCP/IP.
<em>StreamDevice</em> comes with an interface to<a target="ex"
href="http://www.aps.anl.gov/epics/modules/soft/asyn/">
<em>asynDriver</em></a>
but can be extended to
<a href="businterface.html">support other bus drivers</a>.
</p>
<p>
If the device can be controlled with strings like
"<code>RF:FREQ 499.655 MHZ</code>", <em>StreamDevice</em> can be used.
How the strings exactly look like is defined in <em>protocols</em>.
Formatting and interpretation of values is done with
<a href="formats.html"><em>format converters</em></a> similar to those
known from the C functions <em>printf()</em> and <em>scanf()</em>.
To support other formats, it is possible to
<a href="formatconverter.html">write your own converters</a>.
</p>
<p>
Each record with <em>StreamDevice</em> support runs one <em>protocol</em>
to read or write its value.
All <em>protocols</em> are defined in
<a href="protocol.html"><em>protocol files</em></a> in plain ASCII text.
No compiling is necessary to change a protocol or to support new devices.
<em>Protocols</em> can be as simple as just one output string or can
consist of many strings sent to and read from the device.
However, a protocol is linear.
That means it runs from start to end each time the record is
<a href="processing.html">processed</a>.
It does not provide loops or branches.
</p>
<p>
<em>StreamDevice</em> supports all
<a href="recordtypes.html">standard records</a> of EPICS base
which can have device support.
It is also possible to
<a href="recordinterface.html">write support for new record types</a>.
</p>
<h2>What is <em>StreamDevice</em> not?</h2>
<p>
It is not a programming language for a high-level application.
It is, for example, not possible to write a complete scanning program
in a <em>protocol</em>.
Use other tools for that and use <em>StreamDevice</em> only for the
primitive commands.
</p>
<p>
It is not a block oriented device support.
It is not possible to send or receive huge blocks of data that contain
many process variables distributed over many records.
</p>
<h2>Recommended Readings</h2>
<p>
<a href="http://www.aps.anl.gov/epics/base/R3-14/8-docs/AppDevGuide.pdf"
target="ex">IOC Application Developer's Guide (PDF)</a>
</p>
<p>
<a href="http://www.aps.anl.gov/asd/controls/epics/EpicsDocumentation/AppDevManuals/RecordRef/Recordref-1.html"
target="ex">EPICS Record Reference Manual</a>
</p>
<hr>
<p align="right"><a href="setup.html">Next: Setup</a></p>
<p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body>
</html>

View File

@ -1,5 +0,0 @@
if (parent.head) {
parent.head.document.getElementById('subtitle').innerHTML=document.title;
parent.document.title=document.title;
document.getElementsByTagName('h1')[0].style.display="none";
}

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: stringin Records</title> <title>StreamDevice: stringin Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: stringin Records</h1> <h1>StreamDevice: stringin Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -62,6 +63,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: stringout Records</title> <title>StreamDevice: stringout Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: stringout Records</h1> <h1>StreamDevice: stringout Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -62,6 +63,5 @@ written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: Tips and Tricks</title> <title>StreamDevice: Tips and Tricks</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: Tips and Tricks</h1> <h1>StreamDevice: Tips and Tricks</h1>
<a name="argvar"></a> <a name="argvar"></a>
@ -54,7 +55,7 @@ read {in "new value = %f";}
<code> <code>
record (ai, "$(RECORD)") {<br> record (ai, "$(RECORD)") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br> &nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (INP, "@(DEVICETYPE).proto read $(BUS)")<br> &nbsp;&nbsp;field (INP, "@$(DEVICETYPE).proto read $(BUS)")<br>
&nbsp;&nbsp;field (SCAN, "I/O Intr")<br> &nbsp;&nbsp;field (SCAN, "I/O Intr")<br>
} }
</code> </code>
@ -95,10 +96,10 @@ array_out {separator=", "; out "an array: (%.2f)";}
The format <code>%.2f</code> is repeated for each element of the array. The format <code>%.2f</code> is repeated for each element of the array.
All elements are separated by <code>", "</code>.<br> All elements are separated by <code>", "</code>.<br>
Output will look like this: Output will look like this:
</p>
<pre> <pre>
an array: (3.14, 17.30, -12.34) an array: (3.14, 17.30, -12.34)
</pre> </pre>
</p>
<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
@ -121,7 +122,7 @@ record (calcout, "$(RECORD)") {<br>
&nbsp;&nbsp;field (INPC, "$(C_RECORD)")<br> &nbsp;&nbsp;field (INPC, "$(C_RECORD)")<br>
&nbsp;&nbsp;field (CALC, "0")<br> &nbsp;&nbsp;field (CALC, "0")<br>
&nbsp;&nbsp;field (DTYP, "stream")<br> &nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (OUT, "@(DEVICETYPE).proto write_ABC $(BUS)")<br> &nbsp;&nbsp;field (OUT, "@$(DEVICETYPE).proto write_ABC $(BUS)")<br>
} }
</code> </code>
</p> </p>
@ -131,14 +132,14 @@ Use <a href="formats.html#types">record references</a> in the format.
</p> </p>
<p> <p>
<code> <code>
acquire {out 'ACQUIRE "%(\$1:directory.VAL)s/%s",%(\$1:time.VAL).3f;';} acquire {out 'ACQUIRE "%(\$1:directory)s/%s",%(\$1:time).3f;';}
</code> </code>
</p> </p>
<p> <p>
You must specify the full <code>record.FIELD</code> name, You can specify a record name or record.FIELD in parentheses directly
even for <code>VAL</code> fields. after the <code>%</code>.
To avoid record names in protocol files use To avoid plain record names in protocol files use
<a href="protocol.html#argvar">protocol arguments</a>. <a href="protocol.html#argvar">protocol arguments</a> like <code>\$1</code>.
In the link, specify the record name or just the basename of the In the link, specify the record name or just the basename of the
other records (device name) in parentheses. other records (device name) in parentheses.
</p> </p>
@ -146,7 +147,7 @@ other records (device name) in parentheses.
<code> <code>
record (stringout, "$(DEVICE):getimage") {<br> record (stringout, "$(DEVICE):getimage") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br> &nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (OUT, "@(DEVICETYPE).proto acquire($(DEVICE)) $(BUS)")<br> &nbsp;&nbsp;field (OUT, "@$(DEVICETYPE).proto acquire($(DEVICE)) $(BUS)")<br>
} }
</code> </code>
</p> </p>
@ -190,12 +191,12 @@ read_B {in "A=%*f, B=%f";}
<code> <code>
record (ai, "$(DEVICE):A") {<br> record (ai, "$(DEVICE):A") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br> &nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (INP, "@(DEVICETYPE).proto read_A $(BUS)")<br> &nbsp;&nbsp;field (INP, "@$(DEVICETYPE).proto read_A $(BUS)")<br>
&nbsp;&nbsp;field (SCAN, "1 second")<br> &nbsp;&nbsp;field (SCAN, "1 second")<br>
}<br> }<br>
record (ai, "$(DEVICE):B") {<br> record (ai, "$(DEVICE):B") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br> &nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (INP, "@(DEVICETYPE).proto read_B $(BUS)")<br> &nbsp;&nbsp;field (INP, "@$(DEVICETYPE).proto read_B $(BUS)")<br>
&nbsp;&nbsp;field (SCAN, "I/O Intr")<br> &nbsp;&nbsp;field (SCAN, "I/O Intr")<br>
} }
</code> </code>
@ -221,14 +222,14 @@ To avoid record names in protocol files, use
</p> </p>
<p> <p>
<code> <code>
read_AB {out "GET A,B"; in "A=%f, B=%(\$1.VAL)f";} read_AB {out "GET A,B"; in "A=%f, B=%(\$1)f";}
</code> </code>
</p> </p>
<p> <p>
<code> <code>
record (ai, "$(DEVICE):A") {<br> record (ai, "$(DEVICE):A") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br> &nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (INP, "@(DEVICETYPE).proto read_AB($(DEVICE):B) $(BUS)")<br> &nbsp;&nbsp;field (INP, "@$(DEVICETYPE).proto read_AB($(DEVICE):B) $(BUS)")<br>
&nbsp;&nbsp;field (SCAN, "1 second")<br> &nbsp;&nbsp;field (SCAN, "1 second")<br>
}<br> }<br>
record (ai, "$(DEVICE):B") {<br> record (ai, "$(DEVICE):B") {<br>
@ -259,14 +260,14 @@ When asked "<code>CURRENT?</code>", the device send something like
</p> </p>
<p> <p>
<code> <code>
read_current {out "CURRENT?"; in "CURRENT %f A"; @mismatch {in "%(\1.VAL)39c";}} read_current {out "CURRENT?"; in "CURRENT %f A"; @mismatch {in "%(\1)39c";}}
</code> </code>
</p> </p>
<p> <p>
<code> <code>
record (ai, "$(DEVICE):readcurrent") {<br> record (ai, "$(DEVICE):readcurrent") {<br>
&nbsp;&nbsp;field (DTYP, "stream")<br> &nbsp;&nbsp;field (DTYP, "stream")<br>
&nbsp;&nbsp;field (INP, "@(DEVICETYPE).proto read_current($(DEVICE):message) $(BUS)")<br> &nbsp;&nbsp;field (INP, "@$(DEVICETYPE).proto read_current($(DEVICE):message) $(BUS)")<br>
}<br> }<br>
record (stringin, "$(DEVICE):message") {<br> record (stringin, "$(DEVICE):message") {<br>
} }
@ -292,6 +293,5 @@ record (stringout, "$(DEVICE):clean_2") {<br>
</code> </code>
<hr> <hr>
<p><small>Dirk Zimoch, 2007</small></p> <p><small>Dirk Zimoch, 2007</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,12 +3,13 @@
<html> <html>
<head> <head>
<title>StreamDevice: waveform Records</title> <title>StreamDevice: waveform Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<iframe src="nav.html" id="navleft"></iframe>
<h1>StreamDevice: waveform Records</h1> <h1>StreamDevice: waveform Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
@ -121,6 +122,5 @@ the written or read value.
<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, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

55
makefile Normal file
View File

@ -0,0 +1,55 @@
include /ioc/tools/driver.makefile
EXCLUDE_VERSIONS = 3.13.2
PROJECT=stream2
BUILDCLASSES += Linux
#DOCUDIR = doc
DBDS = stream.dbd
BUSSES += AsynDriver
BUSSES += Dummy
FORMATS += Enum
FORMATS += BCD
FORMATS += Raw
FORMATS += RawFloat
FORMATS += Binary
FORMATS += Checksum
FORMATS += Regexp
FORMATS += MantissaExponent
FORMATS += Timestamp
RECORDTYPES += aai aao
RECORDTYPES += ao ai
RECORDTYPES += bo bi
RECORDTYPES += mbbo mbbi
RECORDTYPES += mbboDirect mbbiDirect
RECORDTYPES += longout longin
RECORDTYPES += stringout stringin
RECORDTYPES += waveform
SOURCES += $(RECORDTYPES:%=src/dev%Stream.c)
SOURCES += $(FORMATS:%=src/%Converter.cc)
SOURCES += $(BUSSES:%=src/%Interface.cc)
SOURCES += $(wildcard src/Stream*.cc)
SOURCES += src/StreamVersion.c
SOURCES_3.14 += src/devcalcoutStream.c
HEADERS += StreamFormat.h
HEADERS += StreamFormatConverter.h
HEADERS += StreamBuffer.h
HEADERS += StreamError.h
ifeq (${EPICS_BASETYPE},3.13)
USR_INCLUDES += -include $(INSTALL_INCLUDE)/compat3_13.h
endif
StreamCore.o: streamReferences
streamReferences:
perl ../src/makeref.pl Interface $(BUSSES) > $@
perl ../src/makeref.pl Converter $(FORMATS) >> $@
stream.dbd:
perl ../src/makedbd.pl $(RECORDTYPES) > $@

View File

@ -59,12 +59,12 @@ writeRequest()
pasynManager->queueRequest() pasynManager->queueRequest()
when request is handled when request is handled
pasynOctet->flush() pasynOctet->flush()
pasynOctet->writeRaw() pasynOctet->write()
if writeRaw() times out if write() times out
writeCallback(StreamIoTimeout) writeCallback(StreamIoTimeout)
if writeRaw fails otherwise if write fails otherwise
writeCallback(StreamIoFault) writeCallback(StreamIoFault)
if writeRaw succeeds and all bytes have been written if write succeeds and all bytes have been written
writeCallback(StreamIoSuccess) writeCallback(StreamIoSuccess)
if not all bytes can be written if not all bytes can be written
pasynManager->queueRequest() to write next part pasynManager->queueRequest() to write next part
@ -205,7 +205,7 @@ class AsynDriverInterface : StreamBusInterface
void connectHandler(); void connectHandler();
void disconnectHandler(); void disconnectHandler();
bool connectToAsynPort(); bool connectToAsynPort();
void asynReadHandler(const char *data, int numchars, int eomReason); void asynReadHandler(const char *data, size_t numchars, int eomReason);
asynQueuePriority priority() { asynQueuePriority priority() {
return static_cast<asynQueuePriority> return static_cast<asynQueuePriority>
(StreamBusInterface::priority()); (StreamBusInterface::priority());
@ -502,6 +502,30 @@ connectToAsynPort()
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
return false; return false;
} }
// Is it really connected?
/* does not work because read(...,0,...) deletes 1 byte from input.
if (connected && !pasynGpib)
{
size_t received;
int eomReason;
char buffer[8];
pasynUser->timeout = 0.0;
status = pasynOctet->read(pvtOctet, pasynUser,
buffer, 0, &received, &eomReason);
debug("AsynDriverInterface::connectToAsynPort(%s): "
"read(..., 0, ...) [timeout=%f seconds] = %s\n",
clientName(), pasynUser->timeout,
asynStatusStr[status]);
pasynManager->isConnected(pasynUser, &connected);
debug("AsynDriverInterface::connectToAsynPort(%s): "
"device was %sconnected!\n",
clientName(),connected?"":"dis");
}
*/
debug("AsynDriverInterface::connectToAsynPort(%s) is %s connected\n", debug("AsynDriverInterface::connectToAsynPort(%s) is %s connected\n",
clientName(), connected ? "already" : "not yet"); clientName(), connected ? "already" : "not yet");
if (!connected) if (!connected)
@ -605,15 +629,46 @@ writeHandler()
size_t streameoslen; size_t streameoslen;
const char* streameos = getOutTerminator(streameoslen); const char* streameos = getOutTerminator(streameoslen);
if (streameos) // stream has added eos int oldeoslen = -1;
char oldeos[16];
if (streameos) // stream has already added eos, don't do it again in asyn
{ {
status = pasynOctet->writeRaw(pvtOctet, pasynUser, // clear terminator for asyn
outputBuffer, outputSize, &written); status = pasynOctet->getOutputEos(pvtOctet,
pasynUser, oldeos, sizeof(oldeos)-1, &oldeoslen);
if (status != asynSuccess)
{
oldeoslen = -1;
// No EOS support?
}
pasynOctet->setOutputEos(pvtOctet, pasynUser,
NULL, 0);
} }
else // asyn should add eos status = pasynOctet->write(pvtOctet, pasynUser,
outputBuffer, outputSize, &written);
debug("AsynDriverInterface::writeHandler(%s): "
"write(..., outputSize=%ld, written=%ld) "
"[timeout=%f seconds] = %s\n",
clientName(), (long)outputSize, (long)written,
pasynUser->timeout, asynStatusStr[status]);
// Up to asyn 4.17 I can't see when the server has disconnected. Why?
int connected;
pasynManager->isConnected(pasynUser, &connected);
debug("AsynDriverInterface::writeHandler(%s): "
"device is %sconnected\n",
clientName(),connected?"":"dis");
if (!connected) {
error("%s: connection closed in write\n",
clientName());
writeCallback(StreamIoFault);
return;
}
if (oldeoslen >= 0) // restore asyn terminator
{ {
status = pasynOctet->write(pvtOctet, pasynUser, pasynOctet->setOutputEos(pvtOctet, pasynUser,
outputBuffer, outputSize, &written); oldeos, oldeoslen);
} }
switch (status) switch (status)
{ {
@ -651,6 +706,23 @@ writeHandler()
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
#ifdef ASYN_VERSION // asyn >= 4.14
case asynDisconnected:
error("%s: asynDisconnected in write: %s\n",
clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault);
return;
case asynDisabled:
error("%s: asynDisconnected in write: %s\n",
clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault);
return;
#endif
default:
error("%s: unknown asyn error in write: %s\n",
clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault);
return;
} }
} }
@ -710,40 +782,46 @@ readHandler()
streameos = getInTerminator(streameoslen); streameos = getInTerminator(streameoslen);
deveos = streameos; deveos = streameos;
deveoslen = streameoslen; deveoslen = streameoslen;
if (streameos) do // streameos == NULL means: don't change eos if (streameos) // streameos == NULL means: don't change eos
{ {
asynStatus status; asynStatus status;
status = pasynOctet->getInputEos(pvtOctet, status = pasynOctet->getInputEos(pvtOctet,
pasynUser, oldeos, sizeof(oldeos)-1, &oldeoslen); pasynUser, oldeos, sizeof(oldeos)-1, &oldeoslen);
if (status != asynSuccess) if (status != asynSuccess)
{ {
oldeoslen = -1;
// No EOS support? // No EOS support?
} if (streameos[0])
// device (e.g. GPIB) might not accept full eos length
if (pasynOctet->setInputEos(pvtOctet, pasynUser,
deveos, deveoslen) == asynSuccess)
{
#ifndef NO_TEMPORARY
if (ioAction != AsyncRead)
{ {
debug("AsynDriverInterface::readHandler(%s) " error("%s: warning: No input EOS support.\n",
"input EOS set to %s\n", clientName());
clientName(),
StreamBuffer(deveos, deveoslen).expand()());
} }
oldeoslen = -1;
} else do {
// device (e.g. GPIB) might not accept full eos length
if (pasynOctet->setInputEos(pvtOctet, pasynUser,
deveos, deveoslen) == asynSuccess)
{
#ifndef NO_TEMPORARY
if (ioAction != AsyncRead)
{
debug("AsynDriverInterface::readHandler(%s) "
"input EOS set to %s\n",
clientName(),
StreamBuffer(deveos, deveoslen).expand()());
}
#endif #endif
break; break;
} }
deveos++; deveoslen--; deveos++; deveoslen--;
if (!deveoslen) if (!deveoslen)
{ {
error("%s: warning: pasynOctet->setInputEos() failed: %s\n", error("%s: warning: pasynOctet->setInputEos() failed: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
} }
} while (deveoslen); } while (deveoslen);
}
int bytesToRead = peeksize; long bytesToRead = peeksize;
long buffersize; long buffersize;
if (expectedLength > 0) if (expectedLength > 0)
@ -773,10 +851,11 @@ readHandler()
pasynUser->timeout = replyTimeout; pasynUser->timeout = replyTimeout;
} }
bool waitForReply = true; bool waitForReply = true;
int received; size_t received;
int eomReason; int eomReason;
asynStatus status; asynStatus status;
long readMore; long readMore;
int connected;
while (1) while (1)
{ {
@ -785,15 +864,36 @@ readHandler()
eomReason = 0; eomReason = 0;
status = pasynOctet->read(pvtOctet, pasynUser, status = pasynOctet->read(pvtOctet, pasynUser,
buffer, bytesToRead, (size_t*)&received, &eomReason); buffer, bytesToRead, &received, &eomReason);
if (ioAction == Read || status != asynTimeout) if (ioAction == Read || status != asynTimeout)
{ {
debug("AsynDriverInterface::readHandler(%s): " debug("AsynDriverInterface::readHandler(%s): "
"read(..., bytesToRead=%d, ...) [timeout=%f seconds] = %s\n", "read(..., bytesToRead=%ld, received=%ld...) "
clientName(), bytesToRead, pasynUser->timeout, "[timeout=%f seconds] = %s\n",
asynStatusStr[status]); clientName(), bytesToRead, (long)received,
pasynUser->timeout, asynStatusStr[status]);
}
pasynManager->isConnected(pasynUser, &connected);
debug("AsynDriverInterface::readHandler(%s): "
"device is %sconnected\n",
clientName(),connected?"":"dis");
if (!connected) {
error("%s: connection closed in read\n",
clientName());
readCallback(StreamIoFault);
return;
} }
// pasynOctet->read() has already cut off terminator. // pasynOctet->read() has already cut off terminator.
if (status == asynTimeout &&
pasynUser->timeout == 0.0 &&
received > 0)
{
// Jens Eden (PTB) pointed out that polling asynInterposeEos
// with timeout = 0.0 returns asynTimeout even when bytes
// have been received, but not yet the terminator.
status = asynSuccess;
}
switch (status) switch (status)
{ {
@ -802,9 +902,9 @@ readHandler()
{ {
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("AsynDriverInterface::readHandler(%s): " debug("AsynDriverInterface::readHandler(%s): "
"AsyncRead poll: received %d of %d bytes \"%s\" " "AsyncRead poll: received %ld of %ld bytes \"%s\" "
"eomReason=%s [data ignored]\n", "eomReason=%s [data ignored]\n",
clientName(), received, bytesToRead, clientName(), (long)received, bytesToRead,
StreamBuffer(buffer, received).expand()(), StreamBuffer(buffer, received).expand()(),
eomReasonStr[eomReason&0x7]); eomReasonStr[eomReason&0x7]);
#endif #endif
@ -816,9 +916,9 @@ readHandler()
} }
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("AsynDriverInterface::readHandler(%s): " debug("AsynDriverInterface::readHandler(%s): "
"received %d of %d bytes \"%s\" " "received %ld of %ld bytes \"%s\" "
"eomReason=%s\n", "eomReason=%s\n",
clientName(), received, bytesToRead, clientName(), (long)received, bytesToRead,
StreamBuffer(buffer, received).expand()(), StreamBuffer(buffer, received).expand()(),
eomReasonStr[eomReason&0x7]); eomReasonStr[eomReason&0x7]);
#endif #endif
@ -839,7 +939,7 @@ readHandler()
size_t i; size_t i;
for (i = 0; i < deveoslen; i++, received++) for (i = 0; i < deveoslen; i++, received++)
{ {
if (received >= 0) buffer[received] = deveos[i]; if ((int)received >= 0) buffer[received] = deveos[i];
// It is safe to add to buffer here, because // It is safe to add to buffer here, because
// the terminator was already there before // the terminator was already there before
// asynOctet->read() had cut it. // asynOctet->read() had cut it.
@ -875,9 +975,10 @@ readHandler()
// read timeout // read timeout
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("AsynDriverInterface::readHandler(%s): " debug("AsynDriverInterface::readHandler(%s): "
"ioAction=%s, timeout after %d of %d bytes \"%s\"\n", "ioAction=%s, timeout [%f seconds] "
clientName(), ioActionStr[ioAction], "after %ld of %ld bytes \"%s\"\n",
received, bytesToRead, clientName(), ioActionStr[ioAction], pasynUser->timeout,
(long)received, bytesToRead,
StreamBuffer(buffer, received).expand()()); StreamBuffer(buffer, received).expand()());
#endif #endif
if (ioAction == AsyncRead || ioAction == AsyncReadMore) if (ioAction == AsyncRead || ioAction == AsyncReadMore)
@ -910,6 +1011,23 @@ readHandler()
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault, buffer, received); readCallback(StreamIoFault, buffer, received);
break; break;
#ifdef ASYN_VERSION // asyn >= 4.14
case asynDisconnected:
error("%s: asynDisconnected in read: %s\n",
clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault);
return;
case asynDisabled:
error("%s: asynDisconnected in read: %s\n",
clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault);
return;
#endif
default:
error("%s: unknown asyn error in read: %s\n",
clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault);
return;
} }
if (!readMore) break; if (!readMore) break;
if (readMore > 0) if (readMore > 0)
@ -921,7 +1039,7 @@ readHandler()
bytesToRead = inputBuffer.capacity(); bytesToRead = inputBuffer.capacity();
} }
debug("AsynDriverInterface::readHandler(%s) " debug("AsynDriverInterface::readHandler(%s) "
"readMore=%ld bytesToRead=%d\n", "readMore=%ld bytesToRead=%ld\n",
clientName(), readMore, bytesToRead); clientName(), readMore, bytesToRead);
pasynUser->timeout = readTimeout; pasynUser->timeout = readTimeout;
waitForReply = false; waitForReply = false;
@ -944,33 +1062,16 @@ void intrCallbackOctet(void* /*pvt*/, asynUser *pasynUser,
// Problems here: // Problems here:
// 1. We get this message too when we are the poller. // 1. We get this message too when we are the poller.
// Thus we have to ignore what we got from polling. // Thus we have to ignore what we got from polling.
// 2. We get this message multiple times when original reader // 2. eomReason=ASYN_EOM_CNT when message was too long for
// reads in chunks.
// 3. eomReason=ASYN_EOM_CNT when message was too long for
// internal buffer of asynDriver. // internal buffer of asynDriver.
if (!interruptAccept) return; // too early to process records if (!interruptAccept) return; // too early to process records
debug("AsynDriverInterface::intrCallbackOctet(%s) ioAction = %s\n", interface->asynReadHandler(data, numchars, eomReason);
interface->clientName(), ioActionStr[interface->ioAction]);
if (interface->ioAction == AsyncRead ||
interface->ioAction == AsyncReadMore)
{
interface->asynReadHandler(data, numchars, eomReason);
}
else
{
#ifndef NO_TEMPORARY
debug("AsynDriverInterface::intrCallbackOctet(%s, buffer=\"%s\", "
"received=%d eomReason=%s) ioAction=%s\n",
interface->clientName(), StreamBuffer(data, numchars).expand()(),
numchars, eomReasonStr[eomReason&0x7], ioActionStr[interface->ioAction]);
#endif
}
} }
// get asynchronous input // get asynchronous input
void AsynDriverInterface:: void AsynDriverInterface::
asynReadHandler(const char *buffer, int received, int eomReason) asynReadHandler(const char *buffer, size_t received, int eomReason)
{ {
// Due to multithreading, timerExpired() might come at any time. // Due to multithreading, timerExpired() might come at any time.
// It queues the next poll request which is now useless because // It queues the next poll request which is now useless because
@ -986,9 +1087,9 @@ asynReadHandler(const char *buffer, int received, int eomReason)
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("AsynDriverInterface::asynReadHandler(%s, buffer=\"%s\", " debug("AsynDriverInterface::asynReadHandler(%s, buffer=\"%s\", "
"received=%d eomReason=%s) ioAction=%s\n", "received=%ld eomReason=%s) ioAction=%s\n",
clientName(), StreamBuffer(buffer, received).expand()(), clientName(), StreamBuffer(buffer, received).expand()(),
received, eomReasonStr[eomReason&0x7], ioActionStr[ioAction]); (long)received, eomReasonStr[eomReason&0x7], ioActionStr[ioAction]);
#endif #endif
ioAction = None; ioAction = None;
@ -1044,7 +1145,7 @@ asynReadHandler(const char *buffer, int received, int eomReason)
// set by stream, cut it off now. // set by stream, cut it off now.
status = pasynOctet->getInputEos(pvtOctet, status = pasynOctet->getInputEos(pvtOctet,
pasynUser, deveos, sizeof(deveos)-1, &deveoslen); pasynUser, deveos, sizeof(deveos)-1, &deveoslen);
if (status == asynSuccess && received >= deveoslen) if (status == asynSuccess && (long)received >= (long)deveoslen)
{ {
int i; int i;
for (i = 1; i <= deveoslen; i++) for (i = 1; i <= deveoslen; i++)

View File

@ -65,7 +65,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
{ {
// find number of significant bits // find number of significant bits
prec = sizeof (value) * 8; prec = sizeof (value) * 8;
while (prec && (value & (1 << (prec - 1))) == 0) prec--; while (prec && (value & (1L << (prec - 1))) == 0) prec--;
} }
if (prec == 0) prec++; // print at least one bit if (prec == 0) prec++; // print at least one bit
int width = prec; int width = prec;
@ -75,7 +75,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
char fill = (format.flags & zero_flag) ? zero : ' '; char fill = (format.flags & zero_flag) ? zero : ' ';
if (format.flags & alt_flag) if (format.flags & alt_flag)
{ {
// little endian (least significan bit first) // little endian (least significant bit first)
if (!(format.flags & left_flag)) if (!(format.flags & left_flag))
{ {
// pad left // pad left
@ -99,7 +99,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
} }
else else
{ {
// big endian (most significan bit first) // big endian (most significant bit first)
if (!(format.flags & left_flag)) if (!(format.flags & left_flag))
{ {
// pad left // pad left
@ -111,7 +111,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
} }
while (prec--) while (prec--)
{ {
output.append((value & (1 << prec)) ? one : zero); output.append((value & (1L << prec)) ? one : zero);
width--; width--;
} }
while (width--) while (width--)

View File

@ -13,7 +13,7 @@ RECORDS += longout longin
RECORDS += stringout stringin RECORDS += stringout stringin
RECORDS += waveform RECORDS += waveform
RECORDS += calcout RECORDS += calcout
#RECORDS += aai aao RECORDS += aai aao
# Do you have synApps and want support for scalcout? # Do you have synApps and want support for scalcout?
# Then define CALC or SYNAPPS in your RELEASE file # Then define CALC or SYNAPPS in your RELEASE file
@ -22,6 +22,7 @@ RECORDS += calcout
# you have to build the 'sscan' and 'genSub' # you have to build the 'sscan' and 'genSub'
# modules before building 'calc'. # modules before building 'calc'.
# See doc/scalcout.html for a required fix in scalcout. # See doc/scalcout.html for a required fix in scalcout.
SYNAPPS_RECORDS += scalcout SYNAPPS_RECORDS += scalcout
# You may add more bus interfaces # You may add more bus interfaces
@ -29,7 +30,9 @@ SYNAPPS_RECORDS += scalcout
# $(BUS)Interface.cc # $(BUS)Interface.cc
# asynDriver interface is added automatically # asynDriver interface is added automatically
# if ASYN is defined in your RELEASE file. # if ASYN is defined in your RELEASE file.
# BUSSES += Debug
BUSSES += Debug
BUSSES += Dummy
# You may add more format converters # You may add more format converters
# This requires the naming convention # This requires the naming convention
@ -38,10 +41,11 @@ SYNAPPS_RECORDS += scalcout
FORMATS += Enum FORMATS += Enum
FORMATS += BCD FORMATS += BCD
FORMATS += Raw FORMATS += Raw
FORMATS += RawFloat
FORMATS += Binary FORMATS += Binary
FORMATS += Checksum FORMATS += Checksum
FORMATS += Exponential FORMATS += MantissaExponent
FORMATS += RawFloat FORMATS += Timestamp
# Want Perl regular expression matching? # Want Perl regular expression matching?
# If PCRE is installed at the same location for all # If PCRE is installed at the same location for all
@ -66,10 +70,6 @@ endif
# by "static IoccrfReg iocshReg;" # by "static IoccrfReg iocshReg;"
# LOADABLE_MODULE = YES # LOADABLE_MODULE = YES
# Want to add some memory tracing
# to find memory leaks?
# USE_MEMGUARD = YES
# Sources of Stream Kernel # Sources of Stream Kernel
# Do not modify # Do not modify

View File

@ -488,6 +488,9 @@ static checksum checksumMap[] =
{"crc16r", crc_0x8005_r, 0x0000, 0x0000, 2}, // 0xBB3D {"crc16r", crc_0x8005_r, 0x0000, 0x0000, 2}, // 0xBB3D
{"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
{"crc16c", crc_0x1021, 0x0000, 0x0000, 2}, // 0x31C3
{"xmodem", crc_0x1021, 0x0000, 0x0000, 2}, // 0x31C3
{"crc32", crc_0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFC891918 {"crc32", crc_0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFC891918
{"crc32r", crc_0x04C11DB7_r, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xCBF43926 {"crc32r", crc_0x04C11DB7_r, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xCBF43926
{"jamcrc", crc_0x04C11DB7_r, 0xFFFFFFFF, 0x00000000, 4}, // 0x340BC6D9 {"jamcrc", crc_0x04C11DB7_r, 0xFFFFFFFF, 0x00000000, 4}, // 0x340BC6D9

76
src/DummyInterface.cc Normal file
View File

@ -0,0 +1,76 @@
/***************************************************************
* StreamDevice Support *
* *
* (C) 2011 Dirk Zimoch (dirk.zimoch@psi.ch) *
* *
* This is the interface to a "dummy" bus driver for *
* StreamDevice. It does not provide any I/O functionality. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include "StreamBusInterface.h"
#include "StreamError.h"
#include "StreamBuffer.h"
class DummyInterface : StreamBusInterface
{
DummyInterface(Client* client);
// StreamBusInterface methods
bool lockRequest(unsigned long lockTimeout_ms);
bool unlock();
protected:
~DummyInterface();
public:
// static creator method
static StreamBusInterface* getBusInterface(Client* client,
const char* busname, int addr, const char* param);
};
RegisterStreamBusInterface(DummyInterface);
DummyInterface::
DummyInterface(Client* client) : StreamBusInterface(client)
{
// Nothing to do
}
DummyInterface::
~DummyInterface()
{
// Nothing to do
}
StreamBusInterface* DummyInterface::
getBusInterface(Client* client,
const char* busname, int addr, const char*)
{
if (strcmp(busname, "dummy") == 0)
{
DummyInterface* interface = new DummyInterface(client);
return interface;
}
return NULL;
}
bool DummyInterface::
lockRequest(unsigned long lockTimeout_ms)
{
return false;
}
bool DummyInterface::
unlock()
{
return false;
}

View File

@ -21,6 +21,7 @@
#include "StreamFormatConverter.h" #include "StreamFormatConverter.h"
#include "StreamError.h" #include "StreamError.h"
#include "StreamProtocol.h" #include "StreamProtocol.h"
#include <stdlib.h>
// Enum %{string0|string1|...} // Enum %{string0|string1|...}
@ -31,44 +32,62 @@ class EnumConverter : public StreamFormatConverter
int scanLong(const StreamFormat&, const char*, long&); int scanLong(const StreamFormat&, const char*, long&);
}; };
// info format: <numEnums><index><string>0<index><string>0...
int EnumConverter:: int EnumConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool) const char*& source, bool)
{ {
if (fmt.flags & (left_flag|sign_flag|space_flag|zero_flag|alt_flag)) if (fmt.flags & (left_flag|sign_flag|space_flag|zero_flag))
{ {
error("Use of modifiers '-', '+', ' ', '0', '#'" error("Use of modifiers '-', '+', ' ', '0' "
"not allowed with %%{ conversion\n"); "not allowed with %%{ conversion\n");
return false; return false;
} }
int i = info.length(); // put maxValue here later long numEnums = 0;
info.append('\0'); int n = info.length(); // put numEnums here later
int maxValue = 0; info.append(&numEnums, sizeof(numEnums));
long index = 0;
int i = 0;
i = info.length(); // put index here later
info.append(&index, sizeof(index));
while (*source) while (*source)
{ {
switch (*source) if (*source == '=' && (fmt.flags & alt_flag))
{ {
case '|': char* p;
info.append('\0'); index = strtol(++source, &p, 0);
if (++maxValue > 255) if (p == source || (*p != '|' && *p != '}'))
{ {
error("Too many enums (max 256)\n"); error("Integer expected after '=' "
return false; "in %%{ format conversion\n");
} return false;
break; }
case '}': memcpy(info(i), &index, sizeof(index));
source++; source = p;
info.append('\0'); }
info[i] = maxValue; if (*source == '|' || *source == '}')
debug("EnumConverter::parse %d choices: %s\n", {
maxValue+1, info.expand(i+1)()); numEnums++;
return enum_format; info.append('\0');
case esc:
info.append(*source++); if (*source++ == '}')
default: {
info.append(*source); memcpy(info(n), &numEnums, sizeof(numEnums));
debug("EnumConverter::parse %ld choices: %s\n",
numEnums, info.expand()());
return enum_format;
}
index ++;
i = info.length();
info.append(&index, sizeof(index));
}
else
{
if (*source == esc)
info.append(*source++);
info.append(*source++);
} }
source++;
} }
error("Missing '}' after %%{ format conversion\n"); error("Missing '}' after %%{ format conversion\n");
return false; return false;
@ -77,14 +96,10 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
bool EnumConverter:: bool EnumConverter::
printLong(const StreamFormat& fmt, StreamBuffer& output, long value) printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
long maxValue = fmt.info[0]; // number of enums const char* s = fmt.info;
const char* s = fmt.info+1; // first enum string long numEnums = extract<long>(s);
if (value < 0 || value > maxValue) long index = extract<long>(s);
{ while (numEnums-- && (value != index))
error("Value %li out of range [0...%li]\n", value, maxValue);
return false;
}
while (value--)
{ {
while(*s) while(*s)
{ {
@ -92,6 +107,12 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
s++; s++;
} }
s++; s++;
index = extract<long>(s);
}
if (numEnums == -1)
{
error("Value %li not found in enum set\n", value);
return false;
} }
while(*s) while(*s)
{ {
@ -106,14 +127,16 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
debug("EnumConverter::scanLong(%%%c, \"%s\")\n", debug("EnumConverter::scanLong(%%%c, \"%s\")\n",
fmt.conv, input); fmt.conv, input);
long maxValue = fmt.info[0]; // number of enums const char* s = fmt.info;
const char* s = fmt.info+1; // first enum string long numEnums = extract<long>(s);
long index;
int length; int length;
long val;
bool match; bool match;
for (val = 0; val <= maxValue; val++) while (numEnums--)
{ {
debug("EnumConverter::scanLong: check #%ld \"%s\"\n", val, s); index = extract<long>(s);
debug("EnumConverter::scanLong: check #%ld \"%s\"\n", index, s);
length = 0; length = 0;
match = true; match = true;
while(*s) while(*s)
@ -129,8 +152,8 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
} }
if (match) if (match)
{ {
debug("EnumConverter::scanLong: value %ld matches\n", val); debug("EnumConverter::scanLong: value %ld matches\n", index);
value = val; value = index;
return length; return length;
} }
s++; s++;

View File

@ -65,18 +65,13 @@ ifdef PCRE
LIB_LIBS += pcre LIB_LIBS += pcre
else else
ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0) ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0)
LIB_SYS_LIBS += pcre LIB_SYS_LIBS_DEFAULT += pcre
LIB_SYS_LIBS_WIN32 += $(PCRE_LIB)\\pcre
SHRLIB_DEPLIB_DIRS += $(PCRE_LIB) SHRLIB_DEPLIB_DIRS += $(PCRE_LIB)
endif endif
endif endif
LIB_LIBS += Com dbIoc dbStaticIoc registryIoc iocsh LIB_LIBS += $(EPICS_BASE_IOC_LIBS)
ifeq ($(USE_MEMGUARD),YES)
# memguard looks for memory leaks (gcc only)
CPPFLAGS += -include ../memguard.h
LIB_SRCS += memguard.cc
endif
INC += devStream.h INC += devStream.h
@ -92,22 +87,11 @@ FORCE:
StreamCore$(OBJ): streamReferences StreamCore$(OBJ): streamReferences
streamReferences: ../CONFIG_STREAM streamReferences: ../CONFIG_STREAM
@for i in $(BUSSES); \ $(PERL) ../makeref.pl Interface $(BUSSES) > $@
do echo "extern void* ref_$${i}Interface;"; \ $(PERL) ../makeref.pl Converter $(FORMATS) >> $@
echo "void* p$$i = ref_$${i}Interface;"; \
done > $@
@for i in $(FORMATS); \
do echo "extern void* ref_$${i}Converter;"; \
echo "void* p$$i = ref_$${i}Converter;"; \
done >> $@
# create stream.dbd from all RECORDS # create stream.dbd from all RECORDS
$(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM $(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM
@for r in $(RECORDS); \ $(PERL) ../makedbd.pl $(RECORDS) > $@
do echo "device($$r,INST_IO,dev$${r}Stream,\"stream\")"; \
done > $@
@echo "driver(stream)" >> $@
@echo "variable(streamDebug, int)" >> $@
@echo "registrar(streamRegistrar)" >> $@
endif endif

View File

@ -1,8 +1,7 @@
/*************************************************************** /***************************************************************
* StreamDevice Support * * StreamDevice Support *
* * * *
* (C) 1999 Dirk Zimoch (zimoch@delta.uni-dortmund.de) * * (C) 2008 Dirk Zimoch (dirk.zimoch@psi.ch) *
* (C) 2007 Dirk Zimoch (dirk.zimoch@psi.ch) *
* * * *
* This is a custom exponential format converter for * * This is a custom exponential format converter for *
* StreamDevice. * * StreamDevice. *
@ -32,26 +31,26 @@
// But why not +11000-04 ? // But why not +11000-04 ?
// For writing, I chose the following convention: // For writing, I chose the following convention:
// Format precision defines number of digits in mantissa // Format precision defines number of digits in mantissa
// Number of digits in exponent is at least 2
// No leading '0' in mantissa (except for 0.0 of course) // No leading '0' in mantissa (except for 0.0 of course)
// Number of digits in exponent is at least 2
// Format flags +, -, and space are supported in the usual way // Format flags +, -, and space are supported in the usual way
// Flags #, 0 are not supported // Flags #, 0 are not supported
class ExponentialConverter : public StreamFormatConverter class MantissaExponentConverter : public StreamFormatConverter
{ {
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual int scanDouble(const StreamFormat&, const char*, double&); virtual int scanDouble(const StreamFormat&, const char*, double&);
virtual bool printDouble(const StreamFormat&, StreamBuffer&, double); virtual bool printDouble(const StreamFormat&, StreamBuffer&, double);
}; };
int ExponentialConverter:: int MantissaExponentConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat&, StreamBuffer&,
const char*& source, bool scanFormat) const char*&, bool)
{ {
return double_format; return double_format;
} }
int ExponentialConverter:: int MantissaExponentConverter::
scanDouble(const StreamFormat& fmt, const char* input, double& value) scanDouble(const StreamFormat& fmt, const char* input, double& value)
{ {
int mantissa; int mantissa;
@ -61,11 +60,11 @@ scanDouble(const StreamFormat& fmt, const char* input, double& value)
sscanf(input, "%d%d%n", &mantissa, &exponent, &length); sscanf(input, "%d%d%n", &mantissa, &exponent, &length);
if (fmt.flags & skip_flag) return length; if (fmt.flags & skip_flag) return length;
if (length == -1) return -1; if (length == -1) return -1;
value = (double)(mantissa) * pow(10, exponent); value = (double)(mantissa) * pow(10.0, exponent);
return length; return length;
} }
bool ExponentialConverter:: bool MantissaExponentConverter::
printDouble(const StreamFormat& fmt, StreamBuffer& output, double value) printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
{ {
// Have to divide value into mantissa and exponent // Have to divide value into mantissa and exponent
@ -73,21 +72,23 @@ printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
// number of characters in exponent is at least 2 // number of characters in exponent is at least 2
int spaces; int spaces;
StreamBuffer buf; StreamBuffer buf;
int prec = fmt.prec;
buf.printf("%.*e", fmt.prec-1, fabs(value)); if (prec < 1) prec = 6;
buf.printf("%.*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);
spaces = fmt.width-buf.length(); spaces = fmt.width-buf.length();
if (fmt.flags & (space_flag|sign_flag) || value < 0) spaces--; if (fmt.flags & (space_flag|sign_flag) || value < 0.0) spaces--;
if (spaces < 0) spaces = 0; if (spaces < 0) spaces = 0;
if (!(fmt.flags & left_flag)) if (!(fmt.flags & left_flag))
output.append(' ', spaces); output.append(' ', spaces);
if (fmt.flags & (space_flag|sign_flag) == space_flag && value >= 0) if ((fmt.flags & (space_flag|sign_flag)) == space_flag && value >= 0.0)
output.append(' '); output.append(' ');
if (fmt.flags & sign_flag && value >= 0) if (fmt.flags & sign_flag && value >= 0.0)
output.append('+'); output.append('+');
if (value <= 0) if (value < 0.0)
output.append('-'); output.append('-');
output.append(buf); output.append(buf);
if (fmt.flags & left_flag) if (fmt.flags & left_flag)
@ -95,5 +96,5 @@ printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
return true; return true;
} }
RegisterConverter (ExponentialConverter, "m"); RegisterConverter (MantissaExponentConverter, "m");

View File

@ -40,10 +40,12 @@ parse(const StreamFormat&, StreamBuffer&,
bool RawConverter:: bool RawConverter::
printLong(const StreamFormat& format, StreamBuffer& output, long value) printLong(const StreamFormat& format, StreamBuffer& output, long value)
{ {
int prec = format.prec; // number of bytes from value int prec = format.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 (format.width > width) width = format.width; if (format.width > width) width = format.width;
char byte = 0; char byte = 0;
if (format.flags & alt_flag) // little endian (lsb first) if (format.flags & alt_flag) // little endian (lsb first)
{ {

View File

@ -21,21 +21,7 @@
#include "StreamFormatConverter.h" #include "StreamFormatConverter.h"
#include "StreamError.h" #include "StreamError.h"
#ifdef vxWorks static int endian = 0;
#include "vxWorks.h"
#define __BYTE_ORDER _BYTE_ORDER
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
#define __BIG_ENDIAN _BIG_ENDIAN
#else
// Let's hope all other architectures have endian.h
#include "endian.h"
#endif
#ifndef __BYTE_ORDER
#error define __BYTE_ORDER as __LITTLE_ENDIAN or __BIG_ENDIAN
#endif
#if (__BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __BIG_ENDIAN)
// Raw Float Converter %R // Raw Float Converter %R
@ -50,6 +36,17 @@ int RawFloatConverter::
parse(const StreamFormat& format, StreamBuffer&, parse(const StreamFormat& format, StreamBuffer&,
const char*&, bool) const char*&, bool)
{ {
// Find out byte order
if (!endian) {
union {long l; char c [sizeof(long)];} u;
u.l=1;
if (u.c[0]) { endian = 1234;} // little endian
else if (u.c[sizeof(long)-1]) { endian = 4321;} // big endian
else {
error ("Cannot find out byte order for %%R format.\n");
return false;
}
}
// Assume IEEE formats with 4 or 8 bytes (default: 4) // Assume IEEE formats with 4 or 8 bytes (default: 4)
if (format.width==0 || format.width==4 || format.width==8) if (format.width==0 || format.width==4 || format.width==8)
return double_format; return double_format;
@ -67,24 +64,19 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
float fval; float fval;
char bytes[8]; char bytes[8];
} buffer; } buffer;
nbOfBytes = format.width; nbOfBytes = format.width;
if (nbOfBytes == 0) if (nbOfBytes == 0)
nbOfBytes = 4; nbOfBytes = 4;
if (nbOfBytes == 4) if (nbOfBytes == 4)
buffer.fval = value; buffer.fval = (float)value;
else else
buffer.dval = value; buffer.dval = value;
#if (__BYTE_ORDER == __BIG_ENDIAN) if (!(format.flags & alt_flag) ^ (endian == 4321))
bool swap = format.flags & alt_flag;
#else
bool swap = !(format.flags & alt_flag);
#endif
if (swap)
{ {
// swap if byte orders differ
for (n = nbOfBytes-1; n >= 0; n--) for (n = nbOfBytes-1; n >= 0; n--)
{ {
output.append(buffer.bytes[n]); output.append(buffer.bytes[n]);
@ -94,7 +86,7 @@ printDouble(const StreamFormat& format, StreamBuffer& output, double value)
{ {
output.append(buffer.bytes[n]); output.append(buffer.bytes[n]);
} }
} }
return true; return true;
} }
@ -109,7 +101,7 @@ scanDouble(const StreamFormat& format, const char* input, double& value)
float fval; float fval;
char bytes[8]; char bytes[8];
} buffer; } buffer;
nbOfBytes = format.width; nbOfBytes = format.width;
if (nbOfBytes == 0) if (nbOfBytes == 0)
nbOfBytes = 4; nbOfBytes = 4;
@ -118,15 +110,10 @@ scanDouble(const StreamFormat& format, const char* input, double& value)
{ {
return(nbOfBytes); // just skip input return(nbOfBytes); // just skip input
} }
#if (__BYTE_ORDER == __BIG_ENDIAN)
bool swap = format.flags & alt_flag;
#else
bool swap = !(format.flags & alt_flag);
#endif
if (swap) if (!(format.flags & alt_flag) ^ (endian == 4321))
{ {
// swap if byte orders differ
for (n = nbOfBytes-1, i = 0; n >= 0; n--, i++) for (n = nbOfBytes-1, i = 0; n >= 0; n--, i++)
{ {
buffer.bytes[n] = input[i]; buffer.bytes[n] = input[i];
@ -140,12 +127,10 @@ scanDouble(const StreamFormat& format, const char* input, double& value)
if (nbOfBytes == 4) if (nbOfBytes == 4)
value = buffer.fval; value = buffer.fval;
else else
value = buffer.dval; value = buffer.dval;
return nbOfBytes; return nbOfBytes;
} }
RegisterConverter (RawFloatConverter, "R"); RegisterConverter (RawFloatConverter, "R");
#endif /* known byte order */

View File

@ -112,7 +112,7 @@ scanString(const StreamFormat& fmt, const char* input,
if (!(fmt.flags & sign_flag)) { if (!(fmt.flags & sign_flag)) {
debug("Matching string \"%s\" too long (%d>%d bytes)\n", debug("Matching string \"%s\" too long (%d>%d bytes)\n",
StreamBuffer(input+ovector[subexpr*2], len).expand()(), StreamBuffer(input+ovector[subexpr*2], len).expand()(),
len, maxlen-1); (int)len, (int)maxlen-1);
return -1; return -1;
} }
len = maxlen-1; len = maxlen-1;

View File

@ -46,7 +46,7 @@ init(const void* s, long minsize)
else else
{ {
// clear local buffer // clear local buffer
memset(buffer+minsize, 0, cap-minsize); memset(buffer, 0, cap);
} }
if (s) { if (s) {
len = minsize; len = minsize;
@ -54,6 +54,13 @@ init(const void* s, long minsize)
} }
} }
// How the buffer looks like:
// |----free-----|####used####|-------free-------|
///|<--- offs -->|<-- len --->|<- cap-offs-len ->|
// 0 offs offs+len cap
// |<-------------- minsize --------------->
void StreamBuffer:: void StreamBuffer::
grow(long minsize) grow(long minsize)
{ {
@ -102,7 +109,7 @@ grow(long minsize)
memset(newbuffer+len, 0, newcap-len); memset(newbuffer+len, 0, newcap-len);
if (buffer != local) if (buffer != local)
{ {
delete buffer; delete [] buffer;
} }
buffer = newbuffer; buffer = newbuffer;
cap = newcap; cap = newcap;
@ -135,7 +142,7 @@ find(const void* m, long size, long start) const
start += len; start += len;
if (start < 0) start = 0; if (start < 0) start = 0;
} }
if (start >= len-size+1) return -1; // find nothing after end if (start+size > len) return -1; // find nothing after end
if (!m || size <= 0) return start; // find empty string at start if (!m || size <= 0) return start; // find empty string at start
const char* s = static_cast<const char*>(m); const char* s = static_cast<const char*>(m);
char* b = buffer+offs; char* b = buffer+offs;
@ -143,12 +150,12 @@ find(const void* m, long size, long start) const
long i; long 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))))
{ {
i = 1; for (i = 1; i < size; i++)
while (p[i] == s[i])
{ {
if (++i >= size) return p-b; if (p[i] != s[i]) goto next;
} }
p++; return p-b;
next: p++;
} }
return -1; return -1;
} }
@ -212,7 +219,7 @@ replace(long remstart, long remlen, const void* ins, long inslen)
memset(newbuffer+newlen, 0, newcap-newlen); memset(newbuffer+newlen, 0, newcap-newlen);
if (buffer != local) if (buffer != local)
{ {
delete buffer; delete [] buffer;
} }
buffer = newbuffer; buffer = newbuffer;
cap = newcap; cap = newcap;
@ -266,9 +273,18 @@ StreamBuffer StreamBuffer::expand(long start, long length) const
if (start < 0) if (start < 0)
{ {
start += len; start += len;
if (start < 0) start = 0;
} }
end = length >= 0 ? start+length : len; if (length < 0)
{
start += length;
length = -length;
}
if (start < 0)
{
length += start;
start = 0;
}
end = start+length;
if (end > len) end = len; if (end > len) end = len;
StreamBuffer result((end-start)*2); StreamBuffer result((end-start)*2);
start += offs; start += offs;

View File

@ -35,26 +35,30 @@ class StreamBuffer
long offs; long offs;
char* buffer; char* buffer;
void grow(long); void init(const void* s, long minsize);
void init(const void*, long);
void check(long size) void check(long size)
{if (len+offs+size >= cap) grow(len+size);} {if (len+offs+size >= cap) grow(len+size);}
void grow(long minsize);
public: public:
// Hints: // Hints:
// * Any index parameter (long) can be negative // * Any index parameter (long) 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
// * Any returned char* pointer becomes invalid when // * Any returned char* pointer becomes invalid when
// the StreamBuffer is modified. // the StreamBuffer is modified.
// * End of StreamBuffer always contains 0x00 bytes
// * Deleting from start and clearing is fast
StreamBuffer() StreamBuffer()
{init(NULL, 0);} {init(NULL, 0);}
StreamBuffer(const void*s, long size) StreamBuffer(const void* s, long size)
{init(s, size);} {init(s, size);}
StreamBuffer(const char*s) StreamBuffer(const char* s)
{init(s, s?strlen(s):0);} {init(s, s?strlen(s):0);}
StreamBuffer(const StreamBuffer& s) StreamBuffer(const StreamBuffer& s)
@ -68,10 +72,10 @@ public:
// operator (): get char* pointing to index // operator (): get char* pointing to index
const char* operator()(long index=0) const const char* operator()(long index=0) const
{buffer[offs+len]=0; return buffer+offs+(index<0?index+len:index);} {return buffer+offs+(index<0?index+len:index);}
char* operator()(long index=0) char* operator()(long index=0)
{buffer[offs+len]=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[](long index) const
@ -103,11 +107,16 @@ 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(long size)
{grow(size); char* p=buffer+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, long count=1) StreamBuffer& append(char c)
{check(count); while(count-->0) buffer[offs+len++]=c; return *this;} {check(1); buffer[offs+len++]=c; return *this;}
StreamBuffer& append(char c, long count)
{if (count < 0) truncate(count);
else {check(count); memset(buffer+offs+len, c, count); len+=count;}
return *this;}
StreamBuffer& append(const void* s, long size); StreamBuffer& append(const void* s, long size);
@ -116,6 +125,16 @@ 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
StreamBuffer& operator+=(char c)
{return append(c);}
StreamBuffer& operator+=(const char* s)
{return append(s);}
StreamBuffer& operator+=(const StreamBuffer& 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, long size)
@ -127,7 +146,7 @@ public:
StreamBuffer& set(const StreamBuffer& s) StreamBuffer& set(const StreamBuffer& s)
{clear(); return append(s.buffer+s.offs, s.len);} {clear(); return append(s.buffer+s.offs, s.len);}
// operator =: alias for set // operator = alias for set
StreamBuffer& operator=(const char* s) StreamBuffer& operator=(const char* s)
{return set(s);} {return set(s);}
@ -144,15 +163,16 @@ public:
StreamBuffer& replace(long pos, long length, const StreamBuffer& s) StreamBuffer& replace(long pos, long length, const StreamBuffer& s)
{return replace(pos, length, s.buffer+s.offs, s.len);} {return replace(pos, length, s.buffer+s.offs, s.len);}
// replace: delete part of buffer // remove: delete from start/pos
StreamBuffer& remove(long pos, long length) StreamBuffer& remove(long pos, long length)
{return replace(pos, length, NULL, 0);} {return replace(pos, length, NULL, 0);}
// remove from start: no memset, no function call, fast!
StreamBuffer& remove(long length) StreamBuffer& remove(long length)
{if (length>len) length=len; {if (length>len) length=len;
offs+=length; len-=length; return *this;} offs+=length; len-=length; return *this;}
// replace: delete end of buffer // truncate: delete end of buffer
StreamBuffer& truncate(long pos) StreamBuffer& truncate(long pos)
{return replace(pos, len, NULL, 0);} {return replace(pos, len, NULL, 0);}
@ -188,17 +208,20 @@ public:
long int find(const StreamBuffer& s, long start=0) const long int find(const StreamBuffer& s, long start=0) const
{return find(s.buffer+s.offs, s.len, start);} {return find(s.buffer+s.offs, s.len, start);}
// equals: returns true if first size bytes are equal // startswith: returns true if first size bytes are equal
bool equals(const void* s, long size) const bool startswith(const void* s, long size) const
{return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;} {return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;}
// equals: returns true if first string is equal (empty string match) // startswith: returns true if first string is equal (empty string matches)
bool equals(const char* s) const bool startswith(const char* s) const
{return len ? strcmp(buffer+offs, s) == 0 : !s || !*s;} {return len ? strcmp(buffer+offs, s) == 0 : !s || !*s;}
// 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=0, long length=-1) const; StreamBuffer expand(long start, long length) const;
StreamBuffer expand(long start=0) const
{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
// before and after the real data. Uses colours. // before and after the real data. Uses colours.

View File

@ -39,7 +39,6 @@ static char* printCommands(StreamBuffer& buffer, const char* c)
{ {
unsigned long timeout; unsigned long timeout;
unsigned long eventnumber; unsigned long eventnumber;
unsigned short cmdlen;
while (1) while (1)
{ {
switch(*c++) switch(*c++)
@ -67,7 +66,6 @@ static char* printCommands(StreamBuffer& buffer, const char* c)
break; break;
case exec_cmd: case exec_cmd:
buffer.append(" exec \""); buffer.append(" exec \"");
cmdlen = extract<unsigned short>(c);
c = StreamProtocolParser::printString(buffer, c); c = StreamProtocolParser::printString(buffer, c);
buffer.append("\";\n"); buffer.append("\";\n");
break; break;
@ -325,7 +323,7 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
{ {
if (!busSupportsEvent()) if (!busSupportsEvent())
{ {
protocol->errorMsg(getLineNumber(command), error(getLineNumber(command), protocol->filename(),
"Events not supported by businterface.\n"); "Events not supported by businterface.\n");
return false; return false;
} }
@ -339,7 +337,7 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
} }
if (*args != ')') if (*args != ')')
{ {
protocol->errorMsg(getLineNumber(command), error(getLineNumber(command), protocol->filename(),
"Expect ')' instead of: '%s'\n", args); "Expect ')' instead of: '%s'\n", args);
return false; return false;
} }
@ -360,7 +358,7 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
{ {
buffer.append(exec_cmd); buffer.append(exec_cmd);
if (!protocol->compileString(buffer, args, if (!protocol->compileString(buffer, args,
NoFormat, this)) PrintFormat, this))
{ {
return false; return false;
} }
@ -383,13 +381,29 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
return true; return true;
} }
protocol->errorMsg(getLineNumber(command), error(getLineNumber(command), protocol->filename(),
"Unknown command name '%s'\n", command); "Unknown command name '%s'\n", command);
return false; return false;
} }
// Run the protocol // Run the protocol
// Input and events may come asynchonously from the bus driver
// Especially in the sequence 'out "request"; in "reply";' the
// reply can come before the 'in' command has actually started.
// For asyncronous protocols, input can come at any time.
// Thus, we must always accept input and event while the protocol
// is running or when asyncronous mode is active.
// Early input and event must be buffered until 'in' or 'event'
// start. An 'out' command must discard any early input to avoid
// problems with late input from aborted protocols.
// Async mode ends on Abort or Error or if another command comes
// after the asynchronous 'in' command.
// Input can be discarded when it is not accepted any more, i.e.
// at the end of syncronous protocols and when an asynchronous
// mode ends (but not when 'in'-only protocol finishes normally).
bool StreamCore:: bool StreamCore::
startProtocol(StartMode startMode) startProtocol(StartMode startMode)
{ {
@ -443,7 +457,7 @@ finishProtocol(ProtocolResult status)
flags & WaitPending ? "timerCallback()" : ""); flags & WaitPending ? "timerCallback()" : "");
status = Fault; status = Fault;
} }
flags &= ~(AcceptInput|AcceptEvent); //// flags &= ~(AcceptInput|AcceptEvent);
if (runningHandler) if (runningHandler)
{ {
// get original error status // get original error status
@ -488,6 +502,7 @@ finishProtocol(ProtocolResult status)
break; break;
default: default:
// get rid of all the rubbish whe might have collected // get rid of all the rubbish whe might have collected
unparsedInput = false;
inputBuffer.clear(); inputBuffer.clear();
handler = NULL; handler = NULL;
} }
@ -518,6 +533,7 @@ finishProtocol(ProtocolResult status)
flags &= ~BusOwner; flags &= ~BusOwner;
} }
busFinish(); busFinish();
flags &= ~(AcceptInput|AcceptEvent);
protocolFinishHook(status); protocolFinishHook(status);
} }
@ -539,16 +555,16 @@ evalCommand()
switch (*commandIndex++) switch (*commandIndex++)
{ {
case out_cmd: case out_cmd:
flags &= ~(AcceptInput|AcceptEvent); //// flags &= ~(AcceptInput|AcceptEvent);
return evalOut(); return evalOut();
case in_cmd: case in_cmd:
flags &= ~AcceptEvent; //// flags &= ~AcceptEvent;
return evalIn(); return evalIn();
case wait_cmd: case wait_cmd:
flags &= ~(AcceptInput|AcceptEvent); //// flags &= ~(AcceptInput|AcceptEvent);
return evalWait(); return evalWait();
case event_cmd: case event_cmd:
flags &= ~AcceptInput; //// flags &= ~AcceptInput;
return evalEvent(); return evalEvent();
case exec_cmd: case exec_cmd:
return evalExec(); return evalExec();
@ -573,9 +589,9 @@ evalCommand()
bool StreamCore:: bool StreamCore::
evalOut() evalOut()
{ {
inputBuffer.clear(); // flush all unread input // flush all unread input
unparsedInput = false; unparsedInput = false;
outputLine.clear(); inputBuffer.clear();
if (!formatOutput()) if (!formatOutput())
{ {
finishProtocol(FormatError); finishProtocol(FormatError);
@ -617,13 +633,15 @@ formatOutput()
const char* fieldName = NULL; const char* fieldName = NULL;
const char* formatstring; const char* formatstring;
int formatstringlen; int formatstringlen;
outputLine.clear();
while ((command = *commandIndex++) != StreamProtocolParser::eos) while ((command = *commandIndex++) != StreamProtocolParser::eos)
{ {
switch (command) switch (command)
{ {
case StreamProtocolParser::format_field: case StreamProtocolParser::format_field:
{ {
debug("StreamCore::formatOutput(%s): StreamProtocolParser::format_field\n", debug("StreamCore::formatOutput(%s): StreamProtocolParser::redirect_format\n",
name()); name());
// code layout: // code layout:
// field <eos> addrlen AddressStructure formatstring <eos> StreamFormat [info] // field <eos> addrlen AddressStructure formatstring <eos> StreamFormat [info]
@ -632,9 +650,12 @@ formatOutput()
unsigned short addrlen = extract<unsigned short>(commandIndex); unsigned short addrlen = extract<unsigned short>(commandIndex);
fieldAddress.set(commandIndex, addrlen); fieldAddress.set(commandIndex, addrlen);
commandIndex += addrlen; commandIndex += addrlen;
goto normal_format;
} }
case StreamProtocolParser::format: case StreamProtocolParser::format:
{ {
fieldAddress.clear();
normal_format:
// code layout: // code layout:
// formatstring <eos> StreamFormat [info] // formatstring <eos> StreamFormat [info]
formatstring = commandIndex; formatstring = commandIndex;
@ -646,6 +667,7 @@ formatOutput()
} }
formatstringlen = commandIndex-formatstring; formatstringlen = commandIndex-formatstring;
commandIndex++; 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;
@ -653,6 +675,7 @@ formatOutput()
debug("StreamCore::formatOutput(%s): format = %%%s\n", debug("StreamCore::formatOutput(%s): format = %%%s\n",
name(), StreamBuffer(formatstring, formatstringlen).expand()()); name(), StreamBuffer(formatstring, formatstringlen).expand()());
#endif #endif
if (fmt.type == pseudo_format) if (fmt.type == pseudo_format)
{ {
if (!StreamFormatConverter::find(fmt.conv)-> if (!StreamFormatConverter::find(fmt.conv)->
@ -668,7 +691,7 @@ formatOutput()
if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL)) if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL))
{ {
StreamBuffer formatstr(formatstring, formatstringlen); StreamBuffer formatstr(formatstring, formatstringlen);
if (fieldName) if (fieldAddress)
error("%s: Cannot format field '%s' with '%%%s'\n", error("%s: Cannot format field '%s' with '%%%s'\n",
name(), fieldName, formatstr.expand()()); name(), fieldName, formatstr.expand()());
else else
@ -676,10 +699,12 @@ formatOutput()
name(), formatstr.expand()()); name(), formatstr.expand()());
return false; return false;
} }
fieldAddress.clear();
fieldName = NULL;
continue; continue;
} }
case StreamProtocolParser::whitespace:
outputLine.append(' ');
case StreamProtocolParser::skip:
continue;
case esc: case esc:
// escaped literal byte // escaped literal byte
command = *commandIndex++; command = *commandIndex++;
@ -701,12 +726,21 @@ printSeparator()
} }
if (!separator) return; if (!separator) return;
long i = 0; long i = 0;
if (separator[0] == ' ') i++; // ignore leading space
for (; i < separator.length(); i++) for (; i < separator.length(); i++)
{ {
if (separator[i] == StreamProtocolParser::skip) continue; // wildcard switch (separator[i])
if (separator[i] == esc) i++; // escaped literal byte {
outputLine.append(separator[i]); case StreamProtocolParser::whitespace:
outputLine.append(' '); // print single space
case StreamProtocolParser::skip:
continue;
case esc:
// escaped literal byte
i++;
default:
// literal byte
outputLine.append(separator[i]);
}
} }
} }
@ -727,6 +761,8 @@ printValue(const StreamFormat& fmt, long value)
name(), value); name(), value);
return false; return false;
} }
debug("StreamCore::printValue(%s, long): \"%s\"\n",
name(), outputLine.expand()());
return true; return true;
} }
@ -747,6 +783,8 @@ printValue(const StreamFormat& fmt, double value)
name(), value); name(), value);
return false; return false;
} }
debug("StreamCore::printValue(%s, double): \"%s\"\n",
name(), outputLine.expand()());
return true; return true;
} }
@ -768,6 +806,8 @@ printValue(const StreamFormat& fmt, char* value)
name(), buffer.expand()()); name(), buffer.expand()());
return false; return false;
} }
debug("StreamCore::printValue(%s, char*): \"%s\"\n",
name(), outputLine.expand()());
return true; return true;
} }
@ -785,10 +825,16 @@ lockCallback(StreamIoStatus status)
} }
flags &= ~LockPending; flags &= ~LockPending;
flags |= BusOwner; flags |= BusOwner;
if (status != StreamIoSuccess) switch (status)
{ {
finishProtocol(LockTimeout); case StreamIoSuccess:
return; break;
case StreamIoTimeout:
finishProtocol(LockTimeout);
return;
default:
finishProtocol(Fault);
return;
} }
flags |= WritePending; flags |= WritePending;
if (!busWriteRequest(outputLine(), outputLine.length(), writeTimeout)) if (!busWriteRequest(outputLine(), outputLine.length(), writeTimeout))
@ -907,8 +953,7 @@ readCallback(StreamIoStatus status,
#endif #endif
return 0; return 0;
} }
flags &= ~AcceptInput; //// flags &= ~AcceptInput;
unparsedInput = false;
switch (status) switch (status)
{ {
case StreamIoTimeout: case StreamIoTimeout:
@ -965,10 +1010,36 @@ readCallback(StreamIoStatus status,
if (inTerminator) if (inTerminator)
{ {
// look for terminator // look for terminator
end = inputBuffer.find(inTerminator); // performance issue for long inputs that come in chunks:
if (end >= 0) termlen = inTerminator.length(); // do not parse old chunks again or performance decreases to O(n^2)
debug("StreamCore::readCallback(%s) inTerminator %sfound\n", // but make sure to get all terminators in multi-line input
name(), end >= 0 ? "" : "not ");
long start;
if (unparsedInput)
{
// multi-line input sets 'unparsedInput' and removes the line
// remaining unparsed lines are left at start of inputBuffer
start = 0;
}
else
{
// long line does not set 'unparsedInput' but keeps
// already parsed chunks in inputBuffer
// start parsing at beginning of new data
// but beware of split terminators
start = inputBuffer.length() - size - inTerminator.length();
if (start < 0) start = 0;
}
end = inputBuffer.find(inTerminator, start);
if (end >= 0)
{
termlen = inTerminator.length();
debug("StreamCore::readCallback(%s) inTerminator %s at position %ld\n",
name(), inTerminator.expand()(), end);
} else {
debug("StreamCore::readCallback(%s) inTerminator %s not found\n",
name(), inTerminator.expand()());
}
} }
if (status == StreamIoEnd && end < 0) if (status == StreamIoEnd && end < 0)
{ {
@ -990,6 +1061,12 @@ readCallback(StreamIoStatus status,
end = maxInput; end = maxInput;
termlen = 0; termlen = 0;
} }
if (end >= 0)
{
// be forgiving with timeout because end is found
if (status == StreamIoTimeout)
status = StreamIoEnd;
}
if (end < 0) if (end < 0)
{ {
// no end found // no end found
@ -1006,23 +1083,23 @@ readCallback(StreamIoStatus status,
} }
// try to parse what we got // try to parse what we got
end = inputBuffer.length(); end = inputBuffer.length();
if (!(flags & AsyncMode)) if (flags & AsyncMode)
{
debug("StreamCore::readCallback(%s) async timeout: just restart\n",
name());
unparsedInput = false;
inputBuffer.clear();
commandIndex = commandStart;
evalIn();
return 0;
}
else
{ {
error("%s: Timeout after reading %ld byte%s \"%s%s\"\n", error("%s: Timeout after reading %ld byte%s \"%s%s\"\n",
name(), end, end==1 ? "" : "s", end > 20 ? "..." : "", name(), end, end==1 ? "" : "s", end > 20 ? "..." : "",
inputBuffer.expand(-20)()); inputBuffer.expand(-20)());
} }
} }
if (status == StreamIoTimeout && (flags & AsyncMode))
{
debug("StreamCore::readCallback(%s) async timeout: just restart\n",
name());
inputBuffer.clear();
commandIndex = commandStart;
evalIn();
return 0;
}
inputLine.set(inputBuffer(), end); inputLine.set(inputBuffer(), end);
debug("StreamCore::readCallback(%s) input line: \"%s\"\n", debug("StreamCore::readCallback(%s) input line: \"%s\"\n",
@ -1035,6 +1112,10 @@ readCallback(StreamIoStatus status,
name(), inputBuffer.expand()()); name(), inputBuffer.expand()());
unparsedInput = true; unparsedInput = true;
} }
else
{
unparsedInput = false;
}
if (!matches) if (!matches)
{ {
if (status == StreamIoTimeout) if (status == StreamIoTimeout)
@ -1063,7 +1144,7 @@ readCallback(StreamIoStatus status,
return 0; return 0;
} }
// end input mode and do next command // end input mode and do next command
flags &= ~(AsyncMode|AcceptInput); //// flags &= ~(AsyncMode|AcceptInput);
// -- should we tell someone that input has finished? -- // -- should we tell someone that input has finished? --
evalCommand(); evalCommand();
return 0; return 0;
@ -1077,7 +1158,9 @@ matchInput()
is installed and starts with 'in' (then we reparse the input). is installed and starts with 'in' (then we reparse the input).
*/ */
char command; char command;
const char* fieldName = NULL;
const char* formatstring; const char* formatstring;
int formatstringlen;
consumedInput = 0; consumedInput = 0;
@ -1089,22 +1172,38 @@ matchInput()
{ {
// code layout: // code layout:
// field <StreamProtocolParser::eos> addrlen AddressStructure formatstring <StreamProtocolParser::eos> StreamFormat [info] // field <StreamProtocolParser::eos> addrlen AddressStructure formatstring <StreamProtocolParser::eos> StreamFormat [info]
fieldName = commandIndex;
commandIndex += strlen(commandIndex)+1; commandIndex += strlen(commandIndex)+1;
unsigned short addrlen = extract<unsigned short>(commandIndex); unsigned short addrlen = extract<unsigned short>(commandIndex);
fieldAddress.set(commandIndex, addrlen); fieldAddress.set(commandIndex, addrlen);
commandIndex += addrlen; commandIndex += addrlen;
goto normal_format;
} }
case StreamProtocolParser::format: case StreamProtocolParser::format:
{ {
fieldAddress.clear();
normal_format:
int consumed; int consumed;
// code layout: // code layout:
// formatstring <eos> StreamFormat [info] // formatstring <eos> StreamFormat [info]
formatstring = commandIndex; formatstring = commandIndex;
while (*commandIndex++ != StreamProtocolParser::eos); // jump after <eos> // jump after <eos>
while (*commandIndex)
{
if (*commandIndex == esc) commandIndex++;
commandIndex++;
}
formatstringlen = commandIndex-formatstring;
commandIndex++;
StreamFormat fmt = extract<StreamFormat>(commandIndex); StreamFormat fmt = extract<StreamFormat>(commandIndex);
fmt.info = commandIndex; fmt.info = commandIndex; // point to info string
commandIndex += fmt.infolen; commandIndex += fmt.infolen;
#ifndef NO_TEMPORARY
debug("StreamCore::matchInput(%s): format = %%%s\n",
name(), StreamBuffer(formatstring, formatstringlen).expand()());
#endif
if (fmt.flags & skip_flag || fmt.type == pseudo_format) if (fmt.flags & skip_flag || fmt.type == pseudo_format)
{ {
long ldummy; long ldummy;
@ -1135,17 +1234,74 @@ matchInput()
return false; return false;
} }
if (consumed < 0) if (consumed < 0)
{
if (fmt.flags & default_flag)
{
consumed = 0;
}
else
{
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{
error("%s: Input \"%s%s\" does not match format %%%s\n",
name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring);
}
return false;
}
}
consumedInput += consumed;
break;
}
if (fmt.flags & compare_flag)
{
outputLine.clear();
flags &= ~Separator;
if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL))
{
StreamBuffer formatstr(formatstring, formatstringlen);
if (fieldAddress)
error("%s: Cannot format field '%s' with '%%%s'\n",
name(), fieldName, formatstr.expand()());
else
error("%s: Cannot format value with '%%%s'\n",
name(), formatstr.expand()());
return false;
}
#ifndef NO_TEMPORARY
debug("StreamCore::matchInput(%s): compare \"%s\" with \"%s\"\n",
name(), inputLine.expand(consumedInput,
outputLine.length())(), outputLine.expand()());
#endif
if (inputLine.length() - consumedInput < outputLine.length())
{ {
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\" too short."
name(), inputLine.expand(consumedInput, 20)(), " No match for format %%%s (\"%s\")\n",
inputLine.length()-consumedInput > 20 ? "..." : "", name(),
formatstring); inputLine.length() > 20 ? "..." : "",
inputLine.expand(-20)(),
formatstring,
outputLine.expand()());
} }
return false; return false;
} }
consumedInput += consumed; if (!outputLine.startswith(inputLine(consumedInput),outputLine.length()))
{
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{
error("%s: Input \"%s%s\" does not match"
" format %%%s (\"%s\")\n",
name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring,
outputLine.expand()());
}
return false;
}
consumedInput += outputLine.length();
break; break;
} }
flags &= ~Separator; flags &= ~Separator;
@ -1159,19 +1315,22 @@ matchInput()
inputLine.length()-consumedInput > 20 ? "..." : "", inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring); formatstring);
else else
error("%s: Can't scan value with format %%%s\n", error("%s: Format %%%s has data type %s which does not match this variable.\n",
name(), formatstring); name(), formatstring, StreamFormatTypeStr[fmt.type] );
} }
return false; return false;
} }
// matchValue() has already removed consumed bytes from inputBuffer // matchValue() has already removed consumed bytes from inputBuffer
fieldAddress = NULL;
break; break;
} }
case StreamProtocolParser::skip: case StreamProtocolParser::skip:
// ignore next input byte // ignore next input byte
consumedInput++; consumedInput++;
break; break;
case StreamProtocolParser::whitespace:
// any number of whitespace (including 0)
while (isspace(inputLine[consumedInput])) consumedInput++;
break;
case esc: case esc:
// escaped literal byte // escaped literal byte
command = *commandIndex++; command = *commandIndex++;
@ -1183,12 +1342,14 @@ matchInput()
while (commandIndex[i] >= ' ') i++; while (commandIndex[i] >= ' ') i++;
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.\n",
" No match for \"%s\"\n",
name(), name(),
inputLine.length() > 20 ? "..." : "", inputLine.length() > 20 ? "..." : "",
inputLine.expand(-20)(), inputLine.expand(-20)());
#ifndef NO_TEMPORARY
error("No match for \"%s\"\n",
StreamBuffer(commandIndex-1,i+1).expand()()); StreamBuffer(commandIndex-1,i+1).expand()());
#endif
} }
return false; return false;
} }
@ -1206,10 +1367,12 @@ matchInput()
consumedInput, consumedInput,
consumedInput==1 ? "" : "s"); consumedInput==1 ? "" : "s");
#ifndef NO_TEMPORARY
error("%s: got \"%s\" where \"%s\" was expected\n", error("%s: got \"%s\" where \"%s\" was expected\n",
name(), name(),
inputLine.expand(consumedInput, 20)(), inputLine.expand(consumedInput, 20)(),
StreamBuffer(commandIndex-1,i+1).expand()()); StreamBuffer(commandIndex-1,i+1).expand()());
#endif
} }
return false; return false;
} }
@ -1245,36 +1408,45 @@ matchInput()
bool StreamCore:: bool StreamCore::
matchSeparator() matchSeparator()
{ {
// called before value is read, first value has Separator flag cleared
// for second and next value set Separator flag
if (!separator) {
// empty separator matches
return true;
}
if (!(flags & Separator)) if (!(flags & Separator))
{ {
// before first element, don't expect separator yet
flags |= Separator; flags |= Separator;
return true; return true;
} }
if (!separator) return true; long i;
long i = 0; long j = consumedInput;
if (separator[0] == ' ') for (i = 0; i < separator.length(); i++)
{ {
i++; switch (separator[i])
// skip leading whitespaces {
while (isspace(inputLine[consumedInput++])); case StreamProtocolParser::skip:
j++;
continue;
case StreamProtocolParser::whitespace:
while (isspace(inputLine[j])) j++;
continue;
case esc:
i++;
default:
if (separator[i] != inputLine[j])
{
// no match
// don't complain here, just return false
return false;
}
j++;
}
} }
for (; i < separator.length(); i++,consumedInput++) // separator successfully read
{ consumedInput = j;
if (!inputLine[consumedInput]) return false;
if (separator[i] == StreamProtocolParser::skip) continue; // wildcard
if (separator[i] == esc) i++; // escaped literal byte
if (separator[i] != inputLine[consumedInput]) return false;
}
return true;
}
bool StreamCore::
scanSeparator()
{
// for compatibility only
// read and remove separator
if (!matchSeparator()) return false;
flags &= ~Separator;
return true; return true;
} }
@ -1293,8 +1465,16 @@ scanValue(const StreamFormat& fmt, long& value)
scanLong(fmt, inputLine(consumedInput), value); scanLong(fmt, inputLine(consumedInput), value);
debug("StreamCore::scanValue(%s, format=%%%c, long) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, long) input=\"%s\"\n",
name(), fmt.conv, inputLine.expand(consumedInput)()); name(), fmt.conv, inputLine.expand(consumedInput)());
if (consumed < 0 || if (consumed < 0)
consumed > inputLine.length()-consumedInput) return -1; {
if (fmt.flags & default_flag)
{
value = 0;
consumed = 0;
}
else 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);
flags |= GotValue; flags |= GotValue;
@ -1315,9 +1495,17 @@ scanValue(const StreamFormat& fmt, double& value)
long consumed = StreamFormatConverter::find(fmt.conv)-> long consumed = StreamFormatConverter::find(fmt.conv)->
scanDouble(fmt, inputLine(consumedInput), value); scanDouble(fmt, inputLine(consumedInput), value);
debug("StreamCore::scanValue(%s, format=%%%c, double) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, double) input=\"%s\"\n",
name(), fmt.conv, inputLine.expand(consumedInput)()); name(), fmt.conv, inputLine.expand(consumedInput, 20)());
if (consumed < 0 || if (consumed < 0)
consumed > inputLine.length()-consumedInput) return -1; {
if (fmt.flags & default_flag)
{
value = 0.0;
consumed = 0;
}
else 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);
flags |= GotValue; flags |= GotValue;
@ -1340,8 +1528,16 @@ scanValue(const StreamFormat& fmt, char* value, long maxlen)
scanString(fmt, inputLine(consumedInput), value, maxlen); scanString(fmt, inputLine(consumedInput), value, maxlen);
debug("StreamCore::scanValue(%s, format=%%%c, char*, maxlen=%ld) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, char*, maxlen=%ld) input=\"%s\"\n",
name(), fmt.conv, maxlen, inputLine.expand(consumedInput)()); name(), fmt.conv, maxlen, inputLine.expand(consumedInput)());
if (consumed < 0 || if (consumed < 0)
consumed > inputLine.length()-consumedInput) return -1; {
if (fmt.flags & default_flag)
{
value[0] = 0;
consumed = 0;
}
else 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",
name(), StreamBuffer(value, maxlen).expand()()); name(), StreamBuffer(value, maxlen).expand()());
@ -1453,8 +1649,8 @@ timerCallback()
bool StreamCore:: bool StreamCore::
evalExec() evalExec()
{ {
outputLine.clear();
formatOutput(); formatOutput();
debug ("StreamCore::evalExec: command = \"%s\"\n", outputLine.expand()());
// release bus // release bus
if (flags & BusOwner) if (flags & BusOwner)
{ {

View File

@ -139,7 +139,6 @@ protected:
long scanValue(const StreamFormat& format, double& value); long scanValue(const StreamFormat& format, double& value);
long scanValue(const StreamFormat& format, char* value, long maxlen); long scanValue(const StreamFormat& format, char* value, long maxlen);
long scanValue(const StreamFormat& format); long scanValue(const StreamFormat& format);
bool scanSeparator(); // disencouraged
StreamBuffer protocolname; StreamBuffer protocolname;
unsigned long lockTimeout; unsigned long lockTimeout;

View File

@ -156,7 +156,6 @@ class Stream : protected StreamCore
friend long streamPrintf(dbCommon *record, format_t *format, ...); friend long streamPrintf(dbCommon *record, format_t *format, ...);
friend long streamScanfN(dbCommon *record, format_t *format, friend long streamScanfN(dbCommon *record, format_t *format,
void*, size_t maxStringSize); void*, size_t maxStringSize);
friend long streamScanSep(dbCommon *record);
friend long streamReload(char* recordname); friend long streamReload(char* recordname);
public: public:
@ -173,16 +172,6 @@ epicsExportAddress(int, streamDebug);
} }
#endif #endif
#ifdef MEMGUARD
static const iocshFuncDef memguardReportDef =
{ "memguardReport", 0, NULL };
static void memguardReportFunc (const iocshArgBuf *args)
{
memguardReport();
}
#endif
// for subroutine record // for subroutine record
extern "C" long streamReloadSub() extern "C" long streamReloadSub()
{ {
@ -251,9 +240,6 @@ extern "C" void streamReloadFunc (const iocshArgBuf *args)
static void streamRegistrar () static void streamRegistrar ()
{ {
#ifdef MEMGUARD
iocshRegister(&memguardReportDef, memguardReportFunc);
#endif
iocshRegister(&reloadDef, streamReloadFunc); iocshRegister(&reloadDef, streamReloadFunc);
// make streamReload available for subroutine records // make streamReload available for subroutine records
registryFunctionAdd("streamReload", registryFunctionAdd("streamReload",
@ -352,7 +338,6 @@ report(int interest)
pstream->ioLink->value.instio.string); pstream->ioLink->value.instio.string);
} }
} }
StreamPrintTimestampFunction = streamEpicsPrintTimestamp;
return OK; return OK;
} }
@ -489,20 +474,11 @@ long streamPrintf(dbCommon *record, format_t *format, ...)
return success ? OK : ERROR; return success ? OK : ERROR;
} }
long streamScanSep(dbCommon* record)
{
// depreciated
debug("streamScanSep(%s)\n", record->name);
Stream* pstream = (Stream*)record->dpvt;
if (!pstream) return ERROR;
return pstream->scanSeparator() ? OK : ERROR;
}
long streamScanfN(dbCommon* record, format_t *format, long streamScanfN(dbCommon* record, format_t *format,
void* value, size_t maxStringSize) void* value, size_t maxStringSize)
{ {
debug("streamScanfN(%s,format=%%%c,maxStringSize=%d)\n", debug("streamScanfN(%s,format=%%%c,maxStringSize=%ld)\n",
record->name, format->priv->conv, maxStringSize); record->name, format->priv->conv, (long)maxStringSize);
Stream* pstream = (Stream*)record->dpvt; Stream* pstream = (Stream*)record->dpvt;
if (!pstream) return ERROR; if (!pstream) return ERROR;
if (!pstream->scan(format, value, maxStringSize)) if (!pstream->scan(format, value, maxStringSize))
@ -714,6 +690,7 @@ process()
debug("Stream::process(%s): could not start, status=%d\n", debug("Stream::process(%s): could not start, status=%d\n",
name(), status); name(), status);
(void) recGblSetSevr(record, status, INVALID_ALARM); (void) recGblSetSevr(record, status, INVALID_ALARM);
record->pact = false;
return false; return false;
} }
debug("Stream::process(%s): protocol started\n", name()); debug("Stream::process(%s): protocol started\n", name());
@ -935,10 +912,15 @@ getFieldAddress(const char* fieldname, StreamBuffer& address)
} }
else else
{ {
// FIELD in this record // FIELD in this record or VAL in other record
char fullname[PVNAME_SZ + 1]; char fullname[PVNAME_SZ + 1];
sprintf(fullname, "%s.%s", name(), fieldname); sprintf(fullname, "%s.%s", name(), fieldname);
if (dbNameToAddr(fullname, &dbaddr) != OK) return false; if (dbNameToAddr(fullname, &dbaddr) != OK)
{
// VAL in other record
sprintf(fullname, "%s.VAL", fieldname);
if (dbNameToAddr(fullname, &dbaddr) != OK) return false;
}
} }
address.append(&dbaddr, sizeof(dbaddr)); address.append(&dbaddr, sizeof(dbaddr));
return true; return true;
@ -968,6 +950,26 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
long nelem = pdbaddr->no_elements; long nelem = pdbaddr->no_elements;
size_t size = nelem * typeSize[format.type]; size_t size = nelem * typeSize[format.type];
char* buffer = fieldBuffer.clear().reserve(size); char* buffer = fieldBuffer.clear().reserve(size);
if (strcmp(((dbFldDes*)pdbaddr->pfldDes)->name, "TIME") == 0)
{
double time;
if (format.type != double_format)
{
error ("%s: can only read double values from TIME field\n", name());
return false;
}
if (pdbaddr->precord == record)
{
/* if getting time from own record, update timestamp first */
recGblGetTimeStamp(record);
}
time = pdbaddr->precord->time.secPastEpoch + 631152000u + pdbaddr->precord->time.nsec * 1e-9;
debug("Stream::formatValue(%s): read %f from TIME field\n", name(), time);
return printValue(format, time);
}
if (dbGet(pdbaddr, dbfMapping[format.type], buffer, if (dbGet(pdbaddr, dbfMapping[format.type], buffer,
NULL, &nelem, NULL) != 0) NULL, &nelem, NULL) != 0)
{ {
@ -1034,7 +1036,6 @@ bool Stream::
matchValue(const StreamFormat& format, const void* fieldaddress) matchValue(const StreamFormat& format, const void* fieldaddress)
{ {
// this function must increase consumedInput // this function must increase consumedInput
// [I use goto and feel very ashamed for it.]
long consumed; long consumed;
long lval; long lval;
double dval; double dval;
@ -1053,34 +1054,43 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
buffer = fieldBuffer.clear().reserve(size); buffer = fieldBuffer.clear().reserve(size);
for (nord = 0; nord < nelem; nord++) for (nord = 0; nord < nelem; nord++)
{ {
debug("Stream::matchValue(%s): buffer before: %s\n", name(), fieldBuffer.expand()());
switch (format.type) switch (format.type)
{ {
case long_format: case long_format:
{ {
consumed = scanValue(format, lval); consumed = scanValue(format, lval);
if (consumed < 0) goto noMoreElements; if (consumed >= 0) ((epicsInt32*)buffer)[nord] = lval;
((epicsInt32*)buffer)[nord] = lval; debug("Stream::matchValue(%s): %s[%li] = %li\n",
name(), pdbaddr->precord->name, nord, lval);
break; break;
} }
case enum_format: case enum_format:
{ {
consumed = scanValue(format, lval); consumed = scanValue(format, lval);
if (consumed < 0) goto noMoreElements; if (consumed >= 0) ((epicsUInt16*)buffer)[nord] = (epicsUInt16)lval;
((epicsUInt16*)buffer)[nord] = (epicsUInt16)lval; debug("Stream::matchValue(%s): %s[%li] = %li\n",
name(), pdbaddr->precord->name, nord, lval);
break; break;
} }
case double_format: case double_format:
{ {
consumed = scanValue(format, dval); consumed = scanValue(format, dval);
if (consumed < 0) goto noMoreElements; // Direct assignment to buffer fails fith gcc 3.4.3 for xscale_be
((epicsFloat64*)buffer)[nord] = dval; // Optimization bug?
epicsFloat64 f64=dval;
if (consumed >= 0) memcpy(((epicsFloat64*)buffer)+nord, &f64, sizeof(f64));
debug("Stream::matchValue(%s): %s[%li] = %#g %#g\n",
name(), pdbaddr->precord->name, nord, dval,
((epicsFloat64*)buffer)[nord]);
break; break;
} }
case string_format: case string_format:
{ {
consumed = scanValue(format, consumed = scanValue(format,
buffer+MAX_STRING_SIZE*nord, MAX_STRING_SIZE); buffer+MAX_STRING_SIZE*nord, MAX_STRING_SIZE);
if (consumed < 0) goto noMoreElements; debug("Stream::matchValue(%s): %s[%li] = \"%.*s\"\n",
name(), pdbaddr->precord->name, nord, MAX_STRING_SIZE, buffer+MAX_STRING_SIZE*nord);
break; break;
} }
default: default:
@ -1088,15 +1098,16 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
"Illegal format type\n", name()); "Illegal format type\n", name());
return false; return false;
} }
debug("Stream::matchValue(%s): buffer after: %s\n", name(), fieldBuffer.expand()());
if (consumed < 0) break;
consumedInput += consumed; consumedInput += consumed;
} }
noMoreElements:
if (!nord) if (!nord)
{ {
// scan error: set other record to alarm status // scan error: set other record to alarm status
if (pdbaddr->precord != record) if (pdbaddr->precord != record)
{ {
recGblSetSevr(pdbaddr->precord, CALC_ALARM, INVALID_ALARM); (void) recGblSetSevr(pdbaddr->precord, CALC_ALARM, INVALID_ALARM);
if (!INIT_RUN) if (!INIT_RUN)
{ {
// process other record to send alarm monitor // process other record to send alarm monitor
@ -1105,16 +1116,39 @@ noMoreElements:
} }
return false; return false;
} }
if (strcmp(((dbFldDes*)pdbaddr->pfldDes)->name, "TIME") == 0)
{
#ifdef epicsTimeEventDeviceTime
if (format.type != double_format)
{
error ("%s: can only write double values to TIME field\n", name());
return false;
}
dval = dval-631152000u;
pdbaddr->precord->time.secPastEpoch = (long)dval;
/* rouding: we don't have 9 digits precision in a double of today's number of seconds */
pdbaddr->precord->time.nsec = (long)((dval-(long)dval)*1e6)*1000;
debug("Stream::matchValue(%s): writing %i.%i to TIME field\n", name(),
pdbaddr->precord->time.secPastEpoch, pdbaddr->precord->time.nsec);
pdbaddr->precord->tse = epicsTimeEventDeviceTime;
return true;
#else
error ("%s: writing TIME field is not supported in this EPICS version\n", name());
return false;
#endif
}
if (pdbaddr->precord == record || INIT_RUN) if (pdbaddr->precord == record || INIT_RUN)
{ {
// write into own record, thus don't process it // write into own record, thus don't process it
// in @init we must not process other record // in @init we must not process other record
debug("Stream::matchValue(%s): dbPut(%s.%s,...)\n", debug("Stream::matchValue(%s): dbPut(%s.%s,%s)\n",
name(), name(),
pdbaddr->precord->name, pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name); ((dbFldDes*)pdbaddr->pfldDes)->name,
fieldBuffer.expand()());
putfunc = "dbPut"; putfunc = "dbPut";
status = dbPut(pdbaddr, dbfMapping[format.type], fieldBuffer(), nord); status = dbPut(pdbaddr, dbfMapping[format.type], buffer, nord);
if (INIT_RUN && pdbaddr->precord != record) if (INIT_RUN && pdbaddr->precord != record)
{ {
// clean error status of other record in @init // clean error status of other record in @init
@ -1126,12 +1160,13 @@ noMoreElements:
else else
{ {
// write into other record, thus process it // write into other record, thus process it
debug("Stream::matchValue(%s): dbPutField(%s.%s,...)\n", debug("Stream::matchValue(%s): dbPutField(%s.%s,%s)\n",
name(), name(),
pdbaddr->precord->name, pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name); ((dbFldDes*)pdbaddr->pfldDes)->name,
fieldBuffer.expand()());
putfunc = "dbPutField"; putfunc = "dbPutField";
status = dbPutField(pdbaddr, dbfMapping[format.type], fieldBuffer(), nord); status = dbPutField(pdbaddr, dbfMapping[format.type], buffer, nord);
} }
if (status != 0) if (status != 0)
{ {

View File

@ -58,11 +58,19 @@ void StreamError(const char* fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
StreamVError(fmt, args); StreamVError(0, NULL, fmt, args);
va_end(args); va_end(args);
} }
void StreamVError(const char* fmt, va_list args) void StreamError(int line, const char* file, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
StreamVError(line, file, fmt, args);
va_end(args);
}
void StreamVError(int line, const char* file, const char* fmt, va_list args)
{ {
char timestamp[40]; char timestamp[40];
StreamPrintTimestampFunction(timestamp, 40); StreamPrintTimestampFunction(timestamp, 40);
@ -79,6 +87,10 @@ void StreamVError(const char* fmt, va_list args)
#endif #endif
fprintf(stderr, "\033[31;1m"); fprintf(stderr, "\033[31;1m");
fprintf(stderr, "%s ", timestamp); fprintf(stderr, "%s ", timestamp);
if (file)
{
fprintf(stderr, "%s line %d: ", file, line);
}
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
fprintf(stderr, "\033[0m"); fprintf(stderr, "\033[0m");
} }

View File

@ -30,11 +30,19 @@
extern int streamDebug; extern int streamDebug;
extern void (*StreamPrintTimestampFunction)(char* buffer, int size); extern void (*StreamPrintTimestampFunction)(char* buffer, int size);
void StreamError(int line, const char* file, const char* fmt, ...)
__attribute__ ((format(printf,3,4)));
void StreamVError(int line, const char* file, const char* fmt, va_list args)
__attribute__ ((format(printf,3,0)));
void StreamError(const char* fmt, ...) void StreamError(const char* fmt, ...)
__attribute__ ((format(printf,1,2))); __attribute__ ((format(printf,1,2)));
void StreamVError(const char* fmt, va_list args) inline void StreamVError(const char* fmt, va_list args)
__attribute__ ((format(printf,1,0))); {
StreamVError(0, NULL, fmt, args);
}
class StreamDebugClass class StreamDebugClass
{ {

View File

@ -23,12 +23,14 @@
#define StreamFormat_h #define StreamFormat_h
typedef enum { typedef enum {
left_flag = 0x01, left_flag = 0x01,
sign_flag = 0x02, sign_flag = 0x02,
space_flag = 0x04, space_flag = 0x04,
alt_flag = 0x08, alt_flag = 0x08,
zero_flag = 0x10, zero_flag = 0x10,
skip_flag = 0x20 skip_flag = 0x20,
default_flag = 0x40,
compare_flag = 0x80
} StreamFormatFlag; } StreamFormatFlag;
typedef enum { typedef enum {

View File

@ -19,8 +19,9 @@
* * * *
***************************************************************/ ***************************************************************/
#include <stdlib.h>
#include <ctype.h>
#include "StreamFormatConverter.h" #include "StreamFormatConverter.h"
#include "StreamFormat.h"
#include "StreamError.h" #include "StreamError.h"
StreamFormatConverter* StreamFormatConverter:: StreamFormatConverter* StreamFormatConverter::
@ -31,6 +32,125 @@ StreamFormatConverter::
{ {
} }
int StreamFormatConverter::
parseFormat(const char*& source, FormatType formatType, StreamFormat& streamFormat, StreamBuffer& infoString)
{
/*
source := [flags] [width] ['.' prec] conv [extra]
flags := '-' | '+' | ' ' | '#' | '0' | '*' | '?' | '='
width := integer
prec := integer
conv := character
extra := string
*/
// look for flags
streamFormat.flags = 0;
bool loop = true;
while (loop)
{
switch (*++source)
{
case '-':
streamFormat.flags |= left_flag;
break;
case '+':
streamFormat.flags |= sign_flag;
break;
case ' ':
streamFormat.flags |= space_flag;
break;
case '#':
streamFormat.flags |= alt_flag;
break;
case '0':
streamFormat.flags |= zero_flag;
break;
case '*':
if (formatType != ScanFormat)
{
error("Use of skip modifier '*' "
"only allowed in input formats\n");
return false;
}
streamFormat.flags |= skip_flag;
break;
case '?':
if (formatType != ScanFormat)
{
error("Use of default modifier '?' "
"only allowed in input formats\n");
return false;
}
streamFormat.flags |= default_flag;
break;
case '=':
if (formatType != ScanFormat)
{
error("Use of compare modifier '=' "
"only allowed in input formats\n");
return false;
}
streamFormat.flags |= compare_flag;
formatType = PrintFormat;
break;
default:
loop = false;
}
}
// look for width
unsigned long val;
char* p;
val = strtoul (source, &p, 10);
source = p;
if (val > 0xFFFF)
{
error("Field width %ld out of range\n", val);
return false;
}
streamFormat.width = (unsigned short)val;
// look for prec
streamFormat.prec = -1;
if (*source == '.')
{
source++;
val = strtoul(source, &p, 10);
if (p == source)
{
debug("source = %s\n", source);
error("Numeric precision field expected after '.'\n");
return false;
}
source = p;
if (val > 0x7FFF)
{
error("Precision %ld out of range\n", val);
return false;
}
streamFormat.prec = (short)val;
}
// look for converter
streamFormat.conv = *source++;
if (!streamFormat.conv || strchr("'\" (.0+-*?=", streamFormat.conv))
{
error("Missing converter character\n");
return false;
}
debug("StreamFormatConverter::parseFormat: converter='%c'\n",
streamFormat.conv);
StreamFormatConverter* converter;
converter = StreamFormatConverter::find(streamFormat.conv);
if (!converter)
{
error("No converter registered for format '%%%c'\n",
streamFormat.conv);
return false;
}
// parse format and get info string
return converter->parse(streamFormat, infoString,
source, formatType == ScanFormat);
}
void StreamFormatConverter:: void StreamFormatConverter::
provides(const char* name, const char* provided) provides(const char* name, const char* provided)
{ {
@ -112,11 +232,57 @@ static void copyFormatString(StreamBuffer& info, const char* source)
const char* p = source - 1; const char* p = source - 1;
while (*p != '%' && *p != ')') p--; while (*p != '%' && *p != ')') p--;
info.append('%'); info.append('%');
while (++p != source-1) info.append(*p); while (++p != source-1) if (*p != '?' && *p != '=') info.append(*p);
} }
// A word on sscanf
// GNU's sscanf implementation sucks. It calls strlen on the buffer.
// That leads to a time consumption proportional to the buffer size.
// When reading huge arrays element-wise by repeatedly calling sscanf,
// the performance drops to O(n^2).
// The vxWorks implementation sucks, too. When all parsed values are skipped
// with %*, it returns -1 instead of 0 even though it was successful.
// Standard Long Converter for 'diouxX' // Standard Long Converter for 'diouxX'
static int prepareval(const StreamFormat& fmt, const char*& input, bool& neg)
{
int length = 0;
neg = false;
while (isspace(*input)) { input++; length++; }
if (fmt.width)
{
// take local copy because strto* don't have width parameter
int width = fmt.width;
if (fmt.flags & space_flag)
{
// normally whitespace does not count to width
// but do so if space flag is present
width -= length;
}
strncpy((char*)fmt.info, input, width);
((char*)fmt.info)[width] = 0;
input = fmt.info;
}
if (*input == '+')
{
goto skipsign;
}
if (*input == '-')
{
neg = true;
skipsign:
input++;
length++;
}
if (isspace(*input))
{
// allow space after sign only if # flag is set
if (!(fmt.flags & alt_flag)) return -1;
}
return length;
}
class StdLongConverter : public StreamFormatConverter class StdLongConverter : public StreamFormatConverter
{ {
int parse(const StreamFormat& fmt, StreamBuffer& output, const char*& value, bool scanFormat); int parse(const StreamFormat& fmt, StreamBuffer& output, const char*& value, bool scanFormat);
@ -128,22 +294,22 @@ int StdLongConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool scanFormat) const char*& source, bool scanFormat)
{ {
if (scanFormat && (fmt.flags & alt_flag))
{
error("Use of modifier '#' not allowed with %%%c input conversion\n",
fmt.conv);
return false;
}
if (scanFormat && fmt.prec >= 0) if (scanFormat && fmt.prec >= 0)
{ {
error("Use of precision field '.%d' not allowed with %%%c input conversion\n", error("Use of precision field '.%d' not allowed with %%%c input conversion\n",
fmt.prec, fmt.conv); fmt.prec, fmt.conv);
return false; return false;
} }
copyFormatString(info, source); if (scanFormat)
info.append('l'); {
info.append(fmt.conv); if (fmt.width) info.reserve(fmt.width+1);
if (scanFormat) info.append("%n"); }
else
{
copyFormatString(info, source);
info.append('l');
info.append(fmt.conv);
}
return long_format; return long_format;
} }
@ -157,16 +323,39 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
int StdLongConverter:: int StdLongConverter::
scanLong(const StreamFormat& fmt, const char* input, long& value) scanLong(const StreamFormat& fmt, const char* input, long& value)
{ {
int length = -1; char* end;
if (fmt.flags & skip_flag) int length;
bool neg;
int base;
length = prepareval(fmt, input, neg);
if (length < 0) return -1;
switch (fmt.conv)
{ {
/* on vxWorks, return value of sscanf with %*... is buggy */ case 'd':
sscanf(input, fmt.info, &length); base = 10;
} break;
else case 'o':
{ base = 8;
if (sscanf(input, fmt.info, &value, &length) < 1) return -1; goto signcheck;
case 'x':
case 'X':
base = 16;
signcheck:
// allow negative hex and oct numbers with - flag
if (neg && !(fmt.flags & left_flag)) return -1;
break;
case 'u':
if (neg) return -1;
base = 10;
break;
default:
base = 0;
} }
value = strtoul(input, &end, base);
if (neg) value = -value;
if (end == input) return -1;
length += end-input;
return length; return length;
} }
@ -185,22 +374,21 @@ int StdDoubleConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool scanFormat) const char*& source, bool scanFormat)
{ {
if (scanFormat && (fmt.flags & alt_flag))
{
error("Use of modifier '#' not allowed with %%%c input conversion\n",
fmt.conv);
return false;
}
if (scanFormat && fmt.prec >= 0) if (scanFormat && fmt.prec >= 0)
{ {
error("Use of precision field '.%d' not allowed with %%%c input conversion\n", error("Use of precision field '.%d' not allowed with %%%c input conversion\n",
fmt.prec, fmt.conv); fmt.prec, fmt.conv);
return false; return false;
} }
copyFormatString(info, source); if (scanFormat)
if (scanFormat) info.append('l'); {
info.append(fmt.conv); if (fmt.width) info.reserve(fmt.width+1);
if (scanFormat) info.append("%n"); }
else
{
copyFormatString(info, source);
info.append(fmt.conv);
}
return double_format; return double_format;
} }
@ -214,16 +402,16 @@ printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
int StdDoubleConverter:: int StdDoubleConverter::
scanDouble(const StreamFormat& fmt, const char* input, double& value) scanDouble(const StreamFormat& fmt, const char* input, double& value)
{ {
int length = -1; char* end;
if (fmt.flags & skip_flag) int length;
{ bool neg;
/* on vxWorks, return value of sscanf with %*... is buggy */
sscanf(input, fmt.info, &length); length = prepareval(fmt, input, neg);
} if (length < 0) return -1;
else value = strtod(input, &end);
{ if (neg) value = -value;
if (sscanf(input, fmt.info, &value, &length) < 1) return -1; if (end == input) return -1;
} length += end-input;
return length; return length;
} }
@ -242,11 +430,10 @@ int StdStringConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool scanFormat) const char*& source, bool scanFormat)
{ {
if (fmt.flags & (sign_flag|space_flag|zero_flag|alt_flag)) if (fmt.flags & (sign_flag|zero_flag))
{ {
error("Use of modifiers '+', ' ', '0', '#' " error("Use of modifiers '+', '0'"
"not allowed with %%%c conversion\n", "not allowed with %%s conversion\n");
fmt.conv);
return false; return false;
} }
if (scanFormat && fmt.prec >= 0) if (scanFormat && fmt.prec >= 0)
@ -272,39 +459,52 @@ int StdStringConverter::
scanString(const StreamFormat& fmt, const char* input, scanString(const StreamFormat& fmt, const char* input,
char* value, size_t maxlen) char* value, size_t maxlen)
{ {
int length = -1; int length = 0;
if (*input == '\0')
int width = fmt.width;
if ((fmt.flags & skip_flag) || value == NULL) maxlen = 0;
// if user does not specify width assume "ininity" (-1)
if (width == 0)
{ {
// match empty string if (fmt.conv == 'c') width = 1;
value[0] = '\0'; else width = -1;
return 0;
} }
if (fmt.flags & skip_flag)
while (isspace(*input) && width)
{ {
/* on vxWorks, return value of sscanf with %*... is buggy */ // normally leading whitespace does not count to width
sscanf(input, fmt.info, &length); // but do so if space flag is present
if (fmt.flags & space_flag)
{
if (maxlen > 1)
{
*value++ = *input;
maxlen--;
}
width--;
}
length++;
input++;
} }
else while (*input && width)
{ {
char tmpformat[10]; // normally whitespace ends string
const char* f; // but don't end if # flag is present
if (maxlen <= fmt.width || fmt.width == 0) if (!(fmt.flags & alt_flag) && isspace(*input)) break;
if (maxlen > 1)
{ {
// assure not to read too much *value++ = *input;
sprintf(tmpformat, "%%%d%c%%n", maxlen-1, fmt.conv); maxlen--;
f = tmpformat;
} }
else length++;
{ width--;
f = fmt.info; input++;
} }
if (sscanf(input, f, value, &length) < 1) return -1; if (maxlen > 0)
if (length < 0) return -1; {
value[length] = '\0'; *value = '\0';
#ifndef NO_TEMPORARY
debug("StdStringConverter::scanString: length=%d, value=%s\n",
length, StreamBuffer(value,length).expand()());
#endif
} }
return length; return length;
} }
@ -313,11 +513,11 @@ RegisterConverter (StdStringConverter, "s");
// Standard Characters Converter for 'c' // Standard Characters Converter for 'c'
class StdCharsConverter : public StdStringConverter class StdCharsConverter : public StreamFormatConverter
{ {
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool); virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual bool printLong(const StreamFormat&, StreamBuffer&, long); virtual bool printLong(const StreamFormat&, StreamBuffer&, long);
// scanString is inherited from %s format virtual int scanString(const StreamFormat&, const char*, char*, size_t);
}; };
int StdCharsConverter:: int StdCharsConverter::
@ -327,8 +527,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
if (fmt.flags & (sign_flag|space_flag|zero_flag|alt_flag)) if (fmt.flags & (sign_flag|space_flag|zero_flag|alt_flag))
{ {
error("Use of modifiers '+', ' ', '0', '#' " error("Use of modifiers '+', ' ', '0', '#' "
"not allowed with %%%c conversion\n", "not allowed with %%c conversion\n");
fmt.conv);
return false; return false;
} }
if (scanFormat && fmt.prec >= 0) if (scanFormat && fmt.prec >= 0)
@ -354,6 +553,37 @@ printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
return true; return true;
} }
int StdCharsConverter::
scanString(const StreamFormat& fmt, const char* input,
char* value, size_t maxlen)
{
int length = 0;
int width = fmt.width;
if ((fmt.flags & skip_flag) || value == NULL) maxlen = 0;
// if user does not specify width assume 1
if (width == 0) width = 1;
while (*input && width)
{
if (maxlen > 1)
{
*value++ = *input;
maxlen--;
}
length++;
width--;
input++;
}
if (maxlen > 0)
{
*value = '\0';
}
return length;
}
RegisterConverter (StdCharsConverter, "c"); RegisterConverter (StdCharsConverter, "c");
// Standard Charset Converter for '[' // Standard Charset Converter for '['
@ -365,6 +595,17 @@ class StdCharsetConverter : public StreamFormatConverter
// no print method, %[ is readonly // no print method, %[ is readonly
}; };
inline void markbit(StreamBuffer& info, bool notflag, char c)
{
char &infobyte = info[c>>3];
char mask = 1<<(c&7);
if (notflag)
infobyte |= mask;
else
infobyte &= ~mask;
}
int StdCharsetConverter:: int StdCharsetConverter::
parse(const StreamFormat& fmt, StreamBuffer& info, parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool scanFormat) const char*& source, bool scanFormat)
@ -377,8 +618,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
if (fmt.flags & (left_flag|sign_flag|space_flag|zero_flag|alt_flag)) if (fmt.flags & (left_flag|sign_flag|space_flag|zero_flag|alt_flag))
{ {
error("Use of modifiers '-', '+', ' ', '0', '#'" error("Use of modifiers '-', '+', ' ', '0', '#'"
"not allowed with %%%c conversion\n", "not allowed with %%[ conversion\n");
fmt.conv);
return false; return false;
} }
if (scanFormat && fmt.prec >= 0) if (scanFormat && fmt.prec >= 0)
@ -387,18 +627,46 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
fmt.prec, fmt.conv); fmt.prec, fmt.conv);
return false; return false;
} }
info.printf("%%%s%d[", fmt.flags & skip_flag ? "*" : "", fmt.width);
while (*source && *source != ']') bool notflag = false;
char c = 0;
info.clear().reserve(32);
if (*source == '^')
{ {
if (*source == esc) source++; notflag = true;
info.append(*source++); source++;
}
else
{
memset(info(1), 255, 32);
}
if (*source == ']')
{
markbit(info, notflag, *source++);
}
for (; *source && *source != ']'; source++)
{
if (*source == esc)
{
markbit(info, notflag, *++source);
continue;
}
if (*source == '-' && c && source[1] && source[1] != ']')
{
source++;
while (c < *source) markbit(info, notflag, c++);
while (c > *source) markbit(info, notflag, c--);
}
c = *source;
markbit(info, notflag, c);
} }
if (!*source) { if (!*source) {
error("Missing ']' after %%[ format conversion\n"); error("Missing ']' after %%[ format conversion\n");
return false; return false;
} }
source++; // consume ']' source++; // consume ']'
info.append("]%n");
return string_format; return string_format;
} }
@ -406,32 +674,29 @@ int StdCharsetConverter::
scanString(const StreamFormat& fmt, const char* input, scanString(const StreamFormat& fmt, const char* input,
char* value, size_t maxlen) char* value, size_t maxlen)
{ {
int length = -1; int length = 0;
if (fmt.flags & skip_flag) int width = fmt.width;
if ((fmt.flags & skip_flag) || value == NULL) maxlen = 0;
// if user does not specify width assume "ininity" (-1)
if (width == 0) width = -1;
while (*input && width)
{ {
/* on vxWorks, return value of sscanf with %*... is buggy */ if (fmt.info[*input>>3] & 1<<(*input&7)) break;
sscanf(input, fmt.info, &length); if (maxlen > 1)
{
*value++ = *input;
maxlen--;
}
length++;
width--;
input++;
} }
else if (maxlen > 0)
{ {
char tmpformat[256]; *value = '\0';
const char* f;
if (maxlen <= fmt.width || fmt.width == 0)
{
const char *p = strchr (fmt.info, '[');
// assure not to read too much
sprintf(tmpformat, "%%%d%s", maxlen-1, p);
f = tmpformat;
}
else
{
f = fmt.info;
}
if (sscanf(input, f, value, &length) < 1) return -1;
if (length < 0) return -1;
value[length] = '\0';
debug("StdCharsetConverter::scanString: length=%d, value=%s\n",
length, value);
} }
return length; return length;
} }

View File

@ -22,6 +22,7 @@
#include "StreamFormat.h" #include "StreamFormat.h"
#include "StreamBuffer.h" #include "StreamBuffer.h"
#include "StreamProtocol.h"
#define esc (0x1b) #define esc (0x1b)
@ -41,6 +42,7 @@ class StreamFormatConverter
const char* _name; const char* _name;
public: public:
virtual ~StreamFormatConverter(); virtual ~StreamFormatConverter();
static int parseFormat(const char*& source, FormatType, StreamFormat&, StreamBuffer& infoString);
const char* name() { return _name; } const char* name() { return _name; }
void provides(const char* name, const char* provided); void provides(const char* name, const char* provided);
static StreamFormatConverter* find(unsigned char c); static StreamFormatConverter* find(unsigned char c);

View File

@ -81,18 +81,6 @@ StreamProtocolParser::
delete next; delete next;
} }
void StreamProtocolParser::
errorMsg(const char* fmt, ...)
{
char fmt2[200];
sprintf (fmt2, "'%s' line %d: %s",
filename(), line, fmt);
va_list args;
va_start(args, fmt);
StreamVError(fmt2, args);
va_end(args);
}
void StreamProtocolParser:: void StreamProtocolParser::
report() report()
{ {
@ -118,7 +106,7 @@ getProtocol(const char* filename, const StreamBuffer& protocolAndParams)
// Have we already seen this file? // Have we already seen this file?
for (parser = parsers; parser; parser = parser->next) for (parser = parsers; parser; parser = parser->next)
{ {
if (parser->filename.equals(filename)) if (parser->filename.startswith(filename))
{ {
if (!parser->valid) if (!parser->valid)
{ {
@ -234,12 +222,12 @@ getProtocol(const StreamBuffer& protocolAndParams)
Protocol* protocol; Protocol* protocol;
for (protocol = protocols; protocol; protocol = protocol->next) for (protocol = protocols; protocol; protocol = protocol->next)
{ {
if (protocol->protocolname.equals(name())) if (protocol->protocolname.startswith(name()))
// constructor also replaces parameters // constructor also replaces parameters
return new Protocol(*protocol, name, 0); return new Protocol(*protocol, name, 0);
} }
error("Protocol '%s' not found in protocol file '%s'\n", error("Protocol '%s' not found in protocol file '%s'\n",
name(), filename()); protocolAndParams(), filename());
return NULL; return NULL;
} }
@ -292,18 +280,18 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
// end of protocol or handler definition // end of protocol or handler definition
return true; return true;
} }
errorMsg("Stray '}' in global context\n"); error(line, filename(), "Stray '}' in global context\n");
return false; return false;
} }
if (strchr("{=", token[0])) if (strchr("{=", token[0]))
{ {
errorMsg("Expect name before '%c'\n", token[0]); error(line, filename(), "Expect name before '%c'\n", token[0]);
return false; return false;
} }
do op = readChar(); while (op == ' '); // what comes after token? do op = readChar(); while (op == ' '); // what comes after token?
if (op == EOF) if (op == EOF)
{ {
errorMsg("Unexpected end of file after: %s\n", token()); error(line, filename(), "Unexpected end of file after: %s\n", token());
return false; return false;
} }
if (op == '=') if (op == '=')
@ -311,20 +299,20 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
// variable assignment // variable assignment
if (isHandlerContext(protocol, commands)) if (isHandlerContext(protocol, commands))
{ {
errorMsg("Variables are not allowed in handlers: %s\n", error(line, filename(), "Variables are not allowed in handlers: %s\n",
token()); token());
return false; return false;
} }
if (token[0] == '@' || (token[0] >= '0' && token[0] <= '9')) if (token[0] == '@' || (token[0] >= '0' && token[0] <= '9'))
{ {
errorMsg("Variable name cannot start with '%c': %s\n", error(line, filename(), "Variable name cannot start with '%c': %s\n",
token[0], token()); token[0], token());
return false; return false;
} }
if (!parseAssignment(token(), protocol)) if (!parseAssignment(token(), protocol))
{ {
line = startline; line = startline;
errorMsg("in variable assignment '%s = ...'\n", token()); error(line, filename(), "in variable assignment '%s = ...'\n", token());
return false; return false;
} }
continue; continue;
@ -336,7 +324,7 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
{ {
if (isHandlerContext(protocol, commands)) if (isHandlerContext(protocol, commands))
{ {
errorMsg("Handlers are not allowed in handlers: %s\n", error(line, filename(), "Handlers are not allowed in handlers: %s\n",
token()); token());
return false; return false;
} }
@ -345,7 +333,7 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
if (!parseProtocol(protocol, handler)) if (!parseProtocol(protocol, handler))
{ {
line = startline; line = startline;
errorMsg("in handler '%s'\n", token()); error(line, filename(), "in handler '%s'\n", token());
return false; return false;
} }
continue; continue;
@ -353,16 +341,16 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
// protocol definition // protocol definition
if (!isGlobalContext(commands)) if (!isGlobalContext(commands))
{ {
errorMsg("Definition of '%s' not in global context (missing '}' ?)\n", error(line, filename(), "Definition of '%s' not in global context (missing '}' ?)\n",
token()); token());
return false; return false;
} }
Protocol** ppP; Protocol** ppP;
for (ppP = &protocols; *ppP; ppP = &(*ppP)->next) for (ppP = &protocols; *ppP; ppP = &(*ppP)->next)
{ {
if ((*ppP)->protocolname.equals(token())) if ((*ppP)->protocolname.startswith(token()))
{ {
errorMsg("Protocol '%s' redefined\n", token()); error(line, filename(), "Protocol '%s' redefined\n", token());
return false; return false;
} }
} }
@ -370,7 +358,7 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
if (!parseProtocol(*pP, pP->commands)) if (!parseProtocol(*pP, pP->commands))
{ {
line = startline; line = startline;
errorMsg("in protocol '%s'\n", token()); error(line, filename(), "in protocol '%s'\n", token());
delete pP; delete pP;
return false; return false;
} }
@ -381,7 +369,7 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
// Must be a command or a protocol reference. // Must be a command or a protocol reference.
if (isGlobalContext(commands)) if (isGlobalContext(commands))
{ {
errorMsg("Expect '=' or '{' instead of '%c' after '%s'\n", error(line, filename(), "Expect '=' or '{' instead of '%c' after '%s'\n",
op, token()); op, token());
return false; return false;
} }
@ -392,7 +380,7 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
Protocol* p; Protocol* p;
for (p = protocols; p; p = p->next) for (p = protocols; p; p = p->next)
{ {
if (p->protocolname.equals(token())) if (p->protocolname.startswith(token()))
{ {
commands->append(*p->commands); commands->append(*p->commands);
break; break;
@ -406,7 +394,7 @@ parseProtocol(Protocol& protocol, StreamBuffer* commands)
if (parseValue(*commands, true) == false) if (parseValue(*commands, true) == false)
{ {
line = startline; line = startline;
errorMsg("after command '%s'\n", token()); error(line, filename(), "after command '%s'\n", token());
return false; return false;
} }
debug("parseProtocol: command '%s'\n", (*commands).expand()()); debug("parseProtocol: command '%s'\n", (*commands).expand()());
@ -486,7 +474,7 @@ Each time newline is read, line is incremented.
c = getc(file); c = getc(file);
if (c != '}') if (c != '}')
{ {
errorMsg("Expect '}' instead of '%c' after: %s\n", error(line, filename(), "Expect '}' instead of '%c' after: %s\n",
c, buffer(token)); c, buffer(token));
return false; return false;
} }
@ -495,12 +483,12 @@ Each time newline is read, line is incremented.
} }
if (c == EOF) if (c == EOF)
{ {
errorMsg("Unexpected end of file after '$'\n"); error(line, filename(), "Unexpected end of file after '$'\n");
return false; return false;
} }
if (strchr (specialchars, c)) if (strchr (specialchars, c))
{ {
errorMsg("Unexpected '%c' after '$'\n,", c); error(line, filename(), "Unexpected '%c' after '$'\n,", c);
return false; return false;
} }
// variable like $xyz handled as word token // variable like $xyz handled as word token
@ -519,7 +507,7 @@ Each time newline is read, line is incremented.
{ {
if (c == EOF || c == '\n') if (c == EOF || c == '\n')
{ {
errorMsg("Unterminated quoted string: %s\n", error(line, filename(), "Unterminated quoted string: %s\n",
buffer(token)); buffer(token));
return false; return false;
} }
@ -532,7 +520,7 @@ Each time newline is read, line is incremented.
break; break;
} }
buffer.append(c); buffer.append(c);
if (c == quote && buffer[-1] != '\\') if (c == quote && buffer[-2] != '\\')
{ {
quote = false; quote = false;
break; break;
@ -547,7 +535,7 @@ Each time newline is read, line is incremented.
// end of file // end of file
if (!eofAllowed) if (!eofAllowed)
{ {
errorMsg("Unexpected end of file\n"); error(line, filename(), "Unexpected end of file\n");
return false; return false;
} }
buffer.append('\0'); buffer.append('\0');
@ -620,7 +608,7 @@ parseValue(StreamBuffer& buffer, bool lazy)
} }
if (c == '{' || c == '=') if (c == '{' || c == '=')
{ {
errorMsg("Unexpected '%c' (missing ';' or '\"' ?)\n", c); error(line, filename(), "Unexpected '%c' (missing ';' or '\"' ?)\n", c);
return false; return false;
} }
if (strchr (";}", c)) if (strchr (";}", c))
@ -657,6 +645,9 @@ printString(StreamBuffer& buffer, const char* s)
case skip: case skip:
buffer.append("\\?"); buffer.append("\\?");
break; break;
case whitespace:
buffer.append("\\_");
break;
case '"': case '"':
buffer.append("\\\""); buffer.append("\\\"");
break; break;
@ -768,18 +759,6 @@ StreamProtocolParser::Protocol::
delete next; delete next;
} }
void StreamProtocolParser::Protocol::
errorMsg(int l, const char* fmt, ...)
{
char fmt2[200];
sprintf (fmt2, "'%s' line %d: %s",
filename(), line, fmt);
va_list args;
va_start(args, fmt);
StreamVError(fmt2, args);
va_end(args);
}
void StreamProtocolParser::Protocol:: void StreamProtocolParser::Protocol::
report() report()
{ {
@ -811,7 +790,7 @@ createVariable(const char* name, int linenr)
Variable** ppV; Variable** ppV;
for (ppV = &variables; *ppV; ppV = &(*ppV)->next) for (ppV = &variables; *ppV; ppV = &(*ppV)->next)
{ {
if ((*ppV)->name.equals(name)) if ((*ppV)->name.startswith(name))
{ {
(*ppV)->line = linenr; (*ppV)->line = linenr;
return &(*ppV)->value; return &(*ppV)->value;
@ -829,7 +808,7 @@ getVariable(const char* name)
for (pV = variables; pV; pV = pV->next) for (pV = variables; pV; pV = pV->next)
{ {
if (pV->name.equals(name)) if (pV->name.startswith(name))
{ {
pV->used = true; pV->used = true;
return pV; return pV;
@ -847,12 +826,12 @@ getNumberVariable(const char* varname, unsigned long& value, unsigned long max)
if (!compileNumber(value, source, max)) if (!compileNumber(value, source, max))
{ {
int linenr = getLineNumber(source); int linenr = getLineNumber(source);
errorMsg(linenr, "in variable %s\n", varname); error(linenr, filename(), "in variable %s\n", varname);
return false; return false;
} }
if (source != pvar->value.end()) if (source != pvar->value.end())
{ {
errorMsg(getLineNumber(source), error(getLineNumber(source), filename(),
"Garbage in variable '%s' after numeric value %ld: %s\n", "Garbage in variable '%s' after numeric value %ld: %s\n",
varname, value, source); varname, value, source);
return false; return false;
@ -867,7 +846,7 @@ getEnumVariable(const char* varname, unsigned short& value, const char** enumstr
if (!pvar) return true; if (!pvar) return true;
for (value = 0; enumstrings[value]; value++) for (value = 0; enumstrings[value]; value++)
{ {
if (pvar->value.equals(enumstrings[value])) if (pvar->value.startswith(enumstrings[value]))
{ {
return true; return true;
} }
@ -925,13 +904,14 @@ getCommands(const char* handlername,StreamBuffer& code, Client* client)
{ {
if (handlername) if (handlername)
{ {
errorMsg(pvar->line, error(pvar->line, filename(),
"in handler '%s'\n", handlername); "in handler '%s'\n", handlername);
errorMsg(variables->line, error(variables->line, filename(),
"used by protocol '%s'\n", protocolname()); "used by protocol '%s'\n", protocolname());
return false; return false;
} }
errorMsg(pvar->line, "in protocol '%s'\n", protocolname()); error(pvar->line, filename(),
"in protocol '%s'\n", protocolname());
return false; return false;
} }
debug("commands %s: %s\n", handlername, pvar->value.expand()()); debug("commands %s: %s\n", handlername, pvar->value.expand()());
@ -955,7 +935,7 @@ replaceVariable(StreamBuffer& buffer, const char* varname)
const char* p = parameter[*varname-'0']; const char* p = parameter[*varname-'0'];
if (!p) if (!p)
{ {
errorMsg(linenr, error(linenr, filename(),
"Missing value for parameter $%c\n", *varname); "Missing value for parameter $%c\n", *varname);
return false; return false;
} }
@ -981,7 +961,7 @@ replaceVariable(StreamBuffer& buffer, const char* varname)
const Variable* v = getVariable(varname); const Variable* v = getVariable(varname);
if (!v) if (!v)
{ {
errorMsg(linenr, error(linenr, filename(),
"Undefined variable '%s' referenced\n", "Undefined variable '%s' referenced\n",
varname); varname);
return false; return false;
@ -1045,7 +1025,7 @@ compileNumber(unsigned long& number, const char*& source, unsigned long max)
{ {
debug("StreamProtocolParser::Protocol::compileNumber: %s\n", debug("StreamProtocolParser::Protocol::compileNumber: %s\n",
buffer.expand()()); buffer.expand()());
errorMsg(getLineNumber(source), error(getLineNumber(source), filename(),
"Unsigned numeric value expected: %s\n", buffer()); "Unsigned numeric value expected: %s\n", buffer());
return false; return false;
} }
@ -1053,7 +1033,7 @@ compileNumber(unsigned long& number, const char*& source, unsigned long max)
{ {
debug("StreamProtocolParser::Protocol::compileNumber: %s\n", debug("StreamProtocolParser::Protocol::compileNumber: %s\n",
buffer.expand()()); buffer.expand()());
errorMsg(getLineNumber(source), error(getLineNumber(source), filename(),
"Garbage after numeric value: %s\n", buffer()); "Garbage after numeric value: %s\n", buffer());
return false; return false;
} }
@ -1061,7 +1041,7 @@ compileNumber(unsigned long& number, const char*& source, unsigned long max)
{ {
debug("StreamProtocolParser::Protocol::compileNumber: %s\n", debug("StreamProtocolParser::Protocol::compileNumber: %s\n",
buffer.expand()()); buffer.expand()());
errorMsg(getLineNumber(source), error(getLineNumber(source), filename(),
"Value %s out of range [0...%ld]\n", buffer(), max); "Value %s out of range [0...%ld]\n", buffer(), max);
return false; return false;
} }
@ -1080,10 +1060,9 @@ compileString(StreamBuffer& buffer, const char*& source,
{ {
bool escaped = false; bool escaped = false;
int n; int n;
long formatPos[20];
int numFormats = 0;
int newline = 0; int newline = 0;
StreamBuffer formatbuffer; StreamBuffer formatbuffer;
int formatpos = buffer.length();
line = getLineNumber(source); line = getLineNumber(source);
debug("StreamProtocolParser::Protocol::compileString " debug("StreamProtocolParser::Protocol::compileString "
@ -1094,41 +1073,58 @@ compileString(StreamBuffer& buffer, const char*& source,
// 1) read a line from protocol source and code quoted strings, // 1) read a line from protocol source and code quoted strings,
// numerical bytes, tokens, etc, and replace variables and parameters // numerical bytes, tokens, etc, and replace variables and parameters
// 2) replace the formats in the line // 2) replace the formats in the line
// thus variables can be replaces inside the format info string // thus variables can be replaced inside the format info string
while (1) while (1)
{ {
debug("StreamProtocolParser::Protocol::compileString "
"buffer so far: %s\n", buffer.expand()());
// this is step 2: replacing the formats // this is step 2: replacing the formats
if (!*source || (newline = getLineNumber(source)) != line) if (!*source || (newline = getLineNumber(source)) != line)
{ {
// compile all formats in this line // compile all formats in this line
// We do this here after all variables in this line // We do this here after all variables in this line
// have been replaced and after string has been coded. // have been replaced and after string has been coded.
int offs = 0; if (formatType != NoFormat)
for (n = 0; n < numFormats; n++)
{ {
int pos = formatPos[n] + offs; int nformats=0;
debug("StreamProtocolParser::Protocol::compileString " char c;
"format=\"%s\"\n", buffer.expand(pos)()); while ((c = buffer[formatpos]) != '\0')
formatbuffer.clear();
const char* p = buffer(pos);
if (!compileFormat(formatbuffer, p, formatType, client))
{ {
p = buffer(pos); if (c == esc) {
formatbuffer.clear(); // ignore escaped %
printString(formatbuffer, p); formatpos+=2;
errorMsg(line, "in format string: \"%s\"\n", continue;
formatbuffer()); }
return false; if (c == '%') {
debug("StreamProtocolParser::Protocol::compileString "
"format=\"%s\"\n", buffer.expand(formatpos)());
nformats++;
formatbuffer.clear();
const char* p = buffer(formatpos);
if (!compileFormat(formatbuffer, p, formatType, client))
{
p = buffer(formatpos);
formatbuffer.clear();
printString(formatbuffer, p);
error(line, filename(),
"in format string: \"%s\"\n",
formatbuffer());
return false;
}
int formatlen = p - buffer(formatpos);
buffer.replace(formatpos, formatlen, formatbuffer);
debug("StreamProtocolParser::Protocol::compileString "
"replaced by: \"%s\"\n", buffer.expand(formatpos)());
formatpos += formatbuffer.length();
continue;
}
formatpos ++;
} }
int formatlen = p - buffer(pos);
buffer.replace(pos, formatlen, formatbuffer);
debug("StreamProtocolParser::Protocol::compileString " debug("StreamProtocolParser::Protocol::compileString "
"replaced by: \"%s\"\n", buffer.expand(pos)()); "%d formats found in line %d\n", nformats, line);
offs += formatbuffer.length() - formatlen;
} }
if (!*source) break; if (!*source) break;
numFormats = 0;
line = newline; line = newline;
} }
// this is step 1: coding the string // this is step 1: coding the string
@ -1144,19 +1140,15 @@ compileString(StreamBuffer& buffer, const char*& source,
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
errorMsg(line, error(line, filename(),
"INTERNAL ERROR: unconverted \\$ in quoted string\n"); "INTERNAL ERROR: unconverted \\$ in quoted string\n");
return false; return false;
case '?': case '?':
if (formatType != ScanFormat)
{
errorMsg(line,
"Quoted \\? only allowed in input: %s\n",
source-1);
return false;
}
buffer.append(skip); buffer.append(skip);
break; break;
case '_':
buffer.append(whitespace);
break;
case 'a': case 'a':
buffer.append(7); buffer.append(7);
break; break;
@ -1179,7 +1171,7 @@ compileString(StreamBuffer& buffer, const char*& source,
sscanf (source, "%3o%n", &temp, &n); sscanf (source, "%3o%n", &temp, &n);
if (temp > 0xFF) if (temp > 0xFF)
{ {
errorMsg(line, error(line, filename(),
"Octal source %#o does not fit in byte: %s\n", "Octal source %#o does not fit in byte: %s\n",
temp, source-1); temp, source-1);
return false; return false;
@ -1195,7 +1187,7 @@ compileString(StreamBuffer& buffer, const char*& source,
case 'x': // hex numbers (max 2 digits after 0) case 'x': // hex numbers (max 2 digits after 0)
if (sscanf (source+1, "%2x%n", &temp, &n) < 1) if (sscanf (source+1, "%2x%n", &temp, &n) < 1)
{ {
errorMsg(line, 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;
@ -1220,7 +1212,7 @@ compileString(StreamBuffer& buffer, const char*& source,
sscanf (source, "%3u%n", &temp, &n); sscanf (source, "%3u%n", &temp, &n);
if (temp > 0xFF) if (temp > 0xFF)
{ {
errorMsg(line, error(line, filename(),
"Decimal source %d does not fit in byte: %s\n", "Decimal source %d does not fit in byte: %s\n",
temp, source-1); temp, source-1);
return false; return false;
@ -1239,29 +1231,13 @@ compileString(StreamBuffer& buffer, const char*& source,
source++; source++;
continue; continue;
} }
if (quoted) // look for ending quotes, escapes, and formats if (quoted) // look for ending quotes and escapes
{ {
switch (*source) switch (*source)
{ {
case '\\': // escape next character case '\\': // escape next character
escaped = true; escaped = true;
break; break;
case '%': // format specifier in string
if (formatType != NoFormat)
{
// format is allowed here
// just memorize position here and and do actual coding later
// after all variables and parameters have been replaced
// so that extra information is ready for format converter
if (numFormats+1 == sizeof(formatPos))
{
errorMsg(line, "Max 20 formats allowed in one protocol line");
return false;
}
formatPos[numFormats++]=buffer.length();
buffer.append(*source);
break;
}
case '"': case '"':
case '\'': case '\'':
if (*source == quoted) // ending quote if (*source == quoted) // ending quote
@ -1310,13 +1286,13 @@ compileString(StreamBuffer& buffer, const char*& source,
{ {
if (*p != 0) if (*p != 0)
{ {
errorMsg(line, error(line, filename(),
"Garbage after numeric source: %s", source); "Garbage after numeric source: %s", source);
return false; return false;
} }
if (temp > 0xFF || temp < -0x80) if (temp > 0xFF || temp < -0x80)
{ {
errorMsg(line, 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;
} }
@ -1349,6 +1325,7 @@ compileString(StreamBuffer& buffer, const char*& source,
{"nl", 0x0A}, {"nl", 0x0A},
{"vt", 0x0B}, {"vt", 0x0B},
{"ff", 0x0C}, {"ff", 0x0C},
{"np", 0x0C},
{"cr", 0x0D}, {"cr", 0x0D},
{"so", 0x0E}, {"so", 0x0E},
{"si", 0x0F}, {"si", 0x0F},
@ -1379,7 +1356,7 @@ compileString(StreamBuffer& buffer, const char*& source,
c = codes[i].code; c = codes[i].code;
if (c == skip && formatType != ScanFormat) if (c == skip && formatType != ScanFormat)
{ {
errorMsg(line, error(line, filename(),
"Use of '%s' only allowed in input formats\n", "Use of '%s' only allowed in input formats\n",
source); source);
return false; return false;
@ -1396,7 +1373,7 @@ compileString(StreamBuffer& buffer, const char*& source,
} }
if (c) continue; if (c) continue;
// source may contain a function name // source may contain a function name
errorMsg(line, error(line, filename(),
"Unexpected word: %s\n", source); "Unexpected word: %s\n", source);
return false; return false;
} }
@ -1432,14 +1409,14 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
buffer.append(format_field); buffer.append(format_field);
if (!client) if (!client)
{ {
errorMsg(line, error(line, filename(),
"Using fieldname is not possible in this context\n"); "Using fieldname is not possible in this context\n");
return false; return false;
} }
const char* fieldnameEnd = strchr(source+=2, ')'); const char* fieldnameEnd = strchr(source+=2, ')');
if (!fieldnameEnd) if (!fieldnameEnd)
{ {
errorMsg(line, error(line, filename(),
"Missing ')' after field name\n"); "Missing ')' after field name\n");
return false; return false;
} }
@ -1451,7 +1428,7 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
StreamBuffer fieldAddress; StreamBuffer fieldAddress;
if (!client->getFieldAddress(buffer(fieldname), fieldAddress)) if (!client->getFieldAddress(buffer(fieldname), fieldAddress))
{ {
errorMsg(line, error(line, filename(),
"Field '%s' not found\n", buffer(fieldname)); "Field '%s' not found\n", buffer(fieldname));
return false; return false;
} }
@ -1465,130 +1442,12 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
buffer.append(format); buffer.append(format);
} }
const char* formatstart = source + 1; const char* formatstart = source + 1;
// look for flags
streamFormat.flags = 0;
bool loop = true;
while (loop)
{
switch (*++source)
{
case '-':
streamFormat.flags |= left_flag;
break;
case '+':
streamFormat.flags |= sign_flag;
break;
case ' ':
streamFormat.flags |= space_flag;
break;
case '#':
streamFormat.flags |= alt_flag;
break;
case '0':
streamFormat.flags |= zero_flag;
break;
case '*':
if (formatType != ScanFormat)
{
errorMsg(line,
"Use of skip modifier '*' "
"only allowed in input formats\n");
return false;
}
if (fieldname)
{
errorMsg(line,
"Use of skip modifier '*' not allowed "
"together with field name\n");
return false;
}
streamFormat.flags |= skip_flag;
break;
default:
loop = false;
}
}
/*
if (formatType != PrintFormat &&
streamFormat.flags & (left_flag|sign_flag|space_flag|zero_flag))
{
errorMsg(line,
"Use of format modifiers '-', '+', ' ', '0' "
"only allowed in output formats\n");
return false;
}
if (!(~streamFormat.flags & (left_flag|zero_flag)))
{
errorMsg(line,
"Can't use modifiers '-' and '0' together\n");
return false;
}
if (!(~streamFormat.flags & (space_flag|sign_flag)))
{
errorMsg(line,
"Can't use modifiers ' ' and '+' together\n");
return false;
}
*/
// look for width
unsigned long val;
char* p;
val = strtoul (source, &p, 10);
source = p;
if (val > 0xFFFF)
{
errorMsg(line,
"Field width %ld out of range\n", val);
return false;
}
streamFormat.width = (unsigned short)val;
// look for prec
streamFormat.prec = -1;
if (*source == '.')
{
source++;
val = strtoul(source, &p, 10);
if (p == source)
{
debug("source = %s\n", source);
errorMsg(line,
"Numeric precision field expected after '.'\n");
return false;
}
source = p;
if (val > 0x7FFF)
{
errorMsg(line,
"Precision %ld out of range\n", val);
return false;
}
streamFormat.prec = (short)val;
}
// look for converter
streamFormat.conv = *source++;
debug("StreamProtocolParser::Protocol::compileFormat: converter='%c'\n",
streamFormat.conv);
if (!streamFormat.conv || strchr("'\" (.0+-*", streamFormat.conv))
{
debug("StreamProtocolParser::Protocol::compileFormat: formatstr='%s'\n",
formatstr);
errorMsg(line,
"Missing converter character\n");
return false;
}
StreamFormatConverter* converter;
converter = StreamFormatConverter::find(streamFormat.conv);
if (!converter)
{
errorMsg(line,
"No converter registered for format '%%%c'\n",
streamFormat.conv);
return false;
}
// parse format and get info string // parse format and get info string
StreamBuffer infoString; StreamBuffer infoString;
int type = converter->parse(streamFormat, infoString, int type = StreamFormatConverter::parseFormat(source,
source, formatType == ScanFormat); formatType, streamFormat, infoString);
if (!type) if (!type)
{ {
// parsing failed // parsing failed
@ -1596,18 +1455,25 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
} }
if (type < long_format && type > pseudo_format) if (type < long_format && type > pseudo_format)
{ {
errorMsg(line, error(line, filename(),
"Illegal format type %d returned from '%%%c' converter\n", "Illegal format type %d returned from '%%%c' converter\n",
type, streamFormat.conv); type, streamFormat.conv);
return false; return false;
} }
if (type == pseudo_format && fieldname) if (type == pseudo_format && fieldname)
{ {
errorMsg(line, error(line, filename(),
"Fieldname not allowed with pseudo format: '%%(%s)%c'\n", "Fieldname not allowed with pseudo format: '%%(%s)%c'\n",
buffer(fieldname), streamFormat.conv); buffer(fieldname), streamFormat.conv);
return false; return false;
} }
if (fieldname && streamFormat.flags & skip_flag)
{
error(line, filename(),
"Use of skip modifier '*' not allowed "
"together with redirection\n");
return false;
}
streamFormat.type = static_cast<StreamFormatType>(type); streamFormat.type = static_cast<StreamFormatType>(type);
if (infoString && infoString[-1] != eos) if (infoString && infoString[-1] != eos)
{ {
@ -1645,13 +1511,13 @@ compileCommands(StreamBuffer& buffer, const char*& source, Client* client)
args = source + strlen(source)+1+sizeof(int); args = source + strlen(source)+1+sizeof(int);
if (!client->compileCommand(this, buffer, command, args)) if (!client->compileCommand(this, buffer, command, args))
{ {
errorMsg(getLineNumber(source), error(getLineNumber(source), filename(),
"in command '%s'\n", command); "in command '%s'\n", command);
return false; return false;
} }
if (*args) if (*args)
{ {
errorMsg(getLineNumber(source), error(getLineNumber(source), filename(),
"Garbage after '%s' command: '%s'\n", "Garbage after '%s' command: '%s'\n",
command, args); command, args);
return false; return false;

View File

@ -32,7 +32,7 @@ public:
enum Codes enum Codes
{ {
eos = 0, skip, format, format_field, last_function_code eos = 0, skip, whitespace, format, format_field, last_function_code
}; };
class Client; class Client;
@ -75,8 +75,6 @@ public:
bool compileString(StreamBuffer& buffer, const char*& source, bool compileString(StreamBuffer& buffer, const char*& source,
FormatType formatType = NoFormat, Client* = NULL, int quoted = false); FormatType formatType = NoFormat, Client* = NULL, int quoted = false);
bool checkUnused(); bool checkUnused();
void errorMsg(int line, const char* fmt, ...)
__attribute__ ((format(printf,3,4)));
~Protocol(); ~Protocol();
void report(); void report();
}; };
@ -115,8 +113,6 @@ private:
const char* specialchars = NULL, bool eofAllowed = false); const char* specialchars = NULL, bool eofAllowed = false);
bool parseAssignment(const char* variable, Protocol&); bool parseAssignment(const char* variable, Protocol&);
bool parseValue(StreamBuffer& buffer, bool lazy = false); bool parseValue(StreamBuffer& buffer, bool lazy = false);
void errorMsg(const char* fmt, ...)
__attribute__ ((format(printf,2,3)));
protected: protected:
~StreamProtocolParser(); // get rid of cygnus-2.7.2 compiler warning ~StreamProtocolParser(); // get rid of cygnus-2.7.2 compiler warning

539
src/TimestampConverter.cc Normal file
View File

@ -0,0 +1,539 @@
/***************************************************************
* StreamDevice Support *
* *
* (C) 1999 Dirk Zimoch (zimoch@delta.uni-dortmund.de) *
* (C) 2010 Dirk Zimoch (dirk.zimoch@psi.ch) *
* *
* This is the time stamp converter of StreamDevice. *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include "StreamFormatConverter.h"
#include "StreamError.h"
#include <time.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#ifdef _WIN32
#define tzset() _tzset()
#define timezone _timezone
#define localtime_r(timet,tm) localtime_s(tm,timet) /* Windows sucks */
#endif
#ifdef __rtems__
#define timezone _timezone
#endif
#ifdef vxWorks
int timezone = 0;
#define tzset() do {\
(void) (sscanf(getenv("TIMEZONE"), "%*[^:]::%d", &timezone) || \
sscanf(getenv("TIMEZONE"), "%*[^:]:%*[^:]:%d", &timezone) || \
sscanf(getenv("EPICS_TS_MIN_WEST"), "%d", &timezone));\
timezone*=60;\
} while (0)
#endif
class TimestampConverter : public StreamFormatConverter
{
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printDouble(const StreamFormat&, StreamBuffer&, double);
int scanDouble(const StreamFormat&, const char*, double&);
};
int TimestampConverter::
parse(const StreamFormat&, StreamBuffer& info,
const char*& source, bool)
{
unsigned int n;
char* c;
if (*source == '(')
{
while (*++source != ')')
{
switch (*source)
{
case 0:
error ("missing ')' after %%T format\n");
return false;
case esc:
info.append(*++source);
if (*source == '%') info.append('%');
break;
case '%':
source++;
/* look for formatted fractions like %3f */
if (isdigit(*source))
{
n = strtoul(source, &c, 10);
if (*c == 'f')
{
source = c;
info.printf("%%0%uf", n);
break;
}
}
/* look for nanoseconds %N of %f */
if (*source == 'N' || *source == 'f')
{
info.printf("%%09f");
break;
}
/* look for seconds with fractions like %.3S */
if (*source == '.')
{
c = (char*) source+1;
n = isdigit(*c) ? strtoul(c, &c, 10) : 9;
if (toupper(*c) == 'S')
{
source = c;
info.printf("%%%c.%%0%uf", *c, n);
break;
}
}
/* else normal format */
info.append('%');
default:
info.append(*source);
}
}
source++;
info.append('\0');
}
else
{
info.append("%Y-%m-%d %H:%M:%S").append('\0');
}
return double_format;
}
bool TimestampConverter::
printDouble(const StreamFormat& format, StreamBuffer& output, double value)
{
struct tm brokenDownTime;
char buffer [40];
char fracbuffer [15];
int length;
time_t sec;
double frac;
int i, n;
char* c;
char* p;
sec = (time_t) value;
frac = value - sec;
localtime_r(&sec, &brokenDownTime);
debug ("TimestampConverter::printDouble %f, '%s'\n", value, format.info);
length = strftime(buffer, sizeof(buffer), format.info, &brokenDownTime);
i = output.length();
output.append(buffer, length);
/* look for fractional seconds */
while ((i = output.find("%0",i)) != -1)
{
n = strtol(output(i+1), &c, 10);
if (*c++ != 'f') return false;
/* print fractional part */
sprintf(fracbuffer, "%.*f", n, frac);
p = strchr(fracbuffer, '.')+1;
output.replace(i, c-output(i), p);
}
return true;
}
/* many OS don't have strptime or strptime does not fully support
all fields, e.g. %z.
*/
static int strmatch(const char*& input, const char** strings, int minlen)
{
int i;
int c;
for (i=0; strings[i]; i++) {
for (c=0; ; c++)
{
if (strings[i][c] == 0) {
input += c;
return i;
}
if (tolower(input[c]) != strings[i][c]) {
if (c >= minlen) {
input += c;
return i;
}
break;
}
}
}
return -1;
}
static int nummatch(const char*& input, int min, int max)
{
int i;
char *c;
i = strtol(input, &c, 10);
if (c == input) return -10000;
if (i < min || i > max) return -10000;
input = c;
return i;
}
static const char* scantime(const char* input, const char* format, struct tm *tm, unsigned long *ns)
{
static const char* months[] = {
"january", "february", "march", "april", "may", "june",
"july", "august", "september", "november", "december", 0 };
static const char* ampm[] = {
"am", "pm", 0 };
int i, n;
int pm = -1;
int century = -1;
int zone = 0;
tzset();
zone = timezone/60;
debug ("TimestampConverter::scantime: native time zone = %d\n", zone);
while (*format)
{
switch (*format)
{
case '%':
debug ("TimestampConverter::scantime: input = '%s'\n", input);
format++;
startover:
switch (*format++)
{
/* Modifiers (ignore) */
case 'E':
case 'O':
goto startover;
/* constants */
case 0: /* stray % at end of format string */
format--;
case '%':
if (*input++ != '%') return NULL;
break;
case 'n':
if (*input++ != '\n') return NULL;
break;
case 't':
if (*input++ != '\t') return NULL;
break;
/* ignored */
case 'A': /* day of week name */
case 'a':
while (isalpha((int)*input)) input++;
/* ignore */
break;
case 'u': /* day of week number (Monday = 1 to Sunday = 7) */
case 'w': /* day of week number (Sunday = 0 to Saturday = 6) */
i = nummatch(input, 0, 7);
if (i < 0)
{
error ("error parsing day of week: '%.20s'\n", input);
return NULL;
}
debug ("TimestampConverter::scantime: day of week = %d\n", i);
/* ignore */
break;
case 'U': /* week number */
case 'W':
case 'V':
i = nummatch(input, 0, 53);
if (i < 0)
{
error ("error parsing week number: '%.20s'\n", input);
return NULL;
}
debug ("TimestampConverter::scantime: week number = %d\n", i);
/* ignore */
break;
case 'j': /* day of year */
i = nummatch(input, 0, 366);
if (i < 0)
{
error ("error parsing day of year: '%.20s'\n", input);
return NULL;
}
debug ("TimestampConverter::scantime: day of year = %d\n", i);
/* ignore */
break;
case 'Z': /* time zone name */
while (isalpha((int)*input)) input++;
/* ignore */
break;
/* date */
case 'b': /* month */
case 'h':
case 'B':
case 'm':
i = strmatch(input, months, 3);
if (i < 0)
{
i = nummatch(input, 1, 12);
if (i < 0)
{
error ("error parsing month: '%.20s'\n", input);
return NULL;
}
i--; /* Jan = 0 */
}
tm->tm_mon = i;
debug ("TimestampConverter::scantime: month = %d (%s)\n", tm->tm_mon+1, months[tm->tm_mon]);
break;
case 'd': /* day of month */
case 'e':
i = nummatch(input, 1, 31);
if (i < 0)
{
error ("error parsing day of month: '%.20s'\n", input);
return NULL;
}
tm->tm_mday = i;
debug ("TimestampConverter::scantime: day = %d\n", tm->tm_mday);
break;
case 'Y': /* year */
case 'y':
i = strtol(input, (char**)&input, 10);
if (i < 100)
{ /* 2 digit year */
if (century == -1) century = (i >= 69);
tm->tm_year = i + century * 100; /* 0 = 1900 */
}
else
{ /* 4 digit year */
tm->tm_year = i - 1900; /* 0 = 1900 */
}
debug ("TimestampConverter::scantime: year = %d\n", tm->tm_year + 1900);
break;
case 'C': /* century */
i = nummatch(input, 0, 99);
if (i < 0)
{
error ("error parsing century: '%.20s'\n", input);
return NULL;
}
century = i - 19;
tm->tm_year = tm->tm_year%100 + 100 * i; /* 0 = 1900 */
debug ("TimestampConverter::scantime: year = %d\n", tm->tm_year + 1900);
break;
/* time */
case 'H': /* hour */
case 'k':
case 'I':
case 'l':
i = nummatch(input, 0, 23);
if (i < 0)
{
error ("error parsing hour: '%.20s'\n", input);
return NULL;
}
if ((pm == 0) && (i == 12)) i = 0;
if ((pm == 1) && (i < 12)) i += 12;
tm->tm_hour = i;
debug ("TimestampConverter::scantime: hour = %d\n", tm->tm_hour);
break;
case 'P': /* AM / PM */
case 'p':
i = strmatch(input, ampm, 1);
if (i < 0)
{
error ("error parsing am/pm: '%.20s'\n", input);
return NULL;
}
pm = i;
if ((pm == 0) && (tm->tm_hour == 12)) tm->tm_hour = 0;
if ((pm == 1) && (tm->tm_hour < 12)) tm->tm_hour += 12;
debug ("TimestampConverter::scantime: %s hour = %d\n", pm?"PM":"AM", tm->tm_hour);
break;
case 'M': /* minute */
i = nummatch(input, 1, 59);
if (i < 0)
{
error ("error parsing minute: '%.20s'\n", input);
return NULL;
}
tm->tm_min = i;
debug ("TimestampConverter::scantime: min = %d\n", tm->tm_min);
break;
case 'S': /* second */
i = nummatch(input, 1, 60);
if (i < 0)
{
error ("error parsing week second: '%.20s'\n", input);
return NULL;
}
tm->tm_sec = i;
debug ("TimestampConverter::scantime: sec = %d\n", tm->tm_sec);
break;
case 's': /* second since 1970 */
i = strtol(input, (char**)&input, 10);
tm->tm_sec = i;
tm->tm_mon = -1;
tm->tm_isdst = 0;
debug ("TimestampConverter::scantime: sec = %d\n", tm->tm_sec);
break;
case '0': /* fractions of seconds like %09f */
n = strtol(format-1, (char**)&format, 10);
if (*format++ != 'f') return NULL;
debug ("max %d digits fraction in '%s'\n", n, input);
i = 0;
while (n-- && isdigit(*input))
{
i *= 10;
i += *input++ - '0';
}
while (i < 100000000) i *= 10;
*ns = i;
debug ("TimestampConverter::scantime: nanosec = %d, rest '%s'\n", i, input);
break;
case 'z': /* time zone offset */
i = nummatch(input, -2400, 2400);
if (i < -2400)
{
error ("error parsing time zone: '%.20s'\n", input);
return NULL;
}
zone = i / 100 * 60 + i % 100;
tm->tm_isdst = 0;
debug ("TimestampConverter::scantime: zone = %d\n", zone);
break;
case '+': /* set time zone in format string */
case '-':
format--;
i = nummatch(format, -2400, 2400);
zone = i / 100 * 60 + i % 100;
tm->tm_isdst = 0;
debug ("TimestampConverter::scantime: zone = %d\n", zone);
break;
/* shortcuts */
case 'c':
if ((input = scantime(input, "%a %b %d %H:%M:%S %Y", tm, ns)) == NULL)
return NULL;
break;
case 'D':
if ((input = scantime(input, "%m/%d/%y", tm, ns)) == NULL)
return NULL;
break;
case 'F':
if ((input = scantime(input, "%Y-%m-%d", tm, ns)) == NULL)
return NULL;
break;
case 'R':
if ((input = scantime(input, "%H:%M", tm, ns)) == NULL)
return NULL;
break;
case 'T':
if ((input = scantime(input, "%H:%M:%S", tm, ns)) == NULL)
return NULL;
break;
case 'x':
if ((input = scantime(input, "%m/%d/%y", tm, ns)) == NULL)
return NULL;
break;
case 'X':
case 'r':
if ((input = scantime(input, "%I:%M:%S %p", tm, ns)) == NULL)
return NULL;
break;
default:
error ("unknown time format %%%s\n", --format);
return NULL;
}
break;
case ' ':
format++;
while (isspace(*input)) input++;
break;
default:
if (*format++ != *input++)
{
error("input '%.20s' does not match constant '%.20s'\n", --input, --format);
return NULL;
}
}
}
zone -= timezone/60;
tm->tm_min += zone;
tm->tm_hour += tm->tm_min / 60;
tm->tm_min %= 60;
if (tm->tm_min < 0)
{
tm->tm_min += 60;
tm->tm_hour -= 1;
}
tm->tm_mday -= tm->tm_hour / 24;
tm->tm_hour %= 24;
if (tm->tm_hour < 0)
{
tm->tm_min += 24;
tm->tm_mday -= 1;
}
return input;
}
int TimestampConverter::
scanDouble(const StreamFormat& format, const char* input, double& value)
{
struct tm brokenDownTime;
time_t seconds;
unsigned long nanoseconds;
const char* end;
/* Init time stamp with "today" */
time (&seconds);
localtime_r(&seconds, &brokenDownTime);
brokenDownTime.tm_sec = 0;
brokenDownTime.tm_min = 0;
brokenDownTime.tm_hour = 0;
brokenDownTime.tm_yday = 0;
brokenDownTime.tm_isdst = -1;
nanoseconds = 0;
end = scantime(input, format.info, &brokenDownTime, &nanoseconds);
if (end == NULL) {
error ("error parsing time\n");
return -1;
}
if (brokenDownTime.tm_mon == -1) {
seconds = brokenDownTime.tm_sec;
} else {
seconds = mktime(&brokenDownTime);
if (seconds == (time_t) -1 && brokenDownTime.tm_yday == 0)
{
error ("mktime failed for %02d/%02d/%04d %02d:%02d:%02d\n",
brokenDownTime.tm_mon+1,
brokenDownTime.tm_mday,
brokenDownTime.tm_year+1900,
brokenDownTime.tm_hour,
brokenDownTime.tm_min,
brokenDownTime.tm_sec);
return -1;
}
}
value = seconds + nanoseconds*1e-9;
return end-input;
}
RegisterConverter (TimestampConverter, "T");

View File

@ -22,7 +22,7 @@
#define devStream_h #define devStream_h
#define STREAM_MAJOR 2 #define STREAM_MAJOR 2
#define STREAM_MINOR 3 #define STREAM_MINOR 4
#if defined(__vxworks) || defined(vxWorks) #if defined(__vxworks) || defined(vxWorks)
#include <vxWorks.h> #include <vxWorks.h>
@ -85,7 +85,6 @@ long streamReport(int interest);
long streamReadWrite(dbCommon *record); long streamReadWrite(dbCommon *record);
long streamGetIointInfo(int cmd, dbCommon *record, IOSCANPVT *ppvt); long streamGetIointInfo(int cmd, dbCommon *record, IOSCANPVT *ppvt);
long streamPrintf(dbCommon *record, format_t *format, ...); long streamPrintf(dbCommon *record, format_t *format, ...);
long streamScanSep(dbCommon *record);
long streamScanfN(dbCommon *record, format_t *format, long streamScanfN(dbCommon *record, format_t *format,
void*, size_t maxStringSize); void*, size_t maxStringSize);
@ -99,7 +98,7 @@ long streamScanfN(dbCommon *record, format_t *format,
#define devStreamGetIointInfo streamGetIointInfo #define devStreamGetIointInfo streamGetIointInfo
#define devStreamPrintf streamPrintf #define devStreamPrintf streamPrintf
#define devStreamPrintSep(record) (0) #define devStreamPrintSep(record) (0)
#define devStreamScanSep streamScanSep #define devStreamScanSep (0)
#define devStreamScanf(record, format, value) \ #define devStreamScanf(record, format, value) \
streamScanfN(record, format, value, MAX_STRING_SIZE) streamScanfN(record, format, value, MAX_STRING_SIZE)
#define streamScanf(record, format, value) \ #define streamScanf(record, format, value) \

View File

@ -22,6 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "devStream.h" #include "devStream.h"
#include <aaiRecord.h> #include <aaiRecord.h>
#include <errlog.h>
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -43,10 +44,10 @@ static long readData (dbCommon *record, format_t *format)
switch (aai->ftvl) switch (aai->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
((double *)aai->bptr)[aai->nord] = dval; ((epicsFloat64 *)aai->bptr)[aai->nord] = (epicsFloat64)dval;
break; break;
case DBF_FLOAT: case DBF_FLOAT:
((float *)aai->bptr)[aai->nord] = (float)dval; ((epicsFloat32 *)aai->bptr)[aai->nord] = (epicsFloat32)dval;
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -66,23 +67,23 @@ static long readData (dbCommon *record, format_t *format)
switch (aai->ftvl) switch (aai->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
((double *)aai->bptr)[aai->nord] = lval; ((epicsFloat64 *)aai->bptr)[aai->nord] = (epicsFloat64)lval;
break; break;
case DBF_FLOAT: case DBF_FLOAT:
((float *)aai->bptr)[aai->nord] = (float)lval; ((epicsFloat32 *)aai->bptr)[aai->nord] = (epicsFloat32)lval;
break; break;
case DBF_LONG: case DBF_LONG:
case DBF_ULONG: case DBF_ULONG:
((long *)aai->bptr)[aai->nord] = lval; ((epicsInt32 *)aai->bptr)[aai->nord] = (epicsInt32)lval;
break; break;
case DBF_SHORT: case DBF_SHORT:
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
((short *)aai->bptr)[aai->nord] = (short)lval; ((epicsInt16 *)aai->bptr)[aai->nord] = (epicsInt16)lval;
break; break;
case DBF_CHAR: case DBF_CHAR:
case DBF_UCHAR: case DBF_UCHAR:
((char *)aai->bptr)[aai->nord] = (char)lval; ((epicsInt8 *)aai->bptr)[aai->nord] = (epicsInt8)lval;
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -156,29 +157,29 @@ static long writeData (dbCommon *record, format_t *format)
switch (aai->ftvl) switch (aai->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
dval = ((double *)aai->bptr)[nowd]; dval = ((epicsFloat64 *)aai->bptr)[nowd];
break; break;
case DBF_FLOAT: case DBF_FLOAT:
dval = ((float *)aai->bptr)[nowd]; dval = ((epicsFloat32 *)aai->bptr)[nowd];
break; break;
case DBF_LONG: case DBF_LONG:
dval = ((long *)aai->bptr)[nowd]; dval = ((epicsInt32 *)aai->bptr)[nowd];
break; break;
case DBF_ULONG: case DBF_ULONG:
dval = ((unsigned long *)aai->bptr)[nowd]; dval = ((epicsUInt32 *)aai->bptr)[nowd];
break; break;
case DBF_SHORT: case DBF_SHORT:
dval = ((short *)aai->bptr)[nowd]; dval = ((epicsInt16 *)aai->bptr)[nowd];
break; break;
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
dval = ((unsigned short *)aai->bptr)[nowd]; dval = ((epicsUInt16 *)aai->bptr)[nowd];
break; break;
case DBF_CHAR: case DBF_CHAR:
dval = ((char *)aai->bptr)[nowd]; dval = ((epicsInt8 *)aai->bptr)[nowd];
break; break;
case DBF_UCHAR: case DBF_UCHAR:
dval = ((unsigned char *)aai->bptr)[nowd]; dval = ((epicsUInt8 *)aai->bptr)[nowd];
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -196,21 +197,23 @@ static long writeData (dbCommon *record, format_t *format)
switch (aai->ftvl) switch (aai->ftvl)
{ {
case DBF_LONG: case DBF_LONG:
lval = ((epicsInt32 *)aai->bptr)[nowd];
break;
case DBF_ULONG: case DBF_ULONG:
lval = ((long *)aai->bptr)[nowd]; lval = ((epicsUInt32 *)aai->bptr)[nowd];
break; break;
case DBF_SHORT: case DBF_SHORT:
lval = ((short *)aai->bptr)[nowd]; lval = ((epicsInt16 *)aai->bptr)[nowd];
break; break;
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
lval = ((unsigned short *)aai->bptr)[nowd]; lval = ((epicsUInt16 *)aai->bptr)[nowd];
break; break;
case DBF_CHAR: case DBF_CHAR:
lval = ((char *)aai->bptr)[nowd]; lval = ((epicsInt8 *)aai->bptr)[nowd];
break; break;
case DBF_UCHAR: case DBF_UCHAR:
lval = ((unsigned char *)aai->bptr)[nowd]; lval = ((epicsUInt8 *)aai->bptr)[nowd];
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,

View File

@ -22,6 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "devStream.h" #include "devStream.h"
#include <aaoRecord.h> #include <aaoRecord.h>
#include <errlog.h>
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -43,10 +44,10 @@ static long readData (dbCommon *record, format_t *format)
switch (aao->ftvl) switch (aao->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
((double *)aao->bptr)[aao->nord] = dval; ((epicsFloat64 *)aao->bptr)[aao->nord] = (epicsFloat64)dval;
break; break;
case DBF_FLOAT: case DBF_FLOAT:
((float *)aao->bptr)[aao->nord] = (float)dval; ((epicsFloat32 *)aao->bptr)[aao->nord] = (epicsFloat32)dval;
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -66,23 +67,23 @@ static long readData (dbCommon *record, format_t *format)
switch (aao->ftvl) switch (aao->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
((double *)aao->bptr)[aao->nord] = lval; ((epicsFloat64 *)aao->bptr)[aao->nord] = (epicsFloat64)lval;
break; break;
case DBF_FLOAT: case DBF_FLOAT:
((float *)aao->bptr)[aao->nord] = (float)lval; ((epicsFloat32 *)aao->bptr)[aao->nord] = (epicsFloat32)lval;
break; break;
case DBF_LONG: case DBF_LONG:
case DBF_ULONG: case DBF_ULONG:
((long *)aao->bptr)[aao->nord] = lval; ((epicsInt32 *)aao->bptr)[aao->nord] = (epicsInt32)lval;
break; break;
case DBF_SHORT: case DBF_SHORT:
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
((short *)aao->bptr)[aao->nord] = (short)lval; ((epicsInt16 *)aao->bptr)[aao->nord] = (epicsInt16)lval;
break; break;
case DBF_CHAR: case DBF_CHAR:
case DBF_UCHAR: case DBF_UCHAR:
((char *)aao->bptr)[aao->nord] = (char)lval; ((epicsInt8 *)aao->bptr)[aao->nord] = (epicsInt8)lval;
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -156,29 +157,29 @@ static long writeData (dbCommon *record, format_t *format)
switch (aao->ftvl) switch (aao->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
dval = ((double *)aao->bptr)[nowd]; dval = ((epicsFloat64 *)aao->bptr)[nowd];
break; break;
case DBF_FLOAT: case DBF_FLOAT:
dval = ((float *)aao->bptr)[nowd]; dval = ((epicsFloat32 *)aao->bptr)[nowd];
break; break;
case DBF_LONG: case DBF_LONG:
dval = ((long *)aao->bptr)[nowd]; dval = ((epicsInt32 *)aao->bptr)[nowd];
break; break;
case DBF_ULONG: case DBF_ULONG:
dval = ((unsigned long *)aao->bptr)[nowd]; dval = ((epicsUInt32 *)aao->bptr)[nowd];
break; break;
case DBF_SHORT: case DBF_SHORT:
dval = ((short *)aao->bptr)[nowd]; dval = ((epicsInt16 *)aao->bptr)[nowd];
break; break;
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
dval = ((unsigned short *)aao->bptr)[nowd]; dval = ((epicsUInt16 *)aao->bptr)[nowd];
break; break;
case DBF_CHAR: case DBF_CHAR:
dval = ((char *)aao->bptr)[nowd]; dval = ((epicsInt8 *)aao->bptr)[nowd];
break; break;
case DBF_UCHAR: case DBF_UCHAR:
dval = ((unsigned char *)aao->bptr)[nowd]; dval = ((epicsUInt8 *)aao->bptr)[nowd];
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -196,21 +197,23 @@ static long writeData (dbCommon *record, format_t *format)
switch (aao->ftvl) switch (aao->ftvl)
{ {
case DBF_LONG: case DBF_LONG:
lval = ((epicsInt32 *)aao->bptr)[nowd];
break;
case DBF_ULONG: case DBF_ULONG:
lval = ((long *)aao->bptr)[nowd]; lval = ((epicsUInt32 *)aao->bptr)[nowd];
break; break;
case DBF_SHORT: case DBF_SHORT:
lval = ((short *)aao->bptr)[nowd]; lval = ((epicsInt16 *)aao->bptr)[nowd];
break; break;
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
lval = ((unsigned short *)aao->bptr)[nowd]; lval = ((epicsUInt16 *)aao->bptr)[nowd];
break; break;
case DBF_CHAR: case DBF_CHAR:
lval = ((char *)aao->bptr)[nowd]; lval = ((epicsInt8 *)aao->bptr)[nowd];
break; break;
case DBF_UCHAR: case DBF_UCHAR:
lval = ((unsigned char *)aao->bptr)[nowd]; lval = ((epicsUInt8 *)aao->bptr)[nowd];
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,

View File

@ -25,12 +25,12 @@
static long readData (dbCommon *record, format_t *format) static long readData (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:
{ {
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) val *= ai->aslo;
val += ai->aoff; val += ai->aoff;
@ -43,7 +43,10 @@ static long readData (dbCommon *record, format_t *format)
} }
case DBF_LONG: case DBF_LONG:
{ {
return streamScanf (record, format, &ai->rval); long rval;
if (streamScanf (record, format, &rval)) return ERROR;
ai->rval = rval;
return OK;
} }
} }
return ERROR; return ERROR;
@ -64,7 +67,7 @@ static long writeData (dbCommon *record, format_t *format)
} }
case DBF_LONG: case DBF_LONG:
{ {
return streamPrintf (record, format, ai->rval); return streamPrintf (record, format, (long) ai->rval);
} }
} }
return ERROR; return ERROR;

View File

@ -51,12 +51,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)
{ {
aoRecord *ao = (aoRecord *) record; aoRecord *ao = (aoRecord *) record;
double val;
switch (format->type) switch (format->type)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
{ {
double val;
if (INIT_RUN) val = ao->val; if (INIT_RUN) val = ao->val;
else val = ao->oval; else val = ao->oval;
val -= ao->aoff; val -= ao->aoff;
@ -65,7 +65,7 @@ static long writeData (dbCommon *record, format_t *format)
} }
case DBF_LONG: case DBF_LONG:
{ {
return streamPrintf (record, format, ao->rval); return streamPrintf (record, format, (long) ao->rval);
} }
} }
return ERROR; return ERROR;

View File

@ -28,7 +28,10 @@ static long readData (dbCommon *record, format_t *format)
if (format->type == DBF_LONG || format->type == DBF_ENUM) if (format->type == DBF_LONG || format->type == DBF_ENUM)
{ {
return streamScanf (record, format, &li->val); long val;
if (streamScanf (record, format, &val)) return ERROR;
li->val = val;
return OK;
} }
return ERROR; return ERROR;
} }
@ -39,7 +42,7 @@ static long writeData (dbCommon *record, format_t *format)
if (format->type == DBF_LONG || format->type == DBF_ENUM) if (format->type == DBF_LONG || format->type == DBF_ENUM)
{ {
return streamPrintf (record, format, li->val); return streamPrintf (record, format, (long) li->val);
} }
return ERROR; return ERROR;
} }

View File

@ -29,7 +29,10 @@ static long readData (dbCommon *record, format_t *format)
if (format->type == DBF_LONG || format->type == DBF_ENUM) if (format->type == DBF_LONG || format->type == DBF_ENUM)
{ {
return streamScanf (record, format, &lo->val); long val;
if (streamScanf (record, format, &val)) return ERROR;
lo->val = val;
return OK;
} }
return ERROR; return ERROR;
} }
@ -40,7 +43,7 @@ static long writeData (dbCommon *record, format_t *format)
if (format->type == DBF_LONG || format->type == DBF_ENUM) if (format->type == DBF_LONG || format->type == DBF_ENUM)
{ {
return streamPrintf (record, format, lo->val); return streamPrintf (record, format, (long) lo->val);
} }
return ERROR; return ERROR;
} }

View File

@ -21,6 +21,7 @@
#include "devStream.h" #include "devStream.h"
#include <waveformRecord.h> #include <waveformRecord.h>
#include <string.h> #include <string.h>
#include <errlog.h>
#include <epicsExport.h> #include <epicsExport.h>
static long readData (dbCommon *record, format_t *format) static long readData (dbCommon *record, format_t *format)
@ -43,10 +44,10 @@ static long readData (dbCommon *record, format_t *format)
switch (wf->ftvl) switch (wf->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
((double *)wf->bptr)[wf->nord] = dval; ((epicsFloat64 *)wf->bptr)[wf->nord] = (epicsFloat64)dval;
break; break;
case DBF_FLOAT: case DBF_FLOAT:
((float *)wf->bptr)[wf->nord] = (float)dval; ((epicsFloat32 *)wf->bptr)[wf->nord] = (epicsFloat32)dval;
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -66,23 +67,23 @@ static long readData (dbCommon *record, format_t *format)
switch (wf->ftvl) switch (wf->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
((double *)wf->bptr)[wf->nord] = (double)lval; ((epicsFloat64 *)wf->bptr)[wf->nord] = (epicsFloat64)lval;
break; break;
case DBF_FLOAT: case DBF_FLOAT:
((float *)wf->bptr)[wf->nord] = (float)lval; ((epicsFloat32 *)wf->bptr)[wf->nord] = (epicsFloat32)lval;
break; break;
case DBF_LONG: case DBF_LONG:
case DBF_ULONG: case DBF_ULONG:
((long *)wf->bptr)[wf->nord] = lval; ((epicsInt32 *)wf->bptr)[wf->nord] = (epicsInt32)lval;
break; break;
case DBF_SHORT: case DBF_SHORT:
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
((short *)wf->bptr)[wf->nord] = (short)lval; ((epicsInt16 *)wf->bptr)[wf->nord] = (epicsInt16)lval;
break; break;
case DBF_CHAR: case DBF_CHAR:
case DBF_UCHAR: case DBF_UCHAR:
((char *)wf->bptr)[wf->nord] = (char)lval; ((epicsInt8 *)wf->bptr)[wf->nord] = (epicsInt8)lval;
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -156,29 +157,29 @@ static long writeData (dbCommon *record, format_t *format)
switch (wf->ftvl) switch (wf->ftvl)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
dval = ((double *)wf->bptr)[nowd]; dval = ((epicsFloat64 *)wf->bptr)[nowd];
break; break;
case DBF_FLOAT: case DBF_FLOAT:
dval = ((float *)wf->bptr)[nowd]; dval = ((epicsFloat32 *)wf->bptr)[nowd];
break; break;
case DBF_LONG: case DBF_LONG:
dval = ((long *)wf->bptr)[nowd]; dval = ((epicsInt32 *)wf->bptr)[nowd];
break; break;
case DBF_ULONG: case DBF_ULONG:
dval = ((unsigned long *)wf->bptr)[nowd]; dval = ((epicsUInt32 *)wf->bptr)[nowd];
break; break;
case DBF_SHORT: case DBF_SHORT:
dval = ((short *)wf->bptr)[nowd]; dval = ((epicsInt16 *)wf->bptr)[nowd];
break; break;
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
dval = ((unsigned short *)wf->bptr)[nowd]; dval = ((epicsUInt16 *)wf->bptr)[nowd];
break; break;
case DBF_CHAR: case DBF_CHAR:
dval = ((char *)wf->bptr)[nowd]; dval = ((epicsInt8 *)wf->bptr)[nowd];
break; break;
case DBF_UCHAR: case DBF_UCHAR:
dval = ((unsigned char *)wf->bptr)[nowd]; dval = ((epicsUInt8 *)wf->bptr)[nowd];
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,
@ -196,21 +197,23 @@ static long writeData (dbCommon *record, format_t *format)
switch (wf->ftvl) switch (wf->ftvl)
{ {
case DBF_LONG: case DBF_LONG:
lval = ((epicsInt32 *)wf->bptr)[nowd];
break;
case DBF_ULONG: case DBF_ULONG:
lval = ((long *)wf->bptr)[nowd]; lval = ((epicsUInt32 *)wf->bptr)[nowd];
break; break;
case DBF_SHORT: case DBF_SHORT:
lval = ((short *)wf->bptr)[nowd]; lval = ((epicsInt16 *)wf->bptr)[nowd];
break; break;
case DBF_USHORT: case DBF_USHORT:
case DBF_ENUM: case DBF_ENUM:
lval = ((unsigned short *)wf->bptr)[nowd]; lval = ((epicsUInt16 *)wf->bptr)[nowd];
break; break;
case DBF_CHAR: case DBF_CHAR:
lval = ((char *)wf->bptr)[nowd]; lval = ((epicsInt8 *)wf->bptr)[nowd];
break; break;
case DBF_UCHAR: case DBF_UCHAR:
lval = ((unsigned char *)wf->bptr)[nowd]; lval = ((epicsUInt8 *)wf->bptr)[nowd];
break; break;
default: default:
errlogSevPrintf (errlogFatal, errlogSevPrintf (errlogFatal,

6
src/makedbd.pl Normal file
View File

@ -0,0 +1,6 @@
for (@ARGV) {
print "device($_,INST_IO,dev${_}Stream,\"stream\")\n";
}
print "driver(stream)\n";
print "variable(streamDebug, int)\n";
print "registrar(streamRegistrar)\n";

6
src/makeref.pl Normal file
View File

@ -0,0 +1,6 @@
$t=@ARGV[0];
shift;
for (@ARGV) {
print "extern void* ref_${_}$t;\n";
print "void* p$_ = ref_${_}$t;\n";
}

23
srcSynApps/Makefile Normal file
View File

@ -0,0 +1,23 @@
TOP=../..
include $(TOP)/configure/CONFIG
-include ../src/CONFIG_STREAM
-include ../../src/CONFIG_STREAM
LIBRARY_DEFAULT = streamSynApps
DBD += $(LIBRARY_DEFAULT).dbd
ifeq ($(LOADABLE_MODULE),YES)
SRCS += $(LIBRARY_DEFAULT)_registerRecordDeviceDriver.cpp
endif
SRCS += $(SYNAPPS_RECORDS:%=dev%Stream.c)
LIB_LIBS += stream $(EPICS_BASE_IOC_LIBS)
include $(TOP)/configure/RULES
# create streamSynApps.dbd from all SYNAPPS_RECORDS
$(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../../src/CONFIG_STREAM
$(PERL) ../../src/makedbd.pl $(SYNAPPS_RECORDS) > $@

View File

@ -0,0 +1,108 @@
/***************************************************************
* Stream Device record interface for scalcout records *
* *
* (C) 2006 Dirk Zimoch (dirk.zimoch@psi.ch) *
* *
* This is an EPICS record Interface for StreamDevice. *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include <devStream.h>
#include <sCalcoutRecord.h>
#include <epicsExport.h>
/* scalcout record has a bug: it never calls init_record
of the device support.
Fix: sCalcoutRecord.c, end of init_record() add
if(pscalcoutDSET->init_record ) {
return (*pscalcoutDSET->init_record)(pcalc);
}
The bug has been fixed in version 2-6-1.
*/
static long readData (dbCommon *record, format_t *format)
{
scalcoutRecord *sco = (scalcoutRecord *) record;
switch (format->type)
{
case DBF_DOUBLE:
{
return streamScanf (record, format, &sco->val);
}
case DBF_LONG:
case DBF_ENUM:
{
long lval;
if (streamScanf (record, format, &lval)) return ERROR;
sco->val = lval;
return OK;
}
case DBF_STRING:
{
return (streamScanfN (record, format,
sco->sval, sizeof(sco->val)));
}
}
return ERROR;
}
static long writeData (dbCommon *record, format_t *format)
{
scalcoutRecord *sco = (scalcoutRecord *) record;
switch (format->type)
{
case DBF_DOUBLE:
{
return streamPrintf (record, format, sco->oval);
}
case DBF_LONG:
case DBF_ENUM:
{
return streamPrintf (record, format, (long)sco->oval);
}
case DBF_STRING:
{
return streamPrintf (record, format, sco->osv);
}
}
return ERROR;
}
static long initRecord (dbCommon *record)
{
scalcoutRecord *sco = (scalcoutRecord *) record;
return streamInitRecord (record, &sco->out, readData, writeData);
}
struct {
long number;
DEVSUPFUN report;
DEVSUPFUN init;
DEVSUPFUN init_record;
DEVSUPFUN get_ioint_info;
DEVSUPFUN write;
} devscalcoutStream = {
5,
streamReport,
streamInit,
initRecord,
streamGetIointInfo,
streamWrite,
};
epicsExportAddress(dset,devscalcoutStream);

4
streamApp/.cvsignore Normal file
View File

@ -0,0 +1,4 @@
StreamDebug.log
streamApp
streamApp.exe*
TS.*

81
streamApp/Makefile Normal file
View File

@ -0,0 +1,81 @@
TOP=../..
# Look if we have EPICS R3.13 or R3.14
ifeq ($(wildcard $(TOP)/configure),)
# EPICS R3.13
include $(TOP)/config/CONFIG_APP
# The real work is in Makefile.Vx
include $(TOP)/config/RULES_ARCHS
else
# EPICS R3.14
include $(TOP)/configure/CONFIG
#HOST_OPT = NO
PROD = streamApp
DBD = streamApp.dbd
streamApp_DBD += base.dbd
# In 3.14.12 aaiRecord.dbd and aaoRecord.dbd are part of base.dbd
# In earlier versions, these records are buggy and not included by default
#streamApp_DBD += aaiRecord.dbd aaoRecord.dbd
PROD_SRCS += streamApp_registerRecordDeviceDriver.cpp
PROD_SRCS_DEFAULT = streamAppMain.cc
PROD_SRCS_vxWorks = -nil-
PROD_LIBS = stream
ifdef ASYN
# Which types of asyn busses do you have?
# asynDriver up to version 4-16 does not support serial port for Windows!
#ifneq ($(OS_CLASS), WIN32)
streamApp_DBD += drvAsynSerialPort.dbd
#endif
streamApp_DBD += drvAsynIPPort.dbd
#streamApp_DBD += drvGsIP488.dbd
#streamApp_DBD += drvNi1014.dbd
streamApp_DBD += drvVxi11.dbd
PROD_LIBS += asyn
endif
ifneq ($(words $(CALC) $(SYNAPPS)), 0)
# With synApps scalcout record
streamApp_DBD += calcSupport.dbd
streamApp_DBD += streamSynApps.dbd
PROD_LIBS += calc
# older calc versions require sscan
#PROD_LIBS += sscan
PROD_LIBS_DEFAULT += streamSynApps
endif
streamApp_DBD += stream.dbd
ifdef PCRE
LIB_LIBS += pcre
else
ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0)
PROD_SYS_LIBS_DEFAULT += pcre
PROD_SYS_LIBS_WIN32 += $(PCRE_LIB)\\pcre
SHRLIB_DEPLIB_DIRS += $(PCRE_LIB)
endif
endif
PROD_LIBS += $(EPICS_BASE_IOC_LIBS)
# Write StreamDevice debug output to this file
# If unset output goes to stdout
CPPFLAGS += -DDEBUGFILE=StreamDebug.log
include $(TOP)/configure/RULES
clean:: myclean
myclean:
$(RM) core* StreamDebug.log
endif

8
streamApp/Makefile.Host Normal file
View File

@ -0,0 +1,8 @@
TOP = ../../..
include $(TOP)/config/CONFIG_APP
DBDEXPAND = streamAppInclude-3-13.dbd
DBDNAME = streamApp.dbd
include $(TOP)/config/RULES.Host

20
streamApp/Makefile.Vx Normal file
View File

@ -0,0 +1,20 @@
TOP = ../../..
include $(TOP)/config/CONFIG_APP
LIBNAME = streamApp
LDLIBS += $(COMPAT_BIN)/compatLib
LDLIBS += $(ASYN_BIN)/asynLib
LDLIBS += $(INSTALL_BIN)/streamLib
include ../base-3-13LIBOBJS
# Write StreamDevice debug output to this file
CPPFLAGS += -DDEBUGFILE=StreamDebug.log
include $(TOP)/config/RULES.Vx
include $(TOP)/config/RULES.munch
# Rebuild when LIBOBJS change
$(LIBNAME): ../base-3-13LIBOBJS

242
streamApp/base-3-13.dbd Normal file
View File

@ -0,0 +1,242 @@
include "menuGlobal.dbd"
include "menuConvert.dbd"
include "aiRecord.dbd"
include "aaiRecord.dbd"
include "aoRecord.dbd"
include "aaoRecord.dbd"
include "biRecord.dbd"
include "boRecord.dbd"
include "calcRecord.dbd"
include "calcoutRecord.dbd"
include "compressRecord.dbd"
include "dfanoutRecord.dbd"
#include "egRecord.dbd"
#include "egeventRecord.dbd"
#include "erRecord.dbd"
#include "ereventRecord.dbd"
include "eventRecord.dbd"
include "fanoutRecord.dbd"
#include "histogramRecord.dbd"
include "longinRecord.dbd"
include "longoutRecord.dbd"
include "mbbiRecord.dbd"
include "mbbiDirectRecord.dbd"
include "mbboRecord.dbd"
include "mbboDirectRecord.dbd"
include "permissiveRecord.dbd"
#include "pidRecord.dbd"
#include "pulseCounterRecord.dbd"
#include "pulseDelayRecord.dbd"
#include "pulseTrainRecord.dbd"
#include "scanRecord.dbd"
include "selRecord.dbd"
include "seqRecord.dbd"
include "stateRecord.dbd"
#include "steppermotorRecord.dbd"
include "stringinRecord.dbd"
include "stringoutRecord.dbd"
include "subRecord.dbd"
#include "gsubRecord.dbd"
#include "palRecord.dbd"
include "subArrayRecord.dbd"
#include "timerRecord.dbd"
#include "waitRecord.dbd"
include "waveformRecord.dbd"
device(ai,CONSTANT,devAiSoft,"Soft Channel")
device(ai,CONSTANT,devAiSoftRaw,"Raw Soft Channel")
#device(ai,VME_IO,devAiXy566Se,"XYCOM-566 SE Scanned")
#device(ai,VME_IO,devAiXy566Di,"XYCOM-566 Dif Scanned")
#device(ai,VME_IO,devAiXy566DiL,"XYCOM-566 Dif Latched")
#device(ai,VME_IO,devAiDvx2502,"DVX-2502")
#device(ai,CONSTANT,devAiTestAsyn,"Test Asyn")
#device(ai,AB_IO,devAiAb1771Il,"AB-1771IL-Analog In")
#device(ai,AB_IO,devAiAb1771Ife,"AB-1771IFE")
#device(ai,AB_IO,devAiAb1771Ixe,"AB-1771IXE-Millivolt In")
#device(ai,AB_IO,devAiAb1771IfeSe,"AB-1771IFE-SE")
#device(ai,AB_IO,devAiAb1771IfeMa,"AB-1771IFE-4to20MA")
#device(ai,AB_IO,devAiAb1771Ife0to5V,"AB-1771IFE-0to5Volt")
#device(ai,AB_IO,devAiAb1771IrPlatinum,"AB-1771RTD-Platinum")
#device(ai,AB_IO,devAiAb1771IrCopper,"AB-1771RTD-Copper")
#device(ai,CAMAC_IO,devAiCamac,"Camac")
#device(ai,VME_IO,devAiAt5Vxi,"VXI-AT5-AI")
#device(ai,GPIB_IO,devAiK486Gpib,"Keithley-486")
#device(ai,VME_IO,devAiKscV215,"KSC-V215")
#device(ai,INST_IO,devAiVXStats,"VX stats")
#device(aai,CAMAC_IO,devAaiCamac,"Camac")
device(ao,CONSTANT,devAoSoft,"Soft Channel")
device(ao,CONSTANT,devAoSoftRaw,"Raw Soft Channel")
#device(ao,VME_IO,devAoVmiVme4100,"VMIVME-4100")
#device(ao,CONSTANT,devAoTestAsyn,"Test Asyn")
#device(ao,AB_IO,devAoAb1771Ofe,"AB-1771OFE")
#device(ao,CAMAC_IO,devAoCamac,"Camac")
#device(ao,VME_IO,devAoAt5Vxi,"VXI-AT5-AO")
#device(ao,INST_IO,devAoVXStats,"VX stats")
device(bi,CONSTANT,devBiSoft,"Soft Channel")
device(bi,CONSTANT,devBiSoftRaw,"Raw Soft Channel")
#device(bi,VME_IO,devBiMpv910,"MPV-910")
#device(bi,VME_IO,devBiXVme210,"XVME-210")
#device(bi,CONSTANT,devBiTestAsyn,"Test Asyn")
#device(bi,AB_IO,devBiAb,"AB-Binary Input")
#device(bi,AB_IO,devBiAb16,"AB-16 bit BI")
#device(bi,AB_IO,devBiAb32,"AB-32 bit BI")
#device(bi,CAMAC_IO,devBiCamac,"Camac")
#device(bi,VME_IO,devBiAt5Vxi,"VXI-AT5-BI")
#device(bi,VME_IO,devBiXy240,"XYCOM-240")
#device(bi,VME_IO,devBiHpe1368a,"VXI-HPE1368-VS")
#device(bi,VME_IO,devBiAt8Fp,"AT8-FP10S")
#device(bi,VME_IO,devBiAvme9440,"AVME9440 I")
device(bo,CONSTANT,devBoSoft,"Soft Channel")
device(bo,CONSTANT,devBoSoftRaw,"Raw Soft Channel")
#device(bo,VME_IO,devBoMpv902,"MPV-902")
#device(bo,VME_IO,devBoXVme220,"XVME-220")
#device(bo,CONSTANT,devBoTestAsyn,"Test Asyn")
#device(bo,AB_IO,devBoAb,"AB-Binary Output")
#device(bo,AB_IO,devBoAb16,"AB-16 bit BO")
#device(bo,AB_IO,devBoAb32,"AB-32 bit BO")
#device(bo,CAMAC_IO,devBoCamac,"Camac")
#device(bo,VME_IO,devBoAt5Vxi,"VXI-AT5-BO")
#device(bo,GPIB_IO,devBoK486Gpib,"Keithley-486")
#device(bo,VME_IO,devBoXy240,"XYCOM-240")
#device(bo,VME_IO,devBoHpe1368a,"VXI-HPE1368-VS")
#device(bo,VME_IO,devBoAt8Fp,"AT8-FP10S")
#device(bo,VME_IO,devBoAvme9440,"AVME9440 O")
device(event,CONSTANT,devEventSoft,"Soft Channel")
#device(event,VME_IO,devEventMz8310,"Mizar-8310")
#device(event,CONSTANT,devEventTestIoEvent,"Test IoEvent")
#device(event,VME_IO,devErEpicsEvent,"APS event receiver")
#device(histogram,CONSTANT,devHistogramSoft,"Soft Channel")
#device(histogram,CONSTANT,devHistogramTestAsyn,"Test Asyn")
device(longin,CONSTANT,devLiSoft,"Soft Channel")
#device(longin,CAMAC_IO,devLiCamac,"Camac")
#device(longin,INST_IO,devLiVXStats,"VX stats")
device(longout,CONSTANT,devLoSoft,"Soft Channel")
#device(longout,CAMAC_IO,devLoCamac,"Camac")
device(mbbi,CONSTANT,devMbbiSoft,"Soft Channel")
device(mbbi,CONSTANT,devMbbiSoftRaw,"Raw Soft Channel")
#device(mbbi,VME_IO,devMbbiMpv910,"MPV-910")
#device(mbbi,VME_IO,devMbbiXVme210,"XVME-210")
#device(mbbi,CONSTANT,devMbbiTestAsyn,"Test Asyn")
#device(mbbi,AB_IO,devMbbiAb,"AB-Binary Input")
#device(mbbi,AB_IO,devMbbiAb16,"AB-16 bit BI")
#device(mbbi,AB_IO,devMbbiAb32,"AB-32 bit BI")
#device(mbbi,AB_IO,devMbbiAbAdapterStat,"AB-Adapter Status")
#device(mbbi,AB_IO,devMbbiAbCardStat,"AB-Card Status")
#device(mbbi,CAMAC_IO,devMbbiCamac,"Camac")
#device(mbbi,VME_IO,devMbbiAt5Vxi,"VXI-AT5-BI")
#device(mbbi,VME_IO,devMbbiXy240,"XYCOM-240")
#device(mbbi,VME_IO,devMbbiHpe1368a,"VXI-HPE1368-VS")
#device(mbbi,VME_IO,devMbbiAt8Fp,"AT8-FP10S")
#device(mbbi,VME_IO,devMbbiAvme9440,"AVME9440 I")
device(mbbiDirect,CONSTANT,devMbbiDirectSoft,"Soft Channel")
device(mbbiDirect,CONSTANT,devMbbiDirectSoftRaw,"Raw Soft Channel")
#device(mbbiDirect,VME_IO,devMbbiDirectMpv910,"MPV-910")
#device(mbbiDirect,VME_IO,devMbbiDirectXVme210,"XVME-210")
#device(mbbiDirect,AB_IO,devMbbiDirectAb,"AB-Binary Input")
#device(mbbiDirect,AB_IO,devMbbiDirectAb16,"AB-16 bit BI")
#device(mbbiDirect,AB_IO,devMbbiDirectAb32,"AB-32 bit BI")
#device(mbbiDirect,CAMAC_IO,devMbbiDirectCamac,"Camac")
#device(mbbiDirect,VME_IO,devMbbiDirectAt5Vxi,"VXI-AT5-BI")
device(mbbo,CONSTANT,devMbboSoft,"Soft Channel")
device(mbbo,CONSTANT,devMbboSoftRaw,"Raw Soft Channel")
#device(mbbo,VME_IO,devMbboMpv902,"MPV-902")
#device(mbbo,VME_IO,devMbboXVme220,"XVME-220")
#device(mbbo,CONSTANT,devMbboTestAsyn,"Test Asyn")
#device(mbbo,AB_IO,devMbboAb,"AB-Binary Output")
#device(mbbo,AB_IO,devMbboAb16,"AB-16 bit BO")
#device(mbbo,AB_IO,devMbboAb32,"AB-32 bit BO")
#device(mbbo,VME_IO,devMbboAt5Vxi,"VXI-AT5-BO")
#device(mbbo,GPIB_IO,devMbboK486Gpib,"Keithley-486")
#device(mbbo,VME_IO,devMbboXy240,"XYCOM-240")
#device(mbbo,VME_IO,devMbboHpe1368a,"VXI-HPE1368-VS")
#device(mbbo,VME_IO,devMbboAt8Fp,"AT8-FP10S")
#device(mbbo,VME_IO,devMbboAvme9440,"AVME9440 O")
device(mbboDirect,CONSTANT,devMbboDirectSoft,"Soft Channel")
device(mbboDirect,CONSTANT,devMbboDirectSoftRaw,"Raw Soft Channel")
#device(mbboDirect,VME_IO,devMbboDirectMpv902,"MPV-902")
#device(mbboDirect,VME_IO,devMbboDirectXVme220,"XVME-220")
#device(mbboDirect,AB_IO,devMbboDirectAb,"AB-Binary Output")
#device(mbboDirect,AB_IO,devMbboDirectAb16,"AB-16 bit BO")
#device(mbboDirect,AB_IO,devMbboDirectAb32,"AB-32 bit BO")
#device(mbboDirect,CAMAC_IO,devMbboDirectCamac,"Camac")
#device(mbboDirect,VME_IO,devMbboDirectAt5Vxi,"VXI-AT5-BO")
#device(pulseCounter,VME_IO,devPcMz8310,"Mizar-8310")
#device(pulseDelay,VME_IO,devPdMz8310,"Mizar-8310")
#device(pulseTrain,CONSTANT,devPtSoft,"Soft Channel")
#device(pulseTrain,VME_IO,devPtMz8310,"Mizar-8310")
#device(steppermotor,VME_IO,devSmCompumotor1830,"Compumotor 1830")
#device(steppermotor,VME_IO,devSmOms6Axis,"OMS 6-Axis")
#device(steppermotor,AB_IO,devSmAB1746Hstp1,"Allen Bradley 1746-HTSP1")
device(stringin,CONSTANT,devSiSoft,"Soft Channel")
#device(stringin,CONSTANT,devSiTestAsyn,"Test Asyn")
device(stringout,CONSTANT,devSoSoft,"Soft Channel")
#device(stringout,CONSTANT,devSoTestAsyn,"Test Asyn")
device(subArray,CONSTANT,devSASoft,"Soft Channel")
#device(timer,VME_IO,devTmMizar8310,"Mizar-8310")
#device(timer,VME_IO,devTmDg535,"DG 535")
#device(timer,VME_IO,devTmAt5Vxi,"VXI-AT5-TIME")
device(waveform,CONSTANT,devWfSoft,"Soft Channel")
#device(waveform,VME_IO,devWfXy566Sc,"XYCOM-566 Single Channel")
#device(waveform,VME_IO,devWfComet,"Comet Digitizer")
#device(waveform,VME_IO,devWfJoergerVtr1,"Joerger Digitizer")
#device(waveform,CONSTANT,devWfTestAsyn,"Test Asyn")
#device(waveform,VME_IO,devWfDvx2502,"DVX-2502")
#device(waveform,VME_IO,devWfPentek4261,"Pentek 4261")
#device(waveform,CAMAC_IO,devWfCamac,"Camac")
#device(waveform,VME_IO,devWfJoergerVtr1,"Joerger-VTR1")
#device(waveform,VME_IO,devWfComet,"Omnibyte-COMET")
#device(eg,VME_IO,devEg,"APS event generator G")
#device(egevent,VME_IO,devEgEvent,"APS event generator E")
#device(er,VME_IO,devEr,"APS event receiver")
#device(erevent,VME_IO,devErevent,"APS event receiver")
#device(wait,CONSTANT,devWaitIoEvent,"Soft Channel")
#device(ai,INST_IO,devAiCan,"CANbus")
#device(ao,INST_IO,devAoCan,"CANbus")
#device(bi,INST_IO,devBiCan,"CANbus")
#device(bo,INST_IO,devBoCan,"CANbus")
#device(mbbi,INST_IO,devMbbiCan,"CANbus")
#device(mbbo,INST_IO,devMbboCan,"CANbus")
#device(mbbiDirect,INST_IO,devMbbiDirectCan,"CANbus")
#device(mbboDirect,INST_IO,devMbboDirectCan,"CANbus")
#device(bi,VME_IO,devBiVmic2534,"Vmic2534")
#device(bo,VME_IO,devBoVmic2534,"Vmic2534")
#device(mbbi,VME_IO,devMbbiVmic2534,"Vmic2534")
#device(mbbo,VME_IO,devMbboVmic2534,"Vmic2534")
#include "symb.dbd"
#device(ai,AB_IO,devAiAbSlcDcm,"AB-SLC500DCM")
#device(ai,AB_IO,devAiAbSlcDcmSigned,"AB-SLC500DCM-Signed")
#device(ao,AB_IO,devAoAbSlcDcm,"AB-SLC500DCM")
#device(longin,AB_IO,devLiAbSlcDcm,"AB-SLC500DCM")
#device(longout,AB_IO,devLoAbSlcDcm,"AB-SLC500DCM")
#driver(drvXy010)
#driver(drvVxi)
#driver(drvGpib)
#driver(drvBitBus)
#driver(drvBb910)
#driver(drvXy210)
#driver(drvBb902)
#driver(drvXy220)
#driver(drvXy566)
#driver(drvDvx)
#driver(drvVmi4100)
#driver(drvAb)
#driver(drvAt5Vxi)
#driver(drvCompuSm)
#driver(drvOms)
#driver(drvMz8310)
#driver(drvHpe1368a)
#driver(drvXy240)
#driver(drvKscV215)
#driver(drvComet)
#driver(drvJgvtr1)
#driver(drvFp)
#driver(drvFpm)
#driver(drvIpac)
#driver(drvTip810)
#driver(drvVmi2534)
#include "bptTypeJdegC.dbd"
#include "bptTypeJdegF.dbd"
#include "bptTypeKdegC.dbd"
#include "bptTypeKdegF.dbd"

216
streamApp/base-3-13LIBOBJS Normal file
View File

@ -0,0 +1,216 @@
LIBOBJS += $(EPICS_BASE_BIN)/aaiRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/aaoRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/aiRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/aoRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/biRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/boRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/calcRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/calcoutRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/compressRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/dfanoutRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/egRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/egeventRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/erRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/ereventRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/eventRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/fanoutRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/gsubRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/histogramRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/longinRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/longoutRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/mbbiRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/mbbiDirectRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/mbboRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/mbboDirectRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/palRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/permissiveRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/pidRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/pulseCounterRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/pulseDelayRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/pulseTrainRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/scanRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/recWaitCa.o
#LIBOBJS += $(EPICS_BASE_BIN)/recDynLink.o
#LIBOBJS += $(EPICS_BASE_BIN)/recDynLinkTest.o
LIBOBJS += $(EPICS_BASE_BIN)/selRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/seqRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/stateRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/steppermotorRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/stringinRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/stringoutRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/subRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/subArrayRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/timerRecord.o
#LIBOBJS += $(EPICS_BASE_BIN)/waitRecord.o
LIBOBJS += $(EPICS_BASE_BIN)/waveformRecord.o
#
# Device Support
#
#LIBOBJS += $(EPICS_BASE_BIN)/devAaiCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAiCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAiDvx2502.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAiKscV215.o
LIBOBJS += $(EPICS_BASE_BIN)/devAiSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devAiSoftRaw.o
#LIBOBJS += $(EPICS_BASE_BIN)/devVXStats.o
LIBOBJS += $(EPICS_BASE_BIN)/devAiTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAiXy566Di.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAiXy566DiL.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAiXy566Se.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAaoCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAoCamac.o
LIBOBJS += $(EPICS_BASE_BIN)/devAoSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devAoSoftRaw.o
LIBOBJS += $(EPICS_BASE_BIN)/devAoTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAoVmiVme4100.o
#LIBOBJS += $(EPICS_BASE_BIN)/devApsEg.o
#LIBOBJS += $(EPICS_BASE_BIN)/devApsEr.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAt5Vxi.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAt8Fp.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAvme9440.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBiCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBiMpv910.o
LIBOBJS += $(EPICS_BASE_BIN)/devBiSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devBiSoftRaw.o
LIBOBJS += $(EPICS_BASE_BIN)/devBiTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBiXVme210.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBoCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBoMpv902.o
LIBOBJS += $(EPICS_BASE_BIN)/devBoSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devBoSoftRaw.o
LIBOBJS += $(EPICS_BASE_BIN)/devBoTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBoXVme220.o
#LIBOBJS += $(EPICS_BASE_BIN)/devCommonGpib.o
LIBOBJS += $(EPICS_BASE_BIN)/devEventSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devEventTestIoEvent.o
LIBOBJS += $(EPICS_BASE_BIN)/devHistogramSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devHistogramTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devHpe1368a.o
#LIBOBJS += $(EPICS_BASE_BIN)/devLiCamac.o
LIBOBJS += $(EPICS_BASE_BIN)/devLiSoft.o
#LIBOBJS += $(EPICS_BASE_BIN)/devLoCamac.o
LIBOBJS += $(EPICS_BASE_BIN)/devLoSoft.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiDirectCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiDirectMpv910.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbbiDirectSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbbiDirectSoftRaw.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiDirectXVme210.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiMpv910.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbbiSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbbiSoftRaw.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbbiTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiXVme210.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboDirectCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboDirectMpv902.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbboDirectSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbboDirectSoftRaw.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboDirectXVme220.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboMpv902.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbboSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbboSoftRaw.o
LIBOBJS += $(EPICS_BASE_BIN)/devMbboTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboXVme220.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMz8310.o
#LIBOBJS += $(EPICS_BASE_BIN)/devPtSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devSASoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devSiSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devSiTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devSmCompumotor1830.o
#LIBOBJS += $(EPICS_BASE_BIN)/devSmOms6Axis.o
LIBOBJS += $(EPICS_BASE_BIN)/devSoSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devSoTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devTimerMz8310.o
#LIBOBJS += $(EPICS_BASE_BIN)/devWfCamac.o
#LIBOBJS += $(EPICS_BASE_BIN)/devWfComet.o
#LIBOBJS += $(EPICS_BASE_BIN)/devWfDvx2502.o
#LIBOBJS += $(EPICS_BASE_BIN)/devWfJoergerVtr1.o
LIBOBJS += $(EPICS_BASE_BIN)/devWfSoft.o
LIBOBJS += $(EPICS_BASE_BIN)/devWfTestAsyn.o
#LIBOBJS += $(EPICS_BASE_BIN)/devWfXy566Sc.o
#LIBOBJS += $(EPICS_BASE_BIN)/devWfPentek4261.o
#LIBOBJS += $(EPICS_BASE_BIN)/devXy240.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAB1771IFE.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAB1771IL.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAB1771IR.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAB1771IXE.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAB1771OFE.o
#LIBOBJS += $(EPICS_BASE_BIN)/devABSLCDCM.o
#LIBOBJS += $(EPICS_BASE_BIN)/devABBINARY.o
#LIBOBJS += $(EPICS_BASE_BIN)/devABStatus.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAiCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devAoCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBiCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBoCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbbiDirectCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devMbboDirectCan.o
#LIBOBJS += $(EPICS_BASE_BIN)/devVmic2534.o
#LIBOBJS += $(EPICS_BASE_BIN)/symb
#
# Driver support ANSI
#
#LIBOBJS += $(EPICS_BASE_BIN)/drvAb.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvAt5Vxi.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvEpvxi.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvEpvxiMsg.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvHp1404a.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvHpe1368a.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvHpe1445a.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvKscV215.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvMz8310.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvStc.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvTime.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvCaenV265.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvVipc310.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvVipc610.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvIpMv162.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvIpac.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvTip810.o
#
# Driver support NON ANSI
#
#LIBOBJS += $(EPICS_BASE_BIN)/module_types.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvBB232.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvBb902.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvBb910.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvBitBus.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvComet.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvCompuSm.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvDvx.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvFp.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvFpm.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvGpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvJgvtr1.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvMsg.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvOms.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvTranServ.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvVmi4100.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvXy010.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvXy210.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvXy220.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvXy240.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvXy566.o
#LIBOBJS += $(EPICS_BASE_BIN)/drvVmic2534.o
#
#from src/devOpt
#
#LIBOBJS += $(EPICS_BASE_BIN)/devAnalytekGpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/devBBInteract.o
#LIBOBJS += $(EPICS_BASE_BIN)/devGpibInteract.o
#LIBOBJS += $(EPICS_BASE_BIN)/devK486Gpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/devLibOpt.o
#LIBOBJS += $(EPICS_BASE_BIN)/devXxDc5009Gpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/devXxDg535Gpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/devXxK196Gpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/devXxK263Gpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/devXxSkeletonGpib.o
#LIBOBJS += $(EPICS_BASE_BIN)/devXxSr620Gpib.o

View File

@ -0,0 +1,21 @@
BIN="<library directory>"
DBD="<dbd directory>"
HOME="<ioc home direcory>"
#where can protocols be located?
STREAM_PROTOCOL_PATH=".:protocols:../protocols/"
cd BIN
ld < iocCore
ld < streamApp.munch
dbLoadDatabase "streamApp.dbd",DBD
drvAsynIPPortConfigure "terminal", "xxx.xxx.xxx.xxx:40000"
#load the records
cd HOME
dbLoadRecords "example.db","PREFIX=DZ"
#lots of debug output
#streamDebug=1
iocInit

38
streamApp/example.cmd Normal file
View File

@ -0,0 +1,38 @@
dbLoadDatabase "O.Common/streamApp.dbd"
streamApp_registerRecordDeviceDriver
#where can protocols be located?
epicsEnvSet "STREAM_PROTOCOL_PATH", ".:protocols:../protocols/"
#setup the busses
#example serial port setup
#drvAsynSerialPortConfigure "COM2", "/dev/ttyS1"
#asynOctetSetInputEos "COM2",0,"\r\n"
#asynOctetSetOutputEos "COM2",0,"\r\n"
#asynSetOption ("COM2", 0, "baud", "9600")
#asynSetOption ("COM2", 0, "bits", "8")
#asynSetOption ("COM2", 0, "parity", "none")
#asynSetOption ("COM2", 0, "stop", "1")
#asynSetOption ("COM2", 0, "clocal", "Y")
#asynSetOption ("COM2", 0, "crtscts", "N")
#example telnet style IP port setup
drvAsynIPPortConfigure "terminal", "localhost:40000"
asynOctetSetInputEos "terminal",0,"\r\n"
asynOctetSetOutputEos "terminal",0,"\r\n"
#example VXI11 (GPIB via IP) port setup
#vxi11Configure "GPIB","ins023",1,5.0,"hpib"
#load the records
dbLoadRecords "example.db","PREFIX=DZ"
#dbLoadRecords "scalcout.db","PREFIX=DZ"
#lots! of debug output
#var streamDebug 1
iocInit
#enable debug output
var streamDebug 1

170
streamApp/example.db Normal file
View File

@ -0,0 +1,170 @@
# process this record to reload all stream protocols
record (sub, "$(PREFIX):reload")
{
field (SNAM, "streamReload")
}
# some scaling -10...10V <-> 0x0000...0xffff and back
record (ao, "$(PREFIX):ao")
{
field (DESC, "An analog value")
field (DTYP, "stream")
field (OUT, "@example.proto set-ao terminal")
field (PREC, "3")
field (LINR, "LINEAR")
field (ESLO, "0.000305180437934") # 20.0 / 0xffff
field (EOFF, "-10")
field (DRVL, "-10")
field (DRVH, "10")
field (EGU, "V")
}
record (ai, "$(PREFIX):ai")
{
field (DESC, "An analog value")
field (DTYP, "stream")
field (INP, "@example.proto ai terminal")
field (PREC, "3")
field (LINR, "LINEAR")
field (ESLO, "0.000305180437934") # 20.0 / 0xffff
field (EOFF, "-10")
field (EGU, "V")
}
# simple integer and binary i/o
record (longout, "$(PREFIX):lo")
{
field (DESC, "An integer value")
field (DTYP, "stream")
field (OUT, "@example.proto lo terminal")
}
record (longin, "$(PREFIX):li")
{
field (DESC, "An integer value")
field (DTYP, "stream")
field (INP, "@example.proto li terminal")
}
record (bo, "$(PREFIX):bo")
{
field (DESC, "A bit value")
field (DTYP, "stream")
field (OUT, "@example.proto bo terminal")
field (MASK, "42")
field (ZNAM, "OFF")
field (ONAM, "ON")
}
record (bi, "$(PREFIX):bi")
{
field (DESC, "A bit value")
field (DTYP, "stream")
field (INP, "@example.proto bi terminal")
field (ZNAM, "OFF")
field (ONAM, "ON")
}
# playing with enums
record (mbbo, "$(PREFIX):mbbo")
{
field (DESC, "Print Enums")
field (DTYP, "stream")
field (OUT, "@example.proto enums terminal")
field (ZRST, "A")
field (ZRVL, "2")
field (ONST, "B")
field (ONVL, "3")
field (TWST, "C")
field (TWVL, "1")
field (THST, "D")
field (THVL, "0")
}
record (stringout, "$(PREFIX):command")
{
field (DTYP, "stream")
field (OUT, "@example.proto COMMAND terminal")
}
record (stringin, "$(PREFIX):info")
{
field (DTYP, "stream")
field (INP, "@example.proto info terminal")
}
# prints all available checksums
record (stringout, "$(PREFIX):checksum")
{
field (DTYP, "stream")
field (OUT, "@example.proto checksum terminal")
}
# this record gets any (terminated) input line
record (stringin, "$(PREFIX):spy")
{
field (DTYP, "stream")
field (INP, "@example.proto spy terminal")
field (SCAN, "I/O Intr")
field (FLNK, "$(PREFIX):log5")
}
# these records log the last few input lines
record (stringin, "$(PREFIX):log5")
{
field (INP, "$(PREFIX):log4")
field (FLNK, "$(PREFIX):log4")
}
record (stringin, "$(PREFIX):log4")
{
field (INP, "$(PREFIX):log3")
field (FLNK, "$(PREFIX):log3")
}
record (stringin, "$(PREFIX):log3")
{
field (INP, "$(PREFIX):log2")
field (FLNK, "$(PREFIX):log2")
}
record (stringin, "$(PREFIX):log2")
{
field (INP, "$(PREFIX):log1")
field (FLNK, "$(PREFIX):log1")
}
record (stringin, "$(PREFIX):log1")
{
field (INP, "$(PREFIX):spy")
}
# caput to A,B,C or PROC to process this
record (calcout, "$(PREFIX):calcout")
{
field (DTYP, "stream")
field (OUT, "@example.proto calcout terminal")
field (A, "3.1415")
field (B, "15")
field (C, "8")
field (CALC, "0") # should be a valid expression
field (DESC, "filename")
}
# read a long string as a waveform of characteres
record (waveform, "$(PREFIX):hugestring")
{
field (DTYP, "stream")
field (INP, "@example.proto char_wave_in terminal")
field (FTVL, "CHAR")
field (NELM, "1000")
}
# write an array of strings
record (waveform, "$(PREFIX):strings")
{
field (DTYP, "stream")
field (INP, "@example.proto string_wave_out terminal")
field (FTVL, "STRING")
field (NELM, "10")
}

127
streamApp/example.proto Normal file
View File

@ -0,0 +1,127 @@
# example stream protocol file
Terminator = CR LF;
ReplyTimeout = 10000; # 10 sec is very long, for keyboard input
ReadTimeout = 1000; # also long for keyboard input
binary {
out "%B\x00\xff";
}
# note the field access
ai {
out "%(NAME)s [int] ? ";
in "%i"; # read to RVAL and convert
}
set-ao {
out '%(NAME)s = %f %(EGU)s [0x%04x]';
}
li {
out "%(NAME)s [int] ? ";
in "%i";
}
lo {
out '%(NAME)s = %i = %#x = %b(bin) = %D(BCD)';
}
bi {
out "%(NAME)s [0 or 1] ? ";
in "%i";
}
# using variables
s0 = false;
s1 = true;
bo {
out '%(NAME)s = %i = %{\${s0}|\${s1}} = "%s"';
}
enums
{
out "%{choice0|choice1|choice2} %d %s";
}
checksum {
out "%s%<sum> sum";
out "%s%<nsum> nsum";
out "%s%<-sum> -sum";
out "%s%<notsum> notsum";
out "%s%<~sum> ~sum";
out "%s%<xor> xor";
out "%s%<crc8> crc8";
out "%s%<ccitt8> ccitt8";
out "%s%<sum16> sum16";
out "%s%<crc16> crc16";
out "%s%<crc16r> crc16r";
out "%s%<ccitt16> ccitt16";
out "%s%<ccitt16a> ccitt16 with augment";
out "%s%<sum32> sum32";
out "%s%<crc32> crc32";
out "%s%<crc32r> crcr32";
out "%s%<jamcrc> jamcrc";
out "%s%<adler32> adler32";
out "%s%0<sum> sum (ASCII)";
out "%s%0<nsum> nsum (ASCII)";
out "%s%0<-sum> -sum (ASCII)";
out "%s%0<notsum> notsum (ASCII)";
out "%s%0<~sum> ~sum (ASCII)";
out "%s%0<xor> xor (ASCII)";
out "%s%0<crc8> crc8 (ASCII)";
out "%s%0<ccitt8> ccitt8 (ASCII)";
out "%s%0<sum16> sum16 (ASCII)";
out "%s%0<crc16> crc16 (ASCII)";
out "%s%0<crc16r> crc16r (ASCII)";
out "%s%0<ccitt16> ccitt16 (ASCII)";
out "%s%0<ccitt16a> ccitt16 with augment (ASCII)";
out "%s%0<sum32> sum32 (ASCII)";
out "%s%0<crc32> crc32 (ASCII)";
out "%s%0<crc32r> crcr32 (ASCII)";
out "%s%0<jamcrc> jamcrc (ASCII)";
out "%s%0<adler32> adler32 (ASCII)";
out "%s%0<hexsum8> hexsum8 (ASCII)";
}
command {
out "%s";
}
info {
out "%s";
in "%39c";
}
read {
in "%39c";
}
spy {
extraInput=ignore;
PollPeriod = 10;
in "%39c";
}
# accessing fields
calcout {
out "OVAL=%f A=%(A)f B=%(B)f C=%(C)f";
}
scalcout {
out "OVAL=%f SOV=%s A=%(A)f B=%(B)f AA=%(AA)s";
}
# output an array of strings
string_wave_out {
separator = ", ";
out "waveform %(NAME)s = (%s)";
}
char_wave_in {
outterminator = "";
out CR LF "Enter String: ";
in "%1000c";
out 'Got: "%s"' CR LF;
}

34
streamApp/regexp.README Normal file
View File

@ -0,0 +1,34 @@
How to use regular expressions in StreamDevice.
First, you need the PCRE library.
If it is already installed for your (Linux) system (try: rpm -ql pcre),
set the following variables in your RELEASE file:
PCRE_INCLUDE=<direcrory of pcre.h>
PCRE_LIB=<direcrory of libpcre.so>
For vxWorks, Windows and others you're probably out of luck here.
In that case, download the PCRE package from www.pcre.org and
epics.web.psi.ch/software/streamdevice/pcre/Makefile and compile
PCRE as an EPICS application. Use the variable PCRE in your RELEASE file
to define the location of this application.
If either PCRE or PCRE_INCLUDE or PCRE_LIB are set in the RELEASE file,
StreamDevice is automatically build with regular expression support.
The syntax is %/regexp/. It can only be used in input. It returns the
next string that matches the regexp. Anything before this string is skipped.
To use sub-expressions use %.n/rexexp/ where n is a number from 1 to 9
to match the n-th sub-expression.
It is possible to limit the input length to the match algorithm like
%m/regexp/ where m is the maximal length.
Example:
in "%100.1/<title>(.*)<\/title>/";
This searches the next 100 bytes and returns the string bewteen
<title> and </title>. Any input before <title> is skipped. Any input
after </title> is left in the buffer (and can by matched by other formats).
Note that the / in </title> must be escaped.
See regexp.cmd, regexp.proto, regexp.db for a working example.

10
streamApp/regexp.cmd Normal file
View File

@ -0,0 +1,10 @@
dbLoadDatabase "O.Common/streamApp.dbd"
streamApp_registerRecordDeviceDriver
# no autoconnect for web servers (see regexp.proto)
drvAsynIPPortConfigure web epics.web.psi.ch:80 0 1
dbLoadRecords regexp.db
iocInit
# var streamDebug 1

5
streamApp/regexp.db Normal file
View File

@ -0,0 +1,5 @@
record (stringin, "DZ:regexp")
{
field (DTYP, "stream")
field (INP, "@regexp.proto readTitle web")
}

18
streamApp/regexp.proto Normal file
View File

@ -0,0 +1,18 @@
# regular expression example
# extract the title of from a web page
outterminator = NL;
interminator = "</html>" NL; # terminators can have arbitrary length
# Web servers close the connection after sending a page.
# Thus, we can't use autoconnect (see drvAsynIPPortConfigure)
# Handle connection manually in protocol.
readTitle {
extraInput=ignore;
connect 1000; # connect to server, 1 second timeout
out "GET http://epics.web.psi.ch/"; # HTTP request
in "%.1/<title>(.*)<\/title>/"; # get string in <title></title>
disconnect; # servers closes, so do we.
}

19
streamApp/simple.cmd Normal file
View File

@ -0,0 +1,19 @@
dbLoadDatabase "O.Common/streamApp.dbd"
streamApp_registerRecordDeviceDriver
#where can protocols be located?
epicsEnvSet "STREAM_PROTOCOL_PATH", ".:protocols:../protocols/"
#setup the busses
#drvAsynIPPortConfigure "L0", "localhost:40000"
vxi11Configure "L0","gpib-dz-1",0,0.0,"gpib0",0,0
#load the records
dbLoadRecords "simple.db","P=DZ,BUS=L0 28"
var streamDebug 1
iocInit
#enable debug output
var streamDebug 1

15
streamApp/simple.db Normal file
View File

@ -0,0 +1,15 @@
record (stringout, "$(P):cmd")
{
field (DTYP, "stream")
field (OUT, "@simple.proto cmd $(BUS)")
}
record (stringout, "$(P):info")
{
field (DTYP, "stream")
field (OUT, "@simple.proto info $(BUS)")
}
record (stringin, "$(P):read")
{
field (DTYP, "stream")
field (INP, "@simple.proto read $(BUS)")
}

13
streamApp/simple.proto Normal file
View File

@ -0,0 +1,13 @@
terminator = CR LF;
cmd {
out "%s";
}
info {
extrainput=ignore;
out "%s";
in "%39c";
}
read {
in "%39c";
}

View File

@ -0,0 +1,3 @@
include "base-3-13.dbd"
include "asyn.dbd"
include "stream.dbd"

View File

@ -0,0 +1,37 @@
/***************************************************************
* StreamDevice Support *
* *
* (C) 2005 Dirk Zimoch (dirk.zimoch@psi.ch) *
* *
* This is an example application initializer for StreamDevice. *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include <epicsThread.h>
#include <iocsh.h>
#include <devStream.h>
int main(int argc,char *argv[])
{
#ifdef DEBUGFILE
#define STR2(x) #x
#define STR(x) STR2(x)
StreamDebugFile = fopen(STR(DEBUGFILE), "w");
#endif
if(argc>=2) {
iocsh(argv[1]);
epicsThreadSleep(.2);
}
iocsh(NULL);
return(0);
}

198
streamApp/terminal.tcl Executable file
View File

@ -0,0 +1,198 @@
#!/usr/bin/env wish
wm iconify .
proc createTerm {sock} {
global socket port
toplevel .$sock
text .$sock.t -yscrollcommand ".$sock.v set"
scrollbar .$sock.v -command ".$sock.t yview"
.$sock.t tag configure output -foreground red
.$sock.t tag configure input -foreground darkgreen
grid rowconfigure .$sock 0 -weight 1
grid columnconfigure .$sock 0 -weight 1
grid .$sock.t .$sock.v -sticky nsew
bind .$sock.t <Destroy> "close $sock; unset socket(.$sock.t)"
bind .$sock.t <F1> "%W delete 0.1 end"
set socket(.$sock.t) $sock
focus .$sock.t
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} {
fconfigure $sock -blocking 0 -buffering none
createTerm $sock
fileevent $sock readable "receiveHandler $sock"
}
proc escape {string} {
while {![string is print -failindex index $string]} {
set char [string index $string $index]
scan $char "%c" code
switch $char {
"\r" { set escaped "\\r" }
"\n" { set escaped "\\n" }
"\a" { set escaped "\\a" }
"\t" { set escaped "\\t" }
default { set escaped [format "<%02x>" $code] }
}
set string [string replace $string $index $index $escaped]
}
return $string
}
proc sendReply {sock text} {
.$sock.t mark set insert end
.$sock.t insert end $text
.$sock.t see end
puts -nonewline $sock $text
# puts "sending \"[escape $text]\"\n"
}
proc checkNum {n} {
if {[string is integer $n] && $n >= 0} {return $n}
return -code error "argument $n must be a positive number"
}
proc receiveHandler {sock} {
set a [read $sock]
if [eof $sock] {
destroy .$sock
return
}
.$sock.t mark set insert end
.$sock.t insert end $a output
.$sock.t see end
set l [split $a]
if [catch {
switch -- [lindex $l 0] {
"exit" {
exit
}
"disconnect" {
sendReply $sock [string range $a 11 end]
destroy .$sock
}
"echo" {
sendReply $sock [string range $a 5 end]
}
"longmsg" {
set length [checkNum [lindex $l 1]]
sendReply $sock "[string range x[string repeat 0123456789abcdefghijklmnopqrstuvwxyz [expr $length / 36 + 1]] 1 $length]\n"
}
"wait" {
set wait [checkNum [lindex $l 1]]
after $wait [list sendReply $sock "Done\n"]
}
"start" {
set wait [checkNum [lindex $l 1]]
set ::counter 0
after $wait sendAsync $wait [list [lindex $l 2]]
sendReply $sock "Started\n"
}
"stop" {
set ::counter -1
sendReply $sock "Stopped\n"
}
"set" {
set ::values([lindex $a 1]) [lrange $l 2 end-1]
sendReply $sock "Ok\n"
}
"get" {
if [info exists ::values([lindex $l 1])] {
sendReply $sock "[lindex $l 1] $::values([lindex $l 1])\n"
} else {
sendReply $sock "ERROR: [lindex $l 1] not found\n"
}
}
"help" {
sendReply $sock "help this text\n"
sendReply $sock "echo string reply string\n"
sendReply $sock "wait msec reply Done after some time\n"
sendReply $sock "start msec start sending messages priodically\n"
sendReply $sock "stop stop sending messages\n"
sendReply $sock "set key value set a value\n"
sendReply $sock "get key reply value\n"
sendReply $sock "disconnect close connection\n"
}
}
} msg] {
sendReply $sock "ERROR: $msg\n"
puts stderr $::errorInfo
}
}
proc sendAsync {wait message} {
if {$::counter < 0} return
foreach term [array names ::socket] {
sendReply $::socket($term) "Message number [incr ::counter] $message\n";
}
after $wait sendAsync $wait [list $message]
}
if {[info proc tkTextInsert] != ""} {
set insert tkTextInsert
set paste tkTextPaste
set pastesel tkPasteSelection
} else {
set insert tk::TextInsert
set paste tk_textPaste
set pastesel ::tk::TextPasteSelection
}
rename $insert tkTextInsert_org
rename $paste tkTextPaste_org
rename $pastesel tkTextPasteSel_org
proc $insert {w s} {
puts [list insert $w $s]
global socket
if {[string equal $s ""] || [string equal [$w cget -state] "disabled"]} {
return
}
sendReply $socket($w) $s
}
proc $paste {w x y} {
puts [list paste $w $s]
global insert
set s [selection get -displayof $w]
$insert $w $s
}
proc $pastesel {w x y} {
global insert
$w mark set insert [TextClosestGap $w $x $y]
if {![catch {::tk::GetSelection $w PRIMARY} sel]} {
set oldSeparator [$w cget -autoseparators]
if {$oldSeparator} {
$w configure -autoseparators 0
$w edit separator
}
$insert $w $sel
if {$oldSeparator} {
$w edit separator
$w configure -autoseparators 1
}
}
if {[$w cget -state] eq "normal"} {focus $w}
}
#remove bindings on Control-<letter>
for {set ascii 0x61} {$ascii <= 0x7a} {incr ascii} {
bind Text <Control-[format %c $ascii]> ""
}
#remove bindings on symbolic tags
foreach tag {Clear Paste Copy Cut } {
bind Text <<$tag>> ""
}
bind Text <Control-Key> [list $insert %W %A]

Some files were not shown because too many files have changed in this diff Show More