kyowa / Mbed 2 deprecated HRM1017R

Dependencies:   BLE_API mbed nRF51822

Files at this revision

API Documentation at this revision

Comitter:
kyowa_watanabe
Date:
Fri Jun 19 12:16:50 2015 +0000
Commit message:
??????UUID???

Changed in this revision

BLE_API.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c3d581e41fb4 BLE_API.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE_API.lib	Fri Jun 19 12:16:50 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#c4436674db7b
diff -r 000000000000 -r c3d581e41fb4 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 19 12:16:50 2015 +0000
@@ -0,0 +1,126 @@
+// ヘッダのインクルード
+#include "mbed.h"
+#include "BLEDevice.h"
+
+#define CHARACTERISTIC_LEN 100
+
+// デバイス名の登録
+const static char  DEVICE_NAME[] = "mbed_HRM1017";
+
+// UUIDの登録
+static const uint8_t UUID_BRIL_SERVICE[]    = {0x4d,0x92,0x37,0xc0,0xbd,0x5b,0x45,0x93,0xad,0x55,0xd8,0xf5,0x95,0xcf,0xe2,0xea};
+static const uint8_t UUID_CHAR_DATA[]       = {0xe5,0xc1,0xcf,0x6e,0xe0,0x57,0x40,0x08,0x98,0x21,0x17,0x71,0x10,0x24,0xe8,0x85};
+
+// 
+uint8_t gRwData[CHARACTERISTIC_LEN] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
+int g_conflg = 0;
+int g_test = 0;
+int g_receiveflg = 0;
+uint8_t g_txdata[100];
+uint8_t g_rxdata[100];
+
+BLEDevice   ble;
+Serial      pc(USBTX, USBRX);
+
+uint8_t     txTempPayload[100];
+
+GattCharacteristic  gDataCharacteristic ( UUID_CHAR_DATA, gRwData, sizeof(gRwData), sizeof(gRwData),
+                                            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE);
+
+GattCharacteristic txChar( 0x3A01, txTempPayload, 100, 100,
+                                GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE |
+                                GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |
+                                GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE );
+
+// バッテリーレベル用変数
+uint8_t     rxTempPayload[100];
+
+// バッテリーレベル用GATT
+GattCharacteristic rxChar( 0x3A02, rxTempPayload, 100, 100,
+                                GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY |
+                                GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |
+                                GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE );
+
+// 
+GattCharacteristic *txChars[] = {&txChar, };
+GattCharacteristic *rxChars[] = {&rxChar, };
+GattCharacteristic *RwDataChars[] = {&gDataCharacteristic};
+
+GattService     txService( 0x181C, txChars, sizeof(txChars) / sizeof(GattCharacteristic * ) );
+GattService     rxService( 0x181C, rxChars, sizeof(rxChars) / sizeof(GattCharacteristic * ) );
+
+GattService     gBrilService = GattService(UUID_BRIL_SERVICE, RwDataChars, sizeof(RwDataChars) / sizeof(GattCharacteristic *));
+
+uint16_t        uuid16_list[] = { 0x181C, };
+
+static Gap::ConnectionParams_t connectionParams;
+
+void onDisconnectionCallback( Gap::Handle_t handle, Gap::DisconnectionReason_t reason ){
+
+    g_conflg = 0;
+    ble.startAdvertising();
+    pc.printf( "Disconnect!!\r\n" );
+
+}
+
+void onConnectionCallback( Gap::Handle_t handle, Gap::addr_type_t type, const Gap::address_t addr,
+                            Gap::addr_type_t addr_type_townAddrType, const Gap::address_t ownAddr,
+                            const Gap::ConnectionParams_t *params ){
+
+    g_conflg = 1;
+    pc.printf( "Connect!!\r\n" );
+
+}
+
+void onDataWrittenCallback( const GattCharacteristicWriteCBParams *params ){
+    int i;
+    
+    uint16_t bytesread = params->len;
+
+    pc.printf( "Written %d Bytes.\r\n", bytesread );
+    for( i = 0; i < bytesread; i++ ){
+        pc.printf( "%02x",params->data[i] );
+        if( ( i + 1 ) < bytesread ){
+            pc.printf( ", " );
+        }
+    }
+    pc.printf( "\r\n" );
+
+
+    ble.updateCharacteristicValue( txChar.getValueAttribute().getHandle(), params->data, bytesread );
+
+}
+
+int main( void )
+{
+
+// 初期設定
+    ble.init();
+// コールバック関数の設定
+    ble.onDisconnection( onDisconnectionCallback );
+    ble.onConnection( onConnectionCallback );
+    ble.onDataWritten(onDataWrittenCallback);
+
+    ble.getPreferredConnectionParams( &connectionParams );
+
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+//    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list));
+//    ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.setAdvertisingInterval(160);    // 100ms; in multiples of 0.625ms
+    ble.setAdvertisingTimeout(0);       // アドバタイジングモードのタイムアウト無効
+
+// アドバタイズモード開始
+    ble.startAdvertising();
+
+// サービスの追加
+    ble.addService( txService );
+    ble.addService( rxService );
+
+    while(1){
+
+        ble.waitForEvent();
+
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r c3d581e41fb4 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 19 12:16:50 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file
diff -r 000000000000 -r c3d581e41fb4 nRF51822.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF51822.lib	Fri Jun 19 12:16:50 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#d0fc349b9a1b