Skip to content

Commit

Permalink
Start button support, temp set Spa and Tpa length to 6 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
masonticehurst committed Feb 17, 2024
1 parent 59b8faa commit de12756
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 91 deletions.
12 changes: 6 additions & 6 deletions eRINA_STM32F7/src/net/net-headers.ads
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ package Net.Headers is
Ar_Op : Uint16;
end record;

type Ether_Arp (Appl_Length : Positive) is record
type Ether_Arp is record
Ea_Hdr : Arp_Header;
Arp_Sha : Ether_Addr;
Arp_Spa : String (1 .. Appl_Length);
Arp_Spa : String (1 .. 6);
Arp_Tha : Ether_Addr;
Arp_Tpa : String (1 .. Appl_Length);
Arp_Tpa : String (1 .. 6);
end record;
type Ether_Arp_Access is access all Ether_Arp;

-- ARP Ethernet packet
type Arp_Packet (Appl_Length : Positive) is record
type Arp_Packet is record
Ethernet : Net.Headers.Ether_Header;
Arp : Net.Headers.Ether_Arp (Appl_Length);
Arp : Net.Headers.Ether_Arp;
end record;
type Arp_Packet_Access is access all Arp_Packet;

Expand Down Expand Up @@ -113,7 +113,7 @@ package Net.Headers is
end record;

type Ether_EFCP is record
Ea_Hdr : EFCP_Header;
Efcp_Hdr : EFCP_Header;
end record;

type Ether_EFCP_Access is access all Ether_EFCP;
Expand Down
6 changes: 6 additions & 0 deletions eRINA_STM32F7/src/net/net-protos-arp.adb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-- limitations under the License.
-----------------------------------------------------------------------
with Ada.Real_Time;
with Debug;

with Net.Headers;
package body Net.Protos.Arp is
Expand Down Expand Up @@ -340,6 +341,11 @@ package body Net.Protos.Arp is
-- Ignore any future processing of this ARP message if it's not RINA-related
Ifnet.Rx_Stats.Ignored := Ifnet.Rx_Stats.Ignored + 1;
return;
else
Debug.Print
(Debug.Info,
"RINA ARP Request Received " & Req.Arp.Arp_Spa & " => " &
Req.Arp.Arp_Tpa);
end if;

case Net.Headers.To_Host (Req.Arp.Ea_Hdr.Ar_Op) is
Expand Down
4 changes: 1 addition & 3 deletions eRINA_STM32F7/src/net/receiver.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ with Net.Protos.Dispatchers;
with Net.Headers;
with Network;
with Debug;
with GUI;

package body Receiver is

Expand Down Expand Up @@ -42,7 +41,7 @@ package body Receiver is
Ada.Synchronous_Task_Control.Suspend_Until_True (Ready);

Debug.Print (Debug.Info, "Ethernet Controller Initialized!");

