[Positioning] Read mobiles characteristics

Add MobilesReaderCSV, that reads the known mobiles from a CSV file.
This commit is contained in:
Matteo Cypriani 2011-07-19 18:40:17 +02:00
parent 8878bb2390
commit 0b43e7f5fc
8 changed files with 157 additions and 0 deletions

View File

@ -82,6 +82,7 @@ OBJ_LIST = \
userinterface.o \
inputdatareader.o \
accesspointsreadercsv.o \
mobilesreadercsv.o \
topologyreadercsv.o \
textfilereader.o \
csvfilereader.o \
@ -155,6 +156,7 @@ $(OBJ_DIR)/userinterface.o: \
$(OBJ_DIR)/configuration.o
$(OBJ_DIR)/inputdatareader.o: \
$(OBJ_DIR)/accesspointsreadercsv.o \
$(OBJ_DIR)/mobilesreadercsv.o \
$(OBJ_DIR)/topologyreadercsv.o \
$(OBJ_DIR)/configuration.o \
$(OBJ_DIR)/posexcept.o
@ -162,6 +164,10 @@ $(OBJ_DIR)/accesspointsreadercsv.o: \
$(OBJ_DIR)/csvfilereader.o \
$(OBJ_DIR)/accesspoint.o \
$(OBJ_DIR)/stock.o
$(OBJ_DIR)/mobilesreadercsv.o: \
$(OBJ_DIR)/csvfilereader.o \
$(OBJ_DIR)/mobile.o \
$(OBJ_DIR)/stock.o
$(OBJ_DIR)/topologyreadercsv.o: \
$(OBJ_DIR)/csvfilereader.o \
$(OBJ_DIR)/area.o \

View File

@ -0,0 +1,10 @@
# Mobiles' physical description file.
#
# Each line follows this format:
# MAC address;Antenna gain (dBi);Trx power (dBm)
#
# Blank lines are ignored. Commented lines must have a sharp (#) as
# their FIRST character.
# Example mobile:
#aa:bb:cc:dd:ee:ff;1.8;18.0
1 # Mobiles' physical description file.
2 #
3 # Each line follows this format:
4 # MAC address;Antenna gain (dBi);Trx power (dBm)
5 #
6 # Blank lines are ignored. Commented lines must have a sharp (#) as
7 # their FIRST character.
8 # Example mobile:
9 #aa:bb:cc:dd:ee:ff;1.8;18.0

View File

@ -10,6 +10,10 @@
ap-medium = CSV
ap-csv-file = cfg/listeners.csv
# Description of the clients
mobile-medium = CSV
mobile-csv-file = cfg/mobiles.csv
# Description of deployment area topology.
# You probably don't need a full description of the topology, see the
# topology example file for details.

View File

@ -1,5 +1,6 @@
#include "inputdatareader.hh"
#include "accesspointsreadercsv.hh"
#include "mobilesreadercsv.hh"
#include "topologyreadercsv.hh"
#include "inputcsv.hh"
#include "calibrationrequest.hh"
@ -19,6 +20,7 @@ using namespace std ;
InputDataReader::InputDataReader()
{
read_access_points() ;
read_mobiles() ;
read_topology() ;
read_reference_points() ;
}
@ -80,6 +82,51 @@ void InputDataReader::initialise_access_points_csv()
/* *** Mobiles *** */
void InputDataReader::read_mobiles()
{
if (! Configuration::is_configured("data-input.mobile-medium"))
return ;
initialise_mobiles_media() ;
if (Configuration::is_configured("verbose"))
cerr << Stock::nb_mobiles() << " mobiles stored.\n" ;
}
void InputDataReader::initialise_mobiles_media()
{
const vector<string> &media_names =
Configuration::string_vector_value("data-input.mobile-medium") ;
for (vector<string>::const_iterator i = media_names.begin() ;
i != media_names.end() ; ++i)
{
if (*i == "CSV")
initialise_mobiles_csv() ;
else
throw bad_configuration(
"Mobiles' input medium type unknown « "+ *i +" »") ;
}
}
void InputDataReader::initialise_mobiles_csv()
{
if (! Configuration::is_configured("data-input.mobile-csv-file"))
throw missing_configuration(
"No input CSV file specified for mobiles") ;
MobilesReaderCSV(
Configuration::string_value("data-input.mobile-csv-file")) ;
}
/* *** Topology *** */

View File

@ -16,6 +16,10 @@ protected:
void initialise_access_points_media(void) ;
void initialise_access_points_csv(void) ;
void read_mobiles(void) ;
void initialise_mobiles_media(void) ;
void initialise_mobiles_csv(void) ;
void read_topology(void) ;
void initialise_topology_media(void) ;
void initialise_topology_csv(void) ;

View File

@ -0,0 +1,50 @@
#include "mobilesreadercsv.hh"
#include "point3d.hh"
#include "stock.hh"
#include "posexcept.hh"
using namespace std ;
/* *** Constructors *** */
MobilesReaderCSV::MobilesReaderCSV(const string &file_name):
file(file_name)
{
read_devices() ;
}
/* *** Operations *** */
void MobilesReaderCSV::read_devices()
{
while (file.next_line())
process_device_line() ;
}
void MobilesReaderCSV::process_device_line()
{
string mac ;
if (! file.read_field(mac))
throw malformed_input_data("Cannot read mobile's MAC address!") ;
PosUtil::to_upper(mac) ;
float gain ;
if (! file.read_field(gain))
throw malformed_input_data("Cannot read mobile's gain!") ;
float power ;
if (! file.read_field(power))
throw malformed_input_data("Cannot read mobile's power!") ;
string ip("") ;
Mobile device(ip, mac, gain, power) ;
Stock::find_create_mobile(device) ;
}

View File

@ -0,0 +1,29 @@
#ifndef _OWLPS_POSITIONING_MOBILESREADERCSV_HH_
#define _OWLPS_POSITIONING_MOBILESREADERCSV_HH_
class Point3D ;
#include "csvfilereader.hh"
#include <string>
/// Reads and registers to the Stock Mobile list from CSV files
/**
* CSV format for access points is:
* MAC;Antenna_gain_dBi;Trx_power_dBm
*/
class MobilesReaderCSV
{
protected:
CSVFileReader file ;
void read_devices(void) ;
void process_device_line(void) ;
public:
MobilesReaderCSV(const std::string &file_name) ;
~MobilesReaderCSV(void) {}
} ;
#endif // _OWLPS_POSITIONING_MOBILESREADERCSV_HH_

View File

@ -106,6 +106,13 @@ void UserInterface::fill_data_input_options()
("data-input.ap-csv-file", po::value<string>(),
"CSV file to use for access points input (when"
" data-input.ap-medium = CSV).")
("data-input.mobile-medium", po::value< vector<string> >()
->composing(),
"Medium from which mobiles are read. You can specify this"
" option more than once. Allowed: CSV.")
("data-input.mobile-csv-file", po::value<string>(),
"CSV file to use for mobiles input (when"
" data-input.mobile-medium = CSV).")
("data-input.topology-medium,T", po::value< vector<string> >()
->composing(),
"Medium from which topology (buildings, areas and waypoints) is"