Skip to content

Commit

Permalink
Imported api v0.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Nov 24, 2016
1 parent 80028ad commit 175dae5
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 14 deletions.
4 changes: 2 additions & 2 deletions project_version.mk
@@ -1,4 +1,4 @@
VERSION=0.7.0
VERSION=0.7.4
VERSION_MAJOR=0
VERSION_MINOR=7
VERSION_STEP=0
VERSION_STEP=4
30 changes: 18 additions & 12 deletions src/metawear/impl/cpp/metawearboard.cpp
Expand Up @@ -179,15 +179,17 @@ const unordered_map<uint8_t, void(*)(const MblMwMetaWearBoard*, vector<uint8_t>&
{ MBL_MW_MODULE_GYRO, serialize_gyro_config },
{ MBL_MW_MODULE_AMBIENT_LIGHT, serialize_ambient_light_config },
{ MBL_MW_MODULE_COLOR_DETECTOR, serialize_colordetector_config },
{ MBL_MW_MODULE_PROXIMITY, serialize_proximity_config }
{ MBL_MW_MODULE_PROXIMITY, serialize_proximity_config },
{ MBL_MW_MODULE_SENSOR_FUSION, serialize_sensor_fusion_config }
};
const unordered_map<uint8_t, void(*)(MblMwMetaWearBoard*, uint8_t**)> CONFIG_DESERIALIZATION = {
{ MBL_MW_MODULE_ACCELEROMETER, deserialize_accelerometer_config },
{ MBL_MW_MODULE_BAROMETER, deserialize_barometer_config },
{ MBL_MW_MODULE_GYRO, deserialize_gyro_config },
{ MBL_MW_MODULE_AMBIENT_LIGHT, deserialize_ambient_light_config },
{ MBL_MW_MODULE_COLOR_DETECTOR, deserialize_colordetector_config },
{ MBL_MW_MODULE_PROXIMITY, deserialize_proximity_config }
{ MBL_MW_MODULE_PROXIMITY, deserialize_proximity_config },
{ MBL_MW_MODULE_SENSOR_FUSION, deserialize_sensor_fusion_config }
};

const uint64_t DEVICE_INFO_SERVICE_UUID_HIGH = 0x0000180a00001000;
Expand Down Expand Up @@ -470,8 +472,10 @@ uint8_t* mbl_mw_metawearboard_serialize(const MblMwMetaWearBoard* board, uint32_

serialized_state.push_back((uint8_t)board->module_config.size());
for (auto it : sorted_keys) {
serialized_state.push_back(it);
CONFIG_SERIALIZATION.at(it)(board, serialized_state);
if (CONFIG_SERIALIZATION.count(it)) {
serialized_state.push_back(it);
CONFIG_SERIALIZATION.at(it)(board, serialized_state);
}
}
}

Expand Down Expand Up @@ -560,23 +564,25 @@ int32_t mbl_mw_metawearboard_deserialize(MblMwMetaWearBoard* board, uint8_t* sta
break;
}

ResponseHeader header_copy(saved_event->header);
header_copy.disable_silent();
ResponseHeader live_header(saved_event->header);
live_header.disable_silent();

if (board->module_events.count(header_copy)) {
auto signal = dynamic_cast<MblMwDataSignal*>(board->module_events[saved_event->header]);
if (board->module_events.count(live_header)) {
auto signal = dynamic_cast<MblMwDataSignal*>(board->module_events[live_header]);
signal->components.push_back(dynamic_cast<MblMwDataSignal*>(saved_event));
} else {
board->module_events.emplace(header_copy, saved_event);
board->module_events.emplace(live_header, saved_event);
}
}

uint8_t module_config_size= *current_addr;
current_addr++;
for (uint8_t i= 0; i < module_config_size; i++) {
auto fn= CONFIG_DESERIALIZATION.at(*current_addr);
current_addr++;
fn(board, &current_addr);
if (CONFIG_DESERIALIZATION.count(*current_addr)) {
auto fn = CONFIG_DESERIALIZATION.at(*current_addr);
current_addr++;
fn(board, &current_addr);
}
}

deserialize_logging(board, (format == SIGNAL_COMPONENT_SERIALIZATION_FORMAT), &current_addr);
Expand Down
8 changes: 8 additions & 0 deletions src/metawear/sensor/cpp/sensor_fusion.cpp
Expand Up @@ -97,6 +97,14 @@ void init_sensor_fusion_module(MblMwMetaWearBoard* board) {
}
}

void serialize_sensor_fusion_config(const MblMwMetaWearBoard *board, std::vector<uint8_t>& state) {
SERIALIZE_MODULE_CONFIG(SensorFusionState, MBL_MW_MODULE_SENSOR_FUSION);
}

void deserialize_sensor_fusion_config(MblMwMetaWearBoard *board, uint8_t** state_stream) {
DESERIALIZE_MODULE_CONFIG(SensorFusionState, MBL_MW_MODULE_SENSOR_FUSION);
}

MblMwDataSignal* mbl_mw_sensor_fusion_get_data_signal(const MblMwMetaWearBoard* board, MblMwSensorFusionData data) {
GET_DATA_SIGNAL(RESPONSE_HEADERS[data]);
}
Expand Down
4 changes: 4 additions & 0 deletions src/metawear/sensor/cpp/sensor_fusion_private.h
@@ -1,5 +1,9 @@
#pragma once

#include <vector>

#include "metawear/core/metawearboard_fwd.h"

void init_sensor_fusion_module(MblMwMetaWearBoard* board);
void serialize_sensor_fusion_config(const MblMwMetaWearBoard *board, std::vector<uint8_t>& state);
void deserialize_sensor_fusion_config(MblMwMetaWearBoard *board, uint8_t** state_stream);
35 changes: 35 additions & 0 deletions test/test_accelerometer_bma255.py
Expand Up @@ -166,3 +166,38 @@ def test_handle_data_component(self):
self.libmetawear.mbl_mw_connection_notify_char_changed(self.board, response.raw, len(response))

self.assertAlmostEqual(self.data_float.value, test['expected'], delta = 0.0001)

class TestBma255HighFreqAccdata(TestMetaWearBase):
def setUp(self):
self.boardType= TestMetaWearBase.METAWEAR_ENV_BOARD

super().setUp()

self.accel_data_signal= self.libmetawear.mbl_mw_acc_bosch_get_high_freq_acceleration_data_signal(self.board)

def sensorDataHandler(self, data):
super().sensorDataHandler(data)

self.cartesian_float_values.append(self.data_cartesian_float)

def test_handle_packed_data(self):
response = create_string_buffer(b'\x03\x1c\x31\x26\x55\xf9\x65\x77\x39\x29\x89\xdb\xfd\x7f\x95\x3d\x61\xc1\xf1\x7f', 20)
expected_values = [CartesianFloat(x = 1.1935, y = -0.2084, z = 3.7311), CartesianFloat(x = 1.2882, y = -1.1395, z = 3.9996), CartesianFloat(x = 1.9244, y = -1.9569, z = 3.9982)]

self.cartesian_float_values= []
self.libmetawear.mbl_mw_datasignal_subscribe(self.accel_data_signal, self.sensor_data_handler)
self.libmetawear.mbl_mw_acc_bosch_set_range(self.board, AccelerometerBosch.FSR_4G)
self.libmetawear.mbl_mw_connection_notify_char_changed(self.board, response.raw, len(response))
self.assertEqual(self.cartesian_float_values, expected_values)

def test_subscribe(self):
expected= [0x03, 0x1c, 0x01]

self.libmetawear.mbl_mw_datasignal_subscribe(self.accel_data_signal, self.sensor_data_handler)
self.assertListEqual(self.command, expected)

def test_unsubscribe(self):
expected= [0x03, 0x1c, 0x00]

self.libmetawear.mbl_mw_datasignal_unsubscribe(self.accel_data_signal)
self.assertListEqual(self.command, expected)
106 changes: 106 additions & 0 deletions test/test_metawearboard.py
Expand Up @@ -147,6 +147,112 @@ def test_timer(self):
self.assertEqual(self.command_history[4:], expected_cmds)

class TestMetaWearBoardSerialize(TestMetaWearBase):
motion_r_state = [
0x01,
0x01, 0x03, 0x01,
0x01, 0x35,
0x19,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x03, 0x01, 0x01, 0x00,
0x04, 0x01, 0x00, 0x04, 0x00, 0x03, 0x01, 0x02,
0x05, 0x00, 0x01, 0x05, 0x03, 0x03, 0x03, 0x03, 0x01,
0x06, 0x00, 0x00, 0x00,
0x07, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00,
0x09, 0x00, 0x00, 0x01, 0x1c,
0x0a, 0x00, 0x00, 0x01, 0x1c,
0x0b, 0x00, 0x02, 0x05, 0x08, 0x80, 0x2b, 0x00, 0x00,
0x0c, 0x00, 0x00, 0x01, 0x08,
0x0d, 0x00, 0x01, 0x00,
0x0f, 0x00, 0x01, 0x01, 0x08,
0x10, 0xff, 0xff,
0x11, 0x00, 0x03, 0x00,
0x12, 0x00, 0x00, 0x00,
0x13, 0x00, 0x01, 0x00,
0x14, 0x00, 0x00, 0x00,
0x15, 0x00, 0x01, 0x00,
0x16, 0xff, 0xff,
0x17, 0xff, 0xff,
0x18, 0xff, 0xff,
0x19, 0x00, 0x00, 0x08, 0x03, 0x00, 0x06, 0x00, 0x02, 0x00, 0x01, 0x00,
0xfe, 0x00, 0x00, 0x00,
0x24,
0x01, 0x01, 0xff, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
0x03, 0x04, 0xff, 0x00, 0x07, 0x02, 0x03, 0x02, 0x01, 0x00,
0x03, 0x04, 0xff, 0x00, 0x08, 0x02, 0x01, 0x02, 0x01, 0x00,
0x03, 0x04, 0xff, 0x00, 0x08, 0x02, 0x01, 0x02, 0x01, 0x02,
0x03, 0x04, 0xff, 0x00, 0x08, 0x02, 0x01, 0x02, 0x01, 0x04,
0x03, 0x19, 0xff, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
0x03, 0x1c, 0xff, 0x00, 0x07, 0x02, 0x03, 0x02, 0x01, 0x00,
0x03, 0xda, 0xff, 0x00, 0x01, 0x00, 0x01, 0x02, 0x00, 0x00,
0x04, 0xc1, 0x00, 0x00, 0x02, 0x06, 0x01, 0x02, 0x01, 0x00,
0x04, 0xc1, 0x01, 0x00, 0x02, 0x06, 0x01, 0x02, 0x01, 0x00,
0x04, 0xc1, 0x02, 0x00, 0x02, 0x06, 0x01, 0x02, 0x01, 0x00,
0x04, 0xc1, 0x03, 0x00, 0x02, 0x06, 0x01, 0x02, 0x01, 0x00,
0x11, 0x0a, 0xff, 0x00,
0x11, 0xcc, 0xff, 0x00, 0x0e, 0x00, 0x01, 0x03, 0x00, 0x00,
0x11, 0xcc, 0xff, 0x00, 0x01, 0x00, 0x01, 0x02, 0x00, 0x01,
0x11, 0xcc, 0xff, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
0x12, 0x01, 0xff, 0x00, 0x03, 0x03, 0x01, 0x04, 0x00, 0x00,
0x12, 0x02, 0xff, 0x00, 0x04, 0x03, 0x01, 0x04, 0x01, 0x00,
0x12, 0xc1, 0xff, 0x00, 0x03, 0x03, 0x01, 0x04, 0x00, 0x00,
0x13, 0x05, 0xff, 0x00, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
0x13, 0x05, 0xff, 0x00, 0x06, 0x04, 0x01, 0x02, 0x01, 0x00,
0x13, 0x05, 0xff, 0x00, 0x06, 0x04, 0x01, 0x02, 0x01, 0x02,
0x13, 0x05, 0xff, 0x00, 0x06, 0x04, 0x01, 0x02, 0x01, 0x04,
0x13, 0x07, 0xff, 0x00, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
0x14, 0x03, 0xff, 0x00, 0x01, 0x00, 0x01, 0x04, 0x00, 0x00,
0x15, 0x05, 0xff, 0x00, 0x0c, 0x08, 0x03, 0x02, 0x01, 0x00,
0x15, 0x05, 0xff, 0x00, 0x0d, 0x08, 0x01, 0x02, 0x01, 0x00,
0x15, 0x05, 0xff, 0x00, 0x0d, 0x08, 0x01, 0x02, 0x01, 0x02,
0x15, 0x05, 0xff, 0x00, 0x0d, 0x08, 0x01, 0x02, 0x01, 0x04,
0x19, 0x04, 0xff, 0x00, 0x1a, 0x00, 0x01, 0x0d, 0x01, 0x00,
0x19, 0x05, 0xff, 0x00, 0x18, 0x00, 0x01, 0x0d, 0x01, 0x00,
0x19, 0x06, 0xff, 0x00, 0x18, 0x00, 0x01, 0x0d, 0x01, 0x00,
0x19, 0x07, 0xff, 0x00, 0x16, 0x00, 0x04, 0x04, 0x01, 0x00,
0x19, 0x08, 0xff, 0x00, 0x17, 0x00, 0x04, 0x04, 0x01, 0x00,
0x19, 0x09, 0xff, 0x00, 0x19, 0x00, 0x03, 0x04, 0x01, 0x00,
0x19, 0x0a, 0xff, 0x00, 0x19, 0x00, 0x03, 0x04, 0x01, 0x00,
0x05,
0x03, 0x28, 0x03, 0x07, 0x30, 0x81, 0x0b, 0xc0, 0x00, 0x14, 0x14, 0x14, 0x40, 0x0a, 0x18, 0x48, 0x08, 0x11, 0x00, 0x00,
0x12, 0x2c, 0x00,
0x13, 0x28, 0x00,
0x14, 0x00, 0x03,
0x19, 0x00, 0x03, 0x00,
0x01,
0xb2, 0xb5, 0x3b, 0x95, 0x58, 0x01, 0x00, 0x00, 0x26, 0x92, 0x00, 0x00, 0x05,
0x00
]


