Added the ability for radar to reconnect (CPM)
This commit is contained in:
parent
88015dc131
commit
ae5701bb87
63
src/cpm.c
63
src/cpm.c
|
|
@ -11,6 +11,7 @@
|
|||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <syslog.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdbool.h>
|
||||
|
|
@ -41,6 +42,26 @@ char* station_id;
|
|||
it2s_config_t* config;
|
||||
|
||||
|
||||
bool waitingIncomingConnection(void){
|
||||
// Listening to the socket (Waiting for incoming connection)
|
||||
unsigned int len = sizeof(s_socket.s_client);
|
||||
|
||||
if(listen(s_socket.i32_socket,1)<0){
|
||||
syslog_err("Waiting for incoming requests failed...");
|
||||
return false;
|
||||
}
|
||||
|
||||
if((s_socket.i32_client = accept(s_socket.i32_socket, (struct sockaddr*)&s_socket.s_server, &len)) < 0){
|
||||
syslog_err("Client disconnected...");
|
||||
return false;
|
||||
}
|
||||
|
||||
syslog_debug("Radar connected");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool interface_connection(char* radar_ip,char* radar_port){
|
||||
|
||||
|
|
@ -63,26 +84,14 @@ bool interface_connection(char* radar_ip,char* radar_port){
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 3 - Listening to the socket (Waiting for incoming connection)
|
||||
unsigned int len = sizeof(s_socket.s_client);
|
||||
|
||||
if(listen(s_socket.i32_socket,1)<0){
|
||||
syslog_err("Waiting for incoming requests failed...");
|
||||
if(!waitingIncomingConnection())
|
||||
return false;
|
||||
}
|
||||
|
||||
if((s_socket.i32_client = accept(s_socket.i32_socket, (struct sockaddr*)&s_socket.s_server, &len)) < 0){
|
||||
syslog_err("Client disconnected...");
|
||||
return false;
|
||||
}
|
||||
|
||||
syslog_debug("Radar connected");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void parse_can_data_tm(u_int32_t u32_can_id, int i32_can_len, u_int8_t* au8_can_data) {
|
||||
u_int8_t u8_pvrMessagePart = 0;
|
||||
u_int8_t tmp = 0;
|
||||
|
|
@ -514,11 +523,9 @@ void *cp_service(void *fc){
|
|||
/* Variables */
|
||||
int i32_recv_bytes;
|
||||
u_int8_t au8_readBuffer[READ_BUFFER_SIZE];
|
||||
//void* message_data = malloc(1500);
|
||||
uint8_t bdr_oer[2048];
|
||||
bdr_oer[0] = 4; //Facilities
|
||||
int is_radar_connected_error;
|
||||
// socklen_t len = sizeof(error);
|
||||
bool is_radar_connected;
|
||||
|
||||
|
||||
facilities_t *facilities = (facilities_t *) fc;
|
||||
|
|
@ -554,7 +561,8 @@ void *cp_service(void *fc){
|
|||
*bdr->gnSecurityProfile = 1;
|
||||
}
|
||||
|
||||
interface_connection(RADAR_IP,RADAR_PORT); // Create Radar listening socket
|
||||
is_radar_connected = interface_connection(RADAR_IP,RADAR_PORT); // Create Radar listening socket
|
||||
|
||||
struct timespec* systemtime;
|
||||
systemtime = (struct timespec*)malloc(sizeof(struct timespec));
|
||||
if (systemtime == NULL) {
|
||||
|
|
@ -563,20 +571,20 @@ void *cp_service(void *fc){
|
|||
}
|
||||
|
||||
|
||||
|
||||
while(!facilities->exit){
|
||||
usleep(1000*50);
|
||||
|
||||
|
||||
if (dissemination_check(facilities->dissemination) && facilities->dissemination->active){
|
||||
/* Receive Data from radar interface */
|
||||
CPM_t* cpm_tx = calloc(1, sizeof(CPM_t));
|
||||
i32_recv_bytes = recv(s_socket.i32_client, &au8_readBuffer, READ_BUFFER_SIZE, 0); //recv(socket,buffer,size,flags)
|
||||
|
||||
if (dissemination_check(facilities->dissemination) && facilities->dissemination->active){
|
||||
if(is_radar_connected){
|
||||
|
||||
if(i32_recv_bytes < 0){
|
||||
if(i32_recv_bytes <= 0){
|
||||
syslog_debug("No data received from radar ...");
|
||||
break;
|
||||
is_radar_connected = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Information parsing */
|
||||
|
|
@ -602,16 +610,19 @@ void *cp_service(void *fc){
|
|||
queue_add(facilities->tx_queue, bdr_oer, enc.encoded+1, 3);
|
||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||
|
||||
|
||||
/*Reset Timer for dissemination control */
|
||||
|
||||
dissemination_reset_timer(facilities->dissemination);
|
||||
|
||||
/*TODO: Send message to applications to send it to the broker ? *FacilitiesDataIndication*/
|
||||
|
||||
}else{ /* Waiting for Radar to reconnect */
|
||||
|
||||
is_radar_connected = waitingIncomingConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ASN_STRUCT_FREE(asn_DEF_BTPDataRequest,bdr);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue