aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-12-24 00:19:55 +0100
committerHarald Welte <laforge@gnumonks.org>2016-12-24 00:19:55 +0100
commit2c36375f5bbbaa1ccdb587f97ced6e4dd7562ec3 (patch)
treefd37879eaf72e60a3d7a1f1687e50cc7ad1b784b
parent654f1179c06992c65d5b4ea6b067f1846ce19ac9 (diff)
better formatting of output, incldue LOG/MSG prefix, timestamp, ...
-rw-r--r--src/protocol.c32
-rw-r--r--src/protocol.h2
-rw-r--r--src/qxdm-log.c14
3 files changed, 42 insertions, 6 deletions
diff --git a/src/protocol.c b/src/protocol.c
index 64a7ae2..d89603d 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -12,3 +12,35 @@ int diag_push_subsys_hdr(struct msgb *msg, uint8_t subsys, uint8_t code)
return 0;
}
+
+#include <sys/time.h>
+#include <osmocom/gsm/gsm_utils.h>
+
+uint32_t diag_ts_to_fn(uint64_t ts)
+{
+ return (ts/204800)%GSM_MAX_FN;
+}
+
+uint32_t diag_ts_to_epoch(uint64_t qd_time)
+{
+ double qd_ts;
+
+ qd_ts = osmo_load64le(&qd_time);
+ qd_ts *= 1.25*256.0/1000.0;
+
+ /* Sanity check on timestamp (year > 2011) */
+ if (qd_ts < 1000000000) {
+ /* Use current time */
+ int rv = -1;
+ struct timeval tv;
+
+ rv = gettimeofday(&tv, NULL);
+ if (0 == rv)
+ return tv.tv_sec;
+ } else {
+ /* Adjust timestamp from GPS to UNIX */
+ qd_ts += 315964800.0;
+ }
+
+ return qd_ts;
+}
diff --git a/src/protocol.h b/src/protocol.h
index f4aff77..53b9670 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -97,5 +97,7 @@ struct diagpkt_subsys_hdr {
} __attribute__((packed));
int diag_push_subsys_hdr(struct msgb *msg, uint8_t subsys, uint8_t code);
+uint32_t diag_ts_to_fn(uint64_t ts);
+uint32_t diag_ts_to_epoch(uint64_t qd_time);
#endif
diff --git a/src/qxdm-log.c b/src/qxdm-log.c
index ad797f8..9aa6a81 100644
--- a/src/qxdm-log.c
+++ b/src/qxdm-log.c
@@ -44,7 +44,7 @@ static int diag_rx_ext_msg_f(const uint8_t *data, const size_t len)
fmt = (const char *) msg->params + num_args*sizeof(msg->params[0]);
file = fmt + strlen(fmt) + 1;
- printf("%"PRIu64" %-20s(%u): ", msg->timestamp, file, msg->line_nr);
+ printf("MSG(%u|%s:%u): ", diag_ts_to_epoch(msg->timestamp), file, msg->line_nr);
switch (num_args) {
case 0:
fputs(fmt, stdout);
@@ -281,6 +281,9 @@ static void diag_log_handle(struct msgb *msg)
/* FIXME: verify length */
msgb_pull(msg, sizeof(*lh));
+ printf("LOG(0x%04x|%u|%u): ", lh->code,
+ diag_ts_to_epoch(lh->ts), diag_ts_to_fn(lh->ts));
+
for (i = 0; i < ARRAY_SIZE(log_tbl); i++) {
if (log_tbl[i].code == lh->code) {
log_tbl[i].handler(lh, msg);
@@ -288,8 +291,7 @@ static void diag_log_handle(struct msgb *msg)
}
}
- printf("LOG(0x%04x, %"PRIu64"u, %u): %s\n", lh->code, lh->ts, lh->len,
- osmo_hexdump(lh->data, lh->len));
+ printf("%s\n", osmo_hexdump(lh->data, lh->len));
uint8_t subsys = lh->code >> 12;
@@ -311,9 +313,9 @@ static void diag_process_msg(struct diag_instance *di, struct msgb *msg)
diag_rx_ext_msg_f(msgb_data(msg), msgb_length(msg));
break;
default:
- printf("Got %d bytes data of unknown payload type 0x%02x\n",
- msgb_length(msg), msg->l2h[0]);
- printf("%s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
+ printf("Got %d bytes data of unknown payload type 0x%02x: %s\n",
+ msgb_length(msg), msg->l2h[0],
+ osmo_hexdump(msgb_data(msg), msgb_length(msg)));
break;
}
msgb_free(msg);