-- Loop receiving packets and dispatching them.
Min_Receive_Time := Us_Time'Last;
Max_Receive_Time := Us_Time'First;
Expand All @@ -60,7 +59,6 @@ package body Receiver is
if Ether.Ether_Type =
Net.Headers.To_Network (Net.Protos.ETHERTYPE_ARP)
then
Debug.Print (Debug.Info, "ARP Packet Received (" & Network.Ifnet.Rx_Stats.Ignored'Image & ") total");
Net.Protos.Arp.Receive (Network.Ifnet, Packet);
elsif Ether.Ether_Type =
Net.Headers.To_Network (Net.Protos.ETHERTYPE_RINA)
Expand Down
78 changes: 42 additions & 36 deletions eRINA_STM32F7/src/rina/debug.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,51 @@ with Bitmapped_Drawing;
with GUI;

package body Debug is

procedure Print (Debug_Level : in Debug; Msg : in String) is
M : Message;

-- These line variables shouldn't be confused with the array of lines that are drawn to the screen
-- This is specifically for strings that are too long to fit on a single line, so they can be broken up
Lines_Count : constant Positive := (Msg'Length + (Max_Characters_Per_Line - 1)) / Max_Characters_Per_Line;
Lines : array(1 .. Lines_Count) of String(1 .. Max_Characters_Per_Line);
Lines_Count : constant Positive :=
(Msg'Length + (Max_Characters_Per_Line - 1)) / Max_Characters_Per_Line;
Lines :
array (1 .. Lines_Count) of String (1 .. Max_Characters_Per_Line);
Line_Start : Positive := Lines'First;
begin
for I in 1 .. Lines_Count loop
-- Calculate the start of the next line segment. If it's the last segment, it may be shorter.
if Line_Start + Max_Characters_Per_Line - 1 <= Msg'Length then
Lines(I) := Msg(Line_Start .. Line_Start + Max_Characters_Per_Line - 1);
Lines (I) :=
Msg (Line_Start .. Line_Start + Max_Characters_Per_Line - 1);
else
-- Last segment, potentially shorter than Max_Characters_Per_Line
declare
Last_Segment : constant String := Msg(Line_Start .. Msg'Last);
Padded_Last_Segment : constant String(1 .. Max_Characters_Per_Line) := (Last_Segment & (Last_Segment'Length + 1 .. Max_Characters_Per_Line => ' '));
Last_Segment : constant String := Msg (Line_Start .. Msg'Last);
Padded_Last_Segment :
constant String (1 .. Max_Characters_Per_Line) :=
(Last_Segment &
(Last_Segment'Length + 1 .. Max_Characters_Per_Line => ' '));
begin
Lines(I) := Padded_Last_Segment;
Lines (I) := Padded_Last_Segment;
end;

-- Damn why can't it be this simple
-- Lines(I) := Msg(Line_Start .. Msg'Length) & (others => ' '); -- Fill the rest with spaces
end if;
-- Prepare for the next segment
Line_Start := Line_Start + Max_Characters_Per_Line;
end loop;

for I in Lines'Range loop
M.Msg := Lines(I);
M.Msg := Lines (I);
M.Level := Debug_Level;

-- Any lines after the first don't have the debug heading
if I > 1 then
M.Cont := True;
end if;

if Messages.Full then
Messages.Pop;
end if;
Expand All @@ -52,46 +58,46 @@ package body Debug is
procedure Render is
Foreground : HAL.Bitmap.Bitmap_Color;
Background : HAL.Bitmap.Bitmap_Color;
Pos : HAL.Bitmap.Point := Starting_Point;
Msg : Message;
Pos : HAL.Bitmap.Point := Starting_Point;
Msg : Message;
begin
for I in 0 .. Messages.Size - 1 loop
Msg := Messages.Peek (Queue_Max(I));
Pos := (Starting_Point.X, Starting_Point.Y + I * (Font_Height + Line_Padding));
Msg := Messages.Peek (Queue_Max (I));
Pos :=
(Starting_Point.X,
Starting_Point.Y + I * (Font_Height + Line_Padding));

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

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

-- Restart X position to start
Pos.X := Starting_Point.X;

if not Msg.Cont then
-- Draw debug prefix
Bitmapped_Drawing.Draw_String
(Buffer => GUI.Screen_Buffer.all,
Start =>
GUI.Scale
((Pos.X, Pos.Y)),
Msg => Msg.Level'Image, Font => BMP_Fonts.Font8x8,
Foreground => Foreground, Background => Background);

(Buffer => GUI.Screen_Buffer.all,
Start => GUI.Scale ((Pos.X, Pos.Y)), Msg => Msg.Level'Image,
Font => BMP_Fonts.Font8x8, Foreground => Foreground,
Background => Background);

-- Offset X position for debug level header
Pos.X := Pos.X + GUI.MeasureText (Msg.Level'Image, BMP_Fonts.Font8x8).Width;
Pos.X :=
Pos.X +
GUI.MeasureText (Msg.Level'Image, BMP_Fonts.Font8x8).Width +
Line_Padding;
end if;

-- Draw actual message text
Bitmapped_Drawing.Draw_String
(Buffer => GUI.Screen_Buffer.all,
Start =>
GUI.Scale
((Pos.X + Line_Padding,
Pos.Y)),
Msg => Msg.Msg, Font => BMP_Fonts.Font8x8, Foreground => HAL.Bitmap.White,
(Buffer => GUI.Screen_Buffer.all,
Start => GUI.Scale ((Pos.X, Pos.Y)), Msg => Msg.Msg,
Font => BMP_Fonts.Font8x8, Foreground => HAL.Bitmap.White,
Background => HAL.Bitmap.Black);
end loop;
end Render;
Expand Down
16 changes: 8 additions & 8 deletions eRINA_STM32F7/src/rina/debug.ads
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ with Queues;
package Debug is
type Debug is (Error, Warning, Info);

Font_Height : constant Natural :=
Font_Height : constant Natural :=
BMP_Fonts.Char_Height (Font => BMP_Fonts.Font8x8);
Max_Characters_Per_Line : constant Positive := 50;
Line_Padding : constant Natural := 4;
Starting_Point : constant HAL.Bitmap.Point := (0, 100);
Max_Messages : constant := 14;
Max_Characters_Per_Line : constant Positive := 45;
Line_Padding : constant Natural := 4;
Starting_Point : constant HAL.Bitmap.Point := (0, 100);
Max_Messages : constant := 14;

type Message is record
Msg : String(1 .. Max_Characters_Per_Line);
Msg : String (1 .. Max_Characters_Per_Line);
Level : Debug;
Cont : Boolean := False;
Cont : Boolean := False;
end record;

type Queue_Max is mod Max_Messages;
package Message_Queue is new Queues (Queue_Max, Message);
Messages : Message_Queue.Queue;
Expand Down
22 changes: 8 additions & 14 deletions eRINA_STM32F7/src/rina/demo.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ with Textures.PSU;
with Network;
with STM32;
with STM32.Board;
with Debug;
with Ada.Real_Time; use Ada.Real_Time;
with Debug;

procedure Demo is
Period : constant Time_Span := Milliseconds(1 / GUI.Frame_Rate * 1000);
Next_Render : Time := Clock;
Period : constant Time_Span := Milliseconds (1 / GUI.Frame_Rate * 1_000);
Next_Render : Time := Clock;
begin
GUI.Initialize;
Network.Initialize;
Expand All @@ -19,21 +19,15 @@ begin

-- Render loop keeps the board from immediately terminating
loop
GUI.Print ("eRINA Debug", (80, 15));

GUI.Print
("Status: ",
(80, 45));
Textures.Print (Textures.PSU.Bitmap, (5, 10));

GUI.Print
("Waiting for enrollment request",
(145, 45));
GUI.Print ("eRINA Debug", (80, 15));

Textures.Print (Textures.PSU.Bitmap, (5, 10));
GUI.Print ("Status: ", (80, 45));
GUI.Print ("Waiting for enrollment request", (145, 45));

GUI.Print
("Ignored Packets: " & Network.Ifnet.Rx_Stats.Ignored'Image,
(80, 30));
("Ignored Packets: " & Network.Ifnet.Rx_Stats.Ignored'Image, (80, 30));

Debug.Render;
GUI.Update;
Expand Down
20 changes: 13 additions & 7 deletions eRINA_STM32F7/src/rina/gui.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ with STM32.RNG.Interrupts;

package body GUI is

function Screen_Buffer return HAL.Bitmap.Any_Bitmap_Buffer is
function Screen_Buffer return Any_Bitmap_Buffer is
begin
return STM32.Board.Display.Hidden_Buffer (1);
end Screen_Buffer;

function Scale (Point : in HAL.Bitmap.Point) return HAL.Bitmap.Point is
function Scale (Position : in Point) return Point is
begin
if STM32.Board.LCD_Natural_Width > Board_Resolution.Width then
return
(Point.X * 800 / Board_Resolution.Width,
Point.Y * Board_Resolution.Width / Board_Resolution.Width);
(Position.X * 800 / Board_Resolution.Width,
Position.Y * Board_Resolution.Width / Board_Resolution.Width);
else
return Point;
return Position;
end if;
end Scale;

Expand All @@ -25,7 +25,13 @@ package body GUI is
STM32.Board.Display.Update_Layer (1);
end Update;

procedure Print (Msg : in String; Pos : in HAL.Bitmap.Point) is
procedure Draw_Rectangle (P : Point; S : Size) is
begin
Set_Source (Buffer => Screen_Buffer.all, ARGB => Red);
Fill_Rect (Buffer => Screen_Buffer.all, Area => (P, S.Width, S.Height));
end Draw_Rectangle;

procedure Print (Msg : in String; Pos : in Point) is
begin
Bitmapped_Drawing.Draw_String
(Buffer => Screen_Buffer.all, Start => Scale ((Pos.X, Pos.Y)),
Expand All @@ -37,7 +43,7 @@ package body GUI is
begin
STM32.RNG.Interrupts.Initialize_RNG;
STM32.Board.Display.Initialize;
STM32.Board.Display.Initialize_Layer (1, HAL.Bitmap.ARGB_1555);
STM32.Board.Display.Initialize_Layer (1, ARGB_1555);
end Initialize;

function MeasureText
Expand Down
24 changes: 15 additions & 9 deletions eRINA_STM32F7/src/rina/gui.ads
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
with BMP_Fonts;
with HAL.Bitmap;
with HAL.Bitmap; use HAL.Bitmap;

package GUI is
pragma Warnings (Off);

Large_Font : BMP_Fonts.BMP_Font := BMP_Fonts.Font12x12;
Foreground : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.White;
Background : HAL.Bitmap.Bitmap_Color := HAL.Bitmap.Black;
Large_Font : BMP_Fonts.BMP_Font := BMP_Fonts.Font12x12;
Foreground : Bitmap_Color := White;
Background : Bitmap_Color := Black;

type Size is record
Width : Natural;
Height : Natural;
end record;

Board_Resolution : Size := (480, 272);
Frame_Rate : Natural := 30;
type Button is record
Position : Point;
BSize : Size;
end record;

Board_Resolution : Size := (480, 272);
Frame_Rate : Natural := 30;

procedure Initialize;
procedure Update;
procedure Print (Msg : in String; Pos : in HAL.Bitmap.Point);
function Screen_Buffer return HAL.Bitmap.Any_Bitmap_Buffer;
procedure Print (Msg : in String; Pos : in Point);
function Screen_Buffer return Any_Bitmap_Buffer;
procedure Draw_Rectangle (P : Point; S : Size);

function MeasureText
(Text : in String; Font : in BMP_Fonts.BMP_Font) return Size;
function Scale (Point : in HAL.Bitmap.Point) return HAL.Bitmap.Point;
function Scale (Position : in Point) return Point;
end GUI;
Loading

0 comments on commit de12756

Please sign in to comment.