Mercurial > hg > fxanalyse
annotate dds.c @ 206:c700a2d38fb8
New AD9956 interface
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 31 Mar 2014 17:03:38 +0200 |
parents | |
children | fcc988c6f841 |
rev | line source |
---|---|
206
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
1 #ifdef _CVI_ |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
2 #include <winsock2.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
3 #include <ansi_c.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
4 #else |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
5 #include <stdio.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
6 #include <stdlib.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
7 #include <unistd.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
8 #include <errno.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
9 #include <string.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
10 #include <sys/types.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
11 #include <sys/socket.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
12 #include <netinet/in.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
13 #include <arpa/inet.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
14 #include <netdb.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
15 #include <ctype.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
16 #include <math.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
17 #include <stdarg.h> |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
18 #endif |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
19 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
20 #include "dds.h" |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
21 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
22 int msend(int fd, char *buffer, int n) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
23 { |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
24 int r; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
25 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
26 buffer[n++] = '\r'; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
27 buffer[n++] = '\n'; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
28 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
29 r = send(fd, buffer, n, 0); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
30 if (r < 0) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
31 return r; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
32 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
33 return 0; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
34 } |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
35 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
36 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
37 int mrecv(int fd, char *buffer, int len) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
38 { |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
39 int n; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
40 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
41 n = recv(fd, buffer, len, 0); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
42 if (n < 0) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
43 return n; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
44 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
45 if ((buffer[--n] != '\n') || (buffer[--n] != '\r')) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
46 return -1; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
47 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
48 buffer[n] = '\0'; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
49 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
50 return n; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
51 } |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
52 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
53 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
54 int command(int fd, char *frmt, ...) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
55 { |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
56 int r, n; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
57 char buffer[1024]; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
58 va_list v; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
59 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
60 va_start(v, frmt); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
61 n = vsnprintf(buffer, sizeof(buffer) - 2, frmt, v); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
62 va_end(v); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
63 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
64 r = msend(fd, buffer, n); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
65 if (r < 0) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
66 return r; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
67 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
68 r = mrecv(fd, buffer, sizeof(buffer)); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
69 if (r < 0) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
70 return r; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
71 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
72 if (! streq(buffer, "OK")) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
73 return -1; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
74 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
75 return 0; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
76 } |