Mercurial > hg > fxanalyse
view DDS4xAD9912.c @ 146:931ebae87964
Tweaks to FakeDataProvider
Make generated counter data more realistic. Add the possibility to add noise
to the generated data. Make the sampling period easier to change.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 14:45:24 +0100 |
parents | fd085d61e4ca |
children | d96f0b04f7fe |
line wrap: on
line source
#include <ansi_c.h> #include <utility.h> #include <userint.h> #include <tcpsupp.h> #include "DDS4xAD9912.h" static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) { switch(xType) { case TCP_DISCONNECT: break; case TCP_DATAREADY: ClientTCPRead(handle, Response, sizeof(Response), 0); break; } return 0; } //============================================================================== // DDS4xAD9912_SendCmd // // FUNC : envoie une chaine de caracteres sur un port du serveur TCP/IP de la foxboard // PARAM : DDSNum contient le numero de la DDS (1,2,3 ou 4) // 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; int rv; switch (DDSNum) { case 1: port = Port1; break; case 2: port = Port2; break; case 3: port = Port3; break; case 4: port = Port4; break; default: return -1; } rv = ConnectToTCPServer(&hConv, port, Adress, OnTCPEvent, 0, 0); if (rv < 0) { MessagePopup("DDS4xAD9912", "Connection to server failed!"); return rv; } rv = ClientTCPWrite(hConv, Buffer, strlen(Buffer)+1, 0); if (rv < 0) { MessagePopup("DDS Serveur", "Write to server failed!"); } DisconnectFromTCPServer(hConv); return rv; } //============================================================================== // DDS4xAD9912_Reset // // FUNC : reset des 4 DDS // PARAM : // RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK //============================================================================== int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance) { int chan, rv; 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; } Instance->frequency[chan - 1] = 0.0; } return 0; } //============================================================================== // DDS4xAD9912_SetFreq // // FUNC : sort une fréquence sur la DDS1 ,DDS2, DDS3 ou DDS4 // PARAM : DDSNum contient le numero de la DDS (1, 2 , 3 ou 4) // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK //============================================================================== int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq) { double Word=WORD(Freq,Clk) ; double reste ; int rv; unsigned char b5,b4,b3,b2,b1,b0 ; b5=(unsigned char)(Word/E40); b4=(unsigned char)((Word - E40*b5)/E32); b3=(unsigned char)((Word - E40*b5 - E32*b4)/E24); b2=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3)/E16); b1=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2)/E8); b0=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2 - E8*b1)/1.0); 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); 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; } /* * ramp DDS frequency from `f1` to `f2` in steps of `fstep` * with a delay of 0.01 seoconds after each step */ int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep) { const double delay = 0.01; /* f2 > f1 */ while ((f2 - f1) > fstep) { f1 += fstep; DDS4xAD9912_SetFrequency(dds, channel, f1); Delay(delay); } /* f2 < f1 */ while ((f1 - f2) > fstep) { f1 -= fstep; DDS4xAD9912_SetFrequency(dds, channel, f1); Delay(delay); } /* final adjustment */ DDS4xAD9912_SetFrequency(dds, channel, f2); return 0; } /* * ramp DDS frequency from the current frequency to `f2` in steps * of `fstep` with a delay of 0.01 seoconds after each step */ int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f2, double fstep) { double f1 = DDS4xAD9912_GetFrequency(dds, channel); return DDS4xAD9912_RampFrequency2(dds, channel, f1, f2, fstep); } double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel) { return dds->frequency[channel - 1]; }