77InstrumentCluster::InstrumentCluster (QObject* parent)
88 : QObject(parent), m_speed(0 ), percentage(0 ), autonomy(0 ), gear(0 )
99{
10+ std::cout << " Using default configuration." << std::endl;
1011 auto config = zenoh::Config::create_default ();
1112 session = std::make_unique<zenoh::Session>(
1213 zenoh::Session::open (std::move (config)));
@@ -17,8 +18,8 @@ InstrumentCluster::InstrumentCluster(const std::string& configFile,
1718 QObject* parent)
1819 : QObject(parent), m_speed(0 ), percentage(0 ), autonomy(0 ), gear(0 )
1920{
20-
21- auto config = zenoh::Config::create_default ( );
21+ std::cout << " Using configuration file: " << configFile << std::endl;
22+ auto config = zenoh::Config::from_file (configFile );
2223 session = std::make_unique<zenoh::Session>(zenoh::Session::open (std::move (config)));
2324 this ->setupSubscriptions ();
2425}
@@ -161,12 +162,42 @@ void InstrumentCluster::setupSubscriptions()
161162 parseObjectData (objectData);
162163 },
163164 zenoh::closures::none));
164- warningCode_subscriber.emplace (session->declare_subscriber (
165- " Vehicle/1/Scene/Warning" ,
165+ obstacleWarning_subscriber.emplace (session->declare_subscriber (
166+ " Vehicle/1/ADAS/ObstacleDetection/Warning" ,
167+ [this ](const zenoh::Sample& sample) {
168+ std::cout << " Recebido obstacleWarning: " << sample.get_payload ().as_string () << std::endl;
169+ setWarningCode (1 );
170+ },
171+ zenoh::closures::none));
172+ laneDeparture_subscriber.emplace (session->declare_subscriber (
173+ " Vehicle/1/ADAS/LaneDeparture/Detected" ,
174+ [this ](const zenoh::Sample& sample) {
175+ bool isDeparting = std::stoi (sample.get_payload ().as_string ());
176+ if (isDeparting) {
177+ setWarningCode (2 );
178+ }
179+ setLaneDeparture (isDeparting);
180+ },
181+ zenoh::closures::none));
182+ sae0_subscriber.emplace (session->declare_subscriber (
183+ " Vehicle/1/ADAS/ActiveAutonomyLevel/SAE_0" ,
184+ [this ](const zenoh::Sample& sample) {
185+ std::cout << " Recebido SAE 0" << std::endl;
186+ setAutonomyLevel (0 );
187+ },
188+ zenoh::closures::none));
189+ sae1_subscriber.emplace (session->declare_subscriber (
190+ " Vehicle/1/ADAS/ActiveAutonomyLevel/SAE_1" ,
191+ [this ](const zenoh::Sample& sample) {
192+ std::cout << " Recebido SAE 1" << std::endl;
193+ setAutonomyLevel (1 );
194+ },
195+ zenoh::closures::none));
196+ sae5_subscriber.emplace (session->declare_subscriber (
197+ " Vehicle/1/ADAS/ActiveAutonomyLevel/SAE_5" ,
166198 [this ](const zenoh::Sample& sample) {
167- std::string warningCode = sample.get_payload ().as_string ();
168- std::cout << " Recebido warningCode: " << warningCode << std::endl;
169- setWarningCode (std::stoi (warningCode));
199+ std::cout << " Recebido SAE 5" << std::endl;
200+ setAutonomyLevel (5 );
170201 },
171202 zenoh::closures::none));
172203}
@@ -259,10 +290,20 @@ int InstrumentCluster::getWarningCode() const {
259290void InstrumentCluster::setWarningCode (int code) {
260291 if (this ->warningCode != code) {
261292 this ->warningCode = code;
262- emit warningCodeChanged (code);
263293 }
294+ emit warningCodeChanged (code);
295+ }
296+
297+ bool InstrumentCluster::getLaneDeparture () const {
298+ return this ->laneDeparture ;
264299}
265300
301+ void InstrumentCluster::setLaneDeparture (bool state) {
302+ if (this ->laneDeparture != state) {
303+ this ->laneDeparture = state;
304+ emit laneDepartureChanged (state);
305+ }
306+ }
266307
267308bool InstrumentCluster::getRightBlinker () const
268309{
@@ -415,6 +456,18 @@ QVariantMap InstrumentCluster::getRightLaneCoefs() const {
415456 return m_rightLaneCoefs;
416457}
417458
459+ int InstrumentCluster::getAutonomyLevel () const {
460+ return autonomyLevel;
461+ }
462+
463+ void InstrumentCluster::setAutonomyLevel (int level) {
464+ if (autonomyLevel != level) {
465+ autonomyLevel = level;
466+ std::cout << " Autonomy level updated: " << autonomyLevel << std::endl;
467+ emit autonomyLevelChanged (level);
468+ }
469+ }
470+
418471void InstrumentCluster::setLeftLaneCoefs (const QVariantMap& coefs) {
419472 std::cout << " Coefficients updated: " << std::endl;
420473 if (m_leftLaneCoefs != coefs) {
0 commit comments