Statistics
| Branch: | Revision:

napa-baselibs / monl / plugins / corrected_delay_measure.cpp @ 507372bb

History | View | Annotate | Download (2.72 KB)

1
/***************************************************************************
2
 *   Copyright (C) 2009 by Robert Birke
3
 *   robert.birke@polito.it
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9

10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14

15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
18
 ***********************************************************************/
19

    
20
#include "corrected_delay_measure.h"
21
#include "clockdrift_measure.h"
22
#include "napa_log.h"
23
#include <math.h>
24

    
25
CorrecteddelayMeasure::CorrecteddelayMeasure(class MeasurePlugin *m, MeasurementCapabilities mc, class MeasureDispatcher *md): MonMeasure(m,mc,md) {
26
}
27

    
28
CorrecteddelayMeasure::~CorrecteddelayMeasure() {
29
}
30

    
31
void CorrecteddelayMeasure::stop() {
32
        r_tx_list[R_CORRECTED_DELAY] = r_rx_list[R_CORRECTED_DELAY] = NAN;
33
        mClockdrift = NULL;
34
}
35

    
36
void CorrecteddelayMeasure::init() {
37
        mClockdrift = NULL;
38
}
39

    
40
result CorrecteddelayMeasure::RxPkt(result *r,ExecutionList *el) {
41
        if(mClockdrift == NULL) {
42
                if(el->find(CLOCKDRIFT) == el->end()) {
43
                        error("MONL: Corrected Delay: dependencies not fullfilled");
44
                        return NAN;
45
                }
46
                mClockdrift = (*el)[CLOCKDRIFT];
47
        }
48

    
49
        if(!isnan(r[R_CLOCKDRIFT]))
50
                r[R_CORRECTED_DELAY] = fabs(r[R_SEND_TIME] - r[R_RECEIVE_TIME]) - (r[R_SEND_TIME] - ((ClockdriftMeasure*)mClockdrift)->first_tx) * ((ClockdriftMeasure*)mClockdrift)->b - ((ClockdriftMeasure*)mClockdrift)->a;
51
        else
52
                r[R_CORRECTED_DELAY] = NAN;
53

    
54
        char dbg[512];
55
        snprintf(dbg, sizeof(dbg), "Ts: %f OrgD: %f CorD: %f Tx: %f Rx: %f a: %f b: %f Ftx: %f", r[R_RECEIVE_TIME], fabs(r[R_SEND_TIME] - r[R_RECEIVE_TIME]), r[R_CORRECTED_DELAY], r[R_SEND_TIME], r[R_RECEIVE_TIME], ((ClockdriftMeasure*)mClockdrift)->a, ((ClockdriftMeasure*)mClockdrift)->b, ((ClockdriftMeasure*)mClockdrift)->first_tx);
56
        debugOutput(dbg);
57

    
58
        return r[R_CORRECTED_DELAY];
59
}
60

    
61
result CorrecteddelayMeasure::RxData(result *r,ExecutionList *el) {
62
        return RxPkt(r, el);
63
}
64

    
65

    
66
CorrecteddelayMeasurePlugin::CorrecteddelayMeasurePlugin() {
67
        /* Initialise properties: MANDATORY! */
68
        name = "Corrected delay";
69
        desc = "Forward delay with clock drift correction";
70
        id = CORRECTED_DELAY;
71
        /* end of mandatory properties */
72
        addDependency(CLOCKDRIFT);
73
        //TODO add dependency
74
}