channelStateInformation.c 1.3 KB
Newer Older
1
2
3
4
5
6
#include <stdlib.h>
#include "../defines.h"
#include "../util/common.h"
#include "../util/dbg.h"
#include "channelStateInformation.h"

7
8
9
// TODO: LOCKS

PrrtChannelStateInformation * PrrtChannelStateInformation_create()
10
{
11
12
    PrrtChannelStateInformation *csi = calloc(1, sizeof(PrrtChannelStateInformation));
    check_mem(csi);
13
14
15

    csi->rttMean = 0;
    csi->rttDev = 0;
16
    return csi;
17
18
19

    error:
    PERROR("Should not happen.%s","");
20
    return NULL;
21
22
}

23
void PrrtChannelStateInformation_update_rtt(PrrtChannelStateInformation *csi, prrtTimedelta_t rtt)
24
25
{
    int32_t delta = rtt - csi->rttMean;
26
    // TODO: ensure that there are no arithemtic problems via rounding etc.
27
28
    csi->rttMean = (prrtTimedelta_t) (csi->rttMean + RRT_ALPHA * delta);
    csi->rttDev = (prrtTimedelta_t) (csi->rttDev + RRT_ALPHA * (labs(delta) - csi->rttDev));
29
30
31
32
33
34
35
36
37
38
}

void PrrtChannelStateInformation_print(PrrtChannelStateInformation *csi)
{
    check(csi != NULL, "Input should not be NULL.");
    printf("RTT [us]: %d +- %d\n", csi->rttMean, csi->rttDev);

    return;
    error:
    PERROR("Should not happen.%s","");
39
40
41
42
43
44
45
46
47
48
49
50
}

prrtTimedelta_t PrrtChannelStateInformation_get_rtt(PrrtChannelStateInformation *csi)
{
    return csi->rttMean;
}

bool PrrtChannelStateInformation_destroy(PrrtChannelStateInformation *csi)
{
    free(csi);
    return true;
}