#include #include #include "gpib/ib.h" #include #include #include #include #include #define MAX_TIME 86400 int i=0,j=0,k=0; struct timeval tval_before, tval_during, tval_after, tval_keith, tval_snmp, tval_total; //struct timespec ts_before,ts_after; volatile int ibstatest; //SNMP netsnmp_session session, *ss; netsnmp_pdu *pdu_term[8]; netsnmp_pdu *response_term[8]; oid OID_term[MAX_OID_LEN]; size_t anOID_len; netsnmp_variable_list *vars; int status_term0,status_term1; int count=1,KeithErr=0; //#include int counter=0; //GPIB int devdesc; unsigned char devbuf[2048]; int devdatalen=0; void gpiberr (char *msg); void *SNMPThread (); void *KeithThread (); //void* voidpoint; sem_t KeithStart,SNMPStart,KeithDone,SNMPDone; int main(int argc, char ** argv) { devdesc = ibdev(0, 16, 0, 10, 1, 0x0000); pthread_t keith_id; pthread_t SNMP_id; sem_init(&KeithStart,0,0); sem_init(&SNMPStart,0,0); sem_init(&KeithDone,0,0); sem_init(&SNMPDone,0,0); pthread_create(&SNMP_id,NULL,SNMPThread,NULL); pthread_create(&keith_id,NULL,KeithThread,NULL); //Files FILE* fout_term = fopen("./temp_TermAll","w"); FILE* fout_keith = fopen("./temp_KeithAll","w"); FILE* fout_time = fopen("./temp_TimeAll","w"); char ChanBuf[12]="",TermOIDBuf[36],VoltageOIDBuf[35]="",PowerOIDBuf[35]="1",blankSNMP[10]="00.000000",blankKeith[16]="+0.00000000E+00",timeCurrent[23],timeInfo[70]; // Initialize the SNMP library init_snmp("snmpdemoapp"); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, 1); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, 1); //Initialize a "session" that defines who we're going to talk to snmp_sess_init( &session ); /* set up defaults */ session.peername = strdup("192.168.250.102"); /* set the SNMP version number */ session.version = SNMP_VERSION_2c; /* set the SNMPv1 community name used for authentication */ session.community = "public"; session.community_len = strlen(session.community); // Open the session SOCK_STARTUP; ss = snmp_open(&session); /* establish the session */ //Make sure it opened if (!ss) { snmp_sess_perror("ack", &session); SOCK_CLEANUP; exit(1); } for (j=0;j<7;j++) { printf("Please set to Channel u%d\n",j); fflush(stdout); getchar(); fflush(fout_term); fflush(fout_keith); for (counter=0;countervariables->name,response_term[i]->variables->name_length,response_term[i]->variables); } fwrite(timeCurrent,1,23,fout_keith); fwrite(devbuf,1,ibcnt,fout_keith); sprintf(timeInfo,"Current:%ld.%06ld Keith:%ld.%06ld SNMP:%ld.%06ld Total:%ld.%06ld\n",(long int)tval_during.tv_sec,(long int)tval_during.tv_usec, (long int)tval_keith.tv_sec, (long int)tval_keith.tv_usec, (long int)tval_snmp.tv_sec, (long int)tval_snmp.tv_usec, (long int)tval_total.tv_sec, (long int)tval_total.tv_usec); fwrite(timeInfo,1,70,fout_time); fflush(stdout); } if(KeithErr==1) counter--; //Pretend nothing happened KeithErr=0; } //end loop sprintf(ChanBuf, "End of Channel %d\n",j); fwrite(ChanBuf,1,17,fout_term); fwrite(ChanBuf,1,17,fout_keith); fflush(fout_keith); fflush(fout_term); fflush(fout_time); } /* * Clean up: * 1) free the response. * 2) close the session. */ for (i=0;i<8;i++) { if (response_term[i]) snmp_free_pdu(response_term[i]); } snmp_close(ss); fclose(fout_term); fclose(fout_keith); fclose(fout_time); SOCK_CLEANUP; return (0); } void gpiberr (char *msg) { printf ("%s\n", msg); printf ("ibsta = &H%x <", ibsta); if (ibsta & ERR) printf (" ERR"); if (ibsta & TIMO) printf (" TIMO"); if (ibsta & END) printf (" END"); if (ibsta & SRQI) printf (" SRQI"); if (ibsta & RQS) printf (" RQS"); if (ibsta & CMPL) printf (" CMPL"); if (ibsta & LOK) printf (" LOK"); if (ibsta & REM) printf (" REM"); if (ibsta & CIC) printf (" CIC"); if (ibsta & ATN) printf (" ATN"); if (ibsta & TACS) printf (" TACS"); if (ibsta & LACS) printf (" LACS"); if (ibsta &DTAS) printf (" DTAS"); if (ibsta & DCAS) printf (" DCAS"); printf (" >\n"); printf ("iberr = %d", iberr); if (iberr == EDVR) printf (" EDVR \n"); if (iberr == ECIC) printf (" ECIC \n"); if (iberr == ENOL) printf (" ENOL \n"); if (iberr == EADR) printf (" EADR
\n"); if (iberr == EABO) printf (" EABO \n"); if (iberr == ENEB) printf ("ENEB \n"); if (iberr == EOIP) printf (" EOIP \n"); if (iberr == ECAP) printf (" ECAP \n"); if (iberr == EFSO) printf (" EFSO \n"); if (iberr == EBUS) printf (" EBUS \n"); if (iberr == ESTB) printf (" ESTB \n"); if (iberr == ESRQ) printf (" ESRQ \n"); if (iberr == ETAB) printf (" ETAB
\n"); if (iberr == ETAB) printf (" ETAB \n"); if (iberr == ETAB) printf (" ETAB \n"); if (iberr == ETAB) printf (" ETAB \n"); if (iberr == ETAB) printf (" ETAB \n"); if (iberr == ETAB) printf (" ETAB \n"); printf ("ibcntl = %ld\n", ibcntl); printf ("\n"); /* Call the ibonl function to disable the hardware and software */ //ibonl (dvm, 0); } void *KeithThread() { while(counter