Skip to content

V3 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: v2
Choose a base branch
from
Open

V3 #14

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 16 additions & 29 deletions inc/EtherShield.h → Inc/EtherShield.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
/*
EHTERSHIELD_H library for Arduino etherShield
Copyright (c) 2008 Xing Yu. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file EtherShield.h
* @brief Header file containing definitions and macros for interfacing with the ENC28J60 Ethernet controller.
*
* This file includes control register definitions, chip enable/disable macros, and configurations for delays
* and chip select (CS) handling.
*
* @note For more information, refer to the `license.md` file located at the root of the project.
*/

#ifndef ETHERSHIELD_H
#define ETHERSHIELD_H

#include "stm32includes.h"

#define bool _Bool
#define TRUE 1
#define FALSE 0

#include <inttypes.h>
#include "main.h"
#include "defines.h"
#include "enc28j60.h"
#include "ip_arp_udp_tcp.h"
#include "net.h"

void ES_FullConnection();
void ES_RenewCo();
void ES_ProcessWebPacket();
void ES_ProcessWebPacketFilter();
void ES_init_network();
void ES_enc28j60SpiInit( SPI_HandleTypeDef *hspi );
void ES_enc28j60Init( uint8_t* macaddr);
void ES_enc28j60clkout(uint8_t clk);
Expand Down Expand Up @@ -76,7 +66,6 @@ uint16_t ES_packetloop_icmp_tcp(uint8_t *buf,uint16_t plen);
// functions to fill the web pages with data:
//uint16_t ES_fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s);
uint16_t ES_fill_tcp_data(uint8_t *buf,uint16_t pos, const char *s);
uint16_t ES_fill_tcp_data_len(uint8_t *buf,uint16_t pos, const char *s, uint16_t len );
// send data from the web server to the client:
void ES_www_server_reply(uint8_t *buf,uint16_t dlen);

Expand All @@ -103,7 +92,6 @@ uint8_t *ES_dnslkup_getip( void );
void ES_dnslkup_set_dnsip(uint8_t *dnsipaddr);
void ES_dnslkup_request(uint8_t *buf, uint8_t *hoststr );
uint8_t ES_udp_client_check_for_dns_answer(uint8_t *buf,uint16_t plen);
uint8_t resolveHostname(uint8_t *buf, uint16_t buffer_size, uint8_t *hostname );
#endif

#ifdef DHCP_client
Expand All @@ -113,7 +101,6 @@ void ES_dhcp_start(uint8_t *buf, uint8_t *macaddrin, uint8_t *ipaddrin,
uint8_t *dnssvrin );

uint8_t ES_check_for_dhcp_answer(uint8_t *buf,uint16_t plen);
uint8_t allocateIPAddress(uint8_t *buf, uint16_t buffer_size, uint8_t *mymac, uint16_t myport, uint8_t *myip, uint8_t *mynetmask, uint8_t *gwip, uint8_t *dnsip, uint8_t *dhcpsvrip );
#endif

#define HTTP_HEADER_START ((uint16_t)TCP_SRC_PORT_H_P+(buf[TCP_HEADER_LEN_P]>>4)*4)
Expand Down
31 changes: 31 additions & 0 deletions Inc/LogManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* @file logmanager.c
* @brief Source file
*
* This header file defines the interface for the Log Manager module, which handles logging
* operations for different types of logs such as UDP, Web, and UART. It includes an enumeration
* for log types, function prototypes for logging messages, initializing the log manager, and
* adding logs to the system.
*/

#ifndef LOGMANAGER_H
#define LOGMANAGER_H

#include "main.h"

// Enumeration for log types
typedef enum {
LOG_UDP,
LOG_WEB,
LOG_UART
// Add more log types as needed
} LogType;

// Function prototypes
void ethershieldDebug(char *message);
void udpLog2(char* alerte, char* text);
void add_log(const char *log);
void logMessage(LogType type, const char *message);
void initLogManager(LogType type);

#endif /* LOGMANAGER_H */
28 changes: 28 additions & 0 deletions Inc/RTC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @file RTC.h
* @brief Real-Time Clock (RTC) interaction functions for STM32 microcontroller.
*
* This header file provides the declaration of the function used to obtain the current
* date and time from the RTC of the STM32 microcontroller. The function formats the
* date and time into a human-readable string for logging purposes.
*/

#ifndef INC_RTC_H_
#define INC_RTC_H_

#include "main.h"
//#include "defines.h"


typedef struct {
uint8_t day;
uint8_t month;
uint16_t year;
uint8_t hours;
uint8_t minutes;
uint8_t seconds;
} DateTime;

DateTime getRTCDateTime();

#endif /* INC_RTC_H_ */
89 changes: 89 additions & 0 deletions Inc/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @file defines.h
* @brief Header file containing global definitions and macros for configuring the STM32 and ENC28J60 Ethernet module.
*
* This file includes configurations for SPI settings, conditional compilation flags for enabling various
* networking clients (e.g., NTP, DNS, DHCP), and external declarations of global variables and function prototypes.
*
* @note For more information, refer to the `license.md` file located at the root of the project.
*/

#ifndef INC_DEFINES_H_
#define INC_DEFINESE_H_

#include "main.h"

// Comment only one of this two. Depend of your SPI configuration.
// CS_only is simple (no option from SPI configuration).
// NSS is better. configuration details in enc28J60.h
//#define CS_Only
#define NSS_OutputSignal

