[lib-result] Add the number of algorithms
Add the field nb_results to owl_result, and change the functions to handle it.
This commit is contained in:
parent
c2aaa3af15
commit
73494defe6
|
@ -54,7 +54,6 @@ owl_result* owl_fill_result(char *csv)
|
|||
{
|
||||
char *csv_field = NULL ;
|
||||
owl_result *result = NULL ;
|
||||
int nb_algorithms = 0 ;
|
||||
|
||||
result = malloc(sizeof(owl_result)) ;
|
||||
memset(result, 0, sizeof(*result)) ;
|
||||
|
@ -111,13 +110,13 @@ owl_result* owl_fill_result(char *csv)
|
|||
if (current_algo == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error reading the algorithm #%d!\n",
|
||||
nb_algorithms) ;
|
||||
result->nb_results + 1) ;
|
||||
break ;
|
||||
}
|
||||
// Insert the current algorithm at the begining of the list
|
||||
current_algo->next = result->results ;
|
||||
result->results = current_algo ;
|
||||
++nb_algorithms ;
|
||||
++result->nb_results ;
|
||||
}
|
||||
while (csv) ;
|
||||
|
||||
|
@ -132,7 +131,7 @@ owl_result* owl_fill_result(char *csv)
|
|||
/*
|
||||
* Splits the 'csv' string, stores the fields in a new
|
||||
* owl_algorithm_result, and returns a pointer to it (or NULL
|
||||
* in case of error).
|
||||
* in case of error).
|
||||
*
|
||||
* Note that the new owl_algorithm_result is allocated with malloc()
|
||||
* and must be deleted using free().
|
||||
|
@ -217,6 +216,11 @@ owl_algorithm_result* owl_fill_algorithm_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.
|
||||
*
|
||||
* CSV format:
|
||||
* Mobile_MAC;Request_type;Request_timestamp;Nb_algo;Algo_1;…;Algo_n
|
||||
* Nb_algo is the number of algorithms in the result.
|
||||
* The format of Algo_i is documented in owl_algorithm_result_to_csv().
|
||||
*/
|
||||
void owl_result_to_csv(char dst[OWL_CSV_RESULT_STRLEN],
|
||||
const owl_result *const src)
|
||||
|
@ -228,10 +232,11 @@ void owl_result_to_csv(char dst[OWL_CSV_RESULT_STRLEN],
|
|||
|
||||
owl_timestamp_to_string(timestamp_str, src->mobile_timestamp) ;
|
||||
snprintf(dst, OWL_CSV_RESULT_REQUEST_STRLEN,
|
||||
"%s;%"PRIu8";%s",
|
||||
"%s;%"PRIu8";%s;%u",
|
||||
src->mobile_mac_addr,
|
||||
src->request_type,
|
||||
timestamp_str) ;
|
||||
timestamp_str,
|
||||
src->nb_results) ;
|
||||
dst_len = strlen(dst) ;
|
||||
|
||||
owl_algorithm_result *algo = src->results ;
|
||||
|
@ -251,6 +256,13 @@ void owl_result_to_csv(char dst[OWL_CSV_RESULT_STRLEN],
|
|||
* 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.
|
||||
*
|
||||
* CSV format:
|
||||
* Algorithm_name;X;Y;Z;Error;Area_name
|
||||
* Error is the distance from the true coordinates of the mobile, if
|
||||
* known; if unknown, Error is set to -1.
|
||||
* Area_name is the name of the area or room in which the mobile is (may
|
||||
* be empty).
|
||||
*/
|
||||
void
|
||||
owl_algorithm_result_to_csv(char dst[OWL_CSV_ALGORITHM_RESULT_STRLEN],
|
||||
|
@ -342,12 +354,12 @@ void owl_fprint_result(FILE *stream, const owl_result *const src)
|
|||
"Mobile MAC: %s\n"
|
||||
"Request type: %"PRIu8"\n"
|
||||
"Mobile timestamp: %s\n"
|
||||
"Results:\n"
|
||||
"%u results:\n"
|
||||
,
|
||||
src->mobile_mac_addr,
|
||||
src->request_type,
|
||||
timestamp_str
|
||||
) ;
|
||||
timestamp_str,
|
||||
src->nb_results) ;
|
||||
|
||||
owl_algorithm_result *algo = src->results ;
|
||||
while (algo)
|
||||
|
|
|
@ -70,6 +70,7 @@ typedef struct _owl_result
|
|||
char *mobile_mac_addr ;
|
||||
uint8_t request_type ;
|
||||
owl_timestamp mobile_timestamp ;
|
||||
unsigned int nb_results ;
|
||||
owl_algorithm_result *results ;
|
||||
} owl_result ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue