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 VAN
Fork of BLE_iBeacon_POC by
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "iBeaconService.h" 00019 #include "UARTService.h" 00020 00021 /** 00022 * For this demo application, populate the beacon advertisement payload 00023 * with 2 AD structures: FLAG and MSD (manufacturer specific data). 00024 * 00025 * Reference: 00026 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 00027 */ 00028 00029 BLEDevice ble; 00030 UARTService *uart; 00031 00032 /** 00033 * The Beacon payload has the following composition: 00034 * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00035 * Major/Minor = 0x1122 / 0x3344 00036 * Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB) 00037 * 00038 * Note: please remember to calibrate your beacons 00039 * TX Power for more accurate results. 00040 */ 00041 const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 00042 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x62 00043 }; 00044 uint16_t majorNumber = 1122; 00045 uint16_t minorNumber = 3344; 00046 uint16_t txPower = 0xC8; 00047 00048 00049 const uint8_t b1_id = 0x01; 00050 const uint8_t b2_id = 0x02; 00051 const uint8_t b3_id = 0x03; 00052 const uint8_t b4_id = 0x04; 00053 const uint8_t b5_id = 0x05; 00054 const uint8_t b6_id = 0x06; 00055 00056 00057 const uint8_t bA1_id = 0x31; 00058 const uint8_t bA2_id = 0x32; 00059 const uint8_t bA3_id = 0x33; 00060 const uint8_t bA4_id = 0x34; 00061 const uint8_t bA5_id = 0x35; 00062 const uint8_t bA6_id = 0x36; 00063 00064 00065 00066 PinName b1_p = P0_4; 00067 PinName b2_p = P0_5; 00068 PinName b3_p = P0_11; //RXD 00069 PinName b4_p = P0_10; //CTX 00070 PinName b5_p = P0_9; //TXD 00071 PinName b6_p = P0_8; //RTS 00072 00073 00074 00075 //setup led 00076 DigitalOut led1(P0_19); 00077 00078 //setup digital outs 00079 DigitalOut b1(b1_p); 00080 DigitalOut b2(b2_p); 00081 DigitalOut b3(b3_p); 00082 DigitalOut b4(b4_p); 00083 DigitalOut b5(b5_p); 00084 DigitalOut b6(b6_p); 00085 00086 00087 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason); 00088 void onDataWritten(const GattCharacteristicWriteCBParams *params); 00089 int flip(char value); 00090 00091 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) 00092 { 00093 ble.startAdvertising(); 00094 } 00095 00096 void onDataWritten(const GattCharacteristicWriteCBParams *params) 00097 { 00098 flip(params->data[0]); 00099 } 00100 00101 int main(void) 00102 { 00103 /* initialize stuff */ 00104 led1 = 1; 00105 00106 b1 = 1; // 0x01 flash hazards in5 d4 p04 00107 b2 = 1; // 0x02 horn in6 d5 p05 00108 b3 = 1; // 0x03 headlights in7 d6 p15 00109 b4 = 1; // 0x04 door locking 0.8 in2 in3 d2 cts 00110 b5 = 1; // 0x05 remote start 2x .25 in1 d1 txd 00111 b6 = 1; // 0x06 trip alarm 0.8 in4 d3 rts 00112 00113 00114 00115 00116 ble.init(); 00117 00118 ble.onDisconnection(disconnectionCallback); 00119 ble.onDataWritten(onDataWritten); 00120 00121 00122 uart = new UARTService(ble); 00123 iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower); 00124 00125 ble.setAdvertisingInterval(1000); /* 1000ms. */ 00126 ble.startAdvertising(); 00127 00128 while(1) { 00129 ble.waitForEvent(); // allows or low power operation 00130 } 00131 } 00132 00133 void testAll(void) 00134 { 00135 for(int i=0; i<2; i++) 00136 { 00137 led1 = !led1; 00138 b1 = !b1; 00139 b2 = !b2; 00140 b3 = !b3; 00141 b4 = !b4; 00142 b5 = !b5; 00143 b6 = !b6; 00144 wait(1); 00145 } 00146 } 00147 00148 void blinky(void) 00149 { 00150 for(int i=0; i<15; i++) 00151 { 00152 led1 = !led1; 00153 wait(.3); 00154 } 00155 } 00156 00157 int flip(char value) 00158 { 00159 int ret = 0; 00160 00161 switch(value) 00162 { 00163 // 0x01 flash hazards in5 d4 p4 00164 case b1_id : 00165 case bA1_id : led1 = !led1; 00166 b1 = !b1; 00167 break; 00168 // 0x02 horn in6 d5 p5 00169 case b2_id : 00170 case bA2_id : led1 = !led1; 00171 b2 = !b2; 00172 break; 00173 // 0x03 headlights in7 d6 rxd 00174 case b3_id : 00175 case bA3_id : led1 = !led1; 00176 b3 = !b3; 00177 break; 00178 // 0x04 door locking 0.8 in2 in3 d2 cts 00179 case b4_id : 00180 case bA4_id : led1 = !led1; 00181 b4 = !b4; 00182 wait(0.8); 00183 b4 = !b4; 00184 break; 00185 // 0x05 remote start 2x .25 in1 d1 txd 00186 case b5_id : 00187 case bA5_id : led1 = !led1; 00188 b5 = !b5; 00189 wait(0.25); 00190 b5 = !b5; 00191 00192 b5 = !b5; 00193 wait(0.25); 00194 b5 = !b5; 00195 break; 00196 00197 // 0x06 trip alarm 0.8 in4 d3 rts 00198 case b6_id : 00199 case bA6_id : led1 = !led1; 00200 b6 = !b6; 00201 wait(0.8); 00202 b6 = !b6; 00203 break; 00204 00205 default : blinky(); 00206 ret = 1; 00207 break; 00208 } 00209 return ret; 00210 }
Generated on Tue Aug 2 2022 20:18:49 by
1.7.2
