-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgps_module.ic
146 lines (117 loc) · 4.01 KB
/
gps_module.ic
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//Ryan Hartlage, Pat Wensing 2008-2010
int _gps_data[5];
int gps_x, gps_y, gps_heading, gps_button, gps_bin;
int _gps_continuous_pid = -1;
/*-------------------------------------------------------------------------------------------------*/
void gps_initialize_knob()
{
printf("\nGPS - UNPLUG & Press Start\n");
start_press();
printf("\nSelect region with knob and press start\n");
while(!start_button())
{
printf("Region: %c\n", knob()/32+65);
msleep(200L);
}
gps_initialize(knob()/32+65);
while(start_button());
}
/*-------------------------------------------------------------------------------------------------*/
void gps_initialize(int regionc)
{
int region = (int)regionc;
printf("\nGPS - UNPLUG & Press Start\n");
start_press();
//Select region based on character ranges
if((region >= 97) && (region <= 104)) // 'a'-'h'
region-=96;
else if((region >= 65) && (region <= 72)) // 'A'-'H'
region-=64;
else if((region >= 49) && (region <= 56)) // '1'-'8'
region-=48;
else if((region >= 1) && (region <= 8)) // 1-8
region-=0;
else // Bad
{
printf("INVALID REGION\n");
while(1);
}
// Reconfigures serial port and sets region (gps still not enabled in software)
gps_initialize_asm(region);
// Physically enable RF receiver
set_digital_out(0);
}
/*-------------------------------------------------------------------------------------------------*/
void gps_disable()
{
// Physically disable the RF receiver
clear_digital_out(0);
// Prepare the HandyBoard for serial communication and disables reception of GPS packets
gps_disable_asm(0);
}
/*-------------------------------------------------------------------------------------------------*/
int gps_enable()
{
// Enables software reception of GPS packets
gps_enable_asm(0);
}
/*-------------------------------------------------------------------------------------------------*/
int gps_get_data()
{
int gps_data_size;
int counter = 0;
// Print message if stop signal has been received
if(gps_stopped(0)>0)
{
printf("\nGPS - STOP RECEIVED\n");
msleep(50L);
}
// Run assembly code function to find if data is ready
if(gps_ready(0))
{
gps_data_size = gps_size(0);
// Get the raw data from the packet
while(counter < gps_data_size)
{
// Mask out the parity bit in the LSB
_gps_data[counter] = (gps_element(counter) & 0xFE)/2;
counter++;
}
// Parse data from the individual bytes
gps_x = _gps_data[0]*16+(_gps_data[1]&0xFC)/4 - 288;
gps_y = (_gps_data[1]&0x3)*256 + _gps_data[2]*4 + (_gps_data[3]&0x30)/16;
gps_heading = (_gps_data[3]&0x0F)*16 + (_gps_data[4]&0x3C)/4;
gps_button = _gps_data[4]&0x1;
gps_bin = ( _gps_data[4]&0x2 ) / 2;
// Clear ready flag (so that gps_ready(0) will return 0 until the next packet comes in)
gps_clear(0);
return 1;
}
else
{
return 0;
}
}
/*-------------------------------------------------------------------------------------------------*/
void gps_continuous_enable()
{
if(_gps_continuous_pid == -1)
{
_gps_continuous_pid = start_process(_gps_continuous());
}
}
/*-------------------------------------------------------------------------------------------------*/
void gps_continuous_disable()
{
_gps_continuous_pid = -1;
}
/*-------------------------------------------------------------------------------------------------*/
void _gps_continuous()
{
while(_gps_continuous_pid != -1)
{
gps_get_data();
defer();
}
}
/*-------------------------------------------------------------------------------------------------*/