Purpose

Converts a physical data value into a binary representation using a type descriptor.

Format

        void ndConvertFromPhys(
       TD2 *typeDescriptor,
       double value,
       unsigned char dataOut[],
       long *len);
      

Input

typeDescriptor

A struct that specifies the conversion of the physical value to its binary representation:

             typedef struct {
        long StartByte;
        long ByteLength;
        unsigned short ByteOrder;
        unsigned short DataType;
        double ScaleFactor;
        double ScaleOffset;
        } TD2;
      

StartByte is ignored by ndConvertFromPhys.

ByteLength is the number of bytes in the binary representation.

ByteOrder defines the byte order for multibyte representations. The values are:

0: MSB_FIRST (Motorola)

1: LSB_FIRST (Intel)

DataType is the binary representation format:

0: Unsigned. Only byte lengths of 1–4 are allowed.

1: Signed. Only byte lengths of 1–4 are allowed.

2: Float. Only byte lengths 4 or 8 are allowed.

ScaleFactor defines the physical value scaling:

Phys = (ScaleFactor) * (binary representation) + (ScaleOffset)

ScaleOffset (refer to ScaleFactor)

value

The physical value to be converted to a binary representation. Output

dataOut

Points to the byte array to be filled with the binary representation of value.

len

On input, len must contain the dataOut array length. On return, it contains the number of valid data bytes in the dataOut array. Description

Data input to diagnostic services (for example, ndWriteDataByLocalIdentifier) is usually a byte array of binary data. If you have the data input description (for example, byte 3 and 4 are engine RPM scaled as .25 * x RPM in Motorola representation), you can use ndConvertFromPhys to convert the physical value to the byte stream by filling an appropriate typeDescriptor struct.

ndConvertFromPhys converts only the portion specified by one type descriptor to a binary representation. If your data input consists of several values, you can use ndConvertFromPhys multiple times on different parts of the byte array.