# HG changeset patch # User Daniele Nicolodi # Date 1393004252 -3600 # Node ID d96f0b04f7fec7bbf70c0ed8fb300efd3ee65c5b # Parent 24ab61179ab5544df4d4d6273df48b544c80afbb Make DDS addres configurable in configuration file. Modernize AD9912 driver. diff -r 24ab61179ab5 -r d96f0b04f7fe DDS4xAD9912.c --- a/DDS4xAD9912.c Mon Feb 17 18:39:36 2014 +0100 +++ b/DDS4xAD9912.c Fri Feb 21 18:37:32 2014 +0100 @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,19 +7,17 @@ #include "DDS4xAD9912.h" -static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) +void DDS4xAD9912_Init(DDS4xAD9912_Data *dds, const char *host, double clock) { - switch(xType) - { - case TCP_DISCONNECT: - break; - case TCP_DATAREADY: - ClientTCPRead(handle, Response, sizeof(Response), 0); - break; - } - return 0; + memset(dds, 0, sizeof(DDS4xAD9912_Data)); + dds->port[0] = 6665; + dds->port[1] = 6666; + dds->port[2] = 6667; + dds->port[3] = 6668; + dds->host = StrDup(host); + dds->clock = clock; } - + //============================================================================== // DDS4xAD9912_SendCmd @@ -28,40 +27,18 @@ // 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) +static int DDS4xAD9912_SendCmd(DDS4xAD9912_Data *dds, int channel, 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; - } + unsigned int sock; - rv = ConnectToTCPServer(&hConv, port, Adress, OnTCPEvent, 0, 0); - if (rv < 0) { - MessagePopup("DDS4xAD9912", "Connection to server failed!"); + rv = ConnectToTCPServer(&sock, dds->port[channel - 1], dds->host, NULL, 0, 0); + if (rv < 0) return rv; - } - rv = ClientTCPWrite(hConv, Buffer, strlen(Buffer)+1, 0); - if (rv < 0) { - MessagePopup("DDS Serveur", "Write to server failed!"); - } + rv = ClientTCPWrite(sock, buffer, strlen(buffer) + 1, 0); - DisconnectFromTCPServer(hConv); + DisconnectFromTCPServer(sock); return rv; } @@ -74,23 +51,37 @@ // PARAM : // RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK //============================================================================== - int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance) + int DDS4xAD9912_Reset(DDS4xAD9912_Data *dds) { - int chan, rv; + int channel, rv; + char request[256]; + + sprintf(request, "set;%i;%i", 1, 17); - for (chan = 1; chan < 5; chan++) { - sprintf(Request, "set;%i;%i", 1, 17); - rv = DDS4xAD9912_SendCmd(chan, Request); + for (channel = 1; channel < 5; channel++) { + rv = DDS4xAD9912_SendCmd(dds, channel, request); if (rv < 0) { - MessagePopup("DDS Serveur", "DDS4xAD9912 reset failed"); + MessagePopup("DDS4xAD9912", "Reset failed"); return -1; } - Instance->frequency[chan - 1] = 0.0; + dds->frequency[channel - 1] = 0.0; } return 0; } +/* convert 64 bit integer into 6 bytes array */ +static inline void tobytes(unsigned long long x, unsigned char* bytes) +{ + /* 64 bits integer */ + for (int i = 0; i < 6; i++) + bytes[i] = (unsigned char)((x >> (i * 8)) & 0xFF); +} + + +#define WORD(freq, clock) ((double)(1ULL << 48) * (freq / clock)) + + //============================================================================== // DDS4xAD9912_SetFreq // @@ -98,37 +89,30 @@ // 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 DDS4xAD9912_SetFrequency(DDS4xAD9912_Data *dds, int channel, double frequency) +{ int rv; - unsigned char b5,b4,b3,b2,b1,b0 ; + char request[256]; + unsigned char b[6]; + unsigned long long ftw = WORD(frequency, dds->clock); + + tobytes(ftw, b); - 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) ; + sprintf(request, "set;%i;%i;%i;%i;%i;%i;%i;%i", 0, 10, b[5], b[4], b[3], b[2], b[1], b[0]); + rv = DDS4xAD9912_SendCmd(dds, channel, request); if (rv < 0) { - MessagePopup("DDS Serveur", "SetFrequency function failed !"); + MessagePopup("DDS", "SetFrequency function failed"); return -1; } - sprintf(Request,"set;%i;%i",0,18); - rv = DDS4xAD9912_SendCmd(DDSNum, Request) ; + sprintf(request, "set;%i;%i", 0, 18); + rv = DDS4xAD9912_SendCmd(dds, channel, request) ; if (rv < 0) { - MessagePopup("DDS Serveur", "IO_Update function failed !"); + MessagePopup("DDS", "IOUpdate function failed"); return -1; } - Instance->frequency[DDSNum - 1] = Freq - reste * Clk / E48; + dds->frequency[channel - 1] = (double)ftw * dds->clock / (double)(1ULL << 48); return 0; } diff -r 24ab61179ab5 -r d96f0b04f7fe DDS4xAD9912.h --- a/DDS4xAD9912.h Mon Feb 17 18:39:36 2014 +0100 +++ b/DDS4xAD9912.h Fri Feb 21 18:37:32 2014 +0100 @@ -1,70 +1,24 @@ -//============================================================================== -// -// Title: DDS4xAD9912.h -// Purpose: -// -// Created on: by Volodimer Laurent, modified by YLC -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - #ifndef __DDS4XAD9912_H__ #define __DDS4XAD9912_H__ +typedef struct { + char *host; + int port[4]; + double clock; + double frequency[4]; +} DDS4xAD9912_Data; + #ifdef __cplusplus extern "C" { #endif -//============================================================================== -// Include files - -#include "cvidef.h" - -//============================================================================== -// Defines - -#define Adress "145.238.205.55" -#define Port1 6665 -#define Port2 6666 -#define Port3 6667 -#define Port4 6668 -#define Clk 1000000000 -#define E48 281474976710656.0 -#define E40 1099511627776.0 -#define E32 4294967296.0 -#define E24 16777216.0 -#define E16 65536.0 -#define E8 256.0 - -//============================================================================== -// Macros - -#define WORD(Freq,Clk) pow(2,48)*(Freq/Clk) - -// DDS4xAD9912_Data : the data of crypto class DDS4xAD9912 - -typedef struct { - double frequency[4]; -} DDS4xAD9912_Data ; - -//============================================================================== -// Variables - -char Request[255]; -char Response[255]; -unsigned int hConv; - - -//============================================================================== -// Functions - double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel); +void DDS4xAD9912_Init(DDS4xAD9912_Data *d, const char *host, double clock); int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq); int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance); int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f2, double fstep); int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep); - #ifdef __cplusplus } #endif diff -r 24ab61179ab5 -r d96f0b04f7fe FXAnalyse.c --- a/FXAnalyse.c Mon Feb 17 18:39:36 2014 +0100 +++ b/FXAnalyse.c Fri Feb 21 18:37:32 2014 +0100 @@ -358,6 +358,7 @@ mupDefineVar(parser, "Sign2", &Sign2); mupDefineVar(parser, "Sign3", &Sign3); mupDefineVar(parser, "Ndiv", &Ndiv); + mupDefinePostfixOprt(parser, "P", &Peta, 1); mupDefinePostfixOprt(parser, "T", &Tera, 1); mupDefinePostfixOprt(parser, "G", &Giga, 1); @@ -383,6 +384,9 @@ int rv; double frequency; char expr[1024]; + char host[256]; + int port; + double clock; if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0) return -1; @@ -402,16 +406,15 @@ // data folder rv = Ini_GetStringCopy(configuration, "data", "folder", &datafolder); - if (rv <= 0) { + if (rv > 0) { + logmessage(INFO, "writing data files in %s", datafolder); + } else { logmessage(ERROR, "data folder not configured in %s", path); // do not allow to start the acquisition SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE); } - // get AD9956 configuration parameters - char host[256]; - int port; - double clock; + // AD9956 configuration parameters rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host)); if (! rv) return -1; @@ -422,16 +425,19 @@ if (! rv) return -1; - // dispose configuration - Ini_Dispose(configuration); - - // Sr data logger - sr_datalogger_init(&datalogger); - // dedrift DDS DDSFox_Initialize(&DDS1xAD9956, host, port, dedrift.freq0); - // initialize 4x AD9959 DDS box + // AD9912 configuration parameters + rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host)); + if (! rv) + return -1; + rv = Ini_GetDouble(configuration, "AD9912", "clock", &clock); + if (! rv) + return -1; + + // initialize 4x AD9912 DDS box + DDS4xAD9912_Init(&DDS4xAD9912, host, clock); DDS4xAD9912_Reset(&DDS4xAD9912); GetCtrlVal(MainPanel, PANEL_DDS1, &frequency); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, frequency); @@ -442,6 +448,12 @@ GetCtrlVal(MainPanel, PANEL_DDS4, &frequency); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, frequency); + // dispose configuration + Ini_Dispose(configuration); + + // Sr data logger + sr_datalogger_init(&datalogger); + GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1); GetCtrlVal(MainPanel, PANEL_N2CHOICE, &N2); GetCtrlVal(MainPanel, PANEL_N3CHOICE, &N3);