Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

cmd_mobile.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: cmd_mobile.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.10 $      $Date: 2019/01/17 21:21:03 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Text commands for control of Mobile/SpaceNavigator/Magellan
00019  *   and similar 6DOF input devices.
00020  ***************************************************************************/
00021 
00022 #include <stdlib.h>
00023 #include <tcl.h>
00024 #include "config.h"
00025 #include "VMDApp.h"
00026 #include "MobileInterface.h"
00027 #include "utilities.h"
00028 
00029 // print usage message
00030 static void mobile_usage(Tcl_Interp *interp) {
00031   Tcl_AppendResult(interp, "mobile usage:\n",
00032       "mobile mode <mode>\n",
00033       "   modes: off, move, animate, tracker, user\n",
00034       "mobile port <incoming network port number>\n",
00035       "mobile get <mode/port/clientList/APIsupported>\n",
00036       "mobile set activeClient {name} {ip}\n",
00037       "mobile sendMsg {name} {ip} msgType {msg}\n",
00038 //      "mobile sensitivity <sensitivity>\n",
00039 //      "mobile nullregion <nullregion>\n",
00040       NULL);
00041 }
00042 
00043 int text_cmd_mobile(ClientData cd, Tcl_Interp *interp, int argc,
00044                             const char *argv[]) {
00045 
00046   VMDApp *app = (VMDApp *)cd;
00047 
00048   if (argc < 3 || argc > 6) {
00049     // if here, something went wrong, so return an error message
00050     mobile_usage(interp);
00051     return TCL_ERROR;
00052   }
00053 
00054   if (!strupncmp(argv[1], "mode", CMDLEN)) {
00055     int m1 = Mobile::OFF;
00056     // see if these are string values
00057     if (!strupncmp(argv[2], "off", CMDLEN))          m1 = Mobile::OFF;
00058     else if (!strupncmp(argv[2], "move", CMDLEN))    m1 = Mobile::MOVE;
00059     else if (!strupncmp(argv[2], "animate", CMDLEN)) m1 = Mobile::ANIMATE;
00060     else if (!strupncmp(argv[2], "tracker", CMDLEN)) m1 = Mobile::TRACKER;
00061     else if (!strupncmp(argv[2], "user", CMDLEN))    m1 = Mobile::USER;
00062     else mobile_usage(interp); // error 
00063 
00064     if (!app->mobile_set_mode(m1)) {
00065       Tcl_AppendResult(interp, "Unable to set Mobile mode to ",
00066           argv[2], argc > 3 ? argv[3] : NULL, NULL);
00067 
00068       // if here, something went wrong, so return an error message
00069       mobile_usage(interp);
00070       return TCL_ERROR;
00071     }
00072   } else if(!strupncmp(argv[1], "port", CMDLEN)) {
00073     int port;
00074     if (sscanf(argv[2], "%d", &port) == 1) {
00075       if (!app->mobile_network_port(port)) {
00076         // if here, something went wrong, so return an error message
00077         mobile_usage(interp);
00078         return TCL_ERROR;
00079       }
00080     } else {
00081       // if here, something went wrong, so return an error message
00082       mobile_usage(interp);
00083       return TCL_ERROR;
00084     }
00085   } else if(!strupncmp(argv[1], "get", CMDLEN)) {
00086     if (!strupncmp(argv[2], "mode", CMDLEN))          
00087     {
00088        Tcl_AppendResult(interp, Mobile::get_mode_str((Mobile::MoveMode)app->mobile_get_mode()), NULL);
00089     } else if (!strupncmp(argv[2], "clientList", CMDLEN)) {
00090        ResizeArray <JString *>* ip;
00091        ResizeArray <JString *>* nick;
00092        ResizeArray <bool>* active;
00093        app->mobile_get_client_list( nick, ip, active);
00094        for (int i=0; i<nick->num(); i++)
00095        {
00096           Tcl_AppendResult(interp, " {", NULL);
00097 
00098           Tcl_AppendResult(interp, " {", NULL);
00099           // here's what we've got..
00100           //   (const char *)(*(*nick)[i])
00101           //      now to explain it....
00102           //   (const char *)               Tcl_AppendResult needs a char*
00103           //                 (*          )  We have a JString* in ResizeArray that we want to be a JString   
00104           //                   (*nick)      we have a ResizeArray ptr that we want to be a ResizeArray
00105           //                          [i]   specific array elem
00106           Tcl_AppendResult(interp, (const char *)(*(*nick)[i]), NULL);
00107           Tcl_AppendResult(interp, "}", NULL);
00108 
00109           Tcl_AppendResult(interp, " {", NULL);
00110           Tcl_AppendResult(interp, (const char *)(*(*ip)[i]), NULL);
00111           Tcl_AppendResult(interp, "}", NULL);
00112 
00113           Tcl_AppendResult(interp, " {", NULL);
00114           char tmp[10]; sprintf(tmp, "%d", (*active)[i]);
00115           Tcl_AppendResult(interp, tmp, NULL);
00116           Tcl_AppendResult(interp, "}", NULL);
00117 
00118           Tcl_AppendResult(interp, " }", NULL);
00119        }
00120 
00121     } else if (!strupncmp(argv[2], "port", CMDLEN)) {
00122        char tmpstr[20];
00123        sprintf(tmpstr, "%d", app->mobile_get_network_port());
00124        Tcl_AppendResult(interp, tmpstr, NULL);
00125     } else if (!strupncmp(argv[2], "APIsupported", CMDLEN)) {
00126        char tmpstr[20];
00127        sprintf(tmpstr, "%d", app->mobile_get_APIsupported());
00128        Tcl_AppendResult(interp, tmpstr, NULL);
00129     } else mobile_usage(interp); // error 
00130 
00131   } else if(!strupncmp(argv[1], "sendMsg", CMDLEN)) {
00132     if (argc >= 6)
00133     {
00134        if (!app->mobile_sendMsg(argv[2], argv[3], argv[4], argv[5])) {
00135 
00136             // if here, something went wrong, so return an error message
00137          mobile_usage(interp);
00138          return TCL_ERROR;
00139        }
00140     } else mobile_usage(interp); // error 
00141 
00142   } else if(!strupncmp(argv[1], "set", CMDLEN)) {
00143     if (!strupncmp(argv[2], "activeClient", CMDLEN))          
00144     {
00145        if (argc >= 5)
00146        {
00147           if (!app->mobile_set_activeClient(argv[3], argv[4])) {
00148 //         Tcl_AppendResult(interp, "Unable to set activeClient to ",
00149 //             argv[2], argc > 3 ? argv[3] : NULL, NULL);
00150 
00151             // if here, something went wrong, so return an error message
00152             mobile_usage(interp);
00153             return TCL_ERROR;
00154           }
00155        } else mobile_usage(interp); // error 
00156 
00157     } else mobile_usage(interp); // error 
00158 
00159   } else {
00160     // if here, something went wrong, so return an error message
00161     mobile_usage(interp);
00162     return TCL_ERROR;
00163   }
00164   
00165   // if here, everything worked out ok
00166   return TCL_OK;
00167 }
00168 

Generated on Thu Mar 28 02:42:36 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002