nios temp (#557)

* fixed temp read nios

* divide for eiger and dont print
This commit is contained in:
Dhanya Thattil
2022-10-18 15:47:23 +02:00
committed by GitHub
parent 4a7cd051c1
commit 46bb9bc2d7
22 changed files with 171 additions and 100 deletions

View File

@ -68,3 +68,5 @@ int createEmptyFile(char *mess, char *fname, char *errorPrefix);
int deleteFile(char *mess, char *fname, char *errorPrefix);
int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix);
int readADCFromFile(char *fname, int *value);

View File

@ -378,7 +378,9 @@ void setPower(enum DACINDEX ind, int val);
void powerOff();
#endif
#if !defined(MOENCHD) && !defined(MYTHEN3D) && !defined(GOTTHARD2D)
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
int getADC(enum ADCINDEX ind, int *value);
#elif !defined(MOENCHD)
int getADC(enum ADCINDEX ind);
#endif

View File

@ -701,3 +701,38 @@ int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix) {
}
return OK;
}
int readADCFromFile(char *fname, int *value) {
LOG(logDEBUG1, ("fname:%s\n", fname));
// open file
FILE *fd = fopen(fname, "r");
if (fd == NULL) {
LOG(logERROR, ("Could not open file for reading [%s]\n", fname));
return FAIL;
}
const size_t LZ = 256;
char line[LZ];
memset(line, 0, LZ);
if (NULL == fgets(line, LZ, fd)) {
LOG(logERROR, ("Could not read from file %s\n", fname));
*value = -1;
return FAIL;
}
*value = -1;
if (sscanf(line, "%d", value) != 1) {
LOG(logERROR, ("Could not scan temperature from %s\n", line));
return FAIL;
}
#ifdef EIGERD
*value /= 10;
#else
LOG(logINFO, ("Temperature: %.2f °C\n", (double)(*value) / 1000.00));
#endif
fclose(fd);
return OK;
}

View File

@ -1375,13 +1375,18 @@ int get_adc(int file_des) {
if (receiveData(file_des, &ind, sizeof(ind), INT32) < 0)
return printSocketReadError();
#if defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
#if defined(MOENCHD)
functionNotImplemented();
#else
enum ADCINDEX serverAdcIndex = 0;
// get
switch (ind) {
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
case TEMPERATURE_FPGA:
serverAdcIndex = TEMP_FPGA;
break;
#endif
#if defined(GOTTHARDD) || defined(JUNGFRAUD)
case TEMPERATURE_FPGA:
serverAdcIndex = TEMP_FPGA;
@ -1481,8 +1486,18 @@ int get_adc(int file_des) {
// valid index
if (ret == OK) {
LOG(logDEBUG1, ("Getting ADC %d\n", serverAdcIndex));
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
ret = getADC(serverAdcIndex, &retval);
if (ret == FAIL) {
strcpy(mess, "Could not get temperature\n");
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("ADC(%d): %d\n", serverAdcIndex, retval));
}
#else
retval = getADC(serverAdcIndex);
LOG(logDEBUG1, ("ADC(%d): %d\n", serverAdcIndex, retval));
#endif
}
#endif
@ -1882,55 +1897,57 @@ int acquire(int blocking, int file_des) {
#ifdef EIGERD
// check for hardware mac and hardware ip
if (udpDetails[0].srcmac != getDetectorMAC()) {
ret = FAIL;
uint64_t sourcemac = getDetectorMAC();
char src_mac[MAC_ADDRESS_SIZE];
getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac);
sprintf(mess,
ret = FAIL;
uint64_t sourcemac = getDetectorMAC();
char src_mac[MAC_ADDRESS_SIZE];
getMacAddressinString(src_mac, MAC_ADDRESS_SIZE, sourcemac);
sprintf(
mess,
"Invalid udp source mac address for this detector. Must be "
"same as hardware detector mac address %s\n",
src_mac);
LOG(logERROR, (mess));
} else if (!enableTenGigabitEthernet(GET_FLAG) &&
(udpDetails[0].srcip != getDetectorIP())) {
ret = FAIL;
uint32_t sourceip = getDetectorIP();
char src_ip[INET_ADDRSTRLEN];
getIpAddressinString(src_ip, sourceip);
sprintf(
mess,
"Invalid udp source ip address for this detector. Must be "
"same as hardware detector ip address %s in 1G readout mode \n",
src_ip);
LOG(logERROR, (mess));
} else
#endif
if (configured == FAIL) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because ");
strcat(mess, configureMessage);
LOG(logERROR, (mess));
} else if (sharedMemory_getScanStatus() == RUNNING) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because a scan is "
"already running!\n");
LOG(logERROR, (mess));
} else {
memset(scanErrMessage, 0, MAX_STR_LENGTH);
sharedMemory_setScanStop(0);
sharedMemory_setScanStatus(IDLE); // if it was error
if (pthread_create(&pthread_tid, NULL, &start_state_machine,
&blocking)) {
LOG(logERROR, (mess));
} else if (!enableTenGigabitEthernet(GET_FLAG) &&
(udpDetails[0].srcip != getDetectorIP())) {
ret = FAIL;
strcpy(mess, "Could not start acquisition thread!\n");
uint32_t sourceip = getDetectorIP();
char src_ip[INET_ADDRSTRLEN];
getIpAddressinString(src_ip, sourceip);
sprintf(
mess,
"Invalid udp source ip address for this detector. Must be "
"same as hardware detector ip address %s in 1G readout "
"mode \n",
src_ip);
LOG(logERROR, (mess));
} else
#endif
if (configured == FAIL) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because ");
strcat(mess, configureMessage);
LOG(logERROR, (mess));
} else if (sharedMemory_getScanStatus() == RUNNING) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because a scan is "
"already running!\n");
LOG(logERROR, (mess));
} else {
// only does not wait for non blocking and scan
if (blocking || !scan) {
pthread_join(pthread_tid, NULL);
memset(scanErrMessage, 0, MAX_STR_LENGTH);
sharedMemory_setScanStop(0);
sharedMemory_setScanStatus(IDLE); // if it was error
if (pthread_create(&pthread_tid, NULL, &start_state_machine,
&blocking)) {
ret = FAIL;
strcpy(mess, "Could not start acquisition thread!\n");
LOG(logERROR, (mess));
} else {
// only does not wait for non blocking and scan
if (blocking || !scan) {
pthread_join(pthread_tid, NULL);
}
}
}
}
}
return Server_SendResult(file_des, INT32, NULL, 0);
}
@ -2011,7 +2028,6 @@ void *start_state_machine(void *arg) {
break;
}
#if defined(CHIPTESTBOARDD) || defined(MOENCHD)
readFrames(&ret, mess);
if (ret == FAIL && scan) {
@ -2019,7 +2035,7 @@ void *start_state_machine(void *arg) {
strcat(scanErrMessage, mess);
sharedMemory_setScanStatus(ERROR);
break;
}
}
#endif
// blocking or scan
if (*blocking || times > 1) {