int main(int argc, char **argv){ /* */ //int ii=0;// jj=0; int ans=0; int mapHVmon; // pid_t pid; /* printf("Working directory: %s\n",getcwd(path,PATH_MAX+1)); strcpy(mpod_mib,path); // copy path to mpod mib file strcat(mpod_mib,"/"); // add back the ending directory slash strcat(mpod_mib,MPOD_MIB); // tack on the mib file location printf(" mpod_mib file: %s\n",mpod_mib); */ /* Memory map creation and attachment the segment number is stored in hvptr->pid */ mapHVmon = mmapSetup(); if (mapHVmon == -1) return 0; /* Scroll through options */ while (ans != 100){ menu1(); // scanf ("%i", &ans); // read in ans (pointer is indicated) ans = scan2int (); switch (ans){ case 0: // end program but not kelvin ans = 100; break; case 1: // display temps and limits do not communicate to kelvin printOut(); break; case 2: // display temps and limits printOut(); hvptr->com0 = 2; // command (3) stored in SHM so hvmon can do something printOut(); break; case 3: // display temps and limits printOut(); hvptr->com0 = 3; // command (3) stored in SHM so hvmon can do something printOut(); break; case 4: // display temps and limits printf("HV on...\n"); hvptr->com0 = 4; kill(hvptr->pid,SIGALRM); //send to hvmon for action /*char cmdResult[140]="\0"; int onOff=100; snmp(0,0,"outputSwitch.u300",cmdResult); onOff = readOnOff(cmdResult); printf("%s :cmd, %i : onOFF", cmdResult, onOff); */ //mpodOnOff(1); break; case 5: // display temps and limits printf("HV off...\n"); //mpodOnOff(0); hvptr->com0 = 5; kill(hvptr->pid,SIGALRM); //send to hvmon for action break; case 6: // Save Config File printf("Saving file...\n"); openSaveFile(); fprintOut(); fclose(fileSave); printf("file is saved ...\n"); break; case 7: printf("N/A\n"); //hvptr->com0 = 7; // command (3) stored in SHM so kelvin can do something //kill(hvptr->pid,SIGALRM); // send an alarm to let kelvin know it needs to do command (1) //printf("Recover setup from hardware ...\n"); //sleep(1); break; case 8: // display temps and limits printActive(); break; case 9: printInactive(); break; case 11: // display temps and limits printf("Clone channel parameters...\n"); clone(); break; /* case 14: // display temps and limits printf("Channel HV on...\n"); printInactive(); printf("which channel to turn on?"); ii = scan2int(); hvptr->xx[ii].onoff = 1; hvptr->com0=14; kill(hvptr->pid,SIGALRM); //send to hvmon for action break; case 15: // display temps and limits printf("Channel HV off...\n"); printActive(); printf("which channel to turn off?"); ii = scan2int(); hvptr->xx[ii].onoff = 0; hvptr->com0=15; kill(hvptr->pid,SIGALRM); //send to hvmon for action break; */ case 16: // display temps and limits printf ("Alter parameters.\n"); printAvailable(); detParam(); hvptr->com0=16; kill(hvptr->pid,SIGALRM); // send an alarm to let hvmon know it needs to do command (1) break; case 17: printf("N/A Load config from file...\n"); break; case 18: printf("Reseting.....\n"); ResetAllChan(); break; case 19: printf("Configuration:\n"); printOut(); break; case 100: // End ALL kelvin programs by breaking out of while statement hvptr->com0=-1; // send command to hvmon to break out of its while command hvptr->com1=-1; // send command to hvmon-log to break out of its while command hvptr->com2=-1; // send command to hvmon-daq to break out of its while command kill(hvptr->pid,SIGALRM); break; default: // Do nothing and go back to the list of options ans = 0; break; } } /* Release the shared memory and close the U3 */ if (munmap(hvptr, sizeof (struct hvmon*)) == -1) { perror("Error un-mmapping the file"); /* Decide here whether to close(fd) and exit() or not. Depends... */ } close(mapHVmon); return 0; }
/*=export_func optionSaveFile * * what: saves the option state to a file * * arg: tOptions*, pOpts, program options descriptor * * doc: * * This routine will save the state of option processing to a file. The name * of that file can be specified with the argument to the @code{--save-opts} * option, or by appending the @code{rcfile} attribute to the last * @code{homerc} attribute. If no @code{rcfile} attribute was specified, it * will default to @code{.@i{programname}rc}. If you wish to specify another * file, you should invoke the @code{SET_OPT_SAVE_OPTS( @i{filename} )} macro. * * The recommend usage is as follows: * @example * optionProcess(&progOptions, argc, argv); * if (i_want_a_non_standard_place_for_this) * SET_OPT_SAVE_OPTS("myfilename"); * optionSaveFile(&progOptions); * @end example * * err: * * If no @code{homerc} file was specified, this routine will silently return * and do nothing. If the output file cannot be created or updated, a message * will be printed to @code{stderr} and the routine will return. =*/ void optionSaveFile( tOptions* pOpts ) { tOptDesc* pOD; int ct; FILE* fp = openSaveFile(pOpts); if (fp == NULL) return; /* * FOR each of the defined options, ... */ ct = pOpts->presetOptCt; pOD = pOpts->pOptDesc; do { tOptDesc* p; /* * IF the option has not been defined * OR it does not take an initialization value * OR it is equivalenced to another option * THEN continue (ignore it) * * Equivalenced options get picked up when the equivalenced-to * option is processed. */ if (UNUSED_OPT( pOD )) continue; if ((pOD->fOptState & OPTST_DO_NOT_SAVE_MASK) != 0) continue; if ( (pOD->optEquivIndex != NO_EQUIVALENT) && (pOD->optEquivIndex != pOD->optIndex)) continue; /* * The option argument data are found at the equivalenced-to option, * but the actual option argument type comes from the original * option descriptor. Be careful! */ p = ((pOD->fOptState & OPTST_EQUIVALENCE) != 0) ? (pOpts->pOptDesc + pOD->optActualIndex) : pOD; switch (OPTST_GET_ARGTYPE(pOD->fOptState)) { case OPARG_TYPE_NONE: printNoArgOpt(fp, p, pOD); break; case OPARG_TYPE_NUMERIC: printEntry( fp, p, (void*)(p->optArg.argInt)); break; case OPARG_TYPE_STRING: printStringArg(fp, p); break; case OPARG_TYPE_ENUMERATION: printEnumArg(fp, p); break; case OPARG_TYPE_MEMBERSHIP: printSetMemberArg(fp, p); break; case OPARG_TYPE_BOOLEAN: printEntry( fp, p, p->optArg.argBool ? "true" : "false" ); break; case OPARG_TYPE_HIERARCHY: printHierarchy(fp, p); break; case OPARG_TYPE_FILE: printFileArg(fp, p, pOpts); break; default: break; /* cannot handle - skip it */ } } while ( (pOD++), (--ct > 0)); fclose( fp ); }