Skip to content

Commit

Permalink
Update Galea emulator to support channel On/Off
Browse files Browse the repository at this point in the history
  • Loading branch information
retiutut committed Nov 6, 2023
1 parent dd1e1ea commit 698fe51
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions emulator/brainflow_emulator/galea_manual_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import socket
import struct
import time
from array import array


class State(enum.Enum):
Expand Down Expand Up @@ -37,7 +38,9 @@ def __init__(self):
.0000001) # decreases sampling rate significantly because it will wait for receive to timeout
self.total_packets_sent = 0
self.start_streaming_time = 0
self.DEBUG_MODE = False
self.debug_mode = False
self.channel_on_off = [1] * 24
self.channel_identifiers = array('u', ['1', '2', '3', '4', '5', '6', '7', '8', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I'])

def run(self):
start_time = time.time()
Expand All @@ -53,6 +56,7 @@ def run(self):
self.start_streaming_time
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:
Expand All @@ -68,10 +72,22 @@ 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.debug_mode):
print(t, i, channel)
if (self.channel_on_off[channel - 1] == 1):
single_package.append(random.randint(0, 255))
else:
single_package.append(0)
else:
single_package.append(random.randint(0, 255))
single_package[0] = self.package_num

cur_time = time.time()
Expand Down Expand Up @@ -105,11 +121,23 @@ def run(self):

time.sleep(self.transaction_speed_250)

if (self.DEBUG_MODE):
if (self.debug_mode):
elapsed_time = (time.time() - self.start_streaming_time)
sampling_rate = self.total_packets_sent / elapsed_time
print('elapsed time: ' + str(elapsed_time) + ' sampling rate: ' + str(sampling_rate))

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
print('channel ' + str(channel_num + 1) + ' is on')
else:
self.channel_on_off[channel_num] = 0
print('channel ' + str(channel_num + 1) + ' is off')

def main():
emulator = GaleaEmulator()
emulator.run()
Expand Down

0 comments on commit 698fe51

Please sign in to comment.