139 lines
3.7 KiB
C++
139 lines
3.7 KiB
C++
//****************************************************************************
|
|
// Copyright (C) 2007
|
|
// Nissan North America
|
|
// All Rights Reserved. Proprietary and Confidential.
|
|
//============================================================================
|
|
|
|
//****************************************************************************
|
|
// includes
|
|
//***************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <sys/timeb.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
|
|
#include "CanDaemon.h"
|
|
#include "netlib.h"
|
|
|
|
//****************************************************************************
|
|
// defines
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// macros
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// structs & typedefs
|
|
//***************************************************************************/
|
|
|
|
typedef struct _Can2DsrcMap {
|
|
int Signal;
|
|
double Scale;
|
|
int Offset;
|
|
} Can2DsrcMap;
|
|
|
|
//****************************************************************************
|
|
// global constants
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// global variables
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// static constants
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// static variables
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// static functions
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// C++ functions
|
|
//***************************************************************************/
|
|
|
|
CanDaemon::CanDaemon()
|
|
{
|
|
/* open a log file */
|
|
log_open( CAND_NAME );
|
|
SetTimeout( 1000000L );
|
|
}
|
|
|
|
CanDaemon::~CanDaemon()
|
|
{
|
|
}
|
|
|
|
/* Server *******************************************************************/
|
|
|
|
void CanDaemon::DaemonStartup(void)
|
|
{
|
|
// start threads and detach
|
|
Vehicle.Start( &Can, true ); // Receive CAN messages
|
|
Generator.Start( NULL, true ); // Send TX packets
|
|
|
|
Receiver.Caster = this;
|
|
Receiver.Start( NULL, true ); // Receive RX and TX Echo packets
|
|
}
|
|
|
|
void CanDaemon::DaemonShutdown(void)
|
|
{
|
|
Receiver.Stop();
|
|
Generator.Stop();
|
|
Vehicle.Stop();
|
|
}
|
|
|
|
int CanDaemon::ServerSocket(void)
|
|
{
|
|
int nrec=0;
|
|
|
|
return nrec;
|
|
}
|
|
|
|
int CanDaemon::ServerTimeout(void)
|
|
{
|
|
if ( NumClients() )
|
|
{
|
|
// status
|
|
// char str[128];
|
|
// int n = snprintf( str, sizeof(str), "CANd: %ld sent, %ld recv\n",
|
|
// Generator.SentCount(), Echo.RecvCount() );
|
|
// ClientCast( str, n );
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int CanDaemon::ClientIn( int sock, const char *buf, int n )
|
|
{
|
|
// commands?
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
void CanDaemon::ClientCast( const char *buf, int n )
|
|
{
|
|
TcpServer::ClientCast( buf, n );
|
|
}
|
|
|
|
/* other stuff **************************************************************/
|
|
|
|
int CanDaemon::CanOpen( const char *uri )
|
|
{
|
|
return Can.CanOpen( uri );
|
|
}
|