Skip to content

Commit

Permalink
Merge pull request #22 from PSU-Capstone-Team24/Console_Cleanup
Browse files Browse the repository at this point in the history
Console Output Cleanup
  • Loading branch information
masonticehurst authored Feb 11, 2024
2 parents b05ac13 + aaa506c commit 337ed15
Show file tree
Hide file tree
Showing 22 changed files with 963 additions and 258 deletions.
32 changes: 21 additions & 11 deletions eRINA_STM32F7/src/dns/dns.adb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ procedure Dns is
procedure Refresh is
use type Net.DHCP.State_Type;

Y : Natural := 90;
Y : Natural := 90;
Status : Net.Error_Code;
pragma Unreferenced (Status);
begin
for I in Dns_List.Queries'Range loop
if Dns_List.Queries (I).Get_Name'Length > 0 then
Demos.Put (0, Y, Dns_List.Queries (I).Get_Name);
Demos.Put (180, Y, Net.Utils.To_String (Dns_List.Queries (I).Get_Ip));
Demos.Put
(180, Y, Net.Utils.To_String (Dns_List.Queries (I).Get_Ip));
Demos.Put (330, Y, Get_Status (Dns_List.Queries (I)));
Demos.Put (400, Y, Net.Uint32'Image (Dns_List.Queries (I).Get_Ttl));
Demos.Put
(400, Y, Net.Uint32'Image (Dns_List.Queries (I).Get_Ttl));
-- Put (250, Y, Net.Uint64 (Hosts (I).Seq));
-- Demos.Put (400, Y, Net.Uint64 (Dns_List.Queries (I).));
Y := Y + 16;
Expand All @@ -89,13 +91,20 @@ procedure Dns is
STM32.Board.Display.Update_Layer (1);

if Demos.Dhcp.Get_State = Net.DHCP.STATE_BOUND then
Dns_List.Queries (1).Resolve (Demos.Ifnet'Access, "www.google.com", Status);
Dns_List.Queries (2).Resolve (Demos.Ifnet'Access, "www.facebook.com", Status);
Dns_List.Queries (3).Resolve (Demos.Ifnet'Access, "www.apple.com", Status);
Dns_List.Queries (4).Resolve (Demos.Ifnet'Access, "www.adacore.com", Status);
Dns_List.Queries (5).Resolve (Demos.Ifnet'Access, "github.com", Status);
Dns_List.Queries (6).Resolve (Demos.Ifnet'Access, "www.twitter.com", Status);
Dns_List.Queries (7).Resolve (Demos.Ifnet'Access, "www.kalabosse.com", Status);
Dns_List.Queries (1).Resolve
(Demos.Ifnet'Access, "www.google.com", Status);
Dns_List.Queries (2).Resolve
(Demos.Ifnet'Access, "www.facebook.com", Status);
Dns_List.Queries (3).Resolve
(Demos.Ifnet'Access, "www.apple.com", Status);
Dns_List.Queries (4).Resolve
(Demos.Ifnet'Access, "www.adacore.com", Status);
Dns_List.Queries (5).Resolve
(Demos.Ifnet'Access, "github.com", Status);
Dns_List.Queries (6).Resolve
(Demos.Ifnet'Access, "www.twitter.com", Status);
Dns_List.Queries (7).Resolve
(Demos.Ifnet'Access, "www.kalabosse.com", Status);
end if;
end Refresh;

Expand All @@ -104,7 +113,8 @@ procedure Dns is
procedure Initialize is new Demos.Initialize (Header);

-- The display refresh period.
REFRESH_PERIOD : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds (1000);
REFRESH_PERIOD : constant Ada.Real_Time.Time_Span :=
Ada.Real_Time.Milliseconds (1_000);

-- Refresh display deadline.
Display_Deadline : Ada.Real_Time.Time;
Expand Down
10 changes: 6 additions & 4 deletions eRINA_STM32F7/src/echo/echo.adb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ procedure Echo is
procedure Header;

procedure Refresh is
Msg : constant Echo_Server.Message_List := Echo_Server.Server.Messages.Get;
Y : Natural := 120;
Msg : constant Echo_Server.Message_List :=
Echo_Server.Server.Messages.Get;
Y : Natural := 120;
begin
Demos.Refresh_Ifnet_Stats;
Demos.Put (250, 100, Net.Uint64 (Echo_Server.Server.Count));
Expand All @@ -74,8 +75,9 @@ procedure Echo is
begin
Initialize ("STM32 Echo");

Echo_Server.Server.Bind (Demos.Ifnet'Access, (Port => Net.Headers.To_Network (7),
Addr => (others => 0)));
Echo_Server.Server.Bind
(Demos.Ifnet'Access,
(Port => Net.Headers.To_Network (7), Addr => (others => 0)));

loop
Net.Protos.Arp.Timeout (Demos.Ifnet);
Expand Down
22 changes: 12 additions & 10 deletions eRINA_STM32F7/src/echo/echo_server.adb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ package body Echo_Server is
begin
Id := Id + 1;
if Id <= List'Last then
List (Id).Id := Id;
List (Id).Id := Id;
List (Id).Content := Content.Content;
else
List (1 .. List'Last - 1) := List (2 .. List'Last);
List (List'Last).Id := Id;
List (List'Last).Content := Content.Content;
List (List'Last).Id := Id;
List (List'Last).Content := Content.Content;
end if;
end Echo;

Expand All @@ -40,17 +40,19 @@ package body Echo_Server is

end Logger;

overriding
procedure Receive (Endpoint : in out Echo_Server;
From : in Net.Sockets.Sockaddr_In;
Packet : in out Net.Buffers.Buffer_Type) is
overriding procedure Receive
(Endpoint : in out Echo_Server; From : in Net.Sockets.Sockaddr_In;
Packet : in out Net.Buffers.Buffer_Type)
is
use type Net.Uint16;

Size : constant Net.Uint16 := Packet.Get_Data_Size (Net.Buffers.UDP_PACKET);
Size : constant Net.Uint16 :=
Packet.Get_Data_Size (Net.Buffers.UDP_PACKET);
Status : Net.Error_Code;
Msg : Message;
Len : constant Natural
:= (if Size > Msg.Content'Length then Msg.Content'Length else Natural (Size));
Len : constant Natural :=
(if Size > Msg.Content'Length then Msg.Content'Length
else Natural (Size));
begin
Packet.Get_String (Msg.Content (1 .. Len));
Packet.Set_Data_Size (Size);
Expand Down
9 changes: 4 additions & 5 deletions eRINA_STM32F7/src/echo/echo_server.ads
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with Net.Buffers;
package Echo_Server is

type Message is record
Id : Natural := 0;
Id : Natural := 0;
Content : String (1 .. 80) := (others => ' ');
end record;
type Message_List is array (1 .. 10) of Message;
Expand All @@ -42,10 +42,9 @@ package Echo_Server is
Messages : Logger;
end record;

overriding
procedure Receive (Endpoint : in out Echo_Server;
From : in Net.Sockets.Sockaddr_In;
Packet : in out Net.Buffers.Buffer_Type);
overriding procedure Receive
(Endpoint : in out Echo_Server; From : in Net.Sockets.Sockaddr_In;
Packet : in out Net.Buffers.Buffer_Type);

Server : aliased Echo_Server;

Expand Down
15 changes: 8 additions & 7 deletions eRINA_STM32F7/src/ping/ping.adb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ procedure Ping is
Counter : Natural := 3;

procedure Refresh is
Y : Natural := 90;
Y : Natural := 90;
Hosts : constant Pinger.Ping_Info_Array := Pinger.Get_Hosts;
begin
for I in Hosts'Range loop
Expand All @@ -86,24 +86,25 @@ procedure Ping is
procedure Initialize is new Demos.Initialize (Header);

-- The ping period.
PING_PERIOD : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds (1000);
PING_PERIOD : constant Ada.Real_Time.Time_Span :=
Ada.Real_Time.Milliseconds (1_000);

-- Send ping echo request deadline
Ping_Deadline : Ada.Real_Time.Time;

Icmp_Handler : Net.Protos.Receive_Handler;
Icmp_Handler : Net.Protos.Receive_Handler;
begin
Initialize ("STM32 Ping");

Pinger.Add_Host ((192, 168, 1, 1));
Pinger.Add_Host ((8, 8, 8, 8));
Net.Protos.Dispatchers.Set_Handler (Proto => Net.Protos.IPv4.P_ICMP,
Handler => Pinger.Receive'Access,
Previous => Icmp_Handler);
Net.Protos.Dispatchers.Set_Handler
(Proto => Net.Protos.IPv4.P_ICMP, Handler => Pinger.Receive'Access,
Previous => Icmp_Handler);

-- Change font to 8x8.
Demos.Current_Font := BMP_Fonts.Font8x8;
Ping_Deadline := Ada.Real_Time.Clock;
Ping_Deadline := Ada.Real_Time.Clock;
loop
declare
Now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
Expand Down
25 changes: 12 additions & 13 deletions eRINA_STM32F7/src/ping/pinger.adb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ package body Pinger is
for I in 1 .. Last_Host loop
if Hosts (I).Ip = Ip_Hdr.Ip_Src then
Hosts (I).Received := Hosts (I).Received + 1;
Receive_Count := Receive_Count + 1;
Receive_Count := Receive_Count + 1;
return;
end if;
end loop;
Expand All @@ -58,7 +58,7 @@ package body Pinger is
for I in Targets'Range loop
Hosts (I).Seq := Hosts (I).Seq + 1;
end loop;
Targets := Hosts (Targets'Range);
Targets := Hosts (Targets'Range);
Send_Count := Send_Count + 1;
end Prepare_Send;

Expand All @@ -75,9 +75,9 @@ package body Pinger is
return;
end if;
end loop;
Last_Host := Last_Host + 1;
Hosts (Last_Host).Ip := Ip;
Hosts (Last_Host).Seq := 0;
Last_Host := Last_Host + 1;
Hosts (Last_Host).Ip := Ip;
Hosts (Last_Host).Seq := 0;
Hosts (Last_Host).Received := 0;
end if;
end Add_Host;
Expand All @@ -100,8 +100,10 @@ package body Pinger is
Pinger.Add_Host (Ip);
end Add_Host;

procedure Receive (Ifnet : in out Net.Interfaces.Ifnet_Type'Class;
Packet : in out Net.Buffers.Buffer_Type) is
procedure Receive
(Ifnet : in out Net.Interfaces.Ifnet_Type'Class;
Packet : in out Net.Buffers.Buffer_Type)
is
Hdr : constant Net.Headers.ICMP_Header_Access := Packet.ICMP;
begin
if Hdr.Icmp_Type = Net.Headers.ICMP_ECHO_REPLY then
Expand All @@ -125,12 +127,9 @@ package body Pinger is
exit when Packet.Is_Null;

Packet.Set_Length (64);
Net.Protos.Icmp.Echo_Request (Ifnet => Demos.Ifnet,
Target_Ip => Hosts (I).Ip,
Packet => Packet,
Seq => Hosts (I).Seq,
Ident => 1234,
Status => Status);
Net.Protos.Icmp.Echo_Request
(Ifnet => Demos.Ifnet, Target_Ip => Hosts (I).Ip, Packet => Packet,
Seq => Hosts (I).Seq, Ident => 1_234, Status => Status);
end loop;
end Do_Ping;

Expand Down
5 changes: 3 additions & 2 deletions eRINA_STM32F7/src/ping/pinger.ads
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ package Pinger is
-- Send the ICMP echo request to each host.
procedure Do_Ping;

procedure Receive (Ifnet : in out Net.Interfaces.Ifnet_Type'Class;
Packet : in out Net.Buffers.Buffer_Type);
procedure Receive
(Ifnet : in out Net.Interfaces.Ifnet_Type'Class;
Packet : in out Net.Buffers.Buffer_Type);

end Pinger;
88 changes: 88 additions & 0 deletions eRINA_STM32F7/src/rina/debug.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
with Bitmapped_Drawing;
with STM32.Board;
with GUI;

package body Debug is

-- Probably a cleaner way to do this
procedure Print (Debug_Level : in Debug; Msg : in String) is
currentLine : constant Natural :=
(CURRENT_CONSOLE_POSITION.Y - 100) / FONT_HEIGHT; -- zero indexed
Foreground : HAL.Bitmap.Bitmap_Color;
Background : HAL.Bitmap.Bitmap_Color;
begin

Foreground :=
(case Debug_Level is when Info | Error => HAL.Bitmap.White,
when Warning => HAL.Bitmap.Black);

Background :=
(case Debug_Level is when Info => HAL.Bitmap.Blue,
when Warning => HAL.Bitmap.Yellow, when Error => HAL.Bitmap.Red);

if currentLine > MAX_LINES then
-- Shift console lines up
for I in 1 .. MAX_LINES loop
CopyLine (I, I - 1, I = MAX_LINES);
end loop;

-- Adjust Y position to overwrite the last line
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y - FONT_HEIGHT - LINE_PADDING;
end if;

-- Draw debug prefix
Bitmapped_Drawing.Draw_String
(Buffer => GUI.ScreenBuffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X, CURRENT_CONSOLE_POSITION.Y)),
Msg => Debug_Level'Image, Font => BMP_Fonts.Font8x8,
Foreground => Foreground, Background => Background);

-- Draw actual message text
Bitmapped_Drawing.Draw_String
(Buffer => GUI.ScreenBuffer.all,
Start =>
GUI.Scale
((CURRENT_CONSOLE_POSITION.X +
GUI.MeasureText (Debug_Level'Image, BMP_Fonts.Font8x8).Width +
LINE_PADDING,
CURRENT_CONSOLE_POSITION.Y)),
Msg => Msg, Font => BMP_Fonts.Font8x8, Foreground => HAL.Bitmap.White,
Background => HAL.Bitmap.Black);

-- Move the Y position down for the next message
CURRENT_CONSOLE_POSITION.Y :=
CURRENT_CONSOLE_POSITION.Y + FONT_HEIGHT + LINE_PADDING;

STM32.Board.Display.Update_Layer (1, True);
end Print;

procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean)
is
-- TODO: Cleanup later...
srcToPoint : constant HAL.Bitmap.Point :=
(0, (CONSOLE_STARTING_POINT.Y + (FONT_HEIGHT * SrcLineNumber)));
dstToPoint : constant HAL.Bitmap.Point :=
(0, (CONSOLE_STARTING_POINT.Y + (FONT_HEIGHT * DstLineNumer)));
srcRect : constant HAL.Bitmap.Rect :=
(Position => srcToPoint, Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT);
begin
HAL.Bitmap.Copy_Rect
(Src_Buffer => GUI.ScreenBuffer.all,
Src_Pt => srcToPoint,
Dst_Buffer => GUI.ScreenBuffer.all,
Dst_Pt => dstToPoint, Width => GUI.Board_Resolution.Width,
Height => FONT_HEIGHT, Synchronous => True);
if DeleteSrc then
HAL.Bitmap.Fill_Rect
(Buffer => GUI.ScreenBuffer.all,
Area => srcRect);
end if;
STM32.Board.Display.Update_Layer (1, True);
end CopyLine;
end Debug;
18 changes: 18 additions & 0 deletions eRINA_STM32F7/src/rina/debug.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
with HAL.Bitmap;
with BMP_Fonts;

package Debug is
type Debug is (Error, Warning, Info);

CONSOLE_STARTING_POINT : HAL.Bitmap.Point := (0, 100);
CURRENT_CONSOLE_POSITION : HAL.Bitmap.Point := (0, 100);
FONT_HEIGHT : constant Natural :=
BMP_Fonts.Char_Height (Font => BMP_Fonts.Font8x8);
MAX_LINES : constant Natural := 20;
LINE_PADDING : constant Natural := 2;

procedure Print (Debug_Level : in Debug; Msg : in String);
procedure CopyLine
(SrcLineNumber : in Natural; DstLineNumer : in Natural;
DeleteSrc : in Boolean);
end Debug;
Loading

0 comments on commit 337ed15

Please sign in to comment.