IVIMs part II

This commit is contained in:
emanuel 2020-11-04 19:24:01 +00:00
parent a6c55c090c
commit 7ed9820f69
4 changed files with 52 additions and 26 deletions

View File

@ -86,9 +86,10 @@ int itss_config(void* facilities_s, char* config_file) {
fclose(fp);
// Tables
toml_table_t *general;
toml_table_t *general, *general_station_id;
if (0 == (general = toml_table_in(conf, "general"))) {syslog_err("[itss] [config] failed locating [general] table"); return 1;}
if (0 == (general_station_id = toml_table_in(general, "station-id"))) {syslog_err("CONFIG: Failed locating [general] station-id table"); return 1;}
// Values
// General
@ -104,6 +105,16 @@ int itss_config(void* facilities_s, char* config_file) {
}
free(itss_type);
int station_id_random = 1;
rv = extract_val_bool(&station_id_random, general_station_id, "random");
if (station_id_random) {
srand(time(NULL));
facilities->station_id = rand();
} else {
int64_t station_id_number;
rv = extract_val_int(&station_id_number, general_station_id, "number");
facilities->station_id = station_id_number;
}
toml_free(conf);

View File

@ -154,7 +154,7 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
;
bool fwd = true;
uint32_t transmission_duration = 0;
uint64_t transmission_duration = 0;
uint32_t transmission_interval = 0;
uint64_t transmission_start = 0;
@ -250,8 +250,8 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
}
uint64_t valid_to, valid_from;
asn_INTEGER2ulong((INTEGER_t*) &((IVIM_t*) its_msg)->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) &((IVIM_t*) its_msg)->ivi.mandatory.validFrom, &valid_from);
asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, &valid_from);
transmission_start = valid_from;
transmission_interval = 1000;
@ -371,6 +371,16 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
pthread_mutex_unlock(&facilities->den->lock);
break;
case FacilitiesDataRequest_PR_attribute:
switch (fdreq->choice.attribute) {
case FacilitiesAttribute_stationId:
break;
default:
syslog_err("[facilities] unrecognized FDR attribute request received (%d)", fdreq->present);
rv = 1;
goto cleanup;
}
break;
default:
syslog_err("[facilities] unrecognized FDR type received (%d)", fdreq->present);
rv = 1;

View File

@ -36,6 +36,8 @@ typedef struct facilities {
int station_type;
uint64_t station_id;
bool exit;
} facilities_t;

View File

@ -27,9 +27,9 @@ static enum SERVICE_EVAL_RESULT service_check(infrastructure_t* infrastructure,
IVIM_t* ivim = (IVIM_t*) its_msg;
uint64_t timestamp, valid_to, valid_from;
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.timeStamp, &timestamp);
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.validFrom, &valid_from);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.timeStamp, &timestamp);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.validFrom, &valid_from);
struct timespec systemtime;
clock_gettime(CLOCK_REALTIME, &systemtime);
@ -116,9 +116,9 @@ static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type,
now = now - 1072915200000; // Convert EPOCH to 2004/01/01 00:00:000
uint64_t timestamp, valid_to, valid_from;
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.timeStamp, &timestamp);
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.validFrom, &valid_from);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.timeStamp, &timestamp);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.validFrom, &valid_from);
pthread_mutex_lock(&infrastructure->lock);
@ -191,9 +191,9 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty
now = now - 1072915200000; // Convert EPOCH to 2004/01/01 00:00:000
uint64_t timestamp, valid_to, valid_from;
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.timeStamp, &timestamp);
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) &ivim->ivi.mandatory.validFrom, &valid_from);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.timeStamp, &timestamp);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.validTo, &valid_to);
asn_INTEGER2ulong((INTEGER_t*) ivim->ivi.mandatory.validFrom, &valid_from);
uint8_t state;
switch (ivim->ivi.mandatory.iviStatus) {
@ -256,6 +256,9 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty
infrastructure->services[index]->valid_to = valid_to;
infrastructure->services[index]->timestamp = timestamp;
if (state == SERVICE_CANCELLED || state == SERVICE_NEGATED) { // Keep terminated events for 10 mins
infrastructure->services[index]->valid_to = now + 600 * 1000;
}
ASN_STRUCT_FREE(asn_DEF_IVIM, infrastructure->services[index]->ivim);
infrastructure->services[index]->ivim = ivim;
@ -270,7 +273,7 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty
enum SERVICE_EVAL_RESULT service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, int64_t* id) {
int rv = 0;
switch (rv = service_check(infrastructure, type, its_msg)) {
case EVENT_NEW:
case SERVICE_NEW:
syslog_debug("[facilities] [infrastructure] new service received");
if (service_add(infrastructure, type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed adding service, max services reached");
@ -278,15 +281,15 @@ enum SERVICE_EVAL_RESULT service_eval(infrastructure_t* infrastructure, enum SER
rv = -1;
}
break;
case EVENT_INVALID:
case SERVICE_INVALID:
syslog_debug("[facilities] [infrastructure] invalid service received, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break;
case EVENT_PASSED:
case SERVICE_PASSED:
syslog_debug("[facilities] [infrastructure] old service received, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break;
case EVENT_CANCELLATION:
case SERVICE_CANCELLATION:
syslog_debug("[facilities] [infrastructure] service cancellation received");
if (service_update(infrastructure, type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed cancelling service, event not found");
@ -294,27 +297,27 @@ enum SERVICE_EVAL_RESULT service_eval(infrastructure_t* infrastructure, enum SER
rv = -1;
}
break;
case EVENT_NEGATION:
case SERVICE_NEGATION:
syslog_debug("[facilities] [infrastructure] service negation received");
if (service_update(infrastructure, type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed negating service, event not found");
syslog_debug("[facilities] [infrastructure] failed negating service, service not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1;
}
break;
case EVENT_UPDATE:
case SERVICE_UPDATE:
syslog_debug("[facilities] [infrastructure] service update received");
if (service_update(infrastructure, type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed updating service, event not found");
syslog_debug("[facilities] [infrastructure] failed updating service, service not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1;
}
break;
case EVENT_REPEATED:
syslog_debug("[facilities] [infrastructure] repeated service received or referenceTime doesn't allow an update, ignoring");
case SERVICE_REPEATED:
syslog_debug("[facilities] [infrastructure] repeated service received or timeStamp doesn't allow an update, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break;
case EVENT_NUMBER_EXCEEDED:
case SERVICE_NUMBER_EXCEEDED:
syslog_debug("[facilities] [infrastructure] max services reached, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break;
@ -369,7 +372,7 @@ void* infrastructure_service(void *fc) {
if (now > infrastructure->services[i]->valid_from) {
syslog_debug("[facilities] [infrastructure] service %d expiring in %ld second(s)", i, (infrastructure->services[i]->valid_to - now)/1000);
} else {
syslog_debug("[facilities] [infrastructure] service %d starting in %ld seconds with a duration of %ld seconds", i, (now - infrastructure->services[i]->valid_from)/1000, (infrastructure->services[i]->valid_to - infrastructure->services[i]->valid_to)/1000);
syslog_debug("[facilities] [infrastructure] service %d starting in %ld seconds with a duration of %ld seconds", i, (infrastructure->services[i]->valid_from - now)/1000, (infrastructure->services[i]->valid_to - infrastructure->services[i]->valid_from)/1000);
++n_awaiting_services;
}
break;