changeset 174:7bfb98e62138 main

Merge from upstream.
author Bob Cook <bob@bobcookdev.com>
date Wed, 06 Feb 2013 21:46:34 -0800
parents ac37f2690f0b (current diff) 11b03779b561 (diff)
children f7a234e8e089 070201175cc6
files
diffstat 4 files changed, 123 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/main/robots/cantool/CanToolApp.cpp	Wed Feb 06 21:45:48 2013 -0800
+++ b/main/robots/cantool/CanToolApp.cpp	Wed Feb 06 21:46:34 2013 -0800
@@ -7,7 +7,7 @@
 //
 //  Application object implementation for demonstrating the CANSocket class.    
 //
-//  Copyright (c) 2011 Bob Cook
+//  Copyright (c) 2011-2013 Bob Cook
 //
 //  Permission is hereby granted, free of charge, to any person obtaining a copy
 //  of this software and associated documentation files (the "Software"), to deal
@@ -45,32 +45,10 @@
 #include "CanToolApp.h"
 #include "Commands.h"
 
-#include "packages/common/can/can_helpers.h"
-
-#include "packages/linux/can/CANMessage.h"
 #include "packages/linux/can/CANMsgProcessor.h"
 
 // ----------------------------------------------------------------------------------------
 
-void CommandListen( const std::vector< std::string >& args )
-{
-    std::cout << "listening:" << std::endl;
-
-    for ( ;; )
-    {
-        CANMessage* msg = CANMessage::WaitDequeueReceived( 250 ); // 250 ms
-
-        if ( msg == 0 )
-        {
-            continue;
-        }
-
-        std::cout << "received: " << CANMessage::asText( msg ) << std::endl;
-    }
-}
-
-// ----------------------------------------------------------------------------------------
-
 CanToolApp::CanToolApp()
     : m_helpRequested( false ),
       m_canInterfaceName( "can0" ),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/robots/cantool/CmdListen.cpp	Wed Feb 06 21:46:34 2013 -0800
@@ -0,0 +1,118 @@
+// ----------------------------------------------------------------------------------------
+//
+//  robots/cantool/CmdListen.cpp
+//    
+//  Bob Cook Development, Robotics Library
+//  http://www.bobcookdev.com/rl/
+//
+//  Application object implementation for demonstrating the CANSocket class.    
+//
+//  Copyright (c) 2013 Bob Cook
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to deal
+//  in the Software without restriction, including without limitation the rights
+//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//  copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//  THE SOFTWARE.
+//
+// ----------------------------------------------------------------------------------------
+
+#include <iostream>
+#include <memory>
+#include <stdio.h>
+#include <string>
+#include <vector>
+
+#include "Commands.h"
+
+#include "packages/common/can/can_helpers.h"
+#include "packages/common/can/can_messages.h"
+#include "packages/common/can/can_nodes.h"
+
+#include "packages/linux/can/CANMessage.h"
+#include "packages/linux/can/CANMsgProcessor.h"
+
+// ----------------------------------------------------------------------------------------
+
+static void PrintHelp()
+{
+    std::cerr << "error: listen" << std::endl;
+    std::cerr << "       (this command takes no parameters)" << std::endl;
+}
+
+// ----------------------------------------------------------------------------------------
+
+static const char* NodeName( uint8_t node )
+{
+    switch ( node )
+    {
+        case can_node_odr_manager:
+            return "odr-manager";
+
+        case can_node_odr_motion:
+            return "odr-motion";
+
+        default:
+            return "(unknown node)";
+    }
+}
+
+// ----------------------------------------------------------------------------------------
+
+void CommandListen( const std::vector< std::string >& args )
+{
+    if ( args.size() > 1 )
+    {
+        PrintHelp();
+        return;
+    }
+
+    std::cout << "listening (q to stop):" << std::endl;
+
+    for ( ;; )
+    {
+        if ( getchar() == 'q' )
+        {
+            return;
+        }
+
+        CANMessage* msg = CANMessage::WaitDequeueReceived( 250 ); // 250 ms
+
+        if ( msg == 0 )
+        {
+            continue;
+        }
+
+        uint8_t  srcNode;
+        uint8_t  dstNode;
+        uint16_t dataId;
+
+        can_parse_message_id( msg->msgIdentifier(), &srcNode, &dstNode, &dataId );
+
+        switch ( dataId )
+        {
+            case can_dataid_heartbeat:
+                std::cout << "heartbeat from " << NodeName( srcNode ) << std::endl;
+                break;
+
+            default:
+                std::cout << "message: " << CANMessage::asText( msg ) << std::endl;
+                break;
+        }
+    }
+}
+
+// ----------------------------------------------------------------------------------------
+
--- a/main/robots/cantool/CmdSonarFront.cpp	Wed Feb 06 21:45:48 2013 -0800
+++ b/main/robots/cantool/CmdSonarFront.cpp	Wed Feb 06 21:46:34 2013 -0800
@@ -7,7 +7,7 @@
 //
 //  Command "sonarfront" implementation.
 //
-//  Copyright (c) 2011 Bob Cook
+//  Copyright (c) 2011-2013 Bob Cook
 //
 //  Permission is hereby granted, free of charge, to any person obtaining a copy
 //  of this software and associated documentation files (the "Software"), to deal
@@ -46,14 +46,10 @@
 {
     if ( args.size() < 2 )
     {
-        std::cout << "error: sonarfront <on|off>" << std::endl;
+        std::cerr << "error: sonarfront <on|off>" << std::endl;
         return;
     }
 
-    if ( args[ 1 ] != "on" && args[ 1 ] != "off" )
-    {
-    }
-
     uint32_t msgid;
 
     if ( args[ 1 ] == "on" )
@@ -70,7 +66,7 @@
     }
     else
     {
-        std::cout << "error: sonarfront <on|off>" << std::endl;
+        std::cerr << "error: sonarfront <on|off>" << std::endl;
         return;
     }
 
--- a/main/robots/cantool/jamfile	Wed Feb 06 21:45:48 2013 -0800
+++ b/main/robots/cantool/jamfile	Wed Feb 06 21:46:34 2013 -0800
@@ -37,7 +37,7 @@
 COMMON_SOURCES = 
     main.cpp
     CanToolApp.cpp
-    CmdMotors.cpp CmdSonarFront.cpp
+    CmdListen.cpp CmdMotors.cpp CmdSonarFront.cpp
     packages.common.can.pkg
     packages.linux.can.pkg
     ;