E-1. Ascii String Decoding - Fluke 2620A User Manual

Hydra series ii data acquisition unit, hydra series ii data logger
Hide thumbs Also See for 2620A:
Table of Contents

Advertisement

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
**
+--------+--------+--------+--------+
**
| src[0] | src[1] | src[2] | src[3] |
**
+--------+--------+--------+--------+
**
765432
107654
**
/
/
**
/
/
**
|
/
**
|
/
**
|
|
**
|
|
**
|
|
**
76543210 76543210 76543210
**
+--------+--------+--------+
**
| dst[0] | dst[1] | dst[2] |
**
+--------+--------+--------+
**
** 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
0, 0x3f, 2,
1, 0x30, 4,
1, 0x0f, 4,
2, 0x3c, 2,
2, 0x03, 6,
3, 0x3f, 0,
};
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
543210
543210
(bit number in ASCII bytes)
ASCII string input
321076
543210
(bit number in raw bytes)
/
/
/
/
/
/
|
(bit number in raw bytes)
Raw data output
right */
/* dst[0] from src[0] and src[1] */
/* dst[1] from src[1] and src[2] */
/* dst[2] from src[2] and src[3] */

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

2625a

Table of Contents