From eb89fea1f16430b86b1732396b740119bc193d80 Mon Sep 17 00:00:00 2001 From: emanuel Date: Thu, 19 Nov 2020 14:12:34 +0000 Subject: [PATCH] New configs --- src/cam.c | 6 +++--- src/cam.h | 9 ++++---- src/config.c | 51 +++++++++++++++++++++++++++++++++++++++++++- src/denm.c | 6 ++---- src/denm.h | 1 + src/facilities.c | 22 +++++++++++-------- src/facilities.h | 1 + src/infrastructure.c | 2 -- src/infrastructure.h | 3 +++ 9 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/cam.c b/src/cam.c index 3d66e46..e64a2bf 100644 --- a/src/cam.c +++ b/src/cam.c @@ -198,12 +198,12 @@ void lightship_reset_timer(lightship_t* lightship) { pthread_mutex_lock(&lightship->lock); if (lightship->type != StationType_roadSideUnit) { // Vehicle - lightship->next_cam = now + VEHICLE_GEN_CAM_MAX; + lightship->next_cam = now + lightship->vehicle_gen_max; } else { // RSU - if (now > lightship->last_vehicle + RSU_VEHICLE_PERMANENCE) { + if (now > lightship->last_vehicle + lightship->rsu_vehicle_permanence) { lightship->is_vehicle_near = false; } - lightship->next_cam = now + RSU_GEN_CAM_MIN; + lightship->next_cam = now + lightship->rsu_gen_min; } pthread_mutex_unlock(&lightship->lock); diff --git a/src/cam.h b/src/cam.h index 58c3527..20ed08a 100644 --- a/src/cam.h +++ b/src/cam.h @@ -9,11 +9,6 @@ #include #include -#define VEHICLE_GEN_CAM_MIN 100 -#define VEHICLE_GEN_CAM_MAX 1000 - -#define RSU_GEN_CAM_MIN 1000 -#define RSU_VEHICLE_PERMANENCE 5000 typedef struct lightship { pthread_mutex_t lock; @@ -25,6 +20,10 @@ typedef struct lightship { bool is_vehicle_near; uint64_t last_vehicle; + uint32_t vehicle_gen_min; + uint32_t vehicle_gen_max; + uint32_t rsu_gen_min; + uint32_t rsu_vehicle_permanence; } lightship_t; lightship_t* lightship_init(); diff --git a/src/config.c b/src/config.c index 5aaf18c..6520c6b 100644 --- a/src/config.c +++ b/src/config.c @@ -86,10 +86,16 @@ int itss_config(void* facilities_s, char* config_file) { fclose(fp); // Tables - toml_table_t *general, *security; + toml_table_t *general, *security, *denm, *cam, *beacon, *replay, *ivim; if (0 == (general = toml_table_in(conf, "general"))) {syslog_err("[facilities] [config] failed locating [general] table"); return 1;} if (0 == (security = toml_table_in(conf, "security"))) {syslog_err("[facilities] [config] failed locating [security] table"); return 1;} + if (0 == (denm = toml_table_in(conf, "denm"))) {syslog_err("[facilities] [config] failed locating [denm] table"); return 1;} + if (0 == (cam = toml_table_in(conf, "cam"))) {syslog_err("[facilities] [config] failed locating [cam] table"); return 1;} + if (0 == (replay = toml_table_in(conf, "replay"))) {syslog_err("[facilities] [config] failed locating [replay] table"); return 1;} + if (0 == (ivim = toml_table_in(conf, "ivim"))) {syslog_err("[facilities] [config] failed locating [ivim] table"); return 1;} + + // Values // General @@ -117,6 +123,49 @@ int itss_config(void* facilities_s, char* config_file) { facilities->station_id = station_id_number; } + // DENM + int64_t denm_default_event_duration; + rv = extract_val_int(&denm_default_event_duration, denm, "default-event-duration"); + facilities->den->default_event_duration = denm_default_event_duration; + + int64_t denm_nmax_active_events; + rv = extract_val_int(&denm_nmax_active_events, denm, "nmax-active-events"); + facilities->den->n_max_events = denm_nmax_active_events; + + // CAM + int64_t obu_cam_period_min; + rv = extract_val_int(&obu_cam_period_min, cam, "obu-period-min"); + facilities->lightship->vehicle_gen_min = obu_cam_period_min; + + int64_t obu_cam_period_max; + rv = extract_val_int(&obu_cam_period_max, cam, "obu-period-max"); + facilities->lightship->vehicle_gen_max = obu_cam_period_max; + + int64_t rsu_cam_period_min; + rv = extract_val_int(&rsu_cam_period_min, cam, "rsu-period-min"); + facilities->lightship->rsu_gen_min = rsu_cam_period_min; + + int64_t rsu_vehicle_permanence; + rv = extract_val_int(&rsu_vehicle_permanence, cam, "rsu-vehicle-permanence"); + facilities->lightship->rsu_vehicle_permanence = rsu_vehicle_permanence; + + // IVIM + int64_t nmax_active_services; + rv = extract_val_int(&nmax_active_services, ivim, "nmax-active-services"); + facilities->infrastructure->n_max_services = nmax_active_services; + + int64_t replay_interval; + rv = extract_val_int(&replay_interval, ivim, "replay-interval"); + facilities->infrastructure->replay_interval = replay_interval; + + // Replay + int replay_active = 1; + rv = extract_val_bool(&replay_active, replay, "activate"); + facilities->replay = replay_active; + + + + toml_free(conf); diff --git a/src/denm.c b/src/denm.c index d5e65a9..58e0ac2 100644 --- a/src/denm.c +++ b/src/denm.c @@ -38,7 +38,7 @@ static enum EVENT_CHECK_RESULT event_check(den_t *den, DENM_t *denm) { if (denm->denm.management.validityDuration != NULL) { e_validity_duration = *(uint32_t *) denm->denm.management.validityDuration * 1000; // validityDuration comes in seconds } else { - e_validity_duration = 30000; + e_validity_duration = den->default_event_duration * 1000; } if (e_detection_time + e_validity_duration < now) { @@ -115,7 +115,7 @@ static int event_add(den_t *den, DENM_t *denm, int64_t* id) { if (denm->denm.management.validityDuration != NULL) { e_validity_duration = *(uint32_t *) denm->denm.management.validityDuration * 1000; // validityDuration comes in seconds } else { - e_validity_duration = 30000; + e_validity_duration = den->default_event_duration * 1000; } pthread_mutex_lock(&den->lock); @@ -328,8 +328,6 @@ void* den_service(void *fc) { den_t *den = facilities->den; pthread_mutex_init(&den->lock, NULL); - den->n_max_events = 32; - den->events = malloc(den->n_max_events * sizeof(void*)); for (int i = 0; i < den->n_max_events; ++i) { den->events[i] = calloc(1, sizeof(event_t)); diff --git a/src/denm.h b/src/denm.h index 28e26d5..ec2a70a 100644 --- a/src/denm.h +++ b/src/denm.h @@ -36,6 +36,7 @@ typedef struct den { uint16_t n_cancelled_events; uint16_t n_negated_events; uint16_t n_max_events; + uint32_t default_event_duration; pthread_mutex_t lock; } den_t; diff --git a/src/facilities.c b/src/facilities.c index ac2ff2e..fc60b7a 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -230,7 +230,7 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t if ( ((DENM_t*)its_msg)->denm.management.validityDuration ) { transmission_duration = *( (uint32_t*) ((DENM_t*)its_msg)->denm.management.validityDuration ) * 1000; } else { - transmission_duration = 30000; + transmission_duration = facilities->den->default_event_duration * 1000; } } } else if (fdreq->choice.singleMessage.itssMessageType == ItssMessageType_ivim) { @@ -258,10 +258,15 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, &valid_from); transmission_start = valid_from; - transmission_interval = 1000; + transmission_interval = facilities->infrastructure->replay_interval; transmission_duration = valid_to - valid_from; } + if (!facilities->replay) { + transmission_interval = 0; + transmission_duration = 0; + } + // Respond to [applications] fdres->code = FacilitiesResultCode_accepted; fdres_oer = malloc(16); @@ -568,6 +573,11 @@ int main() { facilities_t facilities; facilities.exit = false; + facilities.lightship = lightship_init(); + facilities.tx_queue = queue_init(); + facilities.den = calloc(1, sizeof(den_t)); + facilities.infrastructure = calloc(1, sizeof(infrastructure_t)); + pthread_mutex_init(&facilities.lock, NULL); struct stat st = {0}; @@ -588,19 +598,13 @@ int main() { void *security_socket = zmq_socket(context, ZMQ_REQ); rc = zmq_bind(security_socket, SECURITY_ADDRESS); - facilities.tx_queue = queue_init(); - facilities.lightship = lightship_init(); facilities.lightship->type = facilities.station_type; - facilities.den = calloc(1, sizeof(den_t)); - - facilities.infrastructure = calloc(1, sizeof(infrastructure_t)); - // Tx pthread_create(&facilities.transmitting, NULL, tx, (void*) &facilities); - // Tx + // Securing pthread_create(&facilities.securing, NULL, securer, (void*) &facilities); // CA diff --git a/src/facilities.h b/src/facilities.h index 7b508e0..3f88492 100644 --- a/src/facilities.h +++ b/src/facilities.h @@ -38,6 +38,7 @@ typedef struct facilities { infrastructure_t* infrastructure; int station_type; + bool replay; pthread_mutex_t lock; uint64_t station_id; diff --git a/src/infrastructure.c b/src/infrastructure.c index 2559ef5..1af3f0d 100644 --- a/src/infrastructure.c +++ b/src/infrastructure.c @@ -334,8 +334,6 @@ void* infrastructure_service(void *fc) { infrastructure_t *infrastructure = facilities->infrastructure; pthread_mutex_init(&infrastructure->lock, NULL); - infrastructure->n_max_services = 32; - infrastructure->services = malloc(infrastructure->n_max_services * sizeof(void*)); for (int i = 0; i < infrastructure->n_max_services; ++i) { infrastructure->services[i] = calloc(1, sizeof(service_t)); diff --git a/src/infrastructure.h b/src/infrastructure.h index e53fe0c..303821d 100644 --- a/src/infrastructure.h +++ b/src/infrastructure.h @@ -43,6 +43,9 @@ typedef struct infrastructure { uint16_t n_negated_services; uint16_t n_max_services; + + uint32_t replay_interval; + pthread_mutex_t lock; } infrastructure_t;