Owl Positioning System: a Wi-Fi-based, infrastructure-centred indoor positioning system. http://owlps.pu-pm.univ-fcomte.fr/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

owlps-resultreader.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * This file is part of the Owl Positioning System (OwlPS) project.
  3. * It is subject to the copyright notice and license terms in the
  4. * COPYRIGHT.t2t file found in the top-level directory of this
  5. * distribution and at
  6. * https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
  7. * No part of the OwlPS Project, including this file, may be copied,
  8. * modified, propagated, or distributed except according to the terms
  9. * contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
  10. * distributed along with this file, either separately or by replacing
  11. * this notice by the COPYRIGHT.t2t file's contents.
  12. */
  13. /**
  14. * @file owlps-resultreader.h
  15. * @brief OwlPS Result Reader library
  16. *
  17. * libowlps-resultreader is the the library that provides functions to
  18. * read and display results sent on UDP by OwlPS Positioner.
  19. *
  20. * See also the source code of the example program
  21. * `owlps-resultreader-udp`.
  22. */
  23. #ifndef _LIBOWLPS_RESULTREADER_CSV_
  24. #define _LIBOWLPS_RESULTREADER_CSV_
  25. #include <owlps.h>
  26. #include <stdio.h>
  27. #include <inttypes.h>
  28. /* Maximum size of a result CSV string sent by OwlPS Positioner.
  29. * Request's information:
  30. * MAC, request type (2 chars), timestamp, ';'
  31. * Plus, for each algorithm:
  32. * Name, three coordinates, error (we assume the same size as the
  33. * coordinates), area name, ';'
  34. * Let's define OWL_NB_ALGORITHMS as the number of implemented
  35. * algorithms (this is ugly).
  36. */
  37. #define OWL_NB_ALGORITHMS 10
  38. #define OWL_CSV_RESULT_REQUEST_STRLEN \
  39. (OWL_ETHER_ADDR_STRLEN + OWL_TIMESTAMP_STRLEN + 3)
  40. #define OWL_CSV_ALGORITHM_RESULT_STRLEN \
  41. (OWL_ALGORITHM_STRLEN + 4 * OWL_COORDINATE_STRLEN + \
  42. OWL_AREA_STRLEN + 1)
  43. /// Maximum size of a result CSV string sent by OwlPS Positioner
  44. #define OWL_CSV_RESULT_STRLEN \
  45. (OWL_CSV_RESULT_REQUEST_STRLEN + \
  46. OWL_NB_ALGORITHMS * OWL_CSV_ALGORITHM_RESULT_STRLEN + 1)
  47. /* Same thing, but for the simplified CSV strings created by
  48. * *_to_csv_simple().
  49. * Request's information is only the MAC address.
  50. * For the algorithm:
  51. * = 12 characters per coordinate + OWL_AREA_STRLEN
  52. */
  53. #define OWL_CSV_RESULT_REQUEST_SIMPLE_STRLEN OWL_ETHER_ADDR_STRLEN
  54. #define OWL_CSV_ALGORITHM_RESULT_SIMPLE_STRLEN \
  55. (3 * OWL_COORDINATE_STRLEN + OWL_AREA_STRLEN + 1)
  56. /// Maximum size of a simplified result CSV string as created by
  57. /// *_to_csv_simple()
  58. #define OWL_CSV_RESULT_SIMPLE_STRLEN \
  59. (OWL_CSV_RESULT_REQUEST_SIMPLE_STRLEN + \
  60. OWL_NB_ALGORITHMS * OWL_CSV_ALGORITHM_RESULT_SIMPLE_STRLEN + 1)
  61. /// Structure of linked list of algorithm's results
  62. /**
  63. * This structure represents the result of a single algorithm, and
  64. * includes a field `next` which points to the next algorithm's result,
  65. * if any, or `NULL` if it is the last algorithm.
  66. */
  67. struct _owl_algorithm_result
  68. {
  69. char *algorithm ; ///< Name of the algorithm used to compute the result
  70. float x ; ///< Computed X coordinate
  71. float y ; ///< Computed Y coordinate
  72. float z ; ///< Computed Z coordinate
  73. float error ; ///< Distance error (if available)
  74. char *area ; ///< Name of the area in which the result point is
  75. struct _owl_algorithm_result *next ; ///< Next result
  76. } ;
  77. /// Linked list of algorithms' results
  78. typedef struct _owl_algorithm_result owl_algorithm_result ;
  79. /// Structure of the generated results for a request
  80. /**
  81. * This structure stores the information of a request along with a
  82. * pointer to the list of generated results.
  83. */
  84. struct _owl_result
  85. {
  86. char mobile_mac_addr[OWL_ETHER_ADDR_STRLEN] ; ///< Mobile's MAC address
  87. uint8_t request_type ; ///< Type of the request
  88. unsigned char __pad0; // 1 byte alignment
  89. /// Local time on the mobile when sending the request
  90. owl_timestamp mobile_timestamp ;
  91. unsigned int nb_results ; ///< Number of results generated
  92. owl_algorithm_result *results ; ///< List of the generated results
  93. } ;
  94. /// Generated results for a request
  95. typedef struct _owl_result owl_result ;
  96. /// Receives a result from the socket `sockfd`
  97. owl_result* owl_receive_position(const int sockfd) ;
  98. /// Splits the `csv` string and stores it in a new `owl_result`
  99. owl_result* owl_fill_result(char *csv) ;
  100. /// Splits the `csv` string and stores it in a new `owl_algorithm_result`
  101. owl_algorithm_result* owl_fill_algorithm_result(char **csv) ;
  102. /// Reads an integer from the `csv` string
  103. int owl_read_long_field(char **const csv, const char *const delim,
  104. long *const ret) ;
  105. int owl_read_float_field(char **const csv, float *const ret) ;
  106. /// Converts an `owl_result back` to a CSV string
  107. void owl_result_to_csv(char dst[OWL_CSV_RESULT_STRLEN],
  108. const owl_result *const src) ;
  109. /// Converts an `owl_algorithm_result` back to a CSV string
  110. void
  111. owl_algorithm_result_to_csv(char dst[OWL_CSV_ALGORITHM_RESULT_STRLEN],
  112. const owl_algorithm_result *const src) ;
  113. /// Converts an `owl_result` back to a CSV string (simplified format)
  114. void owl_result_to_csv_simple(char dst[OWL_CSV_RESULT_SIMPLE_STRLEN],
  115. const owl_result *const src) ;
  116. /// Converts an `owl_algorithm_result` back to a CSV string (simplified
  117. /// format)
  118. void owl_algorithm_result_to_csv_simple
  119. (char dst[OWL_CSV_ALGORITHM_RESULT_SIMPLE_STRLEN],
  120. const owl_algorithm_result *const src) ;
  121. /// Prints an `owl_result` to the given stream
  122. void owl_fprint_result(FILE *const stream, const owl_result *const src) ;
  123. /// Prints an `owl_algorithm_result` to the given stream
  124. void owl_fprint_algorithm_result(FILE *const stream,
  125. const owl_algorithm_result *const src) ;
  126. /// Prints an `owl_result` to the standard output
  127. #define owl_print_result(SRC) \
  128. (owl_fprint_result(stdout, (SRC)))
  129. /// Prints an `owl_algorithm_result` to the standard output
  130. #define owl_print_algorithm_result(SRC) \
  131. (owl_fprint_algorithm_result(stdout, (SRC)))
  132. /// Frees an `owl_result`
  133. void owl_free_result(owl_result *const result) ;
  134. /// Frees a single `owl_algorithm_result`
  135. void owl_free_algorithm_result(owl_algorithm_result *const algo) ;
  136. #endif // _LIBOWLPS_RESULTREADER_CSV_