sample.c
Go to the documentation of this file.
00001 /*
00002  *  Message Client Process
00003  *
00004  *  This program is for JR3/Nitta Force moment sensor.
00005  *  Copyright(C) by Waseda University, Nitta Corporation. 2002.
00006  *
00007  * Modified by Kei Okada, 2014
00008  */
00009 
00010 #include <stdio.h>
00011 #include <unistd.h>
00012 #include <stdlib.h>
00013 #include <fcntl.h>
00014 #include <errno.h>
00015 #include <string.h>
00016 #include <sys/neutrino.h>
00017 #include <sys/iofunc.h>
00018 #include <sys/dispatch.h>
00019 #include <sys/mman.h>
00020 
00021 #define Jr3DmAddrMask   0x6000
00022 #define PAGE_SIZE       0x1000
00023 unsigned long MappedAddress;
00024 
00025 #define SENSOR0         0
00026 #define SENSOR1         0x80000
00027 #define SENSOR2         0x100000
00028 #define SENSOR3         0x180000
00029 
00030 typedef struct
00031 {
00032   uint16_t msg_no;
00033   char msg_data[255];
00034 } client_msg_t;
00035 
00036 int
00037 main (int argc, char **argv)
00038 {
00039   int fd;
00040   int c;
00041   client_msg_t msg;
00042   int ret;
00043   int num;
00044   char msg_reply[255];
00045   int i;
00046 
00047   printf ("\x1b[2J");
00048   printf ("\x1b[0;0H");
00049 
00050   num = 4;
00051 
00052   /* Process any command line arguments */
00053   while ((c = getopt (argc, argv, "n:")) != -1)
00054     {
00055       if (c == 'n')
00056         {
00057           num = strtol (optarg, 0, 0);
00058         }
00059     }
00060 
00061   /* Open a connection to the server (fd == coid) */
00062   fd = open ("/dev/jr3q", O_RDWR);
00063   if (fd == -1)
00064     {
00065       fprintf (stderr, "Unable to open server connection: %s\n",
00066                strerror (errno));
00067       return EXIT_FAILURE;
00068     }
00069 
00070   /* Clear the memory for the msg and the reply */
00071   memset (&msg, 0, sizeof (msg));
00072   memset (&msg_reply, 0, sizeof (msg_reply));
00073 
00074   /* Setup the message data to send to the server */
00075   msg.msg_no = _IO_MAX + num;
00076   snprintf (msg.msg_data, 254, "client %d requesting reply.", getpid ());
00077 
00078   printf ("client: msg_no: _IO_MAX + %d\n", num);
00079   fflush (stdout);
00080 
00081   i = 0;
00082 loop:
00083   /* Send the data to the server and get a reply */
00084   msg.msg_no = _IO_MAX + num;
00085   ret = MsgSend (fd, &msg, sizeof (msg), msg_reply, 255);
00086   if (ret == -1)
00087     {
00088       fprintf (stderr, "Unable to MsgSend() to server: %s\n",
00089                strerror (errno));
00090       return EXIT_FAILURE;
00091     }
00092   if (num == 1)
00093     {
00094       float tmp[12];
00095       memcpy (tmp, msg_reply, sizeof (float) * 12);
00096       printf ("client: msg_reply: %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
00097               tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
00098       printf ("                   %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
00099               tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11]);
00100     }
00101   else
00102     {
00103       printf ("client: msg_reply:\n%s\n", msg_reply);
00104     }
00105 
00106   if (num > 1)
00107     num--;
00108 
00109   usleep (100000);
00110   if ((i % 20) == 0)
00111     {
00112       num = 4;
00113     }
00114 
00115 
00116   if (i++ < 100000)
00117     goto loop;
00118 
00119   close (fd);
00120 
00121   return EXIT_SUCCESS;
00122 }


hironx_ros_bridge
Author(s): Kei Okada
autogenerated on Mon Oct 6 2014 07:19:42