140 lines
3.9 KiB
C++
140 lines
3.9 KiB
C++
//
|
|
// Linux Daemon
|
|
//
|
|
|
|
//****************************************************************************
|
|
// includes
|
|
//***************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.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 <sys/wait.h>
|
|
|
|
#include "ClockTimer.h"
|
|
#include "CanTxGenerator.h"
|
|
|
|
//****************************************************************************
|
|
// defines
|
|
//***************************************************************************/
|
|
|
|
#ifndef min
|
|
#define min(A,B) ((A)<(B)?(A):(B))
|
|
#endif
|
|
|
|
//****************************************************************************
|
|
// macros
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// structs & typedefs
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// global constants
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// global variables
|
|
//***************************************************************************/
|
|
|
|
extern CAN_Packet Can;
|
|
|
|
//****************************************************************************
|
|
// static constants
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// static variables
|
|
//***************************************************************************/
|
|
|
|
static CanTxGenerator *Self = NULL;
|
|
|
|
//****************************************************************************
|
|
// static functions
|
|
//***************************************************************************/
|
|
|
|
//****************************************************************************
|
|
// C++ functions
|
|
//***************************************************************************/
|
|
|
|
CanTxGenerator::CanTxGenerator()
|
|
{
|
|
Self = this;
|
|
m_period = 100;
|
|
}
|
|
|
|
CanTxGenerator::~CanTxGenerator()
|
|
{
|
|
}
|
|
|
|
// generator itself
|
|
void *CanTxGenerator::Run(void *arg)
|
|
{
|
|
ClockTimer Loop;
|
|
|
|
Loop.Start( m_period * 1000 ); // usec
|
|
|
|
while (1)
|
|
{
|
|
|
|
// send out
|
|
SendTo( &Can, sizeof(Can) );
|
|
|
|
// log this message // log this message
|
|
if ( Logging.IsLogging() )
|
|
{
|
|
struct timeval tv;
|
|
struct tm tm;
|
|
gettimeofday( &tv, NULL );
|
|
gmtime_r( &tv.tv_sec, &tm );
|
|
char buf[32];
|
|
sprintf( buf, "%4d/%2d/%2d-%2d:%2d:%2d.%03ld",
|
|
tm.tm_year+1900, tm.tm_mon, tm.tm_mday,
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec,
|
|
tv.tv_usec / 1000L
|
|
);
|
|
|
|
Logging.LogPrintf( "%s,%s,%f,%f,%f,%f,%u,%f,%u,%f,%f,%f,%f,%f,%u,%u,%u,%f,%u,%f",
|
|
buf,
|
|
"TX",
|
|
0.0,
|
|
0.0,
|
|
0.0,
|
|
0.0,
|
|
0,
|
|
Can.fSpeed,
|
|
Can.byTransmission,
|
|
Can.fSteering,
|
|
Can.fAccelLongitudinal,
|
|
Can.fAccelLateral,
|
|
Can.fAccelVertical,
|
|
Can.fYawRate,
|
|
Can.wBrakeSystemStatus,
|
|
Can.wEventFlags,
|
|
Can.byExteriorLights,
|
|
Can.fThrottle,
|
|
Can.byFrontWipers,
|
|
0.0
|
|
);
|
|
}
|
|
|
|
// 100 msec, leave a little time to do the work
|
|
Loop.Sync();
|
|
// msleep( m_period - 10L );
|
|
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|