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/ip_addr.h>
|
2022-05-05 20:55:28 +02:00
|
|
|
#include <lwip/udp.h>
|
2021-07-12 21:21:03 +02:00
|
|
|
|
|
|
|
#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 {
|
2022-05-05 20:55:28 +02:00
|
|
|
friend class UdpTcLwIpPollingTask;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, object_id_t tmStoreId,
|
|
|
|
object_id_t tcStoreId);
|
|
|
|
virtual ~TmTcLwIpUdpBridge();
|
2021-07-12 21:21:03 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
virtual ReturnValue_t initialize() override;
|
|
|
|
ReturnValue_t udp_server_init();
|
2021-07-12 21:21:03 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
/**
|
|
|
|
* In addition to default implementation, ethernet link status is checked.
|
|
|
|
* @param operationCode
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
2021-07-12 21:21:03 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
/** 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;
|
2021-07-12 21:21:03 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
/**
|
|
|
|
* @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);
|
2021-07-12 21:21:03 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
/**
|
|
|
|
* Check whether the communication link is up.
|
|
|
|
* Caller must ensure thread-safety by using the bridge lock.
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
bool comLinkUp() const;
|
2021-07-12 21:21:03 +02:00
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
private:
|
|
|
|
struct udp_pcb *upcb = nullptr;
|
|
|
|
ip_addr_t lastAdd;
|
|
|
|
u16_t lastPort = 0;
|
|
|
|
bool physicalConnection = false;
|
|
|
|
MutexIF *bridgeLock = nullptr;
|
2021-07-12 21:21:03 +02:00
|
|
|
|
|
|
|
#if TCPIP_RECV_WIRETAPPING == 1
|
2022-05-05 20:55:28 +02:00
|
|
|
bool connectFlag = false;
|
2021-07-12 21:21:03 +02:00
|
|
|
#endif
|
|
|
|
|
2022-05-05 20:55:28 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
2021-07-12 21:21:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ */
|