8000 GitHub - helloninglei/profinet: Minimal Profinet implementation in Python · GitHub
[go: up one dir, main page]

Skip to content

helloninglei/profinet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Profinet C Implementation

This is a complete C language refactoring of the original Python Profinet network administration tool. The program enables communication with Profinet industrial devices through the Discovery and Configuration Protocol (DCP) and RPC mechanisms.

Building the Project

To compile the project, use the provided Makefile:

make

This will create the executable in the bin/ directory.

Build Options

  • make all - Build the project (default)
  • make debug - Build with debug flags and sanitizers
  • make clean - Remove build artifacts
  • make install - Install to /usr/local/bin
  • make test - Run tests (placeholder for future implementation)

Usage

The C implementation maintains the same command-line interface as the original Python version:

./bin/profinet -i <INTERFACE> <action> [arguments]

Available Actions

  • discover - Discover Profinet devices on the network
  • get-param <MAC> <param> - Get device parameter
  • set-param <MAC> <param> <value> - Set device parameter
  • read <MAC> <api> <slot> <subslot> <idx> - Read data from device
  • read-inm0-filter <MAC> - Read I&M0 filter data
  • read-inm0 <MAC> <api> <slot> <subslot> - Read I&M0 data
  • read-inm1 <MAC> <api> <slot> <subslot> - Read I&M1 data
  • write-inm1 <MAC> <api> <slot> <subslot> <tag> - Write I&M1 data

Examples

# Discover devices
./bin/profinet -i eth0 discover

# Get station name
./bin/profinet -i eth0 get-param 00:11:22:33:44:55 name

# Set station name
./bin/profinet -i eth0 set-param 00:11:22:33:44:55 name "NewStationName"

# Read I&M0 data
./bin/profinet -i eth0 read-inm0 00:11:22:33:44:55 0 0 0

Architecture

The C implementation follows a modular architecture similar to the original Python version:

Core Modules

  • profinet.h - Core definitions and structures
  • protocol.h - Profinet protocol packet structures (DCP, RPC, IOD)
  • util.h/c - Utility functions for networking, MAC/IP conversion
  • dcp.h/c - Discovery and Configuration Protocol implementation
  • rpc.h/c - RPC communication implementation
  • main.c - CLI interface and main program logic

Key Differences from Python Version

  1. Memory Management: Manual allocation/deallocation for all data structures
  2. Error Handling: Structured error codes instead of Python exceptions
  3. Packet Construction: Manual byte-level packet assembly instead of Python's automatic serialization
  4. Socket Operations: Direct use of Linux socket APIs
  5. Command Line Parsing: Manual parsing instead of Python's argparse

Error Handling

The implementation uses a structured error handling approach with defined error codes:

  • PROFINET_SUCCESS - Operation completed successfully
  • PROFINET_ERROR_SOCKET - Socket creation/operation failed
  • PROFINET_ERROR_BIND - Socket bind failed
  • PROFINET_ERROR_SEND - Data send failed
  • PROFINET_ERROR_RECV - Data receive failed
  • PROFINET_ERROR_TIMEOUT - Operation timed out
  • PROFINET_ERROR_INVALID_PARAM - Invalid parameter provided
  • PROFINET_ERROR_MEMORY - Memory allocation failed
  • PROFINET_ERROR_IOCTL - System ioctl operation failed

Platform Compatibility

This implementation targets Linux systems and uses Linux-specific socket operations (AF_PACKET, ioctl for MAC address retrieval). For other platforms, the socket and interface handling code would need to be adapted.

Requirements

  • GCC compiler with C99 support
  • Linux operating system
  • Network interface with raw socket permissions (typically requires root privileges)

Limitations

  • Some advanced RPC features are implemented as placeholders
  • Web GUI component from the original Python version is not included
  • Error reporting could be more detailed for better troubleshooting
  • Comprehensive test suite is not yet implemented

About

Minimal Profinet implementation in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C 65.7%
  • Python 28.4%
  • HTML 3.8%
  • Makefile 2.1%
0