static svn_error_t * test_entries_alloc(apr_pool_t *pool) { svn_wc__db_t *db; const char *local_abspath; svn_wc_adm_access_t *adm_access; apr_hash_t *entries; const svn_wc_entry_t *entry; const char *local_relpath; #undef WC_NAME #define WC_NAME "test_entries_alloc" SVN_ERR(create_open(&db, &local_abspath, WC_NAME, pool)); SVN_ERR(svn_wc_adm_open3(&adm_access, NULL /* associated */, svn_dirent_join("fake-wc", WC_NAME, pool), FALSE /* write_lock */, 0 /* levels_to_lock */, NULL /* cancel_func */, NULL /* cancel_baton */, pool)); SVN_ERR(svn_wc_entries_read(&entries, adm_access, TRUE /* show_hidden */, pool)); /* The wcroot has 12 BASE children + 1 WORKING child + "this dir". */ SVN_TEST_ASSERT(apr_hash_count(entries) == 14); /* The "D" entry in the entries hash should be what we get from the svn_wc_entry() entrypoint. */ local_relpath = svn_dirent_join_many(pool, "fake-wc", WC_NAME, "D", NULL); SVN_ERR(svn_wc_entry(&entry, local_relpath, adm_access, TRUE, pool)); SVN_TEST_ASSERT(entry == apr_hash_get(entries, "D", APR_HASH_KEY_STRING)); /* This entry should be missing. */ SVN_ERR(svn_wc_entry(&entry, "missing", adm_access, TRUE, pool)); SVN_TEST_ASSERT(entry == NULL); return SVN_NO_ERROR; }
static svn_error_t * test_access_baton_like_locking(apr_pool_t *pool) { svn_wc__db_t *db; svn_wc_context_t *wc_ctx, *wc_ctx2; const char *local_abspath; const char *D, *D1, *D2, *D3, *D4; svn_boolean_t locked_here, locked; svn_error_t *err; svn_wc_adm_access_t *adm_access, *subdir_access; #undef WC_NAME #define WC_NAME "test_access_batons" SVN_ERR(create_open(&db, &local_abspath, WC_NAME, pool)); D = svn_dirent_join(local_abspath, "DD", pool); D1 = svn_dirent_join(D, "DD", pool); D2 = svn_dirent_join(D1, "DD", pool); D3 = svn_dirent_join(D2, "DD", pool); D4 = svn_dirent_join(D3, "DD", pool); SVN_ERR(svn_io_make_dir_recursively(D4, pool)); /* Use the legacy interface */ SVN_ERR(svn_wc_adm_open3(&adm_access, NULL, local_abspath, TRUE, 0, NULL, NULL, pool)); SVN_ERR(svn_wc_add3(D, adm_access, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_adm_retrieve(&subdir_access, adm_access, D, pool)); SVN_ERR(svn_wc_add3(D1, subdir_access, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_adm_retrieve(&subdir_access, adm_access, D1, pool)); SVN_ERR(svn_wc_add3(D2, subdir_access, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_adm_retrieve(&subdir_access, adm_access, D2, pool)); SVN_ERR(svn_wc_add3(D3, subdir_access, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_add3(D4, subdir_access, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_locked(&locked, D3, pool)); SVN_TEST_ASSERT(locked); SVN_ERR(svn_wc_locked(&locked, D4, pool)); SVN_TEST_ASSERT(locked); SVN_ERR(svn_wc_delete3(D4, subdir_access, NULL, NULL, NULL, NULL, FALSE, pool)); SVN_ERR(svn_wc_locked(&locked, D4, pool)); SVN_TEST_ASSERT(!locked); SVN_ERR(svn_wc_revert3(D, adm_access, svn_depth_infinity, FALSE, NULL, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_locked(&locked, D3, pool)); SVN_TEST_ASSERT(!locked); SVN_ERR(svn_wc_locked(&locked, local_abspath, pool)); SVN_TEST_ASSERT(locked); SVN_ERR(svn_wc_adm_close2(adm_access, pool)); SVN_ERR(svn_wc_context_create(&wc_ctx, NULL, pool, pool)); /* Obtain a lock for the root, which is extended on each level */ SVN_ERR(svn_wc__db_wclock_obtain(wc_ctx->db, local_abspath, 0, FALSE, pool)); SVN_ERR(svn_io_make_dir_recursively(D4, pool)); SVN_ERR(svn_wc_add4(wc_ctx, D, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_add4(wc_ctx, D1, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_add4(wc_ctx, D2, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_add4(wc_ctx, D3, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx, D3, pool)); SVN_TEST_ASSERT(locked_here && locked); /* Test if the not added path is already locked */ SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx, D4, pool)); SVN_TEST_ASSERT(!locked_here && !locked); SVN_ERR(svn_wc_add4(wc_ctx, D4, svn_depth_infinity, NULL, SVN_INVALID_REVNUM, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx, D4, pool)); SVN_TEST_ASSERT(locked_here && locked); SVN_ERR(svn_wc__db_wclock_release(wc_ctx->db, local_abspath, pool)); /* Should be unlocked */ SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx, local_abspath, pool)); SVN_TEST_ASSERT(!locked_here && !locked); /* Lock shouldn't be released */ SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx, D, pool)); SVN_TEST_ASSERT(locked_here && locked); SVN_ERR(svn_wc__db_wclock_release(wc_ctx->db, D, pool)); SVN_ERR(svn_wc__db_wclock_release(wc_ctx->db, D1, pool)); SVN_ERR(svn_wc__db_wclock_release(wc_ctx->db, D2, pool)); SVN_ERR(svn_wc__db_wclock_release(wc_ctx->db, D3, pool)); /* Try reobtaining lock on D3; should succeed */ SVN_ERR(svn_wc__db_wclock_obtain(wc_ctx->db, D3, 0, FALSE, pool)); SVN_ERR(svn_wc__db_wclock_release(wc_ctx->db, D4, pool)); /* D3 should still be locked; try stealing in a different context */ SVN_ERR(svn_wc_context_create(&wc_ctx2, NULL, pool, pool)); SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx2, D3, pool)); SVN_TEST_ASSERT(!locked_here && locked); err = svn_wc__db_wclock_obtain(wc_ctx2->db, D3, 0, FALSE, pool); if (err && err->apr_err != SVN_ERR_WC_LOCKED) return svn_error_trace(err); svn_error_clear(err); SVN_TEST_ASSERT(err != NULL); /* Can't lock, as it is still locked */ err = svn_wc__db_wclock_release(wc_ctx2->db, D4, pool); if (err && err->apr_err != SVN_ERR_WC_NOT_LOCKED) return svn_error_trace(err); svn_error_clear(err); SVN_TEST_ASSERT(err != NULL); /* Can't unlock, as it is not ours */ /* Now steal the lock */ SVN_ERR(svn_wc__db_wclock_obtain(wc_ctx2->db, D3, 0, TRUE, pool)); /* We should own the lock now */ SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx2, D3, pool)); SVN_TEST_ASSERT(locked_here && locked); err = svn_wc__db_wclock_release(wc_ctx2->db, D4, pool); if (err && err->apr_err != SVN_ERR_WC_NOT_LOCKED) return svn_error_trace(err); svn_error_clear(err); SVN_TEST_ASSERT(err != NULL); /* Can't unlock a not locked path */ /* Now create a separate working copy from the same repository directly below this WC and test if our code really sees it as a separate wc, for locking and normal operation */ { const char *url, *repos_root_url, *repos_uuid; const char *subdir = svn_dirent_join(local_abspath, "sub-wc", pool); svn_boolean_t is_root; SVN_ERR(svn_wc__node_get_url(&url, wc_ctx, local_abspath, pool, pool)); SVN_ERR(svn_wc__node_get_repos_info(&repos_root_url, &repos_uuid, wc_ctx, local_abspath, pool, pool)); SVN_ERR(svn_io_make_dir_recursively(subdir, pool)); SVN_ERR(svn_wc_ensure_adm3(subdir, repos_uuid, svn_path_url_add_component2(url, "sub-wc", pool), repos_root_url, 0, svn_depth_infinity, pool)); SVN_ERR(svn_wc__check_wc_root(&is_root, NULL, NULL, wc_ctx->db, subdir, pool)); SVN_TEST_ASSERT(is_root); SVN_ERR(svn_wc__check_wc_root(&is_root, NULL, NULL, wc_ctx2->db, subdir, pool)); /* This test was added to show a regression where the next check failed, but the check above this succeeded */ SVN_TEST_ASSERT(is_root); SVN_ERR(svn_wc_locked2(&locked_here, &locked, wc_ctx2, subdir, pool)); SVN_TEST_ASSERT(!locked_here && !locked); } return SVN_NO_ERROR; }
static svn_error_t * test_stubs(apr_pool_t *pool) { svn_wc__db_t *db; const char *local_abspath; const char *local_relpath; svn_wc_adm_access_t *adm_access; svn_wc_adm_access_t *subdir_access; const svn_wc_entry_t *stub_entry; const svn_wc_entry_t *entry; const svn_wc_entry_t *test_entry; apr_hash_t *entries; #undef WC_NAME #define WC_NAME "test_stubs" SVN_ERR(create_open(&db, &local_abspath, WC_NAME, pool)); /* The "M" entry is a subdir. Let's ensure we can reach its stub, and the actual contents. */ local_relpath = svn_dirent_join_many(pool, "fake-wc", WC_NAME, "M", NULL); SVN_ERR(svn_wc_adm_open3(&adm_access, NULL /* associated */, svn_dirent_join("fake-wc", WC_NAME, pool), FALSE /* write_lock */, 0 /* levels_to_lock */, NULL /* cancel_func */, NULL /* cancel_baton */, pool)); /* Ensure we get the stub. NOTE: do this before we have associated the subdir baton with ADM_ACCESS. */ SVN_ERR(svn_wc_entry(&stub_entry, local_relpath, adm_access, TRUE, pool)); SVN_TEST_STRING_ASSERT(stub_entry->name, "M"); SVN_ERR(svn_wc_adm_open3(&subdir_access, adm_access, local_relpath, FALSE /* write_lock */, 0 /* levels_to_lock */, NULL /* cancel_func */, NULL /* cancel_baton */, pool)); /* Ensure we get the real entry. */ SVN_ERR(svn_wc_entry(&entry, local_relpath, subdir_access, TRUE, pool)); SVN_TEST_STRING_ASSERT(entry->name, ""); /* Ensure that we get the SAME entry, even using the parent baton. */ SVN_ERR(svn_wc_entry(&test_entry, local_relpath, adm_access, TRUE, pool)); SVN_TEST_ASSERT(test_entry == entry); /* Ensure we get the stub when reading entries with ADM_ACCESS. */ SVN_ERR(svn_wc_entries_read(&entries, adm_access, TRUE /* show_hidden */, pool)); SVN_TEST_ASSERT(stub_entry == apr_hash_get(entries, "M", APR_HASH_KEY_STRING)); /* Ensure we get the real entry when reading entries with SUBDIR_ACCESS. */ SVN_ERR(svn_wc_entries_read(&entries, subdir_access, TRUE /* show_hidden */, pool)); SVN_TEST_ASSERT(entry == apr_hash_get(entries, "", APR_HASH_KEY_STRING)); return SVN_NO_ERROR; }
int main(int argc, const char **argv) { printf("entered program\n"); /* allocate device objects */ c = create_create("/dev/ttyS2"); r = turret_create(); /* open the create serial comm */ if(create_open(c,FULLCONTROL) < 0) { printf("create open failed\n"); return(-1); } /* Open the i2c device */ if(turret_open(r) < 0) { printf("failed to connect to robostix\n"); return(-1); } /* init the robostix board interfaces */ printf("initialize turret\n"); turret_init(r); // sonar if(!WHICH_SENSOR){ turret_SetServo(r,90); } //ir else{ turret_SetServo(r,0); } filter = firFilterCreate(); waypoints[0].x = 7.3; waypoints[0].y = 0.0; waypoints[1].x = 7.3; waypoints[1].y = 7.62; waypoints[2].x = 26.19; waypoints[2].y = 7.62; waypoints[3].x = 26.19; waypoints[3].y = -3.04; waypoints[4].x = 30.15; waypoints[4].y = -3.04; waypoints[5].x = 30.15; waypoints[5].y = -12.18; waypoints[6].x = 7.3; waypoints[6].y = -12.18; waypoints[7].x = 7.3; waypoints[7].y = 0.0; waypoints[8].x = 0.0; waypoints[8].y = 0.0; int i; for(i = 0; i < 9; i++) { Move(c, r, waypoints, i); } /* // read points from file FILE *file = fopen(argv[1], "r"); printf("just read file\n"); if(file != NULL) { char line[32]; char num_lines; // read the first line in the file. // this gives the number of waypoints printf("fgetting line nums\n"); fgets(num_lines, 1, file); num_waypoints = atoi(num_lines); printf("allocating waypoint size\n"); // allocate the size of *waypoints waypoints = malloc(num_waypoints * sizeof(waypoint)); printf("malloc'd\n"); // store the (x,y) coordinates in *waypoints int i = 0; printf("fgetting lines\n"); while(fgets(line,sizeof(line),file) != NULL) { printf("foo\n"); file_tokens = strtok(line, ","); printf("bar\n"); waypoints[i].x = atof(file_tokens[0]); printf("freep\n"); waypoints[i].y = atof(file_tokens[1]); printf("froop\n"); i++; } fclose(file); // Move to each waypoint int j; for(j = 0; j < num_waypoints; j++) { Move(c, r, waypoints[j], j); } } else { perror(argv[1]); }*/ // Shutdown and tidy up create_set_speeds(c,0.0,0.0); create_close(c); create_destroy(c); turret_close(r); turret_destroy(r); exit(0); return 0; }
int main(int argc, const char **argv) { int i, a; double t; int i2c_fd; coordData_t * waypoints; int numWaypts = NUM_WAYPOINTS; double w[] = WAYPOINT_ARRAY; pthread_t thread; //Set signals to handle signal(SIGINT, &sighandle); signal(SIGTERM, &sighandle); signal(SIGABRT, &sighandle); //allocate structs if((hands = malloc(sizeof(api_HANDLES_t))) == NULL) { fprintf(stderr,"Error calling malloc\n"); return -1; } if((filt = malloc(sizeof(FilterHandles_t))) == NULL) { fprintf(stderr,"Error calling malloc\n"); return -1; } if((pids = malloc(sizeof(pidHandles_t))) == NULL) { fprintf(stderr,"Error calling malloc\n"); return -1; } if((waypoints = malloc(sizeof(coordData_t) * numWaypts)) == NULL) { fprintf(stderr,"Error calling malloc\n"); return -1; } if((posData = malloc(sizeof(roboPos_t))) == NULL) { fprintf(stderr,"Error calling malloc\n"); return -1; } for(i=0; i<numWaypts; i++) { waypoints[i].X = w[i*2]; waypoints[i].Y = w[i*2+1]; } // allocate devices if((hands->c = create_create(COMPORT)) == NULL) { fprintf(stderr,"Error connecting create\n"); return -1; } if((hands->t = turret_create()) == NULL) { fprintf(stderr,"Error connecting turrett\n"); return -1; } //open serial com port if(create_open(hands->c, FULLCONTROL) < 0) { fprintf(stderr,"Failed to open create\n"); return -1; } //open i2c device if(turret_open(hands->t) < 0) { fprintf(stderr,"Failed to connect to robostix\n"); return -1; } //initialize the robostix board turret_init(hands->t); //Initialize Filter structs filt->sonar0 = initializeFilter(FILT_SONAR); filt->sonar1 = initializeFilter(FILT_SONAR); filt->ir0 = initializeFilter(FILT_IR); filt->ir1 = initializeFilter(FILT_IR); //Initialize PID structs pids->trans = initializePID(TRANS_PID); pids->angle = initializePID(ANGLE_PID); pids->sonar = initializePID(SONAR_PID); pids->angleT = initializePID(ANGLET_PID); // process command line args i = 1; while( i < argc ) { if(!strcmp(argv[i], "-w")) { //Accept command line waypoints if(argc >= i+1) { numWaypts = atoi(argv[++i]); if(argc >= i+(2*numWaypts)) { free(waypoints); if((waypoints = malloc(sizeof(coordData_t) * numWaypts)) == NULL) { fprintf(stderr,"Error calling malloc\n"); return -1; } for(a=0; a<numWaypts; a++) { waypoints[a].X = atoi(argv[++i]); waypoints[a].Y = atoi(argv[++i]); } i++; } else { printf("Error using [-w].\n\tUsage: -w numPoints X1 Y1 X2 Y2...\n"); } } else { printf("Error using [-w].\n\tUsage: -w numPoints X1 Y1 X2 Y2...\n"); } } else { printf("Unrecognized option [%s]\n",argv[i]); return -1; } } //Create thread to monitor robot movement pthread_create(&thread, NULL, mapRobot, (void *)hands); // robot is ready #ifdef DEBUG printf("All connections established, ready to go\n"); #endif //Rotate the Servo turret_SetServo(hands->t, T_ANGLE); for(i=0; i<FILT_IR_SAMPLES; i++) { filterIR(hands, filt, &t, &t); #ifndef USE_IR_MODE filterSonar(hands, filt, &t, &t); #endif } //Iterate over all of the waypoints for(i=0; i<numWaypts; i++) { #ifdef DEBUG printf("Waypoint %d (%f,%f).\n",i+1,waypoints[i].X,waypoints[i].Y); #endif Move(hands,filt,pids,waypoints[i].X,waypoints[i].Y); #ifdef DEBUG printf("\nArrived at waypoint %d (%f,%f).\n\n", i+1,waypoints[i].X,waypoints[i].Y); #endif } // Shutdown and tidy up. Close all of the proxy handles cleanup(); return 0; }
int main(int argc,char **argv) { turret_comm_t *r; create_comm_t *c; int i2c_fd; int command; int i,angle; double vx,va; char ch; /* allocate device objects */ c = create_create("/dev/ttyS2"); r = turret_create(); /* open the create serial comm */ if(create_open(c,FULLCONTROL) < 0) { printf("create open failed\n"); return(-1); } /* Open the i2c device */ if(turret_open(r) < 0) { printf("failed to connect to robostix\n"); return(-1); } /* init the robostix board interfaces */ turret_init(r); /* robot is set up and ready -- select tests and run */ for(command = show_menu(); command != 0; command = show_menu() ) switch(command) { case TEST_SONAR: printf("testing Sonars, next 500 readings\n"); for(i=0;i<5;i++) { if((!turret_get_sonar(r))) printf("sensor read timeout\n"); else printf("%d\t%d\n",r->sonar[0],r->sonar[1]); } break; case TEST_IR: printf("testing IR, next 5 readings\n"); for(i=0;i<5;i++) { if(!turret_get_ir(r)) printf("sensor read timeout\n"); else printf("%d\t%d\n",r->ir[0],r->ir[1]); } break; case TEST_TURRET: printf("testing Servo\nEnter angle: "); for(angle == 0;(angle <180) | (angle >180); scanf("%d",&angle)) { printf("setting servo to %d degrees\n",angle); turret_SetServo(r,angle); } break; case TEST_MOVE: printf("i- speed up\nn-slow down\nk- angle right\nj - angle left\n, x- stop\n"); vx=0.;va=0.; for( ch=getchar(); ch != 'x'; ch=getchar()) { switch(ch) { case 'i': vx += INCREMENT; break; case 'n': vx -= INCREMENT; break; case 'j': va += INCREMENT; break; case 'k': va -= INCREMENT; break; case 'x': va = 0.; vx = 0.; break; default: break; } if(vx > 1.) vx = 1.; if(va > 1.) va = 1.; create_set_speeds(c,vx,va); } break; default: command = -1; break; } }