sample.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 
21 #define Jr3DmAddrMask 0x6000
22 #define PAGE_SIZE 0x1000
23 unsigned long MappedAddress;
24 
25 #define SENSOR0 0
26 #define SENSOR1 0x80000
27 #define SENSOR2 0x100000
28 #define SENSOR3 0x180000
29 
30 typedef struct {
31  uint16_t msg_no;
32  char msg_data[255];
33 } client_msg_t;
34 
35 int main(int argc, char **argv) {
36  int fd;
37  int c;
38  client_msg_t msg;
39  int ret;
40  int num;
41  char msg_reply[255];
42  int i;
43 
44  printf("\x1b[2J");
45  printf("\x1b[0;0H");
46 
47  num = 4;
48 
49  /* Process any command line arguments */
50  while ((c = getopt(argc, argv, "n:")) != -1) {
51  if (c == 'n') {
52  num = strtol(optarg, 0, 0);
53  }
54  }
55 
56  /* Open a connection to the server (fd == coid) */
57  fd = open("/dev/jr3q", O_RDWR);
58  if (fd == -1) {
59  fprintf(stderr, "Unable to open server connection: %s\n",
60  strerror(errno));
61  return EXIT_FAILURE;
62  }
63 
64  /* Clear the memory for the msg and the reply */
65  memset(&msg, 0, sizeof(msg));
66  memset(&msg_reply, 0, sizeof(msg_reply));
67 
68  /* Setup the message data to send to the server */
69  msg.msg_no = _IO_MAX + num;
70  snprintf(msg.msg_data, 254, "client %d requesting reply.", getpid());
71 
72  printf("client: msg_no: _IO_MAX + %d\n", num);
73  fflush(stdout);
74 
75  i = 0;
76  loop:
77  /* Send the data to the server and get a reply */
78  msg.msg_no = _IO_MAX + num;
79  ret = MsgSend(fd, &msg, sizeof(msg), msg_reply, 255);
80  if (ret == -1) {
81  fprintf(stderr, "Unable to MsgSend() to server: %s\n", strerror(errno));
82  return EXIT_FAILURE;
83  }
84  if (num == 1) {
85  float tmp[12];
86  memcpy(tmp, msg_reply, sizeof(float) * 12);
87  printf("client: msg_reply: %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
88  tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
89  printf(" %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
90  tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11]);
91  } else {
92  printf("client: msg_reply:\n%s\n", msg_reply);
93  }
94 
95  if (num > 1)
96  num--;
97 
98  usleep(100000);
99  if ((i % 20) == 0) {
100  num = 4;
101  }
102 
103  if (i++ < 100000)
104  goto loop;
105 
106  close(fd);
107 
108  return EXIT_SUCCESS;
109 }
int main(int argc, char **argv)
Definition: sample.c:35
#define EXIT_SUCCESS
png_uint_32 i
unsigned long MappedAddress
Definition: sample.c:23
stderr
fd
uint16_t msg_no
ret
c
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 Mon Feb 28 2022 23:45:15