生活随笔
收集整理的這篇文章主要介紹了
SmartOS之以太网精简协议栈TinyIP
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
做物聯網,沒有以太網怎么能行!
基于Enc28j60,我們團隊獨立實現了以太網精簡協議棧TinyIP,目前支持ARP/ICMP/TCP/UDP/DHCP,還缺一個DNS就完整了。
TinyIP內置一個數據緩沖區,Enc28j60收到數據以后,放入緩沖區,然后TinyIP內部開始根據Ethernet/ARP/IP/ICMP/TCP/UDP/DHCP頭部結構體對數據進行拆分和重組,執行業務邏輯。
TinyIP百分百是我們團隊獨立完成,沒有抄襲那怕參考任何一款已有以太網協議(例如uip/lwip),各種協議結構作為國際標準是公開的,我們只需要按照協議去實現即可。
鄙視那些自己做不到就說別人抄襲的人!
#include "Sys.h"
#include "Enc28j60.h"
#include "SerialPort.h" #include "TinyIP/TinyIP.h" #include "conf.h" Spi* spi; Enc28j60* enc; TinyIP* tip; void OnPing(TinyIP* tip, ICMP_HEADER* icmp, byte* buf, uint len) { ????debug_printf("Ping From "); ????TinyIP::ShowIP(tip->RemoteIP); ????debug_printf(" with Payload=%d\r\n", len); } void OnUdpReceived(TinyIP* tip, UDP_HEADER* udp, byte* buf, uint len) { ????debug_printf("Udp From "); ????TinyIP::ShowIP(tip->RemoteIP); ????debug_printf(":%d with Payload=%d??", tip->RemotePort, len); ????TinyIP::ShowData(buf, len); ????debug_printf(" \r\n"); } void OnTcpAccepted(TinyIP* tip, TCP_HEADER* tcp, byte* buf, uint len) { ????debug_printf("TcpAccepted From "); ????TinyIP::ShowIP(tip->RemoteIP); ????debug_printf(":%d with Payload=%d\r\n", tip->RemotePort, len); } void OnTcpDisconnected(TinyIP* tip, TCP_HEADER* tcp, byte* buf, uint len) { ????debug_printf("TcpDisconnected From "); ????TinyIP::ShowIP(tip->RemoteIP); ????debug_printf(":%d with Payload=%d\r\n", tip->RemotePort, len); } void OnTcpReceived(TinyIP* tip, TCP_HEADER* tcp, byte* buf, uint len) { ????debug_printf("TcpReceived From "); ????TinyIP::ShowIP(tip->RemoteIP); ????debug_printf(":%d with Payload=%d??", tip->RemotePort, len); ????TinyIP::ShowData(buf, len); ????debug_printf(" \r\n"); } void TestEthernet() { ????debug_printf("\r\n\r\n"); ????debug_printf("TestEthernet Start......\r\n"); ????spi = new Spi(SPI_3); ????enc = new Enc28j60(spi); ????tip = new TinyIP(enc); ????tip->UseDHCP = true; ????tip->Init(); ???? ????tip->OnPing = OnPing; ????tip->OnUdpReceived = OnUdpReceived; ????tip->OnTcpAccepted = OnTcpAccepted; ????tip->OnTcpDisconnected = OnTcpDisconnected; ????tip->OnTcpReceived = OnTcpReceived; ????debug_printf("\r\n TestEthernet Finish!\r\n"); } 芯片GD32F103VK/GD32F103VE/STM32F103VE
TinyIP類內部根據系統ID生成隨機的MAC地址和初始IP地址192.168.0.x,IP最后一字節就是系統ID第一字節。
開啟DHCP后,將會自動獲取IP地址。
必須實現ARP協議,否則別人找不到你這個IP所對應的MAC,進而無法通信。
支持Ping/TCP/UDP多種必要事件掛載。
以太網所有功能全開,RTM下固件ROM大概9k。
End.
轉石頭大哥
轉載于:https://www.cnblogs.com/Ph-one/p/3960961.html
總結
以上是生活随笔為你收集整理的SmartOS之以太网精简协议栈TinyIP的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。