class IsmtvModule(wishful_module.AgentModule):
    node = None
    sensor = None
    sweep_config = None
    generator = None
    tx_config = None

    def __init__(self, dev):
        super(IsmtvModule, self).__init__()
        self.log = logging.getLogger('IsmtvModule')
        ser = serial.Serial(dev, 115200)
        self.node = alh.ALHTerminal(ser)

    @wishful_module.bind_function(upis.radio.get_measurements)
    def get_measurements(self, params):
        if not self.sensor:
            self.sensor = SpectrumSensor(self.node)
            config_list = self.sensor.get_config_list()
            self.sweep_config = config_list.get_sweep_config(
                params[0], params[1], params[2])
            if self.sweep_config is None:
                self.sensor = None
                raise Exception("Node can not scan specified frequency range.")
        sweep = self.sensor.sweep(self.sweep_config)
        f = list(self.sweep_config.get_hz_list())
        p = sweep.data
        return {'frequency': f, 'power': p}

    @wishful_module.bind_function(upis.radio.play_waveform)
    def play_waveform(self, iface, freq, power_lvl, kwargs):
        if not self.generator:
            self.generator = SignalGenerator(self.node)
            config_list = self.generator.get_config_list()
            self.tx_config = config_list.get_tx_config(freq, power_lvl)
            if self.tx_config is None:
                self.generator = None
                return 2

        now = time.time()
        program = SignalGeneratorProgram(self.tx_config, now + 5,
                                         kwargs['play_time'])
        self.generator.program(program)

        return 0

    @wishful_module.bind_function(upis.radio.get_radio_info)
    def get_radio_info(self, platform_id):
        if platform_id == "sensor":
            sensor = SpectrumSensor(self.node)
            config_list = sensor.get_config_list()
        elif platform_id == "generator":
            generator = SignalGenerator(self.node)
            config_list = generator.get_config_list()
        else:
            config_list = str(
                platform_id) + ": Not supported! Try: sensor or generator"

        return config_list
Exemplo n.º 2
0
    def test_sweep_1(self):
        class MockALH(ALHProtocol):
            def _post(self, resource, data, *args):
                return b"\x00\x00\x01\x00\x02\x00D\xa4H;"

        alh = MockALH()
        ss = SpectrumSensor(alh)

        sc = self._get_sc()
        r = ss.sweep(sc)

        self.assertEqual(r.data, [0., .01, .02])
Exemplo n.º 3
0
	def test_sweep_1(self):
		class MockALH(ALHProtocol):
			def _post(self, resource, data, *args):
				return b"\x00\x00\x01\x00\x02\x00D\xa4H;"

		alh = MockALH()
		ss = SpectrumSensor(alh)

		sc = self._get_sc()
		r = ss.sweep(sc)

		self.assertEqual(r.data, [0., .01, .02])
Exemplo n.º 4
0
    def test_sweep_2(self):
        class MockALH(ALHProtocol):
            def _post(self, resource, data, *args):
                # negative CRC
                return b"\x00\x00\x01\x00\x08\x00\xceL\xa7\xc1"

        alh = MockALH()
        ss = SpectrumSensor(alh)

        sc = self._get_sc()
        r = ss.sweep(sc)

        self.assertEqual(r.data, [0., .01, .08])
Exemplo n.º 5
0
	def test_sweep_2(self):
		class MockALH(ALHProtocol):
			def _post(self, resource, data, *args):
				# negative CRC
				return b"\x00\x00\x01\x00\x08\x00\xceL\xa7\xc1"

		alh = MockALH()
		ss = SpectrumSensor(alh)

		sc = self._get_sc()
		r = ss.sweep(sc)

		self.assertEqual(r.data, [0., .01, .08])
Exemplo n.º 6
0
def main():
	# Turn on logging so that we can see ALH requests happening in the
	# background.
	logging.basicConfig(level=logging.INFO)

	coor = alh.ALHWeb("https://crn.log-a-tec.eu/communicator", 10001)

	# Node 19 is equipped with an UHF receiver (TDA18219 on SNE-ISMTV-UHF)
	node = alh.ALHProxy(coor, 19) 

	# Node 17 is equipped with an 2.4 GHz receiver (CC2500 on SNE-ISMTV-24)
	#node = alh.ALHProxy(coor, 17)

	# Wrap an ALHProxy object with a SpectrumSensor object that provides an
	# convenient interface to spectrum sensing functionality of the node
	# exposed through ALH resources.
	sensor = SpectrumSensor(node)

	# Get a ConfigList object that contains a list of device configurations
	# supported by the chosen sensor node.
	config_list = sensor.get_config_list()

	# ConfigList.get_sweep_config() method will automatically choose
	# the best device and configuration that can cover the requested
	# frequency range.
	#
	# It returns an instance of SweepConfig class that describes all
	# the settings for a frequency sweep.
	#
	# First example defines a sweep starting at 550 MHz and ending at
	# 574 MHz with 2 MHz steps (use with node 19)
	#
	# Second example define a sweep starting at 2420 MHz and ending at
	# 2430 MHz with 400 kHz steps (use with node 17)
	sweep_config = config_list.get_sweep_config(550e6, 574e6, 1e6)
	#sweep_config = config_list.get_sweep_config(2420e6, 2430e6, 400e3)

	if sweep_config is None:
		raise Exception("Node can not scan specified frequency range.")

	pyplot.ion()

	while True:
		# Perform the sweep
		sweep = sensor.sweep(sweep_config)

		# Get the list of frequencies covered by the sweep
		f_hz = sweep_config.get_hz_list()

		# Convert list from Hz to MHz for nicer plot
		f_mhz = numpy.array(f_hz) / 1e6

		pyplot.clf()
		pyplot.grid()
		pyplot.xlabel("frequency [MHz]")
		pyplot.ylabel("power [dBm]")

		# Plot data
		pyplot.plot(f_mhz, sweep.data)

		pyplot.axis([min(f_mhz), max(f_mhz), -110, -50])
		pyplot.draw()

		pyplot.pause(1)
Exemplo n.º 7
0
def main():
    # Turn on logging so that we can see ALH requests happening in the
    # background.
    logging.basicConfig(level=logging.INFO)

    coor = alh.ALHWeb("https://crn.log-a-tec.eu/communicator", 10001)

    # Node 19 is equipped with an UHF receiver (TDA18219 on SNE-ISMTV-UHF)
    node = alh.ALHProxy(coor, 19)

    # Node 17 is equipped with an 2.4 GHz receiver (CC2500 on SNE-ISMTV-24)
    #node = alh.ALHProxy(coor, 17)

    # Wrap an ALHProxy object with a SpectrumSensor object that provides an
    # convenient interface to spectrum sensing functionality of the node
    # exposed through ALH resources.
    sensor = SpectrumSensor(node)

    # Get a ConfigList object that contains a list of device configurations
    # supported by the chosen sensor node.
    config_list = sensor.get_config_list()

    # ConfigList.get_sweep_config() method will automatically choose
    # the best device and configuration that can cover the requested
    # frequency range.
    #
    # It returns an instance of SweepConfig class that describes all
    # the settings for a frequency sweep.
    #
    # First example defines a sweep starting at 550 MHz and ending at
    # 574 MHz with 2 MHz steps (use with node 19)
    #
    # Second example define a sweep starting at 2420 MHz and ending at
    # 2430 MHz with 400 kHz steps (use with node 17)
    sweep_config = config_list.get_sweep_config(550e6, 574e6, 1e6)
    #sweep_config = config_list.get_sweep_config(2420e6, 2430e6, 400e3)

    if sweep_config is None:
        raise Exception("Node can not scan specified frequency range.")

    pyplot.ion()

    while True:
        # Perform the sweep
        sweep = sensor.sweep(sweep_config)

        # Get the list of frequencies covered by the sweep
        f_hz = sweep_config.get_hz_list()

        # Convert list from Hz to MHz for nicer plot
        f_mhz = numpy.array(f_hz) / 1e6

        pyplot.clf()
        pyplot.grid()
        pyplot.xlabel("frequency [MHz]")
        pyplot.ylabel("power [dBm]")

        # Plot data
        pyplot.plot(f_mhz, sweep.data)

        pyplot.axis([min(f_mhz), max(f_mhz), -110, -50])
        pyplot.draw()

        pyplot.pause(1)