Skip to content

Commit

Permalink
fix board id for neurosity boards (#532)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Parfenov <[email protected]>
  • Loading branch information
Andrey1994 authored Aug 4, 2022
1 parent 3988b6a commit 8382329
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 451 deletions.
69 changes: 32 additions & 37 deletions emulator/brainflow_emulator/galea_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ def __init__(self):
self.server_socket.bind((self.local_ip, self.local_port))
self.state = State.wait.value
self.addr = None
self.exg_package_num = 0
self.aux_package_num = 0
self.exg_package_size = 59
self.aux_package_size = 26
self.num_exg_packages_in_transaction = 20
self.num_aux_packages_in_transaction = 4
self.package_num = 0
self.transaction_size = 19
self.package_size = 72

def run(self):
start_time = time.time()
Expand All @@ -60,39 +57,37 @@ def run(self):
logging.debug('timeout for recv')

if self.state == State.stream.value:
package = list()
# exg
for _ in range(self.num_exg_packages_in_transaction):
package.append(0xA0)
package.append(self.exg_package_num)
self.exg_package_num = self.exg_package_num + 1
if self.exg_package_num % 256 == 0:
self.exg_package_num = 0
for i in range(1, self.exg_package_size - 10):
package.append(random.randint(0, 30))
cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
package.extend(timestamp)
package.append(0xC0)
try:
self.server_socket.sendto(bytes(package), self.addr)
except socket.timeout:
logging.info('timeout for send')
# aux
package = list()
for _ in range(self.num_aux_packages_in_transaction):
package.append(0xA1)
package.append(self.aux_package_num)
self.aux_package_num = self.aux_package_num + 1
if self.aux_package_num % 256 == 0:
self.aux_package_num = 0
for i in range(1, self.aux_package_size - 10):
package.append(random.randint(0, 5))
transaction = list()
for _ in range(self.transaction_size):
single_package = list()
for i in range(self.package_size):
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))
package.extend(timestamp)
package.append(0xC0)
eda = bytearray(struct.pack('f', random.random()))
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(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)

self.package_num = self.package_num + 1
if self.package_num % 256 == 0:
self.package_num = 0
transaction.append(single_package)
try:
package = list()
for i in range(self.transaction_size):
package.extend(bytes(transaction[i]))
self.server_socket.sendto(bytes(package), self.addr)
except socket.timeout:
logging.info('timeout for send')
Expand All @@ -105,4 +100,4 @@ def main():

if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level=logging.INFO)
main()
main()
51 changes: 13 additions & 38 deletions emulator/brainflow_emulator/galea_serial_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,49 +119,24 @@ def __init__(self, port, delay, write):
self.port = port
self.write = write
self.delay = delay
self.package_size = 72 * 19
self.package_num = 0
self.need_data = True

self.exg_package_num = 0
self.aux_package_num = 0
self.exg_package_size = 59
self.aux_package_size = 26
self.num_exg_packages_in_transaction = 20
self.num_aux_packages_in_transaction = 4

def run(self):
start_time = time.time()
while self.need_data:
if self.package_num % 256 == 0:
self.package_num = 0

package = list()
# exg
for _ in range(self.num_exg_packages_in_transaction):
package.append(0xA0)
package.append(self.exg_package_num)
self.exg_package_num = self.exg_package_num + 1
if self.exg_package_num % 256 == 0:
self.exg_package_num = 0
for i in range(1, self.exg_package_size - 10):
package.append(random.randint(0, 30))
cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
package.extend(timestamp)
package.append(0xC0)
self.write(self.port, bytes(package))
time.sleep(self.delay)
# aux
package = list()
for _ in range(self.num_aux_packages_in_transaction):
package.append(0xA1)
package.append(self.aux_package_num)
self.aux_package_num = self.aux_package_num + 1
if self.aux_package_num % 256 == 0:
self.aux_package_num = 0
for i in range(1, self.aux_package_size - 10):
package.append(random.randint(0, 5))
cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
package.extend(timestamp)
package.append(0xC0)
package.append(0xA0)
for i in range(self.package_size):
package.append(random.randint(0, 255))
package.append(0xC0)
logging.debug('package is %s' % ' '.join([str(x) for x in package]))
self.write(self.port, bytes(package))

self.package_num = self.package_num + 1
time.sleep(self.delay)


Expand All @@ -172,4 +147,4 @@ def main():

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
main()
main()
51 changes: 13 additions & 38 deletions emulator/brainflow_emulator/galea_serial_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,49 +133,24 @@ def __init__(self, port, delay, write):
self.port = port
self.write = write
self.delay = delay
self.package_size = 72 * 19
self.package_num = 0
self.need_data = True

self.exg_package_num = 0
self.aux_package_num = 0
self.exg_package_size = 59
self.aux_package_size = 26
self.num_exg_packages_in_transaction = 20
self.num_aux_packages_in_transaction = 4

def run(self):
start_time = time.time()
while self.need_data:
if self.package_num % 256 == 0:
self.package_num = 0

