Compare commits

..

315 Commits

Author SHA1 Message Date
b0c8a14071 start Version 2.8 2018-05-23 11:05:27 +02:00
4feb14ea35 Merge branch 'master' into 2-8 2017-11-03 15:29:45 +01:00
2830f07324 update version number 2017-11-03 13:46:08 +01:00
abd8daafc3 escape all non-ascii chars to avoid problems with UTF terminals 2017-11-03 13:41:38 +01:00
489e783872 Don't change EOS if not necessary. And some improved diagnostics 2017-11-03 13:40:47 +01:00
10d1fa8b02 do not run exceprion handlers from @init 2017-11-02 09:18:24 +01:00
c8bffebfc6 fix version number 2017-11-02 09:17:47 +01:00
97f6beb3ae add rule to install PDF 2017-08-16 10:52:48 +02:00
b80261ba16 source code repo ignore generated pdf file 2017-06-14 17:10:15 +02:00
6a114b2c2c check if wkhtmltopdf is installed, else print message 2017-06-14 17:07:38 +02:00
bf29238762 fix page break in <pre> boxes 2017-06-14 17:07:03 +02:00
13d1fb2ca0 fix formatting problem 2017-06-14 17:06:38 +02:00
cc1ab5685c update documentation 2017-03-21 15:03:13 +01:00
370b3cd8c4 Merge branch 'master' of /tmp/StreamDevice 2017-01-30 16:47:53 +01:00
3a034f843d add examples for 3.14.8 and 3.13.10 to RELEASE 2017-01-30 16:43:27 +01:00
2de8e916b2 add standalone stuff for 3.13 build 2017-01-30 16:41:03 +01:00
6044edfdd9 Merge branch 'master' of github.com:paulscherrerinstitute/StreamDevice 2017-01-30 12:03:24 +01:00
836388cd22 Merge pull request #4 from hhslepicka/write_mbbo_fix
Removing conflict at write in devmmboDirectStream.c
2017-01-30 12:01:47 +01:00
2685a43760 Format %0s pads with null bytes instead of spaces 2017-01-30 11:58:04 +01:00
0eed3ee9c7 for 3.13 compatibility don't use epicsVsnprintf 2017-01-30 11:55:13 +01:00
c5e3e89e44 remove compiler warning 2017-01-30 11:54:43 +01:00
1f27983505 Removing conflict at write in devmmboDirectStream.c 2017-01-27 12:07:19 -08:00
146a8c895f old compilers complain about comma at end of enum list 2017-01-25 17:17:42 +01:00
efd5a0cbcd some compatibility work 2017-01-25 16:40:58 +01:00
2968231b60 renamed doc to documentation so that make distclean does not delete it 2017-01-25 16:13:18 +01:00
ea2238aa53 fix for previous change 2017-01-25 15:57:24 +01:00
d22e1a5f4a make compatible to 3.14.8- and remove duplicate code 2017-01-25 15:28:46 +01:00
31189ebecf move scalcout to src 2017-01-25 15:02:24 +01:00
d42e5a7a9e fixes for 3.13 2017-01-25 14:58:35 +01:00
e13aa2a96f add external modules 2017-01-25 14:42:35 +01:00
ae021ffeab update .gitignore with generated directories 2017-01-25 13:59:12 +01:00
5a9d89822f change macroname to simplify PSI GNUmakefile 2017-01-25 12:04:40 +01:00
054b0c0e3f remove compiler warning 2017-01-25 11:37:41 +01:00
ac07ac3dcf fix standard EPICS build system 2017-01-25 11:37:15 +01:00
0195386606 add format error checking to exec command 2017-01-25 10:35:58 +01:00
0026959b1e fix waveform records printing unsigned integer formats like %c 2017-01-25 10:35:17 +01:00
450e88d9a9 typo in docu fixed 2017-01-24 09:24:59 +01:00
a4888634b6 make compatible to standard EPICS build system 2017-01-19 16:55:28 +01:00
46a68831c2 get isnan and isinf for old 3.13 (vxWorks only) as well as for 3.14+ EPICS 2017-01-19 16:52:02 +01:00
537d573983 Windows does not like macros after strings without space 2017-01-19 16:43:43 +01:00
96450e7010 Merge branch 'master' of github.com:paulscherrerinstitute/StreamDevice 2017-01-19 09:49:49 +01:00
31e1243eed Merge pull request #2 from MarkRivers/master
Fixes to build on Visual Studio 2010
2017-01-19 09:44:40 +01:00
0a90eb3d9c fix ai/ao conversion when using LINR=NO CONVERSION together with ASLO or AOFF 2017-01-18 16:03:02 +01:00
65f46aec36 New file to ignore generated files 2017-01-13 11:12:37 -06:00
37d14caa5b Use epicsMath.h to define isnan and isinf if needed; would not compile on Visual Studio 2010 2017-01-13 11:11:58 -06:00
384474f6fd Merge pull request #1 from mesamike/patch-1
Add missing include in StreamBuffer.h
2016-11-22 09:20:49 +01:00
17d8592574 Update StreamBuffer.h 2016-11-17 14:24:08 -03:00
0936ac7840 version update 2016-08-05 12:04:07 +02:00
704ece6231 Disable error messages by default in order to prevent filling the log. Set variable streamDebug to 1 to enable error messages. 2016-08-05 12:03:50 +02:00
5c6e98127e typo fixed 2016-08-05 12:01:52 +02:00
8805437c68 remove unneeded file 2016-08-02 11:18:15 +02:00
3acf791409 make docu for %r converer more specific about %.2r versus %2r 2016-07-01 10:56:46 +02:00
0ba674a341 workaround for mbboDirect bug 2016-07-01 10:38:38 +02:00
40c33abac7 workaround for mbboDirect bug 2016-07-01 10:18:34 +02:00
bc67317b0b change the meaning of pre for regsub slightly 2016-06-15 14:52:45 +02:00
06e212c66e version macros updated 2016-06-14 12:06:30 +02:00
7b314ccffd bugfix in regsub 2016-06-14 12:00:02 +02:00
1d84986ee8 do not fill log files with lock errors 2016-06-14 11:43:30 +02:00
2ca8a129f7 regsub converter added 2016-06-14 11:36:36 +02:00
126da8c499 "No reply from device" error message removed because it only fills the log files 2016-06-08 15:15:12 +02:00
ea110d5047 improved error message 2016-04-28 11:58:23 +02:00
b37fad41c6 use local variable for fieldBuffer because on some arch (Moxa ARM5) 64 bit (double) values are corrupted otherwise 2016-04-07 11:05:51 +02:00
74775996db find clean way to create dbd file 2015-12-07 17:22:40 +01:00
74426aab66 provide local strncasecmp for 3.13 2015-12-07 17:21:44 +01:00
690bbb13d4 version macros updated 2015-12-07 15:15:06 +01:00
871fbed2b0 checksums updated 2015-10-19 13:58:06 +02:00
85c68d2ae6 uppercase 2015-10-19 13:58:06 +02:00
8870611d4d modbus checksum added 2015-10-19 13:58:06 +02:00
67af7fc1bf links updated 2015-10-19 13:58:06 +02:00
93bea174e4 highlinting of new featured removed 2015-10-19 13:58:06 +02:00
84fc6aabc8 fixed witdth flag ! added 2015-10-19 13:58:06 +02:00
38c4f5bcb6 renamed to make Windows happy 2015-09-17 14:13:01 +02:00
e2af7e3149 typo fixed 2015-09-15 07:21:41 +00:00
950d75ba43 Split long_format into signed_format and unsigned_format to hangle sign extension from EPICS LONG or ULONG to long or unsigned long correctly on systems with 64 bit long. 2015-08-31 15:25:23 +00:00
e651c99697 fix tests 2015-08-18 14:34:11 +00:00
9694628d3f limit number of significant half bytes in %x formats to avoid problems on 64 bit machines 2015-08-18 14:33:48 +00:00
046582d1a0 add default choice in enum output 2015-08-18 14:32:24 +00:00
f6f0ea9ae5 fix redirection of strings to char arrays 2015-08-18 14:30:54 +00:00
018547cdf3 allow and document direct conversion from VAL/OVAL to integer to get more bits on 64 bit systems 2015-08-18 14:28:26 +00:00
d763a64f03 fix for 64 bit machines 2015-08-17 13:34:00 +00:00
cefa460a0d find correct object code 2015-08-17 13:33:35 +00:00
cc5948ad0b If ai uses no conversion, transport long i/o to and from val directly. This preverves more bits on 64 bit systems than going through the 32 bit rval field. 2015-07-17 13:24:37 +00:00
be1943a66d fix for version check 2015-06-25 16:06:39 +00:00
d9acb47afe make it work with old and new version of driver.makefile 2015-06-25 16:03:49 +00:00
b721d26fb8 avoid buffer overflow 2015-04-08 09:35:00 +00:00
7530c7c67d check for error condifiton 2015-04-08 09:34:46 +00:00
824cd4d283 debug message improved 2015-04-02 13:16:22 +00:00
2e30e7aee6 fix message when INP/OUT link is empty
fix bug with formatting arrays of char as strings in redirect
2015-04-02 13:15:46 +00:00
3a5a3e22b9 Stupid error: Minutes and seconds start from 0, not 1. 2015-02-10 16:48:39 +00:00
51bd766ba6 Fix or rather workaround for MinGW and maybe other systems without localtime_r function 2014-06-24 13:20:19 +00:00
0ab0d6db07 function pointer type problem fixed 2014-06-24 13:19:36 +00:00
a12de614d6 script to make a pdf from the hrml pages 2014-05-02 15:10:18 +00:00
240abd2788 new logo and design cleanup, printing improved 2014-05-02 15:09:49 +00:00
e131fcb32f new logo, png instead of gif, better quality 2014-05-02 15:08:36 +00:00
f88f594e87 shorter header, better for printing 2014-05-02 15:07:06 +00:00
56ef0651f2 fix for BSD Linux 2014-04-07 11:55:36 +00:00
9b9726b800 patchlevel fixed 2013-11-06 13:29:42 +00:00
b139221f0b error messages improved 2013-11-06 10:22:51 +00:00
b0ab8a7a8b write error message on write timeout 2013-11-06 09:52:39 +00:00
ddac589676 newline in report output fixed 2013-11-06 09:44:18 +00:00
5b380cdaad No connection checking before locking device. Multi-devices (GPIB) behave strangely. Get an error when device is disconnected. 2013-11-05 14:48:53 +00:00
cc9adc77fa patchlevel updated 2013-10-23 14:38:28 +00:00
2b38f7bcfa . 2013-10-23 14:36:35 +00:00
0ceada70b5 status information added 2013-10-23 14:35:08 +00:00
7bf91b403d status information added
error messages improved
dont mark device as BusOwner when locking fails
2013-10-23 14:34:53 +00:00
bf5c359649 status information added
use class for status strings to make array overrun impossible
2013-10-23 14:33:15 +00:00
c41ac44bd1 typo in comment 2013-10-23 14:31:35 +00:00
e36013d64e error messages improved
Do not queue lock request when not connected
Do not call lock callback when unlock fails
2013-10-23 14:31:00 +00:00
9e48ad3e61 typo 2013-10-02 13:09:17 +00:00
054e74d04a Do not connect unrequested.
Do not register for int/uint interrupts without need.
2013-09-20 12:06:56 +00:00
5f6319ed3d stay at version 2.6 2013-09-20 09:52:43 +00:00
2f39622a57 Error Message improved 2013-09-20 09:44:26 +00:00
7801119215 fix for cygwin 2013-06-13 15:21:12 +00:00
a6696cae49 fixes for windows 2013-06-13 15:13:53 +00:00
40b52167aa lock timeout error message added 2013-06-13 15:12:06 +00:00
814e3d53a3 version update 2013-05-16 08:49:30 +00:00
6bd46e0470 *** empty log message *** 2013-05-16 08:47:16 +00:00
d5cda13f6f version updated 2013-05-16 08:45:49 +00:00
bfc8e6a9cd Handle inverted and negative checksums generically.
Get rid of ulong and uchar typedefs. use unsigned int unstead of ulolg for return types.
2013-05-16 08:31:33 +00:00
73cba130c3 use ssize_t for signed index types. Win has no ssize_t, use ptrdiff_t instead.
use P instead of S as shortcut for PRINTF_SIZE_T_PREFIX because some OK already use S.
2013-05-16 08:28:34 +00:00
c09bc44aa4 use ssize_t for signed index types. Win has no ssize_t, use ptrdiff_t instead. 2013-05-16 08:27:24 +00:00
b907e3f469 changed shortcut for PRINTF_SIZE_T_PREFIX from S to P. Some OS use S already. 2013-05-16 08:26:01 +00:00
8c3bed09e4 more debug
init I/O Intr scanning only if init_record did not fail
2013-05-16 08:24:40 +00:00
4c99b82bb7 make name() public 2013-05-16 08:22:56 +00:00
a6d72761b9 more debug 2013-05-16 08:22:13 +00:00
6c504d30cf use size_t and ssize_t in streamBuffer 2013-04-26 12:21:51 +00:00
1c814a451b new format: %-<> prints "poor man's hex": 0x30 - 0x3f characters 2013-04-26 09:56:39 +00:00
daafc125c3 bug in debug output fixed 2013-04-26 09:56:04 +00:00
63f680bdc1 allow selecting asyn version 2013-04-24 14:27:39 +00:00
e88a327957 *** empty log message *** 2013-04-24 14:27:09 +00:00
223c71bc68 fix the fake flush: break early when no bytes are left 2013-04-24 14:25:52 +00:00
14a04fd200 handle errors in flushing read correctly 2013-04-15 07:03:49 +00:00
dc85511fe9 missing space ckeck in event command 2013-01-21 10:03:27 +00:00
d0b8d3f585 problems with 3.13 solved 2012-11-20 10:51:40 +00:00
97652917c9 Can't poll GPIB. 2012-11-08 09:27:21 +00:00
c171a62f93 Fixes for 3.15 2012-11-08 09:26:57 +00:00
c7c28e7fa2 compiler warning removed 2012-10-08 12:32:44 +00:00
79a17788f2 application developper's guide link updated 2012-09-13 13:00:06 +00:00
9f0a2d2fb6 record reference manual link updated 2012-09-13 12:23:10 +00:00
66f6ce9bd2 version release 2012-09-13 11:47:28 +00:00
e5dfe7b816 version update 2012-08-30 13:41:24 +00:00
6efb17be64 remove warning 2012-08-30 13:39:05 +00:00
0310b30446 Fixes for 3.15 2012-08-30 13:37:25 +00:00
863cdf3d7f avoid multiple inclusion of asyn.dbd 2012-08-22 12:33:20 +00:00
e51bb2555e Adjustments for 3.15: test for 3.13 instead of 3.14 2012-08-22 11:49:43 +00:00
9e0157d679 link pointer is const 2012-08-09 12:22:50 +00:00
3e91eb4fc1 Link parsing in a separate function 2012-08-09 12:22:32 +00:00
caf811c23a Improved debug message, more digits in debug timestamp. 2012-08-09 08:38:05 +00:00
de116c9e5a Dummy-read stale input instead of flushing it in order to make it available for I/O Intr records. 2012-08-09 08:37:08 +00:00
eef38b0557 check if businterface exists before calling its methods 2012-08-08 09:44:18 +00:00
0057899476 missing header 2012-08-07 14:19:51 +00:00
0148e6e27e version update 2012-08-07 14:17:46 +00:00
c6af859f9d no eol translation 2012-07-06 11:19:06 +00:00
01f0761ca8 Fixes for Windows: dll import and export 2012-07-02 16:25:55 +00:00
d7770846aa fixes for asyn 4.11+ (queueRequest fails on disconnected ports) 2012-06-19 13:45:38 +00:00
0e76ba6464 reading web pages 2012-05-16 15:53:06 +00:00
fcb44ec845 anchor for redirections 2012-05-16 15:52:43 +00:00
cec8195e5e always escape special chars and bytes 2012-05-16 14:24:21 +00:00
6c0eb32d75 Print helpful message when matching string is too long 2012-05-16 14:23:43 +00:00
9ae5f1d583 Use disconnect by server as a regular terminator (e.g. web pages) 2012-05-16 14:23:15 +00:00
3b60bb9420 put patchlevel into version string 2012-05-16 09:59:48 +00:00
db50c35ad6 get correct version of stream library 2012-05-15 15:52:29 +00:00
4f05d4e254 added constant "%" test 2012-05-15 15:51:47 +00:00
c5a17b217d high PRIO for command records 2012-05-15 15:50:59 +00:00
fdccb0c5a9 add "binary" command, update help, GUI with exit button. 2012-05-15 15:49:41 +00:00
ccbafef55a rework number parsing. make sure '%' in any numeric format gets escaped. 2012-05-15 15:37:21 +00:00
c594134317 more debug 2012-05-15 13:58:03 +00:00
11cfaf44ee use perl script instead of bash commands to create dbd file 2012-05-15 13:37:19 +00:00
a34678cbcc for 3.13 don't create variable and registrar entries 2012-05-15 13:36:14 +00:00
26fd99823c use a StreamBuffer to hold format string for later error and debug messages 2012-05-15 11:44:41 +00:00
42c305c79b Skip leading whitespaces only if neither 0 nor 1 are whitespaces. 2012-05-15 09:20:22 +00:00
9585506644 debug messages improved 2012-05-15 09:14:34 +00:00
4317ae0f75 forgot to update minot version 2012-03-21 08:45:31 +00:00
6e6c79f5ea implement decimal checksum output 2012-02-17 10:28:02 +00:00
8da0014091 need to rename StreamBuffer method printf to print because on cris architecture printf is a macro. 2012-01-04 15:49:53 +00:00
60d292b3ea calcout support was missing 2011-10-18 14:54:35 +00:00
5ce9b737cf remove compiler warning 2011-10-13 15:42:00 +00:00
7bcb494044 allow checksums in decimal ascii 2011-10-13 15:39:41 +00:00
13758eb08e bugfix: too high array index 2011-10-13 15:37:28 +00:00
b9c26cb6f8 problem with connection handling workaround 2011-09-22 10:01:25 +00:00
e3dd0a319a updates 2011-09-19 09:30:00 +00:00
80b7ceea2d make stream.dbd in O directories 2011-09-19 08:35:58 +00:00
eabcce156a not needed 2011-09-19 08:30:02 +00:00
615beb7d02 ignore stream.dbd 2011-09-19 08:10:56 +00:00
78e6c9355c use perl scripts to generate files 2011-09-19 08:06:54 +00:00
20129ea341 build autimatically 2011-09-16 15:30:57 +00:00
388f950559 put in aai and aao, they are now standard parts in 3.14.12 2011-09-16 15:25:07 +00:00
96c93714a4 Modifications for new versions of base, asyn, calc 2011-09-16 15:23:19 +00:00
252eb44959 use perl script instead of shell script to allow for windows 2011-09-16 15:22:06 +00:00
0442e2ae4f dependency stuff added for 3.14.12 2011-09-16 15:16:40 +00:00
31dae22428 fix for 64 bit machines 2011-09-14 09:08:17 +00:00
1d5c7adb61 typo 2011-09-14 08:38:47 +00:00
c138442a95 fixes for 64 bit machines 2011-09-14 08:33:08 +00:00
a672ab1234 Improve re-connection handling in unexpectedly disconnecting IP ports. 2011-09-13 15:58:00 +00:00
c550cc01be bugfix: this could hang up the record in PACT=1 state 2011-09-13 15:52:24 +00:00
7db71589d8 no portable way to test this 2011-09-13 14:00:37 +00:00
910cf77d97 unfortunately we have to link PCRE here because otherwise static builds fail 2011-09-12 09:54:29 +00:00
807fe825d6 exit command added 2011-09-12 09:52:48 +00:00
ff46c9a4a7 fixes for 64 bit machines 2011-09-12 08:55:23 +00:00
a42fbc9c6c use correct delete operator 2011-09-12 08:46:58 +00:00
74d950ab2d Workaround for strange bug on xscale_be 2011-08-30 11:44:27 +00:00
9049baf730 report protocol name with original case 2011-07-28 12:39:11 +00:00
050a165a82 bugfix: had stale fieldAddress under some circumstances 2011-07-28 12:08:39 +00:00
1428b85a34 must find a way to generate this 2011-07-20 08:33:19 +00:00
e4f8a6ed40 fix endless loop when port does not support EOS 2011-07-20 08:32:09 +00:00
5a5b42cb67 test reserve() 2011-07-20 08:31:10 +00:00
e62553eca6 input tests added 2011-07-20 08:30:38 +00:00
0846c1dd5b don't link to PCRE here, that has been done in stream library already. 2011-05-06 12:17:02 +00:00
774e88241a compatibility problem with shell on solaris 2011-05-06 12:15:45 +00:00
03a04a51b6 *** empty log message *** 2011-05-06 12:15:20 +00:00
103e74be03 compatibility problem with "inf" and "Inf" on different archs 2011-05-06 12:15:01 +00:00
129cc61759 compatibility problem with old tcl version on solaris 2011-05-06 12:14:23 +00:00
70073e1b69 test to check locking and priorities 2011-03-29 15:18:07 +00:00
c94c1a1e70 Fixes for windows
Don't have a bash here so use perl.
Need to give the full path for PCRE (strange)
2011-03-29 12:36:42 +00:00
07026b03ae port locking sometimes deadlocks when used together with syncronous software and sometimes crashes the timer queue 2011-03-29 12:34:50 +00:00
5a6d293a5f windows patch 2011-03-10 10:13:52 +00:00
d51d6648e0 avoid compiler warnings 2011-03-10 10:13:36 +00:00
f521da8606 explicit cast to avoid compiler warning 2011-03-10 10:12:53 +00:00
b64d486925 xmodem alias added 2011-03-07 14:42:12 +00:00
7f1f1c1e65 Bugfix: escaped % in format did not work 2011-02-24 16:12:43 +00:00
2dc0918926 Bugfix: allow out formats in exec 2011-02-24 16:12:08 +00:00
37d412108a Add dummy interface 2011-02-24 16:11:21 +00:00
f03af416eb *** empty log message *** 2011-02-24 16:10:11 +00:00
82066af0e0 non-asyn interface without I/O 2011-02-24 14:29:19 +00:00
9c18afb178 Buggy old Tornado compiler (cygnus-2.7.2). Comment out some debug messages. 2011-02-08 13:59:30 +00:00
04c6cb50d7 allow record name without .VAL in redirection 2011-02-04 15:31:40 +00:00
382784526c make markbit small enough to be inlined on solaris 2011-02-04 15:11:57 +00:00
a91496884c don't mention unused parameters to avoid compiler warning 2011-02-04 15:07:02 +00:00
7cdec03dcb memguard shell fuction removed from here (may go to a separate file) 2011-02-03 16:39:10 +00:00
3e5e4b8375 avoid strange gcc warning 2011-02-03 16:28:17 +00:00
f8b944f325 I/O Intr bugfix: lines where lost when not read in one chunk 2011-02-03 16:27:14 +00:00
c7e7878d9e no memguard 2010-12-09 15:41:35 +00:00
5717dd6345 add NP byte code as alias for FF 2010-12-09 11:03:23 +00:00
2fe3b5c68d Bugfix: Infinite recursion with multi-line input and I/O Intr records 2010-12-07 17:02:52 +00:00
db88081fd7 print single space for "arbitrary whitespace" and nothing for "skip" 2010-12-07 13:23:46 +00:00
1230c01646 use _ to match arbitrary whitespace 2010-12-07 12:49:48 +00:00
8142dd27eb New special char: "_" means arbitrary amount of whitespace 2010-12-07 10:13:21 +00:00
19279b208a Separator re-work did not work 2010-12-07 10:12:17 +00:00
9619c359c1 separator pre-parsing did not work as expected. Problems with whitespace separators. Back to old soluton 2010-12-07 10:07:58 +00:00
6b948abc2d Fix for RTEMS 2010-12-03 08:18:39 +00:00
2c7391602a Bugfixes: escaped quotes in strings and multi-line format strings 2010-12-02 16:04:15 +00:00
fd0fccda46 *** empty log message *** 2010-12-02 16:03:19 +00:00
1164413bd2 fixes for new TCL version 2010-11-29 15:54:38 +00:00
7e1e038ecd *** empty log message *** 2010-11-29 15:53:41 +00:00
2a8b0aed56 wrong sign in time zone calculation 2010-11-29 15:50:20 +00:00
c856dec6dd Space handling in separartors and literal input:
Any amount of whitespace matches space character in litrals and if space is first character of a separator.
2010-11-29 15:30:59 +00:00
53bb235ff1 several bugfixes: time zone, windows, shortcut formats 2010-11-29 15:28:24 +00:00
29ac760f0e sscanf removed from %c and %[] 2010-11-29 15:26:05 +00:00
7836af6423 obsolete separator function removed 2010-11-29 15:24:18 +00:00
1af9c6ea55 fixes for new asyn version 2010-11-29 15:22:50 +00:00
8c619d3350 *** empty log message *** 2010-11-29 15:21:34 +00:00
0155d5ab69 handle new asyn status codes for asyn 4.11 2010-11-05 12:31:30 +00:00
8252b629f5 diamond version of port locking because of probplems with tpmac driver 2010-10-27 11:38:25 +00:00
494661c0e7 sscanf removed from %s 2010-10-27 11:36:07 +00:00
5b652abd25 re-work separator parsing. Now first byte of separator is replaced with a 0x00 byte to allow e.g. simple %s parsing for an element (instead of e.g. %[^,] ) 2010-10-20 13:23:50 +00:00
a3e68d7f7d ugly goto removed 2010-10-20 13:21:28 +00:00
7cc19d2614 allow for negative length (meaning left of start) in expand 2010-10-20 13:21:05 +00:00
318d0e389b changed from scanf to strto* for parsing 2010-10-15 09:47:21 +00:00
8dbe3abcdb sscans removed from integer and double scanning because of bad performance 2010-10-15 09:46:30 +00:00
649d775cd3 Preset buffer size removed (It was not the performance killer)
Bugfix: InTerminator search: distinguisch between long input line and multi-line input
StreamBuffer::equals renamed to startswith
2010-10-14 12:18:48 +00:00
a941061a29 StreamBuffer::equals renamed to startswith 2010-10-14 12:16:27 +00:00
100b7d4543 bugfix: reserve returned wrong pointer
optimized implementation to append 1 char
operator += aliases for append with 1 argument
equals renamed to startswith
2010-10-14 12:15:44 +00:00
1eb8a25432 bugfix: local buffer was not set to 0 at initialization 2010-10-14 12:13:51 +00:00
9b6f8b3386 test empty string enum choice 2010-10-12 08:49:53 +00:00
cc1bb004f2 allow SLS style module loading 2010-10-12 08:49:17 +00:00
ab6a6b730d %f default precision changed to 6 because of limited precision of a double. 2010-10-12 08:47:08 +00:00
3d928c49a0 Performance bug fixed: search for terminator was O(n^2) 2010-10-12 08:33:35 +00:00
8fe70f2e39 errlog.h required for epics 3.14.11 2010-10-12 08:32:14 +00:00
862686aeef made grow() public to allow to set initial buffer size 2010-09-29 07:21:44 +00:00
2fa54cdfb1 Initial buffer size added 2010-09-29 07:21:14 +00:00
d987a9abb9 crc16 xmodem added 2010-09-22 12:05:26 +00:00
d37c142d36 copy from other repository 2010-09-02 14:52:17 +00:00
35768cbfbb latest features added and bugs fixed:
compare %=
timestamp converter %T
error and debug messages
2010-09-02 14:50:33 +00:00
5494aae1ba have both, makebaseapp Makefile and PSI makefile 2010-09-02 14:19:11 +00:00
18ba904d6c timestamp converter added 2010-09-02 13:20:04 +00:00
2cd969d643 allow assigned enums: %#{one=1|two|neg=-1} 2010-06-09 13:12:00 +00:00
0c9d4dc4c0 %m format renamed from Exponential to MantissaExponent 2010-06-09 08:11:05 +00:00
ef3b2ec9fd allow formats in exec 2010-06-09 08:10:33 +00:00
1fb402e838 Allow optional input %? format 2010-06-09 08:05:05 +00:00
eae987e7f1 Find byte order at run-time because there is no standard how to do this at compile-time. 2010-06-09 08:03:49 +00:00
93906dd022 Bugfix: prec too long had corrupted output 2010-06-09 08:02:22 +00:00
7e717c564d *** empty log message *** 2010-06-09 08:01:03 +00:00
14b60c210a renamed %m from Exponention to MantissaExponent 2010-06-09 08:00:08 +00:00
8dae0afa30 take care of early input (race condition device reply and start of in command) 2010-06-09 07:54:47 +00:00
95bf2c78c2 install headers to allow plugins (formats) in other projects 2010-06-09 07:44:51 +00:00
8c10e5395c Initial Import 2009-05-20 10:12:59 +00:00
69de0b9f31 bugfix: find() did not find 1 char strings 2008-09-16 07:29:26 +00:00
22ae510dca comments fixed 2008-09-16 07:28:47 +00:00
5fdf3912c8 avoid compiler warning on 64 bit machines 2008-09-16 07:27:27 +00:00
b50aec424f increase minor version number 2008-09-16 07:26:41 +00:00
4a1033b6dc allow for 64 bit machines 2008-09-16 07:26:02 +00:00
68e178d41b Use long constant 1L to allow for 64 bit machines 2008-09-16 07:25:03 +00:00
e83ceda41c get rid of writeRaw for asyn 4.10 2008-09-16 07:24:24 +00:00
b307adb005 on vxworks, return value of sscanf with %* formats is buggy 2008-08-11 08:55:42 +00:00
0a2a304a2b Build calcout only for 3.14 2008-08-07 14:44:18 +00:00
80477709aa do record processing in callback tread instead of port thread 2008-08-04 15:46:39 +00:00
706c59d069 error msg improved 2008-08-04 15:45:12 +00:00
6541c40818 result strings fixed 2008-08-04 15:44:46 +00:00
04f64c0f67 ShowAsyncErrors hack removed 2008-08-04 15:44:17 +00:00
af669103c2 RawFloat added 2008-08-04 15:43:44 +00:00
40d9641150 comment fixed 2008-07-15 08:59:55 +00:00
9cf2770440 raw float converter added 2008-07-11 14:55:10 +00:00
616bc9a410 When not connected, call lock request with priority asynQueuePiorityConnect to avoid deadlock. 2008-07-11 14:53:28 +00:00
53abbb750b raw float added 2008-07-11 14:50:07 +00:00
ec3cbbf559 allow append of n equal bytes 2008-07-11 14:49:23 +00:00
8a3cbc1c6a output format for exponential converter defined 2008-07-11 14:48:17 +00:00
8a4cda6647 fix debug output of format string 2008-07-11 14:46:08 +00:00
2d513b96d3 %m added 2008-02-22 09:13:11 +00:00
6a0d7b4492 comments fixed 2008-02-21 17:09:31 +00:00
755df7c3ee bugfix: 1st byte was lost
feature: little endian support
2008-02-21 17:07:26 +00:00
ddb602196a comment added 2008-02-21 16:18:30 +00:00
0a5f486a9b improved error message 2008-02-21 16:08:09 +00:00
574052dcb8 alignment bug (on machines where it matters) 2008-02-21 16:05:56 +00:00
eaba256c51 generate 3.14 dbd file 2008-01-16 10:28:09 +00:00
7eab96120f don't return DO_NOT_CONVERT (2) from initRecord 2008-01-15 15:05:55 +00:00
190 changed files with 12762 additions and 2367 deletions

