annotate DDS_Fox.c @ 171:7d0c8319c496

Add new parameters to default condiguration file
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 14 Feb 2014 16:58:19 +0100
parents 8e6a2ec85169
children e5ad3ed47d2c
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
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
69 void DDSFox_Initialize(DDSParameter *Param, char *ip, int port, double frequency)
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;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
77
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
78 // reset the DDS
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
79 //DDSFox_Nop(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
80 DDSFox_Reset(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
81 // set profile number 7 soft frequecy sweep
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
82 DDSFox_SetProfile(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
83 // set clock divider to 1
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
84 DDSFox_SetDiv(Param, 1);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
85 // set frequency
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
86 DDSFox_SetFreqInf(Param, frequency);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
87 // set frequency upper bound to max value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
88 DDSFox_SetFreqMax(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
89 // set sweep rate to 0
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
90 DDSFox_SetDT(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
91 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
92 DDSFox_SetSweepSign(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
93 // start sweep
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
94 DDSFox_StartSweep(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
95 // set frequency lower bound to min value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
96 DDSFox_SetFreqMin(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
97
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
98 return;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
99 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
101 void DDSFox_SetSweepRate(DDSParameter *Param, double sweepRate)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
102 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
103 Param->SweepRate = sweepRate;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
104 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
105 DDSFox_SetSweepSign(Param);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
106 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
107
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
108 void DDSFox_Set(DDSParameter *Param, double frequency, double sweepRate)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
109 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
110 // set desired frequency
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
111 DDSFox_SetFreqInf(Param, frequency);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
112 // set frequency upper bound to max value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
113 DDSFox_SetFreqMax(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
114 // set sweep rate to 0
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
115 Param->SweepRate = 0.0;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
116 DDSFox_SetDT(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
117 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
118 DDSFox_SetSweepSign(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
119 // start sweep
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
120 DDSFox_StartSweep(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
121 // set frequency lower bound to min value
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
122 DDSFox_SetFreqMin(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
123 // set desired sweep rate
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
124 Param->SweepRate = sweepRate;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
125 DDSFox_SetDf(Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
126 DDSFox_SetSweepSign(Param);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
127 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
128
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
129 void DDSFox_Nop (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
130 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
131 // send NOP command
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
132 char request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
133 sprintf(request, "set;%i;%i", 1, CMD_NOP);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
134 SendCmd(request, Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
135 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
136
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
137 void DDSFox_SetProfile (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
138 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
139 char request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
140 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
141 SendCmd(request, 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
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
144 void DDSFox_Reset(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
145 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
146 char Request[255];
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
147 //sprintf(Request,"set;%i;%i",1,CMD_NOP);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
148 //SendCmd(Request, Param) ;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
149 sprintf(Request,"set;%i;%i",1,CMD_RESET_DDS);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
150 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
151 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
152 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
153
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
154 void DDSFox_StopSweep(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
155 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
156 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 sprintf(Request,"set;%i;%i;%i",1,CMD_STOP_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
159 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
162 void DDSFox_StartSweep(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
163 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
164 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 sprintf(Request,"set;%i;%i;%i",1,CMD_START_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
166 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
167 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
168 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
169
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
170 void DDSFox_SetFreqMax (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
171 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
172 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
173 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
174 convert_double_6char(pow(2,48)/2,octets); // borne sup : clock / 2
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
175 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
176 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
177 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
178 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
179 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
180 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
181
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
182 void DDSFox_SetFreqMin (DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
183 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
184 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
185 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
186 convert_double_6char(1,octets); // borne inf : ~0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
187 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
188 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
189 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
190 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
191 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
192 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
193
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
194 void DDSFox_SetFreqInf (DDSParameter *Param, double frequency)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
195 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
196 double word ;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
197 unsigned char octets[6];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
198 char Request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
199 word = pow(2,48)*(frequency / Param->Clock);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
200 convert_double_6char(word, octets);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
201 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
202 *(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
203 SendCmd(Request, Param);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
204 }
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 void DDSFox_SetFreqSup (DDSParameter *Param, double frequency)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
207 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
208 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
209 unsigned char octets[6];
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
210 char Request[255];
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
211 word = pow(2,48)*(frequency / Param->Clock);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
212 convert_double_6char(word, octets);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
213 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
214 *(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
215 SendCmd(Request, Param);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
216 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
217
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
218 static int GetSweepSign(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
219 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
220 if (Param->SweepRate >= 0.0)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
221 return 0;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
222 return 1;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
223 }
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
224
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
225 void DDSFox_SetSweepSign(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
226 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
227 char Request[255] ;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
228 int SweepSign ;
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
229 SweepSign = GetSweepSign(Param) ;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
230 sprintf(Request, "set;%i;%i;%i", 1, CMD_SWEEP_SIGN, SweepSign);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
231 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
232 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
233 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
234
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
235 void DDSFox_SetDT(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
236 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
237 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
238 int dt= 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
239 char FTW0[255]="0"; /**** sinon le fichier inf.xx est faux ***/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
240 dt = ((Param->Delta_T)/BASE_TIME) - 1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
241 sprintf(FTW0,"%ims",dt);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
242 sprintf(Request,"set;%i;%i;%i;%s",1,CMD_DT, dt ,FTW0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
243 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
244 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
245 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
246
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
247 // 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
248 void DDSFox_SetDiv(DDSParameter *Param, int div)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
249 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
250 char Request[255];
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
251 Command Rd;
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
252 char temp;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
253
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
254 int Div = 0;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
255 // Div = log2(div)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
256 while ((div >>= 1) > 1)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
257 Div++;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
258
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
259 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
260 sprintf(Request,"get;%i;%i",1,CMD_CONFIG_REG2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
261 if (RecvCmd(&Rd, Request, Param) < 0)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
262 return;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
263 temp = atoi(Rd.value2) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
264 temp = temp & 0x9F ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
265 temp = temp | Div << 5 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
266 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
267 atoi(Rd.value1),temp,atoi(Rd.value3),atoi(Rd.value4)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
268 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
269 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
270 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
271
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
272 void DDSFox_SetDf(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
273 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
274 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
275 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
276 unsigned char *octets;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
277 word = pow(2,48)*(fabs(Param->SweepRate)*Param->Delta_T/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
278 octets=malloc(6*sizeof(unsigned char));
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
279 convert_double_6char(word, octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
280 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_DF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
281 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
282 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
283 free(octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
284 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
285 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
286
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
287 double DDSFox_ReadFreq(DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
288 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
289 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
290 unsigned int OctetA, OctetB, OctetC, OctetD, OctetE, OctetF ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
291 double FreqRead ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
292 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
293 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
294 sprintf(Request,"get;%i;%i",1,CMD_GET_FREQ);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
295 if (RecvCmd(&Rd, Request, Param) == -1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
296 return -1.;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
297 OctetA=atoi(Rd.value0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
298 OctetB=atoi(Rd.value1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
299 OctetC=atoi(Rd.value2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
300 OctetD=atoi(Rd.value3);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
301 OctetE=atoi(Rd.value4);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
302 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
303 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
304 FreqRead = FreqRead * Param->Clock / pow(2,48);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
305 return(FreqRead);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
306 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
307
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
308 // TCP communication
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
309
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
310 static unsigned int timeout = 0; // milliseconds
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
311
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
312 int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
313 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
314 return 0;
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
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
317 static int SendCmd(char *Buffer, DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
318 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
319 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
320 char Response[255];
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
321 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
322 fprintf(stderr, "> %s\n", Buffer);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
323 #endif
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
324 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
325 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
326 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
327 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
328 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
329 error("Write failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
330 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
331 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
332 sprintf(Response," ");
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
333 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
334 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
335 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
336 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
337 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
338 fprintf(stderr, "< %s\n", Response);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
339 #endif
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
340 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
341 error("Response failed %s %s", Buffer, Response);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
342 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
343 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
344 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
345 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
346
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
347 static int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
348 {
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
349 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
350 char parsebuf[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
351 char Response[255];
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
352 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
353 fprintf(stderr, "> %s\n", Buffer);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
354 #endif
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
355 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, timeout) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
356 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
357 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
358 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
359 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
360 error("Write failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
361 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
362 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
363 sprintf(Response," ");
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
364 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
365 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
366 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
367 }
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
368 #ifdef DEBUG
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
369 fprintf(stderr, "< %s\n", Response);
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
370 #endif
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
371 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
372 error("Response failed %s %s", Buffer, Response);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
373 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
374 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
375
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
376 sprintf(parsebuf,"%s",Response) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
377 parse_command(Rd, parsebuf) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
378 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
379 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
380
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
381 static void init_command(Command *cmd)
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
382 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
383 memset(cmd, 0, sizeof(Command));
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
384 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
385
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
386 static int parse_command(Command *cmd1, char *buf)
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
387 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
388 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
389 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
390
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
391 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
392 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
393 if( c == 0 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
394 cmd1->action = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
395 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
396 else if( c == 1 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
397 cmd1->canal = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
398 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
399 else if( c == 2 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
400 cmd1->command = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
401 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
402 else if( c == 3 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
403 cmd1->value0 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
404 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
405 else if( c == 4 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
406 cmd1->value1 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
407 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
408 else if( c == 5 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
409 cmd1->value2 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
410 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
411 else if( c == 6 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
412 cmd1->value3 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
413 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
414 else if( c == 7 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
415 cmd1->value4 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
416 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
417 else if( c == 8 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
418 cmd1->value5 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
419 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
420 else if( c == 9 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
421 cmd1->value6 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
422 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
423 else if( c == 10 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
424 cmd1->value7 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
425 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
426 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
427 c++;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
428 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
429 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
430 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
431
68
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
432 // 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
433 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
434 {
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
435 // 64 bits integer
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
436 unsigned long long x = fraction;
64a7a1d3d75c Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 63
diff changeset
437 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
438 octets[i] = (unsigned char)((x >> (i * 8)) & 0xFF);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
439 }