⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uip_main.h

📁 CS8900A driver source code project files for Code Composer Studio precompiled static uIP-DSP libra
💻 H
字号:
// ------------------------------------------------------------------------
/// @file uip_main.cpp
/// @brief Library interface
/// @author Harald Axmann
/// @date 08.05.2006
// ------------------------------------------------------------------------

#ifndef _UIP_MAIN_H_
#define _UIP_MAIN_H_

#include "uip.h"
#include "uip_arp.h"

// ------------------------------------------------------------------------
struct fs_file;

// ------------------------------------------------------------------------
namespace Uip
{

// ------------------------------------------------------------------------
/// @brief File information
typedef struct fs_file FsFile;
	
// ------------------------------------------------------------------------
/// @brief Callback function to handle incoming frames
typedef void AppCallback(u16_t localport, u16_t remoteport);

// ------------------------------------------------------------------------
/// @brief Callback for SMTP
typedef void SmtpDoneCallback(unsigned char error);

// ------------------------------------------------------------------------
/// @brief Maximum number of server applications
extern const int MAX_APP_SERVER_NUM;

// ------------------------------------------------------------------------
/// @brief Maximum number of client applications
extern const int MAX_APP_CLIENT_NUM;

// ------------------------------------------------------------------------
/// @brief Callback for the file system
///
/// The callback should return 0, if it will not handle the request. 
/// In this case the built-in file system will search the file in the 
/// read-only structure. If it returns 1, it is assumed, that the 
/// content of the parameter file is set to data to be transmitted.
///
/// @param name the requested file
/// @param file The file pointer, which must be allocated by caller and
///        will be filled in by the function.
/// @return 1, if the request has been handled, 0 otherwise
typedef int FsCallback(const_data_t name, FsFile *file);

// ------------------------------------------------------------------------
/// @brief MAC-Address container
class EthAddr
{
public:
	EthAddr(const uint8 *addr) {
	  eth_addr_.addr[0] = addr[0];
	  eth_addr_.addr[1] = addr[1];
	  eth_addr_.addr[2] = addr[2];
	  eth_addr_.addr[3] = addr[3];
	  eth_addr_.addr[4] = addr[4];
	  eth_addr_.addr[5] = addr[5];
	}
	EthAddr(uint8 a, uint8 b, uint8 c, uint8 d, uint8 e, uint8 f) {
	  eth_addr_.addr[0] = a;
	  eth_addr_.addr[1] = b;
	  eth_addr_.addr[2] = c;
	  eth_addr_.addr[3] = d;
	  eth_addr_.addr[4] = e;
	  eth_addr_.addr[5] = f;
	}
	~EthAddr() {}
	
	const uip_eth_addr &toUipEthAddr() const { return eth_addr_; }

protected:
	struct uip_eth_addr eth_addr_;
};

// ------------------------------------------------------------------------
/// @brief IP-Address container
class IpAddr
{
public:
	IpAddr(const uint8 *addr) { 
	  ip_addr_[0] = addr[0]+(addr[1]<<8); ip_addr_[1] = addr[2]+(addr[3]<<8); }
	IpAddr(uint8 a, uint8 b, uint8 c, uint8 d) {
	  ip_addr_[0] = a+(b<<8); ip_addr_[1] = c+(d<<8); }
	~IpAddr() {}
	
	const u16_t *toArray() const { return ip_addr_; }
	
protected:
	u16_t ip_addr_[2];
};

// ------------------------------------------------------------------------
/// @brief A TCP/IP application
class Application
{
public:
	enum Type 
	{
	  SERVER,
	  CLIENT
	};
	
	typedef void Callback(void);

	Application(Type type, Callback *callback, uint16 port)
	  : type_(type), callback_(callback), nw_port_(htons(port)) {}
	~Application() {}
	
	Type getType() const { return type_; }
	Callback *getCallback() const { return callback_; }
	
	/// @brief Get port in network byte order
	uint16 getNWPort() const { return nw_port_; }
	
protected:
  Type type_;
  Callback *callback_;
  u16_t nw_port_;
};

// ------------------------------------------------------------------------
/// @brief HTTP application
extern const Application http_app;

// ------------------------------------------------------------------------
/// @brief SMTP application
extern const Application smtp_app;

// ------------------------------------------------------------------------
/// @brief Initialize the uIP Stack and the Ethernet driver
///
/// @param eth_addr the MAC address of the device
/// @param ip_addr the IP address of the device
/// @param netmask the subnet mask of the device
/// @param gateway the network gateway IP address
/// @return <code>true</code>, if successful
bool init(const EthAddr &eth_addr, const IpAddr &ip_addr, const IpAddr &netmask, const IpAddr &gateway);

// ------------------------------------------------------------------------
/// @brief Perform an update step
void update();

// ------------------------------------------------------------------------
/// @brief Receive data
///
/// This function must be called by the device driver to process incoming
/// requests.
void receive();

// ------------------------------------------------------------------------
/// @brief This function will be called by the uIP TCP/IP stack, if a new
/// message has arrived.
void appCall(u16_t localport, u16_t remoteport);

// ------------------------------------------------------------------------
/// @brief Setup SMTP client application
///
/// @param hostname the name which will be used as identification
/// @param smtp_server IP address of the SMTP server
void smtpInit(const char *hostname, const IpAddr &smtp_server);

// ------------------------------------------------------------------------
/// @brief Setup HTTP client application
void httpInit();

// ------------------------------------------------------------------------
/// @brief Set the callback for SMTP
///
/// The method supplied here will be called, when the SMTP application
/// has done its work.
void setSmtpDoneCallback(SmtpDoneCallback *callback);

// ------------------------------------------------------------------------
/// @brief Set the filesystem callback. 
///
/// If set, the given function will be called every time a file is requested.
/// 
/// @param callback the callback function
void setFsCallback(FsCallback *callback);

// ------------------------------------------------------------------------
/// @brief Register a TCP/IP application
/// 
/// This function registers the given application (client or server)
/// at the dispatcher for incoming messages. This operation will only be
/// performed, as long as the maximum number of applications is not 
/// exceeded (MAX_APP_SERVER_NUM, MAX_APP_CLIENT_NUM).
///
/// @brief application pointer to the structure describing the application
/// @return <code>true</code>, if successful
bool registerApp(const Application *app);

// ------------------------------------------------------------------------
/// @brief Send a mail using the SMTP client
///
/// Note: pointers should be constant. However we must stay
/// compatible with the SMTP implementation.
///
/// @brief to the receiver's email address
/// @brief from the sender's email address
/// @brief subject email subject line
/// @brief msg the message to send
/// @brief msglen the length of the message
/// @return <code>true</code> if successful
bool sendMail(char *to, char *from, char *subject, char *msg, uint16 msglen);

}

#endif // _UIP_MAIN_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -