int RGBLED::setMode(enum ledModes new_mode) { switch (new_mode) { case LED_MODE_SYSTEMSTATE: case LED_MODE_TEST: mode = new_mode; if (!running) { running = true; set_on(true); work_queue(LPWORK, &_work, (worker_t)&RGBLED::led_trampoline, this, 1); } break; case LED_MODE_OFF: default: if (running) { running = false; set_on(false); } mode = LED_MODE_OFF; break; } return OK; }
void RGBLED::led() { static int led_thread_runcount=0; static int led_interval = 1000; switch (mode) { case LED_MODE_TEST: /* Demo LED pattern for now */ led_colors[0] = LED_COLOR_YELLOW; led_colors[1] = LED_COLOR_AMBER; led_colors[2] = LED_COLOR_RED; led_colors[3] = LED_COLOR_PURPLE; led_colors[4] = LED_COLOR_BLUE; led_colors[5] = LED_COLOR_GREEN; led_colors[6] = LED_COLOR_WHITE; led_colors[7] = LED_COLOR_OFF; led_blink = LED_BLINK_ON; break; case LED_MODE_SYSTEMSTATE: /* XXX TODO set pattern */ led_colors[0] = LED_COLOR_OFF; led_colors[1] = LED_COLOR_OFF; led_colors[2] = LED_COLOR_OFF; led_colors[3] = LED_COLOR_OFF; led_colors[4] = LED_COLOR_OFF; led_colors[5] = LED_COLOR_OFF; led_colors[6] = LED_COLOR_OFF; led_colors[7] = LED_COLOR_OFF; led_blink = LED_BLINK_OFF; break; case LED_MODE_OFF: default: return; break; } if (led_thread_runcount & 1) { if (led_blink == LED_BLINK_ON) setLEDColor(LED_COLOR_OFF); led_interval = LED_OFFTIME; } else { setLEDColor(led_colors[(led_thread_runcount/2) % 8]); led_interval = LED_ONTIME; } led_thread_runcount++; if(running) { /* re-queue ourselves to run again later */ work_queue(LPWORK, &_work, (worker_t)&RGBLED::led_trampoline, this, led_interval); } else { set_on(false); } }
/************************************************************************* * *N query_table * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function returns the set of selected rows of a VPF table * based upon the evaluation of the given selection expression string. * * The expression is strictly evaluated left to right. No nesting * is supported, so parentheses are not allowed. The expression * must match the form: * <field><log op><value> [ <join> <field><log op><value>] * where, * <field> is a valid field name of the table. * <log op> is one of the following: =, <, >, <=, >=, <> (not equal). * <value> is a valid value for the field. * <join> is either " AND " or " OR ". * Any number of clauses (<field><log op><value>) may be joined * together with AND or OR to form the expression. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * expression <input>==(char *) selection expression string. * table <input>==(vpf_table_type) VPF table structure. * return <output>==(set_type) set of selected rows. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F * set_type set_init( rspf_int32 n ) SET.C * void set_insert( rspf_int32 element, set_type set ) SET.C * linked_list_type parse_expression( char *expression, * vpf_table_type table ) VPFQUERY.C * row_type read_next_row( vpf_table_type table ) VPFREAD.C * position_type ll_first( linked_list_type list ) LINKLIST.C * int ll_end( position_type position ) LINKLIST.C * void ll_element( position_type position, void *element ) LINKLIST.C * void *get_table_element( rspf_int32 field_number, * row_type row, * vpf_table_type table, * void *value, * rspf_int32 *count ) VPFREAD.C * void display_message( char *info ) USER DEFINED * static int strcompare( char *val1, char *val2, char op ) VPFQUERY.C * static int icompare( rspf_int32 val1, rspf_int32 val2, char op ) VPFQUERY.C * static int fcompare( float val1, float val2, char op ) VPFQUERY.C * void ll_reset( linked_list_type list ) LINKLIST.C void free_row( row_type row, vpf_table_type table) VPFREAD.C *E *************************************************************************/ set_type query_table( char *expression, vpf_table_type table ) { row_type row; position_type pos; expr_type expr; register rspf_int32 i; int boolval=FALSE, booltemp=0, join = OR; rspf_int32 lval, lval2, count; float fval, fval2; char tval, tval2, *tptr; linked_list_type exprlist; set_type select_set; select_set = set_init(table.nrows+1); if (strcmp(expression,"*")==0) { set_on(select_set); return select_set; } exprlist = parse_expression( expression, table ); if (!exprlist) return select_set; if (table.storage == DISK) fseek( table.fp, index_pos(1,table), SEEK_SET ); for (i=1;i<=table.nrows;i++) { if (table.storage == DISK) row = read_next_row(table); else row = get_row( i, table ); pos = ll_first(exprlist); while (!ll_end(pos)) { ll_element( pos, &expr ); switch (table.header[expr.field].type) { case 'I': if (table.header[expr.field].count == 1) { get_table_element( expr.field, row, table, &lval, &count ); lval2 = atol(expr.value); booltemp = icompare( lval, lval2, expr.op ); } else { display_message( "Selection may not be performed upon arrays"); i=table.nrows+1; } break; case 'T': if (table.header[expr.field].count == 1) { get_table_element( expr.field, row, table, &tval, &count ); tval2 = expr.value[0]; booltemp = comp( &tval, &tval2, sizeof(tval), expr.op ); } else { tptr = (char *)get_table_element( expr.field, row, table, NULL, &count ); booltemp = strcompare( tptr, expr.value, expr.op ); free(tptr); } break; case 'F': if (table.header[expr.field].count == 1) { get_table_element( expr.field, row, table, &fval, &count ); if (!is_vpf_null_float(fval)) { fval2 = (float)atof(expr.value); booltemp = fcompare( fval, fval2, expr.op ); } else booltemp = FALSE; } else { display_message( "Selection may not be performed upon arrays"); i=table.nrows+3; } break; default: display_message("Field type not supported for query"); i=table.nrows+3; break; } if (i>table.nrows) break; if (join==OR) boolval = boolval || booltemp; else boolval = boolval && booltemp; join = expr.join; pos = pos->next; } free_row( row, table ); if (boolval) set_insert(i,select_set); boolval = FALSE; join = OR; if (i==table.nrows+3) break; } ll_reset(exprlist); return select_set; }
/************************************************************************* * *N get_selected_tile_primitives * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function determines all of the selected primitive rows from * the selected features of a given tile. * * This function expects a feature class relationship structure that * has been successfully created with select_feature_class_relate() * from the feature table to the primitive. The primitive table in * the feature class relate structure must have been successfully * opened for the given tile. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * library <input>==(library_type *) VPF library structure. * fcnum <input>==(int) feature class number of the feature table. * fcrel <input>==(fcrel_type) feature class relate structure. * feature_rows <input>==(set_type) set of selected features. * mapenv <input>==(map_environment_type *) map environment. * tile <input>==(rspf_int32) tile number. * tiledir <input>==(char *) path to the tile directory. * status <output>==(int *) status of the function: * 1 if completed, 0 if user escape. * return <output>==(set_type) set of primitives for the features * in the corresponding tile. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *************************************************************************/ set_type get_selected_tile_primitives( library_type *library, int fcnum, fcrel_type fcrel, set_type feature_rows, map_environment_type *mapenv, rspf_int32 tile, char *tiledir, int *status ) { int cov, degree; int feature, prim; row_type row; char *spxname[] = {"","esi","fsi","tsi","nsi","csi"}; char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"}; set_type primitive_rows, tile_features; set_type primitives; rspf_int32 prim_rownum; register rspf_int32 i,pclass, start,end; char path[255], covpath[255]; linked_list_type primlist; position_type p; vpf_relate_struct rcell; ThematicIndex idx; feature = 0; prim = fcrel.nchain-1; /* Assume that fcrel.table[prim] has been opened */ primitives.size = 0; primitives.buf = NULL; cov = library->fc[fcnum].coverage; strcpy( covpath, library->cover[cov].path ); p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list); ll_element(p,&rcell); degree = rcell.degree; for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) { if ((pclass != library->fc[fcnum].primclass) && (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue; primitives = set_init(fcrel.table[prim].nrows+1); /* Get the set of primitive rows within the map extent */ /* Look for the spatial index file to weed out primitives in the */ /* given tile but outside of the viewing area. If a projection */ /* other than plate-carree (rectangular) is on, or if the extent */ /* crosses the meridian, the quick check is no longer valid. */ primitive_rows.size = 0; if (mapenv->projection == PLATE_CARREE && mapenv->mapextent.x1 < mapenv->mapextent.x2) { sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]); /* 20 (below) is a fairly arbitrary cutoff of the number of */ /* primitives that make a spatial index search worth while. */ if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) { primitive_rows = spatial_index_search(path, mapenv->mapextent.x1,mapenv->mapextent.y1, mapenv->mapextent.x2,mapenv->mapextent.y2); } else { /* Next best thing - bounding rectangle table */ sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]); if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) { primitive_rows = bounding_select(path,mapenv->mapextent, library->dec_degrees); } } } if (primitive_rows.size == 0) { /* Search through all the primitives */ primitive_rows=set_init(fcrel.table[prim].nrows+1); set_on(primitive_rows); } if (strcmp(tiledir,"") != 0) { tile_thematic_index_name(fcrel.table[feature], path); if ((strcmp(path,"")!=0) && (access(path,4)==0)) { /* Tile thematic index for feature table present, */ tile_features = read_thematic_index( path, (char *)&tile ); } else { tile_features = set_init(fcrel.table[feature].nrows+1); set_on(tile_features); } } else { tile_features = set_init(fcrel.table[feature].nrows+1); set_on(tile_features); } set_delete(0,tile_features); idx.fp = NULL; i = table_pos(rcell.key2,fcrel.table[prim]); if (i >= 0) { if (fcrel.table[prim].header[i].tdx) { sprintf(path,"%s%s",fcrel.table[prim].path, fcrel.table[prim].header[i].tdx); if (access(path,0)==0) idx = open_thematic_index(path); } if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE; if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY; if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE; } start = set_min(tile_features); end = set_max(tile_features); /* It turns out to be MUCH faster off of a CD-ROM to */ /* read each row and discard unwanted ones than to */ /* forward seek past them. It's about the same off */ /* of a hard disk. */ fseek(fcrel.table[feature].fp,index_pos(start,fcrel.table[feature]), SEEK_SET); for (i=start;i<=end;i++) { row = read_next_row(fcrel.table[feature]); if (!set_member( i, feature_rows )) { free_row(row,fcrel.table[feature]); continue; } if (!set_member( i, tile_features )) { free_row(row,fcrel.table[feature]); continue; } if (degree == R_ONE) { prim_rownum = fc_row_number( row, fcrel, tile ); primlist = NULL; p = NULL; } else { primlist = fc_row_numbers( row, fcrel, tile, &idx ); } free_row( row, fcrel.table[feature] ); if (!primlist) { if ((prim_rownum<1)||(prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives); } } else { p = ll_first(primlist); while (!ll_end(p)) { ll_element(p,&prim_rownum); if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives); } p = ll_next(p); } } if (primlist) ll_reset(primlist); if (kbhit()) { if (getch()==27) { *status = 0; break; } } } set_nuke(&primitive_rows); set_nuke(&tile_features); if (idx.fp) close_thematic_index(&idx); *status = 1; if (kbhit()) { if (getch()==27) { *status = 0; break; } } } return primitives; }
/************************************************************************* * *N get_selected_primitives * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function determines all of the selected primitive rows from * the selected features. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * view <input> == (view_type *) view structure. * themenum <input> == (int) theme number. * library <input> == (library_type *) VPF library structure. * mapenv <input> == (map_environment_type *) map environment. * status <output> == (int *) status of the function: * 1 if completed, 0 if user escape. * get_selected_primitives <output> == (set_type *) array of sets, each position * representing the set of primitives for the * corresponding tile in the tileref.aft table. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels May 1991 DOS Turbo C *E *************************************************************************/ set_type *get_selected_primitives( view_type *view, int themenum, library_type *library, map_environment_type *mapenv, int *status ) { int fcnum, finished, found, cov, tilecover, TILEPATH_, degree; int feature, prim; vpf_table_type tile_table; row_type row; char *ptable[] = {"","edg","fac","txt","end","cnd"}; char *spxname[] = {"","esi","fsi","tsi","nsi","csi"}; char *brname[] = {"","ebr","fbr","tbr","nbr","cbr"}; set_type feature_rows, primitive_rows, tile_features; set_type *primitives; rspf_int32 prim_rownum, count, tile; register rspf_int32 i,j, pclass, start,end; char path[255], covpath[255], tiledir[255], *buf, str[255]; fcrel_type fcrel; linked_list_type primlist; position_type p; vpf_relate_struct rcell; ThematicIndex idx; primitives = (set_type *)vpfmalloc((library->ntiles+1)*sizeof(set_type)); for (i=0;i<=library->ntiles;i++) { primitives[i].size = 0; primitives[i].buf = NULL; } fcnum = view->theme[themenum].fcnum; feature_rows = get_selected_features( view, themenum, *library ); /* Open the tile reference table, if present */ sprintf(path,"%stileref\\tileref.aft",library->path); if (access(path,0) != 0) { tilecover = FALSE; } else { tile_table = vpf_open_table(path,disk,"rb",NULL); TILEPATH_ = table_pos("TILE_NAME",tile_table); tilecover = TRUE; } for (pclass=EDGE;pclass<=CONNECTED_NODE;pclass++) { if ((pclass != library->fc[fcnum].primclass) && (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue; /* Set up the feature class table relate chain. */ /* The feature table is fcrel.table[0]. */ /* The primitive table is the last table in the chain: */ /* fcrel.table[ fcrel.nchain-1 ]. */ j = 0; for (i=0;i<strlen(library->fc[fcnum].table);i++) if (library->fc[fcnum].table[i] == '\\') j = i+1; strcpy( str, &(library->fc[fcnum].table[j])); fcrel = select_feature_class_relate(fcnum, library, str, ptable[pclass]); feature = 0; prim = fcrel.nchain-1; p = ll_previous(ll_last(fcrel.relate_list),fcrel.relate_list); ll_element(p,&rcell); degree = rcell.degree; /*** 'Tile' number 1 is the universe polygon for the tileref cover ***/ for (tile = 2; tile <= library->ntiles; tile++ ) { if (!set_member(tile,library->tile_set)) continue; if (tilecover) { row = get_row(tile,tile_table); buf = (char *)get_table_element(TILEPATH_,row,tile_table, NULL,&count); free_row(row,tile_table); strcpy(tiledir,buf); rightjust(tiledir); strcat(tiledir,"\\"); free(buf); } else { strcpy(tiledir,""); } cov = library->fc[fcnum].coverage; strcpy( covpath, library->cover[cov].path ); finished = 1; found = 0; /* Open primitive table in tile */ sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]); if (access(path,0) != 0) continue; found = 1; fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL); if (primitives[tile].size > 0) { printf("Oops! size = %ld\n",primitives[tile].size); exit(1); } primitives[tile] = set_init(fcrel.table[prim].nrows+1); /* Get the set of primitive rows within the map extent */ /* Look for spatial index file */ primitive_rows.size = 0; if (mapenv->projection == PLATE_CARREE && mapenv->mapextent.x1 < mapenv->mapextent.x2) { sprintf(path,"%s%s%s",covpath,tiledir,spxname[pclass]); if ((access(path,0)==0)&&(fcrel.table[prim].nrows > 20)) { primitive_rows = spatial_index_search(path, mapenv->mapextent.x1,mapenv->mapextent.y1, mapenv->mapextent.x2,mapenv->mapextent.y2); } else { /* Next best thing - bounding rectangle table */ sprintf(path,"%s%s%s",covpath,tiledir,brname[pclass]); if (access(path,0)==0) { primitive_rows = bounding_select(path,mapenv->mapextent, library->dec_degrees); } } } /* projection check */ if (primitive_rows.size == 0) { /* Search through all the primitives */ primitive_rows=set_init(fcrel.table[prim].nrows+1); set_on(primitive_rows); } tile_thematic_index_name(fcrel.table[feature], path); if ( (strcmp(path,"") != 0) && (access(path,4)==0) ) { /* Tile thematic index for feature table present, */ tile_features = read_thematic_index( path, (char *)&tile ); } else { tile_features = set_init(fcrel.table[feature].nrows+1); set_on(tile_features); } idx.fp = NULL; i = table_pos(rcell.key2,fcrel.table[prim]); if (i >= 0) { if (fcrel.table[prim].header[i].tdx) { sprintf(path,"%s%s",fcrel.table[prim].path, fcrel.table[prim].header[i].tdx); if (access(path,0)==0) idx = open_thematic_index(path); } if (fcrel.table[prim].header[i].keytype == 'U') degree = R_ONE; if (fcrel.table[prim].header[i].keytype == 'N') degree = R_MANY; if (fcrel.table[prim].header[i].keytype == 'P') degree = R_ONE; } finished = 1; start = set_min(tile_features); end = set_max(tile_features); fseek(fcrel.table[feature].fp, index_pos(start,fcrel.table[feature]), SEEK_SET); for (i=start;i<=end;i++) { row = read_next_row(fcrel.table[feature]); if (!set_member( i, feature_rows )) { free_row(row,fcrel.table[feature]); continue; } if (!set_member( i, tile_features )) { free_row(row,fcrel.table[feature]); continue; } if (degree == R_ONE) { prim_rownum = fc_row_number( row, fcrel, tile ); primlist = NULL; p = NULL; } else { primlist = fc_row_numbers( row, fcrel, tile, &idx ); } free_row( row, fcrel.table[feature] ); if (!primlist) { if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives[tile]); } } else { p = ll_first(primlist); while (!ll_end(p)) { ll_element(p,&prim_rownum); if ((prim_rownum<1)|| (prim_rownum>fcrel.table[prim].nrows)) continue; if (set_member( prim_rownum, primitive_rows )) { set_insert(prim_rownum,primitives[tile]); } p = ll_next(p); } } if (kbhit()) { if (getch()==27) { *status = 0; finished = 0; break; } } } if (idx.fp) close_thematic_index(&idx); vpf_close_table(&(fcrel.table[prim])); set_nuke(&primitive_rows); set_nuke(&tile_features); if (set_empty(primitives[tile])) { set_nuke(&primitives[tile]); primitives[tile].size = 0; primitives[tile].buf = NULL; } if (!finished) { *status = 0; break; } } if (!finished) { *status = 0; deselect_feature_class_relate( &fcrel ); break; } if (found) *status = 1; if (kbhit()) { if (getch()==27) { *status = 0; deselect_feature_class_relate( &fcrel ); break; } } deselect_feature_class_relate( &fcrel ); } set_nuke(&feature_rows); if (tilecover) { vpf_close_table(&tile_table); } return primitives; }
/* Processes one :set statement. Returns zero on success. */ static int process_option(const char arg[]) { char option[OPTION_NAME_MAX + 1]; int err; const char *p; opt_t *opt; p = skip_alphas(arg); snprintf(option, p - arg + 1, "%s", arg); if(strcmp(option, "all") == 0) { print_options(); return 0; } opt = get_option(option); if(opt == NULL) { text_buffer_addf("%s: %s", "Unknown option", arg); return 1; } err = 0; if(*p == '\0') { opt_t *o = find_option(option); if(o != NULL) { if(o->type == OPT_BOOL) err = set_on(opt); else err = set_print(o); } else if(strncmp(option, "no", 2) == 0) { err = set_off(opt); } else if(strncmp(option, "inv", 3) == 0) { err = set_inv(opt); } } else if(char_is_one_of(ENDING_CHARS, *p)) { if(*(p + 1) != '\0') { text_buffer_addf("%s: %s", "Trailing characters", arg); return 1; } if(*p == '!') err = set_inv(opt); else if(*p == '?') err = set_print(opt); else err = set_reset(opt); } else if(strncmp(p, "+=", 2) == 0) { err = set_add(opt, p + 2); } else if(strncmp(p, "-=", 2) == 0) { err = set_remove(opt, p + 2); } else if(*p == '=' || *p == ':') { err = set_set(opt, p + 1); } else { text_buffer_addf("%s: %s", "Trailing characters", arg); } if(err) { text_buffer_addf("%s: %s", "Invalid argument", arg); } return err; }