compressRecord: LIFO doesn't zero pad
Change handling of OFF so that reading a partially populated buffer doesn't pad with zero. Simplify put_value() and get_array_info()
This commit is contained in:
@@ -108,67 +108,34 @@ static void monitor(compressRecord *prec)
|
||||
db_post_events(prec, prec->bptr, monitor_mask);
|
||||
}
|
||||
|
||||
static void put_value_FIFO(compressRecord *prec, double *psource, int n)
|
||||
{
|
||||
epicsInt32 offset = prec->off;
|
||||
epicsInt32 nuse = prec->nuse;
|
||||
epicsInt32 nsam = prec->nsam;
|
||||
double *pdest = prec->bptr + offset;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
*pdest = *psource++;
|
||||
if (++offset >= nsam) {
|
||||
pdest = prec->bptr;
|
||||
offset = 0;
|
||||
}
|
||||
else
|
||||
pdest++;
|
||||
}
|
||||
nuse += n;
|
||||
if (nuse > nsam)
|
||||
nuse = nsam;
|
||||
prec->off = offset;
|
||||
prec->nuse = nuse;
|
||||
return;
|
||||
}
|
||||
|
||||
static void put_value_LIFO(compressRecord *prec, double *psource, int n)
|
||||
{
|
||||
epicsInt32 offset = prec->off;
|
||||
epicsInt32 nuse = prec->nuse;
|
||||
epicsInt32 nsam = prec->nsam;
|
||||
epicsInt32 start = offset - nuse;
|
||||
double *pdest;
|
||||
int i;
|
||||
if(start<0) start += nsam;
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
if(--start < 0) start += nsam;
|
||||
pdest = prec->bptr + start;
|
||||
*pdest = *psource++;
|
||||
}
|
||||
nuse += n;
|
||||
if(nuse > nsam) nuse = nsam;
|
||||
offset = start + nuse;
|
||||
if(offset>=nsam) offset -= nsam;
|
||||
|
||||
prec->off = offset;
|
||||
prec->nuse = nuse;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void put_value(compressRecord *prec, double *psource, int n)
|
||||
{
|
||||
switch(prec->balg) {
|
||||
case bufferingALG_FIFO: put_value_FIFO(prec, psource, n); break;
|
||||
case bufferingALG_LIFO: put_value_LIFO(prec, psource, n); break;
|
||||
int fifo = prec->balg==bufferingALG_FIFO;
|
||||
epicsUInt32 offset = prec->off;
|
||||
epicsUInt32 nuse = prec->nuse;
|
||||
epicsUInt32 nsam = prec->nsam;
|
||||
|
||||
nuse += n;
|
||||
if(nuse>nsam)
|
||||
nuse = nsam;
|
||||
|
||||
while(n--) {
|
||||
/* for LIFO, decrement before */
|
||||
if(!fifo)
|
||||
offset = (offset-1)%nsam;
|
||||
|
||||
prec->bptr[offset] = *psource++;
|
||||
|
||||
/* for FIFO, increment after */
|
||||
if(fifo)
|
||||
offset = (offset+1)%nsam;
|
||||
}
|
||||
return;
|
||||
|
||||
prec->off = offset;
|
||||
prec->nuse = nuse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* qsort comparison function (for median calculation) */
|
||||
static int compare(const void *arg1, const void *arg2)
|
||||
{
|
||||
@@ -434,13 +401,22 @@ static long cvt_dbaddr(DBADDR *paddr)
|
||||
|
||||
static long get_array_info(DBADDR *paddr, long *no_elements, long *offset)
|
||||
{
|
||||
/* offset indicates the next element which would be written.
|
||||
* In FIFO mode offset-1 is the last valid element
|
||||
* In LIFO mode offset is the first valid element
|
||||
* (*offset) should be set to the index of the first valid element
|
||||
*/
|
||||
compressRecord *prec = (compressRecord *) paddr->precord;
|
||||
epicsInt32 start = prec->off - prec->nuse;
|
||||
if(start<0) start += prec->nsam;
|
||||
if(prec->balg == bufferingALG_FIFO)
|
||||
*no_elements = prec->nuse;
|
||||
else *no_elements = prec->nsam;
|
||||
*offset = start;
|
||||
epicsUInt32 off = prec->off;
|
||||
epicsUInt32 nuse = prec->nuse;
|
||||
epicsUInt32 nsam = prec->nsam;
|
||||
|
||||
*no_elements = nuse;
|
||||
if(prec->balg == bufferingALG_FIFO) {
|
||||
*offset = (off-nuse)%nsam;
|
||||
} else {
|
||||
*offset = off;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -449,7 +425,8 @@ static long put_array_info(DBADDR *paddr, long nNew)
|
||||
{
|
||||
compressRecord *prec = (compressRecord *) paddr->precord;
|
||||
|
||||
prec->off = (prec->off + nNew) % prec->nsam;
|
||||
if(prec->balg == bufferingALG_FIFO)
|
||||
prec->off = (prec->off + nNew) % prec->nsam;
|
||||
prec->nuse += nNew;
|
||||
if (prec->nuse > prec->nsam)
|
||||
prec->nuse = prec->nsam;
|
||||
|
||||
Reference in New Issue
Block a user