def transmitCommand(self, id, cmd):
        try:
            with cc1101.CC1101(lock_spi_device=True) as transceiver:
                print("defaults:", transceiver)
                transceiver.set_base_frequency_hertz(868.34e6)
                transceiver.set_symbol_rate_baud(2400)
                transceiver._set_modulation_format(0b000)
                transceiver.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD)
                # transceiver.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD)
                # transceiver.set_preamble_length_bytes(2)
                # transceiver.set_sync_word(b"\x12\x34")
                transceiver.disable_checksum()
                transceiver.set_output_power((0, 0xC2))  # 
                print(transceiver)
                print("state", transceiver.get_marc_state().name)
                print("base frequency", transceiver.get_base_frequency_hertz(), "Hz")
                print("symbol rate", transceiver.get_symbol_rate_baud(), "Baud")
                print("modulation format", transceiver.get_modulation_format().name)
                sync_mode = transceiver.get_sync_mode()
                print("sync mode", sync_mode)
                if sync_mode != cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD:
                    print("preamble length", transceiver.get_preamble_length_bytes(), "bytes")
                    print("sync word", transceiver.get_sync_word())
                print("output power settings (patable)", transceiver.get_output_power())

                print("\nstarting transmission")
                transceiver.transmit(self.clusterOfStores.listOfStores[id].listCmd[cmd])
        except:
            print("Unable to send command")
Exemplo n.º 2
0
def test___str___(transceiver_str, sync_word):
    transceiver = cc1101.CC1101()
    with unittest.mock.patch.object(
            transceiver,
            "get_main_radio_control_state_machine_state",
            return_value=cc1101.MainRadioControlStateMachineState.IDLE,
    ), unittest.mock.patch.object(
            transceiver, "get_base_frequency_hertz",
            return_value=433.92e6), unittest.mock.patch.object(
                transceiver, "get_symbol_rate_baud",
                return_value=2142), unittest.mock.patch.object(
                    transceiver,
                    "get_modulation_format",
                    return_value=cc1101.ModulationFormat.ASK_OOK,
                ), unittest.mock.patch.object(
                    transceiver,
                    "get_sync_mode",
                    return_value=cc1101.SyncMode.TRANSMIT_16_MATCH_15_BITS if
                    sync_word else cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD,
                ), unittest.mock.patch.object(
                    transceiver, "get_preamble_length_bytes",
                    return_value=4), unittest.mock.patch.object(
                        transceiver, "get_sync_word",
                        return_value=sync_word), unittest.mock.patch.object(
                            transceiver,
                            "get_packet_length_mode",
                            return_value=cc1101.PacketLengthMode.FIXED,
                        ), unittest.mock.patch.object(
                            transceiver,
                            "get_packet_length_bytes",
                            return_value=21), unittest.mock.patch.object(
                                transceiver,
                                "get_output_power",
                                return_value=(0, 0xC0)):
        assert str(transceiver) == transceiver_str
    def __init__(self):

        self.clusterOfStores = ClusterOfStores("System open space")

        with cc1101.CC1101(lock_spi_device=True) as transceiver:
            print("defaults:", transceiver)
            transceiver.set_base_frequency_hertz(868.34e6)
            transceiver.set_symbol_rate_baud(2400)
            transceiver._set_modulation_format(0b000)
            transceiver.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD)
            # transceiver.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD)
            # transceiver.set_preamble_length_bytes(2)
            # transceiver.set_sync_word(b"\x12\x34")
            transceiver.disable_checksum()
            transceiver.set_output_power((0, 0xC2))  # 
            print(transceiver)
            print("state", transceiver.get_marc_state().name)
            print("base frequency", transceiver.get_base_frequency_hertz(), "Hz")
            print("symbol rate", transceiver.get_symbol_rate_baud(), "Baud")
            print("modulation format", transceiver.get_modulation_format().name)
            sync_mode = transceiver.get_sync_mode()
            print("sync mode", sync_mode)
            if sync_mode != cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD:
                print("preamble length", transceiver.get_preamble_length_bytes(), "bytes")
                print("sync word", transceiver.get_sync_word())
            print("output power settings (patable)", transceiver.get_output_power())
Exemplo n.º 4
0
def _export_config():
    argparser = argparse.ArgumentParser(
        description="Export values in CC1101's configuration registers"
        " after applying settings specified via command-line arguments & options",
        allow_abbrev=False,
    )
    _add_common_args(argparser)
    argparser.add_argument("--format",
                           choices=["python-list"],
                           default="python-list")
    args = argparser.parse_args()
    _init_logging(args)
    _LOGGER.debug("args=%r", args)
    with cc1101.CC1101(lock_spi_device=True) as transceiver:
        _configure_via_args(transceiver=transceiver,
                            args=args,
                            packet_length_if_fixed=None)
        _LOGGER.info("%s", transceiver)
        print("[")
        for register_index, (register, value) in enumerate(
                transceiver.get_configuration_register_values().items()):
            assert register_index == register.value
            print("0b{value:08b}, # 0x{value:02x} {register_name}".format(
                value=value, register_name=register.name))
        print("]")
        print("# PATABLE = {}".format(
            # pylint: disable=protected-access; internal function & method
            cc1101._format_patable(transceiver._get_patable(),
                                   insert_spaces=True)))
