From d0c692d5235f8516a4be1e0f27425aec8b0108f7 Mon Sep 17 00:00:00 2001 From: emanuel Date: Tue, 22 Feb 2022 18:12:48 +0000 Subject: [PATCH] PCM simple trigger check --- src/config.c | 4 +++- src/pcm.c | 44 ++++++++++++++++++++++++++++---------------- src/pcm.h | 6 +++++- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/config.c b/src/config.c index 25b328c..b962d94 100644 --- a/src/config.c +++ b/src/config.c @@ -314,8 +314,10 @@ int facilities_config(void* facilities_s) { } facilities->tolling.client_id = config->facilities.tpm.client_id; - // DCM + // PCM facilities->coordination.active = config->facilities.dcm.activate; + facilities->coordination.pcm_period_min = config->facilities.dcm.period_min; + facilities->coordination.pcm_period_max = config->facilities.dcm.period_max; // Replay facilities->replay = config->networking.replay.activate; diff --git a/src/pcm.c b/src/pcm.c index 32b2aee..ea2c73d 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -8,8 +8,6 @@ #include #include -#define SLEEP_TIME_MS 100 - static int are_vehicles_intersecting( it2s_tender_st_s* tA, int tA_len, uint16_t vA_length, uint16_t vA_width, it2s_tender_st_s* tB, int tB_len, uint16_t vB_length, uint16_t vB_width, @@ -512,6 +510,17 @@ cleanup: return rv; } +static bool pcm_timer_check(coordination_s* coordination, uint64_t now) { + + bool send = false; + + if (now > coordination->t_last_send_pcm + coordination->pcm_period_max) { + send = true; + } + + return send; +} + void* pc_service(void* fc) { facilities_t* facilities = (facilities_t*) fc; @@ -547,25 +556,28 @@ void* pc_service(void* fc) { while (!facilities->exit) { - rv = mk_pcm(facilities, bpr->data.buf, (uint16_t *) &bpr->data.size); - if (rv) { - continue; - } + uint64_t now = it2s_tender_get_clock(&facilities->epv); - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023); - if (enc.encoded == -1) { - syslog_err("[facilities] encoding TR for PCM failed"); - continue; - } - - queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, 3); - pthread_mutex_lock(&coordination->lock); + if (pcm_timer_check(coordination, now)) { + rv = mk_pcm(facilities, bpr->data.buf, (uint16_t *) &bpr->data.size); + if (rv) { + continue; + } + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023); + if (enc.encoded == -1) { + syslog_err("[facilities] encoding TR for PCM failed"); + continue; + } + + queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, 3); + + coordination->t_last_send_pcm = now; + } pthread_mutex_unlock(&coordination->lock); - - usleep(SLEEP_TIME_MS * 1000); + usleep(50 * 1000); } diff --git a/src/pcm.h b/src/pcm.h index 1225dca..362ac78 100644 --- a/src/pcm.h +++ b/src/pcm.h @@ -18,8 +18,12 @@ typedef struct { typedef struct coordination { bool active; - + pthread_mutex_t lock; + + uint64_t t_last_send_pcm; + uint64_t pcm_period_min; + uint64_t pcm_period_max; mc_neighbour_s neighbours[MC_MAX_NEIGHBOURS]; uint8_t neighbours_len;