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.

This commit is contained in:
zimoch
2015-08-31 15:25:23 +00:00
parent e651c99697
commit 950d75ba43
25 changed files with 257 additions and 172 deletions

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,11 +33,16 @@ 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')
{ {
// default characters 0 and 1 for %b
info.append("01");
return unsigned_format;
}
// user defined characters for %B (next 2 in source) // user defined characters for %B (next 2 in source)
if (*source) if (*source)
{ {
@ -46,37 +52,40 @@ parse(const StreamFormat& format, StreamBuffer& info,
{ {
if (*source == esc) source++; if (*source == esc) source++;
info.append(*source++); info.append(*source++);
return long_format; return unsigned_format;
} }
} }
error("Missing characters after %%B format conversion\n"); error("Missing characters after %%B format conversion\n");
return false; return false;
}
// default characters for %b
info.append("01");
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 & (1L << (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];
char fill = (format.flags & zero_flag) ? zero : ' '; char fill = (fmt.flags & zero_flag) ? zero : ' ';
if (format.flags & alt_flag) if (fmt.flags & alt_flag)
{ {
// little endian (least significant bit first) // little endian (least significant bit first)
if (!(format.flags & left_flag)) if (!(fmt.flags & left_flag))
{ {
// pad left // pad left
while (width > prec) while (width > prec)
@ -100,7 +109,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
else else
{ {
// big endian (most significant bit first) // big endian (most significant bit first)
if (!(format.flags & left_flag)) if (!(fmt.flags & left_flag))
{ {
// pad left // pad left
while (width > prec) while (width > prec)
@ -124,18 +133,18 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
} }
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;
char zero = format.info[0]; char zero = fmt.info[0];
char one = format.info[1]; char one = fmt.info[1];
if (!isspace(zero) && !isspace(one)) if (!isspace(zero) && !isspace(one))
while (isspace(input[length])) length++; // skip whitespaces 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;
if (format.flags & alt_flag) if (fmt.flags & alt_flag)
{ {
// little endian (least significan bit first) // little endian (least significan bit first)
long mask = 1; long mask = 1;

View File

@ -31,23 +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 (prec > (int)sizeof(long)) prec=sizeof(long); 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; char byte = 0;
if (format.flags & alt_flag) // little endian (lsb first) if (fmt.flags & alt_flag) // little endian (lsb first)
{ {
while (prec--) while (prec--)
{ {
@ -56,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;
@ -73,7 +73,7 @@ printLong(const StreamFormat& format, StreamBuffer& output, long value)
} }
else // big endian (msb first) 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;
@ -97,17 +97,17 @@ 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 (lsb first) // little endian (lsb first)
unsigned int shift = 0; unsigned int shift = 0;
@ -118,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;
@ -134,7 +134,7 @@ scanLong(const StreamFormat& format, const char* input, long& value)
else else
{ {
// big endian (msb first) // 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++];

View File

@ -749,7 +749,7 @@ printSeparator()
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);
@ -1216,7 +1216,8 @@ normal_format:
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);
@ -1457,7 +1458,7 @@ matchSeparator()
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);

View File

@ -751,21 +751,16 @@ process()
bool Stream:: bool Stream::
print(format_t *format, va_list ap) print(format_t *format, va_list ap)
{ {
long lval;
double dval;
char* sval;
switch (format->type) switch (format->type)
{ {
case DBF_ENUM: case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
lval = va_arg(ap, long); case DBF_ENUM:
return printValue(*format->priv, lval); return printValue(*format->priv, va_arg(ap, long));
case DBF_DOUBLE: case DBF_DOUBLE:
dval = va_arg(ap, double); return printValue(*format->priv, va_arg(ap, double));
return printValue(*format->priv, dval);
case DBF_STRING: case DBF_STRING:
sval = va_arg(ap, char*); return printValue(*format->priv, va_arg(ap, char*));
return printValue(*format->priv, sval);
} }
error("INTERNAL ERROR (%s): Illegal format type\n", name()); error("INTERNAL ERROR (%s): Illegal format type\n", name());
return false; return false;
@ -775,27 +770,22 @@ bool Stream::
scan(format_t *format, void* value, size_t maxStringSize) scan(format_t *format, void* value, size_t maxStringSize)
{ {
// called by streamScanfN // called by streamScanfN
long* lptr;
double* dptr;
char* sptr;
// first remove old value from inputLine (if we are scanning arrays) // first remove old value from inputLine (if we are scanning arrays)
consumedInput += currentValueLength; consumedInput += currentValueLength;
currentValueLength = 0; currentValueLength = 0;
switch (format->type) switch (format->type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
lptr = (long*)value; currentValueLength = scanValue(*format->priv, *(long*)value);
currentValueLength = scanValue(*format->priv, *lptr);
break; break;
case DBF_DOUBLE: case DBF_DOUBLE:
dptr = (double*)value; currentValueLength = scanValue(*format->priv, *(double*)value);
currentValueLength = scanValue(*format->priv, *dptr);
break; break;
case DBF_STRING: case DBF_STRING:
sptr = (char*)value; currentValueLength = scanValue(*format->priv, (char*)value,
currentValueLength = scanValue(*format->priv, sptr,
maxStringSize); maxStringSize);
break; break;
default: default:
@ -979,9 +969,9 @@ getFieldAddress(const char* fieldname, StreamBuffer& address)
} }
static const unsigned char dbfMapping[] = 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[] = static const short typeSize[] =
{0, sizeof(epicsInt32), sizeof(epicsUInt16), {0, sizeof(epicsUInt32), sizeof(epicsInt32), sizeof(epicsUInt16),
sizeof(epicsFloat64), MAX_STRING_SIZE}; sizeof(epicsFloat64), MAX_STRING_SIZE};
bool Stream:: bool Stream::
@ -1079,7 +1069,12 @@ formatValue(const StreamFormat& format, const void* fieldaddress)
(long)((epicsUInt16*)buffer)[i])) (long)((epicsUInt16*)buffer)[i]))
return false; return false;
break; break;
case long_format: case unsigned_format:
if (!printValue(format,
(long)((epicsUInt32*)buffer)[i]))
return false;
break;
case signed_format:
if (!printValue(format, if (!printValue(format,
(long)((epicsInt32*)buffer)[i])) (long)((epicsInt32*)buffer)[i]))
return false; return false;
@ -1150,7 +1145,17 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
name(), fieldBuffer.expand()()); name(), fieldBuffer.expand()());
switch (format.type) 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); consumed = scanValue(format, lval);
if (consumed >= 0) ((epicsInt32*)buffer)[nord] = lval; if (consumed >= 0) ((epicsInt32*)buffer)[nord] = lval;
@ -1304,6 +1309,7 @@ matchValue(const StreamFormat& format, const void* fieldaddress)
flags &= ~ScanTried; flags &= ~ScanTried;
switch (fmt.type) switch (fmt.type)
{ {
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
case DBF_ENUM: case DBF_ENUM:
error("%s: %s(%s.%s, %s, %li) failed\n", error("%s: %s(%s.%s, %s, %li) failed\n",

View File

@ -34,11 +34,12 @@ typedef enum {
} StreamFormatFlag; } StreamFormatFlag;
typedef enum { typedef enum {
long_format = 1, unsigned_format = 1,
enum_format = 2, signed_format,
double_format = 3, enum_format,
string_format = 4, double_format,
pseudo_format = 5 string_format,
pseudo_format
} StreamFormatType; } StreamFormatType;
extern const char* StreamFormatTypeStr[]; extern const char* StreamFormatTypeStr[];

View File

@ -21,6 +21,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h>
#include "StreamFormatConverter.h" #include "StreamFormatConverter.h"
#include "StreamError.h" #include "StreamError.h"
@ -310,14 +311,16 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
info.append('l'); info.append('l');
info.append(fmt.conv); info.append(fmt.conv);
} }
return long_format; if (fmt.conv == 'd' || fmt.conv == 'i') return signed_format;
return unsigned_format;
} }
bool StdLongConverter:: bool StdLongConverter::
printLong(const StreamFormat& fmt, StreamBuffer& output, long value) printLong(const StreamFormat& fmt, StreamBuffer& output, long value)
{ {
if (tolower(fmt.conv) == 'x' && fmt.width && fmt.width < 2*sizeof(long)) // limits %x/%X formats to number of half bytes in width.
value &= ~(-1L << (fmt.width<<2)); if (fmt.width && (fmt.conv == 'x' || fmt.conv == 'X') && fmt.width < 2*sizeof(long))
value &= ~(-1L << (fmt.width*4));
output.print(fmt.info, value); output.print(fmt.info, value);
return true; return true;
} }
@ -329,6 +332,7 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
int length; int length;
bool neg; bool neg;
int base; int base;
long v;
length = prepareval(fmt, input, neg); length = prepareval(fmt, input, neg);
if (length < 0) return -1; if (length < 0) return -1;
@ -338,14 +342,11 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
base = 10; base = 10;
break; break;
case 'o': case 'o':
base = 8;
goto signcheck;
case 'x': case 'x':
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; if (neg && !(fmt.flags & left_flag)) return -1;
base = (fmt.conv == 'o') ? 8 : 16;
break; break;
case 'u': case 'u':
if (neg) return -1; if (neg) return -1;
@ -354,10 +355,10 @@ signcheck:
default: default:
base = 0; base = 0;
} }
value = strtoul(input, &end, base); v = strtoul(input, &end, base);
if (neg) value = -value;
if (end == input) return -1; if (end == input) return -1;
length += end-input; length += end-input;
value = neg ? -v : v;
return length; return length;
} }
@ -545,7 +546,7 @@ parse(const StreamFormat& fmt, StreamBuffer& info,
info.append("%n"); info.append("%n");
return string_format; return string_format;
} }
return long_format; return unsigned_format;
} }
bool StdCharsConverter:: bool StdCharsConverter::