Exemplo n.º 5
0
def test___init__select_device(bus, chip_select):
    with unittest.mock.patch("spidev.SpiDev"):
        transceiver = cc1101.CC1101(spi_bus=bus, spi_chip_select=chip_select)
    assert transceiver._spi_bus == bus
    assert transceiver._spi_chip_select == chip_select
    assert transceiver._spi_device_path == "/dev/spidev{}.{}".format(
        bus, chip_select)
    transceiver._spi.open.side_effect = SystemExit
    with pytest.raises(SystemExit):
        with transceiver:
            pass
    transceiver._spi.open.assert_called_once_with(bus, chip_select)
Exemplo n.º 6
0
 def __init__(self,
              gdo0_gpio_line_name: bytes,
              unlock_spi_device: bool = False):
     """
     gdo0_gpio_line_name:
         Name of GPIO pin that CC1101's GDO0 pin is connected to.
         Run command `gpioinfo` to get a list of all available GPIO lines.
     unlock_spi_device:
         If True, flock on SPI device file /dev/spidev0.0
         will be released after configuring the transceiver.
         Useful if another process (infrequently) accesses
         the transceiver simultaneously.
     """
     self._gdo0_gpio_line_name = gdo0_gpio_line_name
     self._unlock_spi_device = unlock_spi_device
     self._transceiver = cc1101.CC1101(lock_spi_device=True)
     self._transmission_length_bytes = math.ceil(self._MESSAGE_LENGTH_BITS *
                                                 self._MESSAGE_REPEATS / 8)
Exemplo n.º 7
0
def _transmit():
    argparser = argparse.ArgumentParser(
        description="Transmits the payload provided via standard input (stdin)"
        " ASK/OOK-modulated in big-endian bit order.",
        allow_abbrev=False,
    )
    _add_common_args(argparser)
    args = argparser.parse_args()
    _init_logging(args)
    _LOGGER.debug("args=%r", args)
    payload = sys.stdin.buffer.read()
    # configure transceiver after reading from stdin
    # to avoid delay between configuration and transmission if pipe is slow
    with cc1101.CC1101(lock_spi_device=True) as transceiver:
        _configure_via_args(transceiver=transceiver,
                            args=args,
                            packet_length_if_fixed=len(payload))
        _LOGGER.info("%s", transceiver)
        transceiver.transmit(payload)
Exemplo n.º 8
0
import logging
import time

import cc1101

logging.basicConfig(level=logging.INFO)

with cc1101.CC1101(lock_spi_device=True) as transceiver:
    print("defaults:", transceiver)
    transceiver.set_base_frequency_hertz(433.5e6)
    transceiver.set_symbol_rate_baud(600)
    # transceiver.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD)
    # transceiver.set_preamble_length_bytes(2)
    # transceiver.set_sync_word(b"\x12\x34")
    # transceiver.disable_checksum()
    transceiver.set_output_power((0, 0xC0))  # OOK modulation: (off, on)
    print(transceiver)
    print("state", transceiver.get_marc_state().name)
    print("base frequency", transceiver.get_base_frequency_hertz(), "Hz")
    print("symbol rate", transceiver.get_symbol_rate_baud(), "Baud")
    print("modulation format", transceiver.get_modulation_format().name)
    sync_mode = transceiver.get_sync_mode()
    print("sync mode", sync_mode)
    if sync_mode != cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD:
        print("preamble length", transceiver.get_preamble_length_bytes(),
              "bytes")
        print("sync word", transceiver.get_sync_word())
    print("output power settings (patable)", transceiver.get_output_power())
    print("\nstarting transmission")
    transceiver.transmit(b"\xff\xaa\x00 message")
    time.sleep(1.0)
import logging

import cc1101

logging.basicConfig(level=logging.INFO)

with cc1101.CC1101() as transceiver:
    transceiver.set_base_frequency_hertz(433.5e6)
    transceiver.set_symbol_rate_baud(600)
    transceiver.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD)
    transceiver.set_packet_length_mode(cc1101.PacketLengthMode.FIXED)
    transceiver.set_packet_length_bytes(4)
    transceiver.disable_checksum()
    transceiver.set_output_power((0, 0xC0))  # OOK modulation: (off, on)
    print(transceiver)
    transceiver.transmit(b"\xff\x00\xaa\xff")
Exemplo n.º 10
0
def transceiver():
    with unittest.mock.patch("spidev.SpiDev"):
        return cc1101.CC1101()