-
Notifications
You must be signed in to change notification settings - Fork 4
Feature: Tap API in simulated broadband source #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
645a53b
tap interface in synapse-sim
arminvoid dd721b5
tap_example
arminvoid 6614f72
migrate to BroadbandFrame from ndtp_types.ElectricalBroadbandData
arminvoid c793392
pass iface_ip to broadband, select random port
arminvoid e3dd3d0
set zmq resources to None
arminvoid 2b8ad98
resolve review comments
arminvoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import synapse as syn | ||
| import sys | ||
| import time | ||
|
|
||
| from synapse.client.taps import Tap | ||
|
|
||
| SIMULATED_PERIPHERAL_ID = 100 | ||
|
|
||
| if __name__ == "__main__": | ||
| uri = sys.argv[1] if len(sys.argv) > 1 else "127.0.0.1:647" | ||
| device = syn.Device(uri) | ||
| info = device.info() | ||
| if info is None: | ||
| print("Couldn't get device info") | ||
| sys.exit(1) | ||
|
|
||
| print("Device info:") | ||
| print(info) | ||
|
|
||
| channels = [ | ||
| syn.Channel( | ||
| id=channel_num, | ||
| electrode_id=channel_num * 2, | ||
| reference_id=channel_num * 2 + 1, | ||
| ) | ||
| for channel_num in range(32) | ||
| ] | ||
|
|
||
| broadband = syn.BroadbandSource( | ||
| # Use the simulated peripheral (100), or replace with your own | ||
| peripheral_id=SIMULATED_PERIPHERAL_ID, | ||
| sample_rate_hz=30000, | ||
| bit_width=12, | ||
| gain=20.0, | ||
| signal=syn.SignalConfig( | ||
| electrode=syn.ElectrodeConfig( | ||
| channels=channels, | ||
| low_cutoff_hz=500.0, | ||
| high_cutoff_hz=6000.0, | ||
| ) | ||
| ), | ||
| ) | ||
|
|
||
| config = syn.Config() | ||
| config.add_node(broadband) | ||
|
|
||
| device.configure(config) | ||
|
|
||
| # export the config to a json file for using with CLI | ||
| # from google.protobuf.json_format import MessageToJson | ||
| # with open("device_config.json", "w") as f: | ||
| # f.write(MessageToJson(config.to_proto())) | ||
| # print("Config written to device_config.json") | ||
|
|
||
| device.start() | ||
|
|
||
| info = device.info() | ||
| if info is None: | ||
| print("Couldn't get device info") | ||
| sys.exit(1) | ||
| print("Configured device info:") | ||
| print(info) | ||
|
|
||
| # stream with tap api | ||
| tap_client = Tap(uri) | ||
| tap_client.connect("broadband_source_sim") | ||
|
|
||
| should_run = True | ||
| total_bytes_read = 0 | ||
| start_time = time.time() | ||
| last_update_time = start_time | ||
| update_interval_sec = 1 | ||
| while should_run: | ||
| try: | ||
| # Wait for data | ||
| syn_data = tap_client.read() | ||
| bytes_read = len(syn_data) | ||
| if syn_data is None or bytes_read == 0: | ||
| print("Failed to read data from node") | ||
| continue | ||
| # Do something with the data | ||
| total_bytes_read += bytes_read | ||
|
|
||
| current_time = time.time() | ||
| if (current_time - last_update_time) >= update_interval_sec: | ||
| sys.stdout.write("\r") | ||
| sys.stdout.write( | ||
| f"{total_bytes_read} bytes in {time.time() - start_time:.2f} sec" | ||
| ) | ||
| last_update_time = current_time | ||
|
|
||
| if current_time - start_time > 5: | ||
| should_run = False | ||
|
|
||
| except KeyboardInterrupt: | ||
| print("Keyboard interrupt detected, stopping") | ||
| should_run = False | ||
|
|
||
| print("Stopping device") | ||
| device.stop() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.