| [534] | 1 | // toillgpsproducer.cc
 | 
|---|
 | 2 | // Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | #include "toillgpsproducer.h"
 | 
|---|
 | 5 | #include "archfileset.h"
 | 
|---|
 | 6 | #include "toimanager.h"
 | 
|---|
 | 7 | #include "requesthandler.h"
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | #define   gpsTime          "gpsTime"
 | 
|---|
 | 10 | #define   latitude         "latitude"
 | 
|---|
 | 11 | #define   longitude        "longitude"
 | 
|---|
 | 12 | #define   altitude         "altitude"
 | 
|---|
 | 13 | #define   gpsQuality       "gpsQuality"
 | 
|---|
 | 14 | #define   gpsNSat          "gpsNSat"
 | 
|---|
 | 15 | #define   gpsHDOP          "gpsHDOP"
 | 
|---|
 | 16 | #define   gpsGeoidSep      "gpsGeoidSep"
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | TOILLGPSProducer::TOILLGPSProducer()
 | 
|---|
 | 20 | {
 | 
|---|
 | 21 |   possibleTOIs.insert(TOI(gpsTime,      TOI::unspec,   "", "seconds", "onboardGPS"));  
 | 
|---|
 | 22 |   possibleTOIs.insert(TOI(latitude,     TOI::unspec,   "", "degrees", "onboardGPS"));  // + = NORTH
 | 
|---|
 | 23 |   possibleTOIs.insert(TOI(longitude,    TOI::unspec,   "", "degrees", "onboardGPS"));  // + = EAST
 | 
|---|
 | 24 |   possibleTOIs.insert(TOI(altitude,     TOI::unspec,   "", "meters",  "onboardGPS"));  
 | 
|---|
 | 25 |   possibleTOIs.insert(TOI(gpsQuality,   TOI::unspec,   "", "flag",    "onboardGPS"));  
 | 
|---|
 | 26 |   possibleTOIs.insert(TOI(gpsNSat,      TOI::unspec,   "", "integer", "onboardGPS"));  
 | 
|---|
 | 27 |   possibleTOIs.insert(TOI(gpsHDOP,      TOI::unspec,   "", "real",    "onboardGPS"));  
 | 
|---|
 | 28 |   possibleTOIs.insert(TOI(gpsGeoidSep,  TOI::unspec,   "", "meters",  "onboardGPS"));
 | 
|---|
 | 29 | }
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | string TOILLGPSProducer::getName() {
 | 
|---|
 | 32 |   return("TOILLGPSProducer 1.0");
 | 
|---|
 | 33 | }
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | // GPGGA string : 
 | 
|---|
 | 37 | // $hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,,
 | 
|---|
 | 38 | // $104020,3740.712,N,00400.781,W,0,00,01.0,0003,M,-050,M,,
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | void TOILLGPSProducer::handleBlock(ArchFileSet* fs)
 | 
