|
42 | 42 |
|
43 | 43 | #define HMI_BUS_ADDRESS "unix:path=/tmp/dbus_hmi_socket" |
44 | 44 | #define SERVICE_BUS_ADDRESS "unix:path=/tmp/dbus_service_socket" |
45 | | -// Check the content folder. sd_nav still exists without the card installed |
46 | | -#define SD_CARD_PATH "/tmp/mnt/sd_nav/content" |
| 45 | + |
47 | 46 |
|
48 | 47 | __asm__(".symver realpath1,realpath1@GLIBC_2.11.1"); |
49 | 48 |
|
@@ -94,91 +93,7 @@ static void nightmode_thread_func(std::condition_variable &quitcv, std::mutex &q |
94 | 93 | } |
95 | 94 | } |
96 | 95 |
|
97 | | -static void gps_thread_func(std::condition_variable& quitcv, std::mutex& quitmutex, DBus::Connection& serviceBus) |
98 | | -{ |
99 | | - GPSData data, newData; |
100 | | - uint64_t oldTs = 0; |
101 | | - int debugLogCount = 0; |
102 | | - mzd_gps2_start(serviceBus); |
103 | | - |
104 | | - //Not sure if this is actually required but the built-in Nav code on CMU does it |
105 | | - mzd_gps2_set_enabled(true); |
106 | | - |
107 | | - config::readConfig(); |
108 | | - while (!exiting) |
109 | | - { |
110 | | - logd("Getting GPS Data"); |
111 | | - if (config::carGPS && mzd_gps2_get(newData) && !data.IsSame(newData)) |
112 | | - { |
113 | | - data = newData; |
114 | | - timeval tv; |
115 | | - gettimeofday(&tv, nullptr); |
116 | | - uint64_t timestamp = tv.tv_sec * 1000000 + tv.tv_usec; |
117 | | - if (debugLogCount < 50) //only print the first 50 to avoid spamming the log and breaking the opera text box |
118 | | - { |
119 | | - logd("GPS data: %d %d %f %f %d %f %f %f %f \n",data.positionAccuracy, data.uTCtime, data.latitude, data.longitude, data.altitude, data.heading, data.velocity, data.horizontalAccuracy, data.verticalAccuracy); |
120 | | - logd("Delta %f\n", (timestamp - oldTs)/1000000.0); |
121 | | - debugLogCount++; |
122 | | - } |
123 | | - oldTs = timestamp; |
124 | | - |
125 | | - g_hu->hu_queue_command([data, timestamp](IHUConnectionThreadInterface& s) |
126 | | - { |
127 | | - HU::SensorEvent sensorEvent; |
128 | | - HU::SensorEvent::LocationData* location = sensorEvent.add_location_data(); |
129 | | - //AA uses uS and the gps data just has seconds, just use the current time to get more precision so AA can |
130 | | - //interpolate better |
131 | | - location->set_timestamp(timestamp); |
132 | | - location->set_latitude(static_cast<int32_t>(data.latitude * 1E7)); |
133 | | - location->set_longitude(static_cast<int32_t>(data.longitude * 1E7)); |
134 | | - |
135 | | - // If the sd card exists then reverse heading. This should only be used on installs that have the |
136 | | - // reversed heading issue. |
137 | | - double newHeading = data.heading; |
138 | | - |
139 | | - if (config::reverseGPS) |
140 | | - { |
141 | | - const char* sdCardFolder; |
142 | | - sdCardFolder = SD_CARD_PATH; |
143 | | - struct stat sb; |
144 | | - |
145 | | - if (stat(sdCardFolder, &sb) == 0 && S_ISDIR(sb.st_mode)) |
146 | | - { |
147 | | - newHeading = data.heading + 180; |
148 | | - if (newHeading >= 360) |
149 | | - { |
150 | | - newHeading = newHeading - 360; |
151 | | - } |
152 | | - } |
153 | | - } |
154 | | - |
155 | | - location->set_bearing(static_cast<int32_t>(newHeading * 1E6)); |
156 | | - //assuming these are the same units as the Android Location API (the rest are) |
157 | | - double velocityMetersPerSecond = data.velocity * 0.277778; //convert km/h to m/s |
158 | | - location->set_speed(static_cast<int32_t>(velocityMetersPerSecond * 1E3)); |
159 | 96 |
|
160 | | - location->set_altitude(static_cast<int32_t>(data.altitude * 1E2)); |
161 | | - location->set_accuracy(static_cast<int32_t>(data.horizontalAccuracy * 1E3)); |
162 | | - |
163 | | - s.hu_aap_enc_send_message(0, AA_CH_SEN, HU_SENSOR_CHANNEL_MESSAGE::SensorEvent, sensorEvent); |
164 | | - }); |
165 | | - } |
166 | | - logd("Done Getting GPS Data"); |
167 | | - |
168 | | - { |
169 | | - std::unique_lock<std::mutex> lk(quitmutex); |
170 | | - //The timestamps on the GPS events are in seconds, but based on logging the data actually changes faster with the same timestamp |
171 | | - if (quitcv.wait_for(lk, std::chrono::milliseconds(250)) == std::cv_status::no_timeout) |
172 | | - { |
173 | | - break; |
174 | | - } |
175 | | - } |
176 | | - } |
177 | | - |
178 | | - mzd_gps2_set_enabled(false); |
179 | | - logd("Exiting"); |
180 | | - |
181 | | -} |
182 | 97 |
|
183 | 98 | void shutdown(int signum){ |
184 | 99 | exiting = true; |
@@ -241,7 +156,7 @@ int run(int mode, DBus::Connection& serviceBus, DBus::Connection& hmiBus){ |
241 | 156 | callbacks.connected = true; |
242 | 157 |
|
243 | 158 | std::thread nm_thread([&quitcv, &quitmutex](){ nightmode_thread_func(quitcv, quitmutex); } ); |
244 | | - std::thread gp_thread([&quitcv, &quitmutex, &serviceBus](){ gps_thread_func(quitcv, quitmutex, serviceBus); } ); |
| 159 | + std::thread gp_thread(gps_thread_func, &quitcv, &quitmutex, &serviceBus, &exiting); |
245 | 160 | std::thread *hud_thread = nullptr; |
246 | 161 | if(hud_installed()){ |
247 | 162 | hud_thread = new std::thread([&quitcv, &quitmutex, &hudmutex](){ hud_thread_func(quitcv, quitmutex, hudmutex, exiting); } ); |
|
0 commit comments