Skip to content

Commit

Permalink
api v0.12.8 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Feb 13, 2018
1 parent 5246787 commit 456601f
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 42 deletions.
16 changes: 8 additions & 8 deletions bindings/javascript/cbindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,6 @@ var DataProcessor = ref.types.void;
var FnVoid_VoidP_DataProcessorP = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(DataProcessor)]);
var Event = ref.types.void;
var FnVoid_VoidP_EventP_Int = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(Event), ref.types.int32]);
var FnInt_VoidP_UByteP_UByte = ffi.Function(ref.types.int32, [ref.refType(ref.types.void), ref.refType(ref.types.uint8), ref.types.uint8]);
var FnVoid_VoidP_Int = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.types.int32]);
var DataLogger = ref.types.void;
var FnVoid_VoidP_DataLoggerP = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(DataLogger)]);
var Timer = ref.types.void;
var FnVoid_VoidP_TimerP = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(Timer)]);
var Data = Struct({
Expand All @@ -546,10 +542,14 @@ var Data = Struct({
});

var FnVoid_VoidP_DataP = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(Data)]);
var DataLogger = ref.types.void;
var FnVoid_VoidP_DataLoggerP = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(DataLogger)]);
var MetaWearBoard = ref.types.void;
var AnonymousDataSignal = ref.types.void;
var FnVoid_VoidP_MetaWearBoardP_AnonymousDataSignalP_UInt = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(MetaWearBoard), ref.refType(AnonymousDataSignal), ref.types.uint32]);
var FnVoid_VoidP_MetaWearBoardP_Int = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.refType(MetaWearBoard), ref.types.int32]);
var FnVoid_VoidP_Int = ffi.Function(ref.types.void, [ref.refType(ref.types.void), ref.types.int32]);
var FnInt_VoidP_UByteP_UByte = ffi.Function(ref.types.int32, [ref.refType(ref.types.void), ref.refType(ref.types.uint8), ref.types.uint8]);
var SpiParameters = Struct({
'mode': SpiMode,
'frequency': SpiFrequency,
Expand Down Expand Up @@ -2925,13 +2925,11 @@ module.exports = {
DfuDelegate: DfuDelegate,
SpiParameters: SpiParameters,
AccBma255Odr: AccBma255Odr,
MetaWearRChannel: MetaWearRChannel,
FnInt_VoidP_UByteP_UByte: FnInt_VoidP_UByteP_UByte,
ArrayAnonymousDataSignalP: ArrayAnonymousDataSignalP,
FnVoid_VoidP_DataLoggerP: FnVoid_VoidP_DataLoggerP,
Timer: Timer,
LogDownloadHandler: LogDownloadHandler,
Data: Data,
ArrayAnonymousDataSignalP: ArrayAnonymousDataSignalP,
FnVoid_VoidP_DataLoggerP: FnVoid_VoidP_DataLoggerP,
AccBoschRange: AccBoschRange,
MetaWearBoard: MetaWearBoard,
GpioAnalogReadParameters: GpioAnalogReadParameters,
Expand All @@ -2943,6 +2941,8 @@ module.exports = {
HumidityBme280Oversampling: HumidityBme280Oversampling,
MagBmm150Odr: MagBmm150Odr,
FnVoid_VoidP_MetaWearBoardP_Int: FnVoid_VoidP_MetaWearBoardP_Int,
MetaWearRChannel: MetaWearRChannel,
FnInt_VoidP_UByteP_UByte: FnInt_VoidP_UByteP_UByte,
BaroBoschIirFilter: BaroBoschIirFilter,
I2cReadParameters: I2cReadParameters,
FnVoid_VoidP_UInt_UInt: FnVoid_VoidP_UInt_UInt,
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/mbientlab/metawear/cbindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ class GpioAnalogReadMode:

FnVoid_VoidP_VoidP = CFUNCTYPE(None, c_void_p, c_void_p)
FnVoid_VoidP_VoidP_Int = CFUNCTYPE(None, c_void_p, c_void_p, c_int)
FnInt_VoidP_UByteP_UByte = CFUNCTYPE(c_int, c_void_p, POINTER(c_ubyte), c_ubyte)
FnVoid_VoidP_Int = CFUNCTYPE(None, c_void_p, c_int)
class Data(Structure):
_fields_ = [
("epoch" , c_longlong),
Expand All @@ -475,6 +473,8 @@ def __deepcopy__(self, memo):

FnVoid_VoidP_DataP = CFUNCTYPE(None, c_void_p, POINTER(Data))
FnVoid_VoidP_VoidP_VoidP_UInt = CFUNCTYPE(None, c_void_p, c_void_p, c_void_p, c_uint)
FnVoid_VoidP_Int = CFUNCTYPE(None, c_void_p, c_int)
FnInt_VoidP_UByteP_UByte = CFUNCTYPE(c_int, c_void_p, POINTER(c_ubyte), c_ubyte)
class SpiParameters(Structure):
_fields_ = [
("mode" , c_int),
Expand Down
39 changes: 39 additions & 0 deletions bindings/swift/cbindings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public let MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_LOW = 1
public let MBL_MW_LED_REPEAT_INDEFINITELY = 255
public let MBL_MW_ACC_ACCEL_X_AXIS_INDEX = 0
public let MBL_MW_ADDRESS_TYPE_PRIVATE_NON_RESOLVABLE = 3
public let MBL_MW_STATUS_ERROR_ENABLE_NOTIFY = 64
public let MBL_MW_SETTINGS_BATTERY_CHARGE_INDEX = 1
public let MBL_MW_ADDRESS_TYPE_PRIVATE_RESOLVABLE = 2
public let MBL_MW_MODULE_BARO_TYPE_BMP280 = 0
public let MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_MEDIUM = 2
public let MBL_MW_STATUS_ERROR_SERIALIZATION_FORMAT = 32
public let MBL_MW_STATUS_WARNING_UNEXPECTED_SENSOR_DATA = 1
public let MBL_MW_STATUS_ERROR_TIMEOUT = 16
public let MBL_MW_STATUS_OK = 0
public let MBL_MW_SETTINGS_BATTERY_VOLTAGE_INDEX = 0
public let MBL_MW_ADDRESS_TYPE_PUBLIC = 0
public let MBL_MW_ADDRESS_TYPE_RANDOM_STATIC = 1
public let MBL_MW_STATUS_WARNING_INVALID_PROCESSOR_TYPE = 2
public let MBL_MW_STATUS_WARNING_INVALID_RESPONSE = 8
public let MBL_MW_MODULE_BARO_TYPE_BME280 = 1
public let MBL_MW_MODULE_ACC_TYPE_BMI160 = 1
public let MBL_MW_MODULE_ACC_TYPE_BMA255 = 3
public let MBL_MW_MAG_BFIELD_Y_AXIS_INDEX = 1
public let MBL_MW_CD_TCS34725_ADC_CLEAR_INDEX = 0
public let MBL_MW_STATUS_ERROR_UNSUPPORTED_PROCESSOR = 4
public let MBL_MW_GYRO_ROTATION_Y_AXIS_INDEX = 1
public let MBL_MW_CD_TCS34725_ADC_RED_INDEX = 1
public let MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_HIGH = 3
public let MBL_MW_MODULE_TYPE_NA = -1
public let MBL_MW_SENSOR_FUSION_CALIBRATION_ACCURACY_UNRELIABLE = 0
public let MBL_MW_CD_TCS34725_ADC_GREEN_INDEX = 2
public let MBL_MW_MAG_BFIELD_X_AXIS_INDEX = 0
public let MBL_MW_GPIO_UNUSED_PIN = 255
public let MBL_MW_ACC_ACCEL_Z_AXIS_INDEX = 2
public let MBL_MW_GYRO_ROTATION_Z_AXIS_INDEX = 2
public let MBL_MW_MAG_BFIELD_Z_AXIS_INDEX = 2
public let MBL_MW_CD_TCS34725_ADC_BLUE_INDEX = 3
public let MBL_MW_ACC_ACCEL_Y_AXIS_INDEX = 1
public let MBL_MW_MODULE_ACC_TYPE_MMA8452Q = 0
public let MBL_MW_GYRO_ROTATION_X_AXIS_INDEX = 0
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.12.1
VERSION=0.12.8
VERSION_MAJOR=0
VERSION_MINOR=12
VERSION_STEP=1
VERSION_STEP=8
8 changes: 2 additions & 6 deletions src/metawear/impl/cpp/metawearboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,7 @@ const vector<tuple<MblMwGattChar, void(*)(MblMwMetaWearBoard*, const uint8_t*, u
make_tuple(DEV_INFO_FIRMWARE_CHAR, [](MblMwMetaWearBoard* board, const uint8_t* value, uint8_t length) {
Version current(string(value, value + length));

if (board->firmware_revision == current) {
if (!mbl_mw_metawearboard_is_initialized(board)) {
board->module_discovery_index = MODULE_DISCOVERY_CMDS.size();
}
} else {
if (!(board->firmware_revision == current)) {
board->firmware_revision = current;

board->logger_state.reset();
Expand All @@ -286,7 +282,6 @@ const vector<tuple<MblMwGattChar, void(*)(MblMwMetaWearBoard*, const uint8_t*, u
board->module_config.clear();

board->module_info.clear();
board->module_discovery_index = -1;
}
}, [](MblMwMetaWearBoard* board) { return false; }),
make_tuple(DEV_INFO_MODEL_CHAR, [](MblMwMetaWearBoard* board, const uint8_t* value, uint8_t length) { board->module_number.assign(value, value + length); },
Expand Down Expand Up @@ -462,6 +457,7 @@ void mbl_mw_metawearboard_initialize(MblMwMetaWearBoard *board, void *context, M
board->initialized_context = context;
board->initialized = initialized;
board->dev_info_index = -1;
board->module_discovery_index = -1;

board->btle_conn.on_disconnect(board->btle_conn.context, board, disconnect_handler);
board->btle_conn.enable_notifications(board->btle_conn.context, board, &METAWEAR_SERVICE_NOTIFY_CHAR, char_changed_handler, enable_notify_ready);
Expand Down
3 changes: 2 additions & 1 deletion src/metawear/sensor/cpp/utils.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <cstdint>
#include <cstddef>
#include <vector>

char* copy_string_index(const char* src, std::uint8_t i);
char* copy_string(const char* src);

uint8_t closest_index(const std::vector<float>& values, float key);
uint8_t closest_index(const float* values, size_t len, float key);
uint8_t closest_index(const float* values, std::size_t len, float key);
32 changes: 20 additions & 12 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ def setUp(self):
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, None, self.initialized_fn)

def tearDown(self):
self.libmetawear.mbl_mw_metawearboard_free(self.board)
#Need to separate the btle code so we can cleanly free the memory.
#Will look into it later
#self.libmetawear.mbl_mw_metawearboard_free(self.board)
#self.board = None
pass

def commandsRecorded(self, context, event, status):
self.event_status.append(status)
Expand All @@ -276,14 +280,14 @@ def timer_created(self, context, timer_signal):
self.events["timer"].set()

def initialized(self, context, board, status):
self.init_status= status;
self.init_status= status

def on_disconnect(self, context, board, handler):
self.dc_handler = handler;
self.dc_handler = handler

def enable_gatt_notify(self, context, board, characteristic, handler, ready):
self.notify_handler = handler;
ready(self.board, 0)
self.notify_handler = handler
ready(board, 0)

def read_gatt_char(self, context, board, characteristic, handler):
if (characteristic.contents.uuid_high == 0x00002a2400001000 and characteristic.contents.uuid_low == 0x800000805f9b34fb):
Expand All @@ -299,22 +303,22 @@ def read_gatt_char(self, context, board, characteristic, handler):
model_number= create_string_buffer(b'5', 1)

bytes = cast(model_number.raw, POINTER(c_ubyte))
handler(self.board, bytes, len(model_number.raw))
handler(board, bytes, len(model_number.raw))
elif (characteristic.contents.uuid_high == 0x00002a2600001000 and characteristic.contents.uuid_low == 0x800000805f9b34fb):
bytes = cast(self.firmware_revision.raw, POINTER(c_ubyte))
handler(self.board, bytes, len(self.firmware_revision.raw))
handler(board, bytes, len(self.firmware_revision.raw))
elif (characteristic.contents.uuid_high == 0x00002a2700001000 and characteristic.contents.uuid_low == 0x800000805f9b34fb):
hw = create_string_buffer(b'0.1', 3)
bytes = cast(hw.raw, POINTER(c_ubyte))
handler(self.board, bytes, len(hw.raw))
handler(board, bytes, len(hw.raw))
elif (characteristic.contents.uuid_high == 0x00002a2900001000 and characteristic.contents.uuid_low == 0x800000805f9b34fb):
mft = create_string_buffer(b'deadbeef', 8)
bytes = cast(mft.raw, POINTER(c_ubyte))
handler(self.board, bytes, len(mft.raw))
handler(board, bytes, len(mft.raw))
elif (characteristic.contents.uuid_high == 0x00002a2500001000 and characteristic.contents.uuid_low == 0x800000805f9b34fb):
serial = create_string_buffer(b'cafebabe', 8)
bytes = cast(serial.raw, POINTER(c_ubyte))
handler(self.board, bytes, len(serial.raw))
handler(board, bytes, len(serial.raw))

def commandLogger(self, context, board, writeType, characteristic, command, length):
self.command= []
Expand Down Expand Up @@ -430,11 +434,15 @@ def sensorDataHandler(self, context, data):

def notify_mw_char(self, buffer):
bytes = cast(buffer, POINTER(c_ubyte))
return self.notify_handler(self.board, bytes, len(buffer.raw))
if (self.board != None):
return self.notify_handler(self.board, bytes, len(buffer.raw))
else:
return 0

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

self.pending_responses.put(response)
Timer(0.020, send_response).start()
Expand Down
46 changes: 35 additions & 11 deletions test/test_metawearboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,52 @@ def test_reinitialize_new_firmware(self):
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, None, self.initialized_fn)
self.assertEqual(self.full_history, expected_cmds)

class TestMetaWearBoardInitTimeout(TestMetaWearBase):
class TestMetaWearBoardInitError(TestMetaWearBase):
def setUp(self):
self.module_limit = 0x3
self.board= self.libmetawear.mbl_mw_metawearboard_create(byref(self.btle_connection))

def initialized(self, context, board, status):
super().initialized(context, board, status)

self.e.set()

def commandLogger(self, context ,board, writeType, characteristic, command, length):
if (command[1] == 0x80):
response= create_string_buffer(b'\x00\x00', 2)
response[0]= command[0]
self.notify_mw_char(response)
else:
super().commandLogger(context, board, writeType, characteristic, command, length)
def commandLogger(self, context, board, writeType, characteristic, command, length):
if (command[1] != 0x80 or command[1] == 0x80 and command[0] <= self.module_limit):
TestMetaWearBase.commandLogger(self, context, board, writeType, characteristic, command, length)

def test_timeout(self):
self.e= threading.Event()
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, None, self.initialized_fn)
self.e.wait()

self.assertEqual(self.init_status, Const.STATUS_ERROR_TIMEOUT)

def test_resume(self):
expected_cmds= [
[0x01, 0x80], [0x02, 0x80], [0x03, 0x80], [0x04, 0x80],
[0x05, 0x80], [0x06, 0x80], [0x07, 0x80], [0x08, 0x80],
[0x09, 0x80], [0x0a, 0x80], [0x0b, 0x80], [0x0c, 0x80],
[0x0d, 0x80], [0x0f, 0x80], [0x10, 0x80], [0x11, 0x80],
[0x12, 0x80], [0x13, 0x80], [0x14, 0x80], [0x15, 0x80],
[0x16, 0x80], [0x17, 0x80], [0x18, 0x80], [0x19, 0x80],
[0xfe, 0x80],
[0x0b, 0x84]
]

self.e= threading.Event()
# this attempt will fail
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, None, self.initialized_fn)
self.e.wait()
self.assertEqual(self.init_status, Const.STATUS_ERROR_TIMEOUT)

self.e.clear()
self.module_limit = 0xff
# this attempt resumes where previous init failed
self.libmetawear.mbl_mw_metawearboard_initialize(self.board, None, self.initialized_fn)
self.e.wait()

self.assertEqual(self.full_history, expected_cmds)

class TestTearDown(TestGpioFeedbackSetup):
def test_dataproc_event(self):
Expand Down Expand Up @@ -453,7 +476,7 @@ def __init__(self, *args, **kwargs):
0x01,
0x03, 0x01, 0x01,
0x01, 0x31,
0x18,
0x19,
0x01, 0xff, 0xff,
0x02, 0xff, 0xff,
0x03, 0x01, 0x00, 0x00,
Expand All @@ -477,6 +500,7 @@ def __init__(self, *args, **kwargs):
0x16, 0xff, 0xff,
0x17, 0xff, 0xff,
0x18, 0xff, 0xff,
0x19, 0xff, 0xff,
0xfe, 0xff, 0xff,
0x0c,
0x03, 0x04, 0xff, 0x00, 0x07, 0x02, 0x03, 0x02, 0x01, 0x00,
Expand Down Expand Up @@ -522,7 +546,7 @@ def test_teardown_serialize(self):
self.libmetawear.mbl_mw_memory_free(state_ptr)

self.maxDiff= None
self.assertEqual(python_array[0:198], self.expected_state[0:198])
self.assertEqual(python_array[0:201], self.expected_state[0:201])

class TestMetaWearBoardDeserialize(TestMetaWearBase):
def setUp(self):
Expand Down Expand Up @@ -793,7 +817,7 @@ def setUp(self):
self.init_event = threading.Event()

def initialized(self, board, status):
self.init_status= status;
self.init_status= status
self.init_event.set()

def commandLogger(self, board, writeType, characteristic, command, length):
Expand Down

0 comments on commit 456601f

Please sign in to comment.