changeset 229:79283dc7dc54 main

Add the "start" command, improve the "listen" command.
author Bob Cook <bob@bobcookdev.com>
date Sat, 12 Jul 2014 17:18:55 -0700
parents 2429999d8731
children 50414c680910
files main/robots/cantool/CanToolApp.cpp main/robots/cantool/CmdGps.cpp main/robots/cantool/CmdListen.cpp main/robots/cantool/CmdStartPgm.cpp main/robots/cantool/Commands.h main/robots/cantool/jamfile
diffstat 6 files changed, 152 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/main/robots/cantool/CanToolApp.cpp	Mon Jul 07 18:59:11 2014 -0700
+++ b/main/robots/cantool/CanToolApp.cpp	Sat Jul 12 17:18:55 2014 -0700
@@ -7,7 +7,7 @@
 //
 //  Application object implementation for demonstrating the CANSocket class.    
 //
-//  Copyright (c) 2011-2013 Bob Cook
+//  Copyright (c) 2011-2014 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
@@ -72,9 +72,10 @@
     m_commandDispatchTable[ "estop" ] = CommandEStop;
     m_commandDispatchTable[ "gps" ] = CommandGps;
     m_commandDispatchTable[ "listen" ] = CommandListen;
+    m_commandDispatchTable[ "sonarfront" ] = CommandSonarFront;
     m_commandDispatchTable[ "speed" ] = CommandSpeed;
+    m_commandDispatchTable[ "start" ] = CommandStartPgm;
     m_commandDispatchTable[ "steer" ] = CommandSteer;
-    m_commandDispatchTable[ "sonarfront" ] = CommandSonarFront;
 }
 
 // ----------------------------------------------------------------------------------------
--- a/main/robots/cantool/CmdGps.cpp	Mon Jul 07 18:59:11 2014 -0700
+++ b/main/robots/cantool/CmdGps.cpp	Sat Jul 12 17:18:55 2014 -0700
@@ -60,7 +60,7 @@
 {
     uint32_t msgid = can_build_message_id( can_node_sensor_gps,
                                            can_node_broadcast,
-                                           can_dataid_latitude );
+                                           can_dataid_gps_latitude );
 
     can_data_gps_data msg;
 
@@ -104,7 +104,7 @@
 {
     uint32_t msgid = can_build_message_id( can_node_sensor_gps,
                                            can_node_broadcast,
-                                           can_dataid_longitude );
+                                           can_dataid_gps_longitude );
 
     can_data_gps_data msg;
 
--- a/main/robots/cantool/CmdListen.cpp	Mon Jul 07 18:59:11 2014 -0700
+++ b/main/robots/cantool/CmdListen.cpp	Sat Jul 12 17:18:55 2014 -0700
@@ -7,7 +7,7 @@
 //
 //  Application object implementation for demonstrating the CANSocket class.    
 //
-//  Copyright (c) 2012-2013 Bob Cook
+//  Copyright (c) 2012-2014 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
@@ -66,6 +66,9 @@
         case can_node_odr_controller:
             return "odr-controller";
 
+        case can_node_odr_display:
+            return "odr-display";
+
         case can_node_odr_motion:
             return "odr-motion";
 
@@ -125,6 +128,33 @@
 
 // ----------------------------------------------------------------------------------------
 
