[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.
This commit is contained in:
parent
e77ad8fb0f
commit
3626a21f99
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue