Skip to content
44 changes: 43 additions & 1 deletion src/explorepy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CommandID(Enum):
"""Command ID enum class"""
API2BCMD = b'\xA0'
API4BCMD = b'\xB0'
API64BCMD = b'\xC0'


class OpcodeID(Enum):
Expand All @@ -27,6 +28,7 @@ class OpcodeID(Enum):
CMD_ZM_ENABLE = b'\xA7'
CMD_SOFT_RESET = b'\xA8'
CMD_TEST_SIG = b'\xAA'
CMD_SET_EMMC_TIME = b'\xAB'


class DeviceConfiguration:
Expand Down Expand Up @@ -182,6 +184,19 @@ def __str__(self):
"""prints the appropriate info about the command. """


class Command64B(Command):
"""An abstract base class for Explore 40 Byte command data length packets"""

def __init__(self):
super().__init__()
self.pid = CommandID.API64BCMD
self.payload_length = int2bytearray(40, 2)

@abc.abstractmethod
def __str__(self):
"""prints the appropriate info about the command. """


class SetSPS(Command2B):
"""Set the sampling rate of ExG device"""

Expand Down Expand Up @@ -213,6 +228,32 @@ def __str__(self):
return "Set sampling rate command"


class SetBinaryTime(Command64B):
def __init__(self):
super().__init__()
self.opcode = OpcodeID.CMD_SET_EMMC_TIME
from datetime import datetime
now = datetime.now()
date_time = bytes(
[
now.year - 2000,
now.month,
now.day,
now.weekday(),
now.hour,
now.minute,
now.second,
1,
2,
3,
]
)
self.param = date_time + bytes(51)

def __str__(self):
return "set time cmd"


class MemoryFormat(Command2B):
"""Format device memory"""

Expand Down Expand Up @@ -282,7 +323,8 @@ def __str__(self):

COMMAND_CLASS_DICT = {
CommandID.API2BCMD: Command2B,
CommandID.API4BCMD: Command4B
CommandID.API4BCMD: Command4B,
CommandID.API64BCMD: Command64B
}


Expand Down
16 changes: 15 additions & 1 deletion src/explorepy/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import explorepy
from explorepy.command import (
MemoryFormat,
SetBinaryTime,
SetChTest,
SetSPS,
SoftReset
Expand Down Expand Up @@ -105,11 +106,13 @@ def connect(self, device_name=None, mac_address=None, file_path=None):
cnt_limit = 20 if self.debug else 15
while "adc_mask" not in self.stream_processor.device_info:
logger.info("Waiting for device info packet...")
time.sleep(1)
time.sleep(.5)
if cnt >= cnt_limit:
raise ConnectionAbortedError(
"Could not get info packet from the device")
cnt += 1
if 'time_cmd' in self.stream_processor.device_info:
self.set_binary_time()
if self.stream_processor.device_info['is_imp_mode'] is True:
self.stream_processor.disable_imp()
logger.info(
Expand Down Expand Up @@ -652,6 +655,17 @@ def set_sampling_rate(self, sampling_rate):
SettingsManager(self.device_name).set_sampling_rate(sampling_rate)
return True

def set_binary_time(self):
"""Set binary file to current time

Returns:
bool: True for success, False otherwise
"""
cmd = SetBinaryTime()
if self.stream_processor.configure_device(cmd):
logger.info('Device set to current time.')
return True

def reset_soft(self):
"""Reset the device to the default settings

Expand Down
14 changes: 13 additions & 1 deletion src/explorepy/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PACKET_ID(IntEnum):
# Info packet from BLE devices, applies to Explore Pro
INFO_BLE = 98
INFO_HYP = 99
INFO_TIME_CMD = 100
# New info packet containing memory and board ID: this applies to all Explore+ systems
INFO_V2 = 97
INFO = 96
Expand Down Expand Up @@ -696,7 +697,17 @@ def get_info(self):


class DeviceInfoHyp(DeviceInfoBLE):
pass
def get_info(self):
as_dict = super().get_info()
as_dict['is_hypersync'] = True
return as_dict


class DeviceInfoBinTimeCmd(DeviceInfoHyp):
def get_info(self):
as_dict = super().get_info()
as_dict['time_cmd'] = True
return as_dict


class CommandRCV(Packet):
Expand Down Expand Up @@ -837,6 +848,7 @@ def __str__(self):
PACKET_ID.INFO_V2: DeviceInfoV2,
PACKET_ID.INFO_BLE: DeviceInfoBLE,
PACKET_ID.INFO_HYP: DeviceInfoHyp,
PACKET_ID.INFO_TIME_CMD: DeviceInfoBinTimeCmd,
PACKET_ID.EEG94: EEG94,
PACKET_ID.EEG98: EEG98,
PACKET_ID.EEG99: EEG99,
Expand Down
7 changes: 6 additions & 1 deletion src/explorepy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from explorepy.packet import (
PACKET_CLASS_DICT,
PACKET_ID,
DeviceInfo,
Packet,
PacketBIN
Expand Down Expand Up @@ -373,7 +374,11 @@ def get_header_bytes(self):
break
if pid_bin is None:
raise ValueError
self.header_len = 12 if pid_bin[0] == 99 else 8
self.header_len = (
12
if pid_bin[0] in (PACKET_ID.INFO_HYP, PACKET_ID.INFO_TIME_CMD)
else 8
)
self.data_len = self.header_len - 4
return pid_bin + self.stream_interface.read(self.header_len - 1)
else:
Expand Down
Loading