-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.hpp
93 lines (78 loc) · 2.6 KB
/
Calculator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*Calculatorクラス*/
#ifndef CALCULATOR_HEAD
#define CALCULATOR_HEAD
class Calculator{
public:
Calculator(){
}
int CarrierSense(NODE *n_data, int id, ModeMemory *modeMemo){
list<int> ::iterator it;
double distance = 0;
double CSLevel;
complex<double> channel_coeff;
/*他端末からの送信信号の受信電力を測定*/
it = modeMemo->All_trans.begin();
//cout << modeMemo->getAllTransNodes().size() << endl;
while(it != modeMemo->All_trans.end()){
if(id != *it){
distance = CalcUtile::NodesDistance(n_data[id].x, n_data[id].y, n_data[*it].x, n_data[*it].y);
channel_coeff = Channel::rayleigh();
CSLevel = Channel::pathLoss(distance, PATHLOSS_num) + abs(channel_coeff) * abs(channel_coeff);
if(CSLevel > CA_dBm){
break; //CAレベルを超えていれば
}
}
++it;
}
if(it != modeMemo->All_trans.end()){
return FALSE;
}
return TRUE;
}
int searchBeacon(double x, double y, NODE *n_data, ModeMemory *modeMemo){
int nodeId = CalcUtile::MinNode(x, y, modeMemo->Beacon_node, n_data);
if(nodeId == EMPTY){
return EMPTY;
}
return nodeId;
}
int searchAck(double x, double y, NODE *n_data, ModeMemory *modeMemo){
int nodeId = CalcUtile::MinNode(x, y, modeMemo->ACK_node, n_data);
if(nodeId == EMPTY){
return EMPTY;
}
return nodeId;
}
int searchTx(double x, double y, NODE *n_data, ModeMemory *modeMemo){
int nodeId = CalcUtile::MinNode(x, y, modeMemo->Trans_node, n_data);
if(nodeId == EMPTY){
return EMPTY;
}
return nodeId;
}
double calcSinr(NODE *n_data, double x, double y, int minNode, ModeMemory *modeMemo){
list<int> ::iterator it = modeMemo->All_trans.begin();
complex<double> chnlCoeff;
double distance = 0;
double loss = 0;
double fading = 0;
double interference = 0;
//int min = CalcUtile::MinNode(n_data, id, All_trans);
while(it != modeMemo->All_trans.end()){
if(*it != minNode){
distance = CalcUtile::NodesDistance(x, y, n_data[*it].x, n_data[*it].y);
loss = Channel::pathLoss(distance, PATHLOSS_num);
chnlCoeff = Channel::rayleigh();
fading = 10 * log10(abs(chnlCoeff) * abs(chnlCoeff));
interference += (pow(10, (fading + loss) / 10.0));
}
it++;
}
distance = CalcUtile::NodesDistance(x, y, n_data[minNode].x, n_data[minNode].y);
loss = Channel::pathLoss(distance, PATHLOSS_num);
chnlCoeff = Channel::rayleigh();;
fading = 10 * log10(abs(chnlCoeff) * abs(chnlCoeff));
return (loss + fading - (10 * log10(interference + NOISE)));
}
};
#endif