Fix day/night sensor polling

This commit is contained in:
hawkeyexp 2018-12-05 19:42:39 +01:00
parent cd36c39037
commit 95a329f33d

View File

@ -41,6 +41,7 @@ SensorService::SensorService(boost::asio::io_service& ioService, aasdk::messenge
void SensorService::start()
{
strand_.dispatch([this, self = this->shared_from_this()]() {
this->nightSensorPolling();
OPENAUTO_LOG(info) << "[SensorService] start.";
channel_->receive(this->shared_from_this());
});
@ -129,16 +130,9 @@ void SensorService::sendNightData()
indication.add_night_mode()->set_is_night(true);
} else {
OPENAUTO_LOG(info) << "[SensorService] Mode day triggered";
indication.add_night_mode()->set_is_night(false);
}
//if (!std::ifstream("/tmp/night_mode_enabled")) {
// OPENAUTO_LOG(error) << "[CS] [SensorService] Mode day triggered";
// indication.add_night_mode()->set_is_night(false);
//} else {
// indication.add_night_mode()->set_is_night(true);
// OPENAUTO_LOG(error) << "[CS] [SensorService] Mode night triggered";
//}
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendSensorEventIndication(indication, std::move(promise));
@ -152,7 +146,6 @@ void SensorService::nightSensorPolling()
this->previous = this->isNight;
this->sendNightData();
}
timer_.expires_from_now(boost::posix_time::seconds(5));
timer_.async_wait(strand_.wrap(std::bind(&SensorService::nightSensorPolling, this->shared_from_this())));
});