Как рассчитывать «на событие» в CANoe Capl? - PullRequest
0 голосов
/ 11 марта 2020

Я бы хотел рассчитывать на событие в течение 200 мс. Я пытался с этим кодом в CANoe Capl, но он не работает хорошо. Я не знаю, в чем проблема. помогите мне плз.

MainActivity.Capl

variables
{ 
  int timerConditionChecker = 0;
  int lockStatusMonitor = 0;

  mstimer conutCheckTimer;
}

on timer conutCheckTimer
{
  //do nothing
}

on sysvar_update sysvar::Frame2
{
    if(timerConditionChecker == 0)
    {
      lockStatusMonitor++;
      timerConditionChecker = 1;
      setTimer(conutCheckTimer, 500);
    }
    else if(timerConditionChecker == 1)
    {
      if(timeToElapse(conutCheckTimer) > 200)
      {
        timerConditionChecker = 2;
      }
      else
      {
        lockStatusMonitor++;
      }
    }
    else if(timerConditionChecker == 2)
    {
      timerConditionChecker = 3;
      Write("lockStatusMonitorCount = %d",lockStatusMonitor);
    }
    else{}
}

1 Ответ

1 голос
/ 11 марта 2020

Как насчет этого (я в основном использовал ваши имена переменных):

variables
{ 
  int lockStatusMonitor = 0;

  mstimer conutCheckTimer;
}

on timer conutCheckTimer
{
  // Is called after 200ms and will output how often the sysvar was updated within these 200ms
  Write("lockStatusMonitorCount = %d",lockStatusMonitor);
}

on sysvar_update sysvar::Frame2
{
    if(isTimerActive(conutCheckTimer))
    {
        // In case the 200ms have already started, just count
        lockStatusMonitor++;
    }
    else {
        // Timer is not yet active, so start counting for the next 200ms now
        lockStatusMonitor = 0; // or = 1 depending on whether your use case
        setTimer(conutCheckTimer, 200);
    }
}

Кроме того, использование отладчика CAPL должно помочь вам решить подобные проблемы.

...