Dummy Lora Packet Sending

Fork of Dealer_18feb17 by kumar singh

Committer:
NarendraSingh
Date:
Fri Jan 27 18:30:02 2017 +0000
Revision:
11:77e595130230
Child:
16:7703b9d92326
Before implementing queue;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NarendraSingh 11:77e595130230 1 #include "Beacon.h"
NarendraSingh 11:77e595130230 2 #include "Lora.h"
NarendraSingh 11:77e595130230 3
NarendraSingh 11:77e595130230 4 RawSerial DEBUG_UART2(PA_9, PA_10);//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 11:77e595130230 39 unsigned char SET_MAJOR[7] = {0x41,0x54,0xFF,0xF2,0x00,0x00,0x0D};
NarendraSingh 11:77e595130230 40 unsigned char SET_MINOR[7] = {0x41,0x54,0xFF,0xF3,0x00,0x00,0x0D};
NarendraSingh 11:77e595130230 41 unsigned char SET_MEASURED_POWER[6] = {0x41,0x54,0xFF,0xF4,0x00,0x0D};
NarendraSingh 11:77e595130230 42 unsigned char SET_TRANSMISSION_POWER[6] = {0x41,0x54,0xFF,0xF5,0x00,0x0D};
NarendraSingh 11:77e595130230 43 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 44 unsigned char SET_BROADCAST_INTERVAL[6] = {0x41,0x54,0xFF,0xF7,0x00,0x0D};
NarendraSingh 11:77e595130230 45 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 46 unsigned char SOFT_REBOOT[13] = {0x41,0x54,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D};
NarendraSingh 11:77e595130230 47 unsigned char SET_OPEN_BEACON[7] = {0x41,0x54,0x6F,0x70,0x65,0x6E,0x0D};
NarendraSingh 11:77e595130230 48 unsigned char SET_CLOSE_BEACON[8] = {0x41,0x54,0x63,0x6C,0x6F,0x73,0x65,0x0D};
NarendraSingh 11:77e595130230 49 unsigned char READ_BEACON_MAC_ID[6] = {0x52,0x44,0x6D,0x61,0x63,0x0D};
NarendraSingh 11:77e595130230 50
NarendraSingh 11:77e595130230 51 void Process_Beacon_Command_Received(unsigned char* Command_Received);
NarendraSingh 11:77e595130230 52 void Change_Beacon_Parameter(unsigned char* Beacon_Parameter_To_Set);
NarendraSingh 11:77e595130230 53 void Get_Beacon_Response(void);
NarendraSingh 11:77e595130230 54 void Read_Beacon_Module_MAC_ID(void);
NarendraSingh 11:77e595130230 55 void Initialize_Beacon_Module(void);
NarendraSingh 11:77e595130230 56
NarendraSingh 11:77e595130230 57 void Process_Beacon_Command_Received(unsigned char* Command_Received)
NarendraSingh 11:77e595130230 58 {
NarendraSingh 11:77e595130230 59 static unsigned char Temp_Pos,Start_Position,End_Position,Data_Length;
NarendraSingh 11:77e595130230 60 Start_Position = 0x04;
NarendraSingh 11:77e595130230 61 Temp_Pos = 0x02;
NarendraSingh 11:77e595130230 62 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 63 {
NarendraSingh 11:77e595130230 64 Data_Length = 16;
NarendraSingh 11:77e595130230 65 End_Position = (Start_Position + Data_Length);
NarendraSingh 11:77e595130230 66 for(;Start_Position < End_Position;Start_Position++)
NarendraSingh 11:77e595130230 67 SET_UUID[Start_Position] = Command_Received[Temp_Pos++];
NarendraSingh 11:77e595130230 68 DEBUG_UART2.printf("%s",SET_UUID);
NarendraSingh 11:77e595130230 69 Change_Beacon_Parameter(SET_UUID);
NarendraSingh 11:77e595130230 70 }
NarendraSingh 11:77e595130230 71 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 72 {
NarendraSingh 11:77e595130230 73 SET_MAJOR[Start_Position++] = Command_Received[Temp_Pos++]; //MSB
NarendraSingh 11:77e595130230 74 SET_MAJOR[Start_Position] = Command_Received[Temp_Pos]; //LSB
NarendraSingh 11:77e595130230 75 DEBUG_UART2.printf("%s",SET_MAJOR);
NarendraSingh 11:77e595130230 76 Change_Beacon_Parameter(SET_MAJOR);
NarendraSingh 11:77e595130230 77 }
NarendraSingh 11:77e595130230 78 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 79 {
NarendraSingh 11:77e595130230 80 SET_MINOR[Start_Position++] = Command_Received[Temp_Pos++]; //MSB
NarendraSingh 11:77e595130230 81 SET_MINOR[Start_Position] = Command_Received[Temp_Pos]; //LSB
NarendraSingh 11:77e595130230 82 DEBUG_UART2.printf("%s",SET_MINOR);
NarendraSingh 11:77e595130230 83 Change_Beacon_Parameter(SET_MINOR);
NarendraSingh 11:77e595130230 84 }
NarendraSingh 11:77e595130230 85 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 86 {
NarendraSingh 11:77e595130230 87 SET_MEASURED_POWER[Start_Position] = Command_Received[Temp_Pos];
NarendraSingh 11:77e595130230 88 DEBUG_UART2.printf("%s",SET_MEASURED_POWER);
NarendraSingh 11:77e595130230 89 Change_Beacon_Parameter(SET_MEASURED_POWER);
NarendraSingh 11:77e595130230 90 }
NarendraSingh 11:77e595130230 91 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 92 {
NarendraSingh 11:77e595130230 93 SET_TRANSMISSION_POWER[Start_Position] = Command_Received[Temp_Pos];
NarendraSingh 11:77e595130230 94 DEBUG_UART2.printf("%s",SET_TRANSMISSION_POWER);
NarendraSingh 11:77e595130230 95 Change_Beacon_Parameter(SET_TRANSMISSION_POWER);
NarendraSingh 11:77e595130230 96 }
NarendraSingh 11:77e595130230 97 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 98 {
NarendraSingh 11:77e595130230 99 Data_Length = 8;
NarendraSingh 11:77e595130230 100 End_Position = (Start_Position + Data_Length);
NarendraSingh 11:77e595130230 101 for(;Start_Position < End_Position;Start_Position++)
NarendraSingh 11:77e595130230 102 SET_PAIRING_PASSWORD[Start_Position] = Command_Received[Temp_Pos++];
NarendraSingh 11:77e595130230 103 DEBUG_UART2.printf("%s",SET_PAIRING_PASSWORD);
NarendraSingh 11:77e595130230 104 //Change_Beacon_Parameter(SET_PAIRING_PASSWORD);
NarendraSingh 11:77e595130230 105 Data_Length = 8;
NarendraSingh 11:77e595130230 106 Start_Position = 4;
NarendraSingh 11:77e595130230 107 End_Position = (Start_Position + Data_Length);
NarendraSingh 11:77e595130230 108 //for(Start_Position;Start_Position < End_Position;Start_Position++)
NarendraSingh 11:77e595130230 109 // SET_SOFT_REBOOT[Start_Position] = Command_Received[Temp_Pos++]; //write code to update this password in eeprom
NarendraSingh 11:77e595130230 110 DEBUG_UART2.printf("%s",SOFT_REBOOT);
NarendraSingh 11:77e595130230 111 }
NarendraSingh 11:77e595130230 112 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 113 {
NarendraSingh 11:77e595130230 114 SET_BROADCAST_INTERVAL[Start_Position] = Command_Received[Temp_Pos];
NarendraSingh 11:77e595130230 115 DEBUG_UART2.printf("%s",SET_BROADCAST_INTERVAL);
NarendraSingh 11:77e595130230 116 Change_Beacon_Parameter(SET_BROADCAST_INTERVAL);
NarendraSingh 11:77e595130230 117 }
NarendraSingh 11:77e595130230 118 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 119 {
NarendraSingh 11:77e595130230 120 Data_Length = 12;
NarendraSingh 11:77e595130230 121 End_Position = (Start_Position + Data_Length);
NarendraSingh 11:77e595130230 122 for(;Start_Position < End_Position;Start_Position++)
NarendraSingh 11:77e595130230 123 SET_IBEACON_NAME[Start_Position] = Command_Received[Temp_Pos++];
NarendraSingh 11:77e595130230 124 DEBUG_UART2.printf("%s",SET_IBEACON_NAME);
NarendraSingh 11:77e595130230 125 Change_Beacon_Parameter(SET_IBEACON_NAME);
NarendraSingh 11:77e595130230 126 }
NarendraSingh 11:77e595130230 127 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 128 {
NarendraSingh 11:77e595130230 129 DEBUG_UART2.printf("%s",SET_OPEN_BEACON);
NarendraSingh 11:77e595130230 130 Change_Beacon_Parameter(SET_OPEN_BEACON);
NarendraSingh 11:77e595130230 131 }
NarendraSingh 11:77e595130230 132 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 133 {
NarendraSingh 11:77e595130230 134 DEBUG_UART2.printf("%s",SET_CLOSE_BEACON);
NarendraSingh 11:77e595130230 135 Change_Beacon_Parameter(SET_CLOSE_BEACON);
NarendraSingh 11:77e595130230 136 }
NarendraSingh 11:77e595130230 137 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 138 {
NarendraSingh 11:77e595130230 139 DEBUG_UART2.printf("%s",SOFT_REBOOT);
NarendraSingh 11:77e595130230 140 Beacon_Module_UART.printf("%s",SOFT_REBOOT); //Soft Reboot Beacon Module
NarendraSingh 11:77e595130230 141 }
NarendraSingh 11:77e595130230 142 }
NarendraSingh 11:77e595130230 143
NarendraSingh 11:77e595130230 144 void Change_Beacon_Parameter(unsigned char* Beacon_Parameter_To_Set)
NarendraSingh 11:77e595130230 145 {
NarendraSingh 11:77e595130230 146 Beacon_Module_UART.printf("%s",Beacon_Parameter_To_Set);
NarendraSingh 11:77e595130230 147 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 11:77e595130230 148 }
NarendraSingh 11:77e595130230 149
NarendraSingh 11:77e595130230 150 void Initialize_Beacon_Module(void)
NarendraSingh 11:77e595130230 151 {
NarendraSingh 11:77e595130230 152 Beacon_Module_UART.baud(9600);
NarendraSingh 11:77e595130230 153 Read_Beacon_Module_MAC_ID();
NarendraSingh 11:77e595130230 154 }
NarendraSingh 11:77e595130230 155
NarendraSingh 11:77e595130230 156 void Read_Beacon_Module_MAC_ID(void)
NarendraSingh 11:77e595130230 157 {
NarendraSingh 11:77e595130230 158 uint8 pos;
NarendraSingh 11:77e595130230 159 Beacon_Module_UART.printf("%s",READ_BEACON_MAC_ID);
NarendraSingh 11:77e595130230 160 Get_Beacon_Response();
NarendraSingh 11:77e595130230 161 for(pos=0;pos<6;pos++)
NarendraSingh 11:77e595130230 162 BLE_Adv_Module_Beacon_ID[pos] = Beacon_RX_Buffer[pos];
NarendraSingh 11:77e595130230 163 }
NarendraSingh 11:77e595130230 164
NarendraSingh 11:77e595130230 165 void Get_Beacon_Response(void)
NarendraSingh 11:77e595130230 166 {
NarendraSingh 11:77e595130230 167 char Beacon_inChar=0;
NarendraSingh 11:77e595130230 168 //Keep reading characters until we get a carriage return
NarendraSingh 11:77e595130230 169 while(Beacon_inChar != '\n')
NarendraSingh 11:77e595130230 170 {
NarendraSingh 11:77e595130230 171 //If a character comes in on the serial port, we need to act on it.
NarendraSingh 11:77e595130230 172 if(Beacon_Module_UART.readable())
NarendraSingh 11:77e595130230 173 {
NarendraSingh 11:77e595130230 174 //Get the new character from the Serial port.
NarendraSingh 11:77e595130230 175 Beacon_inChar = Beacon_Module_UART.getc();
NarendraSingh 11:77e595130230 176 //Start by checking if we've received the end of message character ('\r').
NarendraSingh 11:77e595130230 177 if(Beacon_inChar == '\n')
NarendraSingh 11:77e595130230 178 {
NarendraSingh 11:77e595130230 179 //Put the end of string character on our data string
NarendraSingh 11:77e595130230 180 Beacon_RX_Buffer[Beacon_RxIndex]='\0';
NarendraSingh 11:77e595130230 181 //Reset the buffer index so that the next character go es back at the beginning of the string.
NarendraSingh 11:77e595130230 182 Beacon_RxIndex=0;
NarendraSingh 11:77e595130230 183 }
NarendraSingh 11:77e595130230 184 //If we didn't get the end of message character, just add the new character to the string.
NarendraSingh 11:77e595130230 185 else
NarendraSingh 11:77e595130230 186 {
NarendraSingh 11:77e595130230 187 //Add the new character to the string, and increment the index variable.
NarendraSingh 11:77e595130230 188 Beacon_RX_Buffer[Beacon_RxIndex++]=Beacon_inChar;
NarendraSingh 11:77e595130230 189 }
NarendraSingh 11:77e595130230 190 }
NarendraSingh 11:77e595130230 191 }
NarendraSingh 11:77e595130230 192 }