changeset 129:336ea92dbee9 main

Include support for the front-facing sonar package.
author Bob Cook <bob@bobcookdev.com>
date Tue, 27 Dec 2011 11:46:22 -0800
parents 44140fb96102
children 97148838cfce
files main/robots/odr/Scoreboard.cpp main/robots/odr/Scoreboard.h
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/main/robots/odr/Scoreboard.cpp	Thu Dec 15 10:04:56 2011 -0800
+++ b/main/robots/odr/Scoreboard.cpp	Tue Dec 27 11:46:22 2011 -0800
@@ -51,6 +51,7 @@
 bool         Scoreboard::sm_isButtonOneDown;
 bool         Scoreboard::sm_isButtonTwoDown;
 bool         Scoreboard::sm_isSonarFrontAlive;
+bool         Scoreboard::sm_isSonarFrontEnabled;
 uint16_t     Scoreboard::sm_sonarFrontLeft;
 uint16_t     Scoreboard::sm_sonarFrontCenter;
 uint16_t     Scoreboard::sm_sonarFrontRight;
@@ -117,6 +118,14 @@
 
 // ----------------------------------------------------------------------------------------
 
+bool Scoreboard::isSonarFrontEnabled()
+{
+    Poco::RWLock::ScopedReadLock lock( sm_rwLock );
+    return sm_isSonarFrontEnabled;
+}
+
+// ----------------------------------------------------------------------------------------
+
 void Scoreboard::setSonarFrontEnabled()
 {
     uint32_t msgid = can_build_message_id( can_node_odr_manager,
@@ -273,6 +282,16 @@
 
 // ----------------------------------------------------------------------------------------
 
+void Scoreboard::recvSonarFrontStatus( bool enabled )
+{
+    Poco::RWLock::ScopedWriteLock lock( sm_rwLock );
+
+    sm_isSonarFrontAlive = true;
+    sm_isSonarFrontEnabled = enabled;
+}
+
+// ----------------------------------------------------------------------------------------
+
 void Scoreboard::run()
 {
     Poco::Logger& log = Poco::Logger::get( m_loggerName );
@@ -308,8 +327,6 @@
                 switch ( dataId )
                 {
                     case can_dataid_heartbeat:
-                    case can_dataid_sonar_front_state_enabled:
-                    case can_dataid_sonar_front_state_disabled:
                         recvHeartbeat( srcNode );
                         break;
 
@@ -320,6 +337,14 @@
                     case can_dataid_odrctl_button:
                         recvButtonUpdate( msg );
                         break;
+
+                    case can_dataid_sonar_front_state_enabled:
+                        recvSonarFrontStatus( true /* enabled */ );
+                        break;
+
+                    case can_dataid_sonar_front_state_disabled:
+                        recvSonarFrontStatus( false /* not enabled */ );
+                        break;
                 }
             }
         }
--- a/main/robots/odr/Scoreboard.h	Thu Dec 15 10:04:56 2011 -0800
+++ b/main/robots/odr/Scoreboard.h	Tue Dec 27 11:46:22 2011 -0800
@@ -55,6 +55,7 @@
 
         // odr-sonar-front
         static bool     isSonarFrontAlive();
+        static bool     isSonarFrontEnabled();
         static void     setSonarFrontEnabled();
         static void     setSonarFrontDisabled();
         static uint16_t sonarFrontLeft();
@@ -74,6 +75,7 @@
         static bool         sm_isButtonOneDown;
         static bool         sm_isButtonTwoDown;
         static bool         sm_isSonarFrontAlive;
+        static bool         sm_isSonarFrontEnabled;
         static uint16_t     sm_sonarFrontLeft;
         static uint16_t     sm_sonarFrontCenter;
         static uint16_t     sm_sonarFrontRight;
@@ -92,6 +94,7 @@
         void recvHeartbeat( uint8_t srcNode );
         void recvControllerUpdate( CANMessage* msg );
         void recvButtonUpdate( CANMessage* msg );
+        void recvSonarFrontStatus( bool enabled );
 };
 
 // ----------------------------------------------------------------------------------------