Feature: ocat/ot-recorder: configurable geohash precision per invocation (--precision)

closes #14
This commit is contained in:
Jan-Piet Mens 2015-09-07 17:40:50 +02:00
parent 17f749a6b5
commit 2c586b5a5b
5 changed files with 26 additions and 2 deletions

5
ocat.c
View File

@ -142,6 +142,7 @@ void usage(char *prog)
printf(" --killdata requires -u and -d\n");
printf(" --storage -S storage dir (./store)\n");
printf(" --norevgeo -G disable ghash to reverge-geo lookups\n");
printf(" --precision ghash precision (dflt: %d)\n", GEOHASH_PREC);
printf("\n");
printf("Options override these environment variables:\n");
printf(" $OCAT_USERNAME\n");
@ -201,6 +202,7 @@ int main(int argc, char **argv)
{ "storage", required_argument, 0, 'S'},
{ "last", no_argument, 0, 'L'},
{ "fields", required_argument, 0, 1},
{ "precision", required_argument, 0, 2},
{ "killdata", no_argument, 0, 'K'},
{ "norevgeo", no_argument, 0, 'G'},
{0, 0, 0, 0}
@ -216,6 +218,9 @@ int main(int argc, char **argv)
if (strcmp(optarg, "ALL") != 0)
fields = json_splitter(optarg, ",");
break;
case 2:
geohash_setprec(atoi(optarg));
break;
case 'l':
list = 1;
break;

View File

@ -500,7 +500,7 @@ void on_message(struct mosquitto *mosq, void *userdata, const struct mosquitto_m
*/
utstring_renew(ghash);
p = geohash_encode(lat, lon, GEOHASH_PREC);
p = geohash_encode(lat, lon, geohash_prec());
if (p != NULL) {
utstring_printf(ghash, "%s", p);
free(p);
@ -667,6 +667,7 @@ void usage(char *prog)
printf(" --http-port <port> -A HTTP port (8083)\n");
printf(" --doc-root <directory> document root (./wdocs)\n");
#endif
printf(" --precision ghash precision (dflt: %d)\n", GEOHASH_PREC);
printf("\n");
printf("Options override these environment variables:\n");
printf(" $OTR_HOST MQTT hostname\n");
@ -741,6 +742,7 @@ int main(int argc, char **argv)
{ "port", required_argument, 0, 'p'},
{ "storage", required_argument, 0, 'S'},
{ "logfacility", required_argument, 0, 4},
{ "precision", required_argument, 0, 5},
#ifdef HAVE_HTTP
{ "http-host", required_argument, 0, 3},
{ "http-port", required_argument, 0, 'A'},
@ -755,6 +757,9 @@ int main(int argc, char **argv)
break;
switch (ch) {
case 5:
geohash_setprec(atoi(optarg));
break;
case 4:
logfacility = strdup(optarg);
break;

View File

@ -474,7 +474,7 @@ static JsonNode *line_to_location(char *line)
lon = j->number_;
}
if ((ghash = geohash_encode(lat, lon, GEOHASH_PREC)) != NULL) {
if ((ghash = geohash_encode(lat, lon, geohash_prec())) != NULL) {
json_append_member(o, "ghash", json_mkstring(ghash));
}
json_append_member(o, "isorcv", json_mkstring(tstamp));

12
util.c
View File

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include "config.h"
#include "util.h"
#include "misc.h"
#include <sys/types.h>
@ -528,3 +529,14 @@ int safewrite(char *filename, char *buf)
free(tmpfile);
return (0);
}
static int _precision = GEOHASH_PREC;
void geohash_setprec(int precision)
{
_precision = precision;
}
int geohash_prec(void)
{
return (_precision);
}

2
util.h
View File

@ -28,5 +28,7 @@ int cat(char *filename, int (*func)(char *, void *), void *param);
FILE *pathn(char *mode, char *prefix, UT_string *user, UT_string *device, char *suffix);
int safewrite(char *filename, char *buf);
void olog(int level, char *fmt, ...);
void geohash_setprec(int precision);
int geohash_prec(void);
#endif