void loop() { if( XBee.available() ) { analyzeData(); } }
int main (int argc, char **argv) { int i; int upOrDown; int revolutions,dataPointsPerRevolution; time_t rawtime; float returnFloat; //float probeOffset,mag1Voltage,mag2Voltage; struct tm * timeinfo; char fileName[BUFSIZE], comments[BUFSIZE]; char dailyFileName[BUFSIZE]; char dataCollectionFileName[] = "/home/pi/.takingData"; FILE *fp,*dataCollectionFlagFile,*configFile; float angle=-99; float desiredAngle,tempChange; if (argc==4){ upOrDown=atof(argv[1]); desiredAngle=atof(argv[2]); strcpy(comments,argv[3]); } else { printf("usage '~$ sudo ./stepTemperatureWaitForRotationAngle <up or down (0 down, 1 up)> <desired Angle> <comments in quotes>'\n"); printf(" Don't forget to edit the config file! \n"); return 1; } // Indicate that data is being collected. dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("unable to open file:\t%s\n",dataCollectionFileName); exit(1); } revolutions=1; dataPointsPerRevolution=(int)STEPSPERREV/STEPSIZE; // Set up interfacing devices initializeBoard(); initializeUSB1208(); if(upOrDown==0){ tempChange=-.1; }else{ tempChange=.1; } do{ getPVCN7500(CN_RESERVE,&returnFloat); setSVCN7500(CN_RESERVE,returnFloat+tempChange); delay(1800000); //delay(180); configFile=fopen("/home/pi/RbControl/system.cfg","r"); if (!configFile) { printf("Unable to open config file\n"); exit(1); } // Get file name. Use format "FDayScan"+$DATE+$TIME+".dat" time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo); //INCLUDE if (stat(fileName, &st) == -1){ mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO ); } strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/FDayRotation%F_%H%M%S.dat",timeinfo); //INCLUDE strftime(dailyFileName,BUFSIZE,"/home/pi/RbData/%F/FDayRotation%F.dat",timeinfo); //INCLUDE printf("%s\n",fileName); printf("%s\n",comments); fp=fopen(fileName,"w"); if (!fp) { printf("Unable to open file: %s\n",fileName); exit(1); } fprintf(fp,"#Filename:\t%s\n#Comments:\t%s\n",fileName,comments); getIonGauge(&returnFloat); //printf("IonGauge %2.2E Torr \n",returnFloat); fprintf(fp,"#IonGauge(Torr):\t%2.2E\n",returnFloat); getConvectron(GP_N2_CHAN,&returnFloat); //printf("CVGauge(N2) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(N2)(Torr):\t%2.2E\n", returnFloat); getConvectron(GP_HE_CHAN,&returnFloat); //printf("CVGauge(He) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(He)(Torr):\t%2.2E\n", returnFloat); getPVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res:\t%f\n",returnFloat); getSVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res_set:\t%f\n",returnFloat); getPVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg:\t%f\n",returnFloat); getSVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg_set:\t%f\n",returnFloat); char line[1024]; fgets(line,1024,configFile); while(line[0]=='#'){ fprintf(fp,"%s",line); fgets(line,1024,configFile); } fclose(configFile); fprintf(fp,"#Revolutions:\t%d\n",revolutions); fprintf(fp,"#DataPointsPerRev:\t%d\n",dataPointsPerRevolution); fprintf(fp,"#NumVoltages:\t%d\n",1); fprintf(fp,"#PumpFrequency:\t%f\n",getPumpFrequency(&returnFloat)); //fprintf(fp,"#ProbeWavelength:\t%f\n",getProbeFreq()); // UNCOMMENT THE FOLLOWING LINES WHEN COLLECTING STANDARD DATA int photoDetectors[] = {PUMP_LASER,PROBE_LASER,REF_LASER}; char* names[]={"PMP","PRB","REF"}; // UNCOMMENT THE FOLLOWING LINES WHEN USING THE FLOATING PD //int photoDetectors[] = {PROBE_LASER,PUMP_LASER,REF_LASER}; //char* names[]={"PRB","PMP","REF"}; int numPhotoDetectors = 3; int motor = PROBE_MOTOR; // Write the header for the data to the file. fprintf(fp,"STEP"); for(i=0;i<numPhotoDetectors;i++){ fprintf(fp,"\t%s\t%ssd",names[i],names[i]); } fprintf(fp,"\n"); fclose(fp); fp=fopen(fileName,"a"); homeMotor(motor); angle=collectDiscreteFourierData(fp, photoDetectors, numPhotoDetectors, motor, revolutions); printf("The measured angle was: %3.1f\n",angle); fclose(fp); printf("Processing Data...\n"); analyzeData(fileName, 1, revolutions, dataPointsPerRevolution,FOI); }while(angle > desiredAngle + .4 || angle < desiredAngle -.4); closeUSB1208(); // Remove the file indicating that we are taking data. fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }