Example #1
0
static
void checkArrI(const char *pv, long elen, epicsInt32 a, epicsInt32 b, epicsInt32 c, epicsInt32 d)
{
    epicsInt32 buf[4];
    epicsInt32 expect[4];
    long nReq = NELEMENTS(buf), i;
    unsigned match;
    DBADDR addr;

    expect[0] = a;
    expect[1] = b;
    expect[2] = c;
    expect[3] = d;

    if (dbNameToAddr(pv, &addr))
        testAbort("Unknown PV '%s'", pv);

    if (dbGet(&addr, DBR_LONG, buf, NULL, &nReq, NULL))
        testAbort("Failed to get '%s'", pv);

    match = elen==nReq;
    for (i=0; i<nReq && i<elen; i++) {
        match &= buf[i]==expect[i];
    }
    testOk(match, "dbGet(\"%s\") matches", pv);
    if (elen!=nReq)
        testDiag("lengths don't match %ld != %ld", elen, nReq);
    for (i=0; i<nReq && i<elen; i++) {
        if(buf[i]!=expect[i])
            testDiag("[%ld] -> %d != %d", i, (int)expect[i], (int)buf[i]);
    }
}
Example #2
0
static
void checkArrD(const char *pv, long elen, double a, double b, double c, double d)
{
    double buf[4];
    double expect[4];
    long nReq = NELEMENTS(buf), i;
    unsigned match;
    DBADDR addr;

    expect[0] = a;
    expect[1] = b;
    expect[2] = c;
    expect[3] = d;

    if (dbNameToAddr(pv, &addr))
        testAbort("Unknown PV '%s'", pv);

    if (dbGet(&addr, DBR_DOUBLE, buf, NULL, &nReq, NULL))
        testAbort("Failed to get '%s'", pv);

    match = elen==nReq;
    for (i=0; i<nReq && i<elen; i++) {
        match &= fabs(buf[i]-expect[i])<0.01;
    }
    testOk(match, "dbGet(\"%s\") matches", pv);
    if (elen!=nReq)
        testDiag("lengths don't match %ld != %ld", elen, nReq);
    for (i=0; i<nReq && i<elen; i++) {
        if (fabs(buf[i]-expect[i])>=0.01)
            testDiag("[%ld] -> %f != %f", i, expect[i], buf[i]);
    }
}
Example #3
0
File: main.c Project: jskelcy/pa5
int main(int argc, char *argv[]){
    FILE *customerFile = fopen(argv[1], "r");
    DB *custDB = custDBBuild(customerFile);
    customer *testCust = (customer *)dbGet(custDB, 1);
    if(testCust == NULL){
        printf("this is null");
    }else{
        printf("its not");
    }
}
Example #4
0
long dbGetField(DBADDR *paddr,short dbrType,
    void *pbuffer, long *options, long *nRequest, void *pflin)
{
    dbCommon *precord = paddr->precord;
    long status = 0;

    dbScanLock(precord);
    status = dbGet(paddr, dbrType, pbuffer, options, nRequest, pflin);
    dbScanUnlock(precord);
    return status;
}
Example #5
0
long epicsShareAPI dbGetField(DBADDR *paddr,short dbrType,
    void *pbuffer, long *options, long *nRequest, void *pflin)
{
    short dbfType = paddr->field_type;
    dbCommon *precord = paddr->precord;
    long status = 0;

    dbScanLock(precord);
    if (dbfType >= DBF_INLINK && dbfType <= DBF_FWDLINK) {
        DBENTRY dbEntry;
        dbFldDes *pfldDes = paddr->pfldDes;
        char *rtnString;
        char *pbuf = (char *)pbuffer;
        int maxlen;

        if (options && (*options))
            getOptions(paddr, &pbuf, options, pflin);
        if (nRequest && *nRequest == 0) goto done;

        switch (dbrType) {
        case DBR_STRING:
            maxlen = MAX_STRING_SIZE - 1;
            if (nRequest && *nRequest > 1) *nRequest = 1;
            break;

        case DBR_CHAR:
        case DBR_UCHAR:
            if (nRequest && *nRequest > 0) {
                maxlen = *nRequest - 1;
                break;
            }
            /* else fall through ... */
        default:
            status = S_db_badDbrtype;
            goto done;
        }

        dbInitEntry(pdbbase, &dbEntry);
        status = dbFindRecord(&dbEntry, precord->name);
        if (!status) status = dbFindField(&dbEntry, pfldDes->name);
        if (!status) {
            rtnString = dbGetString(&dbEntry);
            strncpy(pbuf, rtnString, maxlen);
            pbuf[maxlen] = 0;
        }
        dbFinishEntry(&dbEntry);
    } else {
        status = dbGet(paddr, dbrType, pbuffer, options, nRequest, pflin);
    }
done:
    dbScanUnlock(precord);
    return status;
}
Example #6
0
int dbRename(const sds oldSetName, const sds newSetName)
{
    const set *oldSet = NULL;

    if (NULL == oldSetName || NULL == newSetName ||
        0 == strlen(oldSetName) || 0 == strlen(newSetName))
    {
        return -1;
    }

    if (NULL == (oldSet = dbGet(oldSetName)) ||
        NULL != dbGet(newSetName))
    {
        return -1;
    }

    lockWrite(sets);
    dictDelete(sets, oldSetName);
    dictAdd(sets, newSetName, (void *) oldSet);
    unlockWrite(sets);
    return 0;
}
Example #7
0
long epicsShareAPI dbGetPrecision(const struct link *plink,short *precision)
{
    struct buffer {
        DBRprecision
        double value;
    } buffer;
    DBADDR *paddr;
    long options = DBR_PRECISION;
    long number_elements = 0;
    long status;

    if(plink->type == CA_LINK) return(dbCaGetPrecision(plink,precision));
    if(plink->type !=DB_LINK) return(S_db_notFound);
    paddr = (DBADDR *)plink->value.pv_link.pvt;
    status = dbGet(paddr,DBR_DOUBLE,&buffer,&options,&number_elements,0);
    if(status) return(status);
    *precision = buffer.precision.dp;
    return(0);
}
Example #8
0
long epicsShareAPI dbGetUnits(
    const struct link *plink,char *units,int unitsSize)
{
    struct buffer {
        DBRunits
        double value;
    } buffer;
    DBADDR *paddr;
    long options = DBR_UNITS;
    long number_elements = 0;
    long status;

    if(plink->type == CA_LINK) return(dbCaGetUnits(plink,units,unitsSize));
    if(plink->type !=DB_LINK) return(S_db_notFound);
    paddr = (DBADDR *)plink->value.pv_link.pvt;
    status = dbGet(paddr,DBR_DOUBLE,&buffer,&options,&number_elements,0);
    if(status) return(status);
    strncpy(units,buffer.units,unitsSize);
    return(0);
}
Example #9
0
long epicsShareAPI dbGetGraphicLimits(
    const struct link *plink,double *low, double *high)
{
    struct buffer {
        DBRgrDouble
        double value;
    } buffer;
    DBADDR *paddr;
    long options = DBR_GR_DOUBLE;
    long number_elements = 0;
    long status;

    if(plink->type == CA_LINK) return(dbCaGetGraphicLimits(plink,low,high));
    if(plink->type !=DB_LINK) return(S_db_notFound);
    paddr = (DBADDR *)plink->value.pv_link.pvt;
    status = dbGet(paddr,DBR_DOUBLE,&buffer,&options,&number_elements,0);
    if(status) return(status);
    *low = buffer.lower_disp_limit;
    *high = buffer.upper_disp_limit;
    return(0);
}
Example #10
0
/* Try to parse scan period from record's SCAN field.
 * Sounds simple, but I ended up with this mess.
 * Is there a more elegant way to get this?
 * Returns <= 0 for error.
 */
