summaryrefslogtreecommitdiffstats
path: root/lab_control/test/mock_lab.py
blob: 718f319884e430e0623822984a60b2f3132cd159 (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
from collections.abc import Callable

from lab_control.function_generator import FunctionGenerator
from lab_control.oscilloscope import Oscilloscope

class MockLab(FunctionGenerator, Oscilloscope):
    class FGChannelState:
        def __init__(self):
            self.on = False
            self.frequency = None
            self.amplitude = None

    class OscChannelState:
        def __init__(self):
            self.amplitudeFunction = None
            self.fgChannel = None

    def __init__(self):
        self.fgChannels = [MockLab.FGChannelState() for i in range(0, 2)]
        self.oscChannels = [MockLab.OscChannelState() for i in range(0, 4)]

    def setOn(self, channel: int) -> None:
        self.fgChannels[channel - 1].on = True

    def setOff(self, channel: int) -> None:
        self.fgChannels[channel - 1].on = False

    def setFrequency(self, channel: int, frequency: float) -> None:
        self.fgChannels[channel - 1].frequency = frequency

    def setAmplitude(self, channel: int, amplitude: float) -> None:
        self.fgChannels[channel - 1].amplitude = amplitude

    def setFunction(self, channel: int, function: int) -> None:
        pass

    def measureAmplitude(self, channel: int) -> float:
        fgChannel = self.oscChannels[channel - 1].fgChannel
        return self.oscChannels[channel - 1].amplitudeFunction(self.fgChannels[fgChannel].frequency)

    def measurePeakToPeak(self, channel: int) -> float:
        pass

    def measureRMS(self, channel: int) -> float:
        pass

    def measureFrequency(self, channel: int) -> float:
        pass

    def setAmplitudeFunction(self, channel: int, f: Callable[[float], float]) -> None:
        self.oscChannels[channel - 1].amplitudeFunction = f

    def connectChannels(self, fg: int, osc: int) -> None:
        self.oscChannels[osc - 1].fgChannel = fg - 1