Mercurial > hg > fxanalyse
annotate dds.c @ 223:7875436125dd
Variable names clarification and cleanup
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Thu, 18 Sep 2014 18:03:27 +0200 |
parents | fcc988c6f841 |
children |
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 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
21 int msend(int fd, char *buffer, int n) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
22 { |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
23 buffer[n++] = '\r'; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
24 buffer[n++] = '\n'; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
25 |
213
fcc988c6f841
Fix ad9956 sweep rate setting. Disable clock divider on init. Simplify
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
206
diff
changeset
|
26 return send(fd, buffer, n, 0); |
206
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
27 } |
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 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
30 int mrecv(int fd, char *buffer, int len) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
31 { |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
32 int n; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
33 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
34 n = recv(fd, buffer, len, 0); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
35 if (n < 0) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
36 return n; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
37 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
38 if ((buffer[--n] != '\n') || (buffer[--n] != '\r')) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
39 return -1; |
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 buffer[n] = '\0'; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
42 |
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 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
46 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
47 int command(int fd, char *frmt, ...) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
48 { |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
49 int r, n; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
50 char buffer[1024]; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
51 va_list v; |
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 va_start(v, frmt); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
54 n = vsnprintf(buffer, sizeof(buffer) - 2, frmt, v); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
55 va_end(v); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
56 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
57 r = msend(fd, buffer, n); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
58 if (r < 0) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
59 return r; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
60 |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
61 r = mrecv(fd, buffer, sizeof(buffer)); |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
62 if (r < 0) |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
63 return r; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
64 |
213
fcc988c6f841
Fix ad9956 sweep rate setting. Disable clock divider on init. Simplify
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
206
diff
changeset
|
65 if (strcmp(buffer, "OK") != 0) |
206
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
66 return -1; |
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 return 0; |
c700a2d38fb8
New AD9956 interface
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
69 } |