Skip to content

Commit

Permalink
Removed debugging statements and updated macros to constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak031 committed Jul 2, 2024
1 parent ece5cf6 commit 822c88a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 56 deletions.
76 changes: 27 additions & 49 deletions src/board_controller/brainalive/brainalive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,15 @@
#include "get_dll_dir.h"
#include "timestamp.h"

// common constants
#define BRAINALIVE_PACKET_SIZE 220
#define BRAINALIVE_SINGLE_PACKET_SIZE 44
#define NUM_OF_PACKETS BRAINALIVE_TOTAL_PACKET_SIZE / BRAINALIVE_SINGLE_PACKET_SIZE

#define BRAINALIVE_PACKET_ID_INDEX (BRAINALIVE_SINGLE_PACKET_SIZE - 3)

#define BRAINALIVE_EEG_DATA_SIZE 24
#define BRAINALIVE_EEG_DATA_START_INDEX 4
#define BRAINALIVE_EEG_DATA_END_INDEX (BRAINALIVE_EEG_DATA_START_INDEX + BRAINALIVE_EEG_DATA_SIZE)

#define BRAINALIVE_ACCLR_MTR_DATA_SIZE 12
#define BRAINALIVE_ACCLR_MTR_DATA_START_INDEX BRAINALIVE_EEG_DATA_END_INDEX
#define BRAINALIVE_ACCLR_MTR_DATA_END_INDEX \
BRAINALIVE_ACCLR_MTR_DATA_START_INDEX + BRAINALIVE_ACCLR_MTR_DATA_SIZE
#define BRAINALIVE_HANDSHAKING_PACKET_SIZE 6
#define FSR_Value 8388607

// info about services and chars
#define START_BYTE 0x0A
#define STOP_BYTE 0x0D
#define BRAINALIVE_HANDSHAKING_PACKET_SIZE 6
static int software_gain, hardware_gain, reffrence_volatage;

#define BRAINALIVE_WRITE_CHAR "0000fe41-8e22-4541-9d4c-21edae82ed19"
#define BRAINALIVE_NOTIFY_CHAR "0000fe42-8e22-4541-9d4c-21edae82ed19"

// info for equations
#define BRAINALIVE_EEG_SCALE_FACTOR 0.0476837158203125
#define BRAINALIVE_EEG_GAIN_VALUE 12


