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

Commit

Permalink
Improving network hardware interface
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD committed Aug 6, 2023
1 parent 0aab17e commit 689f643
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 60 deletions.
4 changes: 4 additions & 0 deletions Configurations/Linux.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ build_flags =
-std=gnu++17
-D Native

; - Processor

-D Xila_Processor_Hardware_x86_64

; - Board
-D Xila_Board_Hardware_Wireless_Tag_WT32_SC01_Plus

Expand Down
2 changes: 2 additions & 0 deletions Configurations/WT32-SC01.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ build_flags =
${env.build_flags}

-D Arduino


; Board

-D Xila_Board_Hardware_Wireless_Tag_WT32_SC01
Expand Down
4 changes: 4 additions & 0 deletions Configurations/WT32-SC01_Plus.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ build_flags =

-D Arduino

; - Processor

-D Xila_Processor_Hardware_ESP32_S3

; - Board
-D Xila_Board_Hardware_Wireless_Tag_WT32_SC01_Plus

Expand Down
31 changes: 16 additions & 15 deletions lib/Xila/include/Log/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

#include "../Module/Module.hpp"

#if defined(Xila_Processor_Hardware_ESP32_S3) || defined(Xila_Processor_Hardware_ESP32)
#include "esp_log.h"
#endif

namespace Xila_Namespace
{
Expand All @@ -27,21 +29,21 @@ namespace Xila_Namespace
/// @param Arguments Arguments of the message.
void Print(const char *Format, ...)
{
// if (!Semaphore.Is_Valid())
// {
// Print_Static("Semaphore is not valid !\r\n");
// return;
// }
// Print_Static("Wait semaphore...\r\n");

//xSemaphoreTake(Semaphore_Handle, portMAX_DELAY);
//Semaphore.Take();
// if (!Semaphore.Is_Valid())
// {
// Print_Static("Semaphore is not valid !\r\n");
// return;
// }
// Print_Static("Wait semaphore...\r\n");

// xSemaphoreTake(Semaphore_Handle, portMAX_DELAY);
// Semaphore.Take();
va_list Arguments;
va_start(Arguments, Format);
log_printf(Format, Arguments);
va_end(Arguments);
//Semaphore.Give();
//xSemaphoreGive(Semaphore_Handle);
// Semaphore.Give();
// xSemaphoreGive(Semaphore_Handle);
};

/// @brief Print a message to the log.
Expand All @@ -55,7 +57,6 @@ namespace Xila_Namespace
va_end(Arguments);
};


private:
xSemaphoreHandle Semaphore_Handle;
StaticSemaphore_t Semaphore_Buffer;
Expand All @@ -77,8 +78,8 @@ namespace Xila_Namespace

#if Log_Level > 0

#define Log_Raw(Format, ...) log_printf(Format, ##__VA_ARGS__);
#define Log_Raw_Line(Format, ...) Log_Raw(Format "\r\n", ##__VA_ARGS__)
#define Log_Raw(Format, ...) log_printf(Format, ##__VA_ARGS__);
#define Log_Raw_Line(Format, ...) Log_Raw(Format "\r\n", ##__VA_ARGS__)
#define Log_Format(Module_Name, Type, Format) "| %6u ms | %s.%s() | (%s:%u) | %s | " Format "\r\n", (unsigned long)(esp_timer_get_time() / 1000ULL), Module_Name, __FUNCTION__, pathToFileName(__FILE__), __LINE__, Type
#define Log_All(Module_Name, Type, Format, ...) Log_Raw(Log_Format(Module_Name, Type, Format), ##__VA_ARGS__)
#else
Expand Down Expand Up @@ -121,4 +122,4 @@ namespace Xila_Namespace
#define Log_Verbose(Module_Name, Format, ...)
#endif

#endif // Xila_Log_Hpp
#endif // Xila_Log_Hpp
67 changes: 67 additions & 0 deletions lib/Xila/include/Network/Client.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/// @file Client.hpp
/// @author Alix ANNERAUD ([email protected])
/// @brief
/// @version 0.1.0
/// @date 05-08-2023
///
/// @copyright Copyright (c) 2023

#ifndef Xila_Network_Client_Hpp_Included
#define Xila_Network_Client_Hpp_Included

#include "Module/Module.hpp"

namespace Xila_Namespace
{
namespace Network_Types
{
typedef class Client_Class : public Xila_Namespace::Stream_Type
{
public:
// - Methods

// - - Constructors / destructors

Client_Class();
~Client_Class();

virtual Result_Type Connect(const char* Host, Word_Type Port, int32_t Timeout = 30000) = 0;

virtual void Stop() = 0;

virtual bool Connected() = 0;

virtual String_Type& Last_Error(String_Type& Error_Buffer) = 0;

virtual void Set_Insecure() = 0;

virtual void Set_Handshake_Timeout(uint32_t Timeout) = 0;
virtual void Set_Timeout(uint32_t Timeout) = 0;

virtual int Available() = 0;
virtual int Peek() = 0;

virtual int Read() = 0;
virtual Size_Type Read_Bytes(Byte_Type* Buffer, Size_Type Length) = 0;
virtual String_Type& Read_String(String_Type& String) = 0;

virtual void Flush() = 0;

virtual Size_Type Write(Byte_Type Byte) = 0;
virtual Size_Type Write_Bytes(const Byte_Type* Buffer, Size_Type Length) = 0;
virtual Size_Type Write_String(const char* String) = 0;

virtual operator bool() = 0;

virtual operator==(Client_Class& Client) = 0;
virtual operator==(Client_Class& Client) = 0;

private:

void* Data;
} Client_Type;
}

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class IPAddress;

namespace Xila_Namespace
{
namespace Communication_Types
namespace Network_Types
{
typedef class IP_Address_Class
{
Expand Down
91 changes: 91 additions & 0 deletions lib/Xila/include/Network/Interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/// @file Interface.hpp
/// @author Alix ANNERAUD ([email protected])
/// @brief
/// @version 0.1.0
/// @date 04-08-2023
///
/// @copyright Copyright (c) 2023

#ifndef Xila_Interface_Hpp_Included
#define Xila_Interface_Hpp_Included

#include "IP_Address.hpp"
#include "Client.hpp"

namespace Xila_Namespace
{
typedef class Network_Class Network_Type;

namespace Network_Types
{
enum class State_Type
{
Disconnected,
Connected,
Connecting,
Disconnecting,
Error
};

enum class Interface_Type_Type
{
WiFi,
Ethernet,
Cellular
};

typedef class Interface_Class
{
protected:

static Interface_Class* First_Instance_Pointer;
Interface_Class* Next_Instance_Pointer;

public:
// - Methods

// - - Constructor / Destructor

Interface_Class();
~Interface_Class();

// - -

virtual Result_Type Start() = 0;
virtual Result_Type Stop() = 0;

// - - Getters

virtual State_Type Get_State() = 0;

// - - - IP

virtual IP_Address_Type Get_IP_Address(bool IPv6 = false) = 0;
virtual IP_Address_Type Get_Gateway_IP_Address() = 0;
virtual IP_Address_Type Get_DNS_IP_Address(Natural_Type Index) = 0;
virtual Byte_Type Get_Subnet_CIDR() = 0;

virtual Client_Class Create_Client() = 0;



// - - Setters

virtual void Set_State(State_Type State) = 0;

/// @brief Set the network configuration.
/// @param IP_Address IP address.
/// @param Subnet_Mask Subnet mask.
/// @param Gateway Gateway IP address.
/// @param DNS_1_IP_Address First DNS IP address.
/// @param DNS_2_IP_Address Second DNS IP address.
/// @return `Result_Type::Success` if the network configuration has been set, `Result_Type::Error` otherwise.
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));


friend class Xila_Namespace::Network_Class;
} Interface_Type;
}
}

#endif // Xila_Interface_Hpp_Included
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
#include "WiFi.hpp"
#include "HTTP_Client.hpp"

#include "Interface.hpp"

namespace Xila_Namespace
{
namespace Communication_Types
namespace Network_Types
{

}

/// @brief Communication module class.
typedef class Communication_Class
typedef class Network_Class
{
public:

Expand All @@ -35,13 +37,21 @@ namespace Xila_Namespace
/// @return `Result_Type`
Result_Type Stop();

/// @brief WiFi sub-module instance.
Communication_Types::WiFi_Type WiFi;
/// @brief
/// @param Index
/// @return
Network_Types::Interface_Type* Get_Interface(Natural_Type Index = 0);

/// @brief
/// @param Index
/// @return
Network_Types::Interface_Type* Get_Connected_Interface(Natural_Type Index = 0);


} Communication_Type;
} Network_Type;

/// @brief Communication module instance.
extern Communication_Type Communication;
extern Network_Type Network;
}

#endif
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef Communication_WiFi_Client_Hpp_Included
#define Communication_WiFi_Client_Hpp_Included



#ifdef Xila_WiFi_Hardware_ESP32
#include <WiFiClientSecure.h>
#endif
Expand Down
38 changes: 0 additions & 38 deletions lib/Xila/src/Communication/Communication.cpp

This file was deleted.

Loading

0 comments on commit 689f643

Please sign in to comment.