188 lines
3.4 KiB
C
188 lines
3.4 KiB
C
#ifndef FACILITIES_CPM_H
|
|
#define FACILITIES_CPM_H
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <cpm/CPM.h>
|
|
#include <termios.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <net/if.h>
|
|
#include <linux/if_packet.h>
|
|
|
|
#define READ_BUFFER_SIZE 1024 // Buffer for Serial and Ethernet read function (Used in cp_service)
|
|
#define NOF_OBJECTS 127 // Number of Object UMRR-0C
|
|
#define MESSAGE_ID 14
|
|
#define PROTOCOL_VERSION 1
|
|
#define RADAR_PORT "55555" // Destination port from the radar
|
|
|
|
|
|
/* Structures */
|
|
|
|
typedef struct
|
|
{
|
|
int i32_socket; // Socket descriptor server
|
|
int i32_client; // Socket descriptor UMRR-0C
|
|
int i32_port; // Listen on Port
|
|
bool b_moxa;
|
|
struct sockaddr_in s_server;
|
|
struct sockaddr_in s_client;
|
|
} S_ETHERNET_CONNECTION_T;
|
|
|
|
typedef struct
|
|
{
|
|
int raw_fd;
|
|
struct sockaddr_ll sll;
|
|
struct ifreq ifr;
|
|
} S_INTERFACE_CONNECTION_T;
|
|
|
|
typedef struct
|
|
{
|
|
u_int8_t u8_numberOfCountedObjects;
|
|
u_int32_t u32_UnixTime;
|
|
u_int16_t u16_Milliseconds;
|
|
u_int8_t u8_SensorNetworkID;
|
|
u_int8_t u8_ObjectNumber;
|
|
u_int8_t u8_ObjectID;
|
|
int16_t i16_speed;
|
|
u_int8_t u8_class;
|
|
u_int8_t u8_mLineNumber;
|
|
u_int16_t u8_laneNumber;
|
|
} S_PVR_T;
|
|
|
|
typedef struct
|
|
{
|
|
u_int8_t u8_sensorStatus;
|
|
u_int8_t u8_InterfaceMode;
|
|
u_int8_t u8_networkID;
|
|
u_int8_t u8_diagnose;
|
|
u_int32_t u32_time;
|
|
} S_SENSOR_CONTROL_T;
|
|
|
|
typedef struct
|
|
{
|
|
u_int8_t u8_numberOfObjects;
|
|
u_int8_t u8_numberOfMessages;
|
|
u_int8_t u8_cycleDuration;
|
|
u_int8_t u8_objectData0Format;
|
|
u_int8_t u8_objectData1Format;
|
|
u_int32_t u32_cycleCount;
|
|
} S_OBJECT_CONTROL_T;
|
|
|
|
typedef struct
|
|
{
|
|
u_int8_t u8_modeSignal;
|
|
float f_xPoint;
|
|
float f_yPoint;
|
|
float f_xSpeed;
|
|
float f_ySpeed;
|
|
float f_objectLength;
|
|
u_int8_t u8_objectID;
|
|
u_int8_t u8_updateFlag;
|
|
} S_OBJECTS_T;
|
|
|
|
|
|
enum state_t {
|
|
IDLE,
|
|
START_1,
|
|
START_2,
|
|
START_3,
|
|
START_4,
|
|
START_PATTERN,
|
|
PROTOCOLVERSION,
|
|
HEADERLENGTH,
|
|
PAYLOADLENGTH_H,
|
|
PAYLOADLENGTH_L,
|
|
APPPROTOCOLTYPE,
|
|
FLAG_1_H,
|
|
FLAG_1_L,
|
|
FLAG_2_H,
|
|
FLAG_2_L,
|
|
CRC16HEADER_H,
|
|
CRC16HEADER_L,
|
|
PAYLOAD_DATA,
|
|
CAN_ID_H,
|
|
CAN_ID_L,
|
|
CAN_LEN,
|
|
CAN_PAYLOAD,
|
|
PAYLOAD_CRC16_H,
|
|
PAYLOAD_CRC16_L
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
|
|
bool active;
|
|
bool tmc_connect;
|
|
char* int_radar;
|
|
char* ip_radar;
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
uint32_t type;
|
|
|
|
uint64_t next_cpm_max;
|
|
uint64_t next_cpm_min;
|
|
|
|
|
|
uint64_t T_GenCpmMin;
|
|
uint64_t T_GenCpmMax;
|
|
|
|
uint64_t T_AddSensorInformation;
|
|
uint64_t next_AddSensorInformation;
|
|
|
|
|
|
/* Position of the radar (Value from toml) */
|
|
|
|
int64_t radar_rotation;
|
|
int16_t opening_angle_start;
|
|
int16_t opening_angle_end;
|
|
|
|
} dissemination_t;
|
|
|
|
/* Prototype Functions */
|
|
|
|
/*
|
|
Summary : Waits for client to connect (Radar)
|
|
*/
|
|
|
|
bool waitingIncomingConnection(void);
|
|
|
|
|
|
|
|
/*
|
|
Summary : Creation of socket and binding to the radar add and port
|
|
param [in] char* radar_ip: Radar IP
|
|
param [in] char* radar_port: Radar PORT
|
|
*/
|
|
|
|
bool initEthernetConnection(const char* radar_ip,const char* radar_port);
|
|
|
|
|
|
|
|
/*
|
|
Summary : Initialization for dissemination control. (Memory allocation and mutex init
|
|
*/
|
|
|
|
dissemination_t* dissemination_init();
|
|
|
|
|
|
/*
|
|
Summary : Creation of socket and binding to the radar add and port
|
|
param [in] char* radar_ip: Radar IP
|
|
param [in] char* radar_port: Radar PORT
|
|
*/
|
|
|
|
bool initEthernetConnection(const char* radar_ip,const char* radar_port);
|
|
|
|
/*
|
|
Summary: Read from Radar socket (s_socket.i32_socket) call the function to interpret data
|
|
param[in] void
|
|
*/
|
|
|
|
void* cp_service();
|
|
|
|
#endif
|