From 3626a21f9999312bba98f9469bca169707b4ad4a Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 22 Aug 2011 12:01:59 +0200 Subject: [PATCH] [lib-result] Add simplified CSV format functions Add functions owl_result_to_csv_simple() and owl_algorithm_result_to_csv_simple(), that convert an owl_result and an owl_algorithm_result to a CSV string, in a simplified format. --- .../libowlps-resultreader-udp.c | 58 +++++++++++++++++++ .../owlps-resultreader-udp.h | 5 ++ 2 files changed, 63 insertions(+) diff --git a/libowlps-resultreader-udp/libowlps-resultreader-udp.c b/libowlps-resultreader-udp/libowlps-resultreader-udp.c index c384309..b35eb0a 100644 --- a/libowlps-resultreader-udp/libowlps-resultreader-udp.c +++ b/libowlps-resultreader-udp/libowlps-resultreader-udp.c @@ -269,6 +269,64 @@ owl_algorithm_result_to_csv(char dst[OWL_CSV_ALGORITHM_RESULT_STRLEN], } +/* + * Converts an owl_result back to a CSV string, in a simplified format. + * Only the *first* algorithm in the result's algorithm list will be + * included in the string. + * 'dst' must be an allocated string of at least OWL_CSV_RESULT_STRLEN + * characters. + * + * CSV format: + * Mobile_MAC;First_algorithm + * First_algorithm is the first algorithm in src->results. Its format + * is documented in owl_algorithm_result_to_csv_simple(). + */ +void owl_result_to_csv_simple(char dst[OWL_CSV_RESULT_STRLEN], + const owl_result *const src) +{ + size_t dst_len ; + char algo_str[OWL_CSV_ALGORITHM_RESULT_STRLEN] ; + + assert(src) ; + + strncpy(dst, src->mobile_mac_addr, OWL_ETHER_ADDR_STRLEN) ; + dst[OWL_ETHER_ADDR_STRLEN - 1] = ';' ; + dst_len = OWL_ETHER_ADDR_STRLEN ; + + if (! src->results) + return ; + + owl_algorithm_result_to_csv_simple(algo_str, src->results) ; + strncpy(dst + dst_len, algo_str, OWL_CSV_ALGORITHM_RESULT_STRLEN) ; +} + + +/* + * Converts an owl_algorithm_result back to a CSV string, in a + * simplified format. + * 'dst' must be an allocated string of at least + * OWL_CSV_ALGORITHM_RESULT_STRLEN characters. + * + * CSV format: + * X;Y;Z;Area_name + * Area_name is the name of the area or room in which the mobile is (may + * be empty). + */ +void owl_algorithm_result_to_csv_simple +(char dst[OWL_CSV_ALGORITHM_RESULT_STRLEN], + const owl_algorithm_result *const src) +{ + assert(src) ; + + snprintf(dst, OWL_CSV_ALGORITHM_RESULT_STRLEN, + "%f;%f;%f;%s", + src->x, + src->y, + src->z, + src->area ? src->area : "") ; +} + + /* * Prints an owl_result to the given stream. */ diff --git a/libowlps-resultreader-udp/owlps-resultreader-udp.h b/libowlps-resultreader-udp/owlps-resultreader-udp.h index 8e730e3..0142388 100644 --- a/libowlps-resultreader-udp/owlps-resultreader-udp.h +++ b/libowlps-resultreader-udp/owlps-resultreader-udp.h @@ -63,6 +63,11 @@ void owl_result_to_csv(char dst[OWL_CSV_RESULT_STRLEN], void owl_algorithm_result_to_csv(char dst[OWL_CSV_ALGORITHM_RESULT_STRLEN], const owl_algorithm_result *const src) ; +void owl_result_to_csv_simple(char dst[OWL_CSV_RESULT_STRLEN], + const owl_result *const src) ; +void owl_algorithm_result_to_csv_simple +(char dst[OWL_CSV_ALGORITHM_RESULT_STRLEN], + const owl_algorithm_result *const src) ; void owl_fprint_result(FILE *stream, const owl_result *const src) ; void owl_fprint_algorithm_result(FILE *stream,