Compare commits

...

38 Commits

Author SHA1 Message Date
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
28 changed files with 333 additions and 163 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)

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

@ -14,37 +14,18 @@ TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
# define INSTALL_LOCATION_APP here
#INSTALL_LOCATION_APP=<fullpathname>
# For SynApps:
RELEASE=
SUPPORT=$(TOP)/..
-include $(TOP)/../configure/SUPPORT.$(EPICS_HOST_ARCH)
EPICS_BASE=/usr/local/epics/base-7.0.1
ASYN=~/top-7/asyn4-33
CALC=~/top-7/SynApps/calc-2-8
PCRE=~/top-7/pcre-7-2
ASYN=$(SUPPORT)/asyn4-36
CALC=$(SUPPORT)/calc-3-7
PCRE=$(SUPPORT)/pcre-7-2
#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
# 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.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=/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, size_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);
size_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);
size_t&nbsp;expectedLength, bool&nbsp;async);
</code></div>
<div class="indent"><code>
ssize_t readCallback(IoStatus&nbsp;status,

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

@ -99,9 +99,9 @@ IOC Application Developer's Guide:
<a href="https://epics.anl.gov/base/R3-14/12-docs/AppDevGuide/"
target="ex">R3.14.12</a>,
<a href="https://epics.anl.gov/base/R3-15/6-docs/AppDevGuide/AppDevGuide.html"
target="ex">R3.15.5</a>,
<a href="https://epics.anl.gov/base/R3-16/1-docs/AppDevGuide/AppDevGuide.html"
target="ex">R3.16.1</a>
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

@ -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

@ -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>

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>.

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

@ -21,6 +21,14 @@
#include "StreamError.h"
#include "StreamBuffer.h"
#include "asynDriver.h"
#include "asynOctet.h"
#include "asynInt32.h"
#include "asynUInt32Digital.h"
#include "asynGpibDriver.h"
#include "devStream.h"
#ifdef EPICS_3_13
#include <assert.h>
#include <wdLib.h>
@ -32,17 +40,9 @@ extern "C" {
#include "epicsAssert.h"
#include "epicsTime.h"
#include "epicsTimer.h"
#include "epicsStdioRedirect.h"
#include "iocsh.h"
#endif
#include "asynDriver.h"
#include "asynOctet.h"
#include "asynInt32.h"
#include "asynUInt32Digital.h"
#include "asynGpibDriver.h"
#include "devStream.h"
#include "MacroMagic.h"
#define Z PRINTF_SIZE_T_PREFIX
@ -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

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>

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
@ -84,7 +88,27 @@ streamReferences: ../CONFIG_STREAM
$(PERL) ../makeref.pl Interface $(BUSSES) > $@
$(PERL) ../makeref.pl Converter $(FORMATS) >> $@
# create stream.dbd from all RECORDTYPES
# 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) > $@

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,54 +198,94 @@ 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];
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++)
debug("sub%d = \"%s\"\n", r, buffer.expand(start+c+ovector[r*2], ovector[r*2+1]-ovector[r*2])());
debug("after = \"%s\"\n", buffer.expand(start+c+ovector[1])());
s = subst;
debug("subs = \"%s\"\n", s.expand()());
for (r = 0; r < (int)s.length(); r++)
// 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)
{
debug("check \"%s\"\n", s.expand(r)());
if (s[r] == esc)
// 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++)
debug("sub%d = \"%s\"\n", r, buffer.expand(start+c+ovector[r*2], ovector[r*2+1]-ovector[r*2])());
debug("after = \"%s\"\n", buffer.expand(start+c+ovector[1])());
s = subst;
debug("subs = \"%s\"\n", s.expand()());
for (r = 0; r < (int)s.length(); r++)
{
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
debug("check \"%s\"\n", s.expand(r)());
if (s[r] == esc)
{
ch *= 2;
rl = ovector[ch+1] - ovector[ch];
debug("yes, replace \\%d: \"%s\"\n", ch/2, buffer.expand(start+c+ovector[ch], rl)());
s.replace(r, 2, buffer(start+c+ovector[ch]), rl);
r += rl - 1;
unsigned char ch = s[r+1];
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)());
s.replace(r, 2, buffer(start+c+ovector[ch]), rl);
r += rl - 1;
}
else
{
debug("use literal \\%u\n", ch);
s.remove(r, 1); // just remove escape
}
}
else
else if (s[r] == '&') // unescaped & : replace with match
{
debug("no, use literal \\%u\n", ch);
s.remove(r, 1); // just remove escape
debug("replace &: \"%s\"\n", buffer.expand(start+c+ovector[0], l)());
s.replace(r, 1, buffer(start+c+ovector[0]), l);
r += l - 1;
}
else continue;
debug("subs = \"%s\"\n", s.expand()());
}
else if (s[r] == '&') // unescaped & : replace with match
{
debug("replace &: \"%s\"\n", buffer.expand(start+c+ovector[0], l)());
s.replace(r, 1, buffer(start+c+ovector[0]), l);
r += l - 1;
}
else continue;
debug("subs = \"%s\"\n", s.expand()());
buffer.replace(start+c+ovector[0], l, s);
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.
}
buffer.replace(start+c+ovector[0], l, s);
length += s.length() - l;
c += ovector[0] + s.length();
if (n == fmt.prec) // max match reached
{
debug("pcre_exec: max match %d reached\n", n);

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;
@ -449,10 +447,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 +901,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 +916,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::
@ -1082,7 +1077,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();

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

@ -63,8 +63,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"

View File

@ -26,7 +26,7 @@
#include <stdio.h>
int streamDebug = 0;
int streamError = 0;
int streamError = 1;
extern "C" {
#ifdef _WIN32
__declspec(dllexport)
@ -43,6 +43,11 @@ 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;
@ -90,7 +95,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)

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,10 +26,6 @@
#include <string.h>
#include <sys/types.h>
#if defined(__cplusplus)
extern "C" {
#endif
#define STREAM_MAJOR 2
#define STREAM_MINOR 8
@ -47,11 +43,16 @@ extern "C" {
#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
#ifdef epicsExportSharedSymbols
# define devStream_epicsExportSharedSymbols
# undef epicsExportSharedSymbols
# include <shareLib.h>
#endif
#include "dbCommon.h"
@ -65,10 +66,20 @@ extern "C" {
#include "epicsMath.h"
#ifdef devStream_epicsExportSharedSymbols
# undef devStream_epicsExportSharedSymbols
# define epicsExportSharedSymbols
# include <shareLib.h>
#endif
#if defined(_WIN32)
#ifdef EPICS_3_13
#ifdef __cplusplus
}
#endif
#else
#include "epicsStdioRedirect.h"
#endif
#ifdef _WIN32
typedef ptrdiff_t ssize_t;
#endif
@ -82,6 +93,10 @@ extern const char StreamVersion [];
typedef long (*streamIoFunction) (dbCommon*, format_t*);
#ifdef __cplusplus
extern "C" {
#endif
long streamInit(int after);
long streamInitRecord(dbCommon *record,
const struct link *ioLink,
@ -94,6 +109,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)
@ -107,8 +126,4 @@ ssize_t streamScanfN(dbCommon *record, format_t *format,
#include "epicsExport.h"
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,3 +1,6 @@
if (@ARGV[0] eq "--rec-only") {
shift;
} else {
if (@ARGV[0] eq "--with-asyn") {
shift;
$asyn = 1;
@ -11,6 +14,7 @@ if (@ARGV[0] eq "-3.13") {
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"