change obd shmem validation location

This commit is contained in:
David Rocha 2022-01-18 15:09:01 +00:00
parent 236c16fb1f
commit 30903efa5a
2 changed files with 32 additions and 16 deletions

View File

@ -94,16 +94,6 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
int rv = 0; int rv = 0;
int shm_fd, shm_valid = 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_t *cam = calloc(1, sizeof(CAM_t));
cam->header.protocolVersion = 2; 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); pthread_mutex_lock(&lightship->lock);
if (facilities->station_type != StationType_roadSideUnit) { 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; cam->cam.generationDeltaTime = now % 65536;
it2s_tender_lock_space(&facilities->epv); 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; goto cleanup;
} }
*cam_len = (enc.encoded + 7) / 8; *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: cleanup:
ASN_STRUCT_FREE(asn_DEF_CAM, cam); 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*)); 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; return lightship;
} }

View File

@ -77,6 +77,8 @@ typedef struct lightship {
uint32_t rsu_gen_min; uint32_t rsu_gen_min;
uint32_t rsu_vehicle_permanence; uint32_t rsu_vehicle_permanence;
bool use_obd;
struct { struct {
ProtectedCommunicationZone_t ** pz; ProtectedCommunicationZone_t ** pz;
uint16_t pz_len; uint16_t pz_len;