This commit is contained in:
2022-08-08 12:32:06 +02:00
parent d2b15ee4fa
commit 5792aff5e3
32 changed files with 476 additions and 657 deletions

View File

@ -1,6 +1,5 @@
#include "TmTcLwIpUdpBridge.h"
#include <fsfw/ipc/MutexGuard.h>
#include <fsfw/serialize/EndianConverter.h>
#include <fsfw/serviceinterface/ServiceInterface.h>
@ -8,10 +7,8 @@
#include "app_ethernet.h"
#include "udp_config.h"
TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId,
object_id_t ccsdsPacketDistributor,
object_id_t tmStoreId,
object_id_t tcStoreId)
TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor,
object_id_t tmStoreId, object_id_t tcStoreId)
: TmTcBridge(objectId, ccsdsPacketDistributor, tmStoreId, tcStoreId) {
TmTcLwIpUdpBridge::lastAdd.addr = IPADDR_TYPE_ANY;
}
@ -40,8 +37,7 @@ ReturnValue_t TmTcLwIpUdpBridge::udp_server_init() {
if (err == ERR_OK) {
/* Set a receive callback for the upcb */
udp_recv(TmTcLwIpUdpBridge::upcb, &udp_server_receive_callback,
(void *)this);
udp_recv(TmTcLwIpUdpBridge::upcb, &udp_server_receive_callback, (void *)this);
return RETURN_OK;
} else {
udp_remove(TmTcLwIpUdpBridge::upcb);
@ -64,15 +60,13 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) {
int ipAddress4 = ipAddress & 0xFF;
#if OBSW_VERBOSE_LEVEL == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec
<< ipAddress4 << "." << ipAddress3 << "." << ipAddress2 << "."
<< ipAddress1 << std::endl;
sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec << ipAddress4 << "."
<< ipAddress3 << "." << ipAddress2 << "." << ipAddress1 << std::endl;
uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort);
sif::info << "TmTcLwIpUdpBridge: Client IP Port " << (int)portSwapped
<< std::endl;
sif::info << "TmTcLwIpUdpBridge: Client IP Port " << (int)portSwapped << std::endl;
#else
sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n",
ipAddress4, ipAddress3, ipAddress2, ipAddress1);
sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n", ipAddress4, ipAddress3,
ipAddress2, ipAddress1);
uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort);
sif::printInfo("TmTcLwIpUdpBridge: Client IP Port: %d\n", portSwapped);
#endif
@ -86,8 +80,7 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) {
ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
struct pbuf *p_tx = pbuf_alloc(PBUF_TRANSPORT, dataLen, PBUF_RAM);
if ((p_tx != nullptr) && (lastAdd.addr != IPADDR_TYPE_ANY) &&
(upcb != nullptr)) {
if ((p_tx != nullptr) && (lastAdd.addr != IPADDR_TYPE_ANY) && (upcb != nullptr)) {
/* copy data to pbuf */
err_t err = pbuf_take(p_tx, (const char *)data, dataLen);
if (err != ERR_OK) {
@ -115,20 +108,18 @@ ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
return RETURN_OK;
}
void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg,
struct udp_pcb *upcb_,
struct pbuf *p,
const ip_addr_t *addr,
void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg, struct udp_pcb *upcb_,
struct pbuf *p, const ip_addr_t *addr,
u16_t port) {
auto udpBridge = reinterpret_cast<TmTcLwIpUdpBridge *>(arg);
if (udpBridge == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning
<< "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!"
<< std::endl;
sif::warning << "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!"
<< std::endl;
#else
sif::printWarning("TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid "
"UDP bridge!\n");
sif::printWarning(
"TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid "
"UDP bridge!\n");
#endif
}
/* allocate pbuf from RAM*/
@ -159,8 +150,8 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg,
#endif
store_address_t storeId;
ReturnValue_t returnValue = udpBridge->tcStore->addData(
&storeId, reinterpret_cast<uint8_t *>(p->payload), p->len);
ReturnValue_t returnValue =
udpBridge->tcStore->addData(&storeId, reinterpret_cast<uint8_t *>(p->payload), p->len);
if (returnValue != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UDP Server: Data storage failed" << std::endl;