/* status.c controls status bit monitoring $Log: status.c,v $ Revision 1.1 2000/11/03 16:42:49 nort Initial revision * Revision 1.1 1993/08/09 18:23:38 nmd * Initial revision * */ #pragma off (unreferenced) static char statrcsid[] = "$Id: status.c,v 1.1 2000/11/03 16:42:49 nort Exp $"; #pragma on (unreferenced) #include "status.h" #include #include #include #include #include #include #include "subbus.h" #include "msg.h" unsigned maskVal(unsigned char status, unsigned char shift){ return ( status & ( 1 << shift ) ); } unsigned runWasAborted(unsigned char status){ if ( maskVal(status,ABORT_BIT) != 0 ){ return 1; } return 0; } unsigned runHasBegun(unsigned char status){ static unsigned char runWasOn = 0; unsigned char runOn; if ( ((runOn = maskVal(status,RUN_BIT)) != 0) && ! runWasOn ){ runWasOn = runOn; return 1; } runWasOn = runOn; return 0; } unsigned runHasEnded(unsigned char status){ static unsigned char runWasOn = 0; unsigned char runOn; if ( ((runOn = maskVal(status,RUN_BIT)) == 0) && runWasOn ){ runWasOn = runOn; return 1; } runWasOn = runOn; return 0; } void clearDigIOBit(unsigned short baseAddress, char bitNum){ unsigned char settings, mask; settings = sbb(baseAddress); mask = ~ (1 << bitNum); sbwr(baseAddress, settings & mask); } void setDigIOBit(unsigned short baseAddress, char bitNum){ unsigned short settings, mask; settings = sbb(baseAddress); mask = 1 << bitNum; sbwr(baseAddress, settings | mask); } int runPending(){ FILE *IF; char workLine[128], line[128]; unsigned short manNum, bulbNum; float injSize; int convert; if ( (IF = fopen("run.schedule","r")) == NULL ) return 0; /* skip header line */ fgets(line,255,IF); fgets(workLine,255,IF); convert = sscanf(workLine,"%d %d %f",&manNum, &bulbNum, &injSize); msg(1,"Found %d things",convert); fclose(IF); if ( convert == 3 ) return 1; return 0; } ScanInfo scanInfo; int delayCounter; int initScanInfo(ScanInfo *scanInfo) /* Bootstrap for scanning. 1> Read the path to the FTIR control directories from the local disk. Sets the path name for the FTIR information (an NFS disk) Sets the skeleton command line. Sets the scan number to 0 */ { FILE *IF; DIR *dir; struct dirent *ent; char fullPath[256], killPath[256]; char *line = fullPath; char fileName[32] = "FTIR.path"; char *key = fileName; char *dot; int nscan; /* Get the FTIR path */ if ( ( IF = fopen(fileName,"r") ) == NULL ){ msg(0,"Attempt to open file %s for read failed.",fileName); return 0; } while ( fgets(line,256,IF) != NULL && (*line == '#' ) ); if ( ferror(IF) ){ fclose(IF); msg(0,"No valid path for FTIR data"); return 0; } msg(0,"FTIR data path set to %s.",line); strcpy(scanInfo->scanInfoPath,line); fclose(IF); scanInfo->scanNumber = 0; scanInfo->resolutionNumber = 0; sprintf(fullPath,"%s/setup/scan.init",scanInfo->scanInfoPath); if ( ( IF = fopen(fullPath,"r") ) == NULL ){ msg(0,"Attempt to open file %s for read failed.",fullPath); return 0; } while ( ! feof(IF) ){ line = fullPath; while ( fgets(line,256,IF) != NULL && (*line == '#' ) ); /* msg(0,"Initialization line: %s",line); */ if ( ferror(IF) ){ fclose(IF); return 1; } else { sscanf(line," %s =%n",key,&nscan); line += nscan; if ( strncmp(key,"maxScans",8) == 0) sscanf(line," %d",&(scanInfo->maxScans)); else if ( strncmp(key,"skelCmdLine",11) == 0) { while ( isspace(*line) ) line++; strcpy(scanInfo->skelCmdLine,line); } else if ( strncmp(key,"queueEntryExt",13) == 0) sscanf(line," %s",&(scanInfo->entryExt)); else if ( strncmp(key,"queueReceiptExt",15) == 0) sscanf(line," %s",&(scanInfo->receiptExt)); else if ( strncmp(key,"queueKillExt",12) == 0) sscanf(line," %s",&(scanInfo->killExt)); else if ( strncmp(key,"numberOfResolutions",19) == 0) sscanf(line," %d",&(scanInfo->numberOfResolutions)); else if ( strncmp(key,"pollingInterval",15) == 0) sscanf(line," %d",&(scanInfo->pollingInterval)); } } fclose(IF); /* Clean up the recieipt queue */ sprintf(fullPath,"%s/spool",scanInfo->scanInfoPath); if (( dir = opendir(fullPath) ) == NULL) { msg(0,"Unable to open queue directory %s.",fullPath); return 0; } while ( (ent = readdir(dir)) != NULL){ dot = rindex(ent->d_name,'.'); if ( dot && ( strcmp(dot+1,scanInfo->receiptExt) == 0 ) ){ strcpy(killPath,fullPath); strcat(killPath,"/"); strcat(killPath, ent->d_name); msg(0,"Removing %s.", killPath); unlink(killPath); } } closedir(dir); return 1; } /* initScanInfo*/ void readScanInfo(ScanInfo *scanInfo) /* */ { FILE *IF; char fullPath[256]; char *line = fullPath; char fileName[9]; sprintf(fileName,"scan%d", scanInfo->resolutionNumber); sprintf(fullPath,"%s/setup/%s.info",scanInfo->scanInfoPath,fileName); if ( (IF = fopen(fullPath,"r")) == NULL ) return; msg(0,"Reading scan settings from %s",fullPath); fgets(line,255,IF); sscanf(line,"%s %d",&(scanInfo->resolutionStr),&(scanInfo->numberOfScans)); fclose(IF); } /* readScanInfo */ void enqueueFTIRScan(const ScanInfo *scanInfo) /* Write a file into the FTIR spool directory to schedule a scan. */ { FILE *OF; char fullPath[256]; char fileName[9]; sprintf(fileName,"r%02.2ds%02.2d",scanInfo->scanNumber,scanInfo->resolutionNumber); sprintf(fullPath,"%s/spool/%s.%s",scanInfo->scanInfoPath,fileName,scanInfo->entryExt); if ( (OF = fopen(fullPath,"w")) == NULL ){ msg(0,"Failed to enqueue run in %s.",fullPath); return; } msg(0,"Enqueueing run in %s.",fullPath); fprintf(OF,scanInfo->skelCmdLine, scanInfo->resolutionStr, scanInfo->numberOfScans, scanInfo->resolutionStr, scanInfo->scanNumber); fclose(OF); } /* enqueueFTIRScan */ int scanCompleted(const ScanInfo *scanInfo) /* Check spool directory for receipt file. Return true if it is present (and erase it). */ { FILE *OF; DIR *dir; struct dirent *ent; char fullPath[256]; char fileName[16]; sprintf(fileName,"r%02.2ds%02.2d.%s",scanInfo->scanNumber, scanInfo->resolutionNumber,scanInfo->receiptExt); sprintf(fullPath,"%s/spool",scanInfo->scanInfoPath); if (( dir = opendir(fullPath) ) == NULL) { msg(0,"Unable to open queue directory %s.",fullPath); return 0; } while ( (ent = readdir(dir)) != NULL) if ( strcmp(ent->d_name,fileName) == 0 ){ closedir(dir); strcat(fullPath,"/"); strcat(fullPath,fileName); msg(-3,"Removing %s.", fullPath); unlink(fullPath); return 1; } closedir(dir); return 0; } /* scanCompleted */