[teqc] Rockwell binary
Lou Estey
lou at unavco.org
Mon May 29 08:55:30 MDT 2006
Jay,
> Indeed it is an endian problem. I should have looked deeper in
> the sample file for the 0xff81 vs 0x81ff rockwell sends. I'm not
> sure how teqc deals with the endian-ness of rockwell's unsigned triple
> integer format in 1102 records. I would guess, swapping lo/hi of each
> byte in each of the 3 words, then swapping word 1 and 3. But that's
> just a bit of work.. thanks for the help.
It depends on whether you're reading the 1102's 6-byte integer on a
little- or big-endian processor; see below, which is generalized for
either little-endian formats (like the Zodiac's) or big-endian (of
which none have shown up so far), and avoids requiring 8-byte integers,
i.e. it just uses 2- and 4-byte unsigned integers and puts the result
into an 8-byte floating point.
--lou
void
extract_uint6_2m16
#if KR_C
(buf, off, ul6)
uint1 *buf;
uint4 *off;
real8 *ul6;
#else
(uint1 *buf, uint4 *off, real8 *ul6)
#endif
{
/* function to convert a unsigned two's complement 6-byte integer
into the equivalent real8 * 2e-16 (modeled after TI-4100 data conversion for Rockwell Zodiac)
*/
uint2 us;
uint4 ul;
switch (teq.tr.opt & LITTLE_ENDIAN_RECORD) {
case LITTLE_ENDIAN_RECORD:
memcpy((void *)&ul, (void *)(buf + *off), (size_t)4);
memcpy((void *)&us, (void *)(buf + *off + 4), (size_t)2);
break;
default:
memcpy((void *)&us, (void *)(buf + *off), (size_t)2);
memcpy((void *)&ul, (void *)(buf + *off + 2), (size_t)4);
}
switch (teq.tr.opt & REVERSE_I_ENDIAN) {
case REVERSE_I_ENDIAN:
/* little endian format on a big endian processor
or
big endian format on a little endian processor
*/
reverse_bytes((uint1 *)&ul, 4);
reverse_bytes((uint1 *)&us, 2);
break;
/* default: little endian format on a little endian processor
or
big endian format on a big endian processor
(byte order in ul and us is correct)
*/
}
(*off)+= 6;
(*ul6)= (real8)us*65536. + (real8)ul/65536.;
return;
}
More information about the teqc
mailing list