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