-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPS.c
116 lines (98 loc) · 2.48 KB
/
GPS.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <string.h>
#include <stdlib.h>
#include <msp430g2553.h>
#include "GPS.h"
extern char tx_buf[128];
extern volatile int bytes_to_send;
extern volatile int tx_ptr;
void GPS_start_logging(void){
tx_ptr = 0;
strcpy(tx_buf, PMTK_START_LOG);
bytes_to_send = strlen(tx_buf)+2;
UC0IE |= UCA0TXIE;
while (UCA0STAT & UCBUSY);
}
void GPS_stop_logging(void){
tx_ptr = 0;
strcpy(tx_buf, PMTK_STOP_LOG);
bytes_to_send = strlen(tx_buf)+2;
UC0IE |= UCA0TXIE;
while (UCA0STAT & UCBUSY);
}
void GPS_erase_flash(void){
tx_ptr = 0;
strcpy(tx_buf, PMTK_ERASE_FLASH);
bytes_to_send = strlen(tx_buf)+2;
UC0IE |= UCA0TXIE;
while (UCA0STAT & UCBUSY);
}
void GPS_set_fixblink_rate(int rate){
tx_ptr = 0;
switch (rate) {
case PMTK_FIX_RATE_100mhz:
strcpy(tx_buf, PMTK_API_SET_FIX_CTL_100_MILLIHZ);
break;
case PMTK_FIX_RATE_200mhz:
strcpy(tx_buf, PMTK_API_SET_FIX_CTL_200_MILLIHZ);
break;
case PMTK_FIX_RATE_5hz:
strcpy(tx_buf, PMTK_API_SET_FIX_CTL_5HZ);
break;
default:
case PMTK_FIX_RATE_1hz:
strcpy(tx_buf, PMTK_API_SET_FIX_CTL_1HZ);
break;
}
bytes_to_send = strlen(tx_buf)+2;
UC0IE |= UCA0TXIE;
while (UCA0STAT & UCBUSY);
}
void GPS_NMEA_output(int output){
tx_ptr = 0;
switch (output) {
case PMTK_NMEA_OFF:
strcpy(tx_buf, PMTK_SET_NMEA_OUTPUT_OFF);
break;
case PMTK_NMEA_ONLY_RMC_GGA:
strcpy(tx_buf, PMTK_SET_NMEA_OUTPUT_RMC_GGA);
break;
default:
case PMTK_NMEA_ALL_DATA:
strcpy(tx_buf, PMTK_SET_NMEA_OUTPUT_ALL_DATA);
break;
}
bytes_to_send = strlen(tx_buf)+2;
UC0IE |= UCA0TXIE;
while (UCA0STAT & UCBUSY);
}
void GPS_stand_by(void){
tx_ptr &= 0;
strcpy(tx_buf, PMTK_STAND_BY);
bytes_to_send = strlen(tx_buf)+2;
while (UCA0STAT & UCBUSY);
}
void GPS_wake_up(void){
tx_ptr &= 0;
strcpy(tx_buf, "Hi\n"); // 1 byte will suffice to wake module up
bytes_to_send = strlen(tx_buf)+1;
UC0IE |= UCA0TXIE;
while (UCA0STAT & UCBUSY);
__delay_cycles(16383); // give module some time
}
int GPS_flash_usage(char *status){
int _offset;
char *token;
char usage[3]; // up to 3 digit number
token = strtok(status, "*"); // retrieve till end of payload
// locate last item
if (token[strlen(token)-2] == ',') // 1 digit
_offset = strlen(token)-2;
else if (token[strlen(token)-3] == ',') // 2 digits
_offset = strlen(token)-3;
else if (token[strlen(token)-4] == ',') // 3 digits
_offset = strlen(token)-3;
else if (token[strlen(token)-4] == ',') // 3 digits
_offset = strlen(token)-4;
strcpy(usage, token+_offset);
return atoi(usage);
}