annotate DDS_Fox.c @ 12:e8cca9555280

Remove "always on top" attribute to main application window
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 16 Jul 2012 13:00:10 +0200
parents adc9e2a67547
children e45d6e9544f5
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 <userint.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include <tcpsupp.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 #include <ansi_c.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include "DDS_Fox.h"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 //#define DDS_IP "192.168.0.3"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 //#define TCP_PORT 6665
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 #define DIV 0 // divided by 1
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10 #define CMD_SEP ";"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11 #define BASE_TIME 0.01
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 #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
14 #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
15 #define CMD_SINGLE_FREQ_PROF0 7
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16 #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
17 #define CMD_ATTENUATION 16
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 #define CMD_RESET_DDS 17
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 #define CMD_NOP 20
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 #define CMD_FREQ_INF 21
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21 #define CMD_FREQ_SUP 22
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22 #define CMD_DF 23
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 #define CMD_DT 24
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 #define CMD_START_SWEEP 25
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 #define CMD_STOP_SWEEP 26
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 #define CMD_GET_FREQ 28
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 #define CMD_SWEEP_SIGN 29
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30 /************************* Global variables ***********************************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31 //static char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
32
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
33 /************************* My own functions ***********************************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
34 /*DDSParameter DDSGetParam (int panel, int control) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
35 DDSParameter Parameter ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
36
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
37 GetCtrlVal (panel, CONTROL_DDS_IP, Parameter->ip) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
38 GetCtrlVal (panel, CONTROL_DDS_PORT, &(Parameter->Port)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
39 GetCtrlVal (panel, CONTROL_DDS_CLOCK, &(Parameter->Clock)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
40 GetCtrlVal (panel, CONTROL_DDS_RATE, &(Parameter->SweepRate)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
41 GetCtrlVal (panel, CONTROL_DDS_DELTA_T, &(Parameter->Delta_T)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
42 return(Parameter);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
43 }*/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
44
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
45
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
46
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
47 void DDS_Initialize (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
48 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
49 //send NOP command
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
50 sprintf(Request,"set;%i;%i",1,CMD_NOP);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
51 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
52 //reset the DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
53 DDSFox_Reset(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
54
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
55 //Set Profile Number 0 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
56 // sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
57 // SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
58
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
59 //Set Profile Number 7 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
60 sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,7);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
61 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
62
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
63
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
64 //Set Clock Divider to 00b (which means 1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
65 DDSFox_SetDiv(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
66 //Set sweep rate at 0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
67 DDSFox_SetFreqMax (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
68 DDSFox_SetFreq (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
69 DDSFox_SetDT (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
70 DDSFox_SetDf (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71 DDSFox_StartSweep (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
72 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
73 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
74
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
75 void DDS_ReInitialize (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
76 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
77 //send NOP command
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
78 sprintf(Request,"set;%i;%i",1,CMD_NOP);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
79 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
80 //reset the DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
81 //DDSFox_Reset(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
82
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
83 //Set Profile Number 0 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
84 // sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
85 // SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
86
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
87 //Set Profile Number 7 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
88 sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,7);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
89 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
90
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
91
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
92 //Set Clock Divider to 00b (which means 1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
93 DDSFox_SetDiv(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
94 //Set sweep rate at 0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
95 DDSFox_SetFreqMax (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
96 DDSFox_SetFreq (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
97 DDSFox_SetDT (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
98 DDSFox_SetDf (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
99 DDSFox_StartSweep (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
101 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
102
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
103
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
104 void DDSFox_Reset(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
105 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
106 sprintf(Request,"set;%i;%i",1,CMD_NOP);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
107 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
108 sprintf(Request,"set;%i;%i",1,CMD_RESET_DDS);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
109 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
110 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
111 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
112
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
113
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
114 void DDSFox_StopSweep(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
115 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
116 sprintf(Request,"set;%i;%i;%i",1,CMD_STOP_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
117 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
118 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
120
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
121
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
122 void DDSFox_StartSweep(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
123 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
124 sprintf(Request,"set;%i;%i;%i",1,CMD_START_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
125 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
126 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
127 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
128
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
129 void DDSFox_SetFreqMax (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
130 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
131 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
132 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
133 convert_double_6char(pow(2,48)/2,octets); // borne sup : clock / 2
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
134 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
135 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
136 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
137 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
138 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
139 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
140
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
141 void DDSFox_SetFreqMin (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
142 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
143 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
144 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
145 convert_double_6char(1,octets); // borne inf : ~0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
146 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
147 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
148 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
149 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
150 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
151 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
152
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
153 void DDSFox_SetFreq (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
154 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
155 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
156 int SweepSign = -1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158 if (Param->Profil == 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
159 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160 convert_double_6char(word, octets); // borne inf : la freq voulu
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
162 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
163 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
164 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 else if(Param->Profil == 7) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
166 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
167 if(SweepSign == 0){ // sweep positif
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
168 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
169 convert_double_6char(word, octets); // borne inf : la freq voulu
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
170 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
171 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
172 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
173 DDSFox_SetFreqMax (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
174 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
175 else { // sweep neg
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
176 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
177 convert_double_6char(word, octets); // borne sup : la freq voulue
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
178 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
179 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
180 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
181 DDSFox_SetFreqMin (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
182 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
183 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
184 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
185 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
186
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
187
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
188 // Change le signe de sweep en frequence. Argument: struct de param de la DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
189 void DDSFox_SetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
190 char Request[255] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
191 int SweepSign ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
192 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
193 sprintf(Request,"set;%i;%i;%i",1,CMD_SWEEP_SIGN, SweepSign) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
194 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
195 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
196 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
197
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
198 /*void DDSFox_SetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
199 char Request[255] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
200 int SweepSign ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
201 if (Param->Profil == 7)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
202 Param->Frequency = DDSFox_ReadFreq(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
203 DDSFox_SetFreq (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
204 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
205 sprintf(Request,"set;%i;%i;%i",1,CMD_SWEEP_SIGN, SweepSign) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
206 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
207 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
208 }*/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
209
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
210
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
211 // Change la valeur de la base pour 'lincrement de frequence (sweep). Argument: delta T x 10ms, retourne rien.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
212 void DDSFox_SetDT(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
213 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
214 int dt= 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
215 char FTW0[255]="0"; /**** sinon le fichier inf.xx est faux ***/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
216 dt = ((Param->Delta_T)/BASE_TIME) - 1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
217 sprintf(FTW0,"%ims",dt);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
218 sprintf(Request,"set;%i;%i;%i;%s",1,CMD_DT, dt ,FTW0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
219 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
220 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
221 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
222
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
223
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
224 // Change le facteur de division de la clock. Argument: facteur de div, retourne rien
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
225 void DDSFox_SetDiv(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
226 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
227 int Div = DIV ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
228 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
229 char temp;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
230 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
231 sprintf(Request,"get;%i;%i",1,CMD_CONFIG_REG2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
232 if (RecvCmd(&Rd, Request, Param) < 0)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
233 return;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
234 temp = atoi(Rd.value2) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
235 temp = temp & 0x9F ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
236 temp = temp | Div << 5 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
237 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
238 atoi(Rd.value1),temp,atoi(Rd.value3),atoi(Rd.value4)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
239 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
240 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
241 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
242
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
243
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
244
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
245 void DDSFox_SetDf(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
246 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
247 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
248 unsigned char *octets;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
249 word = pow(2,48)*(fabs(Param->SweepRate)*Param->Delta_T/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
250 octets=malloc(6*sizeof(unsigned char));
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
251 convert_double_6char(word, octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
252 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_DF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
253 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
254 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
255 free(octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
256 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
257 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
258
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
259 int DDSFox_GetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
260 if (Param->SweepRate >= 0) return(0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
261 else return(1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
262 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
263
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
264
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
265 double DDSFox_ReadFreq(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
266 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
267 unsigned int OctetA, OctetB, OctetC, OctetD, OctetE, OctetF ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
268 double FreqRead ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
269 int cmd[20];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
270 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
271 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
272 sprintf(Request,"get;%i;%i",1,CMD_GET_FREQ);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
273 if (RecvCmd(&Rd, Request, Param) == -1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
274 return -1.;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
275 OctetA=atoi(Rd.value0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
276 OctetB=atoi(Rd.value1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
277 OctetC=atoi(Rd.value2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
278 OctetD=atoi(Rd.value3);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
279 OctetE=atoi(Rd.value4);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
280 OctetF=atoi(Rd.value5);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
281 FreqRead=(double)(1099511627776*OctetA +4294967296*OctetB +16777216*OctetC +65536*OctetD +256*OctetE +OctetF);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
282 FreqRead=(FreqRead*Param->Clock)/ pow(2,48);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
283 //sprintf(parsebuf,"%fMHz",FreqRead/1000000);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
284 return(FreqRead);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
285 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
286
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
287
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
288 /************************ Fonction de communications TCP ******************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
289 static const double timeout = 0.5;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
290
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
291
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
292 int SendCmd(char *Buffer, DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
293 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
294 char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
295 char parsebuf[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
296 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
297 printf("Connect failed\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
298 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
299 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
300 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
301 printf("Write failed\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
302 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
303 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
304 sprintf(Response," ");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
305 if (ClientTCPRead (hConv, Response, 255, 0) < 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
306 printf("Read failed\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
307 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
308 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
309 if (strncmp("OK",Response,2)) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
310 printf("Response failed %s %s\n", Buffer, Response);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
311 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
312 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
313 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
314 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
315
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
316
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
317 int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
318 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
319 char parsebuf[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
320 char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
321 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
322 printf("Connect failed\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
323 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
324 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
325 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
326 printf("Write failed\n");
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," ");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
330 if (ClientTCPRead (hConv, Response, 255, 0) < 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
331 printf("Read failed\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
332 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
333 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
334
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
335 if (strncmp(Buffer,Response,strlen(Buffer))) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
336 printf("Response failed %s %s\n", Buffer, Response);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
337 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
338 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
339
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
340 sprintf(parsebuf,"%s",Response) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
341 parse_command(Rd, parsebuf) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
342 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
343 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
344
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
345
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
346 int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
347 //char* Response = (char*)(callbackData);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
348 //char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
349 //switch(xType) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
350 // case TCP_DISCONNECT :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
351 //printf("Server disconnected\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
352 // break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
353 // case TCP_DATAREADY :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
354 //printf("Server data ready\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
355 //ClientTCPRead (handle, Response, 255, 5);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
356 // break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
357 //}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
358 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
359 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
360
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
361 /************************ Fonction de mise en forme des données pour le transfert ******************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
362
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
363 void parse_command2(int* cmd, char* buf)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
364 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
365 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
366 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
367
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
368 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
369 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
370 if ((c > 2) && ( c < 19 ))
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
371 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
372 cmd[c-3] = atoi(pointer);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
373 printf("%i", cmd[c-3]);
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
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
377 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
378 c++;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
379 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
380 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
381
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
382
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
383 int parse_command(Command *cmd1, char *buf){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
384 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
385 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
386
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
387 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
388 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
389 if( c == 0 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
390 cmd1->action = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
391 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
392 else if( c == 1 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
393 cmd1->canal = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
394 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
395 else if( c == 2 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
396 cmd1->command = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
397 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
398 else if( c == 3 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
399 cmd1->value0 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
400 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
401 else if( c == 4 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
402 cmd1->value1 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
403 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
404 else if( c == 5 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
405 cmd1->value2 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
406 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
407 else if( c == 6 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
408 cmd1->value3 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
409 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
410 else if( c == 7 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
411 cmd1->value4 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
412 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
413 else if( c == 8 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
414 cmd1->value5 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
415 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
416 else if( c == 9 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
417 cmd1->value6 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
418 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
419 else if( c == 10 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
420 cmd1->value7 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
421 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
422 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
423 c++;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
424 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
425 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
426 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
427
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
428
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
429 int init_command(Command *cmd1){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
430 cmd1->action = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
431 cmd1->canal = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
432 cmd1->command = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
433 cmd1->value0 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
434 cmd1->value1 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
435 cmd1->value2 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
436 cmd1->value3 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
437 cmd1->value4 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
438 cmd1->value5 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
439 cmd1->value6 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
440 cmd1->value7 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
441 cmd1->value8 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
442 cmd1->value9 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
443 cmd1->value10 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
444 cmd1->value11 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
445 cmd1->value12 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
446 cmd1->value13 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
447 cmd1->value14 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
448 cmd1->value15 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
449 cmd1->value16 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
450 cmd1->value17 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
451 cmd1->value18 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
452 cmd1->value19 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
453 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
454 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
455
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
456
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
457 //Convert double into 6 bytes sent back by an unsigned char pointer
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
458 int convert_double_6char (double fraction, unsigned char* octets) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
459 double bita, bitb, bitc, bitd, bite, bitf;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
460 bitf= fraction/(1099511627776.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
461 *(octets+5)=(unsigned char)bitf;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
462 bite= (fraction-1099511627776.0*(*(octets+5)))/(4294967296.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
463 *(octets+4)=(unsigned char)bite;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
464 bitd=(fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4)))/( 16777216.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
465 *(octets+3)=(unsigned char)bitd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
466 bitc=(fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4))-16777216.0*(*(octets+3)))/( 65536.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
467 *(octets+2)=(unsigned char)bitc;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
468 bitb= (fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4))-16777216.0*(*(octets+3))-65536*(*(octets+2)))/ 256.0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
469 *(octets+1)=(unsigned char)bitb;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
470 bita= (fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4))-16777216.0*(*(octets+3))-65536*(*(octets+2))-256.0*(*(octets+1)))/ 1.0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
471 *(octets)=(unsigned char)bita;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
472 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
473 }