00001
00002
00003
00004
00005
00006
00007
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 #include <sys/time.h>
00021
00022 #define Jr3DmAddrMask 0x6000
00023 #define PAGE_SIZE 0x1000
00024 unsigned long MappedAddress;
00025
00026 #define SENSOR0 0
00027 #define SENSOR1 0x80000
00028 #define SENSOR2 0x100000
00029 #define SENSOR3 0x180000
00030
00031 typedef struct
00032 {
00033 uint16_t msg_no;
00034 char msg_data[255];
00035 } client_msg_t;
00036
00037 int
00038 main (int argc, char **argv)
00039 {
00040 int fd;
00041 int c;
00042 client_msg_t msg;
00043 int ret;
00044 int num;
00045 char msg_reply[255];
00046 int i;
00047 struct timeval c0, c1, l0, l1;
00048
00049 printf ("\x1b[2J");
00050 printf ("\x1b[0;0H");
00051
00052 num = 4;
00053
00054
00055 while ((c = getopt (argc, argv, "n:")) != -1)
00056 {
00057 if (c == 'n')
00058 {
00059 num = strtol (optarg, 0, 0);
00060 }
00061 }
00062
00063
00064 fd = open ("/dev/jr3q", O_RDWR);
00065 if (fd == -1)
00066 {
00067 fprintf (stderr, "Unable to open server connection: %s\n",
00068 strerror (errno));
00069 return EXIT_FAILURE;
00070 }
00071
00072
00073 memset (&msg, 0, sizeof (msg));
00074 memset (&msg_reply, 0, sizeof (msg_reply));
00075
00076
00077 msg.msg_no = _IO_MAX + num;
00078 snprintf (msg.msg_data, 254, "client %d requesting reply.", getpid ());
00079
00080 printf ("client: msg_no: _IO_MAX + %d\n", num);
00081 fflush (stdout);
00082
00083 i = 0;
00084 loop:
00085 gettimeofday(&l0, NULL);
00086
00087 msg.msg_no = _IO_MAX + num;
00088 gettimeofday(&c0, NULL);
00089 ret = MsgSend (fd, &msg, sizeof (msg), msg_reply, 255);
00090 gettimeofday(&c1, NULL);
00091 if (ret == -1)
00092 {
00093 fprintf (stderr, "Unable to MsgSend() to server: %s\n",
00094 strerror (errno));
00095 return EXIT_FAILURE;
00096 }
00097 if (num == 1)
00098 {
00099 float tmp[12];
00100 memcpy (tmp, msg_reply, sizeof (float) * 12);
00101 printf ("client: msg_reply: %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
00102 tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
00103 #define DELTA_SEC(start, end) (end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec)/1e6)
00104 printf (" %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f ... %7.3f msec\n",
00105 tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11],
00106 DELTA_SEC(c0, c1)*1000);
00107 }
00108 else
00109 {
00110 printf ("client: msg_reply:\n%s\n", msg_reply);
00111 }
00112
00113 if (num > 1)
00114 num--;
00115
00116 usleep (100000);
00117 if ((i % 20) == 0)
00118 {
00119 num = 4;
00120 }
00121
00122 if (i++ < 100000)
00123 gettimeofday(&l1, NULL);
00124 printf ("Loop took %7.3f msec\n", DELTA_SEC(l0, l1)*1000);
00125 goto loop;
00126
00127 close (fd);
00128
00129 return EXIT_SUCCESS;
00130 }