diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 32518da..d3ced8c 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -136,6 +136,7 @@ typedef struct _owl_autocalibration_order #define OWL_REQUEST_CALIBRATION 1 #define OWL_REQUEST_AUTOCALIBRATION 2 #define OWL_REQUEST_IMPLICIT 10 +#define OWL_REQUEST_UNDEFINED 255 /* Wi-Fi channel frequencies in Hz */ diff --git a/owlps-positioning/src/inputcsv.cc b/owlps-positioning/src/inputcsv.cc index 254da16..c2c1dde 100644 --- a/owlps-positioning/src/inputcsv.cc +++ b/owlps-positioning/src/inputcsv.cc @@ -43,6 +43,16 @@ const Request& InputCSV::get_next_request() const Mobile &mobile = Stock::find_create_mobile(mac_mobile) ; current_request->set_mobile(&mobile) ; + // Read request type + uint8_t type ; + if (! file.read_field(type)) + { + // Wrong number of fields: blank current request + current_request->clear() ; + return *current_request ; + } + current_request->set_type(type) ; + // Read Timestamp field Timestamp timestamp ; if (! file.read_timestamp(timestamp)) @@ -94,8 +104,9 @@ const Request& InputCSV::get_next_request() current_request->set_measurements(measurements) ; - // If the direction is valid, it means we have a CalibrationRequest - if (direction) + // Calibration request? + if (type == OWL_REQUEST_CALIBRATION || + type == OWL_REQUEST_AUTOCALIBRATION) { current_request_to_calibration_request() ; CalibrationRequest *request = diff --git a/owlps-positioning/src/inputlogcsv.cc b/owlps-positioning/src/inputlogcsv.cc index bd982d0..1661a7b 100644 --- a/owlps-positioning/src/inputlogcsv.cc +++ b/owlps-positioning/src/inputlogcsv.cc @@ -19,7 +19,10 @@ const string InputLogCSV::request_to_csv(const Request &request) const ostringstream csv_line ; if (request.get_mobile() != NULL) csv_line << request.get_mobile()->get_mac_addr() ; - csv_line << ';' << request.get_time_sent() << ';' ; + csv_line + << ';' << static_cast(request.get_type()) + << ';' << request.get_time_sent() + << ';' ; const CalibrationRequest *calibration_request = dynamic_cast(&request) ; diff --git a/owlps-positioning/src/inputudpsocket.cc b/owlps-positioning/src/inputudpsocket.cc index e8a57c2..8d968f7 100644 --- a/owlps-positioning/src/inputudpsocket.cc +++ b/owlps-positioning/src/inputudpsocket.cc @@ -110,6 +110,9 @@ const Request& InputUDPSocket::get_next_request() const Mobile &mobile = Stock::find_create_mobile(mac_mobile) ; current_request->set_mobile(&mobile) ; + // Request type + current_request->set_type(request.type) ; + // Timestamp current_request->set_time_sent(Timestamp(request.request_time)) ; diff --git a/owlps-positioning/src/outputcsv.cc b/owlps-positioning/src/outputcsv.cc index b209c46..c413e09 100644 --- a/owlps-positioning/src/outputcsv.cc +++ b/owlps-positioning/src/outputcsv.cc @@ -20,10 +20,12 @@ const string OutputCSV::result_to_csv(const Result &result) { if (request->get_mobile() != NULL) csv_line << request->get_mobile()->get_mac_addr() ; - csv_line << ';' << request->get_time_sent() ; + csv_line + << ';' << static_cast(request->get_type()) + << ';' << request->get_time_sent() ; } else - csv_line << ';' ; + csv_line << ";;;" ; Point3D position = result.get_position() ; csv_line diff --git a/owlps-positioning/src/request.cc b/owlps-positioning/src/request.cc index 8662093..4ef2dc4 100644 --- a/owlps-positioning/src/request.cc +++ b/owlps-positioning/src/request.cc @@ -30,6 +30,7 @@ Request::~Request() */ void Request::clear() { + type = OWL_REQUEST_UNDEFINED ; mobile = NULL ; time_sent.clear() ; measurements.clear() ; @@ -45,6 +46,7 @@ const Request& Request::operator=(const Request &source) if (this == &source) return *this ; + type = source.type ; mobile = source.mobile ; time_sent = source.time_sent ; measurements = source.measurements ; @@ -59,6 +61,7 @@ bool Request::operator==(const Request &source) const return true ; return + type == source.type && mobile == source.mobile && time_sent == source.time_sent && measurements == source.measurements ; @@ -74,7 +77,8 @@ ostream& operator<<(ostream &os, const Request &r) // MAC address os - << "Mobile: " + << "Type: " << static_cast(r.type) + << ", Mobile: " << (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile") << ":" ; @@ -101,6 +105,7 @@ size_t hash_value(const Request &source) { size_t seed = 0 ; + boost::hash_combine(seed, source.type) ; boost::hash_combine(seed, source.time_sent) ; if (source.mobile != NULL) boost::hash_combine(seed, source.mobile->get_mac_addr()) ; diff --git a/owlps-positioning/src/request.hh b/owlps-positioning/src/request.hh index 81a119a..59fb421 100644 --- a/owlps-positioning/src/request.hh +++ b/owlps-positioning/src/request.hh @@ -6,6 +6,8 @@ class Mobile ; #include "measurement.hh" #include "timestamp.hh" +#include + #include #include #include @@ -14,6 +16,8 @@ class Mobile ; class Request { protected: + /// Type of the request + uint_fast8_t type ; /// The mobile that sent the request Mobile *mobile ; /// Local date of the request on the mobile @@ -29,21 +33,25 @@ public: const std::tr1::unordered_map &_measurements = std::tr1::unordered_map()): + type(OWL_REQUEST_UNDEFINED), mobile(const_cast(_mobile)), time_sent(_time_sent), measurements(_measurements) {} Request(const std::tr1::unordered_map &_measurements): + type(OWL_REQUEST_UNDEFINED), mobile(NULL), measurements(_measurements) {} Request(const Timestamp &_time_sent, const std::tr1::unordered_map &_measurements = std::tr1::unordered_map()): + type(OWL_REQUEST_UNDEFINED), mobile(NULL), time_sent(_time_sent), measurements(_measurements) {} Request(const Request &source): + type(source.type), mobile(source.mobile), time_sent(source.time_sent), measurements(source.measurements) {} @@ -51,6 +59,7 @@ public: /** @name Read accessors */ //@{ + uint8_t get_type(void) const ; Mobile* get_mobile(void) const ; const Timestamp& get_time_sent(void) const ; const std::tr1::unordered_map& @@ -59,6 +68,7 @@ public: /** @name Write accessors */ //@{ + void set_type(const uint8_t _type) ; void set_mobile(const Mobile *_mobile) ; void set_time_sent(const Timestamp &_time_sent) ; void set_measurements(const std::tr1::unordered_map @@ -86,6 +96,13 @@ public: /* *** Read accessors *** */ + +inline uint8_t Request::get_type() const +{ + return type ; +} + + inline Mobile* Request::get_mobile() const { return mobile ; @@ -109,6 +126,12 @@ Request::get_measurements(void) const /* *** Write accessors *** */ +inline void Request::set_type(const uint8_t _type) +{ + type = _type ; +} + + inline void Request::set_mobile(const Mobile *_mobile) { mobile = const_cast(_mobile) ;