我有一个零星的任务打印一些东西。我想在指定的时间,即下午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;
答案 0 :(得分:2)
GNATCOLL.Ravenscar
包遵循Ravenscar配置文件的限制,但可以将它们编译到具有不受限制的配置文件的分区中。所以,除非你正在为一个只支持Ravenscar的系统进行编译,否则你可以(由于调用时间有限而出现一个小错误)
Ada.Calendar.Time
Ada.Calendar.Clock
以获得Duration
Ada.Real_Time.To_Time_Span
转换为Time_Span