--- ofic.usb-robot//control.c   Mon May 29 21:12:34 2000
+++ usb-robot-0.1.3/control.c   Thu Jun 29 11:43:10 2000
@@ -12,7 +12,8 @@
 
 typedef enum
 {
-  transfer_bulk
+  transfer_bulk,
+  transfer_ctrl
 }
 transfer_type;
 
@@ -43,6 +44,7 @@
 ;
 typedef int (*command_action)( command_context* context, char*buffer );
 
+#define USB_OK 0
 
 typedef struct 
 {
@@ -118,15 +120,18 @@
   return pointer+1;
 }
 
+extern char usb_error_str[1024];
+
 static
 int
 command_set_config( command_context* context, char*buffer )
 {
   int confignumber;
+  int res;
   confignumber = read_integer( buffer );
-  if ( usb_set_configuration( context->device, confignumber) != USB_OK )
+  if ( (usb_set_configuration( context->device, confignumber)) != USB_OK )
     {
-      error( "problem setting config %d", confignumber );
+      error( "problem setting config %d (%s)", confignumber, usb_error_str );
       return -1;
     }
   return 0;
@@ -137,10 +142,11 @@
 command_claim_interface(command_context* context, char*buffer )
 {
   int interface;
+  int res;
   interface = read_integer( buffer );
-  if ( usb_claim_interface( context->device, interface ) != USB_OK )
+  if ( (usb_claim_interface( context->device, interface )) != USB_OK )
     {
-      error( "problem setting claiming interface %d", interface );
+      error( "problem setting claiming interface %d (%s)", interface, usb_error_str );
       return -1;
     }
   return 0;
@@ -216,6 +222,8 @@
     {
     case 'b': *ttype = transfer_bulk;
       break;
+    case 'c': *ttype = transfer_ctrl;
+      break;
     default:
       return -1;
     }
@@ -231,13 +239,14 @@
   long timeout = 10000;
   // if it hasn't happened after 10 seconds it probably won't ever
   
-  long size = -1;
+  long size = 0;
   long read;
   long ep = -1;
   direction dir = dir_out;
   char* data;
   int return_value = 0;
   transfer_type ttype = transfer_bulk;
+  int requesttype = 0, request = 0, value = 0, index = 0;
   
   const parameter parameters[] = 
   {
@@ -257,19 +266,31 @@
       "type", param_transfer_type, &ttype 
     },
     {
+      "requesttype", param_int, &requesttype 
+    },
+    {
+      "request", param_int, &request 
+    },
+    {
+      "value", param_int, &value 
+    },
+    {
+      "index", param_int, &index 
+    },
+    {
       0,0,0
     }
   }
   ;
   parameter const* param;
-  char const* value;
+  char const* val;
   
   for( param = parameters; param->name; param++ )
     {
-      value = read_param(param->name, buffer);
-      if ( value )
+      val = read_param(param->name, buffer);
+      if ( val )
        {
-         if( param->action( value, param->value ) )
+         if( param->action( val, param->value ) )
            {
              fprintf( context->out, "USERERROR: bad value for parameter %s\n",
                       param->name );
@@ -278,28 +299,15 @@
        }
     }
   
-  if ( ep == -1 )
-    {
-      fprintf( context->out, "USERERROR: no value for ep given\n" );
-      return -2;
-    }
-  if ( size == -1 )
-    {
-      fprintf( context->out, "USERERROR: no value for size given\n" );
-      return -2;
-    }
-  
-  
   switch(dir)
     {
     case dir_in: assert( data = malloc( size ) );break;
-      
     case dir_out: data = read_binary( context->in, size );break;
-      
     default: cant_get_here();
     }
 
-  message( "doing bulk transfer id %d %s ep 0x%x, size %d, timeout %d frames",
+  message( "doing %d transfer id %d %s ep 0x%x, size %d, timeout %d frames",
+          ttype,
           (int)context->id,
           direction_to_string[dir],
           (int)ep,
@@ -308,16 +316,32 @@
       
   switch(ttype)
     {
+    case transfer_ctrl:
+      if (dir!=dir_out)
+       abort();
+      if (usb_control_msg(context->device, requesttype, request, value, index, data, 
+size, timeout)) {
+       error( "problem doing control msg (%s)", usb_error_str);
+       return_value = -1;
+       break;
+      }
+      return_value = 0;
+      break;
+ 
     case transfer_bulk:
+      if ( ep == -1 )
+       {
+         fprintf( context->out, "USERERROR: no value for ep given\n" );
+         return -2;
+       }
       switch(dir)
        {
        case dir_in:
          if ( (read = usb_bulk_read(context->device, ep, data, size, timeout)) != 
size )
            {
              if ( read > 0 )
-               error( "problem doing read; only %d read from %d", (int)read, 
(int)size );
+               error( "problem doing read; only %d read from %d (%s)", (int)read, 
+(int)size, usb_error_str );
              else
-               error( "problem doing read" );
+               error( "problem doing read (%s)", usb_error_str );
              
              return_value = -1;
              break;
@@ -333,7 +357,7 @@
        case dir_out:
          if ( usb_bulk_write(context->device, ep, data, size, timeout) != USB_OK )
            {
-             error( "problem doing write" );
+             error( "problem doing write (%s)", usb_error_str );
              return_value = -1;
            }
          else
@@ -351,6 +375,19 @@
   return return_value;
 }
 
+static
+int
+command_help( command_context* context, char*buffer )
+{
+  printf( " \
+config [configuration number]\n\
+interface [interface]\n\
+transfer type=b size=[bytes] ep=[endpoint number] dir=[in,out] timeout=[frames]\n\
+abort -- go and try another device with same ids\n\
+quit\n\
+help\n" );
+  return 0;
+}
 
 static
 int
@@ -374,6 +411,9 @@
     },
     {
       "abort", command_abort
+    },
+    {
+      "help", command_help
     },
     {
       "quit", command_quit
--- ofic.usb-robot//README      Fri Apr 14 17:48:50 2000
+++ usb-robot-0.1.3/README      Thu Jun 29 10:42:18 2000
@@ -61,5 +61,6 @@
 transfer type=b size=[bytes] ep=[endpoint number] dir=[in,out] timeout=[frames]
 abort -- go and try another device with same ids
 quit
+help
 
 only the first letter of the command is significant.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to