Changes in / [20:30]

Show
Ignore:
Location:
/vtcross/trunk
Files:
4 added
5 modified

Legend:

Unmodified
Added
Removed
  • /vtcross/trunk/xml/example.ce.xml

    r13 r30  
    11<!-- 
    22This is an example XML file to interface with our cognitive engine. 
     3The library shall create a new table "myengine" with the following cols: 
     4  throughput spectral_efficiency log10_ber mod_scheme tx_power SNR 
    35--> 
    46<engine name="myengine" filename="myengine.sql"> 
  • /vtcross/trunk/src/cbr.c

    r20 r28  
    88 
    99#include "cbr.h" 
     10 
    1011 
    1112struct cbr_s { 
     
    1819 
    1920 
    20 // open database or create database is it does not exist 
     21// open a database or create a database if it does not exist 
    2122int OpenDatabase(cbr _cbr){ 
    2223    int rc; 
     
    3940 
    4041 
    41 //int cbr_callback(void *notUsed, int argc, char **argv, char **azColName) 
     42// simple callback function, display result 
    4243int callback(void *notUsed, int argc, char **argv, char **azColName){ 
    4344    int i; 
     
    5051 
    5152 
     53// execute command 
    5254int ExecuteCommand(cbr _cbr){ 
    5355    int rc; 
     
    6668 
    6769 
     70// execute search command 
     71int ExecuteSearchCommand(cbr _cbr, float *_retvals){ 
     72    int rc; 
     73    //char *zErrMsg = 0; 
     74    unsigned int i; 
     75 
     76    printf("command: %s\n", _cbr->command); 
     77    sqlite3_stmt * pStatement; 
     78    rc = sqlite3_prepare_v2(_cbr->db, _cbr->command, -1, &pStatement, NULL); 
     79    if (rc == SQLITE_OK && sqlite3_step(pStatement) == SQLITE_ROW){ 
     80        for (i=0; i<_cbr->num_columns; ++i) 
     81            _retvals[i] = sqlite3_column_double(pStatement, i); 
     82    } 
     83    sqlite3_finalize(pStatement); 
     84     
     85    /*rc = sqlite3_exec(_cbr->db, _cbr->command, SearchCallback, 0, &zErrMsg); 
     86    if( rc!=SQLITE_OK){ 
     87        fprintf(stderr, "SQL error: %s\n", zErrMsg); 
     88        sqlite3_free(zErrMsg); 
     89    } else{ 
     90        printf("command executed.\n"); 
     91    }*/ 
     92 
     93    return rc; 
     94} 
     95 
     96 
     97// create database 
    6898cbr cbr_create(char * _filename, char * _tablename, char * _cols[], unsigned int _len) 
    6999{ 
     
    108138} 
    109139 
     140 
     141// free space 
    110142void cbr_free(cbr _cbr) 
    111 { 
    112     // delete table here 
    113     // delete table 
    114      
    115     /*// generate command, delete all entries of a table 
    116     strcpy(_cbr->command, "delete from "); 
    117     strcat(_cbr->command, _cbr->tablename);*/ 
    118  
     143 
    119144    // generate command, remove a table with its content 
    120145    strcpy(_cbr->command, "drop table "); 
     
    131156} 
    132157 
     158 
     159// print  
    133160void cbr_print(cbr _cbr) 
    134161{ 
     
    145172} 
    146173 
    147 //static 
     174 
     175/*//static 
    148176int cbr_callback(void *notUsed, int argc, char **argv, char **azColName) 
    149177{ 
    150178    return 0; 
    151 } 
     179}*/ 
     180 
    152181 
    153182const char * ops_str[] = { 
    154183    "==", "!=", ">", ">=", "<", "<="}; 
    155184 
     185 
     186// cbr search 
    156187int cbr_search( 
    157188    cbr _cbr, 
     
    161192    unsigned int _n, 
    162193    float *_retvals) 
    163 { 
    164     // set up statement 
    165  
    166     /*char* zErrMsg = NULL; 
    167     //sqlite3_exec(_cbr->db, argv[2], callback, NULL, &zErrMsg); 
    168     sqlite3_exec(_cbr->db, _cbr->command, cbr_callback, NULL, &zErrMsg);*/ 
    169  
     194{    
    170195    // generate command 
    171196    strcpy(_cbr->command, "select "); 
     
    185210 
    186211        strcat(_cbr->command, _names[i]); 
    187         //strcat(_cbr->command, " "); 
    188212        strcat(_cbr->command, ops_str[_ops[i]]); 
    189213        sprintf(str_buffer, "%E", _vals[i]); 
     
    193217            strcat(_cbr->command, " AND "); 
    194218        else 
    195             strcat(_cbr->command, ";"); 
    196     } 
    197  
    198     //printf("command: %s\n", _cbr->command); 
    199     ExecuteCommand(_cbr); 
    200  
    201     return 0; 
    202 } 
    203  
     219            strcat(_cbr->command, " order by utility desc;"); 
     220    } 
     221 
     222    //ExecuteCommand(_cbr); 
     223    ExecuteSearchCommand(_cbr, _retvals); 
     224     
     225    printf("search result: "); 
     226    for (i=0; i<_cbr->num_columns; i++) 
     227        printf("%f, ",_retvals[i]); 
     228    printf("\n"); 
     229 
     230    return 0; 
     231} 
     232 
     233 
     234// cbr add a row 
    204235int cbr_add_row(cbr _cbr, char *_cols[], float *_vals, unsigned int _len) 
    205236{ 
  • /vtcross/trunk/src/main_cbr.c

    r20 r28  
    77 
    88int main() { 
    9     unsigned int num_cols = 7; 
    10     char * cols[] = { 
     9    unsigned int num_cols = 7;  
     10    unsigned int i; 
     11 
     12    ezxml_t f1 = ezxml_parse_file("another.xml"), engine, column; 
     13    char * cols[num_cols]; 
     14     
     15    for (engine = ezxml_child(f1, "engine"); engine; engine = engine->next){ 
     16        i = 0; 
     17        for (column = ezxml_child(engine, "column"); column; column = column->next){ 
     18            cols[i] = ezxml_child(column, "name")->txt; 
     19            i++; 
     20        } 
     21    } 
     22 
     23 
     24    free(f1); 
     25                             
     26    /* char * cols[] = { 
    1127        "BER", "throughput", 
    1228        "mod_scheme", "tx_power", 
    1329        "noise_power", "path_loss", 
    1430        "utility" 
    15     }; 
     31    };*/ 
     32     
     33    for (i = 0; i<num_cols; i++){ 
     34        printf(" %s",cols[i]); 
     35    } 
     36    printf("\n"); 
     37 
    1638    float vals[num_cols]; 
    1739    vals[0] = 1e-3f;    // BER 
  • /vtcross/trunk/src/cbr.h

    r16 r28  
    44 
    55#include "sqlite3.h" 
     6#include "ezxml.h" 
    67 
    78//#define CBR_LEN_FILENAME 64 
  • /vtcross/trunk/Makefile

    r16 r29  
    33# 
    44 
    5 all: cognitive_radio_test utility_test cbr_test 
     5TESTS = cognitive_radio utility cbr 
     6all: $(TESTS) 
    67 
    7 main_test.o: src/main_test.c 
    8         gcc -Wall -c src/main_test.c -Wall -o main_test.o 
     8CC = gcc 
     9CFLAGS = -Wall -O3 
     10LDFLAGS = -lm -ldl -pthread -lsigprocc 
    911 
    10 cognitive_radio_test.o: src/cognitive_radio_test.c 
    11         gcc -Wall -c src/cognitive_radio_test.c -Wall -o cognitive_radio_test.o 
     12OBJS = cbr.o sqlite3.o utility.o cognitive_radio_test.o ezxml.o 
     13HEADERS = src/cbr.h src/cognitive_radio_test.h \ 
     14                  src/sqlite3.h src/sqlite3ext.h \ 
     15                  src/utility.h src/cognitive_radio_test.h 
    1216 
    13 cognitive_radio_test: cognitive_radio_test.o main_test.o 
    14         gcc cognitive_radio_test.o main_test.o -Wall -lm -lsigprocc -o cognitive_radio_test 
     17$(OBJS) : %.o : src/%.c $(HEADERS) 
     18        $(CC) $(CFLAGS) -c $< -o $@ 
    1519 
    16 utility.o: src/utility.c 
    17         gcc -Wall -c src/utility.c -o utility.o 
    18  
    19 main_utility.o: src/main_utility.c 
    20         gcc -Wall -c src/main_utility.c -o main_utility.o 
    21  
    22 utility_test: utility.o main_utility.o 
    23         gcc -Wall utility.o main_utility.o -lm -o utility_test 
    24  
    25 #  
    26 # case database targets 
    27 # 
    28  
    29 sqlite3.o: src/sqlite3.c src/sqlite3.h 
    30         gcc -c src/sqlite3.c -o sqlite3.o 
    31  
    32 cbr.o: src/cbr.c src/cbr.h src/sqlite3.h 
    33         gcc -Wall -c src/cbr.c -o cbr.o 
    34  
    35 main_cbr.o: src/main_cbr.c src/cbr.h 
    36         gcc -Wall -c src/main_cbr.c -o main_cbr.o 
    37  
    38 cbr_test: sqlite3.o cbr.o main_cbr.o 
    39         gcc -Wall sqlite3.o cbr.o main_cbr.o -ldl -pthread -o cbr_test 
    40  
    41 # 
    42 # cleanup 
    43 # 
     20$(TESTS) : % : src/main_%.c $(OBJS) 
     21        $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $< -o $@ 
    4422 
    4523clean: 
    46         rm -rf *.o *_test 
     24        rm -rf *.o $(TESTS) 
    4725