Mercurial > hg > fxanalyse
diff DDS4xAD9912.c @ 142:fd085d61e4ca
Rework data logging
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 14:45:23 +0100 |
parents | 43b35f4aae78 |
children | d96f0b04f7fe |
line wrap: on
line diff
--- a/DDS4xAD9912.c Wed Jan 22 14:45:22 2014 +0100 +++ b/DDS4xAD9912.c Wed Jan 22 14:45:23 2014 +0100 @@ -1,38 +1,23 @@ +#include <ansi_c.h> #include <utility.h> - -//============================================================================== -// -// Title: DDS4xAD9912.c -// Purpose: -// -// Created on: by Volodimer Laurent, modified by YLC -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - -//============================================================================== -// Include files - -#include "DDS4xAD9912.h" #include <userint.h> #include <tcpsupp.h> -#include <ansi_c.h> -//============================================================================== -// Global functions +#include "DDS4xAD9912.h" + static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) - { +{ switch(xType) - { - case TCP_DISCONNECT : + { + case TCP_DISCONNECT: break; - case TCP_DATAREADY : - ClientTCPRead (handle, Response, sizeof(Response), 0); + case TCP_DATAREADY: + ClientTCPRead(handle, Response, sizeof(Response), 0); break; - } - return 0; } + return 0; +} //============================================================================== @@ -43,8 +28,6 @@ // PARAM : Buffer contenant la chaîne de caractères à envoyer // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK //============================================================================== - - static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) { int port = 0; @@ -91,42 +74,21 @@ // PARAM : // RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK //============================================================================== - int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance) - { - int res_1,res_2; + { + int chan, rv; - sprintf(Request,"set;%i;%i",1,17); - res_1 = DDS4xAD9912_SendCmd(1,Request) ; - if(res_1 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_1 Reset failed !") ; - } - else Instance->Frequency1 = 0.0 ; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4xAD9912_SendCmd(2,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_2 Reset failed !") ; + for (chan = 1; chan < 5; chan++) { + sprintf(Request, "set;%i;%i", 1, 17); + rv = DDS4xAD9912_SendCmd(chan, Request); + if (rv < 0) { + MessagePopup("DDS Serveur", "DDS4xAD9912 reset failed"); + return -1; } - else Instance->Frequency2 = 0.0; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4xAD9912_SendCmd(3,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_3 Reset failed !") ; - } - else Instance->Frequency3 = 0.0; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4xAD9912_SendCmd(4,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_4 Reset failed !") ; - } - else Instance->Frequency4 = 0.0; - - - return (res_1+res_2); - } + Instance->frequency[chan - 1] = 0.0; + } + return 0; +} //============================================================================== @@ -141,7 +103,7 @@ double Word=WORD(Freq,Clk) ; double reste ; - int res_0 ; + int rv; unsigned char b5,b4,b3,b2,b1,b0 ; b5=(unsigned char)(Word/E40); @@ -153,25 +115,22 @@ reste = (Word - E40*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); - res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; - if (res_0 <0) { - MessagePopup("DDS Serveur", "SetFrequency function failed !") ; - } - else { - if (DDSNum==1) Instance->Frequency1 = Freq - reste*Clk/E48 ; - if (DDSNum==2) Instance->Frequency2 = Freq - reste*Clk/E48 ; - if (DDSNum==3) Instance->Frequency3 = Freq - reste*Clk/E48 ; - if (DDSNum==4) Instance->Frequency4 = Freq - reste*Clk/E48 ; - } ; - - sprintf(Request,"set;%i;%i",0,18); // IO_Update logiciel - res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; - if (res_0 <0) { - MessagePopup("DDS Serveur", "IO_Update function failed !") ; - } - return(res_0) ; - - } + rv = DDS4xAD9912_SendCmd(DDSNum, Request) ; + if (rv < 0) { + MessagePopup("DDS Serveur", "SetFrequency function failed !"); + return -1; + } + + sprintf(Request,"set;%i;%i",0,18); + rv = DDS4xAD9912_SendCmd(DDSNum, Request) ; + if (rv < 0) { + MessagePopup("DDS Serveur", "IO_Update function failed !"); + return -1; + } + + Instance->frequency[DDSNum - 1] = Freq - reste * Clk / E48; + return 0; +} /* @@ -215,17 +174,6 @@ double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel) { - switch (channel) { - case 1: - return dds->Frequency1; - case 2: - return dds->Frequency2; - case 3: - return dds->Frequency3; - case 4: - return dds->Frequency4; - default: - return 0.0; - } + return dds->frequency[channel - 1]; }