Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of MEDRON_SNIFFER_ABCD-KIMLIKLI-OLANLARI-TARAMA-YAPAR_30062016 by
main.cpp
00001 #include "mbed.h" 00002 #include "toolchain.h" 00003 #include "ble/BLE.h" 00004 #include "spi_master.h" 00005 00006 00007 /////////////////////////////SPI////////////////////// 00008 SPIClass SPI1(NRF_SPI1); 00009 //# CS P0_14 00010 //# SCK P0_25 00011 //# MOSI P0_20" 00012 //# MISO P0_22 00013 DigitalOut spi_cs(P0_7); 00014 ///////////////////////////////////////////////////// 00015 00016 DigitalIn esp_baglimi(P0_11); 00017 00018 ////////////////////////////////DATA_FORMATIM/////////////////////////////////////////////////////// 00019 00020 Serial pc(TX_PIN_NUMBER, P0_3/*RX_PIN_NUMBER*/); 00021 00022 #define ToplamCihaz 1// (10) hakan değiştir 01122016 00023 #define bufferSize 60 00024 uint8_t bulunan_index[ToplamCihaz]; 00025 struct Medron_Data 00026 { 00027 uint8_t MacID[6]; // MAC ID leri bunun içinde tutacağız 00028 uint8_t RSSI; // MAC ID leri bunun içinde tutacağız 00029 uint8_t LENGTH; 00030 uint8_t MYDATA[50]; 00031 uint8_t PAKET_LENGTH;//SPI'YDAN STM32'YE GÖNDERİLCEK DATANIN TOPLAM 00032 //UZUNLUGU. 00033 } PACKED_Data[ToplamCihaz]; 00034 ////////////////////////////////////////////////////////////////////////////////////////////////// 00035 00036 00037 /////////////////////////////////////////////////////////////////////////////////////////////////// 00038 // ÖZEL BİR BEACON ALIYORSAK BU KULLANILIR. ARANACAK OLAN BEACON SAYILARI BELİRTİLMELİ 00039 // VE BEACON MAC ID'SI SİSTEME TANITILMALIDIR. 00040 #define ARANAN_MAC_SAYI 6 00041 typedef struct 00042 { 00043 uint8_t mac_id[6]; 00044 }Beacon_MAC_ID; 00045 Beacon_MAC_ID b_mac[ARANAN_MAC_SAYI]; 00046 uint8_t say=0; 00047 00048 void mac_id_gir() 00049 { 00050 00051 //ISIK SENSOR 00052 b_mac[0].mac_id[5]=0xAC; 00053 b_mac[0].mac_id[4]=0x23; 00054 b_mac[0].mac_id[3]=0x3F; 00055 b_mac[0].mac_id[2]=0xB0; 00056 b_mac[0].mac_id[1]=0x42; 00057 b_mac[0].mac_id[0]=0x12; 00058 00059 //hum+temp s1 SENSOR 00060 b_mac[1].mac_id[5]=0xAC; 00061 b_mac[1].mac_id[4]=0x23; 00062 b_mac[1].mac_id[3]=0x3F; 00063 b_mac[1].mac_id[2]=0xa0; 00064 b_mac[1].mac_id[1]=0x03; 00065 b_mac[1].mac_id[0]=0xcd; 00066 00067 00068 /* //personel SENSOR 00069 b_mac[2].mac_id[5]=0xe7; 00070 b_mac[2].mac_id[4]=0x5e; 00071 b_mac[2].mac_id[3]=0xb3; 00072 b_mac[2].mac_id[2]=0x21; 00073 b_mac[2].mac_id[1]=0x69;* 00074 b_mac[2].mac_id[0]=0xa6; */ 00075 00076 //personel SENSOR 00077 b_mac[2].mac_id[5]=0xCF; 00078 b_mac[2].mac_id[4]=0x70; 00079 b_mac[2].mac_id[3]=0x44; 00080 b_mac[2].mac_id[2]=0xD7; 00081 b_mac[2].mac_id[1]=0x12; 00082 b_mac[2].mac_id[0]=0xA8; 00083 00084 00085 //motion SENSOR 00086 b_mac[3].mac_id[5]=0xC7; 00087 b_mac[3].mac_id[4]=0x6E; 00088 b_mac[3].mac_id[3]=0x50; 00089 b_mac[3].mac_id[2]=0x70; 00090 b_mac[3].mac_id[1]=0x64; 00091 b_mac[3].mac_id[0]=0x6E; 00092 00093 //hum+temp s1 SENSOR 00094 b_mac[4].mac_id[5]=0xAC; 00095 b_mac[4].mac_id[4]=0x23; 00096 b_mac[4].mac_id[3]=0x3F; 00097 b_mac[4].mac_id[2]=0xa0; 00098 b_mac[4].mac_id[1]=0x04; 00099 b_mac[4].mac_id[0]=0x43; 00100 00101 //motion SENSOR 00102 b_mac[5].mac_id[5]=0xE6; 00103 b_mac[5].mac_id[4]=0xD0; 00104 b_mac[5].mac_id[3]=0x4C; 00105 b_mac[5].mac_id[2]=0xFC; 00106 b_mac[5].mac_id[1]=0x4C; 00107 b_mac[5].mac_id[0]=0xB8; 00108 } 00109 //////////////////////////////////////////////////////////////////////////////////////////////// 00110 00111 void Flash_Buff_WriteBytes(uint16_t addr, uint8_t *pbuf, uint16_t len) 00112 { 00113 uint16_t index; 00114 00115 spi_cs = 0; 00116 wait_us(20); 00117 for(index=0; index<len; index++) 00118 { 00119 SPI1.transfer(*pbuf); 00120 pbuf++; 00121 } 00122 00123 wait_us(20); 00124 spi_cs = 1; 00125 } 00126 00127 /* 00128 This function is called every time we scan an advertisement. 00129 */ 00130 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) 00131 { 00132 00133 /* EXAMPLE 00134 00135 fa 8c b3 c7 1c 61 :MAC ; 6 BYTE 00136 2b:RSSI;1BYTE 00137 0a:UZUNLUK;1BYTE-->0A H=10 D 00138 09 ff cd ab 01 00 4d 52 e8 00 00 00 00 00 00 00 00 00 00 00 ;DATA 00139 1 2 3 4 5 6 7 8 9 10 X X X X X X X X X X ;DATA SAYISI 00140 00141 c8 60 85 e2 73 e2 :MAC:6 00142 37:RSSI:1 00143 08:LENGTH:1 00144 07 ff cd ab 00 00 e7 00:DATA 00145 1 2 3 4 5 6 7 8 ;DATA SAYISI 00146 */ 00147 00148 struct AdvertisingData_t 00149 { 00150 uint8_t length; /* doesn't include itself */ 00151 GapAdvertisingData::DataType_t dataType; 00152 uint8_t data[0]; 00153 } PACKED; 00154 00155 struct ApplicationData_t 00156 { 00157 uint16_t applicationSpecificId; /* An ID used to identify temperature value 00158 in the manufacture specific AD data field */ 00159 } PACKED; 00160 00161 00162 for (uint8_t macsay=0; macsay < ARANAN_MAC_SAYI; macsay++) 00163 { 00164 00165 if (( params->peerAddr[5] == b_mac[macsay].mac_id[5] && params->peerAddr[4] == b_mac[macsay].mac_id[4] 00166 && params->peerAddr[3] == b_mac[macsay].mac_id[3] && params->peerAddr[2] == b_mac[macsay].mac_id[2] 00167 && params->peerAddr[1] == b_mac[macsay].mac_id[1] && params->peerAddr[0] == b_mac[macsay].mac_id[0] )) 00168 { 00169 00170 PACKED_Data[say].MacID[5] = params->peerAddr[5]; 00171 PACKED_Data[say].MacID[4] = params->peerAddr[4]; 00172 PACKED_Data[say].MacID[3] = params->peerAddr[3]; 00173 PACKED_Data[say].MacID[2] = params->peerAddr[2]; 00174 PACKED_Data[say].MacID[1] = params->peerAddr[1]; 00175 PACKED_Data[say].MacID[0] = params->peerAddr[0]; 00176 //IŞIK İSE 00177 if (( params->peerAddr[5] ==0xac && params->peerAddr[4] ==0x23 00178 && params->peerAddr[3] ==0x3f && params->peerAddr[2] ==0xb0 00179 && params->peerAddr[1] ==0x42 && params->peerAddr[0] ==0x12)) 00180 { 00181 PACKED_Data[say].RSSI = (params->rssi) * -1; 00182 PACKED_Data[say].LENGTH = 10; //params->advertisingDataLen; 00183 PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 10; //MAC+RSSI+1+LENGTH 00184 00185 pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH); 00186 PACKED_Data[say].MYDATA[0] = 0x07; 00187 PACKED_Data[say].MYDATA[1] = 0xff; 00188 00189 PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil 00190 PACKED_Data[say].MYDATA[3] = 0xab; 00191 00192 PACKED_Data[say].MYDATA[4] = 0x08;// tipi elle girilmiş. 00193 PACKED_Data[say].MYDATA[5] = 0x00; 00194 00195 PACKED_Data[say].MYDATA[6] = params->advertisingData[14];// ISIK 00196 PACKED_Data[say].MYDATA[7] = 0x00; 00197 00198 PACKED_Data[say].MYDATA[8] = params->advertisingData[13];//PİL 00199 PACKED_Data[say].MYDATA[9] = 0x00; 00200 } 00201 00202 if (( params->peerAddr[5] ==0xac && params->peerAddr[4] ==0x23 00203 && params->peerAddr[3] ==0x3f && params->peerAddr[2] ==0xa0 00204 && params->peerAddr[1] ==0x03 && params->peerAddr[0] ==0xcd)) 00205 { 00206 PACKED_Data[say].RSSI = (params->rssi) * -1; 00207 PACKED_Data[say].LENGTH = 12; //params->advertisingDataLen; 00208 PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 12; //MAC+RSSI+1+LENGTH 00209 00210 pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH); 00211 PACKED_Data[say].MYDATA[0] = 0x07; 00212 PACKED_Data[say].MYDATA[1] = 0xff; 00213 00214 PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil 00215 PACKED_Data[say].MYDATA[3] = 0xab; 00216 00217 PACKED_Data[say].MYDATA[4] = 0x09;// tipi elle girilmiş. 00218 PACKED_Data[say].MYDATA[5] = 0x00; 00219 00220 PACKED_Data[say].MYDATA[6] = params->advertisingData[14];// temp 00221 PACKED_Data[say].MYDATA[7] = params->advertisingData[15]; 00222 00223 PACKED_Data[say].MYDATA[8] = params->advertisingData[16];//hum 00224 PACKED_Data[say].MYDATA[9] = params->advertisingData[17]; 00225 00226 PACKED_Data[say].MYDATA[10] = params->advertisingData[13];//PİL 00227 PACKED_Data[say].MYDATA[11] = 0x00; 00228 } 00229 00230 if (( params->peerAddr[5] ==0xac && params->peerAddr[4] ==0x23 00231 && params->peerAddr[3] ==0x3f && params->peerAddr[2] ==0xa0 00232 && params->peerAddr[1] ==0x04 && params->peerAddr[0] ==0x43)) 00233 { 00234 PACKED_Data[say].RSSI = (params->rssi) * -1; 00235 PACKED_Data[say].LENGTH = 12; //params->advertisingDataLen; 00236 PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 12; //MAC+RSSI+1+LENGTH 00237 00238 pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH); 00239 PACKED_Data[say].MYDATA[0] = 0x07; 00240 PACKED_Data[say].MYDATA[1] = 0xff; 00241 00242 PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil 00243 PACKED_Data[say].MYDATA[3] = 0xab; 00244 00245 PACKED_Data[say].MYDATA[4] = 0x09;// tipi elle girilmiş. 00246 PACKED_Data[say].MYDATA[5] = 0x00; 00247 00248 PACKED_Data[say].MYDATA[6] = params->advertisingData[14];// temp 00249 PACKED_Data[say].MYDATA[7] = params->advertisingData[15]; 00250 00251 PACKED_Data[say].MYDATA[8] = params->advertisingData[16];//hum 00252 PACKED_Data[say].MYDATA[9] = params->advertisingData[17]; 00253 00254 PACKED_Data[say].MYDATA[10] = params->advertisingData[13];//PİL 00255 PACKED_Data[say].MYDATA[11] = 0x00; 00256 } 00257 00258 00259 00260 if (( params->peerAddr[5] ==0xCF && params->peerAddr[4] ==0x70 00261 && params->peerAddr[3] ==0x44 && params->peerAddr[2] ==0xD7 00262 && params->peerAddr[1] ==0x12 && params->peerAddr[0] ==0xA8)) 00263 { 00264 PACKED_Data[say].RSSI = (params->rssi) * -1; 00265 PACKED_Data[say].LENGTH = 6; //params->advertisingDataLen; 00266 PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 6; //MAC+RSSI+1+LENGTH 00267 00268 pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH); 00269 PACKED_Data[say].MYDATA[0] = 0x07; 00270 PACKED_Data[say].MYDATA[1] = 0xff; 00271 00272 PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil 00273 PACKED_Data[say].MYDATA[3] = 0xab; 00274 00275 PACKED_Data[say].MYDATA[4] = 0x05;// tipi elle girilmiş. 00276 PACKED_Data[say].MYDATA[5] = 0x00; 00277 } 00278 00279 if (( params->peerAddr[5] ==0xC7 && params->peerAddr[4] ==0x6E 00280 && params->peerAddr[3] ==0x50 && params->peerAddr[2] ==0x70 00281 && params->peerAddr[1] ==0x64 && params->peerAddr[0] ==0x6E)) 00282 { 00283 PACKED_Data[say].RSSI = (params->rssi) * -1; 00284 PACKED_Data[say].LENGTH = 6; //params->advertisingDataLen; 00285 PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 6; //MAC+RSSI+1+LENGTH 00286 00287 pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH); 00288 PACKED_Data[say].MYDATA[0] = 0x07; 00289 PACKED_Data[say].MYDATA[1] = 0xff; 00290 00291 PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil 00292 PACKED_Data[say].MYDATA[3] = 0xab; 00293 00294 PACKED_Data[say].MYDATA[4] = 0x07;// tipi elle girilmiş. 00295 PACKED_Data[say].MYDATA[5] = 0x00; 00296 } 00297 00298 /* if (( params->peerAddr[5] ==0xC7 && params->peerAddr[4] ==0x6E 00299 && params->peerAddr[3] ==0x50 && params->peerAddr[2] ==0x70 00300 && params->peerAddr[1] ==0x64 && params->peerAddr[0] ==0x6E)) 00301 { 00302 PACKED_Data[say].RSSI = (params->rssi) * -1; 00303 PACKED_Data[say].LENGTH = 14; //params->advertisingDataLen; 00304 PACKED_Data[say].PAKET_LENGTH = 6 + 1 + 1 + 14; //MAC+RSSI+1+LENGTH 00305 00306 pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ", PACKED_Data[say].PAKET_LENGTH); 00307 PACKED_Data[say].MYDATA[0] = 0x07; 00308 PACKED_Data[say].MYDATA[1] = 0xff; 00309 00310 PACKED_Data[say].MYDATA[2] = 0xef;//medrona ait olmayan beaconlar için, abcd değil 00311 PACKED_Data[say].MYDATA[3] = 0xab; 00312 00313 PACKED_Data[say].MYDATA[4] = 0x06;// tipi elle girilmiş. 00314 PACKED_Data[say].MYDATA[5] = 0x00; 00315 00316 PACKED_Data[say].MYDATA[6] = params->advertisingData[6];// x 00317 PACKED_Data[say].MYDATA[7] = params->advertisingData[7]; 00318 00319 PACKED_Data[say].MYDATA[8] = params->advertisingData[8];//y 00320 PACKED_Data[say].MYDATA[9] = params->advertisingData[9]; 00321 00322 PACKED_Data[say].MYDATA[10] = params->advertisingData[10];// z 00323 PACKED_Data[say].MYDATA[11] = params->advertisingData[11]; 00324 00325 PACKED_Data[say].MYDATA[12] = params->advertisingData[12];// pil 00326 PACKED_Data[say].MYDATA[13] = params->advertisingData[13]; 00327 00328 } */ 00329 00330 say++; 00331 } 00332 00333 } 00334 00335 00336 static const uint16_t MED_KIMLIK = 0xABEF; 00337 AdvertisingData_t *pAdvData; 00338 size_t index = 0; 00339 while (index < params->advertisingDataLen) 00340 { 00341 pAdvData = (AdvertisingData_t *)¶ms->advertisingData[index]; 00342 if (pAdvData->dataType == GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA) 00343 { 00344 ApplicationData_t *pAppData = (ApplicationData_t *)pAdvData->data; 00345 if (pAppData->applicationSpecificId == MED_KIMLIK) 00346 { 00347 00348 PACKED_Data[say].MacID[5]=params->peerAddr[5]; 00349 PACKED_Data[say].MacID[4]=params->peerAddr[4]; 00350 PACKED_Data[say].MacID[3]=params->peerAddr[3]; 00351 PACKED_Data[say].MacID[2]=params->peerAddr[2]; 00352 PACKED_Data[say].MacID[1]=params->peerAddr[1]; 00353 PACKED_Data[say].MacID[0]=params->peerAddr[0]; 00354 PACKED_Data[say].RSSI=(params->rssi) * -1; 00355 PACKED_Data[say].LENGTH=params->advertisingDataLen; 00356 00357 PACKED_Data[say].PAKET_LENGTH= 6 + 1 + 1 + params->advertisingDataLen;//MAC+RSSI+1+LENGTH 00358 00359 pc.printf("TOPLAM PAKET UZUNLUK = (%d ) : ---> ",PACKED_Data[say].PAKET_LENGTH); 00360 00361 for (unsigned index = 0; index < params->advertisingDataLen; index++) 00362 { 00363 PACKED_Data[say].MYDATA[index]=params->advertisingData[index]; 00364 } 00365 00366 for (unsigned index = params->advertisingDataLen; index < 50; index++) 00367 { 00368 PACKED_Data[say].MYDATA[index]=0x00; 00369 } 00370 00371 say++; 00372 break; 00373 } 00374 } 00375 index += (pAdvData->length + 1); 00376 } 00377 00378 00379 for (unsigned i = 0; i < say; i++) 00380 { 00381 uint8_t buffertoSpi[bufferSize]; 00382 00383 for (unsigned a = 0; a < bufferSize; a++) 00384 { 00385 buffertoSpi[a]=0x00; 00386 } 00387 00388 buffertoSpi[0]=PACKED_Data[i].PAKET_LENGTH; 00389 00390 for (unsigned a = 1; a < 7; a++) 00391 { 00392 buffertoSpi[a]= PACKED_Data[i].MacID[6-a]; 00393 } 00394 00395 buffertoSpi[7]=PACKED_Data[i].RSSI; 00396 buffertoSpi[8]=PACKED_Data[i].LENGTH; 00397 00398 for (unsigned a = 0; a < PACKED_Data[i].LENGTH; a++) 00399 { 00400 buffertoSpi[9+a]=PACKED_Data[i].MYDATA[a]; 00401 } 00402 00403 pc.printf("nRF51 to stm32f103 SENT (BEACON NUMBER = %d ) : ",i); 00404 00405 for (unsigned a = 0; a < bufferSize; a++) 00406 { 00407 pc.printf("%02x",buffertoSpi[a]); 00408 } 00409 pc.printf("\r\n"); 00410 00411 // SPI ÜZERİDEN HAZIRLANAN OLUŞTURULAN PAKET VERİ STM32F103'E GÖNDERİLİR. 00412 //PAKET VERİMİZİ ŞÖYLEDİR; 00413 /* TPU + MAC_ID + RSSI + LEN + BEACONDAN OKUNAN VERİLER 00414 " 00415 TPU : TOPLAM PAKET BYTE UZUNLUGU 00416 LEN : BEACONDAN OKUNAN VERİLER TOPLAM BYTE UZUNLUGU 00417 00418 */ 00419 00420 if(esp_baglimi) 00421 { 00422 Flash_Buff_WriteBytes(0, buffertoSpi, bufferSize); //eger esp nete baglandıysa göndermeye basla // 13072017 00423 } 00424 00425 00426 //wait_ms(200); // hakan ekledi 01122016 00427 wait_ms(1); 00428 bulunan_index[i]=0x00; 00429 } 00430 say=0; 00431 } 00432 00433 /** 00434 This function is called when the ble initialization process has failed 00435 */ 00436 void onBleInitError(BLE &ble, ble_error_t error) 00437 { 00438 /* Initialization error handling should go here */ 00439 } 00440 00441 /** 00442 Callback triggered when the ble initialization process has finished 00443 */ 00444 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) 00445 { 00446 BLE& ble = params->ble; 00447 ble_error_t error = params->error; 00448 00449 if (error != BLE_ERROR_NONE) { 00450 /* In case of error, forward the error handling to onBleInitError */ 00451 onBleInitError(ble, error); 00452 return; 00453 } 00454 00455 /* Ensure that it is the default instance of BLE */ 00456 if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE) { 00457 return; 00458 } 00459 00460 /* Setup and start scanning */ 00461 ble.gap().setScanParams(100 /* scan interval */, 100 /* scan window */); 00462 ble.gap().startScan(advertisementCallback); 00463 00464 } 00465 00466 int main(void) 00467 { 00468 pc.baud(115200); //local terminal baud 00469 pc.printf("----MEDRON TEKNOLOJİ SNIFFER---- \r\n"); 00470 mac_id_gir(); 00471 00472 while(!esp_baglimi) 00473 { 00474 wait_ms(1); 00475 } 00476 SPI1.begin(); 00477 BLE &ble = BLE::Instance(); 00478 ble.init(bleInitComplete); 00479 00480 while (true) 00481 { 00482 ble.waitForEvent(); 00483 } 00484 }
Generated on Wed Jul 20 2022 21:11:05 by
1.7.2
