-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_vehicle_message_type.adb
129 lines (108 loc) · 4.01 KB
/
old_vehicle_message_type.adb
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
with Ada.Calendar; use Ada.Calendar;
package body Vehicle_Message_Type is
----------------------------
-- Inter_Vehicle_Messages --
----------------------------
protected body Local_Vehicle_Messages is
procedure Init_Vehicle (Vehicle : Known_Vehicles_Type) is
begin
Known_Vehicles := Vehicle;
Vehicles_Size := 1;
end Init_Vehicle;
procedure Init_Globe (Globe : Known_Globes_Type) is
begin
Known_Globes := Globe;
Globes_Size := 1;
end Init_Globe;
-------------------
-- Update_Record --
-------------------
procedure Update_Record -- it will update both local Vehicles array and Globes array by receiving the array from other swarms,
(Vehicles : Known_Vehicles_Type; -- the procedure will also delete the info of the vehicle that is no longer discovered by others
Globes : Known_Globes_Type;
VSize : Integer; GSize : Integer)
is
TempVSize : Integer := Vehicles_Size;
TempGSize : Integer := Globes_Size;
TempIndex : Integer := 1;
begin
-- Vehicles update; during the loop we will check for the time and delete outdated info
if VSize /= 0 then
if Vehicles_Size = 0 then
Vehicles_Size := VSize;
Known_Vehicles := Vehicles;
else
for vo of Vehicles (1 .. VSize) loop
TempIndex := 1;
for vl of Known_Vehicles (1 .. Vehicles_Size) loop
if vo.Vehicle_ID = vl.Vehicle_ID then
if vo.LastMetTime > vl.LastMetTime then
vl := vo;
end if;
else
if TempIndex = Vehicles_Size then
TempVSize := TempVSize + 1;
Known_Vehicles (TempVSize) := vo;
end if;
end if;
TempIndex := TempIndex + 1;
end loop;
end loop;
Vehicles_Size := TempVSize;
end if;
end if;
-- Globes update
if GSize /= 0 then
if Globes_Size = 0 then
Globes_Size := GSize;
Known_Globes := Globes;
else
for go of Globes (1 .. GSize) loop
TempIndex := 1;
for gl of Known_Globes (1 .. Globes_Size) loop
if go.Globe_ID = gl.Globe_ID then
if go.LastUpdateTime > gl.LastUpdateTime then
gl := go;
end if;
else
if TempIndex = Globes_Size then
TempGSize := TempGSize + 1;
Known_Globes (TempGSize) := go;
end if;
end if;
TempIndex := TempIndex + 1;
end loop;
end loop;
end if;
end if;
end Update_Record;
--------------------------
-- Read_Vehicles_Record --
--------------------------
function Read_Vehicles_Record return Known_Vehicles_Type is
begin
return Known_Vehicles;
end Read_Vehicles_Record;
------------------------
-- Read_Globes_Record --
------------------------
function Read_Globes_Record return Known_Globes_Type is
begin
return Known_Globes;
end Read_Globes_Record;
------------------------
-- Read_Vehicles_Size --
------------------------
function Read_Vehicles_Size return Positive is
begin
return Vehicles_Size;
end Read_Vehicles_Size;
----------------------
-- Read_Globes_Size --
----------------------
function Read_Globes_Size return Positive is
begin
return Globes_Size;
end Read_Globes_Size;
end Local_Vehicle_Messages;
end Vehicle_Message_Type;