dung

Dependencies:   BLE_API mbed nRF51822

Committer:
tridung141196
Date:
Wed Nov 22 13:48:39 2017 +0000
Revision:
0:45eb97275821
dung

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tridung141196 0:45eb97275821 1 // mbed HRM1017 Eddystone
tridung141196 0:45eb97275821 2 // Programed by Kazuyuki Eguchi
tridung141196 0:45eb97275821 3
tridung141196 0:45eb97275821 4 #include "mbed.h"
tridung141196 0:45eb97275821 5 #include "ble/BLE.h"
tridung141196 0:45eb97275821 6
tridung141196 0:45eb97275821 7 BLEDevice ble;
tridung141196 0:45eb97275821 8
tridung141196 0:45eb97275821 9 static const uint16_t uuid16_list[] = {0x00A0};
tridung141196 0:45eb97275821 10
tridung141196 0:45eb97275821 11 const static uint8_t beaconPayload_uid[] = {
tridung141196 0:45eb97275821 12 0x00,
tridung141196 0:45eb97275821 13 0x12,
tridung141196 0:45eb97275821 14
tridung141196 0:45eb97275821 15 // UID
tridung141196 0:45eb97275821 16
tridung141196 0:45eb97275821 17 0x00, // Frame Type
tridung141196 0:45eb97275821 18 0x00, // Ranging Data
tridung141196 0:45eb97275821 19
tridung141196 0:45eb97275821 20 0x8B, // NID[0]
tridung141196 0:45eb97275821 21 0x0C, // NID[1]
tridung141196 0:45eb97275821 22 0xA7, // NID[2]
tridung141196 0:45eb97275821 23 0x50, // NID[3]
tridung141196 0:45eb97275821 24 0xE7, // NID[4]
tridung141196 0:45eb97275821 25 0xA7, // NID[5]
tridung141196 0:45eb97275821 26 0x4E, // NID[6]
tridung141196 0:45eb97275821 27 0x14, // NID[7]
tridung141196 0:45eb97275821 28 0xBD, // NID[8]
tridung141196 0:45eb97275821 29 0x99, // NID[9]
tridung141196 0:45eb97275821 30
tridung141196 0:45eb97275821 31 0x09, // BID[0]
tridung141196 0:45eb97275821 32 0x54, // BID[1]
tridung141196 0:45eb97275821 33 0x77, // BID[2]
tridung141196 0:45eb97275821 34 0xCB, // BID[3]
tridung141196 0:45eb97275821 35 0x3E, // BID[4]
tridung141196 0:45eb97275821 36 0x77, // BID[5]
tridung141196 0:45eb97275821 37 0x00, // RFU
tridung141196 0:45eb97275821 38 0x00 // RFU
tridung141196 0:45eb97275821 39 };
tridung141196 0:45eb97275821 40
tridung141196 0:45eb97275821 41 const static uint8_t beaconPayload_url[] = {
tridung141196 0:45eb97275821 42 0xaa,
tridung141196 0:45eb97275821 43 0xfe,
tridung141196 0:45eb97275821 44
tridung141196 0:45eb97275821 45 // URL
tridung141196 0:45eb97275821 46
tridung141196 0:45eb97275821 47 0x10, // Frame Type
tridung141196 0:45eb97275821 48 0x20, // Ranging Data
tridung141196 0:45eb97275821 49 0x02, // URL Scheme (http:// = 0x02)
tridung141196 0:45eb97275821 50
tridung141196 0:45eb97275821 51 'i',
tridung141196 0:45eb97275821 52 'o',
tridung141196 0:45eb97275821 53 't',
tridung141196 0:45eb97275821 54 'm',
tridung141196 0:45eb97275821 55 'a',
tridung141196 0:45eb97275821 56 'k',
tridung141196 0:45eb97275821 57 'e',
tridung141196 0:45eb97275821 58 'r',
tridung141196 0:45eb97275821 59 '.',
tridung141196 0:45eb97275821 60 'v',
tridung141196 0:45eb97275821 61 'n',
tridung141196 0:45eb97275821 62 };
tridung141196 0:45eb97275821 63
tridung141196 0:45eb97275821 64 const static uint8_t beaconPayload_tlm[] = {
tridung141196 0:45eb97275821 65 0xaa,
tridung141196 0:45eb97275821 66 0xfe,
tridung141196 0:45eb97275821 67
tridung141196 0:45eb97275821 68 // TLM
tridung141196 0:45eb97275821 69
tridung141196 0:45eb97275821 70 0x20, // Frame Type
tridung141196 0:45eb97275821 71 0x00, // Version
tridung141196 0:45eb97275821 72 0x01, // VBATT[0]
tridung141196 0:45eb97275821 73 0x00, // VBATT[1]
tridung141196 0:45eb97275821 74 0x02, // TEMP[0]
tridung141196 0:45eb97275821 75 0x00, // TEMP[1]
tridung141196 0:45eb97275821 76 0x03, // ADV[0]
tridung141196 0:45eb97275821 77 0x00, // ADV[1]
tridung141196 0:45eb97275821 78 0x00, // ADV[2]
tridung141196 0:45eb97275821 79 0x00, // ADV[3]
tridung141196 0:45eb97275821 80 0x04, // SEC_CNT[0]
tridung141196 0:45eb97275821 81 0x00, // SEC_CNT[1]
tridung141196 0:45eb97275821 82 0x00, // SEC_CNT[2]
tridung141196 0:45eb97275821 83 0x00 // SEC_CNT[3]
tridung141196 0:45eb97275821 84 };
tridung141196 0:45eb97275821 85
tridung141196 0:45eb97275821 86
tridung141196 0:45eb97275821 87 int main(void)
tridung141196 0:45eb97275821 88 {
tridung141196 0:45eb97275821 89 ble.init();
tridung141196 0:45eb97275821 90 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED|GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
tridung141196 0:45eb97275821 91
tridung141196 0:45eb97275821 92 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
tridung141196 0:45eb97275821 93
tridung141196 0:45eb97275821 94 //ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA,beaconPayload_uid, sizeof(beaconPayload_uid));
tridung141196 0:45eb97275821 95 ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA,beaconPayload_url, sizeof(beaconPayload_url));
tridung141196 0:45eb97275821 96 //ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA,beaconPayload_tlm, sizeof(beaconPayload_tlm));
tridung141196 0:45eb97275821 97
tridung141196 0:45eb97275821 98 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
tridung141196 0:45eb97275821 99
tridung141196 0:45eb97275821 100 ble.setAdvertisingInterval(160);
tridung141196 0:45eb97275821 101
tridung141196 0:45eb97275821 102 ble.startAdvertising();
tridung141196 0:45eb97275821 103
tridung141196 0:45eb97275821 104 while(true) {
tridung141196 0:45eb97275821 105 ble.waitForEvent();
tridung141196 0:45eb97275821 106 }
tridung141196 0:45eb97275821 107 }
tridung141196 0:45eb97275821 108
tridung141196 0:45eb97275821 109
tridung141196 0:45eb97275821 110