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 }
int client(char *msg, char *dsthost, int dstport) { // char msg[256]; int s; // int dstport, char *dsthost; /* compose message, determine destination host/port */ // memset(msg, 0, sizeof(msg)); // printf("%s\n", msg); s = dsm_client_open(SOCK_STREAM, dstport, FALSE, dsthost, NULL); dsm_write(s, SOCK_STREAM, msg, strlen(msg) + 1, NULL); // printf("%d\n", s); dsm_close(s); }
void GetACUPosAndStatus(void) { unsigned char buf[8]; float f; if(ReadCANValue(GET_ACU_MODE, buf, 2)) { ACUAccessMode = buf[2] = buf[1]; elDriveMode = buf[1] = buf[0] >> 4; azDriveMode = buf[0] = 0xf & buf[0]; dsm_write(dsm_host, "DSM_ACU_MODE_V3_B", buf); SaI.azMode = buf[0]; SaI.elMode = buf[1]; }
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[]) { 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[]) { 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; }