ubus: display only available information
[project/ugps.git] / main.c
diff --git a/main.c b/main.c
index 7696cbc9c26282e1a55f68e2abdeebbb6517f862..2ab0f8cf388099cf8e033d234ee07a77daf3509c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -52,15 +52,20 @@ gps_info(struct ubus_context *ctx, struct ubus_object *obj,
 
        blob_buf_init(&b, 0);
 
-       if (!stamp.tv_sec) {
+       if (!stamp.tv_sec || !gps_fields) {
                blobmsg_add_u8(&b, "signal", 0);
        } else {
                blobmsg_add_u32(&b, "age", now.tv_sec - stamp.tv_sec);
-               blobmsg_add_string(&b, "latitude", latitude);
-               blobmsg_add_string(&b, "longitude", longitude);
-               blobmsg_add_string(&b, "elevation", elevation);
-               blobmsg_add_string(&b, "course", course);
-               blobmsg_add_string(&b, "speed", speed);
+               if (gps_fields & GPS_FIELD_LAT)
+                       blobmsg_add_string(&b, "latitude", latitude);
+               if (gps_fields & GPS_FIELD_LON)
+                       blobmsg_add_string(&b, "longitude", longitude);
+               if (gps_fields & GPS_FIELD_ALT)
+                       blobmsg_add_string(&b, "elevation", elevation);
+               if (gps_fields & GPS_FIELD_COG)
+                       blobmsg_add_string(&b, "course", course);
+               if (gps_fields & GPS_FIELD_SPD)
+                       blobmsg_add_string(&b, "speed", speed);
        }
        ubus_send_reply(ctx, req, b.head);