it2s_tender_ -> itss_

This commit is contained in:
emanuel 2022-07-03 23:45:38 +01:00
parent 936f92c820
commit 2677dd225d
16 changed files with 233 additions and 223 deletions

View File

@ -22,6 +22,7 @@
#include <it2s-tender/constants.h> #include <it2s-tender/constants.h>
#include <it2s-tender/syslog.h> #include <it2s-tender/syslog.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
#include <it2s-obd/shmem.h> #include <it2s-obd/shmem.h>
@ -109,7 +110,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
BasicContainer_t* bc = &cam->cam.camParameters.basicContainer; BasicContainer_t* bc = &cam->cam.camParameters.basicContainer;
uint64_t now = it2s_tender_get_clock(&facilities->epv); uint64_t now = itss_time_get(&facilities->epv);
lightship_t* lightship = facilities->lightship; lightship_t* lightship = facilities->lightship;
pthread_mutex_lock(&lightship->lock); pthread_mutex_lock(&lightship->lock);
@ -117,8 +118,8 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
if (facilities->station_type != StationType_roadSideUnit) { if (facilities->station_type != StationType_roadSideUnit) {
cam->cam.generationDeltaTime = now % 65536; cam->cam.generationDeltaTime = now % 65536;
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
bc->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude; bc->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
bc->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf; bc->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
@ -168,7 +169,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
bvc_hf->heading.headingValue = facilities->epv.space.heading; bvc_hf->heading.headingValue = facilities->epv.space.heading;
bvc_hf->heading.headingConfidence = facilities->epv.space.heading_conf; bvc_hf->heading.headingConfidence = facilities->epv.space.heading_conf;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
if (lat_conf > lon_conf) { if (lat_conf > lon_conf) {
bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf; bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
@ -289,8 +290,8 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
} else { } else {
cam->cam.generationDeltaTime = now % 65536; cam->cam.generationDeltaTime = now % 65536;
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
bc->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude; bc->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
bc->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf; bc->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
@ -300,7 +301,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = SemiAxisLength_unavailable; bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = SemiAxisLength_unavailable;
bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = SemiAxisLength_unavailable; bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = SemiAxisLength_unavailable;
bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = HeadingValue_unavailable; bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = HeadingValue_unavailable;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_rsuContainerHighFrequency; cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_rsuContainerHighFrequency;
@ -382,10 +383,10 @@ lightship_t* lightship_init() {
} }
int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) { int lightship_check(lightship_t* lightship, itss_epv_t* epv) {
int rv = 0; int rv = 0;
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
pthread_mutex_lock(&lightship->lock); pthread_mutex_lock(&lightship->lock);
@ -398,8 +399,8 @@ int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) {
rv = 1; rv = 1;
} else if (now > lightship->next_cam_min) { } else if (now > lightship->next_cam_min) {
it2s_tender_lock_space(epv); itss_space_lock(epv);
it2s_tender_get_space(epv); itss_space_get(epv);
// Check heading delta > 4º // Check heading delta > 4º
int diff = epv->space.heading - lightship->pos_history[0]->heading; int diff = epv->space.heading - lightship->pos_history[0]->heading;
@ -418,7 +419,7 @@ int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) {
if (avg_speed * delta_time > 4) rv = 1; if (avg_speed * delta_time > 4) rv = 1;
} }
} }
it2s_tender_unlock_space(epv); itss_space_unlock(epv);
} }
@ -444,8 +445,8 @@ int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) {
return rv; return rv;
} }
void lightship_reset_timer(lightship_t* lightship, it2s_tender_epv_t* epv) { void lightship_reset_timer(lightship_t* lightship, itss_epv_t* epv) {
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
pthread_mutex_lock(&lightship->lock); pthread_mutex_lock(&lightship->lock);
@ -462,12 +463,12 @@ void lightship_reset_timer(lightship_t* lightship, it2s_tender_epv_t* epv) {
pthread_mutex_unlock(&lightship->lock); pthread_mutex_unlock(&lightship->lock);
} }
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) { enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, itss_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0; int rv = 0;
facilities_t* facilities = (facilities_t*) fc; facilities_t* facilities = (facilities_t*) fc;
lightship_t *lightship = ((facilities_t*) fc)->lightship; lightship_t *lightship = ((facilities_t*) fc)->lightship;
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
// Check permissions // Check permissions
if (ssp) { if (ssp) {
@ -674,14 +675,14 @@ enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, it2
return rv; return rv;
} }
static int check_pz(lightship_t *lightship, it2s_tender_epv_t* epv) { static int check_pz(lightship_t *lightship, itss_epv_t* epv) {
bool is_inside = false; bool is_inside = false;
it2s_tender_lock_space(epv); itss_space_lock(epv);
it2s_tender_get_space(epv); itss_space_get(epv);
double lat = epv->space.latitude/10000000.0; double lat = epv->space.latitude/10000000.0;
double lon = epv->space.longitude/10000000.0; double lon = epv->space.longitude/10000000.0;
it2s_tender_unlock_space(epv); itss_space_unlock(epv);
pthread_mutex_lock(&lightship->lock); pthread_mutex_lock(&lightship->lock);
@ -757,7 +758,7 @@ void *ca_service(void *fc) {
bpr->gn.communicationProfile = 0; bpr->gn.communicationProfile = 0;
if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) bpr->gn.communicationProfile = 1; if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) bpr->gn.communicationProfile = 1;
uint64_t id = rand() + 1; uint32_t id = itss_id(bpr->data.buf, bpr->data.size);
bpr->id = id; bpr->id = id;
fmi->id = id; fmi->id = id;
@ -773,9 +774,9 @@ void *ca_service(void *fc) {
continue; continue;
} }
it2s_tender_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp"); itss_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
it2s_tender_queue_send(facilities->tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message"); itss_queue_send(facilities->tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
lightship_reset_timer(facilities->lightship, &facilities->epv); lightship_reset_timer(facilities->lightship, &facilities->epv);
@ -784,23 +785,23 @@ void *ca_service(void *fc) {
pthread_mutex_lock(&facilities->id.lock); pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id; uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, ItsPduHeader__messageID_cam, NULL, bpr->data.buf, bpr->data.size); itss_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, ItsPduHeader__messageID_cam, NULL, bpr->data.buf, bpr->data.size);
} }
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
bpr->data.buf, bpr->data.buf,
bpr->data.size, bpr->data.size,
id, id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
} }
} }
} }

View File

@ -88,10 +88,10 @@ typedef struct lightship {
lightship_t* lightship_init(); lightship_t* lightship_init();
int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv); int lightship_check(lightship_t* lightship, itss_epv_t* epv);
void lightship_reset_timer(lightship_t*lightship, it2s_tender_epv_t* epv); void lightship_reset_timer(lightship_t*lightship, itss_epv_t* epv);
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t* bpi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len); enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t* bpi, CAM_t* cam, itss_epv_t* epv, uint8_t* ssp, uint32_t ssp_len);
void* ca_service(void* fc); void* ca_service(void* fc);
#endif #endif

View File

