Compare commits

...

99 Commits

Author SHA1 Message Date
75aa267875 error message on reply timeout 2020-03-16 16:58:07 +01:00
7dda6ca773 bugix for systems where vsnprintf returns -1 on buffer overrun: double buffer capacity 2020-03-02 13:56:42 +01:00
1378a9fcbb Merge branch 'windows_build_fix' of https://github.com/FreddieAkeroyd/StreamDevice 2020-03-02 09:13:38 +01:00
4d3672994d bugfix: when passing negative start index to find(), don't start earlier than index 0 2020-03-02 09:11:50 +01:00
967539c4e1 allow commas inside matching pairs of parentheses in protocol parameters 2020-03-02 09:10:28 +01:00
f072c217f3 allow () inside protocol parameters 2020-02-27 13:45:54 +01:00
a60ffd685f tests updated 2020-02-27 13:44:32 +01:00
0803c94c79 cleanup spaces 2020-02-26 15:53:02 +01:00
b03726903d Fix linker error on WIN32 2019-12-16 19:11:27 +00:00
afe8cc9a3e Merge branch 'master' of github.com:paulscherrerinstitute/StreamDevice 2019-11-27 16:50:36 +01:00
277635c65f fix linker problem on windows 2019-11-27 16:49:57 +01:00
4180bbbdd9 Merge pull request #45 from jgnrendra3/master
New Checksums including support for Brooks Cryopump
2019-11-12 15:30:14 +01:00
d683969556 New Checksums including support for Brooks Cryopump 2019-11-12 07:13:02 -05:00
a62d4d1a40 update documentation according to previous API change 2019-11-11 13:35:56 +01:00
aadecf1853 Merge pull request #44 from SLACer-garth/buffer-overflow-fix
Buffer overflow fix
2019-11-11 13:24:39 +01:00
f172f3d0a0 Merge pull request #43 from bfrk/master
remove error message in streamReadWrite
2019-11-11 12:47:41 +01:00
08ac900eda Make expectedLength ssize_t everywhere.
Also fix other type related warnings.
2019-11-07 17:20:08 -08:00
53caf69f3a Cast expectedLength to ssize_t where it is used as a signed number. Fixes buffer overrun memory corruption segfault. 2019-11-07 17:19:43 -08:00
3eac2b804d Bugfix in 64 bit data type handling. (Thanks to Andrew Johnson) 2019-11-07 20:23:35 +01:00
9b9e7bf722 remove error message in streamReadWrite
If the record hasn't been initialized correctly, we don't want the console
to be spammed every time the record gets processed.
2019-10-10 14:51:56 +02:00
7a48a5440e made RELEASE file more similar to SynApps 2019-08-26 09:10:28 +02:00
ef5d0cf3f1 improve building streamApp for 3.13 2019-08-22 16:34:32 +02:00
a5e9ed2d78 do not use epicsStdioRedirect.h for EPICS 3.13 2019-08-22 15:53:29 +02:00
40e937b091 do not use -ansi with vxWorks compiler in EPICS 3.13 2019-08-22 15:52:52 +02:00
1bac175c42 no need to go into config for 3.13 and it can cause problems with 3.14+ 2019-08-22 15:51:53 +02:00
507a8229de fix generation of stream-calcout.dbd: older EPICS versions have no CAT macro and we don't want duplicate registrations 2019-08-22 15:50:36 +02:00
3fd2e8fd31 support epicsStdioRedirect everywhere 2019-08-21 16:01:06 +02:00
f2e9395377 don't include 3.14 headers in EPICS 3.13 2019-08-21 15:38:13 +02:00
6669b1c33c fix problems with extern C and epics headers in different EPICS versions 2019-08-21 15:33:46 +02:00
21ce272a65 don't complain unnecessarily in finishProtoco() when protocols are reloaded 2019-08-21 14:48:23 +02:00
2b6a064913 Show errors when debug is enabled 2019-08-21 14:40:03 +02:00
81a901b386 updated docu for EPICS 7.0.3 2019-08-21 14:36:55 +02:00
cfbc4ac369 have error logging initially enabled 2019-08-21 14:34:17 +02:00
d1b6c8bf1a fix bug that caused endless loops in I/O Intr records 2019-08-21 14:27:26 +02:00
491cfa6d4b Merge Freddie Akeroyd's Windows fixes 2019-08-19 17:02:26 +02:00
a6b11bea0e document recommended value for PollPeriod 2019-08-08 14:54:20 +02:00
a6190c7ddf document debug and error messages 2019-08-08 14:48:40 +02:00
4ece622c52 Merge pull request #40 from FreddieAkeroyd/build_with_vs2010
Fix build issues with vs2010
2019-07-18 17:34:08 +02:00
0e525fc893 Use $(CAT) for WIN32 2019-06-08 21:48:54 +01:00
85c9a8b130 Fix linker import warning for StreamDebugFile on WIN32 2019-06-08 21:30:37 +01:00
905d8a3b4a Fix for VS2010 usage of __VA_ARGS__ 2019-06-08 20:46:21 +01:00
1cc5f3fbd6 Fix missing inttypes.h on VS2010 2019-06-08 20:44:26 +01:00
3ad63e04d0 Define ENABLE_VIRTUAL_TERMINAL_PROCESSING if not present 2019-06-08 20:34:39 +01:00
880a399e4e fix for commit cb4d49: needed to add SUPPORT=, not RELEASE= for SynApps 2019-05-29 08:48:35 +02:00
592146a648 Have separate dbd file without scalcout support (by Martin Konrad) 2019-05-21 16:58:41 +02:00
e03285b9a9 Merge branch 'master' of github.com:paulscherrerinstitute/StreamDevice 2019-05-21 11:40:30 +02:00
fb3d20bfd9 Merge pull request #37 from shadowguy/master
Update some EPICS related links
2019-05-21 11:39:52 +02:00
3363f4f525 add new record types to the pdf 2019-05-21 11:36:19 +02:00
ed300116bd add tolower and toupper to regsubst 2019-05-21 09:50:53 +02:00
f912e0b370 Update some EPICS related links 2019-05-02 11:24:18 +02:00
b84655e4de Support %% in protocol just like in printf/scanf. (Suggested by Klemen Vodopivec) 2019-02-26 16:30:20 +01:00
ece1e01d21 Fix incosistent readRequst() function signature in documentation. 2019-02-26 15:17:53 +01:00
26877dedbd move enum Commands into class StreamCore to avoid collisions of enum state wait with function pid_t wait(int*) 2019-02-20 15:11:07 +01:00
7aa1802ec6 link streamApp with sscan if SSCAN is defined in RELEASE 2019-02-19 16:14:45 +01:00
eb9f565aec don't mess with asynTraceMask any more 2019-02-18 13:54:43 +01:00
04906a5835 regsub converter: empty match advances by 1 byte to avoid loops 2019-02-18 11:08:21 +01:00
acf7efcff2 fix hanging 'in' command when it is the first command of the protocol and the device is offline 2018-11-27 13:45:27 +01:00
d873d220dc fix broken version detection 2018-11-27 13:41:49 +01:00
9ef1653e73 Use inverse instead of fat for hex byte output because not all terminals support fat off 2018-11-16 15:26:33 +01:00
d1d65344af define feature test macro to ensure vsnprintf is available 2018-11-16 12:02:33 +01:00
a76adc31ab Implement needed vsnprintf for vxWorks 5. (vxWorks 6 has it already) 2018-11-16 11:49:25 +01:00
a2fcbc81c8 RTEMS has vsnprintf at least since 4.5.1-pre3 2018-11-16 11:22:45 +01:00
fa51c376c1 Windows has vsnprintf at least since 2003 2018-11-16 10:59:32 +01:00
483530f053 enable rendering of ANSI term colors on Windows console 2018-11-16 10:40:04 +01:00
8f34dd2c84 avoid problems with echo and quotes in Windows 2018-11-16 10:28:46 +01:00
493dc19d8b fix problem with redirects to records that do not start with a letter or underscore 2018-11-14 15:26:33 +01:00
3b64242ffd Merge branch 'master' of github.com:paulscherrerinstitute/StreamDevice 2018-11-14 11:41:47 +01:00
280cb7765a Merge pull request #19 from shadowguy/master
EPICS R3.15.6 dev guide
2018-11-14 11:01:48 +01:00
835e68bd76 fix test: sign extension does not depend on 32 or 64 bit architecture any more 2018-10-10 11:47:42 +02:00
92903361d0 handle state alarms in mbbo update 2018-10-10 11:08:41 +02:00
fb937316aa fix bug in mbbo string readback 2018-10-10 11:06:58 +02:00
ae6ebc4106 mbbo changes: use SHFT and MASK even with VAL (if no xxVL defined or ENUM format) 2018-10-10 11:06:22 +02:00
0f0dd31a0d test build with epics 7 2018-10-10 10:01:18 +02:00
189e61bbe8 Prep for EPICS R3.15.6 release 2018-10-06 15:22:48 +02:00
d8f88c340a remove STREAM_PATCHLEVEL macro because I always forget to update it anyway 2018-09-27 16:21:46 +02:00
2ef5c47f19 fix rule to rebuild StreamVersion.o whenever any other object code changed 2018-09-27 16:05:35 +02:00
cb4d490fb6 added RELEASE variable for SynApps 2018-09-25 14:35:20 +02:00
da281ebf97 Merge branch 'master' of github.com:paulscherrerinstitute/StreamDevice 2018-09-19 16:42:12 +02:00
c832efbcb6 Merge pull request #17 from shadowguy/master
Updated more EPICS web links.  SynApps link was actually broken
2018-09-19 16:41:37 +02:00
b7b3bc0af0 Fix problem with \? at end of input format when no more input is available. Used to work. Works again (but was not really intended) 2018-09-19 16:36:01 +02:00
4a42c3d43a Web link fixes, updated 3.14.8 dev guide link to 3.14.12 2018-09-17 14:13:39 +02:00
624cc0134a Merge branch 'master' of github.com:paulscherrerinstitute/StreamDevice 2018-09-14 16:19:09 +02:00
d9d5d5f55d Merge pull request #16 from shadowguy/master
Typo
2018-09-14 16:18:07 +02:00
53ea75dc80 use macro instead of magic value 2018-09-12 09:48:55 +02:00
b1f4c2a7d9 improve debug message 2018-09-11 18:27:52 +02:00
d87e9cedd2 reset proc to 0 in case it had been 2 to trigger @init 2018-09-11 18:19:58 +02:00
32d93d9028 Merge pull request #15 from darcato/master
Fix typos
2018-09-11 15:10:06 +02:00
3d30827798 Typos on DFB_ULONG 2018-09-11 15:01:33 +02:00
b688f14c22 Merge pull request #14 from icshwi/master
minor modifications related delete and char size
2018-09-10 15:16:10 +02:00
9e972d3f33 Typo 2018-09-05 22:21:12 +02:00
f5da2ea6b3 Do not limit to 80 chars when the link can be 256 by @krisztianloki 2018-08-29 22:27:07 +02:00
4edd2f2eff Fixed new[] / delete mismatch by @krisztianloki 2018-08-29 22:08:23 +02:00
846b884eb5 fix (and simplify) reading strings into waveform, aai, aao, lsi, lso 2018-08-21 16:03:03 +02:00
3f1918ed2d Merge branch 'shadowguy-master' 2018-08-21 10:44:16 +02:00
1d753366d8 fix of the fix 2018-08-21 10:43:13 +02:00
047f18d113 Merge branch 'master' of https://github.com/shadowguy/StreamDevice into shadowguy-master 2018-08-21 09:21:49 +02:00
26c5b012a7 Start search for end parenthesis one character sooner to allow empty parentheses 2018-08-20 20:02:41 +02:00
4f33600a0f Minor typo 2018-08-20 19:07:31 +02:00
2077dfb0a6 Un-breaking EPICS links 2018-08-20 19:01:54 +02:00
52 changed files with 785 additions and 435 deletions

