Compare commits

...

16 Commits

38 changed files with 550 additions and 337 deletions

View File

@ -41,6 +41,12 @@ written or read value.
(=20.0/0xFFFF) maps 0x0000 to -10.0, 0x7FFF to 0.0 and 0xFFFF to 10.0.
Using unsigned formats with values ≥ 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>
<dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd>
@ -78,6 +84,6 @@ written or read value.
<a href="calcout.html">calcout</a>
<a href="scalcout.html">scalcout</a>
</p>
<p><small>Dirk Zimoch, 2005</small></p>
<p><small>Dirk Zimoch, 2015</small></p>
</body>
</html>

View File

@ -40,6 +40,12 @@ written or read value.
(=20.0/0xFFFF) maps -10.0 to 0x0000, 0.0 to 0x7FFF and 10.0 to 0xFFFF.
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>
<dt>ENUM format (e.g. <code>%{</code>):</dt>
<dd>
@ -79,6 +85,6 @@ written or read value.
<a href="calcout.html">calcout</a>
<a href="scalcout.html">scalcout</a>
</p>
<p><small>Dirk Zimoch, 2005</small></p>
<p><small>Dirk Zimoch, 2015</small></p>
</body>
</html>

View File

@ -28,8 +28,8 @@ A format converter consists of
</p>
<ul>
<li>The <code>%</code> character</li>
<li>Optionally a field <span class="new">or record</span> name in <code>()</code></li>
<li>Optionally flags out of the characters <code>*# +0-<span class="new">?=</span></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 an integer <em>width</em> field</li>
<li>Optionally a period character (<code>.</code>) followed
by an integer <em>precision</em> field (input ony for most formats)</li>
@ -40,7 +40,7 @@ A format converter consists of
<p>
The flags <code>*# +0-</code> work like in the C functions
<em>printf()</em> and <em>scanf()</em>.
The flags <code>?</code> and <code>=</code> are extensions.
The flags <code>?</code>, <code>=</code> and <code>!</code> are extensions.
</p>
<p>
The <code>*</code> flag skips data in input formats.
@ -67,16 +67,24 @@ The <code>0</code> flag says that numbers should be left padded with
The <code>-</code> flag specifies that output is left justified if
<em>width</em> is larger than required.
</p>
<p class="new">
<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 class="new">
<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>
<table>
@ -143,11 +151,8 @@ field formatted as a string.
Use <code>in&nbsp;"%(<i>otherrecord</i>.RVAL)f";</code> to write the floating
point input value into the <code>RVAL</code> field of
<code><i>otherrecord</i></code>.
<span class="new">
If no field is given for an other record .VAL is assumed.
When a record name conflicts with a field name use .VAL explicitly.
</span>
</p>
<p>
This feature is very useful when one line of input contains many values that should
@ -158,6 +163,9 @@ attribute (see
target="ex">Record Reference Manual</a>), the record will be processed.
It is your responsibility that the data type of the record field is
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
default field.
At the moment it is not possible to set <code>otherrecord</code> to an alarm
@ -189,13 +197,13 @@ With the <code>#</code> flag, output always contains a period character.
<p>
<b>Input:</b> All these formats are equivalent. Leading whitespaces are skipped.
</p>
<p class="new">
<p>
With the <code>#</code> flag additional whitespace between sign and number
is accepted.
</p>
<p class="new">
<p>
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is given.
field witdth when the space flag is used.
</p>
<a name="stdl"></a>
@ -210,6 +218,10 @@ field witdth when the space flag is given.
<p>
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
@ -221,16 +233,16 @@ Octal and hexadecimal values can optionally be prefixed.
hexadecimal notation.
Leading whitespaces are skipped.
</p>
<p class="new">
<p>
With the <code>-</code> negative octal and hexadecimal values are accepted.
</p>
<p class="new">
<p>
With the <code>#</code> flag additional whitespace between sign and number
is accepted.
</p>
<p class="new">
<p>
When a maximum field width is given, leading whitespace only counts to the
field witdth when the space flag is given.
field witdth when the space flag is used.
</p>
<a name="stds"></a>
@ -246,13 +258,11 @@ and <code>%c</code> matches a sequence of not-null characters.
The maximum string length is given by <em>width</em>.
The default <em>width</em> is infinite for <code>%s</code> and
1 for <code>%c</code>.
Leading whitespaces are skipped with <code>%s</code>
<span class="new">
except when the space flag is given</span>
but not with <code>%c</code>.
Leading whitespaces are skipped with <code>%s</code> except when
the space flag is used but not with <code>%c</code>.
The empty string matches.
</p>
<p class="new">
<p>
With the <code>#</code> flag <code>%s</code> matches a sequence of not-null
characters instead of non-whitespace characters.
</p>
@ -286,9 +296,20 @@ to the value 0, <code>STANDBY</code> to 1 and <code>ON</code> to 2.
<p>
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>
Example: <code>%#{neg=-1|stop=0|pos=1|fast=10}</code>.
If one string is the initial substing of another, the substing must come
later to ensure correct matching.
In particular if one string is the emptry string, it must be the last one.
Use <code>#</code> and <code>=</code> to renumber if necessary.
</p>
<p>
Use the assignment <code>=?</code> for the last string to make it the
default value for output formats.
</p>
<p>
Example: <code>%#{neg=-1|stop|pos|fast=10|rewind=-10}</code>.
</p>
<p>
If one of the strings contains <code>|</code> or <code>}</code>
@ -296,10 +317,11 @@ If one of the strings contains <code>|</code> or <code>}</code>
a <code>\</code> must be used to escape the character.
</p>
<p>
In output, depending on the value, one of the strings is printed.
<b>Output:</b> Depending on the value, one of the strings is printed,
or the default if no value matches.
</p>
<p>
In input, if any of the strings matches the value is set accordingly.
<b>Input:</b> If any of the strings matches, the value is set accordingly.
</p>
<a name="bin"></a>
@ -466,21 +488,24 @@ In input, the next byte or bytes must match the checksum.
(poly=0x07, init=0x00, xorout=0x00).</dd>
<dt><code>%&lt;ccitt8&gt;</code></dt>
<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>
<dd>Two bytes. An often used 16 bit crc checksum
(poly=0x8005, init=0x0000, xorout=0x0000).</dd>
<dt><code>%&lt;crc16r&gt;</code></dt>
<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>
<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
(poly=0x1021, init=0xFFFF, xorout=0x0000).</dd>
<dt><code>%&lt;ccitt16a&gt;</code></dt>
<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.
(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>
@ -491,10 +516,10 @@ In input, the next byte or bytes must match the checksum.
(poly=0x04C11DB7, init=0xFFFFFFFF, xorout=0xFFFFFFFF).</dd>
<dt><code>%&lt;crc32r&gt;</code></dt>
<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>
<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>
<dd>Four bytes. The Adler32 checksum according to <a target="ex"
href="http://www.ietf.org/rfc/rfc1950.txt">RFC 1950</a>.</dd>
@ -565,7 +590,6 @@ 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>
<div class="new">
<a name="timestamp"></a>
<h2>14. Timestamp DOUBLE converter (<code>%T(<em>timeformat</em>)</code>)</h2>
<p>
@ -618,9 +642,8 @@ Because of the complexity of the problem, locales are not supported.
Thus, only the English month names can be used (week day names are
ignored anyway).
</p>
</div>
<hr>
<p align="right"><a href="processing.html">Next: Record Processing</a></p>
<p><small>Dirk Zimoch, 2011</small></p>
<p><small>Dirk Zimoch, 2015</small></p>
</body>
</html>

View File

@ -104,13 +104,8 @@ This marks text you typically type in configuration files etc.
<pre>
Longer code segments are often set in a box.
</pre>
<p>
Important modifications and new features are
<span class="new">highlighted with a yellow background</span>.
Obsolete features are <strike class="new">highlighted and crossed out</strike>.
</p>
<hr>
<p align="right"><a href="setup.html">Next: Setup</a></p>
<p><small>Dirk Zimoch, 2011</small></p>
<p><small>Dirk Zimoch, 2015</small></p>
</body>
</html>

View File

@ -281,7 +281,7 @@ With some more records, you can clean the message record if SEVR is not INVALID.
<code>
record (calcout, "$(DEVICE):clean_1") {<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 (OUT, "$(DEVICE):clean_2.PROC")<br>
}<br>

View File

@ -31,9 +31,9 @@ class BCDConverter : public StreamFormatConverter
};
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::

