def __init__(
        self,
        nvs,
        nv_model,
        bus,
        tx_id=0x1FFFFFFF,
        rx_id=0x1FFFFFF7,
        parent=None,
    ):
        checkbox_columns = Columns.fill(False)
        checkbox_columns.name = True

        root = epyqlib.variableselectionmodel.Variables()

        epyqlib.pyqabstractitemmodel.PyQAbstractItemModel.__init__(
            self, root=root, checkbox_columns=checkbox_columns, parent=parent)

        self.headers = Columns(
            name="Name",
            type="Type",
            address="Address",
            size="Size",
            bits="Bits",
            value="Value",
            file="File",
        )

        self.nvs = nvs
        self.nv_model = nv_model
        self.bus = bus

        self.git_hash = None

        self.bits_per_byte = None

        self.cache = None

        self.pull_log_progress = epyqlib.utils.qt.Progress()

        if self.nvs is not None:
            signal = self.nvs.neo.signal_by_path("CCP", "Connect",
                                                 "CommandCounter")
            self.protocol = ccp.Handler(
                endianness="little" if signal.little_endian else "big",
                tx_id=tx_id,
                rx_id=rx_id,
            )
            from twisted.internet import reactor

            self.transport = epyqlib.twisted.busproxy.BusProxy(
                protocol=self.protocol, reactor=reactor, bus=self.bus)
        else:
            self.protocol = None
            self.transport = None

        # TODO: consider using locale?  but maybe not since it's C code not
        #       raw strings
        self.sort_key = natsort.natsort_keygen(alg=natsort.ns.IGNORECASE)
        self.role_functions[epyqlib.utils.qt.UserRoles.sort] = self.data_sort
    def __init__(self, nvs, bus, tx_id=0x1FFFFFFF, rx_id=0x1FFFFFF7,
                 parent=None):
        checkbox_columns = Columns.fill(False)
        checkbox_columns.name = True

        root = epyqlib.variableselectionmodel.Variables()

        epyqlib.pyqabstractitemmodel.PyQAbstractItemModel.__init__(
                self, root=root, checkbox_columns=checkbox_columns,
                parent=parent)

        self.headers = Columns(
            name='Name',
            type='Type',
            address='Address',
            size='Size',
            bits='Bits',
            value='Value',
            file='File'
        )

        self.nvs = nvs
        self.bus = bus

        self.git_hash = None

        self.bits_per_byte = None

        self.cache = None

        self.pull_log_progress = epyqlib.utils.qt.Progress()

        signal = self.nvs.neo.signal_by_path('CCP', 'Connect', 'CommandCounter')
        self.protocol = ccp.Handler(
            endianness='little' if signal.little_endian else 'big',
            tx_id=tx_id,
            rx_id=rx_id
        )
        from twisted.internet import reactor
        self.transport = epyqlib.twisted.busproxy.BusProxy(
            protocol=self.protocol,
            reactor=reactor,
            bus=self.bus)

        # TODO: consider using locale?  but maybe not since it's C code not
        #       raw strings
        self.sort_key = natsort.natsort_keygen(alg=natsort.ns.IGNORECASE)
        self.role_functions[epyqlib.utils.qt.UserRoles.sort] = (
            self.data_sort
        )
Exemple #3
0
    def __attrs_post_init__(self):
        signal = self.nvs.neo.signal_by_path('CCP', 'Connect',
                                             'CommandCounter')
        self.ccp_protocol = ccp.Handler(
            endianness='little' if signal.little_endian else 'big',
            tx_id=self.tx_id,
            rx_id=self.rx_id,
        )
        from twisted.internet import reactor
        self.ccp_transport = epyqlib.twisted.busproxy.BusProxy(
            protocol=self.ccp_protocol, reactor=reactor, bus=self.bus)

        self.nv_protocol = epyqlib.twisted.nvs.Protocol()
        self.nv_transport = epyqlib.twisted.busproxy.BusProxy(
            protocol=self.nv_protocol, reactor=reactor, bus=self.bus)
Exemple #4
0
def test_main():
    # TODO: CAMPid 03127876954165421679215396954697
    # https://github.com/kivy/kivy/issues/4182#issuecomment-253159955
    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
    if "twisted.internet.reactor" in sys.modules:
        del sys.modules["twisted.internet.reactor"]

    import qt5reactor

    qt5reactor.install()

    from twisted.internet import reactor

    real_bus = can.interface.Bus(bustype="socketcan", channel="can0")
    bus = epyqlib.busproxy.BusProxy(bus=real_bus)

    device = epyqlib.device.Device(
        file=epyqlib.tests.common.devices["customer"],
        node_id=247,
    )

    tx_signal = device.neo_frames.signal_by_path("CCP", "Connect",
                                                 "CommandCounter")
    rx_signal = device.neo_frames.signal_by_path("CCPResponse", "Connect",
                                                 "CommandCounter")
    protocol = ccp.Handler(
        endianness="little" if tx_signal.little_endian else "big",
        tx_id=tx_signal.frame.id,
        rx_id=rx_signal.frame.id,
    )
    transport = epyqlib.twisted.busproxy.BusProxy(
        protocol=protocol,
        reactor=reactor,
        bus=bus,
    )

    d = protocol.connect()
    d.addCallback(lambda _: protocol.set_mta(
        address_extension=ccp.AddressExtension.flash_memory,
        address=0x310000,
    ))
    d.addCallback(lambda _: protocol.disconnect())
    d.addBoth(logit)

    logging.debug("---------- started")
    QTimer.singleShot(3000, reactor.stop)
    reactor.run()
Exemple #5
0
    def __init__(self, file, bus, progress=None, retries=5, parent=None):
        super().__init__(parent)

        self.progress = progress
        self.deferred = None
        self._canceled = False

        self.completed.connect(self.done)

        self.protocol = ccp.Handler(endianness="big")
        self.protocol.messages_sent.connect(self.update_progress)
        from twisted.internet import reactor

        self.transport = epyqlib.twisted.busproxy.BusProxy(
            protocol=self.protocol, reactor=reactor, bus=bus)

        coff = epyqlib.ticoff.Coff()
        coff.from_stream(file)

        self.retries = retries

        self.sections = [
            s for s in coff.sections if s.data is not None and s.virt_size > 0
        ]

        self.download_bytes = sum([len(s.data) for s in self.sections])
        download_messages_to_send = sum(
            [math.ceil(len(s.data) / 6) for s in self.sections])
        # For every 5 download messages there is also 1 set MTA and 1 CRC.
        # There will likely be a couple retries and there's a bit more overhead
        # to get started.
        self.total_messages_to_send = download_messages_to_send * 7 / 5 + 15

        self.connect_to_progress()

        self._data_start_time = None
        self.data_delta_time = None