-
Notifications
You must be signed in to change notification settings - Fork 4
/
ATK_NEO_6M_GPS.ino
150 lines (146 loc) · 3.54 KB
/
ATK_NEO_6M_GPS.ino
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
147
148
149
150
String data="";
int mark = 0;
boolean Mark_Start=false;
boolean valid=false;
String GGAUTCtime,GGAlatitude,GGAlongitude,GPStatus,SatelliteNum,HDOPfactor,Height,
PositionValid,RMCUTCtime,RMClatitude,RMClongitude,Speed,Direction,Date,Declination,Mode;
void setup(){
Serial.begin(9600);
Serial1.begin(38400);
Serial.println(0);
delay(1000);
}
void loop(){
while (Serial1.available()> 0){
if(Mark_Start){
data=reader();
Serial.println(data);
if(data.equals("GPGGA")){
//Serial.println(1);
GGAUTCtime=reader();
GGAlatitude=reader();
GGAlatitude+=reader();
GGAlongitude=reader();
GGAlongitude+=reader();
GPStatus=reader();
SatelliteNum=reader();
HDOPfactor=reader();
Height=reader();
Mark_Start=false;
valid=true;
data="";
}
else if(data.equals("GPGSA")){
Serial.println(2);
Mark_Start=false;
data="";
}
else if(data.equals("GPGSV")){
Serial.println(3);
Mark_Start=false;
data="";
}
else if(data.equals("GPRMC")){
//Serial.println(4);
RMCUTCtime=reader();
PositionValid=reader();
RMClatitude=reader();
RMClatitude+=reader();
RMClongitude=reader();
RMClongitude+=reader();
Speed=reader();
Direction=reader();
Date=reader();
Declination=reader();
Declination+=reader();
Mode=reader();
valid=true;
Mark_Start=false;
data="";
}
else if(data.equals("GPVTG")){
Serial.println(5);
Mark_Start=false;
data="";
}
else{
Serial.println(6);
Mark_Start=false;
data="";
}
}
if(valid){
if(PositionValid=="A"){
Serial.println("Position Valid");
}
else{
Serial.println("Your position is not valid.");
}
Serial.print("Date:");
Serial.println(Date);
Serial.print("UTCtime:");
Serial.print(RMCUTCtime);
Serial.print(" ");
Serial.println(GGAUTCtime);
Serial.print("Latitude:");
Serial.print(RMClatitude);
Serial.print(" ");
Serial.println(GGAlatitude);
Serial.print("Longitude:");
Serial.print(RMClongitude);
Serial.print(" ");
Serial.println(GGAlongitude);
Serial.print("GPStatus:");
Serial.println(GPStatus);
Serial.print("SatelliteNum:");
Serial.println(SatelliteNum);
Serial.print("HDOPfactor:");
Serial.println(HDOPfactor);
Serial.print("Height:");
Serial.println(Height);
Serial.print("Speed:");
Serial.println(Speed);
Serial.print("Direction:");
Serial.println(Direction);
Serial.print("Declination:");
Serial.println(Declination);
Serial.print("Mode:");
Serial.println(Mode);
valid=false;
}
if(Serial1.find("$")){
Serial.println("capture");
Mark_Start=true;
}
}
}
String reader(){
String value="";
int temp;
startover:
while (Serial1.available() > 0){
delay(2);
temp=Serial1.read();
if((temp==',')||(temp=='*')){
if(value.length()){
//Serial.println("meaningful message");
return value;
}
else {
//Serial.println("empty");
return "";
}
}
else if(temp=='$'){
//Serial.println("failure");
Mark_Start=false;
}
else{
//Serial.println("add");
value+=char(temp);
}
}
while (!(Serial1.available()>0)){
}
goto startover;
}