Fluke 2620A Benutzerhandbuch

Seite von 197
2620A/2625A
Users Manual
E-2
/*
-* decode(): Decode LOG_BIN? response string into raw byte stream
**
** Decoding is done on multiples of four input bytes:
**
**           543210   543210   543210   543210    (bit number in ASCII bytes)
**        +--------+--------+--------+--------+
**        | src[0] | src[1] | src[2] | src[3] |   ASCII string input
**        +--------+--------+--------+--------+
**           765432   107654   321076   543210    (bit number in raw bytes)
**           /          /          /
**          /          /          /
**         |          /          /
**         |         /          /
**         |        |          /
**         |        |         /
**         |        |        |
**         76543210 76543210 76543210             (bit number in raw bytes)
**        +--------+--------+--------+
**        | dst[0] | dst[1] | dst[2] |            Raw data output
**        +--------+--------+--------+
**
** Inputs:
**      dst     Destination for binary data (must have enough space
**              allocated; the maximum needed is 6 timestamp bytes + 3
**              bytes for temp units, measurement rate, and digital I/O
**              + 4 bytes/float * 22 floating point values = 97 bytes).
**
**      src     Source ASCII string (null terminated)
**
** Outputs:
**      dst     Set to binary data, based on ASCII string
**
** Returns:
**      Number of bytes placed in destination buffer
*/
int
decode(dst, src)
    unsigned char *dst;
    char *src;
{
    /* src to dst xlate */
    static struct nibtab_s {
        int lindex;
        int lmask;
        int lshift;
        int rindex;
        int rmask;
        int rshift;
    } nibtab[3] = {
        /* left            right */
        0, 0x3f, 2,     1, 0x30, 4,     /* dst[0] from src[0] and src[1] */
        1, 0x0f, 4,     2, 0x3c, 2,     /* dst[1] from src[1] and src[2] */
        2, 0x03, 6,     3, 0x3f, 0,     /* dst[2] from src[2] and src[3] */
    };
    auto unsigned char n;
    auto struct nibtab_s *t;
    auto unsigned char tmpsrc[4];
    auto int dst_bytes;
    /* Number of bytes created */
    dst_bytes = 0;
    /* Process src in chunks of four */
    while (*src) {
        /* Copy source, filing "holes" at end with zeros */
        for (n = 0; n < 4; n++) {
            if (*src)
                tmpsrc[n] = *src++ - ’0’;
            else
                tmpsrc[n] = 0;
        }
        /* Mung source into destination */
        for (t = nibtab; t < &nibtab[3]; t++) {
            *dst  = (tmpsrc[t->lindex] & t->lmask) << t->lshift;
            *dst |= (tmpsrc[t->rindex] & t->rmask) >> t->rshift;
            dst++;
            dst_bytes++;
        }
    }
    return (dst_bytes);
}
Figure E-1. ASCII String Decoding