Skip to content

[RTOP-69] implement base code to commands#9

Merged
lucasbutzke merged 38 commits into
developmentfrom
task/RTOP-69-Implement-command-compile/status
Sep 25, 2025
Merged

[RTOP-69] implement base code to commands#9
lucasbutzke merged 38 commits into
developmentfrom
task/RTOP-69-Implement-command-compile/status

Conversation

@lucasbutzke
Copy link
Copy Markdown
Contributor

@lucasbutzke lucasbutzke commented Sep 23, 2025

  1. run_compile() Function - Program Compilation

Compiles a program and manages the entire build process.

What it does:

Starts compilation: Executes a bash script (compile.sh)
Monitors progress: Shows real-time output and error messages
Manages build state: Tracks compiling/success/failed status
Handles system restart: Stops and starts the PLC controller after compilation
Performs cleanup: Runs a cleanup script (compile-clean.sh)
Step-by-step flow:

Sets status to "COMPILING"
Starts the compilation script
Creates threads to monitor process output
Waits for compilation to complete
If successful: stops PLC, runs cleanup, restarts PLC
If failed: shows error message

  1. handle_upload_file() Function - File Upload Handling

Receives a ZIP file, validates it, and extracts contents.

What it does:

Validations: Checks file safety (prevents zip bombs)
Preparation: Cleans old directory and extracts new ZIP
Initiates compilation: Calls compilation function in separate thread
Validation checks:

✅ Verifies no active compilation is running
✅ Confirms file exists in request
✅ Checks file size limits
✅ Analyzes ZIP safety
✅ Extracts only valid files

Complete Flow:
Upload ZIP → Validate → Clean folder → Extract → Compile → Stop PLC → Move file → Start PLC

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 23, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

Comment @coderabbitai help to get the list of available commands and usage tips.

@lucasbutzke lucasbutzke requested a review from Copilot September 24, 2025 12:16
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

Implements base code for PLC program management commands including compilation, file upload handling, and runtime process management. This replaces the legacy openplc.py system with a more robust architecture.

  • Introduces RuntimeManager class for managing PLC runtime processes with auto-restart capability
  • Implements secure ZIP file upload with safety validation and compilation pipeline
  • Refactors command handling to use modern patterns with proper error handling

Reviewed Changes

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

Show a summary per file
File Description
webserver/unixclient.py Adds STATUS command support to the Unix socket client
webserver/runtimemanager.py New runtime manager class for PLC process lifecycle management
webserver/plcapp_management.py New module for secure ZIP file handling and compilation management
webserver/app.py Refactors main application to use new runtime and compilation systems
webserver/openplc.py Removes legacy OpenPLC runtime implementation
webserver/credentials.py Removes default parameters from certificate generation method
test_api.py Removes existing API tests
conftest.py Removes test configuration file
scripts/compile.sh Moves cleanup operations to separate script
scripts/compile-clean.sh New cleanup script for post-compilation operations
install.sh Adds PLC application build step to installation
core/src/plc_app/utils/log.c Fixes socket logging implementation
core/src/plc_app/unix_socket.c Improves command handling and adds proper STATUS implementation
.pre-commit-config.yaml Adds comment explaining clang-format configuration
Comments suppressed due to low confidence (2)

webserver/plcapp_management.py:1

  • Variable client is not defined in this function scope. The run_compile function expects a SyncUnixClient parameter but no client is available here.
from dataclasses import dataclass, field

webserver/plcapp_management.py:1

  • The analyze_zip function expects a file path string but zip_file is a FileStorage object from Flask. Should save the file first and pass the path to analyze_zip.
from dataclasses import dataclass, field

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread webserver/app.py Outdated
Comment thread webserver/plcapp_management.py Outdated
Comment thread core/src/plc_app/utils/log.c Outdated
@lucasbutzke lucasbutzke changed the title [RTOP-49] implement base code to commands [RTOP-69] implement base code to commands Sep 24, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread core/src/plc_app/unix_socket.c Outdated
@lucasbutzke lucasbutzke merged commit 4b703c5 into development Sep 25, 2025
@lucasbutzke lucasbutzke deleted the task/RTOP-69-Implement-command-compile/status branch September 25, 2025 20:34
thiagoralves added a commit that referenced this pull request Mar 5, 2026
- Fix #2: Guard buffer mutex release after crash with a volatile flag
  (holding_buffer_mutex) to avoid undefined behavior when unlocking a
  mutex not owned by the calling thread

- Fix #3: Reset plc_crash_signal to 0 at the start of plc_cycle_thread
  so stale values don't persist after successful recovery

- Fix #4: Add plc_force_error_state() function for the watchdog to
  transition to ERROR state through the mutex instead of writing
  plc_state directly. Remove extern PLCState from watchdog.c

- Fix #5: Skip watchdog heartbeat check when already in ERROR state
  to prevent repeated error log spam every 2 seconds. Move heartbeat
  reset to the non-RUNNING branch so it happens once on ERROR entry

- Fix #6: Add trailing newline to plc_state_manager.h

- Fix #8: Add threading.Lock to protect _crash_times and _safe_mode
  in RuntimeManager against concurrent access from the monitor and
  compilation threads

- Fix #9: Rename _should_enter_safe_mode to
  _record_crash_and_check_safe_mode to make the side effect explicit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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