remove manual maping off obd shm

This commit is contained in:
David Rocha 2022-09-22 15:40:00 +01:00
parent bba3956aff
commit 6f0d771a35
2 changed files with 10 additions and 16 deletions

View File

@ -29,6 +29,7 @@ TARGET_LINK_LIBRARIES(it2s-itss-facilities
-lit2s-asn-tpm
-lit2s-asn-vcm
-lit2s-tender
-lit2s-obd
-lm
-lrt
)

View File

@ -22,7 +22,7 @@
#include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
#include <it2s-obd/shmem.h>
#include <it2s-obd.h>
#define LEAP_SECONDS 5
@ -86,17 +86,13 @@ static int permissions_check(int cid, uint8_t* permissions, uint8_t permissions_
static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
int rv = 0;
int shm_fd, shm_valid = 0;
decoded_can_values_shm* shared_message;
it2s_obd_data* shared_message;
lightship_t* lightship = &facilities.lightship;
if (lightship->use_obd){
shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666);
if(shm_fd == -1)
log_error("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)
log_error("failed to map CAN shared memory\n");
it2s_obd_data* shared_message = malloc(sizeof(it2s_obd_data));
it2s_obd_read(shared_message);
}
CAM_t *cam = calloc(1, sizeof(CAM_t));
@ -344,11 +340,8 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
}
*cam_len = (enc.encoded + 7) / 8;
if(lightship->use_obd){
munmap(shared_message, sizeof(can_values_shm));
if(close(shm_fd) == -1)
log_error("failed to close CAN shared memory\n");
}
if (lightship->use_obd)
free(shared_message);
cleanup:
ASN_STRUCT_FREE(asn_DEF_CAM, cam);
@ -367,12 +360,12 @@ int 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);
shm_fd = shm_open("it2s-obd", O_RDONLY, 0666);
if(shm_fd == -1){
log_debug("obd shmem not found\n");
lightship->use_obd = 0;
}
else{
log_debug("obd shmem found\n");
lightship->use_obd = 1;