Advertisement
Guest User

Untitled

a guest
Jun 20th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.10 KB | None | 0 0
  1. void parseString(){
  2.   if (strncmp(parseptr, "$GPGGA",6) == 0)
  3.     parseGPGGA();
  4.   if (strncmp(parseptr, "$GPGSA",6) == 0)
  5.     parseGPGSA();
  6.   if (strncmp(parseptr, "$GPRMC",6) == 0 )
  7.     parseGPRMC();
  8.   if (strncmp(parseptr, "$GPVTG",6) == 0 )
  9.     parseGPVTG();
  10.   if (strncmp(parseptr, "$HCHDG",6) == 0)
  11.     parseHCHDG();
  12.   if (strncmp(parseptr, "$WIMDA",6) == 0 )
  13.     parseWIMDA();
  14.   if (strncmp(parseptr, "$PFEC,GPatt",11) == 0 )
  15.     parsePFEC();
  16.   if (strncmp(parseptr, "$WIXDR",6) == 0 )
  17.     parseWIXDR();
  18.   if (strncmp(parseptr, "$RDATA",6) == 0 )
  19.     parseRDATA();
  20.   if (strncmp(parseptr, "$YPR",4) == 0 )
  21.     parseYPR();
  22. }
  23.  
  24. void parseYPR(){
  25.   parseptr = parseptr+5;
  26.   for (int i = 1; i<10;i++){
  27.     if (parseptr[0] != ',') {
  28.       switch (i){
  29.       case 1:
  30.         yaw = atof(parseptr);
  31.         break;
  32.       case 2:
  33.         pitch = atof(parseptr);
  34.         break;
  35.       case 3:
  36.         roll = atof(parseptr);
  37.         break;
  38.       default:
  39.         break;
  40.       }
  41.       parseptr = strchr(parseptr, ',') + 1;
  42.     }
  43.     else
  44.       parseptr = parseptr +1;
  45.   }
  46. }
  47. void parseGPGGA(){
  48.   parseptr = parseptr+7;
  49.   float inFloat;
  50.   for (int i = 1; i<10;i++){
  51.     if (parseptr[0] != ',') {
  52.       switch (i){
  53.       case 1:
  54.         inFloat= atof(parseptr);
  55.         timeHHMMSS = (uint32_t)inFloat;
  56.         break;
  57.       case 2:
  58.         lattitude = atof(parseptr);
  59.         break;
  60.       case 4:
  61.         longitude =  atof(parseptr);
  62.       case 6:
  63.         fixQuality = atoi(parseptr);
  64.         if(fixQuality == 0)
  65.           gpsFix = false;
  66.         else
  67.           gpsFix = true;
  68.       case 9:
  69.         alt = atof(parseptr);
  70.       default:
  71.         break;
  72.       }
  73.       parseptr = strchr(parseptr, ',') + 1;
  74.     }
  75.     else
  76.       parseptr = parseptr +1;
  77.   }
  78. }
  79. void parseGPGSA(){
  80.   parseptr = parseptr+7;
  81.   if (parseptr[9] == 3)
  82.     gpsFix = true;
  83.   else
  84.     gpsFix = false;
  85. }
  86. void parseGPRMC(){
  87.   parseptr = parseptr+7;
  88.   float inFloat;
  89.   for (int i = 1; i<9;i++){
  90.     if (parseptr[0] != ',') {
  91.       switch (i){
  92.       case 1:
  93.         inFloat= atof(parseptr);
  94.         timeHHMMSS = (uint32_t)inFloat;
  95.         break;
  96.       case 3:
  97.         lattitude = atof(parseptr);
  98.         break;
  99.       case 5:
  100.         longitude =  atof(parseptr);
  101.         break;
  102.       case 7:
  103.         speedKnots = atof(parseptr);
  104.         break;
  105.       case 8:
  106.         trueHeading = atof(parseptr);
  107.         break;
  108.       default:
  109.         break;
  110.       }
  111.       parseptr = strchr(parseptr, ',') + 1;
  112.     }
  113.     else
  114.       parseptr = parseptr +1;
  115.   }      
  116. }
  117.  
  118. void parseGPVTG(){
  119.   parseptr = parseptr+7;
  120.   for (int i = 1; i<8;i++){
  121.     if (parseptr[0] != ',') {
  122.       switch (i){
  123.       case 1:
  124.         trueHeading = atof(parseptr);
  125.         break;
  126.       case 3:
  127.         magneticHeading = atof(parseptr);
  128.         break;
  129.       case 5:
  130.         speedKnots = atof(parseptr);
  131.         break;
  132.       case 7:
  133.         speedKMH = atof(parseptr);
  134.         break;
  135.       default:
  136.         break;
  137.       }
  138.       parseptr = strchr(parseptr, ',') + 1;
  139.     }
  140.     else
  141.       parseptr = parseptr +1;
  142.  
  143.   }
  144. }
  145.  
  146.  
  147. void parseHCHDG(){
  148.   parseptr = parseptr+7;
  149.   for (int i = 1; i<8;i++){
  150.     if (parseptr[0] != ',') {
  151.       switch (i){
  152.       case 1:
  153.         trueHeading = atof(parseptr);
  154.         break;
  155.       case 3:
  156.         magneticHeading = atof(parseptr);
  157.         break;
  158.       case 5:
  159.         speedKnots = atof(parseptr);
  160.         break;
  161.       case 7:
  162.         speedKMH = atof(parseptr);
  163.         break;
  164.       default:
  165.         break;
  166.       }
  167.       parseptr = strchr(parseptr, ',') + 1;
  168.     }
  169.     else {
  170.       parseptr = parseptr +1;
  171.     }
  172.   }
  173. }
  174.  
  175. void parsePFEC(){
  176.   parseptr = parseptr+12;
  177.   for (int i = 1; i<4;i++){
  178.     if (parseptr[0] != ',') {
  179.       switch (i){
  180.       case 1:
  181.         weatherPitch = atof(parseptr);
  182.         break;
  183.       case 2:
  184.         weatherRoll = atof(parseptr);
  185.         break;
  186.       case 3:
  187.         weatherYaw = atof(parseptr);
  188.         break;
  189.       default:
  190.         break;
  191.       }
  192.       parseptr = strchr(parseptr, ',') + 1;
  193.     }
  194.     else
  195.       parseptr = parseptr +1;
  196.   }        
  197. }
  198. void parseWIMDA(){
  199.   parseptr = parseptr+7;
  200.   for (int i = 1; i<20;i++){
  201.     if (parseptr[0] != ',') {
  202.       switch (i){
  203.       case 1:
  204.         barometricPressureInches = atof(parseptr);
  205.         break;
  206.       case 3:
  207.         barometricPressureBars= atof(parseptr);
  208.         break;  
  209.       case 5:
  210.         airTemp = atof(parseptr);
  211.         break;
  212.       case 9:
  213.         relativeHumidity = atof(parseptr);
  214.         break;
  215.       case 11:
  216.         dewPoint = atof(parseptr);
  217.         break;
  218.       case 13:
  219.         windDirectionTrue = atof(parseptr);
  220.         break;
  221.       case 15:
  222.         windDirectionMagnetic = atof(parseptr);
  223.         break;
  224.       case 17:
  225.         windSpeedKnots = atof(parseptr);
  226.         break;
  227.       case 19:
  228.         windSpeedMetersPerSecond = atof(parseptr);
  229.         break;
  230.       default:
  231.         break;
  232.       }
  233.       parseptr = strchr(parseptr, ',') + 1;
  234.     }
  235.     else
  236.       parseptr = parseptr +1;
  237.   }        
  238. }
  239. void parseWIXDR(){
  240.   parseptr = parseptr+7;
  241.   for (int i = 1; i<15;i++){
  242.     if (parseptr[0] != ',') {
  243.       switch (i){
  244.       case 2:
  245.         relativeWindChill = atof(parseptr);
  246.         break;
  247.       case 6:
  248.         theoreticalWindChill = atof(parseptr);
  249.         break;
  250.       case 10:
  251.         weatherPitch = atof(parseptr);
  252.         break;
  253.       case 14:
  254.         weatherRoll = atof(parseptr);
  255.         break;
  256.       default:
  257.         break;
  258.       }
  259.       parseptr = strchr(parseptr, ',') + 1;
  260.     }
  261.     else
  262.       parseptr = parseptr +1;
  263.   }          
  264. }
  265.  
  266. void parseRDATA(){
  267.   parseptr = parseptr+7;
  268.   for (int i = 1; i<4;i++){
  269.     if (parseptr[0] != ',') {
  270.       switch (i){  
  271.       case 1:
  272.         countPerMinute = atoi(parseptr);
  273.         break;
  274.       case 3:
  275.         microSievertPerHour = atof(parseptr);
  276.         break;
  277.       default:
  278.         break;
  279.       }
  280.       parseptr = strchr(parseptr, ',') + 1;
  281.     }
  282.     else {
  283.       parseptr = parseptr +1;
  284.     }
  285.   }        
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement