Skip to content

Commit 8cf3eb8

Browse files
committed
API v0.7.14 changes
1 parent 4f4aef3 commit 8cf3eb8

File tree

6 files changed

+167
-40
lines changed

6 files changed

+167
-40
lines changed

project_version.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=0.7.10
1+
VERSION=0.7.14
22
VERSION_MAJOR=0
33
VERSION_MINOR=7
4-
VERSION_STEP=10
4+
VERSION_STEP=14

src/metawear/core/cpp/logging.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,15 @@ void MblMwDataLogger::process_log_data(uint8_t id, int64_t epoch, uint32_t data)
314314
}
315315

316316
void MblMwDataLogger::serialize(vector<uint8_t>& state) const {
317-
auto root= dynamic_cast<MblMwDataSignal*>(source->owner->module_events.at(source->header));
317+
ResponseHeader copy(source->header);
318+
copy.disable_silent();
319+
320+
auto root = dynamic_cast<MblMwDataSignal*>(source->owner->module_events.at(copy));
318321
if (source == root) {
319322
state.push_back(ROOT_SIGNAL_INDEX);
320323
} else {
321-
uint8_t i= 0;
322-
for(auto it: root->components) {
324+
uint8_t i = 0;
325+
for (auto it : root->components) {
323326
if (it == source) break;
324327
i++;
325328
}
@@ -328,7 +331,7 @@ void MblMwDataLogger::serialize(vector<uint8_t>& state) const {
328331
}
329332
source->header.serialize(state);
330333

331-
state.push_back((uint8_t) entry_ids.size());
334+
state.push_back((uint8_t)entry_ids.size());
332335
state.insert(state.end(), entry_ids.begin(), entry_ids.end());
333336
}
334337

src/metawear/core/cpp/version.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const char SEPARATOR= '.';
1414
Version::Version() : Version(EMPTY_VALUE, EMPTY_VALUE, EMPTY_VALUE) {
1515
}
1616

17+
Version::Version(const string& version) {
18+
assign(version);
19+
}
20+
1721
Version::Version(uint8_t major, uint8_t minor, uint8_t step) {
1822
this->major= major;
1923
this->minor= minor;
@@ -38,7 +42,7 @@ bool Version::empty() const {
3842
return major == EMPTY_VALUE && minor == EMPTY_VALUE && step == EMPTY_VALUE;
3943
}
4044

41-
void Version::assign(const std::string new_version) {
45+
void Version::assign(const std::string& new_version) {
4246
string tempStr;
4347
vector<string> parts;
4448
size_t i= 0;

src/metawear/core/cpp/version.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
struct Version {
88
Version();
9+
Version(const std::string& version);
910
Version(uint8_t major, uint8_t minor, uint8_t step);
1011

1112
void deserialize(uint8_t** state_stream);
1213
void serialize(std::vector<uint8_t>& state) const;
1314

1415
bool empty() const;
15-
void assign(const std::string new_version);
16+
void assign(const std::string& new_version);
1617
Version& operator =(const Version& original);
1718

1819
uint8_t major, minor, step;

src/metawear/impl/cpp/metawearboard.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -348,42 +348,38 @@ void mbl_mw_connection_char_read(MblMwMetaWearBoard *board, const MblMwGattChar
348348

349349
void mbl_mw_metawearboard_char_read(MblMwMetaWearBoard *board, const MblMwGattChar *characteristic, const uint8_t *value, uint8_t length) {
350350
if (characteristic->uuid_high == DEV_INFO_FIRMWARE_CHAR.uuid_high && characteristic->uuid_low == DEV_INFO_FIRMWARE_CHAR.uuid_low) {
351-
if (board->firmware_revision.empty()) {
352-
board->firmware_revision.assign(string(value, value + length));
353-
board->module_discovery_index= -1;
354-
} else {
355-
Version current;
356-
current.assign(string(value, value + length));
357-
358-
if (board->firmware_revision == current) {
359-
if (mbl_mw_metawearboard_is_initialized(board)) {
360-
board->initialized_timeout->cancel();
361-
board->initialized(board, MBL_MW_STATUS_OK);
362-
} else {
363-
board->module_discovery_index = MODULE_DISCOVERY_CMDS.size();
364-
service_discovery_completed(board);
365-
}
366-
return;
351+
Version current(string(value, value + length));
352+
353+
if (board->firmware_revision == current) {
354+
if (mbl_mw_metawearboard_is_initialized(board)) {
355+
board->initialized_timeout->cancel();
356+
board->initialized(board, MBL_MW_STATUS_OK);
367357
} else {
368-
board->logger_state.reset();
369-
board->timer_state.reset();
370-
board->event_state.reset();
371-
board->dp_state.reset();
372-
373-
for (auto it : board->module_events) {
374-
it.second->remove = false;
375-
delete it.second;
376-
}
377-
board->module_events.clear();
358+
board->module_discovery_index = MODULE_DISCOVERY_CMDS.size();
359+
service_discovery_completed(board);
360+
}
361+
return;
362+
} else {
363+
board->firmware_revision = current;
378364

379-
for (auto it: board->module_config) {
380-
free(it.second);
381-
}
382-
board->module_config.clear();
365+
board->logger_state.reset();
366+
board->timer_state.reset();
367+
board->event_state.reset();
368+
board->dp_state.reset();
383369

384-
board->module_info.clear();
385-
board->module_discovery_index= -1;
370+
for (auto it : board->module_events) {
371+
it.second->remove = false;
372+
delete it.second;
386373
}
374+
board->module_events.clear();
375+
376+
for (auto it : board->module_config) {
377+
free(it.second);
378+
}
379+
board->module_config.clear();
380+
381+
board->module_info.clear();
382+
board->module_discovery_index = -1;
387383
}
388384
queue_next_gatt_char(board);
389385
} else if (characteristic->uuid_high == DEV_INFO_MODEL_CHAR.uuid_high && characteristic->uuid_low == DEV_INFO_MODEL_CHAR.uuid_low) {

test/test_metawearboard.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,129 @@ def test_deserialize_motion_r(self):
252252

253253
self.assertTrue(True)
254254

255+
def test_deserialize_motion_r_new_fw(self):
256+
firmware_state = [0x03, 0x03, 0x01]
257+
258+
self.firmware_revision= create_string_buffer(b'1.3.3', 5)
259+
self.boardType = TestMetaWearBase.METAWEAR_MOTION_R_BOARD
260+
261+
state_buffer= self.to_string_buffer(TestMetaWearBoardSerialize.motion_r_state)
262+
self.libmetawear.mbl_mw_metawearboard_deserialize(self.board, state_buffer.raw, len(state_buffer.raw))
263+
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, self.initialized_fn)
264+
265+
state_array_size= c_uint(0)
266+
state_ptr= cast(self.libmetawear.mbl_mw_metawearboard_serialize(self.board, byref(state_array_size)), POINTER(c_ubyte * state_array_size.value))
267+
268+
python_array= []
269+
for i in range(0, state_array_size.value):
270+
python_array.append(state_ptr.contents[i])
271+
self.libmetawear.mbl_mw_memory_free(state_ptr)
272+
273+
self.assertEqual(python_array[1:4], firmware_state)
274+
275+
def test_serialize_readable_logger(self):
276+
logger_state= [
277+
0x1,
278+
0xff, 0x04, 0xc1, 0x00, 0x01, 0x00
279+
]
280+
281+
self.firmware_revision= create_string_buffer(b'1.2.5', 5)
282+
self.boardType = TestMetaWearBase.METAWEAR_RPRO_BOARD
283+
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, self.initialized_fn)
284+
285+
readable_signal = self.libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal(self.board, 0)
286+
self.libmetawear.mbl_mw_datasignal_log(readable_signal, self.logger_created);
287+
288+
state_array_size= c_uint(0)
289+
state_ptr= cast(self.libmetawear.mbl_mw_metawearboard_serialize(self.board, byref(state_array_size)), POINTER(c_ubyte * state_array_size.value))
290+
291+
python_array= []
292+
for i in range(0, state_array_size.value):
293+
python_array.append(state_ptr.contents[i])
294+
self.libmetawear.mbl_mw_memory_free(state_ptr)
295+
296+
print(python_array)
297+
self.assertEqual(python_array[368:], logger_state)
298+
299+
def test_deserialize_readable_logger(self):
300+
state = [
301+
1,
302+
5, 2, 1,
303+
1, 49,
304+
25,
305+
1, 0, 0, 0,
306+
2, 0, 0, 0,
307+
3, 1, 1, 0,
308+
4, 1, 0, 4, 0, 3, 1, 2,
309+
5, 0, 0, 0,
310+
6, 0, 0, 0,
311+
7, 0, 0, 0,
312+
8, 0, 0, 0,
313+
9, 0, 0, 1, 28,
314+
10, 0, 0, 1, 28,
315+
11, 0, 2, 5, 8, 128, 45, 0, 0,
316+
12, 0, 0, 1, 8,
317+
13, 0, 0, 0,
318+
15, 0, 0, 0,
319+
16, 255, 255,
320+
17, 0, 0, 0,
321+
18, 0, 0, 0,
322+
19, 0, 1, 0,
323+
20, 0, 0, 0,
324+
21, 255, 255,
325+
22, 255, 255,
326+
23, 255, 255,
327+
24, 255, 255,
328+
25, 255, 255,
329+
254, 0, 0, 0,
330+
21,
331+
1, 1, 255, 0, 1, 0, 1, 1, 0, 0,
332+
3, 4, 255, 0, 7, 2, 3, 2, 1, 0,
333+
3, 4, 255, 0, 8, 2, 1, 2, 1, 0,
334+
3, 4, 255, 0, 8, 2, 1, 2, 1, 2,
335+
3, 4, 255, 0, 8, 2, 1, 2, 1, 4,
336+
3, 25, 255, 0, 1, 0, 1, 1, 0, 0,
337+
3, 28, 255, 0, 7, 2, 3, 2, 1, 0,
338+
3, 218, 255, 0, 1, 0, 1, 2, 0, 0,
339+
4, 193, 0, 0, 2, 6, 1, 2, 1, 0,
340+
4, 193, 1, 0, 2, 6, 1, 2, 1, 0,
341+
4, 193, 2, 0, 2, 6, 1, 2, 1, 0,
342+
4, 193, 3, 0, 2, 6, 1, 2, 1, 0,
343+
18, 1, 255, 0, 3, 3, 1, 4, 0, 0,
344+
18, 2, 255, 0, 4, 3, 1, 4, 1, 0,
345+
18, 193, 255, 0, 3, 3, 1, 4, 0, 0,
346+
19, 5, 255, 0, 5, 4, 3, 2, 1, 0,
347+
19, 5, 255, 0, 6, 4, 1, 2, 1, 0,
348+
19, 5, 255, 0, 6, 4, 1, 2, 1, 2,
349+
19, 5, 255, 0, 6, 4, 1, 2, 1, 4,
350+
19, 7, 255, 0, 5, 4, 3, 2, 1, 0,
351+
20, 3, 255, 0, 1, 0, 1, 4, 0, 0,
352+
4,
353+
3, 40, 3, 7, 48, 129, 11, 192, 0, 20, 20, 20, 64, 10, 24, 72, 8, 17, 0, 0,
354+
18, 44, 0,
355+
19, 40, 0,
356+
20, 0, 3,
357+
1,
358+
226, 118, 142, 47, 90, 1, 0, 0, 21, 4, 0, 0, 5,
359+
1,
360+
255, 4, 193, 0, 1, 0
361+
]
362+
363+
self.firmware_revision= create_string_buffer(b'1.2.5', 5)
364+
self.boardType = TestMetaWearBase.METAWEAR_RPRO_BOARD
365+
366+
state_buffer= self.to_string_buffer(state)
367+
self.libmetawear.mbl_mw_metawearboard_deserialize(self.board, state_buffer.raw, len(state_buffer.raw))
368+
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, self.initialized_fn)
369+
370+
logger = self.libmetawear.mbl_mw_logger_lookup_id(self.board, 0);
371+
self.libmetawear.mbl_mw_logger_subscribe(logger, self.sensor_data_handler);
372+
373+
buffer = create_string_buffer(b'\x0b\x07\xa0\x37\x43\x00\x00\xc8\x00\x00\x00', 11)
374+
self.libmetawear.mbl_mw_metawearboard_notify_char_changed(self.board, buffer.raw, len(buffer))
375+
376+
self.assertAlmostEqual(self.data_float.value, 25.0)
377+
255378
class TestMetaWearBoardTearDownSerialize(TestMetaWearBase):
256379
def __init__(self, *args, **kwargs):
257380
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)