TeleViLibに対応するMSC

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleChat_LED_kai by EQUUS_KUBOTA

Revision:
4:41cf035db84a
Parent:
3:b3f6c612b603
Child:
5:35728098eeae
diff -r b3f6c612b603 -r 41cf035db84a main.cpp
--- a/main.cpp	Thu Jan 07 02:46:54 2016 +0000
+++ b/main.cpp	Sat Dec 03 10:44:01 2016 +0000
@@ -33,18 +33,32 @@
 #define BLE_UUIDS_RX_CHARACTERISTIC      0x0003 /**< The UUID of the RX Characteristic. */
 
 #define TXRX_BUF_LEN                     20
+#define DIGITAL_OUT_PIN                  P0_17  //D7
+
+
 
 BLE  ble;
 
 Serial pc(USBTX, USBRX);
 
+DigitalOut led1(DIGITAL_OUT_PIN);
+DigitalOut ledori1(LED1);
 
 // The Nordic UART Service
-static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
-static const uint8_t uart_tx_uuid[]   = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
-static const uint8_t uart_rx_uuid[]   = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
-static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
+//static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
+//static const uint8_t uart_tx_uuid[]   = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
+//static const uint8_t uart_rx_uuid[]   = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
+//static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
 
+// The Service
+static const uint8_t uart_base_uuid[] = {0x02, 0xF3, 0xF5, 0x38, 0x8D, 0x11, 0x48, 0x02, 0xB6, 0xFC, 0xFB, 0x66, 0x16, 0xD4, 0xCD, 0x70}; //Service
+static const uint8_t uart_tx_uuid[]   = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_送信用
+static const uint8_t uart_rx_uuid[]   = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; //central_受信用
+static const uint8_t uart_base_uuid_rev[] = {0x70, 0xCD, 0xD4, 0x16, 0x66, 0xFB, 0xFC, 0xB6, 0x02, 0x48, 0x11, 0x8D, 0x38, 0xF5, 0xF3, 0x02};
+
+//02f3f538-8d11-4802-b6fc-fb6616d4cd70
+
+const static char     DEVICE_NAME[]        = "KEI_LED"; // change this
 
 uint8_t txPayload[TXRX_BUF_LEN] = {0,};
 uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
@@ -70,6 +84,13 @@
     ble.startAdvertising();
 }
 
+void ConnectionCallback(const Gap::ConnectionCallbackParams_t *params)
+{
+    pc.printf("Disconnected \r\n");
+    pc.printf("Restart advertising \r\n");
+    ble.startAdvertising();
+}
+
 void WrittenHandler(const GattWriteCallbackParams *Handler)
 {   
     uint8_t buf[TXRX_BUF_LEN];
@@ -82,12 +103,27 @@
         memcpy(txPayload, buf, TXRX_BUF_LEN);       
         pc.printf("WriteHandler \r\n");
         pc.printf("Length: ");
-        pc.putc(bytesRead);
+        pc.putc(bytesRead); //受け取った文字の先頭アドレス?
+        pc.printf("\r\n");
+        pc.printf("[0]: ");
+        pc.putc(txPayload[1]); //1文字目を表示
+        if(txPayload[1]=='a') {
+            pc.printf("yeahhhhhh!!!!!!!!");
+//            if(led1 == 0) {
+                led1 = 1;
+                ledori1 = 1;
+//            } else {
+//                led1 = 0;
+//            }
+        } else if(txPayload[1]=='b') {
+            led1 = 0;
+            ledori1 = 0;
+        }
         pc.printf("\r\n");
         pc.printf("Data: ");
         for(index=0; index<bytesRead; index++)
         {
-            pc.putc(txPayload[index]);        
+            pc.putc(txPayload[index]);
         }
         pc.printf("\r\n");
     }
@@ -113,9 +149,12 @@
 
 int main(void)
 {
+    led1 = 0;
+    ledori1 = 0;
     ble.init();
     ble.onDisconnection(disconnectionCallback);
-    ble.onDataWritten(WrittenHandler);  
+    ble.onDataWritten(WrittenHandler);
+    ble.onConnection(ConnectionCallback);
     
     pc.baud(9600);
     pc.printf("SimpleChat Init \r\n");
@@ -125,11 +164,11 @@
     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
-                                    (const uint8_t *)"Biscuit", sizeof("Biscuit") - 1);
+                                    (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 1);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
     // 100ms; in multiples of 0.625ms. 
-    ble.setAdvertisingInterval(160);
+    ble.setAdvertisingInterval(50);
 
     ble.addService(uartService);
     
@@ -141,19 +180,3 @@
         ble.waitForEvent(); 
     }
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-