kumar singh
/
Dealer_20Mar
BLE Transmitter not working
Fork of Dealer_23Feb by
Diff: Beacon.cpp
- Revision:
- 25:0ac2680d594c
- Parent:
- 22:c2f034a13108
diff -r 1063cfc311e5 -r 0ac2680d594c Beacon.cpp --- a/Beacon.cpp Thu Feb 23 13:21:08 2017 +0000 +++ b/Beacon.cpp Fri Mar 03 08:48:39 2017 +0000 @@ -35,11 +35,7 @@ ------------------------------------------------------------------------------------------------------------------- */ -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}; -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}; -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}; -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}; -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}; +unsigned char SET_UUID[23] = {0x01,0x01,0x41,0x54,0xFF,0xF1,0xFD,0xA5,0x06,0x93,0xA4,0xE2,0x4F,0xB1,0xAF,0xCF,0xC6,0xEB,0x07,0x54,0x87,0x02,0x0D}; unsigned char SET_MAJOR[7] = {0x41,0x54,0xFF,0xF2,0x00,0x00,0x0D}; unsigned char SET_MINOR[7] = {0x41,0x54,0xFF,0xF3,0x00,0x00,0x0D}; unsigned char SET_MEASURED_POWER[6] = {0x41,0x54,0xFF,0xF4,0x00,0x0D}; @@ -47,14 +43,11 @@ 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 unsigned char SET_BROADCAST_INTERVAL[6] = {0x41,0x54,0xFF,0xF7,0x00,0x0D}; unsigned char SET_IBEACON_NAME[17] = {0x41,0x54,0xFF,0xF9,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D}; -unsigned char SOFT_REBOOT[13] = {0x41,0x54,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D}; +unsigned char SOFT_REBOOT[13] = {0x41,0x54,0xFF,0xFF,0x6D,0x69,0x6E,0x65,0x77,0x31,0x32,0x33,0x0D}; unsigned char SET_OPEN_BEACON[7] = {0x41,0x54,0x6F,0x70,0x65,0x6E,0x0D}; unsigned char SET_CLOSE_BEACON[8] = {0x41,0x54,0x63,0x6C,0x6F,0x73,0x65,0x0D}; unsigned char READ_BEACON_MAC_ID[6] = {0x52,0x44,0x6D,0x61,0x63,0x0D}; -unsigned char SOFT_REBOOT1[15] = {0x01,0x0B,0x41,0x54,0xFF,0xFF,0x6D,0x69,0x6E,0x65,0x77,0x31,0x32,0x33,0x0D}; -unsigned char SOFT_REBOOT2[15] = {0x41,0x54,0xFF,0xFF,0x6D,0x69,0x6E,0x65,0x77,0x31,0x32,0x33,0x0D}; - void Process_Beacon_Command_Received(unsigned char* Command_Received); void Change_Beacon_Parameter(unsigned char* Beacon_Parameter_To_Set); void Get_Beacon_Response(void); @@ -64,65 +57,49 @@ void Process_Beacon_Command_Received(unsigned char* Command_Received) { static unsigned char Temp_Pos,Start_Position,End_Position,Data_Length; + static unsigned char Beacon_Data[25],j; + static unsigned char Seq_No; Start_Position = 0x02; Temp_Pos = 0x02; if((Command_Received[0] == SET_BEACON_UUID_CMD0) && (Command_Received[1] == SET_BEACON_UUID_CMD1)) //Check if command is receievd for setting UUID { - //DEBUG_UART2.printf("Setting UUID"); - Data_Length = 16; + DEBUG_UART2.printf("Setting UUID"); + Data_Length = 21; End_Position = (Start_Position + Data_Length); - for(;Start_Position < End_Position;Start_Position++) + for(j=0;Start_Position < End_Position;Start_Position++) { - SET_UUID[Start_Position] = Command_Received[Temp_Pos++]; - //DEBUG_UART2.putc(SET_UUID[Start_Position]); - //DEBUG_UART2.printf("%s",SET_UUID); - - + Beacon_Data[j++] = Command_Received[Start_Position]; } - DEBUG_UART2.printf("UUID Set"); - Change_Beacon_Parameter(SET_VIRTUAL_PACKET_UUID1); - } - else if((Command_Received[0] == 0x12) && (Command_Received[1] == 0x21)) //Check if command is receievd for setting UUID - { - DEBUG_UART2.printf("Setting UUID2"); - Data_Length = 16; - End_Position = (Start_Position + Data_Length); - for(;Start_Position < End_Position;Start_Position++) - { - SET_UUID[Start_Position] = Command_Received[Temp_Pos++]; - //DEBUG_UART2.putc(SET_UUID[Start_Position]); - //DEBUG_UART2.printf("%s",SET_UUID); - - - } - DEBUG_UART2.printf("UUID2 Set"); - Change_Beacon_Parameter(SET_VIRTUAL_PACKET_UUID3); + Beacon_Data[4] = Seq_No++; + Change_Beacon_Parameter(Beacon_Data,Data_Length); + wait(.5); + Change_Beacon_Parameter(SOFT_REBOOT,13); } else if((Command_Received[0] == SET_SET_MAJOR_CMD0) && (Command_Received[1] == SET_SET_MAJOR_CMD1)) //Check if command is received for Setting Major { SET_MAJOR[Start_Position++] = Command_Received[Temp_Pos++]; //MSB SET_MAJOR[Start_Position] = Command_Received[Temp_Pos]; //LSB DEBUG_UART2.printf("%s",SET_MAJOR); - Change_Beacon_Parameter(SET_MAJOR); + //Change_Beacon_Parameter(SET_MAJOR); } else if((Command_Received[0] == SET_SET_MINOR_CMD0) && (Command_Received[1] == SET_SET_MINOR_CMD1)) //Check if command is received for Setting Minor { SET_MINOR[Start_Position++] = Command_Received[Temp_Pos++]; //MSB SET_MINOR[Start_Position] = Command_Received[Temp_Pos]; //LSB DEBUG_UART2.printf("%s",SET_MINOR); - Change_Beacon_Parameter(SET_MINOR); + //Change_Beacon_Parameter(SET_MINOR); } 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 { SET_MEASURED_POWER[Start_Position] = Command_Received[Temp_Pos]; DEBUG_UART2.printf("%s",SET_MEASURED_POWER); - Change_Beacon_Parameter(SET_MEASURED_POWER); + //Change_Beacon_Parameter(SET_MEASURED_POWER); } 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 { SET_TRANSMISSION_POWER[Start_Position] = Command_Received[Temp_Pos]; DEBUG_UART2.printf("%s",SET_TRANSMISSION_POWER); - Change_Beacon_Parameter(SET_TRANSMISSION_POWER); + //Change_Beacon_Parameter(SET_TRANSMISSION_POWER); } 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 { @@ -143,7 +120,7 @@ { SET_BROADCAST_INTERVAL[Start_Position] = Command_Received[Temp_Pos]; DEBUG_UART2.printf("%s",SET_BROADCAST_INTERVAL); - Change_Beacon_Parameter(SET_BROADCAST_INTERVAL); + //Change_Beacon_Parameter(SET_BROADCAST_INTERVAL); } 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 { @@ -152,38 +129,28 @@ for(;Start_Position < End_Position;Start_Position++) SET_IBEACON_NAME[Start_Position] = Command_Received[Temp_Pos++]; DEBUG_UART2.printf("%s",SET_IBEACON_NAME); - Change_Beacon_Parameter(SET_IBEACON_NAME); + //Change_Beacon_Parameter(SET_IBEACON_NAME); } else if((Command_Received[0] == SET_START_BEACON_CMD0) && (Command_Received[1] == SET_START_BEACON_CMD0)) //check if command is receievd for starting Beacon { DEBUG_UART2.printf("%s",SET_OPEN_BEACON); - Change_Beacon_Parameter(SET_OPEN_BEACON); + //Change_Beacon_Parameter(SET_OPEN_BEACON); } 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 { DEBUG_UART2.printf("%s",SET_CLOSE_BEACON); - Change_Beacon_Parameter(SET_CLOSE_BEACON); + //Change_Beacon_Parameter(SET_CLOSE_BEACON); } - 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 - { - Beacon_Module_UART.printf("%s",SOFT_REBOOT2); //Soft Reboot Beacon Module - DEBUG_UART2.printf("Beacon Device Resetted %s",SOFT_REBOOT2); - } } -void Change_Beacon_Parameter(unsigned char* Beacon_Parameter_To_Set) +void Change_Beacon_Parameter(unsigned char* Beacon_Parameter_To_Set,unsigned char Length) { uint8 i; - for(i = 0;i<21;i++) + for(i = 0;i<Length;i++) { Beacon_Module_UART.putc(Beacon_Parameter_To_Set[i]); - DEBUG_UART2.putc(Beacon_Parameter_To_Set[i]); + DEBUG_UART2.printf("%2x",Beacon_Parameter_To_Set[i]); } - //Beacon_Module_UART.printf('%x',0x0d); - //DEBUG_UART2.putc('%x',0x0d); - Beacon_Module_UART.printf("%s",Beacon_Parameter_To_Set); - //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 - //DEBUG_UART2.printf("%s",Beacon_Parameter_To_Set); } void Initialize_Beacon_Module(void)