fix several signed/unsigned problems
This commit is contained in:
@ -23,26 +23,23 @@ written or read value.
|
|||||||
<dd>
|
<dd>
|
||||||
Not allowed.
|
Not allowed.
|
||||||
</dd>
|
</dd>
|
||||||
<dt>LONG format (e.g. <code>%i</code>):</dt>
|
<dt>LONG or ENUM format (e.g. <code>%i</code>):</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>If <code>MASK==0</code> (because <code>NOBT</code> is not set):</dt>
|
<dt>If <code>MASK==0</code> (because <code>NOBT</code> is not set):</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<u>Output:</u> <code><i>x</i>=VAL</code><br>
|
<u>Output:</u> <code><i>x</i>=RVAL</code><br>
|
||||||
<u>Input:</u> <code>VAL=<i>x</i></code><br>
|
<u>Input:</u> <code>RAL=<i>x</i></code>, <code>VAL=RVAL>>SHFT</code><br>
|
||||||
</dd>
|
</dd>
|
||||||
<dt>If <code>MASK!=0</code>:</dt>
|
<dt>If <code>MASK!=0</code>:</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<u>Output:</u> <code><i>x</i>=RVAL&MASK</code><br>
|
<u>Output:</u> <code><i>x</i>=RVAL&MASK</code><br>
|
||||||
<u>Input:</u> <code>RBV=RVAL=<i>x</i>&MASK</code><br>
|
<u>Input:</u> <code>RBV=RVAL=<i>x</i>&MASK</code>, <code>VAL=RVAL>>SHFT</code><br>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<code>MASK</code> is initialized to <code>NOBT</code> 1-bits shifted
|
<code>MASK</code> is initialized to <code>NOBT</code> 1-bits shifted
|
||||||
left by <code>SHFT</code>.
|
left by <code>SHFT</code> (<code>((2^NOBT)-1)<<SHFT</code>).
|
||||||
</dd>
|
The record calculates <code>RVAL=VAL<<SHFT</code>.
|
||||||
<dt>ENUM format (e.g. <code>%{</code>):</dt>
|
|
||||||
<dd>
|
|
||||||
Not allowed.
|
|
||||||
</dd>
|
</dd>
|
||||||
<dt>STRING format (e.g. <code>%s</code>):</dt>
|
<dt>STRING format (e.g. <code>%s</code>):</dt>
|
||||||
<dd>
|
<dd>
|
||||||
|
@ -34,7 +34,7 @@ int RawConverter::
|
|||||||
parse(const StreamFormat& fmt, StreamBuffer&,
|
parse(const StreamFormat& fmt, StreamBuffer&,
|
||||||
const char*&, bool)
|
const char*&, bool)
|
||||||
{
|
{
|
||||||
return (fmt.flags & (sign_flag|zero_flag)) ? signed_format : unsigned_format;
|
return (fmt.flags & zero_flag) ? unsigned_format : signed_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RawConverter::
|
bool RawConverter::
|
||||||
@ -112,7 +112,7 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
|
|||||||
unsigned int shift = 0;
|
unsigned int shift = 0;
|
||||||
while (--width && shift < sizeof(long)*8)
|
while (--width && shift < sizeof(long)*8)
|
||||||
{
|
{
|
||||||
val |= ((unsigned char)input[consumed++]) << shift;
|
val |= (unsigned long)((unsigned char)input[consumed++]) << shift;
|
||||||
shift += 8;
|
shift += 8;
|
||||||
}
|
}
|
||||||
if (width == 0)
|
if (width == 0)
|
||||||
@ -120,12 +120,12 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
|
|||||||
if (fmt.flags & zero_flag)
|
if (fmt.flags & zero_flag)
|
||||||
{
|
{
|
||||||
// fill with zero
|
// fill with zero
|
||||||
val |= ((unsigned char)input[consumed++]) << shift;
|
val |= (unsigned long)((unsigned char)input[consumed++]) << shift;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fill with sign
|
// fill with sign
|
||||||
val |= ((signed char)input[consumed++]) << shift;
|
val |= ((long)(signed char)input[consumed++]) << shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
consumed += width; // ignore upper bytes not fitting in long
|
consumed += width; // ignore upper bytes not fitting in long
|
||||||
|
@ -92,25 +92,26 @@ static long readData(dbCommon *record, format_t *format)
|
|||||||
static long writeData(dbCommon *record, format_t *format)
|
static long writeData(dbCommon *record, format_t *format)
|
||||||
{
|
{
|
||||||
boRecord *bo = (boRecord *)record;
|
boRecord *bo = (boRecord *)record;
|
||||||
|
long val;
|
||||||
|
|
||||||
switch (format->type)
|
switch (format->type)
|
||||||
{
|
{
|
||||||
case DBF_ULONG:
|
case DBF_ULONG:
|
||||||
|
val = bo->rval;
|
||||||
|
break;
|
||||||
case DBF_LONG:
|
case DBF_LONG:
|
||||||
{
|
val = bo->mask ? (epicsInt32)bo->rval : (epicsInt16)bo->val;
|
||||||
return streamPrintf(record, format, bo->rval);
|
break;
|
||||||
}
|
|
||||||
case DBF_ENUM:
|
case DBF_ENUM:
|
||||||
{
|
val = bo->val;
|
||||||
return streamPrintf(record, format, (long)bo->val);
|
break;
|
||||||
}
|
|
||||||
case DBF_STRING:
|
case DBF_STRING:
|
||||||
{
|
|
||||||
return streamPrintf(record, format,
|
return streamPrintf(record, format,
|
||||||
bo->val ? bo->onam : bo->znam);
|
bo->val ? bo->onam : bo->znam);
|
||||||
}
|
default:
|
||||||
|
return ERROR;
|
||||||
}
|
}
|
||||||
return ERROR;
|
return streamPrintf(record, format, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static long initRecord(dbCommon *record)
|
static long initRecord(dbCommon *record)
|
||||||
|
@ -71,7 +71,7 @@ static long writeData(dbCommon *record, format_t *format)
|
|||||||
{
|
{
|
||||||
case DBF_ULONG:
|
case DBF_ULONG:
|
||||||
case DBF_ENUM:
|
case DBF_ENUM:
|
||||||
return streamPrintf(record, format, (unsigned long)lo->val);
|
return streamPrintf(record, format, lo->val);
|
||||||
case DBF_LONG:
|
case DBF_LONG:
|
||||||
return streamPrintf(record, format, (long)lo->val);
|
return streamPrintf(record, format, (long)lo->val);
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,11 @@ static long readData(dbCommon *record, format_t *format)
|
|||||||
if (format->type != DBF_ULONG && format->type != DBF_LONG)
|
if (format->type != DBF_ULONG && format->type != DBF_LONG)
|
||||||
return ERROR;
|
return ERROR;
|
||||||
if (streamScanf(record, format, &val) == ERROR) return ERROR;
|
if (streamScanf(record, format, &val) == ERROR) return ERROR;
|
||||||
if (mbboD->mask)
|
if (mbboD->mask) val &= mbboD->mask;
|
||||||
val &= mbboD->mask;
|
|
||||||
|
|
||||||
mbboD->rbv = val;
|
mbboD->rbv = val;
|
||||||
mbboD->rval = val;
|
mbboD->rval = val;
|
||||||
if (mbboD->shft > 0) val >>= mbboD->shft;
|
val >>= mbboD->shft;
|
||||||
mbboD->val = val; /* no cast because we cannot be sure about type of VAL */
|
mbboD->val = val; /* no cast because we cannot be sure about type of VAL */
|
||||||
|
|
||||||
if (record->pact) return DO_NOT_CONVERT;
|
if (record->pact) return DO_NOT_CONVERT;
|
||||||
@ -87,19 +86,26 @@ static long writeData(dbCommon *record, format_t *format)
|
|||||||
mbboDirectRecord *mbboD = (mbboDirectRecord *)record;
|
mbboDirectRecord *mbboD = (mbboDirectRecord *)record;
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (format->type == DBF_ULONG || format->type == DBF_LONG)
|
switch (format->type)
|
||||||
{
|
{
|
||||||
if (mbboD->mask) val = mbboD->rval & mbboD->mask;
|
case DBF_ULONG:
|
||||||
else val = mbboD->val;
|
case DBF_ENUM:
|
||||||
return streamPrintf(record, format, val);
|
val = mbboD->rval;
|
||||||
|
if (mbboD->mask) val &= mbboD->mask;
|
||||||
|
break;
|
||||||
|
case DBF_LONG:
|
||||||
|
val = (epicsInt32)mbboD->rval;
|
||||||
|
if (mbboD->mask) val &= (epicsInt32)mbboD->mask;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ERROR;
|
||||||
}
|
}
|
||||||
return ERROR;
|
return streamPrintf(record, format, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static long initRecord(dbCommon *record)
|
static long initRecord(dbCommon *record)
|
||||||
{
|
{
|
||||||
mbboDirectRecord *mbboD = (mbboDirectRecord *)record;
|
mbboDirectRecord *mbboD = (mbboDirectRecord *)record;
|
||||||
|
|
||||||
mbboD->mask <<= mbboD->shft;
|
mbboD->mask <<= mbboD->shft;
|
||||||
|
|
||||||
/* Workaround for bug in mbboDirect record:
|
/* Workaround for bug in mbboDirect record:
|
||||||
|
@ -107,14 +107,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;
|
||||||
unsigned long val;
|
long val;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
switch (format->type)
|
switch (format->type)
|
||||||
{
|
{
|
||||||
case DBF_ULONG:
|
case DBF_ULONG:
|
||||||
case DBF_LONG:
|
|
||||||
{
|
|
||||||
/* print VAL or RVAL ? */
|
/* print VAL or RVAL ? */
|
||||||
val = mbbo->val;
|
val = mbbo->val;
|
||||||
if (mbbo->sdef) for (i=0; i<16; i++)
|
if (mbbo->sdef) for (i=0; i<16; i++)
|
||||||
@ -128,10 +126,25 @@ static long writeData(dbCommon *record, format_t *format)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return streamPrintf(record, format, val);
|
return streamPrintf(record, format, val);
|
||||||
|
case DBF_LONG:
|
||||||
|
{
|
||||||
|
/* print VAL or RVAL ? */
|
||||||
|
val = (epicsInt16)mbbo->val;
|
||||||
|
if (mbbo->sdef) for (i=0; i<16; i++)
|
||||||
|
{
|
||||||
|
if ((&mbbo->zrvl)[i])
|
||||||
|
{
|
||||||
|
/* any values defined ? */
|
||||||
|
val = (epicsInt32)mbbo->rval;
|
||||||
|
if (mbbo->mask) val &= mbbo->mask;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return streamPrintf(record, format, val);
|
||||||
}
|
}
|
||||||
case DBF_ENUM:
|
case DBF_ENUM:
|
||||||
{
|
{
|
||||||
return streamPrintf(record, format, (long)mbbo->val);
|
return streamPrintf(record, format, mbbo->val);
|
||||||
}
|
}
|
||||||
case DBF_STRING:
|
case DBF_STRING:
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user