View File

@ -26,7 +26,8 @@
#include "StreamError.h" #include "StreamError.h"
const char* StreamFormatTypeStr[] = { 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 class StreamProtocolParser::Protocol::Variable
@ -1438,7 +1439,7 @@ compileFormat(StreamBuffer& buffer, const char*& formatstr,
// parsing failed // parsing failed
return false; return false;
} }
if (type < long_format && type > pseudo_format) if (type < 1 && type > pseudo_format)
{ {
error(line, filename(), error(line, filename(),
"Illegal format type %d returned from '%%%c' converter\n", "Illegal format type %d returned from '%%%c' converter\n",

View File

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

View File

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

View File

@ -18,11 +18,18 @@
* * * *
***************************************************************/ ***************************************************************/
#include "devStream.h" #include <math.h>
#include <aiRecord.h>
#include <menuConvert.h> #include <menuConvert.h>
#include <aiRecord.h>
#include "devStream.h"
#include <epicsExport.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) static long readData (dbCommon *record, format_t *format)
{ {
aiRecord *ai = (aiRecord *) record; aiRecord *ai = (aiRecord *) record;
@ -33,25 +40,28 @@ static long readData (dbCommon *record, format_t *format)
{ {
double val; double val;
if (streamScanf (record, format, &val)) return ERROR; if (streamScanf (record, format, &val)) return ERROR;
if (ai->aslo != 0.0) val *= ai->aslo; if (ai->aslo != 0.0 && ai->aslo != 1.0) val *= ai->aslo;
val += ai->aoff; 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); val = ai->val * ai->smoo + val * (1.0 - ai->smoo);
}
ai->val = val; ai->val = val;
return DO_NOT_CONVERT; return DO_NOT_CONVERT;
} }
case DBF_ULONG:
case DBF_LONG: case DBF_LONG:
{ {
long rval; long rval;
if (streamScanf (record, format, &rval)) return ERROR; if (streamScanf (record, format, &rval)) return ERROR;
ai->rval = rval;
if (ai->linr == menuConvertNO_CONVERSION) 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; return DO_NOT_CONVERT;
} }
ai->rval = rval;
return OK; return OK;
} }
} }
@ -61,23 +71,32 @@ static long readData (dbCommon *record, format_t *format)
static long writeData (dbCommon *record, format_t *format) static long writeData (dbCommon *record, format_t *format)
{ {
aiRecord *ai = (aiRecord *) record; aiRecord *ai = (aiRecord *) record;
double val;
switch (format->type) switch (format->type)
{ {
case DBF_DOUBLE: case DBF_DOUBLE:
{ {
val = ai->val - ai->aoff; double val = ai->val - ai->aoff;
if (ai->aslo != 0) val /= ai->aslo; if (ai->aslo != 0.0 && ai->aslo != 1.0) val /= ai->aslo;
return streamPrintf (record, format, val); 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: case DBF_LONG:
{ {
if (ai->linr == menuConvertNO_CONVERSION) 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; return ERROR;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -70,11 +70,11 @@ ioccmd {dbpf DZ:lo -1}
if {$tcl_platform(machine) == "x86_64"} { if {$tcl_platform(machine) == "x86_64"} {
assure "-1 -1 -00001 ffffffffffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" assure "-1 -1 -00001 ffffffffffffffff FFFFFF 11111111111111111111111111111111 11111111111111111111111111111111 111111 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
} else { } 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} ioccmd {dbpf DZ:lo -1234}
if {$tcl_platform(machine) == "x86_64"} { if {$tcl_platform(machine) == "x86_64"} {
assure "-1234 -1234 -01234 fffffffffffffb2e FFFB2E 1111111111111111111111111111111111111111111111111111101100101110 1111111111111111111111111111111111111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n" assure "-1234 -1234 -01234 fffffffffffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
} else { } else {
assure "-1234 -1234 -01234 fffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n" assure "-1234 -1234 -01234 fffffb2e FFFB2E 11111111111111111111101100101110 11111111111111111111101100101110 101110 !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!. !!!!!!!!!!!!!!!!!!!!!.!!..!.!!!.\n"
} }