/* RECUPERATION DES PROPRIETE DE PROTOCOLE*/ int init(call_t *c, void *params) { struct protocoleData *entitydata = malloc(sizeof(struct protocoleData)); param_t *param; /* init entity variables */ entitydata->debug = 0; /* reading the "init" markup from the xml config file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "debug")) { if (get_param_integer(param->value, &(entitydata->debug))) { goto error; } } } //INITAILISATION DES FICHIER DE SORTIES init_files(); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; char *filepath = NULL; /* default values */ filepath = "mobility.data"; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "file")) { filepath = param->value; } } /* open file */ if ((entitydata->file = fopen(filepath, "r")) == NULL) { fprintf(stderr, "filestatic: can not open file %s in init()\n", filepath); goto error; } set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* RECUPERATION DES PROPRIETES DE PROTOCOLE*/ int init(call_t *c, void *params) { struct protocoleData *entitydata = malloc(sizeof(struct protocoleData)); param_t *param; /* init entity variables */ entitydata->alpha = 1; entitydata->c = 0; entitydata->eps = 0.01; entitydata->debug = 0; //entitydata->debut = time_seconds_to_nanos(3); //entitydata->periodEVE = time_seconds_to_nanos(1); /* reading the "init" markup from the xml config file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "alpha")) { if (get_param_integer(param->value, &(entitydata->alpha))) { goto error; } } if (!strcmp(param->key, "c")) { if (get_param_integer(param->value, &(entitydata->c))) { goto error; } } if (!strcmp(param->key, "eps")) { if (get_param_double(param->value, &(entitydata->eps))) { goto error; } } if (!strcmp(param->key, "debut")) { if (get_param_integer(param->value, &(entitydata->debug))) { goto error; } } } init_files(); set_entity_private_data(c, entitydata); printf("dlbip : alpha : %d ; c : %d\n", entitydata->alpha, entitydata->c); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); char filenode[100]; param_t *param; /* default values */ entitydata->callbacks = das_create(); entitydata->nbr_nodes = get_node_count(); strcpy(entitydata->map_prefix, "energymap"); strcpy(entitydata->directory,"./"); entitydata->map_period = 1000000000; das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { int i = 0; if (!strcmp(param->key, "directory")) { strcpy(entitydata->directory, param->value); goto parse_key_ok; } if (!strcmp(param->key, "prefix")) { strcpy(entitydata->map_prefix, param->value); goto parse_key_ok; } if (!strcmp(param->key, "map-period")) { if (get_param_time(param->value, &(entitydata->map_period))) { goto error; } goto parse_key_ok; } (void) fprintf(stderr, "WARNING: token %s is not recognized\n", param->key); parse_key_ok: i++; } /* open node activity file */ sprintf(filenode, "%s/%s.data", entitydata->directory, "activenodes"); if ((entitydata->filenode = fopen(filenode, "w")) == NULL) { fprintf(stderr, "NRJ monitor: can not open file %s !\n", filenode); goto error; } set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; char *filepath = NULL; int src, dst; double proba; FILE *file; char str[128]; /* default values */ filepath = "propagation.data"; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "file")) { filepath = param->value; } } /* open file */ if ((file = fopen(filepath, "r")) == NULL) { fprintf(stderr, "filestatic: can not open file %s in init()\n", filepath); goto error; } /* extract link success probability */ entitydata->node_cnt = get_node_count(); entitydata->success = malloc(sizeof(double) * entitydata->node_cnt *entitydata->node_cnt); for (src = 0; src < entitydata->node_cnt; src++) { for (dst = 0; dst < entitydata->node_cnt; dst++) { *(entitydata->success + (src * entitydata->node_cnt) + dst) = MIN_DBM; } } fseek(file, 0L, SEEK_SET); while (fgets(str, 128, file) != NULL) { sscanf(str, "%d %d %lf\n", &src, &dst, &proba); *(entitydata->success + (src * entitydata->node_cnt) + dst) = proba; } fclose(file); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); entitydata->TX_hello = 0; entitydata->TX_data = 0; entitydata->TX_query = 0; entitydata->TX_response = 0; entitydata->TX_sensor_adv = 0; entitydata->TX_sensor_data = 0; entitydata->TX_home_adv = 0; set_entity_private_data(c, entitydata); return 0; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; double frequency = 868; /* default values */ entitydata->pathloss = 2.0; entitydata->deviation = 4.0; entitydata->dist0 = 1.0; entitydata->last_rxdBm = 9999; entitydata->Pr0 = 0.0; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "pathloss")) { if (get_param_distance(param->value, &(entitydata->pathloss))) { goto error; } } if (!strcmp(param->key, "frequency_MHz")) { if (get_param_double(param->value, &(frequency))) { goto error; } } if (!strcmp(param->key, "deviation")) { if (get_param_double(param->value, &(entitydata->deviation))) { goto error; } } if (!strcmp(param->key, "dist0")) { if (get_param_double(param->value, &(entitydata->dist0))) { goto error; } } } /* update factor */ entitydata->factor = 300 / (4 * M_PI * frequency); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; double frequency = 868; /* default values */ entitydata->pathloss = 2.0; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "frequency_MHz")) { if (get_param_double(param->value, &(frequency))) { goto error; } } if (!strcmp(param->key, "pathloss")) { if (get_param_double(param->value, &(entitydata->pathloss))) { goto error; } } } /* * Compute attenuation at reference distance d=1 with reference power Pt=1 : * * Pt * Gt * Gr * lambda^2 * Pr(d) = ------------------------- * (4 * pi * d)^2 * L * * Note: rxmW = Pt * Gt * Gr, and L = 1 * * cf p71 ref "Wireless Communications: Principles and Practice", Theodore Rappaport, 1996. * */ entitydata->Pr0 = mW2dBm((300 / (4 * M_PI * frequency)) * (300 / (4 * M_PI * frequency))); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; /* default values */ entitydata->step = 2; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "step")) { if (get_param_double(param->value, &(entitydata->step))) { goto error; } } } set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; double frequency = 868; /* default values */ entitydata->ht = 1; entitydata->hr = 1; entitydata->pathloss = 2.0; entitydata->deviation = 4.0; entitydata->dist0 = 1.0; entitydata->last_rxdBm = 9999; entitydata->Pr0 = 0.0; entitydata->propagation = FREESPACE; entitydata->m = 1.0; entitydata->period = 0; // coorelation time /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "propagation")) { if (!strcmp(param->value, "freespace")) { entitydata->propagation = FREESPACE; } else if (!strcmp(param->value, "tworayground")) { entitydata->propagation = TWORAYGROUND; } else if (!strcmp(param->value, "logdistance")) { entitydata->propagation = LOGDISTANCE; } else if (!strcmp(param->value, "shadowing")) { entitydata->propagation = LOGNORMAL; } else { fprintf(stderr,"\n[nakagami_fading] Unknown propagation type (%s) !\n", param->value); fprintf(stderr,"[nakagami_fading] Possible propagation models are: freespace, tworayground, logdistance and shadowing\n\n"); goto error; } } if (!strcmp(param->key, "pathloss")) { if (get_param_distance(param->value, &(entitydata->pathloss))) { goto error; } } if (!strcmp(param->key, "frequency_MHz")) { if (get_param_double(param->value, &(frequency))) { goto error; } } if (!strcmp(param->key, "deviation")) { if (get_param_double(param->value, &(entitydata->deviation))) { goto error; } } if (!strcmp(param->key, "dist0")) { if (get_param_double(param->value, &(entitydata->dist0))) { goto error; } } if (!strcmp(param->key, "m")) { if (get_param_double(param->value, &(entitydata->m))) { goto error; } } } /* update factor */ entitydata->factor = 300 / (4 * M_PI * frequency); entitydata->crossover_distance = entitydata->ht * entitydata->hr / entitydata->factor; set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; printf("Parameters for nakagmi-m model are error.\n"); }
/* ************************************************** */ int init(call_t *c, void *params) { struct _env_data *entitydata = malloc(sizeof(struct _env_data)); char *filepath = "collection_ctrl.data"; int line; struct _collec_event *event; param_t *param; char str[128]; char event_str[30]; FILE *file; /* We use a sorted list for the events (sorted by time) */ entitydata->events = sodas_create(event_compare); /* Get parameters from the configuration file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "file")) { filepath = param->value; } } /* Open the data collection scheme file */ if ((file = fopen(filepath, "r")) == NULL) { DBG("ERROR: cannot open file %s in init()\n", filepath); goto error; } /* Save the events in a data structure */ /* Structure of the file is: * <time> <node id> <event type> <value> */ fseek(file, 0L, SEEK_SET); line = 1; while (fgets(str, 128, file) != NULL) { event = malloc(sizeof(struct _collec_event)); memset(event_str, 0, sizeof(event_str)); if (event == NULL) { DBG("ERROR: malloc failed\n"); goto error; } if (str[0] == '#' || str[0] == '\n') { /* Line is a comment or an empty line */ line++; continue; } if (sscanf(str, "%"PRId64" %d %s %d\n", &event->time, &event->node_id, event_str, &event->event_value) != 4) { DBG("ERROR: cannot read event in file %s, line %d\n", filepath, line); free(event); goto error; } if (!strncmp(event_str, "APP_TIME_DRV", sizeof(event_str))) { event->event_type = APP_TIME_DRV; } else if (!strncmp(event_str, "APP_EVENT_DRV", sizeof(event_str))) { event->event_type = APP_EVENT_DRV; } else if (!strncmp(event_str, "APP_QUERY_DRV", sizeof(event_str))) { event->event_type = APP_QUERY_DRV; } else if (!strncmp(event_str, "APP_PAYLOAD_SIZE", sizeof(event_str))) { event->event_type = APP_PAYLOAD_SIZE; } else if (!strncmp(event_str, "ENV_EVENT", sizeof(event_str))) { event->event_type = ENV_EVENT; } else if (!strncmp(event_str, "QUERY_MSG", sizeof(event_str))) { event->event_type = QUERY_MSG; } else if (!strncmp(event_str, "CHANGE_APP_DST", sizeof(event_str))) { event->event_type = CHANGE_APP_DST; } else { DBG("ERROR: event type %s unknown in file %s, line %d\n", event_str, filepath, line); free(event); goto error; } //DBG("EVENT: %"PRId64" %d %d %d\n", // event->time, event->node_id, // event->event_type, event->event_value); if (event->node_id >= get_node_count()) { DBG("ERROR: node id %d (line %d) does not exist, " "skipping this event \n", event->node_id, line); free(event); } else { /* Insert the event in the sorted data structure */ sodas_insert(entitydata->events, &event->time, event); } line++; } /* Close the opened file */ fclose(file); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }