Experimental Physics and Industrial Control System
Hi Emmanuel,
I patched the RawConverter to support both signed and unsigned conversion. To
stay backward compatible, %r converts signed. I use %0r for unsigned now.
The new version is attached.
Dirk
Emmanuel Mayssat wrote:
Dirk,
I hope you are doing well.
I was wondering if you had the time to look at unsigned conversion for
the raw converter.
You are probably busy, so I can work on this patch myself if need be.
Please let me know as I am anxiously waiting for this feature.
Regards,
--
Emmanuel
On Fri, 2007-11-09 at 09:57 -0800, Emmanuel Mayssat wrote:
Dirk,
Is it possible to get a patch for unsigned conversion ?
I would prefer that to additional records as there are many of them.
( I am converting an existing driver to stream)
Please let me know.
I looked at the code, I think it is just a matter of changing signed
char to unsigned char and adding a new flag in the code of the
converter.
Regards,
--
E
On Wed, 2007-10-31 at 11:26 +0100, Dirk Zimoch wrote:
Hi Emmanuel,
It should be sufficient to pass the value through a calc record that does "A&65535".
I will probably add a flag to do unsigned conversion.
Dirk
Emmanuel Mayssat wrote:
Hello all,
I am using stream and a 16 bit word to convert to an unsigned integer (0
to 64xxx). The unsigned integer is coded on 2 characters.
So I use the raw converter and particularly %2.2r
But with that converter then the integer is signed (as mentioned in the
doc). So I can read values between 0 to 32767 and -32768 to -1.
Is there a way to use unsigned integer with the raw converter or do I
have to write my own converter?
Looking at the RawConverter.cc code, I am afraid that I will have to
write my own...
--
Emmanuel
--
Dr. Dirk Zimoch
Paul Scherrer Institut, WBGB/006
5232 Villigen PSI, Switzerland
Phone +41 56 310 5182
/***************************************************************
* StreamDevice Support *
* *
* (C) 1999 Dirk Zimoch ([email protected]) *
* (C) 2005 Dirk Zimoch ([email protected]) *
* *
* This is the raw format converter of StreamDevice. *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include "StreamFormatConverter.h"
#include "StreamError.h"
// Raw Bytes Converter %r
class RawConverter : public StreamFormatConverter
{
int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
bool printLong(const StreamFormat&, StreamBuffer&, long);
int scanLong(const StreamFormat&, const char*, long&);
};
int RawConverter::
parse(const StreamFormat&, StreamBuffer&,
const char*&, bool)
{
return long_format;
}
bool RawConverter::
printLong(const StreamFormat& format, StreamBuffer& output, long value)
{
int prec = format.prec; // number of bytes from value
if (prec == -1) prec = 1; // default: 1 byte
int width = prec; // number of bytes in output
if (format.width > width) width = format.width;
char byte = 0;
if (format.flags & alt_flag) // lsb first (little endian)
{
while (prec--)
{
byte = static_cast<char>(value);
output.append(byte);
value >>= 8;
width--;
}
if (format.flags & zero_flag)
{
// fill with zero
byte = 0;
}
else
{
// fill with sign
byte = (byte & 0x80) ? 0xFF : 0x00;
}
while (width--)
{
output.append(byte);
}
}
else // msb first (big endian)
{
if (format.flags & zero_flag)
{
// fill with zero
byte = 0;
}
else
{
// fill with sign
byte = ((value >> (8 * (prec-1))) & 0x80) ? 0xFF : 0x00;
}
while (width > prec)
{
output.append(byte);
width--;
}
while (prec--)
{
output.append(static_cast<char>(value >> (8 * prec)));
}
}
return true;
}
int RawConverter::
scanLong(const StreamFormat& format, const char* input, long& value)
{
long length = 0;
long val = 0;
int width = format.width;
if (width == 0) width = 1; // default: 1 byte
if (format.flags & skip_flag)
{
return width; // just skip input
}
if (format.flags & alt_flag)
{
// little endian (sign extended)*/
unsigned int shift = 0;
while (--width && shift < sizeof(long)*8)
{
val |= ((unsigned char) input[length++]) << shift;
shift += 8;
}
if (width == 0)
{
if (format.flags & zero_flag)
{
// fill with zero
val |= ((unsigned char) input[length++]) << shift;
}
else
{
// fill with sign
val |= ((signed char) input[length++]) << shift;
}
}
length += width; // ignore upper bytes not fitting in long
}
else
{
// big endian */
if (format.flags & zero_flag)
{
// fill with zero
val = (unsigned char) input[length++];
}
else
{
// fill with sign
val = (signed char) input[length++];
}
while (--width)
{
val <<= 8;
val |= (unsigned char) input[length++];
}
}
value = val;
return length;
}
RegisterConverter (RawConverter, "r");
- References:
- Stream Raw converter and un/signed integrer Emmanuel Mayssat
- Re: Stream Raw converter and un/signed integrer Dirk Zimoch
- Re: Stream Raw converter and un/signed integrer Emmanuel Mayssat
- Navigate by Date:
- Prev:
RE: VDCT Hierarchies Shepherd, EL (Emma)
- Next:
Re: Streams questions (how to read +00011-01 as 11e-01=1.1) Dirk Zimoch
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
<2007>
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
- Navigate by Thread:
- Prev:
Re: Stream Raw converter and un/signed integrer Emmanuel Mayssat
- Next:
edd 1-11-0gz seg fault Kevin Tsubota
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
<2007>
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025