Skip to content

Commit

Permalink
CI: add and run codespell
Browse files Browse the repository at this point in the history
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 <l.goehrs@pengutronix.de>
  • Loading branch information
hnez committed Mar 13, 2024
1 parent 94864ba commit eb8a0d0
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 59 deletions.
2 changes: 2 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[codespell]
skip = ./.git,./build,./venv,./lxa_iobus.egg-info,./lxa_iobus/server/static/lib
12 changes: 12 additions & 0 deletions .github/workflows/codespell.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion bin/lxa-iobus-lpc11xxcanisp-invoke
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import canopen


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
Expand Down
32 changes: 16 additions & 16 deletions bin/lxa-iobus-lpc11xxcanisp-program
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -254,22 +254,22 @@ 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.
"""
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)

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

Expand All @@ -280,28 +280,28 @@ 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)

if start_sector + sectors > 8:
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

Expand All @@ -324,14 +324,14 @@ 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.
"""

size = 4 * 7
vector_table = data[0:size] # First 7 entrys
vector_table = data[0:size] # First 7 entries
vector_table = struct.unpack("iiiiiii", vector_table)

checksum = 0 - (sum(vector_table))
Expand Down
2 changes: 1 addition & 1 deletion bin/lxa-iobus-server
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 3 additions & 3 deletions doc/source/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://en.wikipedia.org/wiki/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.
8 changes: 4 additions & 4 deletions doc/source/can_canopen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions doc/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion doc/source/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions lxa_iobus/canopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions lxa_iobus/lpc11xxcanisp/can_isp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -217,7 +217,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)
Expand Down Expand Up @@ -259,12 +259,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:
Expand Down Expand Up @@ -319,7 +319,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.
Expand All @@ -328,7 +328,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":
Expand All @@ -337,7 +337,7 @@ def compare(self, addr_1, addr_2, lenght):
raise IspCompareError(offset)

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

Expand All @@ -348,20 +348,20 @@ 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

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)

Expand All @@ -374,10 +374,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

Expand Down Expand Up @@ -406,9 +406,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.
"""

Expand Down
10 changes: 5 additions & 5 deletions lxa_iobus/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,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),
Expand Down Expand Up @@ -313,11 +313,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:
Expand Down Expand Up @@ -362,7 +362,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

Expand Down
Loading

0 comments on commit eb8a0d0

Please sign in to comment.