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

67 lines
1.9 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"
2021-07-16 13:20:38 +02:00
#include "networking.h"
2021-07-12 21:21:03 +02:00
#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-16 13:20:38 +02:00
2021-07-13 09:15:36 +02:00
#include "lwip/timeouts.h"
2021-07-12 21:21:03 +02:00
2021-07-16 13:20:38 +02:00
UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId,
struct netif* gnetif):
SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) {
2021-07-12 21:21:03 +02:00
}
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;
}
2021-07-16 13:20:38 +02:00
if (netif_is_link_up(gnetif)) {
networking::setEthCableConnected(true);
2021-07-12 21:21:03 +02:00
}
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 */
2021-07-16 13:20:38 +02:00
ethernetif_input(gnetif);
2021-07-12 21:21:03 +02:00
/* Handle timeouts */
sys_check_timeouts();
#if LWIP_NETIF_LINK_CALLBACK == 1
2021-07-16 13:39:50 +02:00
networking::ethernetLinkPeriodicHandle(gnetif);
2021-07-12 21:21:03 +02:00
#endif
if(udpBridge != nullptr) {
MutexGuard lg(udpBridge->bridgeLock);
/* In case ethernet cable is disconnected */
2021-07-16 13:20:38 +02:00
if(not networking::getEthCableConnected() and udpBridge->comLinkUp()) {
2021-07-12 21:21:03 +02:00
udpBridge->physicalConnectStatusChange(false);
}
2021-07-16 13:20:38 +02:00
else if(networking::getEthCableConnected() and not udpBridge->comLinkUp()) {
2021-07-12 21:21:03 +02:00
udpBridge->physicalConnectStatusChange(true);
}
}
#if LWIP_DHCP == 1
2021-07-16 13:20:38 +02:00
DHCP_Periodic_Handle(gnetif);
2021-07-12 21:21:03 +02:00
#endif
return RETURN_OK;
}