static void brainalive_adapter_1_on_scan_found (
simpleble_adapter_t adapter, simpleble_peripheral_t peripheral, void *board)
Expand All @@ -44,7 +24,14 @@ static void brainalive_adapter_1_on_scan_found (
static void brainalive_read_notifications (simpleble_uuid_t service,
simpleble_uuid_t characteristic, uint8_t *data, size_t size, void *board)
{
((BrainAlive *)(board))->read_data (service, characteristic, data, size, 0);
if (size == BRAINALIVE_HANDSHAKING_PACKET_SIZE)
{
software_gain = data[1];
hardware_gain = data[2];
reffrence_volatage = (data[3] << 8) | data[4];
}
else
((BrainAlive *)(board))->read_data (service, characteristic, data, size, 0);
}

BrainAlive::BrainAlive (struct BrainFlowInputParams params)
Expand Down Expand Up @@ -386,45 +373,36 @@ void BrainAlive::adapter_1_on_scan_found (
void BrainAlive::read_data (simpleble_uuid_t service, simpleble_uuid_t characteristic,
uint8_t *data, size_t size, int channel_num)
{
static int SOFTWARE_GAIN, HARDWARE_GAIN, REFFRENCE_VOLTAGE;
if (size == BRAINALIVE_HANDSHAKING_PACKET_SIZE)
{
// printf ("inside 6\n");
SOFTWARE_GAIN = data[1];
HARDWARE_GAIN = data[2];
REFFRENCE_VOLTAGE = (data[3] << 8) | data[4];
}
else if (size != BRAINALIVE_PACKET_SIZE)
if (size == brainalive_packet_size)
{
safe_logger (spdlog::level::warn, "unknown size of BrainAlive Data {}", size);
return;
}
else
{

for (int i = 0; i < (int)size; i += BRAINALIVE_SINGLE_PACKET_SIZE)
for (int i = 0; i < (int)size; i += brainalive_single_packet_size)
{
double ba_data[15] = {0};
double ba_data[ba_brainflow_package_size] = {0};
int k = 0;
for (int j = i + BRAINALIVE_EEG_DATA_START_INDEX; j < i + BRAINALIVE_EEG_DATA_END_INDEX;
for (int j = i + brainalive_eeg_Start_index; j < i + brainalive_eeg_end_index;
j += 3, k++)
{
ba_data[k] = (float)(((data[j] << 16 | data[j + 1] << 8 | data[j + 2]) << 8) >> 8) *
((((float)REFFRENCE_VOLTAGE * 1000) /
(float)(SOFTWARE_GAIN * HARDWARE_GAIN * FSR_Value)));
// printf ("%f,", ba_data[k]);
((((float)reffrence_volatage * 1000) /
(float)(software_gain * hardware_gain * FSR_Value)));
}
for (int j = i + BRAINALIVE_ACCLR_MTR_DATA_START_INDEX;
j < i + BRAINALIVE_ACCLR_MTR_DATA_END_INDEX; j += 2, k++)
for (int j = i + brainalive_axl_start_index; j < i + brainalive_axl_end_index;
j += 2, k++)
{
ba_data[k] = (data[j] << 8) | data[j + 1];
if (ba_data[k] > 32767)
ba_data[k] = ba_data[k] - 65535;
// printf ("%f,", ba_data[k]);
}
ba_data[14] = data[BRAINALIVE_PACKET_ID_INDEX + i];
// printf ("%f\n", ba_data[14]);
ba_data[14] = data[brainalive_packet_index + i];
ba_data[15] = data[(brainalive_packet_index + 1) + i];
ba_data[16] = get_timestamp ();

push_package (&ba_data[0]);
}
}
else
{
safe_logger (spdlog::level::warn, "unknown size of BrainAlive Data {}", size);
return;
}
}
19 changes: 19 additions & 0 deletions src/board_controller/brainalive/inc/brainalive.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ class BrainAlive : public BLELibBoard
void read_data (simpleble_uuid_t service, simpleble_uuid_t characteristic, uint8_t *data,
size_t size, int channel_num);

// common constants
static constexpr int brainalive_packet_size = 220;
static constexpr int brainalive_single_packet_size = 44;
static constexpr int num_of_packets = brainalive_packet_size / brainalive_single_packet_size;

static constexpr int brainalive_packet_index = (brainalive_single_packet_size - 3);

static constexpr int brainalive_eeg_data_szie = 24;
static constexpr int brainalive_eeg_Start_index = 4;
static constexpr int brainalive_eeg_end_index =
(brainalive_eeg_Start_index + brainalive_eeg_data_szie);

static constexpr int brainalive_axl_gyro_data_size = 12;
static constexpr int brainalive_axl_start_index = brainalive_eeg_end_index;
static constexpr int brainalive_axl_end_index =
brainalive_axl_start_index + brainalive_axl_gyro_data_size;
static constexpr int FSR_Value = 8388607;
static constexpr int ba_brainflow_package_size = 17;

protected:
volatile simpleble_adapter_t brainalive_adapter;
volatile simpleble_peripheral_t brainalive_peripheral;
Expand Down
13 changes: 6 additions & 7 deletions src/board_controller/brainflow_boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,14 @@ BrainFlowBoards::BrainFlowBoards()
{
{"name", "BrainAlive"},
{"sampling_rate", 250},
{"package_num_channel", 14},
{"marker_channel", 15},
{"timestamp_channel", 16},
{"marker_channel", 17},
{"package_num_channel", 0},
{"num_rows", 18},
{"eeg_channels", {1, 2, 3, 4, 5, 6, 7, 8}},
{"num_rows", 17},
{"eeg_channels", {0, 1, 2, 3, 4, 5, 6, 7}},
{"eeg_names", "F7,FT7,T7,CP5,CZ,C6,FC6,F4"},
{"accel_channels", {9, 10, 11}},
{"gyro_channels", {12, 13, 14}},
{"packet_id", {15}}
{"accel_channels", {8, 9, 10}},
{"gyro_channels", {11, 12, 13}}
};
brainflow_boards_json["boards"]["41"]["default"] =
{
Expand Down

0 comments on commit 822c88a

Please sign in to comment.