Ejemplo n.º 1
0
    /**
     * Print the value of a UUID.
     */
    static void print_uuid(const UUID &uuid)
    {
        const uint8_t *uuid_value = uuid.getBaseUUID();

        // UUIDs are in little endian, print them in big endian
        for (size_t i = 0; i < uuid.getLen(); ++i) {
            printf("%02X", uuid_value[(uuid.getLen() - 1) - i]);
        }
    }
Ejemplo n.º 2
0
void app_start(int, char *[])
{
    buffer = (uint8_t*)malloc(24);
    memset(buffer, 0, 24);
    console.attach(serialHandler);
    printf("{{end}}\r\n");
    // setup buttons
    // button1.mode(PullUp);
    // Delay for initial pullup to take effect
    wait(.01);
    // button1.fall(button1ISR);

    // button2.mode(PullUp);
    // Delay for initial pullup to take effect
    wait(.01);
    // button2.fall(button2ISR);

    /*************************************************************************/
    /*************************************************************************/
    /* bluetooth le */
    ble.init();

    // security
    ble.securityManager().onSecuritySetupInitiated(securityInitiated);
    ble.securityManager().onSecuritySetupCompleted(securityCompleted);
    ble.securityManager().onLinkSecured(linkSecured);
    ble.securityManager().onSecurityContextStored(contextStored);
    ble.securityManager().onPasskeyDisplay(passkeyDisplay);

    // connection status handlers
    ble.gap().onConnection(whenConnected);
    ble.gap().onDisconnection(whenDisconnected);

    // set preferred connection parameters to lowest latency
    Gap::ConnectionParams_t fast;
    ble.gap().getPreferredConnectionParams(&fast);
    fast.minConnectionInterval = 16; // 20 ms
    fast.maxConnectionInterval = 32; // 40 ms
    fast.slaveLatency = 0;
    ble.gap().setPreferredConnectionParams(&fast);

    /* construct advertising beacon */
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED|GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *) DEVICE_NAME, sizeof(DEVICE_NAME) - 1);

    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, uuid.getBaseUUID(), uuid.getLen());

    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.gap().setAdvertisingInterval(200);

    // Apple uses device name instead of beacon name
    ble.gap().setDeviceName((const uint8_t*) DEVICE_NAME);

    // ble setup complete - start advertising
    ble.gap().startAdvertising();


    /*************************************************************************/
    /*************************************************************************/
    bts = new BlockTransferService();
    btc = new BlockTransferClient();
    watch = new Timer();

    bts->init(uuid, SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK);

#if 0
    writeBlock.push_back(&writeBlockFragment2);
    writeBlock.push_back(&writeBlockFragment3);
    writeBlock.push_back(&writeBlockFragment4);
#endif

    // set callback functions
    bts->setWriteAuthorizationCallback(blockServerWriteHandler, &receiveBlock);
    bts->setReadAuthorizationCallback(blockServerReadHandler);


    printf("BlockTransfer: %s %s %d\r\n", __DATE__, __TIME__, MAX_INDEX_SET_SIZE);
}