Generalize a bit the SA service

This commit is contained in:
emanuel 2023-02-20 15:21:12 +00:00
parent 1ed2e269c8
commit 648f9c506c
3 changed files with 65 additions and 34 deletions

View File

@ -1,5 +1,6 @@
#include "config.h"
#include "facilities.h"
#include "saem.h"
#include "tpm.h"
#include "vcm.h"
@ -568,10 +569,10 @@ int facilities_config() {
ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq);
ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep);
if (config->facilities.saem.activate) {
if (config->facilities.saem.activate) { // TODO handle various services
facilities.bulletin.to_provide_len = 1;
facilities.bulletin.to_provide[0] = calloc(1, sizeof(announcement_t));
facilities.bulletin.to_provide[0]->endpoint.port = 7011;
facilities.bulletin.to_provide[0]->endpoint.port = 7010 + config->facilities.saem.service_to_advertise;
facilities.bulletin.to_provide[0]->its_aid = config->facilities.saem.service_to_advertise;
}

View File

@ -65,34 +65,42 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) {
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
);
if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) {
TollingPaymentInfo_t* tpi = NULL;
asn_dec_rval_t dec = uper_decode_complete(
NULL,
&asn_DEF_TollingPaymentInfo,
(void**) &tpi,
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.buf,
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
);
if (!dec.code) {
switch (its_aid) {
case SAID_ETC:
if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) {
TollingPaymentInfo_t* tpi = NULL;
asn_dec_rval_t dec = uper_decode_complete(
NULL,
&asn_DEF_TollingPaymentInfo,
(void**) &tpi,
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.buf,
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
);
if (!dec.code) {
bool found = false;
for (int t = 0; t < bulletin->to_consume_len; ++t) {
if (((tolling_info_t*)bulletin->to_consume[t]->info.internal_p)->asn->id == tpi->id) {
found = true;
break;
bool found = false;
for (int t = 0; t < bulletin->to_consume_len; ++t) {
if (((tolling_info_t*)bulletin->to_consume[t]->info.internal_p)->asn->id == tpi->id) {
found = true;
break;
}
}
if (!found) {
facilities.tolling.infos.z[facilities.tolling.infos.length] = tolling_info_new(tpi);
bulletin->to_consume[bulletin->to_consume_len]->info.internal_p = facilities.tolling.infos.z[facilities.tolling.infos.length];
++facilities.tolling.infos.length;
new_announcement = true;
}
} else {
ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, tpi);
}
}
break;
if (!found) {
facilities.tolling.infos.z[facilities.tolling.infos.length] = tolling_info_new(tpi);
bulletin->to_consume[bulletin->to_consume_len]->info.internal_p = facilities.tolling.infos.z[facilities.tolling.infos.length];
++facilities.tolling.infos.length;
new_announcement = true;
}
} else {
ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, tpi);
}
case SAID_EVCSN:
// TODO
break;
}
break;
@ -151,11 +159,17 @@ void bulletin_init() {
}
int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
/**
* @brief Make a SAEM.
* @param b_saem A large enough buffer.
* @param b_saem_len The encoded SAEM length.
* @return 0 on success, 1 otherwise.
*/
static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
int rv = 0;
// Check tolling advertisements
if (!facilities.tolling.infos.length) {
if (!facilities.tolling.infos.length /* || facilites.evcsn.infos.length */) {
return 1;
}
@ -174,14 +188,15 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
saem->sam.version = 0;
saem->sam.body.serviceInfos = calloc(1, sizeof(ServiceInfos_t));
saem->sam.body.serviceInfos->list.count = facilities.tolling.infos.length;
saem->sam.body.serviceInfos->list.size = facilities.tolling.infos.length * sizeof(void*);
saem->sam.body.serviceInfos->list.array = malloc(facilities.tolling.infos.length * sizeof(void*));
saem->sam.body.serviceInfos->list.count = facilities.tolling.infos.length; // + facilities.evcsn.infos.length;
saem->sam.body.serviceInfos->list.size = facilities.tolling.infos.length * sizeof(void*); // + facilities.evcsn.infos.length * sizeof(void*);
saem->sam.body.serviceInfos->list.array = malloc(facilities.tolling.infos.length * sizeof(void*)); // + facilities.evcsn.infos.length * sizeof(void*);
uint8_t buf[1024];
for (int i = 0; i < facilities.tolling.infos.length; ++i) {
int i;
for (i = 0; i < facilities.tolling.infos.length; ++i) {
saem->sam.body.serviceInfos->list.array[i] = calloc(1, sizeof(ServiceInfo_t));
saem->sam.body.serviceInfos->list.array[i]->serviceID = 1;
saem->sam.body.serviceInfos->list.array[i]->serviceID = SAID_ETC;
saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions = calloc(1, sizeof(ServiceInfoExts_t));
@ -259,6 +274,12 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
}
}
for (int j = 0; j < 0/* + facilities.evcsn.infos.length */; ++j) {
saem->sam.body.serviceInfos->list.array[i+j] = calloc(1, sizeof(ServiceInfo_t));
saem->sam.body.serviceInfos->list.array[i+j]->serviceID = SAID_EVCSN;
// TODO
}
pthread_mutex_unlock(&facilities.id.lock);
enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_SAEM, saem, b_saem, *b_saem_len);
@ -372,6 +393,7 @@ void *sa_service() {
pthread_mutex_lock(&bulletin->lock);
for (int a = 0; a < bulletin->to_consume_len; ++a) {
// Tolling
if (facilities.tolling.enabled &&
bulletin->to_consume[a]->its_aid == 1 &&
@ -401,6 +423,9 @@ void *sa_service() {
++bulletin->to_consume[a]->n_trigger;
bulletin->to_consume[a]->t_trigger = now;
break;
default:
break;
}
}
}

View File

@ -5,8 +5,13 @@
#define MAX_ANNOUNCEMENTS_LEN 32
typedef enum {
SAID_ETC = 1,
SAID_EVCSN = 999 // TODO define
} SAID_e;
typedef struct announcement {
uint32_t its_aid;
SAID_e its_aid;
uint8_t protocol_id;
uint8_t traffic_class;