-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
145 lines (122 loc) · 4.6 KB
/
Copy pathmain.py
File metadata and controls
145 lines (122 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python3
"""
Lab Recorder Python - Main Entry Point
A cross-platform Python implementation of Lab Streaming Layer (LSL) recorder
with remote control capabilities.
"""
import sys
import time
import argparse
from labrecorder import LabRecorder
def main():
"""Main entry point for Lab Recorder."""
# Parse command line arguments
parser = argparse.ArgumentParser(
description='Lab Streaming Layer (LSL) Recorder',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
%(prog)s # Start with default settings
%(prog)s -f my_recording.xdf # Specify output filename
%(prog)s --no-remote # Disable remote control
%(prog)s -p 12345 # Use custom remote control port
%(prog)s --config config.json # Use configuration file
"""
)
parser.add_argument(
'--filename', '-f',
default="recording.xdf",
help='Output XDF filename (default: recording.xdf)'
)
parser.add_argument(
'--remote-control', '-r',
action='store_true',
default=True,
help='Enable remote control interface (default: enabled)'
)
parser.add_argument(
'--port', '-p',
type=int,
default=22345,
help='Remote control port (default: 22345)'
)
parser.add_argument(
'--no-remote',
action='store_true',
help='Disable remote control interface'
)
parser.add_argument(
'--config', '-c',
help='Configuration file path'
)
args = parser.parse_args()
# Determine remote control setting
enable_remote = args.remote_control and not args.no_remote
# Create recorder instance
recorder = LabRecorder(
filename=args.filename,
enable_remote_control=enable_remote,
remote_control_port=args.port,
config_file=args.config
)
try:
print("=== Lab Recorder Python ===")
print(f"Output file: {args.filename}")
# Start remote control server if enabled
if enable_remote:
if recorder.start_remote_control_server():
print(f"Remote control enabled on port {args.port}")
print("Commands: select all|none, start, stop, update, filename <name>, status, streams")
else:
print("Warning: Failed to start remote control server")
# Discover available streams
print("\nDiscovering LSL streams...")
available_streams = recorder.find_streams()
if available_streams:
# Select all streams by default
uids_to_record = [info.uid() for info in available_streams]
recorder.select_streams_to_record(uids_to_record)
print(f"\nSelected {len(uids_to_record)} streams for recording.")
if enable_remote:
print("\nRecorder ready. Use remote control commands to start/stop recording.")
print("Or press Ctrl+C to exit.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nShutdown requested...")
else:
# Start recording immediately if no remote control
print("\nStarting recording...")
recorder.start_recording()
print("Recording in progress. Press Ctrl+C to stop.")
try:
while recorder.is_recording():
time.sleep(0.5)
except KeyboardInterrupt:
print("\nStopping recording...")
recorder.stop_recording()
else:
print("No LSL streams found.")
if enable_remote:
print("Remote control server is running. You can:")
print("1. Start streams and use 'update' command")
print("2. Use remote control to manage recording")
print("Press Ctrl+C to exit.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nShutdown requested...")
else:
print("Exiting...")
except Exception as e:
print(f"Error: {e}")
return 1
finally:
# Clean up resources
recorder.cleanup()
print("Lab Recorder finished.")
return 0
if __name__ == "__main__":
sys.exit(main())