2012-02-06 16:44:09 +01:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
2016-11-03 05:10:34 +01:00
|
|
|
* https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
|
2013-05-29 18:43:35 +02:00
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
2013-06-22 23:30:17 +02:00
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-01-12 00:31:22 +01:00
|
|
|
#ifndef _OWLPS_POSITIONING_STOCK_HH_
|
|
|
|
#define _OWLPS_POSITIONING_STOCK_HH_
|
|
|
|
|
2013-07-10 00:00:00 +02:00
|
|
|
class Autocalibration ;
|
|
|
|
|
2010-04-02 14:03:55 +02:00
|
|
|
#include "building.hh"
|
2010-04-13 10:47:10 +02:00
|
|
|
#include "waypoint.hh"
|
2010-01-12 00:31:22 +01:00
|
|
|
#include "mobile.hh"
|
2013-06-14 21:54:26 +02:00
|
|
|
#include "capturepoint.hh"
|
2010-02-19 11:42:04 +01:00
|
|
|
#include "referencepoint.hh"
|
|
|
|
#include "calibrationrequest.hh"
|
2010-01-12 00:31:22 +01:00
|
|
|
|
2013-05-30 20:13:44 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
2010-01-12 00:31:22 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// Storage class
|
2010-01-12 00:31:22 +01:00
|
|
|
class Stock
|
|
|
|
{
|
2012-04-27 17:41:11 +02:00
|
|
|
friend class Autocalibration ;
|
2013-07-08 19:19:04 +02:00
|
|
|
friend class AutocalibrationMesh ;
|
2013-07-10 00:00:00 +02:00
|
|
|
friend class AutocalibrationLine ;
|
|
|
|
|
2012-04-27 17:41:11 +02:00
|
|
|
|
2010-01-12 00:31:22 +01:00
|
|
|
private:
|
2010-04-02 14:03:55 +02:00
|
|
|
/// List of known Building
|
2010-06-21 14:54:50 +02:00
|
|
|
/** The string key of the map is the Building name. */
|
2013-05-30 20:13:44 +02:00
|
|
|
static std::unordered_map<std::string, Building> buildings ;
|
2010-04-02 14:03:55 +02:00
|
|
|
|
2010-04-13 10:47:10 +02:00
|
|
|
/// List of known Waypoint
|
2013-05-30 20:13:44 +02:00
|
|
|
static std::unordered_map<Point3D, Waypoint> waypoints ;
|
2010-04-13 10:47:10 +02:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/// List of known Mobile
|
2010-06-21 14:54:50 +02:00
|
|
|
/** The string key of the map is the Mobile MAC address. */
|
2013-05-30 20:13:44 +02:00
|
|
|
static std::unordered_map<std::string, Mobile> mobiles ;
|
2010-01-16 12:23:07 +01:00
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
/// List of known CapturePoint
|
|
|
|
/** The string key of the map is the CapturePoint MAC address. */
|
|
|
|
static std::unordered_map<std::string, CapturePoint> cps ;
|
2010-01-12 00:31:22 +01:00
|
|
|
|
2010-02-19 11:42:04 +01:00
|
|
|
/// List of known ReferencePoint
|
2013-05-30 20:13:44 +02:00
|
|
|
static std::unordered_set<ReferencePoint> reference_points ;
|
2010-02-19 11:42:04 +01:00
|
|
|
|
|
|
|
/// List of known CalibrationRequest
|
2013-05-30 20:13:44 +02:00
|
|
|
static std::unordered_set<CalibrationRequest> calibration_requests ;
|
2010-02-19 11:42:04 +01:00
|
|
|
|
2011-07-30 20:21:51 +02:00
|
|
|
/** @name CalibrationRequest operations */
|
|
|
|
//@{
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Delete calibration requests that do not come from the CPs
|
|
|
|
static void delete_non_cp_calibration_requests(void) ;
|
2011-07-30 20:21:51 +02:00
|
|
|
//@}
|
|
|
|
|
2013-05-17 21:08:35 +02:00
|
|
|
/** @name ReferencePoint operations */
|
|
|
|
//@{
|
|
|
|
/// Generates reference points according to a meshing
|
|
|
|
static void generate_reference_points_mesh(void) ;
|
2013-07-10 00:00:00 +02:00
|
|
|
/// Generates reference points according to a path
|
|
|
|
static void generate_reference_points_line(void) ;
|
|
|
|
/// Generates reference points between `start` and `end`
|
|
|
|
static void generate_interpolated_reference_points(
|
|
|
|
const Point3D &start, const Point3D &end,
|
|
|
|
const CapturePoint *const cp1,
|
2014-05-13 23:50:53 +02:00
|
|
|
const CapturePoint *const cp2 = nullptr) ;
|
2013-05-17 21:08:35 +02:00
|
|
|
/// Generates reference points according to a list
|
|
|
|
static void generate_reference_points_list(void) ;
|
|
|
|
/// Generates a single reference point
|
2013-07-10 00:00:00 +02:00
|
|
|
static void generate_reference_point(Autocalibration &ac) ;
|
2013-05-17 21:08:35 +02:00
|
|
|
//@}
|
|
|
|
|
|
|
|
|
2010-01-12 00:31:22 +01:00
|
|
|
public:
|
2010-06-23 17:45:59 +02:00
|
|
|
/** @name Building operations */
|
|
|
|
//@{
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Returns the number of buildings
|
2011-06-16 14:10:43 +02:00
|
|
|
static unsigned int nb_buildings(void) ;
|
2016-11-03 16:10:33 +01:00
|
|
|
/// Returns the Building corresponding to a given name
|
2010-04-02 14:03:55 +02:00
|
|
|
static const Building& get_building(const std::string &name) ;
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Searches for a Building and creates it if it does not exist
|
2010-04-02 14:03:55 +02:00
|
|
|
static const Building& find_create_building(const std::string &name) ;
|
2013-05-30 21:23:05 +02:00
|
|
|
/// Searches the Area in which `point` is
|
2011-07-30 20:44:25 +02:00
|
|
|
static const Area* in_which_area_is(const Point3D &point) ;
|
2010-06-23 17:45:59 +02:00
|
|
|
//@}
|
2010-04-02 14:03:55 +02:00
|
|
|
|
2010-06-23 17:45:59 +02:00
|
|
|
/** @name Waypoint operations */
|
|
|
|
//@{
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Returns the number of waypoints
|
2011-06-16 14:10:43 +02:00
|
|
|
static unsigned int nb_waypoints(void) ;
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Searches for a Waypoint and adds it if it does not exist
|
2010-04-13 10:47:10 +02:00
|
|
|
static const Waypoint&
|
|
|
|
find_create_waypoint(const Waypoint &point) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Searches for a Waypoint from its coordinates and adds it if it
|
|
|
|
/// does not exist
|
2010-04-13 10:47:10 +02:00
|
|
|
static const Waypoint&
|
|
|
|
find_create_waypoint(const Point3D &point) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Deletes a Building from the building list of a Waypoint; deletes
|
|
|
|
/// the Waypoint if it is not linked to any Building any more
|
2010-04-13 10:47:10 +02:00
|
|
|
static void waypoint_remove_building(const Waypoint &point,
|
2013-10-02 20:38:45 +02:00
|
|
|
Building *const building) ;
|
2010-06-23 17:45:59 +02:00
|
|
|
//@}
|
2010-04-13 10:47:10 +02:00
|
|
|
|
2010-06-23 17:45:59 +02:00
|
|
|
/** @name Mobile operations */
|
|
|
|
//@{
|
2011-07-19 18:43:54 +02:00
|
|
|
/// Returns the number of mobiles
|
|
|
|
static unsigned int nb_mobiles(void) ;
|
2011-07-19 19:08:50 +02:00
|
|
|
/// Verify the existence of a mobile
|
|
|
|
static bool mobile_exists(const std::string &mac) ;
|
2016-11-03 16:10:33 +01:00
|
|
|
/// Returns the Mobile corresponding to a given MAC address
|
2010-01-12 00:31:22 +01:00
|
|
|
static const Mobile& get_mobile(const std::string &mac) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Searches for a Mobile given its MAC address and creates it if it
|
|
|
|
/// does not exist
|
2010-04-01 11:03:24 +02:00
|
|
|
static const Mobile& find_create_mobile(const std::string &mac) ;
|
2011-07-19 18:20:20 +02:00
|
|
|
/// Searches for a Mobile and create it if it does not exist
|
|
|
|
static const Mobile& find_create_mobile(const Mobile &source) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Returns a reference to the Mobile corresponding to a given MAC
|
|
|
|
/// address
|
2010-01-12 00:31:22 +01:00
|
|
|
static Mobile& getw_mobile(const std::string &mac) ;
|
2010-06-23 17:45:59 +02:00
|
|
|
//@}
|
2010-01-16 12:23:07 +01:00
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
/** @name CapturePoint operations */
|
2010-06-23 17:45:59 +02:00
|
|
|
//@{
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Returns the number of capture points
|
|
|
|
static unsigned int nb_cps(void) ;
|
|
|
|
/// Returns a reference to the CP list
|
2011-07-21 21:44:28 +02:00
|
|
|
static
|
2013-06-14 21:54:26 +02:00
|
|
|
std::unordered_map<std::string, CapturePoint>& get_cps(void) ;
|
|
|
|
/// Verify the existence of a CP
|
|
|
|
static bool cp_exists(const std::string &mac) ;
|
2016-11-03 16:10:33 +01:00
|
|
|
/// Returns the CapturePoint corresponding to a given MAC address
|
2013-06-14 21:54:26 +02:00
|
|
|
static const CapturePoint& get_cp(const std::string &mac) ;
|
|
|
|
/// Searches for a CapturePoint given its MAC address and creates it
|
2013-06-04 00:39:10 +02:00
|
|
|
/// if it does not exist
|
2013-06-14 21:54:26 +02:00
|
|
|
static const CapturePoint& find_create_cp(const std::string &mac) ;
|
|
|
|
/// Searches for a CapturePoint and create it if it does not exist
|
|
|
|
static const CapturePoint& find_create_cp(const CapturePoint &source) ;
|
|
|
|
/// Returns a reference to the CapturePoint corresponding to a given
|
2013-06-04 00:39:10 +02:00
|
|
|
/// MAC address
|
2013-06-14 21:54:26 +02:00
|
|
|
static CapturePoint& getw_cp(const std::string &mac) ;
|
|
|
|
/// Updates the friis indexes of all the CPs
|
2010-06-10 15:57:03 +02:00
|
|
|
static void update_all_friis_indexes(void) ;
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Returns the signal strenth received by a CP `mac_receiver` from
|
|
|
|
/// a CP `mac_transmitter`
|
|
|
|
static double cp_matrix_get_ss(const std::string &mac_transmitter,
|
2011-06-15 15:30:49 +02:00
|
|
|
const std::string &mac_receiver) ;
|
2013-06-14 21:54:26 +02:00
|
|
|
/// Checks if a Point3D is the coordinate of an existing CP
|
2013-07-08 21:08:09 +02:00
|
|
|
static const CapturePoint* is_cp_coordinate(const Point3D &coord) ;
|
2014-05-14 21:55:05 +02:00
|
|
|
/// Returns the distance from `location` to the closest CP
|
|
|
|
static float distance_from_closest_cp(const Point3D &location) ;
|
2010-06-23 17:45:59 +02:00
|
|
|
//@}
|
2010-02-02 17:34:58 +01:00
|
|
|
|
2010-06-23 17:45:59 +02:00
|
|
|
/** @name ReferencePoint operations */
|
|
|
|
//@{
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Returns the number of reference points
|
2011-06-16 14:10:43 +02:00
|
|
|
static unsigned int nb_reference_points(void) ;
|
2011-07-25 19:23:20 +02:00
|
|
|
/// Verify the existence of a reference point at the given coordinates
|
|
|
|
static bool reference_point_exists(const ReferencePoint &point) ;
|
2016-11-03 16:10:33 +01:00
|
|
|
/// Returns the ReferencePoint at the given coordinates
|
2011-06-15 15:13:18 +02:00
|
|
|
static const ReferencePoint&
|
2016-11-05 03:02:30 +01:00
|
|
|
get_reference_point(const Point3D &point) ;
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Searches for a ReferencePoint and adds it if it does not exist
|
2010-02-19 11:42:04 +01:00
|
|
|
static const ReferencePoint&
|
|
|
|
find_create_reference_point(const ReferencePoint &point) ;
|
2016-11-05 03:02:30 +01:00
|
|
|
/// Searches for a ReferencePoint at the given coordinates and adds it
|
|
|
|
/// if it doesn't exist
|
|
|
|
static const ReferencePoint&
|
|
|
|
find_create_reference_point(const Point3D &point);
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Searches for the closest ReferencePoint (in the signal strength
|
|
|
|
/// space) to a given Request
|
2010-06-02 12:37:43 +02:00
|
|
|
static const ReferencePoint&
|
|
|
|
closest_reference_point(const Request &request) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Generates reference points from the reference points corresponding
|
2013-06-14 21:54:26 +02:00
|
|
|
/// to CPs
|
2011-07-22 11:29:30 +02:00
|
|
|
static void regenerate_reference_points(void) ;
|
2010-06-23 17:45:59 +02:00
|
|
|
//@}
|
2010-02-19 11:42:04 +01:00
|
|
|
|
2010-06-23 17:45:59 +02:00
|
|
|
/** @name CalibrationRequest operations */
|
|
|
|
//@{
|
2011-06-27 10:24:59 +02:00
|
|
|
/// Returns the number of calibration requests
|
|
|
|
static unsigned int nb_calibration_requests(void) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Searches for a CalibrationRequest, adds it if it does not exist,
|
|
|
|
/// and links it to its reference point
|
2011-07-26 15:23:15 +02:00
|
|
|
static const CalibrationRequest& store_calibration_request(
|
2011-06-17 12:35:14 +02:00
|
|
|
const CalibrationRequest &request) ;
|
2011-06-20 11:43:17 +02:00
|
|
|
/// Deletes a CalibrationRequest
|
|
|
|
static void delete_calibration_request(
|
|
|
|
const CalibrationRequest &request) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Deletes the calibration requests that are older than `timeout`
|
|
|
|
/// seconds
|
2013-10-02 20:38:45 +02:00
|
|
|
static void delete_calibration_requests_older_than(const int timeout) ;
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Searches for a CalibrationRequest and adds it if it does not exist
|
2010-02-19 11:42:04 +01:00
|
|
|
static const CalibrationRequest&
|
|
|
|
find_create_calibration_request(const CalibrationRequest &request) ;
|
2013-06-04 00:39:10 +02:00
|
|
|
/// Searches for the closest CalibrationRequest (in the signal
|
2011-05-09 16:42:30 +02:00
|
|
|
/// strength space) to a given Request
|
|
|
|
static const CalibrationRequest&
|
|
|
|
closest_calibration_request(const Request &request) ;
|
2010-06-23 17:45:59 +02:00
|
|
|
//@}
|
2010-02-19 11:42:04 +01:00
|
|
|
|
2010-02-02 17:34:58 +01:00
|
|
|
/// Deletes all elements in all attributes
|
|
|
|
static void clear(void) ;
|
2010-01-12 00:31:22 +01:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-16 14:10:43 +02:00
|
|
|
/* *** Building operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
inline unsigned int Stock::nb_buildings()
|
|
|
|
{
|
|
|
|
return buildings.size() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Waypoint operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
inline unsigned int Stock::nb_waypoints()
|
|
|
|
{
|
|
|
|
return waypoints.size() ;
|
|
|
|
}
|
2010-01-12 00:31:22 +01:00
|
|
|
|
|
|
|
|
2010-04-13 10:47:10 +02:00
|
|
|
inline const Waypoint& Stock::
|
|
|
|
find_create_waypoint(const Waypoint &point)
|
|
|
|
{
|
|
|
|
Waypoint& found =
|
|
|
|
const_cast<Waypoint&>(
|
|
|
|
find_create_waypoint(static_cast<Point3D>(point))) ;
|
|
|
|
found.add_buildings(point) ;
|
|
|
|
return found ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 14:10:43 +02:00
|
|
|
|
|
|
|
/* *** Mobile operations *** */
|
|
|
|
|
|
|
|
|
2011-07-19 18:43:54 +02:00
|
|
|
inline unsigned int Stock::nb_mobiles()
|
|
|
|
{
|
|
|
|
return mobiles.size() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
2013-05-30 21:23:05 +02:00
|
|
|
* If the Mobile corresponding to `mac` does not exist, it is created.
|
2010-01-16 12:23:07 +01:00
|
|
|
* @param mac The MAC address of the Mobile to search for. It must be a
|
|
|
|
* valid MAC address, as no check is performed.
|
2013-05-30 21:23:05 +02:00
|
|
|
* @returns A modifiable reference to the Mobile.
|
2010-01-16 12:23:07 +01:00
|
|
|
*/
|
2010-01-12 00:31:22 +01:00
|
|
|
inline Mobile& Stock::getw_mobile(const std::string &mac)
|
|
|
|
{
|
|
|
|
return mobiles[mac] ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 14:10:43 +02:00
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
/* *** CapturePoint operations *** */
|
2011-06-16 14:10:43 +02:00
|
|
|
|
|
|
|
|
2013-06-14 21:54:26 +02:00
|
|
|
inline unsigned int Stock::nb_cps()
|
2011-06-16 14:10:43 +02:00
|
|
|
{
|
2013-06-14 21:54:26 +02:00
|
|
|
return cps.size() ;
|
2011-06-16 14:10:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-21 21:44:28 +02:00
|
|
|
inline
|
2013-06-14 21:54:26 +02:00
|
|
|
std::unordered_map<std::string, CapturePoint>& Stock::get_cps()
|
2011-07-21 21:44:28 +02:00
|
|
|
{
|
2013-06-14 21:54:26 +02:00
|
|
|
return cps ;
|
2011-07-21 21:44:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
2013-06-14 21:54:26 +02:00
|
|
|
* If the CapturePoint corresponding to `mac` does not exist, it is
|
2010-01-16 12:23:07 +01:00
|
|
|
* created.
|
2013-06-14 21:54:26 +02:00
|
|
|
* @param mac The MAC address of the CapturePoint to search for.
|
2010-01-16 12:23:07 +01:00
|
|
|
* It must be a valid MAC address, as no check is performed.
|
2013-06-14 21:54:26 +02:00
|
|
|
* @returns A modifiable reference to the CapturePoint.
|
2010-01-16 12:23:07 +01:00
|
|
|
*/
|
2013-06-14 21:54:26 +02:00
|
|
|
inline CapturePoint& Stock::getw_cp(const std::string &mac)
|
2010-01-12 00:31:22 +01:00
|
|
|
{
|
2013-06-14 21:54:26 +02:00
|
|
|
return cps[mac] ;
|
2010-01-12 00:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-16 14:10:43 +02:00
|
|
|
/* *** ReferencePoint operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
inline unsigned int Stock::nb_reference_points()
|
|
|
|
{
|
|
|
|
return reference_points.size() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-05 03:02:30 +01:00
|
|
|
inline const ReferencePoint&
|
|
|
|
Stock::find_create_reference_point(const Point3D &point)
|
|
|
|
{
|
|
|
|
return find_create_reference_point(ReferencePoint(point));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-16 14:10:43 +02:00
|
|
|
|
2011-06-27 10:24:59 +02:00
|
|
|
/* *** CalibrationRequest operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
inline unsigned int Stock::nb_calibration_requests()
|
|
|
|
{
|
|
|
|
return calibration_requests.size() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-12 00:31:22 +01:00
|
|
|
#endif // _OWLPS_POSITIONING_STOCK_HH_
|