Try day/night code from manvirrr
This commit is contained in:
parent
14662664ed
commit
cd36c39037
@ -34,6 +34,8 @@ class SensorService: public aasdk::channel::sensor::ISensorServiceChannelEventHa
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger);
|
SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger);
|
||||||
|
bool isNight = false;
|
||||||
|
bool previous = false;
|
||||||
|
|
||||||
void start() override;
|
void start() override;
|
||||||
void stop() override;
|
void stop() override;
|
||||||
@ -46,7 +48,10 @@ private:
|
|||||||
using std::enable_shared_from_this<SensorService>::shared_from_this;
|
using std::enable_shared_from_this<SensorService>::shared_from_this;
|
||||||
void sendDrivingStatusUnrestricted();
|
void sendDrivingStatusUnrestricted();
|
||||||
void sendNightData();
|
void sendNightData();
|
||||||
|
bool is_file_exist(const char *filename);
|
||||||
|
void nightSensorPolling();
|
||||||
|
|
||||||
|
boost::asio::deadline_timer timer_;
|
||||||
boost::asio::io_service::strand strand_;
|
boost::asio::io_service::strand strand_;
|
||||||
aasdk::channel::sensor::SensorServiceChannel::Pointer channel_;
|
aasdk::channel::sensor::SensorServiceChannel::Pointer channel_;
|
||||||
};
|
};
|
||||||
|
@ -31,8 +31,9 @@ namespace service
|
|||||||
{
|
{
|
||||||
|
|
||||||
SensorService::SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger)
|
SensorService::SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger)
|
||||||
: strand_(ioService)
|
: strand_(ioService),
|
||||||
, channel_(std::make_shared<aasdk::channel::sensor::SensorServiceChannel>(strand_, std::move(messenger)))
|
timer_(ioService),
|
||||||
|
channel_(std::make_shared<aasdk::channel::sensor::SensorServiceChannel>(strand_, std::move(messenger)))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -122,19 +123,47 @@ void SensorService::sendDrivingStatusUnrestricted()
|
|||||||
void SensorService::sendNightData()
|
void SensorService::sendNightData()
|
||||||
{
|
{
|
||||||
aasdk::proto::messages::SensorEventIndication indication;
|
aasdk::proto::messages::SensorEventIndication indication;
|
||||||
if (!std::ifstream("/tmp/night_mode_enabled")) {
|
|
||||||
OPENAUTO_LOG(error) << "[CS] [SensorService] Mode day triggered";
|
if (SensorService::isNight) {
|
||||||
indication.add_night_mode()->set_is_night(false);
|
OPENAUTO_LOG(info) << "[SensorService] Mode night triggered";
|
||||||
} else {
|
|
||||||
indication.add_night_mode()->set_is_night(true);
|
indication.add_night_mode()->set_is_night(true);
|
||||||
OPENAUTO_LOG(error) << "[CS] [SensorService] Mode night triggered";
|
} else {
|
||||||
|
OPENAUTO_LOG(info) << "[SensorService] Mode day triggered";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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_);
|
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||||
promise->then([]() {}, std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
promise->then([]() {}, std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||||
channel_->sendSensorEventIndication(indication, std::move(promise));
|
channel_->sendSensorEventIndication(indication, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SensorService::nightSensorPolling()
|
||||||
|
{
|
||||||
|
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||||
|
this->isNight = is_file_exist("/tmp/night_mode_enabled");
|
||||||
|
if (this->previous != this->isNight) {
|
||||||
|
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())));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SensorService::is_file_exist(const char *fileName)
|
||||||
|
{
|
||||||
|
std::ifstream ifile(fileName, std::ios::in);
|
||||||
|
return ifile.good();
|
||||||
|
}
|
||||||
|
|
||||||
void SensorService::onChannelError(const aasdk::error::Error& e)
|
void SensorService::onChannelError(const aasdk::error::Error& e)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(error) << "[SensorService] channel error: " << e.what();
|
OPENAUTO_LOG(error) << "[SensorService] channel error: " << e.what();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user