Esempio n. 1
0
int readConfig()
// Load Prioritizerd config stuff
{
  // Config file thingies
  //    KvpErrorCode kvpStatus=0;
  int status=0;
  char* eString ;


  kvpReset();
  status = configLoad (GLOBAL_CONF_FILE,"global") ;
  status = configLoad ("Prioritizerd.config","output") ;
  if(status == CONFIG_E_OK) {
    printToScreen=kvpGetInt("printToScreen",-1);
    verbosity=kvpGetInt("verbosity",-1);
    hkDiskBitMask=kvpGetInt("hkDiskBitMask",0);

    if(printToScreen<0) {
      syslog(LOG_WARNING,
	     "Couldn't fetch printToScreen, defaulting to zero");
      printToScreen=0;
    }
  }
  else {
    eString=configErrorString (status) ;
    syslog(LOG_ERR,"Error reading LOSd.config: %s\n",eString);
    fprintf(stderr,"Error reading LOSd.config: %s\n",eString);
  }
  kvpReset();
  status = configLoad ("Prioritizerd.config","prioritizerd");
  if(status == CONFIG_E_OK) {
      panicQueueLength=kvpGetInt("panicQueueLength",5000);
      writePowSpecPeriodSeconds=kvpGetInt("writePowSpecPeriodSeconds",60);
  }
  else {
    eString=configErrorString (status) ;
    syslog(LOG_ERR,"Error reading Prioritizerd.config: %s\n",eString);
    fprintf(stderr,"Error reading Prioritizerd.config: %s\n",eString);
  }

  kvpReset();
  status = configLoad ("Archived.config","archived");
  if(status == CONFIG_E_OK) {
    priorityPPS1=kvpGetInt("priorityPPS1",3);
    priorityPPS2=kvpGetInt("priorityPPS2",2);
  }
  else {
    eString=configErrorString (status) ;
    syslog(LOG_ERR,"Error reading Prioritizerd.config: %s\n",eString);
    fprintf(stderr,"Error reading Prioritizerd.config: %s\n",eString);
  }

  return status;
}
Esempio n. 2
0
int readConfigFile() 
/* Load Calibd and Relay config stuff */
{
    /* Config file thingies */
    int status=0;
    //    int tempNum=12;
//    int tempNum=3,count=0;
//    KvpErrorCode kvpStatus=0;
    char* eString ;
    kvpReset();
    status = configLoad ("Calibd.config","output") ;
    status = configLoad ("Calibd.config","calibd") ;
    status |= configLoad ("Calibd.config","relays") ;

    if(status == CONFIG_E_OK) {
	//Which board is the digital acromag?
	digitalCarrierNum=kvpGetInt("digitalCarrierNum",1);
      	printf("digitalCarrierNum %d\n",digitalCarrierNum);
	//Debug
	printToScreen=kvpGetInt("printToScreen",-1);
	
	//Heartbeat
	relayWritePeriod=kvpGetInt("relayWritePeriod",60);
	readoutPeriod=kvpGetInt("readoutPeriod",60);
	telemEvery=kvpGetInt("telemEvery",60);
	adcAverage=kvpGetInt("adcAverage",5);
	calibrationPeriod=kvpGetInt("calibrationPeriod",1200);

	//Relay States
	stateAmplite1=kvpGetInt("stateAmplite1",0);
	stateAmplite2=kvpGetInt("stateAmplite2",0);
	stateBZAmpa1=kvpGetInt("stateBZAmpa1",0);
	stateBZAmpa2=kvpGetInt("stateBZAmpa2",0);
	stateNTUAmpa=kvpGetInt("stateNTUAmpa",0);
	stateSB=kvpGetInt("stateSB",0);

	stateNTUSSD5V=kvpGetInt("stateNTUSSD5V",0);
	stateNTUSSD12V=kvpGetInt("stateNTUSSD12V",0);
	//	stateNTUSSDShutdown=kvpGetInt("stateNTUSSDShutdown",0);

    }
    else {
	eString=configErrorString (status) ;
	syslog(LOG_ERR,"Error reading Calibd.config: %s\n",eString);
    }

   


    return status;
   
}
Esempio n. 3
0
int readConfigFile() 
/* Load Playbackd config stuff */
{
    /* Config file thingies */
    char *tempString;
    int status=0;
    char* eString ;
    kvpReset();
    status = configLoad (GLOBAL_CONF_FILE,"global") ;
    status = configLoad ("Playbackd.config","playbackd") ;

    if(status == CONFIG_E_OK) {
	sendData=kvpGetInt("sendData",0);
	useDisk=kvpGetInt("useDisk",0);
	msSleepPeriod=kvpGetInt("msSleepPeriod",0);
	startPriority=kvpGetInt("startPriority",0);
	stopPriority=kvpGetInt("stopPriority",8);
	startEvent=kvpGetInt("startEvent",0);


	tempString=kvpGetString("usbName");
	if(tempString) {
	    strncpy(usbName,tempString,FILENAME_MAX);
	}
	else {
	    syslog(LOG_ERR,"Couldn't get usbName");
	    fprintf(stderr,"Couldn't get usbName\n");
	}
    }
    else {
	eString=configErrorString (status) ;
	syslog(LOG_ERR,"Error reading Playbackd.config: %s\n",eString);
    }
           
    makeDirectories(PLAYBACK_LINK_DIR);
    return status;
}
Esempio n. 4
0
void readConfigFile() {
    /* Config file thingies */
    int status=0;
    KvpErrorCode kvpStatus=0;
    char* eString ;
//    char *tempString;

    /* Load Config */
    kvpReset () ;
    status = configLoad (GLOBAL_CONF_FILE,"global") ;
    status &= configLoad ("Cmdd.config","lengths") ;
    eString = configErrorString (status) ;
    if (status == CONFIG_E_OK) {
	kvpStatus=kvpGetIntArray ("cmdLengths",cmdLengths,&numCmds);
	if(kvpStatus!=KVP_E_OK) {
	    
	    fprintf(stderr,"Problem getting cmdLengths -- %s\n",
		    kvpErrorString(kvpStatus));
	}
    }
    else {
	syslog(LOG_ERR,"Error reading config file: %s\n",eString);
    }
}
Esempio n. 5
0
int readConfig()
// Load Openportd config stuff
{
    // Config file thingies
    KvpErrorCode kvpStatus=0;
    int status=0,tempNum,count,maxVal,maxIndex;
    char* eString ;
    
    //Load output settings
    kvpReset();
    status = configLoad ("Openportd.config","output") ;
    if(status == CONFIG_E_OK) {
	printToScreen=kvpGetInt("printToScreen",-1);
	verbosity=kvpGetInt("verbosity",-1);
	if(printToScreen<0) {
	    printf("Couldn't fetch printToScreen, defaulting to zero\n");
	    printToScreen=0;
	}
    }
    else {
	eString=configErrorString (status) ;
	syslog(LOG_ERR,"Error reading Openportd.config: %s\n",eString);
	fprintf(stderr,"Error reading Openportd.config: %s\n",eString);
    }

    //Load Openportd specfic settings
    kvpReset();
    status = configLoad ("Openportd.config","openportd");
    if(status == CONFIG_E_OK) {
	sendData=kvpGetInt("sendData",0);
	sendWavePackets=kvpGetInt("sendWavePackets",0);
	maxFileSize=kvpGetInt("maxFileSize",50000);
	syslog(LOG_INFO,"sendWavePackets %d\n",sendWavePackets);
    }
    else {
	eString=configErrorString (status) ;
	syslog(LOG_ERR,"Error reading Openportd.config: %s\n",eString);
	fprintf(stderr,"Error reading Openportd.config: %s\n",eString);
    }

    //Load bandwidth settings
    kvpReset();
    status = configLoad ("Openportd.config","bandwidth") ;
    if(status == CONFIG_E_OK) {
//	maxEventsBetweenLists=kvpGetInt("maxEventsBetweenLists",100);
	headersPerEvent=kvpGetInt("headersPerEvent",30);
	eventBandwidth=kvpGetInt("eventBandwidth",5);
	tempNum=NUM_HK_TELEM_DIRS;
	kvpStatus = kvpGetIntArray("hkTelemOrder",hkTelemOrder,&tempNum);
	if(kvpStatus!=KVP_E_OK) {
	    syslog(LOG_WARNING,"kvpGetIntArray(hkTelemOrder): %s",
		   kvpErrorString(kvpStatus));
	    if(printToScreen)
		fprintf(stderr,"kvpGetIntArray(hkTelemOrder): %s\n",
			kvpErrorString(kvpStatus));
	}
	tempNum=NUM_HK_TELEM_DIRS;
	kvpStatus = kvpGetIntArray("hkTelemMaxPackets",hkTelemMaxPackets,&tempNum);
	if(kvpStatus!=KVP_E_OK) {
	    syslog(LOG_WARNING,"kvpGetIntArray(hkTelemMaxPackets): %s",
		   kvpErrorString(kvpStatus));
	    if(printToScreen)
		fprintf(stderr,"kvpGetIntArray(hkTelemMaxPackets): %s\n",
			kvpErrorString(kvpStatus));
	}


	tempNum=10;
	kvpStatus = kvpGetIntArray("priorityBandwidths",priorityBandwidths,&tempNum);
	if(kvpStatus!=KVP_E_OK) {
	    syslog(LOG_WARNING,"kvpGetIntArray(priorityBandwidths): %s",
		   kvpErrorString(kvpStatus));
	    if(printToScreen)
		fprintf(stderr,"kvpGetIntArray(priorityBandwidths): %s\n",
			kvpErrorString(kvpStatus));
	}
	else {
	    for(orderIndex=0;orderIndex<NUM_PRIORITIES*100;orderIndex++) {
		//Check for hundreds first
		for(count=0;count<tempNum;count++) {
		    if(priorityBandwidths[count]>=100) 
			priorityOrder[orderIndex++]=count;
		}
		
		//Next look for highest number
		maxVal=0;
		maxIndex=-1;
		for(count=0;count<tempNum;count++) {
		    if(priorityBandwidths[count]<100) {
			if(priorityBandwidths[count]>maxVal) {
			    maxVal=priorityBandwidths[count];
			    maxIndex=count;
			}
		    }
		}
		if(maxIndex>-1) {
		    priorityOrder[orderIndex]=maxIndex;
		    priorityBandwidths[maxIndex]--;
		}
		else break;
	    }			
	    numOrders=orderIndex;
	    if(printToScreen) {
		printf("Priority Order\n");
		for(orderIndex=0;orderIndex<numOrders;orderIndex++) {
		    printf("%d ",priorityOrder[orderIndex]);
		}
		printf("\n");
	    }
	}
    }
    else {
	eString=configErrorString (status) ;
	syslog(LOG_ERR,"Error reading Openportd.config: %s\n",eString);
	fprintf(stderr,"Error reading Openportd.config: %s\n",eString);
    }

    return status;
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
    //Temporary variables
  int retVal=0,pri=0,ind=0;
  
  /* Config file thingies */
  //  int status=0;
  //  char* eString ;
  sprintf(currentOpenportDir,"%s",OPENPORT_OUTPUT_DIR);
   
    char *progName=basename(argv[0]);

    //
    retVal=sortOutPidFile(progName);
    if(retVal<0)
      return -1;

  
    /* Set signal handlers */
    signal(SIGUSR1, sigUsr1Handler);
    signal(SIGUSR2, sigUsr2Handler);
    signal(SIGTERM, handleBadSigs);
    signal(SIGINT, handleBadSigs);
    signal(SIGSEGV, handleBadSigs);
    signal(SIGRTMIN, refreshLinksHandler);


    /* Setup log */
    setlogmask(LOG_UPTO(LOG_INFO));
    openlog (progName, LOG_PID, ANITA_LOG_FACILITY) ;


    syslog(LOG_INFO,"Starting Openportd\n");

   /* Load Config */
    kvpReset () ;
    //    status = configLoad (GLOBAL_CONF_FILE,"global") ;
    //    eString = configErrorString (status) ;

    //Fill event dir names
    for(pri=0;pri<NUM_PRIORITIES;pri++) {
      retVal=snprintf(eventTelemDirs[pri],sizeof(eventTelemDirs[pri]),"%s/%s%d",BASE_EVENT_TELEM_DIR,EVENT_PRI_PREFIX,pri);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      retVal=snprintf(eventTelemLinkDirs[pri],sizeof(eventTelemLinkDirs[pri]),"%s/link",eventTelemDirs[pri]);
      if(retVal<0) {
	syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
      }
      makeDirectories(eventTelemLinkDirs[pri]);
    }    
    makeDirectories(OPENPORT_OUTPUT_DIR);
    makeDirectories(OPENPORT_STAGE_DIR);
    makeDirectories(OPENPORTD_CMD_ECHO_TELEM_LINK_DIR);


    for(ind=0;ind<NUM_HK_TELEM_DIRS;ind++) {
      makeDirectories(telemLinkDirs[ind]);
    }


    retVal=readConfig();
    
    char currentHeader[FILENAME_MAX];
    static int numLinks[NUM_PRIORITIES]={0};
    static int numHkLinks[NUM_HK_TELEM_DIRS]={0};
    int totalEventLinks=0;
    int totalHkLinks=0;
    int totalEventsSent=0;
    time_t currentTime=0;
    time_t lastRefresh=0;

    int hkInd=0;
    char *tempString=0;
    int numSent=0;
    
    
    //Setup inotify watches
    for(pri=0;pri<NUM_PRIORITIES;pri++) {
      //Setup inotify watches
      if(wdEvents[pri]==0) {
       wdEvents[pri]=setupLinkWatchDir(eventTelemLinkDirs[pri]);
       if(wdEvents[pri]<=0) {
	 fprintf(stderr,"Unable to watch %s\n",eventTelemLinkDirs[pri]);
	 syslog(LOG_ERR,"Unable to watch %s\n",eventTelemLinkDirs[pri]);
	 handleBadSigs(0);
       }
       numLinks[pri]=getNumLinks(wdEvents[pri]);
      }
    }
        
    for(hkInd=0;hkInd<NUM_HK_TELEM_DIRS;hkInd++) {
      if(wdHks[hkInd]==0) {	
	wdHks[hkInd]=setupLinkWatchDir(telemLinkDirs[hkInd]);
	if(wdHks[hkInd]<=0) {
	  fprintf(stderr,"Unable to watch %s\n",telemLinkDirs[hkInd]);
	  syslog(LOG_ERR,"Unable to watch %s\n",telemLinkDirs[hkInd]);
	  //	handleBadSigs(0);
	}
	numHkLinks[hkInd]=getNumLinks(wdHks[hkInd]);
      }      
    }
    time(&lastRefresh);

    int hkCount=0;
    
    printf("Before while loop\n");
    startCopyScript();

    do {
	if(printToScreen) printf("Initalizing Openportd\n");
	currentState=PROG_STATE_RUN;
	while(currentState==PROG_STATE_RUN) {
	  printf("Inside while loop\n");
	  if(!sendData) {
	    sleep(1);
	    continue;
	  }
	  
	  //The idea is that we only write an output file if there is space for it
	  int numWaitingToTransfer=countFilesInDir(currentOpenportDir);
	  if(numWaitingToTransfer>2) {
	    fprintf(stderr,"There are %d files waiting to transer, will sleep now\n",numWaitingToTransfer);
	    
	    sleep(1);
	    continue;
	  }
	  
	  
	  if(totalEventsSent%10==0) {
	    printf("Data sent\nEvents:\t");
	    for(pri=0;pri<NUM_PRIORITIES;pri++)
	      printf("%d ",numEventsSent[pri]);
	    printf("\nHk:\t");
	    for(hkInd=0;hkInd<NUM_HK_TELEM_DIRS;hkInd++) 
	      printf("%d ",numHksSent[hkInd]);
	    printf("\n");
	  }
	  
	  //Check to see if we need to refresh the links
	  time(&currentTime);
	  if(currentTime>lastRefresh+REFRESH_LINKS_EVERY || needToRefreshLinks) {
	    refreshLinkDirs();
	    lastRefresh=currentTime;
	    needToRefreshLinks=0;
	  }
	  
	  //Update the link lists
	  //or some time has passed
	  if(totalEventLinks==0)
	    retVal=checkLinkDirs(1,0);
	  else
	    retVal=checkLinkDirs(0,1);
	  
	  totalEventLinks=0;
	  for(pri=0;pri<NUM_PRIORITIES;pri++) {
	    numLinks[pri]=getNumLinks(wdEvents[pri]);
	    totalEventLinks+=numLinks[pri];
	  }
	  
	  totalHkLinks=0;
	  for(hkInd=0;hkInd<NUM_HK_TELEM_DIRS;hkInd++) {
	    numHkLinks[hkInd]=getNumLinks(wdHks[hkInd]);
	    totalHkLinks+=numHkLinks[hkInd];
	  }
	  if(!retVal && totalHkLinks==0 && totalEventLinks==0) {
	    //No data
	    needToRefreshLinks=1;
	    usleep(1000);
	    continue;
	  }
	  printf("%d %d %d\n",totalEventLinks,totalHkLinks,retVal);
	  
	  if(totalEventLinks) {
	    //Which priority are we sending
	    currentPri=priorityOrder[orderIndex];	
	    int doneEvent=0;
	    while(!doneEvent && totalEventLinks>0) {
	    while(numLinks[currentPri]==0) {
	      orderIndex++;
	      if(orderIndex>=numOrders) orderIndex=0;
	      currentPri=priorityOrder[orderIndex];	
	    }
	    printf("Trying priority %d -- numLinks %d\n",currentPri,numLinks[currentPri]);
	    if(numLinks[currentPri]) {
	      //Got an event	    
	      tempString=getLastLink(wdEvents[currentPri]);
	      retVal=snprintf(currentHeader,sizeof(currentHeader),"%s/%s",eventTelemLinkDirs[currentPri],tempString);
	      if(retVal<0) {
		syslog(LOG_ERR,"Error using snprintf -- %s",strerror(errno));
	      }
	      //	    syslog(LOG_INFO,"Trying %s\n",currentHeader);
	      doneEvent=readAndSendEventRamdisk(currentHeader); //Also deletes
	      if(doneEvent) {
		numEventsSent[currentPri]++;
		totalEventsSent++;
	      }
	      numLinks[currentPri]--;
	      totalEventLinks--;
	    }
	    }
	    
	  if(currentTime>lastRefresh+REFRESH_LINKS_EVERY || 
	     needToRefreshLinks) {
	    refreshLinkDirs();
	    lastRefresh=currentTime;
	    needToRefreshLinks=0;
	    
	    totalHkLinks=0;
	    for(hkInd=0;hkInd<NUM_HK_TELEM_DIRS;hkInd++) {
	      numHkLinks[hkInd]=getNumLinks(wdHks[hkInd]);
	      totalHkLinks+=numHkLinks[hkInd];
	    }	    
	  }
	    

	  //Now try to send some stuff I like
	  numSent=0;
	  if(numHkLinks[OPENPORT_TELEM_HEADER])
	    readHkAndOpenport(wdHks[OPENPORT_TELEM_HEADER],
			   headersPerEvent,HEADER_TELEM_DIR,
			   HEADER_TELEM_LINK_DIR,sizeof(AnitaEventHeader_t),&numSent);
	  numHksSent[OPENPORT_TELEM_HEADER]+=numSent;
	  
	  numSent=0;
	  if(numHkLinks[OPENPORT_TELEM_CMD_ECHO])
	    readHkAndOpenport(wdHks[OPENPORT_TELEM_CMD_ECHO],echoesPerEvent,
			   OPENPORTD_CMD_ECHO_TELEM_DIR,
			   OPENPORTD_CMD_ECHO_TELEM_LINK_DIR,
			   sizeof(CommandEcho_t),&numSent);
	  numHksSent[OPENPORT_TELEM_CMD_ECHO]+=numSent;
	  
	  numSent=0;
	  if(numHkLinks[OPENPORT_TELEM_HK])
	    readHkAndOpenport(wdHks[OPENPORT_TELEM_HK],hkPerEvent,HK_TELEM_DIR,
			   HK_TELEM_LINK_DIR,sizeof(HkDataStruct_t),&numSent);
	  
	  numSent=0;
	  if(numHkLinks[OPENPORT_TELEM_ADU5A_PAT])
	    readHkAndOpenport(wdHks[OPENPORT_TELEM_ADU5A_PAT],1,
			   ADU5A_PAT_TELEM_DIR,
			   ADU5A_PAT_TELEM_LINK_DIR,
			   sizeof(GpsAdu5PatStruct_t),&numSent);
	  numHksSent[OPENPORT_TELEM_ADU5A_PAT]+=numSent;
	  
	  numSent=0;
	  if(numHkLinks[OPENPORT_TELEM_MONITOR])
	    readHkAndOpenport(wdHks[OPENPORT_TELEM_MONITOR],monitorPerEvent,
			   MONITOR_TELEM_DIR,MONITOR_TELEM_LINK_DIR,
			   sizeof(MonitorStruct_t),&numSent); 
	  numHksSent[OPENPORT_TELEM_MONITOR]+=numSent;
	  
	
	  //	else if(totalEventLinks==0) {
	//	  usleep(1000);
	//	}
	  
	  orderIndex++;
	  if(orderIndex>=numOrders) orderIndex=0;
	}
    
	
	//Now we try and send some data
	//I'm going to try and modify this but for now
	if(hkCount%eventBandwidth==0)
	  sendSomeHk(10000);
	hkCount++;
	}
    } while (currentState == PROG_STATE_INIT);
    stopCopyScript();
    unlink(OPENPORTD_PID_FILE);
    return 0;
}
Esempio n. 7
0
int main (int argc, char *argv[])
{
    int retVal=0;
    int relaysChanged=0;
    int firstTime=1;
    int lastRelayWriteSec=0;
       
    // Config file thingies 
    int status=0;
    char* eString;
    char *globalConfFile="anitaSoft.config";
    // Log stuff 
    char *progName=basename(argv[0]);
    

    int millisecs=0;
    struct timespec milliWait;
    milliWait.tv_sec=0;


    int lastCal=0;
    time_t rawTime;

    // Setup log 
    setlogmask(LOG_UPTO(LOG_INFO));
    openlog (progName, LOG_PID, ANITA_LOG_FACILITY) ;

    // Set signal handlers 
    signal(SIGUSR1, sigUsr1Handler);
    signal(SIGUSR2, sigUsr2Handler);
    signal(SIGTERM, handleBadSigs);
    signal(SIGINT, handleBadSigs);
    signal(SIGSEGV, handleBadSigs);

    //Dont' wait for children
    signal(SIGCLD, SIG_IGN);     

    //Sort out PID File
    retVal=sortOutPidFile(progName);
    if(retVal!=0) {
      return retVal;
    }


    // Load Config 
    kvpReset () ;
    status = configLoad (globalConfFile,"global") ;


    // Get Calibd output dirs
    if (status == CONFIG_E_OK) {
	hkDiskBitMask=kvpGetInt("hkDiskBitMask",1);

	disableUsb=kvpGetInt("disableUsb",1);
	if(disableUsb)
	    hkDiskBitMask&=~USB_DISK_MASK;
	//	disableNeobrick=kvpGetInt("disableNeobrick",1);
	//	if(disableNeobrick)
	//	    hkDiskBitMask&=~NEOBRICK_DISK_MASK;
	disableHelium2=kvpGetInt("disableHelium2",1);
	if(disableHelium2)
	    hkDiskBitMask&=~HELIUM2_DISK_MASK;
	disableHelium1=kvpGetInt("disableHelium1",1);
	if(disableHelium1)
	    hkDiskBitMask&=~HELIUM1_DISK_MASK;
    }
    else {
	eString=configErrorString (status) ;
	syslog(LOG_ERR,"Error reading %s: %s\n",globalConfFile,eString);
    }

    makeDirectories(CALIBD_STATUS_LINK_DIR);
    makeDirectories(HK_TELEM_DIR);
    makeDirectories(HK_TELEM_LINK_DIR);

    prepWriterStructs();

    //Need to set digital carrier num
    retVal=readConfigFile();
    //Setup acromag
    acromagSetup();
    ip470Setup();

    //Set code values
    autoZeroStruct.code=IP320_AVZ;
    rawDataStruct.code=IP320_RAW;
    calDataStruct.code=IP320_CAL;



    do {
	if(printToScreen) printf("Initializing Calibd\n");
	retVal=readConfigFile();
	relaysChanged=1;
	currentState=PROG_STATE_RUN;
//RJN for Hkd
        ip320Setup();
	millisecs=0;
	lastRelayWriteSec=0;
	while(currentState==PROG_STATE_RUN) {	  
	  time(&rawTime);
	  
	  //Set Relays to correct state
	  if(relaysChanged || firstTime) retVal=setRelays();
	  
	  if(relaysChanged || (rawTime-lastRelayWriteSec)>=relayWritePeriod) {

	    if(printToScreen) {
	      printf("Amplite1 (%d)  Amplite2 (%d)  BZAmpa1 (%d)  BZAmpa2 (%d)  NTUAmpa (%d)\tSB (%d) SSD_5V (%d) SSD_12V (%d) SSD_Shutdown (%d)\n",stateAmplite1,stateAmplite2,stateBZAmpa1,stateBZAmpa2,stateNTUAmpa,stateSB,stateNTUSSD5V,stateNTUSSD12V,stateNTUSSDShutdown);
	    }
	    writeStatus();
	    relaysChanged=0;
	    lastRelayWriteSec=rawTime;
	  }
	    

	  if(firstTime) firstTime=0;
	  
	  

	  
	  if((millisecs % readoutPeriod)==0) {
	    
	    time(&rawTime);		
	    
	    //		printf("Mag Ret: %d\n",retVal);
	    if((rawTime-lastCal)>calibrationPeriod) {
	      ip320Calibrate();
	      outputData(IP320_CAL);
	      outputData(IP320_AVZ);
	      lastCal=rawTime;
	    }
	    ip320Read(0);
	    outputData(IP320_RAW);
	    
	    millisecs=1;
	  }
	    //Just for safety we'll reset the sleep time
	  milliWait.tv_nsec=1000000;
	  nanosleep(&milliWait,NULL);
	  millisecs++;	   	 

	} //End of run loop
    } while(currentState==PROG_STATE_INIT);
    closeHkFilesAndTidy(&hkRawWriter);
    closeHkFilesAndTidy(&hkCalWriter);
    closeHkFilesAndTidy(&calibWriter);
    unlink(CALIBD_PID_FILE);
    syslog(LOG_INFO,"Calibd Terminating");
    return 0;
    
 }
