long dbpf(const char *pname,const char *pvalue) { DBADDR addr; long status; short dbrType; size_t n = 1; if (!pname || !*pname || !pvalue) { printf("Usage: dbpf \"pv name\", \"value\"\n"); return 1; } if (nameToAddr(pname, &addr)) return -1; if (addr.no_elements > 1 && (addr.dbr_field_type == DBR_CHAR || addr.dbr_field_type == DBR_UCHAR)) { dbrType = addr.dbr_field_type; n = strlen(pvalue) + 1; } else { dbrType = DBR_STRING; } status = dbPutField(&addr, dbrType, pvalue, (long) n); dbgf(pname); return status; }
void epicsShareAPI dbPutNotify(putNotify *ppn) { dbCommon *precord = ppn->paddr->precord; short dbfType = ppn->paddr->field_type; long status=0; putNotifyPvt *pputNotifyPvt; assert(precord); /*check for putField disabled*/ if(precord->disp) { if((void *)(&precord->disp) != ppn->paddr->pfield) { ppn->status = putNotifyPutDisabled; (*ppn->userCallback)(ppn); return; } } /* Must handle DBF_XXXLINKs as special case. * Only dbPutField will change link fields. * Also the record is not processed as a result */ if(dbfType>=DBF_INLINK && dbfType<=DBF_FWDLINK) { status=dbPutField(ppn->paddr,ppn->dbrType,ppn->pbuffer,ppn->nRequest); ppn->status = (status==0) ? putNotifyOK : putNotifyError; (*ppn->userCallback)(ppn); return; } dbScanLock(precord); epicsMutexMustLock(pnotifyGlobal->lock); pputNotifyPvt = (putNotifyPvt *)ppn->pputNotifyPvt; if(pputNotifyPvt && (pputNotifyPvt->magic!=MAGIC)) { printf("dbPutNotify:pputNotifyPvt was not initialized\n"); pputNotifyPvt = 0; } if(pputNotifyPvt) { assert(pputNotifyPvt->state==putNotifyUserCallbackActive); pputNotifyPvt->userCallbackWait = 1; epicsMutexUnlock(pnotifyGlobal->lock); dbScanUnlock(precord); epicsEventWait(pputNotifyPvt->userCallbackEvent); dbScanLock(precord); epicsMutexMustLock(pnotifyGlobal->lock); putNotifyCleanup(ppn); } pputNotifyPvt = (putNotifyPvt *)ppn->pputNotifyPvt; assert(!pputNotifyPvt); putNotifyInit(ppn); pputNotifyPvt = (putNotifyPvt *)ppn->pputNotifyPvt; if(!precord->ppnr) {/* make sure record has a putNotifyRecord*/ precord->ppnr = dbCalloc(1,sizeof(putNotifyRecord)); precord->ppnr->precord = precord; ellInit(&precord->ppnr->restartList); } putNotifyCommon(ppn,precord); }
void mdsPlusShotID(int param) { int status; char buf[40]; DBADDR *paddr; paddr = (DBADDR *)dbCalloc(1, sizeof(struct dbAddr)); /* sleep */ epicsThreadSleep(2.0); /*status = dbPutLink(shotIdOutLink, DBR_LONG, &shotId, 1);*/ /* Put next pulse number */ sprintf(buf, "icrf:pulseid.VAL"); status = dbNameToAddr(buf, paddr); status = dbPutField(paddr, DBR_LONG, &shotId, 1); free(paddr); if(genSubDebug > 0) printf("genSub: mdsPlusShotID() next shot number [%ld]. Status=%d\n",shotId,status); }
long epicsShareAPI dbpf(const char *pname,const char *pvalue) { DBADDR addr; long status; short dbrType; long n = 1; if (!pname || !*pname || !pvalue) { printf("Usage: dbpf \"pv name\", \"value\"\n"); return 1; } if (nameToAddr(pname, &addr)) return -1; if (addr.no_elements > 1 && (addr.dbr_field_type == DBR_CHAR || addr.dbr_field_type == DBR_UCHAR)) { dbrType = addr.dbr_field_type; n = strlen(pvalue) + 1; } else { dbrType = DBR_STRING; } status = dbPutField(&addr, dbrType, pvalue, n); if (status) { if (status == -1) printf("dbpf: Value conversion from %s to %s failed\n", dbr[dbrType], dbf[addr.field_type]); else errMessage(status,"- dbPutField error\n"); return status; } return dbgf(pname); }
static void check(short dbr_type) { dbChannel *pch; db_field_log *pfl, *pfl2; dbAddr valaddr; dbAddr offaddr; const char *offname = NULL, *valname = NULL, *typname = NULL; epicsInt32 ar[10] = {10,11,12,13,14,15,16,17,18,19}; epicsInt32 *ar10_0_1 = ar; epicsInt32 ar10_4_1[10] = {14,15,16,17,18,19,10,11,12,13}; epicsInt32 ar5_0_1[10] = {12,13,14,15,16}; epicsInt32 ar5_3_1[10] = {15,16,17,18,19}; epicsInt32 ar5_5_1[10] = {17,18,19,10,11}; epicsInt32 ar5_9_1[10] = {11,12,13,14,15}; epicsInt32 ar5_0_2[10] = {12,14,16}; epicsInt32 ar5_3_2[10] = {15,17,19}; epicsInt32 ar5_5_2[10] = {17,19,11}; epicsInt32 ar5_9_2[10] = {11,13,15}; epicsInt32 ar5_0_3[10] = {12,15}; epicsInt32 ar5_3_3[10] = {15,18}; epicsInt32 ar5_5_3[10] = {17,10}; epicsInt32 ar5_9_3[10] = {11,14}; epicsInt32 off = 0; switch (dbr_type) { case DBR_LONG: offname = "x.OFF"; valname = "x.VAL"; typname = "long"; break; case DBR_DOUBLE: offname = "y.OFF"; valname = "y.VAL"; typname = "double"; break; case DBR_STRING: offname = "z.OFF"; valname = "z.VAL"; typname = "string"; break; default: testDiag("Invalid data type %d", dbr_type); } (void) dbNameToAddr(offname, &offaddr); (void) dbNameToAddr(valname, &valaddr); (void) dbPutField(&valaddr, DBR_LONG, ar, 10); /* Default: should not change anything */ testHead("Ten %s elements from rec, increment 1, full size (default)", typname); createAndOpen(valname, "{\"arr\":{}}", "(default)", &pch, 1); testOk(pch->final_type == valaddr.field_type, "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); testOk(pch->final_no_elements == valaddr.no_elements, "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); TEST1(10, 0, 1, "no offset"); TEST1(10, 4, 1, "wrapped"); dbChannelDelete(pch); testHead("Ten %s elements from rec, increment 1, out-of-bound start parameter", typname); createAndOpen(valname, "{\"arr\":{\"s\":-500}}", "out-of-bound start", &pch, 1); testOk(pch->final_type == valaddr.field_type, "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); testOk(pch->final_no_elements == valaddr.no_elements, "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); TEST1(10, 4, 1, "wrapped"); dbChannelDelete(pch); testHead("Ten %s elements from rec, increment 1, out-of-bound end parameter", typname); createAndOpen(valname, "{\"arr\":{\"e\":500}}", "out-of-bound end", &pch, 1); testOk(pch->final_type == valaddr.field_type, "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); testOk(pch->final_no_elements == valaddr.no_elements, "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); TEST1(10, 4, 1, "wrapped"); dbChannelDelete(pch); testHead("Ten %s elements from rec, increment 1, zero increment parameter", typname); createAndOpen(valname, "{\"arr\":{\"i\":0}}", "zero increment", &pch, 1); testOk(pch->final_type == valaddr.field_type, "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); testOk(pch->final_no_elements == valaddr.no_elements, "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); TEST1(10, 4, 1, "wrapped"); dbChannelDelete(pch); testHead("Ten %s elements from rec, increment 1, invalid increment parameter", typname); createAndOpen(valname, "{\"arr\":{\"i\":-30}}", "invalid increment", &pch, 1); testOk(pch->final_type == valaddr.field_type, "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); testOk(pch->final_no_elements == valaddr.no_elements, "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); TEST1(10, 4, 1, "wrapped"); dbChannelDelete(pch); #define TEST5(Incr, Left, Right, Type) \ testHead("Five %s elements from rec, increment " #Incr ", " Type " addressing", typname); \ createAndOpen(valname, "{\"arr\":{\"s\":" #Left ",\"e\":" #Right ",\"i\":" #Incr "}}", \ "(" #Left ":" #Incr ":" #Right ")", &pch, 1); \ testOk(pch->final_type == valaddr.field_type, \ "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); \ testOk(pch->final_no_elements == 4 / Incr + 1, \ "final no_elements correct (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); \ TEST1(5, 0, Incr, "no offset"); \ TEST1(5, 3, Incr, "from upper block"); \ TEST1(5, 5, Incr, "wrapped"); \ TEST1(5, 9, Incr, "from lower block"); \ dbChannelDelete(pch); /* Contiguous block of 5 */ TEST5(1, 2, 6, "regular"); TEST5(1, -8, 6, "left side from-end"); TEST5(1, 2, -4, "right side from-end"); TEST5(1, -8, -4, "both sides from-end"); /* 5 elements with increment 2 */ TEST5(2, 2, 6, "regular"); TEST5(2, -8, 6, "left side from-end"); TEST5(2, 2, -4, "right side from-end"); TEST5(2, -8, -4, "both sides from-end"); /* 5 elements with increment 3 */ TEST5(3, 2, 6, "regular"); TEST5(3, -8, 6, "left side from-end"); TEST5(3, 2, -4, "right side from-end"); TEST5(3, -8, -4, "both sides from-end"); /* From buffer (plugin chain) */ #define TEST5B(Incr, Left, Right, Type) \ testHead("Five %s elements from buffer, increment " #Incr ", " Type " addressing", typname); \ createAndOpen(valname, "{\"arr\":{},\"arr\":{\"s\":" #Left ",\"e\":" #Right ",\"i\":" #Incr "}}", \ "(" #Left ":" #Incr ":" #Right ")", &pch, 2); \ testOk(pch->final_type == valaddr.field_type, \ "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); \ testOk(pch->final_no_elements == 4 / Incr + 1, \ "final no_elements correct (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); \ TEST1(5, 0, Incr, "no offset"); \ dbChannelDelete(pch); /* Contiguous block of 5 */ TEST5B(1, 2, 6, "regular"); TEST5B(1, -8, 6, "left side from-end"); TEST5B(1, 2, -4, "right side from-end"); TEST5B(1, -8, -4, "both sides from-end"); /* 5 elements with increment 2 */ TEST5B(2, 2, 6, "regular"); TEST5B(2, -8, 6, "left side from-end"); TEST5B(2, 2, -4, "right side from-end"); TEST5B(2, -8, -4, "both sides from-end"); /* 5 elements with increment 3 */ TEST5B(3, 2, 6, "regular"); TEST5B(3, -8, 6, "left side from-end"); TEST5B(3, 2, -4, "right side from-end"); TEST5B(3, -8, -4, "both sides from-end"); }
static void check(short dbr_type) { dbChannel *pch; db_field_log *pfl; dbAddr valaddr; dbAddr offaddr; const char *offname = NULL, *valname = NULL, *typname = NULL; epicsInt32 buf[26]; long off, req; int i; switch (dbr_type) { case DBR_LONG: offname = "i32.OFF"; valname = "i32.VAL"; typname = "long"; break; case DBR_DOUBLE: offname = "f64.OFF"; valname = "f64.VAL"; typname = "double"; break; case DBR_STRING: offname = "c40.OFF"; valname = "c40.VAL"; typname = "string"; break; default: testDiag("Invalid data type %d", dbr_type); } (void) dbNameToAddr(offname, &offaddr); (void) dbNameToAddr(valname, &valaddr); testHead("Ten %s elements", typname); /* Fill the record's array field with data, 10..19 */ epicsInt32 ar[10] = {10,11,12,13,14,15,16,17,18,19}; (void) dbPutField(&valaddr, DBR_LONG, ar, 10); /* Open a channel to it, make sure no filters present */ createAndOpen(valname, &pch); testOk(pch->final_type == valaddr.field_type, "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); testOk(pch->final_no_elements == valaddr.no_elements, "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); /* TEST1 sets the record's OFF field, then requests 10 elements from the channel, * passing in a transparent db_field_log and converting the data to LONG on the way in. * It checks that it got back the expected data and the right number of elements. */ #define TEST1(Size, Offset, Text, Expected) \ testDiag("Reading from offset = %d (%s)", Offset, Text); \ off = Offset; req = 10; \ memset(buf, 0, sizeof(buf)); \ (void) dbPutField(&offaddr, DBR_LONG, &off, 1); \ pfl = db_create_read_log(pch); \ testOk(pfl && pfl->type == dbfl_type_rec, "Valid pfl, type = rec"); \ testOk(!dbChannelGetField(pch, DBR_LONG, buf, NULL, &req, pfl), "Got Field value"); \ testOk(req == Size, "Got %ld elements (expected %d)", req, Size); \ if (!testOk(!memcmp(buf, Expected, sizeof(Expected)), "Data correct")) \ for (i=0; i<Size; i++) \ testDiag("Element %d expected %d got %d", i, Expected[i], buf[i]); \ db_delete_field_log(pfl); const epicsInt32 res_10_0[] = {10,11,12,13,14,15,16,17,18,19}; TEST1(10, 0, "no offset", res_10_0); const epicsInt32 res_10_4[] = {14,15,16,17,18,19,10,11,12,13}; TEST1(10, 4, "wrapped", res_10_4); /* Partial array */ testHead("Five %s elements", typname); off = 0; /* Reset offset for writing the next buffer */ (void) dbPutField(&offaddr, DBR_LONG, &off, 1); (void) dbPutField(&valaddr, DBR_LONG, &ar[5], 5); createAndOpen(valname, &pch); testOk(pch->final_type == valaddr.field_type, "final type unchanged (%d->%d)", valaddr.field_type, pch->final_type); testOk(pch->final_no_elements == valaddr.no_elements, "final no_elements unchanged (%ld->%ld)", valaddr.no_elements, pch->final_no_elements); const epicsInt32 res_5_0[] = {15,16,17,18,19}; TEST1(5, 0, "no offset", res_5_0); const epicsInt32 res_5_3[] = {18,19,15,16,17}; TEST1(5, 3, "wrapped", res_5_3); /* TEST2 sets the record's OFF field, then requests 15 elements from the channel * but passes in a db_field_log with alternate data, converting that data to LONG. * It checks that it got back the expected data and the right number of elements. */ #define TEST2(Size, Offset, Text, Expected) \ testDiag("Reading from offset = %d (%s)", Offset, Text); \ off = Offset; req = 15; \ memset(buf, 0, sizeof(buf)); \ (void) dbPutField(&offaddr, DBR_LONG, &off, 1); \ pfl = db_create_read_log(pch); \ pfl->type = dbfl_type_ref; \ pfl->field_type = DBF_CHAR; \ pfl->field_size = 1; \ pfl->no_elements = 26; \ pfl->u.r.dtor = freeArray; \ pfl->u.r.field = epicsStrDup("abcdefghijklmnopqrsstuvwxyz"); \ testOk(!dbChannelGetField(pch, DBR_LONG, buf, NULL, &req, pfl), "Got Field value"); \ testOk(req == Size, "Got %ld elements (expected %d)", req, Size); \ if (!testOk(!memcmp(buf, Expected, sizeof(Expected)), "Data correct")) \ for (i=0; i<Size; i++) \ testDiag("Element %d expected '%c' got '%c'", i, Expected[i], buf[i]); \ db_delete_field_log(pfl); testHead("Fifteen letters from field-log instead of %s", typname); const epicsInt32 res_15[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'}; TEST2(15, 0, "no offset", res_15); TEST2(15, 10, "ignored", res_15); dbChannelDelete(pch); }
long dbChannelPutField(dbChannel *chan, short type, const void *pbuffer, long nRequest) { return dbPutField(&chan->addr, type, pbuffer, nRequest); }
long epicsShareAPI dbtpf(const char *pname, const char *pvalue) { /* declare buffer long just to ensure correct alignment */ long buffer[100]; long *pbuffer = buffer; DBADDR addr; long status = 0; long options, no_elements; char *pend; long val_long; int validLong; unsigned long val_ulong; int validULong; int valid = 1; int put_type; epicsFloat32 fvalue; epicsFloat64 dvalue; static TAB_BUFFER msg_Buff; TAB_BUFFER *pMsgBuff = &msg_Buff; char *pmsg = pMsgBuff->message; int tab_size = 10; if (!pname || !*pname || !pvalue) { printf("Usage: dbtpf \"pv name\", \"value\"\n"); return 1; } if (nameToAddr(pname, &addr)) return -1; val_long = strtol(pvalue, &pend, 10); validLong = (*pend == 0); val_ulong = strtoul(pvalue, &pend, 10); validULong = (*pend == 0); for (put_type = DBR_STRING; put_type <= DBF_ENUM; put_type++) { switch (put_type) { case DBR_STRING: status = dbPutField(&addr, put_type, pvalue, 1L); break; case DBR_CHAR: if ((valid = validLong)) { epicsInt8 val_i8 = (epicsInt8)val_long; status = dbPutField(&addr, put_type, &val_i8, 1L); } break; case DBR_UCHAR: if ((valid = validULong)) { epicsUInt8 val_u8 = (epicsUInt8)val_ulong; status = dbPutField(&addr, put_type, &val_u8, 1L); } break; case DBR_SHORT: if ((valid = validLong)) { epicsInt16 val_i16 = val_long; status = dbPutField(&addr, put_type, &val_i16,1L); } break; case DBR_USHORT: if ((valid = validULong)) { epicsUInt16 val_u16 = val_ulong; status = dbPutField(&addr, put_type, &val_u16, 1L); } break; case DBR_LONG: if ((valid = validLong)) { epicsInt32 val_i32 = val_long; status = dbPutField(&addr, put_type,&val_i32,1L); } break; case DBR_ULONG: if ((valid = validULong)) { epicsUInt32 val_u32 = val_ulong; status = dbPutField(&addr, put_type, &val_u32, 1L); } break; case DBR_FLOAT: if ((valid = epicsScanFloat(pvalue, &fvalue) == 1)) status = dbPutField(&addr, put_type, &fvalue, 1L); break; case DBR_DOUBLE: if ((valid = epicsScanDouble(pvalue, &dvalue) == 1)) status = dbPutField(&addr, put_type, &dvalue, 1L); break; case DBR_ENUM: if ((valid = validULong)) { epicsEnum16 val_e16 = val_ulong; status = dbPutField(&addr, put_type, &val_e16, 1L); } break; } if (valid) { if (status) { printf("Put as DBR_%s Failed.\n", dbr[put_type]); } else { printf("Put as DBR_%-6s Ok, result as ", dbr[put_type]); no_elements = MIN(addr.no_elements, ((sizeof(buffer))/addr.field_size)); options = 0; status = dbGetField(&addr, addr.dbr_field_type, pbuffer, &options, &no_elements, NULL); printBuffer(status, addr.dbr_field_type, pbuffer, 0L, 0L, no_elements, pMsgBuff, tab_size); } } } pmsg[0] = '\0'; dbpr_msgOut(pMsgBuff, tab_size); return(0); }
void mdsPlusPut_Task(int param) { unsigned long i; int socket; int null=0; int dtypeFloat = DTYPE_FLOAT; int dataDesc,timeDesc; int status=1, j; float tdT; float toffT; int tnoRd; int tshotID; char ttagName[20]; char ttreeID[20]; char tserverID[20]; float *timeBase; DBADDR *paddr; paddr = (DBADDR *)dbCalloc(1, sizeof(struct dbAddr)); if(genSubDebug > 0) printf("Start MdsPut. ##############.\n"); status = dbNameToAddr(mpActivePV, paddr); enum16Val = 1; status = dbPutField(paddr, DBR_ENUM, &enum16Val, 1); status = mdsPlusCreatePulse(); /* loop numNode times */ for(j = 0;j < numNode; j++) { if(genSubDebug > 5) printf("genSub: mdsPlusPut_Task() started. Task Position=%d, Flag=%ld\n",j,pmdsPutData[j].putFlag); if(pmdsPutData[j].putFlag == 0) goto endloop; epicsThreadSleep(0.01); tnoRd=(int)(pmdsPutData[j].noRd); tshotID=(int)(pmdsPutData[j].shotID); strcpy(ttagName,pmdsPutData[j].tagName); strcpy(ttreeID,pmdsPutData[j].treeID); strcpy(tserverID,pmdsPutData[j].serverID); tdT=pmdsPutData[j].dT; toffT=pmdsPutData[j].offT; if(genSubDebug > 3) printf("genSub: mdsPlusPut_Task() MdsConnect Ready. ServerID=[%s] TreeID=[%s] tagName=[%s] dt=[%f] off=[%f] noRd=[%d]\n",tserverID, ttreeID, ttagName, tdT, toffT, tnoRd); /* Connect server and open tree*/ socket=MdsConnect(tserverID); if(socket == -1) { printf("genSub: Error connecting to mdsip server[%s].\n",tserverID); break; } if(genSubDebug > 5) printf("genSub: mdsPlusPut_Task() MdsConnected[%s]\n",tserverID); status=MdsOpen(ttreeID, &tshotID); if( !status_ok(status) ) { printf("genSub: Error opening tree [%s] for shot [%d].\n", ttreeID,tshotID ); break; } if(genSubDebug > 5) printf("genSub: mdsPlusPut_Task() MdsOpened [%s] shot number [%d].\n", ttreeID,tshotID); /* put data */ timeBase = (float *)malloc(tnoRd*sizeof(float)); for(i=0;i<tnoRd;i++) *(timeBase + i) = ((float)i)*tdT + toffT; dataDesc=descr(&dtypeFloat,pmdsPutData[j].dataArray,&tnoRd, &null); timeDesc=descr(&dtypeFloat,timeBase, &tnoRd, &null); status=MdsPut(ttagName,"BUILD_SIGNAL($1,,$2)",&dataDesc,&timeDesc,&null); if( !status_ok(status) ) { printf("genSub: Error writing signal.\n"); break; } if(genSubDebug > 5) printf("genSub: mdsPlusPut_Task() MdsPutted to tag [%s]. shot number [%d], noRd=[%d].\n", ttagName,tshotID,tnoRd); if(genSubDebug > 10) for(i=0;i<tnoRd;i++) { printf("timeBase=%f,data=%f\n", *((float *)timeBase+i),*((float *)pmdsPutData[j].dataArray+i)); } free(timeBase); status=MdsClose(ttreeID, &tshotID); if( !status_ok(status) ) { printf("genSub: Error closing tree for shot [%d].\n",tshotID ); break; } if(genSubDebug > 5) printf("genSub: mdsPlusPut_Task() MdsClosed [%s] shot number [%d]\n",ttreeID,tshotID); endloop: if(genSubDebug > 5) printf("genSub: mdsPlusPut_Task() Data discarded for taskPos[%d].\n",j); } status = mdsPlusPrepNext(); /* end of mdsput */ startMdsPut = 0; status = dbNameToAddr(mpActivePV, paddr); enum16Val = 0; status = dbPutField(paddr, DBR_ENUM, &enum16Val, 1); free(paddr); }
long mdsPlusPrepNext() { int socket; int null=0; int dtype_long = DTYPE_LONG; int mdsstat, len; int idesc; int status=1,i; int bufsize=40; char buf[bufsize]; char treeID[20]; char serverID[20]; int shotID = 0; DBADDR *paddr; long options, nRequest; paddr = (DBADDR *)dbCalloc(1, sizeof(struct dbAddr)); /* Get server information */ sprintf(buf, "icrf:daq:mptree:i.VAL"); status = dbNameToAddr(buf, paddr); options = 0; nRequest = 1; status = dbGet(paddr, DBR_STRING, buf, &options, &nRequest, NULL); i=sscanf(buf,"%s %s",serverID, treeID); /* Connect server */ socket=MdsConnect(serverID); if(socket == -1) { printf("genSub: Error connecting to mdsip server[%s].\n",serverID); return(-1); } if(genSubDebug > 5) printf("genSub: mdsPlusPrepNext() MdsConnected[%s]\n",serverID); /* Get pulse id */ sprintf(buf, "icrf:pulseid.VAL"); status = dbNameToAddr(buf, paddr); options = 0; nRequest = 1; status = dbGetField(paddr, DBR_LONG, &shotID, &options, &nRequest, NULL); /* open MDSPlus*/ status=MdsOpen(treeID, &shotID); if( !status_ok(status) ) { printf("genSub: Error opening tree [%s] for shot [%d].\n", treeID,shotID ); return(-1); } if(genSubDebug > 5) printf("genSub: mdsPlusPrepNext() MdsOpened [%s] shot number [%d].\n", treeID,shotID); /* generate MDSPlus event*/ sprintf(buf, "TCL(\"SETEVENT cmpl\")"); idesc = descr(&dtype_long, &mdsstat, &null); status = MdsValue(buf,&idesc,&null,&len); if( !status_ok(status) ) { printf("genSub: Error generating event for tree [%s].\n", treeID); return(-1); } if(genSubDebug > 0) printf("genSub: mdsPlusPrepNext() MdsValue %s\n", buf); /* Put next pulse number */ sprintf(buf, "icrf:pulseid.VAL"); status = dbNameToAddr(buf, paddr); options = 0; nRequest = 1; shotID++; status = dbPutField(paddr, DBR_LONG, &shotID, 1); status=MdsClose(treeID, &shotID); free(paddr); return(0); }