~awuerl/blitzortung-tracker/0.9

« back to all changes in this revision

Viewing changes to source/lib/ipc/server/Json.cc

  • Committer: Andreas Würl
  • Date: 2011-06-27 23:15:30 UTC
  • Revision ID: awuerl@gmx.net-20110627231530-28xgku0k9bov975j
more robust ipc interface
access by index in blitzortung-data

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
            const hardware::gps::Base& gps = hardware_.getGps();
27
27
            json_object* jsonGps = json_object_new_object();
 
28
 
 
29
            logger_.debugStream() << "gps";
 
30
            try {
 
31
              json_object_object_add(jsonGps, "longitude", json_object_new_double(gps.getLocation().getLongitude()));
 
32
              json_object_object_add(jsonGps, "longitudeError", json_object_new_double(gps.getLocation().getLongitudeError()));
 
33
              json_object_object_add(jsonGps, "latitude", json_object_new_double(gps.getLocation().getLatitude()));
 
34
              json_object_object_add(jsonGps, "latitudeError", json_object_new_double(gps.getLocation().getLatitudeError()));
 
35
              json_object_object_add(jsonGps, "altitude", json_object_new_int(gps.getLocation().getAltitude()));
 
36
              json_object_object_add(jsonGps, "altitudeError", json_object_new_int(gps.getLocation().getAltitudeError()));
 
37
              pt::ptime gpsTime = gps.getTime();
 
38
              std::ostringstream oss;
 
39
              gr::date_facet *datefacet = new gr::date_facet();
 
40
              datefacet->format("%Y-%m-%d");
 
41
              oss.imbue(std::locale(std::locale::classic(), datefacet));
 
42
              oss << gpsTime.date();
 
43
              json_object_object_add(jsonGps, "date", json_object_new_string(oss.str().c_str()));
 
44
              oss.str("");
 
45
              oss << gpsTime.time_of_day();
 
46
              json_object_object_add(jsonGps, "time", json_object_new_string(oss.str().c_str()));
 
47
              json_object_object_add(jsonGps, "ticksPerSecond", json_object_new_double(gps.getTicksPerSecond()));
 
48
              json_object_object_add(jsonGps, "tickError", json_object_new_double(gps.getTickError()));
 
49
              json_object_object_add(jsonGps, "satelliteCount", json_object_new_int(gps.getSatelliteCount()));
 
50
            } catch (exception::Base &e) {
 
51
            logger_.debugStream() << "gps failed";
 
52
            }
28
53
            char gpsStatus = gps.getStatus();
29
 
            json_object_object_add(jsonGps, "longitude", json_object_new_double(gps.getLocation().getLongitude()));
30
 
            json_object_object_add(jsonGps, "longitudeError", json_object_new_double(gps.getLocation().getLongitudeError()));
31
 
            json_object_object_add(jsonGps, "latitude", json_object_new_double(gps.getLocation().getLatitude()));
32
 
            json_object_object_add(jsonGps, "latitudeError", json_object_new_double(gps.getLocation().getLatitudeError()));
33
 
            json_object_object_add(jsonGps, "altitude", json_object_new_int(gps.getLocation().getAltitude()));
34
 
            json_object_object_add(jsonGps, "altitudeError", json_object_new_int(gps.getLocation().getAltitudeError()));
35
 
            pt::ptime gpsTime = gps.getTime();
36
 
            std::ostringstream oss;
37
 
            gr::date_facet *datefacet = new gr::date_facet();
38
 
            datefacet->format("%Y-%m-%d");
39
 
            oss.imbue(std::locale(std::locale::classic(), datefacet));
40
 
            oss << gpsTime.date();
41
 
            json_object_object_add(jsonGps, "date", json_object_new_string(oss.str().c_str()));
42
 
            oss.str("");
43
 
            oss << gpsTime.time_of_day();
44
 
            json_object_object_add(jsonGps, "time", json_object_new_string(oss.str().c_str()));
45
 
            json_object_object_add(jsonGps, "ticksPerSecond", json_object_new_double(gps.getTicksPerSecond()));
46
 
            json_object_object_add(jsonGps, "tickError", json_object_new_double(gps.getTickError()));
47
54
            json_object_object_add(jsonGps, "status", json_object_new_string_len(&gpsStatus, 1));
48
 
            json_object_object_add(jsonGps, "satelliteCount", json_object_new_int(gps.getSatelliteCount()));
49
55
            json_object_object_add(jsonGps, "type", json_object_new_string(gps.getType().c_str()));
50
56
            json_object_object_add(jsonHardware, "gps", jsonGps);
51
57
            
 
58
            logger_.debugStream() << "comm";
52
59
            const hardware::comm::Base& comm = hardware_.getComm();
53
60
            json_object* jsonComm = json_object_new_object();
54
61
            json_object_object_add(jsonComm, "baudRate", json_object_new_int(comm.getBaudRate()));
55
62
            json_object_object_add(jsonComm, "interfaceName", json_object_new_string(comm.getInterfaceName().c_str()));
56
63
            json_object_object_add(jsonHardware, "comm", jsonComm);
57
64
 
 
65
            logger_.debugStream() << "process";
58
66
            json_object* jsonProcess = json_object_new_object();
 
67
            try {
59
68
            json_object_object_add(jsonProcess, "numberOfSeconds", json_object_new_int(process_.getEventCountBuffer().getActualSize()));
60
69
            json_object_object_add(jsonProcess, "numberOfEvents", json_object_new_int(process_.getEventCountBuffer().getSum()));
61
70
            json_object_object_add(jsonProcess, "eventsPerSecond", json_object_new_double(process_.getEventCountBuffer().getAverage()));
 
71
            } catch (exception::Base &e) {
 
72
            }
62
73
            json_object_object_add(jsonResponse_, "process", jsonProcess);
63
74
      }
64
75
 
116
127
            json_object_object_add(jsonResponse_, "intervalSeconds", json_object_new_int(intervalSeconds));
117
128
 
118
129
            const hardware::gps::Base& gps = hardware_.getGps();
119
 
            pt::ptime gpsTime = gps.getTime();
 
130
            pt::ptime gpsTime;
 
131
            try {
 
132
              gpsTime = gps.getTime();
 
133
            } catch (exception::Base &e) {
 
134
              gpsTime = pt::not_a_date_time;
 
135
            }
 
136
 
120
137
            std::ostringstream oss;
121
138
            gr::date_facet *datefacet = new gr::date_facet();
122
139
            datefacet->format("%Y-%m-%d");