From 5bbf7be238dd16a8a04a9fb9f9c3010e8268c23d Mon Sep 17 00:00:00 2001 From: Eric Tsai Date: Tue, 19 Dec 2017 17:17:12 -0800 Subject: [PATCH] api v0.11.4 commit --- project_version.mk | 4 ++-- src/metawear/core/cpp/logging.cpp | 7 +++++-- test/test_logging.py | 30 +++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/project_version.mk b/project_version.mk index a144d241..237b987a 100644 --- a/project_version.mk +++ b/project_version.mk @@ -1,4 +1,4 @@ -VERSION=0.11.2 +VERSION=0.11.4 VERSION_MAJOR=0 VERSION_MINOR=11 -VERSION_STEP=2 +VERSION_STEP=4 diff --git a/src/metawear/core/cpp/logging.cpp b/src/metawear/core/cpp/logging.cpp index 0fbd153d..c2413aaf 100644 --- a/src/metawear/core/cpp/logging.cpp +++ b/src/metawear/core/cpp/logging.cpp @@ -353,10 +353,13 @@ static TimeReference& mbl_mw_logger_lookup_reset_uid(const MblMwMetaWearBoard* b return logger_state->log_time_references.at(reset_uid); } +static inline int32_t difference(uint32_t a, uint32_t b) { + return (int32_t) (a - b); +} static int64_t calculate_epoch_inner(shared_ptr state, uint32_t tick, TimeReference& reference) { if (state->latest_tick.count(reference.reset_uid) && state->latest_tick.at(reference.reset_uid) > tick) { auto latest = state->latest_tick.at(reference.reset_uid); - milliseconds offset((int64_t) ((tick - latest + (latest - reference.tick)) * TICK_TIME_STEP)); + milliseconds offset((int64_t) ((difference(tick, latest) + difference(latest, reference.tick)) * TICK_TIME_STEP)); reference.timestamp += offset; reference.tick = tick; @@ -367,7 +370,7 @@ static int64_t calculate_epoch_inner(shared_ptr state, uint32_t tic state->latest_tick[reference.reset_uid]= tick; auto timestamp_copy(reference.timestamp); - milliseconds time_offset((int64_t) ((tick - reference.tick) * TICK_TIME_STEP)); + milliseconds time_offset((int64_t) (difference(tick, reference.tick) * TICK_TIME_STEP)); timestamp_copy += time_offset; return duration_cast(timestamp_copy.time_since_epoch()).count(); } diff --git a/test/test_logging.py b/test/test_logging.py index 643bd5a8..c498ea85 100644 --- a/test/test_logging.py +++ b/test/test_logging.py @@ -4,7 +4,7 @@ #from datetime import datetime from logdata import * from mbientlab.metawear.cbindings import * -#from time import mktime +import time import threading class TestLoggingModule(TestMetaWearBase): @@ -325,3 +325,31 @@ def test_timeout(self): self.e.wait() self.assertIsNone(self.created_logger) + +class TestLogTimestamp(TestMetaWearBase): + def initialized(self, board, status): + super().initialized(board, status) + self.now = int(time.time() * 1000) + + def commandLogger(self, board, writeType, characteristic, command, length): + if (command[0] == 0xb and command[1] == 0x84): + self.schedule_response(to_string_buffer([0x0b, 0x84, 0xa9, 0x72, 0x04, 0x00, 0x01])) + else: + super().commandLogger(board, writeType, characteristic, command, length) + + def test_past(self): + epoch = [] + def handler(data): + epoch.append(data.contents.epoch) + + acc_signal= self.libmetawear.mbl_mw_acc_get_acceleration_data_signal(self.board) + self.libmetawear.mbl_mw_datasignal_log(acc_signal, self.logger_created) + self.events["log"].wait() + + handler_ptr = FnVoid_DataP(handler) + self.libmetawear.mbl_mw_logger_subscribe(self.loggers[0], handler_ptr) + + self.notify_mw_char(to_string_buffer([0x0b, 0x07, 0x20, 0x75, 0x1b, 0x04, 0x00, 0x3e, 0x01, 0xcd, 0x01, 0x21, 0x76, 0x1b, 0x04, 0x00, 0xc0, 0x07, 0x00, 0x00])) + + # epoch should be within 32701ms + self.assertTrue(abs(epoch[0] - self.now) <= 32701)