@ -507,8 +507,8 @@ int facilities_config(void* facilities_s) {
// Logging // Logging
facilities->logging.recorder = config->facilities.logging.management; facilities->logging.recorder = config->facilities.logging.management;
if (config->general.logging.enabled && config->facilities.logging.dbms) { if (config->general.logging.enabled && config->facilities.logging.dbms) {
facilities->logging.dbms = calloc(1, sizeof(it2s_tender_database_s)); facilities->logging.dbms = calloc(1, sizeof(itss_db_t));
if (it2s_tender_db_init( if (itss_db_init(
facilities->logging.dbms, facilities->logging.dbms,
config->general.logging.database, config->general.logging.database,
config->general.logging.table_style, config->general.logging.table_style,

View File

@ -23,6 +23,7 @@
#include <it2s-tender/space.h> #include <it2s-tender/space.h>
#include <it2s-tender/syslog.h> #include <it2s-tender/syslog.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
#define PI 3.141592654 #define PI 3.141592654
@ -145,10 +146,10 @@ dissemination_t* dissemination_init(){
} }
int dissemination_check(dissemination_t* dissemination, it2s_tender_epv_t* epv, int f) { int dissemination_check(dissemination_t* dissemination, itss_epv_t* epv, int f) {
int rv = 0; int rv = 0;
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
pthread_mutex_lock(&dissemination->lock); // mutex is used to lock shared resources pthread_mutex_lock(&dissemination->lock); // mutex is used to lock shared resources
@ -175,9 +176,9 @@ int dissemination_check(dissemination_t* dissemination, it2s_tender_epv_t* epv,
} }
void dissemination_reset_timer(dissemination_t* dissemination, it2s_tender_epv_t* epv, int f){ void dissemination_reset_timer(dissemination_t* dissemination, itss_epv_t* epv, int f){
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
/* Both cases for RSU and OBU */ /* Both cases for RSU and OBU */
@ -516,16 +517,16 @@ static int mk_cpm(facilities_t* facilities, uint8_t *bdr_oer, uint32_t *bdr_len,
cpm_tx->header.stationID = facilities->id.station_id; cpm_tx->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
uint64_t generationDeltaTime = it2s_tender_get_clock(&facilities->epv) % 65536; // generationDeltaTime = TimestampIts mod 65 536 uint64_t generationDeltaTime = itss_time_get(&facilities->epv) % 65536; // generationDeltaTime = TimestampIts mod 65 536
int32_t lat, lon, alt, alt_conf; int32_t lat, lon, alt, alt_conf;
pthread_mutex_lock(&facilities->epv.space.lock); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude; lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude; lon = facilities->epv.space.longitude;
alt = facilities->epv.space.altitude; alt = facilities->epv.space.altitude;
alt_conf = facilities->epv.space.altitude_conf; alt_conf = facilities->epv.space.altitude_conf;
pthread_mutex_unlock(&facilities->epv.space.lock); itss_space_unlock(&facilities->epv);
cpm_tx->cpm.generationDeltaTime = generationDeltaTime; cpm_tx->cpm.generationDeltaTime = generationDeltaTime;
cpm_tx->cpm.cpmParameters.managementContainer.stationType = StationType_roadSideUnit; cpm_tx->cpm.cpmParameters.managementContainer.stationType = StationType_roadSideUnit;
@ -716,7 +717,7 @@ void *cp_service(void *fc){
if(mk_cpm(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size, fmi->data.buf, (uint32_t *) &fmi->data.size, history_list, valid_array, history_timestamp) == 1) if(mk_cpm(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size, fmi->data.buf, (uint32_t *) &fmi->data.size, history_list, valid_array, history_timestamp) == 1)
continue; continue;
uint64_t id = rand() + 1; uint32_t id = itss_id(bpr->data.buf, bpr->data.size);
bpr->id = id; bpr->id = id;
fmi->id = id; fmi->id = id;
@ -735,10 +736,10 @@ void *cp_service(void *fc){
} }
/* Create thread to send packet to the Transport Layer (=3) */ /* Create thread to send packet to the Transport Layer (=3) */
it2s_tender_queue_send(facilities->tx_queue, tr_oer, enc_tdr.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp"); itss_queue_send(facilities->tx_queue, tr_oer, enc_tdr.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
/* Create thread to send packet to the Applications Layer (=5) */ /* Create thread to send packet to the Applications Layer (=5) */
it2s_tender_queue_send(facilities->tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message"); itss_queue_send(facilities->tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
/*Reset Timer for dissemination control */ /*Reset Timer for dissemination control */
dissemination_reset_timer(facilities->dissemination, &facilities->epv,1); dissemination_reset_timer(facilities->dissemination, &facilities->epv,1);
@ -748,22 +749,22 @@ void *cp_service(void *fc){
pthread_mutex_lock(&facilities->id.lock); pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id; uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, 14, NULL, bpr->data.buf, bpr->data.size); itss_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, 14, NULL, bpr->data.buf, bpr->data.size);
} }
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
bpr->data.buf, bpr->data.buf,
bpr->data.size, bpr->data.size,
bpr->id, bpr->id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
} }
} }

View File

@ -69,7 +69,7 @@ static int permissions_check(int cause_code, uint8_t* permissions, uint8_t permi
} }
static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) { static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, itss_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0; int rv = 0;
uint64_t e_detection_time, e_reference_time; uint64_t e_detection_time, e_reference_time;
@ -94,7 +94,7 @@ static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, it2s_tender_epv_
e_validity_duration = 600 * 1000; e_validity_duration = 600 * 1000;
} }
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
if (e_detection_time + e_validity_duration < now) { if (e_detection_time + e_validity_duration < now) {
return EVENT_PASSED; return EVENT_PASSED;
@ -155,9 +155,9 @@ static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, it2s_tender_epv_
return EVENT_NEW; return EVENT_NEW;
} }
static int event_add(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64_t* id) { static int event_add(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id) {
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
uint64_t e_detection_time, e_reference_time; uint64_t e_detection_time, e_reference_time;
asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time); asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time);
@ -225,9 +225,9 @@ static int event_add(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64_t*
else return 0; // Event added to db else return 0; // Event added to db
} }
static int event_update(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64_t* id) { static int event_update(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id) {
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
uint64_t e_detection_time, e_reference_time; uint64_t e_detection_time, e_reference_time;
asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time); asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time);
@ -308,7 +308,7 @@ static int event_update(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64
else return 0; // Event updated else return 0; // Event updated
} }
enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) { enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0; int rv = 0;
switch (rv = event_check(den, denm, epv, ssp, ssp_len)) { switch (rv = event_check(den, denm, epv, ssp, ssp_len)) {
case EVENT_NEW: case EVENT_NEW:
@ -384,7 +384,7 @@ void* den_service(void *fc) {
uint32_t sleep_count = 0; uint32_t sleep_count = 0;
while (!facilities->exit) { while (!facilities->exit) {
now = it2s_tender_get_clock(&facilities->epv); now = itss_time_get(&facilities->epv);
pthread_mutex_lock(&den->lock); pthread_mutex_lock(&den->lock);
for (int i = 0; i < den->n_max_events; ++i) { for (int i = 0; i < den->n_max_events; ++i) {

View File

@ -67,7 +67,7 @@ typedef struct cc_ssp_bm {
* @param ssp permissions * @param ssp permissions
* @return 0 if event OK, 1 if event NOK * @return 0 if event OK, 1 if event NOK
*/ */
enum EVENT_CHECK_R event_manage(den_t* den, DENM_t* denm, it2s_tender_epv_t* epv, uint64_t* id, uint8_t* ssp, uint32_t ssp_len); enum EVENT_CHECK_R event_manage(den_t* den, DENM_t* denm, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint32_t ssp_len);
void* den_service(void* fc); void* den_service(void* fc);

View File

@ -40,6 +40,7 @@
#include <it2s-tender/trajectory.h> #include <it2s-tender/trajectory.h>
#include <it2s-tender/syslog.h> #include <it2s-tender/syslog.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
static int transport_indication(facilities_t *facilities, void* responder, void* security_socket, uint8_t *msg, uint32_t msg_len) { static int transport_indication(facilities_t *facilities, void* responder, void* security_socket, uint8_t *msg, uint32_t msg_len) {
int rv = 0, code = 0; int rv = 0, code = 0;
@ -93,7 +94,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
switch (tpi->present) { switch (tpi->present) {
case TransportPacketIndication_PR_btp: case TransportPacketIndication_PR_btp:
id = tpi->choice.btp.id; id = tpi->choice.btp.id;
syslog_debug("[facilities]<- TI.packet.btp | id:%ld size:%dB", id, msg_len); syslog_debug("[facilities]<- TI.packet.btp | id:%08x size:%dB", (uint32_t) id, msg_len);
// Parse message // Parse message
switch (tpi->choice.btp.destinationPort) { switch (tpi->choice.btp.destinationPort) {
case Port_cam: case Port_cam:
@ -326,7 +327,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
tpr->gn->destinationAddress.buf = calloc(1, 6); tpr->gn->destinationAddress.buf = calloc(1, 6);
tpr->gn->destinationAddress.size = 6; tpr->gn->destinationAddress.size = 6;
tpr->id = rand() + 1; tpr->id = itss_id(tpr->data.buf, tpr->data.size);
buf[0] = 4; buf[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1);
@ -336,7 +337,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, tpr->id, "TR.packet.tcp"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, tpr->id, "TR.packet.tcp");
} else { } else {
if (facilities->tolling.enabled && srep->data->choice.tlsRecv.data.size) { if (facilities->tolling.enabled && srep->data->choice.tlsRecv.data.size) {
@ -379,7 +380,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
buffer[0] = 4; // Facilities buffer[0] = 4; // Facilities
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buffer+1, ITSS_SDU_MAX_LEN-1); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buffer+1, ITSS_SDU_MAX_LEN-1);
it2s_tender_queue_send(facilities->tx_queue, buffer, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message"); itss_queue_send(facilities->tx_queue, buffer, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
} }
// Logging // Logging
@ -387,20 +388,20 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
pthread_mutex_lock(&facilities->id.lock); pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id; uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, false, its_msg_type, NULL, packet, packet_len); itss_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, false, its_msg_type, NULL, packet, packet_len);
} }
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buf, buf,
buf_len, buf_len,
tpi->choice.btp.data.buf, tpi->choice.btp.data.buf,
tpi->choice.btp.data.size, tpi->choice.btp.data.size,
tpi->choice.btp.id, tpi->choice.btp.id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
false); false);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buf, e, ITSS_MANAGEMENT, tpi->choice.btp.id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buf, e, ITSS_MANAGEMENT, tpi->choice.btp.id, "MReq.packet.set");
} }
} }
@ -620,7 +621,7 @@ static int networking_indication(facilities_t* facilities, void* responder, uint
*ni->choice.data.mobileNeighbour) { *ni->choice.data.mobileNeighbour) {
pthread_mutex_lock(&facilities->lightship->lock); pthread_mutex_lock(&facilities->lightship->lock);
facilities->lightship->last_vehicle = it2s_tender_get_clock(&facilities->epv); facilities->lightship->last_vehicle = itss_time_get(&facilities->epv);
facilities->lightship->is_vehicle_near = true; facilities->lightship->is_vehicle_near = true;
pthread_mutex_unlock(&facilities->lightship->lock); pthread_mutex_unlock(&facilities->lightship->lock);
} }
@ -650,7 +651,7 @@ static int management_indication(facilities_t* facilities, void* responder, uint
zmq_send(responder, &code, 1, 0); zmq_send(responder, &code, 1, 0);
if (mi->present == ManagementIndication_PR_attributes) { if (mi->present == ManagementIndication_PR_attributes) {
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
facilities->epv.space.latitude = mi->choice.attributes.coordinates.latitude; facilities->epv.space.latitude = mi->choice.attributes.coordinates.latitude;
facilities->epv.space.latitude_conf = mi->choice.attributes.coordinates.latitudeConfidence; facilities->epv.space.latitude_conf = mi->choice.attributes.coordinates.latitudeConfidence;
facilities->epv.space.longitude = mi->choice.attributes.coordinates.longitude; facilities->epv.space.longitude = mi->choice.attributes.coordinates.longitude;
@ -661,9 +662,9 @@ static int management_indication(facilities_t* facilities, void* responder, uint
facilities->epv.space.heading_conf = mi->choice.attributes.heading.headingConfidence; facilities->epv.space.heading_conf = mi->choice.attributes.heading.headingConfidence;
facilities->epv.space.altitude = mi->choice.attributes.altitude.altitudeValue; facilities->epv.space.altitude = mi->choice.attributes.altitude.altitudeValue;
facilities->epv.space.altitude_conf = mi->choice.attributes.altitude.altitudeConfidence; facilities->epv.space.altitude_conf = mi->choice.attributes.altitude.altitudeConfidence;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
it2s_tender_lock_trajectory(&facilities->epv); itss_trajectory_lock(&facilities->epv);
if (mi->choice.attributes.trajectory) { if (mi->choice.attributes.trajectory) {
facilities->epv.trajectory.len = mi->choice.attributes.trajectory->list.count; facilities->epv.trajectory.len = mi->choice.attributes.trajectory->list.count;
for (int i = 0; i < mi->choice.attributes.trajectory->list.count; ++i) { for (int i = 0; i < mi->choice.attributes.trajectory->list.count; ++i) {
@ -672,11 +673,11 @@ static int management_indication(facilities_t* facilities, void* responder, uint
asn_INTEGER2ulong(&mi->choice.attributes.trajectory->list.array[i]->timestamp, (unsigned long long*) &facilities->epv.trajectory.path[i].timestamp); asn_INTEGER2ulong(&mi->choice.attributes.trajectory->list.array[i]->timestamp, (unsigned long long*) &facilities->epv.trajectory.path[i].timestamp);
} }
} }
it2s_tender_unlock_trajectory(&facilities->epv); itss_trajectory_unlock(&facilities->epv);
it2s_tender_lock_time(&facilities->epv); itss_time_lock(&facilities->epv);
asn_INTEGER2ulong(&mi->choice.attributes.clock, (unsigned long long*) &facilities->epv.time.clock); asn_INTEGER2ulong(&mi->choice.attributes.clock, (unsigned long long*) &facilities->epv.time.clock);
it2s_tender_unlock_time(&facilities->epv); itss_time_unlock(&facilities->epv);
} }
cleanup: cleanup:
@ -691,7 +692,7 @@ void* tx(void* fc) {
facilities_t *facilities = (facilities_t*) fc; facilities_t *facilities = (facilities_t*) fc;
it2s_tender_queue_t* queue = facilities->tx_queue; itss_queue_t* queue = facilities->tx_queue;
uint8_t code; uint8_t code;
int wait_ms = 1000; int wait_ms = 1000;
@ -708,7 +709,7 @@ void* tx(void* fc) {
zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int)); zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(management_socket, facilities->zmq.management_address); zmq_connect(management_socket, facilities->zmq.management_address);
it2s_tender_queue_t* stream = it2s_tender_queue_new(); itss_queue_t* stream = itss_queue_new();
while (!facilities->exit) { while (!facilities->exit) {
pthread_mutex_lock(&queue->lock); pthread_mutex_lock(&queue->lock);
@ -730,31 +731,31 @@ void* tx(void* fc) {
for (int i = 0; i < stream->len; ++i) { for (int i = 0; i < stream->len; ++i) {
switch (stream->destination[i]) { switch (stream->destination[i]) {
case ITSS_TRANSPORT: case ITSS_TRANSPORT:
syslog_debug("[facilities]-> %s ->[transport] | id:%ld size:%dB", syslog_debug("[facilities]-> %s ->[transport] | id:%08x size:%dB",
stream->info_msg[i], stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
zmq_send(transport_socket, stream->packet[i], stream->packet_len[i], 0); zmq_send(transport_socket, stream->packet[i], stream->packet_len[i], 0);
rv = zmq_recv(transport_socket, &code, 1, 0); rv = zmq_recv(transport_socket, &code, 1, 0);
if (rv == -1) { if (rv == -1) {
syslog_err("[facilities]-> %s ->[transport] | id:%ld size:%dB <TIMEOUT>", syslog_err("[facilities]-> %s ->[transport] | id:%08x size:%dB <TIMEOUT>",
stream->info_msg[i], stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
} }
break; break;
case ITSS_APPLICATIONS: case ITSS_APPLICATIONS:
syslog_debug("[facilities]-> %s ->[applications] | id:%ld size:%dB", syslog_debug("[facilities]-> %s ->[applications] | id:%08x size:%dB",
stream->info_msg[i], stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
zmq_send(applications_socket, stream->packet[i], stream->packet_len[i], 0); zmq_send(applications_socket, stream->packet[i], stream->packet_len[i], 0);
rv = zmq_recv(applications_socket, &code, 1, 0); rv = zmq_recv(applications_socket, &code, 1, 0);
if (rv == -1) { if (rv == -1) {
syslog_err("[facilities]-> %s ->[applications] | id:%ld size:%dB <TIMEOUT>", syslog_err("[facilities]-> %s ->[applications] | id:%08x size:%dB <TIMEOUT>",
stream->info_msg[i], stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
} }
break; break;
case ITSS_MANAGEMENT: case ITSS_MANAGEMENT:
zmq_send(management_socket, stream->packet[i], stream->packet_len[i], 0); zmq_send(management_socket, stream->packet[i], stream->packet_len[i], 0);
rv = zmq_recv(management_socket, &code, 1, 0); rv = zmq_recv(management_socket, &code, 1, 0);
if (rv == -1) { if (rv == -1) {
syslog_err("[facilities]-> %s ->[management] | id:%ld size:%dB <TIMEOUT>", syslog_err("[facilities]-> %s ->[management] | id:%08x size:%dB <TIMEOUT>",
stream->info_msg[i], stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
} }
break; break;
} }
@ -772,7 +773,7 @@ int main() {
facilities_t facilities = {0}; facilities_t facilities = {0};
facilities.zmq.ctx = zmq_ctx_new(); facilities.zmq.ctx = zmq_ctx_new();
facilities.tx_queue = it2s_tender_queue_new(); facilities.tx_queue = itss_queue_new();
facilities.lightship = lightship_init(); facilities.lightship = lightship_init();
facilities.den = calloc(1, sizeof(den_t)); facilities.den = calloc(1, sizeof(den_t));
facilities.infrastructure = calloc(1, sizeof(infrastructure_t)); facilities.infrastructure = calloc(1, sizeof(infrastructure_t));

View File

@ -48,7 +48,7 @@ typedef struct facilities {
} zmq; } zmq;
// Transmitter // Transmitter
it2s_tender_queue_t* tx_queue; itss_queue_t* tx_queue;
// CA // CA
lightship_t* lightship; lightship_t* lightship;
@ -74,7 +74,7 @@ typedef struct facilities {
// Logging // Logging
struct { struct {
bool recorder; bool recorder;
it2s_tender_database_s* dbms; itss_db_t* dbms;
} logging; } logging;
int station_type; int station_type;
@ -98,7 +98,7 @@ typedef struct facilities {
} change; } change;
} id; } id;
it2s_tender_epv_t epv; itss_epv_t epv;
bool exit; bool exit;
} facilities_t; } facilities_t;

View File

@ -60,10 +60,10 @@ static int permissions_check(int diid, uint8_t* permissions, uint8_t permissions
} }
static enum SERVICE_EVAL_R service_check(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, it2s_tender_epv_t* epv, uint8_t* ssp, uint16_t ssp_len) { static enum SERVICE_EVAL_R service_check(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint8_t* ssp, uint16_t ssp_len) {
int rv = 0; int rv = 0;
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
switch (type) { switch (type) {
case SERVICE_IVI: case SERVICE_IVI:
@ -252,7 +252,7 @@ static enum SERVICE_EVAL_R service_check(infrastructure_t* infrastructure, enum
return SERVICE_NEW; return SERVICE_NEW;
} }
static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, it2s_tender_epv_t* epv, uint64_t* id) { static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint64_t* id) {
switch (type) { switch (type) {
case SERVICE_IVI: case SERVICE_IVI:
@ -263,7 +263,7 @@ static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type,
IVIM_t* ivim = (IVIM_t*) its_msg; IVIM_t* ivim = (IVIM_t*) its_msg;
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
uint64_t timestamp, valid_to, valid_from; uint64_t timestamp, valid_to, valid_from;
if (!ivim->ivi.mandatory.timeStamp) { if (!ivim->ivi.mandatory.timeStamp) {
@ -338,7 +338,7 @@ static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type,
else return 0; // Services added to db else return 0; // Services added to db
} }
static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, it2s_tender_epv_t* epv, uint64_t* id) { static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint64_t* id) {
switch (type) { switch (type) {
case SERVICE_IVI: case SERVICE_IVI:
@ -349,7 +349,7 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty
IVIM_t* ivim = (IVIM_t*) its_msg; IVIM_t* ivim = (IVIM_t*) its_msg;
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
uint64_t timestamp, valid_to, valid_from; uint64_t timestamp, valid_to, valid_from;
if (!ivim->ivi.mandatory.timeStamp) { if (!ivim->ivi.mandatory.timeStamp) {
@ -445,7 +445,7 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty
else return 0; // Event updated else return 0; // Event updated
} }
enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, it2s_tender_epv_t* epv, uint64_t* id, uint8_t* ssp, uint16_t ssp_len) { enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint16_t ssp_len) {
int rv = 0; int rv = 0;
switch (rv = service_check(infrastructure, type, its_msg, epv, ssp, ssp_len)) { switch (rv = service_check(infrastructure, type, its_msg, epv, ssp, ssp_len)) {
case SERVICE_NEW: case SERVICE_NEW:
@ -522,7 +522,7 @@ void* infrastructure_service(void *fc) {
uint32_t sleep_count = 0; uint32_t sleep_count = 0;
while (!facilities->exit) { while (!facilities->exit) {
now = it2s_tender_get_clock(&facilities->epv); now = itss_time_get(&facilities->epv);
int n_awaiting_services = 0; int n_awaiting_services = 0;
pthread_mutex_lock(&infrastructure->lock); pthread_mutex_lock(&infrastructure->lock);

View File

@ -86,7 +86,7 @@ enum SERVICE_EVAL_R {
SERVICE_BAD_PERMISSIONS SERVICE_BAD_PERMISSIONS
}; };
enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, it2s_tender_epv_t* epv, uint64_t* id, uint8_t* ssp, uint16_t ssp_len); enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint16_t ssp_len);
void* infrastructure_service(void* fc); void* infrastructure_service(void* fc);

View File

@ -15,6 +15,7 @@
#include <it2s-tender/time.h> #include <it2s-tender/time.h>
#include <it2s-tender/syslog.h> #include <it2s-tender/syslog.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
int facilities_request_result_accepted(void* responder) { int facilities_request_result_accepted(void* responder) {
int rv = 0; int rv = 0;
@ -47,12 +48,6 @@ int facilities_request_result_rejected(void* responder) {
int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesMessageRequest_t* frm) { int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesMessageRequest_t* frm) {
int rv = 0; int rv = 0;
uint64_t id = 0;
if (!frm->id) {
id = rand();
} else if (*frm->id == 0) {
id = rand();
}
TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t)); TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t));
tr->present = TransportRequest_PR_packet; tr->present = TransportRequest_PR_packet;
@ -118,6 +113,13 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
goto cleanup; goto cleanup;
} }
uint64_t id = 0;
if (!frm->id) {
id = itss_id(frm->data.buf, frm->data.size);
} else if (*frm->id == 0) {
id = itss_id(frm->data.buf, frm->data.size);
}
bool is_update = false; bool is_update = false;
int managed_msg = false; int managed_msg = false;
@ -233,7 +235,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
uint64_t valid_to, valid_from; uint64_t valid_to, valid_from;
if (!((IVIM_t*) its_msg)->ivi.mandatory.validFrom) { if (!((IVIM_t*) its_msg)->ivi.mandatory.validFrom) {
valid_from = it2s_tender_get_clock(&facilities->epv);; valid_from = itss_time_get(&facilities->epv);;
} else { } else {
asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, (unsigned long long*) &valid_from); asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, (unsigned long long*) &valid_from);
} }
@ -308,24 +310,24 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp"); itss_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
} }
// Logging // Logging
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
frm->data.buf, frm->data.buf,
frm->data.size, frm->data.size,
id, id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
} }
} }

View File

@ -8,6 +8,7 @@
#include <it2s-tender/syslog.h> #include <it2s-tender/syslog.h>
#include <it2s-tender/space.h> #include <it2s-tender/space.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
#include <itss-transport/TransportRequest.h> #include <itss-transport/TransportRequest.h>
#include <itss-security/SecurityRequest.h> #include <itss-security/SecurityRequest.h>
#include <itss-security/SecurityReply.h> #include <itss-security/SecurityReply.h>
@ -123,7 +124,7 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne
if (new_announcement && bulletin->to_consume_len < MAX_ANNOUNCEMENTS_LEN - 1) { if (new_announcement && bulletin->to_consume_len < MAX_ANNOUNCEMENTS_LEN - 1) {
bulletin->to_consume[bulletin->to_consume_len]->its_aid = its_aid; bulletin->to_consume[bulletin->to_consume_len]->its_aid = its_aid;
bulletin->to_consume[bulletin->to_consume_len]->station_id = saem->header.stationID; bulletin->to_consume[bulletin->to_consume_len]->station_id = saem->header.stationID;
bulletin->to_consume[bulletin->to_consume_len]->timestamp = it2s_tender_get_clock(&facilities->epv); bulletin->to_consume[bulletin->to_consume_len]->timestamp = itss_time_get(&facilities->epv);
if (neighbour) { if (neighbour) {
bulletin->to_consume[bulletin->to_consume_len]->certificate_id = malloc(8); bulletin->to_consume[bulletin->to_consume_len]->certificate_id = malloc(8);
memcpy(bulletin->to_consume[bulletin->to_consume_len]->certificate_id, neighbour, 8); memcpy(bulletin->to_consume[bulletin->to_consume_len]->certificate_id, neighbour, 8);
@ -323,35 +324,35 @@ void *sa_service(void *fc) {
rv = mk_saem(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size); rv = mk_saem(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size);
if (!rv) { if (!rv) {
bpr->id = rand() + 1; bpr->id = itss_id(bpr->data.buf, bpr->data.size);
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] encoding TR for SAEM failed"); syslog_err("[facilities] encoding TR for SAEM failed");
continue; continue;
} else { } else {
it2s_tender_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); itss_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
// Logging // Logging
if (facilities->logging.dbms) { if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock); pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id; uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, messageID_saem, NULL, bpr->data.buf, bpr->data.size); itss_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, messageID_saem, NULL, bpr->data.buf, bpr->data.size);
} }
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
bpr->data.buf, bpr->data.buf,
bpr->data.size, bpr->data.size,
bpr->id, bpr->id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
} }
} }
} }
@ -361,13 +362,13 @@ void *sa_service(void *fc) {
++mk_saem_n_sleep; ++mk_saem_n_sleep;
int32_t lat, lon; int32_t lat, lon;
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude; lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude; lon = facilities->epv.space.longitude;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
uint64_t now = it2s_tender_get_clock(&facilities->epv); uint64_t now = itss_time_get(&facilities->epv);
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) {

View File

@ -10,6 +10,7 @@
#include <it2s-tender/space.h> #include <it2s-tender/space.h>
#include <it2s-tender/geodesy.h> #include <it2s-tender/geodesy.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -24,13 +25,13 @@ int tpm_is_inside_zone(void* fc, tolling_info_t* ti) {
facilities_t* facilities = (facilities_t*) fc; facilities_t* facilities = (facilities_t*) fc;
double point[2]; double point[2];
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
point[0] = facilities->epv.space.latitude/1.0e7; point[0] = facilities->epv.space.latitude/1.0e7;
point[1] = facilities->epv.space.longitude/1.0e7; point[1] = facilities->epv.space.longitude/1.0e7;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
if (it2s_tender_is_inside_polygon(point, ti->zone.polygon, ti->zone.polygon_len)) { if (itss_is_inside_polygon(point, ti->zone.polygon, ti->zone.polygon_len)) {
return 1; return 1;
} }
@ -53,7 +54,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
} }
pthread_mutex_lock(&facilities->epv.time.lock); pthread_mutex_lock(&facilities->epv.time.lock);
tolling->tz = it2s_tender_get_now(TIME_MICROSECONDS) ; tolling->tz = itss_ts_get(TIME_MICROSECONDS) ;
pthread_mutex_unlock(&facilities->epv.time.lock); pthread_mutex_unlock(&facilities->epv.time.lock);
TPM_t* tpm = NULL; TPM_t* tpm = NULL;
@ -81,21 +82,21 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t)); tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t));
// timestamp // timestamp
asn_ulong2INTEGER(&tpm->tpm->timestamp, it2s_tender_get_clock(&facilities->epv)); asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get(&facilities->epv));
// stationType // stationType
tpm->tpm->stationType = facilities->station_type; tpm->tpm->stationType = facilities->station_type;
// referencePosition // referencePosition
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
tpm->tpm->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude; tpm->tpm->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
tpm->tpm->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf; tpm->tpm->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
tpm->tpm->referencePosition.latitude = facilities->epv.space.latitude; tpm->tpm->referencePosition.latitude = facilities->epv.space.latitude;
tpm->tpm->referencePosition.longitude = facilities->epv.space.longitude; tpm->tpm->referencePosition.longitude = facilities->epv.space.longitude;
uint16_t lat_conf = facilities->epv.space.latitude_conf; uint16_t lat_conf = facilities->epv.space.latitude_conf;
uint16_t lon_conf = facilities->epv.space.longitude_conf; uint16_t lon_conf = facilities->epv.space.longitude_conf;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
if (lat_conf > lon_conf) { if (lat_conf > lon_conf) {
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf; tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf; tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf;
@ -237,8 +238,6 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
tr->choice.packet.present = TransportPacketRequest_PR_btp; tr->choice.packet.present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp;
bpr->id = rand() + 1;
id = bpr->id;
bpr->gn.securityProfile.encrypt = true; bpr->gn.securityProfile.encrypt = true;
bpr->gn.securityProfile.sign = true; bpr->gn.securityProfile.sign = true;
@ -252,6 +251,9 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
bpr->data.buf = malloc(tpm_uper_len); bpr->data.buf = malloc(tpm_uper_len);
memcpy(bpr->data.buf, tpm_uper, tpm_uper_len); memcpy(bpr->data.buf, tpm_uper, tpm_uper_len);
bpr->id = itss_id(bpr->data.buf, bpr->data.size);
id = bpr->id;
bpr->destinationPort = 7011; bpr->destinationPort = 7011;
bpr->btpType = BTPType_btpB; bpr->btpType = BTPType_btpB;
bpr->gn.destinationAddress.buf = malloc(6); bpr->gn.destinationAddress.buf = malloc(6);
@ -339,7 +341,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id,
tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp"); tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp");
// Logging // Logging
@ -347,7 +349,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
pthread_mutex_lock(&facilities->id.lock); pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id; uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len); itss_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len);
} }
// send to [applications] // send to [applications]
@ -364,22 +366,22 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)");
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
tpm_uper, tpm_uper,
tpm_uper_len, tpm_uper_len,
id, id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
} }
} }
@ -557,21 +559,21 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t)); tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t));
// timestamp // timestamp
asn_ulong2INTEGER(&tpm->tpm->timestamp, it2s_tender_get_clock(&facilities->epv)); asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get(&facilities->epv));
// stationType // stationType
tpm->tpm->stationType = facilities->station_type; tpm->tpm->stationType = facilities->station_type;
// referencePosition // referencePosition
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
tpm->tpm->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude; tpm->tpm->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
tpm->tpm->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf; tpm->tpm->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
tpm->tpm->referencePosition.latitude = facilities->epv.space.latitude; tpm->tpm->referencePosition.latitude = facilities->epv.space.latitude;
tpm->tpm->referencePosition.longitude = facilities->epv.space.longitude; tpm->tpm->referencePosition.longitude = facilities->epv.space.longitude;
uint16_t lat_conf = facilities->epv.space.latitude_conf; uint16_t lat_conf = facilities->epv.space.latitude_conf;
uint16_t lon_conf = facilities->epv.space.longitude_conf; uint16_t lon_conf = facilities->epv.space.longitude_conf;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
if (lat_conf > lon_conf) { if (lat_conf > lon_conf) {
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf; tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf; tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf;
@ -678,8 +680,6 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
tr->choice.packet.present = TransportPacketRequest_PR_btp; tr->choice.packet.present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp;
bpr->id = rand() + 1;
id = bpr->id;
bpr->gn.securityProfile.encrypt = true; bpr->gn.securityProfile.encrypt = true;
bpr->gn.securityProfile.sign = true; bpr->gn.securityProfile.sign = true;
@ -688,6 +688,9 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
bpr->data.buf = malloc(tpm_uper_len); bpr->data.buf = malloc(tpm_uper_len);
memcpy(bpr->data.buf, tpm_uper, tpm_uper_len); memcpy(bpr->data.buf, tpm_uper, tpm_uper_len);
bpr->id = itss_id(bpr->data.buf, bpr->data.size);
id = bpr->id;
bpr->destinationPort = 7011; bpr->destinationPort = 7011;
bpr->btpType = BTPType_btpB; bpr->btpType = BTPType_btpB;
bpr->gn.destinationAddress.buf = malloc(6); bpr->gn.destinationAddress.buf = malloc(6);
@ -778,7 +781,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id,
tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp"); tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp");
// Logging // Logging
@ -786,7 +789,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
pthread_mutex_lock(&facilities->id.lock); pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id; uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len); itss_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len);
} }
// send to [applications] // send to [applications]
@ -803,21 +806,21 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)");
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
tpm_uper, tpm_uper,
tpm_uper_len, tpm_uper_len,
id, id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
} }
} }
@ -829,7 +832,7 @@ cleanup:
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
} }
static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_socket, it2s_tender_queue_t* tx_queue, it2s_tender_epv_t* epv, uint8_t* neighbour, uint8_t* src_addr) { static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_socket, itss_queue_t* tx_queue, itss_epv_t* epv, uint8_t* neighbour, uint8_t* src_addr) {
if (!tpm_rx->tpm->tollingType) { if (!tpm_rx->tpm->tollingType) {
syslog_err("[facilities] [tolling] received TPM does not have a type"); syslog_err("[facilities] [tolling] received TPM does not have a type");
@ -1015,7 +1018,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); int32_t rl = zmq_recv(security_socket, buf, buf_len, 0);
syslog_debug("[facilities]<-[security] SecurityReply.tlsClose (%dB)", rl); syslog_debug("[facilities]<-[security] SecurityReply.tlsClose (%dB)", rl);
uint64_t id = rand() + 1; uint32_t id = rand();
tr = calloc(1, sizeof(TransportRequest_t)); tr = calloc(1, sizeof(TransportRequest_t));
tr->present = TransportRequest_PR_data; tr->present = TransportRequest_PR_data;
tr->choice.data.present = TransportDataRequest_PR_tcp; tr->choice.data.present = TransportDataRequest_PR_tcp;
@ -1029,7 +1032,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
buf[0] = 4; buf[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1);
it2s_tender_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); itss_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose");
free(tlsc); free(tlsc);
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) { for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {
@ -1091,7 +1094,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
goto cleanup; goto cleanup;
} }
pthread_mutex_lock(&facilities->epv.time.lock); pthread_mutex_lock(&facilities->epv.time.lock);
syslog_info("[facilities] [tolling] entry.reply took %ld us", it2s_tender_get_now(TIME_MICROSECONDS) - tolling->tz); syslog_info("[facilities] [tolling] entry.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz);
pthread_mutex_unlock(&facilities->epv.time.lock); pthread_mutex_unlock(&facilities->epv.time.lock);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr);
break; break;
@ -1118,7 +1121,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
goto cleanup; goto cleanup;
} }
pthread_mutex_lock(&facilities->epv.time.lock); pthread_mutex_lock(&facilities->epv.time.lock);
syslog_info("[facilities] [tolling] exit.reply took %ld us", it2s_tender_get_now(TIME_MICROSECONDS) - tolling->tz); syslog_info("[facilities] [tolling] exit.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz);
pthread_mutex_unlock(&facilities->epv.time.lock); pthread_mutex_unlock(&facilities->epv.time.lock);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr);
break; break;
@ -1142,7 +1145,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
goto cleanup; goto cleanup;
} }
pthread_mutex_lock(&facilities->epv.time.lock); pthread_mutex_lock(&facilities->epv.time.lock);
syslog_info("[facilities] [tolling] single.reply took %ld us", it2s_tender_get_now(TIME_MICROSECONDS) - tolling->tz); syslog_info("[facilities] [tolling] single.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz);
pthread_mutex_unlock(&facilities->epv.time.lock); pthread_mutex_unlock(&facilities->epv.time.lock);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr);
break; break;
@ -1174,10 +1177,10 @@ int tolling_init(tolling_t* tolling, void* zmq_ctx, char* security_address, uint
return 0; return 0;
} }
tolling_info_t* tolling_info_new(it2s_tender_epv_t* epv, TollingPaymentInfo_t* tpi) { tolling_info_t* tolling_info_new(itss_epv_t* epv, TollingPaymentInfo_t* tpi) {
tolling_info_t* ti = calloc(1, sizeof(tolling_info_t)); tolling_info_t* ti = calloc(1, sizeof(tolling_info_t));
ti->timestamp = it2s_tender_get_clock(epv); ti->timestamp = itss_time_get(epv);
ti->asn = tpi; ti->asn = tpi;
ti->zone.polygon_len = tpi->zone.list.count; ti->zone.polygon_len = tpi->zone.list.count;
@ -1197,7 +1200,7 @@ void tolling_info_free(tolling_info_t* ti) {
free(ti); free(ti);
} }
tlsc_t* tolling_tlsc_new(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port) { tlsc_t* tolling_tlsc_new(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port) {
if (tolling->protocol.c.tls.n_tlsc >= TOLLING_MAX_CONNS - 1) { if (tolling->protocol.c.tls.n_tlsc >= TOLLING_MAX_CONNS - 1) {
return NULL; return NULL;
} }
@ -1206,18 +1209,18 @@ tlsc_t* tolling_tlsc_new(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv
memcpy(tlsc->ipv6, ipv6, 16); memcpy(tlsc->ipv6, ipv6, 16);
tlsc->port = port; tlsc->port = port;
tlsc->id = rand(); tlsc->id = rand();
tlsc->ts = it2s_tender_get_clock(epv); tlsc->ts = itss_time_get(epv);
++tolling->protocol.c.tls.n_tlsc; ++tolling->protocol.c.tls.n_tlsc;
return tlsc; return tlsc;
} }
tlsc_t* tolling_tlsc_get(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port) { tlsc_t* tolling_tlsc_get(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port) {
tlsc_t* tlsc = NULL; tlsc_t* tlsc = NULL;
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) { for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {
if (!memcmp(tolling->protocol.c.tls.tls_conns[i]->ipv6, ipv6, 16) && if (!memcmp(tolling->protocol.c.tls.tls_conns[i]->ipv6, ipv6, 16) &&
tolling->protocol.c.tls.tls_conns[i]->port == port) { tolling->protocol.c.tls.tls_conns[i]->port == port) {
tlsc = tolling->protocol.c.tls.tls_conns[i]; tlsc = tolling->protocol.c.tls.tls_conns[i];
tlsc->ts = it2s_tender_get_clock(epv); tlsc->ts = itss_time_get(epv);
break; break;
} }
} }
@ -1225,9 +1228,9 @@ tlsc_t* tolling_tlsc_get(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv
} }
void tolling_tlsc_mgmt(tolling_t* tolling, it2s_tender_epv_t* epv, it2s_tender_queue_t* tx_queue, void* security_socket) { void tolling_tlsc_mgmt(tolling_t* tolling, itss_epv_t* epv, itss_queue_t* tx_queue, void* security_socket) {
pthread_mutex_lock(&tolling->lock); pthread_mutex_lock(&tolling->lock);
uint64_t now = it2s_tender_get_clock(epv); uint64_t now = itss_time_get(epv);
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) { for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {
tlsc_t* tlsc = tolling->protocol.c.tls.tls_conns[i]; tlsc_t* tlsc = tolling->protocol.c.tls.tls_conns[i];
if (tlsc->ts + TOLLING_CONN_TIMEOUT_MS < now) { if (tlsc->ts + TOLLING_CONN_TIMEOUT_MS < now) {
@ -1262,7 +1265,7 @@ void tolling_tlsc_mgmt(tolling_t* tolling, it2s_tender_epv_t* epv, it2s_tender_q
buf[0] = 4; buf[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1);
it2s_tender_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); itss_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose");
free(tlsc); free(tlsc);
for (int j = i; j < tolling->protocol.c.tls.n_tlsc-1; ++j) { for (int j = i; j < tolling->protocol.c.tls.n_tlsc-1; ++j) {

View File

@ -93,9 +93,9 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr); int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr);
int tpm_is_inside_zone(void* fc, tolling_info_t* ti); int tpm_is_inside_zone(void* fc, tolling_info_t* ti);
tolling_info_t* tolling_info_new(it2s_tender_epv_t* epv, TollingPaymentInfo_t* tpi); tolling_info_t* tolling_info_new(itss_epv_t* epv, TollingPaymentInfo_t* tpi);
void tolling_info_free(tolling_info_t* ti); void tolling_info_free(tolling_info_t* ti);
tlsc_t* tolling_tlsc_new(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port); tlsc_t* tolling_tlsc_new(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port);
tlsc_t* tolling_tlsc_get(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port); tlsc_t* tolling_tlsc_get(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port);
void tolling_tlsc_mgmt(tolling_t* tolling, it2s_tender_epv_t* epv, it2s_tender_queue_t* tx_queue, void* security_socket); void tolling_tlsc_mgmt(tolling_t* tolling, itss_epv_t* epv, itss_queue_t* tx_queue, void* security_socket);

113
src/vcm.c
View File

@ -6,13 +6,14 @@
#include <it2s-tender/trajectory.h> #include <it2s-tender/trajectory.h>
#include <it2s-tender/geodesy.h> #include <it2s-tender/geodesy.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
#include <itss-transport/TransportRequest.h> #include <itss-transport/TransportRequest.h>
#include <itss-facilities/FacilitiesIndication.h> #include <itss-facilities/FacilitiesIndication.h>
#include <vcm/VCM.h> #include <vcm/VCM.h>
static int are_vehicles_intersecting( static int are_vehicles_intersecting(
it2s_tender_st_s* tA, int tA_len, uint16_t vA_length, uint16_t vA_width, itss_st_t* 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, itss_st_t* tB, int tB_len, uint16_t vB_length, uint16_t vB_width,
int* index int* index
) { ) {
@ -34,10 +35,10 @@ static int are_vehicles_intersecting(
// B2[0] = tB[b+1].latitude; // B2[0] = tB[b+1].latitude;
// B2[1] = tB[b+1].longitude; // B2[1] = tB[b+1].longitude;
// if (it2s_tender_do_segments_intersect(A1, A2, B1, B2)) { // if (itss_do_segments_intersect(A1, A2, B1, B2)) {
// printf("tA[a].lat=%d tA[a].lon=%d tB[b].lat=%d tB[b].lon=%d tA[a].ts=%ld tB[b].ts=%ld\n", // printf("tA[a].lat=%d tA[a].lon=%d tB[b].lat=%d tB[b].lon=%d tA[a].ts=%ld tB[b].ts=%ld\n",
// tA[a].latitude, tA[a].longitude, tB[b].latitude, tB[b].longitude, tA[a].timestamp, tB[b].timestamp); fflush(stdout); // tA[a].latitude, tA[a].longitude, tB[b].latitude, tB[b].longitude, tA[a].timestamp, tB[b].timestamp); fflush(stdout);
if (it2s_tender_is_inside_circle(tA[a].latitude, tA[a].longitude, tB[b].latitude, tB[b].longitude, 8, DCM_HAVERSINE)) { if (itss_is_inside_circle(tA[a].latitude, tA[a].longitude, tB[b].latitude, tB[b].longitude, 8, DCM_HAVERSINE)) {
if (tA[a].timestamp < tB[b].timestamp + 2000 && if (tA[a].timestamp < tB[b].timestamp + 2000 &&
tA[a].timestamp > tB[b].timestamp - 2000) { tA[a].timestamp > tB[b].timestamp - 2000) {
*index = a; *index = a;
@ -83,22 +84,22 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
const ssize_t buf_len = 512; const ssize_t buf_len = 512;
uint8_t buf[buf_len]; uint8_t buf[buf_len];
it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */
ssize_t trajectoryA_len = 0; ssize_t trajectoryA_len = 0;
it2s_tender_st_s trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */ itss_st_t trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */
uint16_t trajectoryB_len = 0; uint16_t trajectoryB_len = 0;
uint64_t now = it2s_tender_get_clock(&facilities->epv); uint64_t now = itss_time_get(&facilities->epv);
neighbour->proposed = true; neighbour->proposed = true;
neighbour->t_proposal = now; neighbour->t_proposal = now;
int32_t lat, lon; int32_t lat, lon;
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude; lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude; lon = facilities->epv.space.longitude;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
vcm_rep = calloc(1, sizeof(VCM_t)); vcm_rep = calloc(1, sizeof(VCM_t));
@ -160,7 +161,7 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
tr->choice.packet.present = TransportPacketRequest_PR_btp; tr->choice.packet.present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp;
bpr->btpType = BTPType_btpB; bpr->btpType = BTPType_btpB;
bpr->id = rand() + 1; bpr->id = itss_id(buf, vcm_rep_len);
bpr->gn.destinationAddress.buf = malloc(6); bpr->gn.destinationAddress.buf = malloc(6);
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
bpr->gn.destinationAddress.buf[i] = 0xff; bpr->gn.destinationAddress.buf[i] = 0xff;
@ -180,7 +181,7 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi = calloc(1, sizeof(FacilitiesIndication_t)); fi = calloc(1, sizeof(FacilitiesIndication_t));
fi->present = FacilitiesIndication_PR_message; fi->present = FacilitiesIndication_PR_message;
@ -197,22 +198,22 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
bpr->data.buf, bpr->data.buf,
bpr->data.size, bpr->data.size,
bpr->id, bpr->id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
} }
} }
@ -229,7 +230,7 @@ static int vcm_check_handle_reply(facilities_t* facilities, VCM_t* vcm, mc_neigh
CoordinationReply_t* reply = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.reply; CoordinationReply_t* reply = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.reply;
pthread_mutex_lock(&facilities->epv.time.lock); pthread_mutex_lock(&facilities->epv.time.lock);
uint64_t now_us = it2s_tender_get_now(TIME_MICROSECONDS); uint64_t now_us = itss_ts_get(TIME_MICROSECONDS);
pthread_mutex_unlock(&facilities->epv.time.lock); pthread_mutex_unlock(&facilities->epv.time.lock);
if (neighbour->intersecting) { if (neighbour->intersecting) {
@ -258,10 +259,10 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
const ssize_t buf_len = 1024; const ssize_t buf_len = 1024;
uint8_t buf[buf_len]; uint8_t buf[buf_len];
it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */
uint16_t trajectoryA_len = 0; uint16_t trajectoryA_len = 0;
uint64_t now = it2s_tender_get_clock(&facilities->epv); uint64_t now = itss_time_get(&facilities->epv);
if (now < neighbour->t_iid/1000 + MC_RESOLUTION_TIMEOUT) { if (now < neighbour->t_iid/1000 + MC_RESOLUTION_TIMEOUT) {
rv = 0; rv = 0;
@ -271,7 +272,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
neighbour->intersecting = true; neighbour->intersecting = true;
pthread_mutex_lock(&facilities->epv.time.lock); pthread_mutex_lock(&facilities->epv.time.lock);
uint64_t now_us = it2s_tender_get_now(TIME_MICROSECONDS) ; uint64_t now_us = itss_ts_get(TIME_MICROSECONDS) ;
pthread_mutex_unlock(&facilities->epv.time.lock); pthread_mutex_unlock(&facilities->epv.time.lock);
neighbour->t_iid = now_us; neighbour->t_iid = now_us;
@ -281,16 +282,16 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
} }
int32_t lat, lon; int32_t lat, lon;
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude; lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude; lon = facilities->epv.space.longitude;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
it2s_tender_lock_trajectory(&facilities->epv); itss_trajectory_lock(&facilities->epv);
trajectoryA_len = facilities->epv.trajectory.len; trajectoryA_len = facilities->epv.trajectory.len;
memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(it2s_tender_st_s)); memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t));
it2s_tender_unlock_trajectory(&facilities->epv); itss_trajectory_unlock(&facilities->epv);
trajectoryA[0].latitude = lat; trajectoryA[0].latitude = lat;
@ -382,7 +383,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
tr->present = TransportRequest_PR_packet; tr->present = TransportRequest_PR_packet;
tr->choice.packet.present = TransportPacketRequest_PR_btp; tr->choice.packet.present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp;
bpr->id = rand() + 1; bpr->id = itss_id(buf, vcm_req_len);
bpr->btpType = BTPType_btpB; bpr->btpType = BTPType_btpB;
bpr->gn.destinationAddress.buf = malloc(6); bpr->gn.destinationAddress.buf = malloc(6);
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
@ -403,7 +404,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi = calloc(1, sizeof(FacilitiesIndication_t)); fi = calloc(1, sizeof(FacilitiesIndication_t));
fi->present = FacilitiesIndication_PR_message; fi->present = FacilitiesIndication_PR_message;
@ -420,22 +421,22 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
goto cleanup; goto cleanup;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
bpr->data.buf, bpr->data.buf,
bpr->data.size, bpr->data.size,
bpr->id, bpr->id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
} }
} }
@ -452,19 +453,19 @@ int vcm_check(void* fc, VCM_t* vcm) {
int rv = 0; int rv = 0;
it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */
it2s_tender_st_s trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */ itss_st_t trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */
uint16_t trajectoryA_len = 0; uint16_t trajectoryA_len = 0;
uint16_t trajectoryB_len = 0; uint16_t trajectoryB_len = 0;
uint64_t now = it2s_tender_get_clock(&facilities->epv); uint64_t now = itss_time_get(&facilities->epv);
int32_t lat, lon; int32_t lat, lon;
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude; lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude; lon = facilities->epv.space.longitude;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
pthread_mutex_lock(&coordination->lock); pthread_mutex_lock(&coordination->lock);
@ -501,10 +502,10 @@ int vcm_check(void* fc, VCM_t* vcm) {
} }
} else { } else {
it2s_tender_lock_trajectory(&facilities->epv); itss_trajectory_lock(&facilities->epv);
trajectoryA_len = facilities->epv.trajectory.len; trajectoryA_len = facilities->epv.trajectory.len;
memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(it2s_tender_st_s)); memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t));
it2s_tender_unlock_trajectory(&facilities->epv); itss_trajectory_unlock(&facilities->epv);
trajectoryA[0].latitude = lat; trajectoryA[0].latitude = lat;
trajectoryA[0].longitude = lon; trajectoryA[0].longitude = lon;
@ -560,29 +561,29 @@ static int mk_vcm(facilities_t* facilities, uint8_t* vcm_uper, uint16_t* vcm_upe
coordination_s* coordination = &facilities->coordination; coordination_s* coordination = &facilities->coordination;
it2s_tender_st_s trajectory[TRAJECTORY_MAX_LEN]; itss_st_t trajectory[TRAJECTORY_MAX_LEN];
VCM_t* vcm = calloc(1, sizeof(VCM_t)); VCM_t* vcm = calloc(1, sizeof(VCM_t));
vcm->header.messageID = 43; vcm->header.messageID = 43;
vcm->header.protocolVersion = 1; vcm->header.protocolVersion = 1;
uint64_t now = it2s_tender_get_clock(&facilities->epv); uint64_t now = itss_time_get(&facilities->epv);
pthread_mutex_lock(&facilities->id.lock); pthread_mutex_lock(&facilities->id.lock);
vcm->header.stationID = facilities->id.station_id; vcm->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock); pthread_mutex_unlock(&facilities->id.lock);
int32_t lat, lon; int32_t lat, lon;
uint16_t trajectory_len = 0; uint16_t trajectory_len = 0;
it2s_tender_lock_space(&facilities->epv); itss_space_lock(&facilities->epv);
it2s_tender_get_space(&facilities->epv); itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude; lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude; lon = facilities->epv.space.longitude;
it2s_tender_unlock_space(&facilities->epv); itss_space_unlock(&facilities->epv);
it2s_tender_lock_trajectory(&facilities->epv); itss_trajectory_lock(&facilities->epv);
trajectory_len = facilities->epv.trajectory.len; trajectory_len = facilities->epv.trajectory.len;
memcpy(trajectory, facilities->epv.trajectory.path, trajectory_len * sizeof(it2s_tender_st_s)); memcpy(trajectory, facilities->epv.trajectory.path, trajectory_len * sizeof(itss_st_t));
it2s_tender_unlock_trajectory(&facilities->epv); itss_trajectory_unlock(&facilities->epv);
vcm->vcm.currentPosition.latitude = lat; vcm->vcm.currentPosition.latitude = lat;
vcm->vcm.currentPosition.longitude = lon; vcm->vcm.currentPosition.longitude = lon;
@ -680,7 +681,7 @@ void* vc_service(void* fc) {
while (!facilities->exit) { while (!facilities->exit) {
uint64_t now = it2s_tender_get_clock(&facilities->epv); uint64_t now = itss_time_get(&facilities->epv);
pthread_mutex_lock(&coordination->lock); pthread_mutex_lock(&coordination->lock);
if (vcm_timer_check(coordination, now)) { if (vcm_timer_check(coordination, now)) {
@ -689,14 +690,14 @@ void* vc_service(void* fc) {
continue; continue;
} }
bpr->id = rand() + 1; bpr->id = itss_id(bpr->data.buf, bpr->data.size);
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, 1023); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, 1023);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] encoding TR for VCM failed"); syslog_err("[facilities] encoding TR for VCM failed");
continue; continue;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi->choice.message.id = bpr->id; fi->choice.message.id = bpr->id;
fi->choice.message.data.size = bpr->data.size; fi->choice.message.data.size = bpr->data.size;
@ -706,22 +707,22 @@ void* vc_service(void* fc) {
syslog_err("[facilities] encoding FI for VCM failed"); syslog_err("[facilities] encoding FI for VCM failed");
continue; continue;
} }
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message"); itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
int e = it2s_tender_management_record_packet_sdu( int e = itss_management_record_packet_sdu(
buffer, buffer,
buffer_len, buffer_len,
bpr->data.buf, bpr->data.buf,
bpr->data.size, bpr->data.size,
bpr->id, bpr->id,
it2s_tender_get_clock(&facilities->epv), itss_time_get(&facilities->epv),
ITSS_FACILITIES, ITSS_FACILITIES,
true); true);
if (e != -1) { if (e != -1) {
it2s_tender_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set"); itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
} }
} }

View File

@ -33,7 +33,7 @@ typedef struct coordination {
struct { struct {
uint64_t id; uint64_t id;
uint8_t link[32]; uint8_t link[32];
it2s_tender_region_t region; itss_region_t region;
} chain; } chain;
} coordination_s; } coordination_s;