static double get_period(dbCommon *rec)
{
    char          *buf = 0, *p;
    size_t        buf_size = 0, len;
    struct dbAddr scan_field;
    long          options=0, count=1;
    double        period = -1.0;

    if (rec->scan < SCAN_1ST_PERIODIC)
        return period;
    
    /* Best guess for holding SCAN field name and value */
    if (! EIP_reserve_buffer((void**)&buf, &buf_size, 50))
        return period;
    /* Get SCAN field's address */
    len = strlen (rec->name);
    if (! EIP_reserve_buffer((void**)&buf, &buf_size, len+6))
        goto leave;
    memcpy(buf, rec->name, len);
    memcpy(buf+len, ".SCAN", 6);
    if (dbNameToAddr(buf, &scan_field) != 0)
        goto leave;

    /* Get value */
    len = dbBufferSize(DBR_STRING, options, count);
    if (! EIP_reserve_buffer((void**)&buf, &buf_size, len))
        goto leave;
    if (dbGet(&scan_field, DBR_STRING, buf, &options, &count, 0) != 0)
        goto leave;
    if (! strstr(buf, "second"))
        goto leave;
    period = strtod(buf, &p);
    if (p==buf || period==HUGE_VAL || period==-HUGE_VAL)
        period = -1.0;
  leave:
    free(buf);
    return period;
}
Example #11
0
void dbChannelMakeArrayCopy(void *pvt, db_field_log *pfl, dbChannel *chan)
{
    void *p;
    struct dbCommon *prec = dbChannelRecord(chan);

    if (pfl->type != dbfl_type_rec) return;

    pfl->type = dbfl_type_ref;
    pfl->stat = prec->stat;
    pfl->sevr = prec->sevr;
    pfl->time = prec->time;
    pfl->field_type  = chan->addr.field_type;
    pfl->no_elements = chan->addr.no_elements;
    pfl->field_size  = chan->addr.field_size;
    pfl->u.r.dtor = freeArray;
    pfl->u.r.pvt = pvt;
    if (pfl->field_type == DBF_STRING && pfl->no_elements == 1) {
        p = freeListCalloc(dbchStringFreeList);
    } else {
        p = calloc(pfl->no_elements, pfl->field_size);
    }
    if (p) dbGet(&chan->addr, mapDBFToDBR[pfl->field_type], p, NULL, &pfl->no_elements, NULL);
    pfl->u.r.field = p;
}
Example #12
0
/* Only use dbChannelGet() if the record is already locked. */
long dbChannelGet(dbChannel *chan, short type, void *pbuffer,
        long *options, long *nRequest, void *pfl)
{
    return dbGet(&chan->addr, type, pbuffer, options, nRequest, pfl);
}
Example #13
0
long epicsShareAPI dbGetLinkValue(struct link *plink, short dbrType,
    void *pbuffer, long *poptions, long *pnRequest)
{
    long status = 0;

    if (plink->type == CONSTANT) {
        if (poptions) *poptions = 0;
        if (pnRequest) *pnRequest = 0;
    } else if (plink->type == DB_LINK) {
        struct pv_link *ppv_link = &(plink->value.pv_link);
        DBADDR         *paddr = ppv_link->pvt;
        dbCommon       *precord = plink->value.pv_link.precord;

        /* scan passive records with links that are process passive  */
        if (ppv_link->pvlMask&pvlOptPP) {
            dbCommon *pfrom = paddr->precord;
            unsigned char pact;

            pact = precord->pact;
            precord->pact = TRUE;
            status = dbScanPassive(precord,pfrom);
            precord->pact = pact;
            if (status) return status;
        }
        if(precord!= paddr->precord) {
            inherit_severity(ppv_link,precord,paddr->precord->stat,paddr->precord->sevr);
        }

        if (ppv_link->getCvt && ppv_link->lastGetdbrType == dbrType) {
            status = ppv_link->getCvt(paddr->pfield, pbuffer, paddr);
        } else {
            unsigned short dbfType = paddr->field_type;
            long       no_elements = paddr->no_elements;

            if (dbrType < 0 || dbrType > DBR_ENUM ||
                dbfType > DBF_DEVICE) {
                status = S_db_badDbrtype;
                recGblRecordError(status, precord, "GetLinkValue Failed");
                recGblSetSevr(precord, LINK_ALARM, INVALID_ALARM);
                return status;
            }
            /*  attempt to make a fast link */
            if ((!poptions || *poptions == 0) &&
                no_elements == 1 &&
                (!pnRequest || *pnRequest == 1) &&
                paddr->special != SPC_ATTRIBUTE) {
                ppv_link->getCvt = dbFastGetConvertRoutine[dbfType][dbrType];
                status = ppv_link->getCvt(paddr->pfield, pbuffer, paddr);
            } else {
                ppv_link->getCvt = 0;
                status = dbGet(paddr, dbrType, pbuffer, poptions, pnRequest, NULL);
            }
        }
        ppv_link->lastGetdbrType = dbrType;
        if (status) {
            recGblRecordError(status, precord, "dbGetLinkValue");
            recGblSetSevr(precord, LINK_ALARM, INVALID_ALARM);
        }
    } else if (plink->type == CA_LINK) {
        struct dbCommon *precord = plink->value.pv_link.precord;
        const struct pv_link *pcalink = &plink->value.pv_link;
        epicsEnum16 sevr, stat;

        status=dbCaGetLink(plink,dbrType,pbuffer,&stat,&sevr,pnRequest);
        if (status) {
            recGblSetSevr(precord, LINK_ALARM, INVALID_ALARM);
        } else {
            inherit_severity(pcalink,precord,stat,sevr);
        }
        if (poptions) *poptions = 0;
    } else {
        cantProceed("dbGetLinkValue: Illegal link type");
    }
    return status;
}
Example #14
0
static void callbackSiWriteRead(asynUser *pasynUser)
{
    devPvt         *pdevPvt = (devPvt *)pasynUser->userPvt;
    stringinRecord *precord = (stringinRecord *)pdevPvt->precord;
    asynStatus     status;
    size_t         nBytesRead;
    long           dbStatus;
    char           raw[MAX_STRING_SIZE];
    char           translate[MAX_STRING_SIZE];
    size_t         len = sizeof(precord->val);

    status = pasynManager->unblockProcessCallback(pasynUser,pdevPvt->blockAll);
    if(status!=asynSuccess) {
        asynPrint(pasynUser,ASYN_TRACE_ERROR,
            "%s pasynManager:unblockProcessCallback failed %s\n",
            precord->name,pasynUser->errorMessage);
        recGblSetSevr(precord,READ_ALARM,INVALID_ALARM);
        goto done;
    }
    switch(pdevPvt->state) {
    case stateIdle:
        dbStatus = dbGet(&pdevPvt->dbAddr,DBR_STRING,raw,0,0,0);
        if(dbStatus) {
            asynPrint(pasynUser,ASYN_TRACE_ERROR,
                "%s dbGet failed\n",precord->name);
            recGblSetSevr(precord,READ_ALARM,INVALID_ALARM);
            goto done;
        }
        dbTranslateEscape(translate,raw);
        status = writeIt(pasynUser,translate,strlen(translate));
        if(status!=asynSuccess) {
            asynPrint(pasynUser,ASYN_TRACE_ERROR,
                "%s asynOctet:write failed %s\n",
                precord->name,pasynUser->errorMessage);
            recGblSetSevr(precord,READ_ALARM,INVALID_ALARM);
            goto done;
        }
        pdevPvt->state = stateWrite;
        status = queueIt(pdevPvt);
        if(status!=asynSuccess) goto done;
        return;
    case stateWrite:
        status = readIt(pasynUser,precord->val,len,&nBytesRead);
        if(status!=asynSuccess) {
            asynPrint(pasynUser,ASYN_TRACE_ERROR,
                "%s asynOctet:write failed %s\n",
                precord->name,pasynUser->errorMessage);
            recGblSetSevr(precord,READ_ALARM,INVALID_ALARM);
            goto done;
        }
        if(status==asynSuccess) {
            if(nBytesRead==len) nBytesRead--;
            precord->val[nBytesRead] = 0;
        }
        pdevPvt->state = stateIdle;
        break; /*all done*/
    }
done:
    pdevPvt->state = stateIdle;
    callbackRequestProcessCallback(
        &pdevPvt->processCallback,precord->prio,precord);
}
Example #15
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);
}