1532 lines
42 KiB
C
1532 lines
42 KiB
C
/*
|
|
* C O N V E R T . C
|
|
*
|
|
* Author: D. Kersteins
|
|
*
|
|
*
|
|
* NOTES:
|
|
*
|
|
* 1) All routines in this file have an encode argument which
|
|
* determines if we are converting from the standard format to
|
|
* the local format or vise versa. To date only float and double data
|
|
* types must be converted differently depending on the encode
|
|
* argument - joh
|
|
*
|
|
* History
|
|
* joh 10-21-90 Moved atomic types here to avoid
|
|
* maintenance problems in service.c
|
|
* This also provides for a cleaner seperation
|
|
* of function.
|
|
* joh 10-21-90 Added new DBR_XXXX types for release two
|
|
* joh 03-15-94 Added many missing types, named ca types,
|
|
* and ANSI C changes.
|
|
* joh 07-05-94 Fixed double invocation of ++ operator
|
|
* by byte swap macro bug in cvrt_short(),
|
|
* cvrt_long(), cvrt_enum().
|
|
*
|
|
*
|
|
*/
|
|
|
|
static char *sccsId = "$Id$";
|
|
|
|
#include <string.h>
|
|
|
|
#include "iocinf.h"
|
|
#include "net_convert.h"
|
|
|
|
void htond(double *pHost, double *pNet);
|
|
void ntohd(double *pNet, double *pHost);
|
|
|
|
#ifndef CONVERSION_REQUIRED
|
|
void htonf(float *IEEEhost, float *IEEEnet);
|
|
void ntohf(float *IEEEnet, float *IEEEhost);
|
|
#endif /*not CONVERSION_REQUIRED*/
|
|
|
|
/*
|
|
* if hton is true then it is a host to network conversion
|
|
* otherwise vise-versa
|
|
*
|
|
* net format: big endian and IEEE float
|
|
*
|
|
* typedef void CACVRTFUNC(
|
|
* void *pSource,
|
|
* void *pDestination,
|
|
* int hton,
|
|
* unsigned long count);
|
|
*/
|
|
|
|
LOCAL CACVRTFUNC cvrt_string;
|
|
LOCAL CACVRTFUNC cvrt_short;
|
|
LOCAL CACVRTFUNC cvrt_float;
|
|
LOCAL CACVRTFUNC cvrt_enum;
|
|
LOCAL CACVRTFUNC cvrt_char;
|
|
LOCAL CACVRTFUNC cvrt_long;
|
|
LOCAL CACVRTFUNC cvrt_double;
|
|
|
|
LOCAL CACVRTFUNC cvrt_sts_string;
|
|
LOCAL CACVRTFUNC cvrt_sts_short;
|
|
LOCAL CACVRTFUNC cvrt_sts_float;
|
|
LOCAL CACVRTFUNC cvrt_sts_enum;
|
|
LOCAL CACVRTFUNC cvrt_sts_char;
|
|
LOCAL CACVRTFUNC cvrt_sts_long;
|
|
LOCAL CACVRTFUNC cvrt_sts_double;
|
|
|
|
LOCAL CACVRTFUNC cvrt_time_string;
|
|
LOCAL CACVRTFUNC cvrt_time_short;
|
|
LOCAL CACVRTFUNC cvrt_time_float;
|
|
LOCAL CACVRTFUNC cvrt_time_enum;
|
|
LOCAL CACVRTFUNC cvrt_time_char;
|
|
LOCAL CACVRTFUNC cvrt_time_long;
|
|
LOCAL CACVRTFUNC cvrt_time_double;
|
|
|
|
LOCAL CACVRTFUNC cvrt_gr_short;
|
|
LOCAL CACVRTFUNC cvrt_gr_float;
|
|
LOCAL CACVRTFUNC cvrt_gr_enum;
|
|
LOCAL CACVRTFUNC cvrt_gr_char;
|
|
LOCAL CACVRTFUNC cvrt_gr_long;
|
|
LOCAL CACVRTFUNC cvrt_gr_double;
|
|
|
|
LOCAL CACVRTFUNC cvrt_ctrl_short;
|
|
LOCAL CACVRTFUNC cvrt_ctrl_float;
|
|
LOCAL CACVRTFUNC cvrt_ctrl_enum;
|
|
LOCAL CACVRTFUNC cvrt_ctrl_char;
|
|
LOCAL CACVRTFUNC cvrt_ctrl_long;
|
|
LOCAL CACVRTFUNC cvrt_ctrl_double;
|
|
|
|
/* cvrt is (array of) (pointer to) (function returning) int */
|
|
#ifdef VMS
|
|
globaldef
|
|
#endif
|
|
CACVRTFUNC *cac_dbr_cvrt[]
|
|
=
|
|
{
|
|
cvrt_string,
|
|
cvrt_short,
|
|
cvrt_float,
|
|
cvrt_enum,
|
|
cvrt_char,
|
|
cvrt_long,
|
|
cvrt_double,
|
|
|
|
cvrt_sts_string,
|
|
cvrt_sts_short,
|
|
cvrt_sts_float,
|
|
cvrt_sts_enum,
|
|
cvrt_sts_char,
|
|
cvrt_sts_long,
|
|
cvrt_sts_double,
|
|
|
|
cvrt_time_string,
|
|
cvrt_time_short,
|
|
cvrt_time_float,
|
|
cvrt_time_enum,
|
|
cvrt_time_char,
|
|
cvrt_time_long,
|
|
cvrt_time_double,
|
|
|
|
cvrt_sts_string, /* DBR_GR_STRING identical to dbr_sts_string */
|
|
cvrt_gr_short,
|
|
cvrt_gr_float,
|
|
cvrt_gr_enum,
|
|
cvrt_gr_char,
|
|
cvrt_gr_long,
|
|
cvrt_gr_double,
|
|
|
|
cvrt_sts_string, /* DBR_CTRL_STRING identical to dbr_sts_string */
|
|
cvrt_ctrl_short,
|
|
cvrt_ctrl_float,
|
|
cvrt_ctrl_enum,
|
|
cvrt_ctrl_char,
|
|
cvrt_ctrl_long,
|
|
cvrt_ctrl_double
|
|
};
|
|
|
|
/*
|
|
* Native types may not match EPICS types
|
|
*/
|
|
typedef short ca_short_tt;
|
|
typedef float ca_float_tt;
|
|
typedef short ca_enum_tt;
|
|
typedef char ca_char_tt;
|
|
typedef long ca_long_tt;
|
|
typedef double ca_double_tt;
|
|
|
|
#define dbr_ntohs(A) ntohs(A)
|
|
#define dbr_ntohl(A) ntohl(A)
|
|
#define dbr_htons(A) htons(A)
|
|
#define dbr_htonl(A) htonl(A)
|
|
|
|
|
|
|
|
/*
|
|
* CVRT_STRING()
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
LOCAL void cvrt_string(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
ca_char_tt *pSrc = s;
|
|
ca_char_tt *pDest = d;
|
|
|
|
if(num == 1){
|
|
strcpy(pDest, pSrc);
|
|
}
|
|
else{
|
|
memcpy(pDest, pSrc, num*MAX_STRING_SIZE);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* CVRT_SHORT()
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
LOCAL void cvrt_short(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
ca_short_tt *pSrc = s;
|
|
ca_short_tt *pDest = d;
|
|
unsigned long i;
|
|
|
|
for(i=0; i<num; i++){
|
|
*pDest = dbr_ntohs( *pSrc );
|
|
/*
|
|
* dont increment these inside the MACRO
|
|
*/
|
|
pDest++;
|
|
pSrc++;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* CVRT_CHAR()
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
LOCAL void cvrt_char(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
unsigned int i;
|
|
ca_char_tt *pSrc = s;
|
|
ca_char_tt *pDest = d;
|
|
|
|
for(i=0; i<num; i++){
|
|
*pDest++ = *pSrc++;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* CVRT_LONG()
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
LOCAL void cvrt_long(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
unsigned long i;
|
|
ca_long_tt *pSrc = s;
|
|
ca_long_tt *pDest = d;
|
|
|
|
for(i=0; i<num; i++){
|
|
*pDest = dbr_ntohl( *pSrc );
|
|
/*
|
|
* dont increment these inside the MACRO
|
|
*/
|
|
pDest++;
|
|
pSrc++;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* CVRT_ENUM()
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
LOCAL void cvrt_enum(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
unsigned i;
|
|
ca_enum_tt *pSrc;
|
|
ca_enum_tt *pDest;
|
|
|
|
pSrc = s;
|
|
pDest = d;
|
|
for(i=0; i<num; i++){
|
|
*pDest = dbr_ntohs(*pSrc);
|
|
/*
|
|
* dont increment these inside the MACRO
|
|
*/
|
|
pDest++;
|
|
pSrc++;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* CVRT_FLOAT()
|
|
*
|
|
*
|
|
* NOTES:
|
|
* placing encode outside the loop results in more
|
|
* code but better performance.
|
|
*
|
|
*/
|
|
LOCAL void cvrt_float(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
unsigned long i;
|
|
ca_float_tt *pSrc = s;
|
|
ca_float_tt *pDest = d;
|
|
|
|
for(i=0; i<num; i++){
|
|
if(encode){
|
|
htonf(pSrc, pDest);
|
|
}
|
|
else{
|
|
ntohf(pSrc, pDest);
|
|
}
|
|
/*
|
|
* dont increment these inside the MACRO
|
|
*/
|
|
pSrc++;
|
|
pDest++;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* CVRT_DOUBLE()
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
LOCAL void cvrt_double(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
unsigned int i;
|
|
ca_double_tt *pSrc = s;
|
|
ca_double_tt *pDest = d;
|
|
|
|
for(i=0; i<num; i++){
|
|
if(encode){
|
|
htond(pSrc,pDest);
|
|
}
|
|
else{
|
|
ntohd(pSrc,pDest);
|
|
}
|
|
/*
|
|
* dont increment these inside the MACRO
|
|
*/
|
|
pSrc++;
|
|
pDest++;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_string(s,d)
|
|
** struct dbr_sts_string *s pointer to source struct
|
|
** struct dbr_sts_string *d pointer to destination struct
|
|
** int encode; boolean, if true vax to ieee
|
|
** else ieee to vax
|
|
**
|
|
** converts fields of struct in HOST format to NET format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_sts_string(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_sts_string *pSrc = s;
|
|
struct dbr_sts_string *pDest = d;
|
|
|
|
/* convert ieee to vax format or vax to ieee */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
if (num == 1) /* if single value */
|
|
strcpy(pDest->value, pSrc->value);
|
|
else
|
|
memcpy(pDest->value, pSrc->value, (MAX_STRING_SIZE * num));
|
|
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_short(s,d)
|
|
** struct dbr_sts_int *s pointer to source struct
|
|
** struct dbr_sts_int *d pointer to destination struct
|
|
** int encode; boolean, if true vax to ieee
|
|
** else ieee to vax
|
|
**
|
|
** converts fields ofstruct in HOST format to ieee format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_sts_short(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_sts_int *pSrc = s;
|
|
struct dbr_sts_int *pDest = d;
|
|
|
|
/* convert vax to ieee or ieee to vax format -- same code*/
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
cvrt_short(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
}
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_float(s,d)
|
|
** struct dbr_sts_float *s pointer to source struct
|
|
** struct dbr_sts_float *d pointer to destination struct
|
|
** int encode; boolean, if true vax to ieee
|
|
** else ieee to vax
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_sts_float(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_sts_float *pSrc = s;
|
|
struct dbr_sts_float *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
|
|
cvrt_float(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_double(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_sts_double(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_sts_double *pSrc = s;
|
|
struct dbr_sts_double *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
|
|
cvrt_double(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_enum(s,d)
|
|
** struct dbr_sts_enum *s pointer to source struct
|
|
** struct dbr_sts_enum *d pointer to destination struct
|
|
** int encode; boolean, if true vax to ieee
|
|
** else ieee to vax
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_sts_enum(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_sts_enum *pSrc = s;
|
|
struct dbr_sts_enum *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
if (num == 1)
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else {
|
|
cvrt_enum(&pSrc->value,&pDest->value,encode,num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_gr_short()
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_gr_short(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_gr_int *pSrc = s;
|
|
struct dbr_gr_int *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
|
|
pDest->upper_disp_limit = dbr_ntohs(pSrc->upper_disp_limit);
|
|
pDest->lower_disp_limit = dbr_ntohs(pSrc->lower_disp_limit);
|
|
pDest->upper_alarm_limit = dbr_ntohs(pSrc->upper_alarm_limit);
|
|
pDest->upper_warning_limit = dbr_ntohs(pSrc->upper_warning_limit);
|
|
pDest->lower_alarm_limit = dbr_ntohs(pSrc->lower_alarm_limit);
|
|
pDest->lower_warning_limit = dbr_ntohs(pSrc->lower_warning_limit);
|
|
|
|
if (num == 1)
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else {
|
|
cvrt_short(&pSrc->value, &pDest->value, encode,num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_gr_char()
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_gr_char(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_gr_char *pSrc = s;
|
|
struct dbr_gr_char *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
|
|
pDest->upper_disp_limit = pSrc->upper_disp_limit;
|
|
pDest->lower_disp_limit = pSrc->lower_disp_limit;
|
|
pDest->upper_alarm_limit = pSrc->upper_alarm_limit;
|
|
pDest->upper_warning_limit = pSrc->upper_warning_limit;
|
|
pDest->lower_alarm_limit = pSrc->lower_alarm_limit;
|
|
pDest->lower_warning_limit = pSrc->lower_warning_limit;
|
|
|
|
if (num == 1)
|
|
pDest->value = pSrc->value;
|
|
else {
|
|
memcpy((char *)&pDest->value, (char *)&pSrc->value, num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_gr_long()
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_gr_long(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_gr_long *pSrc = s;
|
|
struct dbr_gr_long *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
|
|
pDest->upper_disp_limit = dbr_ntohl(pSrc->upper_disp_limit);
|
|
pDest->lower_disp_limit = dbr_ntohl(pSrc->lower_disp_limit);
|
|
pDest->upper_alarm_limit = dbr_ntohl(pSrc->upper_alarm_limit);
|
|
pDest->upper_warning_limit = dbr_ntohl(pSrc->upper_warning_limit);
|
|
pDest->lower_alarm_limit = dbr_ntohl(pSrc->lower_alarm_limit);
|
|
pDest->lower_warning_limit = dbr_ntohl(pSrc->lower_warning_limit);
|
|
|
|
if (num == 1)
|
|
pDest->value = dbr_ntohl(pSrc->value);
|
|
else {
|
|
cvrt_long(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_gr_enum(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_gr_enum(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_gr_enum *pSrc = s;
|
|
struct dbr_gr_enum *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->no_str = dbr_ntohs(pSrc->no_str);
|
|
memcpy((void *)pDest->strs,(void *)pSrc->strs,sizeof(pSrc->strs));
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
cvrt_enum(&(pSrc->value), &(pDest->value), encode, num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_gr_double(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_gr_double(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_gr_double *pSrc = s;
|
|
struct dbr_gr_double *pDest = d;
|
|
|
|
/* these are same for vax to ieee or ieee to vax */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->precision = dbr_ntohs(pSrc->precision);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
|
|
if (encode) /* vax to ieee convert */
|
|
{
|
|
if (num == 1){
|
|
htond(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_double(&pSrc->value, &pDest->value, encode,num);
|
|
}
|
|
htond(&pSrc->upper_disp_limit,&pDest->upper_disp_limit);
|
|
htond(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
htond(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
htond(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
htond(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
htond(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
}
|
|
else /* ieee to vax convert */
|
|
{
|
|
if (num == 1){
|
|
ntohd(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_double(&pSrc->value, &pDest->value, encode,num);
|
|
}
|
|
ntohd(&pSrc->upper_disp_limit,&pDest->upper_disp_limit);
|
|
ntohd(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
ntohd(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
ntohd(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
ntohd(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
ntohd(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_gr_float(s,d)
|
|
** struct dbr_gr_float *d pointer to destination struct
|
|
** int encode; boolean, if true vax to ieee
|
|
** else ieee to vax
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_gr_float(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_gr_float *pSrc = s;
|
|
struct dbr_gr_float *pDest = d;
|
|
|
|
/* these are same for vax to ieee or ieee to vax */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->precision = dbr_ntohs(pSrc->precision);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
|
|
if (encode) /* vax to ieee convert */
|
|
{
|
|
if (num == 1){
|
|
htonf(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_float(&pSrc->value, &pDest->value, encode,num);
|
|
}
|
|
htonf(&pSrc->upper_disp_limit,&pDest->upper_disp_limit);
|
|
htonf(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
htonf(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
htonf(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
htonf(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
htonf(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
}
|
|
else /* ieee to vax convert */
|
|
{
|
|
if (num == 1){
|
|
ntohf(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_float(&pSrc->value, &pDest->value, encode,num);
|
|
}
|
|
ntohf(&pSrc->upper_disp_limit,&pDest->upper_disp_limit);
|
|
ntohf(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
ntohf(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
ntohf(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
ntohf(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
ntohf(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_ctrl_short(s,d)
|
|
** struct dbr_gr_int *s pointer to source struct
|
|
** struct dbr_gr_int *d pointer to destination struct
|
|
** int encode; boolean, if true vax to ieee
|
|
** else ieee to vax
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_ctrl_short(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_ctrl_int *pSrc = s;
|
|
struct dbr_ctrl_int *pDest = d;
|
|
|
|
/* vax to ieee or ieee to vax -- same code */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
|
|
pDest->upper_disp_limit = dbr_ntohs(pSrc->upper_disp_limit);
|
|
pDest->lower_disp_limit = dbr_ntohs(pSrc->lower_disp_limit);
|
|
pDest->upper_alarm_limit = dbr_ntohs(pSrc->upper_alarm_limit);
|
|
pDest->upper_warning_limit = dbr_ntohs(pSrc->upper_warning_limit);
|
|
pDest->lower_alarm_limit = dbr_ntohs(pSrc->lower_alarm_limit);
|
|
pDest->lower_warning_limit = dbr_ntohs(pSrc->lower_warning_limit);
|
|
pDest->lower_ctrl_limit = dbr_ntohs(pSrc->lower_ctrl_limit);
|
|
pDest->upper_ctrl_limit = dbr_ntohs(pSrc->upper_ctrl_limit);
|
|
|
|
if (num == 1)
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else {
|
|
cvrt_short(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
}
|
|
|
|
/****************************************************************************
|
|
** cvrt_ctrl_long(s,d)
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_ctrl_long(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_ctrl_long *pSrc = s;
|
|
struct dbr_ctrl_long *pDest = d;
|
|
|
|
/* vax to ieee or ieee to vax -- same code */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
|
|
pDest->upper_disp_limit = dbr_ntohl(pSrc->upper_disp_limit);
|
|
pDest->lower_disp_limit = dbr_ntohl(pSrc->lower_disp_limit);
|
|
pDest->upper_alarm_limit = dbr_ntohl(pSrc->upper_alarm_limit);
|
|
pDest->upper_warning_limit = dbr_ntohl(pSrc->upper_warning_limit);
|
|
pDest->lower_alarm_limit = dbr_ntohl(pSrc->lower_alarm_limit);
|
|
pDest->lower_warning_limit = dbr_ntohl(pSrc->lower_warning_limit);
|
|
pDest->lower_ctrl_limit = dbr_ntohl(pSrc->lower_ctrl_limit);
|
|
pDest->upper_ctrl_limit = dbr_ntohl(pSrc->upper_ctrl_limit);
|
|
|
|
if (num == 1)
|
|
pDest->value = dbr_ntohl(pSrc->value);
|
|
else {
|
|
cvrt_long(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
}
|
|
|
|
/****************************************************************************
|
|
** cvrt_ctrl_short(s,d)
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_ctrl_char(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_ctrl_char *pSrc = s;
|
|
struct dbr_ctrl_char *pDest = d;
|
|
|
|
/* vax to ieee or ieee to vax -- same code */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
|
|
pDest->upper_disp_limit = pSrc->upper_disp_limit;
|
|
pDest->lower_disp_limit = pSrc->lower_disp_limit;
|
|
pDest->upper_alarm_limit = pSrc->upper_alarm_limit;
|
|
pDest->upper_warning_limit = pSrc->upper_warning_limit;
|
|
pDest->lower_ctrl_limit = pSrc->lower_ctrl_limit;
|
|
pDest->upper_ctrl_limit = pSrc->upper_ctrl_limit;
|
|
|
|
if (num == 1)
|
|
pDest->value = pSrc->value;
|
|
else {
|
|
memcpy((void *)&pDest->value, (void *)&pSrc->value, num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_ctrl_double(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_ctrl_double(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_ctrl_double *pSrc = s;
|
|
struct dbr_ctrl_double *pDest = d;
|
|
|
|
/* these are the same for ieee to vaax or vax to ieee */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->precision = dbr_ntohs(pSrc->precision);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
if (encode) /* vax to ieee convert */
|
|
{
|
|
if (num == 1){
|
|
htond(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_double(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
htond(&pSrc->upper_disp_limit,&pDest->upper_disp_limit);
|
|
htond(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
htond(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
htond(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
htond(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
htond(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
htond(&pSrc->lower_ctrl_limit, &pDest->lower_ctrl_limit);
|
|
htond(&pSrc->upper_ctrl_limit, &pDest->upper_ctrl_limit);
|
|
}
|
|
else /* ieee to vax convert */
|
|
{
|
|
if (num == 1){
|
|
ntohd(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_double(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
ntohd(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
ntohd(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
ntohd(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
ntohd(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
ntohd(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
ntohd(&pSrc->lower_ctrl_limit, &pDest->lower_ctrl_limit);
|
|
ntohd(&pSrc->upper_ctrl_limit, &pDest->upper_ctrl_limit);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_ctrl_float(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_ctrl_float(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_ctrl_float *pSrc = s;
|
|
struct dbr_ctrl_float *pDest = d;
|
|
|
|
/* these are the same for ieee to vaax or vax to ieee */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->precision = dbr_ntohs(pSrc->precision);
|
|
memcpy(pDest->units,pSrc->units,sizeof(pSrc->units));
|
|
if (encode) /* vax to ieee convert */
|
|
{
|
|
if (num == 1){
|
|
htonf(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_float(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
htonf(&pSrc->upper_disp_limit,&pDest->upper_disp_limit);
|
|
htonf(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
htonf(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
htonf(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
htonf(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
htonf(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
htonf(&pSrc->lower_ctrl_limit, &pDest->lower_ctrl_limit);
|
|
htonf(&pSrc->upper_ctrl_limit, &pDest->upper_ctrl_limit);
|
|
}
|
|
else /* ieee to vax convert */
|
|
{
|
|
if (num == 1){
|
|
ntohf(&pSrc->value, &pDest->value);
|
|
}
|
|
else {
|
|
cvrt_float(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
ntohf(&pSrc->lower_disp_limit, &pDest->lower_disp_limit);
|
|
ntohf(&pSrc->upper_alarm_limit, &pDest->upper_alarm_limit);
|
|
ntohf(&pSrc->upper_warning_limit, &pDest->upper_warning_limit);
|
|
ntohf(&pSrc->lower_alarm_limit, &pDest->lower_alarm_limit);
|
|
ntohf(&pSrc->lower_warning_limit, &pDest->lower_warning_limit);
|
|
ntohf(&pSrc->lower_ctrl_limit, &pDest->lower_ctrl_limit);
|
|
ntohf(&pSrc->upper_ctrl_limit, &pDest->upper_ctrl_limit);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_ctrl_enum(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_ctrl_enum(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_ctrl_enum *pSrc = s;
|
|
struct dbr_ctrl_enum *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->no_str = dbr_ntohs(pSrc->no_str);
|
|
memcpy((void *)pDest->strs,(void *)pSrc->strs,sizeof(pSrc->strs));
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
cvrt_enum(&(pSrc->value), &(pDest->value), encode, num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_char(s,d)
|
|
** struct dbr_sts_int *s pointer to source struct
|
|
** struct dbr_sts_int *d pointer to destination struct
|
|
** int encode; boolean, if true vax to ieee
|
|
** else ieee to vax
|
|
**
|
|
** converts fields ofstruct in HOST format to ieee format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_sts_char(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_sts_char *pSrc = s;
|
|
struct dbr_sts_char *pDest = d;
|
|
|
|
/* convert vax to ieee or ieee to vax format -- same code*/
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = pSrc->value;
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
memcpy((void *)&pDest->value, (void *)&pSrc->value, num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_long(s,d)
|
|
**
|
|
** converts fields ofstruct in HOST format to ieee format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_sts_long(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_sts_long *pSrc = s;
|
|
struct dbr_sts_long *pDest = d;
|
|
|
|
/* convert vax to ieee or ieee to vax format -- same code*/
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = dbr_ntohl(pSrc->value);
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
cvrt_long(&pDest->value, &pSrc->value, encode, num);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_time_string(s,d)
|
|
**
|
|
** converts fields of struct in HOST format to NET format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_time_string(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_time_string *pSrc = s;
|
|
struct dbr_time_string *pDest = d;
|
|
|
|
/* convert ieee to vax format or vax to ieee */
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->stamp.secPastEpoch = dbr_ntohl(pSrc->stamp.secPastEpoch);
|
|
pDest->stamp.nsec = dbr_ntohl(pSrc->stamp.nsec);
|
|
|
|
if (num == 1) /* if single value */
|
|
strcpy(pDest->value, pSrc->value);
|
|
else
|
|
memcpy(pDest->value, pSrc->value, (MAX_STRING_SIZE * num));
|
|
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_time_short(s,d)
|
|
**
|
|
** converts fields ofstruct in HOST format to ieee format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_time_short(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_time_short *pSrc = s;
|
|
struct dbr_time_short *pDest = d;
|
|
|
|
/* convert vax to ieee or ieee to vax format -- same code*/
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->stamp.secPastEpoch = dbr_ntohl(pSrc->stamp.secPastEpoch);
|
|
pDest->stamp.nsec = dbr_ntohl(pSrc->stamp.nsec);
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
cvrt_short(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_time_float(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_time_float(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_time_float *pSrc = s;
|
|
struct dbr_time_float *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->stamp.secPastEpoch = dbr_ntohl(pSrc->stamp.secPastEpoch);
|
|
pDest->stamp.nsec = dbr_ntohl(pSrc->stamp.nsec);
|
|
|
|
cvrt_float(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_time_double(s,d)
|
|
**
|
|
** if encode
|
|
** converts struct in HOST format to ieee format
|
|
** else
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format;
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_time_double(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_time_double *pSrc = s;
|
|
struct dbr_time_double *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->stamp.secPastEpoch = dbr_ntohl(pSrc->stamp.secPastEpoch);
|
|
pDest->stamp.nsec = dbr_ntohl(pSrc->stamp.nsec);
|
|
|
|
cvrt_double(&pSrc->value, &pDest->value, encode, num);
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_time_enum(s,d)
|
|
**
|
|
** converts fields of struct in NET format to fields with HOST format
|
|
** or
|
|
** converts fields of struct in HOST format to fields with NET format
|
|
**
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_time_enum(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_time_enum *pSrc = s;
|
|
struct dbr_time_enum *pDest = d;
|
|
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->stamp.secPastEpoch = dbr_ntohl(pSrc->stamp.secPastEpoch);
|
|
pDest->stamp.nsec = dbr_ntohl(pSrc->stamp.nsec);
|
|
if (num == 1)
|
|
pDest->value = dbr_ntohs(pSrc->value);
|
|
else {
|
|
cvrt_enum(&pSrc->value,&pDest->value,encode,num);
|
|
}
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
** cvrt_sts_char(s,d)
|
|
**
|
|
** converts fields ofstruct in HOST format to ieee format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_time_char(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_time_char *pSrc = s;
|
|
struct dbr_time_char *pDest = d;
|
|
|
|
/* convert vax to ieee or ieee to vax format -- same code*/
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->stamp.secPastEpoch = dbr_ntohl(pSrc->stamp.secPastEpoch);
|
|
pDest->stamp.nsec = dbr_ntohl(pSrc->stamp.nsec);
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = pSrc->value;
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
memcpy((void *)&pDest->value, (void *)&pSrc->value, num);
|
|
}
|
|
}
|
|
|
|
/****************************************************************************
|
|
** cvrt_time_long(s,d)
|
|
**
|
|
** converts fields ofstruct in HOST format to ieee format
|
|
** or
|
|
** converts fields of struct in NET format to fields with HOST
|
|
** format
|
|
****************************************************************************/
|
|
|
|
LOCAL void cvrt_time_long(
|
|
void *s, /* source */
|
|
void *d, /* destination */
|
|
int encode, /* cvrt HOST to NET if T */
|
|
unsigned long num /* number of values */
|
|
)
|
|
{
|
|
struct dbr_time_long *pSrc = s;
|
|
struct dbr_time_long *pDest = d;
|
|
|
|
/* convert vax to ieee or ieee to vax format -- same code*/
|
|
pDest->status = dbr_ntohs(pSrc->status);
|
|
pDest->severity = dbr_ntohs(pSrc->severity);
|
|
pDest->stamp.secPastEpoch = dbr_ntohl(pSrc->stamp.secPastEpoch);
|
|
pDest->stamp.nsec = dbr_ntohl(pSrc->stamp.nsec);
|
|
|
|
if (num == 1) /* single value */
|
|
pDest->value = dbr_ntohl(pSrc->value);
|
|
else /* array chan-- multiple pts */
|
|
{
|
|
cvrt_long(&pDest->value, &pSrc->value, encode, num);
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef MIT_FLOAT
|
|
/************************************************************************/
|
|
/* double convert */
|
|
/* (THIS ASSUMES IEEE IS THE NETWORK FLOATING POINT FORMAT) */
|
|
/************************************************************************/
|
|
|
|
/* (this includes mapping of fringe reals to zero or infinity) */
|
|
/* (byte swaps included in conversion */
|
|
|
|
struct ieeedbl{
|
|
unsigned int mant2 : 32;
|
|
unsigned int mant1 : 20;
|
|
unsigned int exp : 11;
|
|
unsigned int sign : 1;
|
|
};
|
|
|
|
#define IEEE_DBL_SB 1023
|
|
|
|
/* Conversion Range */
|
|
/* -1022<exp<1024 with mantissa of form 1.mant */
|
|
#define DBLEXPMINIEEE -1022 /* min for norm # IEEE exponent */
|
|
|
|
struct mitdbl{
|
|
unsigned int mant1 : 7;
|
|
unsigned int exp : 8;
|
|
unsigned int sign : 1;
|
|
unsigned int mant2 : 16;
|
|
unsigned int mant3 : 16;
|
|
unsigned int mant4 : 16;
|
|
};
|
|
|
|
/* Exponent sign bias */
|
|
#define MIT_DBL_SB 129
|
|
|
|
/* Conversion Ranges */
|
|
/* -128<exp<126 with mantissa of form 1.mant */
|
|
#define DBLEXPMAXMIT 126 /* max MIT exponent */
|
|
#define DBLEXPMINMIT -128 /* min MIT exponent */
|
|
|
|
|
|
void htond(double *pHost, double *pNet)
|
|
{
|
|
double copyin;
|
|
struct mitdbl *pMIT;
|
|
struct ieeedbl *pIEEE;
|
|
long *ptmp;
|
|
long tmp;
|
|
|
|
copyin = *pHost;
|
|
pMIT = (struct mitdbl *)©in;
|
|
pIEEE = (struct ieeedbl *)pNet;
|
|
|
|
if( ((int)pMIT->exp) < (DBLEXPMINMIT+MIT_DBL_SB) ){
|
|
pIEEE->mant1 = 0;
|
|
pIEEE->mant2 = 0;
|
|
pIEEE->exp = 0;
|
|
pIEEE->sign = 0;
|
|
}
|
|
else{
|
|
pIEEE->exp = ((int)pMIT->exp)+(IEEE_DBL_SB-MIT_DBL_SB);
|
|
pIEEE->mant1 = (pMIT->mant1<<13) | (pMIT->mant2>>3);
|
|
pIEEE->mant2 = (pMIT->mant2<<29) | (pMIT->mant3<<13) |
|
|
(pMIT->mant4>>3);
|
|
pIEEE->sign = pMIT->sign;
|
|
}
|
|
|
|
/*
|
|
* byte swap to net order
|
|
*/
|
|
ptmp = (long *) pNet;
|
|
tmp = htonl(ptmp[0]);
|
|
ptmp[0] = htonl(ptmp[1]);
|
|
ptmp[1] = tmp;
|
|
}
|
|
|
|
|
|
/*
|
|
* sign must be forced to zero if the exponent is zero to prevent a reserved
|
|
* operand fault- joh 9-13-90
|
|
*/
|
|
void ntohd(double *pNet, double *pHost)
|
|
{
|
|
double copyin;
|
|
struct mitdbl *pMIT;
|
|
struct ieeedbl *pIEEE;
|
|
long *ptmp;
|
|
long tmp;
|
|
|
|
copyin = *pNet;
|
|
pMIT = (struct mitdbl *)pHost;
|
|
pIEEE = (struct ieeedbl *)©in;
|
|
|
|
/*
|
|
* Byte swap from net order to host order
|
|
*/
|
|
ptmp = (long *) pIEEE;
|
|
tmp = htonl(ptmp[0]);
|
|
ptmp[0] = htonl(ptmp[1]);
|
|
ptmp[1] = tmp;
|
|
|
|
if( ((int)pIEEE->exp) > (DBLEXPMAXMIT + IEEE_DBL_SB) ){
|
|
pMIT->sign = pIEEE->sign;
|
|
pMIT->exp = DBLEXPMAXMIT + MIT_DBL_SB;
|
|
pMIT->mant1 = ~0;
|
|
pMIT->mant2 = ~0;
|
|
pMIT->mant3 = ~0;
|
|
pMIT->mant4 = ~0;
|
|
}
|
|
else if( ((int)pIEEE->exp) < (DBLEXPMINMIT + IEEE_DBL_SB) ){
|
|
pMIT->sign = 0;
|
|
pMIT->exp = 0;
|
|
pMIT->mant1 = 0;
|
|
pMIT->mant2 = 0;
|
|
pMIT->mant3 = 0;
|
|
pMIT->mant4 = 0;
|
|
}
|
|
else{
|
|
pMIT->sign = pIEEE->sign;
|
|
pMIT->exp = ((int)pIEEE->exp)+(MIT_DBL_SB-IEEE_DBL_SB);
|
|
pMIT->mant1 = pIEEE->mant1>>13;
|
|
pMIT->mant2 = (pIEEE->mant1<<3) | (pIEEE->mant2>>29);
|
|
pMIT->mant3 = pIEEE->mant2>>13;
|
|
pMIT->mant4 = pIEEE->mant2<<3;
|
|
}
|
|
}
|
|
|
|
#endif /*MIT_FLOAT*/
|
|
|
|
#ifndef CONVERSION_REQUIRED
|
|
void htond(double *IEEEhost, double *IEEEnet)
|
|
{
|
|
*IEEEnet = *IEEEhost;
|
|
}
|
|
|
|
void ntohd(double *IEEEnet, double *IEEEhost)
|
|
{
|
|
*IEEEhost = *IEEEnet;
|
|
}
|
|
|
|
void ntohf(float *IEEEnet, float *IEEEhost)
|
|
{
|
|
*IEEEhost = *IEEEnet;
|
|
}
|
|
|
|
void htonf(float *IEEEhost, float *IEEEnet)
|
|
{
|
|
*IEEEnet = *IEEEhost;
|
|
}
|
|
#endif /* not MIT_FLOAT */
|
|
|