crestron-swamp-controller 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crestron_swamp_controller-1.0.0/LICENSE +21 -0
- crestron_swamp_controller-1.0.0/PKG-INFO +297 -0
- crestron_swamp_controller-1.0.0/README.md +271 -0
- crestron_swamp_controller-1.0.0/crestron_swamp_controller.egg-info/PKG-INFO +297 -0
- crestron_swamp_controller-1.0.0/crestron_swamp_controller.egg-info/SOURCES.txt +42 -0
- crestron_swamp_controller-1.0.0/crestron_swamp_controller.egg-info/dependency_links.txt +1 -0
- crestron_swamp_controller-1.0.0/crestron_swamp_controller.egg-info/entry_points.txt +2 -0
- crestron_swamp_controller-1.0.0/crestron_swamp_controller.egg-info/requires.txt +6 -0
- crestron_swamp_controller-1.0.0/crestron_swamp_controller.egg-info/top_level.txt +1 -0
- crestron_swamp_controller-1.0.0/pyproject.toml +49 -0
- crestron_swamp_controller-1.0.0/setup.cfg +4 -0
- crestron_swamp_controller-1.0.0/swamp/__init__.py +0 -0
- crestron_swamp_controller-1.0.0/swamp/__main__.py +120 -0
- crestron_swamp_controller-1.0.0/swamp/core/__init__.py +0 -0
- crestron_swamp_controller-1.0.0/swamp/core/config_manager.py +36 -0
- crestron_swamp_controller-1.0.0/swamp/core/controller.py +120 -0
- crestron_swamp_controller-1.0.0/swamp/core/state_manager.py +87 -0
- crestron_swamp_controller-1.0.0/swamp/models/__init__.py +0 -0
- crestron_swamp_controller-1.0.0/swamp/models/commands.py +23 -0
- crestron_swamp_controller-1.0.0/swamp/models/config.py +31 -0
- crestron_swamp_controller-1.0.0/swamp/models/state.py +41 -0
- crestron_swamp_controller-1.0.0/swamp/network/__init__.py +0 -0
- crestron_swamp_controller-1.0.0/swamp/network/tcp_server.py +235 -0
- crestron_swamp_controller-1.0.0/swamp/protocol/__init__.py +0 -0
- crestron_swamp_controller-1.0.0/swamp/protocol/base.py +45 -0
- crestron_swamp_controller-1.0.0/swamp/protocol/swamp_protocol.py +312 -0
- crestron_swamp_controller-1.0.0/swamp/shell/__init__.py +0 -0
- crestron_swamp_controller-1.0.0/swamp/shell/commands.py +178 -0
- crestron_swamp_controller-1.0.0/swamp/shell/parser.py +36 -0
- crestron_swamp_controller-1.0.0/swamp/shell/repl.py +59 -0
- crestron_swamp_controller-1.0.0/tests/test_client_signon.py +84 -0
- crestron_swamp_controller-1.0.0/tests/test_connection_status.py +175 -0
- crestron_swamp_controller-1.0.0/tests/test_end_to_end.py +229 -0
- crestron_swamp_controller-1.0.0/tests/test_handshake.py +75 -0
- crestron_swamp_controller-1.0.0/tests/test_helpers.py +16 -0
- crestron_swamp_controller-1.0.0/tests/test_integration.py +117 -0
- crestron_swamp_controller-1.0.0/tests/test_join_update.py +86 -0
- crestron_swamp_controller-1.0.0/tests/test_magic_packets.py +212 -0
- crestron_swamp_controller-1.0.0/tests/test_pong.py +78 -0
- crestron_swamp_controller-1.0.0/tests/test_power_command_fix.py +195 -0
- crestron_swamp_controller-1.0.0/tests/test_serial_binary.py +257 -0
- crestron_swamp_controller-1.0.0/tests/test_serial_binary_encode.py +252 -0
- crestron_swamp_controller-1.0.0/tests/test_shutdown.py +114 -0
- crestron_swamp_controller-1.0.0/tests/test_zone_validity.py +241 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 jaroy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crestron-swamp-controller
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Interactive controller for Crestron SWAMP media amplifier systems
|
|
5
|
+
Author-email: jaroy <noreply@github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jaroy/swamp-controller
|
|
8
|
+
Project-URL: Documentation, https://github.com/jaroy/swamp-controller#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/jaroy/swamp-controller
|
|
10
|
+
Project-URL: Issues, https://github.com/jaroy/swamp-controller/issues
|
|
11
|
+
Keywords: crestron,swamp,home-assistant,audio,multi-zone
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Home Automation
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
21
|
+
Requires-Dist: prompt-toolkit>=3.0.43
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.4.3; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# SWAMP Controller
|
|
28
|
+
|
|
29
|
+
Interactive command-line controller for Crestron SWAMP media amplifier systems.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Interactive Shell**: User-friendly command prompt with autocomplete
|
|
34
|
+
- **TCP Server**: Listens for connections from SWAMP devices
|
|
35
|
+
- **State Management**: Maintains local state synchronized with device
|
|
36
|
+
- **Multi-zone Support**: Commands automatically broadcast to all zones in a target
|
|
37
|
+
- **Pluggable Protocol**: Protocol handler designed for easy extension
|
|
38
|
+
- **Home Assistant Integration**: Native HA integration with media player entities
|
|
39
|
+
|
|
40
|
+
## Home Assistant Integration
|
|
41
|
+
|
|
42
|
+
This project includes a **Home Assistant integration** that exposes your Crestron SWAMP system as media player entities in Home Assistant. Each target (room/zone) appears as a controllable media player with volume control, source selection, and power control.
|
|
43
|
+
|
|
44
|
+
### Installation via HACS (Recommended)
|
|
45
|
+
|
|
46
|
+
[](https://github.com/hacs/integration)
|
|
47
|
+
[](https://pypi.org/project/crestron-swamp-controller/)
|
|
48
|
+
|
|
49
|
+
1. Ensure [HACS](https://hacs.xyz/) is installed in your Home Assistant instance
|
|
50
|
+
2. Add this repository as a custom repository in HACS:
|
|
51
|
+
- Open HACS in Home Assistant
|
|
52
|
+
- Go to "Integrations"
|
|
53
|
+
- Click the three dots menu (top right) and select "Custom repositories"
|
|
54
|
+
- Add `https://github.com/jaroy/swamp-controller` as an Integration
|
|
55
|
+
- Click "Add"
|
|
56
|
+
3. Find "Crestron SWAMP Controller" in HACS and click "Download"
|
|
57
|
+
4. Restart Home Assistant
|
|
58
|
+
5. Add the integration through Settings > Devices & Services > Add Integration
|
|
59
|
+
|
|
60
|
+
The `crestron-swamp-controller` package will be automatically installed from PyPI when you add the integration.
|
|
61
|
+
|
|
62
|
+
See [HOMEASSISTANT.md](HOMEASSISTANT.md) for more detailed installation instructions and configuration options.
|
|
63
|
+
|
|
64
|
+
### Features
|
|
65
|
+
- Media player entity for each target/zone
|
|
66
|
+
- Real-time state updates from SWAMP device
|
|
67
|
+
- Volume control (0-100%)
|
|
68
|
+
- Source selection from configured sources
|
|
69
|
+
- Power on/off control
|
|
70
|
+
- Device availability tracking
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## CLI Installation
|
|
75
|
+
|
|
76
|
+
1. Ensure Python 3.12+ is installed
|
|
77
|
+
2. Create and activate virtual environment:
|
|
78
|
+
```bash
|
|
79
|
+
python -m venv .venv
|
|
80
|
+
source .venv/bin/activate # On Linux/Mac
|
|
81
|
+
# or
|
|
82
|
+
.venv\Scripts\activate # On Windows
|
|
83
|
+
```
|
|
84
|
+
3. Install dependencies:
|
|
85
|
+
```bash
|
|
86
|
+
pip install -r requirements.txt
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
Edit `config/config.yaml` to define your audio sources and target zones:
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
sources:
|
|
95
|
+
- id: music-a
|
|
96
|
+
name: Player A
|
|
97
|
+
swamp-source-id: 4
|
|
98
|
+
|
|
99
|
+
targets:
|
|
100
|
+
- id: office-terrace
|
|
101
|
+
name: Office Terrace
|
|
102
|
+
swamp-zones:
|
|
103
|
+
- unit: 3
|
|
104
|
+
zone: 1
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### On the SWAMP
|
|
108
|
+
We have to tell the SWAMP to connect to us instead of a Crestron processor.
|
|
109
|
+
Use these TELNET commands:
|
|
110
|
+
```
|
|
111
|
+
adds 51 <IP address> 4 <port>
|
|
112
|
+
reboot
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Note that you can see the currently configured controller with the `ipt` command:
|
|
116
|
+
```
|
|
117
|
+
$ telnet 192.168.1.89
|
|
118
|
+
Trying 192.168.1.89...
|
|
119
|
+
Connected to 192.168.1.89.
|
|
120
|
+
Escape character is '^]'.
|
|
121
|
+
|
|
122
|
+
SWAMP Control Console
|
|
123
|
+
Connected to Host: SWAMP-00107FE7C4CD
|
|
124
|
+
|
|
125
|
+
SWAMP>ipt
|
|
126
|
+
CIP_ID Type Status DevID Port IP Address/SiteName
|
|
127
|
+
51 GWAY ONLINE 4 41794 010.194.005.251
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Usage
|
|
131
|
+
|
|
132
|
+
Start the controller:
|
|
133
|
+
```bash
|
|
134
|
+
python -m swamp
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Or with custom port:
|
|
138
|
+
```bash
|
|
139
|
+
python -m swamp --port 41794
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Or with custom config:
|
|
143
|
+
```bash
|
|
144
|
+
python -m swamp --config /path/to/config.yaml
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Available Commands
|
|
148
|
+
|
|
149
|
+
Once the shell is running, you can use these commands:
|
|
150
|
+
|
|
151
|
+
### Route audio source to target
|
|
152
|
+
```
|
|
153
|
+
route <source-id> <target-id>
|
|
154
|
+
```
|
|
155
|
+
Example: `route music-a office`
|
|
156
|
+
|
|
157
|
+
### Set volume
|
|
158
|
+
```
|
|
159
|
+
volume <target-id> <level>
|
|
160
|
+
```
|
|
161
|
+
Example: `volume office 75`
|
|
162
|
+
|
|
163
|
+
### Adjust volume relatively
|
|
164
|
+
```
|
|
165
|
+
volume <target-id> +/-<delta>
|
|
166
|
+
```
|
|
167
|
+
Example: `volume office +10` or `volume office -5`
|
|
168
|
+
|
|
169
|
+
### Power control
|
|
170
|
+
```
|
|
171
|
+
power <target-id> on <source-id>
|
|
172
|
+
power <target-id> off
|
|
173
|
+
```
|
|
174
|
+
Power on requires a source (zones need a source to be "on"). Power off sets the source to 0.
|
|
175
|
+
|
|
176
|
+
Examples:
|
|
177
|
+
- `power office on music-a` - Power on office with music-a as source
|
|
178
|
+
- `power office off` - Power off office
|
|
179
|
+
|
|
180
|
+
### Show status
|
|
181
|
+
```
|
|
182
|
+
status [target-id]
|
|
183
|
+
```
|
|
184
|
+
Example: `status office` or `status` (shows all)
|
|
185
|
+
|
|
186
|
+
### Send WHOIS request
|
|
187
|
+
```
|
|
188
|
+
whois
|
|
189
|
+
```
|
|
190
|
+
Sends a WHOIS request (0f 00 01 02) to the connected SWAMP device. This is automatically sent when a device connects.
|
|
191
|
+
|
|
192
|
+
### List sources or targets
|
|
193
|
+
```
|
|
194
|
+
list sources
|
|
195
|
+
list targets
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Get help
|
|
199
|
+
```
|
|
200
|
+
help
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Exit
|
|
204
|
+
```
|
|
205
|
+
quit
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Architecture
|
|
209
|
+
The controller works by impersonating a Crestron processor gateway, e.g. a Crestron CP3. The client
|
|
210
|
+
is the SWAMP and it connects to our server which then establishes the communication link.
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
User Shell (REPL)
|
|
214
|
+
↓
|
|
215
|
+
Controller (orchestration)
|
|
216
|
+
↓
|
|
217
|
+
State Manager (zone/source mapping)
|
|
218
|
+
↓
|
|
219
|
+
Protocol Handler (pluggable)
|
|
220
|
+
↓
|
|
221
|
+
TCP Server (asyncio)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Components
|
|
225
|
+
|
|
226
|
+
- **Models**: Data classes for configuration and state
|
|
227
|
+
- **Core**: Configuration loading, state management, orchestration
|
|
228
|
+
- **Protocol**: Abstract protocol handler with stub implementation
|
|
229
|
+
- **Network**: Asyncio TCP server for SWAMP device connections
|
|
230
|
+
- **Shell**: Command parser and interactive REPL
|
|
231
|
+
|
|
232
|
+
## Protocol Implementation
|
|
233
|
+
The Protocol Handler partially implements the Crestron Internet Protocol (CIP), a proprietary protocol
|
|
234
|
+
for communication between Crestron devices. Only the message types for basic control of the SWAMP system
|
|
235
|
+
are implemented.
|
|
236
|
+
|
|
237
|
+
### Message Format
|
|
238
|
+
All CIP messages follow this format:
|
|
239
|
+
- **Byte 0**: Message type
|
|
240
|
+
- **Bytes 1-2**: Remaining length (total bytes - 3) in big-endian
|
|
241
|
+
- **Bytes 3+**: Payload
|
|
242
|
+
|
|
243
|
+
Example: `0a 00 0a 00 51 a3 42 40 02 00 00 00 00`
|
|
244
|
+
- Type: `0x0a` (CLIENT_SIGNON)
|
|
245
|
+
- Length: `0x00 0x0a` = 10 bytes remaining
|
|
246
|
+
- Payload: `00 51 a3 42 40 02 00 00 00 00` (10 bytes)
|
|
247
|
+
- Total: 1 + 2 + 10 = 13 bytes
|
|
248
|
+
|
|
249
|
+
### Implemented Messages
|
|
250
|
+
- **WHOIS** (`0f 00 01 02`) - Sent automatically when client connects, also available via `whois` command
|
|
251
|
+
- **PING** (`0d 00 02 00 00`) - Automatically detected and triggers PONG response. Sent periodically in the background.
|
|
252
|
+
- **PONG** (`0e 00 02 00 00`) - Sent automatically in response to PING
|
|
253
|
+
- **CLIENT_SIGNON** (`0a ...`) - Sent by device on connect, triggers CONN_ACCEPTED response
|
|
254
|
+
- **CONN_ACCEPTED** (`02 00 04 00 00 00 03`) - Sent automatically in response to CLIENT_SIGNON
|
|
255
|
+
- **JOIN** (`05 ...`) - The actual control messages for setting and getting information about the SWAMP
|
|
256
|
+
|
|
257
|
+
### Unknown Message Handling
|
|
258
|
+
Any message not recognized will be printed to the console in hex format, making it easy to discover and implement new message types.
|
|
259
|
+
|
|
260
|
+
Example output:
|
|
261
|
+
```
|
|
262
|
+
Unknown message type ff (4 bytes): ff aa bb cc
|
|
263
|
+
Recognized but unimplemented message type 0a (13 bytes): 0a 00 0a 00 51 a3 42 40 02 00 00 00 00
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Adding New Message Types
|
|
267
|
+
To add support for a new message type, edit `swamp/protocol/swamp_protocol.py`:
|
|
268
|
+
|
|
269
|
+
1. Add the message type to `decode_message()` dispatcher
|
|
270
|
+
2. Create a `_decode_message_type_XX()` method
|
|
271
|
+
3. Implement encoding methods if needed:
|
|
272
|
+
- `encode_route_command()` - Route audio source to zone
|
|
273
|
+
- `encode_volume_command()` - Set zone volume
|
|
274
|
+
- `encode_power_command()` - Control zone power
|
|
275
|
+
|
|
276
|
+
## Development
|
|
277
|
+
|
|
278
|
+
Run tests:
|
|
279
|
+
```bash
|
|
280
|
+
pytest
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
The test suite uses dynamic port allocation (via `get_free_port()`) to avoid conflicts with running instances of the controller.
|
|
284
|
+
|
|
285
|
+
Enable debug logging:
|
|
286
|
+
```bash
|
|
287
|
+
python -m swamp --log-level DEBUG
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Run on a different port:
|
|
291
|
+
```bash
|
|
292
|
+
python -m swamp --port 41795
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
Copyright © 2025
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# SWAMP Controller
|
|
2
|
+
|
|
3
|
+
Interactive command-line controller for Crestron SWAMP media amplifier systems.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Interactive Shell**: User-friendly command prompt with autocomplete
|
|
8
|
+
- **TCP Server**: Listens for connections from SWAMP devices
|
|
9
|
+
- **State Management**: Maintains local state synchronized with device
|
|
10
|
+
- **Multi-zone Support**: Commands automatically broadcast to all zones in a target
|
|
11
|
+
- **Pluggable Protocol**: Protocol handler designed for easy extension
|
|
12
|
+
- **Home Assistant Integration**: Native HA integration with media player entities
|
|
13
|
+
|
|
14
|
+
## Home Assistant Integration
|
|
15
|
+
|
|
16
|
+
This project includes a **Home Assistant integration** that exposes your Crestron SWAMP system as media player entities in Home Assistant. Each target (room/zone) appears as a controllable media player with volume control, source selection, and power control.
|
|
17
|
+
|
|
18
|
+
### Installation via HACS (Recommended)
|
|
19
|
+
|
|
20
|
+
[](https://github.com/hacs/integration)
|
|
21
|
+
[](https://pypi.org/project/crestron-swamp-controller/)
|
|
22
|
+
|
|
23
|
+
1. Ensure [HACS](https://hacs.xyz/) is installed in your Home Assistant instance
|
|
24
|
+
2. Add this repository as a custom repository in HACS:
|
|
25
|
+
- Open HACS in Home Assistant
|
|
26
|
+
- Go to "Integrations"
|
|
27
|
+
- Click the three dots menu (top right) and select "Custom repositories"
|
|
28
|
+
- Add `https://github.com/jaroy/swamp-controller` as an Integration
|
|
29
|
+
- Click "Add"
|
|
30
|
+
3. Find "Crestron SWAMP Controller" in HACS and click "Download"
|
|
31
|
+
4. Restart Home Assistant
|
|
32
|
+
5. Add the integration through Settings > Devices & Services > Add Integration
|
|
33
|
+
|
|
34
|
+
The `crestron-swamp-controller` package will be automatically installed from PyPI when you add the integration.
|
|
35
|
+
|
|
36
|
+
See [HOMEASSISTANT.md](HOMEASSISTANT.md) for more detailed installation instructions and configuration options.
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
- Media player entity for each target/zone
|
|
40
|
+
- Real-time state updates from SWAMP device
|
|
41
|
+
- Volume control (0-100%)
|
|
42
|
+
- Source selection from configured sources
|
|
43
|
+
- Power on/off control
|
|
44
|
+
- Device availability tracking
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## CLI Installation
|
|
49
|
+
|
|
50
|
+
1. Ensure Python 3.12+ is installed
|
|
51
|
+
2. Create and activate virtual environment:
|
|
52
|
+
```bash
|
|
53
|
+
python -m venv .venv
|
|
54
|
+
source .venv/bin/activate # On Linux/Mac
|
|
55
|
+
# or
|
|
56
|
+
.venv\Scripts\activate # On Windows
|
|
57
|
+
```
|
|
58
|
+
3. Install dependencies:
|
|
59
|
+
```bash
|
|
60
|
+
pip install -r requirements.txt
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
Edit `config/config.yaml` to define your audio sources and target zones:
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
sources:
|
|
69
|
+
- id: music-a
|
|
70
|
+
name: Player A
|
|
71
|
+
swamp-source-id: 4
|
|
72
|
+
|
|
73
|
+
targets:
|
|
74
|
+
- id: office-terrace
|
|
75
|
+
name: Office Terrace
|
|
76
|
+
swamp-zones:
|
|
77
|
+
- unit: 3
|
|
78
|
+
zone: 1
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### On the SWAMP
|
|
82
|
+
We have to tell the SWAMP to connect to us instead of a Crestron processor.
|
|
83
|
+
Use these TELNET commands:
|
|
84
|
+
```
|
|
85
|
+
adds 51 <IP address> 4 <port>
|
|
86
|
+
reboot
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Note that you can see the currently configured controller with the `ipt` command:
|
|
90
|
+
```
|
|
91
|
+
$ telnet 192.168.1.89
|
|
92
|
+
Trying 192.168.1.89...
|
|
93
|
+
Connected to 192.168.1.89.
|
|
94
|
+
Escape character is '^]'.
|
|
95
|
+
|
|
96
|
+
SWAMP Control Console
|
|
97
|
+
Connected to Host: SWAMP-00107FE7C4CD
|
|
98
|
+
|
|
99
|
+
SWAMP>ipt
|
|
100
|
+
CIP_ID Type Status DevID Port IP Address/SiteName
|
|
101
|
+
51 GWAY ONLINE 4 41794 010.194.005.251
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Usage
|
|
105
|
+
|
|
106
|
+
Start the controller:
|
|
107
|
+
```bash
|
|
108
|
+
python -m swamp
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Or with custom port:
|
|
112
|
+
```bash
|
|
113
|
+
python -m swamp --port 41794
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Or with custom config:
|
|
117
|
+
```bash
|
|
118
|
+
python -m swamp --config /path/to/config.yaml
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Available Commands
|
|
122
|
+
|
|
123
|
+
Once the shell is running, you can use these commands:
|
|
124
|
+
|
|
125
|
+
### Route audio source to target
|
|
126
|
+
```
|
|
127
|
+
route <source-id> <target-id>
|
|
128
|
+
```
|
|
129
|
+
Example: `route music-a office`
|
|
130
|
+
|
|
131
|
+
### Set volume
|
|
132
|
+
```
|
|
133
|
+
volume <target-id> <level>
|
|
134
|
+
```
|
|
135
|
+
Example: `volume office 75`
|
|
136
|
+
|
|
137
|
+
### Adjust volume relatively
|
|
138
|
+
```
|
|
139
|
+
volume <target-id> +/-<delta>
|
|
140
|
+
```
|
|
141
|
+
Example: `volume office +10` or `volume office -5`
|
|
142
|
+
|
|
143
|
+
### Power control
|
|
144
|
+
```
|
|
145
|
+
power <target-id> on <source-id>
|
|
146
|
+
power <target-id> off
|
|
147
|
+
```
|
|
148
|
+
Power on requires a source (zones need a source to be "on"). Power off sets the source to 0.
|
|
149
|
+
|
|
150
|
+
Examples:
|
|
151
|
+
- `power office on music-a` - Power on office with music-a as source
|
|
152
|
+
- `power office off` - Power off office
|
|
153
|
+
|
|
154
|
+
### Show status
|
|
155
|
+
```
|
|
156
|
+
status [target-id]
|
|
157
|
+
```
|
|
158
|
+
Example: `status office` or `status` (shows all)
|
|
159
|
+
|
|
160
|
+
### Send WHOIS request
|
|
161
|
+
```
|
|
162
|
+
whois
|
|
163
|
+
```
|
|
164
|
+
Sends a WHOIS request (0f 00 01 02) to the connected SWAMP device. This is automatically sent when a device connects.
|
|
165
|
+
|
|
166
|
+
### List sources or targets
|
|
167
|
+
```
|
|
168
|
+
list sources
|
|
169
|
+
list targets
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Get help
|
|
173
|
+
```
|
|
174
|
+
help
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Exit
|
|
178
|
+
```
|
|
179
|
+
quit
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Architecture
|
|
183
|
+
The controller works by impersonating a Crestron processor gateway, e.g. a Crestron CP3. The client
|
|
184
|
+
is the SWAMP and it connects to our server which then establishes the communication link.
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
User Shell (REPL)
|
|
188
|
+
↓
|
|
189
|
+
Controller (orchestration)
|
|
190
|
+
↓
|
|
191
|
+
State Manager (zone/source mapping)
|
|
192
|
+
↓
|
|
193
|
+
Protocol Handler (pluggable)
|
|
194
|
+
↓
|
|
195
|
+
TCP Server (asyncio)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Components
|
|
199
|
+
|
|
200
|
+
- **Models**: Data classes for configuration and state
|
|
201
|
+
- **Core**: Configuration loading, state management, orchestration
|
|
202
|
+
- **Protocol**: Abstract protocol handler with stub implementation
|
|
203
|
+
- **Network**: Asyncio TCP server for SWAMP device connections
|
|
204
|
+
- **Shell**: Command parser and interactive REPL
|
|
205
|
+
|
|
206
|
+
## Protocol Implementation
|
|
207
|
+
The Protocol Handler partially implements the Crestron Internet Protocol (CIP), a proprietary protocol
|
|
208
|
+
for communication between Crestron devices. Only the message types for basic control of the SWAMP system
|
|
209
|
+
are implemented.
|
|
210
|
+
|
|
211
|
+
### Message Format
|
|
212
|
+
All CIP messages follow this format:
|
|
213
|
+
- **Byte 0**: Message type
|
|
214
|
+
- **Bytes 1-2**: Remaining length (total bytes - 3) in big-endian
|
|
215
|
+
- **Bytes 3+**: Payload
|
|
216
|
+
|
|
217
|
+
Example: `0a 00 0a 00 51 a3 42 40 02 00 00 00 00`
|
|
218
|
+
- Type: `0x0a` (CLIENT_SIGNON)
|
|
219
|
+
- Length: `0x00 0x0a` = 10 bytes remaining
|
|
220
|
+
- Payload: `00 51 a3 42 40 02 00 00 00 00` (10 bytes)
|
|
221
|
+
- Total: 1 + 2 + 10 = 13 bytes
|
|
222
|
+
|
|
223
|
+
### Implemented Messages
|
|
224
|
+
- **WHOIS** (`0f 00 01 02`) - Sent automatically when client connects, also available via `whois` command
|
|
225
|
+
- **PING** (`0d 00 02 00 00`) - Automatically detected and triggers PONG response. Sent periodically in the background.
|
|
226
|
+
- **PONG** (`0e 00 02 00 00`) - Sent automatically in response to PING
|
|
227
|
+
- **CLIENT_SIGNON** (`0a ...`) - Sent by device on connect, triggers CONN_ACCEPTED response
|
|
228
|
+
- **CONN_ACCEPTED** (`02 00 04 00 00 00 03`) - Sent automatically in response to CLIENT_SIGNON
|
|
229
|
+
- **JOIN** (`05 ...`) - The actual control messages for setting and getting information about the SWAMP
|
|
230
|
+
|
|
231
|
+
### Unknown Message Handling
|
|
232
|
+
Any message not recognized will be printed to the console in hex format, making it easy to discover and implement new message types.
|
|
233
|
+
|
|
234
|
+
Example output:
|
|
235
|
+
```
|
|
236
|
+
Unknown message type ff (4 bytes): ff aa bb cc
|
|
237
|
+
Recognized but unimplemented message type 0a (13 bytes): 0a 00 0a 00 51 a3 42 40 02 00 00 00 00
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Adding New Message Types
|
|
241
|
+
To add support for a new message type, edit `swamp/protocol/swamp_protocol.py`:
|
|
242
|
+
|
|
243
|
+
1. Add the message type to `decode_message()` dispatcher
|
|
244
|
+
2. Create a `_decode_message_type_XX()` method
|
|
245
|
+
3. Implement encoding methods if needed:
|
|
246
|
+
- `encode_route_command()` - Route audio source to zone
|
|
247
|
+
- `encode_volume_command()` - Set zone volume
|
|
248
|
+
- `encode_power_command()` - Control zone power
|
|
249
|
+
|
|
250
|
+
## Development
|
|
251
|
+
|
|
252
|
+
Run tests:
|
|
253
|
+
```bash
|
|
254
|
+
pytest
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
The test suite uses dynamic port allocation (via `get_free_port()`) to avoid conflicts with running instances of the controller.
|
|
258
|
+
|
|
259
|
+
Enable debug logging:
|
|
260
|
+
```bash
|
|
261
|
+
python -m swamp --log-level DEBUG
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Run on a different port:
|
|
265
|
+
```bash
|
|
266
|
+
python -m swamp --port 41795
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
Copyright © 2025
|