-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
68 lines (53 loc) · 1.58 KB
/
main.c
File metadata and controls
68 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "mcc_generated_files/mcc.h"
#include "gps.h"
#include "sim800.h"
#include "utils.h"
void main(void) {
double lat, lon;
char RXBuffer[BUFFER_SIZE], batBuf[4], satBuf[3], heightBuf[10], velocityBuf[10];
char latArray[11], lonArray[11];
char response;
// initialize the device
SYSTEM_Initialize();
// give all the devices some time to wake up
__delay_ms(5000);
EUSART_ChangeToSim();
simWakeUp();
EUSART_ChangeToGPS();
while (1) {
//Clear the buffer
memset(RXBuffer, 0, BUFFER_SIZE);
//Wait for a GPGGA line
if(GPS_GetGPGGALine(RXBuffer)){
EUSART_PrintLn(RXBuffer);
// Get amount of satellites
GPS_Get_Satellites(RXBuffer, satBuf);
// Get current height
GPS_Get_Height(RXBuffer, heightBuf);
//Fill the lat & lon double
lat = GPS_NMEAToDouble(RXBuffer, 10);
lon = GPS_NMEAToDouble(RXBuffer, 23);
ftoa(lat, latArray, 6);
ftoa(lon, lonArray, 6);
break;
}
__delay_ms(1000);
}
EUSART_ChangeToSim();
getBatteryLevel(batBuf);
memset(RXBuffer, 0, BUFFER_SIZE);
// Check if a connection has been made
if (waitForConnection()) {
// If so, make the GET request
if (makeGPRSConnection()) {
makeHTTPRequest(latArray, lonArray, batBuf, satBuf, heightBuf);
}
closeGPRSConnection();
}
// Put the sim module to sleep
simSleep();
SLEEP();
}
/**
End of File
*/