fsfw-example-common/stm32h7/networking/UdpTcLwIpPollingTask.cpp

63 lines
1.8 KiB
C++
Raw Normal View History

2021-07-12 21:21:03 +02:00
#include "UdpTcLwIpPollingTask.h"
#include "TmTcLwIpUdpBridge.h"
#include "app_ethernet.h"
#include "ethernetif.h"
#include "app_dhcp.h"
#include <hardware_init.h>
2021-07-13 09:15:36 +02:00
#include "fsfw/ipc/MutexGuard.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/objectmanager/ObjectManager.h"
2021-07-12 21:21:03 +02:00
2021-07-13 09:15:36 +02:00
#include "lwip/timeouts.h"
2021-07-12 21:21:03 +02:00
UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId):
SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId) {
}
UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() {
}
ReturnValue_t UdpTcLwIpPollingTask::initialize() {
2021-07-13 09:15:36 +02:00
udpBridge = ObjectManager::instance()->get<TmTcLwIpUdpBridge>(bridgeId);
2021-07-12 21:21:03 +02:00
if(udpBridge == nullptr) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
if (netif_is_link_up(&gnetif)) {
set_eth_cable_connected(true);
}
return RETURN_OK;
}
/* Poll the EMAC Interface and pass content to the network interface (lwIP) */
ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) {
/* Read a received packet from the Ethernet buffers and send it
to the lwIP for handling */
ethernetif_input(&gnetif);
/* Handle timeouts */
sys_check_timeouts();
#if LWIP_NETIF_LINK_CALLBACK == 1
ethernet_link_periodic_handle(&gnetif);
#endif
if(udpBridge != nullptr) {
MutexGuard lg(udpBridge->bridgeLock);
/* In case ethernet cable is disconnected */
if(not get_eth_cable_connected() and udpBridge->comLinkUp()) {
udpBridge->physicalConnectStatusChange(false);
}
else if(get_eth_cable_connected() and not udpBridge->comLinkUp()) {
udpBridge->physicalConnectStatusChange(true);
}
}
#if LWIP_DHCP == 1
DHCP_Periodic_Handle(&gnetif);
#endif
return RETURN_OK;
}