/* * eth_udp.cpp * * Created on: 15 ���. 2023 �. * Author: sychev */ #include "free_rtos/ethernet_ip/eth_udp_server.hpp" #include "free_rtos/ethernet_ip/eth_udp_types.h" #include "free_rtos/ethernet_ip/eth_ip_types.h" #include "free_rtos/base/swap.h" free_rtos::EthUdpServer::EthUdpServer(EthIpIface& ip_iface) : ip_iface_{ip_iface} { } std::shared_ptr free_rtos::EthUdpServer::createClient(uint16_t port_dst, uint16_t port_src, bool use_chksum) { port_dst = BASE_SWAP16(port_dst); port_src = BASE_SWAP16(port_src); /// ������ ��� ��������������� �� ���� ���� if (connections_.count(port_dst)) { return nullptr; } std::shared_ptr p_client = std::make_shared(ip_iface_, port_id_, port_dst, port_src, use_chksum); if (p_client == nullptr) { return nullptr; } connections_[port_dst] = p_client; return p_client; } int32_t free_rtos::EthUdpServer::Process(uint8_t * p_data, uint32_t len) { if (len <= sizeof(TUdpHeader)) { return 0; } TUdpHeader * hdr = (TUdpHeader *)p_data; uint16_t port = hdr->Dst_port; auto item = connections_.find(port); /// ����� ���� �� ��������������� if (item == connections_.end()) { return 0; } auto& client = item->second; TIpHeader * p_ip_hdr = (TIpHeader*)(p_data - sizeof(TIpHeader)); uint32_t src_ip; memcpy(&src_ip, p_ip_hdr->ip_src, ETH_IP_ADDR_LEN); /// �������� ������ udp client->put_data(src_ip, p_data + sizeof(TUdpHeader), BASE_SWAP16(hdr->Length) - sizeof(TUdpHeader)); rx_sem_.post(); return 0; } uint32_t free_rtos::EthUdpServer::Sender(uint8_t * p_data, size_t scatter_segment) { return 0; }