Skip to content

Commit

Permalink
Anonymous signals bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Nov 3, 2017
1 parent 3906944 commit 261098d
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 74 deletions.
4 changes: 2 additions & 2 deletions project_version.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=0.11.1
VERSION=0.11.2
VERSION_MAJOR=0
VERSION_MINOR=11
VERSION_STEP=1
VERSION_STEP=2
22 changes: 5 additions & 17 deletions src/metawear/impl/cpp/metawearboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,8 @@
#include "metawear/sensor/cpp/sensor_fusion_private.h"
#include "metawear/sensor/cpp/switch_private.h"

using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::chrono::system_clock;
using std::exception;
using std::forward_as_tuple;
using std::free;
using std::less;
using std::malloc;
using std::memcpy;
using std::piecewise_construct;
using std::sort;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using namespace std;
using namespace std::chrono;

const uint8_t CARTESIAN_FLOAT_SIZE= 6;
const uint16_t MAX_TIME_PER_RESPONSE= 4000;
Expand Down Expand Up @@ -803,8 +790,9 @@ static void read_sensor_fusion_config_completed(MblMwMetaWearBoard* board, int32
static void read_gyro_config_completed(MblMwMetaWearBoard* board, int32_t value) {
if (mbl_mw_metawearboard_lookup_module(board, MBL_MW_MODULE_SENSOR_FUSION) != MBL_MW_MODULE_TYPE_NA) {
mbl_mw_sensor_fusion_read_config(board, read_sensor_fusion_config_completed);
} else {
read_sensor_fusion_config_completed(board, MBL_MW_STATUS_OK);
}
read_sensor_fusion_config_completed(board, MBL_MW_STATUS_OK);
}

static void read_acc_config_completed(MblMwMetaWearBoard* board, int32_t value) {
Expand All @@ -818,4 +806,4 @@ static void read_acc_config_completed(MblMwMetaWearBoard* board, int32_t value)
void mbl_mw_metawearboard_create_anonymous_datasignals(MblMwMetaWearBoard* board, MblMwFnAnonSignalArray created) {
board->anon_signals_created = created;
mbl_mw_acc_read_config(board, read_acc_config_completed);
}
}
15 changes: 9 additions & 6 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def commandLogger(self, board, writeType, characteristic, command, length):
self.command= []
for i in range(0, length):
self.command.append(command[i])

self.full_history.append(self.command)
if (command[1] == 0x80):
if (self.boardType == TestMetaWearBase.METAWEAR_RG_BOARD and command[0] in self.metawear_rg_services):
Expand Down Expand Up @@ -359,12 +359,8 @@ def commandLogger(self, board, writeType, characteristic, command, length):
self.notify_mw_char(create_string_buffer(b'\x0b\x85\x9e\x01\x00\x00', 6))
response= None

def send_response():
self.notify_mw_char(self.pending_responses.get())

if (response != None):
self.pending_responses.put(response)
Timer(0.025, send_response).start()
self.schedule_response(response)

def sensorDataHandler(self, data):
if (data.contents.type_id == DataTypeId.UINT32):
Expand Down Expand Up @@ -421,6 +417,13 @@ def notify_mw_char(self, buffer):
bytes = cast(buffer, POINTER(c_ubyte))
return self.notify_handler(self.board, bytes, len(buffer.raw))

def schedule_response(self, response):
def send_response():
self.notify_mw_char(self.pending_responses.get())

self.pending_responses.put(response)
Timer(0.020, send_response).start()

def to_string_buffer(bytes):
buffer= create_string_buffer(len(bytes))
i= 0
Expand Down
130 changes: 81 additions & 49 deletions test/test_anonymous_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ def commandLogger(self, board, writeType, characteristic, command, length):

if (prev != curr):
if (command[0] == 0x03 and command[1] == 0x83):
self.notify_mw_char(to_string_buffer([0x03, 0x83, 40, 8]))
response = to_string_buffer([0x03, 0x83, 40, 8])
elif (command[0] == 0x13 and command[1] == 0x83):
self.notify_mw_char(to_string_buffer([0x13, 0x83, 40, 3]))
elif(command[0] == 0x19 and command[1] == 0x83):
self.notify_mw_char(to_string_buffer([0x19, 0x82, 0x1, 0xf]))
response = to_string_buffer([0x13, 0x83, 40, 3])
elif(command[0] == 0x19 and command[1] == 0x82):
response = to_string_buffer([0x19, 0x82, 0x1, 0xf])
else:
response = None

if (response != None):
self.schedule_response(response)

def sync_loggers(self):
event = Event()
Expand All @@ -46,11 +51,14 @@ def commandLogger(self, board, writeType, characteristic, command, length):
if (prev != curr):
if (command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x60])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x24]))
response = to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x24])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])

if (response != None):
self.schedule_response(response)

def test_sync_loggers(self):
self.assertEqual(self.result['length'], 1)
Expand All @@ -74,9 +82,12 @@ def commandLogger(self, board, writeType, characteristic, command, length):
if (prev != curr):
if (command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x22]))
response = to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x22])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])

if (response != None):
self.schedule_response(response)

def test_sync_loggers(self):
self.assertEqual(self.result['length'], 1)
Expand Down Expand Up @@ -107,15 +118,18 @@ def commandLogger(self, board, writeType, characteristic, command, length):
if (prev != curr):
if (command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x60])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x60])
elif (command[2] == 0x02):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x24]))
response = to_string_buffer([0x0b, 0x82, 0x03, 0x04, 0xff, 0x24])
elif (command[2] == 0x03):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x24]))
response = to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x24])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])

if (response != None):
self.schedule_response(response)

