Skip to content

Commit

Permalink
Merge remote-tracking branch 'openbci/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey1994 committed Mar 27, 2020
2 parents a292a3a + 4e246c1 commit 3fa1bd7
Show file tree
Hide file tree
Showing 28 changed files with 194 additions and 113 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ add_library (
target_include_directories (
${BRAINFLOW_CPP_BINDING_NAME} PRIVATE
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc
${CMAKE_HOME_DIRECTORY}/src/utils/inc
${CMAKE_HOME_DIRECTORY}/src/data_handler/inc
${CMAKE_HOME_DIRECTORY}/cpp-package/src/inc
${CMAKE_HOME_DIRECTORY}/third_party/json
Expand All @@ -261,6 +262,7 @@ if (MSVC)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_controller.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_controller.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_info_getter.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_info_getter.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/third_party/neurosdk/lib/${NEUROSDK_LIB_NAME}.dll" "${CMAKE_HOME_DIRECTORY}/csharp-package/brainflow/brainflow/lib/${NEUROSDK_LIB_NAME}.dll"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/third_party/neurosdk/lib/${NEUROSDK_LIB_NAME}.dll" "${CMAKE_HOME_DIRECTORY}/python-package/brainflow/lib/${NEUROSDK_LIB_NAME}.dll"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/third_party/neurosdk/lib/${NEUROSDK_LIB_NAME}.dll" "${CMAKE_HOME_DIRECTORY}/java-package/brainflow/src/main/resources/${NEUROSDK_LIB_NAME}.dll"
Expand All @@ -274,6 +276,7 @@ if (MSVC)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/$<CONFIG>/${DATA_HANDLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/lib/${DATA_HANDLER_COMPILED_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/data_handler/inc/data_handler.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/data_handler.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
)
endif (MSVC)
if (UNIX)
Expand All @@ -284,6 +287,7 @@ if (UNIX)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${BOARD_CONTROLLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/csharp-package/brainflow/brainflow/${BOARD_CONTROLLER_COMPILED_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_controller.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_controller.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_info_getter.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_info_getter.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${BOARD_CONTROLLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/lib/${BOARD_CONTROLLER_COMPILED_NAME}"
)
Expand All @@ -294,6 +298,7 @@ if (UNIX)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${DATA_HANDLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/csharp-package/brainflow/brainflow/lib/${DATA_HANDLER_COMPILED_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/data_handler/inc/data_handler.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/data_handler.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${DATA_HANDLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/lib/${DATA_HANDLER_COMPILED_NAME}"
)
endif (UNIX)
Expand Down Expand Up @@ -343,6 +348,7 @@ install (
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_info_getter.h
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_input_params.h
${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export.h
${CMAKE_HOME_DIRECTORY}/src/data_handler/inc/data_handler.h
${CMAKE_HOME_DIRECTORY}/cpp-package/src/inc/data_filter.h
${CMAKE_HOME_DIRECTORY}/cpp-package/src/inc/board_shim.h
Expand Down
1 change: 1 addition & 0 deletions cpp-package/src/board_shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ std::string params_to_string (struct BrainFlowInputParams params)
j["ip_address"] = params.ip_address;
j["mac_address"] = params.mac_address;
j["other_info"] = params.other_info;
j["timeout"] = params.timeout;
std::string post_str = j.dump ();
return post_str;
}
Expand Down
6 changes: 6 additions & 0 deletions csharp-package/brainflow/brainflow/brainflow_input_params.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class BrainFlowInputParams
/// </summary>
[DataMember]
public string other_info;
/// <summary>
/// timeout for device discovery or connection
/// </summary>
[DataMember]
public int timeout;

public BrainFlowInputParams ()
{
Expand All @@ -58,6 +63,7 @@ public BrainFlowInputParams ()
ip_port = 0;
ip_protocol = (int)IpProtocolType.NONE;
other_info = "";
timeout = 0;
}

public string to_json ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ static int parse_args (string[] args, BrainFlowInputParams input_params)
{
board_id = Convert.ToInt32 (args[i + 1]);
}
if (args[i].Equals("--timeout"))
{
input_params.timeout = Convert.ToInt32(args[i + 1]);
}
}
return board_id;
}
Expand Down
10 changes: 7 additions & 3 deletions docs/BuildBrainFlow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ You are able to download jar files directly from `release page <https://github.c
Matlab
--------

To use Matlab binding you HAVE to build core module first.
After compilation of core module you will be able to open brainflow/matlab-package/brainflow folder in Matlab IDE, add examples folder to Matlab's path and run them.
Steps to setup Matlab binding for BrainFlow:

Compilation of Core module and C++ binding
- Compile Core Module, using instructions below
- Open Matlab IDE and open brainflow/matlab-package/brainflow folder there
- Add folders lib and inc to Matlab path
- If you want to run Matlab scripts from folders different than brainflow/matlab-package/brainflow you need to add it to your Matlab path too

Compilation of Core Module and C++ Binding
-------------------------------------------

Windows
Expand Down
22 changes: 12 additions & 10 deletions docs/SupportedBoards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Supported Boards
To create an instance of BoardShim class for your board check required inputs in the table below:

.. csv-table:: Required inputs
:header: "Board", "Board Id", "BrainFlowInputParams.serial_port", "BrainFlowInputParams.mac_address", "BrainFlowInputParams.ip_address", "BrainFlowInputParams.ip_port", "BrainFlowInputParams.ip_protocol", "BrainFlowInputParams.other_info"
:header: "Board", "Board Id", "BrainFlowInputParams.serial_port", "BrainFlowInputParams.mac_address", "BrainFlowInputParams.ip_address", "BrainFlowInputParams.ip_port", "BrainFlowInputParams.ip_protocol", "BrainFlowInputParams.other_info", "BrainFlowInputParams.timeout"

"Streaming Board", "BoardIds.STREAMING_BOARD (-2)", "-", "-", "multicast IP address", "port", "-", "Board Id of master board"
"Synthetic Board", "BoardIds.SYNTHETIC_BOARD (-1)", "-", "-", "-", "-", "-", "-"
"Cyton", "BoardIds.CYTON_BOARD (0)", "dongle serial port(COM3, /dev/ttyUSB0, /dev/cu.usbserial-xxxxxx...)", "-", "-", "-", "-", "-"
"Ganglion", "BoardIds.GANGLION_BOARD (1)", "dongle serial port(COM3, /dev/ttyUSB0...)", "Optional: Ganglion's MAC address", "-", "-", "-", "-"
"Cyton Daisy", "BoardIds.CYTON_DAISY_BOARD (2)", "dongle serial port(COM3, /dev/ttyUSB0, /dev/cu.usbserial-xxxxxx...)", "-", "-", "-", "-", "-"
"Ganglion Wifi", "BoardIds.GANGLION_WIFI_BOARD (4)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
"Cyton Wifi", "BoardIds.CYTON_WIFI_BOARD (5)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
"Cyton Daisy Wifi", "BoardIds.CYTON_DAISY_WIFI_BOARD (6)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-"
"BrainBit", "BoardIds.BRAINBIT_BOARD (7)", "-", "-", "-", "-", "-", "Serial Number of BrainBit device"
"Streaming Board", "BoardIds.STREAMING_BOARD (-2)", "-", "-", "multicast IP address", "port", "-", "Board Id of master board", "-"
"Synthetic Board", "BoardIds.SYNTHETIC_BOARD (-1)", "-", "-", "-", "-", "-", "-", "-"
"Cyton", "BoardIds.CYTON_BOARD (0)", "dongle serial port(COM3, /dev/ttyUSB0, /dev/cu.usbserial-xxxxxx...)", "-", "-", "-", "-", "-", "-"
"Ganglion", "BoardIds.GANGLION_BOARD (1)", "dongle serial port(COM3, /dev/ttyUSB0...)", "Optional: Ganglion's MAC address", "-", "-", "-", "-", "Timeout for device discovery(default 15sec)"
"Cyton Daisy", "BoardIds.CYTON_DAISY_BOARD (2)", "dongle serial port(COM3, /dev/ttyUSB0, /dev/cu.usbserial-xxxxxx...)", "-", "-", "-", "-", "-", "-"
"Ganglion Wifi", "BoardIds.GANGLION_WIFI_BOARD (4)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-", "-"
"Cyton Wifi", "BoardIds.CYTON_WIFI_BOARD (5)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-", "-"
"Cyton Daisy Wifi", "BoardIds.CYTON_DAISY_WIFI_BOARD (6)", "-", "-", "Wifi Shield IP(default 192.168.4.1)", "any local port which is free", "-", "-", "-"
"BrainBit", "BoardIds.BRAINBIT_BOARD (7)", "-", "-", "-", "-", "-", "Serial Number of BrainBit device", "Timeout for device discovery(default 15sec)"


Streaming Board
Expand Down Expand Up @@ -136,6 +136,7 @@ To choose this board in BoardShim constructor please specify:
- board_id: 1
- serial_port field of BrainFlowInputParams structure
- mac_address field of BrainFlowInputParams structure, if its empty BrainFlow will try to autodiscover Ganglion
- optional: timeout field of BrainFlowInputParams structure, default is 15sec

To get Ganglion's MAC address you can use:

Expand Down Expand Up @@ -297,6 +298,7 @@ To choose this board in BoardShim constructor please specify:

- board_id: 7
- other_info field of BrainFlowInputParams structure should contain Serial Number of BrainBit device
- optional: timeout field of BrainFlowInputParams structure, default is 15sec

Supported platforms:

Expand Down
6 changes: 6 additions & 0 deletions docs/UserAPI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ Matlab API Reference
----------------------

Matlab binding calls C\C++ code as any other binding, it's not compatible with Octave. Use our code samples as a reference for Matlab API.

A few general rules to keep in mind:

- Use char arrays instead strings to work with BrainFlow API, it means 'my_string' instead "my_string", otherwise you will get calllib error
- Use int32 values intead enums, it means int32 (BoardIDs.SYNTHETIC_BOARD) instead BoardIDs.SYNTHETIC_BOARD, the same is true for all enums in BrainFlow API

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class BrainFlowInputParams
public int ip_port;
public int ip_protocol;
public String other_info;
public int timeout;

public BrainFlowInputParams ()
{
Expand All @@ -22,6 +23,7 @@ public BrainFlowInputParams ()
ip_port = 0;
ip_protocol = IpProtocolType.NONE.get_code ();
other_info = "";
timeout = 0;
}

public String to_json ()
Expand Down Expand Up @@ -88,4 +90,14 @@ public void set_other_info (String other_info)
{
this.other_info = other_info;
}

public void set_timeout (int timeout)
{
this.timeout = timeout;
}

public int get_timeout ()
{
return timeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ private static int parse_args (String[] args, BrainFlowInputParams params)
{
board_id = Integer.parseInt (args[i + 1]);
}
if (args[i].equals ("--timeout"))
{
params.timeout = Integer.parseInt (args[i + 1]);
}
}
return board_id;
}
Expand Down
6 changes: 3 additions & 3 deletions matlab-package/brainflow/BoardShim.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
function lib_name = load_lib ()
if ispc
if not (libisloaded ('BoardController'))
loadlibrary ('./lib/BoardController.dll', './inc/board_controller.h', 'includepath', './inc', 'addheader', 'board_info_getter');
loadlibrary ('BoardController.dll', 'board_controller.h', 'addheader', 'board_info_getter');
end
lib_name = 'BoardController';
elseif ismac
if not (libisloaded ('libBoardController'))
loadlibrary ('./lib/libBoardController.dylib', './inc/board_controller.h', 'includepath', './inc', 'addheader', 'board_info_getter');
loadlibrary ('libBoardController.dylib', 'board_controller.h', 'addheader', 'board_info_getter');
end
lib_name = 'libBoardController';
elseif isunix
if not (libisloaded ('libBoardController'))
loadlibrary ('./liblibBoardController.so', './inc/board_controller.h', 'includepath', './inc', 'addheader', 'board_info_getter');
loadlibrary ('libBoardController.so', 'board_controller.h', 'addheader', 'board_info_getter');
end
lib_name = 'libBoardController';
else
Expand Down
2 changes: 2 additions & 0 deletions matlab-package/brainflow/BrainFlowInputParams.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ip_port
ip_protocol
other_info
timeout
end
methods
function obj = BrainFlowInputParams ()
Expand All @@ -15,6 +16,7 @@
obj.ip_port = 0;
obj.ip_protocol = int32 (IpProtocolType.NONE);
obj.other_info = '';
obj.timeout = 0;
end
function json_string = to_json (obj)
json_string = jsonencode(obj);
Expand Down
6 changes: 3 additions & 3 deletions matlab-package/brainflow/DataFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
function lib_name = load_lib ()
if ispc
if not (libisloaded ('DataHandler'))
loadlibrary ('./lib/DataHandler.dll', './inc/data_handler.h', 'includepath', './inc');
loadlibrary ('DataHandler.dll', 'data_handler.h');
end
lib_name = 'DataHandler';
elseif ismac
if not (libisloaded ('libDataHandler'))
loadlibrary ('./lib/libDataHandler.dylib', './inc/data_handler.h', 'includepath', './inc');
loadlibrary ('libDataHandler.dylib', 'data_handler.h');
end
lib_name = 'libDataHandler';
elseif isunix
if not (libisloaded ('libDataHandler'))
loadlibrary ('./lib/libDataHandler.so', './inc/data_handler.h', 'includepath', './inc');
loadlibrary ('libDataHandler.so', 'data_handler.h');
end
lib_name = 'libDataHandler';
else
Expand Down
1 change: 1 addition & 0 deletions python-package/brainflow/board_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__ (self):
self.ip_port = 0
self.ip_protocol = IpProtocolType.NONE.value
self.other_info = ''
self.timeout = 0

def to_json (self):
return json.dumps (self, default = lambda o: o.__dict__,
Expand Down
1 change: 1 addition & 0 deletions src/board_controller/board_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ int string_to_brainflow_input_params (
params->other_info = config["other_info"];
params->mac_address = config["mac_address"];
params->ip_address = config["ip_address"];
params->timeout = config["timeout"];
return STATUS_OK;
}
catch (json::exception &e)
Expand Down
9 changes: 1 addition & 8 deletions src/board_controller/inc/board_controller.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#pragma once

#ifdef _WIN32
#define SHARED_EXPORT __declspec(dllexport)
#define CALLING_CONVENTION __cdecl
#else
#define SHARED_EXPORT __attribute__ ((visibility ("default")))
#define CALLING_CONVENTION
#endif

#include "board_info_getter.h"
#include "brainflow_constants.h"
#include "shared_export.h"


#ifdef __cplusplus
Expand Down
8 changes: 1 addition & 7 deletions src/board_controller/inc/board_info_getter.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#pragma once

#ifdef _WIN32
#define SHARED_EXPORT __declspec(dllexport)
#define CALLING_CONVENTION __cdecl
#else
#define SHARED_EXPORT __attribute__ ((visibility ("default")))
#define CALLING_CONVENTION
#endif
#include "shared_export.h"

#ifdef __cplusplus
extern "C"
Expand Down
8 changes: 5 additions & 3 deletions src/board_controller/inc/brainflow_input_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct BrainFlowInputParams
int ip_port;
int ip_protocol;
std::string other_info;
int timeout;

BrainFlowInputParams ()
{
Expand All @@ -28,13 +29,14 @@ struct BrainFlowInputParams
ip_port = 0;
ip_protocol = (int)IpProtocolType::NONE;
other_info = "";
timeout = 0;
}

// default copy constructor and assignment operator are ok, need less operator to use in map
bool operator< (const struct BrainFlowInputParams &other) const
{
return std::tie (serial_port, mac_address, ip_address, ip_port, ip_protocol, other_info) <
std::tie (other.serial_port, other.mac_address, other.ip_address, other.ip_port,
other.ip_protocol, other.other_info);
return std::tie (serial_port, mac_address, ip_address, ip_port, ip_protocol, other_info,
timeout) < std::tie (other.serial_port, other.mac_address, other.ip_address,
other.ip_port, other.ip_protocol, other.other_info, timeout);
}
};
Loading

0 comments on commit 3fa1bd7

Please sign in to comment.