零星任务将在特定时间运行

时间:2016-05-26 08:20:53

标签: real-time ada

我有一个零星的任务打印一些东西。我想在指定的时间,即下午4:40运行此任务。

我有一个想法是创建循环任务,它检查时间以及当时间等于我指定的时间时,这个循环任务会重新发现偶发任务的障碍。但是如何检查我的指定时间(表示为Unix时间戳或字符串)是否等于现在的时间?如何根据Ravenscar Profile将我指定的时间转换为Ada.Real_Time.Time?

我如何在Ada中实现这一目标?

这是我的代码:

sprinkler.ads

pragma Profile(Ravenscar);
with GNATCOLL.Ravenscar.Simple_Cyclic_Task;
with GNATCOLL.Ravenscar.Simple_Sporadic_Task;

package Sprinkler is

    Counter : Integer := 0;
    MyTime : String := "4:45";

    procedure My_Cyclic_Operation;
    package My_Cyclic_Task is new GNATCOLL.Ravenscar.Simple_Cyclic_Task
     (Task_Priority => 10,
      Phase => 0,
      Period => 1000,
      Cyclic_Operation => My_Cyclic_Operation);


    procedure My_Sporadic_Operation;
    package My_Sporadic_Task is new GNATCOLL.Ravenscar.Simple_Sporadic_Task
        (Task_Priority => 10,
        Minimum_Interelease_Time => 1_000,
        Protocol_Ceiling => 15,
        Sporadic_Operation => My_Sporadic_Operation);

end Sprinkler;

sprinkler.adb

pragma Profile(Ravenscar);
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;

package body Sprinkler is

    procedure My_Cyclic_Operation is
    begin 
        -- Here I want to run My_Sporadic_Operation when time at now is equal to my specified time
        null;
    end My_Cyclic_Operation;

    procedure My_Sporadic_Operation is
    begin
        Put_Line("Sporadic at specified time!");
    end;

end Sprinkler;

1 个答案:

答案 0 :(得分:2)

GNATCOLL.Ravenscar包遵循Ravenscar配置文件的限制,但可以将它们编译到具有不受限制的配置文件的分区中。所以,除非你正在为一个只支持Ravenscar的系统进行编译,否则你可以(由于调用时间有限而出现一个小错误)

  • 将您的下午4:40转换为Ada.Calendar.Time
  • 减去Ada.Calendar.Clock以获得Duration
  • 使用Ada.Real_Time.To_Time_Span转换为Time_Span