A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
spectrum-data.cc
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*
15
* Author: Abdulla K. Al-Ali <abdulla.alali@qu.edu.qa>
16
*/
17
18
#include "spectrum-data.h"
19
20
21
namespace
ns3 {
22
23
TypeId
24
SpectrumData::GetTypeId (
void
)
25
{
26
static
TypeId tid = TypeId (
"ns3::SpectrumData"
)
27
.SetParent<Object> ()
28
.AddConstructor<SpectrumData> ()
29
;
30
return
tid;
31
}
32
33
34
35
// SpectrumData initializer
36
SpectrumData::SpectrumData() {
37
38
}
39
40
41
42
// ReadSpectrumFile: load the information form the spectrum file into the spectrum_table_
43
void
44
SpectrumData::ReadSpectrumFile(
char
*fileName) {
45
46
FILE* fd;
47
48
fd=fopen(fileName,
"rt"
);
49
50
if
(IO_SPECTRUM_DEBUG)
51
printf(
"Reading PU Data from File: %s \n"
, fileName);
52
53
54
if
(fd==NULL) {
55
printf(
" ERROR. Can't open file %s \n"
,fileName);
56
exit(0);
57
}
58
59
60
// For each channel in the range [0: MAX_CHANNELS]
61
// the spectrum file contains these entries:
62
// - bandwidth (b/s)
63
// - packet error rate
64
65
for
(
int
i=0; i<MAX_CHANNELS; i++) {
66
67
int
channel;
68
float
bandwidth;
69
float
per;
70
71
// read the next entry
72
fscanf(fd,
"%d %f %f"
,&channel,&bandwidth,&per);
73
74
if
(ferror(fd)) {
75
printf(
" ERROR. Can't read Spectrum Information from file %s \n"
, fileName);
76
exit(0);
77
}
78
79
80
if
(IO_SPECTRUM_DEBUG)
81
printf(
"[READING SPECTRUM FILE] #CHANNEL: %d #BANDWIDTH: %f PER: %f\n"
,channel, bandwidth, per);
82
83
// save the information in the spectrum_table_
84
m_spectrumTable_[channel].bandwidth=bandwidth;
85
m_spectrumTable_[channel].per=per;
86
}
87
88
fclose(fd);
89
}
90
91
92
93
94
// GetSpectrumData: return the spectrum_entry for the current channel
95
SpectrumEntry
96
SpectrumData::GetSpectrumData(
int
channel) {
97
98
if
((channel>=0) && (channel <MAX_CHANNELS))
99
return
m_spectrumTable_[channel];
100
101
else
{
102
printf(
" ERROR. Can't retrive Spectrum Information for channel %d \n"
, channel);
103
exit(0);
104
105
}
106
107
}
108
109
}
src
cognitive
model
spectrum-data.cc
Generated on Sun Mar 16 2014 11:25:01 for ns-3 by
1.8.6