xvcv

Dependencies:   BLE_API mbed nRF51822

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

main.cpp

Committer:
hknydn
Date:
2016-06-30
Revision:
14:59ba4a2a17c7
Parent:
13:5f87b9cdeb6f
Child:
15:d824140299d9

File content as of revision 14:59ba4a2a17c7:

/* 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.
 */
#include "mbed.h"
#include "toolchain.h"
#include "ble/BLE.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

DigitalOut alivenessLED(LED1, 1);
Ticker     ticker;
Serial pc(TX_PIN_NUMBER, RX_PIN_NUMBER);

void periodicCallback(void)
{
    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.
 */
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 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;

    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++) 
                {
                       pc.printf("%02x", params->advertisingData[index]);
                }
                pc.printf("%02x\r",0xFF);// BITIS

                break;
            }
        }
        index += (pAdvData->length + 1);
    }
}

/**
 * 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 */
}

/**
 * Callback triggered when the ble initialization process has finished
 */
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
{
    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;
    }

    /* 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);
}

int main(void)
{
    pc.baud(9600);                        //local terminal baud  
    ticker.attach(periodicCallback, 1);  /* trigger sensor polling every 2 seconds */

    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");
        
    }


    BLE &ble = BLE::Instance();
    ble.init(bleInitComplete);

    while (true) {
        ble.waitForEvent();
    }
}