+static void MsgStartProgram( const CANMessage* msg )
+{
+    can_data_pgm_selection info;
+    msg->msgData( reinterpret_cast< uint8_t* >( &info ), sizeof( info ) );
+
+    switch ( info.pgm_id )
+    {
+        case odr_pgm_wander:
+            std::cout << "start program wander" << std::endl;
+            break;
+
+        case odr_pgm_straight_line:
+            std::cout << "start program staight line" << std::endl;
+            break;
+
+        case odr_pgm_small_box:
+            std::cout << "start program small box" << std::endl;
+            break;
+
+        default:
+            std::cout << "start program (unknown)" << std::endl;
+            break;
+    }
+}
+
+// ----------------------------------------------------------------------------------------
+
 static void MsgSonarFrontUpdate( const CANMessage* msg )
 {
     can_data_sonar_front info;
@@ -183,12 +213,12 @@
                 std::cout << "heartbeat from " << NodeName( srcNode ) << std::endl;
                 break;
 
-            case can_dataid_latitude:
+            case can_dataid_gps_latitude:
                 MsgGpsLatitude( msg );
                 std::cout << "message: " << CANMessage::asText( msg ) << std::endl;
                 break;
 
-            case can_dataid_longitude:
+            case can_dataid_gps_longitude:
                 MsgGpsLongitude( msg );
                 std::cout << "message: " << CANMessage::asText( msg ) << std::endl;
                 break;
@@ -197,6 +227,10 @@
                 MsgGpsFix( msg );
                 break;
 
+            case can_dataid_odr_start_pgm:
+                MsgStartProgram( msg );
+                break;
+
             case can_dataid_sonar_front:
                 MsgSonarFrontUpdate( msg );
                 break;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/robots/cantool/CmdStartPgm.cpp	Sat Jul 12 17:18:55 2014 -0700
@@ -0,0 +1,106 @@
+// ----------------------------------------------------------------------------------------
+//
+//  robots/cantool/CmdStartPgm.cpp
+//    
+//  Bob Cook Development, Robotics Library
+//  http://www.bobcookdev.com/rl/
+//
+//  Command "start" implementation.
+//
+//  Copyright (c) 2014 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 <Poco/Exception.h>
+#include <Poco/NumberFormatter.h>
+#include <Poco/NumberParser.h>
+
+#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: start <program>" << std::endl;
+    std::cerr << "       where \"program\" may be one of:" << std::endl;
+    std::cerr << "              wander" << std::endl;
+    std::cerr << "              line" << std::endl;
+    std::cerr << "              smbox" << std::endl;
+}
+
+// ----------------------------------------------------------------------------------------
+
+void CommandStartPgm( const std::vector< std::string >& args )
+{
+    if ( args.size() != 2 )
+    {
+        PrintHelp();
+        return;
+    }
+
+    uint32_t msgid = can_build_message_id( can_node_odr_manager,
+                                           can_node_odr_display,
+                                           can_dataid_odr_start_pgm );
+    can_data_pgm_selection msg;
+
+    try
+    {
+        if ( args[ 1 ] == "wander" )
+        {
+            msg.pgm_id = odr_pgm_wander;
+        }
+        else if ( args[ 1 ] == "line" )
+        {
+            msg.pgm_id = odr_pgm_straight_line;
+        }
+        else if ( args[ 1 ] == "smbox" )
+        {
+            msg.pgm_id = odr_pgm_small_box;
+        }
+        else
+        {
+            throw Poco::SyntaxException( "unrecognized program name", 1 );
+        }
+
+    }
+    catch ( const Poco::SyntaxException& ex )
+    {
+        PrintHelp();
+        return;
+    }
+
+    CANMessage::QueueToSend(
+        new CANMessage( msgid, reinterpret_cast< uint8_t* >( &msg ), sizeof( msg ) ) );
+
+    std::cout << "sent start cmd " << args[ 1 ] << std::endl;
+}
+
+// ----------------------------------------------------------------------------------------
+
--- a/main/robots/cantool/Commands.h	Mon Jul 07 18:59:11 2014 -0700
+++ b/main/robots/cantool/Commands.h	Sat Jul 12 17:18:55 2014 -0700
@@ -7,7 +7,7 @@
 //
 //  Command function prototypes.
 //
-//  Copyright (c) 2011 Bob Cook
+//  Copyright (c) 2011-2014 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,5 +45,7 @@
 
 void CommandGps( const std::vector< std::string >& args );
 
+void CommandStartPgm( const std::vector< std::string >& args );
+
 // ----------------------------------------------------------------------------------------
 
--- a/main/robots/cantool/jamfile	Mon Jul 07 18:59:11 2014 -0700
+++ b/main/robots/cantool/jamfile	Sat Jul 12 17:18:55 2014 -0700
@@ -38,6 +38,7 @@
     main.cpp
     CanToolApp.cpp
     CmdEStop.cpp CmdGps.cpp CmdListen.cpp CmdSpeed.cpp CmdSonarFront.cpp CmdSteer.cpp
+    CmdStartPgm.cpp
     packages.common.can.pkg
     packages.linux.can.pkg
     ;