aboutsummaryrefslogtreecommitdiff
path: root/src/devices/merger.cpp
blob: 2aa3e9ffea3df4dd5c36109b81a57b550f657194 (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
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
#include <merger.h>
#include <specs.h>

using namespace std;

void Merger::on_port_in1_changed()
{
    const double transmission = pow(10.0, - m_attenuation_dB / 20) / sqrt(2);
    m_memory_in1[0] = 0; // initializing for nan wavelength

    if (specsGlobalConfig.verbose_component_initialization)
    {
        cout << name() << ":" << endl;
        cout << "transmission = " << pow(transmission, 2) << " W/W" << endl;
        cout << (dynamic_cast<spx::oa_signal_type *>(p_in1.get_interface()))->name() << endl;
        cout << "\t --> \t" << (dynamic_cast<spx::oa_signal_type *>(p_out.get_interface()))->name() << endl;
        cout << (dynamic_cast<spx::oa_signal_type *>(p_in2.get_interface()))->name();
        cout << endl;
        cout << endl;
    }

    OpticalSignal p_in1_read;

    while (true) {
        // Wait for a new input signal
        wait();
        // Read sum of input signals
        p_in1_read = p_in1->read();

        auto cur_wavelength_id = p_in1_read.m_wavelength_id;
        // Updating the field memory
        m_memory_in1[cur_wavelength_id] = p_in1_read.m_field;

        auto s = OpticalSignal(m_memory_in1[cur_wavelength_id] +
                                m_memory_in2[cur_wavelength_id]
                                , cur_wavelength_id);

        s *= transmission;

        m_out_writer.delayedWrite(s,SC_ZERO_TIME);
    }
}

void Merger::on_port_in2_changed()
{
    const double transmission = pow(10.0, - m_attenuation_dB / 20) / sqrt(2);
    m_memory_in2[0] = 0; // initializing for nan wavelength

    OpticalSignal p_in2_read;

    while (true) {
        // Wait for a new input signal
        wait();
        // Read sum of input signals
        p_in2_read = p_in2->read();

        auto cur_wavelength_id = p_in2_read.m_wavelength_id;
        // Updating the field memory
        m_memory_in2[cur_wavelength_id] = p_in2_read.m_field;

        auto s = OpticalSignal(m_memory_in1[cur_wavelength_id] +
                                m_memory_in2[cur_wavelength_id]
                                , cur_wavelength_id);

        s *= transmission;

        m_out_writer.delayedWrite(s,SC_ZERO_TIME);
    }
}