133 lines
3.3 KiB
Rust
133 lines
3.3 KiB
Rust
//! EGI Format Constants
|
|
//!
|
|
//! File offsets, magic numbers, and type definitions for EGI files.
|
|
|
|
/// Magic header for EGI simple binary format
|
|
pub const EGI_RAW_MAGIC: &[u8; 4] = b"VERS";
|
|
|
|
/// Header line start for version
|
|
pub const EGI_VERSION_TAG: &str = "Version";
|
|
|
|
/// Header line start for sample rate
|
|
pub const EGI_SFREQ_TAG: &str = "Sample Rate";
|
|
|
|
/// Header line start for channel count
|
|
pub const EGI_NCHAN_TAG: &str = "Number of Channels";
|
|
|
|
/// Header line start for gain
|
|
pub const EGI_GAIN_TAG: &str = "Gain";
|
|
|
|
/// Header line start for number of samples
|
|
pub const EGI_NSAMP_TAG: &str = "Number of Samples";
|
|
|
|
/// Header line start for precision
|
|
pub const EGI_PRECISION_TAG: &str = "Precision";
|
|
|
|
/// Header line start for number of categories
|
|
pub const EGI_NCATS_TAG: &str = "Number of Categories";
|
|
|
|
/// Header line start for category name
|
|
pub const EGI_CATEGORY_TAG: &str = "Category";
|
|
|
|
// Data types
|
|
/// Float32 precision
|
|
pub const EGI_DTYPE_FLOAT: i16 = 4;
|
|
/// Int16 precision
|
|
pub const EGI_DTYPE_INT16: i16 = 2;
|
|
/// Float64 precision
|
|
pub const EGI_DTYPE_DOUBLE: i16 = 8;
|
|
|
|
// EGI sensor net sizes
|
|
/// 32-channel net
|
|
pub const EGI_NET_32: usize = 32;
|
|
/// 64-channel net
|
|
pub const EGI_NET_64: usize = 64;
|
|
/// 128-channel net
|
|
pub const EGI_NET_128: usize = 128;
|
|
/// 256-channel net
|
|
pub const EGI_NET_256: usize = 256;
|
|
|
|
// MFF file names
|
|
/// MFF info file
|
|
pub const MFF_INFO_FILE: &str = "info.xml";
|
|
/// MFF signal file pattern
|
|
pub const MFF_SIGNAL_PREFIX: &str = "signal";
|
|
/// MFF coordinates file
|
|
pub const MFF_COORDS_FILE: &str = "coordinates.xml";
|
|
/// MFF categories file
|
|
pub const MFF_CATEGORIES_FILE: &str = "categories.xml";
|
|
/// MFF events file
|
|
pub const MFF_EVENTS_FILE: &str = "Events.xml";
|
|
|
|
/// Data type enumeration for EGI files
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum EgiDataType {
|
|
/// 16-bit signed integer
|
|
Int16,
|
|
/// 32-bit float
|
|
Float32,
|
|
/// 64-bit float
|
|
Float64,
|
|
}
|
|
|
|
impl TryFrom<i16> for EgiDataType {
|
|
type Error = &'static str;
|
|
|
|
fn try_from(value: i16) -> Result<Self, Self::Error> {
|
|
match value {
|
|
EGI_DTYPE_INT16 => Ok(Self::Int16),
|
|
EGI_DTYPE_FLOAT => Ok(Self::Float32),
|
|
EGI_DTYPE_DOUBLE => Ok(Self::Float64),
|
|
_ => Err("Unknown EGI data type"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl EgiDataType {
|
|
/// Size of this data type in bytes
|
|
pub fn size(&self) -> usize {
|
|
match self {
|
|
Self::Int16 => 2,
|
|
Self::Float32 => 4,
|
|
Self::Float64 => 8,
|
|
}
|
|
}
|
|
|
|
/// Create from byte count
|
|
pub fn from_bytes(bytes: usize) -> Self {
|
|
match bytes {
|
|
2 => Self::Int16,
|
|
8 => Self::Float64,
|
|
_ => Self::Float32,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Channel type for EGI
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum EgiChannelType {
|
|
/// Standard EEG electrode
|
|
Eeg,
|
|
/// Reference electrode (e.g., Cz)
|
|
Ref,
|
|
/// Trigger/event channel
|
|
Event,
|
|
/// PNS (photoplethysmograph, etc.)
|
|
Pns,
|
|
/// Other auxiliary channel
|
|
Other,
|
|
}
|
|
|
|
impl EgiChannelType {
|
|
/// Get string representation
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
Self::Eeg => "EEG",
|
|
Self::Ref => "REF",
|
|
Self::Event => "EVENT",
|
|
Self::Pns => "PNS",
|
|
Self::Other => "OTHER",
|
|
}
|
|
}
|
|
}
|