void vv2monitor(char *ip) { #if __powerpc__ int d; char dsmhost[NAMELEN]; int originaldd, original; short lock1,lock2; struct sigaction action, oldAction; continueVVMlogging = 1; d = dsm_open(); if (d) { dsm_error_message(d,"dsm_open"); return; } original = whichVVM; originaldd = whichVVMdd; strcpy(dsmhost,"hal9000"); /* install control-c handler */ action.sa_flags = 0; action.sa_handler = cleanupControlCvvm; sigemptyset(&action.sa_mask); if (sigaction(SIGINT, &action, &oldAction) != 0) { STRERROR("sigaction:"); } WARN("Control-C handler installed. Hit Cntrl-C to exit the DSM logging mode.\n"); do { whichVVM = 1; whichVVMdd = vector_voltmeter.dd; lock1 = vectorQueryLock(); whichVVM = 2; whichVVMdd = vector_voltmeter2.dd; lock2 = vectorQueryLock(); d = dsm_write(dsmhost,"DSM_VVM1_LOCK_STATUS_S",&lock1); if (d) { dsm_error_message(d,"dsm_write(DSM_VVM1_LOCK_STATUS_S)"); } d=dsm_write(dsmhost,"DSM_VVM2_LOCK_STATUS_S",&lock2); if (d) { dsm_error_message(d,"dsm_write(DSM_VVM2_LOCK_STATUS_S)"); } sleep(5); } while (continueVVMlogging == 1); d = dsm_close(); WARN("restoring previous control-c handler (if any)\n"); if (sigaction(SIGINT, &oldAction, &action) != 0) { STRERROR("sigaction:"); } whichVVM = original; whichVVMdd = originaldd; #else WARN("This feature is not supported on linux\n"); #endif }
static void read_param(u8 *param) { int x=0; uint32_t filter_set; int32_t port_id =0x4000; //hardcoded to slimbus filter_set = 2; dsm_open(port_id, &filter_set, param); memcpy(¶m_voice_coil_temp, ¶m[x*4], 4); x++; memcpy(¶m_voice_coil_temp_sz, ¶m[x*4], 4); x++; memcpy(¶m_excursion, ¶m[x*4], 4); x++; memcpy(¶m_excursion_sz, ¶m[x*4], 4); x++; memcpy(¶m_rdc, ¶m[x*4], 4); x++; memcpy(¶m_rdc_sz, ¶m[x*4], 4); x++; memcpy(¶m_q, ¶m[x*4], 4); x++; memcpy(¶m_q_sz, ¶m[x*4], 4); x++; memcpy(¶m_fres, ¶m[x*4], 4); x++; memcpy(¶m_fres_sz, ¶m[x*4], 4); x++; memcpy(¶m_excur_limit, ¶m[x*4], 4); x++; memcpy(¶m_excur_limit_sz, ¶m[x*4], 4); x++; memcpy(¶m_voice_coil, ¶m[x*4], 4); x++; memcpy(¶m_voice_coil_sz, ¶m[x*4], 4); x++; memcpy(¶m_thermal_limit, ¶m[x*4], 4); x++; memcpy(¶m_thermal_limit_sz, ¶m[x*4], 4); x++; memcpy(¶m_release_time, ¶m[x*4], 4); x++; memcpy(¶m_release_time_sz, ¶m[x*4], 4); x++; memcpy(¶m_onoff, ¶m[x*4], 4); x++; memcpy(¶m_onoff_sz, ¶m[x*4], 4); /* get params from the algorithm to application */ //pr_info("[RYAN] read_param(1) param_rdc:%d, param_q:%d, param_fres:%d\n", param_rdc, param_q, param_fres); //pr_info("[RYAN] read_param(2) param_excur_limit:%d, param_voice_coil:%d, param_thermal_limit:%d\n", param_excur_limit, param_voice_coil, param_thermal_limit); //pr_info("[RYAN] read_param(3) param_release_time:%d, param_onoff:%d\n", param_release_time, param_onoff); }
static void write_param(u8 *param) { uint32_t filter_set; int32_t port_id =0x4000; //hardcoded to slimbus int x=0; x=10; memcpy(¶m_excur_limit, ¶m[x*4], 4); x+=2; memcpy(¶m_voice_coil, ¶m[x*4], 4); x+=2; memcpy(¶m_thermal_limit, ¶m[x*4], 4); x+=2; memcpy(¶m_release_time, ¶m[x*4], 4); x+=2; memcpy(¶m_onoff, ¶m[x*4], 4); /* set params from the algorithm to application */ filter_set = 3; dsm_open(port_id, &filter_set, param); //pr_info("[RYAN] write_param excur_limit:%d, voice_coil:%d\n", param_excur_limit, param_voice_coil); //pr_info("[RYAN] thermal_limit:%d, param_release_time:%d, param_onoff:%d\n", param_thermal_limit, param_release_time, param_onoff); }
int main(int argc, char *argv[]) { int s, size, notify, is_struct=0; char element[DSM_NAME_LENGTH],name[DSM_NAME_LENGTH],host[DSM_NAME_LENGTH]; char *p, *type, *val; dsm_structure ds; if(argc!=6 && argc!=7) { fprintf(stderr, "Usage: %s [-v] <hostname> <allocation name> <type> " "<value> <notify>\n", argv[0]); fprintf(stderr, " (type= (f)loat, (d)ouble, (i)nt, (s)hort, (c)har)\n"); fprintf(stderr, "notify=1 no notify=0\n"); exit(1); } if(argc==6) { strcpy(host,argv[1]); strcpy(name,argv[2]); type = argv[3]; val = argv[4]; notify = atoi(argv[5]); } else if(argc==7 && argv[1][0]!='-' && argv[1][1]!='v') { fprintf(stderr, "Usage: %s [-v] <hostname> <allocation name> <type> " "<value> <notify>\n", argv[0]); fprintf(stderr, " (type= (f)loat, (d)ouble, (i)nt, (s)hort, (c)har)\n"); fprintf(stderr, "notify=1 no notify=0\n"); exit(1); } else { strcpy(host,argv[2]); strcpy(name,argv[3]); type = argv[4]; val = argv[5]; notify = atoi(argv[6]); verbose = DSM_TRUE; } if( (s=dsm_open())!=DSM_SUCCESS) { dsm_error_message(s, "dsm_open()"); exit(1); } /* is it a structure? */ if((p = strchr(name, ':')) !=NULL) { /* yes! separate the structure name from the element name */ *p = '\0'; p++; strcpy(element, p); is_struct = DSM_TRUE; s = dsm_structure_init(&ds, name); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_structure_init"); exit(1); } s = dsm_read(host, name, &ds, NULL); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_read"); exit(1); } } if(type[0]=='c') size = atoi(type+1); else size = 8; p = (char *)malloc(size); if(p==NULL) { fprintf(stderr,"Error: can't malloc(%d)\n", size); exit(1); } switch(type[0]) { case 'f': *((float *)p) = (float)atof(val); break; case 'd': *((double *)p) = atof(val); break; case 'i': *((unsigned int *)p) = (int)strtoul(val,NULL,0); break; case 's': *((short *)p) = (short)strtol(val,NULL,0); break; case 'c': strcpy(p,val); break; default: fprintf(stderr, "type %c unknown\n", type[0]); exit(1); } if(is_struct) { s = dsm_structure_set_element(&ds, element, p); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_structure_set_element"); exit(1); } p = &ds; } if(notify==1) { s=dsm_write_notify(host, name, p); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_write_notify()"); exit(1); } } else { s=dsm_write(host, name, p); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_write()"); exit(1); } } return(0); }
int main(int argc, char *argv[]) { int s,i; char p[1000],name[DSM_NAME_LENGTH],host[DSM_NAME_LENGTH]; int n_struct = 100; dsm_structure ds[n_struct]; if(argc<2 || argc % 2 != 1) { fprintf(stderr, "Usage: %s <host alloc> [host alloc]...\n", argv[0]); exit(1); } for(i=0; i<n_struct; i++) ds[i].name[0] = '\0'; if( (s=dsm_open())!=DSM_SUCCESS) { dsm_error_message(s, "dsm_open()"); exit(1); } dprintf("dsm_open() succeeded\n"); for(i=1; i<argc; i+=2) { if(argv[i+1][strlen(argv[i+1])-1] == 'X') { s=dsm_structure_init(&ds[i], argv[i+1]); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_structure_init"); } s=dsm_monitor(argv[i], argv[i+1], &ds[i]); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_monitor(struct)"); exit(1); } } else { s=dsm_monitor(argv[i], argv[i+1]); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_monitor(nonstruct)"); exit(1); } } dprintf("dsm_monitor(%s:%s) succeeded\n", argv[i], argv[i+1]); } dprintf("calling dsm_read_wait()\n"); s=dsm_read_wait(host, name, p); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_read()"); exit(1); } if(name[strlen(name)-1]=='X') { dsm_structure *sp = *((dsm_structure **)p); /* it's a structure */ printf("received %s from %s\n", name, host); for(i=0; i<sp->n_elements; i++) { printf(" %30s: val 0x%08x\n", sp->elements[i].name, *(unsigned *)(sp->elements[i].datap)); } } else { printf("received %s from %s, value 0x%08x\n", name, host, *((unsigned *)p)); } return(0); }
int main(int argc, char *argv[]) { int pid=(int)getpid(); int i,j,s; unsigned long randseed; int howmany, totalallocs=0; size_t size; u_long mach,alloc; char myhostname[DSM_NAME_LENGTH]; u_long *my_addresses; u_long my_address; int my_num_addresses; char *p, host[DSM_NAME_LENGTH], allocname[DSM_NAME_LENGTH]; char *progname; struct alloc_list_head *alhp=NULL; struct class_entry *clp=NULL; struct class_share *csp=NULL; u_long nmachines,nclasses,nclassshares,version; int readwait; time_t t; int is_structure; #define NSTRUCT 100 dsm_structure ds[NSTRUCT]; struct timeval now; struct timezone dummy; char allocfile[256]; /*********/ /* Begin */ /*********/ if(argc>1 && argv[1][0]=='-' && argv[1][1]=='v') verbose=DSM_TRUE; progname = strrchr(argv[0], '/'); if(progname == (char *)NULL) progname = argv[0]; else progname += 1; for(i=0; i<NSTRUCT; i++) ds[i].name[0] = '\0'; /*************************************************/ /* now get the allocation table and my host info */ /*************************************************/ s = dsm_determine_network_info(&my_addresses, &my_num_addresses, myhostname); if(s != DSM_SUCCESS) { fprintf(stderr, "Failed to determine our network information\n"); exit(DSM_ERROR); } allocfile[0] = '\0'; dsm_determine_alloc_file_location(allocfile); if(dsm_read_allocation_file(&alhp, &nmachines, &clp, &nclasses, &csp, &nclassshares, &version, my_addresses, my_num_addresses, &my_address, allocfile) != DSM_SUCCESS) { fprintf(stderr, "Couldn't read allocation file\n"); exit(DSM_ERROR); } if(alhp == NULL) { printf("No allocations for my host address 0x%lx\n",my_address); exit(DSM_ERROR); } printf("Read allocations for %ld machines\n", nmachines); totalallocs=0; for(i=0; i<nmachines; i++) { if(verbose) printf("Host #%d %s, %d allocs\n", i, alhp[i].machine_name, alhp[i].nallocs); for(j=0; j<alhp[i].nallocs; j++) { if(verbose) printf(" alloc #%d size %3d %s\n", j, alhp[i].allocs[j].size, alhp[i].allocs[j].name); totalallocs++; } } /************************/ /* start dsm operations */ /************************/ if( (s=dsm_open())!=DSM_SUCCESS) { dsm_error_message(s, "dsm_open()"); exit(DSM_ERROR); } randseed = (unsigned long)time(NULL)/* + (unsigned long)pid*/; while(1) { if(myrandom(&randseed) & 0x2000UL) readwait = DSM_TRUE; else readwait = DSM_FALSE; /* how many allocations do we wait on? */ if(readwait) { howmany = 1 + (int) ((double)totalallocs * ((double)myrandom(&randseed) / (double)UINT_MAX)); if(howmany>NSTRUCT) howmany = NSTRUCT; printf("%s[%d] will monitor %d allocations\n", progname, pid, howmany); } else { howmany = 1; } size = 0; for(i=0; i<howmany; i++) { dprintf("%s[%d]: looping to select howmany=%d allocs; doing i=%d\n", progname, pid, howmany, i); /* pick one at random */ mach = (int)((double)nmachines * myrandom(&randseed) / UINT_MAX); alloc = (int)((double)alhp[mach].nallocs * myrandom(&randseed) / UINT_MAX); is_structure = alhp[mach].allocs[alloc].is_structure; if(is_structure == DSM_TRUE) { /* it's a structure; initialize a structure object */ dprintf("about to call dsm_struct_init(&ds[%d], %s)\n", i, alhp[mach].allocs[alloc].name); s = dsm_structure_init(&ds[i], alhp[mach].allocs[alloc].name); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_structure_init"); fprintf(stderr, "can't initialize dsm_struct for %s; skipping\n", alhp[mach].allocs[alloc].name); continue; } size = sizeof(dsm_structure *) > size ? sizeof(dsm_structure *) : size; } else { size = alhp[mach].allocs[alloc].size > size ? alhp[mach].allocs[alloc].size : size; } if(readwait) { dprintf("%s[%d]: mach = %d/%d alloc=%d/%d size=%d\n", progname, pid, mach, nmachines, alloc, alhp[mach].nallocs, size); dprintf("%s[%d]: calling dsm_monitor for \"%s\":\"%s\"\n", progname,pid, alhp[mach].machine_name,alhp[mach].allocs[alloc].name); if(is_structure==DSM_TRUE) { s = dsm_monitor(alhp[mach].machine_name, alhp[mach].allocs[alloc].name, &ds[i]); } else { s = dsm_monitor(alhp[mach].machine_name, alhp[mach].allocs[alloc].name); } if(s!=DSM_SUCCESS) { if(s==DSM_IN_MON_LIST) { if(is_structure==DSM_TRUE) { dsm_structure_destroy(&ds[i]); ds[i].name[0]='\0'; } --i; continue; } else { fprintf(stderr, "error: alloc %s/%s\n", alhp[mach].machine_name,alhp[mach].allocs[alloc].name); dsm_error_message(s, "dsm_monitor()"); if(s==DSM_RPC_ERROR || s==DSM_MON_LIST_EMPTY) continue; else abort(); } } printf("%s[%d]: monitor #%d (sz %d) %s:%s\n", progname,pid,i+1,alhp[mach].allocs[alloc].size, alhp[mach].machine_name,alhp[mach].allocs[alloc].name); } } /* for loop over howmany */ dprintf("%s[%d]: allocating %d for return buffer\n", progname,pid,size); p = (char *)malloc(size); if(p==(char *)NULL) { perror("malloc"); abort(); } if(readwait) { gettimeofday(&now, &dummy); printf("%s[%d]: calling dsm_read_wait() at %ld.%06ld\n", progname,pid, now.tv_sec, now.tv_usec); s = dsm_read_wait(host, allocname, p); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_read_wait()"); if(s==DSM_RPC_ERROR) { free(p); s = dsm_clear_monitor(); if(s != DSM_SUCCESS) { dsm_error_message(s,"dsm_clear_monitor()"); if(s!=DSM_RPC_ERROR) abort(); } sleep(2); continue; } else if(s==DSM_MON_LIST_EMPTY) { free(p); continue; } else abort(); } if(allocname[strlen(allocname)-1]=='X') { dsm_structure *sp = *((dsm_structure **)p); printf("%s[%d] **** received %s:%s\n", progname, pid, host, allocname); for(i=0; i<sp->n_elements; i++) { printf(" %s: lval=%d at %d\n", sp->elements[i].name, *(unsigned *)(sp->elements[i].datap), (int)time(NULL)); } } else { gettimeofday(&now, &dummy); printf("%s[%d] **** received %s:%s, lval=%ld at %ld.%06ld\n", progname, pid, host, allocname, *((long *)p), now.tv_sec, now.tv_usec); } dprintf("%s[%d] calling dsm_clear_monitor()\n", progname, pid); s = dsm_clear_monitor(); if(s != DSM_SUCCESS) { dsm_error_message(s,"dsm_clear_monitor()"); if(s==DSM_RPC_ERROR) { free(p); continue; } else abort(); } for(i=0; i<NSTRUCT; i++) { if(ds[i].name[0] != '\0') { dsm_structure_destroy(&ds[i]); ds[i].name[0] = '\0'; } } free(p); } else { dprintf("%s[%d]: calling dsm_read() at %d\n", progname,pid, (int)time(NULL)); printf("%s[%d] **** reading %s:%s\n", progname, pid, alhp[mach].machine_name, alhp[mach].allocs[alloc].name); if(is_structure) { free(p); p = (char *)&ds[0]; } s = dsm_read(alhp[mach].machine_name, alhp[mach].allocs[alloc].name, p, &t); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_read()"); if(s==DSM_RPC_ERROR) { if(!is_structure) free(p); continue; } else abort(); } if(is_structure) { for(i=0; i<ds[0].n_elements; i++) { printf(" %30s: lval %ld\n", ds[0].elements[i].name, *(long *)(ds[0].elements[i].datap)); } dsm_structure_destroy(&ds[0]); ds[0].name[0]='\0'; } else { printf("%s[%d] lval=%ld at %d\n", progname, pid, *((long *)p), (int)time(NULL)); free(p); } } /* if not read_wait */ printf("\n\n"); } /* while 1 */ return(0); }
main(int argc, char *argv[]) { int i; int ant=ARRAY_DISPLAY; /* start up on the 'a' page */ int cycle = FALSE; int delay = 1; #ifdef LINUX int spinCount = 0; #endif char *outputFile = NULL; struct utsname unamebuf; int rms; struct sigaction action, old_action; int sigactionInt; int icount=0; int firstUpdate = TRUE; int rc; int startDay; int message = 0; int ignoreFlag; struct stat messageStat, oldMessageStat; /* The following variables are for the default Tilt flag read from the pointing model files */ FILE *fpMountModel; int itilt; char mountModelFile[100],line[BUFSIZ]; char pointingParameter[20],opticalValue[20],radioValue[20]; /* signal handler for control C */ action.sa_flags=0; sigemptyset(&action.sa_mask); action.sa_handler = handlerForSIGINT; sigactionInt = sigaction(SIGINT,&action, &old_action); uname(&unamebuf); #ifndef LINUX if(strcmp(unamebuf.nodename,"hal9000")) { printf("This program will run only on hal9000. Bye.\n"); exit(-1); } #endif #if DEBUG fprintf(stderr,"Finished opening RM\n"); #endif i = 0; #if 0 while (antlist[i] != RM_ANT_LIST_END) { antsAvailable[antlist[i]] = 1; deadAntennas[antlist[i]] = 0; i++; } #endif #if 0 defaultTiltFlag[0]=0; for(itilt=1;itilt<=8;itilt++) { defaultTiltFlag[itilt]=0; sprintf(mountModelFile,"/otherInstances/acc/%d/configFiles/pointingModel",itilt); fpMountModel=fopen(mountModelFile,"r"); if(fpMountModel!=NULL) { while(fgets(line,sizeof(line),fpMountModel) != NULL) { line[strlen(line)-1]='\0'; if(line[0]!='#') { sscanf(line,"%s %s %s", pointingParameter, opticalValue, radioValue); if(!strcmp(pointingParameter,"TiltFlag")) { defaultTiltFlag[itilt]=(int)atof(radioValue); } } } } fclose(fpMountModel); } #endif rms = dsm_open(); if(rms != DSM_SUCCESS) { dsm_error_message(rms, "dsm_open"); exit(-1); } #if DEBUG fprintf(stderr,"Finished opening DSM\n"); #endif /* * This is to get the user input as a single unbuffered char and * zero-wait */ ioctl(0, TCGETA, &tio); tin = tio; tin.c_lflag &= ~ECHO; tin.c_lflag &= ~ICANON; tin.c_cc[VMIN] = 0; tin.c_cc[VTIME] = 0; ioctl(0, TCSETA, &tin); stat(MESSAGES_LOG, &oldMessageStat); #if DEBUG fprintf(stderr,"1. Finished stat() on messages file\n"); #endif /* starting infinite loop */ /* begin while loop every 1 second */ initialize(); while (1) { time_t lastKeystrokeTime, curTime; #ifndef LINUX yield(); #endif ioctl(0, TCSETA,&tin); icount++; lastUser = user; user = getchar(); switch (user) { case 'q': move(LINES-1,0); printw("Bye.\n"); refresh(); ioctl(0, TCSETA, &tio); goto80width(); printf("\n"); rms = dsm_close(); if(rms != DSM_SUCCESS) { dsm_error_message(rms, "dsm_close"); exit(-1); } exit(0); break; } /* end of switch */ ant=1; antDisplay(ant, icount); #ifndef LINUX sleep(delay); #else usleep(delay*500000); spinCount++; if ((spinCount % 2) && ((icount % 30) > 1)) icount--; #endif } /* this is the big while loop */ ioctl(0, TCSETA, &tio); } /* end of main Loop */
int main(int argc, char *argv[]) { void dotimestats(char, struct timeval, struct timeval); int s, i, j; char *p; size_t size; struct alloc_list_head *alhp = NULL, **mainalhp; struct class_entry *clp = NULL; struct class_share *csp = NULL; u_long nmachines, n, nclasses, nclassshares; u_long version; u_long my_address; u_long *my_addresses; int my_num_addresses; u_long mach; struct hostent *hep; char myhostname[DSM_NAME_LENGTH]; unsigned usec; int random=DSM_FALSE; int delay=1000000; unsigned long randseed; struct timeval start,stop; struct timezone zone; time_t t; char allocfile[256]; /*********/ /* Begin */ /*********/ signal(SIGINT, (void *)siginthandler); /* with no args, print usage */ if(argc==1) USAGE; /* command line args */ for(i=1; i<argc; i++) { if(argv[i][0] != '-') USAGE; switch(argv[i][1]) { case 'v': verbose = DSM_TRUE; break; case 'd': if(++i >= argc) USAGE; if(argv[i][0]=='r') { random=DSM_TRUE; if(++i >= argc) USAGE; } delay = atoi(argv[i]); if(delay <= 0) USAGE; break; default: USAGE; } } printf("Verbose %s, delay = ", verbose==DSM_TRUE ? "on" : "off"); if(random==DSM_TRUE) printf("random, maxdur = %d usec\n", delay); else printf("%d usec\n", delay); /********************************/ /* now get the allocation table */ /********************************/ s = dsm_determine_network_info(&my_addresses, &my_num_addresses, myhostname); if(s != DSM_SUCCESS) { fprintf(stderr, "Failed to determine our network information\n"); exit(DSM_ERROR); } allocfile[0] = '\0'; dsm_determine_alloc_file_location(allocfile); if(dsm_read_allocation_file(&alhp, &nmachines, &clp, &nclasses, &csp, &nclassshares, &version, my_addresses, my_num_addresses, &my_address, allocfile) != DSM_SUCCESS) { fprintf(stderr, "Couldn't read allocation file\n"); exit(DSM_ERROR); } if(alhp == NULL) { printf("No allocations for my host address 0x%lx\n",my_address); exit(DSM_ERROR); } printf("Read allocations for %ld machines\n", nmachines); if(verbose) { for(i=0; i<nmachines; i++) { printf("Host %s, %d allocs\n", alhp[i].machine_name, alhp[i].nallocs); for(j=0; j<alhp[i].nallocs; j++) { printf(" size %3d %s\n", alhp[i].allocs[j].size, alhp[i].allocs[j].name); } } } /* weed out any machines which do not have the LATENCY_VAR variable */ if(verbose) printf("finding hosts which have allocation %s\n", LATENCY_VAR); mainalhp = (struct alloc_list_head **) malloc(nmachines * sizeof(struct alloc_list_head *)); if(mainalhp == NULL){ perror("malloc(mainalhp)"); exit(1); } n=0; for(i=0; i<nmachines; i++) { for(j=0; j<alhp[i].nallocs; j++) { if(!strcmp(alhp[i].allocs[j].name, LATENCY_VAR)) { mainalhp[n++] = &alhp[i]; if(verbose) printf("machine %s has allocation %s\n", alhp[i].machine_name, LATENCY_VAR); break; } } } if(verbose) printf("found %ld machines with allocation %s\n", n, LATENCY_VAR); /************************/ /* start dsm operations */ /************************/ while( (s=dsm_open())!=DSM_SUCCESS) { dsm_error_message(s, "dsm_open()"); sleep(1); } randseed = (unsigned long)time(NULL); while(1) { /* pick a random machine */ mach = (int)((double)n * myrandom(&randseed) / UINT_MAX); size = LATENCY_VAR_SIZE; if(random==DSM_TRUE) { usec = (unsigned)((double)delay * myrandom(&randseed) / UINT_MAX); } else { usec = (unsigned)(2.0 * myrandom(&randseed) / UINT_MAX); } if( (p = (char *)malloc(size)) == NULL ) { fprintf(stderr,"Error: can't malloc(%d)\n",size); exit(1); } /* are we reading or writing? */ if( usec % 2 == 0) { /* reading */ gettimeofday(&start, &zone); s=dsm_read(mainalhp[mach]->machine_name, LATENCY_VAR, p, &t); gettimeofday(&stop, &zone); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_read()"); } else { printf("R %5d %-20s: %-30s usleep(%6u)\n", *((short *)p), mainalhp[mach]->machine_name, LATENCY_VAR, random==DSM_TRUE ? usec : delay); dotimestats('r', start, stop); } free(p); } else { /* writing */ *((short *)p) = 10*mach; gettimeofday(&start, &zone); s=dsm_write(mainalhp[mach]->machine_name, LATENCY_VAR, p); gettimeofday(&stop, &zone); if(s!=DSM_SUCCESS) { dsm_error_message(s, "dsm_write()"); } else { printf("W %5d %-20s: %-30s usleep(%6u)\n", *((short *)p), mainalhp[mach]->machine_name, LATENCY_VAR, random==DSM_TRUE ? usec : delay); dotimestats('w', start, stop); } free(p); } if(random==DSM_TRUE) usleep( usec ); else usleep(delay); } return(0); }
int main(int argc, char *argv[]) { int i,dsm_status; enum DRVSTATE oldAzState, oldElState; char msg[80]; DAEMONSET #if USE_SIGTIMEDWAIT sigemptyset(&sigs); sigaddset(&sigs, SIGHUP); /* 1 */ sigaddset(&sigs, SIGINT); /* 2 */ sigaddset(&sigs, SIGQUIT); /* 3 */ sigaddset(&sigs, SIGTERM); /* 15 */ #else /* USE_SIGTIMEDWAIT */ #if CATCH_SIGNALS if(signal(SIGINT, SigIntHndlr) == SIG_ERR) { ErrPrintf("Error setting INT signal disposition\n"); exit(SYSERR_RTN); } if(signal(SIGQUIT, SigQuitHndlr) == SIG_ERR) { ErrPrintf("Error setting QUIT signal disposition\n"); exit(SYSERR_RTN); } if(signal(SIGTERM, SigQuitHndlr) == SIG_ERR) { ErrPrintf("Error setting TERM signal disposition\n"); exit(SYSERR_RTN); } if(signal(SIGHUP, SigQuitHndlr) == SIG_ERR) { ErrPrintf("Error setting HUP signal disposition\n"); exit(SYSERR_RTN); } #endif /* CATCH_SIGNALS */ #endif /* USE_SIGTIMEDWAIT */ az_amax = AZ_AMAX; el_amax = EL_AMAX; for (i=1; i<argc; i++) { if (strstr(argv[i],"-h") != NULL) { servoUsage(argv[0]); } if(strstr(argv[i],"-v") != NULL) { verbose++; } } /* Set some constants */ trAzVmax = 3*MAS; trElVmax = 3*MAS; setpriority(PRIO_PROCESS, (0), (SERVOPRIO)); umask(0111); tsshm = OpenShm(TSSHMNAME, TSSHMSZ); if(verbose) { fprintf(stderr, "tsshm = %d. ", (int)tsshm); fprintf(stderr, "Starting check of tsshm.."); for(i = 0; i < TSSHMSZ; i++) { msg[i%20] = ((char *)tsshm)[i]; } fprintf(stderr, "Done\n"); } /* Set samp buffer full so by default servo will not collect data */ tsshm->sampIn = tsshm->sampOut = 0; if(tsshm->azCmd != OFF_CMD || tsshm->elCmd != OFF_CMD) { ErrPrintf("Warning: Track was not commanding drives off\n"); tsshm->azCmd = tsshm->elCmd = OFF_CMD; } tsshm->sendEncToPalm = 0; #if SIMULATING scbStatus = 0; encAz = 0; encEl = 45*MAS; elState = azState = 0; #else /* SIMULATING */ ttfd = open("/dev/vme_sg_simple", O_RDWR, 0); if(ttfd <= 0) { ErrPrintf("Error opening TrueTime - /dev/vme_sg_simple\n"); exit(SYSERR_RTN); } i = VME_SG_SIMPLE_RATE_1K; ioctl(ttfd, VME_SG_SIMPLE_SET_PULSE_RATE, &i); tsshm->fault = NO_FAULT; OpenCntr(); /* Open the heartbeat counter */ dprintf("Counter, "); SetupCanBus(); dprintf("Canbus, "); /* SafeOpenDsm(); */ /* Since SafeOpenDsm() did not work, I am adding dsm_open here... NAP 26June12*/ dsm_status = dsm_open(); if(dsm_status != DSM_SUCCESS) { dsm_error_message(dsm_status, "dsm_open failed."); exit(-1); } dprintf("Dsm, "); WriteDsmMonitorPoints(); dprintf("Monitor points, "); /* Set a few things in a safe state. */ azState = SERVOOFF; elState = SERVOOFF; oldAzState = oldElState = SERVOOFF; #endif /* SIMULATING */ /* Set a few things in a safe state. */ azState = SERVOOFF; elState = SERVOOFF; oldAzState = oldElState = SERVOOFF; #if AZ_VERBOSE > 1 || EL_VERBOSE > 1 azPrintNext = 0; elPrintNext = 0; #endif /* VERBOSE */ WaitTickGetTime(); /* Wait for the 48 ms heartbeat */ dprintf("Tick and time, "); GetACUPosAndStatus(); dprintf("ACU pos, status, "); nxtAz[0] = lastAz / ACU_TURNS_TO_MAS; nxtAz[1] = 0; /* set zero velocity */ nxtEl[0] = lastEl / ACU_TURNS_TO_MAS; nxtEl[1] = 0; /* set zero velocity */ /* if the drives are on, set to standby, otherwise to shutdown */ if(ACUAccessMode == REMOTE) { if(azDriveMode >= STANDBY) { azModeCmd = STANDBY; } if(elDriveMode >= STANDBY) { elModeCmd = STANDBY; } SetACUMode(azDriveMode, elDriveMode); } if((tsshm->el < 10*MAS) || (tsshm->el > 90*MAS) || (tsshm->az > 270*MAS) || (tsshm->az < -270*MAS)) { tsshm->az = lastAz; tsshm->azVel = 0; tsshm->el = lastEl; tsshm->elVel = 0; } trAz = trAzRaw = tsshm->az; trEl = trElRaw = tsshm->el; dprintf("completed\n"); /* Here the infinite loop begins */ dprintf("Entering servo's main loop\n"); while(shutdownSignal == 0) { tsshm->azState = azState; tsshm->elState = elState; /* Get time and read encoder */ WaitTickGetTime(); GetACUPosAndStatus(); tsshm->encAz = lastAz; tsshm->encEl = lastEl; #if 0 CheckTrCmds(); /* Is there a new command from Track? */ #else trAz = trAzRaw = tsshm->az; trEl = trElRaw = tsshm->el; trAzVel = trAzVelRaw = tsshm->azVel; trElVel = trElVelRaw = tsshm->elVel; trMsecCmd = tsshm->msecCmd; tsshm->msecAccept = tsshm->msecCmd; #endif SaI.msec = tsshm->msec; dt = (tsshm->msec - trMsecCmd)/1000.; if(dt < -3600) dt += 24*3600; tsshm->azTrError = trAzRaw + trAzVelRaw * dt - lastAz; tsshm->elTrError = trElRaw + trElVelRaw * dt - lastEl; #if AZ_VERBOSE || EL_VERBOSE if(azState != oldAzState || elState != oldElState) { printf("at %.3f azState = %d, elState = %d\n", tsshm->msec/1000., azState, elState); oldAzState = azState; oldElState = elState; } #endif /* AZ_VERBOSE || EL_VERBOSE */ i = 0; if(tsshm->azCmd != trAzCmd) { if(tsshm->azCmd == OFF_CMD && azState != SERVOOFF) { azState = STOPPING1; i = 1; } else if(tsshm->azCmd == ON_CMD && azState == SERVOOFF) { azTry = 0; azCnt = 0; azState = STARTING1; } trAzCmd = tsshm->azCmd; } if(tsshm->elCmd != trElCmd) { if(tsshm->elCmd == OFF_CMD && elState != SERVOOFF) { elState = STOPPING1; i = 1; } if(tsshm->elCmd == ON_CMD && elState == SERVOOFF) { elTry = 0; elCnt = 0; elState = STARTING1; } trElCmd = tsshm->elCmd; } if(i) { if(i == 1) { ErrPrintf("servo received OFF_CMD from Track\n"); } } if(fabs(dt) > 3.0 && ( (azState != SERVOOFF && azState != STOPPING1 && azState != STOPPING2) || (elState != SERVOOFF && elState != STOPPING1 && elState != STOPPING2))) { ErrPrintf("Track timeout or clock jump, dt %.2f sec.," "avg. dt %.2f sec.\n", dt, avgDt); #if !SIMULATING vSendOpMessage(OPMSG_SEVERE, 19, 60, "Track timeout"); #endif /* !SIMULATING */ if(azState != SERVOOFF && azState != STOPPING1 && azState != STOPPING2) { azState = STOPPING1; } if(elState != SERVOOFF && elState != STOPPING1 && elState != STOPPING2) { elState = STOPPING1; } } avgDt += (dt - avgDt)/10; /* If svdata is not running, keep the sample buffer moving */ if(SFULL) { INC_OUT; } AzCycle(); ElCycle(); /* Save the data from this cycle */ tsshm->sampIn = NEXT_SAMP(tsshm->sampIn); /* Set up expected positions and velocities for next data cycle */ SaI.curAz = trAz + trAzVel * (dt + HEARTBEAT_PERIOD); SaI.cmdAzVel = trAzVel; SaI.curEl = trEl + trElVel * (dt + HEARTBEAT_PERIOD); SaI.cmdElVel = trElVel; if(azState != oldAzState || elState != oldElState) { if(elState >= TRACKING && azState >= TRACKING) { /* Both drives are up, so report the old FaultWord * and clear it. */ } if(azState != oldAzState && azState == SERVOOFF) { dprintf("Az drive is off\n"); } if(elState != oldElState && elState == SERVOOFF) { dprintf("El drive is off\n"); } oldElState = elState; oldAzState = azState; } /* read the parameters from the ACU and send them to dsm at the * change of the second */ curSec = tsshm->msec/1000; if(curSec != prevSec ) { WriteDsmMonitorPoints(); prevSec = curSec; } #if !SIMULATING /* Make checks of the scb less frequently than once/cycle */ auxCycle = (tsshm->msec / 10) % 100; /* Compute average pointing errors */ if((auxCycle % 10) == 9) { static double ssq = 0; /* Instantaneous az error (commanded - actual) */ azTrErrorArcSec = (float)tsshm->azTrError * cos(RAD_PER_MAS * (trEl + trElVel * dt)) * 0.001; ssq += azTrErrorArcSec * azTrErrorArcSec; elTrErrorArcSec = (float)tsshm->elTrError * 0.001; ssq += elTrErrorArcSec * elTrErrorArcSec; /* commenting out the following dsm_write since these are now in dsmsub.h dsm_write(dsm_host, "DSM_AZ_TRACKING_ERROR_F", &azTrErrorArcSec); dsm_write(dsm_host, "DSM_EL_TRACKING_ERROR_F", &elTrErrorArcSec); */ if(auxCycle == 99) { static int trErrCnt = 0; static char m[] = "Tracking error is excessive"; tsshm->avgTrErrorArcSec = sqrt(ssq / 10.); ssq = 0.; if(tsshm->azCmd > 0 && tsshm->elCmd > 0 && tsshm->avgTrErrorArcSec > 10 && (fabs(tsshm->tachAzVel) < 1.0) && (fabs(tsshm->tachElVel) < 1.0)) { if(trErrCnt == 10) { vSendOpMessage(OPMSG_SEVERE, 18, 0, m); } if(trErrCnt < 15) trErrCnt++; } else { if(trErrCnt > 0) { if(trErrCnt-- == 10) { vSendOpMessage(OPMSG_SEVERE, 18, 0, ""); trErrCnt = 0; } } } } } #endif /* !SIMULATING */ } return((gotQuit)? QUIT_RTN: NORMAL_RTN); }
int main(int argc, char *argv[]) { char c,command_n[30]; short pmac_command_flag=0; int dsm_status; smapoptContext optCon; int i ; int trackStatus=0; int tracktimestamp,timestamp; time_t dsmtimestamp; struct smapoptOption optionsTable[] = { {"help",'h',SMAPOPT_ARG_NONE,0,'h'}, {NULL,0,0,NULL,0} }; optCon = smapoptGetContext("stop", argc, argv, optionsTable,0); while ((c = smapoptGetNextOpt(optCon)) >= 0) { switch(c) { case 'h': usage(0,NULL,NULL); break; } } for(i=0;i<30;i++) { command_n[i]=0x0; }; command_n[0]='@'; /* send the command */ pmac_command_flag=0; if(c<-1) { fprintf(stderr, "%s: %s\n", smapoptBadOption(optCon, SMAPOPT_BADOPTION_NOALIAS), smapoptStrerror(c)); } smapoptFreeContext(optCon); /* initializing DSM */ dsm_status=dsm_open(); if(dsm_status != DSM_SUCCESS) { dsm_error_message(dsm_status,"dsm_open()"); exit(1); } #if 0 /* check if track is running on this antenna */ dsm_status=dsm_read(DSM_HOST,"DSM_UNIX_TIME_L",×tamp,&dsmtimestamp); dsm_status=dsm_read(DSM_HOST,"DSM_TRACK_TIMESTAMP_L",&tracktimestamp,&dsmtimestamp); if(abs(tracktimestamp-timestamp)>3L) { trackStatus=0; printf("Track is not running.\n"); } if(abs(tracktimestamp-timestamp)<=3L) trackStatus=1; if(trackStatus==1) { dsm_status=dsm_write(DSM_HOST,"DSM_COMMANDED_TRACK_COMMAND_C30", &command_n); if(dsm_status != DSM_SUCCESS) { dsm_error_message(dsm_status,"dsm_write()"); exit(1); } #endif dsm_status=dsm_write(DSM_HOST,"DSM_COMMANDED_TRACK_COMMAND_C30", &command_n); if(dsm_status != DSM_SUCCESS) { dsm_error_message(dsm_status,"dsm_write()"); exit(1); } /* the following dsm_write should actually be dsm_write_notify- but due to a bug in gltTrack, dsm_write_notify does not work */ dsm_status=dsm_write(DSM_HOST,"DSM_COMMAND_FLAG_S", &pmac_command_flag); if(dsm_status != DSM_SUCCESS) { dsm_error_message(dsm_status,"dsm_write()"); exit(1); } #if 0 } /* if track is running */ #endif return 0; }