Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Fixing stuff in network module
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD committed Sep 17, 2023
1 parent 206428b commit 0d1f728
Show file tree
Hide file tree
Showing 9 changed files with 482 additions and 409 deletions.
4 changes: 4 additions & 0 deletions lib/Xila/include/Network/IP_Address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace Xila_Namespace
/// @param Address : Pointer to an array of 4 or 16 bytes representing the IP address.
IP_Address_Class(const uint8_t *Address, bool Is_IPv4 = true);

/// @brief Constructor to create an IP v4 or v6 address from a char array.
/// @param Address : Pointer to a char array representing the IP address.
IP_Address_Class(const char *Address);

/// @brief Constructor to create an IP v4 address.
/// @param Byte_1 First byte of the IP address.
/// @param Byte_2 Second byte of the IP address.
Expand Down
10 changes: 10 additions & 0 deletions lib/Xila/include/Network/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace Xila_Namespace
virtual IP_Address_Type Get_Subnet_Mask() = 0;
virtual IP_Address_Type Get_DNS_IP_Address(Natural_Type Index) = 0;
virtual Byte_Type Get_Subnet_CIDR() = 0;
virtual bool Is_IPv6() = 0;

virtual Client_Type& Create_Client() = 0;

Expand All @@ -83,6 +84,15 @@ namespace Xila_Namespace
/// @return `Result_Type::Success` if the network configuration has been set, `Result_Type::Error` otherwise.
virtual Result_Type Set_Configuration(IP_Address_Type IP_Address, IP_Address_Type Subnet_Mask, IP_Address_Type Gateway, IP_Address_Type DNS_1_IP_Address = static_cast<uint32_t>(0x00000000), IP_Address_Type DNS_2_IP_Address = static_cast<uint32_t>(0x00000000)) = 0;

/// @brief Set the host name of the device over the interface.
/// @param Host_Name
/// @return Result_Type `Result_Type::Success` if the host name has been setted successfully.
virtual Result_Type Set_Host_Name(const char* Host_Name) = 0;

/// @brief Get the host name of the device over the interface.
/// @param Host_Name String to store the host name.
/// @return String_Type& Host name.
virtual String_Type& Get_Host_Name(String_Type& Host_Name) = 0;

friend class Xila_Namespace::Network_Class;
} Interface_Type;
Expand Down
10 changes: 10 additions & 0 deletions lib/Xila/include/Network/Network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ namespace Xila_Namespace
/// @return Count of the connected interface.
Natural_Type Get_Connected_Interface_Count();

/// @brief Set host name of the device over all interfaces.
/// @param Host_Name
/// @return `Result_Type::Success` if the host name has been setted successfully.
Result_Type Set_Host_Name(const char* Host_Name);

/// @brief Get host name of the device over all interfaces.
/// @param Host_Name
/// @return `Result_Type::Success` if the host name has been getted successfully.
String_Type& Get_Host_Name(String_Type& Host_Name);


} Network_Type;

Expand Down
12 changes: 4 additions & 8 deletions lib/Xila/include/Network/WiFi/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ namespace Xila_Namespace
IP_Address_Type Get_Subnet_Mask() override;
IP_Address_Type Get_DNS_IP_Address(Natural_Type Index) override;
Byte_Type Get_Subnet_CIDR() override;
bool Is_IPv6() override;

Client_Type& Create_Client() override;

void Set_State(State_Type State) override;

Result_Type Set_Configuration(IP_Address_Type IP_Address, IP_Address_Type Subnet_Mask, IP_Address_Type Gateway, IP_Address_Type DNS_1_IP_Address = static_cast<uint32_t>(0x00000000), IP_Address_Type DNS_2_IP_Address = static_cast<uint32_t>(0x00000000)) override;

String_Type &Get_Host_Name(String_Type &Host_Name) override;
Result_Type Set_Host_Name(const char *Host_Name);

// - - Managment

/// @brief Turn on the WiFi module.
Expand All @@ -119,9 +123,6 @@ namespace Xila_Namespace
/// @return Current WiFi transmission power in dBm.
int16_t Get_Transmission_Power();

