-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: create lsl reader and config parser #30
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
base: main
Are you sure you want to change the base?
Changes from all commits
a3e2273
061fde1
550486e
d812779
a4cbee1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #ifndef CHANNELCONFIG_HPP | ||
| #define CHANNELCONFIG_HPP | ||
|
|
||
| #include <string> | ||
|
|
||
| // Description of a single EEG channel as declared in the device config file. | ||
| struct ChannelConfig { | ||
| int index = 0; | ||
| std::string label; | ||
| bool enabled = true; | ||
| std::string unit; | ||
| }; | ||
|
|
||
| #endif // CHANNELCONFIG_HPP |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #ifndef CONFIGPARSER_HPP | ||
| #define CONFIGPARSER_HPP | ||
|
|
||
| #include <config/ExperimentConfig.hpp> | ||
| #include <istream> | ||
| #include <string> | ||
|
|
||
| class ConfigParser { | ||
| public: | ||
| ConfigParser() = default; | ||
|
|
||
| static ExperimentConfig parse(const std::string& filePath); | ||
| static ExperimentConfig parseStream(std::istream& stream); | ||
| }; | ||
|
|
||
| #endif // CONFIGPARSER_HPP | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No proper validation functions before parsing for every config type. Consider making private constructors with a factory or at least a This is not a problem if the config's purpose is and will only ever be to pass them into a parser. If so, document it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #ifndef EXPERIMENTCONFIG_HPP | ||
| #define EXPERIMENTCONFIG_HPP | ||
|
|
||
| #include <config/LSLConfig.hpp> | ||
| #include <string> | ||
|
|
||
| struct ReferenceConfig { | ||
| std::string label; | ||
| std::string scheme; | ||
| }; | ||
|
|
||
| struct GroundConfig { | ||
| std::string label; | ||
| }; | ||
|
|
||
| struct ImpedanceConfig { | ||
| bool supported = false; | ||
| double thresholdKohm = 0.0; | ||
| }; | ||
|
|
||
| struct ExperimentConfig { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename ExperimentConfig to e.g. DeviceConfig, HardwareConfig? This has nothing to do with the experiment configuration, which will be stored in the Protobuf files. |
||
| std::string configVersion; | ||
| std::string deviceName; | ||
| std::string montageStandard; | ||
| LSLConfig lsl; | ||
| ReferenceConfig reference; | ||
| GroundConfig ground; | ||
| ImpedanceConfig impedance; | ||
| // TODO: DataWriterConfig writer; // EEG output file format strategy | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JSON config representation requires the |
||
|
|
||
| #endif // EXPERIMENTCONFIG_HPP | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #ifndef LSLCONFIG_HPP | ||
| #define LSLCONFIG_HPP | ||
|
|
||
| #include <config/ChannelConfig.hpp> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| struct LSLConfig { | ||
| std::string name; // lsl_stream.name | ||
| std::string type; // lsl_stream.type | ||
| std::string sourceId; // lsl_stream.source_id | ||
| int expectedChannelCount = 0; | ||
| double expectedSampleRateHz = 0.0; | ||
| std::vector<ChannelConfig> channels; | ||
| }; | ||
|
|
||
| #endif // LSLCONFIG_HPP |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #ifndef LSLREADER_HPP | ||
| #define LSLREADER_HPP | ||
|
|
||
| #include <concurrentqueue.h> | ||
|
|
||
| #include <config/LSLConfig.hpp> | ||
| #include <memory> | ||
| #include <thread> | ||
|
|
||
| struct EEGData; | ||
|
|
||
| class LSLReader { | ||
| public: | ||
| explicit LSLReader(LSLConfig config); | ||
| ~LSLReader(); | ||
|
|
||
| LSLReader(const LSLReader&) = delete; | ||
| LSLReader& operator=(const LSLReader&) = delete; | ||
| LSLReader(LSLReader&&) = delete; | ||
| LSLReader& operator=(LSLReader&&) = delete; | ||
|
|
||
| void start(std::shared_ptr<moodycamel::ConcurrentQueue<EEGData>> eegQueue); | ||
| void stop(); | ||
|
|
||
| private: | ||
| void readLoop(const std::stop_token& stopToken); | ||
|
|
||
| LSLConfig config; | ||
| std::shared_ptr<moodycamel::ConcurrentQueue<EEGData>> eegQueue; | ||
| std::jthread readerThread; | ||
| }; | ||
|
|
||
| #endif // LSLREADER_HPP |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| add_library(config OBJECT | ||
| ConfigParser.cpp | ||
| ) | ||
|
|
||
| target_include_directories(config PUBLIC | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../include/config | ||
| ) | ||
|
|
||
| target_link_libraries(config PRIVATE nlohmann_json::nlohmann_json) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All-static classes should be replaced by namespaced free functions, e.g.
This is also a problem with the already established
Parser