annotate DDS_Fox.c @ 197:79db2c87d1b0

New build. Do not install configuration file.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 31 Mar 2014 17:03:37 +0200
parents 12df3a2b18de
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 #include <tcpsupp.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include <ansi_c.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 #include "DDS_Fox.h"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
5 // #define DEBUG 1
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 #define CMD_SEP ";"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 #define BASE_TIME 0.01
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 #define CMD_CONFIG_REG1 1 // cmd d'acces direct au rergistre 1 de config de la DDS (voir datasheet)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10 #define CMD_CONFIG_REG2 2 // cmd d'acces direct au rergistre 1 de config de la DDS (voir datasheet)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11 #define CMD_SINGLE_FREQ_PROF0 7
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12 #define CMD_PROFILE 15 // cmd de choix du profile de fonctionnement de la DDS (voir datasheet)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 #define CMD_ATTENUATION 16
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 #define CMD_RESET_DDS 17
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 #define CMD_NOP 20
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16 #define CMD_FREQ_INF 21
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 #define CMD_FREQ_SUP 22
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 #define CMD_DF 23
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 #define CMD_DT 24
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 #define CMD_START_SWEEP 25
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21 #define CMD_STOP_SWEEP 26
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22 #define CMD_GET_FREQ 28
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 #define CMD_SWEEP_SIGN 29
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
25 typedef struct {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
26 char* action;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
27 char* canal;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
28 char* command;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
29 char* value0;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
30 char* value1;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
31 char* value2;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
32 char* value3;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
33 char* value4;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
34 char* value5;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
35 char* value6;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
36 char* value7;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
37 char* value8;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
38 char* value9;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
39 char* value10;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
40 char* value11;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
41 char* value12;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
42 char* value13;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
43 char* value14;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
44 char* value15;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
45 char* value16;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
46 char* value17;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
47 char* value18;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
48 char* value19;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
49 } Command;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
50
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
51 static int SendCmd(char *Buffer, DDSParameter *Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
52 static int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
53 static void init_command(Command *cmd);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
54 static int parse_command(Command *cmd1, char *buf);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
55 static void convert_double_6char (double fraction, unsigned char* octets);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
56
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
57 #define error(...) _error(__FILE__, __LINE__, __func__, __VA_ARGS__)
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
58
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
59 void _error(const char *file, int line, const char *func, const char *frmt, ...)
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
60 {
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
61 va_list args;
63
2320f5fc66aa Fix varargs handling in DDS Fox driver error function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 50
diff changeset
62 va_start(args, frmt);
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
63 fprintf(stderr, "ERROR: %s:%d:%s: ", file, line, func);
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
64 vfprintf(stderr, frmt, args);
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
65 fprintf(stderr, "\n");
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
66 va_end(args);
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
67 }
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
68
184
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
69 void DDSFox_Init(DDSParameter *Param, char *ip, int port)
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
70 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
71 strcpy(Param->ip, ip);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
72 Param->Port = 6665;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
73 Param->Profil = 7; // configuration profile: single freq=0, sweep=7
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
74 Param->Clock = 200000000;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
75 Param->Delta_T = 0.01;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
76 Param->SweepRate = 0.0;
184
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
77 }
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
78
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
79 void DDSFox_Reset(DDSParameter *Param, double frequency)
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
80 {
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
81 // set sweep rate to 0
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
82 Param->SweepRate = 0.0;
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
83 // reset the DDS
184
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
84 DDSFox_DeviceReset(Param);
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
85 // set profile number 7 soft frequecy sweep
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
86 DDSFox_SetProfile(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
87 // set clock divider to 1
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
88 DDSFox_SetDiv(Param, 1);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
89 // set frequency
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
90 DDSFox_SetFreqInf(Param, frequency);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
91 // set frequency upper bound to max value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
92 DDSFox_SetFreqMax(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
93 // set sweep rate to 0
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
94 DDSFox_SetDT(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
95 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
96 DDSFox_SetSweepSign(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
97 // start sweep
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
98 DDSFox_StartSweep(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
99 // set frequency lower bound to min value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
100 DDSFox_SetFreqMin(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
101
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
102 return;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
103 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
104
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
105 void DDSFox_SetSweepRate(DDSParameter *Param, double sweepRate)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
106 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
107 Param->SweepRate = sweepRate;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
108 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
109 DDSFox_SetSweepSign(Param);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
110 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
111
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
112 void DDSFox_Set(DDSParameter *Param, double frequency, double sweepRate)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
113 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
114 // set desired frequency
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
115 DDSFox_SetFreqInf(Param, frequency);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
116 // set frequency upper bound to max value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
117 DDSFox_SetFreqMax(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
118 // set sweep rate to 0
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
119 Param->SweepRate = 0.0;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
120 DDSFox_SetDT(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
121 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
122 DDSFox_SetSweepSign(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
123 // start sweep
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
124 DDSFox_StartSweep(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
125 // set frequency lower bound to min value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
126 DDSFox_SetFreqMin(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
127 // set desired sweep rate
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
128 Param->SweepRate = sweepRate;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
129 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
130 DDSFox_SetSweepSign(Param);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
131 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
132
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
133 void DDSFox_Nop (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
134 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
135 // send NOP command
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
136 char request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
137 sprintf(request, "set;%i;%i", 1, CMD_NOP);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
138 SendCmd(request, Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
139 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
140
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
141 void DDSFox_SetProfile (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
142 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
143 char request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
144 sprintf(request, "set;%i;%i;%i", 1, CMD_PROFILE, Param->Profil);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
145 SendCmd(request, Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
146 }
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
147
184
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
148 void DDSFox_DeviceReset(DDSParameter *Param)
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
149 {
184
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
150 char request[255];
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
151 sprintf(request, "set;%i;%i", 1, CMD_RESET_DDS);
12df3a2b18de Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 175
diff changeset
152 SendCmd(request, Param);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
153 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
154
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
155 void DDSFox_StopSweep(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
156 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158 sprintf(Request,"set;%i;%i;%i",1,CMD_STOP_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
159 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
162
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
163 void DDSFox_StartSweep(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
164 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
166 sprintf(Request,"set;%i;%i;%i",1,CMD_START_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
167 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
168 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
169 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
170
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
171 void DDSFox_SetFreqMax (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
172 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
173 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
174 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
175 convert_double_6char(pow(2,48)/2,octets); // borne sup : clock / 2
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
176 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
177 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
178 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
179 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
180 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
181 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
182
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
183 void DDSFox_SetFreqMin (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
184 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
185 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
186 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
187 convert_double_6char(1,octets); // borne inf : ~0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
188 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
189 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
190 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
191 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
192 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
193 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
194
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
195 void DDSFox_SetFreqInf (DDSParameter *Param, double frequency)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
196 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
197 double word ;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
198 unsigned char octets[6];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
199 char Request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
200 word = pow(2,48)*(frequency / Param->Clock);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
201 convert_double_6char(word, octets);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
202 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
203 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
204 SendCmd(Request, Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
205 }
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
206
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
207 void DDSFox_SetFreqSup (DDSParameter *Param, double frequency)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
208 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
209 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
210 unsigned char octets[6];
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
211 char Request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
212 word = pow(2,48)*(frequency / Param->Clock);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
213 convert_double_6char(word, octets);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
214 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
215 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
216 SendCmd(Request, Param);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
217 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
218
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
219 static int GetSweepSign(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
220 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
221 if (Param->SweepRate >= 0.0)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
222 return 0;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
223 return 1;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
224 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
225
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
226 void DDSFox_SetSweepSign(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
227 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
228 char Request[255] ;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
229 int SweepSign ;
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
230 SweepSign = GetSweepSign(Param) ;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
231 sprintf(Request, "set;%i;%i;%i", 1, CMD_SWEEP_SIGN, SweepSign);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
232 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
233 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
234 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
235
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
236 void DDSFox_SetDT(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
237 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
238 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
239 int dt= 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
240 char FTW0[255]="0"; /**** sinon le fichier inf.xx est faux ***/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
241 dt = ((Param->Delta_T)/BASE_TIME) - 1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
242 sprintf(FTW0,"%ims",dt);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
243 sprintf(Request,"set;%i;%i;%i;%s",1,CMD_DT, dt ,FTW0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
244 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
245 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
246 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
247
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
248 // Change le facteur de division de la clock. Argument: facteur de div, retourne rien
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
249 void DDSFox_SetDiv(DDSParameter *Param, int div)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
250 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
251 char Request[255];
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
252 Command Rd;
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
253 char temp;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
254
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
255 int Div = 0;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
256 // Div = log2(div)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
257 while ((div >>= 1) > 1)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
258 Div++;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
259
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
260 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
261 sprintf(Request,"get;%i;%i",1,CMD_CONFIG_REG2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
262 if (RecvCmd(&Rd, Request, Param) < 0)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
263 return;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
264 temp = atoi(Rd.value2) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
265 temp = temp & 0x9F ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
266 temp = temp | Div << 5 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
267 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i",1,CMD_CONFIG_REG2,atoi(Rd.value0),
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
268 atoi(Rd.value1),temp,atoi(Rd.value3),atoi(Rd.value4)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
269 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
270 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
271 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
272
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
273 void DDSFox_SetDf(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
274 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
275 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
276 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
277 unsigned char *octets;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
278 word = pow(2,48)*(fabs(Param->SweepRate)*Param->Delta_T/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
279 octets=malloc(6*sizeof(unsigned char));
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
280 convert_double_6char(word, octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
281 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_DF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
282 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
283 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
284 free(octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
285 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
286 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
287
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
288 double DDSFox_ReadFreq(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
289 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
290 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
291 unsigned int OctetA, OctetB, OctetC, OctetD, OctetE, OctetF ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
292 double FreqRead ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
293 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
294 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
295 sprintf(Request,"get;%i;%i",1,CMD_GET_FREQ);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
296 if (RecvCmd(&Rd, Request, Param) == -1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
297 return -1.;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
298 OctetA=atoi(Rd.value0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
299 OctetB=atoi(Rd.value1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
300 OctetC=atoi(Rd.value2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
301 OctetD=atoi(Rd.value3);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
302 OctetE=atoi(Rd.value4);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
303 OctetF=atoi(Rd.value5);
45
b47b97cfd050 Fix output frequency read back in DDS Fox driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 13
diff changeset
304 FreqRead = 1099511627776.0 * OctetA + 4294967296.0 * OctetB + 16777216.0 * OctetC + 65536.0 * OctetD + 256.0 * OctetE + 1.0 * OctetF;
b47b97cfd050 Fix output frequency read back in DDS Fox driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 13
diff changeset
305 FreqRead = FreqRead * Param->Clock / pow(2,48);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
306 return(FreqRead);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
307 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
308
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
309 // TCP communication
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
310
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
311 static unsigned int timeout = 0; // milliseconds
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
312
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
313
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
314 static int SendCmd(char *Buffer, DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
315 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
316 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
317 char Response[255];
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
318 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
319 fprintf(stderr, "> %s\n", Buffer);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
320 #endif
175
e5ad3ed47d2c Code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 72
diff changeset
321 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, NULL, NULL, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
322 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
323 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
324 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
325 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
326 error("Write failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
327 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
328 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
329 sprintf(Response," ");
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
330 if (ClientTCPRead (hConv, Response, 255, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
331 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
332 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
333 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
334 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
335 fprintf(stderr, "< %s\n", Response);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
336 #endif
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
337 if (strncmp("OK",Response,2)) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
338 error("Response failed %s %s", Buffer, Response);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
339 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
340 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
341 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
342 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
343
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
344 static int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
345 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
346 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
347 char parsebuf[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
348 char Response[255];
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
349 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
350 fprintf(stderr, "> %s\n", Buffer);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
351 #endif
175
e5ad3ed47d2c Code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 72
diff changeset
352 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, NULL, NULL, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
353 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
354 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
355 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
356 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
357 error("Write failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
358 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
359 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
360 sprintf(Response," ");
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
361 if (ClientTCPRead (hConv, Response, 255, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
362 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
363 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
364 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
365 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
366 fprintf(stderr, "< %s\n", Response);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
367 #endif
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
368 if (strncmp(Buffer,Response,strlen(Buffer))) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
369 error("Response failed %s %s", Buffer, Response);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
370 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
371 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
372
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
373 sprintf(parsebuf,"%s",Response) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
374 parse_command(Rd, parsebuf) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
375 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
376 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
377
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
378 static void init_command(Command *cmd)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
379 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
380 memset(cmd, 0, sizeof(Command));
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
381 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
382
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
383 static int parse_command(Command *cmd1, char *buf)
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
384 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
385 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
386 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
387
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
388 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
389 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
390 if( c == 0 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
391 cmd1->action = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
392 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
393 else if( c == 1 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
394 cmd1->canal = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
395 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
396 else if( c == 2 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
397 cmd1->command = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
398 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
399 else if( c == 3 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
400 cmd1->value0 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
401 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
402 else if( c == 4 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
403 cmd1->value1 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
404 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
405 else if( c == 5 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
406 cmd1->value2 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
407 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
408 else if( c == 6 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
409 cmd1->value3 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
410 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
411 else if( c == 7 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
412 cmd1->value4 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
413 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
414 else if( c == 8 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
415 cmd1->value5 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
416 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
417 else if( c == 9 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
418 cmd1->value6 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
419 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
420 else if( c == 10 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
421 cmd1->value7 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
422 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
423 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
424 c++;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
425 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
426 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
427 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
428
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
429 // convert double into 6 bytes sent back by an unsigned char pointer
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
430 static void convert_double_6char (double fraction, unsigned char* octets)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
431 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
432 // 64 bits integer
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
433 unsigned long long x = fraction;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
434 for (int i = 0; i < 6; i++)
72
8e6a2ec85169 Fix byte order in AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 68
diff changeset
435 octets[i] = (unsigned char)((x >> (i * 8)) & 0xFF);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
436 }