xvcv

Dependencies:   BLE_API mbed nRF51822

Fork of MEDRON_SNIFFER_ABCD-KIMLIKLI-OLANLARI-TARAMA-YAPAR_30062016 by HAKAN AYDIN

Files at this revision

API Documentation at this revision

Comitter:
Adembay
Date:
Mon Sep 11 14:18:29 2017 +0000
Parent:
14:59ba4a2a17c7
Commit message:
c cx

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
spi_master.cpp Show annotated file Show diff for this revision Revisions of this file
spi_master.h Show annotated file Show diff for this revision Revisions of this file
diff -r 59ba4a2a17c7 -r d824140299d9 main.cpp
--- a/main.cpp	Thu Jun 30 07:09:50 2016 +0000
+++ b/main.cpp	Mon Sep 11 14:18:29 2017 +0000
@@ -1,133 +1,572 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2015 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+/*  
+     farklı macleri ara çıkartır ve aynı zamanda abcd leri gönderir.
+*/
 #include "mbed.h"
 #include "toolchain.h"
 #include "ble/BLE.h"
+#include "spi_master.h"
 
-//ABCD bir kimlik olarak belirlenir ve şifre vazifedi görür herhangi bir bluetooth modülü ABCD içerirse burada görülecektir.
-//Yayın okuyan program
+#define RSSI_DEGER 55 // -55dBm'in altındakileri görür.
+//# CS      P0_14
+//# SCK     P0_25
+//# MOSI    P0_20"
+//# MISO    P0_22
+DigitalOut spi_cs(P0_7);
 
-DigitalOut alivenessLED(LED1, 1);
+DigitalIn esp_baglimi(P0_11);
+
+DigitalOut alivenessLED(p2, 1);
+
 Ticker     ticker;
 Serial pc(TX_PIN_NUMBER, RX_PIN_NUMBER);
 
+
+SPIClass SPI1(NRF_SPI1);
+#define ToplamCihaz 1// (10) hakan değiştir 01122016
+#define bufferSize 60
+uint8_t       bulunan_index[ToplamCihaz];
+struct Medron_Data
+{    
+        uint8_t                         MacID[6];   // MAC ID leri bunun içinde tutacağız
+        uint8_t                         RSSI;   // MAC ID leri bunun içinde tutacağız
+        uint8_t                         LENGTH;
+        uint8_t                         MYDATA[50];
+        uint8_t                         PAKET_LENGTH;//SPI'YDAN STM32'YE GÖNDERİLCEK DATANIN TOPLAM
+                                                     //UZUNLUGU. 
+} PACKED_Data[ToplamCihaz]; 
+
+
+
+uint8_t say=0;
+
+void Flash_Buff_WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t len)
+{
+    uint16_t index;
+    
+    spi_cs = 0;
+    wait_us(20);     
+    for(index=0; index<len; index++)
+    {
+        SPI1.transfer(*pbuf);
+        pbuf++;        
+    }
+    
+    wait_us(20);
+    spi_cs = 1;
+}
+
+
+
+#define ARANAN_MAC_SAYI 5
+typedef struct
+{
+    uint8_t mac_id[6];
+}Beacon_MAC_ID; 
+
+Beacon_MAC_ID b_mac[ARANAN_MAC_SAYI];
+
+
+
 void periodicCallback(void)
 {
-    alivenessLED = !alivenessLED; /* Do blinky on LED1 while we're waiting for BLE events. This is optional. */
+  // alivenessLED = !alivenessLED; /* Do blinky on LED1 while we're waiting for BLE events. This is optional. */
 }
 
 /*
- * This function is called every time we scan an advertisement.
- */
+   This function is called every time we scan an advertisement.
+*/
 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
 {
-    struct AdvertisingData_t {
-        uint8_t                        length; /* doesn't include itself */
-        GapAdvertisingData::DataType_t dataType;
-        uint8_t                        data[0];
-    } PACKED;
+  struct AdvertisingData_t
+  {
+    uint8_t                        length; /* doesn't include itself */
+    GapAdvertisingData::DataType_t dataType;
+    uint8_t                        data[0];
+  } PACKED;
+
+  struct ApplicationData_t
+  {
+    uint16_t applicationSpecificId;             /* An ID used to identify temperature value
+                                                       in the manufacture specific AD data field */
+  } PACKED;
+  
+   
+   if(esp_baglimi)
+   {
+    
+          for (uint8_t macsay=0; macsay < ARANAN_MAC_SAYI; macsay++)
+          {
+          
+            if ((         params->peerAddr[5] == b_mac[macsay].mac_id[5]     &&  params->peerAddr[4] == b_mac[macsay].mac_id[4]
+                       && params->peerAddr[3] == b_mac[macsay].mac_id[3]     &&  params->peerAddr[2] == b_mac[macsay].mac_id[2]
+                       && params->peerAddr[1] == b_mac[macsay].mac_id[1]     &&  params->peerAddr[0] == b_mac[macsay].mac_id[0] ))
+            {
+
+                for (unsigned index = 0; index < 50; index++)
+                {
+                  PACKED_Data[say].MYDATA[index] = 0x00;
+                }
+
+              
+                PACKED_Data[say].MacID[5] = params->peerAddr[5];
+                PACKED_Data[say].MacID[4] = params->peerAddr[4];
+                PACKED_Data[say].MacID[3] = params->peerAddr[3];
+                PACKED_Data[say].MacID[2] = params->peerAddr[2];
+                PACKED_Data[say].MacID[1] = params->peerAddr[1];
+                PACKED_Data[say].MacID[0] = params->peerAddr[0];
+                    
 
-    struct ApplicationData_t {
-        uint16_t applicationSpecificId;             /* An ID used to identify temperature value
-                                                       in the manufacture specific AD data field */
-        //TMP_nrf51::TempSensorValue_t tmpSensorValue; /* User defined application data */
-    } PACKED;
+                /*
+                 EXAMPLE
+          
+                 fa 8c b3 c7 1c 61 :MAC ; 6 BYTE
+                 2b:RSSI;1BYTE
+                 0a:UZUNLUK;1BYTE-->0A H=10 D
+                 09  ff cd ab 01 00 4d 52 e8 00 00 00 00 00 00 00 00 00 00 00 ;DATA
+                 1   2  3  4  5  6  7  8  9  10  X  X  X  X  X  X  X  X  X  X ;DATA SAYISI
+          
+                 c8 60 85 e2 73 e2 :MAC:6
+                 37:RSSI:1
+                 08:LENGTH:1
+                 07 ff cd ab 00 00 e7 00:DATA
+                 1  2  3  4   5  6  7  8 ;DATA SAYISI
+          
+                */
+          
+                //PACKED_Data[say].PAKET_LENGTH= 6 + 1 + 1 + params->advertisingDataLen;//MAC+RSSI+1+LENGTH
+          
+                //IŞIK İSE
+                 if ((    params->peerAddr[5] ==0xac      &&   params->peerAddr[4] ==0x23 
+                       && params->peerAddr[3] ==0x3f      &&   params->peerAddr[2] ==0xb0 
+                       && params->peerAddr[1] ==0x42      &&   params->peerAddr[0] ==0x12))
+                 {  
+                         PACKED_Data[say].RSSI = (params->rssi) * -1;
+                         PACKED_Data[say].LENGTH = 10; //params->advertisingDataLen;
+                         PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 10; //MAC+RSSI+1+LENGTH  
+                       
+                         pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH);          
+                         PACKED_Data[say].MYDATA[0] = 0x07;
+                         PACKED_Data[say].MYDATA[1] = 0xff;
+                         
+                         PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil
+                         PACKED_Data[say].MYDATA[3] = 0xab;
+                         
+                         PACKED_Data[say].MYDATA[4] = 0x08;// tipi elle girilmiş.
+                         PACKED_Data[say].MYDATA[5] = 0x00;
+
+                         PACKED_Data[say].MYDATA[6] = params->advertisingData[14];// ISIK
+                         PACKED_Data[say].MYDATA[7] = 0x00;
+                         
+                         PACKED_Data[say].MYDATA[8] = params->advertisingData[13];//PİL
+                         PACKED_Data[say].MYDATA[9] = 0x00;
+                 } 
+                 
+                  if ((   params->peerAddr[5] ==0xac      &&   params->peerAddr[4] ==0x23 
+                       && params->peerAddr[3] ==0x3f      &&   params->peerAddr[2] ==0xa0 
+                       && params->peerAddr[1] ==0x03      &&   params->peerAddr[0] ==0xcd))
+                 {  
+                         PACKED_Data[say].RSSI = (params->rssi) * -1;
+                         PACKED_Data[say].LENGTH = 12; //params->advertisingDataLen;
+                         PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 12; //MAC+RSSI+1+LENGTH  
+                       
+                         pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH);          
+                         PACKED_Data[say].MYDATA[0] = 0x07;
+                         PACKED_Data[say].MYDATA[1] = 0xff;
+                         
+                         PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil
+                         PACKED_Data[say].MYDATA[3] = 0xab;
+                         
+                         PACKED_Data[say].MYDATA[4] = 0x09;// tipi elle girilmiş.
+                         PACKED_Data[say].MYDATA[5] = 0x00;
+
+                         PACKED_Data[say].MYDATA[6] = params->advertisingData[14];// temp
+                         PACKED_Data[say].MYDATA[7] = params->advertisingData[15];
+                         
+                         PACKED_Data[say].MYDATA[8] = params->advertisingData[16];//hum
+                         PACKED_Data[say].MYDATA[9] = params->advertisingData[17];
+                         
+                         PACKED_Data[say].MYDATA[10] = params->advertisingData[13];//PİL
+                         PACKED_Data[say].MYDATA[11] = 0x00;                        
+                 } 
+                
+                  if ((   params->peerAddr[5] ==0xac      &&   params->peerAddr[4] ==0x23 
+                       && params->peerAddr[3] ==0x3f      &&   params->peerAddr[2] ==0xa0 
+                       && params->peerAddr[1] ==0x04      &&   params->peerAddr[0] ==0x43))
+                 {  
+                         PACKED_Data[say].RSSI = (params->rssi) * -1;
+                         PACKED_Data[say].LENGTH = 12; //params->advertisingDataLen;
+                         PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 12; //MAC+RSSI+1+LENGTH  
+                       
+                         pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH);          
+                         PACKED_Data[say].MYDATA[0] = 0x07;
+                         PACKED_Data[say].MYDATA[1] = 0xff;
+                         
+                         PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil
+                         PACKED_Data[say].MYDATA[3] = 0xab;
+                         
+                         PACKED_Data[say].MYDATA[4] = 0x09;// tipi elle girilmiş.
+                         PACKED_Data[say].MYDATA[5] = 0x00;
 
-    static const uint16_t MED_KIMLIK = 0xABCD;
-    /* Search for the manufacturer specific data with matching application-ID */
-    AdvertisingData_t *pAdvData;
-    size_t index = 0;
-    while (index < params->advertisingDataLen) {
-        pAdvData = (AdvertisingData_t *)&params->advertisingData[index];
-        if (pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) {
-            ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data;
-            if (pAppData->applicationSpecificId == MED_KIMLIK ) {
-                /* dump information on the console. */
-                pc.printf("name=aysegul&pass=123&sender=sniffer1&temparaturedata=");// Birinci Sniffer
-                pc.printf("%02x%02x",0xFA,0xCC);//BASLANGIC BİTLERİ
-                //MAC adresi, RSSI 
-                pc.printf("%02x%02x%02x%02x%02x%02x%x",
-                params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],((params->rssi)*-1)); 
-                pc.printf("%02x",  params->advertisingDataLen);// AdvDATA UZUNLUGU
-                /* RSSI DEĞERİNİ DECİMALE ÇEVİRDİKTEN SONRA -1 İLE ÇARPILMALIDIR.  */
-                for (unsigned index = 0; index < params->advertisingDataLen; index++) 
+                         PACKED_Data[say].MYDATA[6] = params->advertisingData[14];// temp
+                         PACKED_Data[say].MYDATA[7] = params->advertisingData[15];
+                         
+                         PACKED_Data[say].MYDATA[8] = params->advertisingData[16];//hum
+                         PACKED_Data[say].MYDATA[9] = params->advertisingData[17];
+                         
+                         PACKED_Data[say].MYDATA[10] = params->advertisingData[13];//PİL
+                         PACKED_Data[say].MYDATA[11] = 0x00;                        
+                 } 
+                              
+                  if ((   params->peerAddr[5] ==0xCF      &&   params->peerAddr[4] ==0x70 
+                       && params->peerAddr[3] ==0x44      &&   params->peerAddr[2] ==0xD7 
+                       && params->peerAddr[1] ==0x12      &&   params->peerAddr[0] ==0xA8))
+                 {  
+                         PACKED_Data[say].RSSI = (params->rssi) * -1;
+                         PACKED_Data[say].LENGTH = 6; //params->advertisingDataLen;
+                         PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 6; //MAC+RSSI+1+LENGTH  
+                       
+                         pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH);          
+                         PACKED_Data[say].MYDATA[0] = 0x07;
+                         PACKED_Data[say].MYDATA[1] = 0xff;
+                         
+                         PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil
+                         PACKED_Data[say].MYDATA[3] = 0xab;
+                         
+                         PACKED_Data[say].MYDATA[4] = 0x05;// tipi elle girilmiş.
+                         PACKED_Data[say].MYDATA[5] = 0x00;                
+                 } 
+                 
+                  if ((   params->peerAddr[5] ==0xE6      &&   params->peerAddr[4] ==0xD0
+                       && params->peerAddr[3] ==0x4C      &&   params->peerAddr[2] ==0xFC 
+                       && params->peerAddr[1] ==0x4C      &&   params->peerAddr[0] ==0xB8))
+                 {  
+                         PACKED_Data[say].RSSI = (params->rssi) * -1;
+                         PACKED_Data[say].LENGTH = 14; //params->advertisingDataLen;
+                         PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 14; //MAC+RSSI+1+LENGTH  
+                       
+                         pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH);          
+                         PACKED_Data[say].MYDATA[0] = 0x07;
+                         PACKED_Data[say].MYDATA[1] = 0xff;
+                         
+                         PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil
+                         PACKED_Data[say].MYDATA[3] = 0xab;
+                         
+                         PACKED_Data[say].MYDATA[4] = 0x06;// tipi elle girilmiş.
+                         PACKED_Data[say].MYDATA[5] = 0x00;      
+                         
+                         PACKED_Data[say].MYDATA[6] = params->advertisingData[6];// x
+                         PACKED_Data[say].MYDATA[7] = params->advertisingData[7];      
+                         
+                         PACKED_Data[say].MYDATA[8] = params->advertisingData[8];//y
+                         PACKED_Data[say].MYDATA[9] = params->advertisingData[9];      
+                         
+                         PACKED_Data[say].MYDATA[10] = params->advertisingData[10];// z
+                         PACKED_Data[say].MYDATA[11] = params->advertisingData[11];      
+                         
+                         PACKED_Data[say].MYDATA[12] = params->advertisingData[12];// pil
+                         PACKED_Data[say].MYDATA[13] = params->advertisingData[13];      
+                                   
+                 } 
+                 
+                bulunan_index[say] = 0xff;
+                say++;
+          
+                if (say == ToplamCihaz)
                 {
-                       pc.printf("%02x", params->advertisingData[index]);
+          
+                  for (unsigned i = 0; i < say; i++)
+                  {
+                    uint8_t buffertoSpi[bufferSize];
+          
+                    for (unsigned a = 0; a < bufferSize; a++)
+                    {
+                      buffertoSpi[a] = 0x00;
+                    }
+          
+                    buffertoSpi[0] = PACKED_Data[i].PAKET_LENGTH;
+          
+                    for (unsigned a = 1; a < 7; a++)
+                    {
+                      buffertoSpi[a] = PACKED_Data[i].MacID[6 - a];
+                    }
+          
+                    buffertoSpi[7] = PACKED_Data[i].RSSI;
+                    buffertoSpi[8] = PACKED_Data[i].LENGTH;
+          
+                    for (unsigned a = 0; a < PACKED_Data[i].LENGTH; a++)
+                    {
+                      buffertoSpi[9 + a] = PACKED_Data[i].MYDATA[a];
+                    }
+          
+                    pc.printf("nRF51 to stm32f103 SENT (BEACON NUMBER = %d )   :  ", i);
+          
+                    for (unsigned a = 0; a < bufferSize; a++)
+                    {
+                      pc.printf("%02x", buffertoSpi[a]);
+                    }
+                    pc.printf("\r\n");
+          
+          
+                    Flash_Buff_WriteBytes(0, buffertoSpi, bufferSize);
+                    //wait_ms(200); // hakan ekledi 01122016
+                    wait_ms(20);
+                    bulunan_index[i] = 0x00;
+                  }
+                  say = 0;
                 }
-                pc.printf("%02x\r",0xFF);// BITIS
+                alivenessLED = 0;
 
-                break;
             }
