mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-28 01:00:02 +02:00
created programming mode, where only programming is allowed, one has to restart servers afterwards
This commit is contained in:
parent
a37bbc50fe
commit
68e9648854
@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
#define GOODBYE (-200)
|
||||
#define PROGRAMMING_MODE (-200)
|
||||
#define MIN_REQRD_VRSN_T_RD_API 0x171220
|
||||
#define REQRD_FRMWR_VRSN 0x180226
|
||||
|
||||
|
@ -7834,6 +7834,7 @@ int slsDetector::programFPGA(string fname){
|
||||
updateDetector();
|
||||
}
|
||||
|
||||
|
||||
//remapping stop server
|
||||
fnum=F_RESET_FPGA;
|
||||
int stopret;
|
||||
|
@ -11,7 +11,8 @@
|
||||
/* global variables */
|
||||
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
||||
int gpioDefined=0;
|
||||
char mtdvalue[10];
|
||||
#define MTDSIZE 10
|
||||
char mtdvalue[MTDSIZE];
|
||||
|
||||
|
||||
|
||||
@ -85,9 +86,12 @@ int startWritingFPGAprogram(FILE** filefp){
|
||||
|
||||
//getting the drive
|
||||
char output[255];
|
||||
memset(output, 0, 255);
|
||||
FILE* fp = popen("awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r");
|
||||
fgets(output, sizeof(output), fp);
|
||||
pclose(fp);
|
||||
//cprintf(RED,"output: %s\n", output);
|
||||
memset(mtdvalue, 0, MTDSIZE);
|
||||
strcpy(mtdvalue,"/dev/");
|
||||
char* pch = strtok(output,":");
|
||||
if(pch == NULL){
|
||||
@ -161,12 +165,12 @@ 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:%d\n",fsize);
|
||||
cprintf(BLUE,"fsize:%lu\n",fsize);
|
||||
cprintf(BLUE,"pointer:%p\n",(void*)filefp);
|
||||
#endif
|
||||
|
||||
if(fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp )!= fsize){
|
||||
cprintf(RED,"Could not write FPGA source to flash\n");
|
||||
cprintf(RED,"Could not write FPGA source to flash (size:%lu)\n", fsize);
|
||||
return 1;
|
||||
}
|
||||
#ifdef VERY_VERBOSE
|
||||
|
@ -24,51 +24,69 @@ int main(int argc, char *argv[]){
|
||||
int retval=OK;
|
||||
int sd, fd;
|
||||
int debugflag = 0;
|
||||
int controlserver = 1;
|
||||
|
||||
// if socket crash, ignores SISPIPE, prevents global signal handler
|
||||
// subsequent read/write to socket gives error - must handle locally
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// circumvent the basic tests
|
||||
if(argc > 1) {
|
||||
if(!strcasecmp(argv[1],"-debug")){
|
||||
debugflag = 1;
|
||||
argc=1;
|
||||
}
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if(!strcasecmp(argv[i],"-stopserver")) {
|
||||
cprintf(BLUE,"detected stop server\n");
|
||||
controlserver = 0;
|
||||
}
|
||||
else if(!strcasecmp(argv[i],"-debug")){
|
||||
cprintf(BLUE,"detected debug mode\n");
|
||||
debugflag = 1;
|
||||
}
|
||||
#ifdef JUNGFRAUD
|
||||
else if(!strcasecmp(argv[i],"-programming")){
|
||||
cprintf(BLUE,"detected programming mode\n");
|
||||
debugflag = PROGRAMMING_MODE;
|
||||
}
|
||||
#endif
|
||||
else if(strchr(argv[i],'-') != NULL) {
|
||||
cprintf(RED,"cannot scan program argument %s\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STOP_SERVER
|
||||
char cmd[100];
|
||||
memset(cmd, 0, 100);
|
||||
#endif
|
||||
if (argc==1) {
|
||||
if (controlserver) {
|
||||
portno = DEFAULT_PORTNO;
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
"********* opening control server on port %d **********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
b=1;
|
||||
basictests(debugflag);
|
||||
#ifdef STOP_SERVER
|
||||
sprintf(cmd,"%s %d &",argv[0],DEFAULT_PORTNO+1);
|
||||
//cprintf(BLUE,"cmd:%s\n", cmd);
|
||||
system(cmd);
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < argc; ++i)
|
||||
sprintf(cmd, "%s %s", cmd, argv[i]);
|
||||
sprintf(cmd,"%s -stopserver&", cmd);
|
||||
cprintf(BLUE,"cmd:%s\n", cmd);
|
||||
system(cmd);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
portno = DEFAULT_PORTNO+1;
|
||||
if ( sscanf(argv[1],"%d",&portno) == 0) {
|
||||
printf("could not open stop server: unknown port\n");
|
||||
return 1;
|
||||
}
|
||||
cprintf(BLUE,
|
||||
"********************************************************\n"
|
||||
"*********** opening stop server on port %d ***********\n"
|
||||
"********************************************************\n\n"
|
||||
, portno);
|
||||
b=0;
|
||||
}
|
||||
|
||||
init_detector(b); //defined in slsDetectorServer_funcs
|
||||
setModeFlag(debugflag); //defined in slsDetectorServer_funcs
|
||||
init_detector(controlserver); //defined in slsDetectorServer_funcs
|
||||
|
||||
sd=bindSocket(portno); //defined in communication_funcs
|
||||
sockfd=sd;
|
||||
|
@ -52,8 +52,11 @@ int printSocketReadError() {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
void basictests(int flag) {
|
||||
void setModeFlag(int flag) {
|
||||
debugflag = flag;
|
||||
}
|
||||
|
||||
void basictests() {
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
checkFirmwareCompatibility(debugflag);
|
||||
#endif
|
||||
@ -68,6 +71,10 @@ void init_detector(int controlserver) {
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
if (controlserver) {
|
||||
isControlServer = 1;
|
||||
basictests();
|
||||
#ifdef JUNGFRAUD
|
||||
if (debugflag != PROGRAMMING_MODE)
|
||||
#endif
|
||||
initControlServer();
|
||||
#ifdef EIGERD
|
||||
dhcpipad = getDetectorIP();
|
||||
@ -102,6 +109,14 @@ int decode_function(int file_des) {
|
||||
|
||||
#ifdef VERBOSE
|
||||
printf(" calling function fnum=%d, (%s) located at 0x%x\n", fnum, getFunctionName((enum detFuncs)fnum), (unsigned int)flist[fnum]);
|
||||
#endif
|
||||
#ifdef JUNGFRAUD
|
||||
if ((debugflag == PROGRAMMING_MODE) &&
|
||||
((fnum != F_PROGRAM_FPGA) && (fnum != F_GET_DETECTOR_TYPE) &&
|
||||
(fnum != F_RESET_FPGA) && (fnum != F_UPDATE_CLIENT))) {
|
||||
sprintf(mess,"This Function %s cannot be executed. ", getFunctionName((enum detFuncs)fnum));
|
||||
ret=(M_nofuncMode)(file_des);
|
||||
} else
|
||||
#endif
|
||||
if (fnum<0 || fnum>=NUM_DET_FUNCTIONS) {
|
||||
cprintf(BG_RED,"Unknown function enum %d\n", fnum);
|
||||
@ -315,6 +330,21 @@ int M_nofunc(int file_des){
|
||||
|
||||
|
||||
|
||||
int M_nofuncMode(int file_des){
|
||||
int ret=FAIL,ret1=FAIL;
|
||||
int n=0;
|
||||
//to receive any arguments
|
||||
while (n > 0)
|
||||
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
|
||||
|
||||
strcat(mess, "On-board detector server in programming mode. Restart detector server in normal mode (without any arguments).\n");
|
||||
cprintf(BG_RED,"Error: %s",mess);
|
||||
n = sendData(file_des,&ret1,sizeof(ret1),INT32);
|
||||
n = sendData(file_des,mess,sizeof(mess),OTHER); // mess is defined at function call
|
||||
|
||||
// return ok / fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4924,7 +4954,7 @@ int program_fpga(int file_des) {
|
||||
int ret=OK,ret1=OK;
|
||||
int n=0;
|
||||
sprintf(mess,"program FPGA failed\n");
|
||||
|
||||
printf("Programming FPGA...")
|
||||
|
||||
#ifndef JUNGFRAUD
|
||||
//to receive any arguments
|
||||
@ -4987,10 +5017,10 @@ int program_fpga(int file_des) {
|
||||
unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb
|
||||
if(unitprogramsize > filesize) //less than 2mb
|
||||
unitprogramsize = filesize;
|
||||
#ifdef VERY_VERBOSE
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("unit size to receive is:%d\n",unitprogramsize);
|
||||
printf("filesize:%d currentpointer:%d\n",filesize,currentPointer);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//receive
|
||||
n = receiveData(file_des,fpgasrc,unitprogramsize,OTHER);
|
||||
@ -5035,15 +5065,16 @@ int program_fpga(int file_des) {
|
||||
if(fp!=NULL)
|
||||
fclose(fp);
|
||||
#ifdef VERY_VERBOSE
|
||||
printf("Done with program receiving command\n");
|
||||
printf("Done with program receiving command\n");
|
||||
#endif
|
||||
if (isControlServer)
|
||||
basictests(debugflag);
|
||||
init_detector(isControlServer);
|
||||
|
||||
if (isControlServer)
|
||||
basictests(debugflag);
|
||||
init_detector(isControlServer);
|
||||
}
|
||||
#endif
|
||||
if (ret==OK)
|
||||
ret=FORCE_UPDATE;
|
||||
if (ret==OK)
|
||||
ret=FORCE_UPDATE;
|
||||
#endif
|
||||
|
||||
// ret could be swapped during sendData
|
||||
@ -5085,9 +5116,13 @@ int reset_fpga(int file_des) {
|
||||
}
|
||||
#ifdef SLS_DETECTOR_FUNCTION_LIST
|
||||
else {
|
||||
if (isControlServer)
|
||||
if (isControlServer) {
|
||||
basictests(debugflag);
|
||||
initControlServer(isControlServer);
|
||||
#ifdef JUNGFRAUD
|
||||
if (debugflag != PROGRAMMING_MODE)
|
||||
#endif
|
||||
initControlServer();
|
||||
}
|
||||
ret = FORCE_UPDATE;
|
||||
}
|
||||
#endif
|
||||
|
@ -6,12 +6,14 @@
|
||||
|
||||
// initialization functions
|
||||
int printSocketReadError();
|
||||
void basictests(int);
|
||||
void setModeFlag(int);
|
||||
void basictests();
|
||||
void init_detector(int);
|
||||
int decode_function(int);
|
||||
const char* getFunctionName(enum detFuncs func);
|
||||
void function_table();
|
||||
int M_nofunc(int);
|
||||
int M_nofuncMode(int);
|
||||
|
||||
// functions called by client
|
||||
int exec_command(int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user