View File

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

View File

@ -138,38 +138,38 @@ static unsigned int crc_0x8005(const unsigned char* data, unsigned int len, unsi
{
// x^16 + x^15 + x^2 + x^0 (0x8005)
const static unsigned short table[256] = {
0x0000,0x8005,0x800f,0x000a,0x801b,0x001e,0x0014,0x8011,
0x8033,0x0036,0x003c,0x8039,0x0028,0x802d,0x8027,0x0022,
0x8063,0x0066,0x006c,0x8069,0x0078,0x807d,0x8077,0x0072,
0x0050,0x8055,0x805f,0x005a,0x804b,0x004e,0x0044,0x8041,
0x80c3,0x00c6,0x00cc,0x80c9,0x00d8,0x80dd,0x80d7,0x00d2,
0x00f0,0x80f5,0x80ff,0x00fa,0x80eb,0x00ee,0x00e4,0x80e1,
0x00a0,0x80a5,0x80af,0x00aa,0x80bb,0x00be,0x00b4,0x80b1,
0x8093,0x0096,0x009c,0x8099,0x0088,0x808d,0x8087,0x0082,
0x8183,0x0186,0x018c,0x8189,0x0198,0x819d,0x8197,0x0192,
0x01b0,0x81b5,0x81bf,0x01ba,0x81ab,0x01ae,0x01a4,0x81a1,
0x01e0,0x81e5,0x81ef,0x01ea,0x81fb,0x01fe,0x01f4,0x81f1,
0x81d3,0x01d6,0x01dc,0x81d9,0x01c8,0x81cd,0x81c7,0x01c2,
0x0140,0x8145,0x814f,0x014a,0x815b,0x015e,0x0154,0x8151,
0x8173,0x0176,0x017c,0x8179,0x0168,0x816d,0x8167,0x0162,
0x8123,0x0126,0x012c,0x8129,0x0138,0x813d,0x8137,0x0132,
0x0110,0x8115,0x811f,0x011a,0x810b,0x010e,0x0104,0x8101,
0x8303,0x0306,0x030c,0x8309,0x0318,0x831d,0x8317,0x0312,
0x0330,0x8335,0x833f,0x033a,0x832b,0x032e,0x0324,0x8321,
0x0360,0x8365,0x836f,0x036a,0x837b,0x037e,0x0374,0x8371,
0x8353,0x0356,0x035c,0x8359,0x0348,0x834d,0x8347,0x0342,
0x03c0,0x83c5,0x83cf,0x03ca,0x83db,0x03de,0x03d4,0x83d1,
0x83f3,0x03f6,0x03fc,0x83f9,0x03e8,0x83ed,0x83e7,0x03e2,
0x83a3,0x03a6,0x03ac,0x83a9,0x03b8,0x83bd,0x83b7,0x03b2,
0x0390,0x8395,0x839f,0x039a,0x838b,0x038e,0x0384,0x8381,
0x0280,0x8285,0x828f,0x028a,0x829b,0x029e,0x0294,0x8291,
0x82b3,0x02b6,0x02bc,0x82b9,0x02a8,0x82ad,0x82a7,0x02a2,
0x82e3,0x02e6,0x02ec,0x82e9,0x02f8,0x82fd,0x82f7,0x02f2,
0x02d0,0x82d5,0x82df,0x02da,0x82cb,0x02ce,0x02c4,0x82c1,
0x8243,0x0246,0x024c,0x8249,0x0258,0x825d,0x8257,0x0252,
0x0270,0x8275,0x827f,0x027a,0x826b,0x026e,0x0264,0x8261,
0x0220,0x8225,0x822f,0x022a,0x823b,0x023e,0x0234,0x8231,
0x8213,0x0216,0x021c,0x8219,0x0208,0x820d,0x8207,0x0202 };
0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202 };
while (len--) crc = table[((crc>>8) ^ *data++) & 0xFF] ^ (crc << 8);
return crc;
@ -180,38 +180,38 @@ static unsigned int crc_0x8005_r(const unsigned char* data, unsigned int len, un
// x^16 + x^15 + x^2 + x^0 (0x8005)
// reflected
const static unsigned short table[256] = {
0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241,
0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440,
0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40,
0x0A00,0xCAC1,0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841,
0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,0x1A40,
0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41,
0x1400,0xD4C1,0xD581,0x1540,0xD701,0x17C0,0x1680,0xD641,
0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040,
0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240,
0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441,
0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41,
0xFA01,0x3AC0,0x3B80,0xFB41,0x3900,0xF9C1,0xF881,0x3840,
0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41,
0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40,
0xE401,0x24C0,0x2580,0xE541,0x2700,0xE7C1,0xE681,0x2640,
0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041,
0xA001,0x60C0,0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240,
0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,0xA441,
0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41,
0xAA01,0x6AC0,0x6B80,0xAB41,0x6900,0xA9C1,0xA881,0x6840,
0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41,
0xBE01,0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40,
0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,0xB681,0x7640,
0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041,
0x5000,0x90C1,0x9181,0x5140,0x9301,0x53C0,0x5280,0x9241,
0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440,
0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40,
0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,0x59C0,0x5880,0x9841,
0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40,
0x4E00,0x8EC1,0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41,
0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,0x8641,
0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040 };
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 };
while (len--) crc = table[(crc ^ *data++) & 0xFF] ^ (crc >> 8);
return crc;
@ -469,6 +469,7 @@ static checksum checksumMap[] =
{"ccitt8", crc_0x31, 0x00, 0x00, 1}, // 0xA1
{"crc16", crc_0x8005, 0x0000, 0x0000, 2}, // 0xFEE8
{"crc16r", crc_0x8005_r, 0x0000, 0x0000, 2}, // 0xBB3D
{"modbus", crc_0x8005_r, 0xFFFF, 0x0000, 2}, // 0x4B37
{"ccitt16", crc_0x1021, 0xFFFF, 0x0000, 2}, // 0x29B1
{"ccitt16a",crc_0x1021, 0x1D0F, 0x0000, 2}, // 0xE5CC
{"ccitt16x",crc_0x1021, 0x0000, 0x0000, 2}, // 0x31C3

View File

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

View File

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

View File

@ -749,7 +749,7 @@ printSeparator()
bool StreamCore::
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",
name(), fmt.conv);
@ -1216,7 +1216,8 @@ normal_format:
double ddummy;
switch (fmt.type)
{
case long_format:
case unsigned_format:
case signed_format:
case enum_format:
consumed = StreamFormatConverter::find(fmt.conv)->
scanLong(fmt, inputLine(consumedInput), ldummy);
@ -1457,7 +1458,7 @@ matchSeparator()
long StreamCore::
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",
name(), fmt.conv);
@ -1478,6 +1479,7 @@ scanValue(const StreamFormat& fmt, long& value)
}
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",
name(), value);
@ -1509,6 +1511,7 @@ scanValue(const StreamFormat& fmt, double& value)
}
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",
name(), value);
@ -1541,6 +1544,7 @@ scanValue(const StreamFormat& fmt, char* value, long maxlen)
}
else return -1;
}
if (fmt.flags & fix_width_flag && consumed != fmt.width) return -1;
if (consumed > inputLine.length()-consumedInput) return -1;
#ifndef NO_TEMPORARY
debug("StreamCore::scanValue(%s) scanned \"%s\"\n",

View File

@ -751,21 +751,16 @@ process()
bool Stream::
print(format_t *format, va_list ap)
{
long lval;
double dval;
char* sval;
switch (format->type)
{
case DBF_ENUM:
case DBF_ULONG:
case DBF_LONG:
lval = va_arg(ap, long);
return printValue(*format->priv, lval);
case DBF_ENUM:
return printValue(*format->priv, va_arg(ap, long));
case DBF_DOUBLE:
dval = va_arg(ap, double);
return printValue(*format->priv, dval);
return printValue(*format->priv, va_arg(ap, double));
case DBF_STRING:
sval = va_arg(ap, char*);
return printValue(*format->priv, sval);
return printValue(*format->priv, va_arg(ap, char*));
}
error("INTERNAL ERROR (%s): Illegal format type\n", name());
return false;
@ -775,27 +770,22 @@ bool Stream::
scan(format_t *format, void* value, size_t maxStringSize)
{
// called by streamScanfN
long* lptr;
double* dptr;
char* sptr;
// first remove old value from inputLine (if we are scanning arrays)
consumedInput += currentValueLength;
currentValueLength = 0;
switch (format->type)
{
case DBF_ULONG:
case DBF_LONG:
case DBF_ENUM:
lptr = (long*)value;
currentValueLength = scanValue(*format->priv, *lptr);
currentValueLength = scanValue(*format->priv, *(long*)value);
break;
case DBF_DOUBLE:
dptr = (double*)value;
currentValueLength = scanValue(*format->priv, *dptr);
currentValueLength = scanValue(*format->priv, *(double*)value);
break;
case DBF_STRING:
sptr = (char*)value;
currentValueLength = scanValue(*format->priv, sptr,
currentValueLength = scanValue(*format->priv, (char*)value,
maxStringSize);
break;
default:
@ -979,9 +969,9 @@ getFieldAddress(const char* fieldname, StreamBuffer& address)
}
static const unsigned char dbfMapping[] =
{0, DBF_LONG, DBF_ENUM, DBF_DOUBLE, DBF_STRING};
{0, DBF_ULONG, DBF_LONG, DBF_ENUM, DBF_DOUBLE, DBF_STRING};
static const short typeSize[] =
{0, sizeof(epicsInt32), sizeof(epicsUInt16),
{0, sizeof(epicsUInt32), sizeof(epicsInt32), sizeof(epicsUInt16),
sizeof(epicsFloat64), MAX_STRING_SIZE};
bool Stream::
@ -993,6 +983,9 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
// -- TO DO: If SCAN is "I/O Intr" and record has not been processed, --
// -- do it now to get the latest value (only for output records?) --
format_s fmt;
fmt.type = dbfMapping[format.type];
fmt.priv = &format;
if (fieldaddress)
{
// Format like "%([record.]field)..." has requested to get value
@ -1025,7 +1018,6 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
}
/* convert type to LONG, ENUM, DOUBLE, or STRING */
int type = dbfMapping[format.type];
long nelem = pdbaddr->no_elements;
size_t size = nelem * typeSize[format.type];
@ -1040,13 +1032,13 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
nelem,
pdbaddr->field_size,
pamapdbfType[pdbaddr->field_type].strvalue);
type = DBF_CHAR;
fmt.type = DBF_CHAR;
size = nelem;
}
char* buffer = fieldBuffer.clear().reserve(size);
if (dbGet(pdbaddr, type, buffer,
if (dbGet(pdbaddr, fmt.type, buffer,
NULL, &nelem, NULL) != 0)
{
error("%s: dbGet(%s.%s, %s) failed\n",
@ -1060,7 +1052,7 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
name(),nelem);
/* terminate CHAR array as string */
if (type == DBF_CHAR)
if (fmt.type == DBF_CHAR)
{
if (nelem >= pdbaddr->no_elements) nelem = pdbaddr->no_elements-1;
buffer[nelem] = 0;
@ -1077,7 +1069,12 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
(long)((epicsUInt16*)buffer)[i]))
return false;
break;
case long_format:
case unsigned_format:
if (!printValue(format,
(long)((epicsUInt32*)buffer)[i]))
return false;
break;
case signed_format:
if (!printValue(format,
(long)((epicsInt32*)buffer)[i]))
return false;
@ -1104,9 +1101,6 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
}
return true;
}
format_s fmt;
fmt.type = dbfMapping[format.type];
fmt.priv = &format;
debug("Stream::formatValue(%s) format=%%%c type=%s\n",
name(), format.conv, pamapdbfType[fmt.type].strvalue);
if (!writeData)
@ -1132,7 +1126,10 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
char* buffer;
int status;
const char* putfunc;
format_s fmt;
fmt.type = dbfMapping[format.type];
fmt.priv = &format;
if (fieldaddress)
{
// Format like "%([record.]field)..." has requested to put value
@ -1148,12 +1145,24 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
name(), fieldBuffer.expand()());
switch (format.type)
{
case long_format:
case unsigned_format:
{
consumed = scanValue(format, lval);
if (consumed >= 0) ((epicsUInt32*)buffer)[nord] = lval;
debug("Stream::matchValue(%s): %s.%s[%li] = %lu\n",
name(), pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
nord, lval);
break;
}
case signed_format:
{
consumed = scanValue(format, lval);
if (consumed >= 0) ((epicsInt32*)buffer)[nord] = lval;
debug("Stream::matchValue(%s): %s[%li] = %li\n",
name(), pdbaddr->precord->name, nord, lval);
debug("Stream::matchValue(%s): %s.%s[%li] = %li\n",
name(), pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
nord, lval);
break;
}
case enum_format:
@ -1161,8 +1170,10 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
consumed = scanValue(format, lval);
if (consumed >= 0)
((epicsUInt16*)buffer)[nord] = (epicsUInt16)lval;
debug("Stream::matchValue(%s): %s[%li] = %li\n",
name(), pdbaddr->precord->name, nord, lval);
debug("Stream::matchValue(%s): %s.%s[%li] = %li\n",
name(), pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
nord, lval);
break;
}
case double_format:
@ -1175,18 +1186,34 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
if (consumed >= 0)
memcpy(((epicsFloat64*)buffer)+nord,
&f64, sizeof(f64));
debug("Stream::matchValue(%s): %s[%li] = %#g %#g\n",
name(), pdbaddr->precord->name, nord, dval,
debug("Stream::matchValue(%s): %s.%s[%li] = %#g %#g\n",
name(), pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
nord, dval,
((epicsFloat64*)buffer)[nord]);
break;
}
case string_format:
{
consumed = scanValue(format,
buffer+MAX_STRING_SIZE*nord, MAX_STRING_SIZE);
debug("Stream::matchValue(%s): %s[%li] = \"%.*s\"\n",
name(), pdbaddr->precord->name, nord,
MAX_STRING_SIZE, buffer+MAX_STRING_SIZE*nord);
if (pdbaddr->field_type == DBF_CHAR)
{
// string to char array
consumed = scanValue(format, buffer, nelem);
debug("Stream::matchValue(%s): %s.%s = \"%.*s\"\n",
name(), pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
(int)consumed, buffer);
nord = nelem;
}
else
{
consumed = scanValue(format,
buffer+MAX_STRING_SIZE*nord, MAX_STRING_SIZE);
debug("Stream::matchValue(%s): %s.%s[%li] = \"%.*s\"\n",
name(), pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
nord, MAX_STRING_SIZE, buffer+MAX_STRING_SIZE*nord);
}
break;
}
default:
@ -1223,15 +1250,17 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
name());
return false;
}
/* convert from Unix epoch (1 Jan 1970) to EPICS epoch (1 Jan 1990) */
dval = dval-631152000u;
pdbaddr->precord->time.secPastEpoch = (long)dval;
// rouding: we don't have 9 digits precision
// in a double of today's number of seconds
pdbaddr->precord->time.nsec = (long)((dval-(long)dval)*1e6)*1000;
debug("Stream::matchValue(%s): writing %i.%i to TIME field\n",
debug("Stream::matchValue(%s): writing %i.%i to %s.TIME field\n",
name(),
pdbaddr->precord->time.secPastEpoch,
pdbaddr->precord->time.nsec);
pdbaddr->precord->time.nsec,
pdbaddr->precord->name);
pdbaddr->precord->tse = epicsTimeEventDeviceTime;
return true;
#else
@ -1240,18 +1269,19 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
return false;
#endif
}
if (format.type == string_format &&
(pdbaddr->field_type == DBF_CHAR || pdbaddr->field_type == DBF_UCHAR))
{
/* write strings to [U]CHAR arrays */
nord = consumed;
fmt.type = DBF_CHAR;
}
if (pdbaddr->precord == record || INIT_RUN)
{
// write into own record, thus don't process it
// in @init we must not process other record
debug("Stream::matchValue(%s): dbPut(%s.%s,%s)\n",
name(),
pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
fieldBuffer.expand()());
putfunc = "dbPut";
status = dbPut(pdbaddr, dbfMapping[format.type], buffer, nord);
status = dbPut(pdbaddr, fmt.type, buffer, nord);
if (INIT_RUN && pdbaddr->precord != record)
{
// clean error status of other record in @init
@ -1263,41 +1293,44 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
else
{
// write into other record, thus process it
debug("Stream::matchValue(%s): dbPutField(%s.%s,%s)\n",
name(),
pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
fieldBuffer.expand()());
putfunc = "dbPutField";
status = dbPutField(pdbaddr, dbfMapping[format.type],
status = dbPutField(pdbaddr, fmt.type,
buffer, nord);
}
debug("Stream::matchValue(%s): %s(%s.%s, %s, %s) status=0x%x\n",
name(), putfunc,
pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
pamapdbfType[fmt.type].strvalue,
fieldBuffer.expand()(),
status);
if (status != 0)
{
flags &= ~ScanTried;
switch (format.type)
switch (fmt.type)
{
case long_format:
case enum_format:
case DBF_ULONG:
case DBF_LONG:
case DBF_ENUM:
error("%s: %s(%s.%s, %s, %li) failed\n",
putfunc, name(), pdbaddr->precord->name,
name(), putfunc, pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
pamapdbfType[dbfMapping[format.type]].strvalue,
pamapdbfType[fmt.type].strvalue,
lval);
return false;
case double_format:
case DBF_DOUBLE:
error("%s: %s(%s.%s, %s, %#g) failed\n",
putfunc, name(), pdbaddr->precord->name,
name(), putfunc, pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
pamapdbfType[dbfMapping[format.type]].strvalue,
pamapdbfType[fmt.type].strvalue,
dval);
return false;
case string_format:
error("%s: %s(%s.%s, %s, \"%s\") failed\n",
putfunc, name(), pdbaddr->precord->name,
case DBF_STRING:
error("%s: %s(%s.%s, %s, \"%.*s\") failed\n",
name(), putfunc, pdbaddr->precord->name,
((dbFldDes*)pdbaddr->pfldDes)->name,
pamapdbfType[dbfMapping[format.type]].strvalue,
buffer);
pamapdbfType[fmt.type].strvalue,
(int)consumed, buffer);
return false;
default:
return false;
@ -1306,9 +1339,6 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
return true;
}
// no fieldaddress (the "normal" case)
format_s fmt;
fmt.type = dbfMapping[format.type];
fmt.priv = &format;
if (!readData)
{
error("%s: No readData() function provided\n", name());

View File

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

View File

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

View File

@ -26,7 +26,8 @@
#include "StreamError.h"
const char* StreamFormatTypeStr[] = {
"none", "long", "enum", "double", "string", "pseudo"
// must match the order in StreamFormat.h
"none", "unsigned", "signed", "enum", "double", "string", "pseudo"
};
class StreamProtocolParser::Protocol::Variable
@ -1438,7 +1439,7 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
// parsing failed
return false;
}
if (type < long_format && type > pseudo_format)
if (type < 1 && type > pseudo_format)
{
error(line, filename(),
"Illegal format type %d returned from '%%%c' converter\n",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,16 +19,16 @@
* *
***************************************************************/
#include "devStream.h"
#include <mbboDirectRecord.h>
#include "devStream.h"
#include <epicsExport.h>
static long readData (dbCommon *record, format_t *format)
{
mbboDirectRecord *mbboD = (mbboDirectRecord *) record;
long val;
unsigned long val;
if (format->type == DBF_LONG)
if (format->type == DBF_ULONG || format->type == DBF_LONG)
{
if (streamScanf (record, format, &val)) return ERROR;
if (mbboD->mask)
@ -53,7 +53,7 @@ static long writeData (dbCommon *record, format_t *format)
mbboDirectRecord *mbboD = (mbboDirectRecord *) record;
long val;
if (format->type == DBF_LONG)
if (format->type == DBF_ULONG || format->type == DBF_LONG)
{
if (mbboD->mask) val = mbboD->rval & mbboD->mask;
else val = mbboD->val;

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,7 @@ proc startioc {} {
if [info exists asynversion] {
puts $fd "require asyn,$asynversion"
}
puts $fd "require stream2,$streamversion"
puts $fd "require stream,$streamversion"
} else {
puts $fd "#!../O.$env(EPICS_HOST_ARCH)/streamApp"
puts $fd "dbLoadDatabase ../O.Common/streamApp.dbd"
@ -77,7 +77,9 @@ proc startioc {} {
}
fconfigure $ioc -blocking yes -buffering none
debugmsg "waiting to connect"
set timer [after 1000 {puts stderr "\033\[31;7mCannot start IOC.\033\[0m"; exit 1}]
vwait sock
after cancel $timer
}
set lastcommand ""

View File

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

View File

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

View File

@ -68,15 +68,15 @@ ioccmd {dbpf DZ:lo 12345}
assure "12345 12345 012345 3039 003039 11000000111001 11000000111001 111001 !!......!!!..! !!......!!!..!\n"
ioccmd {dbpf DZ:lo -1}
if {$tcl_platform(machine) == "x86_64"} {
assure "-1 -1 -00001 ffffffffffffffff FFFFFFFFFFFFFFFF 1111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
assure "-1 -1 -00001 ffffffffffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
} else {
assure "-1 -1 -00001 ffffffff FFFFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
assure "-1 -1 -00001 ffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
}
ioccmd {dbpf DZ:lo -1234}
if {$tcl_platform(machine) == "x86_64"} {
assure "-1234 -1234 -01234 fffffffffffffb2e FFFFFFFFFFFFFB2E 1111111111111111111111111111111111111111111111111111101100101110 1111111111111111111111111111111111111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
assure "-1234 -1234 -01234 fffffffffffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
} else {
assure "-1234 -1234 -01234 fffffb2e FFFFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
assure "-1234 -1234 -01234 fffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
}
ioccmd {dbpf DZ:lo 255}
assure "255 255 000255 ff 0000FF 11111111 11111111 111111 !!!!!!!! !!!!!!!!\n"

View File

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

View File

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