/* * This file is part of the Owl Positioning System (OwlPS). * OwlPS is a project of the University of Franche-Comté * (Université de Franche-Comté), France. */ #include "inputcsv.hh" #include "posutil.hh" #include "posexcept.hh" #include "stock.hh" #include "calibrationrequest.hh" #include "configuration.hh" #include #include using namespace std ; using std::tr1::unordered_map ; /* *** Operations *** */ /** * This function fills the current Request from the CSV input file. * Blank lines and lines containing only spaces are skipped until a line * containing a request is found. * * @returns \em true if #current_request was correctly filled. * @returns \em false in case of error (file not opened, end of file, * invalid field or wrong number of fields in the line). */ bool InputCSV::fill_current_request() { if (! file.next_line()) // End of file or error return false ; ++current_line_nb ; // Read Mobile MAC field string mac_mobile ; if (! file.read_field(mac_mobile)) // Wrong number of fields { if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read mac_mobile.\n" ; return false ; } PosUtil::to_upper(mac_mobile) ; if (! Configuration::bool_value("positioning.accept-new-mobiles") && ! Stock::mobile_exists(mac_mobile)) return false ; const Mobile &mobile = Stock::find_create_mobile(mac_mobile) ; current_request->set_mobile(&mobile) ; // Read request type uint8_t type ; uint16_t type_r ; if (! file.read_field(type_r)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read type.\n" ; return false ; } type = type_r ; current_request->set_type(type) ; // Read Timestamp field Timestamp timestamp ; if (! file.read_timestamp(timestamp)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read timestamp.\n" ; return false ; } current_request->set_time_sent(timestamp) ; // Read position fields Point3D position ; if (! file.read_point3d(position)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read coordinates.\n" ; return false ; } // Read direction field Direction direction ; int direction_int ; if (! file.read_field(direction_int)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read direction.\n" ; return false ; } if (direction_int != 0) direction = direction_int ; // Reading {MAC_AP;SS} couples unordered_map measurements ; string mac_ap ; while (file.read_field(mac_ap)) { int ss ; if (! file.read_field(ss)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read mac_ap.\n" ; return false ; } PosUtil::to_upper(mac_ap) ; if (! Configuration::bool_value("positioning.accept-new-aps") && ! Stock::ap_exists(mac_ap)) continue ; const AccessPoint &ap = Stock::find_create_ap(mac_ap) ; measurements[mac_ap].set_ap(&ap) ; measurements[mac_ap].add_ss(ss) ; } if (measurements.empty()) return false ; current_request->set_measurements(measurements) ; // Calibration request? fill_calibration_request_data(mac_mobile, position, direction, type) ; return true ; }