Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups, code deduplication, improvements and maintenance #38

Merged
merged 19 commits into from
Mar 22, 2024

Conversation

hnez
Copy link
Member

@hnez hnez commented Mar 14, 2024

Just like the diffuse PR title implies this is a collection of changes that I have accumulated while working on the LXA Optick support, which itself is added in another pull request.

TODO before merging:

@hnez hnez force-pushed the maintenance branch 7 times, most recently from 8dbe76e to e0ded51 Compare March 18, 2024 14:06
@hnez hnez marked this pull request as ready for review March 18, 2024 14:06
@hnez hnez force-pushed the maintenance branch 2 times, most recently from b4c8cae to 257e5f5 Compare March 20, 2024 11:59
@SmithChart
Copy link
Member

#36 and #37 have been merged. Please rebase and resolve conflicts.

@hnez
Copy link
Member Author

hnez commented Mar 20, 2024

I've rebased on top of recent master and tested this pull request with a couple of LXA Ethernet Muxes (because I did not test those previously).
Seems to work fine.

@SmithChart
Copy link
Member

In commit "lxa_iobus: node: replace ad-hoc struct parsing with central object_directory":

Previously unpacking and packing structs to send to the node was done
always done ad-hoc, where it was needed.

Sounds like there is one done too much there.

Copy link
Member

@SmithChart SmithChart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite a large change-set. For what I can tell most looks good.

@hnez Thanks for testing. Once my two comments have been resolved we can get this merged.

lxa_iobus/object_directory.py Outdated Show resolved Hide resolved
hnez added 12 commits March 21, 2024 15:52
The _sdo_queues dict ist only written to, but never used.

Signed-off-by: Leonard Göhrs <[email protected]>
The try: except: block must have been intended to catch the case
where node_id is not in self.nodes (since set_sdo_response does not do any
relevant indexing), but since the access is only done after checking
if the dict contains node_id this is redunant.

Remove the block.

Signed-off-by: Leonard Göhrs <[email protected]>
Before this any consumer of the node list had to know that node 125
is special (because it does not behave like the others and is most likely
not even present).

Instead make the isp node special by not adding it to the node list at all.

Signed-off-by: Leonard Göhrs <[email protected]>
This improves the usecase where the Network class should be used outside
of the server (e.g. in the flashing commandline utils or when using
lxa_iobus as a library), because it means that e.g. await_interface_is_up()
can be used before run() got around to setting the _interface_state.

Signed-off-by: Leonard Göhrs <[email protected]>
This means we do not have to spawn two extra threads and can instead
stay in async land.

The `if True:` is only there to separate the formatting change from
the code change and will be removed in a followup commit.

Signed-off-by: Leonard Göhrs <[email protected]>
…mmit

No actual code change, just a reduction of indentation level.

Signed-off-by: Leonard Göhrs <[email protected]>
Filesystem access is generally a blocking operation and some low latency
or high performance software needs to take that into account.
We are neither. The single connect client can likely accept the
millisecond latency spike when the lss cache file is written to
disk whenever a not previously seen node is connected for the first time.

The `if True:` is only there to separate the formatting change from
the code change and will be removed in a followup commit.

Signed-off-by: Leonard Göhrs <[email protected]>
…mmit

No actual code change, just a reduction of indentation level.

Signed-off-by: Leonard Göhrs <[email protected]>
…rectory

Previously unpacking and packing structs to send to the node was always
done ad-hoc, where it was needed.
This required a deep knowledge of the different IOBus protocols whenever
any of the node handling code should be changed and made it difficult
to use lxa_iobus as a library outside of the server, because there was
no complete documentation of IOBus CANopen endpoints.

Centralize the IOBus protocol handling in a single object_directory.py
file.

This also changes the way IOBus protocols on nodes are enumerated.
Now any node that advertises support for a specific protocol will appear
in the web interface with a list of inputs/outputs/adcs it has and
not just as an empty dummy node.

This change also removes the notion of a "Node Driver".
A node is just a collection of the IOBus protocols / CANopen endpoints
it supports. The drivers only served to give the inputs and outputs
and the node itself human readable and descriptive names.

This is now done in a list of products in products.py.
A node can however be perfectly usable without appearing in the products
list, and will just use default names for all inputs and outputs.

Signed-off-by: Leonard Göhrs <[email protected]>
hnez added 6 commits March 21, 2024 16:04
Previously a node could be accessed via e.g. the API before it was
fully set up (e.g. before the supported protocols were enumerated).
This looked a bit weird in the web interface but did not do serious
harm because enumartion usually happened quite fast.

Completely prevent the half-initialized nodes from appearing in the web
interface so that the presented state is always consistent,
by only adding the node to the list once it is fully set up.

Signed-off-by: Leonard Göhrs <[email protected]>
This can e.g. happen if a node was assumed to be unavailable but
actually only needed a really long time to respond.
In practice this should not happen, which means we want to want to
be informed about it even more.

Signed-off-by: Leonard Göhrs <[email protected]>
…here

When specifying a struct format without a "@,=,<,>!" prefix python will
default to native struct encoding with native byte order, alignment and
sizes. Which is what we want if the native byte order is little endian,
the alignment is "close enough" and the sizes are not crazy.

This did not seam to affect anyone yet, because we do not rely on alignment
to much and most systems are little endian and not crazy.

But we should not rely on that and explicity state the format we want
so the one person with a big endian MIPS box can use the IOBus server.

Signed-off-by: Leonard Göhrs <[email protected]>
The CanIsp class has gone through a few iterations as a commandline
tool using the external canopen library before it was included in the
server and used the lxa_iobus intenal async canopen implementation.
This is why it stayed non-async until now, making integration with the
rest of the IOBus server cumbersome.

Make CanIsp async-native.

Signed-off-by: Leonard Göhrs <[email protected]>
…iobus

We already have a perfectly working implementation of a CANopen bus
and node handling, so we can de-duplicate the code we use in the
commandline utils and reduce our reliance on the external canopen library.

Signed-off-by: Leonard Göhrs <[email protected]>
We already have a firmware flashing implementation in the LXA IOBus server,
so we do not have to duplicate it again in the commandline tool.

Signed-off-by: Leonard Göhrs <[email protected]>
@hnez
Copy link
Member Author

hnez commented Mar 21, 2024

In commit "lxa_iobus: node: replace ad-hoc struct parsing with central object_directory":

Previously unpacking and packing structs to send to the node was done
always done ad-hoc, where it was needed.

Sounds like there is one done too much there.

Good catch, should be fixed.

Copy link
Member

@SmithChart SmithChart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@SmithChart SmithChart merged commit e6de255 into linux-automation:master Mar 22, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants