-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
52 lines (43 loc) · 1.4 KB
/
scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Task:
def __init__(self, _pTask, _Delay, _Period):
self.pTask = _pTask
self.Delay = _Delay
self.Period = _Period
pTask = None
Delay = 0
Period = 0
RunMe = 0
TaskID = -1
class Scheduler:
TICK = 1000
SCH_MAX_TASKS = 40
SCH_tasks_G = []
current_index_task = 0
def __int__(self):
return
def SCH_Init(self):
self.current_index_task = 0
def SCH_Add_Task(self, pFunction, DELAY, PERIOD):
if self.current_index_task < self.SCH_MAX_TASKS:
aTask = Task(pFunction, DELAY / self.TICK, PERIOD / self.TICK)
aTask.TaskID = self.current_index_task
self.SCH_tasks_G.append(aTask)
self.current_index_task += 1
else:
print("PrivateTasks are full!!!")
def SCH_Update(self):
for i in range(0, len(self.SCH_tasks_G)):
if self.SCH_tasks_G[i].Delay > 0:
self.SCH_tasks_G[i].Delay -= 1
else:
self.SCH_tasks_G[i].Delay = self.SCH_tasks_G[i].Period
self.SCH_tasks_G[i].RunMe += 1
def SCH_Dispatch_Tasks(self):
for i in range(0, len(self.SCH_tasks_G)):
if self.SCH_tasks_G[i].RunMe > 0:
self.SCH_tasks_G[i].RunMe -= 1
self.SCH_tasks_G[i].pTask()
def SCH_Delete(self, aTask):
return
def SCH_GenerateID(self):
return -1