long epicsShareAPI dbgf(const char *pname) { /* declare buffer long just to ensure correct alignment */ long buffer[100]; long *pbuffer=&buffer[0]; DBADDR addr; long options = 0; long no_elements; static TAB_BUFFER msg_Buff; if (!pname || !*pname) { printf("Usage: dbgf \"pv name\"\n"); return 1; } if (nameToAddr(pname, &addr)) return -1; no_elements = MIN(addr.no_elements, sizeof(buffer)/addr.field_size); if (addr.dbr_field_type == DBR_ENUM) { long status = dbGetField(&addr, DBR_STRING, pbuffer, &options, &no_elements, NULL); printBuffer(status, DBR_STRING, pbuffer, 0L, 0L, no_elements, &msg_Buff, 10); } else { long status = dbGetField(&addr, addr.dbr_field_type, pbuffer, &options, &no_elements, NULL); printBuffer(status, addr.dbr_field_type, pbuffer, 0L, 0L, no_elements, &msg_Buff, 10); } msg_Buff.message[0] = '\0'; dbpr_msgOut(&msg_Buff, 10); return 0; }
static void caPutLogAs(asTrapWriteMessage *pmessage, int afterPut) { #if BASE_3_14 dbAddr *paddr = pmessage->serverSpecific; #else struct dbChannel *pchan = pmessage->serverSpecific; dbAddr *paddr = &pchan->addr; const char *pv_name = pchan->name; #endif LOGDATA *plogData; long options, num_elm; long status; if (!afterPut) { /* before put */ plogData = caPutLogDataCalloc(); if (plogData == NULL) { errlogPrintf("caPutLog: memory allocation failed\n"); pmessage->userPvt = NULL; return; } pmessage->userPvt = (void *)plogData; epicsSnprintf(plogData->userid, MAX_USERID_SIZE, "%s", pmessage->userid); epicsSnprintf(plogData->hostid, MAX_HOSTID_SIZE, "%s", pmessage->hostid); #if BASE_3_14 dbNameOfPV(paddr, plogData->pv_name, PVNAME_STRINGSZ); #else epicsSnprintf(plogData->pv_name, PVNAME_STRINGSZ, "%s", pv_name); #endif if (VALID_DB_REQ(paddr->field_type)) { plogData->type = paddr->field_type; } else { plogData->type = DBR_STRING; } /* included for efficient pv-equality test: */ plogData->pfield = paddr->pfield; options = 0; num_elm = 1; status = dbGetField( paddr, plogData->type, &plogData->old_value, &options, &num_elm, 0); if (status) { errlogPrintf("caPutLog: dbGetField error=%ld\n", status); plogData->type = DBR_STRING; strcpy(plogData->old_value.v_string, "Not Accessible"); } } else { /* after put */ epicsTimeStamp curTime; plogData = (LOGDATA *) pmessage->userPvt; options = DBR_TIME; num_elm = 1; status = dbGetField( paddr, plogData->type, &plogData->new_value, &options, &num_elm, 0); if (status) { errlogPrintf("caPutLog: dbGetField error=%ld.\n", status); plogData->type = DBR_STRING; strcpy(plogData->new_value.value.v_string, "Not Accessible"); } epicsTimeGetCurrent(&curTime); /* get current time stamp */ /* replace, if necessary, the time stamp */ if (plogData->new_value.time.secPastEpoch < curTime.secPastEpoch) { plogData->new_value.time.secPastEpoch = curTime.secPastEpoch; plogData->new_value.time.nsec = curTime.nsec; } caPutLogTaskSend(plogData); } }
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); }
long epicsShareAPI dbtgf(const char *pname) { /* declare buffer long just to ensure correct alignment */ long buffer[400]; long *pbuffer = &buffer[0]; DBADDR addr; long status; long req_options, ret_options, no_elements; short dbr_type; static TAB_BUFFER msg_Buff; TAB_BUFFER *pMsgBuff = &msg_Buff; char *pmsg = pMsgBuff->message; int tab_size = 10; if (pname==0 || *pname==0) { printf("Usage: dbtgf \"pv name\"\n"); return 1; } if (nameToAddr(pname, &addr)) return -1; /* try all options first */ req_options = 0xffffffff; ret_options = req_options; no_elements = 0; status = dbGetField(&addr, addr.dbr_field_type, pbuffer, &ret_options, &no_elements, NULL); printBuffer(status, addr.dbr_field_type, pbuffer, req_options, ret_options, no_elements, pMsgBuff, tab_size); /* Now try all request types */ ret_options=0; dbr_type = DBR_STRING; no_elements = MIN(addr.no_elements,((sizeof(buffer))/MAX_STRING_SIZE)); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_CHAR; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsInt8))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_UCHAR; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsUInt8))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_SHORT; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsInt16))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_USHORT; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsUInt16))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_LONG; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsInt32))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_ULONG; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsUInt32))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_FLOAT; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsFloat32))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_DOUBLE; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsFloat64))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); dbr_type = DBR_ENUM; no_elements = MIN(addr.no_elements,((sizeof(buffer))/sizeof(epicsEnum16))); status = dbGetField(&addr,dbr_type,pbuffer,&ret_options,&no_elements,NULL); printBuffer(status,dbr_type,pbuffer,0L,0L,no_elements,pMsgBuff,tab_size); pmsg[0] = '\0'; dbpr_msgOut(pMsgBuff, tab_size); return(0); }
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); }
long mdsPlusCreatePulse() { int socket; int null=0; int dtype_long = DTYPE_LONG; int dtype_cstring = DTYPE_CSTRING; int dtype_float = DTYPE_FLOAT; int mdsstat, len; int idesc; int sdesc; int fdesc; int status=1,i; int bufsize=40; char buf[bufsize]; char treeID[20]; char serverID[20]; int shotID = 0; int tmpShotID = 0; int nextShotID; int tok_pulse; float coef=1.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 = dbGetField(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: mdsPlusCreatePulse() MdsConnected[%s]\n",serverID); */ /* Get pulse id */ /* sprintf(buf, "icrf:pulseid.VAL");*/ /* sprintf(buf, "icrf:daq:mcont:pulseid.VAL"); status = dbNameToAddr(buf, paddr); options = 0; nRequest = 1; status = dbGetField(paddr, DBR_LONG, &nextShotID, &options, &nRequest, NULL); */ /* open MDSPlus */ /* should be opened with shot -1 */ /* shotID = -1; 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: mdsPlusCreatePulse() MdsOpened [%s] shot number [%d].\n", treeID,shotID); */ /* create new pulse */ /* shot increment */ /* sprintf(buf, "TCL(\"SET CURRENT %s /INCREMENT\")", treeID); idesc = descr(&dtype_long, &mdsstat, &null); status = MdsValue(buf,&idesc,&null,&len); if(genSubDebug > 0) printf("genSub: mdsPlusCreatePulse() MdsValue %s\n", buf); */ /* get increased current shot id. increased shot ID should be same to the nextShotID */ /* sprintf(buf, "TCL(\"SHOW CURRENT %s\",_output)", treeID); idesc = descr(&dtype_long, &mdsstat, &null); status = MdsValue(buf,&idesc,&null,&len); if( !status_ok(status) ) { printf("genSub: Error with %s.", buf); return (-1); } if(genSubDebug > 3) printf("genSub: mdsPlusCreatePulse() MdsValue %s\n",buf); if( status_ok(mdsstat) ) { sdesc = descr(&dtype_cstring, buf, &null, &bufsize); status = MdsValue("_output",&sdesc, &null, &len); if( !status_ok(status) ) { printf("genSub: Error getting output with %s.",buf); } sscanf(buf,"Current shot is %d", &tmpShotID); if(tmpShotID != nextShotID ) { printf("genSub: Shot ID is incorrect.\n"); return(-1); } if(genSubDebug > 0) printf("genSub: mdsPlusCreatePulse() MdsValue SHOW CURRENT gets shot number [%d].\n", tmpShotID); */ /* create current pulse */ /* sprintf(buf, "TCL(\"CREATE PULSE %d\")", tmpShotID); status = MdsValue(buf,&idesc,&null,&len); if(genSubDebug > 3) printf("genSub: mdsPlusCreatePulse() MdsValue %s\n",buf); } */ /* close and reopen with increased shot id*/ /* status=MdsClose(treeID, &shotID);*/ /* shotID=nextShotID;*/ /* 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: mdsPlusCreatePulse() MdsConnected[%s]\n",serverID); /* open MDSPlus */ shotID = 0; 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: mdsPlusCreatePulse() MdsOpened [%s] shot number [%d].\n", treeID,shotID); /* write data at current(increased) shot id*/ /* Get tokamak shot ID */ /* sprintf(buf, "icrf:shotid.VAL"); status = dbNameToAddr(buf, paddr); options = 0; nRequest = 1; status = dbGetField(paddr, DBR_LONG, &tok_pulse, &options, &nRequest, NULL); */ /* write tokamak shot id */ /* idesc = descr(&dtype_long, &tok_pulse, &null); status = MdsPut("\\TOK_SHOT", "$", &idesc, &null); if(genSubDebug > 3) printf("genSub: mdsPlusCreatePulse() MdsPut [\\TOK_SHOT=%d]\n",tok_pulse); */ /* Get current time string */ /* sprintf(buf, "icrf:ioc:time.VAL"); status = dbNameToAddr(buf, paddr); options = 0; nRequest = 1; status = dbGetField(paddr, DBR_STRING, buf, &options, &nRequest, NULL); */ /* write time */ /* sdesc = descr(&dtype_cstring, buf, &null, &bufsize); status = MdsPut("\\PULSE_TIME", "$", &sdesc, &null); if(genSubDebug > 3) printf("genSub: mdsPlusCreatePulse() MdsPut [\\PULSE_TIME=%s]\n",buf); */ /* write coefficient */ sprintf(buf, "icrf:daq:rfd:coef0.VAL"); status = dbNameToAddr(buf, paddr); status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL); fdesc = descr(&dtype_float, &coef, &null); status = MdsPut("\\ICRF_0C", "$", &fdesc, &null); sprintf(buf, "icrf:daq:rfd:coef1.VAL"); status = dbNameToAddr(buf, paddr); status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL); fdesc = descr(&dtype_float, &coef, &null); status = MdsPut("\\ICRF_1C", "$", &fdesc, &null); sprintf(buf, "icrf:daq:rfd:coef2.VAL"); status = dbNameToAddr(buf, paddr); status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL); fdesc = descr(&dtype_float, &coef, &null); status = MdsPut("\\ICRF_2C", "$", &fdesc, &null); sprintf(buf, "icrf:daq:rfd:coef3.VAL"); status = dbNameToAddr(buf, paddr); status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL); fdesc = descr(&dtype_float, &coef, &null); status = MdsPut("\\ICRF_3C", "$", &fdesc, &null); status=MdsClose(treeID, &shotID); free(paddr); return(0); }