Skip to content

siddrajput/Metawear-CppAPI

 
 

Repository files navigation

MetaWear C++ API

This project is a C++ implementation of the MetaWear protocol. If compiled as a shared library, it can be used with any language that supports calling C functions from a shared library, such as C# and Python. The library only constructs the bytes for communicating with the MetaWear platform, it does not contain any Bluetooth LE code. Users will need to fill in the appropriate Bluetooth LE functions for their target device.

Build

Building the project has been tested on *nix systems with GCC 4.8.5 and Clang 3.7.0, and on Windows with Visual Studio Community 2015.

> gcc --version
gcc (SUSE Linux) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> clang++ --version
clang version 3.7.0 (tags/RELEASE_370/final 246586)
Target: x86_64-suse-linux
Thread model: posix
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

GCC and Clang

Linux users can build the project by invoking GNU make; the default action is to build the shared library for your current platform. You can also change the C++ compiler by overriding the CXX make variable.

> make

# build using clang++ as the compiler
> make CXX=clang++

Upon a successful compile, the library will be placed in the newly created "dist" directory.

> tree dist
dist/
└── release
    └── lib
        └── x64
            ├── libmetawear.so -> libmetawear.so.0
            ├── libmetawear.so.0 -> libmetawear.so.0.7.0
            └── libmetawear.so.0.7.0

Visual Studio 2015

MSBuild files have been provided to build the project as both a Win32 and WinRT dll. The Win32 dll is for classic Win32 applications whereas the WinRT dll is for Universal Windows apps. You will need to have Visual Studio 2015 installed in order to run the build.

When calling MSBuild, you can set the Configuration and Platform properties to control debug/release builds and x86/x64/ARM platforms respectively. If not specified on the command line, the default action is to build a debug dll targeting the x86 (Win32) platform. Note that the ARM platform is only available for the WinRT build.

# default properties are debug config with x86 (win32) platform
msbuild MetaWear.Win32.vcxproj

# release build for Win32 applications targeting the x64 architecture 
msbuild MetaWear.Win32.vcxproj /p:Configuration=Release;Platform=x64

# debug build for WinRT applications targeting the ARM architecture 
msbuild MetaWear.WinRT.vcxproj /p:Configuration=Debug;Platform=ARM

As with the Makefile, the .dll, .lib, .pdb, and .exp files are placed in the dist directory.

> tree dist
dist/
└── release
    └── lib
        └── x64
            ├── MetaWear.Win32.dll
            ├── MetaWear.Win32.exp
            ├── MetaWear.Win32.iobj
            ├── MetaWear.Win32.ipdb
            ├── MetaWear.Win32.lib
            └── MetaWear.Win32.pdb

Testing

Unit tests for the library are written in Python (min v3.4.1) and can be invoked by calling the test target (Test for MSBuild).

GNU Make

> make test
python3 -m unittest discover -s test
................................................................................
................................................................................
................................................................................
................................................................................
.........
----------------------------------------------------------------------
Ran 329 tests in 6.292s

OK

MSBuild

When testing with MSBuild, it is important that the Platform property matches the installed Python's target platform as well. For example, if 64-bit Python is installed, set the Platform property to x64 when running the Test target otherwise MSBuild will use the x86 dll which will cause all of the tests to fail.

metawear-cpp-api>msbuild MetaWear.Win32.vcxproj /p:Platform=x64 /t:Test
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 9/13/2016 10:59:12 PM.
Project "MetaWear.Win32.vcxproj" on node 1 (Test target(s)).
InitializeBuildStatus:
  Creating "build\x64\Debug\MetaWear.Win32\MetaWear.Win32.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
  All outputs are up-to-date.
Link:
  All outputs are up-to-date.
  MetaWear.Win32.vcxproj -> dist\Debug\lib\x64\MetaWear.Win32.dll
  MetaWear.Win32.vcxproj -> dist\Debug\lib\x64\MetaWear.Win32.pdb (Full PDB)
FinalizeBuildStatus:
  Deleting file "build\x64\Debug\MetaWear.Win32\MetaWear.Win32.tlog\unsuccessfulbuild".
  Touching "build\x64\Debug\MetaWear.Win32\MetaWear.Win32.tlog\MetaWear.Win32.lastbuildstate".
Test:
  python3 -m unittest discover -s test
  .....................................................................................................................
  .....................................................................................................................
  ...............................................................................................
  ----------------------------------------------------------------------
  Ran 329 tests in 6.292s

  OK

Done Building Project "MetaWear.Win32.vcxproj" (Test target(s)).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:07.68

About

C++ implementation of the MetaWear protocol

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 40.8%
  • C++ 31.3%
  • C# 15.1%
  • C 11.7%
  • Other 1.1%