|---|
 | 42 | {
 | 
|---|
 | 43 |   block_type_gps* blk = fs->lastGPS();
 | 
|---|
 | 44 |   long sample0 = numero_block(blk)*72;
 | 
|---|
 | 45 |     
 | 
|---|
 | 46 |   double gpsutc;        //  secondes depuis minuit
 | 
|---|
 | 47 |   double gpslat;        //  degres, + = NORD
 | 
|---|
 | 48 |   double gpslong;       //  degres, + = EST
 | 
|---|
 | 49 |   double alt;           //  altitude en metres
 | 
|---|
 | 50 |   int    quality;       //  0 = NO FIX, 1 = GPS FIX, 2 = DGPS FIX
 | 
|---|
 | 51 |   int    nsat;          //  nombre de satellites utilises
 | 
|---|
 | 52 |   double hdop;          //  horizontal dilution of precision
 | 
|---|
 | 53 |   double gsep;          //  separation geoide en metres
 | 
|---|
 | 54 |   
 | 
|---|
 | 55 |   char* p = blk->gps;
 | 
|---|
 | 56 |   char* fence = p+80;
 | 
|---|
 | 57 |   if (*p!='$') return;
 | 
|---|
 | 58 |   p++;
 | 
|---|
 | 59 |   
 | 
|---|
 | 60 |   // UTC
 | 
|---|
 | 61 |   if (*p < '0' || *p > '9') return;
 | 
|---|
 | 62 |   double t;
 | 
|---|
 | 63 |   sscanf(p, "%lg", &t);
 | 
|---|
 | 64 |   int h = int(t/10000); t -= h*10000;
 | 
|---|
 | 65 |   int m = int(t/100);   t -= m*100;
 | 
|---|
 | 66 |   gpsutc = h*3600. + m*60. + t;
 | 
|---|
 | 67 |   p += 6;
 | 
|---|
 | 68 |   if (*p != ',') return;
 | 
|---|
 | 69 |   p++;
 | 
|---|
 | 70 |   if (p>=fence) return;
 | 
|---|
 | 71 |   
 | 
|---|
 | 72 |   // LATITUDE
 | 
|---|
 | 73 |   if (*p < '0' || *p > '9') return;
 | 
|---|
 | 74 |   sscanf(p, "%lg", &t);
 | 
|---|
 | 75 |   int d = int(t/100); t -= d*100;
 | 
|---|
 | 76 |   t = d + t/60;
 | 
|---|
 | 77 |   p += 8;
 | 
|---|
 | 78 |   if (*p != ',') return; 
 | 
|---|
 | 79 |   p++;
 | 
|---|
 | 80 |   if (*p == 'S') t = -t;
 | 
|---|
 | 81 |   gpslat = t;
 | 
|---|
 | 82 |   p++;
 | 
|---|
 | 83 |   if (*p != ',') return; 
 | 
|---|
 | 84 |   p++;
 | 
|---|
 | 85 |   if (p>=fence) return;
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 |   // LONGITUDE
 | 
|---|
 | 88 |   if (*p < '0' || *p > '9') return;
 | 
|---|
 | 89 |   sscanf(p, "%lg", &t);
 | 
|---|
 | 90 |   d = int(t/100); t -= d*100;
 | 
|---|
 | 91 |   t = d + t/60;
 | 
|---|
 | 92 |   p += 9;
 | 
|---|
 | 93 |   if (*p != ',') return; 
 | 
|---|
 | 94 |   p++;
 | 
|---|
 | 95 |   if (*p == 'W') t = -t;
 | 
|---|
 | 96 |   gpslong = t;
 | 
|---|
 | 97 |   p++;
 | 
|---|
 | 98 |   if (*p != ',') return; 
 | 
|---|
 | 99 |   p++;
 | 
|---|
 | 100 |   if (p>=fence) return;
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 |   // QUALITY
 | 
|---|
 | 103 |   quality = *p - '0';
 | 
|---|
 | 104 |   if (quality < 0 || quality > 9) return;
 | 
|---|
 | 105 |   p++;
 | 
|---|
 | 106 |   if (*p != ',') return; 
 | 
|---|
 | 107 |   p++;
 | 
|---|
 | 108 |   if (p>=fence) return;
 | 
|---|
 | 109 |   
 | 
|---|
 | 110 |   // NSAT
 | 
|---|
 | 111 |   if (*p < '0' || *p > '9') return;
 | 
|---|
 | 112 |   sscanf(p, "%d", &nsat);
 | 
|---|
 | 113 |   p += 2;
 | 
|---|
 | 114 |   if (*p != ',') return; 
 | 
|---|
 | 115 |   p++;
 | 
|---|
 | 116 |   
 | 
|---|
 | 117 |   // HDOP
 | 
|---|
 | 118 |   if (*p < '0' || *p > '9') return;
 | 
|---|
 | 119 |   sscanf(p, "%lg", &hdop);
 | 
|---|
 | 120 |   while (*p != ',' && p<fence) p++;
 | 
|---|
 | 121 |   if (*p != ',') return; 
 | 
|---|
 | 122 |   p++;
 | 
|---|
 | 123 |   
 | 
|---|
 | 124 |   // Altitude
 | 
|---|
 | 125 |   if (*p < '0' || *p > '9') return;
 | 
|---|
 | 126 |   sscanf(p, "%lg", &alt);
 | 
|---|
 | 127 |   while (*p != ',' && p<fence) p++;
 | 
|---|
 | 128 |   if (*p != ',') return; 
 | 
|---|
 | 129 |   p++;
 | 
|---|
 | 130 |   if (*p != 'M') return; 
 | 
|---|
 | 131 |   p++;
 | 
|---|
 | 132 |   if (*p != ',') return; 
 | 
|---|
 | 133 |   p++;
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 |   // Geoid separation
 | 
|---|
 | 136 |   if ((*p < '0' || *p > '9') && *p != '-') return;
 | 
|---|
 | 137 |   sscanf(p, "%lg", &gsep);
 | 
|---|
 | 138 |   while (*p != ',' && p<fence) p++;
 | 
|---|
 | 139 |   if (*p != ',') return; 
 | 
|---|
 | 140 |   p++;
 | 
|---|
 | 141 |   if (*p != 'M') return; 
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 |   for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
 | 
|---|
 | 144 |     if ((*i).name == gpsTime)        computedValue((*i), sample0, gpsutc);
 | 
|---|
 | 145 |     if ((*i).name == latitude)       computedValue((*i), sample0, gpslat);
 | 
|---|
 | 146 |     if ((*i).name == longitude)      computedValue((*i), sample0, gpslong);
 | 
|---|
 | 147 |     if ((*i).name == altitude)       computedValue((*i), sample0, alt);
 | 
|---|
 | 148 |     if ((*i).name == gpsQuality)     computedValue((*i), sample0, quality);
 | 
|---|
 | 149 |     if ((*i).name == gpsNSat)        computedValue((*i), sample0, nsat);
 | 
|---|
 | 150 |     if ((*i).name == gpsHDOP)        computedValue((*i), sample0, hdop);
 | 
|---|
 | 151 |     if ((*i).name == gpsGeoidSep)    computedValue((*i), sample0, gsep);
 | 
|---|
 | 152 |   }
 | 
|---|
 | 153 | }
 | 
|---|
 | 154 | 
 | 
|---|
 | 155 | 
 | 
|---|
 | 156 | 
 | 
|---|