fsfw-example-common/stm32h7/networking/TmTcLwIpUdpBridge.h

80 lines
2.3 KiB
C
Raw Normal View History

2021-07-12 21:21:03 +02:00
#ifndef BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_
#define BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_
#include <fsfw/tmtcservices/TmTcBridge.h>
#include <lwip/udp.h>
#include <lwip/ip_addr.h>
#define TCPIP_RECV_WIRETAPPING 0
/**
* This bridge is used to forward TMTC packets received via LwIP UDP to the internal software bus.
*/
class TmTcLwIpUdpBridge : public TmTcBridge {
friend class UdpTcLwIpPollingTask;
public:
TmTcLwIpUdpBridge(object_id_t objectId,
object_id_t ccsdsPacketDistributor, object_id_t tmStoreId,
object_id_t tcStoreId);
virtual ~TmTcLwIpUdpBridge();
virtual ReturnValue_t initialize() override;
ReturnValue_t udp_server_init();
/**
* In addition to default implementation, ethernet link status is checked.
* @param operationCode
* @return
*/
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
/** TM Send implementation uses udp_send function from lwIP stack
* @param data
* @param dataLen
* @return
*/
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
/**
* @brief This function is called when an UDP datagram has been
* received on the port UDP_PORT.
* @param arg
* @param upcb_
* @param p
* @param addr Source address which will be bound to TmTcUdpBridge::lastAdd
* @param port
*/
static void udp_server_receive_callback(void *arg,
struct udp_pcb *upcb_, struct pbuf *p, const ip_addr_t *addr,
u16_t port);
/**
* Check whether the communication link is up.
* Caller must ensure thread-safety by using the bridge lock.
* @return
*/
bool comLinkUp() const;
private:
struct udp_pcb *upcb = nullptr;
ip_addr_t lastAdd;
u16_t lastPort = 0;
bool physicalConnection = false;
MutexIF* bridgeLock = nullptr;
#if TCPIP_RECV_WIRETAPPING == 1
bool connectFlag = false;
#endif
/**
* Used to notify bridge about change in the physical ethernet connection.
* Connection does not mean that replies are possible (recipient not set yet), but
* disconnect means that we can't send anything. Caller must ensure thread-safety
* by using the bridge lock.
*/
void physicalConnectStatusChange(bool connect);
};
#endif /* BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ */