ProfinetConnector/src/app.cpp
2022-12-09 12:54:37 +03:00

55 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "app.hpp"
#include "program_config.hpp"
bool App::Init(std::string profinet_config_file)
{
ProfinetSettings profinet_settings;
ProfinetDeviceSettings profinet_dev_settings;
ProfinetPipesSettings profinet_pipe_settings;
/// Читаем настройки из файла
if (!programconf_getProfinetSettings(profinet_config_file, profinet_settings, profinet_pipe_settings))
{
return false;
}
///Создаем структуру в разделяемой памяти
ProfinetData_Map * p_profinetMap = shared_data_.Create("profinet_shared_data");
/// Читаем настройки из файла, выделяем память под структуру модулей и подмодулей
if (!programconf_getProfinetDeviceSettings(profinet_settings.profinet_device_config,
profinet_dev_settings,
p_profinetMap,
shared_data_,
user_data_map_))
{
return false;
}
/// Настройка Profinet: Инициализация pnet, добавление DAP слотов и подслотов и подключение к ним модулей и подмодулей,
if (!profinet_.Config(profinet_settings, profinet_dev_settings, p_profinetMap))
{
return false;
}
/// Создаем именованые каналы
pipes_.Init(profinet_pipe_settings);
/**
* Циклические данные устройства передаются с определенным периодом, сообщения от контроллера при этом не требуются.
*/
/// Запуск потока Profinet
profinet_.Start();
/// Запуск потока чтения запросов по pipe
pipes_.Start(&profinet_, &user_data_map_);
return true;
}
void App::Run()
{
for (;;)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}