-        }
-        index += (pAdvData->length + 1);
+          
+          }
+ 
+  
+  static const uint16_t MED_KIMLIK = 0xABCD;
+  AdvertisingData_t *pAdvData;
+  size_t index = 0;
+  while (index < params->advertisingDataLen) 
+  {
+    pAdvData = (AdvertisingData_t *)&params->advertisingData[index];
+    if (pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) 
+    {
+      ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data;
+      if (pAppData->applicationSpecificId == MED_KIMLIK)
+      {
+           
+       // if(params->rssi > -85)
+       // {
+           alivenessLED = 1;
+    
+           //pc.printf("%d\r", say+1);
+           
+           PACKED_Data[say].MacID[5]=params->peerAddr[5];
+           PACKED_Data[say].MacID[4]=params->peerAddr[4];
+           PACKED_Data[say].MacID[3]=params->peerAddr[3];
+           PACKED_Data[say].MacID[2]=params->peerAddr[2];
+           PACKED_Data[say].MacID[1]=params->peerAddr[1];
+           PACKED_Data[say].MacID[0]=params->peerAddr[0];
+           PACKED_Data[say].RSSI=(params->rssi) * -1;
+           PACKED_Data[say].LENGTH=params->advertisingDataLen;
+           /*
+            EXAMPLE
+           
+            fa 8c b3 c7 1c 61 :MAC ; 6 BYTE
+            2b:RSSI;1BYTE 
+            0a:UZUNLUK;1BYTE-->0A H=10 D
+            09  ff cd ab 01 00 4d 52 e8 00 00 00 00 00 00 00 00 00 00 00 ;DATA
+            1   2  3  4  5  6  7  8  9  10  X  X  X  X  X  X  X  X  X  X ;DATA SAYISI    
+            
+            c8 60 85 e2 73 e2 :MAC:6
+            37:RSSI:1
+            08:LENGTH:1
+            07 ff cd ab 00 00 e7 00:DATA
+            1  2  3  4  5  6  7  8 ;DATA SAYISI   
+               
+           */
+           
+            PACKED_Data[say].PAKET_LENGTH= 6 + 1 + 1 + params->advertisingDataLen;//MAC+RSSI+1+LENGTH
+            
+            pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ",PACKED_Data[say].PAKET_LENGTH); 
+            
+            for (unsigned index = 0; index < params->advertisingDataLen; index++)
+            {
+              PACKED_Data[say].MYDATA[index]=params->advertisingData[index];
+            }      
+            
+            for (unsigned index = params->advertisingDataLen; index < 50; index++)
+            {
+              PACKED_Data[say].MYDATA[index]=0x00;
+            } 
+            
+            bulunan_index[say]=0xff;
+            say++;
+            
+            if(say==ToplamCihaz)
+            {
+               
+               for (unsigned i = 0; i < say; i++)
+               { 
+                 uint8_t buffertoSpi[bufferSize];
+
+                 for (unsigned a = 0; a < bufferSize; a++)
+                 {
+                      buffertoSpi[a]=0x00;
+                 } 
+                  
+                 buffertoSpi[0]=PACKED_Data[i].PAKET_LENGTH;
+                 
+                 for (unsigned a = 1; a < 7; a++)
+                 { 
+                    buffertoSpi[a]= PACKED_Data[i].MacID[6-a];
+                 } 
+                 
+                 buffertoSpi[7]=PACKED_Data[i].RSSI; 
+                 buffertoSpi[8]=PACKED_Data[i].LENGTH;
+                 
+                 for (unsigned a = 0; a < PACKED_Data[i].LENGTH; a++)
+                 {
+                    buffertoSpi[9+a]=PACKED_Data[i].MYDATA[a];
+                 }
+    
+                 pc.printf("nRF51 to stm32f103 SENT (BEACON NUMBER = %d )   :  ",i); 
+                 
+                 for (unsigned a = 0; a < bufferSize; a++)
+                 {
+                      pc.printf("%02x",buffertoSpi[a]);
+                 } 
+                pc.printf("\r\n");
+                   
+
+                
+                 
+               Flash_Buff_WriteBytes(0, buffertoSpi, bufferSize); //eger esp nete baglandıysa göndermeye basla // 13072017
+              
+                //wait_ms(200); // hakan ekledi 01122016
+                //wait_ms(20);                    
+                bulunan_index[i]=0x00;                 
+               }
+              say=0;
+            }    
+           
+        alivenessLED = 0;
+        //}
+        break;
+      }
     }
+    index += (pAdvData->length + 1);
+  }
+  
+  
+  
+  }
+  
 }
 
 /**
- * This function is called when the ble initialization process has failed
- */
+   This function is called when the ble initialization process has failed
+*/
 void onBleInitError(BLE &ble, ble_error_t error)
 {
-    /* Initialization error handling should go here */
+  /* Initialization error handling should go here */
 }
 
 /**
- * Callback triggered when the ble initialization process has finished
- */
+   Callback triggered when the ble initialization process has finished
+*/
 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
 {
-    BLE&        ble   = params->ble;
-    ble_error_t error = params->error;
+  BLE&        ble   = params->ble;
+  ble_error_t error = params->error;
 
-    if (error != BLE_ERROR_NONE) {
-        /* In case of error, forward the error handling to onBleInitError */
-        onBleInitError(ble, error);
-        return;
-    }
+  if (error != BLE_ERROR_NONE) {
+    /* In case of error, forward the error handling to onBleInitError */
+    onBleInitError(ble, error);
+    return;
+  }
 
-    /* Ensure that it is the default instance of BLE */
-    if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
-        return;
-    }
+  /* Ensure that it is the default instance of BLE */
+  if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
+    return;
+  }
 
