New configs
This commit is contained in:
parent
e2e66d12fe
commit
eb89fea1f1
|
|
@ -198,12 +198,12 @@ void lightship_reset_timer(lightship_t* lightship) {
|
||||||
pthread_mutex_lock(&lightship->lock);
|
pthread_mutex_lock(&lightship->lock);
|
||||||
|
|
||||||
if (lightship->type != StationType_roadSideUnit) { // Vehicle
|
if (lightship->type != StationType_roadSideUnit) { // Vehicle
|
||||||
lightship->next_cam = now + VEHICLE_GEN_CAM_MAX;
|
lightship->next_cam = now + lightship->vehicle_gen_max;
|
||||||
} else { // RSU
|
} 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->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);
|
pthread_mutex_unlock(&lightship->lock);
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,6 @@
|
||||||
#include <camv2/CAM.h>
|
#include <camv2/CAM.h>
|
||||||
#include <itss-transport/BTPDataIndication.h>
|
#include <itss-transport/BTPDataIndication.h>
|
||||||
|
|
||||||
#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 {
|
typedef struct lightship {
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
|
|
@ -25,6 +20,10 @@ typedef struct lightship {
|
||||||
bool is_vehicle_near;
|
bool is_vehicle_near;
|
||||||
uint64_t last_vehicle;
|
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_t* lightship_init();
|
lightship_t* lightship_init();
|
||||||
|
|
|
||||||
51
src/config.c
51
src/config.c
|
|
@ -86,10 +86,16 @@ int itss_config(void* facilities_s, char* config_file) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
// Tables
|
// 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 == (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 == (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
|
// Values
|
||||||
// General
|
// General
|
||||||
|
|
@ -117,6 +123,49 @@ int itss_config(void* facilities_s, char* config_file) {
|
||||||
facilities->station_id = station_id_number;
|
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);
|
toml_free(conf);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ static enum EVENT_CHECK_RESULT event_check(den_t *den, DENM_t *denm) {
|
||||||
if (denm->denm.management.validityDuration != NULL) {
|
if (denm->denm.management.validityDuration != NULL) {
|
||||||
e_validity_duration = *(uint32_t *) denm->denm.management.validityDuration * 1000; // validityDuration comes in seconds
|
e_validity_duration = *(uint32_t *) denm->denm.management.validityDuration * 1000; // validityDuration comes in seconds
|
||||||
} else {
|
} else {
|
||||||
e_validity_duration = 30000;
|
e_validity_duration = den->default_event_duration * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e_detection_time + e_validity_duration < now) {
|
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) {
|
if (denm->denm.management.validityDuration != NULL) {
|
||||||
e_validity_duration = *(uint32_t *) denm->denm.management.validityDuration * 1000; // validityDuration comes in seconds
|
e_validity_duration = *(uint32_t *) denm->denm.management.validityDuration * 1000; // validityDuration comes in seconds
|
||||||
} else {
|
} else {
|
||||||
e_validity_duration = 30000;
|
e_validity_duration = den->default_event_duration * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&den->lock);
|
pthread_mutex_lock(&den->lock);
|
||||||
|
|
@ -328,8 +328,6 @@ void* den_service(void *fc) {
|
||||||
den_t *den = facilities->den;
|
den_t *den = facilities->den;
|
||||||
pthread_mutex_init(&den->lock, NULL);
|
pthread_mutex_init(&den->lock, NULL);
|
||||||
|
|
||||||
den->n_max_events = 32;
|
|
||||||
|
|
||||||
den->events = malloc(den->n_max_events * sizeof(void*));
|
den->events = malloc(den->n_max_events * sizeof(void*));
|
||||||
for (int i = 0; i < den->n_max_events; ++i) {
|
for (int i = 0; i < den->n_max_events; ++i) {
|
||||||
den->events[i] = calloc(1, sizeof(event_t));
|
den->events[i] = calloc(1, sizeof(event_t));
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ typedef struct den {
|
||||||
uint16_t n_cancelled_events;
|
uint16_t n_cancelled_events;
|
||||||
uint16_t n_negated_events;
|
uint16_t n_negated_events;
|
||||||
uint16_t n_max_events;
|
uint16_t n_max_events;
|
||||||
|
uint32_t default_event_duration;
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
} den_t;
|
} den_t;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
|
||||||
if ( ((DENM_t*)its_msg)->denm.management.validityDuration ) {
|
if ( ((DENM_t*)its_msg)->denm.management.validityDuration ) {
|
||||||
transmission_duration = *( (uint32_t*) ((DENM_t*)its_msg)->denm.management.validityDuration ) * 1000;
|
transmission_duration = *( (uint32_t*) ((DENM_t*)its_msg)->denm.management.validityDuration ) * 1000;
|
||||||
} else {
|
} else {
|
||||||
transmission_duration = 30000;
|
transmission_duration = facilities->den->default_event_duration * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (fdreq->choice.singleMessage.itssMessageType == ItssMessageType_ivim) {
|
} 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);
|
asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, &valid_from);
|
||||||
|
|
||||||
transmission_start = valid_from;
|
transmission_start = valid_from;
|
||||||
transmission_interval = 1000;
|
transmission_interval = facilities->infrastructure->replay_interval;
|
||||||
transmission_duration = valid_to - valid_from;
|
transmission_duration = valid_to - valid_from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!facilities->replay) {
|
||||||
|
transmission_interval = 0;
|
||||||
|
transmission_duration = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Respond to [applications]
|
// Respond to [applications]
|
||||||
fdres->code = FacilitiesResultCode_accepted;
|
fdres->code = FacilitiesResultCode_accepted;
|
||||||
fdres_oer = malloc(16);
|
fdres_oer = malloc(16);
|
||||||
|
|
@ -568,6 +573,11 @@ int main() {
|
||||||
facilities_t facilities;
|
facilities_t facilities;
|
||||||
facilities.exit = false;
|
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);
|
pthread_mutex_init(&facilities.lock, NULL);
|
||||||
|
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
|
|
@ -588,19 +598,13 @@ int main() {
|
||||||
void *security_socket = zmq_socket(context, ZMQ_REQ);
|
void *security_socket = zmq_socket(context, ZMQ_REQ);
|
||||||
rc = zmq_bind(security_socket, SECURITY_ADDRESS);
|
rc = zmq_bind(security_socket, SECURITY_ADDRESS);
|
||||||
|
|
||||||
facilities.tx_queue = queue_init();
|
|
||||||
|
|
||||||
facilities.lightship = lightship_init();
|
|
||||||
facilities.lightship->type = facilities.station_type;
|
facilities.lightship->type = facilities.station_type;
|
||||||
|
|
||||||
facilities.den = calloc(1, sizeof(den_t));
|
|
||||||
|
|
||||||
facilities.infrastructure = calloc(1, sizeof(infrastructure_t));
|
|
||||||
|
|
||||||
// Tx
|
// Tx
|
||||||
pthread_create(&facilities.transmitting, NULL, tx, (void*) &facilities);
|
pthread_create(&facilities.transmitting, NULL, tx, (void*) &facilities);
|
||||||
|
|
||||||
// Tx
|
// Securing
|
||||||
pthread_create(&facilities.securing, NULL, securer, (void*) &facilities);
|
pthread_create(&facilities.securing, NULL, securer, (void*) &facilities);
|
||||||
|
|
||||||
// CA
|
// CA
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ typedef struct facilities {
|
||||||
infrastructure_t* infrastructure;
|
infrastructure_t* infrastructure;
|
||||||
|
|
||||||
int station_type;
|
int station_type;
|
||||||
|
bool replay;
|
||||||
|
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
uint64_t station_id;
|
uint64_t station_id;
|
||||||
|
|
|
||||||
|
|
@ -334,8 +334,6 @@ void* infrastructure_service(void *fc) {
|
||||||
infrastructure_t *infrastructure = facilities->infrastructure;
|
infrastructure_t *infrastructure = facilities->infrastructure;
|
||||||
pthread_mutex_init(&infrastructure->lock, NULL);
|
pthread_mutex_init(&infrastructure->lock, NULL);
|
||||||
|
|
||||||
infrastructure->n_max_services = 32;
|
|
||||||
|
|
||||||
infrastructure->services = malloc(infrastructure->n_max_services * sizeof(void*));
|
infrastructure->services = malloc(infrastructure->n_max_services * sizeof(void*));
|
||||||
for (int i = 0; i < infrastructure->n_max_services; ++i) {
|
for (int i = 0; i < infrastructure->n_max_services; ++i) {
|
||||||
infrastructure->services[i] = calloc(1, sizeof(service_t));
|
infrastructure->services[i] = calloc(1, sizeof(service_t));
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ typedef struct infrastructure {
|
||||||
uint16_t n_negated_services;
|
uint16_t n_negated_services;
|
||||||
|
|
||||||
uint16_t n_max_services;
|
uint16_t n_max_services;
|
||||||
|
|
||||||
|
uint32_t replay_interval;
|
||||||
|
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
} infrastructure_t;
|
} infrastructure_t;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue