Fixes and additions in dbExtractArray.c
MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add forced write of '\0' to destination to end strings correctly * Add dbExtractArrayFromBuf() to make array copies from ref type field logs easier
This commit is contained in:
committed by
Michael Davidsaver
parent
0b32220e86
commit
0e2a66e721
@@ -24,12 +24,13 @@
|
||||
#define epicsExportSharedSymbols
|
||||
#include "dbExtractArray.h"
|
||||
|
||||
void dbExtractArray(const dbAddr *paddr,
|
||||
void *pto, long nRequest, long no_elements, long offset, long increment)
|
||||
void dbExtractArrayFromRec(const dbAddr *paddr, void *pto,
|
||||
long nRequest, long no_elements, long offset, long increment)
|
||||
{
|
||||
char *pdst = (char *) pto;
|
||||
char *psrc = (char *) paddr->pfield;
|
||||
long nUpperPart;
|
||||
int i;
|
||||
short srcSize = paddr->field_size;
|
||||
short dstSize = srcSize;
|
||||
char isString = (paddr->field_type == DBF_STRING);
|
||||
@@ -42,6 +43,9 @@ void dbExtractArray(const dbAddr *paddr,
|
||||
memcpy(pdst, &psrc[offset * srcSize], dstSize * nUpperPart);
|
||||
if (nRequest > nUpperPart)
|
||||
memcpy(&pdst[dstSize * nUpperPart], psrc, dstSize * (nRequest - nUpperPart));
|
||||
if (isString)
|
||||
for (i = 1; i <= nRequest; i++)
|
||||
pdst[dstSize*i] = '\0';
|
||||
} else {
|
||||
for (; nRequest > 0; nRequest--, pdst += srcSize, offset += increment) {
|
||||
offset %= no_elements;
|
||||
@@ -50,3 +54,31 @@ void dbExtractArray(const dbAddr *paddr,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dbExtractArrayFromBuf(const void *pfrom, void *pto,
|
||||
short field_size, short field_type,
|
||||
long nRequest, long no_elements, long offset, long increment)
|
||||
{
|
||||
char *pdst = (char *) pto;
|
||||
char *psrc = (char *) pfrom;
|
||||
int i;
|
||||
short srcSize = field_size;
|
||||
short dstSize = srcSize;
|
||||
char isString = (field_type == DBF_STRING);
|
||||
|
||||
if (nRequest > no_elements) nRequest = no_elements;
|
||||
if (offset > no_elements - 1) offset = no_elements - 1;
|
||||
if (isString && dstSize >= MAX_STRING_SIZE) dstSize = MAX_STRING_SIZE - 1;
|
||||
|
||||
if (increment == 1) {
|
||||
memcpy(pdst, &psrc[offset * srcSize], dstSize * nRequest);
|
||||
if (isString)
|
||||
for (i = 1; i <= nRequest; i++)
|
||||
pdst[dstSize*i] = '\0';
|
||||
} else {
|
||||
for (; nRequest > 0; nRequest--, pdst += srcSize, offset += increment) {
|
||||
memcpy(pdst, &psrc[offset*srcSize], dstSize);
|
||||
if (isString) pdst[dstSize] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,18 @@
|
||||
#define INC_dbExtractArray_H
|
||||
|
||||
#include "dbFldTypes.h"
|
||||
#include "dbAddr.h"
|
||||
#include "shareLib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
epicsShareExtern void dbExtractArray(const DBADDR *paddr, void *pbuffer,
|
||||
long nRequest, long no_elements, long offset, long increment);
|
||||
epicsShareFunc void dbExtractArrayFromRec(const DBADDR *paddr, void *pto,
|
||||
long nRequest, long no_elements, long offset, long increment);
|
||||
epicsShareFunc void dbExtractArrayFromBuf(const void *pfrom, void *pto,
|
||||
short field_size, short field_type,
|
||||
long nRequest, long no_elements, long offset, long increment);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user