From 7dabc43dcf4ad506a9b1ca58e29161773abf0600 Mon Sep 17 00:00:00 2001
From: Juan David Gonzalez Cobas <dcobas@cern.ch>
Date: Thu, 18 Aug 2016 15:59:53 +0200
Subject: [PATCH] application of patch from nmagnin

This is a cleaned up version of the modifications added by Nicolas
Magning to the AC Dipole library.

    From 7be18db35c8b51cb0d9c280b8e43ac78335aad64 Mon Sep 17 00:00:00 2001
    From: Michel Arruat <michel.arruat@cern.ch>
    Date: Thu, 18 Feb 2016 17:38:13 +0100
    [PATCH] From Nicolas Magnin: support for individual reference file's
    amplifier. Up to now, the library was suported only similar amplifiers
    (sharing the same reference file). Now each amplifier has its own
    reference file.

Signed-off-by: Michel Arruat <michel.arruat@cern.ch>
---
 acdx/lib/libacdx.c |  8 ++++++--
 acdx/lib/libacdx.h | 56 ++++++++++++++++++++++++++++--------------------------
 acdx/lib/libamp.c  | 18 +++++++++++-------
 3 files changed, 46 insertions(+), 36 deletions(-)
---
 acdx/lib/libacdx.c |  8 ++++++--
 acdx/lib/libacdx.h |  6 ++++--
 acdx/lib/libamp.c  | 16 ++++++++++------
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/acdx/lib/libacdx.c b/acdx/lib/libacdx.c
index c4a2c18c..3dbcff47 100644
--- a/acdx/lib/libacdx.c
+++ b/acdx/lib/libacdx.c
@@ -184,8 +184,10 @@ AcdxLibCompletion AcdxLibInit() {
 
 /* ================================================ */
 
-AcdxLibCompletion AcdxLoadFunction(unsigned int f,   /* Frequency in Hertz */
-				   unsigned int a) { /* Amplitude in Milli-Volts */
+AcdxLibCompletion AcdxLoadFunction(
+					unsigned int f,      /* Frequency in Hertz */
+					unsigned int a,     /* Amplitude in Milli-Volts */
+					unsigned int ft) {  /* ftop in Milli-Seconds */
 
    if (AcdxLibInit() == AcdxLibOK) {
 
@@ -193,6 +195,8 @@ AcdxLibCompletion AcdxLoadFunction(unsigned int f,   /* Frequency in Hertz */
       else   freq = 3000;
       if (a) ampl = a;
       else   ampl = 500;
+      if (ft) ftop = ft * 1000; // ft in ms
+      else   ftop = 200000;
 
       SinWave();
       if (PutFunc()) return AcdxLibOK;
diff --git a/acdx/lib/libacdx.h b/acdx/lib/libacdx.h
index a00424c1..7c96456c 100644
--- a/acdx/lib/libacdx.h
+++ b/acdx/lib/libacdx.h
@@ -9,8 +9,10 @@ typedef enum {
  } AcdxLibCompletion;
 
 
-AcdxLibCompletion AcdxLoadFunction(unsigned int freq,         /* Frequency in Hertz */
-				   unsigned int ampl);        /* Amplitude in Milli-Volts */
+AcdxLibCompletion AcdxLoadFunction(
+                  unsigned int freq,         /* Frequency in Hertz */
+                  unsigned int ampl,       /* Amplitude in Milli-Volts */
+                  unsigned int ftop);       /* Flat-Top Width in Milli-Seconds */
 
 AcdxLibCompletion AcdxArm();      /* Arm */
 
diff --git a/acdx/lib/libamp.c b/acdx/lib/libamp.c
index e47e72ee..8b4f54c7 100644
--- a/acdx/lib/libamp.c
+++ b/acdx/lib/libamp.c
@@ -331,7 +331,7 @@ char *cp;
    cp = GetRouteName(GetFile("AmpDevice"));
    if ((cp == NULL) || (*cp == '.')) cp = DEFAULT_AMP_DEVICE;
 
-   fprintf(stderr,"libamp:Opening:AmpDevice:%s",cp);
+   fprintf(stderr,"libamp:Opening:AmpDevice:%s\n",cp);
 
    if ((amp = open(cp,O_RDWR|O_SYNC|O_NDELAY,0)) > 0) {
       if (SetOptions(19200,8,"None","1",0,0) > 0) return amp;
@@ -352,7 +352,7 @@ char *cp;
 
    tcflush(amp, TCIOFLUSH);
    if (close(amp) != 0) {
-      fprintf(stderr,"libamp:Error:Closing:AmpDevice:%s",cp);
+      fprintf(stderr,"libamp:Error:Closing:AmpDevice:%s\n",cp);
       perror("close");
    }
    AmpOpen();
@@ -630,7 +630,7 @@ char param[6];
 
 // ====================================================
 
-static int CompareParamsFile(int blk) {
+static int CompareParamsFile(int blk, int ampId) {
 
 FILE *fp;
 int i, len, cc, bad;
@@ -644,6 +644,7 @@ char *cp;
 
    cp = GetFile("RefAmpDspBin");
    sprintf(path,"%s%d",path,blk);
+   sprintf(path,"%s_%d",path,ampId);
 
    umask(0);
    fp = fopen(path,"r");
@@ -697,7 +698,7 @@ int ReadStatBlk() {
 
 // ====================================================
 
-int CompareStatusFile() {
+int CompareStatusFile(int ampId) {
 
 FILE *fp;
 int cc;
@@ -706,6 +707,9 @@ char *cp;
 AmpStatus *ref;
 
    cp = GetFile("RefAmpStatus");
+
+   sprintf(path,"%s_%d",path,ampId);
+
    umask(0);
    fp = fopen(path,"r");
    if (fp == NULL) {
@@ -863,10 +867,10 @@ int i, blk, bad;
       sprintf(Id,"%02X",i);
       for (blk=0; blk<3; blk++) {
 	 if (GetDspParams(blk) == 0) bad++;
-	 if (CompareParamsFile(blk) == 0) bad++;
+	 if (CompareParamsFile(blk, i) == 0) bad++;
       }
       if (ReadStatBlk() == 0) bad++;
-      if (CompareStatusFile() == 0) bad++;
+      if (CompareStatusFile(i) == 0) bad++;
    }
    AmpUnBlock();
 
-- 
GitLab