Skip to content

Commit

Permalink
log methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Preumont committed Jul 24, 2023
1 parent e6c9681 commit 62b63c5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
49 changes: 48 additions & 1 deletion nodejs_package/brainflow/board-shim.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import _ from 'lodash';
import * as os from 'os';
import koffi from 'koffi';
import { BoardIds, IInputParams, IpProtocolTypes, BrainFlowPresets, BrainFlowExitCodes } from './brainflow.types';
import {
BoardIds,
IInputParams,
IpProtocolTypes,
BrainFlowPresets,
BrainFlowExitCodes,
LogLevels,
} from './brainflow.types';
import { BoardControllerCLikeFunctions as CLike, BoardControllerFunctions } from './functions.types';

class BrainFlowInputParams {
Expand Down Expand Up @@ -61,6 +68,11 @@ class BoardControllerDLL extends BoardControllerFunctions {
this.getSamplingRate = this.lib.func(CLike.get_sampling_rate);
this.getEegChannels = this.lib.func(CLike.get_eeg_channels);
this.addStreamer = this.lib.func(CLike.add_streamer);
this.deleteStreamer = this.lib.func(CLike.delete_streamer);
this.insertMarker = this.lib.func(CLike.insert_marker);
this.setLogLevelBoardController = this.lib.func(CLike.set_log_level_board_controller);
this.setLogFileBoardController = this.lib.func(CLike.set_log_file_board_controller);
this.logMessageBoardController = this.lib.func(CLike.log_message_board_controller);
}

private getDLLPath() {
Expand Down Expand Up @@ -122,6 +134,41 @@ export class BoardShim {
}
}

public deleteStreamer(streamerParams: string, preset = BrainFlowPresets.DEFAULT_PRESET): void {
const res = this.boardController.deleteStreamer(streamerParams, preset, this.boardId, this.inputJson);
if (res !== BrainFlowExitCodes.STATUS_OK) {
throw new Error('Could not delete streamer');
}
}

public insertMarker(value: number, preset = BrainFlowPresets.DEFAULT_PRESET): void {
const res = this.boardController.insertMarker(value, preset, this.boardId, this.inputJson);
if (res !== BrainFlowExitCodes.STATUS_OK) {
throw new Error('Could not insert marker');
}
}

public setLogLevel(logLevel: LogLevels): void {
const res = this.boardController.setLogLevelBoardController(logLevel);
if (res !== BrainFlowExitCodes.STATUS_OK) {
throw new Error('Could not set log level properly');
}
}

public setLogFile(file: string): void {
const res = this.boardController.setLogFileBoardController(file);
if (res !== BrainFlowExitCodes.STATUS_OK) {
throw new Error('Could not redirect to log file');
}
}

public logMessage(logLevel: LogLevels, message: string): void {
const res = this.boardController.logMessageBoardController(logLevel, message);
if (res !== BrainFlowExitCodes.STATUS_OK) {
throw new Error('Could not writte message');
}
}

public prepareSession(): void {
const res = this.boardController.prepareSession(this.boardId, this.inputJson);
if (res !== BrainFlowExitCodes.STATUS_OK) {
Expand Down
10 changes: 10 additions & 0 deletions nodejs_package/brainflow/brainflow.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ export enum BrainFlowPresets {
ANCILLARY_PRESET = 2,
}

export enum LogLevels {
LEVEL_TRACE = 0,
LEVEL_DEBUG = 1,
LEVEL_INFO = 2,
LEVEL_WARN = 3,
LEVEL_ERROR = 4,
LEVEL_CRITICAL = 5,
LEVEL_OFF = 6,
}

// --------------------------- //
// II. DataFilter enums
// --------------------------- //
Expand Down
22 changes: 19 additions & 3 deletions nodejs_package/brainflow/functions.types.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { BoardIds, BrainFlowExitCodes, BrainFlowPresets } from './brainflow.types';
import { BoardIds, BrainFlowExitCodes, BrainFlowPresets, LogLevels } from './brainflow.types';

// --------------------------- //
// C++ Functions
// --------------------------- //

// c-like prototype strings
export enum BoardControllerCLikeFunctions {
// Simple methods:
start_stream = 'int start_stream (int buffer_size, const char *streamer_params, int board_id, const char *json_brainflow_input_params)',
stop_stream = 'int stop_stream (int board_id, const char *json_brainflow_input_params)',
prepare_session = 'int prepare_session (int board_id, const char *json_brainflow_input_params)',
release_all_sessions = 'int release_all_sessions ()',
release_session = 'int release_session (int board_id, const char *json_brainflow_input_params)',
add_streamer = 'int add_streamer (const char *streamer, int preset, int board_id, const char *json_brainflow_input_params)',
delete_streamer = 'int delete_streamer (const char *streamer, int preset, int board_id, const char *json_brainflow_input_params)',
insert_marker = 'int insert_marker (double value, int preset, int board_id, const char *json_brainflow_input_params)',
set_log_level_board_controller = 'int set_log_level_board_controller (int log_level)',
set_log_file_board_controller = 'int set_log_file_board_controller (const char *log_file)',
log_message_board_controller = 'int log_message_board_controller (int log_level, char *log_message)',

// '_Inout_' pointer -> dual input/output parameter.
// Methods with '_Inout_' pointer -> dual input/output parameter:
is_prepared = 'int is_prepared (_Inout_ int *prepared, int board_id, const char *json_brainflow_input_params)',
get_board_data_count = 'int get_board_data_count (int preset, _Inout_ int *result, int board_id, const char *json_brainflow_input_params)',
get_board_data = 'int get_board_data (int data_count, int preset, _Inout_ double *data_buf, int board_id, const char *json_brainflow_input_params)',
Expand All @@ -30,6 +36,16 @@ export class BoardControllerFunctions {
boardId: BoardIds,
inputJson: string,
) => BrainFlowExitCodes;
deleteStreamer!: (
streamer: string,
preset: BrainFlowPresets,
boardId: BoardIds,
inputJson: string,
) => BrainFlowExitCodes;
insertMarker!: (value: number, preset: BrainFlowPresets, boardId: BoardIds, inputJson: string) => BrainFlowExitCodes;
setLogLevelBoardController!: (logLevel: LogLevels) => BrainFlowExitCodes;
setLogFileBoardController!: (logFile: string) => BrainFlowExitCodes;
logMessageBoardController!: (logLevel: LogLevels, logMessage: string) => BrainFlowExitCodes;
isPrepared!: (prepared: number[], boardId: BoardIds, inputJson: string) => BrainFlowExitCodes;
prepareSession!: (boardId: BoardIds, inputJson: string) => BrainFlowExitCodes;
startStream!: (
Expand Down Expand Up @@ -73,7 +89,7 @@ export class BoardControllerFunctions {
}

export enum DataHandlerCLikeFunctions {
// '_Inout_' pointer -> dual input/output parameter.
// Methods with '_Inout_' pointer -> dual input/output parameter:
get_railed_percentage = 'int get_railed_percentage (double *raw_data, int data_len, int gain, _Inout_ double *output)',
}

Expand Down

0 comments on commit 62b63c5

Please sign in to comment.