[Positioning] InputMedium::fill_calibration_request_data()

Refactor some code of Input{CSV,UDPSocket}::fill_current_request() into
the new function InputMedium::fill_calibration_request_data().
This commit is contained in:
Matteo Cypriani 2011-08-01 12:28:33 +02:00
parent a71dcfdcfe
commit 90f26261a2
6 changed files with 64 additions and 49 deletions

2
TODO
View File

@ -86,8 +86,6 @@
- Refactoring
° Split Stock::generate_reference_point() into several functions.
° Synchronise InputCSV & InputUDPSocket (calibration requests),
factorise code into InputMedium.
° Write a class for Request::type?
CalibrationRequest::direction uses a dedicated class Direction, why
not Request::type? That would simplify writing of the type to

View File

@ -215,17 +215,23 @@ $(OBJ_DIR)/csvfilereader.o: \
$(OBJ_DIR)/textfilereader.o
$(OBJ_DIR)/textfilewriter.o: \
$(OBJ_DIR)/posexcept.o
$(OBJ_DIR)/inputmedium.o: \
$(OBJ_DIR)/calibrationrequest.o \
$(OBJ_DIR)/configuration.o \
$(OBJ_DIR)/stock.o
$(OBJ_DIR)/inputcsv.o: \
$(OBJ_DIR)/inputmedium.o \
$(OBJ_DIR)/csvfilereader.o \
$(OBJ_DIR)/request.o \
$(OBJ_DIR)/calibrationrequest.o \
$(OBJ_DIR)/configuration.o \
$(OBJ_DIR)/stock.o
$(OBJ_DIR)/inputudpsocket.o: \
$(OBJ_DIR)/inputmedium.o \
$(OBJ_DIR)/posexcept.o \
$(OBJ_DIR)/request.o \
$(OBJ_DIR)/calibrationrequest.o \
$(OBJ_DIR)/configuration.o \
$(OBJ_DIR)/stock.o
$(OBJ_DIR)/inputlogcsv.o: \
$(SRC_DIR)/inputlogmedium.hh \

View File

@ -124,19 +124,7 @@ bool InputCSV::fill_current_request()
current_request->set_measurements(measurements) ;
// Calibration request?
if (type == OWL_REQUEST_CALIBRATION ||
type == OWL_REQUEST_AUTOCALIBRATION)
{
const ReferencePoint &reference_point =
Stock::find_create_reference_point(position) ;
current_request_to_calibration_request(&reference_point,
direction, type) ;
}
// We set the real coordinates (if found) only for non-calibration
// requests
else if (position)
current_request->set_real_position(position) ;
fill_calibration_request_data(mac_mobile, position, direction, type) ;
return true ;
}

View File

@ -1,5 +1,9 @@
#include "inputmedium.hh"
#include "calibrationrequest.hh"
#include "stock.hh"
#include "configuration.hh"
using namespace std ;
@ -62,6 +66,49 @@ void InputMedium::clear_current_request()
}
/**
* The \em position argument can be changed by this function.
*/
void InputMedium::
fill_calibration_request_data(const string &mac_mobile, Point3D &position,
const Direction &direction, uint8_t type)
{
if ((type == OWL_REQUEST_CALIBRATION ||
type == OWL_REQUEST_AUTOCALIBRATION)
&&
(Configuration::bool_value("positioning.accept-new-aps") ||
Stock::ap_exists(mac_mobile)))
{
AccessPoint &transmitter =
const_cast<AccessPoint&>(Stock::find_create_ap(mac_mobile)) ;
// If an autocalibration request does not contain the coordinates
// of the AP, we use the current coordinates of the AP as
// ReferencePoint.
if (type == OWL_REQUEST_AUTOCALIBRATION && ! position)
position = transmitter.get_coordinates() ;
// Update the AP's coordinates if allowed. A 'false' position
// (i.e. 0;0;0) is only set for calibration requests, to avoid
// setting the coordinates to 0;0;0 if an autocalibration
// request that does not contain the coordinates is received.
else if (Configuration::
bool_value("positioning.update-ap-coordinates-online"))
transmitter.set_coordinates(position) ;
const ReferencePoint &reference_point =
Stock::find_create_reference_point(position) ;
current_request_to_calibration_request(
&reference_point, direction, type) ;
}
// We set the real coordinates (if found) only for non-calibration
// requests
else if (position)
current_request->set_real_position(position) ;
}
void InputMedium::
current_request_to_calibration_request(
const ReferencePoint *const reference_point,

View File

@ -6,6 +6,8 @@ class Direction ;
#include "request.hh"
#include <string>
/// Super class of all input media
/**
* This class Provides an interface for input media, i.e. to read
@ -22,6 +24,12 @@ protected:
//@{
/// Reads data & fills the current request
virtual bool fill_current_request(void) = 0 ;
/// \brief Checks if the current request is a calibration request and
/// if so fills it with additionnal data
void fill_calibration_request_data(const std::string &mac_mobile,
Point3D &position,
const Direction &direction,
uint8_t type) ;
//@}
public:

View File

@ -153,40 +153,8 @@ bool InputUDPSocket::fill_current_request()
current_request->set_measurements(measurements) ;
// Calibration request?
if ((request.type == OWL_REQUEST_CALIBRATION ||
request.type == OWL_REQUEST_AUTOCALIBRATION)
&&
(Configuration::bool_value("positioning.accept-new-aps") ||
Stock::ap_exists(mac_mobile)))
{
AccessPoint &transmitter =
const_cast<AccessPoint&>(Stock::find_create_ap(mac_mobile)) ;
// If an autocalibration request does not contain the coordinates
// of the AP, we use the current coordinates of the AP as
// ReferencePoint.
if (request.type == OWL_REQUEST_AUTOCALIBRATION && ! position)
position = transmitter.get_coordinates() ;
// Update the AP's coordinates if allowed. A 'false' position
// (i.e. 0;0;0) is only set for calibration requests, to avoid
// setting the coordinates to 0;0;0 if an autocalibration
// request that does not contain the coordinates is received.
else if (Configuration::
bool_value("positioning.update-ap-coordinates-online"))
transmitter.set_coordinates(position) ;
const ReferencePoint &reference_point =
Stock::find_create_reference_point(position) ;
current_request_to_calibration_request(&reference_point,
Direction(request.direction),
request.type) ;
}
// We set the real coordinates (if found) only for non-calibration
// requests
else if (position)
current_request->set_real_position(position) ;
fill_calibration_request_data(
mac_mobile, position, request.direction, request.type) ;
return true ;
}