-    /* Setup and start scanning */
-    ble.gap().setScanParams(1800 /* scan interval */, 100 /* scan window */);
-    ble.gap().startScan(advertisementCallback);
+  /* Setup and start scanning */
+  ble.gap().setScanParams(100 /* scan interval */, 100 /* scan window */);
+  ble.gap().startScan(advertisementCallback);
+
 }
 
+void mac_id_gir()
+{          
+      
+   //ISIK SENSOR 
+   b_mac[0].mac_id[5]=0xAC;
+   b_mac[0].mac_id[4]=0x23;
+   b_mac[0].mac_id[3]=0x3F;
+   b_mac[0].mac_id[2]=0xB0;
+   b_mac[0].mac_id[1]=0x42;
+   b_mac[0].mac_id[0]=0x12;
+
+   //hum+temp  s1  SENSOR 
+   b_mac[1].mac_id[5]=0xAC;
+   b_mac[1].mac_id[4]=0x23;
+   b_mac[1].mac_id[3]=0x3F;
+   b_mac[1].mac_id[2]=0xa0;
+   b_mac[1].mac_id[1]=0x03;
+   b_mac[1].mac_id[0]=0xcd;  
+   
+   
+   //personel   SENSOR 
+   b_mac[2].mac_id[5]=0xCF;
+   b_mac[2].mac_id[4]=0x70;
+   b_mac[2].mac_id[3]=0x44;
+   b_mac[2].mac_id[2]=0xD7;
+   b_mac[2].mac_id[1]=0x12;
+   b_mac[2].mac_id[0]=0xA8;  
+   
+   
+  //motion   SENSOR 
+   b_mac[3].mac_id[5]=0xE6;
+   b_mac[3].mac_id[4]=0xD0;
+   b_mac[3].mac_id[3]=0x4C;
+   b_mac[3].mac_id[2]=0xFC;
+   b_mac[3].mac_id[1]=0x4C;
+   b_mac[3].mac_id[0]=0xB8;  
+   
+    //hum+temp  s1  SENSOR 
+   b_mac[4].mac_id[5]=0xAC;
+   b_mac[4].mac_id[4]=0x23;
+   b_mac[4].mac_id[3]=0x3F;
+   b_mac[4].mac_id[2]=0xa0;
+   b_mac[4].mac_id[1]=0x04;
+   b_mac[4].mac_id[0]=0x43;  
+    
+}
 int main(void)
 {
-    pc.baud(9600);                        //local terminal baud  
-    ticker.attach(periodicCallback, 1);  /* trigger sensor polling every 2 seconds */
+  pc.baud(115200); //local terminal baud
+  mac_id_gir();
+  pc.printf("MEDRON SNIFFER nRF51\r\n"); 
+  //ticker.attach(periodicCallback, 1);  /* trigger sensor polling every 2 seconds */
+  
+  for(uint8_t i;i<ToplamCihaz;i++)
+  {
+      bulunan_index[i]=0x00;//0x00 ise bulunan mac id gönderilmiştir stm32f'e
+                            // eğer ff ise gönderilmemistir.
+  }
 
-    for(uint8_t say=0; say<5; say++ )
-    { 
-        wait(1);
-         pc.printf("wifi_id=MedronTeknoloji|<>|pass=medron2011");
-       
-        //pc.printf("wifi_id=AndroidAP|<>|pass=duqy0286"); //Ayşegülün telefonuna bağlanırken kullanıyorduk
-        pc.printf("\r");
-        
+/*
+while(1)
+{
+    uint8_t buffertoSpi[58];
+                 buffertoSpi[0]=0x00;
+                  buffertoSpi[1]=0x01;
+                   buffertoSpi[2]=0x02;
+                     buffertoSpi[3]=0x03;
+                       buffertoSpi[4]=0x04;
+                 for (unsigned a = 5; a < 58; a++)
+                  {
+                      buffertoSpi[a]=+a;
+                      pc.printf("%02x",buffertoSpi[a]);
+                  } 
+                   Flash_Buff_WriteBytes(0, buffertoSpi, 58);
+                   pc.printf("\r\n"); 
+                    wait_ms(1000); 
     }
 
+*/
 
-    BLE &ble = BLE::Instance();
-    ble.init(bleInitComplete);
+  while(!esp_baglimi)
+  {
+      wait_ms(1);
+  }
+
+  SPI1.begin();
 
-    while (true) {
-        ble.waitForEvent();
-    }
+  BLE &ble = BLE::Instance();
+  ble.init(bleInitComplete);
+
+  while (true)
+ {
+    ble.waitForEvent();
+  }
 }
diff -r 59ba4a2a17c7 -r d824140299d9 spi_master.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spi_master.cpp	Mon Sep 11 14:18:29 2017 +0000
@@ -0,0 +1,236 @@
+/*
+
+Copyright (c) 2012-2014 RedBearLab
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+and associated documentation files (the "Software"), to deal in the Software without restriction, 
+including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
+subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
+FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+*/
+
+#include "spi_master.h"
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+SPIClass::SPIClass(NRF_SPI_Type *_spi) : spi(_spi)
+{
+    //do nothing
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+void SPIClass::setCPOL( bool active_low)
+{
+    if(active_low)
+    {
+        spi->CONFIG |= (SPI_CONFIG_CPOL_ActiveLow << SPI_CONFIG_CPOL_Pos);
+    }
+    else
+    {
+        spi->CONFIG |= (SPI_CONFIG_CPOL_ActiveHigh << SPI_CONFIG_CPOL_Pos);
+    }
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+void SPIClass::setCPHA( bool trailing)
+{
+    if(trailing)
+    {
+        spi->CONFIG |= (SPI_CONFIG_CPHA_Trailing << SPI_CONFIG_CPHA_Pos);
+    }
+    else
+    {
+        spi->CONFIG |= (SPI_CONFIG_CPHA_Leading << SPI_CONFIG_CPHA_Pos);
+    }
+
+}
+
+/**********************************************************************
+name :
+function : MSBFIRST, LSBFIRST
+**********************************************************************/
+void SPIClass::setBitORDER( BitOrder  bit)
+{
+    if(bit == MSBFIRST)
+    {
+        spi->CONFIG |= (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos);
+    }
+    else
+    {
+        spi->CONFIG |= (SPI_CONFIG_ORDER_LsbFirst << SPI_CONFIG_ORDER_Pos);
+    }
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+void SPIClass::setFrequency(uint8_t speed)
+{
+    if (speed == 0)
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_125K;
+    }
+    else if (speed == 1)
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_250K;
+    }
+    else if (speed == 2)
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_500K;
+    }
+    else if (speed == 3)
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_1M;
+    }
+    else if (speed == 4)
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_2M;
+    }
+    else if (speed == 5)
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_4M;
+    }
+    else if (speed == 6)
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_8M;
+    }
+    else
+    {
+        spi->FREQUENCY = SPI_FREQUENCY_4M;
+    }   
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+void SPIClass::setSPIMode( uint8_t mode )
+{
+    if (SPI_MODE0 == mode)
+    {
+        setCPOL(0);
+        setCPHA(0);     
+    }
+    else if (mode == SPI_MODE1)
+    {
+        setCPOL(0);
+        setCPHA(1);
+    }
+    else if (mode == SPI_MODE2)
+    {
+        setCPOL(1);
+        setCPHA(0);
+    }
+    else if (mode == SPI_MODE3)
+    {
+        setCPOL(1);
+        setCPHA(1);
+    }
+    else
+    {
+        setCPOL(0);
+        setCPHA(0);         
+    }
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+void SPIClass::begin(uint32_t sck, uint32_t mosi, uint32_t miso)
+{
+
+        SCK_Pin = sck;
+        MOSI_Pin = mosi;
+        MISO_Pin = miso;
+        
+        NRF_GPIO->PIN_CNF[SCK_Pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
+                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
+                                        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
+                                        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
+                                        | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);    
+                                        
+        NRF_GPIO->PIN_CNF[MOSI_Pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
+                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
+                                        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
+                                        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
+                                        | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
+                                        
+        NRF_GPIO->PIN_CNF[MISO_Pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
+                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
+                                        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
+                                        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
+                                        | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);                                     
+        spi->PSELSCK  = SCK_Pin;
+        spi->PSELMOSI = MOSI_Pin;
+        spi->PSELMISO = MISO_Pin;       
+        
+        setFrequency(SPI_2M);
+        setSPIMode(SPI_MODE0);
+        setBitORDER(MSBFIRST);
+        
+        spi->EVENTS_READY = 0;
+        spi->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos);
+    
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+void SPIClass::begin()
+{
+    begin(SCK, MOSI, MISO);
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+uint8_t SPIClass::transfer(uint8_t data)
+{
+    while( spi->EVENTS_READY != 0U );
+    
+    spi->TXD = (uint32_t)data;
+    
+    while(spi->EVENTS_READY == 0);
+    
+    data = (uint8_t)spi->RXD;
+    
+    spi->EVENTS_READY = 0;
+    
+    return data;
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+void SPIClass::endTransfer()
+{
+    spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
+}
+
+/**********************************************************************
+name :
+function : 
+**********************************************************************/
+
+//SPIClass SPI(NRF_SPI1);
diff -r 59ba4a2a17c7 -r d824140299d9 spi_master.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spi_master.h	Mon Sep 11 14:18:29 2017 +0000
@@ -0,0 +1,84 @@
+/*
+
+Copyright (c) 2012-2014 RedBearLab
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+and associated documentation files (the "Software"), to deal in the Software without restriction, 
+including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
+and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
+subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
+FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+*/
+
+#ifndef _SPI_MASTER_H_
+#define _SPI_MASTER_H_
+
+#include "mbed.h"
+
+#define SPI_FREQUENCY_125K 0x02000000UL
+#define SPI_FREQUENCY_250K 0x04000000UL
+#define SPI_FREQUENCY_500K 0x08000000UL
+#define SPI_FREQUENCY_1M   0x10000000UL
+#define SPI_FREQUENCY_2M   0x20000000UL
+#define SPI_FREQUENCY_4M   0x40000000UL
+#define SPI_FREQUENCY_8M   0x80000000UL
+
+#define SPI_125K 0
+#define SPI_250K 1
+#define SPI_500K 2
+#define SPI_1M   3
+#define SPI_2M   4
+#define SPI_4M   5
+#define SPI_8M   6
+
+#define SPI_MODE0 0
+#define SPI_MODE1 1
+#define SPI_MODE2 2
+#define SPI_MODE3 3
+
+#define CS      P0_14
+#define SCK     P0_25
+#define MOSI    P0_20
+#define MISO    P0_22
+
+typedef enum{
+    
+    MSBFIRST = 0,
+    LSBFIRST = 1
+    
+}BitOrder;
+
+class SPIClass
+{
+    public:
+        SPIClass(NRF_SPI_Type *_spi);
+    
+        void begin();
+        void begin(uint32_t sck, uint32_t mosi, uint32_t miso);
+        uint8_t transfer(uint8_t data);
+        void endTransfer();
+            
+        void setSPIMode( uint8_t mode );
+        void setFrequency(uint8_t speed );
+        void setBitORDER( BitOrder  bit);
+        void setCPHA( bool trailing);
+        void setCPOL( bool active_low);
+        
+        
+    private:
+        NRF_SPI_Type *spi;
+        
+        uint32_t SCK_Pin;
+        uint32_t MOSI_Pin;
+        uint32_t MISO_Pin;
+
+};
+
+#endif