From 30903efa5a2b0b91fd20848619361ff8bbaa4343 Mon Sep 17 00:00:00 2001 From: David Rocha Date: Tue, 18 Jan 2022 15:09:01 +0000 Subject: [PATCH] change obd shmem validation location --- src/cam.c | 46 ++++++++++++++++++++++++++++++---------------- src/cam.h | 2 ++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/cam.c b/src/cam.c index 92f4387..75d1a75 100644 --- a/src/cam.c +++ b/src/cam.c @@ -94,16 +94,6 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) int rv = 0; int shm_fd, shm_valid = 0; - shm_fd = shm_open("it2s-bluetooth-decoded", O_CREAT | O_RDONLY, 0666); - if(shm_fd == -1) - syslog_err("[facilities] failed to open CAN shared memory\n"); - - decoded_can_values_shm *shared_message = (decoded_can_values_shm *)mmap(0, sizeof(decoded_can_values_shm), PROT_READ, MAP_SHARED, shm_fd, 0); - if(shared_message == MAP_FAILED) - syslog_err("[facilities] failed to map CAN shared memory\n"); - else - shm_valid = 1; - CAM_t *cam = calloc(1, sizeof(CAM_t)); cam->header.protocolVersion = 2; @@ -121,6 +111,24 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) pthread_mutex_lock(&lightship->lock); if (facilities->station_type != StationType_roadSideUnit) { + int shm_fd; + decoded_can_values_shm* shared_message; + if(facilities->lightship->use_obd){ + shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666); + if(shm_fd == -1) + syslog_err("[facilities] failed to open CAN shared memory\n"); + + shared_message = (decoded_can_values_shm *)mmap(0, sizeof(decoded_can_values_shm), PROT_READ, MAP_SHARED, shm_fd, 0); + if(shared_message == MAP_FAILED) + syslog_err("[facilities] failed to map CAN shared memory\n"); + + // process and fill fields here + + munmap(shared_message, sizeof(can_values_shm)); + if(close(shm_fd) == -1) + syslog_err("[facilities] failed to close CAN shared memory\n"); + } + cam->cam.generationDeltaTime = now % 65536; it2s_tender_lock_space(&facilities->epv); @@ -304,12 +312,6 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) goto cleanup; } *cam_len = (enc.encoded + 7) / 8; - - if(shm_valid){ - munmap(shared_message, sizeof(can_values_shm)); - if(close(shm_fd) == -1) - syslog_err("[facilities] failed to close CAN shared memory\n"); - } cleanup: ASN_STRUCT_FREE(asn_DEF_CAM, cam); @@ -326,6 +328,18 @@ lightship_t* lightship_init() { lightship->pos_history = malloc(POS_HISTORY_MAX_LEN * sizeof(void*)); + int shm_fd; + + shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666); + if(shm_fd == -1){ + syslog_debug("[facilities] obd shmem not found\n"); + lightship->use_obd = 0; + } + else{ + lightship->use_obd = 1; + close(shm_fd); + } + return lightship; } diff --git a/src/cam.h b/src/cam.h index 149ae5c..6eaa8fb 100644 --- a/src/cam.h +++ b/src/cam.h @@ -77,6 +77,8 @@ typedef struct lightship { uint32_t rsu_gen_min; uint32_t rsu_vehicle_permanence; + bool use_obd; + struct { ProtectedCommunicationZone_t ** pz; uint16_t pz_len;