add dist to geofence report

closes #172
This commit is contained in:
Jan-Piet Mens
2016-12-10 17:50:55 +01:00
parent f43de2032c
commit 73b19bc524
5 changed files with 10 additions and 8 deletions
+1
View File
@@ -56,4 +56,5 @@ end
In addition to the payload as described in the Booklet, recorder enhances the table passed to the Lua function with the following elements:
- `dist` the distance in meters between the current position and the center of the waypoint
- `wplat` / `wplon` are the latitude / longitude of the original waypoint definition
+5 -5
View File
@@ -38,13 +38,13 @@
static int check_a_waypoint(char *key, wpoint *wp, double lat, double lon)
{
double d;
double dist;
bool rewrite = false;
d = haversine_dist(wp->lat, wp->lon, lat, lon);
// printf("WP= rad=%ld, io=%d, dist=%lf %s\n", wp->rad, wp->io, d, wp->desc);
dist = haversine_dist(wp->lat, wp->lon, lat, lon);
// printf("WP= rad=%ld, io=%d, dist=%lf %s\n", wp->rad, wp->io, dist, wp->desc);
if (d < wp->rad) {
if (dist < wp->rad) {
// printf("YEAH: key(%s)\n", key);
if (wp->io == false) {
@@ -62,7 +62,7 @@ static int check_a_waypoint(char *key, wpoint *wp, double lat, double lon)
// printf("%s - %s: EVENT == %s\n", wp->user, wp->device, wp->event == 0 ? "ENTER" : "LEAVE");
#ifdef WITH_LUA
if (wp->ud->luadata) {
hooks_transition(wp->ud, wp->user, wp->device, wp->event, wp->desc, wp->lat, wp->lon, lat, lon, wp->topic, wp->json);
hooks_transition(wp->ud, wp->user, wp->device, wp->event, wp->desc, wp->lat, wp->lon, lat, lon, wp->topic, wp->json, (long)dist);
}
#endif /* WITH_LUA */
}
+2 -1
View File
@@ -385,7 +385,7 @@ void hooks_hook(struct udata *ud, char *topic, JsonNode *fullo)
* json is the original JSON we received enhanced with stuff from recorder.
*/
void hooks_transition(struct udata *ud, char *user, char *device, int event, char *desc, double wplat, double wplon, double lat, double lon, char *topic, JsonNode *json)
void hooks_transition(struct udata *ud, char *user, char *device, int event, char *desc, double wplat, double wplon, double lat, double lon, char *topic, JsonNode *json, long meters)
{
JsonNode *j;
@@ -398,6 +398,7 @@ void hooks_transition(struct udata *ud, char *user, char *device, int event, cha
json_append_member(json, "desc", json_mkstring(desc));
json_append_member(json, "wplat", json_mknumber(wplat));
json_append_member(json, "wplon", json_mknumber(wplon));
json_append_member(json, "dist", json_mknumber(meters));
olog(LOG_DEBUG, "**** Lua hook for %s %s\n",
event == ENTER ? "ENTER" : "LEAVE", desc);
+1 -1
View File
@@ -15,7 +15,7 @@ void hooks_exit(struct luadata *, char *reason);
void hooks_hook(struct udata *ud, char *topic, JsonNode *obj);
int hooks_norec(struct udata *ud, char *user, char *device, char *payload);
JsonNode *hooks_http(struct udata *ud, char *user, char *device, char *payload);
void hooks_transition(struct udata *ud, char *user, char *device, int event, char *desc, double wplat, double wplon, double lat, double lon, char *topic, JsonNode *json);
void hooks_transition(struct udata *ud, char *user, char *device, int event, char *desc, double wplat, double wplon, double lat, double lon, char *topic, JsonNode *json, long meters);
#endif /* WITH_LUA */
+1 -1
View File
@@ -1561,7 +1561,7 @@ static bool load_otrw_waypoints(struct udata *ud, JsonNode *wplist, char *user,
utstring_printf(key, "%s-%s-%s", user, device,
geohash_encode(lat->number_, lon->number_, 10));
printf("--> %s: %s\t(%lf, %lf) (%ld)\n", UB(key), desc->string_, lat->number_, lon->number_, (long)rad->number_);
olog(LOG_DEBUG, "--> %s: %s\t(%lf, %lf) (%ld)", UB(key), desc->string_, lat->number_, lon->number_, (long)rad->number_);
/*
* Just before initially storing in LMDB, we need to determine whether