Go to the documentation of this file.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
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 uint16_t msg_no;
00032 char msg_data[255];
00033 } client_msg_t;
00034
00035 int main(int argc, char **argv) {
00036 int fd;
00037 int c;
00038 client_msg_t msg;
00039 int ret;
00040 int num;
00041 char msg_reply[255];
00042 int i;
00043
00044 printf("\x1b[2J");
00045 printf("\x1b[0;0H");
00046
00047 num = 4;
00048
00049
00050 while ((c = getopt(argc, argv, "n:")) != -1) {
00051 if (c == 'n') {
00052 num = strtol(optarg, 0, 0);
00053 }
00054 }
00055
00056
00057 fd = open("/dev/jr3q", O_RDWR);
00058 if (fd == -1) {
00059 fprintf(stderr, "Unable to open server connection: %s\n",
00060 strerror(errno));
00061 return EXIT_FAILURE;
00062 }
00063
00064
00065 memset(&msg, 0, sizeof(msg));
00066 memset(&msg_reply, 0, sizeof(msg_reply));
00067
00068
00069 msg.msg_no = _IO_MAX + num;
00070 snprintf(msg.msg_data, 254, "client %d requesting reply.", getpid());
00071
00072 printf("client: msg_no: _IO_MAX + %d\n", num);
00073 fflush(stdout);
00074
00075 i = 0;
00076 loop:
00077
00078 msg.msg_no = _IO_MAX + num;
00079 ret = MsgSend(fd, &msg, sizeof(msg), msg_reply, 255);
00080 if (ret == -1) {
00081 fprintf(stderr, "Unable to MsgSend() to server: %s\n", strerror(errno));
00082 return EXIT_FAILURE;
00083 }
00084 if (num == 1) {
00085 float tmp[12];
00086 memcpy(tmp, msg_reply, sizeof(float) * 12);
00087 printf("client: msg_reply: %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
00088 tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5]);
00089 printf(" %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n",
00090 tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11]);
00091 } else {
00092 printf("client: msg_reply:\n%s\n", msg_reply);
00093 }
00094
00095 if (num > 1)
00096 num--;
00097
00098 usleep(100000);
00099 if ((i % 20) == 0) {
00100 num = 4;
00101 }
00102
00103 if (i++ < 100000)
00104 goto loop;
00105
00106 close(fd);
00107
00108 return EXIT_SUCCESS;
00109 }