Example #1
0
def test_harvesting_voltage_fail_mode(shepherd_up, mode):
    sysfs_interface.set_mode(mode)
    with pytest.raises(sysfs_interface.SysfsInterfaceException):
        sysfs_interface.set_harvesting_voltage(2**15)
Example #2
0
def test_set_mode_fail_invalid(shepherd_up):
    with pytest.raises(sysfs_interface.SysfsInterfaceException):
        sysfs_interface.set_mode('invalidmode')
Example #3
0
def test_set_mode(shepherd_up, mode):
    sysfs_interface.set_mode(mode)
    assert sysfs_interface.get_mode() == mode
Example #4
0
def test_set_mode_fail_offline(shepherd_running):
    with pytest.raises(sysfs_interface.SysfsInterfaceException):
        sysfs_interface.set_mode('harvesting')
Example #5
0
    def __enter__(self):
        try:

            for name, pin in gpio_pin_nums.items():
                self.gpios[name] = GPIO(pin, "out")

            self._set_power(True)
            self.set_mppt(False)
            self.set_harvester(False)
            self.set_lvl_conv(False)

            self._adc_set_power(True)

            logger.debug("Shepherd hardware is powered up")

            # If shepherd hasn't been terminated properly
            if sysfs_interface.get_state() != "idle":
                sysfs_interface.set_stop()

            sysfs_interface.wait_for_state("idle", 5)
            logger.debug(f"Switching to '{ self.mode }' mode")
            sysfs_interface.set_mode(self.mode)

            # Open the RPMSG channel provided by rpmsg_pru kernel module
            rpmsg_dev = Path("/dev/rpmsg_pru0")
            self.rpmsg_fd = os.open(str(rpmsg_dev), os.O_RDWR | os.O_SYNC)
            os.set_blocking(self.rpmsg_fd, False)
            self._flush_msgs()

            # Ask PRU for base address of shared mem (reserved with remoteproc)
            mem_address = sysfs_interface.get_mem_address()
            # Ask PRU for size of shared memory (reserved with remoteproc)
            mem_size = sysfs_interface.get_mem_size()

            logger.debug(
                f"Shared memory address: \t0x{mem_address:08X}, size: {mem_size} byte"
            )

            # Ask PRU for size of individual buffers
            samples_per_buffer = sysfs_interface.get_samples_per_buffer()
            logger.debug(f"Samples per buffer: \t{ samples_per_buffer }")

            self.n_buffers = sysfs_interface.get_n_buffers()
            logger.debug(f"Number of buffers: \t{ self.n_buffers }")

            self.buffer_period_ns = sysfs_interface.get_buffer_period_ns()
            logger.debug(f"Buffer period: \t\t{ self.buffer_period_ns } ns")

            self.shared_mem = SharedMem(
                mem_address, mem_size, self.n_buffers, samples_per_buffer
            )

            self.shared_mem.__enter__()

            logger.debug(f"Setting load to '{ self.load }'")
            self.set_load(self.load)

            self.ldo.__enter__()
            self.set_ldo_voltage(False)

        except Exception:
            self._cleanup()
            raise

        sysfs_interface.wait_for_state("idle", 3)
        return self