View File

@ -11,12 +11,8 @@ DOCUDIR = docs
PCRE=1
ASYN=1
ifdef EPICSVERSION
ifndef RECORDTYPES
include src/CONFIG_STREAM
export RECORDTYPES BUSSES FORMATS
endif
endif
-include ../src/CONFIG_STREAM
-include src/CONFIG_STREAM
SOURCES += $(RECORDTYPES:%=src/dev%Stream.c)
SOURCES += $(FORMATS:%=src/%Converter.cc)
@ -32,9 +28,8 @@ HEADERS += StreamError.h
StreamCore.o StreamCore.d: streamReferences
# Update version string (contains __DATE__ and __TIME__)
# each time make runs.
StreamVersion.o: FORCE
FORCE:
# each time anything changes.
StreamVersion.o: $(filter-out StreamVersion.o stream_exportAddress.o,$(LIBOBJS))
streamReferences:
$(PERL) ../src/makeref.pl Interface $(BUSSES) > $@

View File

@ -9,7 +9,7 @@ else ifneq ($(wildcard ../config),)
else
# Using our own local configuration
TOP = .
DIRS = config configure
DIRS = configure
src_DEPEND_DIRS := $(DIRS)
include $(TOP)/configure/CONFIG
endif

View File

@ -1,6 +1,6 @@
# StreamDevice
_StreamDevice_ is a generic [EPICS](https://www.aps.anl.gov/epics)
_StreamDevice_ is a generic [EPICS](https://epics.anl.gov/)
device support for devices with a "byte stream" based
communication interface.
That means devices that can be controlled by sending and receiving

View File

@ -14,30 +14,18 @@ TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
# define INSTALL_LOCATION_APP here
#INSTALL_LOCATION_APP=<fullpathname>
SUPPORT=$(TOP)/..
-include $(TOP)/../configure/SUPPORT.$(EPICS_HOST_ARCH)
EPICS_BASE=/usr/local/epics/base-3.16.1
ASYN=~/top-3.16/asyn4-30
CALC=~/top-3.16/SynApps/calc-2-8
PCRE=~/top-3.16/pcre-7-2
PCRE_INCLUDE_SL6-x86=/usr/include
PCRE_INCLUDE_SL6-x86_64=/usr/include
PCRE_INCLUDE_SL6-x86_64-clang=/usr/include
ASYN=$(SUPPORT)/asyn4-36
CALC=$(SUPPORT)/calc-3-7
PCRE=$(SUPPORT)/pcre-7-2
#EPICS_BASE=/usr/local/epics/base-3.15.5
#ASYN=~/top-3.15/asyn4-30
#CALC=~/top-3.15/SynApps/calc-2-8
#PCRE=~/top-3.15/pcre-7-2
# EPICS_BASE usually appears last so other apps can override stuff:
EPICS_BASE=/usr/local/epics/base-7.0.3
#EPICS_BASE=/usr/local/epics/base-3.14.12
#ASYN=~/top/asyn4-30
#CALC=~/top/SynApps/calc-2-8
#PCRE=~/top/pcre-7-2
#3.14.8 does not understand ~
#EPICS_BASE=/usr/local/epics/base-3.14.8
#ASYN=/afs/psi.ch/user/z/zimoch/top/asyn-4.10
##Example 3.13 build
#EPICS_BASE=/usr/local/epics/base-3.13.10
#ASYN=/afs/psi.ch/user/z/zimoch/top_3.13/4-6
#COMPAT=/afs/psi.ch/user/z/zimoch/top_3.13
# These lines allow developers to override these RELEASE settings
# without having to modify this file directly.
-include $(TOP)/../RELEASE.local
-include $(TOP)/../RELEASE.$(EPICS_HOST_ARCH).local
-include $(TOP)/configure/RELEASE.local

View File

@ -69,7 +69,7 @@ class MyInterface : StreamBusInterface
bool <a href="#lock">lockRequest</a>(unsigned long lockTimeout_ms);
bool <a href="#lock">unlock</a>();
bool <a href="#write">writeRequest</a>(const void* output, size_t size, unsigned long writeTimeout_ms);
bool <a href="#read">readRequest</a>(unsigned long replyTimeout_ms, unsigned long readTimeout_ms, long expectedLength, bool async);
bool <a href="#read">readRequest</a>(unsigned long replyTimeout_ms, unsigned long readTimeout_ms, ssize_t expectedLength, bool async);
bool <a href="#read">supportsAsyncRead</a>();
bool <a href="#event">supportsEvent</a>();
bool <a href="#event">acceptEvent</a>(unsigned long mask, unsigned long timeout_ms);
@ -118,7 +118,7 @@ bool <a href="#write">writeRequest</a>(const&nbsp;void*&nbsp;output,
<div class="indent"><code>
bool <a href="#read">readRequest</a>(unsigned&nbsp;long&nbsp;replyTimeout_ms,
unsigned&nbsp;long&nbsp;readTimeout_ms,
long&nbsp;expectedLength, bool&nbsp;async);
ssize_t&nbsp;expectedLength, bool&nbsp;async);
</code></div>
<div class="indent"><code>
bool <a href="#read">supportsAsyncRead</a>();
@ -460,7 +460,7 @@ The client may request more I/O or call <code>unlock()</code> after
<div class="indent"><code>
bool readRequest(unsigned&nbsp;long&nbsp;replyTimeout_ms,
unsigned&nbsp;long&nbsp;readTimeout_ms,
long&nbsp;expectedLength, bool&nbsp;async);
ssize_t&nbsp;expectedLength, bool&nbsp;async);
</code></div>
<div class="indent"><code>
ssize_t readCallback(IoStatus&nbsp;status,

View File

@ -53,7 +53,7 @@ RegisterConverter(MyConverter,"Q");
</pre>
<a name="theory"></a>
<h2>Theroy of Operation</h2>
<h2>Theory of Operation</h2>
<a name="registration"></a>
<h3>Registration </h3>

View File

@ -37,6 +37,14 @@ A format converter consists of
<li>Additional information required by some converters</li>
</ul>
<p class="new">
An exception is the sequence <code>%%</code> which stands for a single
literal <code>%</code>.
This has been added for compatibility with the C functions
<em>printf()</em> and <em>scanf()</em>.
It behaves the same as the escaped percent <code>\%</code>.
</p>
<p>
The flags <code>*# +0-</code> work like in the C functions
<em>printf()</em> and <em>scanf()</em>.
@ -83,8 +91,6 @@ formatted (like for output) and then compared to the input.
The <code>!</code> flag demands that input is exactly <em>width</em>
bytes long (normally <em>width</em> defines the maximum number of
bytes read in many formats).
For example <code>in "%!5d";</code> expects exactly 5 digits.
Fewer digits are considered loss of data and make the format fail.
This feature has been added by Klemen Vodopivec, SNS.
</p>
@ -118,6 +124,14 @@ This feature has been added by Klemen Vodopivec, SNS.
<td><code>in "%=.3f";</code></td>
<td>Assure that the input is equal to the current value formatted as a float with precision 3</td>
</tr>
<tr>
<td><code>in "%!5d";</code></td>
<td>Expect exactly 5 decimal digits. Fewer digits are considered loss of data and make the format fail.
</tr>
<tr>
<td><code>in "%d%%";</code></td>
<td>Read a decimal number followed by a % sign</td>
</tr>
</table>
<a name="types"></a>
@ -587,7 +601,7 @@ It is only available if a PCRE library is installed.
<div class="box">
<p>
If PCRE is not available for your host or cross architecture, download
the sourcecode from <a target="ex" href="http://www.pcre.org/">www.pcre.org</a>
the sourcecode from <a target="ex" href="https://www.pcre.org/">www.pcre.org</a>
and try my EPICS compatible <a target="ex"
href="http://epics.web.psi.ch/software/streamdevice/pcre/Makefile">Makefile</a>
to compile it like a normal EPICS support module.
@ -642,6 +656,13 @@ Matches of the <em>regex</em> are replaced by the string <em>subst</em> with all
<code>\1</code> through <code>\9</code> replaced with the match of the corresponding
sub-expression <span class="new"> if such a sub-expression exists.
Occurrences of <code>\U<i>n</i></code>, <code>\L<i>n</i></code>, <code>\u<i>n</i></code>,
or <code>\l<i>n</i></code> with <code><i>n</i></code> being a number <code>0</code>
through <code>9</code> or <code>&</code> are replaced with the corresponding sub-expression
converted to all upper case, all lower case, first letter upper case, or first letter lower
case, respectively.</span>
</p>
<p><span class="new">
Due to limitations of the parser, <code>\1</code> and <code>\x01</code> are the same
which makes it difficult to use literal bytes with values lower than 10 in <em>subst</em>.
Therefore <code>\0</code> aways means a literal byte (incompatible change from earlier version!)
@ -666,6 +687,13 @@ Otherwise <em>precision</em> is the index (counting from 1) of the match to repl
Without <em>precision</em> (or 0), all matches are replaced.
</p>
<p>
When replacing multiple matches, the next match is searched directly after the currently
replaced string, so that the <em>subst</em> string itself will never be modified recursively.
<span class="new">
However if an empty string is matched, searching advances by 1 character in order to
avoid matching the same empty string again.</span>
</p>
<p>
In input this converter pre-processes data received from the device before
following converters read it.
Converters preceding this one will read unmodified input.
@ -701,6 +729,9 @@ which is not at the end of a word.
<code>%#/([^+-])*([+-])/\2\1/</code> moves a postfix sign to the front.
(<code>1.23-</code> becomes <code>-1.23</code>)<br>
</div>
<div class="indent">
<code>%#-2/.*/\U0/</code> converts the previous 2 characters to upper case.
</div>
<a name="mantexp"></a>
<h2>15. MantissaExponent DOUBLE converter (<code>%m</code>)</h2>
<p>

View File

@ -15,7 +15,7 @@
<h2>What is <em>StreamDevice</em>?</h2>
<p>
<em>StreamDevice</em> is a generic
<a href="https://www.aps.anl.gov/epics" target="ex">EPICS</a>
<a href="https://epics.anl.gov/" 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
@ -96,12 +96,12 @@ come in a predictible order to be parsable by <em>StreamDevice</em>.
<h2>Recommended Readings</h2>
<p>
IOC Application Developer's Guide:
<a href="https://www.aps.anl.gov/epics/base/R3-14/12-docs/AppDevGuide"
<a href="https://epics.anl.gov/base/R3-14/12-docs/AppDevGuide/"
target="ex">R3.14.12</a>,
<a href="https://www.aps.anl.gov/epics/base/R3-16/1-docs/AppDevGuide"
target="ex">R3.15.5</a>,
<a href="https://www.aps.anl.gov/epics/base/R3-15/5-docs/AppDevGuide"
target="ex">R3.16.1</a>
<a href="https://epics.anl.gov/base/R3-15/6-docs/AppDevGuide/AppDevGuide.html"
target="ex">R3.15.6</a>,
<a href="https://epics.anl.gov/base/R3-16/2-docs/AppDevGuide/AppDevGuide.html"
target="ex">R3.16.2</a>
</p>
<p>
<a href="https://wiki-ext.aps.anl.gov/epics/index.php/RRM_3-14"
@ -120,7 +120,7 @@ Longer code segments are often set in a box.
<h2>Changes in Version 2.8</h2>
<ul>
<li>Support standard EPICS module build system.
<li>Compatible with EPICS base releases up to 7.0.1.
<li>Compatible with EPICS 7.
<ul>
<li>Support for new record types: int64in, int64out, lsi, lso.
<li>Support for INT64 and UINT64 in aai, aao, waveform.
@ -128,7 +128,6 @@ Longer code segments are often set in a box.
<li>Run @init more often (e.g. when device re-connects or paused IOC is resumed).
<li>Use "COMM" error code in .STAT when device is disconnected.
<li>Allow spaces in protocol parameter list.
<li>Errors are new silent by default (var streamError 0) except during init.
<li>Support output redirect of all shell functions.
<li>Fix building shared libraries on Windows.
<li>Fix some C++11 warnings.

View File

@ -20,17 +20,21 @@ ai.html
ao.html
bi.html
bo.html
mbbi.html
mbbo.html
mbbiDirect.html
mbboDirect.html
stringin.html
stringout.html
calcout.html
int64in.html
int64out.html
longin.html
longout.html
waveform.html
calcout.html
lsi.html
lso.html
mbbiDirect.html
mbboDirect.html
mbbi.html
mbbo.html
scalcout.html
stringin.html
stringout.html
waveform.html
tipsandtricks.html
recordinterface.html
businterface.html

View File

@ -23,7 +23,7 @@ written or read value.
<dd>
Not allowed.
</dd>
<dt>LONG format (e.g. <code>%i</code>):</dt>
<dt>LONG <span class=new>or ENUM</span> format (e.g. <code>%i</code>):</dt>
<dd>
<dl>
<dt>If any of <code>ZRVL</code> ... <code>FFVL</code> is set
@ -41,17 +41,12 @@ written or read value.
</dd>
<dt>If none of <code>ZRVL</code> ... <code>FFVL</code> is set
(all are <code>0</code>):</dt>
<dd>
<u>Output:</u> <code><i>x</i>=VAL</code><br>
<u>Input:</u> <code>VAL=<i>x</i></code><br>
<dd class=new>
<u>Output:</u> <code><i>x</i>=(VAL&lt;&lt;SHFT)&amp;MASK</code><br>
<u>Input:</u> <code>VAL=(RBV=(<i>x</i>&amp;MASK))&gt;&gt;SHFT</code><br>
</dd>
</dl>
</dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd>
<u>Output:</u> <code><i>x</i>=VAL</code><br>
<u>Input:</u> <code>VAL=<i>x</i></code><br>
</dd>
<dt>STRING format (e.g. <code>%s</code>):</dt>
<dd>
<u>Output:</u> Depending on <code>VAL</code>, one of <code>ZRST</code>

View File

@ -95,6 +95,7 @@ div div div a {list-style-type:circle;}
<div>
<a target="_parent" href="setup.html#reload">Reloading</a>
</div>
<a target="_parent" href="setup.html#debug">Debugging</a>
<a target="_parent" href="setup.html#rec">Records</a>
</div>
</div>

View File

@ -16,7 +16,7 @@
<h2>1. Normal Processing</h2>
<p>
<em>StreamDevice</em> is an asynchronous device support
(see <a href="http://www.aps.anl.gov/epics/base/R3-14/8-docs/AppDevGuide.pdf"
(see <a href="http://www.aps.anl.gov/epics/base/R3-14/12-docs/AppDevGuide.pdf"
target="ex">IOC Application Developer's Guide</a> chapter 12:
Device Support).
Whenever the record is processed, the <a href="protocol.html">protocol</a>

View File

@ -390,6 +390,9 @@ what they influence.
the moment.
How many milliseconds to wait after last poll or last received
input before polling again?
A good value is about half the time of the expected input period.
Longer values cause latency and shorter values may increase CPU
consumption.
If not set the same value as for <code>ReplyTimeout</code> is
used.
</dd>
@ -479,12 +482,63 @@ To make this easier, <em>protocol arguments</em> can be used:
move { out "\$1 GOTO %d"; }
</pre>
<p>
Now, the protocol can be references in the <code>OUT</code> link
Now the same protocol can be used in the <code>OUT</code> link
of three different records as <code>move(X)</code>,
<code>move(Y)</code> and <code>move(Z)</code>.
Up to 9 parameters, referenced as <code>$1</code> ... <code>$9</code>
can be specified in parentheses, separated by comma.
The variable <code>$0</code> is replaced by the name of the protocol.
</p>
<p>
Up to 9 parameters can be specified in parentheses, separated by comma.
In the protocol, they are referenced as <code>$1</code> ...
<code>$9</code> outside quotes or <code>\$1</code> ... <code>\$9</code>
within quotes. The parameter <code>$0</code> resolves to the protocol name.
</p>
<div class="new">
<p>
To make links more readable, one space is allowed before and after each comma
and the enclosing parentheses. This space is not part of the parameter string.
Any additional space is part of the parameter.
</p>
<p>
If a parameter contains matching pairs of parentheses, these and all commas
inside are part of the parameter.
This allows to pass parameter strings like <code>(1,2)</code> easily without
much escaping.
</p>
<p>
Unmatched parentheses must be escaped with double backslash <code>\\</code>
as well as must be commas outside pairs of parentheses.
Double backslash is necessary because one backslash is already consumed by
the db file parser.
To pass a literal backslash in a parameter string use 4 backslashes
<code>\\\\</code>.
</p>
</div>
<p>
Note that macros can be used in parameters. That makes it possible to
pass part of the record name to the protocol to be used in
<a href="formats.html#redirection">redirections</a>.
</p>
<h4>Example:</h3>
<pre>
record(ai, "$(PREFIX)recX5") {
field(DTYP, "stream")
field(INP, "@$(PROTOCOLFILE) read(5, X\\,Y $(PREFIX)) $(PORT)")
}
record(ai, "$(PREFIX)recY5") {}
read { out 0x8$1 "READ \$2"; in "%f,%(\$3recY\$1)f" }
</pre>
<p>
The protocol resolves to:
</p>
<pre>
read { out 0x85 "READ X,Y"; in "%f,%($(PREFIX)recY5)f" }
</pre>
<p>
Here <code>$(PREFIX)</code> is replaced with its macro value.
But be aware that the macro is actually replaced before the link is parsed so
that macro values containing comma or parentheses may have unintended effects.
</p>
<a name="usrvar"></a>
@ -562,7 +616,7 @@ There is a fixed set of exception handler names starting with
</dd>
</dl>
<h3>Example:</h3>
<h4>Example:</h3>
<pre>
setPosition {
out "POS %f";

View File

@ -15,7 +15,7 @@
<p>
<b>Note:</b> The scalcout record is part of the <i>calc</i> module of
the <a target="ex"
href="http://www.aps.anl.gov/aod/bcda/synApps/index.php"
href="https://www.aps.anl.gov/BCDA/synApps"
><em>synApps</em></a> package.
Device support for scalcout records is only available for <i>calc</i>
module release 2-4 or higher.

View File

@ -17,9 +17,9 @@
<p>
<em>StreamDevice</em> works with
<a href="https://epics.anl.gov/base/index.php">EPICS base</a>
versions from R3.14.6 on, tested up to 7.0.1.
versions from R3.14.6 on, tested up to 7.0.3.
It also works (with limitations) with older
<a href="https://www.aps.anl.gov/epics/base/R3-13.php">R3.13</a>
<a href="https://epics.anl.gov/base/R3-13.php">R3.13</a>
versions from R3.13.7 on.
How to use <em>StreamDevice</em> with EPICS R3.13 is described on a
<a href="epics3_13.html">separate page</a>.
@ -377,8 +377,43 @@ protocol is loaded.
See the <a href="protocol.html">next chapter</a> for protocol files in depth.
</p>
<a name="debug"></a>
<h2>5. Debug and Error Messages</h2>
<p>
Generation of debug and error messages is controlled with two shell variables,
<code>streamDebug</code> and <code>streamError</code>.
Setting those variables to 1 (actually to any number but 0) enables the
messages.
Per default debug messages are switched off and error messages are switched on.
Errors occuring while loading protocol files are always shown.
</p>
<p>
Warning: Enabling debug messages can create a lot of output!
At the moment, there is no way to set filters on debug or error messages.
</p>
<p>
Debug output can be redirected to a file with the command
<code>streamSetLogfile("<var>filename</var>")</code>.
When called without a filename, debug output is directed back
to the console.
</p>
<h3>Example (vxWorks):</h3>
<pre>
streamError=1
streamDebug=1
streamSetLogfile("logfile.txt")
</pre>
<h3>Example (iocsh):</h3>
<pre>
var streamError 1
var streamDebug 1
streamSetLogfile("logfile.txt")
</pre>
<a name="rec"></a>
<h2>5. Configuring the Records</h2>
<h2>6. Configuring the Records</h2>
<p>
To tell a record to use <em>StreamDevice</em>, set its <code>DTYP</code> field to
<code>"stream"</code>.
@ -388,7 +423,7 @@ The <code>INP</code> or <code>OUT</code> link has the form
<code>"@<var>filename&nbsp;protocol</var>[(<var>arg1</var>,<var>arg2</var>,...)]&nbsp;</var>bus</var>&nbsp;[<var>address</var>&nbsp;[<var>parameters</var>]]"</code>.
</p>
<p>
(Elements in <code>[]</code> are optional. To not type the <code>[]</code>).
(Elements in <code>[]</code> are optional. Do not type the <code>[]</code>).
</p>
<p>
Here, <code><var>filename</var></code> is the name of the protocol file and

View File

@ -69,6 +69,10 @@ h4 {
margin-bottom:0.25ex;
}
h1, h2, h3, h4 {
page-break-after:avoid;
}
p {
margin-top:0.75ex;
margin-bottom:0.75ex;

View File

@ -17,10 +17,6 @@
* *
***************************************************************/
#include "StreamBusInterface.h"
#include "StreamError.h"
#include "StreamBuffer.h"
#ifdef EPICS_3_13
#include <assert.h>
#include <wdLib.h>
@ -32,10 +28,13 @@ extern "C" {
#include "epicsAssert.h"
#include "epicsTime.h"
#include "epicsTimer.h"
#include "epicsStdioRedirect.h"
#include "iocsh.h"
#endif
#include "StreamBusInterface.h"
#include "StreamError.h"
#include "StreamBuffer.h"
#include "asynDriver.h"
#include "asynOctet.h"
#include "asynInt32.h"
@ -43,6 +42,7 @@ extern "C" {
#include "asynGpibDriver.h"
#include "devStream.h"
#include "MacroMagic.h"
#define Z PRINTF_SIZE_T_PREFIX
@ -162,7 +162,7 @@ class AsynDriverInterface : StreamBusInterface
double writeTimeout;
double readTimeout;
double replyTimeout;
size_t expectedLength;
ssize_t expectedLength;
unsigned long eventMask;
unsigned long receivedEvent;
StreamBuffer inputBuffer;
@ -187,7 +187,7 @@ class AsynDriverInterface : StreamBusInterface
bool writeRequest(const void* output, size_t size,
unsigned long writeTimeout_ms);
bool readRequest(unsigned long replyTimeout_ms,
unsigned long readTimeout_ms, size_t expectedLength, bool async);
unsigned long readTimeout_ms, ssize_t expectedLength, bool async);
bool acceptEvent(unsigned long mask, unsigned long replytimeout_ms);
bool supportsEvent();
bool supportsAsyncRead();
@ -457,10 +457,6 @@ connectToBus(const char* portname, int addr)
return false;
}
// disable asyn errors to avoid flooding when device is disconnected
// user can re-enable later
pasynTrace->setTraceMask(pasynUser, 0);
asynInterface* pasynInterface;
// find the asynCommon interface
@ -804,7 +800,7 @@ writeHandler()
// interface function: we want to read something
bool AsynDriverInterface::
readRequest(unsigned long replyTimeout_ms, unsigned long readTimeout_ms,
size_t _expectedLength, bool async)
ssize_t _expectedLength, bool async)
{
debug("AsynDriverInterface::readRequest(%s, %ld msec reply, "
"%ld msec read, expect %" Z "u bytes, async=%s)\n",

35
src/ChecksumConverter.cc Normal file → Executable file
View File

@ -28,6 +28,12 @@
#define SCNx8 "hhx"
#define uint_fast8_t uint8_t
#define int_fast8_t int8_t
#elif defined(_MSC_VER) && _MSC_VER < 1700 /* Visual Studio 2010 does not have inttypes.h */
#include <stdint.h>
#define PRIX32 "X"
#define PRIu32 "u"
#define PRIX8 "X"
#define SCNx8 "hhx"
#else
#define __STDC_FORMAT_MACROS
#include <stdint.h>
@ -498,6 +504,18 @@ static uint32_t leybold(const uint8_t* data, size_t len, uint32_t sum)
return sum;
}
// Checksum used by Brooks Cryopumps
static uint32_t brksCryo(const uint8_t* data, size_t len, uint32_t sum)
{
uint32_t xsum;
while (len--) {
sum += (*data++) & 0x7F;
}
xsum = (((sum >> 6) ^ sum) & 0x3F) + 0x30;
return xsum;
}
struct checksum
{
const char* name;
@ -515,8 +533,13 @@ static checksum checksumMap[] =
{"sum8", sum, 0x00, 0x00, 1}, // 0xDD
{"sum16", sum, 0x0000, 0x0000, 2}, // 0x01DD
{"sum32", sum, 0x00000000, 0x00000000, 4}, // 0x000001DD
{"nsum8", sum, 0xFF, 0xFF, 1}, // 0x23
{"nsum16", sum, 0xFFFF, 0xFFFF, 2}, // 0xFE23
{"nsum32", sum, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFFFFFE23
{"notsum", sum, 0x00, 0xFF, 1}, // 0x22
{"xor", xor8, 0x00, 0x00, 1}, // 0x31
{"xor8", xor8, 0x00, 0x00, 1}, // 0x31
{"xor8ff", xor8, 0x00, 0xFF, 1}, // 0xCE
{"xor7", xor7, 0x00, 0x00, 1}, // 0x31
{"crc8", crc_0x07, 0x00, 0x00, 1}, // 0xF4
{"ccitt8", crc_0x31, 0x00, 0x00, 1}, // 0xA1
@ -535,6 +558,7 @@ static checksum checksumMap[] =
{"hexsum8", hexsum, 0x00, 0x00, 1}, // 0x2D
{"cpi", CPI, 0x00, 0x00, 1}, // 0x7E
{"leybold", leybold, 0x00, 0x00, 1}, // 0x22
{"brksCryo",brksCryo, 0x00, 0x00, 1} // 0x4A
};
static uint32_t mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};
@ -700,13 +724,14 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
debug("ChecksumConverter %s: input to check: \"%s\n",
checksumMap[fnum].name, input.expand(start,length)());
uint_fast8_t expectedLength =
uint_fast8_t nDigits =
// get number of decimal digits from number of bytes: ceil(bytes*2.5)
format.flags & sign_flag ? (checksumMap[fnum].bytes + 1) * 25 / 10 - 2 :
format.flags & (zero_flag|left_flag) ? 2 * checksumMap[fnum].bytes :
checksumMap[fnum].bytes;
ssize_t expectedLength = nDigits;
if (input.length() - cursor < expectedLength)
if ((ssize_t)( input.length() - cursor ) < expectedLength)
{
debug("ChecksumConverter %s: Input '%s' too short for checksum\n",
checksumMap[fnum].name, input.expand(cursor)());
@ -725,7 +750,7 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
if (format.flags & sign_flag) // decimal
{
uint32_t sumin = 0;
size_t i;
ssize_t i;
for (i = 0; i < expectedLength; i++)
{
inchar = input[cursor+i];
@ -747,7 +772,7 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
{
if (format.flags & zero_flag) // ASCII
{
if (sscanf(input(cursor+2*i), "%2" SCNx8, &inchar) != 1)
if (sscanf(input(cursor+2*i), "%2" SCNx8, (int8_t *) &inchar) != 1)
{
debug("ChecksumConverter %s: Input byte '%s' is not a hex byte\n",
checksumMap[fnum].name, input.expand(cursor+2*i,2)());
@ -791,7 +816,7 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, size_t& cursor)
{
if (format.flags & zero_flag) // ASCII
{
sscanf(input(cursor+2*i), "%2" SCNx8, &inchar);
sscanf(input(cursor+2*i), "%2" SCNx8, (int8_t *) &inchar);
}
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F

View File

@ -37,7 +37,7 @@ class DebugInterface : StreamBusInterface
bool writeRequest(const void* output, size_t size,
unsigned long writeTimeout_ms);
bool readRequest(unsigned long replyTimeout_ms,
unsigned long readTimeout_ms, size_t expectedLength, bool async);
unsigned long readTimeout_ms, ssize_t expectedLength, bool async);
protected:
~DebugInterface();
@ -169,9 +169,9 @@ writeRequest(const void* output, size_t size, unsigned long writeTimeout_ms)
// Return false if the read request cannot be accepted.
bool DebugInterface::
readRequest(unsigned long replyTimeout_ms, unsigned long readTimeout_ms,
size_t expectedLength, bool async)
ssize_t expectedLength, bool async)
{
debug("DebugInterface::readRequest(%s, %ld msec reply, %ld msec read, expect %" Z "u bytes, asyn=%s)\n",
debug("DebugInterface::readRequest(%s, %ld msec reply, %ld msec read, expect %" Z "d bytes, asyn=%s)\n",
clientName(), replyTimeout_ms, readTimeout_ms, expectedLength, async?"yes":"no");
// Debug interface does not support async mode.

View File

@ -37,28 +37,35 @@ _ENUM_CAST(type)
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, N, ...) N
/*
* we need to use _EXPAND below to work around a problem in Visual Studio 2010
* where __VA_ARGS__ is treated as a single argument
* See https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly
*/
#define _EXPAND( x ) x
#define _fe_0(_call, ...)
#define _fe_1(_call, x) _call(x)
#define _fe_2(_call, x, ...) _call(x) _fe_1(_call, __VA_ARGS__)
#define _fe_3(_call, x, ...) _call(x) _fe_2(_call, __VA_ARGS__)
#define _fe_4(_call, x, ...) _call(x) _fe_3(_call, __VA_ARGS__)
#define _fe_5(_call, x, ...) _call(x) _fe_4(_call, __VA_ARGS__)
#define _fe_6(_call, x, ...) _call(x) _fe_5(_call, __VA_ARGS__)
#define _fe_7(_call, x, ...) _call(x) _fe_6(_call, __VA_ARGS__)
#define _fe_8(_call, x, ...) _call(x) _fe_7(_call, __VA_ARGS__)
#define _fe_9(_call, x, ...) _call(x) _fe_8(_call, __VA_ARGS__)
#define _fe_10(_call, x, ...) _call(x) _fe_9(_call, __VA_ARGS__)
#define _fe_2(_call, x, ...) _call(x) _EXPAND(_fe_1(_call, __VA_ARGS__))
#define _fe_3(_call, x, ...) _call(x) _EXPAND(_fe_2(_call, __VA_ARGS__))
#define _fe_4(_call, x, ...) _call(x) _EXPAND(_fe_3(_call, __VA_ARGS__))
#define _fe_5(_call, x, ...) _call(x) _EXPAND(_fe_4(_call, __VA_ARGS__))
#define _fe_6(_call, x, ...) _call(x) _EXPAND(_fe_5(_call, __VA_ARGS__))
#define _fe_7(_call, x, ...) _call(x) _EXPAND(_fe_6(_call, __VA_ARGS__))
#define _fe_8(_call, x, ...) _call(x) _EXPAND(_fe_7(_call, __VA_ARGS__))
#define _fe_9(_call, x, ...) _call(x) _EXPAND(_fe_8(_call, __VA_ARGS__))
#define _fe_10(_call, x, ...) _call(x) _EXPAND(_fe_9(_call, __VA_ARGS__))
#define MACRO_FOR_EACH(x, ...) \
_NTH_ARG(_, ##__VA_ARGS__, \
_EXPAND(_NTH_ARG(_, ##__VA_ARGS__, \
_fe_10, _fe_9, _fe_8, _fe_7, _fe_6, _fe_5, _fe_4, _fe_3, _fe_2, _fe_1, _fe_0) \
(x, ##__VA_ARGS__)
(x, ##__VA_ARGS__))
/* Enum to string magic */
#define ENUM(type,...) \
enum type { __VA_ARGS__ }; \
static inline const char* type##ToStr(int x) {switch(x){MACRO_FOR_EACH(_CASE_LINE,__VA_ARGS__) default: return "invalid";}} \
static inline const char* type##ToStr(int x) {switch(x) {_EXPAND(MACRO_FOR_EACH(_CASE_LINE,__VA_ARGS__)) default: return "invalid";}} \
_ENUM_CAST(type)
#endif

View File

@ -35,6 +35,10 @@ endif
LIBRARY_DEFAULT = stream
DBD += $(LIBRARY_DEFAULT).dbd
DBD += $(LIBRARY_DEFAULT)-base.dbd
ifdef CALC
DBD += $(LIBRARY_DEFAULT)-scalcout.dbd
endif
ifdef ASYN
LIB_LIBS += asyn
@ -74,7 +78,7 @@ CPPFLAGS += -DUSE_TYPED_RSET
-include $(TOP)/configure/RULES
# Update version string whenever something changes
StreamVersion$(OBJ): ../*.c ../*.h ../*.cc ../CONFIG_STREAM
StreamVersion$(OBJ): $(filter-out StreamVersion.o,$(LIBOBJS)$(LIBRARY_OBJS))
# Add references to all registrars to main file to avoid
# missing initialization.
@ -84,12 +88,29 @@ streamReferences: ../CONFIG_STREAM
$(PERL) ../makeref.pl Interface $(BUSSES) > $@
$(PERL) ../makeref.pl Converter $(FORMATS) >> $@
# create stream.dbd from all RECORDTYPES
$(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM
$(PERL) ../makedbd.pl $(RECORDTYPES) > $@
ifdef ASYN
echo "registrar(AsynDriverInterfaceRegistrar)" >> $@
# create stream-base.dbd from all RECORDTYPES except scalcout record
$(COMMON_DIR)/$(LIBRARY_DEFAULT)-base.dbd: ../CONFIG_STREAM
$(PERL) ../makedbd.pl $(if $(ASYN),--with-asyn) $(if $(BASE_3_14),,-3.13) $(filter-out scalcout, $(RECORDTYPES)) > $@
$(LIBRARY_DEFAULT)-base.dbd$(DEP): ../CONFIG_STREAM
echo $(LIBRARY_DEFAULT)-base.dbd: $< > $@
STREAM_DBD_FILES = $(LIBRARY_DEFAULT)-base.dbd
ifdef CALC
# create stream-scalcout.dbd for scalcout record
$(COMMON_DIR)/$(LIBRARY_DEFAULT)-scalcout.dbd: ../CONFIG_STREAM
$(PERL) ../makedbd.pl --rec-only scalcout > $@
$(LIBRARY_DEFAULT)-scalcout.dbd$(DEP): ../CONFIG_STREAM
echo $(LIBRARY_DEFAULT)-scalcout.dbd: $< > $@
STREAM_DBD_FILES += $(LIBRARY_DEFAULT)-scalcout.dbd
endif
# create stream.dbd for all record types
$(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM
$(PERL) ../makedbd.pl $(if $(ASYN),--with-asyn) $(if $(BASE_3_14),,-3.13) $(RECORDTYPES) > $@
$(LIBRARY_DEFAULT).dbd$(DEP): ../CONFIG_STREAM
echo $(LIBRARY_DEFAULT).dbd: $< > $@

View File

@ -26,6 +26,9 @@ endif
include $(TOP)/config/CONFIG_APP
include ../CONFIG_STREAM
CXXCMPLR=NORMAL
G++_NORMAL = $(G++)
LIBNAME = streamLib
SRCS.cc += $(BUSSES:%=../%Interface.cc)

View File

@ -20,9 +20,10 @@
#include "StreamFormatConverter.h"
#include "StreamError.h"
#include "string.h"
#include "pcre.h"
#include <string.h>
#include <limits.h>
#include <ctype.h>
#define Z PRINTF_SIZE_T_PREFIX
@ -197,14 +198,15 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, size_t start
debug("pcre_exec: no match\n");
break;
}
if (!(fmt.flags & sign_flag) && n < fmt.prec) // without + flag
{
// do not yet replace this match
c += ovector[1];
continue;
}
// replace subexpressions
l = ovector[1] - ovector[0];
// no prec: replace all matches
// prec with + flag: replace first prec matches
// prec without + flag: replace only match number prec
if ((fmt.flags & sign_flag) || n >= fmt.prec)
{
// replace subexpressions
debug("before [%d]= \"%s\"\n", ovector[0], buffer.expand(start+c,ovector[0])());
debug("match [%d]= \"%s\"\n", l, buffer.expand(start+c+ovector[0],l)());
for (r = 1; r < rc; r++)
@ -218,9 +220,40 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, size_t start
if (s[r] == esc)
{
unsigned char ch = s[r+1];
debug("found escaped \\%u, in range 1-%d?\n", ch, rc-1);
if (ch != 0 && ch < rc) // escaped 1 - 9 : replace with subexpr
if (strchr("ulUL", ch))
{
unsigned char br = s[r+2] - '0';
if (br == (unsigned char)('&'-'0')) br = 0;
debug("found case conversion \\%c%u\n", ch, br);
if (br >= rc)
{
s.remove(r, 1);
continue;
}
br *= 2;
rl = ovector[br+1] - ovector[br];
s.replace(r, 3, buffer(start+c+ovector[br]), rl);
switch (ch)
{
case 'u':
if (islower(s[r])) s[r] = toupper(s[r]);
break;
case 'l':
if (isupper(s[r])) s[r] = tolower(s[r]);
break;
case 'U':
for (int i = 0; i < rl; i++)
if (islower(s[r+i])) s[r+i] = toupper(s[r+i]);
break;
case 'L':
for (int i = 0; i < rl; i++)
if (isupper(s[r+i])) s[r+i] = tolower(s[r+i]);
break;
}
}
else if (ch != 0 && ch < rc) // escaped 1 - 9 : replace with subexpr
{
debug("found escaped \\%u\n", ch);
ch *= 2;
rl = ovector[ch+1] - ovector[ch];
debug("yes, replace \\%d: \"%s\"\n", ch/2, buffer.expand(start+c+ovector[ch], rl)());
@ -229,7 +262,7 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, size_t start
}
else
{
debug("no, use literal \\%u\n", ch);
debug("use literal \\%u\n", ch);
s.remove(r, 1); // just remove escape
}
}
@ -243,8 +276,16 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, size_t start
debug("subs = \"%s\"\n", s.expand()());
}
buffer.replace(start+c+ovector[0], l, s);
length += s.length() - l;
c += ovector[0] + s.length();
length -= l;
length += s.length();
c += s.length();
}
c += ovector[0];
if (l == 0)
{
debug("pcre_exec: empty match\n");
c++; // Empty strings may lead to an endless loop. Match them only once.
}
if (n == fmt.prec) // max match reached
{
debug("pcre_exec: max match %d reached\n", n);

View File

@ -17,6 +17,11 @@
* *
***************************************************************/
// Make sure that vsnprintf is available
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#include "StreamBuffer.h"
#include "StreamError.h"
@ -24,10 +29,47 @@
#include <stdarg.h>
#include <stdlib.h>
#if defined(__vxworks) || defined(vxWorks) || defined(_WIN32) || defined(__rtems__)
// These systems have no vsnprintf
#define vsnprintf(p,l,f,v) vsprintf(p,f,v)
#endif
#ifdef vxWorks
#include <version.h>
#ifndef _WRS_VXWORKS_MAJOR
// VxWorks 5 has no vsnprintf
// Implementation taken from EPICS 3.14
#include <vxWorks.h>
#include <fioLib.h>
struct outStr_s {
char *str;
int free;
};
static STATUS outRoutine(char *buffer, int nchars, int outarg) {
struct outStr_s *poutStr = (struct outStr_s *) outarg;
int free = poutStr->free;
int len;
if (free < 1) { /*let fioFormatV continue to count length*/
return OK;
} else if (free > 1) {
len = min(free-1, nchars);
strncpy(poutStr->str, buffer, len);
poutStr->str += len;
poutStr->free -= len;
}
/*make sure final string is null terminated*/
*poutStr->str = 0;
return OK;
}
int vsnprintf(char *str, size_t size, const char *format, va_list ap) {
struct outStr_s outStr;
outStr.str = str;
outStr.free = size;
return fioFormatV(format, ap, (FUNCPTR)outRoutine, (int)&outStr);
}
#endif // ! _WRS_VXWORKS_MAJOR
#endif // vxWorks
#define P PRINTF_SIZE_T_PREFIX
@ -264,7 +306,7 @@ print(const char* fmt, ...)
return *this;
}
if (printed > -1) grow(len+printed);
else grow(len);
else grow(cap*2-1);
}
}
@ -296,7 +338,7 @@ StreamBuffer StreamBuffer::expand(ssize_t start, ssize_t length) const
{
c = buffer[i];
if (c < 0x20 || c >= 0x7f)
result.print("\033[1m<%02x>\033[22m", c & 0xff);
result.print("\033[7m<%02x>\033[27m", c & 0xff);
else
result.append(c);
}
@ -316,7 +358,7 @@ dump() const
c = buffer[i];
if (offs && i == offs) result.append("\033[0m");
if (c < 0x20 || c >= 0x7f)
result.print("\033[1m<%02x>\033[22m", c & 0xff);
result.print("\033[7m<%02x>\033[27m", c & 0xff);
else
result.append(c);
if (i == offs+len-1) result.append("\033[47m");

View File

@ -73,7 +73,7 @@ public:
{init(NULL, size);}
~StreamBuffer()
{if (buffer != local) delete buffer;}
{if (buffer != local) delete [] buffer;}
// operator (): get char* pointing to index
const char* operator()(ssize_t index=0) const
@ -199,11 +199,10 @@ public:
// find: get index of data in buffer or -1
ssize_t find(char c, ssize_t start=0) const
{char* p;
{if (start < 0 && (start -= len) < 0) start = 0;
char* p;
return (p = static_cast<char*>(
memchr(buffer+offs+(start<0?start+len:start),
c, start<0?-start:len-start)))?
p-(buffer+offs) : -1;}
memchr(buffer+offs+start, c, len-start)))? p-(buffer+offs) : -1;}
ssize_t find(const void* s, size_t size, ssize_t start=0) const;

View File

@ -118,7 +118,7 @@ writeRequest(const void*, size_t, unsigned long)
}
bool StreamBusInterface::
readRequest(unsigned long, unsigned long, size_t, bool)
readRequest(unsigned long, unsigned long, ssize_t, bool)
{
return false;
}

View File

@ -76,7 +76,7 @@ public:
return businterface && businterface->writeRequest(output, size, timeout_ms);
}
bool busReadRequest(unsigned long replytimeout_ms,
unsigned long readtimeout_ms, size_t expectedLength,
unsigned long readtimeout_ms, ssize_t expectedLength,
bool async) {
return businterface && businterface->readRequest(replytimeout_ms,
readtimeout_ms, expectedLength, async);
@ -133,7 +133,7 @@ protected:
virtual bool writeRequest(const void* output, size_t size,
unsigned long timeout_ms);
virtual bool readRequest(unsigned long replytimeout_ms,
unsigned long readtimeout_ms, size_t expectedLength,
unsigned long readtimeout_ms, ssize_t expectedLength,
bool async);
virtual bool supportsEvent(); // defaults to false
virtual bool supportsAsyncRead(); // defaults to false

View File

@ -25,12 +25,10 @@
#define Z PRINTF_SIZE_T_PREFIX
ENUM (Commands,
end, in, out, wait, event, exec, connect, disconnect);
/// debug functions /////////////////////////////////////////////
static char* printCommands(StreamBuffer& buffer, const char* c)
char* StreamCore::
printCommands(StreamBuffer& buffer, const char* c)
{
unsigned long timeout;
unsigned long eventnumber;
@ -191,14 +189,26 @@ parse(const char* filename, const char* _protocolname)
ssize_t i = protocolname.find('(');
if (i >= 0)
{
while (i >= 0)
while (i < (ssize_t)protocolname.length())
{
if (protocolname[i-1] == ' ')
protocolname.remove(--i, 1); // remove trailing space
protocolname[i] = '\0'; // replace '(' and ',' with '\0'
protocolname[i] = '\0'; // replace initial '(' and separating ',' with '\0'
if (protocolname[i+1] == ' ')
protocolname.remove(i+1, 1); // remove leading space
i = protocolname.find(',', i+1);
int brackets = 0;
do {
i++;
i += strcspn(protocolname(i), ",()\\");
char c = protocolname[i];
if (c == '(') brackets++;
else if (c == ')') brackets--;
else if (c == ',' && brackets <= 0) break;
else if (c == '\\') {
if (protocolname[i+1] == '\\') i++; // keep '\\'
else protocolname.remove(i, 1); // else skip over next char
}
} while (i < (ssize_t)protocolname.length());
}
// should have closing parentheses
if (protocolname[-1] != ')')
@ -208,9 +218,8 @@ parse(const char* filename, const char* _protocolname)
}
protocolname.truncate(-1); // remove ')'
if (protocolname[-1] == ' ')
{
protocolname.truncate(-1); // remove trailing space
}
debug("StreamCore::parse \"%s\" -> \"%s\"\n", _protocolname, protocolname.expand()());
}
StreamProtocolParser::Protocol* protocol;
protocol = StreamProtocolParser::getProtocol(filename, protocolname);
@ -449,10 +458,10 @@ finishProtocol(ProtocolResult status)
debug("StreamCore::finishProtocol(%s, %s) %sbus owner\n",
name(), toStr(status), flags & BusOwner ? "" : "not ");
if (flags & BusPending)
if (status == Success && flags & BusPending)
{
error("StreamCore::finishProtocol(%s): Still waiting for %s%s%s\n",
name(),
error("StreamCore::finishProtocol(%s, %s): Still waiting for %s%s%s\n",
name(), toStr(status),
flags & LockPending ? "lockSuccess() " : "",
flags & WritePending ? "writeSuccess() " : "",
flags & WaitPending ? "timerCallback()" : "");
@ -903,11 +912,10 @@ evalIn()
debug("StreamCore::evalIn(%s): early input: %s\n",
name(), inputBuffer.expand()());
expectedInput = readCallback(lastInputStatus, NULL, 0);
if (!expectedInput)
{
// no more input needed
if (expectedInput == 0)
return true;
}
if (expectedInput == -1) // don't know how much
expectedInput = 0;
}
if (flags & AsyncMode)
{
@ -919,14 +927,12 @@ evalIn()
busUnlock();
flags &= ~BusOwner;
}
busReadRequest(pollPeriod, readTimeout,
return busReadRequest(pollPeriod, readTimeout,
expectedInput, true);
return true;
}
busReadRequest(replyTimeout, readTimeout,
return busReadRequest(replyTimeout, readTimeout,
expectedInput, false);
// continue with readCallback() in another thread
return true;
}
ssize_t StreamCore::
@ -980,8 +986,8 @@ readCallback(StreamIoStatus status,
evalIn();
return 0;
}
debug("StreamCore::readCallback(%s): No reply from device within %ld ms\n",
name(), replyTimeout);
error("%s: No reply within %ld ms to \"%s\"\n",
name(), replyTimeout, outputLine.expand()());
inputBuffer.clear();
finishProtocol(ReplyTimeout);
return 0;
@ -1082,7 +1088,7 @@ readCallback(StreamIoStatus status,
if (maxInput)
return maxInput - inputBuffer.length();
else
return -1;
return -1; // We don't know for how much to wait
}
// try to parse what we got
end = inputBuffer.length();
@ -1315,12 +1321,12 @@ normal_format:
break;
}
case StreamProtocolParser::skip:
// ignore next input byte
consumedInput++;
// ignore next input byte (if exists)
if (consumedInput < inputLine.length()) consumedInput++;
break;
case StreamProtocolParser::whitespace:
// any number of whitespace (including 0)
while (isspace(inputLine[consumedInput])) consumedInput++;
while (consumedInput < inputLine.length() && isspace(inputLine[consumedInput])) consumedInput++;
break;
case esc:
// escaped literal byte

View File

@ -107,6 +107,9 @@ protected:
ENUM(StartMode,
StartNormal, StartInit, StartAsync);
ENUM (Commands,
end, in, out, wait, event, exec, connect, disconnect);
class MutexLock
{
StreamCore* stream;
@ -221,6 +224,9 @@ public:
void printProtocol(FILE* = stdout);
const char* name() { return streamname; }
void printStatus(StreamBuffer& buffer);
private:
char* printCommands(StreamBuffer& buffer, const char* c);
};
#endif

View File

@ -29,6 +29,9 @@
#ifdef EPICS_3_13
extern "C" {
static char* epicsStrDup(const char *s) { char* c = (char*)malloc(strlen(s)+1); strcpy(c, s); return c; }
#endif
#define epicsAlarmGLOBAL
@ -63,8 +66,8 @@ extern DBBASE *pdbbase;
#include "epicsThread.h"
#include "epicsString.h"
#include "registryFunction.h"
#include "epicsStdioRedirect.h"
#include "iocsh.h"
#include "epicsExport.h"
#if defined(VERSION_INT) || EPICS_MODIFICATION >= 11
#include "initHooks.h"
@ -161,10 +164,7 @@ class Stream : protected StreamCore
Stream(dbCommon* record, const struct link *ioLink,
streamIoFunction readData, streamIoFunction writeData);
~Stream();
long parseLink(const struct link *ioLink, char* filename, char* protocol,
char* busname, int* addr, char* busparam);
long initRecord(const char* filename, const char* protocol,
const char* busname, int addr, const char* busparam);
long initRecord(char* linkstring);
bool print(format_t *format, va_list ap);
ssize_t scan(format_t *format, void* pvalue, size_t maxStringSize);
bool process();
@ -534,12 +534,7 @@ long streamInitRecord(dbCommon* record, const struct link *ioLink,
streamIoFunction readData, streamIoFunction writeData)
{
long status;
char filename[80];
char protocol[80];
char busname[80];
int addr = -1;
char busparam[80];
memset(busparam, 0 ,sizeof(busparam));
char* linkstring;
debug("streamInitRecord(%s): SEVR=%d\n", record->name, record->sevr);
Stream* stream = static_cast<Stream*>(record->dpvt);
@ -556,19 +551,30 @@ long streamInitRecord(dbCommon* record, const struct link *ioLink,
record->name);
stream->finishProtocol(Stream::Abort);
}
// scan the i/o link
debug("streamInitRecord(%s): parse link \"%s\"\n",
record->name, ioLink->value.instio.string);
status = stream->parseLink(ioLink, filename, protocol,
busname, &addr, busparam);
// (re)initialize bus and protocol
if (status == 0)
if (ioLink->type != INST_IO)
{
error("%s: Wrong I/O link type %s\n", record->name,
pamaplinkType[ioLink->type].strvalue);
return S_dev_badInitRet;
}
if (!ioLink->value.instio.string[0])
{
error("%s: Empty I/O link. "
"Forgot the leading '@' or confused INP with OUT or link is too long ?\n",
record->name);
return S_dev_badInitRet;
}
// (re)initialize bus and protocol
linkstring = epicsStrDup(ioLink->value.instio.string);
if (!linkstring)
{
error("%s: Out of memory", record->name);
return S_dev_noMemory;
}
debug("streamInitRecord(%s): calling initRecord\n",
record->name);
status = stream->initRecord(filename, protocol,
busname, addr, busparam);
}
status = stream->initRecord(linkstring);
free(linkstring);
if (status != OK && status != DO_NOT_CONVERT)
{
error("%s: Record initialization failed\n", record->name);
@ -587,7 +593,6 @@ long streamReadWrite(dbCommon *record)
if (!stream || stream->status == ERROR)
{
(void) recGblSetSevr(record, UDF_ALARM, INVALID_ALARM);
error("%s: Record not initialised correctly\n", record->name);
return ERROR;
}
return stream->process() ? stream->convert : ERROR;
@ -699,78 +704,77 @@ Stream::
}
long Stream::
parseLink(const struct link *ioLink, char* filename,
char* protocol, char* busname, int* addr, char* busparam)
initRecord(char* linkstring /* modifiable copy */)
{
// parse link parameters: filename protocol busname addr busparam
int n1, n2;
if (ioLink->type != INST_IO)
{
error("%s: Wrong I/O link type %s\n", name(),
pamaplinkType[ioLink->type].strvalue);
return S_dev_badInitRet;
}
if (0 >= sscanf(ioLink->value.instio.string, "%s%n", filename, &n1))
{
error("%s: Empty I/O link. "
"Forgot the leading '@' or confused INP with OUT or link is too long ?\n",
name());
return S_dev_badInitRet;
}
if (0 >= sscanf(ioLink->value.instio.string+n1, " %[^ \t(] %n", protocol, &n2))
{
error("%s: Missing protocol name\n"
" expect \"@file protocol[(args)] bus [addr] [params]\"\n"
" in \"@%s\"\n", name(),
ioLink->value.instio.string);
return S_dev_badInitRet;
}
n1+=n2;
if (ioLink->value.instio.string[n1] == '(')
{
strcat(protocol, "(");
n1++;
sscanf(ioLink->value.instio.string+n1, " %[^)] %n", protocol+strlen(protocol), &n2);
n1+=n2;
if (ioLink->value.instio.string[n1++] != ')')
{
error("%s: Missing ')' after protocol '%s': '%s'\n"
" expect \"@file protocol(args) bus [addr] [params]\"\n"
" in \"@%s\"\n", name(), protocol, ioLink->value.instio.string+n1-1,
ioLink->value.instio.string);
return S_dev_badInitRet;
}
strcat(protocol, ")");
}
if (0 >= sscanf(ioLink->value.instio.string+n1, "%s %i %99c", busname, addr, busparam))
{
error("%s: Missing bus name\n"
" expect \"@file protocol[(args)] bus [addr] [params]\"\n"
" in \"@%s\"\n", name(),
ioLink->value.instio.string);
return S_dev_badInitRet;
}
return OK;
}
char *filename;
char *protocol;
char *busname;
char *busparam;
long addr = -1;
long Stream::
initRecord(const char* filename, const char* protocol,
const char* busname, int addr, const char* busparam)
debug("Stream::initRecord %s: parse link string \"%s\"\n", name(), linkstring);
while (isspace(*linkstring)) linkstring++;
filename = linkstring;
while (*linkstring && !isspace(*linkstring)) linkstring++;
if (*linkstring) *linkstring++ = 0;
while (isspace(*linkstring)) linkstring++;
protocol = linkstring;
while (*linkstring && !isspace(*linkstring) && *linkstring != '(') linkstring++;
while (isspace(*linkstring)) linkstring++;
if (*linkstring == '(') {
int brackets = 0;
while(*++linkstring) {
if (*linkstring == '(') brackets++;
else if (*linkstring == ')') brackets--;
else if (*linkstring == '\\' && !*++linkstring) break;
else if (isspace(*linkstring) && brackets < 0) break;
}
}
else if (*linkstring) linkstring--;
if (*linkstring) *linkstring++ = 0;
while (isspace(*linkstring)) linkstring++;
busname = linkstring;
while (*linkstring && !isspace(*linkstring)) linkstring++;
if (*linkstring) *linkstring++ = 0;
if (linkstring) addr = strtol(linkstring, &linkstring, 0);
while (isspace(*linkstring)) linkstring++;
busparam = linkstring;
debug("Stream::initRecord %s: filename=\"%s\" protocol=\"%s\" bus=\"%s\" addr=%ld params=\"%s\"\n",
name(), filename, protocol, busname, addr, busparam);
if (!*filename)
{
// It is safe to call this function again with different arguments
error("%s: Missing protocol file name\n", name());
return S_dev_badInitRet;
}
if (!*protocol)
{
error("%s: Missing protocol name\n", name());
return S_dev_badInitRet;
}
if (!*busname)
{
error("%s: Missing bus name\n", name());
return S_dev_badInitRet;
}
// attach to bus interface
debug("Stream::initRecord %s: attachBus(%s, %d, \"%s\")\n",
debug("Stream::initRecord %s: attachBus(\"%s\", %ld, \"%s\")\n",
name(), busname, addr, busparam);
if (!attachBus(busname, addr, busparam))
{
error("%s: Can't attach to bus %s %d\n",
error("%s: Can't attach to bus %s %ld\n",
name(), busname, addr);
return S_dev_noDevice;
}
// parse protocol file
debug("Stream::initRecord %s: parse(%s, %s)\n",
debug("Stream::initRecord %s: parse(\"%s\", \"%s\")\n",
name(), filename, protocol);
if (!parse(filename, protocol))
{
@ -832,7 +836,7 @@ initRecord(const char* filename, const char* protocol,
return ERROR;
}
debug("Stream::initRecord %s: initialized. %s\n",
name(), convert==2 ?
name(), convert == DO_NOT_CONVERT ?
"convert" : "don't convert");
return convert;
}
@ -844,6 +848,7 @@ process()
debug("Stream::process(%s)\n", name());
if (record->pact || record->scan == SCAN_IO_EVENT)
{
record->proc = 0;
if (status != NO_ALARM)
{
debug("Stream::process(%s) error status=%s (%d)\n",
@ -855,7 +860,7 @@ process()
return false;
}
debug("Stream::process(%s) ready. %s\n",
name(), convert==2 ?
name(), convert == DO_NOT_CONVERT ?
"convert" : "don't convert");
return true;
}
@ -871,9 +876,13 @@ process()
convert = OK;
if (!startProtocol(record->proc == 2 ? StreamCore::StartInit : StreamCore::StartNormal))
{
debug("Stream::process(%s): could not start %sprotocol, status=%d\n",
name(), record->proc==2 ? "@init " : "", status);
debug("Stream::process(%s): could not start %sprotocol, status=%s (%d)\n",
name(), record->proc == 2 ? "@init " : "",
status >= 0 && status < ALARM_NSTATUS ?
epicsAlarmConditionStrings[status] : "ERROR",
status);
(void) recGblSetSevr(record, status ? status : UDF_ALARM, INVALID_ALARM);
record->proc = 0;
return false;
}
debug("Stream::process(%s): protocol started\n", name());
@ -1084,7 +1093,7 @@ getFieldAddress(const char* fieldname, StreamBuffer& address)
// FIELD in this record or VAL in other record
StreamBuffer fullname;
fullname.print("%s.%s", name(), fieldname);
if (dbNameToAddr(fullname(), &dbaddr) != OK)
if (dbNameToAddr(fullname(), &dbaddr) != OK || strcmp(((dbFldDes*)dbaddr.pfldDes)->name, fieldname) != 0)
{
// VAL in other record
fullname.clear().print("%s.VAL", fieldname);
@ -1096,7 +1105,7 @@ getFieldAddress(const char* fieldname, StreamBuffer& address)
}
static const unsigned char dbfMapping[] =
#ifdef DBF_INT64
#ifdef DBR_INT64
{0, DBF_UINT64, DBF_INT64, DBF_ENUM, DBF_DOUBLE, DBF_STRING};
#else
{0, DBF_ULONG, DBF_LONG, DBF_ENUM, DBF_DOUBLE, DBF_STRING};

View File

@ -18,18 +18,16 @@
***************************************************************/
#include "StreamError.h"
#ifdef _WIN32
#include <windows.h>
#endif
#include <string.h>
#include <time.h>
#include <stdio.h>
int streamDebug = 0;
int streamError = 0;
extern "C" {
#ifdef _WIN32
__declspec(dllexport)
#endif
int streamError = 1;
FILE *StreamDebugFile = NULL;
}
#ifndef va_copy
#ifdef __va_copy
@ -39,6 +37,23 @@ FILE *StreamDebugFile = NULL;
#ifdef _WIN32
#define localtime_r(timet,tm) localtime_s(tm,timet)
/* this may not be defined if using older Windows SDKs */
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
/* Enable ANSI colors in Windows console */
static int win_console_init() {
DWORD dwMode = 0;
HANDLE hCons = GetStdHandle(STD_ERROR_HANDLE);
GetConsoleMode(hCons, &dwMode);
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(hCons, dwMode);
return 0;
}
static int s = win_console_init();
#endif
/* You can globally change the printTimestamp function
@ -75,7 +90,7 @@ void StreamError(int line, const char* file, const char* fmt, ...)
void StreamVError(int line, const char* file, const char* fmt, va_list args)
{
char timestamp[40];
if (!streamError) return; // Error logging disabled
if (!(streamError || streamDebug)) return; // Error logging disabled
StreamPrintTimestampFunction(timestamp, 40);
#ifdef va_copy
if (StreamDebugFile)
@ -115,4 +130,3 @@ print(const char* fmt, ...)
va_end(args);
return 1;
}

View File

@ -1124,6 +1124,13 @@ compileString(StreamBuffer& buffer, const char*& source,
continue;
}
if (c == '%') {
if (buffer[formatpos+1] == '%') {
// treat %% as literal % like printf/scanf do
// replace with escaped %
buffer[formatpos] = esc;
formatpos+=2;
continue;
}
debug("StreamProtocolParser::Protocol::compileString "
"format=\"%s\"\n", buffer.expand(formatpos)());
nformats++;

View File

@ -26,13 +26,8 @@
#include <string.h>
#include <sys/types.h>
#if defined(__cplusplus)
extern "C" {
#endif
#define STREAM_MAJOR 2
#define STREAM_MINOR 8
#define STREAM_PATCHLEVEL 0
#ifndef OK
#define OK 0
@ -45,14 +40,19 @@ extern "C" {
#define DO_NOT_CONVERT 2
#define INIT_RUN (!interruptAccept)
#include "epicsVersion.h"
#ifdef BASE_VERSION
#define EPICS_3_13
#endif
#ifdef epicsExportSharedSymbols
# define devStream_epicsExportSharedSymbols
# undef epicsExportSharedSymbols
# include "shareLib.h"
#endif
#include "epicsVersion.h"
#ifdef BASE_VERSION
#define EPICS_3_13
/* EPICS 3.13 include files are not C++ ready. */
#ifdef __cplusplus
extern "C" {
#endif
#endif
#include "dbCommon.h"
@ -65,11 +65,21 @@ extern "C" {
#include "dbEvent.h"
#include "epicsMath.h"
#ifdef devStream_epicsExportSharedSymbols
# define epicsExportSharedSymbols
#ifdef EPICS_3_13
#ifdef __cplusplus
}
#endif
#else
#include "epicsStdioRedirect.h"
#endif
#if defined(_WIN32)
#ifdef devStream_epicsExportSharedSymbols
# undef devStream_epicsExportSharedSymbols
# define epicsExportSharedSymbols
# include "shareLib.h"
#endif
#ifdef _WIN32
typedef ptrdiff_t ssize_t;
#endif
@ -78,11 +88,16 @@ typedef const struct format_s {
const struct StreamFormat* priv;
} format_t;
epicsShareExtern FILE* StreamDebugFile;
extern const char StreamVersion [];
extern FILE* StreamDebugFile;
typedef long (*streamIoFunction) (dbCommon*, format_t*);
#ifdef __cplusplus
extern "C" {
#endif
extern const char StreamVersion [];
long streamInit(int after);
long streamInitRecord(dbCommon *record,
const struct link *ioLink,
@ -95,6 +110,10 @@ long streamPrintf(dbCommon *record, format_t *format, ...);
ssize_t streamScanfN(dbCommon *record, format_t *format,
void*, size_t maxStringSize);
#ifdef __cplusplus
}
#endif
/* backward compatibility stuff */
#define streamScanf(record, format, value) \
streamScanfN(record, format, value, MAX_STRING_SIZE)
@ -108,8 +127,4 @@ ssize_t streamScanfN(dbCommon *record, format_t *format,
#include "epicsExport.h"
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -69,7 +69,7 @@ static long readData(dbCommon *record, format_t *format)
case DBF_FLOAT:
((epicsFloat32 *)aai->bptr)[aai->nord] = (epicsFloat32)lval;
break;
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
case DBF_UINT64:
((epicsInt64 *)aai->bptr)[aai->nord] = (epicsInt64)lval;
@ -116,17 +116,11 @@ static long readData(dbCommon *record, format_t *format)
if ((length = streamScanfN(record, format,
(char *)aai->bptr, aai->nelm)) == ERROR)
{
memset(aai->bptr, 0, aai->nelm);
return ERROR;
}
if (lval < (ssize_t)aai->nelm)
if (length < (ssize_t)aai->nelm)
{
memset(((char*)aai->bptr)+lval , 0, aai->nelm-lval);
lval++;
}
else
{
((char*)aai->bptr)[aai->nelm-1] = 0;
((char*)aai->bptr)[length] = 0;
}
aai->nord = (long)length;
return OK;
@ -173,7 +167,7 @@ static long writeData(dbCommon *record, format_t *format)
case DBF_FLOAT:
dval = ((epicsFloat32 *)aai->bptr)[nowd];
break;
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
dval = ((epicsInt64 *)aai->bptr)[nowd];
break;
@ -216,12 +210,12 @@ static long writeData(dbCommon *record, format_t *format)
{
switch (aai->ftvl)
{
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
lval = ((epicsInt64 *)aao->bptr)[nowd];
lval = ((epicsInt64 *)aai->bptr)[nowd];
break;
case DBF_UINT64:
lval = ((epicsUInt64 *)aao->bptr)[nowd];
lval = ((epicsUInt64 *)aai->bptr)[nowd];
break;
#endif
case DBF_LONG:

View File

@ -68,7 +68,7 @@ static long readData(dbCommon *record, format_t *format)
case DBF_FLOAT:
((epicsFloat32 *)aao->bptr)[aao->nord] = (epicsFloat32)lval;
break;
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
case DBF_UINT64:
((epicsInt64 *)aao->bptr)[aao->nord] = (epicsInt64)lval;
@ -113,17 +113,11 @@ static long readData(dbCommon *record, format_t *format)
if ((length = streamScanfN(record, format,
(char *)aao->bptr, aao->nelm)) == ERROR)
{
memset(aao->bptr, 0, aao->nelm);
return ERROR;
}
if (length < (ssize_t)aao->nelm)
{
memset(((char*)aao->bptr)+lval , 0, aao->nelm-lval);
lval++;
}
else
{
((char*)aao->bptr)[aao->nelm-1] = 0;
((char*)aao->bptr)[length] = 0;
}
aao->nord = (long)length;
goto end_no_check;
@ -202,7 +196,7 @@ static long writeData(dbCommon *record, format_t *format)
case DBF_FLOAT:
dval = ((epicsFloat32 *)aao->bptr)[nowd];
break;
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
dval = ((epicsInt64 *)aao->bptr)[nowd];
break;
@ -245,7 +239,7 @@ static long writeData(dbCommon *record, format_t *format)
{
switch (aao->ftvl)
{
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
lval = ((epicsInt64 *)aao->bptr)[nowd];
break;

View File

@ -23,31 +23,28 @@
static long readData(dbCommon *record, format_t *format)
{
lsiRecord *lsi = (lsiRecord *)record;
ssize_t length;
if (format->type == DBF_STRING)
if (format->type != DBF_STRING) return ERROR;
if ((length = streamScanfN(record, format, lsi->val, (long)lsi->sizv)) == ERROR)
{
long len;
if ((len = streamScanfN(record, format, lsi->val, lsi->sizv) == ERROR))
{
lsi->len = 0;
return ERROR;
}
lsi->len = len;
if (length < (ssize_t)lsi->sizv)
{
lsi->val[length] = 0;
}
lsi->len = length;
return OK;
}
return ERROR;
}
static long writeData(dbCommon *record, format_t *format)
{
lsiRecord *lsi = (lsiRecord *)record;
if (format->type == DBF_STRING)
{
if (format->type != DBF_STRING) return ERROR;
return streamPrintf(record, format, lsi->val);
}
return ERROR;
}
static long initRecord(dbCommon *record)
{

View File

@ -24,17 +24,19 @@
static long readData(dbCommon *record, format_t *format)
{
lsoRecord *lso = (lsoRecord *)record;
long len;
ssize_t length;
unsigned short monitor_mask;
if (format->type != DBF_STRING)
return ERROR;
if ((len = streamScanfN(record, format, lso->val, lso->sizv) == ERROR))
if (format->type != DBF_STRING) return ERROR;
if ((length = streamScanfN(record, format, lso->val, lso->sizv)) == ERROR)
{
lso->len = 0;
return ERROR;
}
lso->len = len;
if (length < (ssize_t)lso->sizv)
{
lso->val[length] = 0;
}
lso->len = length;
if (record->pact) return OK;
/* In @init handler, no processing, enforce monitor updates. */
monitor_mask = recGblResetAlarms(record);
@ -60,12 +62,9 @@ static long writeData(dbCommon *record, format_t *format)
{
lsoRecord *lso = (lsoRecord *)record;
if (format->type == DBF_STRING)
{
if (format->type != DBF_STRING) return ERROR;
return streamPrintf(record, format, lso->val);
}
return ERROR;
}
static long initRecord(dbCommon *record)
{

View File

@ -33,11 +33,12 @@ static long readData(dbCommon *record, format_t *format)
{
case DBF_ULONG:
case DBF_LONG:
case DBF_ENUM:
{
if (streamScanf(record, format, &val) == ERROR) return ERROR;
if (mbbo->mask) val &= mbbo->mask;
mbbo->rbv = val;
mbbo->rval = val;
if (mbbo->mask) val &= mbbo->mask;
if (mbbo->shft > 0) val >>= mbbo->shft;
/* read VAL or RBV? Look if any value is defined */
if (mbbo->sdef)
@ -56,17 +57,12 @@ static long readData(dbCommon *record, format_t *format)
mbbo->val = (epicsEnum16)val;
break;
}
case DBF_ENUM:
{
if (streamScanf(record, format, &val) == ERROR) return ERROR;
mbbo->val = (epicsEnum16)val;
break;
}
case DBF_STRING:
{
char buffer[sizeof(mbbo->zrst)];
if (streamScanfN(record, format, buffer, sizeof(buffer)) == ERROR)
return ERROR;
mbbo->val = 65535; /* initalize to unknown state*/
for (val = 0; val < 16; val++)
{
if (strcmp ((&mbbo->zrst)[val], buffer) == 0)
@ -75,6 +71,7 @@ static long readData(dbCommon *record, format_t *format)
break;
}
}
break;
}
default:
return ERROR;
@ -82,6 +79,15 @@ static long readData(dbCommon *record, format_t *format)
if (record->pact) return DO_NOT_CONVERT;
/* In @init handler, no processing, enforce monitor updates. */
monitor_mask = recGblResetAlarms(record);
if (mbbo->val > 15) {
recGblSetSevr(record, STATE_ALARM, mbbo->unsv);
} else {
recGblSetSevr(record, STATE_ALARM, (&(mbbo->zrsv))[mbbo->val]);
}
mbbo->lalm = mbbo->val;
if (mbbo->val != mbbo->lalm) {
if (!recGblSetSevr(record, COS_ALARM, mbbo->cosv)) mbbo->lalm = mbbo->val;
}
if (mbbo->mlst != mbbo->val)
{
monitor_mask |= (DBE_VALUE | DBE_LOG);
@ -110,39 +116,38 @@ static long writeData(dbCommon *record, format_t *format)
switch (format->type)
{
case DBF_ULONG:
case DBF_ENUM:
/* print VAL or RVAL ? */
val = mbbo->val;
if (mbbo->shft > 0) val <<= mbbo->shft;
if (mbbo->sdef) for (i=0; i<16; i++)
{
if ((&mbbo->zrvl)[i])
{
/* any values defined ? */
val = mbbo->rval;
if (mbbo->mask) val &= mbbo->mask;
break;
}
}
if (mbbo->mask) val &= mbbo->mask;
return streamPrintf(record, format, val);
case DBF_LONG:
{
/* print VAL or RVAL ? */
val = (epicsInt16)mbbo->val;
if (mbbo->shft > 0) val <<= mbbo->shft;
if (mbbo->sdef) for (i=0; i<16; i++)
{
if ((&mbbo->zrvl)[i])
{
/* any values defined ? */
val = (epicsInt32)mbbo->rval;
if (mbbo->mask) val &= mbbo->mask;
break;
}
}
if (mbbo->mask) val &= mbbo->mask;
return streamPrintf(record, format, val);
}
case DBF_ENUM:
{
return streamPrintf(record, format, mbbo->val);
}
case DBF_STRING:
{
if (mbbo->val >= 16) return ERROR;

View File

@ -42,7 +42,7 @@ static long readData(dbCommon *record, format_t *format)
return OK;
}
case DBF_LONG:
case DBF_UONG:
case DBF_ULONG:
case DBF_ENUM:
{
long lval;
@ -72,7 +72,7 @@ static long writeData(dbCommon *record, format_t *format)
return streamPrintf(record, format, sco->oval);
}
case DBF_LONG:
case DBF_UONG:
case DBF_ULONG:
case DBF_ENUM:
{
return streamPrintf(record, format, (long)sco->oval);

View File

@ -70,10 +70,10 @@ static long readData(dbCommon *record, format_t *format)
case DBF_FLOAT:
((epicsFloat32 *)wf->bptr)[wf->nord] = (epicsFloat32)lval;
break;
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
case DBF_UINT64:
((epicsInt64 *)wf->bptr)[aao->nord] = (epicsInt64)lval;
((epicsInt64 *)wf->bptr)[wf->nord] = (epicsInt64)lval;
break;
#endif
case DBF_LONG:
@ -117,17 +117,11 @@ static long readData(dbCommon *record, format_t *format)
if ((length = streamScanfN(record, format,
(char *)wf->bptr, wf->nelm)) == ERROR)
{
memset(wf->bptr, 0, wf->nelm);
return ERROR;
}
if (length < (ssize_t)wf->nelm)
{
memset(((char*)wf->bptr)+lval , 0, wf->nelm-lval);
lval++;
}
else
{
((char*)wf->bptr)[wf->nelm-1] = 0;
((char*)wf->bptr)[length] = 0;
}
wf->nord = (long)length;
return OK;
@ -174,7 +168,7 @@ static long writeData(dbCommon *record, format_t *format)
case DBF_FLOAT:
dval = ((epicsFloat32 *)wf->bptr)[nowd];
break;
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
dval = ((epicsInt64 *)wf->bptr)[nowd];
break;
@ -217,7 +211,7 @@ static long writeData(dbCommon *record, format_t *format)
{
switch (wf->ftvl)
{
#ifdef DBF_INT64
#ifdef DBR_INT64
case DBF_INT64:
lval = ((epicsInt64 *)wf->bptr)[nowd];
break;

View File

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

1
streamApp/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
streamAppInclude.dbd

View File

@ -40,8 +40,9 @@ ifneq ($(words $(CALC) $(SYNAPPS)), 0)
# With synApps scalcout record
streamApp_DBD += calcSupport.dbd
PROD_LIBS += calc
# older calc versions require sscan
#PROD_LIBS += sscan
ifneq ($(words $(SSCAN) $(SYNAPPS)), 0)
PROD_LIBS += sscan
endif
endif
streamApp_DBD += stream.dbd

View File

@ -7,19 +7,27 @@ include $(TOP)/config/CONFIG_APP
LIBNAME = streamApp
DBD += base-3-13.dbd
DBD += stream.dbd
LDLIBS += $(TOP)/bin/$(T_A)/streamLib
ifdef ASYN
LDLIBS += $(ASYN)/bin/$(T_A)/asynLib
DBD += asyn.dbd
endif
ifdef COMPAT
LDLIBS += $(COMPAT)/bin/$(T_A)/compatLib
endif
include ../base-3-13LIBOBJS
streamApp_DBD += base-3-13.dbd
streamApp_DBD += stream.dbd
DBDNAME = streamApp.dbd
DBDEXPAND = streamAppInclude-3-13.dbd
DBDEXPAND = streamAppInclude.dbd
# Write StreamDevice debug output to this file
#CPPFLAGS += -DDEBUGFILE=StreamDebug.log
$(DBDNAME): ../$(DBDEXPAND)
.PHONY:: ../$(DBDEXPAND)
../$(DBDEXPAND):
echo -e '$(DBD:%=include "%"\n)' > $@
include $(EPICS_BASE)/config/RULES.Vx
include ../../config/RULES.munch

View File

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

View File

@ -62,14 +62,17 @@ proc startioc {} {
puts $fd "streamApp_registerRecordDeviceDriver"
}
puts $fd "streamSetLogfile StreamDebug.log"
puts $fd "var streamDebug 1"
puts $fd "var streamError 1"
puts $fd "epicsEnvSet STREAM_PROTOCOL_PATH ."
puts $fd "drvAsynIPPortConfigure device localhost:$port"
puts $fd "dbLoadRecords test.db"
if [info exists startup] {
puts $fd $startup
}
puts $fd "dbLoadRecords test.db"
puts $fd "iocInit"
puts $fd "dbl"
puts $fd "dbior stream 2"
puts $fd "var streamDebug 1"
close $fd
if [info exists streamversion] {
set ioc [open "|iocsh test.cmd >& $testname.ioclog 2>@stderr" w]

View File

@ -54,8 +54,6 @@ set debug 0
startioc
# Some formats give different results on 32 bit and 64 bit machines.
# This occurs when printing negative numbers with unsigned formats.
# This is normal. E.g. -1 HAS a different number of 1 bits.
# Specify the width field in the format if this is a problem.
put DZ:percent 1
@ -75,17 +73,9 @@ assure "12345 12345 012345 3039 003039 11000000111001 11000000111001 111001 !!..
put DZ:lo 2147483647
assure "2147483647 2147483647 2147483647 7fffffff FFFFFF 1111111111111111111111111111111 1111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
put DZ:lo -1
if {$tcl_platform(machine) == "x86_64"} {
assure "-1 -1 -00001 ffffffffffffffff FFFFFF 1111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
} else {
assure "-1 -1 -00001 ffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
}
put DZ:lo -1234
if {$tcl_platform(machine) == "x86_64"} {
assure "-1234 -1234 -01234 fffffffffffffb2e FFFB2E 1111111111111111111111111111111111111111111111111111101100101110 1111111111111111111111111111111111111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
} else {
assure "-1234 -1234 -01234 fffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
}
put DZ:lo 255
assure "255 255 000255 ff 0000FF 11111111 11111111 111111 !!!!!!!! !!!!!!!!\n"
put DZ:lo 65535

View File

@ -0,0 +1,61 @@
#!/usr/bin/env tclsh
source streamtestlib.tcl
# Define records, protocol and startup (text goes to files)
# The asynPort "device" is connected to a network TCP socket
# Talk to the socket with send/receive/assure
# Send commands to the ioc shell with ioccmd
set records {
record(ao, "DZ:test1")
{
field (DTYP, "stream")
field (OUT, "@test.proto test1(ARG(10),20,30) device")
}
record(ao, "DZ:test2")
{
field (DTYP, "stream")
field (OUT, "@test.proto test1 (ARG(10,20), 30) device")
}
record(ao, "DZ:test3")
{
field (DTYP, "stream")
field (OUT, "@test.proto test1 ( ARG ( 10 , 20 ) , 30 ) device")
}
record(ao, "DZ:test4")
{
field (DTYP, "stream")
field (OUT, "@test.proto test1( ARG \\( 10 , 20 , 30 ) device")
}
record(ao, "DZ:test5")
{
field (DTYP, "stream")
field (OUT, "@test.proto test1(\\ ARG\\,\\\\(10,20)\\,30) device")
}
}
set protocol {
Terminator = LF;
test1 { out "VAL:\$1:%d"}
}
set startup {
}
set debug 0
startioc
put DZ:test1 "1"
assure "VAL:ARG(10):1\n"
put DZ:test2 "1"
assure "VAL:ARG(10,20):1\n"
put DZ:test3 "1"
assure "VAL:ARG ( 10 , 20 ):1\n"
put DZ:test4 "1"
assure "VAL: ARG ( 10 :1\n"
put DZ:test5 "1"
assure "VAL: ARG,\\(10,20),30:1\n"
#finish

View File

@ -16,7 +16,7 @@ set records {
set protocol {
Terminator = LF;
test1 {out "\%\e%d\e\e\%";}
test1 {out "\%\e%d%%\e\e\%";}
}
set startup {
@ -28,6 +28,6 @@ set debug 0
startioc
put DZ:test1 1
assure "%\0331\033\033%\n"
assure "%\0331%\033\033%\n"
finish

View File

@ -63,7 +63,7 @@ fi
for o in $O
do
g++ -I ../../src $o test.cc -o test.exe
test.exe
./test.exe
if [ $? != 0 ]
then
echo -e "\033[31;7mTest failed.\033[0m"