| 128 | } |
| 129 | |
| 130 | bool GpsService::startReceiving() { |
| 131 | LOGGER.info("Start receiving"); |
| 132 | |
| 133 | if (getState() != State::Off) { |
| 134 | LOGGER.error("Already receiving"); |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | setState(State::OnPending); |
| 139 | |
| 140 | auto lock = mutex.asScopedLock(); |
| 141 | lock.lock(); |
| 142 | |
| 143 | deviceRecords.clear(); |
| 144 | |
| 145 | std::vector<hal::gps::GpsConfiguration> configurations; |
| 146 | if (!getGpsConfigurations(configurations)) { |
| 147 | LOGGER.error("Failed to get GPS configurations"); |
| 148 | setState(State::Off); |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | if (configurations.empty()) { |
| 153 | LOGGER.error("No GPS configurations"); |
| 154 | setState(State::Off); |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | for (const auto& configuration: configurations) { |
| 159 | auto device = std::make_shared<GpsDevice>(configuration); |
| 160 | addGpsDevice(device); |
| 161 | } |
| 162 | |
| 163 | // Reset times before starting devices to avoid race with incoming data |
| 164 | rmcTime = 0; |
| 165 | ggaTime = 0; |
| 166 | |
| 167 | bool started_one_or_more = false; |
| 168 | |
| 169 | for (auto& record: deviceRecords) { |
| 170 | started_one_or_more |= startGpsDevice(record); |
| 171 | } |
| 172 | |
| 173 | if (started_one_or_more) { |
| 174 | setState(State::On); |
| 175 | return true; |
| 176 | } else { |
| 177 | setState(State::Off); |
| 178 | return false; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | void GpsService::stopReceiving() { |
| 183 | LOGGER.info("Stop receiving"); |
no test coverage detected