[RTOP-49] Implement base code to commands#4
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughInitializes a full runtime stack: C-based PLC core with plugin loading, timing, logging, watchdog, and a UNIX socket control server; a Flask REST API with JWT auth and a Unix-socket client; build/tooling (CMake, Docker, pre-commit), scripts, and tests. Adds configs, types, and executable entry point. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User/Client
participant F as Flask REST API
participant Q as Command Queue
participant AC as Async Unix Client
participant US as Unix Socket Server
participant SM as PLC State Manager
participant PM as Plugin Manager
rect rgba(220,235,255,0.4)
U->>F: HTTPS GET/POST (e.g., start-plc)
F->>Q: enqueue("START")
note right of F: JWT-authenticated routes
end
par Client Worker
F->>AC: start_unix_socket_client()
AC->>US: Connect /run/runtime/plc_runtime.socket
loop While commands
AC->>Q: dequeue()
AC->>US: SEND: START/STOP/PING
US-->>AC: RESP: START:OK/ERROR
end
and Runtime Control
US->>SM: handle command
alt START
SM->>PM: load plugin, init symbols
SM->>SM: start cycle thread
else STOP
SM->>SM: stop cycle thread
SM->>PM: unload plugin
else PING/STATUS
SM-->>US: status
end
end
sequenceDiagram
participant CT as Cycle Thread
participant TM as Timing Manager
participant WG as Watchdog
CT->>TM: scan_cycle_time_start()
CT->>CT: ext_config_run__(tick++)
CT->>CT: ext_updateTime()
CT->>TM: scan_cycle_time_end()
CT->>CT: sleep_until(next_tick)
WG-->>WG: Check heartbeat periodically
WG->>WG: Exit on stall
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
…hub.com/Autonomy-Logic/openplc-runtime into RTOP-49-Implement-base-code-to-Commands
This change migrates the certificate generation from the Python Cryptography library to OpenSSL CLI commands, following the same approach as PR #4 in the OpenPLC_v3 repository. Key changes: - Replaced credentials.py to use subprocess calls to OpenSSL instead of cryptography library - Upgraded from RSA 2048-bit to 4096-bit keys for enhanced security - Increased certificate validity from 365 days to 36500 days (~100 years) - Removed cryptography dependency from requirements.txt - Added platform detection to app.py: HTTPS on Linux, HTTP on other platforms - Maintained same CertGen class interface for backward compatibility Benefits: - OpenSSL is universally available on Linux systems - No complex Python library dependencies - Stronger security with 4096-bit keys - Cross-platform compatibility with HTTP fallback for non-Linux systems Implements the same changes as: - OpenPLC_v3 PR #4: Autonomy-Logic/OpenPLC_v3#4 - Commits: 1b82973, b3a1e65 Requested by: Thiago Alves (@thiagoralves) Devin run: https://app.devin.ai/sessions/7734798dc74e4823ab03bc8402ba6cfa Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
- 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>
Summary by CodeRabbit
New Features
Chores
Tests
Documentation