def test_sync_loggers(self):
self.assertEqual(self.result['length'], 2)
Expand All @@ -140,24 +154,28 @@ def commandLogger(self, board, writeType, characteristic, command, length):
curr = len(self.full_history)

if (prev != curr):
response = None
if (command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x02, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x02, 0x60])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0xc4, 0x03, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0xc4, 0x03, 0x60])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])
elif (command[0] == 0x9 and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x09, 0x82, 0x03, 0x04, 0xff, 0xa0, 0x07, 0xa5, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
response = to_string_buffer([0x09, 0x82, 0x03, 0x04, 0xff, 0xa0, 0x07, 0xa5, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x09, 0x82, 0x09, 0x03, 0x00, 0x20, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
response = to_string_buffer([0x09, 0x82, 0x09, 0x03, 0x00, 0x20, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
elif (command[2] == 0x02):
self.notify_mw_char(to_string_buffer([0x09, 0x82, 0x09, 0x03, 0x01, 0x60, 0x08, 0x13, 0x30, 0x75, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
response = to_string_buffer([0x09, 0x82, 0x09, 0x03, 0x01, 0x60, 0x08, 0x13, 0x30, 0x75, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
elif (command[2] == 0x03):
self.notify_mw_char(to_string_buffer([0x09, 0x82, 0x09, 0x03, 0x01, 0x60, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
response = to_string_buffer([0x09, 0x82, 0x09, 0x03, 0x01, 0x60, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])

if (response != None):
self.schedule_response(response)

def test_sync_loggers(self):
self.assertEqual(self.result['length'], 2)
Expand Down Expand Up @@ -199,22 +217,26 @@ def commandLogger(self, board, writeType, characteristic, command, length):
curr = len(self.full_history)

if (prev != curr):
response = None
if (command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x60])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x64]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x64])
elif (command[2] == 0x02):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x68]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x68])
elif (command[2] == 0x03):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x6c]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x6c])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])
elif (command[0] == 0x9 and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x09, 0x82, 0x19, 0x07, 0xff, 0xe0, 0x08, 0x17, 0x14, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
response = to_string_buffer([0x09, 0x82, 0x19, 0x07, 0xff, 0xe0, 0x08, 0x17, 0x14, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])

if (response != None):
self.schedule_response(response)

def test_sync_loggers(self):
self.assertEqual(self.result['length'], 1)
Expand All @@ -234,13 +256,16 @@ def commandLogger(self, board, writeType, characteristic, command, length):
if (prev != curr):
if (command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x60])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x24]))
response = to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x24])
elif (command[2] == 0x02):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x22]))
response = to_string_buffer([0x0b, 0x82, 0x13, 0x05, 0xff, 0x22])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])

if (response != None):
self.schedule_response(response)

def test_sync_loggers(self):
self.assertEqual(self.result['length'], 2)
Expand All @@ -257,15 +282,18 @@ def commandLogger(self, board, writeType, characteristic, command, length):
if (prev != curr):
if (command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x00, 0x20]))
response = to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x00, 0x20])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x01, 0x20]))
response = to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x01, 0x20])
elif (command[2] == 0x02):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x02, 0x20]))
response = to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x02, 0x20])
elif (command[2] == 0x03):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x03, 0x20]))
response = to_string_buffer([0x0b, 0x82, 0x04, 0xc1, 0x03, 0x20])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])

if (response != None):
self.schedule_response(response)

def test_sync_loggers(self):
self.assertEqual(self.result['length'], 4)
Expand Down Expand Up @@ -305,28 +333,32 @@ def commandLogger(self, board, writeType, characteristic, command, length):
curr = len(self.full_history)

if (prev != curr):
response = None
if (command[0] == 0x03 and command[1] == 0x83):
self.notify_mw_char(to_string_buffer([0x03, 0x83, 40, 8]))
response = to_string_buffer([0x03, 0x83, 40, 8])
elif (command[0] == 0x13 and command[1] == 0x83):
self.notify_mw_char(to_string_buffer([0x13, 0x83, 40, 3]))
elif(command[0] == 0x19 and command[1] == 0x83):
self.notify_mw_char(to_string_buffer([0x19, 0x82, 0x1, 0xf]))
response = to_string_buffer([0x13, 0x83, 40, 3])
elif(command[0] == 0x19 and command[1] == 0x82):
response = to_string_buffer([0x19, 0x82, 0x1, 0xf])
elif (self.sync_logger and command[0] == 0xb and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x60]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x60])
elif (command[2] == 0x01):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x64]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x64])
elif (command[2] == 0x02):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x68]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x68])
elif (command[2] == 0x03):
self.notify_mw_char(to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x6c]))
response = to_string_buffer([0x0b, 0x82, 0x09, 0x03, 0x00, 0x6c])
else:
self.notify_mw_char(to_string_buffer([0x0b, 0x82]))
response = to_string_buffer([0x0b, 0x82])
elif (self.sync_dataproc and command[0] == 0x9 and command[1] == 0x82):
if (command[2] == 0x00):
self.notify_mw_char(to_string_buffer([0x09, 0x82, 0x19, 0x07, 0xff, 0xe0, 0x08, 0x17, 0x14, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
response = to_string_buffer([0x09, 0x82, 0x19, 0x07, 0xff, 0xe0, 0x08, 0x17, 0x14, 0x00, 0x00, 0x00, 0xd0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
else:
self.notify_mw_char(to_string_buffer([0x09, 0x82]))
response = to_string_buffer([0x09, 0x82])

if (response != None):
self.schedule_response(response)

def test_log_sync_timeout(self):
self.sync_logger = False
Expand Down

0 comments on commit 261098d

Please sign in to comment.