Skip to content

Commit

Permalink
Add IPCP_Manager package, refactor demo
Browse files Browse the repository at this point in the history
  • Loading branch information
masonticehurst committed Jan 29, 2024
1 parent 55e768a commit 6e1038d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 30 deletions.
35 changes: 5 additions & 30 deletions eRINA_STM32F7/src/rina/demo.adb
Original file line number Diff line number Diff line change
@@ -1,47 +1,22 @@
with Demos;
with Net;
with Ada.Strings.Hash;
with Ada.Strings.Bounded;
with Ada.Containers.Indefinite_Hashed_Maps;
with CDAP;
with EFCP;
with IPCP_Manager; use IPCP_Manager;

procedure Demo is

-- Mac address type
use Net;

procedure Header is
begin
Demos.Put (0, 0, "eRINA_Debug");
end Header;

-- Max of 32 IPCs can be registered
MAX_IPC_COUNT : constant Natural := 32;
MAX_IPCP_NAME_LENGTH : constant Natural := 128;

package IPCP_String is new Ada.Strings.Bounded.Generic_Bounded_Length (MAX_IPCP_NAME_LENGTH);
use IPCP_String;

function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type is begin
return Ada.Strings.Hash(To_String (Name));
end Hash;

-- Eventually make this the protected object that holds the IPC database
package IPCP_MAC_Map is new Ada.Containers.Indefinite_Hashed_Maps (
Key_Type => Bounded_String,
Element_Type => Ether_Addr,
Hash => Hash,
Equivalent_Keys => "="
);

use IPCP_MAC_Map;

-- Instantiate IPCP map
IPCP_Map : Map;

-- Debug only, remove later
Demo_IPCP_Name : constant Bounded_String := To_Bounded_String ("Demo.IPCP");
Demo_IPCP_Name : constant IPCP_Name.Bounded_String := IPCP_Name.To_Bounded_String ("Demo.IPCP");
Demo_IPCP_MacAddr : constant Ether_Addr := (others => 16#ff#);
Demo_IPCP : IPCP := IPCP_Manager.Create (Demo_IPCP_Name, Demo_IPCP_MacAddr);
begin
Header;
IPCP_Map.Include (Demo_IPCP_Name, Demo_IPCP_MacAddr);
end Demo;
16 changes: 16 additions & 0 deletions eRINA_STM32F7/src/rina/ipcp_manager.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package body IPCP_Manager is

function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type is begin
return Ada.Strings.Hash(To_String (Name));
end Hash;

function Create (Name : Bounded_String; MAC_Addr : Net.Ether_Addr) return IPCP is
New_IPCP : IPCP;
begin
New_IPCP.Name := Name;
IPCP_Map.Insert (Name, MAC_Addr);

return New_IPCP;
end Create;

end IPCP_Manager;
41 changes: 41 additions & 0 deletions eRINA_STM32F7/src/rina/ipcp_manager.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
with Ada.Strings.Hash;
with Ada.Strings.Bounded;
with Ada.Containers.Indefinite_Hashed_Maps;
with Net;

package IPCP_Manager is
use type Net.Uint8;
use type Net.Ether_Addr;

-- Max of 32 IPCs can be registered
MAX_IPC_COUNT : constant Natural := 32;
MAX_IPCP_NAME_LENGTH : constant Natural := 128;

package IPCP_Name is
new Ada.Strings.Bounded.Generic_Bounded_Length (MAX_IPCP_NAME_LENGTH);

use IPCP_Name;

function Hash(Name : in Bounded_String) return Ada.Containers.Hash_Type;

-- Eventually make this the protected object that holds the IPC database
package IPCP_MAC_Map is new Ada.Containers.Indefinite_Hashed_Maps (
Key_Type => Bounded_String,
Element_Type => Net.Ether_Addr,
Hash => Hash,
Equivalent_Keys => "="
);

-- Instantiate IPCP map
IPCP_Map : IPCP_MAC_Map.Map;

type Data_Buffer is array(1 .. 128) of Net.Uint8;

type IPCP is tagged record
Name : Bounded_String;
IO_Buffer : Data_Buffer := (others => 0);
end record;

function Create (Name : Bounded_String; MAC_Addr : Net.Ether_Addr) return IPCP;

end IPCP_Manager;

0 comments on commit 6e1038d

Please sign in to comment.