Esempio n. 8
0
int readConfig()
// Load LOSd config stuff
{
  // Config file thingies
  KvpErrorCode kvpStatus=0;
  int status=0,tempNum,count,maxVal,maxIndex;
  char* eString ;
  kvpReset();
  status = configLoad ("LOSd.config","output") ;
  if(status == CONFIG_E_OK) {
    printToScreen=kvpGetInt("printToScreen",-1);
    verbosity=kvpGetInt("verbosity",-1);
    if(printToScreen<0) {
      syslog(LOG_WARNING,
	     "Couldn't fetch printToScreen, defaulting to zero");
      printToScreen=0;
    }
  }
  else {
    eString=configErrorString (status) ;
    syslog(LOG_ERR,"Error reading LOSd.config: %s\n",eString);
    fprintf(stderr,"Error reading LOSd.config: %s\n",eString);
  }
  kvpReset();
  status = configLoad ("LOSd.config","losd");
  if(status == CONFIG_E_OK) {
    sendData=kvpGetInt("sendData",0);
    sendWavePackets=kvpGetInt("sendWavePackets",0);
    maxEventsBetweenLists=kvpGetInt("maxEventsBetweenLists",100);
    minTimeWait_b = kvpGetFloat("minTimeWait_b", 0.005); 
    minTimeWait_m = kvpGetFloat("minTimeWait_m", 1e-5); 
    laptopDebug=kvpGetInt("laptopDebug",0);
    losBus=kvpGetInt("losBus",1);
    losSlot=kvpGetInt("losSlot",1);
  }
  else {
    eString=configErrorString (status) ;
    syslog(LOG_ERR,"Error reading LOSd.config: %s\n",eString);
    fprintf(stderr,"Error reading LOSd.config: %s\n",eString);
  }
  kvpReset();
  status = configLoad ("LOSd.config","bandwidth") ;
  if(status == CONFIG_E_OK) {
    eventBandwidth=kvpGetInt("eventBandwidth",80);
    tempNum=10;
    kvpStatus = kvpGetIntArray("priorityBandwidths",priorityBandwidths,&tempNum);
    if(kvpStatus!=KVP_E_OK) {
      syslog(LOG_WARNING,"kvpGetIntArray(priorityBandwidths): %s",
	     kvpErrorString(kvpStatus));
      if(printToScreen)
	fprintf(stderr,"kvpGetIntArray(priorityBandwidths): %s\n",
		kvpErrorString(kvpStatus));
    }
    else {
      for(orderIndex=0;orderIndex<NUM_PRIORITIES*100;orderIndex++) {
	//Check for hundreds first
	for(count=0;count<tempNum;count++) {
	  if(priorityBandwidths[count]>=100) 
	    priorityOrder[orderIndex++]=count;
	}
		

	//Next look for highest number
	maxVal=0;
	maxIndex=-1;
	for(count=0;count<tempNum;count++) {
	  if(priorityBandwidths[count]<100) {
	    if(priorityBandwidths[count]>maxVal) {
	      maxVal=priorityBandwidths[count];
	      maxIndex=count;
	    }
	  }
	}
	if(maxIndex>-1) {
	  priorityOrder[orderIndex]=maxIndex;
	  priorityBandwidths[maxIndex]--;
	}
	else break;
      }			
      numOrders=orderIndex;
      if(printToScreen) {
	printf("Priority Order\n");
	for(orderIndex=0;orderIndex<numOrders;orderIndex++) {
	  printf("%d ",priorityOrder[orderIndex]);
	}
	printf("\n");
      }
    }
  }
  else {
    eString=configErrorString (status) ;
    syslog(LOG_ERR,"Error reading LOSd.config: %s\n",eString);
    fprintf(stderr,"Error reading LOSd.config: %s\n",eString);
  }

  return status;
}
int main (int argc, char *argv[])
{
    char ip470carrier[FILENAME_MAX];
    sprintf(ip470carrier,"%s",carrierDefault);
    int retVal,port,channel,value,ip470BoardLocation=0;
    int gpsOnPort,gpsOffPort,ndOnPort,ndOffPort,rfcmOnPort,rfcmOffPort;

    /* Config file thingies */
    int status=0;
    char* eString ;

    /* Log stuff */
    char *progName=basename(argv[0]);

    /* Getopt needs to run first: it'll resort the argv array */
    char option;
    while ((option = getopt(argc, argv, "tn:")) != -1)
      {
	switch (option) {
	case 't':
	  toggle = 1; printf("Toggle mode.\n"); break;
	case 'n':
	  nbits = atoi(optarg);
	  if (nbits < 2) nbits = 1;
	  printf("%d-bit mode.\n", nbits); break;
	default:
	  return usage(progName);
	}
      }
    /* All non-options are now offset by optind */
    if(argc-optind==3) {
	port = atoi(argv[optind]);
	channel = atoi(argv[optind+1]);
	value = atoi(argv[optind+2]);	
    }
    else return usage(progName);

    if (channel + nbits > 8)
      return usage(progName);


    /* Setup log */
    setlogmask(LOG_UPTO(LOG_INFO));
    openlog (progName, LOG_PID, ANITA_LOG_FACILITY) ;

   
    /* Load Config */
    kvpReset () ;
    status = configLoad ("Hkd.config","relaycontrol") ;
    eString = configErrorString (status) ;

    /* Get Port Numbers */
    if (status == CONFIG_E_OK) {
        char *temp;
	temp = kvpGetString("ip470carrier");
	if (temp != NULL) sprintf(ip470carrier,"%s",temp);
	ip470BoardLocation=kvpGetInt("ip470BoardLocation",-1);
	gpsOnPort=kvpGetInt("gpsOnLogic",-1);
	gpsOffPort=kvpGetInt("gpsOffLogic",-1);
	ndOnPort=kvpGetInt("ndOnLogic",-1);
	ndOffPort=kvpGetInt("ndOffLogic",-1);
	rfcmOnPort=kvpGetInt("rfcmOnLogic",-1);
	rfcmOffPort=kvpGetInt("rfcmOffLogic",-1);
    }
    else {
	printf("Error trying to read %s:\t%s\n","Hkd.config",eString);
    }
    
    printf("ip470carrier: %s\n", ip470carrier);
    retVal=0;

    acromagSetup(ip470BoardLocation, ip470carrier);
    ip470Setup();
	
    retVal=ip470Write(port,channel,value);
    if(retVal<0) {
	printf("Error setting: port %d, chan %d, value %d\n%d\n",port,channel,value,retVal);
	return 0;
    }
    printf("Set: port %d, chan %d, value %d\n%d\n",port,channel,value,retVal);
    return 0;
}