- Location:
- /vtcross/trunk
- Files:
-
- 4 added
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
/vtcross/trunk/xml/example.ce.xml
r13 r30 1 1 <!-- 2 2 This is an example XML file to interface with our cognitive engine. 3 The library shall create a new table "myengine" with the following cols: 4 throughput spectral_efficiency log10_ber mod_scheme tx_power SNR 3 5 --> 4 6 <engine name="myengine" filename="myengine.sql"> -
/vtcross/trunk/src/cbr.c
r20 r28 8 8 9 9 #include "cbr.h" 10 10 11 11 12 struct cbr_s { … … 18 19 19 20 20 // open database or create database isit does not exist21 // open a database or create a database if it does not exist 21 22 int OpenDatabase(cbr _cbr){ 22 23 int rc; … … 39 40 40 41 41 // int cbr_callback(void *notUsed, int argc, char **argv, char **azColName)42 // simple callback function, display result 42 43 int callback(void *notUsed, int argc, char **argv, char **azColName){ 43 44 int i; … … 50 51 51 52 53 // execute command 52 54 int ExecuteCommand(cbr _cbr){ 53 55 int rc; … … 66 68 67 69 70 // execute search command 71 int 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 68 98 cbr cbr_create(char * _filename, char * _tablename, char * _cols[], unsigned int _len) 69 99 { … … 108 138 } 109 139 140 141 // free space 110 142 void 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 { 119 144 // generate command, remove a table with its content 120 145 strcpy(_cbr->command, "drop table "); … … 131 156 } 132 157 158 159 // print 133 160 void cbr_print(cbr _cbr) 134 161 { … … 145 172 } 146 173 147 //static 174 175 /*//static 148 176 int cbr_callback(void *notUsed, int argc, char **argv, char **azColName) 149 177 { 150 178 return 0; 151 } 179 }*/ 180 152 181 153 182 const char * ops_str[] = { 154 183 "==", "!=", ">", ">=", "<", "<="}; 155 184 185 186 // cbr search 156 187 int cbr_search( 157 188 cbr _cbr, … … 161 192 unsigned int _n, 162 193 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 { 170 195 // generate command 171 196 strcpy(_cbr->command, "select "); … … 185 210 186 211 strcat(_cbr->command, _names[i]); 187 //strcat(_cbr->command, " ");188 212 strcat(_cbr->command, ops_str[_ops[i]]); 189 213 sprintf(str_buffer, "%E", _vals[i]); … … 193 217 strcat(_cbr->command, " AND "); 194 218 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 204 235 int cbr_add_row(cbr _cbr, char *_cols[], float *_vals, unsigned int _len) 205 236 { -
/vtcross/trunk/src/main_cbr.c
r20 r28 7 7 8 8 int 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[] = { 11 27 "BER", "throughput", 12 28 "mod_scheme", "tx_power", 13 29 "noise_power", "path_loss", 14 30 "utility" 15 }; 31 };*/ 32 33 for (i = 0; i<num_cols; i++){ 34 printf(" %s",cols[i]); 35 } 36 printf("\n"); 37 16 38 float vals[num_cols]; 17 39 vals[0] = 1e-3f; // BER -
/vtcross/trunk/src/cbr.h
r16 r28 4 4 5 5 #include "sqlite3.h" 6 #include "ezxml.h" 6 7 7 8 //#define CBR_LEN_FILENAME 64 -
/vtcross/trunk/Makefile
r16 r29 3 3 # 4 4 5 all: cognitive_radio_test utility_test cbr_test 5 TESTS = cognitive_radio utility cbr 6 all: $(TESTS) 6 7 7 main_test.o: src/main_test.c 8 gcc -Wall -c src/main_test.c -Wall -o main_test.o 8 CC = gcc 9 CFLAGS = -Wall -O3 10 LDFLAGS = -lm -ldl -pthread -lsigprocc 9 11 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 12 OBJS = cbr.o sqlite3.o utility.o cognitive_radio_test.o ezxml.o 13 HEADERS = src/cbr.h src/cognitive_radio_test.h \ 14 src/sqlite3.h src/sqlite3ext.h \ 15 src/utility.h src/cognitive_radio_test.h 12 16 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_test17 $(OBJS) : %.o : src/%.c $(HEADERS) 18 $(CC) $(CFLAGS) -c $< -o $@ 15 19 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 $@ 44 22 45 23 clean: 46 rm -rf *.o *_test24 rm -rf *.o $(TESTS) 47 25