kumar singh
/
Dealer_23Feb
Dummy Lora Packet Sending
Fork of Dealer_18feb17 by
Lora.h@16:7703b9d92326, 2017-02-17 (annotated)
- Committer:
- NarendraSingh
- Date:
- Fri Feb 17 08:30:35 2017 +0000
- Revision:
- 16:7703b9d92326
- Parent:
- 14:144ed8b74713
- Child:
- 18:86f069689502
Dealer - Committed by BALA; To change - Debug UART to Serial PC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NarendraSingh | 11:77e595130230 | 1 | #include "mbed.h" |
NarendraSingh | 11:77e595130230 | 2 | #include "Common_Defs.h" |
NarendraSingh | 11:77e595130230 | 3 | |
NarendraSingh | 11:77e595130230 | 4 | // mDOT AT COMMANDS DEFINITIONS |
NarendraSingh | 11:77e595130230 | 5 | #define ENABLED 1 |
NarendraSingh | 11:77e595130230 | 6 | #define Disabled 0 |
NarendraSingh | 11:77e595130230 | 7 | #define NWK_PARA_HEX 0 |
NarendraSingh | 11:77e595130230 | 8 | #define NWK_PARA_STRING 1 |
NarendraSingh | 11:77e595130230 | 9 | #define LORA_UART_RX_Size 2000//Buffer for receiving Lora responses |
NarendraSingh | 11:77e595130230 | 10 | |
NarendraSingh | 11:77e595130230 | 11 | #define LORA_PACKET_HEADER 0xFE //Lora Header,SOF,Every packet sent starts with 0xFE |
NarendraSingh | 11:77e595130230 | 12 | |
NarendraSingh | 11:77e595130230 | 13 | #define HEART_BEAT_PACKET_CMD 0x01 //MSB,HeartBeat Identification Packet |
NarendraSingh | 11:77e595130230 | 14 | #define CHECKIN_PACKET_CMD 0x02 //MSB,CheckIn Identification Packet |
NarendraSingh | 11:77e595130230 | 15 | #define MOTION_PACKET_CMD 0x03 //MSB,Motion Identification Packet |
NarendraSingh | 11:77e595130230 | 16 | #define LOW_BATTERY_PACKET_CMD 0x04 //MSB,Low Battery Identification Packet |
NarendraSingh | 11:77e595130230 | 17 | #define STATUS_PACKET_CMD 0x05 //MSB,Status Packet |
NarendraSingh | 11:77e595130230 | 18 | #define NEW_DEV_PACKET_CMD 0x06 //MSB,New Device Identification Packet |
NarendraSingh | 11:77e595130230 | 19 | |
NarendraSingh | 11:77e595130230 | 20 | |
NarendraSingh | 11:77e595130230 | 21 | //Lora Frequency SubBand |
NarendraSingh | 11:77e595130230 | 22 | #define FREQUENCY_SUB_BAND_CHANNEL0 0 |
NarendraSingh | 11:77e595130230 | 23 | #define FREQUENCY_SUB_BAND_CHANNEL1 1 |
NarendraSingh | 11:77e595130230 | 24 | #define FREQUENCY_SUB_BAND_CHANNEL2 2 |
NarendraSingh | 11:77e595130230 | 25 | #define FREQUENCY_SUB_BAND_CHANNEL3 3 |
NarendraSingh | 11:77e595130230 | 26 | #define FREQUENCY_SUB_BAND_CHANNEL4 4 |
NarendraSingh | 11:77e595130230 | 27 | #define FREQUENCY_SUB_BAND_CHANNEL5 5 |
NarendraSingh | 11:77e595130230 | 28 | #define FREQUENCY_SUB_BAND_CHANNEL6 6 |
NarendraSingh | 11:77e595130230 | 29 | #define FREQUENCY_SUB_BAND_CHANNEL7 7 |
NarendraSingh | 11:77e595130230 | 30 | #define FREQUENCY_SUB_BAND_CHANNEL8 8 |
NarendraSingh | 11:77e595130230 | 31 | |
NarendraSingh | 11:77e595130230 | 32 | #define HEX_PARAMETER 0 |
NarendraSingh | 11:77e595130230 | 33 | #define STRING_PARAMETER 1 |
NarendraSingh | 11:77e595130230 | 34 | |
NarendraSingh | 11:77e595130230 | 35 | //Network Join Status |
NarendraSingh | 11:77e595130230 | 36 | #define NETWORK_STATUS_JOINED 1 |
NarendraSingh | 11:77e595130230 | 37 | #define NETWORK_STATUS_NOT_JOINED 0 |
NarendraSingh | 11:77e595130230 | 38 | |
NarendraSingh | 11:77e595130230 | 39 | //Netwrork Join Retries Definitions |
NarendraSingh | 11:77e595130230 | 40 | #define NETWORK_JOIN_RETRIES_Disable 0 |
NarendraSingh | 11:77e595130230 | 41 | #define NETWORK_JOIN_RETRIES_1 1 |
NarendraSingh | 11:77e595130230 | 42 | #define NETWORK_JOIN_RETRIES_2 2 |
NarendraSingh | 11:77e595130230 | 43 | #define NETWORK_JOIN_RETRIES_3 3 |
NarendraSingh | 11:77e595130230 | 44 | #define NETWORK_JOIN_RETRIES_4 4 |
NarendraSingh | 11:77e595130230 | 45 | |
NarendraSingh | 11:77e595130230 | 46 | #define HEARTBEAT_TYPE_PACKET 0x01 |
NarendraSingh | 11:77e595130230 | 47 | #define MOTION_TYPE_PACKET 0x02 |
NarendraSingh | 11:77e595130230 | 48 | #define CHECKIN_TYPE_PACKET 0x03 |
NarendraSingh | 12:6107b32b0729 | 49 | #define STATUS_TYPE_PACKET 0x04 |
NarendraSingh | 12:6107b32b0729 | 50 | |
NarendraSingh | 11:77e595130230 | 51 | |
NarendraSingh | 11:77e595130230 | 52 | extern uint8 Packet_Type_To_Send; //By Default Heart Beat PAckets should be sent |
NarendraSingh | 11:77e595130230 | 53 | |
NarendraSingh | 11:77e595130230 | 54 | |
NarendraSingh | 16:7703b9d92326 | 55 | struct Fixed_Beacon |
NarendraSingh | 16:7703b9d92326 | 56 | { |
NarendraSingh | 16:7703b9d92326 | 57 | uint8 Parking1_Beacon_ID[6]; |
NarendraSingh | 16:7703b9d92326 | 58 | uint16 Parking1_Beacon_Minor; |
NarendraSingh | 16:7703b9d92326 | 59 | uint8 Parking1_Beacon_Signal_Strength; |
NarendraSingh | 16:7703b9d92326 | 60 | uint8 Parking2_Beacon_ID[6]; |
NarendraSingh | 16:7703b9d92326 | 61 | uint16 Parking2_Beacon_Minor; |
NarendraSingh | 16:7703b9d92326 | 62 | uint8 Parking2_Beacon_Signal_Strength; |
NarendraSingh | 16:7703b9d92326 | 63 | uint8 Parking3_Beacon_ID[6]; |
NarendraSingh | 16:7703b9d92326 | 64 | uint16 Parking3_Beacon_Minor; |
NarendraSingh | 16:7703b9d92326 | 65 | uint8 Parking3_Beacon_Signal_Strength; |
NarendraSingh | 16:7703b9d92326 | 66 | }; |
NarendraSingh | 16:7703b9d92326 | 67 | |
NarendraSingh | 16:7703b9d92326 | 68 | struct Near_Car_Beacon |
NarendraSingh | 16:7703b9d92326 | 69 | { |
NarendraSingh | 16:7703b9d92326 | 70 | uint8 Near_Car1_Beacon_ID[6]; |
NarendraSingh | 16:7703b9d92326 | 71 | uint16 Near_Car1_Beacon_Minor; |
NarendraSingh | 16:7703b9d92326 | 72 | uint8 Near_Car1_Beacon_Signal_Strength; |
NarendraSingh | 16:7703b9d92326 | 73 | uint8 Near_Car2_Beacon_ID[6]; |
NarendraSingh | 16:7703b9d92326 | 74 | uint16 Near_Car2_Beacon_Minor; |
NarendraSingh | 16:7703b9d92326 | 75 | uint8 Near_Car2_Beacon_Signal_Strength; |
NarendraSingh | 16:7703b9d92326 | 76 | uint8 Near_Car3_Beacon_ID[6]; |
NarendraSingh | 16:7703b9d92326 | 77 | uint16 Near_Car3_Beacon_Minor; |
NarendraSingh | 16:7703b9d92326 | 78 | uint8 Near_Car3_Beacon_Signal_Strength; |
NarendraSingh | 16:7703b9d92326 | 79 | }; |
NarendraSingh | 16:7703b9d92326 | 80 | |
NarendraSingh | 11:77e595130230 | 81 | struct Heart_Beat_PacketType |
NarendraSingh | 11:77e595130230 | 82 | { |
NarendraSingh | 11:77e595130230 | 83 | uint8 Header; |
NarendraSingh | 11:77e595130230 | 84 | uint8 Protocol_Version; |
NarendraSingh | 11:77e595130230 | 85 | uint8 Packet_Type; |
NarendraSingh | 11:77e595130230 | 86 | uint16 OBD_Battery_Voltage; |
NarendraSingh | 11:77e595130230 | 87 | uint16 Car_Battery_Voltage; |
NarendraSingh | 11:77e595130230 | 88 | uint8 OBD_Battery_Temperature; |
NarendraSingh | 11:77e595130230 | 89 | uint8 Car_Ambient_Temperature; |
NarendraSingh | 16:7703b9d92326 | 90 | Fixed_Beacon Fixed_Beacon_Packet; |
NarendraSingh | 11:77e595130230 | 91 | uint8 FCS; |
NarendraSingh | 11:77e595130230 | 92 | }; |
NarendraSingh | 11:77e595130230 | 93 | |
NarendraSingh | 11:77e595130230 | 94 | struct Vehicle_Status_PacketType |
NarendraSingh | 11:77e595130230 | 95 | { |
NarendraSingh | 11:77e595130230 | 96 | uint8 Header; |
NarendraSingh | 11:77e595130230 | 97 | uint8 Protocol_Version; |
NarendraSingh | 11:77e595130230 | 98 | uint8 Packet_Type; |
NarendraSingh | 11:77e595130230 | 99 | uint8 VIN[17]; |
NarendraSingh | 11:77e595130230 | 100 | uint8 ODO_METER_READING[3]; |
NarendraSingh | 11:77e595130230 | 101 | uint16 Fuel_Level; |
NarendraSingh | 11:77e595130230 | 102 | uint16 OBD_Battery_Voltage; |
NarendraSingh | 11:77e595130230 | 103 | uint16 Car_Battery_Voltage; |
NarendraSingh | 11:77e595130230 | 104 | uint8 OBD_Battery_Temperature; |
NarendraSingh | 11:77e595130230 | 105 | uint8 Car_Ambient_Temperature; |
NarendraSingh | 11:77e595130230 | 106 | uint8 BLE_Adv_Beacon_ID[6]; |
NarendraSingh | 16:7703b9d92326 | 107 | Fixed_Beacon Fixed_Beacon_Packet; |
NarendraSingh | 16:7703b9d92326 | 108 | Near_Car_Beacon Near_Car_Beacon_Packet; |
NarendraSingh | 11:77e595130230 | 109 | uint8 FCS; |
NarendraSingh | 11:77e595130230 | 110 | }; |
NarendraSingh | 11:77e595130230 | 111 | |
NarendraSingh | 11:77e595130230 | 112 | struct CheckIN_PacketType |
NarendraSingh | 11:77e595130230 | 113 | { |
NarendraSingh | 11:77e595130230 | 114 | uint8 Header; |
NarendraSingh | 11:77e595130230 | 115 | uint8 Protocol_Version; |
NarendraSingh | 11:77e595130230 | 116 | uint8 Packet_Type; |
NarendraSingh | 11:77e595130230 | 117 | uint8 VIN[17]; |
NarendraSingh | 11:77e595130230 | 118 | uint8 ODO_METER_READING[3]; |
NarendraSingh | 11:77e595130230 | 119 | uint16 OBD_Battery_Voltage; |
NarendraSingh | 11:77e595130230 | 120 | uint16 Car_Battery_Voltage; |
NarendraSingh | 11:77e595130230 | 121 | uint8 OBD_Battery_Temperature; |
NarendraSingh | 11:77e595130230 | 122 | uint8 Car_Ambient_Temperature; |
NarendraSingh | 16:7703b9d92326 | 123 | Fixed_Beacon Fixed_Beacon_Packet; |
NarendraSingh | 11:77e595130230 | 124 | uint8 FCS; |
NarendraSingh | 11:77e595130230 | 125 | }; |
NarendraSingh | 11:77e595130230 | 126 | |
NarendraSingh | 11:77e595130230 | 127 | struct Motion_PacketType |
NarendraSingh | 11:77e595130230 | 128 | { |
NarendraSingh | 11:77e595130230 | 129 | uint8 Header; |
NarendraSingh | 11:77e595130230 | 130 | uint8 Protocol_Version; |
NarendraSingh | 11:77e595130230 | 131 | uint8 Packet_Type; |
NarendraSingh | 16:7703b9d92326 | 132 | Fixed_Beacon Fixed_Beacon_Packet; |
NarendraSingh | 16:7703b9d92326 | 133 | Near_Car_Beacon Near_Car_Beacon_Packet; |
NarendraSingh | 11:77e595130230 | 134 | uint8 Acceleration_Type; |
NarendraSingh | 11:77e595130230 | 135 | uint8 FCS; |
NarendraSingh | 11:77e595130230 | 136 | }; |
NarendraSingh | 11:77e595130230 | 137 | |
NarendraSingh | 16:7703b9d92326 | 138 | |
NarendraSingh | 11:77e595130230 | 139 | extern uint8 Send_Lora_Packet_Flag; |
NarendraSingh | 11:77e595130230 | 140 | extern int Lora_RxBuffer_Crnt_Pos,Lora_RxBuffer_End_Pos; // must be volatile or the compiler may over-optimise. |
NarendraSingh | 11:77e595130230 | 141 | extern int receivedDataCount; |
NarendraSingh | 11:77e595130230 | 142 | extern char LORA_UART_RX_Buffer[LORA_UART_RX_Size]; |
NarendraSingh | 11:77e595130230 | 143 | extern int LORA_UART_RX_Crnt_Pos; |
NarendraSingh | 11:77e595130230 | 144 | extern uint8 Lora_Command_Rcvd[100]; |
NarendraSingh | 11:77e595130230 | 145 | extern uint8 Lora_Cmd_Length; |
NarendraSingh | 11:77e595130230 | 146 | extern uint8 AT_Response_Receive_Status; |
NarendraSingh | 11:77e595130230 | 147 | extern uint8 Vehicle_Identification_Number[17]; //Unique Vehicle_Identification_Number, Read using OBD |
NarendraSingh | 11:77e595130230 | 148 | extern uint8 Motion_Packet_Sent_Count; |
NarendraSingh | 11:77e595130230 | 149 | extern uint8 CheckIN_Packet_Sent_Count; |
NarendraSingh | 11:77e595130230 | 150 | extern uint8 Lora_Packet_To_Send[100]; |
NarendraSingh | 11:77e595130230 | 151 | |
NarendraSingh | 11:77e595130230 | 152 | extern uint8 OBD_Protocol_Version; |
NarendraSingh | 11:77e595130230 | 153 | extern Heart_Beat_PacketType Heart_Beat_Lora_Packet; //Allocate Memory for HeartBeat Lora Packets |
NarendraSingh | 11:77e595130230 | 154 | extern CheckIN_PacketType CheckIN_Lora_Packet; //Allocate Memory for CheckIN Lora Packets |
NarendraSingh | 11:77e595130230 | 155 | extern Motion_PacketType Motion_Lora_Packet; //Allocate Memory for Movement Lora Packets |
NarendraSingh | 11:77e595130230 | 156 | extern Vehicle_Status_PacketType Vehicle_Status_Lora_Packet; //Allocate Memory for Movement Lora Packets |
NarendraSingh | 16:7703b9d92326 | 157 | extern Near_Car_Beacon Near_Car_Packet; |
NarendraSingh | 16:7703b9d92326 | 158 | extern Fixed_Beacon Fixed_Beacon_Packet; |
NarendraSingh | 11:77e595130230 | 159 | |
NarendraSingh | 11:77e595130230 | 160 | void Send_Lora_Packet_To_Gateway(uint8* Command_To_Send,uint8 Length); |
NarendraSingh | 11:77e595130230 | 161 | extern void Flip_Lora_Packet_Sending(); |
NarendraSingh | 11:77e595130230 | 162 | extern void Lora_Periodic_Packet_Sending_thread(void const *arg); |
NarendraSingh | 11:77e595130230 | 163 | void Initialize_lora_Packets(); |
NarendraSingh | 11:77e595130230 | 164 | static void Process_Received_Response(uint8 Response_Length); |
NarendraSingh | 11:77e595130230 | 165 | void Read_Lora_END_Node_ID(uint8* Buffer,uint8 Start_Position,uint8 Response_Length); |
NarendraSingh | 11:77e595130230 | 166 | //extern void Lora_Rcvd_Cmd_Processing_thread(void const *args); |
NarendraSingh | 11:77e595130230 | 167 | void Get_Acceleration_Type(void); |
NarendraSingh | 11:77e595130230 | 168 | void Send_Motion_Packet(void); |
NarendraSingh | 11:77e595130230 | 169 | void Send_CheckIN_Packet(void); |
NarendraSingh | 11:77e595130230 | 170 | void Send_HeartBeat_Packet(void); |
NarendraSingh | 13:8955f2e95021 | 171 | void Send_Vehicle_Status_Packet(void); |
NarendraSingh | 11:77e595130230 | 172 | extern uint8 Calculate_Lora_Frame_FCS(uint8* Packet_Data,uint8 Packet_Length); |
NarendraSingh | 11:77e595130230 | 173 | extern void Set_Up_Lora_Network_Configuration(void); |
NarendraSingh | 13:8955f2e95021 | 174 | extern void Get_Lora_Response(void); |