| SQ2PPJ   Nowicjusz
 
  
 Liczba postów: 19
 Dołączył: 17-07-2014
 | 
			| RE: Tracker APRS do samochodu 
 
				Po małych przeróbkach kod wygląda tak: 
Kod:
 #include <SoftwareSerial.h>#include<string.h>
 #include <Wire.h>
 
 SoftwareSerial gps(3, 4);
 
 void setup()
 {
 Serial.begin(115200);
 gps.begin(9600);
 }
 void loop()
 {
 String gps_data = "";
 String gps_gpgga = "";
 
 while (gps.available())
 {
 gps_data = gps_data + char(gps.read());
 }
 if (gps_data != "")
 {
 int pos_b = gps_data.indexOf('$GPGGA');
 int pos_e = gps_data.indexOf('*');
 gps_gpgga = gps_data.substring(pos_b-5,pos_e);
 Serial.println(gps_gpgga);
 }
 }
 
A dane wyjściowe -tak:
 Cytat:$GPGGA,081849.000,5428.5809,N,01822.3485,E,1,8,0.95,165.6,M,34.0,M,,$GPGGA,081850.000,5428.5807,N,01822.3490,E,1,8,0.96,165.5,M,34.0,M,,
 $GPGGA,081851.000,5428.5809,N,01822.3490,E,1,8,0.96,165.4,M,34.0,M,,
 $GPGGA,081852.000,5428.5810,N,01822.3491,E,1,8,0.96,165.3,M,34.0,M,,
 $GPGGA,081853.000,5428.5810,N,01822.3493,E,1,8,0.95,165.3,M,34.0,M,,
 $GPGGA,081854.000,5428.5808,N,01822.3496,E,1,8,0.95,165.2,M,34.0,M,,
 $GPGGA,081855.000,5428.5806,N,01822.3498,E,1,8,0.96,165.1,M,34.0,M,,
 $GPGGA,081856.000,5428.5806,N,01822.3495,E,1,8,0.95,165.1,M,34.0,M,,
 $GPGGA,081857.000,5428.5804,N,01822.3496,E,1,8,0.95,165.1,M,34.0,M,,
 $GPGGA,081858.000,5428.5803,N,01822.3497,E,1,8,0.95,165.0,M,34.0,M,,
 
Odczyt z GPS-u uznaje tymczasowo za zamknięty, choć nie jestem z niego w 100% zadowolony - zdecydowałem się korzystać z łańcucha GPGGA, ponieważ z GPRMC nadal mam problemy. Pętla while zastosowana w programie "wrzuca" do string-a tylko taki fragment danych:
 Cytat:$GPGGA,083936.000,5428.5816,N,01822.3504,E,1,7,1.04,164.7,M,34.0,M,,*50$GPGSA,A,34,1,,3,.
 ,.056,2E430,AP34,,.3
 
Mimo, że pełne dane wyglądają tak:
 Cytat:$GPGGA,070017.000,5428.5821,N,01822.3515,E,1,7,0.99,162.6,M,34.0,M,,*50$GPGSA,A,3,24,26,28,12,15,18,22,,,,,$GPGGA,070019.000,5428.5822,N,01822.3513,E,1,7,0.99,162.6,M,34.0,M,,*5B
 $GPGSA,A,3,24,26,28,12,15,18,22,,,,,,1.33,0.99,0.89*04
 $GPRMC,070019.000,A,5428.5822,N,01822.3513,E,0.26,118.04,290714,,,A*6B
 $GPVTG,118.04,T,,M,0.26,N,0.48,K,A*39
 
Niemniej dane z łańcucha GPGGA są dla mnie, na tę chwilę, wystarczające dla osiągnięcia zamierzonego celu, więc dalsze testy spycham na razie na dalszy plan.
 
Dodałem obróbkę danych i w tej chwili wygląda to tak:
 
Kod:
 #include <SoftwareSerial.h>#include<string.h>
 #include <Wire.h>
 
 SoftwareSerial gps(3, 4);
 
 void setup()
 {
 Serial.begin(115200);
 gps.begin(9600);
 }
 
 void loop()
 {
 String gps_data, gps_gpgga;
 int coma1,coma2,coma3,coma4,coma5,coma6,coma7;
 while (gps.available())
 {
 gps_data = gps_data + char(gps.read());
 }
 
 if (gps_data != "")
 {
 int pos_b = gps_data.indexOf('$GPGGA');
 int pos_e = gps_data.indexOf('*');
 gps_gpgga = gps_data.substring(pos_b-5,pos_e);
 coma1 = gps_gpgga.indexOf(',');
 coma2 = gps_gpgga.indexOf(',',coma1+1);
 coma3 = gps_gpgga.indexOf(',',coma2+1);
 coma4 = gps_gpgga.indexOf(',',coma3+1);
 coma5 = gps_gpgga.indexOf(',',coma4+1);
 coma6 = gps_gpgga.indexOf(',',coma5+1);
 coma7 = gps_gpgga.indexOf(',',coma6+1);
 int fix = gps_gpgga.substring(coma6+1,coma6+2).toInt();
 if (fix=1)
 {
 int hh = gps_gpgga.substring(coma1+1,coma1+3).toInt();
 int mm = gps_gpgga.substring(coma1+3,coma1+5).toInt();
 int ss = gps_gpgga.substring(coma1+5,coma1+7).toInt();
 Serial.print("Time: ");Serial.print(hh,DEC);Serial.print(":");Serial.print(mm,DEC);Serial.print(":");Serial.println(ss,DEC);
 String lat =  gps_gpgga.substring(coma2+1,coma3) + gps_gpgga.substring(coma3+1,coma3+2);
 Serial.print("Latitude: ");Serial.println(lat);
 String lon =  gps_gpgga.substring(coma4+1,coma5) + gps_gpgga.substring(coma5+1,coma5+2);
 Serial.print("Longitude: ");Serial.println(lon);
 }
 else
 {
 Serial.print("Waiting for GPS fix");
 }
 }
 }
 
I na serial monitor wysyłane są dane w postaci:
 Cytat:Time: 9:51:48Latitude: 5428.5841N
 Longitude: 01822.3546E
 Time: 9:51:49
 Latitude: 5428.5841N
 Longitude: 01822.3556E
 Time: 9:51:50
 Latitude: 5428.5837N
 Longitude: 01822.3577E
 Time: 9:51:51
 Latitude: 5428.5832N
 Longitude: 01822.3594E
				
(Ten post był ostatnio modyfikowany: 30-07-2014 11:52 przez SQ2PPJ.)
 |  |