Format, some docs
This commit is contained in:
parent
1d3469e840
commit
aef5bf4797
91
src/cam.c
91
src/cam.c
|
|
@ -90,9 +90,9 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
|
|||
|
||||
lightship_t* lightship = &facilities.lightship;
|
||||
|
||||
if (lightship->use_obd){
|
||||
it2s_obd_data* shared_message = malloc(sizeof(it2s_obd_data));
|
||||
it2s_obd_read(shared_message);
|
||||
if (lightship->use_obd) {
|
||||
it2s_obd_data* shared_message = malloc(sizeof(it2s_obd_data));
|
||||
it2s_obd_read(shared_message);
|
||||
}
|
||||
|
||||
CAM_t *cam = calloc(1, sizeof(CAM_t));
|
||||
|
|
@ -127,33 +127,33 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
|
|||
cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_basicVehicleContainerHighFrequency;
|
||||
BasicVehicleContainerHighFrequency_t* bvc_hf = &cam->cam.camParameters.highFrequencyContainer.choice.basicVehicleContainerHighFrequency;
|
||||
|
||||
if(lightship->use_obd){
|
||||
uint8_t ac = 0x00;
|
||||
if (lightship->use_obd) {
|
||||
uint8_t ac = 0x00;
|
||||
|
||||
// Speed (already getting set bellow)
|
||||
// Speed (already getting set bellow)
|
||||
// bvc_hf.speed.speedValue = ceil(shared_message->speed_value ÷ 0.036);
|
||||
// bvc_hf_speed.speedConfidence = 1;
|
||||
// bvc_hf_speed.speedConfidence = 1;
|
||||
|
||||
// Steering Wheel Angle
|
||||
if(shared_message->w_angle_value != 1683 && (now/1000 - shared_message->w_angle_timestamp) <= 1){
|
||||
bvc_hf->steeringWheelAngle = calloc(1, sizeof(SteeringWheelAngle_t));
|
||||
bvc_hf->steeringWheelAngle->steeringWheelAngleValue = shared_message->w_angle_value;
|
||||
bvc_hf->steeringWheelAngle->steeringWheelAngleConfidence = 1;
|
||||
}
|
||||
// still missing temperature; where is de_temperature ?
|
||||
// Steering Wheel Angle
|
||||
if(shared_message->w_angle_value != 1683 && (now/1000 - shared_message->w_angle_timestamp) <= 1){
|
||||
bvc_hf->steeringWheelAngle = calloc(1, sizeof(SteeringWheelAngle_t));
|
||||
bvc_hf->steeringWheelAngle->steeringWheelAngleValue = shared_message->w_angle_value;
|
||||
bvc_hf->steeringWheelAngle->steeringWheelAngleConfidence = 1;
|
||||
}
|
||||
// still missing temperature; where is de_temperature ?
|
||||
|
||||
// Acceleration Control (encondig failure)
|
||||
if(shared_message->b_pedal_value != 1683 && shared_message->s_pedal_value != 1683 && (now/1000 - shared_message->b_pedal_timestamp) <= 1 && (now - shared_message->s_pedal_timestamp) <= 1){
|
||||
if(shared_message->b_pedal_value)
|
||||
ac = ac | 0x80;
|
||||
if(shared_message->s_pedal_value)
|
||||
ac = ac | 0x40;
|
||||
bvc_hf->accelerationControl = calloc(1, sizeof(AccelerationControl_t));
|
||||
bvc_hf->accelerationControl->buf = malloc(sizeof(uint8_t));
|
||||
memcpy(bvc_hf->accelerationControl->buf, &ac, 1);
|
||||
bvc_hf->accelerationControl->size = 1;
|
||||
bvc_hf->accelerationControl->bits_unused = 1;
|
||||
}
|
||||
// Acceleration Control (encondig failure)
|
||||
if (shared_message->b_pedal_value != 1683 && shared_message->s_pedal_value != 1683 && (now/1000 - shared_message->b_pedal_timestamp) <= 1 && (now - shared_message->s_pedal_timestamp) <= 1){
|
||||
if(shared_message->b_pedal_value)
|
||||
ac = ac | 0x80;
|
||||
if(shared_message->s_pedal_value)
|
||||
ac = ac | 0x40;
|
||||
bvc_hf->accelerationControl = calloc(1, sizeof(AccelerationControl_t));
|
||||
bvc_hf->accelerationControl->buf = malloc(sizeof(uint8_t));
|
||||
memcpy(bvc_hf->accelerationControl->buf, &ac, 1);
|
||||
bvc_hf->accelerationControl->size = 1;
|
||||
bvc_hf->accelerationControl->bits_unused = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Set speed
|
||||
|
|
@ -232,21 +232,21 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
|
|||
|
||||
cam->cam.camParameters.lowFrequencyContainer->present = LowFrequencyContainer_PR_basicVehicleContainerLowFrequency;
|
||||
|
||||
BasicVehicleContainerLowFrequency_t* bvc_lf = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency;
|
||||
BasicVehicleContainerLowFrequency_t* bvc_lf = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency;
|
||||
|
||||
if(lightship->use_obd){
|
||||
uint8_t el = 0x00;
|
||||
if (lightship->use_obd) {
|
||||
uint8_t el = 0x00;
|
||||
|
||||
// Exterior Lights
|
||||
if(shared_message->lights_value != 1683 && (now/1000 - shared_message->lights_timestamp) <= 1){
|
||||
if(shared_message->lights_value)
|
||||
el = el | 0x80;
|
||||
bvc_lf->exteriorLights.buf = malloc(sizeof(uint8_t));
|
||||
memcpy(bvc_lf->exteriorLights.buf, &el, 1);
|
||||
bvc_lf->exteriorLights.size = 1;
|
||||
bvc_lf->exteriorLights.bits_unused = 0;
|
||||
}
|
||||
}
|
||||
// Exterior Lights
|
||||
if (shared_message->lights_value != 1683 && (now/1000 - shared_message->lights_timestamp) <= 1) {
|
||||
if (shared_message->lights_value)
|
||||
el = el | 0x80;
|
||||
bvc_lf->exteriorLights.buf = malloc(sizeof(uint8_t));
|
||||
memcpy(bvc_lf->exteriorLights.buf, &el, 1);
|
||||
bvc_lf->exteriorLights.size = 1;
|
||||
bvc_lf->exteriorLights.bits_unused = 0;
|
||||
}
|
||||
}
|
||||
|
||||
PathHistory_t* ph = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency.pathHistory;
|
||||
|
||||
|
|
@ -277,6 +277,7 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
|
|||
|
||||
ph->list.array[i]->pathDeltaTime = calloc(1,sizeof(PathDeltaTime_t));
|
||||
*ph->list.array[i]->pathDeltaTime = (lightship->pos_history[i]->ts - lightship->pos_history[i+1]->ts)/10;
|
||||
|
||||
}
|
||||
|
||||
lightship->last_cam_lfc = now;
|
||||
|
|
@ -354,20 +355,18 @@ int lightship_init() {
|
|||
|
||||
lightship_t* lightship = &facilities.lightship;
|
||||
|
||||
lightship->protected_zones.pz = calloc(256 , sizeof(void*));
|
||||
lightship->protected_zones.pz = calloc(256, sizeof(void*));
|
||||
pthread_mutex_init(&lightship->lock, NULL);
|
||||
|
||||
lightship->pos_history = malloc(POS_HISTORY_MAX_LEN * sizeof(void*));
|
||||
|
||||
int shm_fd;
|
||||
shm_fd = shm_open("it2s-obd", O_RDONLY, 0666);
|
||||
if(shm_fd == -1){
|
||||
if (shm_fd == -1) {
|
||||
log_debug("obd shmem not found\n");
|
||||
lightship->use_obd = 0;
|
||||
}
|
||||
|
||||
else{
|
||||
log_debug("obd shmem found\n");
|
||||
} else {
|
||||
log_debug("obd shmem found\n");
|
||||
lightship->use_obd = 1;
|
||||
close(shm_fd);
|
||||
}
|
||||
|
|
@ -700,7 +699,7 @@ static int check_pz() {
|
|||
return is_inside;
|
||||
}
|
||||
|
||||
void *ca_service() {
|
||||
void* ca_service() {
|
||||
int rv = 0;
|
||||
|
||||
TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t));
|
||||
|
|
|
|||
27
src/cam.h
27
src/cam.h
|
|
@ -86,12 +86,39 @@ typedef struct lightship {
|
|||
|
||||
} lightship_t;
|
||||
|
||||
/*
|
||||
* @brief Initializes the main CA struct (lightship)
|
||||
*
|
||||
* @return Always zero
|
||||
*/
|
||||
int lightship_init();
|
||||
|
||||
/*
|
||||
* @brief Checks if a CAM must be sent
|
||||
*
|
||||
* @return True if CAM must be sent, false otherwise
|
||||
*/
|
||||
int lightship_check();
|
||||
|
||||
/*
|
||||
* @brief Resets the CAM sending timer
|
||||
*
|
||||
* @return Nothing
|
||||
*/
|
||||
void lightship_reset_timer();
|
||||
|
||||
/*
|
||||
* @brief Analyzes a received CAM
|
||||
*
|
||||
* @return A CAM check code
|
||||
*/
|
||||
enum CAM_CHECK_R check_cam(BTPPacketIndication_t* bpi, CAM_t* cam,uint8_t* ssp, uint32_t ssp_len);
|
||||
|
||||
/*
|
||||
* @brief Main CA service
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
void* ca_service();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue