Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
x64/
x86/
bld/
build/
[Bb]in/
[Oo]bj/
[Ll]og/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public enum BoardIds
FREEEEG32_BOARD = 17,
BRAINBIT_BLED_BOARD = 18,
GFORCE_DUAL_BOARD = 19,
GALEA_SERIAL_BOARD = 20,
MUSE_S_BLED_BOARD = 21,
MUSE_2_BLED_BOARD = 22,
CROWN_BOARD = 23,
Expand All @@ -107,8 +106,6 @@ public enum BoardIds
EXPLORE_8_CHAN_BOARD = 45,
GANGLION_NATIVE_BOARD = 46,
EMOTIBIT_BOARD = 47,
GALEA_BOARD_V4 = 48,
GALEA_SERIAL_BOARD_V4 = 49,
NTL_WIFI_BOARD = 50,
ANT_NEURO_EE_511_BOARD = 51,
FREEEEG128_BOARD = 52,
Expand Down
79 changes: 63 additions & 16 deletions emulator/brainflow_emulator/galea_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class State(enum.Enum):
class Message(enum.Enum):
start_stream = b'b'
stop_stream = b's'
ack_values = (b'd', b'~6', b'~5', b'o', b'F0')
ack_values = (b'd', b'~6', b'~5', b'~4', b'o', b'F0')
ack_from_device = b'A'
time_calc_command = b'F4444444'

Expand All @@ -25,14 +25,19 @@ def __init__(self):
self.local_ip = '127.0.0.1'
self.local_port = 2390
self.server_socket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
self.server_socket.settimeout(
0.1) # decreases sampling rate significantly because it will wait for recv 0.1 sec but it's just a test
self.server_socket.bind((self.local_ip, self.local_port))
self.state = State.wait.value
self.addr = None
self.package_num = 0
self.transaction_size = 19
self.package_size = 72
self.transaction_size = 12
self.package_size = 114
self.server_socket.settimeout(.0001)
self.channel_on_off = [1] * 24
self.channel_identifiers = [
'1', '2', '3', '4', '5', '6', '7', '8',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
'A', 'S', 'D', 'G', 'H', 'J', 'K', 'L'
]

def run(self):
start_time = time.time()
Expand All @@ -43,8 +48,14 @@ def run(self):
self.state = State.stream.value
elif msg == Message.stop_stream.value:
self.state = State.wait.value
elif msg.decode('utf-8').startswith('~'):
self.server_socket.sendto(Message.ack_from_device.value, self.addr)
self.process_sampling_rate(msg.decode('utf-8'))
elif msg in Message.ack_values.value or msg.decode('utf-8').startswith('x'):
self.server_socket.sendto(Message.ack_from_device.value, self.addr)
self.process_channel_on_off(msg.decode('utf-8'))
elif msg in Message.ack_values.value or msg.decode('utf-8').startswith('z'):
self.server_socket.sendto(Message.ack_from_device.value, self.addr)
elif msg == Message.time_calc_command.value:
cur_time = time.time()
resp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
Expand All @@ -58,27 +69,40 @@ def run(self):

if self.state == State.stream.value:
transaction = list()
for _ in range(self.transaction_size):
for t in range(self.transaction_size):
single_package = list()
channel = 0
for i in range(self.package_size):
single_package.append(random.randint(0, 255))
if (i > 4 and i < 77):
sample = i - 4
if (sample % 3 == 1):
channel += 1
if (self.channel_on_off[channel - 1] == 1):
if (sample % 3 == 2):
single_package.append(random.randint(0, 8 + (channel * 2)))
else:
single_package.append(0)
else:
single_package.append(0)
else:
single_package.append(random.randint(0, 255))
single_package[0] = self.package_num

cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
eda = bytearray(struct.pack('f', random.random()))
eda = bytearray(struct.pack('f', .5))
ppg_red = bytearray(struct.pack('i', int(random.random() * 5000)))
ppg_ir = bytearray(struct.pack('i', int(random.random() * 5000)))

for i in range(64, 72):
single_package[i] = timestamp[i - 64]
for i in range(88, 96):
single_package[i] = timestamp[i - 88]
for i in range(1, 5):
single_package[i] = eda[i - 1]
for i in range(60, 64):
single_package[i] = ppg_ir[i - 60]
for i in range(56, 60):
single_package[i] = ppg_red[i - 56]
single_package[53] = random.randint(0, 100)
for i in range(84, 88):
single_package[i] = ppg_ir[i - 84]
for i in range(80, 84):
single_package[i] = ppg_red[i - 80]
single_package[77] = random.randint(0, 100)

self.package_num = self.package_num + 1
if self.package_num % 256 == 0:
Expand All @@ -91,7 +115,30 @@ def run(self):
self.server_socket.sendto(bytes(package), self.addr)
except socket.timeout:
logging.info('timeout for send')

time.sleep(0.001)


def process_channel_on_off(self, msg):
if msg.startswith('x'):
for channel_id in self.channel_identifiers:
channel_num = self.channel_identifiers.index(channel_id)
if (msg[1] == channel_id):
if (msg[2] == '0'): # 0 is off (or Power Down), 1 is on
self.channel_on_off[channel_num] = 1
logging.info('channel '+ str(channel_num + 1) + ' is on')
else:
self.channel_on_off[channel_num] = 0
logging.info('channel ' + str(channel_num + 1) + ' is off')

def process_sampling_rate(self, msg):
if (msg[1] == '6'):
logging.info('sampling rate is 250Hz')
elif (msg[1] == '5'):
logging.info('sampling rate is 500Hz')
elif (msg[1] == '4'):
logging.info('sampling rate is 1000Hz')
else:
logging.warning(f'did not recognize sampling rate command: {msg}')

def main():
emulator = GaleaEmulator()
Expand Down
150 changes: 0 additions & 150 deletions emulator/brainflow_emulator/galea_manual_v4.py

This file was deleted.

Loading
Loading