[Positioning] Add classes InputMedium & InputCSV
- Add classes InputMedium and InputCSV. They handle Measurements. - Measurement: add set_ss_list() and clear(). - Add new files in Makefile. - TODO: thinking about Measurement vs. a new class Request.
This commit is contained in:
parent
1cf560309a
commit
8f071d13b0
|
@ -20,7 +20,7 @@ LIBS = -lpq -lboost_program_options-mt
|
|||
|
||||
TARGET = owlps-positioning
|
||||
HEADER = owlps-positioning.hh
|
||||
OBJ = posutil.o point3d.o referencepoint.o waypoint.o building.o area.o wifidevice.o accesspoint.o mobile.o measurement.o calibrationmeasurement.o
|
||||
OBJ = posutil.o point3d.o referencepoint.o waypoint.o building.o area.o wifidevice.o accesspoint.o mobile.o measurement.o calibrationmeasurement.o inputcsv.o
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
|
@ -40,6 +40,7 @@ accesspoint.o: accesspoint.hh wifidevice.hh point3d.hh
|
|||
mobile.o: mobile.hh wifidevice.hh
|
||||
measurement.o: measurement.hh mobile.hh accesspoint.hh
|
||||
calibrationmeasurement.o: calibrationmeasurement.hh measurement.hh referencepoint.hh
|
||||
inputcsv.o: inputcsv.hh inputmedium.hh
|
||||
#libowlps-positioning.o: libowlps-positioning.hh
|
||||
#positioning.o: point.hh referencepoint.hh accesspoint.hh area.hh measurement.hh libowlps-positioning.hh
|
||||
#server.o: server.hh positioning.hh point.hh measurement.hh treatment.hh libowlps-positioning.hh
|
||||
|
@ -65,4 +66,4 @@ uninstall:
|
|||
@$(RM) $(INSTALL_DIR)/$(TARGET)
|
||||
|
||||
style:
|
||||
@$(STYLE) $(OBJ:.o=.hh) $(OBJ:.o=.cc)
|
||||
@$(STYLE) $(OBJ:.o=.hh) $(OBJ:.o=.cc) inputmedium.hh
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
|
||||
- Measurement
|
||||
Un Measurement est un groupe de mesures de signaux envoyés par un
|
||||
mobile à un AP. Pour une demande de localisation, on aura donc
|
||||
plusieurs Measurement. Cela pose-t-il problème ? Faut-il grouper
|
||||
les Measurement dans une classe Demande ?
|
||||
Anciennement, on avait une liste de points de référence, et à
|
||||
chaque point étaient associés des mesures {MAC AP, SS}.
|
||||
|
||||
- '\n' vs. endl.
|
||||
Utiliser '\n' plutôt que endl lorsque le vidage du tampon n'est pas
|
||||
nécessaire.
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
#include "inputcsv.hh"
|
||||
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std ;
|
||||
using namespace boost ;
|
||||
|
||||
|
||||
|
||||
/*** Constructeurs ***/
|
||||
|
||||
|
||||
InputCSV::InputCSV(const string &filename)
|
||||
{
|
||||
input_file_name = filename ;
|
||||
|
||||
input_file.open(input_file_name.c_str()) ;
|
||||
if (! input_file)
|
||||
cerr
|
||||
<< "InputCSV(): Error opening input file « " << input_file_name
|
||||
<< " »!" << endl ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*** Opérations ***/
|
||||
|
||||
|
||||
const Measurement& InputCSV::get_next_measurement()
|
||||
{
|
||||
if (! input_file)
|
||||
return current_measurement ;
|
||||
|
||||
string line ;
|
||||
|
||||
// Skipping blank lines
|
||||
do
|
||||
{
|
||||
++current_line ;
|
||||
getline(input_file, line) ;
|
||||
}
|
||||
while (! input_file.eof()
|
||||
&& line.find_first_not_of(" \t") == string::npos) ;
|
||||
|
||||
if (input_file.eof())
|
||||
{
|
||||
// End of file reached: blank current measurement
|
||||
current_measurement.clear() ;
|
||||
return current_measurement ;
|
||||
}
|
||||
|
||||
// Split read string into fields (semicolon-separated)
|
||||
tokenizer<escaped_list_separator<char> > tok(
|
||||
line, escaped_list_separator<char>('\\', ';', '\"')) ;
|
||||
|
||||
vector<int> ss_list ;
|
||||
|
||||
for (tokenizer<escaped_list_separator<char> >::iterator i(tok.begin()) ;
|
||||
i != tok.end() ; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
ss_list.push_back(lexical_cast<int>(*i)) ;
|
||||
}
|
||||
catch (bad_lexical_cast &e)
|
||||
{
|
||||
cerr
|
||||
<< "InputCSV::getNextMeasurement(): Bad value at line "
|
||||
<< current_line
|
||||
<< " of input file « " << input_file_name << " »!"
|
||||
<< endl ;
|
||||
current_measurement.clear() ; // Blank current measurement
|
||||
return current_measurement ;
|
||||
}
|
||||
}
|
||||
|
||||
current_measurement.set_ss_list(ss_list) ;
|
||||
|
||||
return current_measurement ;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
#ifndef _OWLPS_POSITIONING_INPUTCSV_HH_
|
||||
#define _OWLPS_POSITIONING_INPUTCSV_HH_
|
||||
|
||||
#include "inputmedium.hh"
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
class InputCSV: public InputMedium
|
||||
{
|
||||
protected:
|
||||
std::string input_file_name ;
|
||||
std::ifstream input_file ;
|
||||
|
||||
public:
|
||||
InputCSV(const std::string &filename = "") ;
|
||||
|
||||
bool eof(void) const ;
|
||||
|
||||
const Measurement& get_next_measurement(void) ;
|
||||
|
||||
operator bool(void) const ;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
/*** Accesseurs lecture ***/
|
||||
|
||||
|
||||
inline bool InputCSV::eof() const
|
||||
{
|
||||
return input_file.eof() ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*** Opérateurs ***/
|
||||
|
||||
|
||||
inline InputCSV::operator bool() const
|
||||
{
|
||||
return input_file ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // _OWLPS_POSITIONING_INPUTCSV_HH_
|
|
@ -0,0 +1,59 @@
|
|||
#ifndef _OWLPS_POSITIONING_INPUTMEDIUM_HH_
|
||||
#define _OWLPS_POSITIONING_INPUTMEDIUM_HH_
|
||||
|
||||
#include "measurement.hh"
|
||||
|
||||
class InputMedium
|
||||
{
|
||||
protected:
|
||||
Measurement current_measurement ;
|
||||
unsigned long current_line ;
|
||||
|
||||
public:
|
||||
InputMedium() ;
|
||||
|
||||
const Measurement& get_current_measurement(void) const ;
|
||||
unsigned int get_current_line(void) const ;
|
||||
|
||||
/*
|
||||
* Reads the next measurement and returns it, increments current_line
|
||||
* Returns an empty Measurement in case of error or EOF (note that
|
||||
* when casted in bool, an empty Measurement is false).
|
||||
*/
|
||||
virtual const Measurement& get_next_measurement(void) = 0 ;
|
||||
|
||||
/*
|
||||
* Returns true if the last measurement has been reached
|
||||
*/
|
||||
virtual bool eof(void) const = 0 ;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
/*** Constructeurs ***/
|
||||
|
||||
|
||||
inline InputMedium::InputMedium()
|
||||
{
|
||||
current_line = 0 ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*** Accesseurs lecture ***/
|
||||
|
||||
|
||||
inline const Measurement& InputMedium::get_current_measurement() const
|
||||
{
|
||||
return current_measurement ;
|
||||
}
|
||||
|
||||
|
||||
inline unsigned int InputMedium::get_current_line() const
|
||||
{
|
||||
return current_line ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // _OWLPS_POSITIONING_INPUTMEDIUM_HH_
|
|
@ -65,6 +65,26 @@ void Measurement::add_ss(const int &ss)
|
|||
}
|
||||
|
||||
|
||||
void Measurement::set_ss_list(const std::vector<int> &_ss_list)
|
||||
{
|
||||
ss_list = _ss_list ;
|
||||
update_average_ss() ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Reinitialises the Measurement
|
||||
* ap and mobile are not deleted, only initialised at NULL.
|
||||
*/
|
||||
void Measurement::clear()
|
||||
{
|
||||
ss_list.clear() ;
|
||||
average_ss = 0 ;
|
||||
ap = NULL ;
|
||||
mobile = NULL ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*** Opérateurs ***/
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
void set_mobile(const Mobile *_mobile) ;
|
||||
void set_ap(const AccessPoint *_ap) ;
|
||||
void add_ss(const int &ss) ;
|
||||
void set_ss_list(const std::vector<int> &_ss_list) ;
|
||||
void clear(void) ;
|
||||
|
||||
Measurement operator=(const Measurement &m) ;
|
||||
bool operator==(const Measurement &m) const ;
|
||||
|
|
Loading…
Reference in New Issue