text stringlengths 0 234 |
|---|
procedure parse_wire(w_str : in String; w : in out Wire.Vector) is |
start : Natural := w_str'First; |
finish : Natural; |
delimiters : constant Ada.Strings.Maps.Character_Set := Ada.Strings.Maps.to_set(Sequence => ","); |
begin |
w.clear; |
while start <= w_str'Last loop |
Ada.Strings.Fixed.find_token(Source => w_str(start .. w_str'Last), |
Set => delimiters, |
Test => Ada.Strings.outside, |
First => start, Last => finish); |
if not(finish = 0 and then start = w_str'First) then |
w.append((dir => to_dir(w_str(start)), distance => Integer'Value(w_str(start+1 .. finish)))); |
end if; |
start := finish + 1; |
end loop; |
end parse_wire; |
procedure step(pos : in out Position; dir : in Direction) is |
begin |
case dir is |
when Up => pos := (x => pos.x, y => pos.y - 1, dist => pos.dist + 1); |
when Down => pos := (x => pos.x, y => pos.y + 1, dist => pos.dist + 1); |
when Left => pos := (x => pos.x - 1, y => pos.y, dist => pos.dist + 1); |
when Right => pos := (x => pos.x + 1, y => pos.y, dist => pos.dist + 1); |
end case; |
end step; |
procedure expand(pos : in out Position; segment : in Wire_Segment; points : in out Wire_Points.Set) is |
begin |
for i in 1 .. segment.distance loop |
step(pos => pos, dir => segment.dir); |
points.include(pos); |
end loop; |
end expand; |
procedure expand_segments(w : in Wire.Vector; points : in out Wire_Points.Set) is |
start_pos : constant Position := (x => 0, y => 0, dist => 0); |
curr_pos : Position := start_pos; |
begin |
points.clear; |
for segment of w loop |
expand(pos => curr_pos, segment => segment, points => points); |
end loop; |
end expand_segments; |
procedure load(w1 : in String; w2 : in String) is |
begin |
parse_wire(w1, wire_1); |
expand_segments(wire_1, wire_points_1); |
parse_wire(w2, wire_2); |
expand_segments(wire_2, wire_points_2); |
end load; |
procedure load_file(path : String) is |
file : TIO.File_Type; |
begin |
TIO.open(File => file, Mode => TIO.In_File, Name => path); |
declare |
str1 : constant String := TIO.get_line(file); |
str2 : constant String := TIO.get_line(file); |
begin |
load(w1 => str1, w2 => str2); |
Function Definition: procedure Ping is |
Function Body: use type Interfaces.Unsigned_32; |
use type Net.Ip_Addr; |
use type Net.DHCP.State_Type; |
use type Ada.Real_Time.Time; |
use type Ada.Real_Time.Time_Span; |
procedure Refresh; |
procedure Header; |
procedure Refresh is |
Y : Natural := 90; |
Hosts : constant Pinger.Ping_Info_Array := Pinger.Get_Hosts; |
begin |
for I in Hosts'Range loop |
Demos.Put (0, Y, Net.Utils.To_String (Hosts (I).Ip)); |
Demos.Put (250, Y, Net.Uint64 (Hosts (I).Seq)); |
Demos.Put (350, Y, Net.Uint64 (Hosts (I).Received)); |
Y := Y + 16; |
end loop; |
Demos.Refresh_Ifnet_Stats; |
STM32.Board.Display.Update_Layer (1); |
end Refresh; |
procedure Header is |
begin |
Demos.Put (0, 70, "Host"); |
Demos.Put (326, 70, "Send"); |
Demos.Put (402, 70, "Receive"); |
end Header; |
procedure Initialize is new Demos.Initialize (Header); |
-- The ping period. |
PING_PERIOD : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds (1000); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.