mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 01:58:00 +02:00
jungfrau server works
This commit is contained in:
@ -1,10 +1,7 @@
|
||||
#ifndef AD9257_H
|
||||
#define AD9257_H
|
||||
|
||||
#include "ansi.h"
|
||||
|
||||
#include "commonServerFunctions.h"
|
||||
#include <stdio.h>
|
||||
#include "commonServerFunctions.h" // blackfin.h, ansi.h
|
||||
|
||||
/* AD9257 ADC DEFINES */
|
||||
#define AD9257_ADC_NUMBITS (24)
|
||||
@ -81,36 +78,36 @@ void setAdc(int addr, int val) {
|
||||
|
||||
u_int32_t codata;
|
||||
codata = val + (addr << 8);
|
||||
printf(" Setting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr);
|
||||
FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr));
|
||||
serializeToSPI(ADC_SPI_REG, codata, ADC_SERIAL_CS_OUT_MSK, AD9257_ADC_NUMBITS,
|
||||
ADC_SERIAL_CLK_OUT_MSK, ADC_SERIAL_DATA_OUT_MSK, ADC_SERIAL_DATA_OUT_OFST);
|
||||
}
|
||||
|
||||
void prepareADC(){
|
||||
printf("\n\nPreparing ADC ... \n");
|
||||
FILE_LOG(logINFOBLUE, ("Preparing ADC:\n"));
|
||||
|
||||
//power mode reset
|
||||
printf("power mode reset:\n");
|
||||
FILE_LOG(logINFO, ("\tPower mode reset\n"));
|
||||
setAdc(AD9257_POWER_MODE_REG,
|
||||
(AD9257_INT_RESET_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK);
|
||||
|
||||
//power mode chip run
|
||||
printf("power mode chip run:\n");
|
||||
FILE_LOG(logINFO, ("\tPower mode chip run\n"));
|
||||
setAdc(AD9257_POWER_MODE_REG,
|
||||
(AD9257_INT_CHIP_RUN_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK);
|
||||
|
||||
//output clock phase
|
||||
printf("output clock phase:\n");
|
||||
FILE_LOG(logINFO, ("\tOutput clock phase\n"));
|
||||
setAdc(AD9257_OUT_PHASE_REG,
|
||||
(AD9257_OUT_CLK_60_VAL << AD9257_OUT_CLK_OFST) & AD9257_OUT_CLK_MSK);
|
||||
|
||||
// lvds-iee reduced , binary offset
|
||||
printf("lvds-iee reduced, binary offset:\n");
|
||||
FILE_LOG(logINFO, ("\tLvds-iee reduced, binary offset\n"));
|
||||
setAdc(AD9257_OUT_MODE_REG,
|
||||
(AD9257_OUT_LVDS_IEEE_VAL << AD9257_OUT_LVDS_OPT_OFST) & AD9257_OUT_LVDS_OPT_MSK);
|
||||
|
||||
// all devices on chip to receive next command
|
||||
printf("all devices on chip to receive next command:\n");
|
||||
FILE_LOG(logINFO, ("\tAll devices on chip to receive next command\n"));
|
||||
setAdc(AD9257_DEV_IND_2_REG,
|
||||
AD9257_CHAN_H_MSK | AD9257_CHAN_G_MSK | AD9257_CHAN_F_MSK | AD9257_CHAN_E_MSK);
|
||||
setAdc(AD9257_DEV_IND_1_REG,
|
||||
@ -118,21 +115,19 @@ void prepareADC(){
|
||||
AD9257_CLK_CH_DCO_MSK | AD9257_CLK_CH_IFCO_MSK);
|
||||
|
||||
// vref 1.33
|
||||
printf("vref 1.33:\n");
|
||||
FILE_LOG(logINFO, ("\tVref 1.33\n"));
|
||||
setAdc(AD9257_VREF_REG,
|
||||
(AD9257_VREF_1_33_VAL << AD9257_VREF_OFST) & AD9257_VREF_MSK);
|
||||
|
||||
// no test mode
|
||||
printf("no test mode:\n");
|
||||
FILE_LOG(logINFO, ("\tNo test mode\n"));
|
||||
setAdc(AD9257_TEST_MODE_REG,
|
||||
(AD9257_NONE_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK);
|
||||
|
||||
#ifdef TESTADC
|
||||
printf("***************************************** *******\n");
|
||||
printf("******* PUTTING ADC IN TEST MODE!!!!!!!!! *******\n");
|
||||
printf("***************************************** *******\n");
|
||||
FILE_LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n");
|
||||
// mixed bit frequency test mode
|
||||
printf("mixed bit frequency test mode:\n");
|
||||
FILE_LOG(logINFO, ("\tMixed bit frequency test mode\n"));
|
||||
setAdc(AD9257_TEST_MODE_REG,
|
||||
(AD9257_MIXED_BIT_FREQ_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK);
|
||||
#endif
|
||||
|
@ -1,9 +1,7 @@
|
||||
#ifndef BLACKFIN_H
|
||||
#define BLACKFIN_H
|
||||
#pragma once
|
||||
|
||||
#include "ansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h> // open
|
||||
#include <sys/mman.h> // mmap
|
||||
|
||||
@ -73,7 +71,7 @@ int64_t get64BitReg(int aLSB, int aMSB){
|
||||
vMSB=bus_r(aMSB);
|
||||
v64=vMSB;
|
||||
v64=(v64<<32) | vLSB;
|
||||
printf(" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64);
|
||||
FILE_LOG(logDEBUG1, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64));
|
||||
return v64;
|
||||
}
|
||||
|
||||
@ -124,39 +122,33 @@ u_int32_t writeRegister(u_int32_t offset, u_int32_t data) {
|
||||
int mapCSP0(void) {
|
||||
// if not mapped
|
||||
if (CSP0BASE == 0) {
|
||||
printf("Mapping memory\n");
|
||||
FILE_LOG(logINFO, ("Mapping memory\n"));
|
||||
#ifdef VIRTUAL
|
||||
CSP0BASE = malloc(MEM_SIZE);
|
||||
if (CSP0BASE == NULL) {
|
||||
cprintf(BG_RED, "Error: Could not allocate virtual memory.\n");
|
||||
FILE_LOG(logERROR, ("Could not allocate virtual memory.\n"));
|
||||
return FAIL;
|
||||
}
|
||||
printf("memory allocated\n");
|
||||
FILE_LOG(logINFO, (("memory allocated\n"));
|
||||
#else
|
||||
int fd;
|
||||
fd = open("/dev/mem", O_RDWR | O_SYNC, 0);
|
||||
if (fd == -1) {
|
||||
cprintf(BG_RED, "Error: Can't find /dev/mem\n");
|
||||
FILE_LOG(logERROR, ("Can't find /dev/mem\n"));
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("/dev/mem opened\n");
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("/dev/mem opened\n"));
|
||||
CSP0BASE = mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0);
|
||||
if (CSP0BASE == MAP_FAILED) {
|
||||
cprintf(BG_RED, "Error: Can't map memmory area\n");
|
||||
FILE_LOG(logERROR, ("Can't map memmory area\n"));
|
||||
return FAIL;
|
||||
}
|
||||
#endif
|
||||
printf("CSPOBASE mapped from 0x%llx to 0x%llx\n",
|
||||
FILE_LOG(logINFO, ("CSPOBASE mapped from 0x%llx to 0x%llx\n",
|
||||
(long long unsigned int)CSP0BASE,
|
||||
(long long unsigned int)(CSP0BASE+MEM_SIZE));
|
||||
printf("Status Register: %08x\n",bus_r(STATUS_REG));
|
||||
|
||||
(long long unsigned int)(CSP0BASE+MEM_SIZE)));
|
||||
FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
|
||||
}else
|
||||
printf("Memory already mapped before\n");
|
||||
FILE_LOG(logINFO, ("Memory already mapped before\n"));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
#endif //BLACKFIN_H
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#ifndef GOTTHARDD //gotthard already had bus_w etc defined in its firmware_funcs.c (not yet made with common files)
|
||||
#include "blackfin.h"
|
||||
#else
|
||||
#include "ansi.h"
|
||||
#endif
|
||||
|
||||
/* global variables */
|
||||
@ -54,13 +56,11 @@ void sendDataToSPI (u_int32_t* valw, u_int32_t addr, u_int32_t val, int numbitst
|
||||
|
||||
|
||||
void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) {
|
||||
#ifdef VERBOSE
|
||||
if (numbitstosend == 16)
|
||||
printf("Writing to SPI Register: 0x%04x\n",val);
|
||||
else
|
||||
printf("Writing to SPI Register: 0x%08x\n", val);
|
||||
#endif
|
||||
|
||||
if (numbitstosend == 16) {
|
||||
FILE_LOG(logDEBUG1, ("Writing to SPI Register: 0x%04x\n", val));
|
||||
} else {
|
||||
FILE_LOG(logDEBUG1, ("Writing to SPI Register: 0x%08x\n", val));
|
||||
}
|
||||
u_int32_t valw;
|
||||
|
||||
SPIChipSelect (&valw, addr, csmask);
|
||||
|
@ -1,14 +1,15 @@
|
||||
|
||||
|
||||
#include "communication_funcs.h"
|
||||
#include "logger.h"
|
||||
|
||||
//#include <netinet/tcp.h> /* for TCP_NODELAY */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SEND_REC_MAX_SIZE 4096
|
||||
#define DEFAULT_PORTNO 1952
|
||||
#define DEFAULT_BACKLOG 5
|
||||
|
||||
|
||||
// Global variables from errno.h
|
||||
extern int errno;
|
||||
@ -25,7 +26,6 @@ char mess[MAX_STR_LENGTH];
|
||||
|
||||
// Local variables
|
||||
char dummyClientIP[INET_ADDRSTRLEN] = "";
|
||||
const int send_rec_max_size = SEND_REC_MAX_SIZE;
|
||||
int myport = -1;
|
||||
// socket descriptor set
|
||||
fd_set readset, tempset;
|
||||
@ -36,10 +36,6 @@ int isock = 0;
|
||||
int maxfd = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
#define DEFAULT_BACKLOG 5
|
||||
|
||||
int bindSocket(unsigned short int port_number) {
|
||||
ret = FAIL;
|
||||
int socketDescriptor = -1;
|
||||
@ -324,7 +320,7 @@ int receiveDataOnly(int file_des, void* buf,int length) {
|
||||
length, (isControlServer ? "control":"stop")));
|
||||
|
||||
while(length > 0) {
|
||||
nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; // (condition) ? if_true : if_false
|
||||
nreceiving = (length>SEND_REC_MAX_SIZE) ? SEND_REC_MAX_SIZE:length; // (condition) ? if_true : if_false
|
||||
nreceived = read(file_des,(char*)buf+total_received,nreceiving);
|
||||
if(!nreceived){
|
||||
if(!total_received) {
|
||||
|
@ -1,21 +1,9 @@
|
||||
#ifndef COMMUNICATION_FUNCS_H
|
||||
#define COMMUNICATION_FUNCS_H
|
||||
|
||||
#define SEND_REC_MAX_SIZE 4096
|
||||
#define DEFAULT_PORTNO 1952
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
|
||||
|
||||
typedef enum{
|
||||
INT16,
|
||||
INT32,
|
||||
|
@ -20,7 +20,7 @@
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFO,
|
||||
logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFORED, logINFO,
|
||||
logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5
|
||||
}TLogLevel;
|
||||
|
||||
@ -36,6 +36,7 @@ static inline void FILELOG_PrintLog(TLogLevel level, char* m) {
|
||||
case logWARNING: cprintf(YELLOW BOLD, "WARNING: %s", m); break;
|
||||
case logINFOBLUE: cprintf(BLUE, "INFO: %s", m); break;
|
||||
case logINFOGREEN: cprintf(GREEN, "INFO: %s", m); break;
|
||||
case logINFORED: cprintf(RED, "INFO: %s", m); break;
|
||||
case logINFO: cprintf(RESET, "INFO: %s", m); break;
|
||||
case logDEBUG: cprintf(MAGENTA, "DEBUG: %s", m); break;
|
||||
case logDEBUG1: cprintf(MAGENTA, "DEBUG1: %s", m); break;
|
||||
|
@ -1,19 +1,17 @@
|
||||
#ifndef PROGRAM_FPGA_H
|
||||
#define PROGRAM_FPGA_H
|
||||
#pragma once
|
||||
|
||||
#include "ansi.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> // usleep
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* global variables */
|
||||
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
||||
int gpioDefined=0;
|
||||
#define MTDSIZE 10
|
||||
char mtdvalue[MTDSIZE];
|
||||
#define MTDSIZE 10
|
||||
|
||||
int gpioDefined = 0;
|
||||
char mtdvalue[MTDSIZE] = {0};
|
||||
|
||||
|
||||
/**
|
||||
@ -27,9 +25,9 @@ void defineGPIOpins(){
|
||||
//define their direction
|
||||
system("echo in > /sys/class/gpio/gpio7/direction");
|
||||
system("echo out > /sys/class/gpio/gpio9/direction");
|
||||
printf("gpio pins defined\n");
|
||||
FILE_LOG(logINFO, ("gpio pins defined\n"));
|
||||
gpioDefined = 1;
|
||||
}else printf("gpio pins already defined earlier\n");
|
||||
}else FILE_LOG(logDEBUG1, ("gpio pins already defined earlier\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +52,7 @@ void FPGATouchFlash(){
|
||||
* Reset FPGA
|
||||
*/
|
||||
void resetFPGA(){
|
||||
cprintf(BLUE,"\n*** Reseting FPGA ***\n");
|
||||
FILE_LOG(logINFOBLUE, ("Reseting FPGA\n"));
|
||||
FPGAdontTouchFlash();
|
||||
FPGATouchFlash();
|
||||
usleep(CTRL_SRVR_INIT_TIME_US);
|
||||
@ -64,14 +62,12 @@ void resetFPGA(){
|
||||
* Erasing flash
|
||||
*/
|
||||
void eraseFlash(){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nErasing Flash\n");
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Erasing Flash\n"));
|
||||
char command[255];
|
||||
memset(command, 0, 255);
|
||||
sprintf(command,"flash_eraseall %s",mtdvalue);
|
||||
system(command);
|
||||
printf("Flash erased\n");
|
||||
FILE_LOG(logINFO, ("Flash erased\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,43 +77,40 @@ void eraseFlash(){
|
||||
* @return 0 for success, 1 for fail (cannot open file for writing program)
|
||||
*/
|
||||
int startWritingFPGAprogram(FILE** filefp){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nStart Writing of FPGA program\n");
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Start Writing of FPGA program\n"));
|
||||
|
||||
//getting the drive
|
||||
char output[255];
|
||||
memset(output, 0, 255);
|
||||
FILE* fp = popen("awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r");
|
||||
if (fp == NULL) {
|
||||
cprintf(RED,"popen returned NULL. Need that to get mtd drive.\n");
|
||||
FILE_LOG(logERROR, ("popen returned NULL. Need that to get mtd drive.\n"));
|
||||
return 1;
|
||||
}
|
||||
if (fgets(output, sizeof(output), fp) == NULL) {
|
||||
cprintf(RED,"fgets returned NULL. Need that to get mtd drive.\n");
|
||||
FILE_LOG(logERROR, ("fgets returned NULL. Need that to get mtd drive.\n"));
|
||||
return 1;
|
||||
}
|
||||
pclose(fp);
|
||||
//cprintf(RED,"output: %s\n", output);
|
||||
memset(mtdvalue, 0, MTDSIZE);
|
||||
strcpy(mtdvalue,"/dev/");
|
||||
char* pch = strtok(output,":");
|
||||
if(pch == NULL){
|
||||
cprintf(RED,"Could not get mtd value\n");
|
||||
FILE_LOG(logERROR, ("Could not get mtd value\n"));
|
||||
return 1;
|
||||
}
|
||||
strcat(mtdvalue,pch);
|
||||
printf ("\nFlash drive found: %s\n",mtdvalue);
|
||||
FILE_LOG(logINFO, ("Flash drive found: %s\n", mtdvalue));
|
||||
|
||||
FPGAdontTouchFlash();
|
||||
|
||||
//writing the program to flash
|
||||
*filefp = fopen(mtdvalue, "w");
|
||||
if(*filefp == NULL){
|
||||
cprintf(RED,"Unable to open %s in write mode\n",mtdvalue);
|
||||
FILE_LOG(logERROR, ("Unable to open %s in write mode\n", mtdvalue));
|
||||
return 1;
|
||||
}
|
||||
printf("Flash ready for writing\n");
|
||||
FILE_LOG(logINFO, ("Flash ready for writing\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -128,9 +121,7 @@ int startWritingFPGAprogram(FILE** filefp){
|
||||
* @param filefp pointer to flash
|
||||
*/
|
||||
void stopWritingFPGAprogram(FILE* filefp){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nStopping of writing FPGA program\n");
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Stopping of writing FPGA program\n"));
|
||||
|
||||
int wait = 0;
|
||||
if(filefp!= NULL){
|
||||
@ -142,9 +133,7 @@ void stopWritingFPGAprogram(FILE* filefp){
|
||||
FPGATouchFlash();
|
||||
|
||||
if(wait){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Waiting for FPGA to program from flash\n");
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Waiting for FPGA to program from flash\n"));
|
||||
//waiting for success or done
|
||||
char output[255];
|
||||
int res=0;
|
||||
@ -153,12 +142,10 @@ void stopWritingFPGAprogram(FILE* filefp){
|
||||
fgets(output, sizeof(output), sysFile);
|
||||
pclose(sysFile);
|
||||
sscanf(output,"%d",&res);
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("gpi07 returned %d\n",res);
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("gpi07 returned %d\n", res));
|
||||
}
|
||||
}
|
||||
printf("FPGA has picked up the program from flash\n\n");
|
||||
FILE_LOG(logINFO, ("FPGA has picked up the program from flash\n"));
|
||||
}
|
||||
|
||||
|
||||
@ -170,21 +157,15 @@ void stopWritingFPGAprogram(FILE* filefp){
|
||||
* @return 0 for success, 1 for fail (cannot write)
|
||||
*/
|
||||
int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp){
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("\nWriting of FPGA Program\n");
|
||||
cprintf(BLUE,"address of fpgasrc:%p\n",(void *)fpgasrc);
|
||||
cprintf(BLUE,"fsize:%lu\n",fsize);
|
||||
cprintf(BLUE,"pointer:%p\n",(void*)filefp);
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("Writing of FPGA Program\n"
|
||||
"\taddress of fpgasrc:%p\n"
|
||||
"\tfsize:%lu\n\tpointer:%p\n",
|
||||
(void *)fpgasrc, fsize, (void*)filefp));
|
||||
|
||||
if(fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp )!= fsize){
|
||||
cprintf(RED,"Could not write FPGA source to flash (size:%lu)\n", fsize);
|
||||
FILE_LOG(logERROR, ("Could not write FPGA source to flash (size:%lu)\n", fsize));
|
||||
return 1;
|
||||
}
|
||||
#ifdef VERY_VERBOSE
|
||||
cprintf(BLUE, "program written to flash\n");
|
||||
#endif
|
||||
FILE_LOG(logDEBUG1, ("program written to flash\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif //PROGRAM_FPGA_H
|
||||
|
@ -37,9 +37,7 @@ u_int64_t getFirmwareAPIVersion();
|
||||
u_int16_t getHardwareVersionNumber();
|
||||
u_int16_t getHardwareSerialNumber();
|
||||
#endif
|
||||
#ifdef EIGERD
|
||||
u_int32_t getDetectorNumber();
|
||||
#endif
|
||||
u_int64_t getDetectorMAC();
|
||||
u_int32_t getDetectorIP();
|
||||
|
||||
|
@ -2,16 +2,15 @@
|
||||
The port number is passed as an argument */
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
#include "logger.h"
|
||||
#include "communication_funcs.h"
|
||||
#include "slsDetectorServer_funcs.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// Global variables from communication_funcs
|
||||
extern int isControlServer;
|
||||
extern int ret;
|
||||
|
@ -3,19 +3,19 @@
|
||||
#include "communication_funcs.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
//defined in the detector specific Makefile
|
||||
#ifdef GOTTHARDD
|
||||
const enum detectorType myDetectorType=GOTTHARD;
|
||||
const enum detectorType myDetectorType = GOTTHARD;
|
||||
#elif EIGERD
|
||||
const enum detectorType myDetectorType=EIGER;
|
||||
const enum detectorType myDetectorType = EIGER;
|
||||
#elif JUNGFRAUD
|
||||
const enum detectorType myDetectorType=JUNGFRAU;
|
||||
const enum detectorType myDetectorType = JUNGFRAU;
|
||||
#else
|
||||
const enum detectorType myDetectorType=GENERIC;
|
||||
const enum detectorType myDetectorType = GENERIC;
|
||||
#endif
|
||||
|
||||
// Global variables from communication_funcs
|
||||
@ -64,7 +64,7 @@ void init_detector() {
|
||||
if (isControlServer) {
|
||||
basictests();
|
||||
#ifdef JUNGFRAUD
|
||||
if (debugflag == PROGRAMMING_MODE)
|
||||
if (debugflag != PROGRAMMING_MODE)
|
||||
#endif
|
||||
initControlServer();
|
||||
#ifdef EIGERD
|
||||
@ -1331,53 +1331,54 @@ int set_timer(int file_des) {
|
||||
|
||||
|
||||
int get_time_left(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
enum timerIndex ind = -1;
|
||||
int64_t retval = -1;
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
enum timerIndex ind = -1;
|
||||
int64_t retval = -1;
|
||||
|
||||
if (receiveData(file_des, &ind, sizeof(ind), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logDEBUG1, ("Getting timer left index %d\n", ind));
|
||||
if (receiveData(file_des, &ind, sizeof(ind), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logDEBUG1, ("Getting timer left index %d\n", ind));
|
||||
|
||||
// only get
|
||||
// check index
|
||||
switch(ind) {
|
||||
// only get
|
||||
// check index
|
||||
#ifdef JUNGFRAUD
|
||||
if (ind == DELAY_AFTER_TRIGGER) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Timer Left Index (%d) is not implemented for this release.\n", (int)ind);
|
||||
FILE_LOG(logERROR,(mess));
|
||||
}
|
||||
#endif
|
||||
if (ret == OK) {
|
||||
switch(ind) {
|
||||
#ifdef EIGERD
|
||||
case MEASURED_PERIOD:
|
||||
case MEASURED_SUBPERIOD:
|
||||
case MEASURED_PERIOD:
|
||||
case MEASURED_SUBPERIOD:
|
||||
#elif JUNGFRAUD
|
||||
case FRAMES_FROM_START:
|
||||
case FRAMES_FROM_START_PG:
|
||||
case FRAMES_FROM_START:
|
||||
case FRAMES_FROM_START_PG:
|
||||
#elif GOTTHARDD
|
||||
case GATES_NUMBER:
|
||||
case GATES_NUMBER:
|
||||
#endif
|
||||
#if defined(GOTTHARDD) || defined(JUNGFRAUD)
|
||||
case FRAME_NUMBER:
|
||||
case ACQUISITION_TIME:
|
||||
case FRAME_PERIOD:
|
||||
case DELAY_AFTER_TRIGGER:
|
||||
case CYCLES_NUMBER:
|
||||
case PROGRESS:
|
||||
case ACTUAL_TIME:
|
||||
case MEASUREMENT_TIME:
|
||||
case FRAME_NUMBER:
|
||||
case ACQUISITION_TIME:
|
||||
case FRAME_PERIOD:
|
||||
case DELAY_AFTER_TRIGGER:
|
||||
case CYCLES_NUMBER:
|
||||
case PROGRESS:
|
||||
case ACTUAL_TIME:
|
||||
case MEASUREMENT_TIME:
|
||||
#endif
|
||||
retval = getTimeLeft(ind);
|
||||
FILE_LOG(logDEBUG1, ("Timer left index %d: %lld\n", ind, retval));
|
||||
break;
|
||||
#ifdef JUNGFRAUD
|
||||
case DELAY_AFTER_TRIGGER:
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Timer Left Index (%d) is not implemented for this release.\n", (int)ind);
|
||||
FILE_LOG(logERROR,(mess));
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
modeNotImplemented("Timer left index", (int)ind);
|
||||
break;
|
||||
}
|
||||
return Server_SendResult(file_des, INT64, 1, &retval, sizeof(retval));
|
||||
retval = getTimeLeft(ind);
|
||||
FILE_LOG(logDEBUG1, ("Timer left index %d: %lld\n", ind, retval));
|
||||
break;
|
||||
default:
|
||||
modeNotImplemented("Timer left index", (int)ind);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Server_SendResult(file_des, INT64, 1, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
|
||||
@ -1692,9 +1693,16 @@ int set_port(int file_des) {
|
||||
|
||||
|
||||
int update_client(int file_des) {
|
||||
ret = OK;
|
||||
ret = FORCE_UPDATE;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
#ifdef JUNGFRAUD
|
||||
if (debugflag == PROGRAMMING_MODE) {
|
||||
ret = OK;
|
||||
}
|
||||
#endif
|
||||
Server_SendResult(file_des, INT32, 0, NULL, 0);
|
||||
if (ret == OK)
|
||||
return ret;
|
||||
return send_update(file_des);
|
||||
}
|
||||
|
||||
@ -1702,6 +1710,7 @@ int update_client(int file_des) {
|
||||
|
||||
|
||||
int send_update(int file_des) {
|
||||
ret = OK;
|
||||
int n = 0;
|
||||
int i32 = -1;
|
||||
int64_t i64 = -1;
|
||||
@ -1769,7 +1778,7 @@ int send_update(int file_des) {
|
||||
strcpy(lastClientIP,thisClientIP);
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -2369,7 +2378,6 @@ int program_fpga(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
FILE_LOG(logDEBUG1, ("Programming FPGA\n"));
|
||||
#ifndef JUNGFRAUD
|
||||
//to receive any arguments
|
||||
int n = 1;
|
||||
@ -2405,7 +2413,7 @@ int program_fpga(int file_des) {
|
||||
if (receiveData(file_des,&filesize,sizeof(filesize),INT32) < 0)
|
||||
return printSocketReadError();
|
||||
totalsize = filesize;
|
||||
FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize);
|
||||
FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize));
|
||||
|
||||
// opening file pointer to flash and telling FPGA to not touch flash
|
||||
if (startWritingFPGAprogram(&fp) != OK) {
|
||||
@ -2430,8 +2438,7 @@ int program_fpga(int file_des) {
|
||||
if (unitprogramsize > filesize) //less than 2mb
|
||||
unitprogramsize = filesize;
|
||||
FILE_LOG(logDEBUG1, ("unit size to receive is:%d\n"
|
||||
"filesize:%d currentpointer:%d\n",
|
||||
unitprogramsize, filesize, currentPointer));
|
||||
"filesize:%d\n", unitprogramsize, filesize));
|
||||
|
||||
|
||||
//receive part of program
|
||||
@ -2462,8 +2469,8 @@ int program_fpga(int file_des) {
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO("\nDone copying program\n"));
|
||||
printf("\n");
|
||||
FILE_LOG(logINFO, ("Done copying program\n"));
|
||||
|
||||
// closing file pointer to flash and informing FPGA
|
||||
stopWritingFPGAprogram(fp);
|
||||
@ -2712,29 +2719,30 @@ int auto_comp_disable(int file_des) {
|
||||
|
||||
|
||||
int storage_cell_start(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int arg = -1;
|
||||
int retval = -1;
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int arg = -1;
|
||||
int retval = -1;
|
||||
|
||||
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logDEBUG1, ("Setting Storage cell start to %d\n", arg));
|
||||
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logDEBUG1, ("Setting Storage cell start to %d\n", arg));
|
||||
|
||||
#ifndef JUNGFRAUD
|
||||
functionNotImplemented();
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// set & get
|
||||
if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) {
|
||||
if (arg > MAX_STORAGE_CELL_VAL) {
|
||||
ret = FAIL;
|
||||
strcpy(mess,"Max Storage cell number should not exceed 15\n");
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else {
|
||||
retval = selectStoragecellStart(arg);
|
||||
FILE_LOG(logDEBUG1, ("Storage cell start: %d\n", retval));
|
||||
validate(arg, retval, "set storage cell start", 0);
|
||||
}
|
||||
// set & get
|
||||
if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) {
|
||||
if (arg > MAX_STORAGE_CELL_VAL) {
|
||||
ret = FAIL;
|
||||
strcpy(mess,"Max Storage cell number should not exceed 15\n");
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else {
|
||||
retval = selectStoragecellStart(arg);
|
||||
FILE_LOG(logDEBUG1, ("Storage cell start: %d\n", retval));
|
||||
validate(arg, retval, "set storage cell start", 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval));
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "sls_detector_defs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// initialization functions
|
||||
int printSocketReadError();
|
||||
|
Reference in New Issue
Block a user