diff --git a/documentation/mbboDirect.html b/documentation/mbboDirect.html
index c4e25af..dc621ac 100644
--- a/documentation/mbboDirect.html
+++ b/documentation/mbboDirect.html
@@ -23,26 +23,23 @@ written or read value.
Not allowed.
- LONG format (e.g. %i
):
+ LONG or ENUM format (e.g. %i
):
- If
MASK==0
(because NOBT
is not set):
-
- Output:
x=VAL
- Input: VAL=x
+ Output: x=RVAL
+ Input: RAL=x
, VAL=RVAL>>SHFT
- If
MASK!=0
:
-
Output:
x=RVAL&MASK
- Input: RBV=RVAL=x&MASK
+ Input: RBV=RVAL=x&MASK
, VAL=RVAL>>SHFT
MASK
is initialized to NOBT
1-bits shifted
- left by SHFT
.
-
- ENUM format (e.g. %{
):
-
- Not allowed.
+ left by SHFT
(((2^NOBT)-1)<<SHFT
).
+ The record calculates RVAL=VAL<<SHFT
.
STRING format (e.g. %s
):
diff --git a/src/RawConverter.cc b/src/RawConverter.cc
index dfe1f25..274fa36 100644
--- a/src/RawConverter.cc
+++ b/src/RawConverter.cc
@@ -34,7 +34,7 @@ int RawConverter::
parse(const StreamFormat& fmt, StreamBuffer&,
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::
@@ -112,7 +112,7 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
unsigned int shift = 0;
while (--width && shift < sizeof(long)*8)
{
- val |= ((unsigned char)input[consumed++]) << shift;
+ val |= (unsigned long)((unsigned char)input[consumed++]) << shift;
shift += 8;
}
if (width == 0)
@@ -120,12 +120,12 @@ scanLong(const StreamFormat& fmt, const char* input, long& value)
if (fmt.flags & zero_flag)
{
// fill with zero
- val |= ((unsigned char)input[consumed++]) << shift;
+ val |= (unsigned long)((unsigned char)input[consumed++]) << shift;
}
else
{
// 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
diff --git a/src/devboStream.c b/src/devboStream.c
index f590fb5..e69e65f 100644
--- a/src/devboStream.c
+++ b/src/devboStream.c
@@ -92,25 +92,26 @@ static long readData(dbCommon *record, format_t *format)
static long writeData(dbCommon *record, format_t *format)
{
boRecord *bo = (boRecord *)record;
+ long val;
switch (format->type)
{
case DBF_ULONG:
+ val = bo->rval;
+ break;
case DBF_LONG:
- {
- return streamPrintf(record, format, bo->rval);
- }
+ val = bo->mask ? (epicsInt32)bo->rval : (epicsInt16)bo->val;
+ break;
case DBF_ENUM:
- {
- return streamPrintf(record, format, (long)bo->val);
- }
+ val = bo->val;
+ break;
case DBF_STRING:
- {
return streamPrintf(record, format,
bo->val ? bo->onam : bo->znam);
- }
+ default:
+ return ERROR;
}
- return ERROR;
+ return streamPrintf(record, format, val);
}
static long initRecord(dbCommon *record)
diff --git a/src/devlongoutStream.c b/src/devlongoutStream.c
index a2d8894..03a255c 100644
--- a/src/devlongoutStream.c
+++ b/src/devlongoutStream.c
@@ -71,7 +71,7 @@ static long writeData(dbCommon *record, format_t *format)
{
case DBF_ULONG:
case DBF_ENUM:
- return streamPrintf(record, format, (unsigned long)lo->val);
+ return streamPrintf(record, format, lo->val);
case DBF_LONG:
return streamPrintf(record, format, (long)lo->val);
}
diff --git a/src/devmbboDirectStream.c b/src/devmbboDirectStream.c
index 69a5662..7c15337 100644
--- a/src/devmbboDirectStream.c
+++ b/src/devmbboDirectStream.c
@@ -36,12 +36,11 @@ static long readData(dbCommon *record, format_t *format)
if (format->type != DBF_ULONG && format->type != DBF_LONG)
return ERROR;
if (streamScanf(record, format, &val) == ERROR) return ERROR;
- if (mbboD->mask)
- val &= mbboD->mask;
-
+ if (mbboD->mask) val &= mbboD->mask;
+
mbboD->rbv = 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 */
if (record->pact) return DO_NOT_CONVERT;
@@ -87,19 +86,26 @@ static long writeData(dbCommon *record, format_t *format)
mbboDirectRecord *mbboD = (mbboDirectRecord *)record;
long val;
- if (format->type == DBF_ULONG || format->type == DBF_LONG)
+ switch (format->type)
{
- if (mbboD->mask) val = mbboD->rval & mbboD->mask;
- else val = mbboD->val;
- return streamPrintf(record, format, val);
+ case DBF_ULONG:
+ case DBF_ENUM:
+ 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)
{
mbboDirectRecord *mbboD = (mbboDirectRecord *)record;
-
mbboD->mask <<= mbboD->shft;
/* Workaround for bug in mbboDirect record:
diff --git a/src/devmbboStream.c b/src/devmbboStream.c
index 03f5b7d..d949039 100644
--- a/src/devmbboStream.c
+++ b/src/devmbboStream.c
@@ -107,14 +107,12 @@ static long readData(dbCommon *record, format_t *format)
static long writeData(dbCommon *record, format_t *format)
{
mbboRecord *mbbo = (mbboRecord *)record;
- unsigned long val;
+ long val;
int i;
switch (format->type)
{
case DBF_ULONG:
- case DBF_LONG:
- {
/* print VAL or RVAL ? */
val = mbbo->val;
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);
+ 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:
{
- return streamPrintf(record, format, (long)mbbo->val);
+ return streamPrintf(record, format, mbbo->val);
}
case DBF_STRING:
{