Skip to content

Commit

Permalink
Init resync server
Browse files Browse the repository at this point in the history
  • Loading branch information
rp_local committed Sep 24, 2024
1 parent ed6f101 commit d820174
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/server/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sequenceData_t * allocSequence() {
seq->enableLUT = NULL;
seq->rampUp = NULL;
seq->rampDown = NULL;
seq->resyncLUT = NULL;
return seq;
}

Expand All @@ -66,6 +67,10 @@ void freeSequence(sequenceData_t *seqData) {
freeRamping(seqData->rampDown);
seqData->rampDown = NULL;
}
if (seqData->resyncLUT != NULL) {
free(seqData->resyncLUT);
seqData->resyncLUT = NULL;
}
}

rampingData_t * allocRamping() {
Expand Down Expand Up @@ -120,6 +125,15 @@ bool getSequenceEnableValue(sequenceData_t *seqData, int seqStep, int channel) {
return result;
}

bool getSequenceResyncValue(sequenceData_t *seqData, int seqStep, int channel) {
bool result = false;
if (seqData->resyncLUT != NULL) {
int localStep = seqStep % seqData->numStepsPerRepetition;
result = seqData->resyncLUT[localStep + channel];
}
return result;
}

float getRampingValue(rampingData_t *rampData, int rampStep, int channel) {
int localStep = rampStep % rampData->numStepsPerRepetition;
return rampData->LUT[localStep * numSlowDACChan + channel];
Expand Down Expand Up @@ -216,6 +230,7 @@ static void setLUTValuesFor(int futureStep, int channel, int currPDMIndex) {
float val = 0.0;
bool enable = true;
bool rampDown = false;
bool resync = false;

switch(interval) {
case RAMPUP:
Expand All @@ -224,6 +239,7 @@ static void setLUTValuesFor(int futureStep, int channel, int currPDMIndex) {
case REGULAR:
val = getSequenceValue(activeSequence, localStep, channel);
enable = getSequenceEnableValue(activeSequence, localStep, channel);
resync = getSequenceResyncValue(activeSequence, localStep, channel);
break;
case RAMPDOWN:
val = getRampingValue(activeSequence->rampDown, localStep, channel);
Expand All @@ -240,6 +256,9 @@ static void setLUTValuesFor(int futureStep, int channel, int currPDMIndex) {
printf("Could not set AO[%d] voltage.\n", channel);
}
setEnableDAC(enable, channel, currPDMIndex);
if (channel < 2) {
setResyncDAC(resync, channel, currPDMIndex);
}
setRampDownDAC(rampDown, channel, currPDMIndex);

}
Expand Down
2 changes: 2 additions & 0 deletions src/server/daq_server_scpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef struct {
int numStepsPerRepetition; // How many steps per repetition
float* LUT; // LUT for value function pointer
bool * enableLUT;
bool * resyncLUT;
rampingData_t* rampUp;
rampingData_t* rampDown;
} sequenceData_t;
Expand All @@ -131,6 +132,7 @@ extern sequenceInterval_t computeInterval(sequenceData_t *seqData, int step);
extern bool isSequenceConfigurable();
extern float getSequenceValue(sequenceData_t *seqData, int seqStep, int channel);
extern bool getSequenceEnableValue(sequenceData_t *seqData, int seqStep, int channel);
extern bool getSequenceResyncValue(sequenceData_t *seqData, int seqStep, int channel);
extern float getRampingValue(rampingData_t *rampData, int rampStep, int channel);
extern int getRampUpSteps(sequenceData_t *seqData);
extern int getRampDownSteps(sequenceData_t *seqData);
Expand Down
26 changes: 26 additions & 0 deletions src/server/scpi_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,31 @@ static scpi_result_t RP_DAC_SetEnableLUT(scpi_t * context) {
}
}

static scpi_result_t RP_DAC_SetResyncLUT(scpi_t * context) {

readyConfigSequence();

if(configSeq->LUT != NULL && numSlowDACChan > 0 && isSequenceConfigurable()) {
if(configSeq->resyncLUT != NULL) {
free(configSeq->resyncLUT);
configSeq->resyncLUT = NULL;
}

int numChan = numSlowDACChan > 2 ? 2 : numSlowDACChan;
printf("Allocating ressyncLUT\n");
configSeq->resyncLUT = (bool *)calloc(numChan, configSeq->numStepsPerRepetition * sizeof(bool));

int n = readAll(newdatasockfd, configSeq->resyncLUT, numSlowDACChan * configSeq->numStepsPerRepetition * sizeof(bool));
seqState = CONFIG;
if (n < 0) perror("ERROR reading from socket");
return returnSCPIBool(context, true);
}
else {
return returnSCPIBool(context, false);
}

}

static scpi_result_t RP_DAC_SetUpLUT(scpi_t * context) {

readyConfigSequence();
Expand Down Expand Up @@ -1739,6 +1764,7 @@ const scpi_command_t scpi_commands[] = {
{.pattern = "RP:DAC:SEQ:CHan?", .callback = RP_DAC_GetNumSlowDACChan,},
{.pattern = "RP:DAC:SEQ:LUT", .callback = RP_DAC_SetValueLUT,},
{.pattern = "RP:DAC:SEQ:LUT:ENaBle", .callback = RP_DAC_SetEnableLUT,},
{.pattern = "RP:DAC:SEQ:LUT:ReSYNC", .callback = RP_DAC_SetResyncLUT,},
{.pattern = "RP:DAC:SEQ:LUT:UP", .callback = RP_DAC_SetUpLUT,},
{.pattern = "RP:DAC:SEQ:LUT:DOWN", .callback = RP_DAC_SetDownLUT,},
{.pattern = "RP:DAC:SEQ:SET", .callback = RP_DAC_SetSequence,},
Expand Down

0 comments on commit d820174

Please sign in to comment.