kumar singh
/
Dealer_20Mar
BLE Transmitter not working
Fork of Dealer_23Feb by
Beacon.cpp@22:c2f034a13108, 2017-02-23 (annotated)
- Committer:
- NarendraSingh
- Date:
- Thu Feb 23 04:41:47 2017 +0000
- Revision:
- 22:c2f034a13108
- Parent:
- 21:a5fb0ae94dc6
- Child:
- 25:0ac2680d594c
status packet with dummy data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NarendraSingh | 11:77e595130230 | 1 | #include "Beacon.h" |
NarendraSingh | 11:77e595130230 | 2 | #include "Lora.h" |
NarendraSingh | 11:77e595130230 | 3 | |
NarendraSingh | 16:7703b9d92326 | 4 | RawSerial DEBUG_UART2(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 |
NarendraSingh | 11:77e595130230 | 5 | RawSerial Beacon_Module_UART(PC_4, PC_5);//USART3_TX->PC4,USART3_RX->PC_5 |
NarendraSingh | 11:77e595130230 | 6 | |
NarendraSingh | 11:77e595130230 | 7 | |
NarendraSingh | 11:77e595130230 | 8 | uint8 Beacon_RxBuffer_Crnt_Pos,Beacon_RxBuffer_End_Pos; // must be volatile or the compiler may over-optimise. |
NarendraSingh | 11:77e595130230 | 9 | uint8 Beacon_RX_Buffer[100]; |
NarendraSingh | 11:77e595130230 | 10 | char Beacon_RxIndex=0; |
NarendraSingh | 11:77e595130230 | 11 | uint8 BLE_Adv_Module_Beacon_ID[6]; |
NarendraSingh | 11:77e595130230 | 12 | |
NarendraSingh | 11:77e595130230 | 13 | /*Instructions for operation(MS49SF1U) |
NarendraSingh | 11:77e595130230 | 14 | 1. UART command list(Commands for modifying configuration) |
NarendraSingh | 11:77e595130230 | 15 | |-------------------|-----------------------------|---------------|---------------------------------------------------| |
NarendraSingh | 11:77e595130230 | 16 | | Item | Command format | Length(data) | Returned value after successful receiving | |
NarendraSingh | 11:77e595130230 | 17 | |-------------------|-----------------------------|---------------|---------------------------------------------------| |
NarendraSingh | 11:77e595130230 | 18 | UUID 0x4154+0xFFF1+data+0x0d 16character 0xFFF1+received data |
NarendraSingh | 11:77e595130230 | 19 | Major 0x4154+0xFFF2+data+0x0d 2character 0xFFF2+received data |
NarendraSingh | 11:77e595130230 | 20 | Minor 0x4154+0xFFF3+data+0x0d 2character 0xFFF3+received data |
NarendraSingh | 11:77e595130230 | 21 | Measured power 0x4154+0xFFF4+data+0x0d 1character 0xFFF4+received data |
NarendraSingh | 11:77e595130230 | 22 | Transmission power 0x4154+0xFFF5+data+0x0d 1character 0xFFF5+received data |
NarendraSingh | 11:77e595130230 | 23 | Pairing Password 0x4154+0xFFF6+data+0x0d 8character 0xFFF6+received data |
NarendraSingh | 11:77e595130230 | 24 | Broadcasting Interval 0x4154+0xFFF7+data+0x0d 1character 0xFFF7+received data |
NarendraSingh | 11:77e595130230 | 25 | Beacon_Serial_ID 0x4154+0xFFF8+data+0x0d 4character 0xFFF8+received data |
NarendraSingh | 11:77e595130230 | 26 | iBeacon_name 0x4154+0xFFF9+data+0x0d 12character 0xFFF9+received data |
NarendraSingh | 11:77e595130230 | 27 | Authentication 0x4154+0xFFFA+data+0x0d 12character 0xFFFA+received data |
NarendraSingh | 11:77e595130230 | 28 | Connection Mode 0x4154+0xFFFE+data+0x0d 1character 0xFFFE+received data |
NarendraSingh | 11:77e595130230 | 29 | Soft Reboot 0x4154+0xFFFF+data+0x0d 8character 0xFFFF+received data+0K or ERROR |
NarendraSingh | 11:77e595130230 | 30 | open beacon 0x4154+0x6F70656E+0x0d return Beacon is open\n |
NarendraSingh | 11:77e595130230 | 31 | close beacon 0x4154+0x636C6F7365+0x0d return Beacon is closed\n |
NarendraSingh | 11:77e595130230 | 32 | app enable 0x4154+0x656E61626C65+0x0d return app enabled |
NarendraSingh | 11:77e595130230 | 33 | app unable 0x4154+0x756E61626C65+0x0d |
NarendraSingh | 11:77e595130230 | 34 | Read MAC ID 0x5244+0x6d6163+0x0d |
NarendraSingh | 11:77e595130230 | 35 | ------------------------------------------------------------------------------------------------------------------- |
NarendraSingh | 11:77e595130230 | 36 | */ |
NarendraSingh | 11:77e595130230 | 37 | |
NarendraSingh | 11:77e595130230 | 38 | unsigned char SET_UUID[21] = {0x41,0x54,0xFF,0xF1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D}; |
NarendraSingh | 21:a5fb0ae94dc6 | 39 | unsigned char SET_VIRTUAL_PACKET_UUID[23] = {0x01,0x01,0x41,0x54,0x01,0x01,0x02,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x03,0x0B,0x0C,0x05,0x0E,0x0F,0x0D}; |
NarendraSingh | 20:f812f85cf97e | 40 | unsigned char SET_VIRTUAL_PACKET_UUID1[23] = {0x41,0x54,0xFF,0xF1,0x02,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x02,0x0B,0x0C,0x05,0x0E,0x0F,0x0D}; |
NarendraSingh | 21:a5fb0ae94dc6 | 41 | unsigned char SET_VIRTUAL_PACKET_UUID2[23] = {0x12,0x21,0x41,0x54,0xFF,0xF1,0x0F,0x0E,0x0D,0x0C,0x0B,0x0A,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x0D}; |
NarendraSingh | 21:a5fb0ae94dc6 | 42 | unsigned char SET_VIRTUAL_PACKET_UUID3[23] = {0x41,0x54,0xFF,0xF1,0x0F,0x0E,0x0D,0x0C,0x0B,0x04,0x05,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 43 | unsigned char SET_MAJOR[7] = {0x41,0x54,0xFF,0xF2,0x00,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 44 | unsigned char SET_MINOR[7] = {0x41,0x54,0xFF,0xF3,0x00,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 45 | unsigned char SET_MEASURED_POWER[6] = {0x41,0x54,0xFF,0xF4,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 46 | unsigned char SET_TRANSMISSION_POWER[6] = {0x41,0x54,0xFF,0xF5,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 47 | unsigned char SET_PAIRING_PASSWORD[13] = {0x41,0x54,0xFF,0xF6,0x4F,0x42,0x44,0x21,0x30,0x30,0x30,0x31,0x0D};//Set Password here, Now set as OBD!1234 |
NarendraSingh | 11:77e595130230 | 48 | unsigned char SET_BROADCAST_INTERVAL[6] = {0x41,0x54,0xFF,0xF7,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 49 | unsigned char SET_IBEACON_NAME[17] = {0x41,0x54,0xFF,0xF9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 50 | unsigned char SOFT_REBOOT[13] = {0x41,0x54,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D}; |
NarendraSingh | 11:77e595130230 | 51 | unsigned char SET_OPEN_BEACON[7] = {0x41,0x54,0x6F,0x70,0x65,0x6E,0x0D}; |
NarendraSingh | 11:77e595130230 | 52 | unsigned char SET_CLOSE_BEACON[8] = {0x41,0x54,0x63,0x6C,0x6F,0x73,0x65,0x0D}; |
NarendraSingh | 11:77e595130230 | 53 | unsigned char READ_BEACON_MAC_ID[6] = {0x52,0x44,0x6D,0x61,0x63,0x0D}; |
NarendraSingh | 11:77e595130230 | 54 | |
NarendraSingh | 20:f812f85cf97e | 55 | unsigned char SOFT_REBOOT1[15] = {0x01,0x0B,0x41,0x54,0xFF,0xFF,0x6D,0x69,0x6E,0x65,0x77,0x31,0x32,0x33,0x0D}; |
NarendraSingh | 20:f812f85cf97e | 56 | unsigned char SOFT_REBOOT2[15] = {0x41,0x54,0xFF,0xFF,0x6D,0x69,0x6E,0x65,0x77,0x31,0x32,0x33,0x0D}; |
NarendraSingh | 20:f812f85cf97e | 57 | |
NarendraSingh | 11:77e595130230 | 58 | void Process_Beacon_Command_Received(unsigned char* Command_Received); |
NarendraSingh | 11:77e595130230 | 59 | void Change_Beacon_Parameter(unsigned char* Beacon_Parameter_To_Set); |
NarendraSingh | 11:77e595130230 | 60 | void Get_Beacon_Response(void); |
NarendraSingh | 11:77e595130230 | 61 | void Read_Beacon_Module_MAC_ID(void); |
NarendraSingh | 11:77e595130230 | 62 | void Initialize_Beacon_Module(void); |
NarendraSingh | 11:77e595130230 | 63 | |
NarendraSingh | 11:77e595130230 | 64 | void Process_Beacon_Command_Received(unsigned char* Command_Received) |
NarendraSingh | 11:77e595130230 | 65 | { |
NarendraSingh | 11:77e595130230 | 66 | static unsigned char Temp_Pos,Start_Position,End_Position,Data_Length; |
NarendraSingh | 20:f812f85cf97e | 67 | Start_Position = 0x02; |
NarendraSingh | 11:77e595130230 | 68 | Temp_Pos = 0x02; |
NarendraSingh | 11:77e595130230 | 69 | if((Command_Received[0] == SET_BEACON_UUID_CMD0) && (Command_Received[1] == SET_BEACON_UUID_CMD1)) //Check if command is receievd for setting UUID |
NarendraSingh | 11:77e595130230 | 70 | { |
NarendraSingh | 21:a5fb0ae94dc6 | 71 | //DEBUG_UART2.printf("Setting UUID"); |
NarendraSingh | 11:77e595130230 | 72 | Data_Length = 16; |
NarendraSingh | 11:77e595130230 | 73 | End_Position = (Start_Position + Data_Length); |
NarendraSingh | 11:77e595130230 | 74 | for(;Start_Position < End_Position;Start_Position++) |
NarendraSingh | 20:f812f85cf97e | 75 | { |
NarendraSingh | 11:77e595130230 | 76 | SET_UUID[Start_Position] = Command_Received[Temp_Pos++]; |
NarendraSingh | 20:f812f85cf97e | 77 | //DEBUG_UART2.putc(SET_UUID[Start_Position]); |
NarendraSingh | 20:f812f85cf97e | 78 | //DEBUG_UART2.printf("%s",SET_UUID); |
NarendraSingh | 20:f812f85cf97e | 79 | |
NarendraSingh | 20:f812f85cf97e | 80 | |
NarendraSingh | 20:f812f85cf97e | 81 | } |
NarendraSingh | 22:c2f034a13108 | 82 | DEBUG_UART2.printf("UUID Set"); |
NarendraSingh | 20:f812f85cf97e | 83 | Change_Beacon_Parameter(SET_VIRTUAL_PACKET_UUID1); |
NarendraSingh | 21:a5fb0ae94dc6 | 84 | } |
NarendraSingh | 21:a5fb0ae94dc6 | 85 | else if((Command_Received[0] == 0x12) && (Command_Received[1] == 0x21)) //Check if command is receievd for setting UUID |
NarendraSingh | 21:a5fb0ae94dc6 | 86 | { |
NarendraSingh | 21:a5fb0ae94dc6 | 87 | DEBUG_UART2.printf("Setting UUID2"); |
NarendraSingh | 21:a5fb0ae94dc6 | 88 | Data_Length = 16; |
NarendraSingh | 21:a5fb0ae94dc6 | 89 | End_Position = (Start_Position + Data_Length); |
NarendraSingh | 21:a5fb0ae94dc6 | 90 | for(;Start_Position < End_Position;Start_Position++) |
NarendraSingh | 21:a5fb0ae94dc6 | 91 | { |
NarendraSingh | 21:a5fb0ae94dc6 | 92 | SET_UUID[Start_Position] = Command_Received[Temp_Pos++]; |
NarendraSingh | 21:a5fb0ae94dc6 | 93 | //DEBUG_UART2.putc(SET_UUID[Start_Position]); |
NarendraSingh | 21:a5fb0ae94dc6 | 94 | //DEBUG_UART2.printf("%s",SET_UUID); |
NarendraSingh | 21:a5fb0ae94dc6 | 95 | |
NarendraSingh | 21:a5fb0ae94dc6 | 96 | |
NarendraSingh | 21:a5fb0ae94dc6 | 97 | } |
NarendraSingh | 21:a5fb0ae94dc6 | 98 | DEBUG_UART2.printf("UUID2 Set"); |
NarendraSingh | 21:a5fb0ae94dc6 | 99 | Change_Beacon_Parameter(SET_VIRTUAL_PACKET_UUID3); |
NarendraSingh | 11:77e595130230 | 100 | } |
NarendraSingh | 11:77e595130230 | 101 | else if((Command_Received[0] == SET_SET_MAJOR_CMD0) && (Command_Received[1] == SET_SET_MAJOR_CMD1)) //Check if command is received for Setting Major |
NarendraSingh | 11:77e595130230 | 102 | { |
NarendraSingh | 11:77e595130230 | 103 | SET_MAJOR[Start_Position++] = Command_Received[Temp_Pos++]; //MSB |
NarendraSingh | 11:77e595130230 | 104 | SET_MAJOR[Start_Position] = Command_Received[Temp_Pos]; //LSB |
NarendraSingh | 11:77e595130230 | 105 | DEBUG_UART2.printf("%s",SET_MAJOR); |
NarendraSingh | 11:77e595130230 | 106 | Change_Beacon_Parameter(SET_MAJOR); |
NarendraSingh | 11:77e595130230 | 107 | } |
NarendraSingh | 11:77e595130230 | 108 | else if((Command_Received[0] == SET_SET_MINOR_CMD0) && (Command_Received[1] == SET_SET_MINOR_CMD1)) //Check if command is received for Setting Minor |
NarendraSingh | 11:77e595130230 | 109 | { |
NarendraSingh | 11:77e595130230 | 110 | SET_MINOR[Start_Position++] = Command_Received[Temp_Pos++]; //MSB |
NarendraSingh | 11:77e595130230 | 111 | SET_MINOR[Start_Position] = Command_Received[Temp_Pos]; //LSB |
NarendraSingh | 11:77e595130230 | 112 | DEBUG_UART2.printf("%s",SET_MINOR); |
NarendraSingh | 11:77e595130230 | 113 | Change_Beacon_Parameter(SET_MINOR); |
NarendraSingh | 11:77e595130230 | 114 | } |
NarendraSingh | 11:77e595130230 | 115 | else if((Command_Received[0] == SET_SET_MEASURED_POWER_CMD0) && (Command_Received[1] == SET_SET_MEASURED_POWER_CMD1)) //Check if command is received for Setting Measured power |
NarendraSingh | 11:77e595130230 | 116 | { |
NarendraSingh | 11:77e595130230 | 117 | SET_MEASURED_POWER[Start_Position] = Command_Received[Temp_Pos]; |
NarendraSingh | 11:77e595130230 | 118 | DEBUG_UART2.printf("%s",SET_MEASURED_POWER); |
NarendraSingh | 11:77e595130230 | 119 | Change_Beacon_Parameter(SET_MEASURED_POWER); |
NarendraSingh | 11:77e595130230 | 120 | } |
NarendraSingh | 11:77e595130230 | 121 | else if((Command_Received[0] == SET_TRANSMISSION_POWER_CMD0) && (Command_Received[1] == SET_TRANSMISSION_POWER_CMD1)) //Check if command is received for settting Transmission power |
NarendraSingh | 11:77e595130230 | 122 | { |
NarendraSingh | 11:77e595130230 | 123 | SET_TRANSMISSION_POWER[Start_Position] = Command_Received[Temp_Pos]; |
NarendraSingh | 11:77e595130230 | 124 | DEBUG_UART2.printf("%s",SET_TRANSMISSION_POWER); |
NarendraSingh | 11:77e595130230 | 125 | Change_Beacon_Parameter(SET_TRANSMISSION_POWER); |
NarendraSingh | 11:77e595130230 | 126 | } |
NarendraSingh | 11:77e595130230 | 127 | else if((Command_Received[0] == SET_PAIRING_PASSWORD_CMD0) && (Command_Received[1] == SET_PAIRING_PASSWORD_CMD1)) //Check if command is received for Changing Pairing Password |
NarendraSingh | 11:77e595130230 | 128 | { |
NarendraSingh | 11:77e595130230 | 129 | Data_Length = 8; |
NarendraSingh | 11:77e595130230 | 130 | End_Position = (Start_Position + Data_Length); |
NarendraSingh | 11:77e595130230 | 131 | for(;Start_Position < End_Position;Start_Position++) |
NarendraSingh | 11:77e595130230 | 132 | SET_PAIRING_PASSWORD[Start_Position] = Command_Received[Temp_Pos++]; |
NarendraSingh | 11:77e595130230 | 133 | DEBUG_UART2.printf("%s",SET_PAIRING_PASSWORD); |
NarendraSingh | 11:77e595130230 | 134 | //Change_Beacon_Parameter(SET_PAIRING_PASSWORD); |
NarendraSingh | 11:77e595130230 | 135 | Data_Length = 8; |
NarendraSingh | 11:77e595130230 | 136 | Start_Position = 4; |
NarendraSingh | 11:77e595130230 | 137 | End_Position = (Start_Position + Data_Length); |
NarendraSingh | 11:77e595130230 | 138 | //for(Start_Position;Start_Position < End_Position;Start_Position++) |
NarendraSingh | 11:77e595130230 | 139 | // SET_SOFT_REBOOT[Start_Position] = Command_Received[Temp_Pos++]; //write code to update this password in eeprom |
NarendraSingh | 11:77e595130230 | 140 | DEBUG_UART2.printf("%s",SOFT_REBOOT); |
NarendraSingh | 11:77e595130230 | 141 | } |
NarendraSingh | 11:77e595130230 | 142 | else if((Command_Received[0] == SET_BROADCAST_INTERVAL_CMD0) && (Command_Received[1] == SET_BROADCAST_INTERVAL_CMD1)) //Check if command is received for setting BroadCast Interval |
NarendraSingh | 11:77e595130230 | 143 | { |
NarendraSingh | 11:77e595130230 | 144 | SET_BROADCAST_INTERVAL[Start_Position] = Command_Received[Temp_Pos]; |
NarendraSingh | 11:77e595130230 | 145 | DEBUG_UART2.printf("%s",SET_BROADCAST_INTERVAL); |
NarendraSingh | 11:77e595130230 | 146 | Change_Beacon_Parameter(SET_BROADCAST_INTERVAL); |
NarendraSingh | 11:77e595130230 | 147 | } |
NarendraSingh | 11:77e595130230 | 148 | else if((Command_Received[0] == SET_IBEACON_NAME_CMD0) && (Command_Received[1] == SET_IBEACON_NAME_CMD1)) //Check if command is received for setting ibeacon name |
NarendraSingh | 11:77e595130230 | 149 | { |
NarendraSingh | 11:77e595130230 | 150 | Data_Length = 12; |
NarendraSingh | 11:77e595130230 | 151 | End_Position = (Start_Position + Data_Length); |
NarendraSingh | 11:77e595130230 | 152 | for(;Start_Position < End_Position;Start_Position++) |
NarendraSingh | 11:77e595130230 | 153 | SET_IBEACON_NAME[Start_Position] = Command_Received[Temp_Pos++]; |
NarendraSingh | 11:77e595130230 | 154 | DEBUG_UART2.printf("%s",SET_IBEACON_NAME); |
NarendraSingh | 11:77e595130230 | 155 | Change_Beacon_Parameter(SET_IBEACON_NAME); |
NarendraSingh | 11:77e595130230 | 156 | } |
NarendraSingh | 11:77e595130230 | 157 | else if((Command_Received[0] == SET_START_BEACON_CMD0) && (Command_Received[1] == SET_START_BEACON_CMD0)) //check if command is receievd for starting Beacon |
NarendraSingh | 11:77e595130230 | 158 | { |
NarendraSingh | 11:77e595130230 | 159 | DEBUG_UART2.printf("%s",SET_OPEN_BEACON); |
NarendraSingh | 11:77e595130230 | 160 | Change_Beacon_Parameter(SET_OPEN_BEACON); |
NarendraSingh | 11:77e595130230 | 161 | } |
NarendraSingh | 11:77e595130230 | 162 | else if((Command_Received[0] == SET_STOP_BEACON_CMD0) && (Command_Received[1] == SET_STOP_BEACON_CMD1)) //Check if command is received for Stopping beacon and go to sleep mode |
NarendraSingh | 11:77e595130230 | 163 | { |
NarendraSingh | 11:77e595130230 | 164 | DEBUG_UART2.printf("%s",SET_CLOSE_BEACON); |
NarendraSingh | 11:77e595130230 | 165 | Change_Beacon_Parameter(SET_CLOSE_BEACON); |
NarendraSingh | 11:77e595130230 | 166 | } |
NarendraSingh | 11:77e595130230 | 167 | else if((Command_Received[0] == SET_SOFT_REBOOT_CMD0) && (Command_Received[1] == SET_SOFT_REBOOT_CMD1)) //Check if command is received for Stopping beacon and go to sleep mode |
NarendraSingh | 11:77e595130230 | 168 | { |
NarendraSingh | 20:f812f85cf97e | 169 | Beacon_Module_UART.printf("%s",SOFT_REBOOT2); //Soft Reboot Beacon Module |
NarendraSingh | 21:a5fb0ae94dc6 | 170 | DEBUG_UART2.printf("Beacon Device Resetted %s",SOFT_REBOOT2); |
NarendraSingh | 11:77e595130230 | 171 | } |
NarendraSingh | 11:77e595130230 | 172 | } |
NarendraSingh | 11:77e595130230 | 173 | |
NarendraSingh | 11:77e595130230 | 174 | void Change_Beacon_Parameter(unsigned char* Beacon_Parameter_To_Set) |
NarendraSingh | 11:77e595130230 | 175 | { |
NarendraSingh | 21:a5fb0ae94dc6 | 176 | uint8 i; |
NarendraSingh | 21:a5fb0ae94dc6 | 177 | for(i = 0;i<21;i++) |
NarendraSingh | 21:a5fb0ae94dc6 | 178 | { |
NarendraSingh | 21:a5fb0ae94dc6 | 179 | Beacon_Module_UART.putc(Beacon_Parameter_To_Set[i]); |
NarendraSingh | 22:c2f034a13108 | 180 | DEBUG_UART2.putc(Beacon_Parameter_To_Set[i]); |
NarendraSingh | 21:a5fb0ae94dc6 | 181 | } |
NarendraSingh | 21:a5fb0ae94dc6 | 182 | //Beacon_Module_UART.printf('%x',0x0d); |
NarendraSingh | 21:a5fb0ae94dc6 | 183 | //DEBUG_UART2.putc('%x',0x0d); |
NarendraSingh | 11:77e595130230 | 184 | Beacon_Module_UART.printf("%s",Beacon_Parameter_To_Set); |
NarendraSingh | 21:a5fb0ae94dc6 | 185 | //Beacon_Module_UART.printf("%s",SOFT_REBOOT); //Every Ibeacon command must be followed by Soft reset command in order to make the changes take place instantly |
NarendraSingh | 21:a5fb0ae94dc6 | 186 | //DEBUG_UART2.printf("%s",Beacon_Parameter_To_Set); |
NarendraSingh | 11:77e595130230 | 187 | } |
NarendraSingh | 11:77e595130230 | 188 | |
NarendraSingh | 11:77e595130230 | 189 | void Initialize_Beacon_Module(void) |
NarendraSingh | 11:77e595130230 | 190 | { |
NarendraSingh | 21:a5fb0ae94dc6 | 191 | Beacon_Module_UART.baud(9600); //set Beacon transmitter uart baud rate to default 9600 |
NarendraSingh | 22:c2f034a13108 | 192 | //Read_Beacon_Module_MAC_ID(); |
NarendraSingh | 11:77e595130230 | 193 | } |
NarendraSingh | 11:77e595130230 | 194 | |
NarendraSingh | 11:77e595130230 | 195 | void Read_Beacon_Module_MAC_ID(void) |
NarendraSingh | 11:77e595130230 | 196 | { |
NarendraSingh | 11:77e595130230 | 197 | uint8 pos; |
NarendraSingh | 11:77e595130230 | 198 | Beacon_Module_UART.printf("%s",READ_BEACON_MAC_ID); |
NarendraSingh | 11:77e595130230 | 199 | Get_Beacon_Response(); |
NarendraSingh | 11:77e595130230 | 200 | for(pos=0;pos<6;pos++) |
NarendraSingh | 11:77e595130230 | 201 | BLE_Adv_Module_Beacon_ID[pos] = Beacon_RX_Buffer[pos]; |
NarendraSingh | 11:77e595130230 | 202 | } |
NarendraSingh | 11:77e595130230 | 203 | |
NarendraSingh | 11:77e595130230 | 204 | void Get_Beacon_Response(void) |
NarendraSingh | 11:77e595130230 | 205 | { |
NarendraSingh | 11:77e595130230 | 206 | char Beacon_inChar=0; |
NarendraSingh | 11:77e595130230 | 207 | //Keep reading characters until we get a carriage return |
NarendraSingh | 11:77e595130230 | 208 | while(Beacon_inChar != '\n') |
NarendraSingh | 11:77e595130230 | 209 | { |
NarendraSingh | 11:77e595130230 | 210 | //If a character comes in on the serial port, we need to act on it. |
NarendraSingh | 11:77e595130230 | 211 | if(Beacon_Module_UART.readable()) |
NarendraSingh | 11:77e595130230 | 212 | { |
NarendraSingh | 11:77e595130230 | 213 | //Get the new character from the Serial port. |
NarendraSingh | 11:77e595130230 | 214 | Beacon_inChar = Beacon_Module_UART.getc(); |
NarendraSingh | 11:77e595130230 | 215 | //Start by checking if we've received the end of message character ('\r'). |
NarendraSingh | 11:77e595130230 | 216 | if(Beacon_inChar == '\n') |
NarendraSingh | 11:77e595130230 | 217 | { |
NarendraSingh | 11:77e595130230 | 218 | //Put the end of string character on our data string |
NarendraSingh | 11:77e595130230 | 219 | Beacon_RX_Buffer[Beacon_RxIndex]='\0'; |
NarendraSingh | 11:77e595130230 | 220 | //Reset the buffer index so that the next character go es back at the beginning of the string. |
NarendraSingh | 11:77e595130230 | 221 | Beacon_RxIndex=0; |
NarendraSingh | 11:77e595130230 | 222 | } |
NarendraSingh | 11:77e595130230 | 223 | //If we didn't get the end of message character, just add the new character to the string. |
NarendraSingh | 11:77e595130230 | 224 | else |
NarendraSingh | 11:77e595130230 | 225 | { |
NarendraSingh | 11:77e595130230 | 226 | //Add the new character to the string, and increment the index variable. |
NarendraSingh | 11:77e595130230 | 227 | Beacon_RX_Buffer[Beacon_RxIndex++]=Beacon_inChar; |
NarendraSingh | 11:77e595130230 | 228 | } |
NarendraSingh | 11:77e595130230 | 229 | } |
NarendraSingh | 11:77e595130230 | 230 | } |
NarendraSingh | 11:77e595130230 | 231 | } |