From e4ed6f6b3809be23226cbcd3027837f863040e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=B6hrs?= Date: Fri, 8 Mar 2024 13:58:50 +0100 Subject: [PATCH] CI: add and run codespell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Typos happen. Some are easy to spot in a review, but other ones are good in hiding from the human eye. Machines can not be tricked in the same way, which is why codespell finds some typos a human reviewer wouldn't. Run codespell once, fix all the found typos and add it to the CI. Signed-off-by: Leonard Göhrs --- .codespellrc | 2 ++ .github/workflows/codespell.yaml | 12 +++++++++++ bin/lxa-iobus-lpc11xxcanisp-invoke | 2 +- bin/lxa-iobus-lpc11xxcanisp-program | 32 ++++++++++++++--------------- bin/lxa-iobus-server | 2 +- doc/source/architecture.rst | 6 +++--- doc/source/can_canopen.rst | 8 ++++---- doc/source/getting_started.rst | 4 ++-- doc/source/web.rst | 2 +- lxa_iobus/canopen.py | 5 ----- lxa_iobus/lpc11xxcanisp/can_isp.py | 30 +++++++++++++-------------- lxa_iobus/network.py | 10 ++++----- lxa_iobus/node.py | 8 ++++---- lxa_iobus/node_drivers.py | 8 ++++---- lxa_iobus/server/server.py | 4 ++-- 15 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 .codespellrc create mode 100644 .github/workflows/codespell.yaml diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..6e47547 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,2 @@ +[codespell] +skip = ./.git,./build,./venv,./lxa_iobus.egg-info,./lxa_iobus/server/static/lib diff --git a/.github/workflows/codespell.yaml b/.github/workflows/codespell.yaml new file mode 100644 index 0000000..3ff689e --- /dev/null +++ b/.github/workflows/codespell.yaml @@ -0,0 +1,12 @@ +name: codespell + +on: [push, pull_request] + +jobs: + codespell: + name: Codespell + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: python3 -m pip install codespell + - run: codespell diff --git a/bin/lxa-iobus-lpc11xxcanisp-invoke b/bin/lxa-iobus-lpc11xxcanisp-invoke index cb61044..897f8cb 100755 --- a/bin/lxa-iobus-lpc11xxcanisp-invoke +++ b/bin/lxa-iobus-lpc11xxcanisp-invoke @@ -9,7 +9,7 @@ from canopen.sdo.exceptions import SdoCommunicationError class CanOpen: - """Minimal Setup to controll one ethmux""" + """Minimal Setup to control one ethmux""" def __init__(self, channel="can0", node_id=1): self.node_id = node_id diff --git a/bin/lxa-iobus-lpc11xxcanisp-program b/bin/lxa-iobus-lpc11xxcanisp-program index 7806d65..d5683cb 100755 --- a/bin/lxa-iobus-lpc11xxcanisp-program +++ b/bin/lxa-iobus-lpc11xxcanisp-program @@ -67,7 +67,7 @@ class IspCompareError(Exception): class CanIsp: DATA_SIZES = {8: "B", 16: "H", 32: "I"} - ram_offset = 0x10000500 # Offset to savely usable RAM + ram_offset = 0x10000500 # Offset to safely usable RAM object_directory = { "Device Type": [0x1000, 0, 32], @@ -177,7 +177,7 @@ class CanIsp: def unlock(self): """Unlocks write operations - Needs to be called befor writing to RAM or Flash""" + Needs to be called before writing to RAM or Flash""" self.send("Unlock Code", 23130) def write_to_ram(self, addr: int, data: bytes): @@ -210,11 +210,11 @@ class CanIsp: self.send("Copy Length", length) def go(self, addr): - """Jumps to given addresse""" + """Jumps to given address""" self.send("Execution Address", addr) self.send("Program Control", 1) # Trigger jump - def erase_flash_secotrs(self, start, stop): + def erase_flash_sectors(self, start, stop): """Clear given flash range""" if stop < start: raise ExceptionCanIsp("Sector range not ascending") @@ -254,7 +254,7 @@ class CanIsp: obj = self.object_directory["Device Type"] return self._get(obj[0], obj[1], None) # Get uint32 as bytearray - def compare(self, addr_1, addr_2, lenght): + def compare(self, addr_1, addr_2, length): """ Takes two addresses and a length and compare the data. Raises IspCompareError if a mismatch is found. @@ -262,14 +262,14 @@ class CanIsp: try: self.send("Compare Address 1", addr_1) self.send("Compare Address 2", addr_2) - self.send("Compare Length", lenght) + self.send("Compare Length", length) except IspSdoAbortedError as e: if e.str() == "COMPARE_ERROR": offset = self.get("Compare mismatch") raise IspCompareError(offset) from e def flash_image(self, start, data): - logging.info("Data to be writen: %d Byte", len(data)) + logging.info("Data to be written: %d Byte", len(data)) block_size = 4096 @@ -280,17 +280,17 @@ class CanIsp: # data must be multiple of block size # TODO add option for smaller block size - # Supporte are: 256, 512, 1024, 4096. + # Supported are: 256, 512, 1024, 4096. stuffing = len(data) % block_size if stuffing != 0: logging.info("Date buffer is extended by %d", stuffing) data += b"\xff" * (block_size - stuffing) - logging.info("Data to be writen %d Bytes", len(data)) + logging.info("Data to be written %d Bytes", len(data)) logging.info("Start sector %d", start_sector) sectors = len(data) // block_size - assert (len(data) % block_size) == 0, "Need to erease extra sector to fit date: %d" % len(data) + assert (len(data) % block_size) == 0, "Need to erase extra sector to fit date: %d" % len(data) logging.info("Sectors to write %d", sectors) @@ -298,10 +298,10 @@ class CanIsp: raise Exception("Data to write does not fit into flash are of 32k") logging.info("Erasing blocks %d to %d", start_sector, start_sector + sectors - 1) - # TODO: Add check if we need to erease block use Blank check sectors + # TODO: Add check if we need to erase block use Blank check sectors self.unlock() # Unlock writes self.prepare_flash_sectors(start_sector, start_sector + sectors - 1) - self.erase_flash_secotrs(start_sector, start_sector + sectors - 1) + self.erase_flash_sectors(start_sector, start_sector + sectors - 1) blocks = sectors @@ -323,13 +323,13 @@ class CanIsp: def fix_checksum(data): """ - This generate the checksum in the vectro table. - This is needed for the LPC11CXX und probebly all Cortex-M0. - and is normaly done somewhere in the swd programming chain. + This generate the checksum in the vector table. + This is needed for the LPC11CXX und probably all Cortex-M0. + and is normally done somewhere in the swd programming chain. For more info see: UM10398 26.3.3 Criterion for Valid User Code. """ - vector_table = data[0 : 4 * 7] # First 7 entrys + vector_table = data[0 : 4 * 7] # First 7 entries vector_table = struct.unpack("iiiiiii", vector_table) checksum = 0 - (sum(vector_table)) diff --git a/bin/lxa-iobus-server b/bin/lxa-iobus-server index 3a95fc7..47aeddb 100755 --- a/bin/lxa-iobus-server +++ b/bin/lxa-iobus-server @@ -137,7 +137,7 @@ except OSError as e: if e.errno == errno.ENODEV: # can interface not available exit("interface {} not available".format(args.interface)) -loop.create_task(server.flush_state_periodicly()) +loop.create_task(server.flush_state_periodically()) if args.shell: diff --git a/doc/source/architecture.rst b/doc/source/architecture.rst index 5e6beae..c696290 100644 --- a/doc/source/architecture.rst +++ b/doc/source/architecture.rst @@ -47,10 +47,10 @@ The following figure shows the structure of the LXA IOBus system: current state of the bus and connected devices. * **Linux SocketCAN**: The LXA IOBus Server uses `SocketCAN `_ - to interfact with the CAN-bus. + to interact with the CAN-bus. * **Node-specific electrical interface**: - Every LXA IOBus node has an application-specific specialiced electiral interface + Every LXA IOBus node has an application-specific specialised electrical interface that is designed to perform different automation tasks. * **CAN-Bus**: This is the actual electrical interface that connects server and nodes. - This is the same CAN bus inteface you may know from many automotive applications. + This is the same CAN bus interface you may know from many automotive applications. diff --git a/doc/source/can_canopen.rst b/doc/source/can_canopen.rst index 6a3b53d..c276062 100644 --- a/doc/source/can_canopen.rst +++ b/doc/source/can_canopen.rst @@ -2,7 +2,7 @@ CAN Basics ========== CAN and CANopen are, when compared to modern Ethernet and IP, -quite simple protcols. +quite simple protocols. Most software developers are however more familiar with Ethernet and IP and less with CAN and CANopen. @@ -62,7 +62,7 @@ Reliable transmission CAN makes a good amount of effort to make sure all nodes on the bus share a common understanding of the information transmitted: Every message contains a checksum to make sure no bit-errors -occour on the bus. +occur on the bus. Additionally all nodes on the bus do a handshake for every message that ensures that either all or no node received the message. @@ -86,9 +86,9 @@ Let's take a look at the following scenarios: been received by any node. This can happen if there are only two nodes on a bus and one is not powered or disconnected due to a faulty - conenction. + connection. * **Two other nodes on the bus and the checksum is OK**: - Both receiving nodes send an acknowlege after the end + Both receiving nodes send an acknowledge after the end of the message. All three nodes assume that every other node has received the message correctly. diff --git a/doc/source/getting_started.rst b/doc/source/getting_started.rst index 0a78e54..3ac5b30 100644 --- a/doc/source/getting_started.rst +++ b/doc/source/getting_started.rst @@ -58,7 +58,7 @@ a single LXA IOBus device: CAN structure for a single LXA IOBus device on a short bus. The 120Ω termination resistor is connected between CAN_H and CAN_L - and (for short busses) may be placed anywhere on the bus. + and (for short buses) may be placed anywhere on the bus. In this example the LXA IOBus device and the CAN adapter are the only devices on the CAN bus. @@ -168,7 +168,7 @@ differential impedance should be used for the CAN bus. For GND and power supply use wires with a sufficient cross section to keep the power supply and CAN bus common mode voltage in the allowed ranges. -For short busses flat ribbon cables present a cheap and easy-to-install +For short buses flat ribbon cables present a cheap and easy-to-install alternative to UTP cabling. Plugs and sockets are available from many manufacturers, for example *L17DEFRA09P* and *L17DEFRA09S* from Amphenol. diff --git a/doc/source/web.rst b/doc/source/web.rst index 957cbac..08d7196 100644 --- a/doc/source/web.rst +++ b/doc/source/web.rst @@ -28,7 +28,7 @@ output are available. Read the manual for the specific node for more information on specific options. -The following fiels are available for every node: +The following fields are available for every node: * **Name:** The logical name for this device. This name is used to identify this node on the :term:`REST` interface. diff --git a/lxa_iobus/canopen.py b/lxa_iobus/canopen.py index faefcde..03eea33 100644 --- a/lxa_iobus/canopen.py +++ b/lxa_iobus/canopen.py @@ -94,11 +94,6 @@ def __init__(self, **kwargs): setattr(self, key, value) -# lss_adresse: sowas wie mac adresse (wie eingebrannt) -# id_number : (unbekannt, kann man wahrscheinlich nicht verstehen) -# node_id : temporaere adresse auf dem bus (wie ip unter dhcp) - - def gen_lss_switch_mode_global_message(lss_mode): if lss_mode not in (LssMode.OPERATION, LssMode.CONFIGURATION): raise ValueError diff --git a/lxa_iobus/lpc11xxcanisp/can_isp.py b/lxa_iobus/lpc11xxcanisp/can_isp.py index 917f819..bc84ed5 100644 --- a/lxa_iobus/lpc11xxcanisp/can_isp.py +++ b/lxa_iobus/lpc11xxcanisp/can_isp.py @@ -67,7 +67,7 @@ def __str__(self): class CanIsp: DATA_SIZES = {8: "B", 16: "H", 32: "I"} - ram_offset = 0x10000500 # Offset to savely usable RAM + ram_offset = 0x10000500 # Offset to safely usable RAM object_directory = { "Device Type": [0x1000, 0, 32], @@ -216,7 +216,7 @@ def get(self, name): def unlock(self): """ Unlocks write operations - Needs to be called befor writing to RAM or Flash + Needs to be called before writing to RAM or Flash """ self.send("Unlock Code", 23130) @@ -258,12 +258,12 @@ def copy_ram_to_flash(self, ram_addr, flash_addr, length): self.send("Copy Length", length) def go(self, addr): - """Jumps to given addresse""" + """Jumps to given address""" self.send("Execution Address", addr) self.send("Program Control", 1) # Trigger jump - def erase_flash_secotrs(self, start, stop): + def erase_flash_sectors(self, start, stop): """Clear given flash range""" if stop < start: @@ -318,7 +318,7 @@ def read_device_type(self) -> bytes: return self._get(obj[0], obj[1], None) # Get uint32 as bytearray - def compare(self, addr_1, addr_2, lenght): + def compare(self, addr_1, addr_2, length): """ Takes two addresses and a length and compare the data. Raises IspCompareError if a mismatch is found. @@ -327,7 +327,7 @@ def compare(self, addr_1, addr_2, lenght): try: self.send("Compare Address 1", addr_1) self.send("Compare Address 2", addr_2) - self.send("Compare Length", lenght) + self.send("Compare Length", length) except IspSdoAbortedError as e: if e.str() == "COMPARE_ERROR": @@ -336,7 +336,7 @@ def compare(self, addr_1, addr_2, lenght): raise IspCompareError(offset) from e def flash_image(self, start, data): - logging.info("Data to be writen: %d Byte", len(data)) + logging.info("Data to be written: %d Byte", len(data)) block_size = 4096 @@ -347,7 +347,7 @@ def flash_image(self, start, data): # data must be multiple of block size # TODO add option for smaller block size - # Supporte are: 256, 512, 1024, 4096. + # Supported are: 256, 512, 1024, 4096. stuffing = len(data) % block_size @@ -355,12 +355,12 @@ def flash_image(self, start, data): logging.info("Date buffer is extended by %d", stuffing) data += b"\xff" * (block_size - stuffing) - logging.info("Data to be writen %d Bytes", len(data)) + logging.info("Data to be written %d Bytes", len(data)) logging.info("Start sector %d", start_sector) sectors = len(data) // block_size - assert (len(data) % block_size) == 0, "Need to erease extra sector to fit date: %d" % len(data) + assert (len(data) % block_size) == 0, "Need to erase extra sector to fit date: %d" % len(data) logging.info("Sectors to write %d", sectors) @@ -373,10 +373,10 @@ def flash_image(self, start, data): start_sector + sectors - 1, ) - # TODO: Add check if we need to erease block use Blank check sectors + # TODO: Add check if we need to erase block use Blank check sectors self.unlock() # Unlock writes self.prepare_flash_sectors(start_sector, start_sector + sectors - 1) - self.erase_flash_secotrs(start_sector, start_sector + sectors - 1) + self.erase_flash_sectors(start_sector, start_sector + sectors - 1) blocks = sectors @@ -404,9 +404,9 @@ def flash_image(self, start, data): # helper methods ########################################################## def fix_checksum(self, data): """ - This generate the checksum in the vectro table. - This is needed for the LPC11CXX und probebly all Cortex-M0. - and is normaly done somewhere in the swd programming chain. + This generate the checksum in the vector table. + This is needed for the LPC11CXX und probably all Cortex-M0. + and is normally done somewhere in the swd programming chain. For more info see: UM10398 26.3.3 Criterion for Valid User Code. """ # First 7 entries: diff --git a/lxa_iobus/network.py b/lxa_iobus/network.py index 8ff0ff7..e2c4403 100644 --- a/lxa_iobus/network.py +++ b/lxa_iobus/network.py @@ -276,8 +276,8 @@ async def lss_request(self, message, timeout=0.2): async def fast_scan_request(self, lss_id, bit_checked, lss_sub, lss_next): # TODO: check if we got the correct response - # FIXME: sleep wird gebraucht weil RX nicht clean ist. - # wir krigen Pakete vom der letzten anfrage + # FIXME: sleep is required because RX may not be clean + # and we may still get replies from the previous request. response = await self.lss_request( gen_lss_fast_scan_message(lss_id, bit_checked, lss_sub, lss_next), @@ -317,11 +317,11 @@ async def _fast_scan(self, start=None, mask=None): fast_scan_request: fast_scan_request method start: Start value for the LSS address (default: [0, 0, 0, 0]) mask: Only bits that are 0 are going to be tested. - (dafault: [0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff]) + (default: [0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff]) returns: None: No node could be selected - LSS Adress + LSS Address """ if start is None: @@ -366,7 +366,7 @@ async def _fast_scan(self, start=None, mask=None): # Final select if not await self.fast_scan_request(lss_id[3], 0, 3, 0): - logger.debug("fast_scan: Final round fail ") + logger.debug("fast_scan: Final round fail") return None diff --git a/lxa_iobus/node.py b/lxa_iobus/node.py index 5e21184..6f37112 100644 --- a/lxa_iobus/node.py +++ b/lxa_iobus/node.py @@ -193,12 +193,12 @@ async def sdo_read(self, index, sub_index, timeout=DEFAULT_TIMEOUT): async def sdo_write(self, index, sub_index, data, timeout=DEFAULT_TIMEOUT): async with self._lock: - # * normal(Segment) transfare > 4 byte: multiple transactions + # * normal(Segment) transfer > 4 byte: multiple transactions # * expedited <= 4 byte: one transaction if len(data) <= 4: ####################################### - # expedited transfare + # expedited transfer message = gen_sdo_initiate_download( node_id=self.node_id, index=index, @@ -229,10 +229,10 @@ async def sdo_write(self, index, sub_index, data, timeout=DEFAULT_TIMEOUT): return ######################################## - # Segment transfare + # Segment transfer transfer_size = len(data) - # Send the length of the transfare + # Send the length of the transfer message = gen_sdo_initiate_download( node_id=self.node_id, index=index, diff --git a/lxa_iobus/node_drivers.py b/lxa_iobus/node_drivers.py index f295acd..2c8f24d 100644 --- a/lxa_iobus/node_drivers.py +++ b/lxa_iobus/node_drivers.py @@ -21,7 +21,7 @@ async def read(self): async def write(self, value): if self.pin_type != "output": - raise RuntimeError("Attemped to write to an {} channel".format(self.pin_type)) + raise RuntimeError("Attempted to write to an {} channel".format(self.pin_type)) value = value << self.bit mask = 1 << self.bit @@ -63,7 +63,7 @@ def pins(self): class Iobus4Do3Di3AiDriver(NodeDriver): """LXA IOBus 4DO-3DI-3AI driver - The follwing pins are provided by this driver: + The following pins are provided by this driver: - OUT0-OUT3: Digital outputs - IN0-IN2: Digital inputs @@ -98,7 +98,7 @@ class PTXIOMuxDriver(NodeDriver): This board is deprecated by the 4DO-3DI-3AI and does not get any firmware upgrades. - The follwing pins are provided by this driver: + The following pins are provided by this driver: - OUT0-OUT3: Digital outputs - IN4-IN6: Digital inputs @@ -130,7 +130,7 @@ def _get_pins(self): class EthernetMuxDriver(NodeDriver): """LXA Ethernet-Mux node driver - The follwing pins are provided by this driver: + The following pins are provided by this driver: - SW: Switch between Ethernet port A and B - SW_EXT: Status of the GPIO override input diff --git a/lxa_iobus/server/server.py b/lxa_iobus/server/server.py index c73460a..054d28b 100644 --- a/lxa_iobus/server/server.py +++ b/lxa_iobus/server/server.py @@ -131,7 +131,7 @@ async def flash_worker(self): callback = partial(self.can_isp.write_flash, file_name) await self.loop.run_in_executor(None, callback) - self.can_isp.console_log("Reseting node") + self.can_isp.console_log("Resetting node") await self.loop.run_in_executor(None, self.can_isp.reset) self.can_isp.console_log("Flashing done") @@ -707,7 +707,7 @@ async def flush_state(self): def flush_state_sync(self, wait=True): self.rpc.worker_pool.run_sync(partial(self.rpc.notify, "state", pformat(self.state)), wait=wait) - async def flush_state_periodicly(self): + async def flush_state_periodically(self): while self._running: await self.flush_state() await asyncio.sleep(1)