7
.cvsignore Normal file
View File

@ -0,0 +1,7 @@
O.*
*~
bin
lib
dbd
include
*.pdf

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
O.*
*~
bin
lib
dbd
include
*.pdf

37
GNUmakefile Normal file
View File

@ -0,0 +1,37 @@
ifeq ($(wildcard /ioc/tools/driver.makefile),)
$(warning It seems you do not have the PSI build environment. Remove GNUmakefile.)
include Makefile
else
include /ioc/tools/driver.makefile
EXCLUDE_VERSIONS = 3.13.2
PROJECT=stream
BUILDCLASSES += Linux
DOCUDIR = documentation
PCRE=1
ASYN=1
-include src/CONFIG_STREAM
SOURCES += $(RECORDS:%=src/dev%Stream.c)
SOURCES += $(FORMATS:%=src/%Converter.cc)
SOURCES += $(BUSSES:%=src/%Interface.cc)
SOURCES += $(STREAM_SRCS:%=src/%)
HEADERS += devStream.h
HEADERS += StreamFormat.h
HEADERS += StreamFormatConverter.h
HEADERS += StreamBuffer.h
HEADERS += StreamError.h
StreamCore.o: streamReferences
streamReferences:
perl ../src/makeref.pl Interface $(BUSSES) > $@
perl ../src/makeref.pl Converter $(FORMATS) >> $@
export DBDFILES = streamSup.dbd
streamSup.dbd:
@echo Creating $@
perl ../src/makedbd.pl $(RECORDTYPES) > $@
endif

View File

@ -1,54 +1,29 @@
include /ioc/tools/driver.makefile TOP = ..
EXCLUDE_VERSIONS = 3.13.2
PROJECT=stream2
BUILDCLASSES += Linux
DOCUDIR = doc # Look if we have EPICS R3.13 or R3.14
ifneq ($(wildcard $(TOP)/configure),)
DBDS = stream.dbd # EPICS R3.14
DIRS = configure
BUSSES += AsynDriver include $(TOP)/configure/CONFIG
FORMATS += Enum else ifneq ($(wildcard $(TOP)/config),)
FORMATS += BCD # EPICS R3.13
FORMATS += Raw CONFIG = $(TOP)/config
FORMATS += Binary DIRS = config
FORMATS += Checksum include $(TOP)/config/CONFIG_APP
FORMATS += Regexp else
FORMATS += Exponential TOP = .
RECORDTYPES += aai aao DIRS = configure
RECORDTYPES += ao ai include $(TOP)/configure/CONFIG
RECORDTYPES += bo bi
RECORDTYPES += mbbo mbbi
RECORDTYPES += mbboDirect mbbiDirect
RECORDTYPES += longout longin
RECORDTYPES += stringout stringin
RECORDTYPES += waveform
RECORDTYPES += calcout
SOURCES += $(RECORDTYPES:%=src/dev%Stream.c)
SOURCES += $(FORMATS:%=src/%Converter.cc)
SOURCES += $(BUSSES:%=src/%Interface.cc)
SOURCES += $(wildcard src/Stream*.cc)
SOURCES += src/StreamVersion.c
ifeq (${EPICS_BASETYPE},3.13)
USR_INCLUDES += -include $(INSTALL_INCLUDE)/compat3_13.h
endif endif
StreamCore.o: streamReferences DIRS += src
src_DEPEND_DIRS = configure
DIRS += streamApp
streamApp_DEPEND_DIRS = src
streamReferences: include $(CONFIG)/RULES_TOP
@for i in $(BUSSES); \
do echo "extern void* ref_$${i}Interface;"; \
echo "void* p$$i = ref_$${i}Interface;"; \
done > $@
@for i in $(FORMATS); \
do echo "extern void* ref_$${i}Converter;"; \
echo "void* p$$i = ref_$${i}Converter;"; \
done >> $@
stream.dbd: documentation/stream.pdf: documentation/*.html documentation/*.css documentation/*.png
@for r in $(RECORDTYPES); \ cd documentation; makepdf
do echo "device($$r,INST_IO,dev$${r}Stream,\"stream\")"; \
done > $@ install: documentation/stream.pdf
@echo "driver(stream)" >> $@

3
config/CONFIG Normal file
View File

@ -0,0 +1,3 @@
#CONFIG
# Add any changes to make rules here
#CROSS_COMPILER_TARGET_ARCHS = mv167

20
config/CONFIG_APP Normal file
View File

@ -0,0 +1,20 @@
#CONFIG_APP
include $(TOP)/config/RELEASE
-include $(TOP)/config/RELEASE.$(HOST_ARCH)
include $(EPICS_BASE)/config/CONFIG
INSTALL_LOCATION = $(TOP)
ifdef INSTALL_LOCATION_APP
INSTALL_LOCATION = $(INSTALL_LOCATION_APP)
endif
ifdef T_A
-include $(TOP)/config/O.$(T_A)/CONFIG_APP_INCLUDE
endif
# Where to install databases
INSTALL_DB = $(INSTALL_LOCATION)/db
# dbst based database optimization (default: NO)
DB_OPT = NO
# May be overridden if not all databases should be installed
INSTALLDB = $(DB)
include $(TOP)/config/CONFIG

9
config/Makefile Normal file
View File

@ -0,0 +1,9 @@
#
# Makefile,v 1.1.2.1 1999/07/15 19:55:30 jba Exp
#
TOP=..
include $(TOP)/config/CONFIG_APP
include $(TOP)/config/RULES_ARCHS

21
config/Makefile.Host Normal file
View File

@ -0,0 +1,21 @@
#
# Makefile.Host,v 1.1.2.3 2001/09/14 19:39:14 anj Exp
#
TOP=../..
include $(TOP)/config/CONFIG_APP
TARGETS = checkRelease CONFIG_APP_INCLUDE
include $(TOP)/config/RULES.Host
inc:: $(TARGETS)
CONFIG_APP_INCLUDE: $(wildcard $(TOP)/config/RELEASE*) $(TOP)/config/CONFIG_APP
$(PERL) $(TOP)/config/convertRelease.pl $@
checkRelease:
$(PERL) $(TOP)/config/convertRelease.pl $@
.PHONY :: checkRelease

15
config/Makefile.Vx Normal file
View File

@ -0,0 +1,15 @@
#
# Makefile.Vx,v 1.1.2.3 2001/09/14 19:39:15 anj Exp
#
TOP=../..
include $(TOP)/config/CONFIG_APP
TARGETS = CONFIG_APP_INCLUDE
include $(TOP)/config/RULES.Vx
inc:: $(TARGETS)
CONFIG_APP_INCLUDE: $(wildcard $(TOP)/config/RELEASE*) $(TOP)/config/CONFIG_APP
$(PERL) $(TOP)/config/convertRelease.pl -h $(HOST_ARCH) $@

1
config/RELEASE Normal file
View File

@ -0,0 +1 @@
include $(TOP)/configure/RELEASE

203
config/RULES.Db Normal file
View File

@ -0,0 +1,203 @@
# RULES.Db,v 1.9.6.6 2003/03/25 23:13:22 jba Exp
#
# Rules for making things related to databases
#
MAKEBPT = $(EPICS_BASE_HOST_BIN)/makeBpt$(EXE)
DBLOADTEMPLATE = $(EPICS_BASE_HOST_BIN)/dbLoadTemplate$(EXE)
DBEXPAND = $(EPICS_BASE_HOST_BIN)/dbExpand$(EXE)
DBST = dbst
MAKEDBDEPENDS = $(PERL) $(TOP)/config/makeDbDepends.pl
REPLACEVAR = $(PERL) $(TOP)/config/replaceVAR.pl
ifndef WIN32
TOUCH = touch
else
TOUCH = $(PERL) $(TOP)/config/touch.pl
endif
#-----------------------------------------------------------------
# if we are not building base add base dbd dirs
ifneq ($(EPICS_BASE),$(TOP))
ifneq ($(EPICS_BASE),$(INSTALL_LOCATION))
EPICS_DBDFLAGS += -I $(EPICS_BASE)/dbd
endif
endif
#---------------------------------------------------------------
# ----------------------------------------------------
# create names (lists) for installed things
# ----------------------------------------------------
INSTALL_BPTS = $(BPTS:%= $(INSTALL_DBD)/%)
INSTALL_DBDS = $(DBDINSTALL:%= $(INSTALL_DBD)/%)
INSTALL_DBDNAME = $(DBDNAME:%= $(INSTALL_DBD)/%)
INSTALL_DATA = $(INSTALLDB:%=$(INSTALL_DB)/%)
INSTALL_TEMPLATES = $(filter %.template,$(INSTALL_DATA))
#---------------------------------------------------------------
# Main targets
all:: install
inc:: $(INSTALL_DBDS) $(INSTALL_BPTS) $(INSTALL_TEMPLATES)
rebuild:: clean install
install:: inc buildInstall
buildInstall:: build $(INSTALL_DATA)
depends::
clean::
@echo "Cleaning"
@$(RM) $(DB) $(DBDNAME) *.template *.substitutions *.db.raw \
*.db-stamp *.edf esiread.cnf
##################################################### "Foreign" templates
TEMPLATE_LINKS = $(filter-out $(notdir $(USES_TEMPLATE)), $(USES_TEMPLATE))
TEMPLATE_FILES = $(filter $(notdir $(USES_TEMPLATE)), $(USES_TEMPLATE))
DB_STAMP = $(patsubst %.db, %.db-stamp, $(DB))
DB_REALTARGET = $(patsubst %.db-stamp, %.db, $@)
ifneq '$(TEMPLATE_LINKS)' ''
build:: $(notdir $(TEMPLATE_LINKS))
endif
build:: $(INSTALL_DBDNAME) $(TEMPLATE_FILES) $(DB_STAMP)
$(notdir $(TEMPLATE_LINKS)): %.template:
ifndef WIN32
@$(RM) $(notdir $(TEMPLATE_LINKS))
ln -s $(TEMPLATE_LINKS) .
# Workaround for dbLoadTemplate bug: terminate here if link target doesn't exist
@cat $(TEMPLATE_LINKS) > /dev/null
else
@$(RM) $(notdir $(TEMPLATE_LINKS))
$(CP) $(TEMPLATE_LINKS) .
endif
##################################################### Inflated or plain databases
$(INSTALL_DB)/%.db: %.db-stamp
@echo "Installing database $@"
@$(INSTALL) -d -m 644 $(patsubst %.db-stamp, %.db, $<) $(@D)
# Must have DBDNAME defined to use dbst optimization
ifndef DBDNAME
DB_OPT = NO
endif
# dbst based database optimization
ifeq '$(DB_OPT)' 'YES'
.PRECIOUS: %.db.raw
%.db-stamp: %.db.raw $(INSTALL_DBD)/$(DBDNAME)
@echo "Optimizing database $@"
$(DBST) $(INSTALL_DBD)/$(DBDNAME) $< -d > $(DB_REALTARGET)
@$(TOUCH) $@
%.db-stamp: %.t.db.raw $(INSTALL_DBD)/$(DBDNAME)
@echo "Optimizing database $@"
$(DBST) $(INSTALL_DBD)/$(DBDNAME) $< -d > $(DB_REALTARGET)
@$(TOUCH) $@
else
# NO optimization => move it and keep a stamp
%.db-stamp: %.db.raw
@$(MV) $< $(DB_REALTARGET)
@$(TOUCH) $@
@$(TOUCH) $<
%.db-stamp: %.t.db.raw
@$(MV) $< $(DB_REALTARGET)
@$(TOUCH) $@
@$(TOUCH) $<
endif
%.t.db.raw: %.substitutions
@echo "Inflating database from $<"
@$(RM) $@
@$(DBLOADTEMPLATE) $< > $@
##################################################### CapFast filter
%.edf:: ../%.sch $(DEPSCHS)
@if [ ! -f cad.rc -a -r ../cad.rc ] ; then ln -s ../cad.rc ; fi
$(SCH2EDIF) $(SCH2EDIF_SYSFLAGS) $(SCH2EDIF_FLAGS) $<
##################################################### Substitution files
$(INSTALL_DB)/%.substitutions: %.substitutions
@echo "Installing $@"
@$(INSTALL) -d -m 644 $(@F) $(@D)
%.substitutions:: ../%.substitutions
@$(CP) $< $@
ifdef CREATESUBSTITUTIONS
%.substitutions:: $(word $(words $(CREATESUBSTITUTIONS)),$(CREATESUBSTITUTIONS))
@$(CREATESUBSTITUTIONS) $*
endif
# Better make it PRECIOUS (to get around make bug)
.PRECIOUS: %.substitutions
##################################################### Template databases
# Installed template files (dbLoadTemplate() on IOC side)
$(INSTALL_DB)/%.template: %.template
@echo "Installing $@"
@$(INSTALL) -d -m 644 $(@F) $(@D)
%.template:: ../%.template
@$(CP) $< $@
%.template: %.edf
$(E2DB) $(E2DB_SYSFLAGS) $(E2DB_FLAGS) -n $@.VAR $<
@$(REPLACEVAR) < $@.VAR > $@
@$(RM) $@.VAR
##################################################### Flat databases
%.db.raw:: ../%.db
$(CP) $< $@
%.db.raw: %.edf
$(E2DB) $(E2DB_SYSFLAGS) $(E2DB_FLAGS) -n $@.VAR $<
@$(REPLACEVAR) < $@.VAR > $@
@$(RM) $@.VAR
##################################################### DBD stuff
$(INSTALL_DBD)/%: %
@echo "Installing $@"
@$(INSTALL) -d -m 644 $< $(@D)
$(INSTALL_DBD)/%:: ../%
@echo "Installing $@"
@$(INSTALL) -d -m 644 $< $(@D)
bpt%.dbd: bpt%.data
$(RM) $@
$(MAKEBPT) $<
bpt%.dbd:: ../bpt%.data
$(RM) $@
$(MAKEBPT) $<
# Patch for old applications
ifdef USER_DBDFLAGS
DBDFLAGS = $(USER_DBDFLAGS)
endif
ifdef DBDEXPAND
$(DBDNAME): ../$(DBDEXPAND)
@echo "Expanding dbd"
@$(RM) $@
$(DBEXPAND) $(DBDFLAGS) $< > dbExpand.tmp
$(MV) dbExpand.tmp $@
endif
##################################################### Dependencies
DEPENDS: $(filter $(patsubst %.db, %.substitutions, $(DB)), $(wildcard *.substitutions))
@$(MAKEDBDEPENDS) $^
-include DEPENDS

3
config/RULES.Host Normal file
View File

@ -0,0 +1,3 @@
#RULES.Host
include $(EPICS_BASE)/config/RULES.Host

7
config/RULES.Vx Normal file
View File

@ -0,0 +1,7 @@
#RULES.Vx
include $(EPICS_BASE)/config/RULES.Vx
inc:: $(INSTALL_INCREC)
# Library should be rebuilt because LIBOBJS may have changed.
$(LIBNAME): ../Makefile.Vx

9
config/RULES.ioc Normal file
View File

@ -0,0 +1,9 @@
#RULES.ioc
include $(EPICS_BASE)/config/RULES_DIRS
buildInstall:: cdCommands
cdCommands: Makefile $(wildcard $(TOP)/config/RELEASE*)
@$(PERL) $(TOP)/config/convertRelease.pl -a $(ARCH) -h $(HOST_ARCH) $@
clean::
@$(RM) cdCommands

4
config/RULES.iocBoot Normal file
View File

@ -0,0 +1,4 @@
#RULES.iocBoot
DIRS += $(wildcard ioc*)
DIRS += $(wildcard as*)
include $(EPICS_BASE)/config/RULES_DIRS

14
config/RULES.munch Normal file
View File

@ -0,0 +1,14 @@
MUNCH = $(PERL) $(INSTALL_LOCATION)/bin/$(HOST_ARCH)/munch.pl
# The original 3.13.10 munching rule does not really work well
build:: $(LIBNAME).munch
buildInstall:: $(INSTALL_BIN)/$(LIBNAME).munch
%.munch: %
$(RM) $*_ctct.o $*_ctdt.c
$(NM) $< | $(MUNCH) > $*_ctdt.c
$(GCC) -traditional $(CFLAGS) -fdollars-in-identifiers -c $(SOURCE_FLAG) $*_ctdt.c
$(LINK.c) $@ $< $*_ctdt.o

2
config/RULES_ARCHS Normal file
View File

@ -0,0 +1,2 @@
#RULES_ARCHS
include $(EPICS_BASE)/config/RULES_ARCHS

2
config/RULES_DIRS Normal file
View File

@ -0,0 +1,2 @@
#RULES_DIRS
include $(EPICS_BASE)/config/RULES_DIRS

5
config/RULES_TOP Normal file
View File

@ -0,0 +1,5 @@
#RULES_TOP
include $(EPICS_BASE)/config/RULES_TOP
uninstall::
@$(RMDIR) $(INSTALL_DB)

186
config/convertRelease.pl Normal file
View File

@ -0,0 +1,186 @@
eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*-
if $running_under_some_shell; # convertRelease.pl
#
# convertRelease.pl,v 1.1.2.1 2001/09/14 19:39:15 anj Exp
#
# Parse config/RELEASE file(s) and generate a derived output file.
#
# This tool replaces makeConfigAppInclude.pl and makeIocCdCommands.pl
# and adds consistency checks for RELEASE files.
#
use Cwd;
use Getopt::Std;
$cwd = cwd();
$cwd =~ s/\/tmp_mnt//; # hack for sun4
$cwd =~ s/\\/\//g; # hack for win32
getopt "aht";
if ($opt_a) {
$arch = $opt_a;
} else { # Look for O.<arch> in current path
$_ = $cwd;
($arch) = /.*\/O.([\w-]+)$/;
}
$hostarch = $arch;
$hostarch = $opt_h if ($opt_h);
if ($opt_t) {
$top = $opt_t;
} else { # Find $top from current path
$top = $cwd;
$top =~ s/\/iocBoot.*//;
$top =~ s/\/config\/O\..*//;
}
unless (@ARGV == 1) {
print "Usage: convertRelease.pl [-a arch] [-h hostarch] [-t top] outfile\n";
print " where outfile is be one of:\n";
print "\tcheckRelease - checks consistency with support apps\n";
print "\tcdCommands - generate cd path strings for IOC use\n";
print "\tCONFIG_APP_INCLUDE - additional build variables\n";
exit 2;
}
$outfile = $ARGV[0];
# TOP refers to this application
%macros = (TOP => $top);
@apps = (TOP); # Provides the order of apps in RELEASE file
# Read the RELEASE file(s)
$relfile = "$top/config/RELEASE";
die "Can't find config/RELEASE file" unless (-r $relfile);
&readRelease($relfile, \%macros, \@apps);
if ($hostarch) {
$relfile .= ".$hostarch";
&readRelease($relfile, \%macros, \@apps) if (-r $relfile);
}
# This is a perl switch statement:
for ($outfile) {
/CONFIG_APP_INCLUDE/ and do { &configAppInclude; last; };
/cdCommands/ and do { &cdCommands; last; };
/checkRelease/ and do { &checkRelease; last; };
die "Output file type \'$outfile\' not supported";
}
sub readRelease {
my ($file, $Rmacros, $Rapps) = @_;
# $Rmacros is a reference to a hash, $Rapps a ref to an array
my ($pre, $macro, $post, $path);
local *IN;
open(IN, $file) or die "Can't open $file: $!\n";
while (<IN>) {
chomp;
s/\s*#.*$//; # Remove trailing comments
next if /^\s*$/; # Skip blank lines
# Expand all macros in the line:
while (($pre,$macro,$post) = /(.*)\$\((\w+)\)(.*)/, $macro ne "") {
$_ = $pre . $Rmacros->{$macro} . $post;
}
# Handle "<macro> = <path>"
($macro, $path) = /^\s*(\w+)\s*=\s*(.*)/;
if ($macro ne "") {
$Rmacros->{$macro} = $path;
push @$Rapps, $macro;
next;
}
# Handle "include <path>" syntax
($path) = /^\s*include\s+(.*)/;
&readRelease($path, $Rmacros, $Rapps) if (-r $path);
}
close IN;
}
sub configAppInclude {
@includes = grep !/^(TOP|TEMPLATE_TOP)$/, @apps;
unlink($outfile);
open(OUT,">$outfile") or die "$! creating $outfile";
print OUT "# Do not modify this file, changes made here will\n";
print OUT "# be lost when the application is next rebuilt.\n\n";
if ($arch) {
foreach $app (@includes) {
$path = $macros{$app};
next unless (-d "$path/bin/$arch");
print OUT "${app}_BIN = \$($app)/bin/$arch\n";
}
foreach $app (@includes) {
$path = $macros{$app};
next unless (-d "$path/lib/$arch");
print OUT "${app}_LIB = \$($app)/lib/$arch\n";
}
}
foreach $app (@includes) {
$path = $macros{$app};
next unless (-d "$path/include");
print OUT "EPICS_INCLUDES += -I\$($app)/include\n";
}
foreach $app (@includes) {
$path = $macros{$app};
next unless (-d "$path/dbd");
print OUT "EPICS_DBDFLAGS += -I \$($app)/dbd\n";
}
close OUT;
}
sub cdCommands {
die "Architecture not set (use -a option)" unless ($arch);
@includes = grep !/^TEMPLATE_TOP$/, @apps;
# if -t <top> was given, substitute it in the startup path
$startup = $cwd;
$startup =~ s/.*(\/iocBoot\/.*)/$top$1/ if ($opt_t);
unlink($outfile);
open(OUT,">$outfile") or die "$! creating $outfile";
print OUT "startup = \"$startup\"\n";
print OUT "appbin = \"$top/bin/$arch\"\n"; # compatibility with R3.13.1
foreach $app (@includes) {
$path = $macros{$app};
$lcapp = lc($app);
print OUT "$lcapp = \"$path\"\n" if (-d $path);
print OUT "${lcapp}bin = \"$path/bin/$arch\"\n" if (-d "$path/bin/$arch");
}
close OUT;
}
sub checkRelease {
$status = 0;
delete $macros{TOP};
delete $macros{TEMPLATE_TOP};
while (($app, $path) = each %macros) {
%check = (TOP => $path);
@order = ();
$relfile = "$path/config/RELEASE";
&readRelease($relfile, \%check, \@order) if (-r $relfile);
if ($hostarch) {
$relfile .= ".$hostarch";
&readRelease($relfile, \%check, \@order) if (-r $relfile);
}
delete $check{TOP};
while (($parent, $ppath) = each %check) {
if (exists $macros{$parent} && ($macros{$parent} ne $ppath)) {
print "\n" unless ($status);
print "Definition of $parent conflicts with $app support.\n";
print "In this application config/RELEASE defines\n";
print "\t$parent = $macros{$parent}\n";
print "but $app at $path has\n";
print "\t$parent = $ppath\n";
$status = 1;
}
}
}
print "\n" if ($status);
exit $status;
}

