Linux “没有可用的来源”__0xb779e424“处的内核”vsyscall();? #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #定义百万一百万 计时器\u t firstTimerID、se

Linux “没有可用的来源”__0xb779e424“处的内核”vsyscall();? #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #定义百万一百万 计时器\u t firstTimerID、se,linux,sockets,udp,kernel,system-calls,Linux,Sockets,Udp,Kernel,System Calls,“没有可用的来源”__0xb779e424“处的内核”vsyscall();? #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #定义百万一百万 计时器\u t firstTimerID、secondTimerID、thirdTimerID; 双任务2ms\u光栅、任务10ms\u光栅、任务100ms\u光栅; 客户端地址中的结构sockaddr\u; int接受插座; char-buf[1024]; chara[128]; 长rc

“没有可用的来源”__0xb779e424“处的内核”vsyscall();?
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#定义百万一百万
计时器\u t firstTimerID、secondTimerID、thirdTimerID;
双任务2ms\u光栅、任务10ms\u光栅、任务100ms\u光栅;
客户端地址中的结构sockaddr\u;
int接受插座;
char-buf[1024];
chara[128];
长rc,千字节;
int端口=18033;
无效TASK1(Task2ms_光栅)
{
结构timespec启动、停止;
uint32开始时间,停止时间;
if((startTime=clock\u gettime(clock\u REALTIME,&start))=-1){
perror(“时钟获取时间”);
}
startTime=start.tv\u sec+0.00000001*start.tv\u nsec;
//printf(“开始时间为%lf”,开始时间);
//返回退出成功;
/*触发2ms XCP光栅的DAQ*/
if(XCPEVENT_DAQ_重载&Xcp_DoDaqForEvent_2msRstr())
{
++numdaq2ms;
}
/*每2ms更新一次修改的变量*/
计数器32+=斜率32;
/*2ms XCP光栅的触发时间*/
如果(启用旁路2ms)
{
如果(XCPEVENT\u缺失\u DTO和Xcp\u DoStimForEvent\u 2msRstr())
{
++numMissingDto2ms;
}
}
if((stopTime=clock\u gettime(clock\u REALTIME,&stop))=-1){
perror(“时钟获取时间”);
}
stopTime=stop.tv\u sec+0.00000001*stop.tv\u nsec;
//printf(“停止时间为%ld”,停止时间);
持续时间2ms=(停止时间-开始时间);
//printf(“时差=%ld\n”,持续时间2ms);
}
无效任务2(任务10ms\u光栅)
{
结构timespec启动、停止;
uint32开始时间,停止时间;
if((startTime=clock\u gettime(clock\u REALTIME,&start))=-1){
perror(“时钟获取时间”);
}
startTime=start.tv\u sec+0.00000001*start.tv\u nsec;
//printf(“开始时间为%lf”,开始时间);
/*触发10ms XCP光栅的DAQ*/
如果(XCPEVENT\u DAQ\u重载和Xcp\u DoDaqForEvent\u 10MSRSSTR())
{
++numdaq10ms;
}
/*每10毫秒更新一次修改的变量*/
计数器16+=斜率16;
/*10ms XCP光栅的触发时间*/
如果(启用10毫秒)
{
如果(XCPEVENT\u缺失\u DTO和Xcp\u DoStimForEvent\u 10msRstr())
{
++数值为10ms;
}
}
if((stopTime=clock\u gettime(clock\u REALTIME,&stop))=-1){
perror(“时钟获取时间”);
}
Xcp_CmdProcessor();
stopTime=stop.tv\u sec+0.00000001*stop.tv\u nsec;
//printf(“停止时间为%lf”,停止时间);
持续时间10ms=(stop.tv_秒-start.tv_秒)
+(双)(stop.tv\u nsec-start.tv\u nsec)
/(加倍)100万;
//printf(“时差=%ld\n”,持续时间10ms);
}
void TASK3(Task100ms\u光栅)
{
结构timespec启动、停止;
uint32开始时间,停止时间;
if((startTime=clock\u gettime(clock\u REALTIME,&start))=-1)
{
perror(“时钟获取时间”);
}
startTime=start.tv\u sec+0.00000001*start.tv\u nsec;
//printf(“开始时间为%lf”,开始时间);
/*触发100ms XCP光栅的DAQ*/
if(XCPEVENT_DAQ_重载&Xcp_DoDaqForEvent_100msRstr())
{
++numdaq100ms;
}
/*更新每100ms修改一次的变量*/
计数器8+=斜率8;
/*触发100ms XCP光栅的STIM*/
如果(启用100毫秒)
{
如果(XCPEVENT\u缺失\u DTO和Xcp\u DoStimForEvent\u 100msRstr())
{
++100毫秒;
}
}
if((stopTime=clock\u gettime(clock\u REALTIME,&stop))=-1){
perror(“时钟获取时间”);
}
stopTime=stop.tv\u sec+0.00000001*stop.tv\u nsec;
//printf(“停止时间为%lf”,停止时间);
持续时间100ms=(stop.tv_秒-start.tv_秒)
+(双)(stop.tv\u nsec-start.tv\u nsec)
/(加倍)100万;
//printf(“时差=%ld\n”,持续时间100ms);
}
静态void timerHandler(int-sig、siginfo\u-t*si、void*uc)
{
定时器_t*tidp;
tidp=si->si_value.sival_ptr;
如果(*tidp==firstTimerID)
TASK1(Task2ms_光栅);
else if(*tidp==secondTimerID)
TASK2(Task10ms_光栅);
如果(*tidp==thirdTimerID),则为else
TASK3(Task100ms_光栅);
}
静态int makeTimer(字符*名称、计时器\u t*timerID、int expireMS、int intervalMS)
{
结构sigte;
结构itimerspec its;
struct-sigaction-sa;
int sigNo=SIGRTMIN;
/*设置信号处理器*/
sa.sa_flags=sa_SIGINFO;
sa.sa_sigaction=timerHandler;
sigemptyset(和sa.sa_面具);
if(sigaction(sigNo,&sa,NULL)=-1)
{
佩罗尔(“sigaction”);
}
/*设置并启用报警*/
te.sigev_notify=sigev_信号;
te.sigev_signo=signo;
te.sigev_value.sival_ptr=timerID;
计时器\u创建(时钟\u实时,&te,timerID);
its.it_interval.tv_sec=0;
its.it\u interval.tv\u nsec=间隔*1000000;
its.it_value.tv_sec=0;
its.it\u value.tv\u nsec=expireMS*1000000;
timer_settime(*timerID,0,&its,NULL);
返回1;
}
int CreateSocket()
{
socklen_t len=sizeof(客户);
//UDP的套接字创建
acceptSocket=socket(AF_INET,SOCK_DGRAM,0);
if(acceptSocket==-1)
{
printf(“失败:套接字创建失败,失败代码\n”);
返回1;
}
其他的
{
printf(“套接字已启动!\n”);
}
memset(&addr,0,sizeof(addr));
地址sinu family=AF\u INET;
地址sin_端口=htons(端口);
地址sin_addr.s_addr=htonl(不包含任何地址);
rc=bind(acceptSocket,(struct sockaddr*)&addr,sizeof(addr));
如果(rc==-1)
{
printf(“故障:侦听,故障代码:\n”);
返回1;
}
其他的
{
#include <features.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

#include <netinet/in.h>
#include <arpa/inet.h>






#define million 1000000L

timer_t firstTimerID, secondTimerID, thirdTimerID;
double Task2ms_Raster, Task10ms_Raster, Task100ms_Raster;

struct sockaddr_in addr, client;
int acceptSocket;
char buf[1024];
char a[128];
long rc, sentbytes;
int port = 18033;






void TASK1(Task2ms_Raster)
{

     struct timespec start, stop;
     uint32 startTime, stopTime;

        if( (startTime = clock_gettime( CLOCK_REALTIME, &start)) == -1 ) {
          perror("clock gettime");

        }

        startTime =start.tv_sec + 0.00000001 * start.tv_nsec;
             //  printf("start time is %lf", StartTime);


       // return EXIT_SUCCESS;

    /* Trigger DAQ for the 2ms XCP raster. */
    if( XCPEVENT_DAQ_OVERLOAD & Xcp_DoDaqForEvent_2msRstr( ))
    {
        ++numDaqOverload2ms;
    }

    /* Update those variables which are modified every 2ms. */
 counter32 += slope32;

    /* Trigger STIM for the 2ms XCP raster. */
  if( enableBypass2ms )
   {
        if( XCPEVENT_MISSING_DTO & Xcp_DoStimForEvent_2msRstr( ) )
        {
     ++numMissingDto2ms;
        }
        }
  if( (stopTime = clock_gettime( CLOCK_REALTIME, &stop)) == -1 ) {
          perror( "clock gettime" );

        }
  stopTime =  stop.tv_sec + 0.00000001 * stop.tv_nsec;
    //printf("stop time is %ld", stopTime);

            duration2ms = (stopTime- startTime);
           // printf( "time difference is= %ld\n", duration2ms );



}

void TASK2(Task10ms_Raster)
{
     struct timespec start, stop;

     uint32 startTime, stopTime;
            if( (startTime = clock_gettime( CLOCK_REALTIME, &start)) == -1 ) {
              perror( "clock gettime" );

            }

            startTime =start.tv_sec + 0.00000001 * start.tv_nsec;
             //  printf("start time is %lf", StartTime);


    /* Trigger DAQ for the 10ms XCP raster. */
    if( XCPEVENT_DAQ_OVERLOAD & Xcp_DoDaqForEvent_10msRstr( ))
    {
        ++numDaqOverload10ms;
    }

    /* Update those variables which are modified every 10ms. */
    counter16 += slope16;

    /* Trigger STIM for the 10ms XCP raster. */
    if( enableBypass10ms )
    {
        if( XCPEVENT_MISSING_DTO & Xcp_DoStimForEvent_10msRstr( ) )
        {
            ++numMissingDto10ms;
        }
    }

    if( (stopTime = clock_gettime( CLOCK_REALTIME, &stop)) == -1 ) {
              perror( "clock gettime" );

            }
    Xcp_CmdProcessor();

    stopTime =  stop.tv_sec + 0.00000001 * stop.tv_nsec;
      //printf("stop time is %lf", stopTime);


    duration10ms = ( stop.tv_sec - start.tv_sec )
                             + (double)( stop.tv_nsec - start.tv_nsec )
                               / (double)million;
           // printf( "time difference is= %ld\n", duration10ms );
}


void TASK3(Task100ms_Raster)
{
     struct timespec start, stop;
     uint32 startTime, stopTime;



            if( (startTime = clock_gettime( CLOCK_REALTIME, &start)) == -1 )
            {
              perror("clock gettime");

            }
           startTime =start.tv_sec + 0.00000001 * start.tv_nsec;
          // printf("start time is %lf", startTime);

    /* Trigger DAQ for the 100ms XCP raster. */
    if( XCPEVENT_DAQ_OVERLOAD & Xcp_DoDaqForEvent_100msRstr( ))
    {
        ++numDaqOverload100ms;
    }

    /* Update those variables which are modified every 100ms. */
    counter8 += slope8;


    /* Trigger STIM for the 100ms XCP raster. */
    if( enableBypass100ms )
    {
        if( XCPEVENT_MISSING_DTO & Xcp_DoStimForEvent_100msRstr( ) )
        {
            ++numMissingDto100ms;
        }
    }

    if((stopTime = clock_gettime( CLOCK_REALTIME, &stop)) == -1 ) {
              perror( "clock gettime" );

            }

    stopTime =  stop.tv_sec + 0.00000001 * stop.tv_nsec;
     // printf("stop time is %lf", stopTime);


    duration100ms = ( stop.tv_sec - start.tv_sec )
                     + (double)( stop.tv_nsec - start.tv_nsec )
                       / (double)million;
          //  printf( "time difference is= %ld\n", duration100ms );
}



static void timerHandler( int sig, siginfo_t *si, void *uc )
{
    timer_t *tidp;

    tidp = si->si_value.sival_ptr;

    if ( *tidp == firstTimerID )

        TASK1(Task2ms_Raster);
   else if ( *tidp == secondTimerID )
       TASK2(Task10ms_Raster);
    else if ( *tidp == thirdTimerID )
        TASK3(Task100ms_Raster);
}


 static int makeTimer( char *name, timer_t *timerID, int expireMS, int intervalMS )
{
    struct sigevent         te;
    struct itimerspec       its;
    struct sigaction        sa;
    int                     sigNo = SIGRTMIN;

    /* Set up signal handler. */
    sa.sa_flags = SA_SIGINFO;
    sa.sa_sigaction = timerHandler;
    sigemptyset(&sa.sa_mask);
    if (sigaction(sigNo, &sa, NULL) == -1)
    {
        perror("sigaction");
    }

    /* Set and enable alarm */
    te.sigev_notify = SIGEV_SIGNAL;
    te.sigev_signo = sigNo;
    te.sigev_value.sival_ptr = timerID;
    timer_create(CLOCK_REALTIME, &te, timerID);

    its.it_interval.tv_sec = 0;
    its.it_interval.tv_nsec = intervalMS * 1000000;
    its.it_value.tv_sec = 0;
    its.it_value.tv_nsec = expireMS * 1000000;
    timer_settime(*timerID, 0, &its, NULL);

    return 1;
}



int CreateSocket()
{

    socklen_t len = sizeof(client);
       // Socket creation for UDP

       acceptSocket=socket(AF_INET,SOCK_DGRAM,0);

       if(acceptSocket==-1)

       {

         printf("Failure: socket creation is failed, failure code\n");

         return 1;

       }

       else

       {

         printf("Socket started!\n");

       }

     memset(&addr, 0, sizeof(addr));

     addr.sin_family=AF_INET;

     addr.sin_port=htons(port);

     addr.sin_addr.s_addr=htonl(INADDR_ANY);

     rc=bind(acceptSocket,(struct sockaddr*)&addr,sizeof(addr));

     if(rc== -1)

     {

       printf("Failure: listen, failure code:\n");

       return 1;

     }

     else

     {

       printf("Socket an port %d \n",port);

     }


     if(acceptSocket == -1)
     {
         printf("Fehler: accept, fehler code:\n");

          return 1;
     }
     else
     {

     while(rc!=-1)
         {


         rc=recvfrom(acceptSocket,buf, sizeof(buf), 0, (struct sockaddr*) &client, &len);
         if(rc==0)
         {
           printf("Server has no connection..\n");
           break;
         }
         if(rc==-1)
         {
             printf("something went wrong with data %s", strerror(errno));
           break;
         }


         XcpIp_RxCallback( (uint16) rc, (uint8*) buf, (uint16) port );


                makeTimer("First Timer", &firstTimerID, 2, 2);   //2ms
             makeTimer("Second Timer", &secondTimerID, 10, 10);    //10ms
                makeTimer("Third Timer", &thirdTimerID, 100, 100);  //100ms
          }


     }

       close(acceptSocket);



       return 0;

     }



int main()
{

     Xcp_Initialize();
     CreateSocket();
     return 0;
}




void XcpApp_IpTransmit( uint16 XcpPort,  Xcp_StatePtr8 pBytes, uint16 numBytes )
{


        if ((long)XcpPort==port){
                sentbytes = sendto(acceptSocket,(char*)pBytes,(long)numBytes,0, (struct sockaddr*)&client, sizeof(client));
        }
        XcpIp_TxCallback(port,(uint16)sentbytes);
    }