// # CS SECTION
#ifdef CS_Only
#define ETHERNET_LED_GPIO GPIOC
#define ETHERNET_LED_PIN GPIO_PIN_13
#define ETHERNET_CS_GPIO GPIOA
#define ETHERNET_CS_PIN GPIO_PIN_4
#define ETHERNET_CS_DELAY 10 // Start with 2, then 1 and 0. 1000 is an other step. if it work try 10, could be Unstable but fast.
#endif

// # Parameters SECTION
// Comment or not depend on your need below :
#define ETHERSHIELD_DEBUG 1
#define NTP_client
#define DNS_client
#define DHCP_client
#define HOSTNAME "STM32_ENC28J60"
#define DHCP_HOSTNAME_LEN 14 // here the len of the HOSTNAME define just before
#define DHCP_HOSTNAME "STM32_ENC28J60"
#define PING_client
//#define PINGPATTERN 0x42 (element needed in net.c - is it very usefull ?
#define TCP_client
#define WWW_client //uncoment next one too
#define WWW_USER_AGENT "MyUserAgent"
#define FROMDECODE_websrv_help
#define URLENCODE_websrv_help



//extern volatile uint8_t dma_isr_called;


// Define this in defines.c file
extern uint8_t macaddrin[6];
extern uint8_t ipaddrin[4];
extern uint8_t maskin[4];
extern uint8_t gwipin[4];
extern uint8_t dhcpsvrin[4];
extern uint8_t dnssvrin[4];
extern uint8_t dnsipaddr[4];
extern uint8_t ntpip[4];
extern char domainName[];
extern uint8_t dest_ip[4];
extern uint16_t dest_port;
extern uint16_t srcport;
extern uint8_t dstport_h;
extern uint8_t dstport_l;
extern uint8_t dip[];
extern uint16_t dport;
extern uint16_t sport;

// Define the structure for command mapping
typedef void (*CommandFunction)();
typedef void (*CommandFunctionWithArg)(char*);

typedef struct {
const char *command;
CommandFunction function;
CommandFunctionWithArg function_with_arg;
} CommandMapping;

// Declare the command table
extern CommandMapping commandTable[];

// Declare command functions here
void sendSTM32State(); // Function to send the STM32 state
void sendRTCDateTime(); // Function to send the RTC date and time

#endif /* INC_DEFINES_H_ */
32 changes: 32 additions & 0 deletions Inc/dhcp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file dhcp.h
* @brief Header file for DHCP client function prototypes and definitions.
*
* This file provides the function prototypes and necessary definitions for implementing DHCP client functionality.
* It includes declarations for initializing the DHCP process, sending requests, and handling DHCP responses
* such as DHCPOFFER and DHCPACK.
*
* @note For more information, refer to the `license.md` file located at the root of the project.
*/


#ifndef DHCP_H
#define DHCP_H

#include "main.h"
#include "defines.h"

extern void dhcp_start(uint8_t *buf, uint8_t *macaddrDCPin, uint8_t *ipaddrin,
uint8_t *maskin, uint8_t *gwipin, uint8_t *dhcpsvrin,
uint8_t *dnssvrin );

extern uint8_t dhcp_state( void );

void dhcp_send(uint8_t *buf, uint8_t requestType);
uint8_t check_for_dhcp_answer(uint8_t *buf,uint16_t plen);
uint8_t have_dhcpoffer(uint8_t *buf,uint16_t plen);
uint8_t have_dhcpack(uint8_t *buf,uint16_t plen);

uint8_t allocateIPAddress(uint8_t *buf, uint16_t buffer_size, uint8_t *mymac, uint16_t myport, uint8_t *myip, uint8_t *mynetmask, uint8_t *gwip, uint8_t *dnsip, uint8_t *dhcpsvrip );

#endif /* DHCP_H */
29 changes: 13 additions & 16 deletions inc/dnslkup.h → Inc/dnslkup.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
/*********************************************
* vim:sw=8:ts=8:si:et
* To use the above modeline in vim you must have "set modeline" in your .vimrc
* Author: Guido Socher
* Copyright: GPL V2
/**
* @file dnslkup.h
* @brief Header file for DNS lookup function prototypes and related definitions.
*
* DNS look-up functions based on the udp client
* This file provides the function prototypes for DNS client operations, such as sending DNS requests,
* processing DNS responses, and resolving hostnames to IP addresses. It also includes functions
* for setting the DNS server and checking for errors during DNS lookups.
*
* Chip type : ATMEGA88/ATMEGA168/ATMEGA328p with ENC28J60
*********************************************/
//@{
* @note For more information, refer to the `license.md` file located at the root of the project.
*/

#ifndef DNSLKUP_H
#define DNSLKUP_H

#include "stm32includes.h"

// to use this you need to enable UDP_client in the file ip_config.h
//
#if defined (UDP_client)
#include "main.h"
//#include "defines.h"

// look-up a hostname (you should check client_waiting_gw() before calling this function):
extern void dnslkup_request(uint8_t *buf, uint8_t *hostname);
Expand All @@ -36,6 +33,6 @@ extern uint8_t *dnslkup_getip(void);
// set DNS server to be used for lookups.
extern void dnslkup_set_dnsip(uint8_t *dnsipaddr);

#endif /* UDP_client */
uint8_t resolveHostname(uint8_t *buf, uint16_t buffer_size, uint8_t *hostname );

#endif /* DNSLKUP_H */
//@}
Loading