示例#1
0
bool send_address(uint8_t address, uint8_t write)
{
    int c = 0;
begin:
    uart_send("START");
    // Set the START flag
    
    SEND_AND_WAIT(1, 1 << TWSTA);
    
    if (TW_STATUS != TW_START && TW_STATUS != TW_REP_START) {
        DUMP_ERROR();
        return false;
    }
    
    if (write == TW_WRITE) {
        uart_send("SLA+W");
    } else {
        uart_send("SLA+R");
    }
    
    // Write the address + write byte
    TWDR = (address << 1) | write;
    SEND_AND_WAIT(1, 0);
    
    uint8_t ack;
    uint8_t nack;
    if (write == TW_WRITE) {
        ack = TW_MT_SLA_ACK;
        nack = TW_MT_SLA_NACK;
    } else {
        ack = TW_MR_SLA_ACK;
        nack = TW_MR_SLA_NACK;
    }
    
    if (TW_STATUS == nack) {
        c++;
        if (c > 3) {
            DUMP_ERROR();
            return false;
        } else {
            goto begin;
        }
    } else if (TW_STATUS != ack) {
        DUMP_ERROR();
        return false;
    }
    
    return true;
}
示例#2
0
bool twi_get(uint8_t address, uint8_t* data)
{
    if (!send_address(address, TW_WRITE)) {
        uart_send("Send address failed");
        return false;
    }
    
    uart_send("Send GET");
    
    // Send a GET packet
    TWDR = 1;
    SEND_AND_WAIT(1, 0);
    
    if (TW_STATUS != TW_MT_DATA_ACK) {
        DUMP_ERROR();
        return false;
    }
    
    uart_send("Switch to MR");
    if (!send_address(address, TW_READ)) {
        uart_send("MR send_address failed");
        STOP();
        return false;
    }
    
    SEND_AND_WAIT(0, 0);
    
    if (TW_STATUS != TW_MR_DATA_ACK && TW_STATUS != TW_MR_DATA_NACK) {
        DUMP_ERROR();
        return false;
    }
    
    uart_send("Read packet");
    // Read the data packet
    *data = TWDR;
    
    char val[20];
    sprintf(val, "--read = %x", *data);
    uart_send(val);
    
    STOP();
    
    return true;
}
示例#3
0
int
auks_cred_repo_load_cache(auks_cred_repo_t * cr)
{
    int fstatus = AUKS_ERROR;

    unsigned int loaded_ccache = 0;

    char str_error[STR_ERROR_SIZE];

    char *cachedir;

    DIR *dir;
    struct dirent entry;
    struct dirent *cookie;

    char filename[AUKS_CRED_FILE_MAX_LENGTH + 1];
    size_t filename_maxlength = AUKS_CRED_FILE_MAX_LENGTH;

    auks_cred_t cred;

    cachedir = cr->cachedir;

    /* cache dir validity check */
    if (cachedir == NULL) {
        auks_log2("load : no cache directory defined in this repo");
        fstatus = AUKS_ERROR_CRED_REPO_CACHEDIR_IS_NULL;
        goto exit;
    }

    /* open cache directory */
    dir = opendir(cachedir);
    if (dir == NULL) {
        DUMP_ERROR(errno, str_error, STR_ERROR_SIZE);
        auks_log2("load : unable to open cache directory %s : %s",
                  cachedir, str_error);
        fstatus = AUKS_ERROR_CRED_REPO_CACHEDIR_OPEN;
        goto exit;
    }

    while (1) {

        /* lookup */
        fstatus = readdir_r(dir, &entry, &cookie);
        if (fstatus != 0) {
            DUMP_ERROR(errno, str_error,
                       STR_ERROR_SIZE);
            auks_log2("load : an error occured while processing"
                      " cache directory : %s",str_error);
            break;
        } else if (fstatus == 0 && cookie == NULL) {
            /* no more entry to process */
            auks_log3("load : no more entry to process in cache "
                      "directory");
            break;
        }

        /* look for auks cred cache patterned file */
        if (fnmatch(AUKS_CRED_CACHE_FILE_MOTIF,entry.d_name,
                    FNM_PATHNAME | FNM_PERIOD) != 0 ) {
            auks_log3("load : '%s' is not an auks cred cache",
                      entry.d_name);
            continue;
        }
        auks_log3("load : entry %s is an auks cred cache",entry.d_name);

        /* build auks cred cache filename */
        fstatus = snprintf(filename,filename_maxlength,"%s/%s",
                           cr->cachedir,entry.d_name);
        if ( fstatus >= filename_maxlength || fstatus < 0) {
            auks_log2("load : unable to build auks cred"
                      " cache filename");
            continue;
        }

        /* init auks cred from file */
        fstatus = auks_cred_extract(&cred,filename);
        if (fstatus) {
            auks_log2("load : unable to init auks cred from"
                      " auks cache '%s'",filename);
            goto cred_loop;
        }
        auks_log3("load : auks cred successfully initialized from auks "
                  "cache '%s'",filename);

        /* add auks cred to repo */
        fstatus = auks_cred_repo_add(cr,&cred);
        if (fstatus) {
            auks_log2("load : unable to add cred from auks cache"
                      " '%s' to the tree : %s",
                      filename,auks_strerror(fstatus));
        } else {
            auks_log3("load : auks cred cache '%s' successfully"
                      " loaded",filename);
            loaded_ccache += 1;
        }

        auks_cred_free_contents(&cred);

cred_loop:
        memset(filename,'\0',filename_maxlength);

        continue;
    }

    auks_log("%u cred(s) loaded from cachedir %s",loaded_ccache,cachedir);
    fstatus = AUKS_SUCCESS;

    closedir(dir);

exit:
    return fstatus;
}
CameraManager::CameraManager()
{
    Json::Value root;
    Json::Reader reader;
    std::string fileContents;
    
    if (!readFile(&fileContents, FILE_NAME))
    {
        DUMP_ERROR("Could not open file.");
        exit(0);
    }
    
    if (!reader.parse(fileContents, root))
    {
        DUMP_ERROR("Error Parsing file.");
        exit(0);
    }
    
    float h = CGKAppGetScreenHeight();
    float w = CGKAppGetScreenWidth();
    float asp = w/h;
    
    for (int i = 0; i < root.size(); i++)
    {
        CGKOpenGLCamera* cam = new CGKOpenGLCamera();
        
        if (!cam)
        {
            DUMP_ERROR("could not allocate [cam]");
            exit(0);
        }
        
        CGKVector3f eye;
        CGKVector3f focus;
        CGKVector3f up;
        
        eye[0] = root[i]["eye"][0].asFloat();
        eye[1] = root[i]["eye"][1].asFloat();
        eye[2] = root[i]["eye"][2].asFloat();

        focus[0] = root[i]["focus"][0].asFloat();
        focus[1] = root[i]["focus"][1].asFloat();
        focus[2] = root[i]["focus"][2].asFloat();

        up[0] = root[i]["up"][0].asFloat();
        up[1] = root[i]["up"][1].asFloat();
        up[2] = root[i]["up"][2].asFloat();
        
        float fovy = M_PI/180.0*root[i]["fovy"].asFloat();
        float near = root[i]["near"].asFloat();
        float far = root[i]["far"].asFloat();
        
        cam->SetView(eye, focus, up);
        cam->SetPerspective(fovy, asp, near, far);
        
        int id = root[i]["id"].asInt();
        
        this->cameras[id] = cam;
    }
    
    // set main camera
    if (this->cameras.size())
    {
        this->mainCamera = this->cameras.begin()->second;
    }
    else
    {
        this->mainCamera = new CGKOpenGLCamera();
    }
}
示例#5
0
int
auks_cred_repo_remove_nolock(auks_cred_repo_t * cr, uid_t uid)
{
    int fstatus = AUKS_ERROR;

    char str_error[STR_ERROR_SIZE];
    str_error[0] = '\0';

    char uid_str[UID_STR_LENGTH];

    char filename[AUKS_CRED_FILE_MAX_LENGTH + 1];

    /* if not in read-only mode, */
    /* try to unlink corresponding auks cred cache */
    if (cr->read_only) {
        auks_log3("remove : read-only mode, skipping");
        fstatus = AUKS_ERROR_CRED_REPO_READONLY ;
        goto exit;
    }

    /* set reference value */
    if ( snprintf(uid_str, UID_STR_LENGTH, "%u", uid) >= UID_STR_LENGTH ) {
        auks_log2("add : unable to build uid='%u' str representation",
                  uid);
        fstatus = AUKS_ERROR_LIBRARY_UID_TO_STR;
        goto exit;
    }


    /* try to remove cred from library */
    fstatus = xlibrary_remove_item(&(cr->library), uid_str);
    if (fstatus) {
        auks_log2("remove : unable to remove '%u' cred "
                  "from the library",uid);
        fstatus = AUKS_ERROR_LIBRARY_UID_NOT_FOUND;
    } else {
        auks_log3("remove : '%u' cred successfully removed "
                  "from the library",uid);
        fstatus = AUKS_SUCCESS;
    }

    if (fstatus != AUKS_SUCCESS)
        goto exit;

    /* build auks cred cache file name */
    fstatus = auks_cred_repo_auks_credfile(cr,uid,filename,
                                           AUKS_CRED_FILE_MAX_LENGTH);
    if ( fstatus !=AUKS_SUCCESS )
        goto exit;
    auks_log3("remove : '%d' auks cred cache is '%s'",uid, filename);

    /* unlink auks cred cache */
    fstatus = unlink(filename);
    if (fstatus) {
        DUMP_ERROR(errno,str_error,STR_ERROR_SIZE);
        auks_log2("remove : unable to unlink '%d' auks cred "
                  "cache '%s' : %s",uid, filename, str_error);
        fstatus = AUKS_ERROR_CRED_REPO_UNLINK ;
    } else {
        auks_log3("remove : '%d' auks cred cache '%s' successfully "
                  "removed from cache directory",uid, filename);
        fstatus = AUKS_SUCCESS ;
    }

exit:
    return fstatus;
}