







                                     Kinemation 3.0

                             Motion Capture Server Library

                                    Reference Manual

                                      _V_e_r_s_i_o_n _1_._0



              This  manual  is  designed  to help you write motion capture
              servers for use with Kinemation 3.0.  This manual  the  ver-
              sion  of  the library as it is released with Kinemation 3.0.
              Enhancements may be made in the future but the functionality
              described here will be maintained as much as possible.

              _D_e_s_i_g_n _P_h_i_l_o_s_o_p_h_y

              The   motion  capture  server  library  (lliibbccaappsseerrvveerr..aa)  is
              designed to allow the server process maximum flexibility  in
              dealing  with  the  motion capture hardware while hiding the
              details of the communication between the server and  Kinema-
              tion.   This  manual  describes  the  library and gives some
              hints for writing motion capture servers.

              _T_h_e _B_i_g _P_i_c_t_u_r_e

              Motion capture servers are separate processes that  communi-
              cate  with  Kinemation  via  sockets.   Because  sockets are
              largely network transparent, the server can  be  running  on
              the same machine as Kinemation or a different machine.  This
              allows the server machine to be dedicated  to  handling  the
              input  from  the  motion  capture  hardware while the client
              machine runs Kinemation.

              A motion capture server will create a number of named  chan-
              nels.  Each channel is an independent data stream that has a
              type and a usage.  Magnetic sensors, such as  the  Flock  of
              Birds or the Fastrak, each return a position and an orienta-
              tion.  Angular sensors in an armature may  return  a  single
              angle.   A  channel 6d channel could be created for the mag-
              netic sensor and a 1d channel for the armature sensor.

              The server library exists to handle the communications  pro-
              tocol between the server and Kinemation.  The library parses
              the messages on the  socket,  handles  error  messages,  and
              deals  with byte ordering problems.  The library also encap-
              sulates the message passing  protocol  so  that  it  can  be
              changed  without requiring changes to servers that have been
              built with it.





              Capture Server LibraryORcetfoebreernc3e1, 1995                     1





         The Server Library                            Server Library


         _T_h_e _S_e_r_v_e_r _L_i_b_r_a_r_y

         The server library has  about  20  user  callable  routines.
         These  routines  fall  into  four categories:  client/server
         communications, serial line  routines,  quaternion  handling
         routines,   and   general   Unix   server   routines.    The
         client/server communications routines handle the  communica-
         tions  protocol,  byte  ordering, and error messages between
         the client and server.  The serial line routines allow  sim-
         ple servers to handle devices on a serial line without know-
         ing the details of <<tteerrmmiioo..hh>>.  These routines  may  not  be
         sufficient  for  sophisticated servers serial line handling.
         The quaternion handling routines provide routines to convert
         between  Euler  angles, quaternions, and matrices.  The gen-
         eral Unix server routines are used to  control  the  process
         and   to   create   and  initialize  the  sockets  used  for
         client/server communication.

         _C_l_i_e_n_t_/_S_e_r_v_e_r _C_o_m_m_u_n_i_c_a_t_i_o_n_s _R_o_u_t_i_n_e_s

         These routines are the heart of the server library.  A  good
         understanding  of  them  is essential to writing good motion
         capture servers.  The client/server communications  routines
         are:

         CCaappAAuutthhoorriizzee(())
              Return authorization information to Kinemation.

         CCaappCCrreeaatteeCChhaannnneell(())
              Define  a data channel for motion capture data from the
              server.

         CCaappDDaattaa(())
              Send the data for all channels to Kinemation.

         CCaappEErrrroorr(())
              Pass an error message from the server to Kinemation.

         CCaappGGeettAAuutthhIInnffoo(())
              If the last command was CCAAPP__CCMMDD__AAUUTTHHOORRIIZZEE then retrieve
              the  authorization  information  that was provided with
              the command.

         CCaappGGeettCCoommmmaanndd(())
              Get the next command from Kinemation.

         CCaappGGeettRReeqquueesstteeddFFrraammee(())
              Get the frame number from the  preceeding  CCAAPP__CCMMDD__DDAATTAA
              command.

         CCaappGGeettRReeqquueesstteeddTTiimmee(())
              Get   the   time   in   seconds   from  the  preceeding
              CCAAPP__CCMMDD__DDAATTAA command.




         2                     OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library         Client/Server Communications Routines


              CCaappIInnffoo(())
                   Return motion capture channel definition information to
                   Kinemation.

              CCaappIInniittiiaalliizzee(())
                   Do the initial handshake between the client and server.

              CCaappSSeettDDaattaa(())
                   Set the data for a channel.

              CCaappVVeerrssiioonn(())
                   Return server version information to Kinemation.













































              Capture Server LibraryORcetfoebreernc3e1, 1995                     3





         CCaappAAuutthhoorriizzee(())                                Server Library


         Function:
              Return authorization information to Kinemation.

         Usage:

              iinntt CCaappAAuutthhoorriizzee((iinntt cclliieenntt__ffdd,, iinntt aauutthhoorriizzeedd));;


              cclliieenntt__ffdd
                   The socket file descriptor to the client.

              aauutthhoorriizzeedd
                   A logical value indicating whether the  client  is
                   allowed to use this server or not.

         Description:
              This routine is used by the server to return a response
              to the CCAAPP__CCMMDD__AAUUTTHHOORRIIZZEE  command.   If  aauutthhoorriizzeedd  is
              zero,  the client is not authorized to use this server.
              If aauutthhoorriizzeedd is non-zero,  the  client  will  consider
              itself  authorized  to use the server and will continue
              sending commands.  There is  probably  little  use  for
              this  routine since generally the client will always be
              authorized but since these servers can live on internet
              sockets, it is better to be safe than sorry.  It is not
              a major security breach but you probably  do  not  want
              someone  from,  say,  Finland connecting to your motion
              capture server.

         Return Value:
              Returns 0 if there was no error or  -1  if  some  error
              occurred.   If  there  was an error, eerrrrnnoo is set to an
              appropriate value.
























         4                     OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                            CCaappCCrreeaatteeCChhaannnneell(())


              Function:
                   Define a data channel for motion capture data from  the
                   server.

              Usage:

                   CCaappCChhaannnneell CCaappCCrreeaatteeCChhaannnneell((cchhaarr **nnaammee,, CCaappCChhaannnneellUUssaaggee uussaaggee,,
                                      iinntt ddaattaa__ttyyppee));;


                   nnaammee The name of the channel.  The name can be up to 32
                        characters long but should not have any spaces  or
                        other strange characters in it.  This name will be
                        visible in  Kinemation  so  it  should  be  chosen
                        mnemonically.   A  name like "bird_3" is all right
                        but a name like "RWrist" is better.

                   uussaaggee This defines how the  data  for  the  channel  is
                        meant to be used.

                   ddaattaa__ttyyppee
                        This  integer  defines  how many words of data are
                        available.  The only allowed values are 1,  3,  4,
                        or 7.  They have the following meanings:

                        1    A  1 dimensional piece of data.  The value of
                             usage determines how this data can be used by
                             Kinemation.

                        3    Three  dimensional data.  Usage should always
                             be CCAAPP__UUSSAAGGEE__PPOOSSIITTIIOONN.

                        4    Four dimensional data.  This is  an  orienta-
                             tion  quaternion  and the usage should always
                             be CCAAPP__UUSSAAGGEE__OORRIIEENNTTAATTIIOONN.

                        7    Seven dimensional data.   This  is  always  a
                             position  and an orientation quaternion.  The
                             usage should be CCAAPP__UUSSAAGGEE__PPOOSS__OORRIIEENNTT.

              Description:
                   This routine defines a channel for motion capture data.
                   These  channels are named and are used by Kinemation to
                   refer to some particular data.  The data for a  channel
                   has a usage and a data type.  The usage is one of:

                                      Data
                      Usage           Type

              CCAAPP__UUSSAAGGEE__UUNNKKNNOOWWNN         1    A   single  scalar  floating  point
                                             value That can be assigned  to  any
                                             single leaf track
              CCAAPP__UUSSAAGGEE__PPOOSSIITTIIOONN        3    An (_x,_y,_z) position value




              Capture Server LibraryORcetfoebreernc3e1, 1995                     5





         CCaappCCrreeaatteeCChhaannnneell(())                            Server Library


         CCAAPP__UUSSAAGGEE__OORRIIEENNTTAATTIIOONN     4    The   data  type  is  a  quaternion
                                        passed  as  _q0+_i_q1+_j_q2+_k_q3.    (See
                                        CCaappEEuulleerr22QQuuaatt(()).)
         CCAAPP__UUSSAAGGEE__XXPPOOSS            1    A single floating point x position.
                                        It can be assigned to an xxppooss or  a
                                        ppoossiittiioonn track.
         CCAAPP__UUSSAAGGEE__YYPPOOSS            1    A single floating point y position.
         CCAAPP__UUSSAAGGEE__ZZPPOOSS            1    A single floating point z position.
         CCAAPP__UUSSAAGGEE__XXRROOTT            1    A single floating point x rotation.
         CCAAPP__UUSSAAGGEE__YYRROOTT            1    A single floating point y rotation.
         CCAAPP__UUSSAAGGEE__ZZRROOTT            1    A single floating point z rotation.
         CCAAPP__UUSSAAGGEE__XXSSCCAALLEE          1    A single floating point x scale.
         CCAAPP__UUSSAAGGEE__YYSSCCAALLEE          1    A single floating point z scale.
         CCAAPP__UUSSAAGGEE__ZZSSCCAALLEE          1    A single floating point z scale.
         CCAAPP__UUSSAAGGEE__SSCCAALLEE          1,3   If  ddaattaa__ttyyppee is 1 then the data is
                                        applied to x, y, and  z  uniformly.
                                        If  ddaattaa__ttyyppee is 3 then the data is
                                        separate x, y, and z scale  values.
         CCAAPP__UUSSAAGGEE__PPOOSS__OORRIIEENNTT      7    The  data is a position and an ori-
                                        entation such as is returned from a
                                        magnetic  sensor.   The  data is an
                                        (_x,_y,_z)  position  followed  by   a
                                        quaternion         passed        as
                                        _q0+_i_q1+_j_q2+_k_q3.


              These channels will be attached to  tracks  in  Kinema-
              tion.   Basically, if the attachment makes any sense at
              all, you can do it.  You can attach a position  channel
              for  instance  to a position track or an xpos, ypos, or
              zpos track.  You can attach an xpos channel to a  posi-
              tion  track or to an xpos track.  The individual tracks
              automatically find the appropriate piece of the channel
              data, if there is one, and use it.

         Return Value:
              The  routine returns a CCaappCChhaannnneell which is a pointer to
              a private structure.  The return  value  will  be  used
              later  in CCaappSSeettDDaattaa(()) to specify the channel for which
              the data is being set.

















         6                     OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                                     CCaappDDaattaa(())


              Function:
                   Send the data for all channels to Kinemation.

                   iinntt CCaappDDaattaa((iinntt cclliieenntt__ffdd));;


                   cclliieenntt__ffdd
                        The socket file descriptor to the client.

              Description:
                   CCaappDDaattaa(()) takes a snapshot of the data currently set in
                   the channels by CCaappSSeettDDaattaa(()) and sends it back to Kine-
                   mation.  It is used in response to a CCAAPP__CCMMDD__DDAATTAA  com-
                   mand.

              Return Value:
                   Returns  0  if  there  was no error or -1 if some error
                   occurred.  If there was an error, eerrrrnnoo is  set  to  an
                   appropriate value.






































              Capture Server LibraryORcetfoebreernc3e1, 1995                     7





         CCaappEErrrroorr(())                                    Server Library


         Function:
              Send  an  error  message  back to Kinemation to be dis-
              played.

              iinntt CCaappEErrrroorr((iinntt cclliieenntt__ffdd,, CCaappSSeevveerriittyy sseevv,, cchhaarr **ppggmm,, cchhaarr **ffmmtt,, ......));;


              cclliieenntt__ffdd
                   The socket file descriptor to the client.

              sseevv  This specifies the severity of the error  message.
                   Severity  levels  are debug, info, warning, error,
                   and fatal.  See below for details.

              ppggmm  The name of the server program.

              ffmmtt  A pprriinnttff(()) style format string for printing a mes-
                   sage.   If  ffmmtt is NNUULLLL then the system error mes-
                   sage specified by eerrrrnnoo  is  printed.   Any  addi-
                   tional  arguments needed by the format should fol-
                   low this argument.

         Description:
              They have the following meanings:

              CCAAPP__SSEEVV__DDEEBBUUGG
                   A debug message that can be safely ignored.

              CCAAPP__SSEEVV__IINNFFOO
                   An informational message such as  "Flock  recorded
                   7.2   seconds."   These  messages  can  be  safely
                   ignored.

              CCAAPP__SSEEVV__WWAARRNNIINNGG
                   Some important condition exists but the server can
                   continue.   For  example,  a missing configuration
                   file might be a warning not an error.

              CCAAPP__SSEEVV__EERRRROORR
                   An error has occured  in  the  current  operation.
                   The current operation cannot complete.

              CCAAPP__SSEEVV__FFAATTAALL
                   A  fatal  server error has occured.  The server is
                   unable to recover.
              Error and fatal messages are displayed in error dialogs
              by Kinemation.

         Return Value:
              Returns  0  if  there  was no error or -1 if some error
              occurred.  If there was an error, eerrrrnnoo is  set  to  an
              appropriate value.





         8                     OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                              CCaappGGeettAAuutthhIInnffoo(())


              Function:
                   If the last command was CCAAPP__CCMMDD__AAUUTTHHOORRIIZZEE then retrieve
                   the authorization information that  was  provided  with
                   the command.

                   iinntt CCaappGGeettAAuutthhIInnffoo((iinntt cclliieenntt__ffdd,, cchhaarr **uusseerr,, cchhaarr **hhoosstt,,
                                cchhaarr **rreeaallhhoosstt));;


                   cclliieenntt__ffdd
                        The socket file descriptor to the client.

                   uusseerr This  is  the user name _a_s _r_e_p_o_r_t_e_d _b_y _t_h_e _c_l_i_e_n_t.
                        It is not necessarily to be trusted.

                   hhoosstt This is the host name _a_s _r_e_p_o_r_t_e_d _b_y  _t_h_e  _c_l_i_e_n_t.
                        It is not necessarily to be trusted either.

                   rreeaallhhoosstt
                        This  is  the name of the host on the other end of
                        the socket.  If the name cannot be determined,  an
                        empty string is returned.

              Description:
                   It  is  assumed  that uusseerr, hhoosstt, and rreeaallhhoosstt point to
                   enough space to hold the  corresponding  string.   Cur-
                   rently  these  strings  are  no more than 64 characters
                   long.  If any of the three arguments is NNUULLLL  then  the
                   string is not set.

              Return Value:
                   Returns  0  if there was no error or -1 if the previous
                   command was not CCAAPP__CCMMDD__AAUUTTHHOORRIIZZEE.
























              Capture Server LibraryORcetfoebreernc3e1, 1995                     9





         CCaappGGeettCCoommmmaanndd(())                               Server Library


         Function:
              Get the next command from Kinemation.

              CCaappCCoommmmaanndd CCaappGGeettCCoommmmaanndd((iinntt cclliieenntt__ffdd));;


              cclliieenntt__ffdd
                   The socket file descriptor to the client.

         Description:
              This routine returns the next command from  Kinemation.
              If  there is no command pending, it blocks until a com-
              mand is sent.

         Return Value:
              Returns a command.  CCAAPP__CCMMDD__EERRRROORR will be  returned  if
              there was some error.








































         10                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                        CCaappGGeettRReeqquueesstteeddFFrraammee(())


              Function:
                   Get  the  frame number from the preceeding CCAAPP__CCMMDD__DDAATTAA
                   command.

                   iinntt CCaappGGeettRReeqquueesstteeddFFrraammee((iinntt cclliieenntt__ffdd));;


                   cclliieenntt__ffdd
                        The socket file descriptor to the client.

              Description:
                   This command returns the frame number that  was  speci-
                   fied in the previous CCAAPP__CCMMDD__DDAATTAA command.

              Return Value:
                   Returns  the frame number or -1 if the previous command
                   was not CCAAPP__CCMMDD__DDAATTAA.








































              Capture Server LibraryORcetfoebreernc3e1, 1995                    11





         CCaappGGeettRReeqquueesstteeddTTiimmee(())                         Server Library


         Function:
              Get  the  time   in   seconds   from   the   preceeding
              CCAAPP__CCMMDD__DDAATTAA command.

              ffllooaatt CCaappGGeettRReeqquueesstteeddTTiimmee((iinntt cclliieenntt__ffdd));;


              cclliieenntt__ffdd
                   The socket file descriptor to the client.

         Description:
              This command returns the time in seconds that was spec-
              ified in the previous CCAAPP__CCMMDD__DDAATTAA command.

         Return Value:
              Returns the time in seconds or  -1.0  if  the  previous
              command was not CCAAPP__CCMMDD__DDAATTAA.








































         12                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                                     CCaappIInnffoo(())


              Function:
                   Return  motion  capture  channel definitions and server
                   information to Kinemation.

                   iinntt CCaappIInnffoo((iinntt cclliieenntt__ffdd,, ffllooaatt mmiinn__rraattee,, ffllooaatt mmaaxx__rraattee,,
                            ffllooaatt ddeeff__rraattee,, ssiizzee__tt bbuuff__ssiizzee,, iinntt ddyynnaammiicc));;


                   cclliieenntt__ffdd
                        The socket file descriptor to the client.

                   mmiinn__rraattee
                        The slowest sample rate at which  the  server  can
                        record  (in  samples  per second).  For example, a
                        Flock of Birds will not record slower than 10 sam-
                        ples per second.

                   mmaaxx__rraattee
                        The  fastest  sample  rate at which the server can
                        record (in samples per second).   For  example,  a
                        Flock  of  Birds  will  not record faster than 144
                        samples per second.  If this is zero, recording is
                        not supported.

                   ddeeff__rraattee
                        The default sampling rate.  For example, the Flock
                        of Birds default rate is 100 samples per second.

                   bbuuff__ssiizzee
                        The maximum buffer size for holding recorded data.
                        If  this  is zero, then the server does not imple-
                        ment recording.  This buffer is generally  dynami-
                        cally allocated at start record time.  The special
                        value CCAAPP__UUNNLLIIMMIITTEEDD means that the buffer is  lim-
                        ited only by available memory.

                   ddyynnaammiicc
                        The  server  provides  dynamic, changing data.  If
                        the server provides dynamic data, Kinemation  will
                        query  the  server  continuously for new data.  If
                        the server/data is not  dynamic,  Kinemation  will
                        only query when the current frame changes and only
                        if it does not  have  that  frames  data  buffered
                        already.

              Description:
                   CCaappIInnffoo(())  returns  a  description  of the channels and
                   general information about  the  server  to  Kinemation.
                   All of the channels must have been created with CCaappCCrree--
                   aatteeCChhaannnneell(()) before calling CCaappIInnffoo(()) and once  it  has
                   been called, no more channels can be created.

              Return Value:
                   Returns  0  if  there  was no error or -1 if some error



              Capture Server LibraryORcetfoebreernc3e1, 1995                    13





         CCaappIInnffoo(())                                     Server Library


              occurred.  If there was an error, eerrrrnnoo is  set  to  an
              appropriate value.























































         14                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                               CCaappIInniittiiaalliizzee(())


              Function:
                   Do the initial handshake between the client and server.

                   iinntt CCaappIInniittiiaalliizzee((iinntt cclliieenntt__ffdd,, cchhaarr **nnaammee));;


                   cclliieenntt__ffdd
                        The socket file descriptor to the client.

                   nnaammee The name of the server program.  This is used only
                        for error messages.

              Description:
                   This  routine  responds to the CCAAPP__CCMMDD__IINNIITT command and
                   performs the initial handshake between the  server  and
                   Kinemation.

              Return Value:
                   Returns  0  if  there  was no error or -1 if some error
                   occurred.  If there was an error, eerrrrnnoo is  set  to  an
                   appropriate value.




































              Capture Server LibraryORcetfoebreernc3e1, 1995                    15





         CCaappSSeettDDaattaa(())                                  Server Library


         Function:
              Set the data for a channel.

              iinntt CCaappSSeettDDaattaa((CCaappCChhaannnneell cchhaannnneell,, vvooiidd **ddaattaa));;


              cchhaannnneell
                   A channel that was returned by CCaappCCrreeaatteeCChhaannnneell(()).

              ddaattaa A pointer to the data to set.  The data is assumed
                   to  be  of the correct type, that is 1, 3, 4, or 7
                   floating point values depending on the  data  type
                   of the channel.

         Description:
              This  routine  sets  the data for a specific channel to
              values that have (presumably) come from the motion cap-
              ture  hardware.   This  data  is just stored until CCaapp--
              DDaattaa(()) is called.

         Return Value:
              Returns 0 if there was no error or  -1  if  some  error
              occurred.   If  there  was an error, eerrrrnnoo is set to an
              appropriate value.

































         16                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                                  CCaappVVeerrssiioonn(())


              Function:
                   Return server version information to Kinemation.

                   iinntt CCaappVVeerrssiioonn((iinntt cclliieenntt__ffdd,, cchhaarr **sseerrvveerr__nnaammee,, cchhaarr **vveerrssiioonn,,
                                  cchhaarr **ddeessccrriippttiioonn));;


                   cclliieenntt__ffdd
                        The socket file descriptor to the client.

                   sseerrvveerr__nnaammee
                        The name of the server.  This should be short  and
                        sweet  since  it will be displayed in Kinemation's
                        Object Browser. sseerrvveerr__nnaammee will be  truncated  to
                        64 characters if it is longer than that.

                   vveerrssiioonn
                        A  short  version string.  The version string will
                        be truncated to 16 characters if it is longer than
                        that.

                   ddeessccrriippttiioonn
                        A  one-line  description of the server.  This will
                        be truncated to 256 characters  if  it  is  longer
                        than that.

              Description:
                   This  version  information is mostly for the enlighten-
                   ment of the Kinemation user.  Kinemation currently only
                   uses the server name.

              Return Value:
                   Returns  0  if  there  was no error or -1 if some error
                   occurred.  If there was an error, eerrrrnnoo is  set  to  an
                   appropriate value.






















              Capture Server LibraryORcetfoebreernc3e1, 1995                    17





         Serial Line Routines                          Server Library


         _S_e_r_i_a_l _L_i_n_e _R_o_u_t_i_n_e_s

         The  serial  line routines provide a simplified interface to
         the Unix terminal handling routines.  These routines do  not
         attempt  to  do  everything but they should be sufficient to
         hook up most hardware over a serial line.  The  serial  line
         routines are:

         CCaappSSeerriiaallOOppeenn(())
              Open  a  serial line specifying the baud rate and other
              common serial line parameters.

         CCaappSSeerriiaallRReeaadd(())
              Read data from a serial line.

         CCaappSSeerriiaallRReesseett(())
              Reset the terminal attributes of a  serial  line  to  a
              known state.

         CCaappSSeerriiaallWWrriittee(())
              Write data to a serial line.




































         18                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                               CCaappSSeerriiaallOOppeenn(())


              Function:
                   Open  a  serial line specifying the baud rate and other
                   common serial line parameters.

                   iinntt CCaappSSeerriiaallOOppeenn((cchhaarr **ttttyy,,
                               iinntt bbaauudd,,
                               iinntt ddaattaa,,
                               CCaappPPaarriittyy ppaarriittyy,,
                               iinntt ssttoopp,,
                               CCaappSSeerriiaallMMooddee mmooddee,,
                               ssttrruucctt tteerrmmiiooss **ssaavvee__aattttrr));;


                   ttttyy  The name of the tty device (e.g., ""//ddeevv//ttttyydd11"").

                   bbaauudd The baud rate.  Currently supported values are 50,
                        75,  110,  134,  150,  200,  300, 600, 1200, 1800,
                        2400, 4800, 9600, 19200, and 38400.

                   ppaarriittyy
                        The parity.   Legal  values  are  CCAAPP__PPAARRIITTYY__EEVVEENN,
                        CCAAPP__PPAARRIITTYY__OODDDD, and CCAAPP__PPAARRIITTYY__NNOONNEE.

                   ssttoopp The number of stop bits.  The value 1 is most com-
                        mon but 1 and 2 are allowed.

                   mmooddee The mmooddee  does  not  change  any  single  terminal
                        attribute but instead changes several to deal with
                        different    types     of     connections.      In
                        CCAAPP__SSEERRIIAALL__AASSCCIIII  mode,  the  tty will return com-
                        plete lines of text  and  carriage  returns  ('\r'
                        characters)     will     be     discarded.      In
                        CCAAPP__SSEERRIIAALL__BBIINNAARRYY mode, characters are returned as
                        they  become  available,  special  characters  are
                        treated as data, and reads time out after 0.2 sec-
                        onds to keep the server from hanging waiting for a
                        response  from  a  slow  or  hung  serial  device.
                        ssaavvee__aattttrr  If  ssaavvee__aattttrr is not NNUULLLL, it defines a
                        place to store  the  initial  terminal  attributes
                        before  this  routine  starts  changing them.  The
                        saved attributes can later be passed to CCaappSSeerriiaall--
                        RReesseett(())  to  restore  the  terminal  attributes to
                        their original values.  If you do not  care  about
                        the  original  attributes,  just pass ssaavvee__aattttrr as
                        NNUULLLL.

              Description:
                   CCaappSSeerriiaallOOppeenn(()) opens a serial line and sets  its  ini-
                   tial  attributes.   Even if you need more sophisticated
                   terminal handling, this routine is a good easy  way  to
                   get  the  baud  rate,  parity, and other basic terminal
                   attributes set.  You can then  set  the  rest  of  them
                   yourself with the tteerrmmiioo interface.




              Capture Server LibraryORcetfoebreernc3e1, 1995                    19





         CCaappSSeerriiaallOOppeenn(())                               Server Library


         Return Value:
              The  file  descriptor  for  the serial line, opened for
              reading and writing.   If  an  error  occurred,  -1  is
              returned and eerrrrnnoo is set appropriately.





















































         20                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                               CCaappSSeerriiaallRReeaadd(())


              Function:
                   Read data from a serial line

                   iinntt CCaappSSeerriiaallRReeaadd((iinntt ttttyy__ffdd,, vvooiidd **bbuuff,, ssiizzee__tt nnbbyytteess));;


                   ttttyy__ffddThe  file descriptor of a serial line.  (Actually
                        almost any file descriptor will work.)

                   bbuuff  A pointer to the buffer in which the  data  should
                        be  stored.   It  is assumed to be at least nnbbyytteess
                        bytes long.

                   nnbbyytteessThe size of the buffer pointed to by bbuuff.

              Description:
                   This routine is a replacement  for  rreeaadd(())  that  works
                   particularly well on serial lines that have been opened
                   in binary mode.  A normal read on such  a  serial  line
                   may  complete before all the characters have been read.
                   This routine will keep  reading  characters  until  the
                   read  times out (set to 0.2 seconds in CCaappSSeerriiaallOOppeenn(()))
                   with zero characters read or  until  nnbbyytteess  characters
                   have been read.

              Return Value:
                   There are several different possible return values.

                   If all went well, the routine will return the number of
                   bytes read which should equal nnbbyytteess.

                   If some characters  were  read  but  the  timeout  time
                   passed without any characters, the number of characters
                   read will be returned.  This will be  some  value  less
                   than nnbbyytteess.

                   If  the read timed out without returning any characters
                   0 will be returned.  This  probably  indicates  a  hung
                   device.

                   If  there was some error returned by rreeaadd(()), -1 will be
                   returned and eerrrrnnoo will be set appropriately.















              Capture Server LibraryORcetfoebreernc3e1, 1995                    21





         CCaappSSeerriiaallRReesseett(())                              Server Library


         Function:
              Reset the terminal attributes of a  serial  line  to  a
              known state.

              iinntt CCaappSSeerriiaallRReesseett((iinntt ttttyy__ffdd,, ssttrruucctt tteerrmmiiooss **aattttrr));;


              ttttyy__ffddThe  file descriptor of a serial line.  (Actually
                   almost any file descriptor will work.)

              aattttrr The value returned as ssaavvee__aattttrr  from  an  earlier
                   call to CCaappSSeerriiaallOOppeenn(()).

         Description:
              This  routine  restores the terminal line attributes to
              the values stored in aattttrr.  This would normally be  the
              value  returned  as  ssaavvee__aattttrr from CCaappSSeerriiaallOOppeenn(()) but
              could be any valid tteerrmmiiooss structure.

         Return Value:
              Returns 0 if there was no error or  -1  if  some  error
              occurred.   If  there  was an error, eerrrrnnoo is set to an
              appropriate value.


































         22                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                              CCaappSSeerriiaallWWrriittee(())


              Function:
                   Write data to a serial line.

                   iinntt CCaappSSeerriiaallWWrriittee((iinntt ttttyy__ffdd,, vvooiidd **bbuuff,, ssiizzee__tt nnbbyytteess));;


                   ttttyy__ffddThe file descriptor of a serial line.   (Actually
                        almost any file descriptor will work.)

                   bbuuff  A  pointer  to  the  buffer  in  which the data is
                        stored.  It is assumed to be at least nnbbyytteess bytes
                        long.

                   nnbbyytteessThe size of the buffer pointed to by bbuuff.

              Description:
                   This  is  the corresponding routine to CCaappSSeerriiaallRReeaadd(()).
                   There is less reason to use it since writes  to  serial
                   lines  do  not  suffer the same problems that reads do.
                   Nevertheless, it is included here for completeness.

              Return Value:
                   Returns 0 if there was no error or  -1  if  some  error
                   occurred.   If  there  was an error, eerrrrnnoo is set to an
                   appropriate value.
































              Capture Server LibraryORcetfoebreernc3e1, 1995                    23





         Quaternion Handling Routines                  Server Library


         _Q_u_a_t_e_r_n_i_o_n _H_a_n_d_l_i_n_g _R_o_u_t_i_n_e_s

         These routines are used for handling  quaternions.   Quater-
         nions are mathimatical entities that provide a way to handle
         rotations or orientations without  the  problems  associated
         with  Euler angles.  It is sort of like a simplified version
         of a matrix.  All of the routines that handle  Euler  angles
         have a rotation order parameter.  This parameter defines the
         order in which the Euler angles are processed.  If  you  are
         used  to  programming  in  SGI's GL or OpenGL then the order
         CAP_ROT_XYZ is equivalent to multiplying the  top  of  stack
         matrix  by  the  x  rotation,  the y rotation and then the z
         rotation.  For more information on quaternions, see _G_r_a_p_h_i_c_s
         _G_e_m_s  _I, _I_I, or _I_I_I, or Ken Shoemake's excelent paper in the
         1985 Siggraph proceedings.  The quaternion handling routines
         are:

         CCaappEEuulleerr22MMaattrriixx(())
              Convert a set of Euler angles to a 4x4 rotation matrix.

         CCaappEEuulleerr22QQuuaatt(())
              Convert a set of Euler angles to a quaternion.

         CCaappMMaattrriixx22EEuulleerr(())
              Convert a 4x4 rotation matrix to a set of Euler angles.

         CCaappMMaattrriixx22QQuuaatt(())
              Convert a 4x4 rotation matrix to a quaternion.

         CCaappQQuuaatt22EEuulleerr(())
              Convert a quaternion to a set of Euler angles.

         CCaappQQuuaatt22MMaattrriixx(())
              Convert a quaternion to a matrix.

         CCaappQQuuaattMMuulltt(())
              Multiply two quaternions and return the result.




















         24                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                             CCaappEEuulleerr22MMaattrriixx(())


              Function:
                   Convert Euler angles to a 4x4 rotation matrix.

                   vvooiidd CCaappEEuulleerr22MMaattrriixx((CCaappRRoottaattiioonnOOrrddeerr oorrddeerr,, ffllooaatt xx,, ffllooaatt yy,, ffllooaatt zz,,
                                  MMaattrriixx mm));;


                   oorrddeerrThe order in which the rotations are applied.

                   xx    The rotation about the x axis.

                   yy    The rotation about the y axis.

                   zz    The rotation about the z axis.

                   mm    The resulting 4x4 matrix.

              Description
                   This routine converts the Euler angles in the specified
                   order to an equivalent matrix representation.

              Return Value
                   None


































              Capture Server LibraryORcetfoebreernc3e1, 1995                    25





         CCaappEEuulleerr22QQuuaatt(())                               Server Library


         Function:
              Convert Euler angles to a quaternion.

              vvooiidd CCaappEEuulleerr22QQuuaatt((CCaappRRoottaattiioonnOOrrddeerr oorrddeerr,, ffllooaatt xx,, ffllooaatt yy,, ffllooaatt zz,,
                           CCaappQQuuaatteerrnniioonn qq));;


              oorrddeerrThe order in which the rotations are applied.

              xx    The rotation about the x axis.

              yy    The rotation about the y axis.

              zz    The rotation about the z axis.

              qq    The resulting quaternion.

         Description
              This routine converts the Euler angles in the specified
              order to an equivalent quaternion representation.

         Return Value
              None


































         26                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                             CCaappMMaattrriixx22EEuulleerr(())


              Function:
                   Convert a 4x4 rotation matrix to Euler angles.

                   vvooiidd CCaappMMaattrriixx22EEuulleerr((CCaappRRoottaattiioonnOOrrddeerr oorrddeerr,, MMaattrriixx mm,,
                                  ffllooaatt **xx,, ffllooaatt **yy,, ffllooaatt **zz))


                   oorrddeerrThe order in which the rotations are applied.

                   mm    The 4x4 rotation matrix.

                   xx    The rotation about the x axis.

                   yy    The rotation about the y axis.

                   zz    The rotation about the z axis.

              Description
                   This routine converts the rotation matrix to an equiva-
                   lent set of Euler angles when applied in the  specified
                   order.

              Return Value
                   None

































              Capture Server LibraryORcetfoebreernc3e1, 1995                    27





         CCaappMMaattrriixx22QQuuaatt(())                              Server Library


         Function:
              Convert a 4x4 rotation matrix to a quaternion.

              vvooiidd CCaappMMaattrriixx22QQuuaatt((MMaattrriixx mm,, CCaappQQuuaatteerrnniioonn qq));;


              mm    The 4x4 rotation matrix.

              qq    The resulting quaternion.

         Description
              This  routine  converts  the  4x4 rotation matrix to an
              equivalent quaternion rotation.

         Return Value
              None









































         28                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                              CCaappQQuuaattxx22EEuulleerr(())


              Function:
                   Convert a quaternion to Euler angles.

                   vvooiidd CCaappMMaattrriixx22EEuulleerr((CCaappRRoottaattiioonnOOrrddeerr oorrddeerr,, CCaappQQuuaatteerrnniioonn qq,,
                                  ffllooaatt **xx,, ffllooaatt **yy,, ffllooaatt **zz))


                   oorrddeerrThe order in which the rotations are applied.

                   qq    The input quaternion.

                   xx    The rotation about the x axis.

                   yy    The rotation about the y axis.

                   zz    The rotation about the z axis.

              Description
                   This routine converts a quaternion to an equivalent set
                   of Euler angles when applied in the specified order.

              Return Value
                   None


































              Capture Server LibraryORcetfoebreernc3e1, 1995                    29





         CCaappQQuuaatt22MMaattrriixx(())                              Server Library


         Function:
              Convert a quaternion to a 4x4 rotation matrix.

              vvooiidd CCaappQQuuaatt22MMaattrriixx((CCaappQQuuaatteerrnniioonn qq,, MMaattrriixx mm));;


              qq    The input quaternion.

              mm    The output 4x4 rotation matrix.

         Description
              This routine converts the input quaternion to an equiv-
              alent 4x4 rotation matrix.

         Return Value
              None









































         30                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                                 CCaappQQuuaattMMuulltt(())


              Function:
                   Multiply or composite two quaternions.

                   vvooiidd CCaappQQuuaattMMuulltt((CCaappQQuuaatteerrnniioonn qq11,, CCaappQQuuaatteerrnniioonn qq22,, CCaappQQuuaatteerrnniioonn rr));;


                   qq11   The quaternion on the left side of the multiplica-
                        tion.

                   qq22   The  quaternion on the right side of the multipli-
                        cation.

                   rr    The resulting quaternion.

              Description
                   This  routine  computes  _r=_q1x_q2.   If  the   resulting
                   quaternion _r is used for rotations, it is equivalent to
                   rotating by _q1 followed by rotating by _q2.

              Return Value
                   None




































              Capture Server LibraryORcetfoebreernc3e1, 1995                    31





         General Unix Server Routines                  Server Library


         _G_e_n_e_r_a_l _U_n_i_x _S_e_r_v_e_r _R_o_u_t_i_n_e_s

         These handle the Unix specific requirements for running pro-
         cesses as daemons and for creating and connecting to sockets
         for communication.  The general Unix server routines are:

         CCaappCCrreeaatteeIInneettSSoocckkeett(())
              Create an internet domain socket for clients to connect
              to.

         CCaappCCrreeaatteeUUnniixxSSoocckkeett(())
              Create  a Unix domain socket for clients to connect to.

         CCaappDDaaeemmoonniizzee(())
              Convert the current process into a daemon process.

         CCaappSSeerrvvee(())
              Create a socket, and wait for a connection on it.







































         32                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                         CCaappCCrreeaatteeIInneettSSoocckkeett(())


              Function:
                   Create an internet domain socket for clients to connect
                   to.

                   iinntt CCaappCCrreeaatteeIInneettSSoocckkeett((cchhaarr **sseerrvviiccee,, sshhoorrtt ddeeff__ppoorrtt));;


                   sseerrvviiccee
                        This   is   a   service   name   as  specified  in
                        //eettcc//sseerrvviicceess.  If the service is not found or  is
                        NNUULLLL then the ddeeff__ppoorrtt is used instead.

                   ddeeff__ppoorrtt
                        The  default  port to use if sseerrvviicceePP iiss nnoott vvaalliidd
                        oorr nnoott ssppeecciiffiieedd..

              Description:
                   This routine creates an internet domain socket  on  the
                   port specified by the service name and //eettcc//sseerrvviicceess or
                   by the port specified by ddeeff__ppoorrtt.   If  the  specified
                   port  number  is less than 1024, the server must be run
                   as root or the call will fail with eerrrrnnoo  set  to  EEAACC--
                   CCEESSSS.

                   This  routine is very low level.  CCaappSSeerrvvee(()) provides a
                   much easier interface and is the recommended method  of
                   creating server sockets.

              Return Value:
                   Returns  the socket file descriptor if all went well or
                   -1 if some error occurred.   If  there  was  an  error,
                   eerrrrnnoo is set to an appropriate value.

























              Capture Server LibraryORcetfoebreernc3e1, 1995                    33





         CCaappCCrreeaatteeUUnniixxSSoocckkeett(())                         Server Library


         Function:
              Create an Unix domain socket for clients to connect to.

              iinntt CCaappCCrreeaatteeUUnniixxSSoocckkeett((cchhaarr **nnaammee));;


              nnaammee The name of the unix domain socket.  If  the  name
                   is  not  a full path name (i.e., it does not start
                   with '//') then ""//ttmmpp//"" is prepended to the name to
                   make a name in the directory //ttmmpp.

         Description:
              This routine creates an unix domain socket on the file-
              name specified by name.  The directory in which name is
              to  be  created must be writable by the server process.
              If the socket name is a full path name,  that  name  is
              used.   If  the  name  is  not  a full path name, it is
              assumed to be relative to the directory  //ttmmpp  and  the
              socket is created there.

              This  routine is very low level.  CCaappSSeerrvvee(()) provides a
              much easier interface and is the recommended method  of
              creating server sockets.

         Return Value:
              Returns  the socket file descriptor if all went well or
              -1 if some error occurred.   If  there  was  an  error,
              eerrrrnnoo is set to an appropriate value.





























         34                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                                CCaappDDaaeemmoonniizzee(())


              Function:
                   Convert the current process into a daemon process.

                   iinntt CCaappDDaaeemmoonniizzee((vvooiidd));;


              Description:
                   This routine actually creates a new process that is not
                   associated with the users terminal, current  directory,
                   or  process group.  It does this by forking and calling
                   various system services  to  disassociate  the  process
                   from  the  controlling terminal.  This prevents it from
                   getting signals when the user types control-C for exam-
                   ple.  Finally, the process changes its directory to "/"
                   to make sure that it is not on a mounted  file  system.
                   (This  means  that / has to be searchable by the server
                   process.)

              Return Value:
                   Returns 0 if there was no error or  -1  if  some  error
                   occurred.   If  there  was an error, eerrrrnnoo is set to an
                   appropriate value.



































              Capture Server LibraryORcetfoebreernc3e1, 1995                    35





         CCaappSSeerrvvee(())                                    Server Library


         Function:
              Create a socket, and wait for a connection on it.

              iinntt CCaappSSeerrvvee((cchhaarr **sseerrvveerr));;


              sseerrvveerrThe name of the server.  See below for details.

         Description:
              This routine creates an appropriate socket, waits for a
              connection, cleans up the file system (if it was a unix
              domain socket), sets some socket  options  on  internet
              sockets  for  performance reasons, and returns the file
              descriptor of a connection to  a  client  if  all  went
              well.   This  is a higher level but much simpler inter-
              face to  creating  server  sockets  and  connecting  to
              clients.

              The server name is the same name that a user would pro-
              vide to Kinemation.  There are two forms that this name
              can take.  Unix domain sockets are simply a filename on
              the disk.  If this name is not a full path name, it  is
              taken  to be relative to //ttmmpp.  Internet domain sockets
              are a colon followed by a  port  number  specification.
              The  port number specification is either a service name
              or a decimal port number.  If the service  name  cannot
              be found then it is assumed to be a decimal number.

              The following are valid server names:

              cclloocckk__sseerrvveerr
                   This  name would create a unix domain socket named
                   //ttmmpp//cclloocckk__sseerrvveerr.

              //uussrr//ttmmpp//cclloocckk__sseerrvveerr
                   This  time  the  unix  domain  socket   is   named
                   //uussrr//ttmmpp//cclloocckk__sseerrvveerr.

              ::33000011 This would create an internet socket on the local
                   machine at port 3001.  If this machine were called
                   hhoosstt11  then  Kinemation running on another machine
                   could open the server  hhoosstt11::33000011  to  connect  to
                   this socket.

              ::fflloocckk
                   This  would  lookup  the  service  name  fflloocckk  in
                   /etc/services and use the port  defined  there  to
                   create  a  socket.  Kinemation running on a remote
                   machine could open the server hhoosstt11::fflloocckk to  con-
                   nect to this socket.  This assumes that bbootthh hosts
                   have an entry  for  the  service  fflloocckk  in  their
                   //eettcc//sseerrvviicceess files.

         Return Value:



         36                    OctoberCa3p1t,ur1e99S5erver Library Reference





              Server Library                                    CCaappSSeerrvvee(())


                   Returns a socket file descriptor that is connected to a
                   client if there were no errors  or  -1  if  some  error
                   occurred.   If  there  was an error, eerrrrnnoo is set to an
                   appropriate value.





















































              Capture Server LibraryORcetfoebreernc3e1, 1995                    37


