sample_dynpick.c
Go to the documentation of this file.
1 /*
2  * Message Client Process
3  *
4  * This program is for JR3/Nitta Force moment sensor.
5  * Copyright(C) by Waseda University, Nitta Corporation. 2002.
6  *
7  * Modified by Kei Okada, 2014
8  */
9 
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <stdlib.h>
13 #include <fcntl.h>
14 #include <errno.h>
15 #include <string.h>
16 #include <sys/neutrino.h>
17 #include <sys/iofunc.h>
18 #include <sys/dispatch.h>
19 #include <sys/mman.h>
20 #include <sys/time.h>
21 
22 #define Jr3DmAddrMask 0x6000
23 #define PAGE_SIZE 0x1000
24 unsigned long MappedAddress;
25 
26 #define SENSOR0 0
27 #define SENSOR1 0x80000
28 #define SENSOR2 0x100000
29 #define SENSOR3 0x180000
30 
31 typedef struct
32 {
33  uint16_t msg_no;
34  char msg_data[255];
35 } client_msg_t;
36 
37 int
38 main (int argc, char **argv)
39 {
40  int fd;
41  int c;
42  client_msg_t msg;
43  int ret;
44  int num;
45  char msg_reply[255];
46  int i;
47  struct timeval c0, c1, l0, l1;
48 
49  printf ("\x1b[2J");
50  printf ("\x1b[0;0H");
51 
52  num = 4;
53 
54  /* Process any command line arguments */
55  while ((c = getopt (argc, argv, "n:")) != -1)
56  {
57  if (c == 'n')
58  {
59  num = strtol (optarg, 0, 0);
60  }
61  }
62 
63  /* Open a connection to the server (fd == coid) */
64  fd = open ("/dev/jr3q", O_RDWR);
65  if (fd == -1)
66  {
67  fprintf (stderr, "Unable to open server connection: %s\n",
68  strerror (errno));
69  return EXIT_FAILURE;
70  }
71 
72  /* Clear the memory for the msg and the reply */
73  memset (&msg, 0, sizeof (msg));
74  memset (&msg_reply, 0, sizeof (msg_reply));
75 
76  /* Setup the message data to send to the server */
77  msg.msg_no = _IO_MAX + num;
78  snprintf (msg.msg_data, 254, "client %d requesting reply.", getpid ());
79 
80  printf ("client: msg_no: _IO_MAX + %d\n", num);
81  fflush (stdout);
82 
83  i = 0;
84 loop:
85  gettimeofday(&l0, NULL);
86  /* Send the data to the server and get a reply */
87  msg.msg_no = _IO_MAX + num;
88  gettimeofday(&c0, NULL);
89  ret = MsgSend (fd, &msg, sizeof (msg), msg_reply, 255);
90  gettimeofday(&c1, NULL);
91  if (ret == -1)
92  {
93  fprintf (stderr, "Unable to MsgSend() to server: %s\n",
94  strerror (errno));
95  return EXIT_FAILURE;
96  }
97  if (num == 1)
98  {
99  float tmp[12];
100  memcpy (tmp, msg_reply, sizeof (float) * 12);
101  printf ("client: msg_reply: %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
102  tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
103 #define DELTA_SEC(start, end) (end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec)/1e6)
104  printf (" %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f ... %7.3f msec\n",
105  tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11],
106  DELTA_SEC(c0, c1)*1000);
107  }
108  else
109  {
110  printf ("client: msg_reply:\n%s\n", msg_reply);
111  }
112 
113  if (num > 1)
114  num--;
115 
116  usleep (100000);
117  if ((i % 20) == 0)
118  {
119  num = 4;
120  }
121 
122  if (i++ < 100000)
123  gettimeofday(&l1, NULL);
124  printf ("Loop took %7.3f msec\n", DELTA_SEC(l0, l1)*1000);
125  goto loop;
126 
127  close (fd);
128 
129  return EXIT_SUCCESS;
130 }
unsigned long MappedAddress
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
#define EXIT_SUCCESS
#define DELTA_SEC(start, end)
png_uint_32 i
stderr
fd
uint16_t msg_no
int gettimeofday(struct timeval *tv, struct timezone *tz)
c
int main(int argc, char **argv)
char msg_data[255]
pid_t getpid()
int num
char * optarg
#define EXIT_FAILURE
int usleep(useconds_t usec)


hironx_ros_bridge
Author(s): Kei Okada , Isaac I.Y. Saito
autogenerated on Thu May 14 2020 03:52:05