Skip to content

Commit 4cd841e

Browse files
committed
Merge remote-tracking branch 'openbci/master'
2 parents df123cf + 54d3d66 commit 4cd841e

4 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/board_controller/openbci/ganglion_bglib/callbacks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void ble_evt_attclient_find_information_found (
188188

189189
void ble_evt_attclient_attribute_value (const struct ble_msg_attclient_attribute_value_evt_t *msg)
190190
{
191-
if ((int)msg->value.len >= 18)
191+
if (((int)msg->value.len >= 18) && ((int)msg->value.len <= 20))
192192
{
193193
unsigned char values[20] = {0};
194194
memcpy (values, msg->value.data, msg->value.len * sizeof (unsigned char));

src/board_controller/openbci/ganglion_bglib/helpers.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define FIRST_HANDLE 0x0001
2020
#define LAST_HANDLE 0xffff
2121

22+
2223
namespace GanglionLib
2324
{
2425
extern volatile int exit_code;
@@ -27,8 +28,8 @@ namespace GanglionLib
2728
extern volatile uint16 client_char_handle;
2829
extern char uart_port[1024];
2930
extern volatile State state;
30-
extern std::mutex m;
3131
extern std::condition_variable cv;
32+
std::mutex mutex;
3233

3334
void output (uint8 len1, uint8 *data1, uint16 len2, uint8 *data2)
3435
{
@@ -41,7 +42,9 @@ namespace GanglionLib
4142
// reads messages and calls required callbacks (copypaste from sample)
4243
int read_message (int timeout_ms)
4344
{
44-
unsigned char data[256]; // enough for BLE
45+
std::lock_guard<std::mutex> lock (mutex);
46+
47+
unsigned char *data = NULL;
4548
struct ble_header hdr;
4649
int r;
4750

@@ -57,10 +60,12 @@ namespace GanglionLib
5760
}
5861
if (hdr.lolen)
5962
{
63+
data = new unsigned char[hdr.lolen];
6064
r = uart_rx (hdr.lolen, data, UART_TIMEOUT);
6165
if (r <= 0)
6266
{
6367
exit_code = (int)GanglionLib::PORT_OPEN_ERROR;
68+
delete[] data;
6469
return 1; // fails to read
6570
}
6671
}
@@ -70,11 +75,12 @@ namespace GanglionLib
7075
if (!msg)
7176
{
7277
exit_code = (int)GanglionLib::GENERAL_ERROR;
78+
delete[] data;
7379
return 1;
7480
}
7581

7682
msg->handler (data);
77-
83+
delete[] data;
7884
return 0;
7985
}
8086

src/board_controller/openbci/ganglion_bglib/main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <chrono>
22
#include <ctype.h>
3-
#include <mutex>
43
#include <queue>
54
#include <stdlib.h>
65
#include <string.h>
@@ -28,11 +27,10 @@ namespace GanglionLib
2827
volatile uint16 client_char_handle = 0;
2928
volatile State state =
3029
State::NONE; // same callbacks are triggered by different methods we need to differ them
30+
volatile bool should_stop_stream = true;
3131

3232
bool initialized = false;
33-
std::mutex mutex;
3433
std::thread read_characteristic_thread;
35-
bool should_stop_stream = true;
3634

3735
void read_characteristic_worker ()
3836
{

src/board_controller/openbci/ganglion_bglib/uart.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Bluegigas Bluetooth Smart Demo Application
2+
// Bluegigas Bluetooth Smart Demo Application
33
// Contact: support@bluegiga.com.
44
//
55
// This is free software distributed under the terms of the MIT license reproduced below.
@@ -179,7 +179,7 @@ int uart_tx (int len, unsigned char *data)
179179
return -1;
180180
}
181181
len -= written;
182-
data += len;
182+
data += written;
183183
}
184184

185185
return 0;
@@ -213,7 +213,7 @@ int uart_rx (int len, unsigned char *data, int timeout_ms)
213213
return 0;
214214
}
215215
len -= rread;
216-
data += len;
216+
data += rread;
217217
}
218218

219219
return l;
@@ -296,7 +296,7 @@ int uart_tx (int len, unsigned char *data)
296296
return -1;
297297
}
298298
len -= written;
299-
data += len;
299+
data += written;
300300
}
301301

302302
return 0;
@@ -325,7 +325,7 @@ int uart_rx (int len, unsigned char *data, int timeout_ms)
325325
return -1;
326326
}
327327
len -= rread;
328-
data += len;
328+
data += rread;
329329
}
330330

331331
return l;

0 commit comments

Comments
 (0)