diff --git a/doc/FENCES.md b/doc/FENCES.md index 95dff1b..610e741 100644 --- a/doc/FENCES.md +++ b/doc/FENCES.md @@ -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 diff --git a/fences.c b/fences.c index a221a0d..f6ef913 100644 --- a/fences.c +++ b/fences.c @@ -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 */ } diff --git a/hooks.c b/hooks.c index a06f4d3..babc0b0 100644 --- a/hooks.c +++ b/hooks.c @@ -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); diff --git a/hooks.h b/hooks.h index 2a22a0e..526af16 100644 --- a/hooks.h +++ b/hooks.h @@ -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 */ diff --git a/storage.c b/storage.c index 2aa04ee..666e2eb 100644 --- a/storage.c +++ b/storage.c @@ -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