view dump-sat.c @ 63:fbf26ed4884d

dump-sat: a utility to dump UBX-NAV-SAT messages Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Mon, 20 Jan 2020 10:16:31 -0500
parents dump-ecef.c@d135288b7f53
children 3de43d6cacd6
line wrap: on
line source

/*
 * Copyright (c) 2019-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "dump-common.h"

void process_ubx_message(const struct ubx_header *header,
			 const uint8_t *raw, size_t len,
			 uint64_t tick)
{
	struct ubx_nav_sat *msg;
	uint8_t local_raw[len];
	int i;

	if ((header->class != UBX_CLASS_NAV) || (header->id != 0x35))
		return;

	memcpy(&local_raw, raw, len);
	msg = (struct ubx_nav_sat *) local_raw;

	ASSERT3U(msg->version, ==, 1);

	msg->itow  = le32_to_cpu(msg->itow);

	for (i = 0; i < msg->num_svs; i++) {
		msg->sv[i].azim = le16_to_cpu(msg->sv[i].azim);
		msg->sv[i].prres = le16_to_cpu(msg->sv[i].prres);
		msg->sv[i].flags = le32_to_cpu(msg->sv[i].flags);

		printf("{\"msg\":\"UBX-NAV-SAT\",\"itow\":%.3f,"
		       "\"gnss\":%u,\"sv\":%u,"
		       "\"cno\":%u,\"az\":%d,\"el\":%d}\n",
		       msg->itow / 1000.,
		       msg->sv[i].gnssid, msg->sv[i].svid,
		       msg->sv[i].cno,
		       (int16_t) msg->sv[i].azim,
		       (int8_t) msg->sv[i].elev);
	}
}