def setUp(self):
self.board= self.libmetawear.mbl_mw_metawearboard_create(byref(self.btle_connection))

def test_serialize_motion_r(self):
self.firmware_revision= create_string_buffer(b'1.3.1', 5)
self.boardType = TestMetaWearBase.METAWEAR_MOTION_R_BOARD
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, self.initialized_fn)

state_array_size= c_uint(0)
state_ptr= cast(self.libmetawear.mbl_mw_metawearboard_serialize(self.board, byref(state_array_size)), POINTER(c_ubyte * state_array_size.value))

self.python_array= []
for i in range(0, state_array_size.value):
self.python_array.append(state_ptr.contents[i])
self.libmetawear.mbl_mw_memory_free(state_ptr)

self.maxDiff= None
self.assertEqual(self.python_array[0:518], TestMetaWearBoardSerialize.motion_r_state[0:518])

def test_deserialize_motion_r(self):
# just test that deserialization is successful
state_buffer= self.to_string_buffer(TestMetaWearBoardSerialize.motion_r_state)
self.libmetawear.mbl_mw_metawearboard_deserialize(self.board, state_buffer.raw, len(state_buffer.raw))

self.assertTrue(True)

class TestMetaWearBoardTearDownSerialize(TestMetaWearBase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down

0 comments on commit 175dae5

Please sign in to comment.