- fread(pi, sizeof(Platform_info), 1, in);
- /* Now, convert from Big Endian. */
- if (little_endian()) {
- swap_4_bytes(&pi->len);
- swap_4_bytes(&pi->longitude);
- swap_4_bytes(&pi->latitude);
- swap_4_bytes(&pi->altitude);
- swap_4_bytes(&pi->height);
- swap_4_bytes(&pi->ew_speed);
- swap_4_bytes(&pi->ns_speed);
- swap_4_bytes(&pi->v_speed);
- swap_4_bytes(&pi->heading);
- swap_4_bytes(&pi->roll);
- swap_4_bytes(&pi->pitch);
- swap_4_bytes(&pi->drift);
- swap_4_bytes(&pi->rotation);
- swap_4_bytes(&pi->tilt);
- swap_4_bytes(&pi->ew_wind_speed);
- swap_4_bytes(&pi->ns_wind_speed);
- swap_4_bytes(&pi->v_wind_speed);
- swap_4_bytes(&pi->heading_rate);
- swap_4_bytes(&pi->pitch_rate);
+ /* Read the id code to make sure we have "ASIB" for platform info. If
+ * id is ASIB, then read data into the Platform_info structure. If it is
+ * XSTF, read and discard remainder of block, which will have a different
+ * size than Platform_info. XSTF is undocumented, but apparently it takes
+ * the place of ASIB when radar is grounded.
+ */
+
+ fread(pi->code, sizeof(pi->code), 1, in);
+ fread(&pi->len, sizeof(pi->len), 1, in);
+ if (do_swap) swap_4_bytes(&pi->len);
+ len_first_two = sizeof(pi->code) + sizeof(pi->len);
+
+ if (strncmp(pi->code, "ASIB", 4) == 0) {
+ fread(&pi->longitude, sizeof(Platform_info)-len_first_two, 1, in);
+ /* Read past any extra bytes. */
+ if (pi->len > sizeof(Platform_info)) {
+ if (read_extra_bytes(pi->len - sizeof(Platform_info), in) <= 0)
+ fprintf(stderr,"Called from %s, line: %d\n",__FILE__,__LINE__-1);
+ }
+ /* Now, convert from Big Endian. */
+ if (do_swap) {
+ swap_4_bytes(&pi->longitude);
+ swap_4_bytes(&pi->latitude);
+ swap_4_bytes(&pi->altitude);
+ swap_4_bytes(&pi->height);
+ swap_4_bytes(&pi->ew_speed);
+ swap_4_bytes(&pi->ns_speed);
+ swap_4_bytes(&pi->v_speed);
+ swap_4_bytes(&pi->heading);
+ swap_4_bytes(&pi->roll);
+ swap_4_bytes(&pi->pitch);
+ swap_4_bytes(&pi->drift);
+ swap_4_bytes(&pi->rotation);
+ swap_4_bytes(&pi->tilt);
+ swap_4_bytes(&pi->ew_wind_speed);
+ swap_4_bytes(&pi->ns_wind_speed);
+ swap_4_bytes(&pi->v_wind_speed);
+ swap_4_bytes(&pi->heading_rate);
+ swap_4_bytes(&pi->pitch_rate);
+ }
+ } else if (strncmp(pi->code, "XSTF", 4) == 0) {
+ /* Read to end of XSTF block. */
+ if (read_extra_bytes(pi->len - len_first_two, in) <= 0)
+ fprintf(stderr,"Called from %s, line: %d\n", __FILE__, __LINE__ - 1);
+ } else {
+ fprintf(stderr,"Unexpected block id: \"%s\"."
+ " Expected \"ASIB\" or \"XSTF\"\n", pi->code);