static void add_segment_cache (gpointer key, gpointer value, gpointer user) { IntersectionState * s = user; RndfOverlayWaypoint * w = value; if (!s->segments_stopline) { s->segments_stopline = g_array_new (FALSE, FALSE, sizeof (SegmentCache)); s->segments_no_stop = g_array_new (FALSE, FALSE, sizeof (SegmentCache)); double ll[2] = { w->waypoint->lat, w->waypoint->lon }; gps_linearize_init (&s->gpslin, ll); } GArray * list = s->segments_no_stop; if (w->is_stop) list = s->segments_stopline; for (int i = 0; i < w->num_exits; i++) add_segment (s, w, w->exits[i], list); if (w->type == RNDF_POINT_WAYPOINT && w->next) add_segment (s, w, w->next, list); }
void move_to_pole(int count) { init_path(); switch (count) { case 1: add_segment(22, 180, 30); add_segment(0, 90, 30); add_segment(20, 0, 100); break; case 2: add_segment(-7, 0, 50); add_segment(0, -160, 30); add_segment(50, 0, 100); break; case 3: add_segment(0, -90, 30); add_segment(15, 0, 60); add_segment(0, -90, 30); add_segment(45, 0, 80); break; } stop_path(); dead_reckon(); }
int image_mips_load(int argc, char **argv, const char *buf, off_t len, struct kexec_info *info) { unsigned long base, offset, offset_args; char *command_line; int opt; static const struct option options[] = { KEXEC_ARCH_OPTIONS {"command-line", 1, 0, OPT_APPEND}, {"append", 1, 0, OPT_APPEND}, {0, 0, 0, 0}, }; static const char short_options[] = KEXEC_ARCH_OPT_STR "d"; command_line = NULL; while ((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) { switch (opt) { default: /* Ignore core options */ if (opt < OPT_ARCH_MAX) { break; } case '?': usage(); return -1; case OPT_APPEND: command_line = optarg; break; } } /* * Default image load address, 1MB. This is what we use on * the Octeon targets anyway. Probably be better to have this * come in through a command line arg. * The kernel boot args are put in a page just below the kernel * start address. Again, could be set at load time on the * command line. */ offset = 0x100000; offset_args = offset - 8192; /* Load image binary blob */ base = locate_hole(info, offset+len, 0, 0, ULONG_MAX, INT_MAX); if (base == ULONG_MAX) return -1; add_segment(info, buf, len, base + offset, len); if (command_line) { image_mips_parseargs(command_line); image_mips_fixupargs(offset_args); add_segment(info, &image_args, sizeof(image_args), base + offset_args, sizeof(image_args)); } info->entry = (void *) offset; return 0; }
void cmtp_dump(int level, struct frame *frm) { struct frame *msg; uint8_t hdr, bid; uint16_t len; while (frm->len > 0) { hdr = p_get_u8(frm); bid = (hdr & 0x3c) >> 2; switch ((hdr & 0xc0) >> 6) { case 0x01: len = p_get_u8(frm); break; case 0x02: len = htons(p_get_u16(frm)); break; default: len = 0; break; } p_indent(level, frm); printf("CMTP: %s: id %d len %d\n", bst2str(hdr & 0x03), bid, len); switch (hdr & 0x03) { case 0x00: add_segment(bid, frm, len); msg = get_segment(bid, frm); if (!msg) break; if (!p_filter(FILT_CAPI)) capi_dump(level + 1, msg); else raw_dump(level, msg); free_segment(bid, frm); break; case 0x01: add_segment(bid, frm, len); break; default: free_segment(bid, frm); break; } frm->ptr += len; frm->len -= len; } }
static void add_case_ctl_segment (struct transform *tf, enum case_ctl_type ctl) { struct replace_segm *segm = add_segment (tf); segm->type = segm_case_ctl; segm->v.ctl = ctl; }
bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time, double tissue_tolerance, struct gasmix *gasmix, int po2, double surface_pressure) { bool clear_to_ascend = true; char *trial_cache = NULL; cache_deco_state(tissue_tolerance, &trial_cache); while (trial_depth > stoplevel) { int deltad = ascent_velocity(trial_depth, avg_depth, bottom_time) * TIMESTEP; if (deltad > trial_depth) /* don't test against depth above surface */ deltad = trial_depth; tissue_tolerance = add_segment(depth_to_mbar(trial_depth, &displayed_dive) / 1000.0, gasmix, TIMESTEP, po2, &displayed_dive, prefs.decosac); if (deco_allowed_depth(tissue_tolerance, surface_pressure, &displayed_dive, 1) > trial_depth - deltad) { /* We should have stopped */ clear_to_ascend = false; break; } trial_depth -= deltad; } restore_deco_state(trial_cache); free(trial_cache); return clear_to_ascend; }
// Determine whether ascending to the next stop will break the ceiling. Return true if the ascent is ok, false if it isn't. bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time, double tissue_tolerance, struct gasmix *gasmix, int po2, double surface_pressure) { bool clear_to_ascend = true; char *trial_cache = NULL; // For VPM-B it is not relevant if we would violate a ceiling during ascent to the next stop but // if the next stop is below the ceiling at the start of the ascent (thus the offgasing during // the ascent is ignored. if (prefs.deco_mode == VPMB) return (deco_allowed_depth(tissue_tolerance, surface_pressure, &displayed_dive, 1) <= stoplevel); cache_deco_state(tissue_tolerance, &trial_cache); while (trial_depth > stoplevel) { int deltad = ascent_velocity(trial_depth, avg_depth, bottom_time) * TIMESTEP; if (deltad > trial_depth) /* don't test against depth above surface */ deltad = trial_depth; tissue_tolerance = add_segment(depth_to_mbar(trial_depth, &displayed_dive) / 1000.0, gasmix, TIMESTEP, po2, &displayed_dive, prefs.decosac); if (deco_allowed_depth(tissue_tolerance, surface_pressure, &displayed_dive, 1) > trial_depth - deltad) { /* We should have stopped */ clear_to_ascend = false; break; } trial_depth -= deltad; } restore_deco_state(trial_cache); free(trial_cache); return clear_to_ascend; }
int main(int argc, const char *argv[]) { int count = 0; segment_t segment; segment.id = 1; if (argc != 2) exit(3); sscanf(argv[1], "%d", &count); add_segment(&segment, count); message_t msg = PARENT | LEFT; char c; while (scanf("%c", &c)) { if (c == 'm') { send(segment, msg); msg ^= LR_MASK; } if (c == 'q') { int msg = EXIT; send(segment, msg); return 0; } } return 0; }
int ultrasound(tSensors us_sensor, int distance, int ultrasound_dist1, int ultrasound_dist3) #endif { int s_val; init_path(); add_segment(distance, 0, 45); stop_path(); dead_reckon(); wait1Msec(1000); #ifdef __HTSMUX_SUPPORT__ s_val = USreadDist(us_sensor); #else s_val = SensorValue[us_sensor]; #endif if (s_val < ultrasound_dist3) { return 3; } else if (s_val < ultrasound_dist1) { return 1; } else { return 2; } }
static void add_backref_segment (struct transform *tf, size_t ref) { struct replace_segm *segm = add_segment (tf); segm->type = segm_backref; segm->v.ref = ref; }
task main() { int i; servo[leftEye] = LSERVO_CENTER; servo[rightEye] = RSERVO_CENTER; init_path(); add_segment(24, 0, 50); // Move to beacon sensing position. stop_path(); dead_reckon(); if (SensorValue[carrot] < 60) { position = 3; } else if (SensorValue[carrot] < 80) { // If ultrasonic sensor sees a position, position = 1; // set variable "position" to position number. } else { position = 2; } move_to_pole(position); // Move to pole using position number. for (i = 0; i < position; i++) { // Beep for the position number that the playImmediateTone(251, 50); // ultrasonic sensor sees. wait1Msec(1000); } }
unsigned long add_buffer(struct kexec_info *info, const void *buf, unsigned long bufsz, unsigned long memsz, unsigned long buf_align, unsigned long buf_min, unsigned long buf_max, int buf_end) { unsigned long base; int result; int pagesize; result = sort_segments(info); if (result < 0) { die("sort_segments failed\n"); } /* Round memsz up to a multiple of pagesize */ pagesize = getpagesize(); memsz = (memsz + (pagesize - 1)) & ~(pagesize - 1); base = locate_hole(info, memsz, buf_align, buf_min, buf_max, buf_end); if (base == ULONG_MAX) { die("locate_hole failed\n"); } add_segment(info, buf, bufsz, base, memsz); return base; }
void add_segment(segment_t *segment, int counter) { int childpid; segment_t next; if (counter <= 0) return; pipe(segment->fd); if ((segment->pid = fork()) == -1) { perror("Cannot fork"); exit(1); } if (segment->pid == 0) { next.id = segment->id + 1; next.parent = segment; add_segment(&next, counter - 1); segment->legs[0].segment = segment; segment->legs[1].segment = segment; add_leg(&segment->legs[0]); add_leg(&segment->legs[1]); int msg = 0; int ready = FALSE; int leg = 0; while (read(segment->fd[0], &msg, MSG_S)) { if (msg & CHILD) { /*printf("child %d of %d moved\n", next.id, segment->id);*/ if (leg == (msg & LR_MASK)) ready = FALSE; send(*segment->parent, msg); } if (msg & PARENT) { send(segment->legs[!(msg & LEFT)], msg); ready = TRUE; leg = msg & LR_MASK; msg ^= LR_MASK; send(next, msg); } if (msg & LEG) { printf("%s noga z członu %d %s\n", msg & LEFT ? "lewa" : "prawa", segment->id, ready ? "wykonała krok": "potknęła się"); msg = (msg & LR_MASK) | CHILD; send(*segment->parent, msg); fflush(stdout); } if (msg == EXIT) { send(next, msg); kill(segment->legs[0].pid, SIGTERM); kill(segment->legs[1].pid, SIGTERM); exit(0); } } } }
task main() { initializeRobot(); RNRR_waitForStart(); init_path(); add_segment(28, 0, 100); add_segment(27, 45, 100); stop_path(); dead_reckon(); dumpBlock(); while (true) { } }
void GCSWrapper::circle_min_diameter(int id, double diameter) { int s1 = add_segment(0.0, 0.0, 0.0, diameter); line_vertical(s1); fix_length(s1, diameter); coincident_line_circle(s1, id); }
void snake_sleep() { struct timespec sleep_time = (struct timespec) {.tv_sec = 0, .tv_nsec = SLEEP_TIME}; struct timespec remaining; nanosleep(&sleep_time, &remaining); } void grow_snake() { add_segment(snake); }
void player::update() { if (input::pressed(KEY_P1_UP) && head->pvelocity != D_DOWN) { head->velocity = D_UP; } if (input::pressed(KEY_P1_DOWN) && head->pvelocity != D_UP) { head->velocity = D_DOWN; } if (input::pressed(KEY_P1_LEFT) && head->pvelocity != D_RIGHT) { head->velocity = D_LEFT; } if (input::pressed(KEY_P1_RIGHT) && head->pvelocity != D_LEFT) { head->velocity = D_RIGHT; } int now = SDL_GetTicks(); if (now - last_advance > advance_delay ) { // printf("advance snake\n"); head->advance(); for (std::list<segment*>::iterator it=body.begin(); it!=body.end(); ++it) { (*it)->advance(); } if (head->velocity != last_vel) { level->pivots[head->py][head->px] = head->velocity; last_vel = head->velocity; } if ((*level->walls)(head->x, head->y)) { // printf("game over\n"); hit->play(0,1); dead = true; return; } for (std::list<segment*>::iterator it=body.begin(); it!=body.end(); ++it) { if ((*it)->x == head->x && (*it)->y == head->y){ hit->play(0,1); dead = true; return; } } if ((*level->cherries)(head->x, head->y) == 1) { (*level->cherries)(head->x, head->y) = 0; cherry->play(0,1); add_segment(); grew = true; } if (tail != NULL) { level->pivots[tail->py][tail->px] = D_NONE; } last_advance = now; } }
void output_ogr(const std::string& filename, const std::string& driver_name, const segvec& removed_segments, const segvec& added_segments) { OGRRegisterAll(); OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver_name.c_str()); if (!driver) { std::cerr << driver_name << " driver not available.\n"; exit(return_code_fatal); } //const char* options[] = { "SPATIALITE=yes", "OGR_SQLITE_SYNCHRONOUS=OFF", "INIT_WITH_EPSG=no", nullptr }; const char* options[] = { nullptr }; auto data_source = std::unique_ptr<OGRDataSource, OGRDataSourceDestroyer>(driver->CreateDataSource(filename.c_str(), const_cast<char**>(options))); if (!data_source) { std::cerr << "Creation of output file failed.\n"; exit(return_code_fatal); } SRS srs; auto layer = data_source->CreateLayer("changes", srs.out(), wkbLineString, const_cast<char**>(options)); if (!layer) { std::cerr << "Creating layer 'changes' failed.\n"; exit(return_code_fatal); } OGRFieldDefn field_change("change", OFTInteger); field_change.SetWidth(1); if (layer->CreateField(&field_change) != OGRERR_NONE ) { std::cerr << "Creating field 'change' on 'changes' layer failed.\n"; exit(return_code_fatal); } layer->StartTransaction(); for (const auto& segment : removed_segments) { add_segment(layer, 0, segment); } for (const auto& segment : added_segments) { add_segment(layer, 1, segment); } layer->CommitTransaction(); }
static void add_char_segment (struct transform *tf, int chr) { struct replace_segm *segm = add_segment (tf); segm->type = segm_literal; segm->v.literal.ptr = xmalloc (2); segm->v.literal.ptr[0] = chr; segm->v.literal.ptr[1] = 0; segm->v.literal.size = 1; }
// helper funcion for lvm2cmd, used to parse mappings between // logical extents and physical extents void parse_pvs_segments(int level, const char *file, int line, int dm_errno, const char *format) { // disregard debug output if (level != 4) return; char pv_name[4096]={0}, vg_name[4096]={0}, vg_format[4096]={0}, vg_attr[4096]={0}, pv_size[4096]={0}, pv_free[4096]={0}, lv_name[4096]={0}, pv_type[4096]={0}; int pv_start=0, pv_length=0, lv_start=0; int r; // try to match standard format (allocated extents) r = sscanf(format, " %4095s %4095s %4095s %4095s %4095s " "%4095s %40u %40u %4095s %40d %4095s ", pv_name, vg_name, vg_format, vg_attr, pv_size, pv_free, &pv_start, &pv_length, lv_name, &lv_start, pv_type); if (r==EOF) { fprintf(stderr, "Error matching line %i: %s\n", line, format); goto parse_error; } else if (r != 11) { // segments with state "free" require matching format without "lv_name" lv_name[0]='\000'; r = sscanf(format, " %4095s %4095s %4095s %4095s %4095s %4095s " "%40u %40u %40d %4095s ", pv_name, vg_name, vg_format, vg_attr, pv_size, pv_free, &pv_start, &pv_length, &lv_start, pv_type); if (r==EOF || r != 10) { fprintf(stderr, "Error matching line %i: %s\n", line, format); goto parse_error; } } else { // r == 11 // do nothing, correct parse } add_segment(pv_name, vg_name, vg_format, vg_attr, lv_name, pv_type, pv_start, pv_length, lv_start); // DEBUG // printf("matched %i fields:", r); // printf("%s,%s,%s,%s,%s,%s,%i,%i,%s,%i,%s\n", // pv_name, vg_name, vg_format, vg_attr, pv_size, pv_free, // pv_start, pv_length, lv_name, lv_start, pv_type); // DEBUG //printf("%s\n", format); parse_error: return; }
double interpolate_transition(struct dive *dive, int t0, int t1, int d0, int d1, const struct gasmix *gasmix, int po2) { int j; double tissue_tolerance = 0.0; for (j = t0; j < t1; j++) { int depth = interpolate(d0, d1, j - t0, t1 - t0); tissue_tolerance = add_segment(depth_to_mbar(depth, dive) / 1000.0, gasmix, 1, po2, dive); } return tissue_tolerance; }
double interpolate_transition(struct dive *dive, duration_t t0, duration_t t1, depth_t d0, depth_t d1, const struct gasmix *gasmix, o2pressure_t po2) { int j; double tissue_tolerance = 0.0; for (j = t0.seconds; j < t1.seconds; j++) { int depth = interpolate(d0.mm, d1.mm, j - t0.seconds, t1.seconds - t0.seconds); tissue_tolerance = add_segment(depth_to_mbar(depth, dive) / 1000.0, gasmix, 1, po2.mbar, dive); } return tissue_tolerance; }
void make_segment(struct Point* points, struct Segment* segments, float radius, size_t number_of_points) { for (size_t i = 0; i < number_of_points; ++i) { if (radius * radius + EPS >= points[i].coord_y * points[i].coord_y) { add_segment(points, segments, radius, i); } else { segments[2 * i].entry = -1; segments[2 * i + 1].entry = -1; } } }
void move_to_position(int position) { init_path(); switch (position) { // add_segment(distance, angle, power); case 1: add_segment(18, 0, 50); // Move robot to position one. break; case 2: add_segment(30, -45, 50); // Move robot to position two. add_segment(0, 90, 25); break; case 3: add_segment(15, -90, 50); // Move robot to position three. add_segment(0, 135, 25); break; stop_path(); dead_reckon(); } }
void load_segments(Elf *elf,int phnum,char *base,int flen, int which) { Elf32_Phdr *phdr; int i; phdr = elf32_getphdr(elf); if (phdr == NULL) { failure("getphdr"); } /* printf("headers at %d\n",ehdr->e_phoff); */ for (i = 0; i < phnum; i++) { if (phdr[i].p_type == PT_NOTE) { if (which) { fprintf(of,"%d: NOTE offset=0x%x filesz=0x%x flags=%d align=%d\n", i, phdr[i].p_offset, phdr[i].p_filesz, phdr[i].p_flags, phdr[i].p_align); } } else if (phdr[i].p_type == PT_LOAD) { if (which) { fprintf(of,"%d: LOAD vaddr=0x%x filesz=0x%x memsz=0x%x mode=%s\n", i, phdr[i].p_vaddr, phdr[i].p_filesz, phdr[i].p_memsz, modes[phdr[i].p_flags & 0x7]); } if (phdr[i].p_offset && phdr[i].p_filesz) { if (phdr[i].p_offset + phdr[i].p_filesz > flen) { fprintf(of,"%d: segment out of range - core file is incomplete.\n",i); continue; } } if ((phdr[i].p_flags == 7 || phdr[i].p_flags == 5) && phdr[i].p_filesz) { add_segment(&phdr[i],base,which); } } else { if (which) { fprintf(of,"%d: type=%d offset=0x%x vaddr=0x%x p=0x%x filesz=%d memsz=%d flags=%d align=%d\n", i, phdr[i].p_type,phdr[i].p_offset, phdr[i].p_vaddr, phdr[i].p_paddr, phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_flags, phdr[i].p_align); } } } }
static void add_literal_segment (struct transform *tf, char *str, char *end) { size_t len = end - str; if (len) { struct replace_segm *segm = add_segment (tf); segm->type = segm_literal; segm->v.literal.ptr = xmalloc (len + 1); memcpy (segm->v.literal.ptr, str, len); segm->v.literal.ptr[len] = 0; segm->v.literal.size = len; } }
void split_segment_table (segtable* st, int id, segtable** _leftovers) { segtable* leftovers = *_leftovers; possum cov; score lowScore; u32 srcIx, dstIx; segment* seg; cov = 0; lowScore = worstPossibleScore; //fprintf (stderr, "incoming\n"); //dump_segments (stderr, st, NULL, NULL); dstIx = 0; for (srcIx=0 ; srcIx<st->len ; srcIx++) { seg = &st->seg[srcIx]; if (seg->id != id) { leftovers = add_segment (leftovers, seg->pos1, seg->pos2, seg->length, seg->s, seg->id); continue; } cov += seg->length; if ((dstIx == 0) || (seg->s < lowScore)) lowScore = seg->s; if (dstIx != srcIx) st->seg[dstIx] = *seg; dstIx++; } st->len = dstIx; st->coverage = cov; st->lowScore = lowScore; //fprintf (stderr, "\nid=%d\n", id); //dump_segments (stderr, st, NULL, NULL); //fprintf (stderr, "\nileftovers\n"); //dump_segments (stderr, leftovers, NULL, NULL); //fprintf (stderr, "\n"); *_leftovers = leftovers; }
/////////////////////////////////// // Add all particles to the grid // /////////////////////////////////// void charge_grid( ) { int i, j; #pragma omp parallel for for ( i=0 ; i<M ; i++ ) for ( j=0 ; j<ntypes ; j++ ) rho[j][i] = 0.0 ; #pragma omp parallel for for ( i=0 ; i<M ; i++ ) { rhogb[i] = rhoda[i] = rhoha[i] = rhodb[i] = rhohb[i] = rhop[i] = smrhop[i] = rhoga[i] = 0.0 ; for ( j=0 ; j<nthreads ; j++ ) rhogb_t[j][i] = rhoda_t[j][i] = rhoha_t[j][i] = rhodb_t[j][i] = rhohb_t[j][i] = rhoga_t[j][i] = rhop_t[j][i] = 0.0 ; } //////////////////////////////////////////////////// // Add segments to each processors density fields // //////////////////////////////////////////////////// #pragma omp parallel for for ( i=0 ; i<nstot ; i++ ) { if ( tp[i] != -1 ) { add_segment( i ) ; } } #pragma omp parallel for private(j) for ( i=0 ; i<M ; i++ ) { for ( j=0 ; j<nthreads ; j++ ) { rhoda[i] += rhoda_t[j][i] ; rhodb[i] += rhodb_t[j][i] ; rhoha[i] += rhoha_t[j][i] ; rhohb[i] += rhohb_t[j][i] ; rhop[i] += rhop_t[j][i] ; rhoga[i] += rhoga_t[j][i] ; rhogb[i] += rhogb_t[j][i] ; } rhot[i] = rhogb[i] + rhoda[i] + rhodb[i] + rhoha[i] + rhohb[i] + rhoga[i]; rho[0][i] = rhoda[i] + rhoha[i] + rhoga[i] ; rho[1][i] = rhodb[i] + rhohb[i] + rhogb[i]; rho[2][i] = rhop[i] ; } }
void GCSWrapper::point_segment_coincidence(int id1, int id2) // id1 = point, id2 = line { SaPoint* p = (SaPoint*)get_shape(id1); SaLine* l1 = (SaLine*)get_shape(id2); double l1_lgh; double l1_midx; double l1_midy; calculate_line_length(l1, l1_lgh); calculate_line_midpoint(l1, l1_midx, l1_midy); //int p = add_point(5.0, 5.0); //int c = add_circle(10.0, 10.0, 3.0); int c = add_circle(l1_midx, l1_midy, l1_lgh/2); SaCircle* circle = (SaCircle*)get_shape(c); coincident_line_circle(id2, c); //solve(); gcs_sys.addConstraintPointOnLine(circle->get_gcs_circle().center, l1->get_gcs_line(), 1); //solve(); collinear_point_line(id1, id2); //solve(); double l2_x1, l2_y1, l2_x2, l2_y2; calculate_rotate_line(l1, l2_x1, l2_y1, l2_x2, l2_y2); int l2 = add_segment(l2_x1, l2_y1, l2_x2, l2_y2); perpendicular(id2, l2); //solve(); coincident_line_circle(l2, c); //solve(); //collinear_point_line(p, id2); collinear_point_line(id1, l2); //solve(); //circle->get_gcs_circle().center; }
size_t WKT(int polygon) { while (listHasData(&segs)) { struct keyval *p; unsigned int id, to, from; double x0, y0, x1, y1; p = popItem(&segs); id = strtoul(p->value, NULL, 10); freeItem(p); from = segments[id].from; to = segments[id].to; x0 = nodes[from].lon; y0 = nodes[from].lat; x1 = nodes[to].lon; y1 = nodes[to].lat; add_segment(x0,y0,x1,y1); } return build_geometry(polygon); }