change obd shmem validation location
This commit is contained in:
parent
236c16fb1f
commit
30903efa5a
46
src/cam.c
46
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);
|
||||
|
|
@ -305,12 +313,6 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
|
|||
}
|
||||
*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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue