[lib-result] Add {algorithm,}result_to_csv()
Add owl_result_to_csv() and owl_algorithm_result_to_csv(), that allow to get an owl_result or owl_algorithm_result as a CSV string.
This commit is contained in:
parent
44055929b1
commit
8da063b597
|
@ -182,6 +182,62 @@ void owl_fill_result(owl_result **result, char *csv)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Converts an owl_result back to a CSV string.
|
||||
* 'dst' must be an allocated string of at least OWL_CSV_RESULT_STRLEN
|
||||
* characters.
|
||||
*/
|
||||
void owl_result_to_csv(char dst[OWL_CSV_RESULT_STRLEN],
|
||||
const owl_result *const src)
|
||||
{
|
||||
size_t dst_len ;
|
||||
char timestamp_str[OWL_TIMESTAMP_STRLEN] ;
|
||||
|
||||
assert(src) ;
|
||||
|
||||
owl_timestamp_to_string(timestamp_str, src->mobile_timestamp) ;
|
||||
snprintf(dst, OWL_CSV_RESULT_REQUEST_STRLEN,
|
||||
"%s;%"PRIu8";%s",
|
||||
src->mobile_mac_addr,
|
||||
src->request_type,
|
||||
timestamp_str) ;
|
||||
dst_len = strlen(dst) ;
|
||||
|
||||
owl_algorithm_result *algo = src->results ;
|
||||
while (algo)
|
||||
{
|
||||
char algo_str[OWL_CSV_ALGORITHM_RESULT_STRLEN] ;
|
||||
owl_algorithm_result_to_csv(algo_str, algo) ;
|
||||
dst[dst_len++] = ';' ;
|
||||
strncpy(dst + dst_len, algo_str, OWL_CSV_ALGORITHM_RESULT_STRLEN) ;
|
||||
dst_len += strlen(algo_str) ;
|
||||
algo = algo->next ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Converts an owl_algorithm_result back to a CSV string.
|
||||
* 'dst' must be an allocated string of at least
|
||||
* OWL_CSV_ALGORITHM_RESULT_STRLEN characters.
|
||||
*/
|
||||
void
|
||||
owl_algorithm_result_to_csv(char dst[OWL_CSV_ALGORITHM_RESULT_STRLEN],
|
||||
const owl_algorithm_result *const src)
|
||||
{
|
||||
assert(src) ;
|
||||
|
||||
snprintf(dst, OWL_CSV_ALGORITHM_RESULT_STRLEN,
|
||||
"%s;%f;%f;%f;%f;%s",
|
||||
src->algorithm,
|
||||
src->x,
|
||||
src->y,
|
||||
src->z,
|
||||
src->error,
|
||||
src->area ? src->area : "") ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prints an owl_result to the given stream.
|
||||
*/
|
||||
|
|
|
@ -57,6 +57,12 @@ typedef struct _owl_result
|
|||
void owl_receive_position(int sockfd, owl_result **result) ;
|
||||
void owl_fill_result(owl_result **result, char *csv) ;
|
||||
|
||||
void owl_result_to_csv(char dst[OWL_CSV_RESULT_STRLEN],
|
||||
const owl_result *const src) ;
|
||||
void
|
||||
owl_algorithm_result_to_csv(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,
|
||||
const owl_algorithm_result *const src) ;
|
||||
|
|
Loading…
Reference in New Issue