Skip to content

Rtop 106 create multiple addr access debug function#37

Merged
marconetsf merged 14 commits into
RTOP-100-OPC-UAfrom
RTOP-106-Create-multiple-addr-access-debug-function
Nov 26, 2025
Merged

Rtop 106 create multiple addr access debug function#37
marconetsf merged 14 commits into
RTOP-100-OPC-UAfrom
RTOP-106-Create-multiple-addr-access-debug-function

Conversation

@marconetsf
Copy link
Copy Markdown
Contributor

@marconetsf marconetsf commented Nov 21, 2025

This pull request introduces several enhancements and refactoring to the OpenPLC core and Python plugin infrastructure, focusing on improved buffer access, batch operation support, and clearer API definitions. The most significant changes include the addition of new utility functions for variable access in the C core, a comprehensive refactored Python buffer access API, and the implementation of a batch processor for efficient buffer operations. These updates aim to improve performance, maintain backward compatibility, and provide clearer extension points for plugin developers.

C Core Enhancements

Plugin variable access utilities:

  • Added new utility functions (get_var_list, get_var_size, get_var_count) in plugin_utils.c and exposed them via plugin_utils.h for structured variable access from plugins. These functions are now integrated into the plugin driver argument structure and initialization, enabling plugins to query variable addresses, sizes, and counts in a standardized way. [1] [2] [3] [4]
  • Updated CMakeLists.txt to include plugin_utils.c in the build, ensuring the new utilities are compiled and available.
  • Included necessary headers in plugin_driver.c and plugin_driver.h for the new utility functions and types. [1] [2]

Python Plugin System Refactoring

Shared components and API definition:

  • Refactored __init__.py in the shared Python plugin package to clarify its role, explicitly export the new SafeBufferAccess class, legacy compatibility types, configuration models, and extension interfaces. This makes the package structure clearer and easier to use for plugin authors.
  • Added a detailed API specification document (API_SPECIFICATION.md) for the SafeBufferAccess class, outlining all public methods, parameters, return types, error handling, thread safety, batch operation formats, and compatibility requirements. This serves as a contract for future refactoring and extension.

Batch operations support:

  • Introduced the BatchProcessor class in batch_processor.py, providing efficient batch read, write, and mixed operations for buffer access. The processor acquires the mutex only once per batch, improving performance for plugins that need to access multiple buffers simultaneously. It also includes validation and error handling for batch operations.

References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

@marconetsf marconetsf requested a review from Copilot November 21, 2025 13:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new debug function for accessing multiple variable addresses simultaneously, along with supporting functions for variable size retrieval and value manipulation. The implementation provides a Python API wrapper around C functions that enable batch retrieval of variable addresses from the debug system.

Key changes:

  • Added get_var_list function to retrieve multiple variable addresses in a single call
  • Implemented helper functions for variable size queries and type inference
  • Extended Python plugin interface with methods for reading/writing variable values based on size

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
core/src/drivers/plugins/python/shared/python_plugin_types.py Adds Python wrapper methods for the new debug API including get_var_list, get_var_size, get_var_value, set_var_value, and get_var_info
core/src/drivers/plugin_utils.h Declares C function prototypes for get_var_list and get_var_size
core/src/drivers/plugin_utils.c Implements wrapper functions that interface with the existing debug system
core/src/drivers/plugin_driver.h Extends the plugin runtime args structure with new function pointers
core/src/drivers/plugin_driver.c Initializes the new function pointers in the plugin args structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/drivers/plugin_utils.c Outdated
Comment thread core/src/drivers/plugins/python/shared/python_plugin_types.py Outdated
Comment thread core/src/drivers/plugins/python/shared/python_plugin_types.py
Comment thread core/src/drivers/plugins/python/shared/python_plugin_types.py
marconetsf and others added 3 commits November 21, 2025 14:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@marconetsf marconetsf requested a review from Copilot November 21, 2025 14:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/drivers/plugins/python/shared/python_plugin_types.py Outdated
Comment thread core/src/drivers/plugins/python/shared/python_plugin_types.py Outdated
marconetsf and others added 3 commits November 21, 2025 15:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Autonomy-Logic Autonomy-Logic deleted a comment from Copilot AI Nov 21, 2025
@marconetsf marconetsf requested a review from Copilot November 24, 2025 12:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/src/drivers/plugins/python/shared/debug_utils.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Autonomy-Logic Autonomy-Logic deleted a comment from Copilot AI Nov 24, 2025
@Autonomy-Logic Autonomy-Logic deleted a comment from Copilot AI Nov 24, 2025
Comment thread core/src/drivers/plugins/python/shared/debug_utils.py Outdated
Comment thread core/src/drivers/plugins/python/shared/debug_utils.py Outdated
Comment thread core/src/drivers/plugins/python/shared/debug_utils.py Outdated
Comment thread core/src/drivers/plugins/python/shared/debug_utils.py Outdated
Comment on lines +224 to +232
# Singleton instance
_buffer_types_instance = None

def get_buffer_types() -> BufferTypes:
"""Get the singleton BufferTypes instance"""
global _buffer_types_instance
if _buffer_types_instance is None:
_buffer_types_instance = BufferTypes()
return _buffer_types_instance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

é realmente necessário esta abordagem singleton? caso não forem mutáveis, usar algo como:

BUFFER_TYPES = {
'bool': BoolBufferType(),
'byte': ByteBufferType(),
# ...
}

@lucasbutzke
Copy link
Copy Markdown
Contributor

python_plugin_types.py não foi modificado neste RTOP mas ele é um arquivo GIGANTE, talvez separar em pequenos arquivos

@marconetsf
Copy link
Copy Markdown
Contributor Author

python_plugin_types.py não foi modificado neste RTOP mas ele é um arquivo GIGANTE, talvez separar em pequenos arquivos

O arquivo python_plugin_types.py será descontinuado, os novos arquivos adicionados em shared nesse commit são a substituição dele. Porém para evitar problemas e não afetar o desenvolvimento do runtime essa substituição será feita em um espaço de tempo reservado. PS: A retrocompatibilidade foi testada substituindo o import dos plugins de:

from shared.python_plugin_types import ( 
    SafeBufferAccess
)

Para

from shared import SafeBufferAccess

@marconetsf marconetsf marked this pull request as ready for review November 26, 2025 13:34
@marconetsf marconetsf merged commit d02b868 into RTOP-100-OPC-UA Nov 26, 2025
@marconetsf marconetsf deleted the RTOP-106-Create-multiple-addr-access-debug-function branch November 26, 2025 13:34
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.

3 participants