/// @brief Get the host name.
/// @param Host_Name Reference to a `String_Type` where the host name will be stored.
String_Type &Get_Host_Name(String_Type &Host_Name);

// - - Setters

Expand All @@ -134,11 +135,6 @@ namespace Xila_Namespace
/// @return `Result_Type::Success` if the transmission power has been set, `Result_Type::Error` otherwise.
Result_Type Set_Transmission_Power(int16_t Power);

/// @brief Set the host name.
/// @param Host_Name Host name.
/// @return `Result_Type::Success` if the host name has been set, `Result_Type::Error` otherwise.
Result_Type Set_Host_Name(const char *Host_Name);

// Result_Type Set_Antennas(uint8_t GPIO_1, uint8_t GPIO_2);
// - -

Expand Down
81 changes: 66 additions & 15 deletions lib/Xila/src/Network/IP_Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,15 @@
///
/// @copyright Copyright (c) 2023

#include "Communication/IP_Address.hpp"
#include "Network/IP_Address.hpp"

#include <WiFi.h>

using namespace Xila_Namespace;
using namespace Xila_Namespace::Communication_Types;
using namespace Xila_Namespace::Network_Types;

IP_Address_Class::IP_Address_Class() : Is_IPv4(true)
{

}

IP_Address_Class::IP_Address_Class(const IPAddress& IP_Address)
: Is_IPv4(true)
{
Address.DWord = IP_Address;
}

IP_Address_Class::IP_Address_Class(const IPv6Address& IP_Address)
: Is_IPv4(false)
{
memcpy(Address.Bytes, (const uint8_t*)IP_Address, sizeof(Address.Bytes));
}

IP_Address_Class::IP_Address_Class(bool Is_IPv4)
Expand Down Expand Up @@ -56,6 +43,70 @@ IP_Address_Class::IP_Address_Class(const uint8_t *Address, bool Is_IPv4)
}
}

IP_Address_Class::IP_Address_Class(const char* Address)
{

uint8_t Index = 0;

bool Is_IPv4 = true;

{
uint8_t Separators = 0;

while (*Address != '\0')
{
if (*Address == ':' or *Address == '.')
{
Separators++;
}
Address++;
}

if (Separators == 3)
{
this->Is_IPv4 = true;
}
else if (Separators == 7)
{
this->Is_IPv4 = false;
}
else
{
return;
}
}


while (Address != '\0' and Index < sizeof(this->Address.Bytes))
{
char Character = tolower(*Address);
if ((Character >= '9' and Character <= '0') or (Character >= 'a' and Character <= 'f'))
{
switch (Character)
{
case '0':
Address[Index] = 0x0;
break;
case '1':
Address[Index] = 0x1;
break;
case '2':
Address[Index] = 2;
break;
case '3':
Address[Index] = 3;
break;

default:
break;
}
}
Address++;
}

}


IP_Address_Class::IP_Address_Class(uint8_t Byte_1, uint8_t Byte_2, uint8_t Byte_3, uint8_t Byte_4)
{
Address.Bytes[0] = Byte_1;
Expand Down
22 changes: 22 additions & 0 deletions lib/Xila/src/Network/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,26 @@ Natural_Type Network_Class::Get_Connected_Interface_Count()
Interface_Pointer = Interface_Pointer->Next_Instance_Pointer;
}
return Count;
}

Result_Type Network_Class::Set_Host_Name(const char* Host_Name)
{
Result_Type Result = Result_Type::Success;
Interface_Type* Interface_Pointer = Interface_Class::First_Instance_Pointer;
while (Interface_Pointer)
{
if (Interface_Pointer->Set_Host_Name(Host_Name) != Result_Type::Success)
Result = Result_Type::Error;

Interface_Pointer = Interface_Pointer->Next_Instance_Pointer;
}
return Result;
}

String_Type& Network_Class::Get_Host_Name(String_Type& Host_Name)
{
if (Interface_Class::First_Instance_Pointer)
return Interface_Class::First_Instance_Pointer->Get_Host_Name(Host_Name);

return Host_Name;
}
Loading

0 comments on commit 0d1f728

Please sign in to comment.