Skip to content

Commit

Permalink
api v0.11.4 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Dec 20, 2017
1 parent 261098d commit 5bbf7be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 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.2
VERSION=0.11.4
VERSION_MAJOR=0
VERSION_MINOR=11
VERSION_STEP=2
VERSION_STEP=4
7 changes: 5 additions & 2 deletions src/metawear/core/cpp/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoggerState> 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;

Expand All @@ -367,7 +370,7 @@ static int64_t calculate_epoch_inner(shared_ptr<LoggerState> 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<milliseconds>(timestamp_copy.time_since_epoch()).count();
}
Expand Down
30 changes: 29 additions & 1 deletion test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 5bbf7be

Please sign in to comment.