我有个零星的任务要打印一些东西。我想在指定的时间,即下午4:40运行这个任务。
我有一个创建循环任务的想法,它检查时间,当时间等于我指定的时间时,这个循环任务实现了零星任务的障碍。但是,如何检查我指定的时间(表示为Unix时间戳或字符串)现在是否等于时间?如何根据Ravenscar配置文件将我指定的时间转换为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;发布于 2016-05-29 07:22:50
GNATCOLL.Ravenscar包遵守Ravenscar配置文件的限制,但是可以将它们编译到具有无限制配置文件的分区中。因此,除非您正在为一个只支持Ravenscar的系统进行编译,否则您可以(因为调用时间有限而导致一个小错误)。
Ada.Calendar.TimeAda.Calendar.Clock以获得DurationAda.Real_Time.To_Time_Span转换为Time_Spanhttps://stackoverflow.com/questions/37455321
复制相似问题