bluetooth で go!

16
Bluetooth で Go! Bar Windows 8 in 名名名 with 8.1 名名名Kouji Matsui @kekyo2

Upload: baxter

Post on 23-Feb-2016

34 views

Category:

Documents


0 download

DESCRIPTION

Bluetooth で Go!. Bar Windows 8 in 名古屋 with 8.1 けきょ( Kouji Matsui @kekyo2 ). 自己紹介. けきょ @kekyo2 (あまり tweet してません) 会社やってます 「 Micoci 」と「まどべんよっかいち」 主に Windows 。 C#, C++/CLI, ATL, C++0x, x86/x64 アセンブラ , WDM, Azure, TFS, OpenCV , Geo, JNI, 鯖管理 , MCP 少々 , 自作 PC, 昔マイコン , 複式簿記経理 - PowerPoint PPT Presentation

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!

それでは、引き続きお楽しみ下さい ありがとうございました