[33] | 1 | // |
---|
| 2 | // |
---|
| 3 | // |
---|
| 4 | |
---|
| 5 | #include <stdio.h> |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include <string.h> |
---|
| 8 | |
---|
| 9 | #include "cognitive_engine.h" |
---|
| 10 | |
---|
| 11 | ce ce_create(char * _xmlfilename) |
---|
| 12 | { |
---|
| 13 | // parse xml |
---|
| 14 | ce engine = (ce) malloc(sizeof(struct ce_s)); |
---|
| 15 | |
---|
| 16 | // TODO read length, name from XML file |
---|
| 17 | engine->num_utilities = 1; |
---|
| 18 | engine->num_parameters = 2; |
---|
| 19 | engine->num_observables = 1; |
---|
| 20 | |
---|
| 21 | engine->u = (object*) malloc((engine->num_utilities)*sizeof(object)); |
---|
| 22 | engine->p = (object*) malloc((engine->num_parameters)*sizeof(object)); |
---|
| 23 | engine->o = (object*) malloc((engine->num_observables)*sizeof(object)); |
---|
| 24 | |
---|
| 25 | // Just to test |
---|
| 26 | strcpy(engine->u[0].name,"BER"); |
---|
| 27 | engine->u[0].value = 0.2f; |
---|
| 28 | |
---|
| 29 | strcpy(engine->p[0].name, "mod_scheme"); |
---|
| 30 | engine->p[0].value = 1.0f; |
---|
| 31 | strcpy(engine->p[1].name,"tx_power"); |
---|
| 32 | engine->p[1].value = 20.0f; |
---|
| 33 | |
---|
| 34 | strcpy(engine->o[0].name, "path_loss"); |
---|
| 35 | engine->o[0].value = 120.0f; |
---|
| 36 | |
---|
| 37 | return engine; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | void ce_destroy(ce _engine) |
---|
| 41 | { |
---|
| 42 | free(_engine->u); |
---|
| 43 | free(_engine->p); |
---|
| 44 | free(_engine->o); |
---|
| 45 | free(_engine); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void ce_print(ce _engine) |
---|
| 49 | { |
---|
| 50 | printf("engine : %s\n", _engine->name); |
---|
| 51 | unsigned int i; |
---|
| 52 | |
---|
| 53 | for (i=0; i<_engine->num_utilities; i++) |
---|
| 54 | printf(" u[%2d] : %8.2f (%s)\n", i, _engine->u[i].value, _engine->u[i].name); |
---|
| 55 | |
---|
| 56 | for (i=0; i<_engine->num_parameters; i++) |
---|
| 57 | printf(" p[%2d] : %8.2f (%s)\n", i, _engine->p[i].value, _engine->p[i].name); |
---|
| 58 | |
---|
| 59 | for (i=0; i<_engine->num_observables; i++) |
---|
| 60 | printf(" o[%2d] : %8.2f (%s)\n", i, _engine->o[i].value, _engine->o[i].name); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|