static void dbMenuBody(void) { dbMenu *pnewMenu; dbMenu *pMenu; int nChoice; int i; GPHENTRY *pgphentry; if(duplicate) { duplicate = FALSE; return; } pnewMenu = (dbMenu *)popFirstTemp(); pnewMenu->nChoice = nChoice = ellCount(&tempList)/2; pnewMenu->papChoiceName = dbCalloc(pnewMenu->nChoice,sizeof(char *)); pnewMenu->papChoiceValue = dbCalloc(pnewMenu->nChoice,sizeof(char *)); for(i=0; i<nChoice; i++) { pnewMenu->papChoiceName[i] = (char *)popFirstTemp(); pnewMenu->papChoiceValue[i] = (char *)popFirstTemp(); } if(ellCount(&tempList)) yyerrorAbort("dbMenuBody: tempList not empty"); /* Add menu in sorted order */ pMenu = (dbMenu *)ellFirst(&pdbbase->menuList); while(pMenu && strcmp(pMenu->name,pnewMenu->name) >0 ) pMenu = (dbMenu *)ellNext(&pMenu->node); if(pMenu) ellInsert(&pdbbase->menuList,ellPrevious(&pMenu->node),&pnewMenu->node); else ellAdd(&pdbbase->menuList,&pnewMenu->node); pgphentry = gphAdd(pdbbase->pgpHash,pnewMenu->name,&pdbbase->menuList); if(!pgphentry) { yyerrorAbort("gphAdd failed"); } else { pgphentry->userPvt = pnewMenu; } }
static void dbRecordtypeCdef(char *text) { dbText *pdbCdef; tempListNode *ptempListNode; dbRecordType *pdbRecordType; if (!pdbbase->loadCdefs || duplicate) return; ptempListNode = (tempListNode *)ellFirst(&tempList); pdbRecordType = ptempListNode->item; pdbCdef = dbCalloc(1,sizeof(dbText)); if (text[0] == ' ') text++; /* strip leading space if present */ pdbCdef->text = epicsStrDup(text); ellAdd(&pdbRecordType->cdefList, &pdbCdef->node); return; }
static void dbMenuHead(char *name) { dbMenu *pdbMenu; GPHENTRY *pgphentry; pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->menuList); if(pgphentry) { duplicate = TRUE; return; } if(ellCount(&tempList)) yyerrorAbort("dbMenuHead: tempList not empty"); pdbMenu = dbCalloc(1,sizeof(dbMenu)); pdbMenu->name = epicsStrDup(name); allocTemp(pdbMenu); }
static long process(compressRecord *prec) { long status=0; long nelements = 0; int alg = prec->alg; prec->pact = TRUE; if(!dbIsLinkConnected(&prec->inp) || dbGetNelements(&prec->inp,&nelements) || nelements<=0) { recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM); } else { if(!prec->wptr || nelements!=prec->inpn) { if(prec->wptr) { free(prec->wptr); reset(prec); } prec->wptr = (double *)dbCalloc(nelements,sizeof(double)); prec->inpn = nelements; } status = dbGetLink(&prec->inp,DBF_DOUBLE,prec->wptr,0,&nelements); if(status || nelements<=0) { recGblSetSevr(prec,LINK_ALARM,INVALID_ALARM); status = 0; } else { if(alg==compressALG_Average) { status = array_average(prec,prec->wptr,nelements); } else if(alg==compressALG_Circular_Buffer) { (void)put_value(prec,prec->wptr,nelements); status = 0; } else if(nelements>1) { status = compress_array(prec,prec->wptr,nelements); }else if(nelements==1){ status = compress_scalar(prec,prec->wptr); }else status=1; } } /* check event list */ if(status!=1) { prec->udf=FALSE; recGblGetTimeStamp(prec); monitor(prec); /* process the forward scan link record */ recGblFwdLink(prec); } prec->pact=FALSE; return(0); }
static void dbRecordtypeHead(char *name) { dbRecordType *pdbRecordType; GPHENTRY *pgphentry; pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->recordTypeList); if(pgphentry) { duplicate = TRUE; return; } pdbRecordType = dbCalloc(1,sizeof(dbRecordType)); pdbRecordType->name = epicsStrDup(name); if (pdbbase->loadCdefs) ellInit(&pdbRecordType->cdefList); if(ellCount(&tempList)) yyerrorAbort("dbRecordtypeHead tempList not empty"); allocTemp(pdbRecordType); }
static void dbRecordtypeFieldHead(char *name,char *type) { dbFldDes *pdbFldDes; int i; if(duplicate) return; pdbFldDes = dbCalloc(1,sizeof(dbFldDes)); allocTemp(pdbFldDes); pdbFldDes->name = epicsStrDup(name); pdbFldDes->as_level = ASL1; for(i=0; i<DBF_NTYPES; i++) { if(strcmp(type,pamapdbfType[i].strvalue)==0) { pdbFldDes->field_type = pamapdbfType[i].value; return; } } yyerrorAbort("Illegal Field Type"); }
static void dbDriver(char *name) { drvSup *pdrvSup; GPHENTRY *pgphentry; pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->drvList); if(pgphentry) { return; } pdrvSup = dbCalloc(1,sizeof(drvSup)); pdrvSup->name = epicsStrDup(name); pgphentry = gphAdd(pdbbase->pgpHash,pdrvSup->name,&pdbbase->drvList); if(!pgphentry) { yyerrorAbort("gphAdd failed"); } pgphentry->userPvt = pdrvSup; ellAdd(&pdbbase->drvList,&pdrvSup->node); }
static void dbFunction(char *name) { dbText *ptext; GPHENTRY *pgphentry; pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->functionList); if(pgphentry) { return; } ptext = dbCalloc(1,sizeof(dbText)); ptext->text = epicsStrDup(name); pgphentry = gphAdd(pdbbase->pgpHash,ptext->text,&pdbbase->functionList); if(!pgphentry) { yyerrorAbort("gphAdd failed"); } pgphentry->userPvt = ptext; ellAdd(&pdbbase->functionList,&ptext->node); }
static void dbDevice(char *recordtype,char *linktype, char *dsetname,char *choicestring) { devSup *pdevSup; dbRecordType *pdbRecordType; GPHENTRY *pgphentry; int i,link_type; pgphentry = gphFind(pdbbase->pgpHash,recordtype,&pdbbase->recordTypeList); if(!pgphentry) { epicsPrintf("Record type \"%s\" not found for device \"%s\"\n", recordtype, choicestring); yyerror(NULL); return; } link_type=-1; for(i=0; i<LINK_NTYPES; i++) { if(strcmp(pamaplinkType[i].strvalue,linktype)==0) { link_type = pamaplinkType[i].value; break; } } if(link_type==-1) { epicsPrintf("Bad link type \"%s\" for device \"%s\"\n", linktype, choicestring); yyerror(NULL); return; } pdbRecordType = (dbRecordType *)pgphentry->userPvt; pgphentry = gphFind(pdbbase->pgpHash,choicestring,&pdbRecordType->devList); if(pgphentry) { return; } pdevSup = dbCalloc(1,sizeof(devSup)); pdevSup->name = epicsStrDup(dsetname); pdevSup->choice = epicsStrDup(choicestring); pdevSup->link_type = link_type; pgphentry = gphAdd(pdbbase->pgpHash,pdevSup->choice,&pdbRecordType->devList); if(!pgphentry) { yyerrorAbort("gphAdd failed"); } else { pgphentry->userPvt = pdevSup; } ellAdd(&pdbRecordType->devList,&pdevSup->node); }
static void dbVariable(char *name, char *type) { dbVariableDef *pvar; GPHENTRY *pgphentry; pgphentry = gphFind(pdbbase->pgpHash,name,&pdbbase->variableList); if(pgphentry) { return; } pvar = dbCalloc(1,sizeof(dbVariableDef)); pvar->name = epicsStrDup(name); pvar->type = epicsStrDup(type); pgphentry = gphAdd(pdbbase->pgpHash,pvar->name,&pdbbase->variableList); if(!pgphentry) { yyerrorAbort("gphAdd failed"); } pgphentry->userPvt = pvar; ellAdd(&pdbbase->variableList,&pvar->node); }
static void dbIncludeNew(char *filename) { inputFile *pinputFile; FILE *fp; pinputFile = dbCalloc(1,sizeof(inputFile)); pinputFile->filename = macEnvExpand(filename); pinputFile->path = dbOpenFile(pdbbase, pinputFile->filename, &fp); if (!fp) { epicsPrintf("Can't open include file \"%s\"\n", filename); yyerror(NULL); free((void *)pinputFile->filename); free((void *)pinputFile); return; } pinputFile->fp = fp; ellAdd(&inputFileList,&pinputFile->node); pinputFileNow = pinputFile; }
void scanIoInit(IOSCANPVT *pioscanpvt) { ioscan_head *piosh = dbCalloc(1, sizeof(ioscan_head)); int prio; ioscanInit(); for (prio = 0; prio < NUM_CALLBACK_PRIORITIES; prio++) { io_scan_list *piosl = &piosh->iosl[prio]; callbackSetCallback(ioscanCallback, &piosl->callback); callbackSetPriority(prio, &piosl->callback); callbackSetUser(piosh, &piosl->callback); ellInit(&piosl->scan_list.list); piosl->scan_list.lock = epicsMutexMustCreate(); } epicsMutexMustLock(ioscan_lock); piosh->next = pioscan_list; pioscan_list = piosh; epicsMutexUnlock(ioscan_lock); *pioscanpvt = piosh; }
void dbCaAddLinkCallback(struct link *plink, dbCaCallback connect, dbCaCallback monitor, void *userPvt) { caLink *pca; assert(!plink->value.pv_link.pvt); pca = (caLink *)dbCalloc(1, sizeof(caLink)); pca->lock = epicsMutexMustCreate(); pca->plink = plink; pca->pvname = epicsStrDup(plink->value.pv_link.pvname); pca->connect = connect; pca->monitor = monitor; pca->userPvt = userPvt; epicsMutexMustLock(pca->lock); plink->type = CA_LINK; plink->value.pv_link.pvt = pca; addAction(pca, CA_CONNECT); epicsMutexUnlock(pca->lock); }
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); }
void epicsShareAPI dbNotifyAdd(dbCommon *pfrom, dbCommon *pto) { putNotify *ppn = pfrom->ppn; putNotifyPvt *pputNotifyPvt; if(pto->pact) return; /*if active it will not be processed*/ epicsMutexMustLock(pnotifyGlobal->lock); if(!pto->ppnr) {/* make sure record has a putNotifyRecord*/ pto->ppnr = dbCalloc(1,sizeof(putNotifyRecord)); pto->ppnr->precord = pto; ellInit(&pto->ppnr->restartList); } assert(ppn); pputNotifyPvt = (putNotifyPvt *)ppn->pputNotifyPvt; if(!(pto->ppn) && (pputNotifyPvt->state==putNotifyPutInProgress) && (pto!=ppn->paddr->precord)) { putNotifyPvt *pputNotifyPvt; pto->ppn = pfrom->ppn; pputNotifyPvt = (putNotifyPvt *)pfrom->ppn->pputNotifyPvt; ellSafeAdd(&pputNotifyPvt->waitList,&pto->ppnr->waitNode); } epicsMutexUnlock(pnotifyGlobal->lock); }
static void putNotifyInit(putNotify *ppn) { putNotifyPvt *pputNotifyPvt; pputNotifyPvt = (putNotifyPvt *)ellFirst(&pnotifyGlobal->freeList); if(pputNotifyPvt) { ellDelete(&pnotifyGlobal->freeList,&pputNotifyPvt->node); } else { pputNotifyPvt = dbCalloc(1,sizeof(putNotifyPvt)); pputNotifyPvt->cancelEvent = epicsEventCreate(epicsEventEmpty); pputNotifyPvt->userCallbackEvent = epicsEventCreate(epicsEventEmpty); pputNotifyPvt->magic = MAGIC; pputNotifyPvt->state = putNotifyNotActive; } pputNotifyPvt->state = putNotifyNotActive; callbackSetCallback(notifyCallback,&pputNotifyPvt->callback); callbackSetUser(ppn,&pputNotifyPvt->callback); callbackSetPriority(priorityLow,&pputNotifyPvt->callback); ellInit(&pputNotifyPvt->waitList); ppn->status = 0; pputNotifyPvt->state = putNotifyNotActive; pputNotifyPvt->cancelWait = pputNotifyPvt->userCallbackWait = 0; ppn->pputNotifyPvt = pputNotifyPvt; }
static void addToList(struct dbCommon *precord, scan_list *psl) { scan_element *pse, *ptemp; epicsMutexMustLock(psl->lock); pse = precord->spvt; if (pse == NULL) { pse = dbCalloc(1, sizeof(scan_element)); precord->spvt = pse; pse->precord = precord; } pse->pscan_list = psl; ptemp = (scan_element *)ellFirst(&psl->list); while (ptemp) { if (ptemp->precord->phas > precord->phas) { ellInsert(&psl->list, ellPrevious(&ptemp->node), &pse->node); break; } ptemp = (scan_element *)ellNext(&ptemp->node); } if (ptemp == NULL) ellAdd(&psl->list, (void *)pse); psl->modified = TRUE; epicsMutexUnlock(psl->lock); }
event_list *eventNameToHandle(const char *eventname) { int prio; event_list *pel; static epicsThreadOnceId onceId = EPICS_THREAD_ONCE_INIT; if (!eventname || eventname[0] == 0) return NULL; epicsThreadOnce(&onceId, eventOnce, NULL); epicsMutexMustLock(event_lock); for (pel = pevent_list[0]; pel; pel=pel->next) { if (strcmp(pel->event_name, eventname) == 0) break; } if (pel == NULL) { pel = dbCalloc(1, sizeof(event_list)); strcpy(pel->event_name, eventname); for (prio = 0; prio < NUM_CALLBACK_PRIORITIES; prio++) { callbackSetUser(&pel->scan_list[prio], &pel->callback[prio]); callbackSetPriority(prio, &pel->callback[prio]); callbackSetCallback(eventCallback, &pel->callback[prio]); pel->scan_list[prio].lock = epicsMutexMustCreate(); ellInit(&pel->scan_list[prio].list); } pel->next=pevent_list[0]; pevent_list[0]=pel; { /* backward compatibility */ char* p; long e = strtol(eventname, &p, 0); if (*p == 0 && e > 0 && e <= 255) pevent_list[e] = pel; } } epicsMutexUnlock(event_lock); return pel; }
static void dbCaTask(void *arg) { taskwdInsert(0, NULL, NULL); SEVCHK(ca_context_create(ca_enable_preemptive_callback), "dbCaTask calling ca_context_create"); dbCaClientContext = ca_current_context (); SEVCHK(ca_add_exception_event(exceptionCallback,NULL), "ca_add_exception_event"); epicsEventSignal(startStopEvent); /* channel access event loop */ while (TRUE){ do { epicsEventMustWait(workListEvent); } while (dbCaCtl == ctlPause); while (TRUE) { /* process all requests in workList*/ caLink *pca; short link_action; int status; epicsMutexMustLock(workListLock); if (!(pca = (caLink *)ellGet(&workList))){ /* Take off list head */ epicsMutexUnlock(workListLock); if (dbCaCtl == ctlExit) goto shutdown; break; /* workList is empty */ } link_action = pca->link_action; pca->link_action = 0; if (link_action & CA_CLEAR_CHANNEL) --removesOutstanding; epicsMutexUnlock(workListLock); /* Give back immediately */ if (link_action & CA_CLEAR_CHANNEL) { /* This must be first */ dbCaLinkFree(pca); /* No alarm is raised. Since link is changing so what? */ continue; /* No other link_action makes sense */ } if (link_action & CA_CONNECT) { status = ca_create_channel( pca->pvname,connectionCallback,(void *)pca, CA_PRIORITY_DB_LINKS, &(pca->chid)); if (status != ECA_NORMAL) { errlogPrintf("dbCaTask ca_create_channel %s\n", ca_message(status)); printLinks(pca); continue; } dbca_chan_count++; status = ca_replace_access_rights_event(pca->chid, accessRightsCallback); if (status != ECA_NORMAL) { errlogPrintf("dbCaTask replace_access_rights_event %s\n", ca_message(status)); printLinks(pca); } continue; /*Other options must wait until connect*/ } if (ca_state(pca->chid) != cs_conn) continue; if (link_action & CA_WRITE_NATIVE) { assert(pca->pputNative); if (pca->putType == CA_PUT) { status = ca_array_put( pca->dbrType, pca->nelements, pca->chid, pca->pputNative); } else if (pca->putType==CA_PUT_CALLBACK) { status = ca_array_put_callback( pca->dbrType, pca->nelements, pca->chid, pca->pputNative, putCallback, pca); } else { status = ECA_PUTFAIL; } if (status != ECA_NORMAL) { errlogPrintf("dbCaTask ca_array_put %s\n", ca_message(status)); printLinks(pca); } epicsMutexMustLock(pca->lock); if (status == ECA_NORMAL) pca->newOutNative = FALSE; epicsMutexUnlock(pca->lock); } if (link_action & CA_WRITE_STRING) { assert(pca->pputString); if (pca->putType == CA_PUT) { status = ca_array_put( DBR_STRING, 1, pca->chid, pca->pputString); } else if (pca->putType==CA_PUT_CALLBACK) { status = ca_array_put_callback( DBR_STRING, 1, pca->chid, pca->pputString, putCallback, pca); } else { status = ECA_PUTFAIL; } if (status != ECA_NORMAL) { errlogPrintf("dbCaTask ca_array_put %s\n", ca_message(status)); printLinks(pca); } epicsMutexMustLock(pca->lock); if (status == ECA_NORMAL) pca->newOutString = FALSE; epicsMutexUnlock(pca->lock); } /*CA_GET_ATTRIBUTES before CA_MONITOR so that attributes available * before the first monitor callback */ if (link_action & CA_GET_ATTRIBUTES) { status = ca_get_callback(DBR_CTRL_DOUBLE, pca->chid, getAttribEventCallback, pca); if (status != ECA_NORMAL) { errlogPrintf("dbCaTask ca_get_callback %s\n", ca_message(status)); printLinks(pca); } } if (link_action & CA_MONITOR_NATIVE) { size_t element_size; element_size = dbr_value_size[ca_field_type(pca->chid)]; epicsMutexMustLock(pca->lock); pca->pgetNative = dbCalloc(pca->nelements, element_size); epicsMutexUnlock(pca->lock); status = ca_add_array_event( ca_field_type(pca->chid)+DBR_TIME_STRING, ca_element_count(pca->chid), pca->chid, eventCallback, pca, 0.0, 0.0, 0.0, 0); if (status != ECA_NORMAL) { errlogPrintf("dbCaTask ca_add_array_event %s\n", ca_message(status)); printLinks(pca); } } if (link_action & CA_MONITOR_STRING) { epicsMutexMustLock(pca->lock); pca->pgetString = dbCalloc(1, MAX_STRING_SIZE); epicsMutexUnlock(pca->lock); status = ca_add_array_event(DBR_TIME_STRING, 1, pca->chid, eventCallback, pca, 0.0, 0.0, 0.0, 0); if (status != ECA_NORMAL) { errlogPrintf("dbCaTask ca_add_array_event %s\n", ca_message(status)); printLinks(pca); } } } SEVCHK(ca_flush_io(), "dbCaTask"); } shutdown: taskwdRemove(0); if (dbca_chan_count == 0) ca_context_destroy(); else fprintf(stderr, "dbCa: chan_count = %d at shutdown\n", dbca_chan_count); epicsEventSignal(startStopEvent); }
static void dbBreakBody(void) { brkTable *pnewbrkTable; brkInt *paBrkInt; brkTable *pbrkTable; int number, down=0; int i; GPHENTRY *pgphentry; if (duplicate) { duplicate = FALSE; return; } pnewbrkTable = (brkTable *)popFirstTemp(); number = ellCount(&tempList); if (number % 2) { yyerrorAbort("breaktable: Raw value missing"); return; } number /= 2; if (number < 2) { yyerrorAbort("breaktable: Must have at least two points!"); return; } pnewbrkTable->number = number; pnewbrkTable->paBrkInt = paBrkInt = dbCalloc(number, sizeof(brkInt)); for (i=0; i<number; i++) { char *str; str = (char *)popFirstTemp(); epicsScanDouble(str, &paBrkInt[i].raw); free(str); str = (char *)popFirstTemp(); epicsScanDouble(str, &paBrkInt[i].eng); free(str); } /* Compute slopes */ for (i=0; i<number-1; i++) { double slope = (paBrkInt[i+1].eng - paBrkInt[i].eng)/ (paBrkInt[i+1].raw - paBrkInt[i].raw); if (!dbBptNotMonotonic && slope == 0) { yyerrorAbort("breaktable slope is zero"); return; } if (i == 0) { down = (slope < 0); } else if (!dbBptNotMonotonic && down != (slope < 0)) { yyerrorAbort("breaktable slope changes sign"); return; } paBrkInt[i].slope = slope; } /* Continue with last slope beyond the final point */ paBrkInt[number-1].slope = paBrkInt[number-2].slope; /* Add brkTable in sorted order */ pbrkTable = (brkTable *)ellFirst(&pdbbase->bptList); while (pbrkTable) { if (strcmp(pbrkTable->name, pnewbrkTable->name) > 0) { ellInsert(&pdbbase->bptList, ellPrevious((ELLNODE *)pbrkTable), (ELLNODE *)pnewbrkTable); break; } pbrkTable = (brkTable *)ellNext(&pbrkTable->node); } if (!pbrkTable) ellAdd(&pdbbase->bptList, &pnewbrkTable->node); pgphentry = gphAdd(pdbbase->pgpHash,pnewbrkTable->name,&pdbbase->bptList); if (!pgphentry) { yyerrorAbort("dbBreakBody: gphAdd failed"); return; } pgphentry->userPvt = pnewbrkTable; }
long epicsShareAPI dbl(const char *precordTypename, const char *fields) { DBENTRY dbentry; DBENTRY *pdbentry=&dbentry; long status; int nfields = 0; int ifield; char *fieldnames = 0; char **papfields = 0; if (!pdbbase) { printf("No database loaded\n"); return 0; } if (precordTypename && ((*precordTypename == '\0') || !strcmp(precordTypename,"*"))) precordTypename = NULL; if (fields && (*fields == '\0')) fields = NULL; if (fields) { char *pnext; fieldnames = epicsStrDup(fields); nfields = 1; pnext = fieldnames; while (*pnext && (pnext = strchr(pnext,' '))) { nfields++; while (*pnext == ' ') pnext++; } papfields = dbCalloc(nfields,sizeof(char *)); pnext = fieldnames; for (ifield = 0; ifield < nfields; ifield++) { papfields[ifield] = pnext; if (ifield < nfields - 1) { pnext = strchr(pnext, ' '); *pnext++ = 0; while (*pnext == ' ') pnext++; } } } dbInitEntry(pdbbase, pdbentry); if (!precordTypename) status = dbFirstRecordType(pdbentry); else status = dbFindRecordType(pdbentry,precordTypename); if (status) { printf("No record type\n"); } while (!status) { status = dbFirstRecord(pdbentry); while (!status) { printf("%s", dbGetRecordName(pdbentry)); for (ifield = 0; ifield < nfields; ifield++) { char *pvalue; status = dbFindField(pdbentry, papfields[ifield]); if (status) { if (!strcmp(papfields[ifield], "recordType")) { pvalue = dbGetRecordTypeName(pdbentry); } else { printf(", "); continue; } } else { pvalue = dbGetString(pdbentry); } printf(", \"%s\"", pvalue ? pvalue : ""); } printf("\n"); status = dbNextRecord(pdbentry); } if (precordTypename) break; status = dbNextRecordType(pdbentry); } if (nfields > 0) { free((void *)papfields); free((void *)fieldnames); } dbFinishEntry(pdbentry); 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); }
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); }
static long dbReadCOM(DBBASE **ppdbbase,const char *filename, FILE *fp, const char *path,const char *substitutions) { long status; inputFile *pinputFile = NULL; char *penv; char **macPairs; if(*ppdbbase == 0) *ppdbbase = dbAllocBase(); pdbbase = *ppdbbase; if(path && strlen(path)>0) { dbPath(pdbbase,path); } else { penv = getenv("EPICS_DB_INCLUDE_PATH"); if(penv) { dbPath(pdbbase,penv); } else { dbPath(pdbbase,"."); } } my_buffer = dbCalloc(MY_BUFFER_SIZE,sizeof(char)); freeListInitPvt(&freeListPvt,sizeof(tempListNode),100); if(substitutions) { if(macCreateHandle(&macHandle,NULL)) { epicsPrintf("macCreateHandle error\n"); status = -1; goto cleanup; } macParseDefns(macHandle,(char *)substitutions,&macPairs); if(macPairs ==NULL) { macDeleteHandle(macHandle); macHandle = NULL; } else { macInstallMacros(macHandle,macPairs); free((void *)macPairs); mac_input_buffer = dbCalloc(MY_BUFFER_SIZE,sizeof(char)); } } pinputFile = dbCalloc(1,sizeof(inputFile)); if(filename) { pinputFile->filename = macEnvExpand(filename); } if(!fp) { FILE *fp1; if(pinputFile->filename) pinputFile->path = dbOpenFile(pdbbase,pinputFile->filename,&fp1); if(!pinputFile->filename || !fp1) { errPrintf(0,__FILE__, __LINE__, "dbRead opening file %s",pinputFile->filename); free((void *)pinputFile->filename); free((void *)pinputFile); status = -1; goto cleanup; } pinputFile->fp = fp1; } else { pinputFile->fp = fp; } pinputFile->line_num = 0; pinputFileNow = pinputFile; my_buffer[0] = '\0'; my_buffer_ptr = my_buffer; ellAdd(&inputFileList,&pinputFile->node); status = pvt_yy_parse(); dbFreePath(pdbbase); if(!status) { /*add RTYP and VERS as an attribute */ DBENTRY dbEntry; DBENTRY *pdbEntry = &dbEntry; long localStatus; dbInitEntry(pdbbase,pdbEntry); localStatus = dbFirstRecordType(pdbEntry); while(!localStatus) { localStatus = dbPutRecordAttribute(pdbEntry,"RTYP", dbGetRecordTypeName(pdbEntry)); if(!localStatus) { localStatus = dbPutRecordAttribute(pdbEntry,"VERS", "none specified"); } if(localStatus) { fprintf(stderr,"dbPutRecordAttribute status %ld\n",status); } else { localStatus = dbNextRecordType(pdbEntry); } } dbFinishEntry(pdbEntry); } cleanup: if(macHandle) macDeleteHandle(macHandle); macHandle = NULL; if(mac_input_buffer) free((void *)mac_input_buffer); mac_input_buffer = NULL; if(freeListPvt) freeListCleanup(freeListPvt); freeListPvt = NULL; if(my_buffer) free((void *)my_buffer); my_buffer = NULL; freeInputFileList(); return(status); }
static void dbRecordtypeBody(void) { dbRecordType *pdbRecordType; dbFldDes *pdbFldDes; int i,j,ilink; GPHENTRY *pgphentry; int no_fields,no_prompt,no_links; dbfType field_type; char *psortFldNameTemp; short psortFldIndTemp; char **papsortFldName; short *sortFldInd; if(duplicate) { duplicate = FALSE; return; } pdbRecordType= (dbRecordType *)popFirstTemp(); pdbRecordType->no_fields = no_fields = ellCount(&tempList); pdbRecordType->papFldDes = dbCalloc(no_fields,sizeof(dbFldDes *)); pdbRecordType->papsortFldName = dbCalloc(no_fields,sizeof(char *)); pdbRecordType->sortFldInd = dbCalloc(no_fields,sizeof(short)); no_prompt = no_links = 0; for(i=0; i<no_fields; i++) { pdbFldDes = (dbFldDes *)popFirstTemp(); pdbFldDes->pdbRecordType = pdbRecordType; pdbFldDes->indRecordType = i; pdbRecordType->papFldDes[i] = pdbFldDes; if(pdbFldDes->promptgroup) no_prompt++; field_type = pdbFldDes->field_type; if((field_type>=DBF_INLINK) && (field_type<=DBF_FWDLINK))no_links++; if((field_type==DBF_STRING) && (pdbFldDes->size==0)) fprintf(stderr,"recordtype(%s).%s size not specified\n", pdbRecordType->name,pdbFldDes->name); if((field_type==DBF_NOACCESS) && (pdbFldDes->extra==0)) fprintf(stderr,"recordtype(%s).%s extra not specified\n", pdbRecordType->name,pdbFldDes->name); } if(ellCount(&tempList)) yyerrorAbort("dbMenuBody: tempList not empty"); pdbRecordType->no_prompt = no_prompt; pdbRecordType->no_links = no_links; pdbRecordType->link_ind = dbCalloc(no_links,sizeof(short)); ilink = 0; for(i=0; i<no_fields; i++) { pdbFldDes = pdbRecordType->papFldDes[i]; /* if prompt is null make it a null string */ if(!pdbFldDes->prompt) pdbFldDes->prompt = dbCalloc(1,sizeof(char)); field_type = pdbFldDes->field_type; if((field_type>=DBF_INLINK) && (field_type<=DBF_FWDLINK)) pdbRecordType->link_ind[ilink++] = i; if(strcmp(pdbFldDes->name,"VAL")==0) { pdbRecordType->pvalFldDes = pdbRecordType->papFldDes[i]; pdbRecordType->indvalFlddes = i; } pdbRecordType->papsortFldName[i] = pdbFldDes->name; pdbRecordType->sortFldInd[i] = i; } /*Now sort fields. Sorry dumb sort algorithm */ papsortFldName = pdbRecordType->papsortFldName; sortFldInd = pdbRecordType->sortFldInd; for(i=0; i<no_fields; i++) { for(j=i+1; j<no_fields; j++) { if(strcmp(papsortFldName[j],papsortFldName[i])<0 ) { psortFldNameTemp = papsortFldName[j]; psortFldIndTemp = sortFldInd[j]; papsortFldName[j] = papsortFldName[i]; sortFldInd[j] = sortFldInd[i]; papsortFldName[i] = psortFldNameTemp; sortFldInd[i] = psortFldIndTemp; } } } /*Initialize lists*/ ellInit(&pdbRecordType->attributeList); ellInit(&pdbRecordType->recList); ellInit(&pdbRecordType->devList); pgphentry = gphAdd(pdbbase->pgpHash,pdbRecordType->name, &pdbbase->recordTypeList); if(!pgphentry) { yyerrorAbort("gphAdd failed"); } else { pgphentry->userPvt = pdbRecordType; } ellAdd(&pdbbase->recordTypeList,&pdbRecordType->node); }
long dbCaPutLinkCallback(struct link *plink,short dbrType, const void *pbuffer,long nRequest,dbCaCallback callback,void *userPvt) { caLink *pca = (caLink *)plink->value.pv_link.pvt; long status = 0; short link_action = 0; assert(pca); /* put the new value in */ epicsMutexMustLock(pca->lock); assert(pca->plink); if (!pca->isConnected || !pca->hasWriteAccess) { epicsMutexUnlock(pca->lock); return -1; } if (pca->dbrType == DBR_ENUM && dbDBRnewToDBRold[dbrType] == DBR_STRING) { long (*fConvert)(const void *from, void *to, struct dbAddr *paddr); /* Send as DBR_STRING */ if (!pca->pputString) { pca->pputString = dbCalloc(1, MAX_STRING_SIZE); /* Disabled by ANJ, needs a link flag to allow user to control this. * Setting these makes the reconnect callback re-do the last CA put. plink->value.pv_link.pvlMask |= pvlOptOutString; */ } fConvert = dbFastPutConvertRoutine[dbrType][dbDBRoldToDBFnew[DBR_STRING]]; status = fConvert(pbuffer, pca->pputString, 0); link_action |= CA_WRITE_STRING; pca->gotOutString = TRUE; if (pca->newOutString) pca->nNoWrite++; pca->newOutString = TRUE; } else { int newType = dbDBRoldToDBFnew[pca->dbrType]; if (!pca->pputNative) { pca->pputNative = dbCalloc(pca->nelements, dbr_value_size[ca_field_type(pca->chid)]); /* Fixed and disabled by ANJ, see comment above. plink->value.pv_link.pvlMask |= pvlOptOutNative; */ } if (nRequest == 1 && pca->nelements==1){ long (*fConvert)(const void *from, void *to, struct dbAddr *paddr); fConvert = dbFastPutConvertRoutine[dbrType][newType]; status = fConvert(pbuffer, pca->pputNative, 0); } else { struct dbAddr dbAddr; long (*aConvert)(struct dbAddr *paddr, const void *from, long nreq, long nfrom, long off); aConvert = dbPutConvertRoutine[dbrType][newType]; memset((void *)&dbAddr, 0, sizeof(dbAddr)); dbAddr.pfield = pca->pputNative; /*Following only used for DBF_STRING*/ dbAddr.field_size = MAX_STRING_SIZE; if(nRequest>pca->nelements) nRequest = pca->nelements; status = aConvert(&dbAddr, pbuffer, nRequest, pca->nelements, 0); if(nRequest<pca->nelements) { long elemsize = dbr_value_size[ca_field_type(pca->chid)]; memset(nRequest*elemsize+(char*)pca->pputNative, 0, (pca->nelements-nRequest)*elemsize); } } link_action |= CA_WRITE_NATIVE; pca->gotOutNative = TRUE; if (pca->newOutNative) pca->nNoWrite++; pca->newOutNative = TRUE; } if (callback) { pca->putType = CA_PUT_CALLBACK; pca->putCallback = callback; pca->putUserPvt = userPvt; } else { pca->putType = CA_PUT; pca->putCallback = 0; } addAction(pca, link_action); epicsMutexUnlock(pca->lock); return status; }
int main(int argc,char **argv) { dbMenu *pdbMenu; char *outFilename; char *pext; FILE *outFile; char *plastSlash; int i; int strip; char *path = NULL; char *sub = NULL; int pathLength = 0; int subLength = 0; char **pstr; char *psep; int *len; long status; static char *pathSep = OSI_PATH_LIST_SEPARATOR; static char *subSep = ","; /*Look for options*/ if(argc<2) { fprintf(stderr,"usage: dbToMenu -Idir -Idir file.dbd [outfile]\n"); exit(0); } while((strncmp(argv[1],"-I",2)==0)||(strncmp(argv[1],"-S",2)==0)) { if(strncmp(argv[1],"-I",2)==0) { pstr = &path; psep = pathSep; len = &pathLength; } else { pstr = ⊂ psep = subSep; len = &subLength; } if(strlen(argv[1])==2) { dbCatString(pstr,len,argv[2],psep); strip = 2; } else { dbCatString(pstr,len,argv[1]+2,psep); strip = 1; } argc -= strip; for(i=1; i<argc; i++) argv[i] = argv[i + strip]; } if(argc<2 || (strncmp(argv[1],"-",1)==0)) { fprintf(stderr,"usage: dbToMenu -Idir -Idir file.dbd [outfile]\n"); exit(0); } if (argc==2) { /*remove path so that outFile is created where program is executed*/ plastSlash = strrchr(argv[1],'/'); if(!plastSlash) plastSlash = strrchr(argv[1],'\\'); plastSlash = (plastSlash ? plastSlash+1 : argv[1]); outFilename = dbCalloc(1,strlen(plastSlash)+1); strcpy(outFilename,plastSlash); pext = strstr(outFilename,".dbd"); if (!pext) { fprintf(stderr,"Input file MUST have .dbd extension\n"); exit(-1); } strcpy(pext,".h"); } else { outFilename = dbCalloc(1,strlen(argv[2])+1); strcpy(outFilename,argv[2]); } pdbbase = dbAllocBase(); pdbbase->ignoreMissingMenus = TRUE; status = dbReadDatabase(&pdbbase,argv[1],path,sub); if (status) { errlogFlush(); fprintf(stderr, "dbToMenuH: Input errors, no output generated\n"); exit(1); } outFile = fopen(outFilename, "w"); if (!outFile) { epicsPrintf("Error creating output file \"%s\"\n", outFilename); exit(1); } pdbMenu = (dbMenu *)ellFirst(&pdbbase->menuList); while(pdbMenu) { fprintf(outFile,"#ifndef INC%sH\n",pdbMenu->name); fprintf(outFile,"#define INC%sH\n",pdbMenu->name); fprintf(outFile,"typedef enum {\n"); for(i=0; i<pdbMenu->nChoice; i++) { fprintf(outFile,"\t%s",pdbMenu->papChoiceName[i]); if(i < (pdbMenu->nChoice - 1)) fprintf(outFile,","); fprintf(outFile,"\n"); } fprintf(outFile,"}%s;\n",pdbMenu->name); fprintf(outFile,"#endif /*INC%sH*/\n",pdbMenu->name); pdbMenu = (dbMenu *)ellNext(&pdbMenu->node); } fclose(outFile); free((void *)outFilename); return(0); }
int main(int argc,char **argv) { int i; char *outFilename; char *pext; FILE *outFile; dbMenu *pdbMenu; dbRecordType *pdbRecordType; dbFldDes *pdbFldDes; char *plastSlash; int strip; char *path = NULL; char *sub = NULL; int pathLength = 0; int subLength = 0; char **pstr; char *psep; int *len; long status; static char *pathSep = OSI_PATH_LIST_SEPARATOR; static char *subSep = ","; /*Look for options*/ if(argc<2) { fprintf(stderr,"usage: dbToDoxygen -Idir -Idir file.dbd [outfile]\n"); exit(0); } while((strncmp(argv[1],"-I",2)==0)||(strncmp(argv[1],"-S",2)==0)) { if(strncmp(argv[1],"-I",2)==0) { pstr = &path; psep = pathSep; len = &pathLength; } else { pstr = ⊂ psep = subSep; len = &subLength; } if(strlen(argv[1])==2) { dbCatString(pstr,len,argv[2],psep); strip = 2; } else { dbCatString(pstr,len,argv[1]+2,psep); strip = 1; } argc -= strip; for(i=1; i<argc; i++) argv[i] = argv[i + strip]; } if(argc<2 || (strncmp(argv[1],"-",1)==0)) { fprintf(stderr,"usage: dbToRecordtypeH -Idir -Idir file.dbd [outfile]\n"); exit(0); } if(argc==2){ /*remove path so that outFile is created where program is executed*/ plastSlash = strrchr(argv[1],'/'); if(!plastSlash) plastSlash = strrchr(argv[1],'\\'); plastSlash = (plastSlash ? plastSlash+1 : argv[1]); outFilename = (char*)dbCalloc(1,strlen(plastSlash)+1); strcpy(outFilename,plastSlash); pext = strstr(outFilename,".dbd"); if(!pext) { fprintf(stderr,"Input file MUST have .dbd extension\n"); exit(-1); } strcpy(pext,".h"); }else { outFilename = (char*)dbCalloc(1,strlen(argv[2])+1); strcpy(outFilename,argv[2]); } pdbbase = dbAllocBase(); pdbbase->ignoreMissingMenus = TRUE; pdbbase->loadCdefs = TRUE; status = dbReadDatabase(&pdbbase,argv[1],path,sub); if(status) { errlogFlush(); fprintf(stderr, "dbToMenuH: Input errors, no output generated\n"); exit(1); } outFile = fopen(outFilename,"wt"); if(!outFile) { epicsPrintf("Error creating output file \"%s\"\n", outFilename); exit(1); } fprintf(outFile,"/// @file\n/// EPICS DB record definitions\n\n"); pdbMenu = (dbMenu *)ellFirst(&pdbbase->menuList); while(pdbMenu) { fprintf(outFile,"/// %s EPICS DB menu\n",pdbMenu->name); fprintf(outFile,"enum %s\n{\n", pdbMenu->name); for(i=0; i<pdbMenu->nChoice; i++) { fprintf(outFile,"\t%s",pdbMenu->papChoiceName[i]); if(i < (pdbMenu->nChoice - 1)) fprintf(outFile,","); fprintf(outFile,"\t///< %s", pdbMenu->papChoiceValue[i]); fprintf(outFile,"\n"); } fprintf(outFile,"};\n\n"); pdbMenu = (dbMenu *)ellNext(&pdbMenu->node); } pdbRecordType = (dbRecordType *)ellFirst(&pdbbase->recordTypeList); while(pdbRecordType) { fprintf(outFile,"/// %s EPICS DB record\n",pdbRecordType->name); fprintf(outFile,"struct %s\n{\n",pdbRecordType->name); for(i=0; i<pdbRecordType->no_fields; i++) { char name[256]; int j; pdbFldDes = pdbRecordType->papFldDes[i]; for(j=0; j< (int)strlen(pdbFldDes->name); j++) name[j] = pdbFldDes->name[j]; name[strlen(pdbFldDes->name)] = 0; switch(pdbFldDes->field_type) { case DBF_STRING : fprintf(outFile, "\tchar\t\t%s[%d];\t///< %s\n", name, pdbFldDes->size, pdbFldDes->prompt); break; case DBF_CHAR : fprintf(outFile, "\tepicsInt8\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_UCHAR : fprintf(outFile, "\tepicsUInt8\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_SHORT : fprintf(outFile, "\tepicsInt16\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_USHORT : fprintf(outFile, "\tepicsUInt16\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_LONG : fprintf(outFile, "\tepicsInt32\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_ULONG : fprintf(outFile, "\tepicsUInt32\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_FLOAT : fprintf(outFile, "\tepicsFloat32\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_DOUBLE : fprintf(outFile, "\tepicsFloat64\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_MENU : pdbMenu = (dbMenu*)pdbFldDes->ftPvt; if (pdbMenu != NULL) { fprintf(outFile, "\t%s\t%s;\t///< %s\n", pdbMenu->name, name, pdbFldDes->prompt); } else { fprintf(outFile, "\tepicsEnum16\t%s;\t///< %s\n", name, pdbFldDes->prompt); } break; case DBF_ENUM : case DBF_DEVICE : fprintf(outFile, "\tepicsEnum16\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_INLINK : case DBF_OUTLINK : case DBF_FWDLINK : fprintf(outFile, "\tDBLINK\t\t%s;\t///< %s\n", name, pdbFldDes->prompt); break; case DBF_NOACCESS: break; default: fprintf(outFile,"ILLEGAL FIELD TYPE\n"); } } fprintf(outFile,"};\n"); pdbRecordType = (dbRecordType *)ellNext(&pdbRecordType->node); if(pdbRecordType) fprintf(outFile,"\n"); } fclose(outFile); free((void *)outFilename); return(0); }
int main(int argc,char **argv) { int i; char *outFilename; char *pext; FILE *outFile; dbMenu *pdbMenu; dbRecordType *pdbRecordType; dbFldDes *pdbFldDes; dbText *pdbCdef; int isdbCommonRecord = FALSE; char *plastSlash; int strip; char *path = NULL; char *sub = NULL; int pathLength = 0; int subLength = 0; char **pstr; char *psep; int *len; long status; static char *pathSep = OSI_PATH_LIST_SEPARATOR; static char *subSep = ","; /*Look for options*/ if(argc<2) { fprintf(stderr,"usage: dbToRecordtypeH -Idir -Idir file.dbd [outfile]\n"); exit(0); } while((strncmp(argv[1],"-I",2)==0)||(strncmp(argv[1],"-S",2)==0)) { if(strncmp(argv[1],"-I",2)==0) { pstr = &path; psep = pathSep; len = &pathLength; } else { pstr = ⊂ psep = subSep; len = &subLength; } if(strlen(argv[1])==2) { dbCatString(pstr,len,argv[2],psep); strip = 2; } else { dbCatString(pstr,len,argv[1]+2,psep); strip = 1; } argc -= strip; for(i=1; i<argc; i++) argv[i] = argv[i + strip]; } if(argc<2 || (strncmp(argv[1],"-",1)==0)) { fprintf(stderr,"usage: dbToRecordtypeH -Idir -Idir file.dbd [outfile]\n"); exit(0); } if(argc==2){ /*remove path so that outFile is created where program is executed*/ plastSlash = strrchr(argv[1],'/'); if(!plastSlash) plastSlash = strrchr(argv[1],'\\'); plastSlash = (plastSlash ? plastSlash+1 : argv[1]); outFilename = dbCalloc(1,strlen(plastSlash)+1); strcpy(outFilename,plastSlash); pext = strstr(outFilename,".dbd"); if(!pext) { fprintf(stderr,"Input file MUST have .dbd extension\n"); exit(-1); } strcpy(pext,".h"); if(strcmp(outFilename,"dbCommonRecord.h")==0) { strcpy(outFilename,"dbCommon.h"); isdbCommonRecord = TRUE; } }else { outFilename = dbCalloc(1,strlen(argv[2])+1); strcpy(outFilename,argv[2]); if(strstr(outFilename,"dbCommon.h")!=0) { isdbCommonRecord = TRUE; } } pdbbase = dbAllocBase(); pdbbase->ignoreMissingMenus = TRUE; pdbbase->loadCdefs = TRUE; status = dbReadDatabase(&pdbbase,argv[1],path,sub); if(status) { errlogFlush(); fprintf(stderr, "dbToMenuH: Input errors, no output generated\n"); exit(1); } outFile = fopen(outFilename,"w"); if(!outFile) { epicsPrintf("Error creating output file \"%s\"\n", outFilename); exit(1); } pdbMenu = (dbMenu *)ellFirst(&pdbbase->menuList); while(pdbMenu) { fprintf(outFile,"\n#ifndef INC%sH\n",pdbMenu->name); fprintf(outFile,"#define INC%sH\n",pdbMenu->name); fprintf(outFile,"typedef enum {\n"); for(i=0; i<pdbMenu->nChoice; i++) { fprintf(outFile,"\t%s",pdbMenu->papChoiceName[i]); if(i < (pdbMenu->nChoice - 1)) fprintf(outFile,","); fprintf(outFile,"\n"); } fprintf(outFile,"}%s;\n",pdbMenu->name); fprintf(outFile,"#endif /*INC%sH*/\n",pdbMenu->name); pdbMenu = (dbMenu *)ellNext(&pdbMenu->node); } pdbRecordType = (dbRecordType *)ellFirst(&pdbbase->recordTypeList); while(pdbRecordType) { fprintf(outFile,"#ifndef INC%sH\n",pdbRecordType->name); fprintf(outFile,"#define INC%sH\n",pdbRecordType->name); pdbCdef = (dbText *)ellFirst(&pdbRecordType->cdefList); while (pdbCdef) { fprintf(outFile,"%s\n",pdbCdef->text); pdbCdef = (dbText *)ellNext(&pdbCdef->node); } fprintf(outFile,"typedef struct %s",pdbRecordType->name); if(!isdbCommonRecord) fprintf(outFile,"Record"); fprintf(outFile," {\n"); for(i=0; i<pdbRecordType->no_fields; i++) { char name[256]; int j; pdbFldDes = pdbRecordType->papFldDes[i]; for(j=0; j< (int)strlen(pdbFldDes->name); j++) name[j] = tolower(pdbFldDes->name[j]); name[strlen(pdbFldDes->name)] = 0; switch(pdbFldDes->field_type) { case DBF_STRING : fprintf(outFile, "\tchar\t\t%s[%d];\t/* %s */\n", name, pdbFldDes->size, pdbFldDes->prompt); break; case DBF_CHAR : fprintf(outFile, "\tepicsInt8\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_UCHAR : fprintf(outFile, "\tepicsUInt8\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_SHORT : fprintf(outFile, "\tepicsInt16\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_USHORT : fprintf(outFile, "\tepicsUInt16\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_LONG : fprintf(outFile, "\tepicsInt32\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_ULONG : fprintf(outFile, "\tepicsUInt32\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_FLOAT : fprintf(outFile, "\tepicsFloat32\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_DOUBLE : fprintf(outFile, "\tepicsFloat64\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_ENUM : case DBF_MENU : case DBF_DEVICE : fprintf(outFile, "\tepicsEnum16\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_INLINK : case DBF_OUTLINK : case DBF_FWDLINK : fprintf(outFile, "\tDBLINK\t\t%s;\t/* %s */\n", name, pdbFldDes->prompt); break; case DBF_NOACCESS: fprintf(outFile, "\t%s;\t/* %s */\n", pdbFldDes->extra, pdbFldDes->prompt); break; default: fprintf(outFile,"ILLEGAL FIELD TYPE\n"); } } fprintf(outFile,"} %s",pdbRecordType->name); if(!isdbCommonRecord) fprintf(outFile,"Record"); fprintf(outFile,";\n"); if(!isdbCommonRecord) { for(i=0; i<pdbRecordType->no_fields; i++) { pdbFldDes = pdbRecordType->papFldDes[i]; fprintf(outFile,"#define %sRecord%s\t%d\n", pdbRecordType->name,pdbFldDes->name,pdbFldDes->indRecordType); } } fprintf(outFile,"#endif /*INC%sH*/\n",pdbRecordType->name); pdbRecordType = (dbRecordType *)ellNext(&pdbRecordType->node); if(pdbRecordType) fprintf(outFile,"\n"); } if(!isdbCommonRecord) { fprintf(outFile,"#ifdef GEN_SIZE_OFFSET\n"); fprintf(outFile,"#ifdef __cplusplus\n"); fprintf(outFile,"extern \"C\" {\n"); fprintf(outFile,"#endif\n"); fprintf(outFile,"#include <epicsExport.h>\n"); pdbRecordType = (dbRecordType *)ellFirst(&pdbbase->recordTypeList); while(pdbRecordType) { fprintf(outFile,"static int %sRecordSizeOffset(dbRecordType *pdbRecordType)\n{\n", pdbRecordType->name); fprintf(outFile," %sRecord *prec = 0;\n",pdbRecordType->name); for(i=0; i<pdbRecordType->no_fields; i++) { char name[256]; int j; pdbFldDes = pdbRecordType->papFldDes[i]; for(j=0; j< (int)strlen(pdbFldDes->name); j++) name[j] = tolower(pdbFldDes->name[j]); name[strlen(pdbFldDes->name)] = 0; fprintf(outFile, " pdbRecordType->papFldDes[%d]->size=sizeof(prec->%s);\n", i,name); fprintf(outFile," pdbRecordType->papFldDes[%d]->offset=",i); fprintf(outFile, "(short)((char *)&prec->%s - (char *)prec);\n",name); } fprintf(outFile," pdbRecordType->rec_size = sizeof(*prec);\n"); fprintf(outFile," return(0);\n"); fprintf(outFile,"}\n"); fprintf(outFile,"epicsExportRegistrar(%sRecordSizeOffset);\n", pdbRecordType->name); pdbRecordType = (dbRecordType *)ellNext(&pdbRecordType->node); } fprintf(outFile,"#ifdef __cplusplus\n"); fprintf(outFile,"}\n"); fprintf(outFile,"#endif\n"); fprintf(outFile,"#endif /*GEN_SIZE_OFFSET*/\n"); } fclose(outFile); free((void *)outFilename); return(0); }