UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


code:emulator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code:emulator [2008/01/19 22:40] rocketboycode:emulator [2021/03/04 14:52] (current) – [C code to simulate NMEA output from a GPS in real time - with live Google Earth Display] rocketboy
Line 1: Line 1:
-===== C code to simulate NMEA output from a GPS in real time - with live Google Erath Display =====+===== C code to simulate NMEA output from a GPS in real time - with live Google Earth Display =====
  
-The code here perfoms the following: +The code here performs the following: 
-**GPSgen.c** - converts source balloon track KML files into GPS NEMA log +**GPSgen.c** - converts source balloon track KML files into GPS NEMA logs (i.e. files containing $GPGGA messages etc.) 
-**emulate.c** - outputs the log to the PC serial port - pacing the output to similate a real gps - at the same time it creates a realtime KML file so you can see where the payload is currently flying using Google Earth. +**emulate.c** - outputs a GPS log to the PC serial port - pacing the output to simulate real time gps output - at the same time //emulate// creates a real-time KML file so you can see where the payload is currently flying using Google Earth. 
-**outer.kml** is the outer kml shell that is configured to re-read the realtime kml file generated by emulate.+**outer.kml** is kml shell that is configured to initiate the real-time display of the kml file generated by emulate (open //outer.kml// file from Google Earth to initiate the real-time display).
  
-Together these programs allow real time testing of payloads with a GPS simulation - as if the payload was flying through the coordinates in the source KML. This allows cut-down algorithms etc. to be checked.  The sorce KML can be from a previous balloon flight - the output of a balloon trajectory forecast - or can be hand crafted to test something specific. +Together these programs allow real time testing of payloads with a GPS simulation - as if the payload was flying through the coordinates in the source KML. This allows cut-down algorithms etc. to be checked.  The source KML can be from a previous balloon flight - the output of a balloon trajectory forecast - or can be hand crafted to test something specific. 
  
-The screenshot below shows the emulation of the Pegasus 1 flight running in the top left DOS window, the generated NMEA in the bottom left DOS window against a background of a Google Earth realtime display of the flight.+Some test NMEA files can be found [[code:NMEA|here]] 
 + 
 +The screenshot below shows the emulation of the Pegasus 1 flight running in the top left DOS window, the generated NMEA in the bottom left DOS window against a background of a Google Earth real-time display of the flight.
  
 {{code:scrsh75.jpg|}} {{code:scrsh75.jpg|}}
  
-Both programs are "filters" (a program that reads form standard input and writes to standard output)- here is how to use them on the command line (in a DOS environment): +Both programs are "filters" (a program that reads form standard input and writes to standard output)- here is how to use them on the command line in a DOS environment (unix is similar): 
  
 <code> <code>
Line 22: Line 24:
  
 Both programs are written using stanard POSIX function calls - so should be portble to many environments including unix and DOS.  Both programs are written using stanard POSIX function calls - so should be portble to many environments including unix and DOS. 
 +
  
  
Line 264: Line 267:
  while(1)  while(1)
  {  {
- i = fscanf(stdin,"%128s",buf); // read a non whitespace from the input+ i = scanf("%128s",buf); // read a non whitespace from the input
  if (i != 1)  if (i != 1)
  {  {
Line 298: Line 301:
  
  // get first LineString co-ordinate as launch position  // get first LineString co-ordinate as launch position
- i = fscanf(stdin,"%f , %f , %f",&FromLon,&FromLat,&FromAlt);+ i = scanf("%f , %f , %f",&FromLon,&FromLat,&FromAlt);
  if (i !=3)  if (i !=3)
  {  {
  fprintf(stderr,"1st coordinate not 3D\n");  fprintf(stderr,"1st coordinate not 3D\n");
- return(1); // abnormal termination+ return 1; // abnormal termination
  }  }
  
Line 309: Line 312:
  while(1)  while(1)
  {  {
- i = fscanf(stdin,"%f , %f , %f",&ToLon,&ToLat,&ToAlt);+ i = scanf("%f , %f , %f",&ToLon,&ToLat,&ToAlt);
  
  if (i != 3)  if (i != 3)
Line 323: Line 326:
  Output_NEMA(Now,ToLat,ToLon,ToAlt,0.0,0.0); // Final Position (assume stationary)  Output_NEMA(Now,ToLat,ToLon,ToAlt,0.0,0.0); // Final Position (assume stationary)
  
- look_for("</coordinates>"); // look for closing <coordinates> token+ look_for("</coordinates>"); // look for closing </coordinates> token
  
  look_for("</LineString>"); // look for closing </LineString> token  look_for("</LineString>"); // look for closing </LineString> token
  
- return(0);+ return 0;
 } }
  
Line 473: Line 476:
  do  do
  {  {
- if (fgets(pch, size - 1, stdin) == NULL) + if (fgets(pch, size, stdin) == NULL) 
- return(0);+ return 0;
  }  }
  while(buf[0] != '$'); // loop until NMEA valid line read  while(buf[0] != '$'); // loop until NMEA valid line read
   
- return(1); // line read OK+ return 1; // line read OK
 } }
  
Line 540: Line 543:
  point = (int)((bearing + 11.25) / 22.5); // calculate a compas point 0 - 16 for 0 - 360  point = (int)((bearing + 11.25) / 22.5); // calculate a compas point 0 - 16 for 0 - 360
  point &= 0x000F; // wrap 16 to 0   point &= 0x000F; // wrap 16 to 0 
- return&points[point * 4]);   + return &points[point * 4];   
 } }
  
Line 548: Line 551:
 double Time_to_Sec(int Hours, int Minutes, double Seconds) double Time_to_Sec(int Hours, int Minutes, double Seconds)
 { {
- return(Seconds + ((double)Minutes * 60.0) + ((double)Hours * 3600.0));+ return Seconds + ((double)Minutes * 60.0) + ((double)Hours * 3600.0);
 } }
  
Line 558: Line 561:
  
  if ((Dir == 'N') || (Dir == 'E'))  if ((Dir == 'N') || (Dir == 'E'))
- return(Deg);+ return Deg;
  else  else
- return(-Deg); // Assume 'W' or 'S'+ return -Deg; // Assume 'W' or 'S'
 } }
  
Line 621: Line 624:
  Second - BaseSec,LatDeg,LonDeg,Alt,Bearing,deg_to_compass16(Bearing),Distance);  Second - BaseSec,LatDeg,LonDeg,Alt,Bearing,deg_to_compass16(Bearing),Distance);
  
- return(GPGGA);+ return GPGGA;
  }  }
  
Line 631: Line 634:
  fprintf(stderr," Co=%5.1f %.3s Kh=%.1f%",Course,deg_to_compass16(Course),SpeedKn * 1.852);  fprintf(stderr," Co=%5.1f %.3s Kh=%.1f%",Course,deg_to_compass16(Course),SpeedKn * 1.852);
  
- return(GPRMC);+ return GPRMC;
  }  }
  
Line 638: Line 641:
  if (i > 0)  if (i > 0)
  { // some fileds converted  { // some fileds converted
- return(GPVTG);+ return GPVTG;
  }  }
  
- return(NONE);+ return NONE;
 } }
  
Line 685: Line 688:
     }     }
  
- return(0); // normal termination+ return 0; // normal termination
 } }
  
code/emulator.1200782400.txt.gz · Last modified: 2008/07/19 23:31 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki