eive-obsw/bsp_linux_board/ObjectFactory.cpp

166 lines
6.6 KiB
C++
Raw Normal View History

#include <fsfw_hal/linux/uart/UartComIF.h>
#include <fsfw_hal/linux/uart/UartCookie.h>
2021-06-24 11:42:40 +02:00
#include <mission/devices/GPSHyperionHandler.h>
2020-09-30 17:17:01 +02:00
#include "ObjectFactory.h"
2021-05-23 20:44:54 +02:00
#include "objects/systemObjectList.h"
#include "devices/addresses.h"
#include "devices/gpioIds.h"
#include "OBSWConfig.h"
#include "tmtc/apid.h"
#include "tmtc/pusIds.h"
2021-05-24 01:20:44 +02:00
#include "spiConf.h"
2020-09-30 17:17:01 +02:00
2021-06-16 18:38:06 +02:00
#include "linux/boardtest/LibgpiodTest.h"
#include "linux/boardtest/SpiTestClass.h"
#include "linux/boardtest/UartTestClass.h"
#include "mission/core/GenericFactory.h"
#include "mission/utility/TmFunnel.h"
#include "mission/devices/MGMHandlerLIS3MDL.h"
#include "mission/devices/MGMHandlerRM3100.h"
#include "mission/devices/GyroADIS16507Handler.h"
#include "fsfw/datapoollocal/LocalDataPoolManager.h"
#include "fsfw/tmtcservices/CommandingServiceBase.h"
#include "fsfw/tmtcservices/PusServiceBase.h"
2021-06-21 16:54:33 +02:00
#include "fsfw/tmtcpacket/pus/tm.h"
2021-06-16 18:38:06 +02:00
#include "fsfw/tasks/TaskFactory.h"
2021-03-23 16:45:07 +01:00
/* UDP server includes */
2021-06-16 18:38:06 +02:00
#include "fsfw/osal/common/UdpTmTcBridge.h"
#include "fsfw/osal/common/UdpTcPollingTask.h"
2021-06-16 18:38:06 +02:00
#include "fsfw_hal/devicehandlers/GyroL3GD20Handler.h"
#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h"
#include "fsfw_hal/linux/rpi/GpioRPi.h"
#include "fsfw_hal/common/gpio/GpioCookie.h"
#include "fsfw_hal/linux/spi/SpiCookie.h"
#include "fsfw_hal/linux/spi/SpiComIF.h"
2021-02-22 18:46:45 +01:00
2020-11-20 18:27:07 +01:00
void Factory::setStaticFrameworkObjectIds() {
2021-02-24 11:35:22 +01:00
PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR;
PusServiceBase::packetDestination = objects::TM_FUNNEL;
2020-09-30 17:17:01 +02:00
2021-02-24 11:35:22 +01:00
CommandingServiceBase::defaultPacketSource = objects::PUS_PACKET_DISTRIBUTOR;
CommandingServiceBase::defaultPacketDestination = objects::TM_FUNNEL;
2020-09-30 17:17:01 +02:00
2021-02-24 11:35:22 +01:00
TmFunnel::downlinkDestination = objects::UDP_BRIDGE;
// No storage object for now.
TmFunnel::storageDestination = objects::NO_OBJECT;
2020-09-30 17:17:01 +02:00
2021-02-24 11:35:22 +01:00
VerificationReporter::messageReceiver = objects::PUS_SERVICE_1_VERIFICATION;
2021-05-05 22:47:24 +02:00
TmPacketBase::timeStamperId = objects::TIME_STAMPER;
2020-09-30 17:17:01 +02:00
}
2021-06-08 16:45:25 +02:00
void ObjectFactory::produce(void* args){
2021-02-24 11:35:22 +01:00
Factory::setStaticFrameworkObjectIds();
ObjectFactory::produceGenericObjects();
2020-09-30 17:17:01 +02:00
2021-05-23 20:44:54 +02:00
new UdpTmTcBridge(objects::UDP_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR);
new UdpTcPollingTask(objects::UDP_POLLING_TASK, objects::UDP_BRIDGE);
2021-01-14 00:40:30 +01:00
2021-02-23 16:47:34 +01:00
GpioIF* gpioIF = new LinuxLibgpioIF(objects::GPIO_IF);
2021-06-11 11:01:23 +02:00
GpioCookie* gpioCookie = nullptr;
2021-06-16 18:38:06 +02:00
static_cast<void>(gpioCookie);
2021-02-22 17:36:44 +01:00
#if RPI_ADD_SPI_TEST == 1
2021-02-24 11:35:22 +01:00
new SpiTestClass(objects::SPI_TEST, gpioIF);
2021-02-22 17:36:44 +01:00
#endif
2021-02-22 12:57:41 +01:00
2021-06-16 18:38:06 +02:00
#if RPI_ADD_UART_TEST == 1
new UartTestClass(objects::UART_TEST);
#else
new UartComIF(objects::UART_COM_IF);
2021-06-16 18:38:06 +02:00
#endif
2021-02-22 17:36:44 +01:00
#if RPI_LOOPBACK_TEST_GPIO == 1
2021-02-24 11:35:22 +01:00
GpioCookie* gpioCookieLoopback = new GpioCookie();
/* Loopback pins. Adapt according to setup */
gpioId_t gpioIdSender = gpioIds::TEST_ID_0;
int bcmPinSender = 26;
gpioId_t gpioIdReader = gpioIds::TEST_ID_1;
int bcmPinReader = 16;
gpio::createRpiGpioConfig(gpioCookieLoopback, gpioIdSender, bcmPinSender, "GPIO_LB_SENDER",
gpio::Direction::OUT, 0);
2021-02-23 22:07:39 +01:00
gpio::createRpiGpioConfig(gpioCookieLoopback, gpioIdReader, bcmPinReader, "GPIO_LB_READER",
2021-02-22 17:36:44 +01:00
gpio::Direction::IN, 0);
2021-02-24 11:35:22 +01:00
new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookieLoopback);
2021-02-24 11:36:35 +01:00
#endif /* RPI_LOOPBACK_TEST_GPIO == 1 */
2021-02-23 22:07:39 +01:00
new SpiComIF(objects::SPI_COM_IF, gpioIF);
2021-06-11 11:01:23 +02:00
std::string spiDev;
SpiCookie* spiCookie = nullptr;
2021-06-16 18:38:06 +02:00
static_cast<void>(spiCookie);
2021-02-23 22:07:39 +01:00
2021-06-11 11:01:23 +02:00
#if RPI_TEST_ACS_BOARD == 1
if(gpioCookie == nullptr) {
gpioCookie = new GpioCookie();
}
gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_0_LIS3_CS, gpio::MGM_0_BCM_PIN,
2021-02-24 11:35:22 +01:00
"MGM_0_LIS3", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_1_RM3100_CS, gpio::MGM_1_BCM_PIN,
2021-02-23 22:07:39 +01:00
"MGM_1_RM3100", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_2_LIS3_CS, gpio::MGM_2_BCM_PIN,
2021-02-23 22:07:39 +01:00
"MGM_2_LIS3", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpio::createRpiGpioConfig(gpioCookie, gpioIds::MGM_3_RM3100_CS, gpio::MGM_3_BCM_PIN,
2021-02-23 22:07:39 +01:00
"MGM_3_RM3100", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_0_ADIS_CS, gpio::GYRO_0_BCM_PIN,
2021-02-23 22:07:39 +01:00
"GYRO_0_ADIS", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_1_L3G_CS, gpio::GYRO_1_BCM_PIN,
2021-02-23 22:07:39 +01:00
"GYRO_1_L3G", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_2_L3G_CS, gpio::GYRO_2_BCM_PIN,
2021-02-23 22:07:39 +01:00
"GYRO_2_L3G", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpioIF->addGpios(gpioCookie);
2021-02-23 22:07:39 +01:00
2021-06-11 11:01:23 +02:00
spiDev = "/dev/spidev0.0";
spiCookie = new SpiCookie(addresses::MGM_0_LIS3, gpioIds::MGM_0_LIS3_CS, spiDev,
2021-03-07 14:06:29 +01:00
MGMLIS3MDL::MAX_BUFFER_SIZE, spi::DEFAULT_LIS3_MODE, spi::DEFAULT_LIS3_SPEED);
2021-03-06 18:12:50 +01:00
auto mgmLis3Handler = new MGMHandlerLIS3MDL(objects::MGM_0_LIS3_HANDLER,
2021-02-24 11:35:22 +01:00
objects::SPI_COM_IF, spiCookie);
2021-03-06 18:12:50 +01:00
mgmLis3Handler->setStartUpImmediately();
2021-03-07 14:06:29 +01:00
spiCookie = new SpiCookie(addresses::MGM_1_RM3100, gpioIds::MGM_1_RM3100_CS, spiDev,
RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED);
2021-03-06 18:12:50 +01:00
auto mgmRm3100Handler = new MGMHandlerRM3100(objects::MGM_1_RM3100_HANDLER,
objects::SPI_COM_IF, spiCookie);
mgmRm3100Handler->setStartUpImmediately();
2021-02-24 11:36:35 +01:00
2021-03-07 14:06:29 +01:00
spiCookie = new SpiCookie(addresses::GYRO_1_L3G, gpioIds::GYRO_1_L3G_CS, spiDev,
L3GD20H::MAX_BUFFER_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED);
auto gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_1_L3G_HANDLER, objects::SPI_COM_IF,
spiCookie);
gyroL3gHandler->setStartUpImmediately();
2021-02-24 11:36:35 +01:00
#endif /* RPI_TEST_ACS_BOARD == 1 */
2021-05-24 01:20:44 +02:00
#if RPI_TEST_ADIS16507 == 1
2021-06-11 11:01:23 +02:00
if(gpioCookie == nullptr) {
gpioCookie = new GpioCookie();
}
gpio::createRpiGpioConfig(gpioCookie, gpioIds::GYRO_0_ADIS_CS, gpio::GYRO_0_BCM_PIN,
2021-05-25 13:53:03 +02:00
"GYRO_0_ADIS", gpio::Direction::OUT, 1);
2021-06-11 11:01:23 +02:00
gpioIF->addGpios(gpioCookie);
2021-05-25 13:53:03 +02:00
2021-06-11 11:01:23 +02:00
spiDev = "/dev/spidev0.0";
spiCookie = new SpiCookie(addresses::GYRO_0_ADIS, gpioIds::GYRO_0_ADIS_CS, spiDev,
2021-05-24 01:20:44 +02:00
ADIS16507::MAXIMUM_REPLY_SIZE, spi::DEFAULT_ADIS16507_MODE, spi::DEFAULT_ADIS16507_SPEED,
nullptr, nullptr);
auto adisGyroHandler = new GyroADIS16507Handler(objects::GYRO_0_ADIS_HANDLER, objects::SPI_COM_IF, spiCookie);
adisGyroHandler->setStartUpImmediately();
#endif /* RPI_TEST_ADIS16507 == 1 */
#if RPI_TEST_GPS_HANDLER == 1
UartCookie* uartCookie = new UartCookie(objects::GPS0_HANDLER, "/dev/serial0",
UartModes::CANONICAL, 9600, 1024);
uartCookie->setToFlushInput(true);
uartCookie->setReadCycles(6);
2021-06-24 11:42:40 +02:00
GPSHyperionHandler* gpsHandler = new GPSHyperionHandler(objects::GPS0_HANDLER,
objects::UART_COM_IF, uartCookie);
gpsHandler->setStartUpImmediately();
#endif
2020-09-30 17:17:01 +02:00
}