blob: ad3976d2fca8bd44bfd4f962baf5747381fd24f9 (
plain)
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
|
#include "specs.h"
#include <power_meter.h>
#include <cstdlib> // system()
#include <random>
#include <complex>
using namespace std;
void PowerMeter::trace(sc_trace_file *Tf) const
{
sc_trace(Tf, m_cur_power, (string(name()) + ".power").c_str());
}
void PowerMeter::on_port_in_changed()
{
// always initialize memory
m_memory_in[0] = 0;
while (true) {
// Wait for a new input signal
wait();
const auto &p_in_read = p_in->read();
auto cur_wavelength_id = p_in_read.m_wavelength_id;
// Updating the field memory
m_memory_in[cur_wavelength_id] = p_in_read.m_field;
double total_power = 0;
for (auto field : m_memory_in)
{
total_power += norm(field.second);
}
m_cur_power = total_power;
}
}
|