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 "config.h"
#include "facilities.h" #include "facilities.h"
#include "saem.h"
#include "tpm.h" #include "tpm.h"
#include "vcm.h" #include "vcm.h"
@ -568,10 +569,10 @@ int facilities_config() {
ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq); ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq);
ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep); 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_len = 1;
facilities.bulletin.to_provide[0] = calloc(1, sizeof(announcement_t)); 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; 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 si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
); );
if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) { switch (its_aid) {
TollingPaymentInfo_t* tpi = NULL; case SAID_ETC:
asn_dec_rval_t dec = uper_decode_complete( if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) {
NULL, TollingPaymentInfo_t* tpi = NULL;
&asn_DEF_TollingPaymentInfo, asn_dec_rval_t dec = uper_decode_complete(
(void**) &tpi, NULL,
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.buf, &asn_DEF_TollingPaymentInfo,
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size (void**) &tpi,
); si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.buf,
if (!dec.code) { si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
);
if (!dec.code) {
bool found = false; bool found = false;
for (int t = 0; t < bulletin->to_consume_len; ++t) { 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) { if (((tolling_info_t*)bulletin->to_consume[t]->info.internal_p)->asn->id == tpi->id) {
found = true; found = true;
break; 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) { case SAID_EVCSN:
facilities.tolling.infos.z[facilities.tolling.infos.length] = tolling_info_new(tpi); // TODO
bulletin->to_consume[bulletin->to_consume_len]->info.internal_p = facilities.tolling.infos.z[facilities.tolling.infos.length]; break;
++facilities.tolling.infos.length;
new_announcement = true;
}
} else {
ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, tpi);
}
} }
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; int rv = 0;
// Check tolling advertisements // Check tolling advertisements
if (!facilities.tolling.infos.length) { if (!facilities.tolling.infos.length /* || facilites.evcsn.infos.length */) {
return 1; return 1;
} }
@ -174,14 +188,15 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
saem->sam.version = 0; saem->sam.version = 0;
saem->sam.body.serviceInfos = calloc(1, sizeof(ServiceInfos_t)); saem->sam.body.serviceInfos = calloc(1, sizeof(ServiceInfos_t));
saem->sam.body.serviceInfos->list.count = facilities.tolling.infos.length; 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*); 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*)); saem->sam.body.serviceInfos->list.array = malloc(facilities.tolling.infos.length * sizeof(void*)); // + facilities.evcsn.infos.length * sizeof(void*);
uint8_t buf[1024]; 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] = 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)); 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); 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); 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); pthread_mutex_lock(&bulletin->lock);
for (int a = 0; a < bulletin->to_consume_len; ++a) { for (int a = 0; a < bulletin->to_consume_len; ++a) {
// Tolling // Tolling
if (facilities.tolling.enabled && if (facilities.tolling.enabled &&
bulletin->to_consume[a]->its_aid == 1 && bulletin->to_consume[a]->its_aid == 1 &&
@ -401,6 +423,9 @@ void *sa_service() {
++bulletin->to_consume[a]->n_trigger; ++bulletin->to_consume[a]->n_trigger;
bulletin->to_consume[a]->t_trigger = now; bulletin->to_consume[a]->t_trigger = now;
break; break;
default:
break;
} }
} }
} }

View File

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