23
config/makeDbDepends.pl Normal file
View File

@ -0,0 +1,23 @@
eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*-
if $running_under_some_shell; # makeDbDepends.pl
# Called from within the object directory.
# Searches the .substitutions files (from the command line) for
# "file xxx {" entries to create a .DEPENDS file
open(OUT, ">.DEPENDS") or die "Cannot open .DEPENDS: $!";
foreach $file (@ARGV) {
open(IN, "<$file") or die "Cannot open $file: $!";
@substfile = <IN>;
close IN or die "Cannot close $file: $!";
@depends = grep { s/^\s*file\s*(.*)\s*\{.*$/\1/ } @substfile;
chomp @depends;
if (@depends) {
$file =~ s/\.substitutions/\.t.db.raw/;
print OUT "${file}:: @depends\n";
}
}
close OUT or die "Cannot close $file: $!";

12
config/replaceVAR.pl Normal file
View File

@ -0,0 +1,12 @@
eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*-
if $running_under_some_shell; # replaceVAR.pl
# Called from within the object directory
# Replaces VAR(xxx) with $(xxx)
# and VAR_xxx_ with $(xxx)
while (<STDIN>) {
s/VAR\(/\$\(/g;
s/VAR_([^_]*)_/\$\($1\)/g;
print;
}

31
config/touch.pl Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/perl
#
# unix touch in Perl
use File::Copy;
use File::Basename;
sub Usage
{
my ($txt) = @_;
print "Usage:\n";
print "\ttouch file [ file2 file3 ...]\n";
print "\nError: $txt\n" if $txt;
exit 2;
}
# need at least one arg: ARGV[0]
Usage("need more args") if $#ARGV < 0;
@targets=@ARGV[0..$#ARGV];
foreach $file ( @targets )
{
open(OUT,">$file") or die "$! creating $file";
#print OUT "NUL\n";
close OUT;
}
# EOF touch.pl

14
configure/CONFIG Normal file
View File

@ -0,0 +1,14 @@
#CONFIG
include $(TOP)/configure/CONFIG_APP
# Add any changes to make definitions here
#CROSS_COMPILER_TARGET_ARCHS = vxWorks-68040
#CROSS_COMPILER_TARGET_ARCHS =
# Use this when your IOC and the host use different paths
# to access the application. Typically this will be
# used with the Microsoft FTP server or with NFS mounts. Use
# is indicated by failure of the cdCommands script on
# vxWorks. You must rebuild in the iocBoot directory
# before this takes effect.
#IOCS_APPL_TOP = <the top of the application as seen by the IOC>

27
configure/CONFIG_APP Normal file
View File

@ -0,0 +1,27 @@
# CONFIG_APP
include $(TOP)/configure/RELEASE
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH)
-include $(TOP)/configure/RELEASE.Common.$(T_A)
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).$(T_A)
ifneq ($(wildcard $(EPICS_BASE)/configure),)
CONFIG=$(EPICS_BASE)/configure
else
CONFIG=$(EPICS_BASE)/config
DIRS += config
endif
include $(CONFIG)/CONFIG
INSTALL_LOCATION = $(TOP)
ifdef INSTALL_LOCATION_APP
INSTALL_LOCATION = $(INSTALL_LOCATION_APP)
endif
ifdef T_A
-include $(TOP)/configure/O.$(T_A)/CONFIG_APP_INCLUDE
endif
# dbst based database optimization (default: NO)
DB_OPT = NO
HOST_OPT=NO

15
configure/Makefile Normal file
View File

@ -0,0 +1,15 @@
# Makefile
TOP=..
include $(TOP)/configure/CONFIG
# Set the following to NO to disable consistency checking of
# the support applications defined in $(TOP)/configure/RELEASE
CHECK_RELEASE = YES
TARGETS = $(CONFIG_TARGETS)
CONFIGS += $(subst ../,,$(wildcard $(CONFIG_INSTALLS)))
include $(TOP)/configure/RULES

29
configure/RELEASE Normal file
View File

@ -0,0 +1,29 @@
#RELEASE Location of external products
# Run "gnumake clean uninstall install" in the application
# top directory each time this file is changed.
#
# NOTE: The build does not check dependancies on files
# external to this application. Thus you should run
# "gnumake clean uninstall install" in the top directory
# each time EPICS_BASE, SNCSEQ, or any other external
# module defined in the RELEASE file is rebuilt.
TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
# If you don't want to install into $(TOP) then
# define INSTALL_LOCATION_APP here
#INSTALL_LOCATION_APP=<fullpathname>
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

9
configure/RULES Normal file
View File

@ -0,0 +1,9 @@
#CONFIG
ifneq ($(wildcard $(EPICS_BASE)/configure),)
include $(EPICS_BASE)/configure/RULES
else
include $(EPICS_BASE)/config/RULES_ARCHS
endif
# Library should be rebuilt because LIBOBJS may have changed.
$(LIBNAME): ../Makefile

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 868 B

View File

@ -1,20 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>StreamDevice: Format Converter API</title>
<link rel="shortcut icon" href="sls_icon.ico">
<link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch">
</head>
<body>
<h1>StreamDevice: Format Converter API</h1>
<h2>Sorry, this documentation is still missing.</h2>
<hr>
<p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body>
</html>

View File

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

View File

@ -1,20 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>StreamDevice Documentation</title>
<link rel="shortcut icon" href="sls_icon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch">
</head>
<frameset rows="80,*" framespacing=0 frameborder=0 border=0>
<frame src="head.html" name="head" scrolling="no" noresize>
<frameset cols="180,*" >
<frame src="nav.html" name="nav" noresize>
<frame src="stream.html" name="text">
</frameset>
<noframes>
<a href="stream.html">Click here for no-frames version.</a>
</noframes>
</frameset>
</html>

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 807 B

View File

@ -1,79 +0,0 @@
a:link {color: #0000D0; text-decoration:none;}
a:visited {color: #0000D0; text-decoration:none;}
a:hover {color: #FF0000; text-decoration:none;}
body {
margin-right:20px;
font-family:sans-serif;
font-size:14px;
background-color:#ffffff;
}
pre {
background-color:#f4f4f4;
padding:1ex;
border:1px solid #000000;
white-space:pre;
margin:2ex;
}
dt {
margin-top:0.5ex;
}
h1 {
font-size:225%;
margin-top:0;
font-style:italic;
font-family:serif;
}
h2 {
font-size:150%;
margin-bottom:0.5ex;
}
h3 {
font-size:100%;
margin-bottom:0.25ex;
}
p {
margin-top:0.75ex;
margin-bottom:0.75ex;
}
small {
font-size:75%;
}
code {
color: #008000;
}
.indent {
text-indent:-4ex;
margin-left:4ex;
margin-top:0.5ex;
text-align:left;
}
/*
a[target=ex] {
background-image:url(ex.png);
background-repeat:no-repeat;
background-position:right center;
padding-right: 12px;
}
a[target=ex]:hover {
background-image:url(exr.png);
}
*/
@media print {
a:link {color: black; text-decoration:none;}
a:visited {color: black; text-decoration:none;}
a:hover {color: black; text-decoration:none;}
code {color: black; }
}

View File

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

BIN
documentation/PSI.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -3,13 +3,14 @@
<html> <html>
<head> <head>
<title>StreamDevice: aai Records</title> <title>StreamDevice: aai Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<h1>StreamDevice: aai Records</h1> <iframe src="nav.html" id="navleft"></iframe>
<h1>aai Records</h1>
<p> <p>
<b>Note:</b> aai record support is disabled per default. <b>Note:</b> aai record support is disabled per default.
Enable it in <code>src/CONFIG_STREAM</code>. Enable it in <code>src/CONFIG_STREAM</code>.
@ -123,6 +124,5 @@ the written or read value.
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,13 +3,14 @@
<html> <html>
<head> <head>
<title>StreamDevice: aao Records</title> <title>StreamDevice: aao Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<h1>StreamDevice: aao Records</h1> <iframe src="nav.html" id="navleft"></iframe>
<h1>aao Records</h1>
<p> <p>
<b>Note:</b> aao record support is disabled per default. <b>Note:</b> aao record support is disabled per default.
Enable it in <code>src/CONFIG_STREAM</code>. Enable it in <code>src/CONFIG_STREAM</code>.
@ -123,6 +124,5 @@ the written or read value.
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2006</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,13 +3,14 @@
<html> <html>
<head> <head>
<title>StreamDevice: ai Records</title> <title>StreamDevice: ai Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<h1>StreamDevice: ai Records</h1> <iframe src="nav.html" id="navleft"></iframe>
<h1>ai Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>
@ -38,6 +39,14 @@ written or read value.
definition. <em>StreamDevice</em> does not set it. For example, definition. <em>StreamDevice</em> does not set it. For example,
<code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code> <code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code>
(=20.0/0xFFFF) maps 0x0000 to -10.0, 0x7FFF to 0.0 and 0xFFFF to 10.0. (=20.0/0xFFFF) maps 0x0000 to -10.0, 0x7FFF to 0.0 and 0xFFFF to 10.0.
Using unsigned formats with values &ge; 0x800000 gives different results
on 64 bit machines.
<p>
If <code>LINR=="NO CONVERSION"</code> (the default), <code>VAL</code>
is directly converted from and to <code>long</code> without going through
<code>RVAL</code>. This allows for more bits on 64 bit machines.
To get the old behavior, use <code>LINR=="LINEAR"</code>.
</p>
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -75,7 +84,6 @@ written or read value.
<a href="calcout.html">calcout</a> <a href="calcout.html">calcout</a>
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2015</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,13 +3,14 @@
<html> <html>
<head> <head>
<title>StreamDevice: ao Records</title> <title>StreamDevice: ao Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<h1>StreamDevice: ao Records</h1> <iframe src="nav.html" id="navleft"></iframe>
<h1>ao Records</h1>
<h2>Normal Operation</h2> <h2>Normal Operation</h2>
<p> <p>
@ -37,6 +38,14 @@ written or read value.
might be set in the record definition. <em>StreamDevice</em> does not set it. might be set in the record definition. <em>StreamDevice</em> does not set it.
For example, <code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code> For example, <code>EOFF=-10</code> and <code>ESLO=0.000305180437934</code>
(=20.0/0xFFFF) maps -10.0 to 0x0000, 0.0 to 0x7FFF and 10.0 to 0xFFFF. (=20.0/0xFFFF) maps -10.0 to 0x0000, 0.0 to 0x7FFF and 10.0 to 0xFFFF.
Using unsigned formats with values &ge; 0x800000 gives different results
on 64 bit machines.
<p>
If <code>LINR=="NO CONVERSION"</code> (the default), <code>OVAL</code>
is directly converted to <code>long</code> without going through
<code>RVAL</code>. This allows for more bits on 64 bit machines.
To get the old behavior, use <code>LINR=="LINEAR"</code>.
</p>
</dd> </dd>
<dt>ENUM format (e.g. <code>%{</code>):</dt> <dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd> <dd>
@ -76,7 +85,6 @@ written or read value.
<a href="calcout.html">calcout</a> <a href="calcout.html">calcout</a>
<a href="scalcout.html">scalcout</a> <a href="scalcout.html">scalcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2015</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

Before

Width:  |  Height:  |  Size: 187 B

After

Width:  |  Height:  |  Size: 187 B

View File

Before

Width:  |  Height:  |  Size: 187 B

After

Width:  |  Height:  |  Size: 187 B

BIN
documentation/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

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

View File

@ -3,13 +3,14 @@
<html> <html>
<head> <head>
<title>StreamDevice: Format Converters</title> <title>StreamDevice: Format Converters</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<h1>StreamDevice: Format Converters</h1> <iframe src="nav.html" id="navleft"></iframe>
<h1>Format Converters</h1>
<a name="syntax"></a> <a name="syntax"></a>
<h2>1. Format Syntax</h2> <h2>1. Format Syntax</h2>
@ -27,8 +28,8 @@ A format converter consists of
</p> </p>
<ul> <ul>
<li>The <code>%</code> character</li> <li>The <code>%</code> character</li>
<li>Optionally a field name in <code>()</code></li> <li>Optionally a field or record name in <code>()</code></li>
<li>Optionally flags out of the characters <code>*# +0-</code></li> <li>Optionally flags out of the characters <code>*# +0-?=!</code></li>
<li>Optionally an integer <em>width</em> field</li> <li>Optionally an integer <em>width</em> field</li>
<li>Optionally a period character (<code>.</code>) followed <li>Optionally a period character (<code>.</code>) followed
by an integer <em>precision</em> field (input ony for most formats)</li> by an integer <em>precision</em> field (input ony for most formats)</li>
@ -36,6 +37,11 @@ A format converter consists of
<li>Additional information required by some converters</li> <li>Additional information required by some converters</li>
</ul> </ul>
<p>
The flags <code>*# +0-</code> work like in the C functions
<em>printf()</em> and <em>scanf()</em>.
The flags <code>?</code>, <code>=</code> and <code>!</code> are extensions.
</p>
<p> <p>
The <code>*</code> flag skips data in input formats. The <code>*</code> flag skips data in input formats.
Input is consumed and parsed, a mismatch is an error, but the read Input is consumed and parsed, a mismatch is an error, but the read
@ -61,6 +67,24 @@ The <code>0</code> flag says that numbers should be left padded with
The <code>-</code> flag specifies that output is left justified if The <code>-</code> flag specifies that output is left justified if
<em>width</em> is larger than required. <em>width</em> is larger than required.
</p> </p>
<p>
The <code>?</code> flag makes failing input conversions succeed with
a default zero value (0, 0.0, or "", depending on the format type).
</p>
<p>
The <code>=</code> flag allows to compare input with current values.
It is only allowed in input formats.
Instead of reading a new value from input, the current value is
formatted (like for output) and then compared to the input.
</p>
<p>
The <code>!</code> flag demands that input is exactly <em>width</em>
bytes long (normally <em>width</em> defines the maximum number of
bytes read in many formats).
For example <code>in "%!5d";</code> expects exactly 5 digits.
Fewer digits are considered loss of data and make the format fail.
This feature has been added by Klemen Vodopivec, SNS.
</p>
<h3>Examples:</h3> <h3>Examples:</h3>
<table> <table>
@ -84,6 +108,14 @@ The <code>-</code> flag specifies that output is left justified if
<td><code>in "%*i";</code></td> <td><code>in "%*i";</code></td>
<td>skipped integer number</td> <td>skipped integer number</td>
</tr> </tr>
<tr>
<td><code>in "%?d";</code></td>
<td>decimal number or nothing (read as 0)</td>
</tr>
<tr>
<td><code>in "%=.3f";</code></td>
<td>compare input to the current value formatted as a float with precision 3</td>
</tr>
</table> </table>
<a name="types"></a> <a name="types"></a>
@ -108,18 +140,22 @@ Thus, data type modifiers like <code>l</code> or <code>h</code> do not
exist in <em>StreamDevice</em> formats. exist in <em>StreamDevice</em> formats.
</p> </p>
<h3>Accessing record fields directly</h3> <a name="redirection"></a>
<h3>Redirection</h3>
<p> <p>
To use other fields of the record or even fields of other records on the To use other fields of the record or even fields of other records on the
same IOC for the conversion, write the field name in parentheses directly same IOC for the conversion, write the field name in parentheses directly
after the <code>%</code>. after the <code>%</code>.
For example <code>out&nbsp;"%(EGU)s";</code> outputs the <code>EGU</code> For example <code>out&nbsp;"%(EGU)s";</code> outputs the <code>EGU</code>
field formatted as a string. field formatted as a string.
Use <code>in&nbsp;"%(<i>otherrecord</i>.VAL)f";</code> to write the floating Use <code>in&nbsp;"%(<i>otherrecord</i>.RVAL)f";</code> to write the floating
point input value into the <code>VAL</code> field of point input value into the <code>RVAL</code> field of
<code><i>otherrecord</i></code>. <code><i>otherrecord</i></code>.
(You can't skip <code>.VAL</code> here.) If no field is given for an other record .VAL is assumed.
This is very useful when one line of input contains many values that should When a record name conflicts with a field name use .VAL explicitly.
</p>
<p>
This feature is very useful when one line of input contains many values that should
be distributed to many records. be distributed to many records.
If <code><i>otherrecord</i></code> is passive and the field has the PP If <code><i>otherrecord</i></code> is passive and the field has the PP
attribute (see attribute (see
@ -127,8 +163,13 @@ attribute (see
target="ex">Record Reference Manual</a>), the record will be processed. target="ex">Record Reference Manual</a>), the record will be processed.
It is your responsibility that the data type of the record field is It is your responsibility that the data type of the record field is
compatible to the the data type of the converter. compatible to the the data type of the converter.
STRING formats are compatible with arrays of CHAR or UCHAR.
</p>
<p>
Note that using this syntax is by far not as efficient as using the Note that using this syntax is by far not as efficient as using the
default field. default field.
At the moment it is not possible to set <code>otherrecord</code> to an alarm
state when anything fails.
</p> </p>
<h3>Pseudo-converters</h3> <h3>Pseudo-converters</h3>
@ -144,31 +185,46 @@ No data type corresponds to those <em>pseudo-converters</em> and the
<h2>3. Standard DOUBLE Converters (<code>%f</code>, <code>%e</code>, <h2>3. Standard DOUBLE Converters (<code>%f</code>, <code>%e</code>,
<code>%E</code>, <code>%g</code>, <code>%G</code>)</h2> <code>%E</code>, <code>%g</code>, <code>%G</code>)</h2>
<p> <p>
In output, <code>%f</code> prints fixed point, <code>%e</code> prints <b>Output:</b> <code>%f</code> prints fixed point, <code>%e</code> prints
exponential notation and <code>%g</code> prints either fixed point or exponential notation and <code>%g</code> prints either fixed point or
exponential depending on the magnitude of the value. exponential depending on the magnitude of the value.
<code>%E</code> and <code>%G</code> use <code>E</code> instead of <code>%E</code> and <code>%G</code> use <code>E</code> instead of
<code>e</code> to separate the exponent. <code>e</code> to separate the exponent.
</p>
<p>
With the <code>#</code> flag, output always contains a period character. With the <code>#</code> flag, output always contains a period character.
</p> </p>
<p> <p>
In input, all these formats are equivalent. <b>Input:</b> All these formats are equivalent. Leading whitespaces are skipped.
Leading whitespaces are skipped. </p>
<p>
With the <code>#</code> flag additional whitespace between sign and number
is accepted.
</p>
<p>
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is used.
</p> </p>
<a name="stdl"></a> <a name="stdl"></a>
<h2>4. Standard LONG Converters (<code>%d</code>, <code>%i</code>, <h2>4. Standard LONG Converters (<code>%d</code>, <code>%i</code>,
<code>%u</code>, <code>%o</code>, <code>%x</code>, <code>%X</code>)</h2> <code>%u</code>, <code>%o</code>, <code>%x</code>, <code>%X</code>)</h2>
<p> <p>
In output, <code>%d</code> and <code>%i</code> print signed decimal, <b>Output</b>: <code>%d</code> and <code>%i</code> print signed decimal,
<code>%u</code> unsigned decimal, <code>%o</code> unsigned octal, and <code>%u</code> unsigned decimal, <code>%o</code> unsigned octal, and
<code>%x</code> or <code>%X</code> unsigned hexadecimal. <code>%x</code> or <code>%X</code> unsigned hexadecimal.
<code>%X</code> uses upper case letters. <code>%X</code> uses upper case letters.
With the <code>#</code> flag, octal values are prefixed with <code>0</code>
and hexadecimal values with <code>0x</code> or <code>0X</code>.
</p> </p>
<p> <p>
In input, <code>%d</code> matches signed decimal, <code>%u</code> matches With the <code>#</code> flag, octal values are prefixed with <code>0</code>
and hexadecimal values with <code>0x</code> or <code>0X</code>.
<p>
Unlike printf, <code>%x</code> and <code>%X</code> truncate the
output to the the given width (number of least significant half bytes).
</p>
</p>
<p>
<b>Input:</b> <code>%d</code> matches signed decimal, <code>%u</code> matches
unsigned decimal, <code>%o</code> unsigned octal. unsigned decimal, <code>%o</code> unsigned octal.
<code>%x</code> and <code>%X</code> both match upper or lower case unsigned <code>%x</code> and <code>%X</code> both match upper or lower case unsigned
hexadecimal. hexadecimal.
@ -177,24 +233,44 @@ Octal and hexadecimal values can optionally be prefixed.
hexadecimal notation. hexadecimal notation.
Leading whitespaces are skipped. Leading whitespaces are skipped.
</p> </p>
<p>
With the <code>-</code> negative octal and hexadecimal values are accepted.
</p>
<p>
With the <code>#</code> flag additional whitespace between sign and number
is accepted.
</p>
<p>
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is used.
</p>
<a name="stds"></a> <a name="stds"></a>
<h2>5. Standard STRING Converters (<code>%s</code>, <code>%c</code>)</h2> <h2>5. Standard STRING Converters (<code>%s</code>, <code>%c</code>)</h2>
<p> <p>
In output, <code>%s</code> prints a string. <b>Output:</b> <code>%s</code> prints a string.
If <em>precision</em> is specified, this is the maximum string length. If <em>precision</em> is specified, this is the maximum string length.
<code>%c</code> is a LONG format in output, printing one character! <code>%c</code> is a LONG format in output, printing one character!
</p> </p>
<p> <p>
In input, <code>%s</code> matches a sequence of non-whitespace characters <b>Input:</b> <code>%s</code> matches a sequence of non-whitespace characters
and <code>%c</code> a sequence of not-null characters. and <code>%c</code> matches a sequence of not-null characters.
The maximum string length is given by <em>width</em>. The maximum string length is given by <em>width</em>.
The default <em>width</em> is infinite for <code>%s</code> and The default <em>width</em> is infinite for <code>%s</code> and
1 for <code>%c</code>. 1 for <code>%c</code>.
Leading whitespaces are skipped with <code>%s</code> but not with Leading whitespaces are skipped with <code>%s</code> except when
<code>%c</code>. the space flag is used but not with <code>%c</code>.
The empty string matches. The empty string matches.
</p> </p>
<p>
With the <code>#</code> flag <code>%s</code> matches a sequence of not-null
characters instead of non-whitespace characters.
</p>
<p>
With the <code>0</code> flag <code>%s</code> pads with 0 bytes instead of
spaces.
</p>
<a name="cset"></a> <a name="cset"></a>
<h2>6. Standard Charset STRING Converter (<code>%[<em>charset</em>]</code>)</h2> <h2>6. Standard Charset STRING Converter (<code>%[<em>charset</em>]</code>)</h2>
@ -217,18 +293,40 @@ to <code>z</code>.
This format maps an unsigned integer value on a set of strings. This format maps an unsigned integer value on a set of strings.
The value 0 corresponds to <em>string0</em> and so on. The value 0 corresponds to <em>string0</em> and so on.
The strings are separated by <code>|</code>. The strings are separated by <code>|</code>.
If one of the strings contains <code>|</code> or <code>}</code>,
a <code>\</code> must be used to escape the character.
</p> </p>
<p> <p>
Example: <code>%{OFF|STANDBY|ON}</code> mapps the string <code>OFF</code> Example: <code>%{OFF|STANDBY|ON}</code> mapps the string <code>OFF</code>
to the value 0, <code>STANDBY</code> to 1 and <code>ON</code> to 2. to the value 0, <code>STANDBY</code> to 1 and <code>ON</code> to 2.
</p> </p>
<p> <p>
In output, depending on the value, one of the strings is printed. When using the <code>#</code> flag it is allowed to assign integer values
to the strings using <code>=</code>.
Unassigned strings increment their values by 1 as usual.
</p> </p>
<p> <p>
In input, if any of the strings matches the value is set accordingly. If one string is the initial substing of another, the substing must come
later to ensure correct matching.
In particular if one string is the emptry string, it must be the last one.
Use <code>#</code> and <code>=</code> to renumber if necessary.
</p>
<p>
Use the assignment <code>=?</code> for the last string to make it the
default value for output formats.
</p>
<p>
Example: <code>%#{neg=-1|stop|pos|fast=10|rewind=-10}</code>.
</p>
<p>
If one of the strings contains <code>|</code> or <code>}</code>
(or <code>=</code> if the <code>#</code> flag is used)
a <code>\</code> must be used to escape the character.
</p>
<p>
<b>Output:</b> Depending on the value, one of the strings is printed,
or the default if no value matches.
</p>
<p>
<b>Input:</b> If any of the strings matches, the value is set accordingly.
</p> </p>
<a name="bin"></a> <a name="bin"></a>
@ -240,18 +338,19 @@ The <code>%b</code> format uses the characters <code>0</code> and
<code>1</code>. <code>1</code>.
With the <code>%B</code> format, you can choose two other characters With the <code>%B</code> format, you can choose two other characters
to represent zero and one. to represent zero and one.
With the <code>#</code> flag, the bit order is changed to <em>little
endian</em>, i.e. least significant bit first.
</p> </p>
<p> <p>
Examples: <code>%B.!</code> or <code>%B\x00\xff</code>. Examples: <code>%B.!</code> or <code>%B\x00\xff</code>.
<code>%B01</code> is equivalent to <code>%b</code>. <code>%B01</code> is equivalent to <code>%b</code>.
</p> </p>
<p> <p>
If in output <em>width</em> is larger than the number of significant bits, In output, if <em>width</em> is larger than the number of significant bits,
then the flag <code>0</code> means that the value should be padded with then the flag <code>0</code> means that the value should be padded with
with the chosen zero character instead of spaces. with the chosen zero character instead of spaces.
If <em>precision</em> is set, it means the number of significant bits. If <em>precision</em> is set, it means the number of significant bits.
Otherwise, the highest 1 bit defines the number of significant bits. Otherwise, the highest 1 bit defines the number of significant bits.
There is no alternate format when <code>#</code> is used.
</p> </p>
<p> <p>
In input, leading spaces are skipped. In input, leading spaces are skipped.
@ -264,27 +363,49 @@ one character.
<h2>9. Raw LONG Converter (<code>%r</code>)</h2> <h2>9. Raw LONG Converter (<code>%r</code>)</h2>
<p> <p>
The raw converter does not really "convert". The raw converter does not really "convert".
A signed integer value is written or read in the internal A signed or unsigned integer value is written or read in the internal
(usually two's complement) representation of the computer. (usually two's complement) representation of the computer.
The normal byte order is <em>big endian</em>, i.e. most significant byte The normal byte order is <em>big endian</em>, i.e. most significant byte
first. first.
With the <code>#</code> flag, the byte order is changed to <em>little With the <code>#</code> flag, the byte order is changed to <em>little
endian</em>, i.e. least significant byte first. endian</em>, i.e. least significant byte first.
With the <code>0</code> flag, the value is unsigned, otherwise signed.
</p> </p>
<p> <p>
In output, the <em>width</em> least significant bytes of the value In output, the <em>precision</em> (or sizeof(long) whatever is less) least
are written. significant bytes of the value are sign extended or zero extended
If <em>width</em> is larger than the size of a <code>long</code>, (depending on the <code>0</code> flag) to <em>width</em> bytes.
the value is sign extended. The default for <em>precision</em> is 1. Thus if you do not specify
the <em>precision</em>, only the least significant byte is written!
It is common error to write <code>out "%2r";</code> instead of <code>out "%.2r";</code>.
</p> </p>
<p> <p>
In input, <em>width</em> bytes are read and put into the value. In input, <em>width</em> bytes are read and put into the value.
If <em>width</em> is longer than the size of a <code>long</code>, only If <em>width</em> is larger than the size of a <code>long</code>, only
the least significant bytes are used. the least significant bytes are used.
If <em>width</em> is smaller than the size of a <code>long</code>,
the value is sign extended or zero extended, depending on the
<code>0</code> flag.
</p>
<p>
Examples: <code>out "%.2r"; in "%02r";</code>
</p>
<a name="rawdouble"></a>
<h2>10. Raw DOUBLE Converter (<code>%R</code>)</h2>
<p>
The raw converter does not really "convert".
A float or double value is written or read in the internal
(maybe IEEE) representation of the computer.
The normal byte order is <em>big endian</em>, i.e. most significant byte
first.
With the <code>#</code> flag, the byte order is changed to <em>little
endian</em>, i.e. least significant byte first.
The <em>width</em> must be 4 (float) or 8 (double). The default is 4.
</p> </p>
<a name="bcd"></a> <a name="bcd"></a>
<h2>10. Packed BCD (Binary Coded Decimal) LONG Converter (<code>%D</code>)</h2> <h2>11. Packed BCD (Binary Coded Decimal) LONG Converter (<code>%D</code>)</h2>
<p> <p>
Packed BCD is a format where each byte contains two binary coded Packed BCD is a format where each byte contains two binary coded
decimal digits (<code>0</code> ... <code>9</code>). decimal digits (<code>0</code> ... <code>9</code>).
@ -313,7 +434,7 @@ than 9.
</p> </p>
<a name="chksum"></a> <a name="chksum"></a>
<h2>11. Checksum Pseudo-Converter (<code>%&lt;<em>checksum</em>&gt;</code>)</h2> <h2>12. Checksum Pseudo-Converter (<code>%&lt;<em>checksum</em>&gt;</code>)</h2>
<p> <p>
This is not a normal "converter", because no user data is converted. This is not a normal "converter", because no user data is converted.
Instead, a checksum is calculated from the input or output. Instead, a checksum is calculated from the input or output.
@ -321,7 +442,7 @@ The <em>width</em> field is the byte number from which to start
calculating the checksum. calculating the checksum.
Default is 0, i.e. the first byte of the input or output of the current Default is 0, i.e. the first byte of the input or output of the current
command. command.
The last byte is <em>prec</em> bytes before the checksum (default 0). The last byte is <em>precision</em> bytes before the checksum (default 0).
For example in <code>"abcdefg%&lt;xor&gt;"</code> the checksum is calculated For example in <code>"abcdefg%&lt;xor&gt;"</code> the checksum is calculated
from <code>abcdefg</code>, from <code>abcdefg</code>,
but in <code>"abcdefg%2.1&lt;xor&gt;"</code> only from <code>cdef</code>. but in <code>"abcdefg%2.1&lt;xor&gt;"</code> only from <code>cdef</code>.
@ -333,8 +454,17 @@ With the <code>#</code> flag, the byte order is changed to <em>little
endian</em>, i.e. least significant byte first. endian</em>, i.e. least significant byte first.
</p> </p>
<p> <p>
The <code>0</code> flag changes the checksum representation from The <code>0</code> flag changes the checksum representation to
binary to hexadecimal ASCII (2 bytes per checksum byte). to hexadecimal ASCII (2 chars per checksum byte).
</p>
<p>
The <code>-</code> flag changes the checksum representation to
"poor man's hex": 0x30 ... 0x3f (2 chars per checksum byte).
</p>
<p>
The <code>+</code> flag changes the checksum representation to
decimal ASCII (formatted with %d).
</p>
<!-- <!--
In output, the case of the ASCII checksum matches the case of first In output, the case of the ASCII checksum matches the case of first
letter of the function name. letter of the function name.
@ -375,32 +505,38 @@ In input, the next byte or bytes must match the checksum.
(poly=0x07, init=0x00, xorout=0x00).</dd> (poly=0x07, init=0x00, xorout=0x00).</dd>
<dt><code>%&lt;ccitt8&gt;</code></dt> <dt><code>%&lt;ccitt8&gt;</code></dt>
<dd>One byte. The CCITT standard 8 bit crc checksum <dd>One byte. The CCITT standard 8 bit crc checksum
(poly=0x31, init=0x00, xorout=0x00).</dd> (poly=0x31, init=0x00, xorout=0x00, reflected).</dd>
<dt><code>%&lt;crc16&gt;</code></dt> <dt><code>%&lt;crc16&gt;</code></dt>
<dd>Two bytes. An often used 16 bit crc checksum <dd>Two bytes. An often used 16 bit crc checksum
(poly=0x8005, init=0x0000, xorout=0x0000).</dd> (poly=0x8005, init=0x0000, xorout=0x0000).</dd>
<dt><code>%&lt;crc16r&gt;</code></dt> <dt><code>%&lt;crc16r&gt;</code></dt>
<dd>Two bytes. An often used reflected 16 bit crc checksum <dd>Two bytes. An often used reflected 16 bit crc checksum
(poly=0x8005, init=0x0000, xorout=0x0000).</dd> (poly=0x8005, init=0x0000, xorout=0x0000, reflected).</dd>
<dt><code>%&lt;modbus&gt;</code></dt>
<dd>Two bytes. The modbus 16 bit crc checksum
(poly=0x8005, init=0xffff, xorout=0x0000, reflected)</dd>
<dt><code>%&lt;ccitt16&gt;</code></dt> <dt><code>%&lt;ccitt16&gt;</code></dt>
<dd>Two bytes. The usual (but <a target="ex" <dd>Two bytes. The usual (but <a target="ex"
href="http://www.joegeluso.com/software/articles/ccitt.htm">wrong?</a>) href="http://srecord.sourceforge.net/crc16-ccitt.html">wrong?</a>)
implementation of the CCITT standard 16 bit crc checksum implementation of the CCITT standard 16 bit crc checksum
(poly=0x1021, init=0xFFFF, xorout=0x0000).</dd> (poly=0x1021, init=0xFFFF, xorout=0x0000).</dd>
<dt><code>%&lt;ccitt16a&gt;</code></dt> <dt><code>%&lt;ccitt16a&gt;</code></dt>
<dd>Two bytes. The unusual (but <a target="ex" <dd>Two bytes. The unusual (but <a target="ex"
href="http://www.joegeluso.com/software/articles/ccitt.htm">correct?</a>) href="http://srecord.sourceforge.net/crc16-ccitt.html">correct?</a>)
implementation of the CCITT standard 16 bit crc checksum with augment. implementation of the CCITT standard 16 bit crc checksum with augment.
(poly=0x1021, init=0x1D0F, xorout=0x0000).</dd> (poly=0x1021, init=0x1D0F, xorout=0x0000).</dd>
<dt><code>%&lt;ccitt16x&gt;</code> or <code>%&lt;crc16c&gt;</code> or <code>%&lt;xmodem&gt;</code></dt>
<dd>Two bytes. The XMODEM checksum.
(poly=0x1021, init=0x0000, xorout=0x0000).</dd>
<dt><code>%&lt;crc32&gt;</code></dt> <dt><code>%&lt;crc32&gt;</code></dt>
<dd>Four bytes. The standard 32 bit crc checksum. <dd>Four bytes. The standard 32 bit crc checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd> (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd>
<dt><code>%&lt;crc32r&gt;</code></dt> <dt><code>%&lt;crc32r&gt;</code></dt>
<dd>Four bytes. The standard reflected 32 bit crc checksum. <dd>Four bytes. The standard reflected 32 bit crc checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd> (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF, reflected).</dd>
<dt><code>%&lt;jamcrc&gt;</code></dt> <dt><code>%&lt;jamcrc&gt;</code></dt>
<dd>Four bytes. Another reflected 32 bit crc checksum. <dd>Four bytes. Another reflected 32 bit crc checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0x00000000).</dd> (poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0x00000000, reflected).</dd>
<dt><code>%&lt;adler32&gt;</code></dt> <dt><code>%&lt;adler32&gt;</code></dt>
<dd>Four bytes. The Adler32 checksum according to <a target="ex" <dd>Four bytes. The Adler32 checksum according to <a target="ex"
href="http://www.ietf.org/rfc/rfc1950.txt">RFC 1950</a>.</dd> href="http://www.ietf.org/rfc/rfc1950.txt">RFC 1950</a>.</dd>
@ -409,41 +545,49 @@ In input, the next byte or bytes must match the checksum.
</dl> </dl>
<a name="regex"></a> <a name="regex"></a>
<h2>12. Regular Expresion STRING Converter (<code>%/<em>regex</em>/</code>)</h2> <h2>13. Regular Expresion STRING Converter (<code>%/<em>regex</em>/</code>)</h2>
<p> <p>
This input-only format matches <a target="ex" This input-only format matches <a target="ex"
href="http://www.pcre.org/" >Perl compatible regular expressions (PCRE)</a>. href="http://www.pcre.org/" >Perl compatible regular expressions (PCRE)</a>.
It is only available if a PCRE library is installed. It is only available if a PCRE library is installed.
</p> </p>
<div class="box">
<p> <p>
If PCRE is not available for your host or cross architecture, download If PCRE is not available for your host or cross architecture, download
the sourcecode from <a target="ex" href="http://www.pcre.org/">www.pcre.org</a> the sourcecode from <a target="ex" href="http://www.pcre.org/">www.pcre.org</a>
and try my EPICS compatible <a target="ex" and try my EPICS compatible <a target="ex"
href="http://epics.web.psi.ch/software/streamdevice/pcre/Makefile">Makefile</a> href="http://epics.web.psi.ch/software/streamdevice/pcre/Makefile">Makefile</a>
to compile it like a normal EPICS application. to compile it like a normal EPICS support module.
The Makefile is known to work with EPICS 3.14.8 and PCRE 7.2. The Makefile is known to work with EPICS 3.14.8 and PCRE 7.2.
In your RELEASE file define the variable <code>PCRE</code> so that In your RELEASE file define the variable <code>PCRE</code> so that
it points to the install location of PCRE. it points to the install location of PCRE.
</p> </p>
<p> <p>
If PCRE is already installed on your system, use the variables If PCRE is already installed on (some of) your systems, you may add
<code>PCRE_INCLUDE</code> and <code>PCRE_LIB</code> instead to provide architectures where PCRE can be found in standard include and library
the install directories of <code>pcre.h</code> and the library. locations to the variable <code>WITH_SYSTEM_PCRE</code>.
</p> If either the header file or the library are in a non-standard place,
<p> set in your RELEASE file the variables <code>PCRE_INCLUDE_<em>arch</em></code>
If you have PCRE installed in different locations for different (cross) and/or <code>PCRE_LIB_<em>arch</em></code> for the respective architectures
architectures, define the variables in RELEASE.Common.&lt;architecture&gt; to the correct directories or set
instead of the global RELEASE file. <code>PCRE_INCLUDE</code> and/or <code>PCRE_LIB</code>
in architecture specific RELEASE.Common.<em>arch</em> files.
</p> </p>
</div>
<p> <p>
If the regular expression is not anchored, i.e. does not start with If the regular expression is not anchored, i.e. does not start with
<code>^</code>, leading non-matching input is skipped. <code>^</code>, leading non-matching input is skipped.
To match in multiline mode (across newlines) add <code>(?m)</code>
at the beginning of the pattern.
To match case insensitive, add <code>(?i)</code>.
</p>
<p>
A maximum of <em>width</em> bytes is matched, if specified. A maximum of <em>width</em> bytes is matched, if specified.
If <em>prec</em> is given, it specifies the sub-expression whose match If <em>precision</em> is given, it specifies the sub-expression whose match
is retuned. is returned.
Otherwise the complete match is returned. Otherwise the complete match is returned.
In any case, the complete match is consumed from the input buffer. In any case, the complete match is consumed from the input buffer.
If the expression contains a <code>/</code> is must be escaped. If the expression contains a <code>/</code> it must be escaped like <code>\/</code>.
</p> </p>
<p> <p>
Example: <code>%.1/&lt;title&gt;(.*)&lt;\/title&gt;/</code> returns Example: <code>%.1/&lt;title&gt;(.*)&lt;\/title&gt;/</code> returns
@ -451,9 +595,146 @@ the title of an HTML page, skipps anything before the
<code>&lt;title&gt</code> tag and leaves anything after the <code>&lt;title&gt</code> tag and leaves anything after the
<code>&lt;/title&gt;</code> tag in the input buffer. <code>&lt;/title&gt;</code> tag in the input buffer.
</p> </p>
<a name="regsub"></a>
<h2>14. Regular Expresion Substitution Pseudo-Converter (<code>%#/<em>regex</em>/<em>subst</em>/</code>)</h2>
<p>
This is a variant of the previous converter (note the <code>#</code>)
but instead of returning the matching string,
it can be used as a pre-processor for input or
as a post-processor for output.
</p>
<p>
Matches of the <em>regex</em> are replaced by the string <em>subst</em> with all
<code>&</code> or <code>\0</code> in <em>subst</em> replaced with the match itself and all
<code>\1</code> through <code>\9</code> replaced with the match of the corresponding sub-expression.
To get a literal <code>&</code> or <code>\</code> or <code>/</code> in the substitution write
<code>\&</code> or <code>\\</code> or <code>\/</code>.
There is no way to specify literal bytes with values less or equal to 9 in the
substitution!
</p>
<p>
If <em>width</em> is specified, it limits the number of characters processed.
If the <code>-</code> flag is used (i.e. <em>width</em> looks like a negative number)
only the last <em>width</em> characters are processed, else the first.
Without <em>width</em> (or 0) all available characters are processed.
</p>
<p>
If <em>precision</em> is specified, it indicates which matches to replace.
With the <code>+</code> flag given, <em>precision</em> is the maximum
number of matches to replace.
Otherwise <em>precision</em> is the index (counting from 1) of the match to replace.
Without <em>precision</em> (or 0), all matches are replaced.
</p>
<p>
In input this converter pre-processes data received from the device before
following converters read it.
Converters preceding this one will read unmodified input.
Thus place this converter before those whose input should be pre-processed.
</p>
<p>
In output it post-processes data already formatted by preceding converters
before sending it to the device.
Converters following this one will send their output unmodified.
Thus place this converter after those whose output should be post-processed.
</p>
<p>
Examples:
<div class="indent">
<code>%#+-10.2/ab/X/</code> replaces the string <code>ab</code> with <code>X</code>
maximal 2 times in the last 10 characters.
(<code>abcabcabcabc</code> becomes <code>abcXcXcabc</code>)
</div>
<div class="indent">
<code>%#/\\/\//</code> replaces all <code>\</code> with <code>/</code>
(<code>\dir\file</code> becomes <code>/dir/file</code>)
</div>
<div class="indent">
<code>%#/..\B/&:/</code> inserts <code>:</code> after every second character
which is not at the end of a word.
(<code>0b19353134</code> becomes <code>0b:19:35:31:34</code>)
</div>
<div class="indent">
<code>%#/://</code> removes all <code>:</code> characters.
(<code>0b:19:35:31:34</code> becomes <code>0b19353134</code>)
</div>
<div class="indent">
<code>%#/([^+-])*([+-])/\2\1/</code> moves a postfix sign to the front.
(<code>1.23-</code> becomes <code>-1.23</code>)<br>
</div>
<a name="mantexp"></a>
<h2>15. MantissaExponent DOUBLE converter (<code>%m</code>)</h2>
<p>
This exotic and experimental format matches numbers in the format
<i>[sign] mantissa sign exponent</i>, e.g <code>+123-4</code> meaning
123e-4 or 0.0123. Mantissa and exponent are decimal integers.
The sign of the mantissa is optional.
Compared to the standard <code>%e</code> format, this format does not
contain the characters <code>.</code> and <code>e</code>.
</p>
<p>
Output formatting is ambigous (e.g. <code>123-4</code> versus
<code>1230-5</code>). I chose the following convention:
Format <em>precision</em> defines number of digits in mantissa.
No leading '0' in mantissa (except for 0.0 of course).
Number of digits in exponent is at least 2.
Format flags <code>+</code>, <code>-</code>, and space are supported in
the usual way (always sign, left justified, space instead of + sign).
Flags <code>#</code> and <code>0</code> are unsupported.
</p>
<a name="timestamp"></a>
<h2>16. Timestamp DOUBLE converter (<code>%T(<em>timeformat</em>)</code>)</h2>
<p>
This format reads or writes timestamps and converts them to a double number.
The value represents the number of seconds since 1970 (the UNIX epoch).
The precision of a double is large enough for microseconds (but not for
nanoseconds). This format is probably used best in combination with a
redirection to the <code>TIME</code> field. In this case, the value is
converted to EPICS timestamps (seconds since 1990 and nanoseconds).
The timestamp format understands the usual converters that the C function
<em>strftime()</em> understands. In addition, fractions of a second can
be specified and the time zone can be set in the format string.
</p>
<p>
Example: <code>%(TIME)T(%d %b %Y %H:%M:%.3S %z)</code> may print something like
<code> 3 Sep 2010 15:45:59 +0200</code>.
</p>
<p>
Fractions of a second can be specified as <code>%.<em>n</em>S</code>
(seconds with <em>n</em> fractional digits), as <code>%0<em>n</em>f</code>
or <code>%<em>n</em>f</code> (<em>n</em> fractional digits) or as
<code>%N</code> (nanoseconds).
In input, <em>n</em> is the maximum number of digits parsed, there may be
actually less digits in the input.
If <em>n</em> is not specified (<code>%.S</code> or <code>%f</code>) it uses
a default value of 6.
</p>
<p>
In input, the time zone can be specified in the format like
<code>%+<em>hhmm</em></code> or <code>%-<em>hhmm</em></code> for cases
where the parsed time stamp does not specify the time zone, where
<em>hhmm</em> is a 4 digit number specifying the offset in hours and minutes.
</p>
<p>
In output, the system function <em>strftime()</em> is used to format the time.
There may be differences in the implementation between operating systems.
</p>
<p>
In input, <em>StreamDevice</em> uses its own implementation because many
systems are missing the <em>strptime()</em> function and additional formats
are supported.
</p>
<p>
Day of the week can be parsed but is ignored because the information is
redundant when used together with day, month and year and more or less
useless otherwise. No check is done for consistency.
</p>
<p>
Because of the complexity of the problem, locales are not supported.
Thus, only the English month names can be used (week day names are
ignored anyway).
</p>
<hr> <hr>
<p align="right"><a href="processing.html">Next: Record Processing</a></p> <p align="right"><a href="processing.html">Next: Record Processing</a></p>
<p><small>Dirk Zimoch, 2007</small></p> <p><small>Dirk Zimoch, 2015</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

@ -3,13 +3,14 @@
<html> <html>
<head> <head>
<title>StreamDevice</title> <title>StreamDevice</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<h1>EPICS <em>StreamDevice</em> Documentation</h1> <iframe src="nav.html" id="navleft"></iframe>
<h1>EPICS <em>StreamDevice</em></h1>
<h2>What is <em>StreamDevice</em>?</h2> <h2>What is <em>StreamDevice</em>?</h2>
<p> <p>
@ -22,30 +23,27 @@ receiving strings (in the broadest sense, including non-printable
characters and even null-bytes). characters and even null-bytes).
Examples for this type of communication interface are Examples for this type of communication interface are
serial line (RS-232, RS-485, ...), serial line (RS-232, RS-485, ...),
IEEE-488 (also known as GPIB or HP-IB), and TCP/IP. IEEE-488 (also known as GPIB or HP-IB), and telnet-like TCP/IP.
<em>StreamDevice</em> comes with an interface to<a target="ex"
href="http://www.aps.anl.gov/epics/modules/soft/asyn/">
<em>asynDriver</em></a>
but can be extended to
<a href="businterface.html">support other bus drivers</a>.
</p> </p>
<p> <p>
<em>StreamDevice</em> is not limited to a specific device type or
manufacturer nor is it necessary to re-compile anything to support a
new device type.
Instead, it can be configured for any device type with
<a href="protocol.html"><em>protocol files</em></a> in plain ASCII text
which describes the commands a device understands and the replies it sends.
If the device can be controlled with strings like If the device can be controlled with strings like
"<code>RF:FREQ 499.655 MHZ</code>", <em>StreamDevice</em> can be used. "<kbd>RF:FREQ 499.655 MHZ</kbd>" <em>StreamDevice</em> can be used.
How the strings exactly look like is defined in <em>protocols</em>. Formatting and parsing of values is done with
Formatting and interpretation of values is done with
<a href="formats.html"><em>format converters</em></a> similar to those <a href="formats.html"><em>format converters</em></a> similar to those
known from the C functions <em>printf()</em> and <em>scanf()</em>. known from the C functions <em>printf()</em> and <em>scanf()</em>.
To support other formats, it is possible to To support other formats, it is possible to
<a href="formatconverter.html">write your own converters</a>. <a href="formatconverter.html">write your own converters</a>.
</p> </p>
<p> <p>
Each record with <em>StreamDevice</em> support runs one <em>protocol</em> Each record with <em>StreamDevice</em> support runs one protocol
to read or write its value. from the protocol file to read or write its value.
All <em>protocols</em> are defined in Protocols can be as simple as just one output string or can
<a href="protocol.html"><em>protocol files</em></a> in plain ASCII text.
No compiling is necessary to change a protocol or to support new devices.
<em>Protocols</em> can be as simple as just one output string or can
consist of many strings sent to and read from the device. consist of many strings sent to and read from the device.
However, a protocol is linear. However, a protocol is linear.
That means it runs from start to end each time the record is That means it runs from start to end each time the record is
@ -53,6 +51,20 @@ That means it runs from start to end each time the record is
It does not provide loops or branches. It does not provide loops or branches.
</p> </p>
<p> <p>
<em>StreamDevice</em> comes with an interface to<a target="ex"
href="http://www.aps.anl.gov/epics/modules/soft/asyn/">
<em>asynDriver</em></a>
but can be extended to
<a href="businterface.html">support other bus drivers</a>.
Note that <em>StreamDevice</em> is not an alternative or replacement
but a supplement for <em>asynDriver</em>.
<em>StreamDevice</em> converts record values to and from strings but
leaves it to <em>asynDriver</em> (or other bus interfaces) to exchange
these strings with the device.
Thus any bus type supported by <em>asynDriver</em> (to be exact by
<em>asynOctet</em>) can automatically be used with <em>StreamDevice</em>.
</p>
<p>
<em>StreamDevice</em> supports all <em>StreamDevice</em> supports all
<a href="recordtypes.html">standard records</a> of EPICS base <a href="recordtypes.html">standard records</a> of EPICS base
which can have device support. which can have device support.
@ -64,7 +76,7 @@ It is also possible to
<p> <p>
It is not a programming language for a high-level application. It is not a programming language for a high-level application.
It is, for example, not possible to write a complete scanning program It is, for example, not possible to write a complete scanning program
in a <em>protocol</em>. in a protocol.
Use other tools for that and use <em>StreamDevice</em> only for the Use other tools for that and use <em>StreamDevice</em> only for the
primitive commands. primitive commands.
</p> </p>
@ -76,17 +88,24 @@ many process variables distributed over many records.
<h2>Recommended Readings</h2> <h2>Recommended Readings</h2>
<p> <p>
<a href="http://www.aps.anl.gov/epics/base/R3-14/8-docs/AppDevGuide.pdf" <a href="http://www.aps.anl.gov/epics/base/R3-14/12-docs/AppDevGuide"
target="ex">IOC Application Developer's Guide (PDF)</a> target="ex">IOC Application Developer's Guide</a>
</p> </p>
<p> <p>
<a href="http://www.aps.anl.gov/asd/controls/epics/EpicsDocumentation/AppDevManuals/RecordRef/Recordref-1.html" <a href="https://wiki-ext.aps.anl.gov/epics/index.php/RRM_3-14"
target="ex">EPICS Record Reference Manual</a> target="ex">EPICS Record Reference Manual</a>
</p> </p>
<h2>Color and Style Conventions</h2>
<p>
In this document, code is witten in <code>green fixed width font</code>.
This marks text you typically type in configuration files etc.
</p>
<pre>
Longer code segments are often set in a box.
</pre>
<hr> <hr>
<p align="right"><a href="setup.html">Next: Setup</a></p> <p align="right"><a href="setup.html">Next: Setup</a></p>
<p><small>Dirk Zimoch, 2006</small></p> <p><small>Dirk Zimoch, 2015</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

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

View File

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

43
documentation/makepdf Executable file
View File

@ -0,0 +1,43 @@
#/bin/sh
if ! wkhtmltopdf -V >/dev/null 2>&1
then
echo "wkhtmltopdf not installed."
echo "See https://wkhtmltopdf.org"
exit 1
fi >&2
PAGES="
index.html
setup.html
epics3_13.html
protocol.html
formats.html
processing.html
recordtypes.html
aai.html
aao.html
ai.html
ao.html
bi.html
bo.html
mbbi.html
mbbo.html
mbbiDirect.html
mbboDirect.html
stringin.html
stringout.html
longin.html
longout.html
waveform.html
calcout.html
scalcout.html
tipsandtricks.html
recordinterface.html
businterface.html
formatconverter.html
osinterface.html
"
rm -f stream.pdf
wkhtmltopdf --print-media-type --dpi 1200 --zoom 0.85 --page-size Letter \
$PAGES stream.pdf

View File

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

View File

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

View File

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

View File

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

215
documentation/nav.html Normal file
View File

@ -0,0 +1,215 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Navbar</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch">
<style type="text/css">
<!--
body {margin:0 0 13ex 1em;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight:bold;
font-size:13px;
background-color:#e3eaf6;}
a {text-decoration:none;}
a:link {color:#333333;}
a:visited {color:#333333;}
a:hover {color:#FF0000;}
a:active {color:#FF0000;}
h1 {font-size:120%;
margin-top: 20px;
margin-right: 20px;
margin-bottom: 10px;
color:#267ab8;}
div {border-bottom:1px solid black;
padding-top:1ex;}
div div, div div div, div:hover div div
{
padding-top:0;
margin-right:.1em;
border:none;
box-shadow: none;
-moz-box-shadow: none;
-webkit-box-shadow: none;
padding 0;
display:block;
position:relative;
}
div div
{display:none;
margin-left:2em;
margin-right:1em;
background-color:#e3eaf6;
padding:0 .5em .5ex .5em;
border-width:0 thick thick 1px;
border-color:black;
border-style:solid;
}
:root *> div div
{border-width:0 1px 1px 1px;
box-shadow: 5px 5px 5px black;
-moz-box-shadow: 5px 5px 5px black;
-webkit-box-shadow: 5px 5px 5px black;
}
div:hover div {
position:absolute;
display:block;}
div div div {margin-left:0;}
a {display:block;
margin-top:.3ex;}
div div a {display:list-item;
margin-left:1em;
list-style-type:disc;
}
div div div a {list-style-type:circle;}
-->
</style>
</head>
<body>
<h1>User's Guide</h1>
<div>
<a target="_parent" href="index.html">Intro</a>
</div>
<div>
<a target="_parent" href="setup.html">Setup</a>
<a href="javascript:show('setup')" id="setupButton"></a>
<div>
<a target="_parent" href="setup.html#pre">Prerequisites</a>
<div>
<a target="_parent" href="epics3_13.html">Using EPICS 3.13</a>
</div>
<a target="_parent" href="setup.html#lib">Build Library</a>
<a target="_parent" href="setup.html#app">Build Application</a>
<a target="_parent" href="setup.html#sta">Startup Script</a>
<a target="_parent" href="setup.html#pro">Protocol File</a>
<div>
<a target="_parent" href="setup.html#reload">Reloading</a>
</div>
<a target="_parent" href="setup.html#rec">Records</a>
</div>
</div>
<div>
<a target="_parent" href="protocol.html">Protocol Files</a>
<a href="javascript:show('protocol')" id="protocolButton"></a>
<div>
<a target="_parent" href="protocol.html#gen">General</a>
<a target="_parent" href="protocol.html#proto">Protocols</a>
<a target="_parent" href="protocol.html#cmd">Commands</a>
<a target="_parent" href="protocol.html#str">Strings</a>
<a target="_parent" href="protocol.html#var">Variables</a>
<div>
<a target="_parent" href="protocol.html#sysvar">System variables</a>
<a target="_parent" href="protocol.html#argvar">Protocol Arguments</a>
<a target="_parent" href="protocol.html#usrvar">User variables</a>
</div>
<a target="_parent" href="protocol.html#except">Exception Handlers</a>
</div>
</div>
<div>
<a target="_parent" href="formats.html">Format Converters</a>
<a href="javascript:show('formats')" id="formatsButton"></a>
<div>
<a target="_parent" href="formats.html#syntax">Syntax</a>
<a target="_parent" href="formats.html#types">Types &amp; Fields</a>
<a target="_parent" href="formats.html#stdd" title="Standard DOUBLE converters">%f %e %g</a>
<a target="_parent" href="formats.html#stdl" title="Standard LONG converters">%i %d %u %o %x</a>
<a target="_parent" href="formats.html#stds" title="Standard STRING converters">%s %c</a>
<a target="_parent" href="formats.html#cset" title="Character set STRING converter">%[<em>charset</em>]</a>
<a target="_parent" href="formats.html#enum" title="Enumeration LONG converter">%{<em>s0</em>|<em>s1</em>|...}</a>
<a target="_parent" href="formats.html#bin" title="Binary LONG converter">%b %B</a>
<a target="_parent" href="formats.html#raw" title="Raw LONG converter">%r</a>
<a target="_parent" href="formats.html#rawdouble" title="Raw DOUBLE converter">%R</a>
<a target="_parent" href="formats.html#bcd" title="Binary coded decimal LONG converter">%D</a>
<a target="_parent" href="formats.html#chksum" title="Checksum pseudo converter">%&lt;<em>checksum</em>&gt;</a>
<a target="_parent" href="formats.html#regex" title="Perl regular expression STRING converter">%/<em>regex</em>/</a>
<a target="_parent" href="formats.html#regsub" title="Perl regular expression substitution pseudo converter">%#/<em>regex</em>/<em>subst</em>/</a>
<a target="_parent" href="formats.html#mantexp" title="MantissaExponent DOUBLE converter">%m</a>
<a target="_parent" href="formats.html#timestamp" title="Timestamp DOUBLE converter">%T</a>
</div>
</div>
<div>
<a target="_parent" href="processing.html">Record Processing</a>
<a href="javascript:show('proc')" id="procButton"></a>
<div>
<a target="_parent" href="processing.html#proc">Normal Processing</a>
<a target="_parent" href="processing.html#init">Initialization</a>
<a target="_parent" href="processing.html#iointr">I/O Intr</a>
</div>
</div>
<div>
<a target="_parent" href="recordtypes.html">Record Types</a>
<a href="javascript:show('records')" id="recordsButton"></a>
<div>
<a target="_parent" href="aai.html">aai</a>
<a target="_parent" href="aao.html">aao</a>
<a target="_parent" href="ai.html">ai</a>
<a target="_parent" href="ao.html">ao</a>
<a target="_parent" href="bi.html">bi</a>
<a target="_parent" href="bo.html">bo</a>
<a target="_parent" href="mbbi.html">mbbi</a>
<a target="_parent" href="mbbo.html">mbbo</a>
<a target="_parent" href="mbbiDirect.html">mbbiDirect</a>
<a target="_parent" href="mbboDirect.html">mbboDirect</a>
<a target="_parent" href="stringin.html">stringin</a>
<a target="_parent" href="stringout.html">stringout</a>
<a target="_parent" href="longin.html">longin</a>
<a target="_parent" href="longout.html">longout</a>
<a target="_parent" href="waveform.html">waveform</a>
<a target="_parent" href="calcout.html">calcout</a>
<a target="_parent" href="scalcout.html">scalcout</a>
</div>
</div>
<div>
<a target="_parent" href="tipsandtricks.html">Tips &amp; Tricks</a>
<a href="javascript:show('tipsandtricks')" id="tipsandtricksButton"></a>
<div>
<a target="_parent" href="tipsandtricks.html#argvar">Many almost identical protocols</a>
<a target="_parent" href="tipsandtricks.html#iointr">Read unsolicited input</a>
<a target="_parent" href="tipsandtricks.html#multiline">Read multi-line messages</a>
<a target="_parent" href="tipsandtricks.html#writemany">Write more than one value in one message</a>
<a target="_parent" href="tipsandtricks.html#readmany">Read more than one value from one message</a>
<a target="_parent" href="tipsandtricks.html#mixed">Read values of mixed data type</a>
<a target="_parent" href="tipsandtricks.html#web">Read a web page</a>
</div>
</div>
<h1>Programmer's Guide</h1>
<div>
<a target="_parent" href="recordinterface.html">Record API</a>
</div>
<div>
<a target="_parent" href="businterface.html">Bus API</a>
<a href="javascript:show('bus')" id="busButton"></a>
<div>
<a target="_parent" href="businterface.html#class">Interface Class</a>
<a target="_parent" href="businterface.html#theory">Theory of Operation</a>
<div>
<a target="_parent" href="businterface.html#registration">Registration</a>
<a target="_parent" href="businterface.html#create">Creation &amp; deletion</a>
<a target="_parent" href="businterface.html#connect">Connecting</a>
<a target="_parent" href="businterface.html#lock">Bus locking</a>
<a target="_parent" href="businterface.html#write">Writing output</a>
<a target="_parent" href="businterface.html#read">Reading input</a>
<a target="_parent" href="businterface.html#event">Handling events</a>
</div>
</div>
</div>
<div>
<a target="_parent" href="formatconverter.html">Format Converter API</a>
</div>
<div>
<a target="_parent" href="osinterface.html">Operating System API</a>
</div>
</body>
</html>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,13 +3,14 @@
<html> <html>
<head> <head>
<title>StreamDevice: scalcout Records</title> <title>StreamDevice: scalcout Records</title>
<link rel="shortcut icon" href="sls_icon.ico"> <link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="stream.css"> <link rel="stylesheet" type="text/css" href="stream.css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="author" content="Dirk Zimoch"> <meta name="author" content="Dirk Zimoch">
</head> </head>
<body> <body>
<h1>StreamDevice: scalcout Records</h1> <iframe src="nav.html" id="navleft"></iframe>
<h1>scalcout Records</h1>
<p> <p>
<b>Note:</b> The scalcout record is part of the <i>calc</i> module of <b>Note:</b> The scalcout record is part of the <i>calc</i> module of
@ -28,7 +29,7 @@ before the final <code>return(0)</code>:
</p> </p>
<pre class="box"> <pre class="box">
if(pscalcoutDSET->init_record ) { if(pscalcoutDSET->init_record ) {
return (*pscalcoutDSET->init_record)(pcalc); return (*pscalcoutDSET->init_record)(pcalc);
} }
</pre> </pre>
@ -96,6 +97,5 @@ Different record fields are used for output and input. The variable
<a href="calcout.html">calcout</a> <a href="calcout.html">calcout</a>
</p> </p>
<p><small>Dirk Zimoch, 2005</small></p> <p><small>Dirk Zimoch, 2005</small></p>
<script src="stream.js" type="text/javascript"></script>
</body> </body>
</html> </html>

View File

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

135
documentation/stream.css Normal file
View File

@ -0,0 +1,135 @@
a:link {color: #0000D0;}
a:visited {color: #0000D0;}
a:hover {color: #FF0000;}
body {
margin-right:1em;
margin-left:15em;
margin-top:70px;
padding-top:1px;
font-family: Helvetica, Arial, sans-serif;
font-size:14px;
background-color:#ffffff;
}
a[name] { position:relative; top:-11ex;}
pre {
background-color:#f4f4f4;
padding:1ex;
border:1px solid #000000;
white-space:pre;
margin:2ex;
page-break-inside:avoid;
}
kbd {
font-weight:bold;
}
dt {
margin-top:0.5ex;
}
h1 {
font-size:250%;
margin-top:0;
font-style:italic;
font-weight:bold;
font-family:"Times New Roman", serif;
text-align:center;
position:fixed;
top:0;
left:0;
width:100%;
line-height:190%;
background-color:white;
border-width:0;
border-bottom:3px solid #1b4486;
white-space:nowrap;
background-image:url(PSI.png);
background-repeat:no-repeat;
background-position:10px 5px;
text-shadow:.1em .1em .1em darkgray;
box-shadow:0 .3em .1em -.2em darkgray;
}
h2 {
font-size:150%;
margin-bottom:0.5ex;
}
h3 {
font-size:120%;
margin-bottom:0.25ex;
}
h4 {
font-size:100%;
margin-bottom:0.25ex;
}
p {
margin-top:0.75ex;
margin-bottom:0.75ex;
}
small {
font-size:75%;
}
code {
color: #008000;
}
.indent {
text-indent:-4ex;
margin-left:4ex;
margin-top:0.5ex;
text-align:left;
}
.box {
margin-left:1ex;
margin-right:1ex;
margin-top:0.5ex;
padding: 0 1ex;
border: 1px solid black;
text-align:left;
background-color:#f0f0f0;
}
#navleft {
position:fixed;
left:0;
top:0;
padding-top:70px;
width:14em;
height:100%;
border-style:solid;
border-color:black;
border-width:0 1px 0 0;
background-color:#e3eaf6;
overflow:hidden;
z-index:0;
}
.new {
background-color: #ffc;
}
a[target=ex]:after {
content:" " url(ex.png);
}
a[target=ex]:hover:after {
content: " " url(exr.png);
}
@media print {
a:link {text-decoration:none;}
a[target=ex]:after {content:" [" attr(href) "]";}
body {margin:0 4em;}
h1 {position:relative; background-position:0 0;}
#navleft {display:none;}
}

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -3,17 +3,17 @@
# You may add more record interfaces # You may add more record interfaces
# This requires the naming conventions # This requires the naming conventions
# dev$(RECORD)Stream.c # dev$(RECORDTYPE)Stream.c
RECORDS += ao ai RECORDTYPES += ao ai
RECORDS += bo bi RECORDTYPES += bo bi
RECORDS += mbbo mbbi RECORDTYPES += mbbo mbbi
RECORDS += mbboDirect mbbiDirect RECORDTYPES += mbboDirect mbbiDirect
RECORDS += longout longin RECORDTYPES += longout longin
RECORDS += stringout stringin RECORDTYPES += stringout stringin
RECORDS += waveform RECORDTYPES += waveform
RECORDS += calcout RECORDTYPES += calcout
#RECORDS += aai aao RECORDTYPES += aai aao
# Do you have synApps and want support for scalcout? # Do you have synApps and want support for scalcout?
# Then define CALC or SYNAPPS in your RELEASE file # Then define CALC or SYNAPPS in your RELEASE file
@ -21,15 +21,23 @@ RECORDS += calcout
# Due to strange cross dependencies in synApps # Due to strange cross dependencies in synApps
# you have to build the 'sscan' and 'genSub' # you have to build the 'sscan' and 'genSub'
# modules before building 'calc'. # modules before building 'calc'.
# See doc/scalcout.html for a required fix in scalcout. # The 'calc' version must be 2-4 or higher.
SYNAPPS_RECORDS += scalcout # Up to version 2-6 (synApps 5.1) the 'calc' module needs a fix.
# See doc/scalcout.html for details.
ifneq ($(words $(CALC) $(SYNAPPS)), 0)
RECORDTYPES += scalcout
endif
# You may add more bus interfaces # You may add more bus interfaces
# This requires the naming convention # This requires the naming convention
# $(BUS)Interface.cc # $(BUS)Interface.cc
# asynDriver interface is added automatically # asynDriver interface is added if ASYN is defined in your RELEASE file.
# if ASYN is defined in your RELEASE file.
# BUSSES += Debug BUSSES += Debug
BUSSES += Dummy
ifdef ASYN
BUSSES += AsynDriver
endif
# You may add more format converters # You may add more format converters
# This requires the naming convention # This requires the naming convention
@ -38,9 +46,11 @@ SYNAPPS_RECORDS += scalcout
FORMATS += Enum FORMATS += Enum
FORMATS += BCD FORMATS += BCD
FORMATS += Raw FORMATS += Raw
FORMATS += RawFloat
FORMATS += Binary FORMATS += Binary
FORMATS += Checksum FORMATS += Checksum
FORMATS += Exponential FORMATS += MantissaExponent
FORMATS += Timestamp
# Want Perl regular expression matching? # Want Perl regular expression matching?
# If PCRE is installed at the same location for all # If PCRE is installed at the same location for all
@ -65,10 +75,6 @@ endif
# by "static IoccrfReg iocshReg;" # by "static IoccrfReg iocshReg;"
# LOADABLE_MODULE = YES # LOADABLE_MODULE = YES
# Want to add some memory tracing
# to find memory leaks?
# USE_MEMGUARD = YES
# Sources of Stream Kernel # Sources of Stream Kernel
# Do not modify # Do not modify

View File

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

76
src/DummyInterface.cc Normal file
View File

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

View File

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

View File

@ -1,63 +0,0 @@
/***************************************************************
* StreamDevice Support *
* *
* (C) 1999 Dirk Zimoch (zimoch@delta.uni-dortmund.de) *
* (C) 2007 Dirk Zimoch (dirk.zimoch@psi.ch) *
* *
* This is a custom exponential format converter for *
* StreamDevice. *
* The number is represented as two signed integers, mantissa *
* and exponent, like in +00011-01 *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include "StreamFormatConverter.h"
#include "StreamError.h"
#include <math.h>
// Exponential Converter %m: format +00351-02 means +351e-2
class ExponentialConverter : public StreamFormatConverter
{
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual int scanDouble(const StreamFormat&, const char*, double&);
};
int ExponentialConverter::
parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool scanFormat)
{
if (!scanFormat)
{
error("At the moment for %%m format only input is implemented\n");
return false;
}
return double_format;
}
int ExponentialConverter::
scanDouble(const StreamFormat& fmt, const char* input, double& value)
{
int mantissa;
int exponent;
int length = -1;
sscanf(input, "%d%d%n", &mantissa, &exponent, &length);
if (fmt.flags & skip_flag) return length;
if (length == -1) return -1;
value = (double)(mantissa) * pow(10, exponent);
return length;
}
RegisterConverter (ExponentialConverter, "m");

View File

@ -18,7 +18,7 @@
# # # #
################################################################ ################################################################
TOP=../.. TOP:=../$(TOP)
# Look if we have EPICS R3.13 or R3.14 # Look if we have EPICS R3.13 or R3.14
ifeq ($(wildcard $(TOP)/configure),) ifeq ($(wildcard $(TOP)/configure),)
@ -40,13 +40,8 @@ DBD += $(LIBRARY_DEFAULT).dbd
ifdef ASYN ifdef ASYN
LIB_LIBS += asyn LIB_LIBS += asyn
BUSSES += AsynDriver else
endif $(warning Asyn not included! Didn't you set ASYN in your RELEASE file?)
ifdef T_A
ifndef BUSSES
$(error No bus interface defined! Didn't you set ASYN in your RELEASE file?)
endif
endif endif
ifeq ($(LOADABLE_MODULE),YES) ifeq ($(LOADABLE_MODULE),YES)
@ -54,7 +49,7 @@ SRCS += $(LIBRARY_DEFAULT)_registerRecordDeviceDriver.cpp
endif endif
SRCS += $(BUSSES:%=%Interface.cc) SRCS += $(BUSSES:%=%Interface.cc)
SRCS += $(FORMATS:%=%Converter.cc) SRCS += $(FORMATS:%=%Converter.cc)
SRCS += $(RECORDS:%=dev%Stream.c) SRCS += $(RECORDTYPES:%=dev%Stream.c)
SRCS += $(STREAM_SRCS) SRCS += $(STREAM_SRCS)
# find system wide or local PCRE header and library # find system wide or local PCRE header and library
@ -65,18 +60,13 @@ ifdef PCRE
LIB_LIBS += pcre LIB_LIBS += pcre
else else
ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0) ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0)
LIB_SYS_LIBS += pcre LIB_SYS_LIBS_DEFAULT += pcre
LIB_SYS_LIBS_WIN32 += $(PCRE_LIB)\\pcre
SHRLIB_DEPLIB_DIRS += $(PCRE_LIB) SHRLIB_DEPLIB_DIRS += $(PCRE_LIB)
endif endif
endif endif
LIB_LIBS += Com dbIoc dbStaticIoc registryIoc iocsh LIB_LIBS += $(EPICS_BASE_IOC_LIBS)
ifeq ($(USE_MEMGUARD),YES)
# memguard looks for memory leaks (gcc only)
CPPFLAGS += -include ../memguard.h
LIB_SRCS += memguard.cc
endif
INC += devStream.h INC += devStream.h
@ -84,31 +74,21 @@ include $(TOP)/configure/RULES
# Update version string (contains __DATE__ and __TIME__) # Update version string (contains __DATE__ and __TIME__)
# each time make runs. # each time make runs.
StreamVersion$(OBJ): FORCE StreamVersion$(OBJ): ../*.c ../*.h ../*.cc ../CONFIG_STREAM ../Makefile
FORCE:
# Add references to all registrars to main file to avoid # Add references to all registrars to main file to avoid
# missing initialization. # missing initialization.
StreamCore$(OBJ): streamReferences StreamCore$(OBJ) StreamCore$(DEP): streamReferences
streamReferences: ../CONFIG_STREAM streamReferences: ../CONFIG_STREAM
@for i in $(BUSSES); \ $(PERL) ../makeref.pl Interface $(BUSSES) > $@
do echo "extern void* ref_$${i}Interface;"; \ $(PERL) ../makeref.pl Converter $(FORMATS) >> $@
echo "void* p$$i = ref_$${i}Interface;"; \
done > $@
@for i in $(FORMATS); \
do echo "extern void* ref_$${i}Converter;"; \
echo "void* p$$i = ref_$${i}Converter;"; \
done >> $@
# create stream.dbd from all RECORDS # create stream.dbd from all RECORDTYPES
$(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM $(COMMON_DIR)/$(LIBRARY_DEFAULT).dbd: ../CONFIG_STREAM
@for r in $(RECORDS); \ $(PERL) ../makedbd.pl $(RECORDTYPES) > $@
do echo "device($$r,INST_IO,dev$${r}Stream,\"stream\")"; \
done > $@ $(LIBRARY_DEFAULT).dbd$(DEP): ../CONFIG_STREAM
@echo "driver(stream)" >> $@ echo $(LIBRARY_DEFAULT).dbd: $< > $@
@echo "variable(streamDebug, int)" >> $@
@echo "variable(showAsyncErrors, int)" >> $@
@echo "registrar(streamRegistrar)" >> $@
endif endif

View File

@ -18,14 +18,11 @@
# # # #
################################################################ ################################################################
TOP = ../../.. TOP := ../../$(TOP)
include $(TOP)/config/CONFIG_APP include $(TOP)/config/CONFIG_APP
include ../CONFIG_STREAM include ../CONFIG_STREAM
# In 3.13, calcout has no device support
RECORDS_3_13 = $(filter-out calcout,$(RECORDS))
DBDNAME = stream.dbd DBDNAME = stream.dbd
INC += devStream.h INC += devStream.h
@ -35,11 +32,9 @@ INC += devStream.h
CONFIGS = RULES.munch CONFIGS = RULES.munch
SCRIPTS = munch.pl SCRIPTS = munch.pl
include $(TOP)/config/RULES.Host include $(EPICS_BASE)/config/RULES.Host
# create stream.dbd from all RECORDS # create stream.dbd from all RECORDTYPES
# In 3.13, calcout has no device support
stream.dbd: ../CONFIG_STREAM stream.dbd: ../CONFIG_STREAM
@for r in $(RECORDS_3_13); \ $(PERL) ../makedbd.pl -3.13 $(filter-out calcout,$(RECORDTYPES)) > $@
do echo "device($$r,INST_IO,dev$${r}Stream,\"stream\")"; \
done > $@
@echo "driver(stream)" >> $@

View File

@ -18,29 +18,23 @@
# # # #
################################################################ ################################################################
TOP = ../../.. TOP := ../../$(TOP)
include $(TOP)/config/CONFIG_APP include $(TOP)/config/CONFIG_APP
include ../CONFIG_STREAM include ../CONFIG_STREAM
LIBNAME = streamLib LIBNAME = streamLib
# In 3.13, calcout has no device support
RECORDS_3_13 = $(filter-out calcout,$(RECORDS))
ifdef ASYN
BUSSES += AsynDriver
endif
SRCS.cc += $(patsubst %,../%,$(filter %.cc,$(STREAM_SRCS))) SRCS.cc += $(patsubst %,../%,$(filter %.cc,$(STREAM_SRCS)))
SRCS.cc += $(BUSSES:%=../%Interface.cc) SRCS.cc += $(BUSSES:%=../%Interface.cc)
SRCS.cc += $(FORMATS:%=../%Converter.cc) SRCS.cc += $(FORMATS:%=../%Converter.cc)
SRCS.c += $(patsubst %,../%,$(filter %.c,$(STREAM_SRCS))) SRCS.c += $(patsubst %,../%,$(filter %.c,$(STREAM_SRCS)))
SRCS.c += $(RECORDS_3_13:%=../dev%Stream.c) # In 3.13, calcout has no device support
SRCS.c += $(patsubst %,../dev%Stream.c,$(filter-out calcout,$(RECORDTYPES)))
LIBOBJS = $(patsubst ../%,%.o,$(basename $(SRCS.cc) $(SRCS.c))) LIBOBJS = $(patsubst ../%,%.o,$(basename $(SRCS.cc) $(SRCS.c)))
include $(TOP)/config/RULES.Vx include $(EPICS_BASE)/config/RULES.Vx
include $(TOP)/config/RULES.munch include $(TOP)/config/RULES.munch
build:: depends build:: depends

View File

@ -0,0 +1,100 @@
/***************************************************************
* StreamDevice Support *
* *
* (C) 2008 Dirk Zimoch (dirk.zimoch@psi.ch) *
* *
* This is a custom exponential format converter for *
* StreamDevice. *
* The number is represented as two signed integers, mantissa *
* and exponent, like in +00011-01 *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include "StreamFormatConverter.h"
#include "StreamError.h"
#include <math.h>
// Exponential Converter %m
// Eric Berryman requested a double format that reads
// +00011-01 as 11e-01
// I.e integer mantissa and exponent without 'e' or '.'
// But why not +11000-04 ?
// For writing, I chose the following convention:
// Format precision defines number of digits in mantissa
// No leading '0' in mantissa (except for 0.0 of course)
// Number of digits in exponent is at least 2
// Format flags +, -, and space are supported in the usual way
// Flags #, 0 are not supported
class MantissaExponentConverter : public StreamFormatConverter
{
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual int scanDouble(const StreamFormat&, const char*, double&);
virtual bool printDouble(const StreamFormat&, StreamBuffer&, double);
};
int MantissaExponentConverter::
parse(const StreamFormat&, StreamBuffer&,
const char*&, bool)
{
return double_format;
}
int MantissaExponentConverter::
scanDouble(const StreamFormat& fmt, const char* input, double& value)
{
int mantissa;
int exponent;
int length = -1;
sscanf(input, "%d%d%n", &mantissa, &exponent, &length);
if (fmt.flags & skip_flag) return length;
if (length == -1) return -1;
value = (double)(mantissa) * pow(10.0, exponent);
return length;
}
bool MantissaExponentConverter::
printDouble(const StreamFormat& fmt, StreamBuffer& output, double value)
{
// Have to divide value into mantissa and exponent
// precision field is number of characters in mantissa
// number of characters in exponent is at least 2
int spaces;
StreamBuffer buf;
int prec = fmt.prec;
if (prec < 1) prec = 6;
buf.print("%.*e", prec-1, fabs(value)/pow(10.0, prec-1));
buf.remove(1,1);
buf.remove(buf.find('e'),1);
spaces = fmt.width-buf.length();
if (fmt.flags & (space_flag|sign_flag) || value < 0.0) spaces--;
if (spaces < 0) spaces = 0;
if (!(fmt.flags & left_flag))
output.append(' ', spaces);
if ((fmt.flags & (space_flag|sign_flag)) == space_flag && value >= 0.0)
output.append(' ');
if (fmt.flags & sign_flag && value >= 0.0)
output.append('+');
if (value < 0.0)
output.append('-');
output.append(buf);
if (fmt.flags & left_flag)
output.append(' ', spaces);
return true;
}
RegisterConverter (MantissaExponentConverter, "m");

View File

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

136
src/RawFloatConverter.cc Normal file
View File

@ -0,0 +1,136 @@
/***************************************************************
* StreamDevice Support *
* *
* (C) 1999 Dirk Zimoch (zimoch@delta.uni-dortmund.de) *
* (C) 2005 Dirk Zimoch (dirk.zimoch@psi.ch) *
* *
* This is the raw format converter of StreamDevice. *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include "StreamFormatConverter.h"
#include "StreamError.h"
static int endian = 0;
// Raw Float Converter %R
class RawFloatConverter : public StreamFormatConverter
{
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printDouble(const StreamFormat&, StreamBuffer&, double);
int scanDouble(const StreamFormat&, const char*, double&);
};
int RawFloatConverter::
parse(const StreamFormat& format, StreamBuffer&,
const char*&, bool)
{
// Find out byte order
if (!endian) {
union {long l; char c [sizeof(long)];} u;
u.l=1;
if (u.c[0]) { endian = 1234;} // little endian
else if (u.c[sizeof(long)-1]) { endian = 4321;} // big endian
else {
error ("Cannot find out byte order for %%R format.\n");
return false;
}
}
// Assume IEEE formats with 4 or 8 bytes (default: 4)
if (format.width==0 || format.width==4 || format.width==8)
return double_format;
error ("Only width 4 or 8 allowed for %%R format.\n");
return false;
}
bool RawFloatConverter::
printDouble(const StreamFormat& format, StreamBuffer& output, double value)
{
int nbOfBytes;
int n;
union {
double dval;
float fval;
char bytes[8];
} buffer;
nbOfBytes = format.width;
if (nbOfBytes == 0)
nbOfBytes = 4;
if (nbOfBytes == 4)
buffer.fval = (float)value;
else
buffer.dval = value;
if (!(format.flags & alt_flag) ^ (endian == 4321))
{
// swap if byte orders differ
for (n = nbOfBytes-1; n >= 0; n--)
{
output.append(buffer.bytes[n]);
}
} else {
for (n = 0; n < nbOfBytes; n++)
{
output.append(buffer.bytes[n]);
}
}
return true;
}
int RawFloatConverter::
scanDouble(const StreamFormat& format, const char* input, double& value)
{
int nbOfBytes;
int i, n;
union {
double dval;
float fval;
char bytes[8];
} buffer;
nbOfBytes = format.width;
if (nbOfBytes == 0)
nbOfBytes = 4;
if (format.flags & skip_flag)
{
return(nbOfBytes); // just skip input
}
if (!(format.flags & alt_flag) ^ (endian == 4321))
{
// swap if byte orders differ
for (n = nbOfBytes-1, i = 0; n >= 0; n--, i++)
{
buffer.bytes[n] = input[i];
}
} else {
for (n = 0; n < nbOfBytes; n++)
{
buffer.bytes[n] = input[n];
}
}
if (nbOfBytes == 4)
value = buffer.fval;
else
value = buffer.dval;
return nbOfBytes;
}
RegisterConverter (RawFloatConverter, "R");

View File

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

View File

@ -26,19 +26,20 @@
#if defined(__vxworks) || defined(vxWorks) || defined(_WIN32) || defined(__rtems__) #if defined(__vxworks) || defined(vxWorks) || defined(_WIN32) || defined(__rtems__)
// These systems have no vsnprintf // These systems have no vsnprintf
#include <epicsStdio.h> #define vsnprintf(p,l,f,v) vsprintf(p,f,v)
#define vsnprintf epicsVsnprintf
#endif #endif
#define P PRINTF_SIZE_T_PREFIX
void StreamBuffer:: void StreamBuffer::
init(const void* s, long minsize) init(const void* s, ssize_t minsize)
{ {
len = 0; len = 0;
offs = 0; offs = 0;
buffer = local; buffer = local;
cap = sizeof(local); cap = sizeof(local);
if (minsize < 0) minsize = 0; if (minsize < 0) minsize = 0;
if (minsize >= cap) if ((size_t)minsize >= cap)
{ {
// use allocated buffer // use allocated buffer
grow(minsize); grow(minsize);
@ -46,7 +47,7 @@ init(const void* s, long minsize)
else else
{ {
// clear local buffer // clear local buffer
memset(buffer+minsize, 0, cap-minsize); memset(buffer, 0, cap);
} }
if (s) { if (s) {
len = minsize; len = minsize;
@ -54,12 +55,19 @@ init(const void* s, long minsize)
} }
} }
// How the buffer looks like:
// |----free-----|####used####|--------00--------|
///|<--- offs -->|<-- len --->|<- cap-offs-len ->|
// 0 offs offs+len cap
// |<-------------- minsize --------------->
void StreamBuffer:: void StreamBuffer::
grow(long minsize) grow(size_t minsize)
{ {
// make space for minsize + 1 (for termination) bytes // make space for minsize + 1 (for termination) bytes
char* newbuffer; char* newbuffer;
long newcap; size_t newcap;
#ifdef EXPLODE #ifdef EXPLODE
if (minsize > 1000000) if (minsize > 1000000)
{ {
@ -102,7 +110,7 @@ grow(long minsize)
memset(newbuffer+len, 0, newcap-len); memset(newbuffer+len, 0, newcap-len);
if (buffer != local) if (buffer != local)
{ {
delete buffer; delete [] buffer;
} }
buffer = newbuffer; buffer = newbuffer;
cap = newcap; cap = newcap;
@ -110,12 +118,12 @@ grow(long minsize)
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
append(const void* s, long size) append(const void* s, ssize_t size)
{ {
if (size <= 0) if (size <= 0)
{ {
// append negative number of bytes? let's delete some // append negative number of bytes? let's delete some
if (size < -len) size = -len; if (size < -(ssize_t)len) size = -(ssize_t)len;
memset (buffer+offs+len+size, 0, -size); memset (buffer+offs+len+size, 0, -size);
} }
else else
@ -127,34 +135,34 @@ append(const void* s, long size)
return *this; return *this;
} }
long int StreamBuffer:: ssize_t StreamBuffer::
find(const void* m, long size, long start) const find(const void* m, size_t size, ssize_t start) const
{ {
if (start < 0) if (start < 0)
{ {
start += len; start += len;
if (start < 0) start = 0; if (start < 0) start = 0;
} }
if (start >= len-size+1) return -1; // find nothing after end if (start+size > len) return -1; // find nothing after end
if (!m || size <= 0) return start; // find empty string at start if (!m || size <= 0) return start; // find empty string at start
const char* s = static_cast<const char*>(m); const char* s = static_cast<const char*>(m);
char* b = buffer+offs; char* b = buffer+offs;
char* p = b+start; char* p = b+start;
long i; size_t i;
while ((p = static_cast<char*>(memchr(p, s[0], b-p+len-size+1)))) while ((p = static_cast<char*>(memchr(p, s[0], b-p+len-size+1))))
{ {
i = 1; for (i = 1; i < size; i++)
while (p[i] == s[i])
{ {
if (++i >= size) return p-b; if (p[i] != s[i]) goto next;
} }
p++; return p-b;
next: p++;
} }
return -1; return -1;
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
replace(long remstart, long remlen, const void* ins, long inslen) replace(ssize_t remstart, ssize_t remlen, const void* ins, ssize_t inslen)
{ {
if (remstart < 0) if (remstart < 0)
{ {
@ -180,12 +188,12 @@ replace(long remstart, long remlen, const void* ins, long inslen)
remlen += remstart; remlen += remstart;
remstart = 0; remstart = 0;
} }
if (remstart > len) if ((size_t)remstart > len)
{ {
// remove begins after bufferend // remove begins after bufferend
remstart = len; remstart = len;
} }
if (remlen >= len-remstart) if ((size_t)remlen >= len-remstart)
{ {
// truncate remove after bufferend // truncate remove after bufferend
remlen = len-remstart; remlen = len-remstart;
@ -198,12 +206,12 @@ replace(long remstart, long remlen, const void* ins, long inslen)
return *this; return *this;
} }
if (inslen < 0) inslen = 0; if (inslen < 0) inslen = 0;
long remend = remstart+remlen; size_t remend = remstart+remlen;
long newlen = len+inslen-remlen; size_t newlen = len+inslen-remlen;
if (cap <= newlen) if (cap <= newlen)
{ {
// buffer too short // buffer too short
long newcap; size_t newcap;
for (newcap = sizeof(local)*2; newcap <= newlen; newcap *= 2); for (newcap = sizeof(local)*2; newcap <= newlen; newcap *= 2);
char* newbuffer = new char[newcap]; char* newbuffer = new char[newcap];
memcpy(newbuffer, buffer+offs, remstart); memcpy(newbuffer, buffer+offs, remstart);
@ -212,7 +220,7 @@ replace(long remstart, long remlen, const void* ins, long inslen)
memset(newbuffer+newlen, 0, newcap-newlen); memset(newbuffer+newlen, 0, newcap-newlen);
if (buffer != local) if (buffer != local)
{ {
delete buffer; delete [] buffer;
} }
buffer = newbuffer; buffer = newbuffer;
cap = newcap; cap = newcap;
@ -241,16 +249,16 @@ replace(long remstart, long remlen, const void* ins, long inslen)
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
printf(const char* fmt, ...) print(const char* fmt, ...)
{ {
va_list va; va_list va;
int printed; ssize_t printed;
while (1) while (1)
{ {
va_start(va, fmt); va_start(va, fmt);
printed = vsnprintf(buffer+offs+len, cap-offs-len, fmt, va); printed = vsnprintf(buffer+offs+len, cap-offs-len, fmt, va);
va_end(va); va_end(va);
if (printed > -1 && printed < (int)(cap-offs-len)) if (printed > -1 && printed < (ssize_t)(cap-offs-len))
{ {
len += printed; len += printed;
return *this; return *this;
@ -260,27 +268,36 @@ printf(const char* fmt, ...)
} }
} }
StreamBuffer StreamBuffer::expand(long start, long length) const StreamBuffer StreamBuffer::expand(ssize_t start, ssize_t length) const
{ {
long end; size_t end;
if (start < 0) if (start < 0)
{ {
start += len; start += len;
if (start < 0) start = 0;
} }
end = length >= 0 ? start+length : len; if (length < 0)
{
start += length;
length = -length;
}
if (start < 0)
{
length += start;
start = 0;
}
end = start+length;
if (end > len) end = len; if (end > len) end = len;
StreamBuffer result((end-start)*2); StreamBuffer result((end-start)*2);
start += offs; start += offs;
end += offs; end += offs;
long i; size_t i;
char c; char c;
for (i = start; i < end; i++) for (i = start; i < end; i++)
{ {
c = buffer[i]; c = buffer[i];
if ((c & 0x7f) < 0x20 || (c & 0x7f) == 0x7f) if (c < 0x20 || c >= 0x7f)
{ {
result.printf("<%02x>", c & 0xff); result.print("<%02x>", c & 0xff);
} }
else else
{ {
@ -295,18 +312,18 @@ dump() const
{ {
StreamBuffer result(256+cap*5); StreamBuffer result(256+cap*5);
result.append("\033[0m"); result.append("\033[0m");
long i; size_t i;
result.printf("%ld,%ld,%ld:\033[37m", offs, len, cap); result.print("%" P "d,%" P "d,%" P "d:\033[37m", offs, len, cap);
for (i = 0; i < cap; i++) for (i = 0; i < cap; i++)
{ {
if (i == offs) result.append("\033[34m[\033[0m"); if (i == offs) result.append("\033[34m[\033[0m");
if ((buffer[i] & 0x7f) < 0x20 || (buffer[i] & 0x7f) == 0x7f) if ((buffer[i] & 0x7f) < 0x20 || (buffer[i] & 0x7f) == 0x7f)
{ {
if (i < offs || i >= offs+len) if (i < offs || i >= offs+len)
result.printf( result.print(
"<%02x>", buffer[i] & 0xff); "<%02x>", buffer[i] & 0xff);
else else
result.printf( result.print(
"\033[34m<%02x>\033[37m", buffer[i] & 0xff); "\033[34m<%02x>\033[37m", buffer[i] & 0xff);
} }
else else

View File

@ -21,63 +21,73 @@
#define StreamBuffer_h #define StreamBuffer_h
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdlib.h>
#include <sys/types.h>
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(x) #define __attribute__(x)
#endif #endif
#ifdef _WIN32
#define ssize_t ptrdiff_t
#endif
class StreamBuffer class StreamBuffer
{ {
long len;
long cap;
long offs;
char* buffer;
char local[64]; char local[64];
size_t len;
size_t cap;
size_t offs;
char* buffer;
void grow(long); void init(const void* s, ssize_t minsize);
void init(const void*, long);
void check(long size) void check(size_t size)
{if (len+offs+size >= cap) grow(len+size);} {if (len+offs+size >= cap) grow(len+size);}
void grow(size_t minsize);
public: public:
// Hints: // Hints:
// * Any index parameter (long) can be negative // * Any index parameter (ssize_t) can be negative
// meaning "count from end" (-1 is the last byte) // meaning "count from end" (-1 is the last byte)
// * Appending negative count deletes from end
// * Any returned char* pointer becomes invalid when // * Any returned char* pointer becomes invalid when
// the StreamBuffer is modified. // the StreamBuffer is modified.
// * End of StreamBuffer always contains 0x00 bytes
// * Deleting from start and clearing is fast
StreamBuffer() StreamBuffer()
{init(NULL, 0);} {init(NULL, 0);}
StreamBuffer(const void*s, long size) StreamBuffer(const void* s, ssize_t size)
{init(s, size);} {init(s, size);}
StreamBuffer(const char*s) StreamBuffer(const char* s)
{init(s, s?strlen(s):0);} {init(s, s?strlen(s):0);}
StreamBuffer(const StreamBuffer& s) StreamBuffer(const StreamBuffer& s)
{init(s.buffer+s.offs, s.len);} {init(s.buffer+s.offs, s.len);}
StreamBuffer(long size) StreamBuffer(ssize_t size)
{init(NULL, size);} {init(NULL, size);}
~StreamBuffer() ~StreamBuffer()
{if (buffer != local) delete buffer;} {if (buffer != local) delete buffer;}
// operator (): get char* pointing to index // operator (): get char* pointing to index
const char* operator()(long index=0) const const char* operator()(ssize_t index=0) const
{buffer[offs+len]=0; return buffer+offs+(index<0?index+len:index);} {return buffer+offs+(index<0?index+len:index);}
char* operator()(long index=0) char* operator()(ssize_t index=0)
{buffer[offs+len]=0; return buffer+offs+(index<0?index+len:index);} {return buffer+offs+(index<0?index+len:index);}
// operator []: get byte at index // operator []: get byte at index
char operator[](long index) const char operator[](ssize_t index) const
{return buffer[offs+(index<0?index+len:index)];} {return buffer[offs+(index<0?index+len:index)];}
char& operator[](long index) char& operator[](ssize_t index)
{return buffer[offs+(index<0?index+len:index)];} {return buffer[offs+(index<0?index+len:index)];}
// cast to bool: not empty? // cast to bool: not empty?
@ -85,11 +95,11 @@ public:
{return len>0;} {return len>0;}
// length: get current data length // length: get current data length
long length() const ssize_t length() const
{return len;} {return len;}
// capacity: get current max data length (spare one byte for end) // capacity: get current max data length (spare one byte for end)
long capacity() const ssize_t capacity() const
{return cap-1;} {return cap-1;}
// end: get pointer to byte after last data byte // end: get pointer to byte after last data byte
@ -102,23 +112,38 @@ public:
// reserve: reserve size bytes of memory and return // reserve: reserve size bytes of memory and return
// pointer to that memory (for copying something to it) // pointer to that memory (for copying something to it)
char* reserve(long size) char* reserve(size_t size)
{check(size); char* p=buffer+offs+len; len+=size; return p; } {check(size); char* p=buffer+offs+len; len+=size; return p;}
// append: append data at the end of the buffer // append: append data at the end of the buffer
StreamBuffer& append(char c) StreamBuffer& append(char c)
{check(1); buffer[offs+len++]=c; return *this;} {check(1); buffer[offs+len++]=c; return *this;}
StreamBuffer& append(const void* s, long size); StreamBuffer& append(char c, ssize_t count)
{if (count < 0) truncate(count);
else {check(count); memset(buffer+offs+len, c, count); len+=count;}
return *this;}
StreamBuffer& append(const void* s, ssize_t size);
StreamBuffer& append(const char* s) StreamBuffer& append(const char* s)
{return append(s, s?strlen(s):0);} {return append(s, s?strlen(s):0);}
StreamBuffer& append(const StreamBuffer& s) StreamBuffer& append(const StreamBuffer& s)
{return append(s.buffer+s.offs, s.len);} {return append(s.buffer+s.offs, s.len);}
// operator += alias for append
StreamBuffer& operator+=(char c)
{return append(c);}
StreamBuffer& operator+=(const char* s)
{return append(s);}
StreamBuffer& operator+=(const StreamBuffer& s)
{return append(s);}
// set: clear buffer and fill with new data // set: clear buffer and fill with new data
StreamBuffer& set(const void* s, long size) StreamBuffer& set(const void* s, size_t size)
{clear(); return append(s, size);} {clear(); return append(s, size);}
StreamBuffer& set(const char* s) StreamBuffer& set(const char* s)
@ -127,7 +152,7 @@ public:
StreamBuffer& set(const StreamBuffer& s) StreamBuffer& set(const StreamBuffer& s)
{clear(); return append(s.buffer+s.offs, s.len);} {clear(); return append(s.buffer+s.offs, s.len);}
// operator =: alias for set // operator = alias for set
StreamBuffer& operator=(const char* s) StreamBuffer& operator=(const char* s)
{return set(s);} {return set(s);}
@ -136,73 +161,86 @@ public:
// replace: delete part of buffer (pos/length) and insert new data // replace: delete part of buffer (pos/length) and insert new data
StreamBuffer& replace( StreamBuffer& replace(
long pos, long length, const void* s, long size); ssize_t pos, ssize_t length, const void* s, ssize_t size);
StreamBuffer& replace(long pos, long length, const char* s) StreamBuffer& replace(ssize_t pos, ssize_t length, const char* s)
{return replace(pos, length, s, s?strlen(s):0);} {return replace(pos, length, s, s?strlen(s):0);}
StreamBuffer& replace(long pos, long length, const StreamBuffer& s) StreamBuffer& replace(ssize_t pos, ssize_t length, const StreamBuffer& s)
{return replace(pos, length, s.buffer+s.offs, s.len);} {return replace(pos, length, s.buffer+s.offs, s.len);}
// replace: delete part of buffer // remove: delete from start/pos
StreamBuffer& remove(long pos, long length) StreamBuffer& remove(ssize_t pos, ssize_t length)
{return replace(pos, length, NULL, 0);} {return replace(pos, length, NULL, 0);}
StreamBuffer& remove(long length) // remove from start: no memset, no function call, fast!
StreamBuffer& remove(size_t length)
{if (length>len) length=len; {if (length>len) length=len;
offs+=length; len-=length; return *this;} offs+=length; len-=length; return *this;}
// replace: delete end of buffer // truncate: delete end of buffer
StreamBuffer& truncate(long pos) StreamBuffer& truncate(ssize_t pos)
{return replace(pos, len, NULL, 0);} {return replace(pos, len, NULL, 0);}
// insert: insert new data into buffer // insert: insert new data into buffer
StreamBuffer& insert(long pos, const void* s, long size) StreamBuffer& insert(ssize_t pos, const void* s, ssize_t size)
{return replace(pos, 0, s, size);} {return replace(pos, 0, s, size);}
StreamBuffer& insert(long pos, const char* s) StreamBuffer& insert(ssize_t pos, const char* s)
{return replace(pos, 0, s, s?strlen(s):0);} {return replace(pos, 0, s, s?strlen(s):0);}
StreamBuffer& insert(long pos, const StreamBuffer& s) StreamBuffer& insert(ssize_t pos, const StreamBuffer& s)
{return replace(pos, 0, s.buffer+s.offs, s.len);} {return replace(pos, 0, s.buffer+s.offs, s.len);}
StreamBuffer& insert(long pos, char c) StreamBuffer& insert(ssize_t pos, char c)
{return replace(pos, 0, &c, 1);} {return replace(pos, 0, &c, 1);}
StreamBuffer& printf(const char* fmt, ...) StreamBuffer& print(const char* fmt, ...)
__attribute__ ((format(printf,2,3))); __attribute__ ((format(printf,2,3)));
// find: get index of data in buffer or -1 // find: get index of data in buffer or -1
long find(char c, long start=0) const ssize_t find(char c, ssize_t start=0) const
{char* p; {char* p;
return (p = static_cast<char*>( return (p = static_cast<char*>(
memchr(buffer+offs+(start<0?start+len:start), memchr(buffer+offs+(start<0?start+len:start),
c, start<0?-start:len-start)))? c, start<0?-start:len-start)))?
p-(buffer+offs) : -1;} p-(buffer+offs) : -1;}
long find(const void* s, long size, long start=0) const; ssize_t find(const void* s, size_t size, ssize_t start=0) const;
long find(const char* s, long start=0) const ssize_t find(const char* s, ssize_t start=0) const
{return find(s, s?strlen(s):0, start);} {return find(s, s?strlen(s):0, start);}
long int find(const StreamBuffer& s, long start=0) const ssize_t find(const StreamBuffer& s, ssize_t start=0) const
{return find(s.buffer+s.offs, s.len, start);} {return find(s.buffer+s.offs, s.len, start);}
// equals: returns true if first size bytes are equal // startswith: returns true if first size bytes are equal
bool equals(const void* s, long size) const bool startswith(const void* s, size_t size) const
{return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;} {return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;}
// equals: returns true if first string is equal (empty string match) // startswith: returns true if first string is equal (empty string matches)
bool equals(const char* s) const bool startswith(const char* s) const
{return len ? strcmp(buffer+offs, s) == 0 : !s || !*s;} {return len ? strcmp(buffer+offs, s) == 0 : !s || !*s;}
// expand: create copy of StreamBuffer where all nonprintable characters // expand: create copy of StreamBuffer where all nonprintable characters
// are replaced by <xx> with xx being the hex code of the characters // are replaced by <xx> with xx being the hex code of the characters
StreamBuffer expand(long start=0, long length=-1) const; StreamBuffer expand(ssize_t start, ssize_t length) const;
StreamBuffer expand(ssize_t start=0) const
{return expand(start, len);}
// dump: debug function, like expand but also show the 'hidden' memory // dump: debug function, like expand but also show the 'hidden' memory
// before and after the real data. Uses colours. // before and after the real data. Uses colours.
StreamBuffer dump() const; StreamBuffer dump() const;
}; };
// printf size prefix for size_t and ssize_t
#if defined (__GNUC__) && __GNUC__ >= 3
#define PRINTF_SIZE_T_PREFIX "z"
#elif defined (_WIN32)
#define PRINTF_SIZE_T_PREFIX "I"
#else
#define PRINTF_SIZE_T_PREFIX ""
#endif
#endif #endif

View File

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

View File

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

View File

@ -23,11 +23,7 @@
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <epicsExport.h> #define P PRINTF_SIZE_T_PREFIX
int showAsyncErrors = 0;
extern "C" {
epicsExportAddress(int, showAsyncErrors);
}
enum Commands { end_cmd, in_cmd, out_cmd, wait_cmd, event_cmd, exec_cmd, enum Commands { end_cmd, in_cmd, out_cmd, wait_cmd, event_cmd, exec_cmd,
connect_cmd, disconnect_cmd }; connect_cmd, disconnect_cmd };
@ -45,7 +41,6 @@ static char* printCommands(StreamBuffer& buffer, const char* c)
{ {
unsigned long timeout; unsigned long timeout;
unsigned long eventnumber; unsigned long eventnumber;
unsigned short cmdlen;
while (1) while (1)
{ {
switch(*c++) switch(*c++)
@ -64,22 +59,21 @@ static char* printCommands(StreamBuffer& buffer, const char* c)
break; break;
case wait_cmd: case wait_cmd:
timeout = extract<unsigned long>(c); timeout = extract<unsigned long>(c);
buffer.printf(" wait %ld;\n # ms", timeout); buffer.print(" wait %ld; # ms\n", timeout);
break; break;
case event_cmd: case event_cmd:
eventnumber = extract<unsigned long>(c); eventnumber = extract<unsigned long>(c);
timeout = extract<unsigned long>(c); timeout = extract<unsigned long>(c);
buffer.printf(" event(%ld) %ld; # ms\n", eventnumber, timeout); buffer.print(" event(%ld) %ld; # ms\n", eventnumber, timeout);
break; break;
case exec_cmd: case exec_cmd:
buffer.append(" exec \""); buffer.append(" exec \"");
cmdlen = extract<unsigned short>(c);
c = StreamProtocolParser::printString(buffer, c); c = StreamProtocolParser::printString(buffer, c);
buffer.append("\";\n"); buffer.append("\";\n");
break; break;
case connect_cmd: case connect_cmd:
timeout = extract<unsigned long>(c); timeout = extract<unsigned long>(c);
buffer.printf(" connect %ld; # ms\n", timeout); buffer.print(" connect %ld; # ms\n", timeout);
break; break;
case disconnect_cmd: case disconnect_cmd:
buffer.append(" disconnect;\n"); buffer.append(" disconnect;\n");
@ -126,7 +120,6 @@ printProtocol()
if (onMismatch) if (onMismatch)
printf(" @Mismatch {\n%s }\n", printf(" @Mismatch {\n%s }\n",
printCommands(buffer.clear(), onMismatch())); printCommands(buffer.clear(), onMismatch()));
debug("StreamCore::printProtocol: commands=%s\n", commands.expand()());
printf("\n%s}\n", printf("\n%s}\n",
printCommands(buffer.clear(), commands())); printCommands(buffer.clear(), commands()));
} }
@ -172,7 +165,7 @@ attachBus(const char* busname, int addr, const char* param)
businterface = StreamBusInterface::find(this, busname, addr, param); businterface = StreamBusInterface::find(this, busname, addr, param);
if (!businterface) if (!businterface)
{ {
error("Businterface '%s' not found for '%s'\n", error("Cannot find a bus named '%s' for '%s'\n",
busname, name()); busname, name());
return false; return false;
} }
@ -331,7 +324,7 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
{ {
if (!busSupportsEvent()) if (!busSupportsEvent())
{ {
protocol->errorMsg(getLineNumber(command), error(getLineNumber(command), protocol->filename(),
"Events not supported by businterface.\n"); "Events not supported by businterface.\n");
return false; return false;
} }
@ -345,11 +338,12 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
} }
if (*args != ')') if (*args != ')')
{ {
protocol->errorMsg(getLineNumber(command), error(getLineNumber(command), protocol->filename(),
"Expect ')' instead of: '%s'\n", args); "Expect ')' instead of: '%s'\n", args);
return false; return false;
} }
args++; args++;
while (isspace(*args)) args++;
} }
buffer.append(&eventmask, sizeof(eventmask)); buffer.append(&eventmask, sizeof(eventmask));
if (*args) if (*args)
@ -366,7 +360,7 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
{ {
buffer.append(exec_cmd); buffer.append(exec_cmd);
if (!protocol->compileString(buffer, args, if (!protocol->compileString(buffer, args,
NoFormat, this)) PrintFormat, this))
{ {
return false; return false;
} }
@ -389,13 +383,29 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
return true; return true;
} }
protocol->errorMsg(getLineNumber(command), error(getLineNumber(command), protocol->filename(),
"Unknown command name '%s'\n", command); "Unknown command name '%s'\n", command);
return false; return false;
} }
// Run the protocol // Run the protocol
// Input and events may come asynchonously from the bus driver
// Especially in the sequence 'out "request"; in "reply";' the
// reply can come before the 'in' command has actually started.
// For asyncronous protocols, input can come at any time.
// Thus, we must always accept input and event while the protocol
// is running or when asyncronous mode is active.
// Early input and event must be buffered until 'in' or 'event'
// start. An 'out' command must discard any early input to avoid
// problems with late input from aborted protocols.
// Async mode ends on Abort or Error or if another command comes
// after the asynchronous 'in' command.
// Input can be discarded when it is not accepted any more, i.e.
// at the end of syncronous protocols and when an asynchronous
// mode ends (but not when 'in'-only protocol finishes normally).
bool StreamCore:: bool StreamCore::
startProtocol(StartMode startMode) startProtocol(StartMode startMode)
{ {
@ -449,8 +459,8 @@ finishProtocol(ProtocolResult status)
flags & WaitPending ? "timerCallback()" : ""); flags & WaitPending ? "timerCallback()" : "");
status = Fault; status = Fault;
} }
flags &= ~(AcceptInput|AcceptEvent); //// flags &= ~(AcceptInput|AcceptEvent);
if (runningHandler) if (runningHandler || flags & InitRun)
{ {
// get original error status // get original error status
if (status == Success) status = runningHandler; if (status == Success) status = runningHandler;
@ -494,6 +504,7 @@ finishProtocol(ProtocolResult status)
break; break;
default: default:
// get rid of all the rubbish whe might have collected // get rid of all the rubbish whe might have collected
unparsedInput = false;
inputBuffer.clear(); inputBuffer.clear();
handler = NULL; handler = NULL;
} }
@ -524,6 +535,7 @@ finishProtocol(ProtocolResult status)
flags &= ~BusOwner; flags &= ~BusOwner;
} }
busFinish(); busFinish();
flags &= ~(AcceptInput|AcceptEvent);
protocolFinishHook(status); protocolFinishHook(status);
} }
@ -545,16 +557,16 @@ evalCommand()
switch (*commandIndex++) switch (*commandIndex++)
{ {
case out_cmd: case out_cmd:
flags &= ~(AcceptInput|AcceptEvent); //// flags &= ~(AcceptInput|AcceptEvent);
return evalOut(); return evalOut();
case in_cmd: case in_cmd:
flags &= ~AcceptEvent; //// flags &= ~AcceptEvent;
return evalIn(); return evalIn();
case wait_cmd: case wait_cmd:
flags &= ~(AcceptInput|AcceptEvent); //// flags &= ~(AcceptInput|AcceptEvent);
return evalWait(); return evalWait();
case event_cmd: case event_cmd:
flags &= ~AcceptInput; //// flags &= ~AcceptInput;
return evalEvent(); return evalEvent();
case exec_cmd: case exec_cmd:
return evalExec(); return evalExec();
@ -579,9 +591,9 @@ evalCommand()
bool StreamCore:: bool StreamCore::
evalOut() evalOut()
{ {
inputBuffer.clear(); // flush all unread input // flush all unread input
unparsedInput = false; unparsedInput = false;
outputLine.clear(); inputBuffer.clear();
if (!formatOutput()) if (!formatOutput())
{ {
finishProtocol(FormatError); finishProtocol(FormatError);
@ -622,33 +634,50 @@ formatOutput()
char command; char command;
const char* fieldName = NULL; const char* fieldName = NULL;
const char* formatstring; const char* formatstring;
int formatstringlen;
outputLine.clear();
while ((command = *commandIndex++) != StreamProtocolParser::eos) while ((command = *commandIndex++) != StreamProtocolParser::eos)
{ {
switch (command) switch (command)
{ {
case StreamProtocolParser::format_field: case StreamProtocolParser::format_field:
{ {
debug("StreamCore::formatOutput(%s): StreamProtocolParser::format_field\n", debug("StreamCore::formatOutput(%s): StreamProtocolParser::redirect_format\n",
name()); name());
// code layout: // code layout:
// field <StreamProtocolParser::eos> addrlen AddressStructure formatstring <StreamProtocolParser::eos> StreamFormat [info] // field <eos> addrlen AddressStructure formatstring <eos> StreamFormat [info]
fieldName = commandIndex; fieldName = commandIndex;
commandIndex += strlen(commandIndex)+1; commandIndex += strlen(commandIndex)+1;
unsigned short addrlen = extract<unsigned short>(commandIndex); unsigned short addrlen = extract<unsigned short>(commandIndex);
fieldAddress.set(commandIndex, addrlen); fieldAddress.set(commandIndex, addrlen);
commandIndex += addrlen; commandIndex += addrlen;
goto normal_format;
} }
case StreamProtocolParser::format: case StreamProtocolParser::format:
{ {
fieldAddress.clear();
normal_format:
// code layout: // code layout:
// formatstring <StreamProtocolParser::eos> StreamFormat [info] // formatstring <eos> StreamFormat [info]
formatstring = commandIndex; formatstring = commandIndex;
while (*commandIndex++); // jump after <StreamProtocolParser::eos> // jump after <eos>
while (*commandIndex)
{
if (*commandIndex == esc) commandIndex++;
commandIndex++;
}
formatstringlen = commandIndex-formatstring;
commandIndex++;
StreamFormat fmt = extract<StreamFormat>(commandIndex); StreamFormat fmt = extract<StreamFormat>(commandIndex);
fmt.info = commandIndex; // point to info string fmt.info = commandIndex; // point to info string
commandIndex += fmt.infolen; commandIndex += fmt.infolen;
#ifndef NO_TEMPORARY
debug("StreamCore::formatOutput(%s): format = %%%s\n", debug("StreamCore::formatOutput(%s): format = %%%s\n",
name(), formatstring); name(), StreamBuffer(formatstring, formatstringlen).expand()());
#endif
if (fmt.type == pseudo_format) if (fmt.type == pseudo_format)
{ {
if (!StreamFormatConverter::find(fmt.conv)-> if (!StreamFormatConverter::find(fmt.conv)->
@ -663,18 +692,21 @@ formatOutput()
flags &= ~Separator; flags &= ~Separator;
if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL)) if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL))
{ {
if (fieldName) StreamBuffer formatstr(formatstring, formatstringlen);
if (fieldAddress)
error("%s: Cannot format field '%s' with '%%%s'\n", error("%s: Cannot format field '%s' with '%%%s'\n",
name(), fieldName, formatstring); name(), fieldName, formatstr.expand()());
else else
error("%s: Cannot format value with '%%%s'\n", error("%s: Cannot format value with '%%%s'\n",
name(), formatstring); name(), formatstr.expand()());
return false; return false;
} }
fieldAddress.clear();
fieldName = NULL;
continue; continue;
} }
case StreamProtocolParser::whitespace:
outputLine.append(' ');
case StreamProtocolParser::skip:
continue;
case esc: case esc:
// escaped literal byte // escaped literal byte
command = *commandIndex++; command = *commandIndex++;
@ -696,19 +728,28 @@ printSeparator()
} }
if (!separator) return; if (!separator) return;
long i = 0; long i = 0;
if (separator[0] == ' ') i++; // ignore leading space
for (; i < separator.length(); i++) for (; i < separator.length(); i++)
{ {
if (separator[i] == StreamProtocolParser::skip) continue; // wildcard switch (separator[i])
if (separator[i] == esc) i++; // escaped literal byte {
outputLine.append(separator[i]); case StreamProtocolParser::whitespace:
outputLine.append(' '); // print single space
case StreamProtocolParser::skip:
continue;
case esc:
// escaped literal byte
i++;
default:
// literal byte
outputLine.append(separator[i]);
}
} }
} }
bool StreamCore:: bool StreamCore::
printValue(const StreamFormat& fmt, long value) printValue(const StreamFormat& fmt, long value)
{ {
if (fmt.type != long_format && fmt.type != enum_format) if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format)
{ {
error("%s: printValue(long) called with %%%c format\n", error("%s: printValue(long) called with %%%c format\n",
name(), fmt.conv); name(), fmt.conv);
@ -722,6 +763,8 @@ printValue(const StreamFormat& fmt, long value)
name(), value); name(), value);
return false; return false;
} }
debug("StreamCore::printValue %s %%%c long %ld (%lx): \"%s\"\n",
name(), fmt.conv, value, value, outputLine.expand()());
return true; return true;
} }
@ -742,6 +785,8 @@ printValue(const StreamFormat& fmt, double value)
name(), value); name(), value);
return false; return false;
} }
debug("StreamCore::printValue %s %%%c double %#g: \"%s\"\n",
name(), fmt.conv, value, outputLine.expand()());
return true; return true;
} }
@ -763,6 +808,8 @@ printValue(const StreamFormat& fmt, char* value)
name(), buffer.expand()()); name(), buffer.expand()());
return false; return false;
} }
debug("StreamCore::printValue %s %%%c char* \"%s\"): \"%s\"\n",
name(), fmt.conv, value, outputLine.expand()());
return true; return true;
} }
@ -771,7 +818,7 @@ lockCallback(StreamIoStatus status)
{ {
MutexLock lock(this); MutexLock lock(this);
debug("StreamCore::lockCallback(%s, status=%s)\n", debug("StreamCore::lockCallback(%s, status=%s)\n",
name(), status ? "Timeout" : "Success"); name(), StreamIoStatusStr[status]);
if (!(flags & LockPending)) if (!(flags & LockPending))
{ {
error("StreamCore::lockCallback(%s) called unexpectedly\n", error("StreamCore::lockCallback(%s) called unexpectedly\n",
@ -780,10 +827,28 @@ lockCallback(StreamIoStatus status)
} }
flags &= ~LockPending; flags &= ~LockPending;
flags |= BusOwner; flags |= BusOwner;
if (status != StreamIoSuccess) switch (status)
{ {
finishProtocol(LockTimeout); case StreamIoSuccess:
return; break;
case StreamIoTimeout:
debug("%s: Cannot lock device within %ld ms, device seems to be busy\n",
name(), lockTimeout);
flags &= ~BusOwner;
finishProtocol(LockTimeout);
return;
case StreamIoFault:
error("%s: Locking failed because of a device fault\n",
name());
flags &= ~BusOwner;
finishProtocol(LockTimeout);
return;
default:
error("StreamCore::lockCallback(%s) unexpected status %s\n",
name(), StreamIoStatusStr[status]);
flags &= ~BusOwner;
finishProtocol(Fault);
return;
} }
flags |= WritePending; flags |= WritePending;
if (!busWriteRequest(outputLine(), outputLine.length(), writeTimeout)) if (!busWriteRequest(outputLine(), outputLine.length(), writeTimeout))
@ -807,8 +872,6 @@ writeCallback(StreamIoStatus status)
flags &= ~WritePending; flags &= ~WritePending;
if (status != StreamIoSuccess) if (status != StreamIoSuccess)
{ {
error("%s: write failed: %s\n",
name(), StreamIoStatusStr[status]);
finishProtocol(WriteTimeout); finishProtocol(WriteTimeout);
return; return;
} }
@ -894,12 +957,17 @@ readCallback(StreamIoStatus status,
if (!(flags & AcceptInput)) if (!(flags & AcceptInput))
{ {
error("StreamCore::readCallback(%s) called unexpectedly\n", #ifdef NO_TEMPORARY
name()); error("StreamCore::readCallback(%s, %s) called unexpectedly\n",
name(), StreamIoStatusStr[status]);
#else
error("StreamCore::readCallback(%s, %s, \"%s\") called unexpectedly\n",
name(), StreamIoStatusStr[status],
StreamBuffer(input, size).expand()());
#endif
return 0; return 0;
} }
flags &= ~AcceptInput; //// flags &= ~AcceptInput;
unparsedInput = false;
switch (status) switch (status)
{ {
case StreamIoTimeout: case StreamIoTimeout:
@ -923,13 +991,13 @@ readCallback(StreamIoStatus status,
evalIn(); evalIn();
return 0; return 0;
} }
error("%s: No reply from device within %ld ms\n", debug("StreamCore::readCallback(%s): No reply from device within %ld ms\n",
name(), replyTimeout); name(), replyTimeout);
inputBuffer.clear(); inputBuffer.clear();
finishProtocol(ReplyTimeout); finishProtocol(ReplyTimeout);
return 0; return 0;
case StreamIoFault: case StreamIoFault:
error("%s: I/O error after reading %ld byte%s: \"%s%s\"\n", error("%s: I/O error after reading %" P "d byte%s: \"%s%s\"\n",
name(), name(),
inputBuffer.length(), inputBuffer.length()==1 ? "" : "s", inputBuffer.length(), inputBuffer.length()==1 ? "" : "s",
inputBuffer.length() > 20 ? "..." : "", inputBuffer.length() > 20 ? "..." : "",
@ -938,7 +1006,7 @@ readCallback(StreamIoStatus status,
return 0; return 0;
} }
inputBuffer.append(input, size); inputBuffer.append(input, size);
debug("StreamCore::readCallback(%s) inputBuffer=\"%s\", size %ld\n", debug("StreamCore::readCallback(%s) inputBuffer=\"%s\", size %" P "d\n",
name(), inputBuffer.expand()(), inputBuffer.length()); name(), inputBuffer.expand()(), inputBuffer.length());
if (*activeCommand != in_cmd) if (*activeCommand != in_cmd)
{ {
@ -956,10 +1024,36 @@ readCallback(StreamIoStatus status,
if (inTerminator) if (inTerminator)
{ {
// look for terminator // look for terminator
end = inputBuffer.find(inTerminator); // performance issue for long inputs that come in chunks:
if (end >= 0) termlen = inTerminator.length(); // do not parse old chunks again or performance decreases to O(n^2)
debug("StreamCore::readCallback(%s) inTerminator %sfound\n", // but make sure to get all terminators in multi-line input
name(), end >= 0 ? "" : "not ");
long start;
if (unparsedInput)
{
// multi-line input sets 'unparsedInput' and removes the line
// remaining unparsed lines are left at start of inputBuffer
start = 0;
}
else
{
// long line does not set 'unparsedInput' but keeps
// already parsed chunks in inputBuffer
// start parsing at beginning of new data
// but beware of split terminators
start = inputBuffer.length() - size - inTerminator.length();
if (start < 0) start = 0;
}
end = inputBuffer.find(inTerminator, start);
if (end >= 0)
{
termlen = inTerminator.length();
debug("StreamCore::readCallback(%s) inTerminator %s at position %ld\n",
name(), inTerminator.expand()(), end);
} else {
debug("StreamCore::readCallback(%s) inTerminator %s not found\n",
name(), inTerminator.expand()());
}
} }
if (status == StreamIoEnd && end < 0) if (status == StreamIoEnd && end < 0)
{ {
@ -981,6 +1075,12 @@ readCallback(StreamIoStatus status,
end = maxInput; end = maxInput;
termlen = 0; termlen = 0;
} }
if (end >= 0)
{
// be forgiving with timeout because end is found
if (status == StreamIoTimeout)
status = StreamIoEnd;
}
if (end < 0) if (end < 0)
{ {
// no end found // no end found
@ -997,23 +1097,23 @@ readCallback(StreamIoStatus status,
} }
// try to parse what we got // try to parse what we got
end = inputBuffer.length(); end = inputBuffer.length();
if (!(flags & AsyncMode)||showAsyncErrors) if (flags & AsyncMode)
{
debug("StreamCore::readCallback(%s) async timeout: just restart\n",
name());
unparsedInput = false;
inputBuffer.clear();
commandIndex = commandStart;
evalIn();
return 0;
}
else
{ {
error("%s: Timeout after reading %ld byte%s \"%s%s\"\n", error("%s: Timeout after reading %ld byte%s \"%s%s\"\n",
name(), end, end==1 ? "" : "s", end > 20 ? "..." : "", name(), end, end==1 ? "" : "s", end > 20 ? "..." : "",
inputBuffer.expand(-20)()); inputBuffer.expand(-20)());
} }
} }
if (status == StreamIoTimeout && (flags & AsyncMode))
{
debug("StreamCore::readCallback(%s) async timeout: just restart\n",
name());
inputBuffer.clear();
commandIndex = commandStart;
evalIn();
return 0;
}
inputLine.set(inputBuffer(), end); inputLine.set(inputBuffer(), end);
debug("StreamCore::readCallback(%s) input line: \"%s\"\n", debug("StreamCore::readCallback(%s) input line: \"%s\"\n",
@ -1026,6 +1126,10 @@ readCallback(StreamIoStatus status,
name(), inputBuffer.expand()()); name(), inputBuffer.expand()());
unparsedInput = true; unparsedInput = true;
} }
else
{
unparsedInput = false;
}
if (!matches) if (!matches)
{ {
if (status == StreamIoTimeout) if (status == StreamIoTimeout)
@ -1054,7 +1158,7 @@ readCallback(StreamIoStatus status,
return 0; return 0;
} }
// end input mode and do next command // end input mode and do next command
flags &= ~(AsyncMode|AcceptInput); //// flags &= ~(AsyncMode|AcceptInput);
// -- should we tell someone that input has finished? -- // -- should we tell someone that input has finished? --
evalCommand(); evalCommand();
return 0; return 0;
@ -1068,7 +1172,8 @@ matchInput()
is installed and starts with 'in' (then we reparse the input). is installed and starts with 'in' (then we reparse the input).
*/ */
char command; char command;
const char* formatstring; const char* fieldName = NULL;
StreamBuffer formatstring;
consumedInput = 0; consumedInput = 0;
@ -1080,29 +1185,39 @@ matchInput()
{ {
// code layout: // code layout:
// field <StreamProtocolParser::eos> addrlen AddressStructure formatstring <StreamProtocolParser::eos> StreamFormat [info] // field <StreamProtocolParser::eos> addrlen AddressStructure formatstring <StreamProtocolParser::eos> StreamFormat [info]
fieldName = commandIndex;
commandIndex += strlen(commandIndex)+1; commandIndex += strlen(commandIndex)+1;
unsigned short addrlen = extract<unsigned short>(commandIndex); unsigned short addrlen = extract<unsigned short>(commandIndex);
fieldAddress.set(commandIndex, addrlen); fieldAddress.set(commandIndex, addrlen);
commandIndex += addrlen; commandIndex += addrlen;
goto normal_format;
} }
case StreamProtocolParser::format: case StreamProtocolParser::format:
{ {
fieldAddress.clear();
normal_format:
int consumed; int consumed;
// code layout: // code layout:
// formatstring <eos> StreamFormat [info] // formatstring <eos> StreamFormat [info]
formatstring = commandIndex; formatstring.clear();
while (*commandIndex++ != StreamProtocolParser::eos); // jump after <eos> commandIndex = StreamProtocolParser::printString(formatstring, commandIndex);
StreamFormat fmt = extract<StreamFormat>(commandIndex); StreamFormat fmt = extract<StreamFormat>(commandIndex);
fmt.info = commandIndex; fmt.info = commandIndex; // point to info string
commandIndex += fmt.infolen; commandIndex += fmt.infolen;
#ifndef NO_TEMPORARY
debug("StreamCore::matchInput(%s): format = \"%%%s\"\n",
name(), formatstring());
#endif
if (fmt.flags & skip_flag || fmt.type == pseudo_format) if (fmt.flags & skip_flag || fmt.type == pseudo_format)
{ {
long ldummy; long ldummy;
double ddummy; double ddummy;
switch (fmt.type) switch (fmt.type)
{ {
case long_format: case unsigned_format:
case signed_format:
case enum_format: case enum_format:
consumed = StreamFormatConverter::find(fmt.conv)-> consumed = StreamFormatConverter::find(fmt.conv)->
scanLong(fmt, inputLine(consumedInput), ldummy); scanLong(fmt, inputLine(consumedInput), ldummy);
@ -1127,42 +1242,100 @@ matchInput()
} }
if (consumed < 0) if (consumed < 0)
{ {
if ((!(flags & AsyncMode)||showAsyncErrors) && onMismatch[0] != in_cmd) if (fmt.flags & default_flag)
{ {
error("%s: Input \"%s%s\" does not match format %%%s\n", consumed = 0;
name(), inputLine.expand(consumedInput, 20)(), }
inputLine.length()-consumedInput > 20 ? "..." : "", else
formatstring); {
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{
error("%s: Input \"%s%s\" does not match format \"%%%s\"\n",
name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring());
}
return false;
}
}
consumedInput += consumed;
break;
}
if (fmt.flags & compare_flag)
{
outputLine.clear();
flags &= ~Separator;
if (!formatValue(fmt, fieldAddress ? fieldAddress() : NULL))
{
if (fieldAddress)
error("%s: Cannot format variable \"%s\" with \"%%%s\"\n",
name(), fieldName, formatstring());
else
error("%s: Cannot format value with \"%%%s\"\n",
name(), formatstring());
return false;
}
#ifndef NO_TEMPORARY
debug("StreamCore::matchInput(%s): compare \"%s\" with \"%s\"\n",
name(), inputLine.expand(consumedInput,
outputLine.length())(), outputLine.expand()());
#endif
if (inputLine.length() - consumedInput < outputLine.length())
{
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{
error("%s: Input \"%s%s\" too short."
" No match for format \"%%%s\" (\"%s\")\n",
name(),
inputLine.length() > 20 ? "..." : "",
inputLine.expand(-20)(),
formatstring(),
outputLine.expand()());
} }
return false; return false;
} }
consumedInput += consumed; if (!outputLine.startswith(inputLine(consumedInput),outputLine.length()))
{
if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{
error("%s: Input \"%s%s\" does not match format \"%%%s\" (\"%s\")\n",
name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring(),
outputLine.expand()());
}
return false;
}
consumedInput += outputLine.length();
break; break;
} }
flags &= ~Separator; flags &= ~Separator;
if (!matchValue(fmt, fieldAddress ? fieldAddress() : NULL)) if (!matchValue(fmt, fieldAddress ? fieldAddress() : NULL))
{ {
if ((!(flags & AsyncMode)||showAsyncErrors) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
if (flags & ScanTried) if (flags & ScanTried)
error("%s: Input \"%s%s\" does not match format %%%s\n", error("%s: Input \"%s%s\" does not match format \"%%%s\"\n",
name(), inputLine.expand(consumedInput, 20)(), name(), inputLine.expand(consumedInput, 20)(),
inputLine.length()-consumedInput > 20 ? "..." : "", inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring); formatstring());
else else
error("%s: Can't scan value with format %%%s\n", error("%s: Format \"%%%s\" has data type %s which does not match the type of \"%s\".\n",
name(), formatstring); name(), formatstring(), StreamFormatTypeStr[fmt.type], fieldAddress ? fieldName : name());
} }
return false; return false;
} }
// matchValue() has already removed consumed bytes from inputBuffer // matchValue() has already removed consumed bytes from inputBuffer
fieldAddress = NULL;
break; break;
} }
case StreamProtocolParser::skip: case StreamProtocolParser::skip:
// ignore next input byte // ignore next input byte
consumedInput++; consumedInput++;
break; break;
case StreamProtocolParser::whitespace:
// any number of whitespace (including 0)
while (isspace(inputLine[consumedInput])) consumedInput++;
break;
case esc: case esc:
// escaped literal byte // escaped literal byte
command = *commandIndex++; command = *commandIndex++;
@ -1172,20 +1345,22 @@ matchInput()
{ {
int i = 0; int i = 0;
while (commandIndex[i] >= ' ') i++; while (commandIndex[i] >= ' ') i++;
if ((!(flags & AsyncMode)||showAsyncErrors) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
error("%s: Input \"%s%s\" too short." error("%s: Input \"%s%s\" too short.\n",
" No match for \"%s\"\n",
name(), name(),
inputLine.length() > 20 ? "..." : "", inputLine.length() > 20 ? "..." : "",
inputLine.expand(-20)(), inputLine.expand(-20)());
#ifndef NO_TEMPORARY
error("No match for \"%s\"\n",
StreamBuffer(commandIndex-1,i+1).expand()()); StreamBuffer(commandIndex-1,i+1).expand()());
#endif
} }
return false; return false;
} }
if (command != inputLine[consumedInput]) if (command != inputLine[consumedInput])
{ {
if ((!(flags & AsyncMode)||showAsyncErrors) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
int i = 0; int i = 0;
while (commandIndex[i] >= ' ') i++; while (commandIndex[i] >= ' ') i++;
@ -1197,10 +1372,12 @@ matchInput()
consumedInput, consumedInput,
consumedInput==1 ? "" : "s"); consumedInput==1 ? "" : "s");
#ifndef NO_TEMPORARY
error("%s: got \"%s\" where \"%s\" was expected\n", error("%s: got \"%s\" where \"%s\" was expected\n",
name(), name(),
inputLine.expand(consumedInput, 20)(), inputLine.expand(consumedInput, 20)(),
StreamBuffer(commandIndex-1,i+1).expand()()); StreamBuffer(commandIndex-1,i+1).expand()());
#endif
} }
return false; return false;
} }
@ -1210,7 +1387,7 @@ matchInput()
long surplus = inputLine.length()-consumedInput; long surplus = inputLine.length()-consumedInput;
if (surplus > 0 && !(flags & IgnoreExtraInput)) if (surplus > 0 && !(flags & IgnoreExtraInput))
{ {
if ((!(flags & AsyncMode)||showAsyncErrors) && onMismatch[0] != in_cmd) if (!(flags & AsyncMode) && onMismatch[0] != in_cmd)
{ {
error("%s: %ld byte%s surplus input \"%s%s\"\n", error("%s: %ld byte%s surplus input \"%s%s\"\n",
name(), surplus, surplus==1 ? "" : "s", name(), surplus, surplus==1 ? "" : "s",
@ -1236,43 +1413,52 @@ matchInput()
bool StreamCore:: bool StreamCore::
matchSeparator() matchSeparator()
{ {
// called before value is read, first value has Separator flag cleared
// for second and next value set Separator flag
if (!separator) {
// empty separator matches
return true;
}
if (!(flags & Separator)) if (!(flags & Separator))
{ {
// before first element, don't expect separator yet
flags |= Separator; flags |= Separator;
return true; return true;
} }
if (!separator) return true; long i;
long i = 0; long j = consumedInput;
if (separator[0] == ' ') for (i = 0; i < separator.length(); i++)
{ {
i++; switch (separator[i])
// skip leading whitespaces {
while (isspace(inputLine[consumedInput++])); case StreamProtocolParser::skip:
j++;
continue;
case StreamProtocolParser::whitespace:
while (isspace(inputLine[j])) j++;
continue;
case esc:
i++;
default:
if (separator[i] != inputLine[j])
{
// no match
// don't complain here, just return false
return false;
}
j++;
}
} }
for (; i < separator.length(); i++,consumedInput++) // separator successfully read
{ consumedInput = j;
if (!inputLine[consumedInput]) return false;
if (separator[i] == StreamProtocolParser::skip) continue; // wildcard
if (separator[i] == esc) i++; // escaped literal byte
if (separator[i] != inputLine[consumedInput]) return false;
}
return true;
}
bool StreamCore::
scanSeparator()
{
// for compatibility only
// read and remove separator
if (!matchSeparator()) return false;
flags &= ~Separator;
return true; return true;
} }
long StreamCore:: long StreamCore::
scanValue(const StreamFormat& fmt, long& value) scanValue(const StreamFormat& fmt, long& value)
{ {
if (fmt.type != long_format && fmt.type != enum_format) if (fmt.type != unsigned_format && fmt.type != signed_format && fmt.type != enum_format)
{ {
error("%s: scanValue(long&) called with %%%c format\n", error("%s: scanValue(long&) called with %%%c format\n",
name(), fmt.conv); name(), fmt.conv);
@ -1284,8 +1470,17 @@ scanValue(const StreamFormat& fmt, long& value)
scanLong(fmt, inputLine(consumedInput), value); scanLong(fmt, inputLine(consumedInput), value);
debug("StreamCore::scanValue(%s, format=%%%c, long) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, long) input=\"%s\"\n",
name(), fmt.conv, inputLine.expand(consumedInput)()); name(), fmt.conv, inputLine.expand(consumedInput)());
if (consumed < 0 || if (consumed < 0)
consumed > inputLine.length()-consumedInput) return -1; {
if (fmt.flags & default_flag)
{
value = 0;
consumed = 0;
}
else return -1;
}
if (fmt.flags & fix_width_flag && consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %li\n", debug("StreamCore::scanValue(%s) scanned %li\n",
name(), value); name(), value);
flags |= GotValue; flags |= GotValue;
@ -1306,9 +1501,18 @@ scanValue(const StreamFormat& fmt, double& value)
long consumed = StreamFormatConverter::find(fmt.conv)-> long consumed = StreamFormatConverter::find(fmt.conv)->
scanDouble(fmt, inputLine(consumedInput), value); scanDouble(fmt, inputLine(consumedInput), value);
debug("StreamCore::scanValue(%s, format=%%%c, double) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, double) input=\"%s\"\n",
name(), fmt.conv, inputLine.expand(consumedInput)()); name(), fmt.conv, inputLine.expand(consumedInput, 20)());
if (consumed < 0 || if (consumed < 0)
consumed > inputLine.length()-consumedInput) return -1; {
if (fmt.flags & default_flag)
{
value = 0.0;
consumed = 0;
}
else return -1;
}
if (fmt.flags & fix_width_flag && (consumed != (fmt.width + fmt.prec + 1))) return -1;
if (consumed > inputLine.length()-consumedInput) return -1;
debug("StreamCore::scanValue(%s) scanned %#g\n", debug("StreamCore::scanValue(%s) scanned %#g\n",
name(), value); name(), value);
flags |= GotValue; flags |= GotValue;
@ -1331,8 +1535,17 @@ scanValue(const StreamFormat& fmt, char* value, long maxlen)
scanString(fmt, inputLine(consumedInput), value, maxlen); scanString(fmt, inputLine(consumedInput), value, maxlen);
debug("StreamCore::scanValue(%s, format=%%%c, char*, maxlen=%ld) input=\"%s\"\n", debug("StreamCore::scanValue(%s, format=%%%c, char*, maxlen=%ld) input=\"%s\"\n",
name(), fmt.conv, maxlen, inputLine.expand(consumedInput)()); name(), fmt.conv, maxlen, inputLine.expand(consumedInput)());
if (consumed < 0 || if (consumed < 0)
consumed > inputLine.length()-consumedInput) return -1; {
if (fmt.flags & default_flag)
{
value[0] = 0;
consumed = 0;
}
else return -1;
}
if (fmt.flags & fix_width_flag && consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1;
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
debug("StreamCore::scanValue(%s) scanned \"%s\"\n", debug("StreamCore::scanValue(%s) scanned \"%s\"\n",
name(), StreamBuffer(value, maxlen).expand()()); name(), StreamBuffer(value, maxlen).expand()());
@ -1444,8 +1657,12 @@ timerCallback()
bool StreamCore:: bool StreamCore::
evalExec() evalExec()
{ {
outputLine.clear(); if (!formatOutput())
formatOutput(); {
finishProtocol(FormatError);
return false;
}
debug ("StreamCore::evalExec: command = \"%s\"\n", outputLine.expand()());
// release bus // release bus
if (flags & BusOwner) if (flags & BusOwner)
{ {
@ -1541,4 +1758,25 @@ disconnectCallback(StreamIoStatus status)
} }
} }
void StreamCore::
printStatus(StreamBuffer& buffer)
{
buffer.print("active command=%s ",
activeCommand ? commandName(*activeCommand) : "NULL");
buffer.print("flags=0x%04lx ", flags);
if (flags & IgnoreExtraInput) buffer.append("IgnoreExtraInput ");
if (flags & InitRun) buffer.append("InitRun ");
if (flags & AsyncMode) buffer.append("AsyncMode ");
if (flags & GotValue) buffer.append("GotValue ");
if (flags & BusOwner) buffer.append("BusOwner ");
if (flags & Separator) buffer.append("Separator ");
if (flags & ScanTried) buffer.append("ScanTried ");
if (flags & AcceptInput) buffer.append("AcceptInput ");
if (flags & AcceptEvent) buffer.append("AcceptEvent ");
if (flags & LockPending) buffer.append("LockPending ");
if (flags & WritePending) buffer.append("WritePending ");
if (flags & WaitPending) buffer.append("WaitPending ");
busPrintStatus(buffer);
}
#include "streamReferences" #include "streamReferences"

View File

@ -139,7 +139,6 @@ protected:
long scanValue(const StreamFormat& format, double& value); long scanValue(const StreamFormat& format, double& value);
long scanValue(const StreamFormat& format, char* value, long maxlen); long scanValue(const StreamFormat& format, char* value, long maxlen);
long scanValue(const StreamFormat& format); long scanValue(const StreamFormat& format);
bool scanSeparator(); // disencouraged
StreamBuffer protocolname; StreamBuffer protocolname;
unsigned long lockTimeout; unsigned long lockTimeout;
@ -220,6 +219,7 @@ public:
bool parse(const char* filename, const char* protocolname); bool parse(const char* filename, const char* protocolname);
void printProtocol(); void printProtocol();
const char* name() { return streamname; } const char* name() { return streamname; }
void printStatus(StreamBuffer& buffer);
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,10 @@
#include "StreamError.h" #include "StreamError.h"
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <stdio.h>
int streamDebug = 0; int streamDebug = 0;
int streamError = 0;
extern "C" { extern "C" {
#ifdef _WIN32 #ifdef _WIN32
__declspec(dllexport) __declspec(dllexport)
@ -58,13 +60,22 @@ void StreamError(const char* fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
StreamVError(fmt, args); StreamVError(0, NULL, fmt, args);
va_end(args); va_end(args);
} }
void StreamVError(const char* fmt, va_list args) void StreamError(int line, const char* file, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
StreamVError(line, file, fmt, args);
va_end(args);
}
void StreamVError(int line, const char* file, const char* fmt, va_list args)
{ {
char timestamp[40]; char timestamp[40];
if (!streamError) return; // Error logging disabled
StreamPrintTimestampFunction(timestamp, 40); StreamPrintTimestampFunction(timestamp, 40);
#ifdef va_copy #ifdef va_copy
if (StreamDebugFile) if (StreamDebugFile)
@ -79,6 +90,10 @@ void StreamVError(const char* fmt, va_list args)
#endif #endif
fprintf(stderr, "\033[31;1m"); fprintf(stderr, "\033[31;1m");
fprintf(stderr, "%s ", timestamp); fprintf(stderr, "%s ", timestamp);
if (file)
{
fprintf(stderr, "%s line %d: ", file, line);
}
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
fprintf(stderr, "\033[0m"); fprintf(stderr, "\033[0m");
} }

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