/* * 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 * http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t * 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 * this notice by the COPYRITGHT.t2t file's contents. */ #include "inputcsv.hh" #include "posutil.hh" #include "posexcept.hh" #include "stock.hh" #include "calibrationrequest.hh" #include "configuration.hh" #include #include using namespace std ; /* *** 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 uint_fast8_t type ; uint_fast16_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 the number of packets uint_fast16_t nb_packets ; if (! file.read_field(nb_packets)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read the number of packets.\n" ; return false ; } current_request->set_nb_packets(nb_packets) ; // 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 all the {AP_MAC;Packet_ID;SS} unordered_map measurements ; string mac_ap ; while (file.read_field(mac_ap)) { pkt_id_t packet_id ; if (! file.read_field(packet_id)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read the packet ID.\n" ; return false ; } int_fast16_t ss ; if (! file.read_field(ss)) { // Wrong number of fields if (Configuration::is_configured("verbose")) cerr << "InputCSV: cannot read the signal strength.\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(packet_id, ss) ; } if (measurements.empty()) return false ; current_request->set_measurements(measurements) ; // Calibration request? fill_calibration_request_data(mac_mobile, position, direction, type) ; return true ; }