TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: All
from: Kurt Kuzba
date: 2004-02-22 06:44:58
subject: [C] way out ?

From: "Kurt Kuzba" 


From: prabir senapati
PS>  i am having some 200 'C' API's for a device driver of an
PS>  embeddedproduct.  now i wanna develop a CLI from where i
PS>  wud invoke each API for corresponding task. This can be
PS>  done in ways----  i write a program where i tokenize the
PS>  command line and do checking and call proper API(s), but
PS>  each API is different in work and its argument list.
PS>  So i will hv to write 200 such small funcs for calling
PS>  200 diff APIs, right; or else i write a common parse and
PS>  write 200 small programs for each command...
PS>  Hell lot of others....
PS>  How to do this kind of stuff, pls throw some light...

    I don't know if I can help much.  This is pretty complex for
 a hobbyist such as myself.  I suppose it really boils down to
 whether you are developing a user interface or an automated
 system interface for your embedded device.  If system memory and
 program access speed are not issues, then the whole ball of device
 functions may be rolled into a single app, callable from a switch
 list and directed by the first argument or a specified switch such
 as /f to denote function.
 widget /f calibrate 0 0 -15
 This example calls widget.exe and instructs the widget controller
 to recalibrate 15 units lower along the z axis.  Your user CLI
 might present the user with a menu list, on which calibrate could
 be one item.  When calibrate was selected, it would present the
 user with three inputs, with allowable ranges for each, and then
 call widget.exe, supplying the proper arguments.  The API call
 would be more like
 Func_calibrate(0, 0, -15);
 Another switch could select another area of control functions,
 such as process operations.
 widget /o dump a datalog.txt
 This example would call widget.exe and instruct it to perform an
 operation, a data dump, to the datalog.txt file, using append.
 The corresponding API call to an already dynamically linked API
 would be something like;
 Ops_dump('a', "datalog.txt");
 In any case, the user interface is the focal point of your query.
 A menuing system would work well, and one could break the set of
 command functions into a manageable number of logical areas, which
 could then be presented as text menu options, or as GUI options,
 depending on the type of command interface available.  If there is
 only a rudimentary interface, every possible action may be
 programmed into the interface for simple selection where detailed
 input from the user can not be allowed, with selections being made
 from available menus.  A simple example:

/*_|_|  threekey.c  PUBLIC DOMAIN by Kurt Kuzba - (02/22/2004)
_|_|_|  C code module to demonstrate very simple user interface. _|_|_| 
Code is supplied AS IS.  No warrantees or guarantees _|_|_|  are given or
implied as to usability or appropriateness. _|_|*/

#include 
#include 
int threekey_input(int a, int b, int c) {
   int keypress = 0;
   do {
      keypress=getch();
      if(keypress == a || keypress == b || keypress == c) break;
   } while(1);
   return keypress;
}
int setvars(char* tag, int max, int min, int set) {
   int key;
   puts("\nUse the [1] key to decrease value.");
   puts("Use the [2] key to increase value.");
   puts("Use the [ENTER] key to use value.");
   do{
      printf("\r%s = [%3d]", tag, set);
      key = threekey_input('1', '2', '\r');
      if(key == '\r') break;
      if(key == '1'){
         set--;
         if(set < min)
            set = max;
      }
      if(key == '2'){
         set++;
         if(set > max)
            set = min;
      }
   } while(1);
   return set;
}
int main(void)
{
   int vert = -30, pan = 0, zoom = 0;
   char syscmd[128];
   puts("\n\nSet external camera vertical angle.");
   vert = setvars("vertical angle", 3, -45, vert);
   puts("\n\nSet external camera pan angle.");
   pan = setvars("pan angle", 45, -45, pan);
   puts("\n\nSet external camera zoom value.");
   zoom = setvars("zoom value", 16, 0, zoom);
   printf("\n\nYour camera is set to a vertical"
      " angle of %d degrees.", vert);
   printf("\nYour camera is set to a pan angle"
      " of %d degrees.", pan);
   printf("\nYour camera is set to a zoom value"
      " of %dX.\n", zoom);
   /*   API call for accessing dynamically linked function

   camctrl(vert, pan, zoom);
   */
   /*   system command line for calling separate executable:
   sprintf(syscmd, "camset.exe %d %d %d", vert, pan, zoom);
   system(syscmd);
        In the case of an all-in-one program with switching:
   sprintf(syscmd, "camera.exe /s %d %d %d", vert, pan, zoom);
   system(syscmd);
   */
   return 0;
}
/*_|_|  end threekey.c
_|_|*/


>  kkuzba{at}centurytel.net   http://home.centurytel.net/kkuzba
>  If he didn't laugh, it wouldn't be the Tao. (Tao Te Ching - 41)

--- BBBS/LiI v4.01 Flag-5
* Origin: Prism's_Point (1:261/38.1)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.