Skip to content

Commit 066e537

Browse files
committed
Make sure mode also changes unique ID to prevent reconnection on mode change.
1 parent f413b30 commit 066e537

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/core/include/egiamp/AmpServerConfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ struct AmpServerConfig {
2424
/// .51 → "EGINetAmp_51", .52 → "EGINetAmp_52", localhost/127.* → "EGINetAmp_mock".
2525
std::string streamName() const;
2626

27+
/// Suffix for LSL source ID to distinguish native/decimated mode and timestamp alignment.
28+
/// Ensures LSL consumers won't auto-reconnect across incompatible configurations.
29+
std::string modeSuffix() const {
30+
const bool native = sampleRate > 1000 || (fastRecovery && sampleRate >= 500);
31+
std::string s = native ? "_native" : "_decimated";
32+
if (alignTimestamps && !native) s += "_aligned";
33+
return s;
34+
}
35+
2736
static AmpServerConfig loadFromFile(const std::string& filename);
2837
void saveToFile(const std::string& filename) const;
2938
};

src/core/include/egiamp/LSLStreamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class LSLStreamer {
2626
int physioChannelCount, int dinChannelCount, int sampleRate,
2727
const std::string& hostname,
2828
const AmplifierDetails& details,
29-
bool nativeFormat = false);
29+
bool nativeFormat = false,
30+
const std::string& modeSuffix = "");
3031

3132
void createImpedanceOutlet(const std::string& streamName, int channelCount,
3233
const std::string& hostname,

src/core/src/EGIAmpClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ void EGIAmpClient::readPacketFormat2() {
815815
std::string streamName = config_.streamName();
816816
streamer_.createOutlet(streamName, eegChannelCount, physioChannelCount, 0,
817817
config_.sampleRate, config_.serverAddress, details_,
818-
config_.nativeFormat);
818+
config_.nativeFormat, config_.modeSuffix());
819819

820820
// Create separate DIN event stream (irregular rate, no filter delay)
821821
dinStreamer_.createDINOutlet(streamName + "_DIN", config_.serverAddress);
@@ -914,7 +914,7 @@ void EGIAmpClient::readPacketFormat2() {
914914
(physioConnectionStatus_ > 0) ? 16 : 0;
915915
streamer_.createOutlet(streamName, nChannels + 1, physioChCount, 0,
916916
config_.sampleRate, config_.serverAddress, details_,
917-
config_.nativeFormat);
917+
config_.nativeFormat, config_.modeSuffix());
918918
dinStreamer_.createDINOutlet(streamName + "_DIN", config_.serverAddress);
919919

920920
// Apply timestamp offset for filter delay compensation if enabled

src/core/src/LSLStreamer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ void LSLStreamer::createOutlet(const std::string& streamName, int eegChannelCoun
8888
int physioChannelCount, int dinChannelCount, int sampleRate,
8989
const std::string& hostname,
9090
const AmplifierDetails& details,
91-
bool nativeFormat) {
91+
bool nativeFormat,
92+
const std::string& modeSuffix) {
9293
// Close existing outlet if any
9394
closeOutlet();
9495

@@ -102,7 +103,7 @@ void LSLStreamer::createOutlet(const std::string& streamName, int eegChannelCoun
102103
std::string sourceId = "EGI_" + hostname +
103104
"_ch" + std::to_string(totalChannelCount) +
104105
"_sr" + std::to_string(sampleRate) +
105-
formatSuffix;
106+
formatSuffix + modeSuffix;
106107
lsl::channel_format_t channelFormat = nativeFormat ? lsl::cf_int32 : lsl::cf_float32;
107108
lsl::stream_info info(streamName, "EEG", totalChannelCount,
108109
static_cast<double>(sampleRate),
@@ -399,6 +400,7 @@ void LSLStreamer::pushNotification(const std::string& text, const double timesta
399400

400401
void LSLStreamer::closeOutlet() {
401402
outlet_.reset();
403+
timestampOffset_ = 0.0;
402404
}
403405

404406
} // namespace egiamp

0 commit comments

Comments
 (0)