add can bus shmem readings; still have to decide what to process

This commit is contained in:
David Rocha 2022-01-14 18:22:22 +00:00
parent b253e3de6c
commit b6fc0eeadd
2 changed files with 22 additions and 0 deletions

View File

@ -28,6 +28,7 @@ TARGET_LINK_LIBRARIES(it2s-itss-facilities
-lit2s-asn-tpm -lit2s-asn-tpm
-lit2s-tender -lit2s-tender
-lm -lm
-lrt
) )
INSTALL( INSTALL(

View File

@ -7,16 +7,20 @@
#include <itss-management/ManagementRequest.h> #include <itss-management/ManagementRequest.h>
#include <camv2/CAM.h> #include <camv2/CAM.h>
#include <sys/mman.h>
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#include <zmq.h> #include <zmq.h>
#include <unistd.h> #include <unistd.h>
#include <syslog.h> #include <syslog.h>
#include <math.h> #include <math.h>
#include <fcntl.h>
#include <it2s-tender/space.h> #include <it2s-tender/space.h>
#include <it2s-tender/time.h> #include <it2s-tender/time.h>
#include <it2s-obd/shmem.h>
#define syslog_info(msg, ...) syslog(LOG_INFO, msg, ##__VA_ARGS__) #define syslog_info(msg, ...) syslog(LOG_INFO, msg, ##__VA_ARGS__)
#define syslog_emerg(msg, ...) syslog(LOG_EMERG, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__) #define syslog_emerg(msg, ...) syslog(LOG_EMERG, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__)
#define syslog_err(msg, ...) syslog(LOG_ERR, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__) #define syslog_err(msg, ...) syslog(LOG_ERR, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__)
@ -88,6 +92,17 @@ static int permissions_check(int cid, uint8_t* permissions, uint8_t permissions_
static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) { 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;
shm_fd = shm_open("it2s-bluetooth-decoded", 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));
@ -290,6 +305,12 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
} }
*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);