package = list()
# exg
for _ in range(self.num_exg_packages_in_transaction):
package.append(0xA0)
package.append(self.exg_package_num)
self.exg_package_num = self.exg_package_num + 1
if self.exg_package_num % 256 == 0:
self.exg_package_num = 0
for i in range(1, self.exg_package_size - 10):
package.append(random.randint(0, 30))
cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
package.extend(timestamp)
package.append(0xC0)
self.write(self.port, bytes(package))
time.sleep(self.delay)
# aux
package = list()
for _ in range(self.num_aux_packages_in_transaction):
package.append(0xA1)
package.append(self.aux_package_num)
self.aux_package_num = self.aux_package_num + 1
if self.aux_package_num % 256 == 0:
self.aux_package_num = 0
for i in range(1, self.aux_package_size - 10):
package.append(random.randint(0, 5))
cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
package.extend(timestamp)
package.append(0xC0)
package.append(0xA0)
for i in range(self.package_size):
package.append(random.randint(0, 255))
package.append(0xC0)
logging.debug('package is %s' % ' '.join([str(x) for x in package]))
self.write(self.port, bytes(package))

self.package_num = self.package_num + 1
time.sleep(self.delay)


Expand All @@ -189,4 +164,4 @@ def main(cmd_list):

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
main(sys.argv[1:])
main(sys.argv[1:])
48 changes: 11 additions & 37 deletions emulator/brainflow_emulator/galea_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ def __init__(self):
self.server_socket.bind((self.local_ip, self.local_port))
self.state = State.wait.value
self.addr = None
self.package_num = 0
self.package_size = 72
self.keep_alive = True

self.exg_package_num = 0
self.aux_package_num = 0
self.exg_package_size = 59
self.aux_package_size = 26
self.num_exg_packages_in_transaction = 20
self.num_aux_packages_in_transaction = 4


def run(self):
start_time = time.time()
Expand Down Expand Up @@ -92,42 +86,22 @@ def run(self):

if self.state == State.stream.value:
package = list()
# exg
for _ in range(self.num_exg_packages_in_transaction):
package.append(0xA0)
package.append(self.exg_package_num)
self.exg_package_num = self.exg_package_num + 1
if self.exg_package_num % 256 == 0:
self.exg_package_num = 0
for i in range(1, self.exg_package_size - 10):
package.append(random.randint(0, 30))
for _ in range(19):
package.append(self.package_num)
self.package_num = self.package_num + 1
if self.package_num % 256 == 0:
self.package_num = 0
for i in range(1, self.package_size - 8):
package.append(random.randint(0, 255))
cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
package.extend(timestamp)
package.append(0xC0)
try:
self.server_socket.sendto(bytes(package), self.addr)
except socket.timeout:
logging.info('timeout for send')
# aux
package = list()
for _ in range(self.num_aux_packages_in_transaction):
package.append(0xA1)
package.append(self.aux_package_num)
self.aux_package_num = self.aux_package_num + 1
if self.aux_package_num % 256 == 0:
self.aux_package_num = 0
for i in range(1, self.aux_package_size - 10):
package.append(random.randint(0, 5))
cur_time = time.time()
timestamp = bytearray(struct.pack('d', (cur_time - start_time) * 1000))
package.extend(timestamp)
package.append(0xC0)
try:
self.server_socket.sendto(bytes(package), self.addr)
except socket.timeout:
logging.info('timeout for send')


def main(cmd_list):
if not cmd_list:
raise Exception('No command to execute')
Expand All @@ -139,4 +113,4 @@ def main(cmd_list):

if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level=logging.INFO)
main(sys.argv[1:])
main(sys.argv[1:])
6 changes: 3 additions & 3 deletions src/board_controller/board_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ int prepare_session (int board_id, const char *json_brainflow_input_params)
// notion 1, notion 2 and crown have the same class
// the only difference are get_eeg_names and sampling_rate
case BoardIds::NOTION_1_BOARD:
board = std::shared_ptr<Board> (new NotionOSC (params));
board = std::shared_ptr<Board> (new NotionOSC (board_id, params));
break;
case BoardIds::NOTION_2_BOARD:
board = std::shared_ptr<Board> (new NotionOSC (params));
board = std::shared_ptr<Board> (new NotionOSC (board_id, params));
break;
case BoardIds::CROWN_BOARD:
board = std::shared_ptr<Board> (new NotionOSC (params));
board = std::shared_ptr<Board> (new NotionOSC (board_id, params));
break;
case BoardIds::IRONBCI_BOARD:
board = std::shared_ptr<Board> (new IronBCI (params));
Expand Down
2 changes: 1 addition & 1 deletion src/board_controller/neurosity/inc/notion_osc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NotionOSC : public Board
void handle_packet (double *package, const OSCPP::Server::Packet &packet);

public:
NotionOSC (struct BrainFlowInputParams params);
NotionOSC (int board_id, struct BrainFlowInputParams params);
~NotionOSC ();

int prepare_session ();
Expand Down
3 changes: 1 addition & 2 deletions src/board_controller/neurosity/notion_osc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <iostream>


NotionOSC::NotionOSC (struct BrainFlowInputParams params)
: Board ((int)BoardIds::NOTION_1_BOARD, params)
NotionOSC::NotionOSC (int board_id, struct BrainFlowInputParams params) : Board (board_id, params)
{
socket = NULL;
keep_alive = false;
Expand Down
Loading

0 comments on commit 8382329

Please sign in to comment.