2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
24 #include <libubox/uloop.h>
30 static struct ustream_fd stream
;
31 static struct ubus_auto_conn conn
;
32 static struct blob_buf b
;
33 struct timespec stamp
= { 0 };
38 clock_gettime(CLOCK_MONOTONIC
, &stamp
);
42 gps_info(struct ubus_context
*ctx
, struct ubus_object
*obj
,
43 struct ubus_request_data
*req
, const char *method
,
44 struct blob_attr
*msg
)
48 clock_gettime(CLOCK_MONOTONIC
, &now
);
53 blobmsg_add_u8(&b
, "signal", 0);
55 blobmsg_add_u32(&b
, "age", now
.tv_sec
- stamp
.tv_sec
);
56 blobmsg_add_string(&b
, "lattitude", lattitude
);
57 blobmsg_add_string(&b
, "longitude", longitude
);
58 blobmsg_add_string(&b
, "elivation", elivation
);
59 blobmsg_add_string(&b
, "course", course
);
60 blobmsg_add_string(&b
, "speed", speed
);
62 ubus_send_reply(ctx
, req
, b
.head
);
64 return UBUS_STATUS_OK
;
67 static const struct ubus_method gps_methods
[] = {
68 UBUS_METHOD_NOARG("info", gps_info
),
71 static struct ubus_object_type gps_object_type
=
72 UBUS_OBJECT_TYPE("gps", gps_methods
);
74 static struct ubus_object gps_object
= {
76 .type
= &gps_object_type
,
77 .methods
= gps_methods
,
78 .n_methods
= ARRAY_SIZE(gps_methods
),
82 ubus_connect_handler(struct ubus_context
*ctx
)
86 ret
= ubus_add_object(ctx
, &gps_object
);
88 fprintf(stderr
, "Failed to add object: %s\n", ubus_strerror(ret
));
94 LOG("ugps <device>\n");
99 main(int argc
, char ** argv
)
102 signal(SIGPIPE
, SIG_IGN
);
108 conn
.cb
= ubus_connect_handler
;
109 ubus_auto_connect(&conn
);
110 nmea_open(argv
[1], &stream
, B4800
);