bluetoothでgo!

16
BluetoothGo! Bar Windows 8 in 名古屋 with 8.1 けきょ(Kouji Matsui @kekyo2

Upload: kouji-matsui

Post on 14-Jul-2015

785 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Bluetoothでgo!

BluetoothでGo!

Bar Windows 8 in 名古屋 with 8.1 けきょ(Kouji Matsui @kekyo2)

Page 2: Bluetoothでgo!

自己紹介

けきょ @kekyo2 (あまりtweetしてません)

会社やってます

「Micoci」と「まどべんよっかいち」

主にWindows。C#, C++/CLI, ATL, C++0x, x86/x64アセンブラ, WDM, Azure, TFS, OpenCV,

Geo, JNI, 鯖管理, MCP少々, 自作PC, 昔マイコン, 複式簿記経理

アプリケーションフレームワーク設計・アーキテクトが仕事の主体。最近はWPFを使ったMVVMに足をツッコミ中

Page 3: Bluetoothでgo!

Windows 8と言えば…

Bluetooth 4.0対応

で、4.0で何が追加されたの?

Page 4: Bluetoothでgo!

Bluetooth 4.0って?

「Bluetooth 4.0 LE」ですよ

「Low Energy」ですよ

別名、「Bluetooth Smart」ですよ

何か呼称がごちゃごちゃしてますが、3.0以前の規格とLEに互換性は無いです。(大人の事情で4.0としたのかも?)

1.0~4.0全部ひっくるめて使えるのが、「Bluetooth Smart Ready」です(レシーバーしかない、多分)

Page 5: Bluetoothでgo!

Bluetooth 4.0 LEって?

コンシューマーブランド「Bluetooth Smart」

「超」低消費電力デバイス向けの規格ボタン電池で半年~1年

3.0以前と互換性なし

プロファイルがいっぱい増えた

ライバルは、「Zigbee」「ANT+」「RFID」か?

Page 6: Bluetoothでgo!

Windows 8との関係は?

Windows 8.0で「Bluetooth 4.0」対応表明

しかし、一体何に対応したのか良く分からない(単に4.0プロトコルスタックを配布しただけ?)

APIについての情報が皆無

そうこうしているうちに、Windows 8.1現わる!!

WinRTに名前空間が増えた!

Page 7: Bluetoothでgo!

Bluetooth API

Windows.Devices.Bluetooth

Windows.Devices.Bluetooth.GenericAttributeProfile

これぞLEデバイス!

GATT

Page 8: Bluetoothでgo!

公式サンプルコード

「Bluetooth Generic Attribute Profile - Heart Rate Service」Demonstrates use of the Bluetooth Generic Attribute Profile (Gatt) Windows Runtime API to

interact with a Bluetooth Gatt device which contains a Heart Rate Service.

http://code.msdn.microsoft.com/windowsapps/Bluetooth-Generic-5a99ef95

汚いサンプルコード… (T_T)

Page 9: Bluetoothでgo!

取りあえずやってみた

Bluetooth Smartデバイスが無ければ話にならない

幸い?ロードバイク乗りなので…

Wahoo FITNESS BLUE HR (心拍計)http://www.wahoofitness.com/devices/wahoo-blue-hr-heart-rate-strap.html#

レシーバーは PLANEX BT-MICRO4

Page 10: Bluetoothでgo!

Demo(サンプルコード)

Page 11: Bluetoothでgo!

まあ…

サンプルコードを動かしただけでは面白くない

WinRTって、噂ではデスクトップからも呼び出せるらしいし

WPFから使えた方が、私的に面白いかも?

本当にデスクトップアプリケーションから、デバイスにアクセス出来るか?

Page 12: Bluetoothでgo!

APIはどう使うの?

デスクトップアプリケーションからWinRTを使うには、Bingって下さい例: http://www.codeproject.com/Articles/457335/How-to-call-WinRT-APIs-from-NET-desktop-apps

Windows 8.1の場合は、「TargetPlatformVersion」を「8.1」にすること(8.0では、新しいAPIは使えない)

Bluetooth APIはWindows.winmdに含まれているので、追加のアセンブリは不要

Page 13: Bluetoothでgo!

APIはどう使うの?

デバイスセレクタの取得var selector =

GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate);

デバイスの列挙IEnumerable<DeviceInformation> dis = await DeviceInformation.FindAllAsync(selector);

デバイスの初期化var service = await GattDeviceService.FromIdAsync(deviceInformation.Id);

心拍情報のイベントをフックvar characteristics =

service.GetCharacteristics(GattCharacteristicUuids.HeartRateMeasurement);

characteristics[0].ValueChanged += (sender, e) => { … };

心拍計

Page 14: Bluetoothでgo!

イベントで心拍数が得られるんだ!(喜)

いやいや、得られるのは、ペイロードの「生」データ(バイト列)です解析はプロトコルに合わせて独自に行う必要があります(爆) orz

プロトコルの情報は、Bluetooth SIGで調べる必要がありますhttps://developer.bluetooth.org/gatt/Pages/GATT-Specification-Documents.aspx

(ペイロードの説明は全部文書で、ボックス図がないです。辛い…)

とりあえず、心拍計については、サンプルコードのデコーダーが参考になるでしょう

Page 15: Bluetoothでgo!

Demo(WPF版)

Page 16: Bluetoothでgo!

それでは、引き続きお楽しみ下さい

ありがとうございました