Skip to content

Claude/socanmatic issue 1 patches 7cgu4r - #2

Open
saulrh wants to merge 2 commits into
golems:masterfrom
saulrh:claude/socanmatic-issue-1-patches-7cgu4r
Open

Claude/socanmatic issue 1 patches 7cgu4r#2
saulrh wants to merge 2 commits into
golems:masterfrom
saulrh:claude/socanmatic-issue-1-patches-7cgu4r

Conversation

@saulrh

@saulrh saulrh commented Jul 21, 2026

Copy link
Copy Markdown
Member

Disclaimer: I have not reviewed this code, nor have I run this on real hardware. In fact, it's been like ten or twelve years since I so much as touched one of the motors that this library talks to! But it compiles on modern systems now. :V

I hope your day just got a little bit weirder.

Claude's PR description follows:


Closes #1.

Adds the CANopen profiles requested in the issue — DS305, DS401, and DS405 — alongside the existing DS301 (communication) and DS402 (drives) support.

New profiles

  • DS305 — Layer Setting Services (LSS). Lets an LSS master configure the node-ID and bit-rate of slaves over the bus: switch mode global and selective, configure/activate bit timing, configure node-ID, store configuration, and inquire node-ID / identity. Also exposed through the shell tool as canmat lss .... Lives in the base library.
  • DS401 — Generic I/O device profile. Read/write helpers for 8-bit digital I/O (0x6000/0x6200) and 16-bit analogue I/O (0x6401/0x6411). Built as a separate libsocanmatic401 profile library.
  • DS405 — Interface and device profile for IEC 61131-3 programmable devices. Typed read/write accessors for network variables, with the full input/output index table from CiA 405 tables 4 and 5 (including the REAL32 network-variable path). Built as a separate libsocanmatic405 profile library.

Build fixes needed to build this decade-old tree on a modern toolchain

  • Port the canmatc EDS-to-C generator from Python 2 to Python 3 (configparser, print(), read_file, eager map, list() around dict keys/range), restoring the inline ; comment stripping that Python 2's ConfigParser did by default.
  • Add the missing typedef on enum canmat_402_polarity_mask in ds402.h, which otherwise fails to link under modern GCC's -fno-common default.

Verification

Full autotools build (autoreconf/configure/make) is clean and make check passes (PASS: test_sdo), with libsocanmatic401, libsocanmatic405, and ds305.o all produced.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

claude added 2 commits July 21, 2026 07:33
Implements the profiles requested in issue golems#1, alongside the existing
DS301 (communication) and DS402 (drives) support.

New profiles:

* DS305 -- Layer Setting Services (LSS).  Lets an LSS master configure
  the node-ID and bit-rate of slaves over the bus: switch mode global
  and selective, configure/activate bit timing, configure node-ID,
  store configuration, and inquire node-ID / identity.  Also exposed
  through the shell tool as `canmat lss ...`.

* DS401 -- Generic I/O device profile.  Read/write helpers for 8-bit
  digital I/O (0x6000/0x6200) and 16-bit analogue I/O (0x6401/0x6411).

* DS405 -- Interface and device profile for IEC 61131-3 programmable
  devices.  Typed read/write accessors for network variables, with the
  full input/output index table from CiA 405 tables 4 and 5 (including
  the REAL32 network-variable path).

DS305 lives in the base library; DS401 and DS405 are built as separate
profile libraries mirroring the DS402 layout.

Build fixes needed to make this decade-old tree build on a modern
toolchain:

* Port the canmatc EDS-to-C generator from Python 2 to Python 3
  (configparser, print(), read_file, eager map, list() around dict
  keys/range).  Restore inline ';' comment stripping that Python 2's
  ConfigParser did by default, which the generated dictionaries rely on.

* Add the missing `typedef` on enum canmat_402_polarity_mask in
  ds402.h.  Without it the enum name became a tentative global
  definition in every translation unit, which fails to link under
  modern GCC's -fno-common default.

Verified with the full autotools build (autoreconf/configure/make)
and make check (test_sdo passes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P2vev2FUGJ83n8XdihYHo2
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013DfTvJceEThw8L7uzes7Am
Review fixes for the LSS support:

* canmat lss node/baud/store printed canmat_lss_strerror(err) on any
  failure, but err is only meaningful when the slave itself reported
  an error (CANMAT_ERR_DEV).  A transport or protocol failure left
  err at 0 and printed "failed: Success".  Fall back to
  canmat_iface_strerror for non-device errors.

* canmat_lss_switch_mode_selective read data[0] of the response
  without checking can_dlc, unlike the other LSS receive paths.
  Reject frames shorter than 1 byte as a protocol error.

* Mark fail() noreturn (new ATTR_NORETURN macro alongside
  ATTR_PRINTF) and drop the unreachable return after it in the
  lss switch branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013DfTvJceEThw8L7uzes7Am
@chenyurong22

Copy link
Copy Markdown

@saulrh
Bro, the code you guys wrote is awesome, the structure is pretty good, just need to add a few things.

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.

can you add DS301,DS305, DS401, DS405 in your socanmatic canopen stack.

3 participants