Skip to content

Commit d682be5

Browse files
Copilotemiltin
andcommitted
Add documentation for TLCProxy functionality
Co-authored-by: emiltin <[email protected]>
1 parent 7b69e69 commit d682be5

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

documentation/classes_and_modules.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Super Site - - include Components
1010
Proxy - - include Logging, Wait
1111
/ \
1212
SupervisorProxy SiteProxy - - include Components, SiteProxyWait
13+
\
14+
TrafficLightControllerProxy
1315
```
1416

1517
## Modules
@@ -49,6 +51,12 @@ A proxy also has a repaating async timer task for handling watchdog and acknowle
4951

5052
Proxy has to child classes: SiteProxy and SupervisorProxy.
5153

54+
### SiteProxy
55+
A SiteProxy represents a connection from a Supervisor to a remote Site. It provides methods for sending commands and requesting status from the connected site.
56+
57+
### TrafficLightControllerProxy
58+
A TrafficLightControllerProxy is a specialized SiteProxy for Traffic Light Controller (TLC) sites. It provides high-level methods for common TLC operations like setting signal plans and fetching current plan status. The supervisor automatically creates TLCProxy instances when TLC sites connect (based on the site configuration having `sxl: 'tlc'`).
59+
5260
### SiteProxy
5361
A connection to a remote Site.
5462

documentation/tlc_proxy.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# TLC Proxy
2+
3+
## Overview
4+
5+
The `RSMP::TLC::TrafficLightControllerProxy` is a specialized proxy class for handling communication with remote Traffic Light Controller (TLC) sites. It extends the base `SiteProxy` class to provide high-level methods for common TLC operations.
6+
7+
## Features
8+
9+
The TLC proxy provides convenient methods that abstract away the low-level RSMP message handling for common TLC operations:
10+
11+
### Signal Plan Management
12+
13+
- **`set_plan(plan_nr, security_code:, options: {})`** - Sets the active signal plan using M0002 command
14+
- **`fetch_signal_plan(options: {})`** - Retrieves current signal plan information using S0014 status request
15+
16+
## Automatic Detection
17+
18+
When a TLC site connects to a supervisor, the supervisor automatically detects that it's a TLC based on the site configuration (`sxl: 'tlc'`) and creates a `TrafficLightControllerProxy` instead of a generic `SiteProxy`.
19+
20+
This happens in the supervisor's connection handling:
21+
22+
```ruby
23+
# In supervisor configuration
24+
supervisor_settings = {
25+
'sites' => {
26+
'TLC001' => { 'sxl' => 'tlc' }
27+
},
28+
'guest' => { 'sxl' => 'tlc' } # For unknown TLC sites
29+
}
30+
31+
# When TLC001 connects, supervisor creates TLCProxy automatically
32+
tlc_proxy = supervisor.wait_for_site('TLC001')
33+
# tlc_proxy is now an instance of TrafficLightControllerProxy
34+
```
35+
36+
## Usage Examples
37+
38+
### Setting a Signal Plan
39+
40+
```ruby
41+
# Set signal plan 3 with security code
42+
result = tlc_proxy.set_plan(3, security_code: '2222')
43+
44+
# Set plan and collect the response
45+
result = tlc_proxy.set_plan(2,
46+
security_code: '2222',
47+
options: { collect: { timeout: 5 } }
48+
)
49+
50+
# Check if command was successful
51+
if result[:collector].ok?
52+
puts "Signal plan changed successfully"
53+
else
54+
puts "Failed to change signal plan"
55+
end
56+
```
57+
58+
### Fetching Current Signal Plan
59+
60+
```ruby
61+
# Get current signal plan information
62+
result = tlc_proxy.fetch_signal_plan(collect: { timeout: 5 })
63+
64+
if result[:collector].ok?
65+
response = result[:collector].messages.first
66+
status_items = response.attribute('sS')
67+
68+
# Find current plan and source
69+
current_plan = status_items.find { |item| item['n'] == 'status' }['s']
70+
plan_source = status_items.find { |item| item['n'] == 'source' }['s']
71+
72+
puts "Current signal plan: #{current_plan} (source: #{plan_source})"
73+
end
74+
```
75+
76+
### Error Handling
77+
78+
```ruby
79+
begin
80+
result = tlc_proxy.set_plan(5, security_code: 'wrong_code')
81+
rescue RSMP::NotReady
82+
puts "TLC is not ready for commands"
83+
rescue RSMP::MessageRejected => e
84+
puts "Command rejected: #{e.message}"
85+
end
86+
```
87+
88+
## RSMP Message Details
89+
90+
### M0002 - Set Signal Plan
91+
92+
The `set_plan` method sends an M0002 command with the following parameters:
93+
94+
- `status`: "True" (activate the plan)
95+
- `securityCode`: The provided security code
96+
- `timeplan`: The signal plan number
97+
98+
### S0014 - Signal Plan Status
99+
100+
The `fetch_signal_plan` method requests S0014 status with:
101+
102+
- `status`: Current active signal plan number
103+
- `source`: Source of the current plan (e.g., "forced", "startup", "clock")
104+
105+
## Integration with Existing Code
106+
107+
The TLC proxy seamlessly integrates with existing RSMP infrastructure:
108+
109+
- Inherits all base functionality from `SiteProxy`
110+
- Uses existing message sending and collection mechanisms
111+
- Works with existing logging and error handling
112+
- Compatible with all existing proxy configuration options
113+
114+
## Testing
115+
116+
Comprehensive tests are included:
117+
118+
- Unit tests for method behavior and parameter validation
119+
- Integration tests with real TLC site connections
120+
- Error handling and edge case testing
121+
- Supervisor proxy creation testing
122+
123+
## Implementation Notes
124+
125+
- The TLC proxy automatically finds the main TLC component (grouped component)
126+
- All security and validation is handled by the underlying TLC site implementation
127+
- The proxy provides a cleaner API while maintaining full RSMP protocol compliance
128+
- Thread-safe and async-compatible with the rest of the RSMP framework

0 commit comments

Comments
 (0)