From 2ddad20371983d5f6ba95f404f120b4051e51a5c Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Sat, 23 Jul 2011 09:13:22 +0200 Subject: [PATCH] [Positioning] Stock: generate one CR for all APs A Request is received by *all* the APs, therefore we have to generate one CalibrationRequest per ReferencePoint, and not one CalibrationRequest per AP in each ReferencePoint. --- owlps-positioning/src/stock.cc | 65 +++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/owlps-positioning/src/stock.cc b/owlps-positioning/src/stock.cc index 194bde9..2e8c88b 100644 --- a/owlps-positioning/src/stock.cc +++ b/owlps-positioning/src/stock.cc @@ -450,9 +450,31 @@ void Stock::regenerate_reference_points() if (is_ap_coordinate(current_point)) continue ; + /* Get/create the reference point */ + const ReferencePoint ¤t_rp = + find_create_reference_point(current_point) ; + + /* Create the timestamp */ + Timestamp time_sent ; + time_sent.now() ; + + /* Create the measurement list */ + unordered_map measurements ; + + /* Prepare the virtual mobile */ + string vmob_mac(PosUtil::int_to_mac(nb_virtual_mobiles++)) ; + // The gain and trx power of the mobile will be the average of + // those of all the known APs (could be better, probably) + double vmob_gain = 0 ; + double vmob_pow = 0 ; + for (unordered_map::const_iterator rx = aps.begin() ; rx != aps.end() ; ++rx) { + /* Update the mobile's attributes */ + vmob_gain += rx->second.get_antenna_gain() / aps.size() ; + vmob_pow += rx->second.get_trx_power() / aps.size() ; + /* Choose the 2 nearest APs in angle */ const Point3D &rx_coord = rx->second.get_coordinates() ; @@ -540,39 +562,24 @@ void Stock::regenerate_reference_points() ref2_ss = ref2_ss * ref2_percent / 100 ; double rx_ss = (ref1_ss + ref2_ss) / 2 ; - /* Create the timestamp */ - Timestamp time_sent ; - time_sent.now() ; - - /* Create the virtual mobile */ - string vmob_mac(PosUtil::int_to_mac(nb_virtual_mobiles++)) ; - float vmob_gain = - ref1.get_antenna_gain() * ref1_percent / 100 + - ref2.get_antenna_gain() * ref2_percent / 100 ; - float vmob_pow = - ref1.get_trx_power() * ref1_percent / 100 + - ref2.get_trx_power() * ref2_percent / 100 ; - Mobile vmob("", vmob_mac, vmob_gain, vmob_pow) ; - const Mobile &mobile = find_create_mobile(vmob) ; - - /* Create the measurement list */ + /* Create the measurement, add it to the list */ Measurement m(&rx->second) ; m.add_ss(rx_ss) ; - unordered_map measurements ; measurements[rx->second.get_mac_addr()] = m ; - - /* Get/create the reference point */ - const ReferencePoint &rp = - find_create_reference_point(current_point) ; - - /* Create the calibration request */ - CalibrationRequest cr(OWL_REQUEST_GENERATED) ; - cr.set_time_sent(time_sent) ; - cr.set_mobile(&mobile) ; - cr.set_measurements(measurements) ; - cr.set_reference_point(&rp) ; - store_calibration_request(cr) ; } + + /* Create the virtual mobile */ + Mobile vmob("", vmob_mac, vmob_gain, vmob_pow) ; + const Mobile &mobile = find_create_mobile(vmob) ; + + /* Create the calibration request */ + CalibrationRequest cr(OWL_REQUEST_GENERATED) ; + cr.set_time_sent(time_sent) ; + cr.set_mobile(&mobile) ; + cr.set_measurements(measurements) ; + cr.set_reference_point(¤t_rp) ; + + store_calibration_request(cr) ; } }