diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..810bf76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# игнорирование папок build +/src/build +/profinet_test/sample_app/build +*.bin diff --git a/src/main.cpp b/src/main.cpp index f688dfa..b0226be 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,19 +9,21 @@ int main(int argc, char * argv[]) }; ProfinetSettings settings = { + .ticks_us = 1000, .EthIface = "enp6s1", - .ticks_us = 1000 }; ProfinetDeviceSettings profinet_settings = { + .product_name = "P-Net Sample Application", + .station_name = "rt-labs-dev", .im_0 = { .vendor_id = 0x0493, .hw_revision = 3, .sw_revision = { .prefix = 'V', .functional_enhancement = 0, + .bug_fix = 2, .internal_change = 0, - .bug_fix = 2 }, .revision_counter = 0, .profile_id = 0x1234, @@ -46,8 +48,6 @@ int main(int argc, char * argv[]) .device_id = 0x0002, .oem_vendor_id = 0xcafe, .oem_device_id = 0xee02, - .product_name = "P-Net Sample Application", - .station_name = "rt-labs-dev", .send_hello = true, .min_device_interval = 32 //1ms ?? }; diff --git a/src/profinet/profinet.cmake b/src/profinet/profinet.cmake index bd95bc4..a11d898 100644 --- a/src/profinet/profinet.cmake +++ b/src/profinet/profinet.cmake @@ -1,6 +1,8 @@ set(SRC_FILES ${SRC_FILES} ./profinet/profinet.cpp + ./profinet/profinet_slot.cpp + ./profinet/profinet_subslot.cpp ./profinet/profinet_cb_alarm_ack_cnf.cpp ./profinet/profinet_cb_alarm_cnf.cpp ./profinet/profinet_cb_alarm_ind.cpp @@ -16,8 +18,6 @@ set(SRC_FILES ${SRC_FILES} ./profinet/profinet_cb_signal_led_ind.cpp ./profinet/profinet_cb_state_ind.cpp ./profinet/profinet_cb_write_ind.cpp - ./profinet/profinet.cpp - ./profinet/profinet_slot.cpp - ./profinet/profinet_subslot.cpp) + ) set(INC_DIRS ${INC_DIRS} ./profinet) \ No newline at end of file diff --git a/src/profinet/profinet.cpp b/src/profinet/profinet.cpp index 1448d67..80a107f 100644 --- a/src/profinet/profinet.cpp +++ b/src/profinet/profinet.cpp @@ -256,4 +256,187 @@ bool Profinet::addSlotAndPlugModule(std::shared_ptr& slot_ptr) return false; return true; +} + +ProfinetSlot * Profinet::getSlotPtr(uint16_t slot_nbr, uint32_t module_id) +{ + /// 1. Проверить, что слот slot добавлен в конфигурацию + if (!m_slots.count(slot_nbr)) + { + return nullptr; + } + + ProfinetSlot * const slot_ptr = m_slots[slot_nbr].get(); + + /// 2. Проверить, что в слоте slot идентификатор модуля m_module_id совпадает с module_ident + if (slot_ptr->m_module_id != module_id) + { + return nullptr; + } + + return slot_ptr; +} + + +/**\ + * ========================================================================================= + * Callbacks + * ========================================================================================= + */ + +int Profinet::callbackStateInd ( uint32_t arep, pnet_event_values_t event) +{ + return 0; +} + +int Profinet::callbackConnectInd ( uint32_t arep, pnet_result_t * p_result) +{ + return 0; +} + +int Profinet::callbackReleaseInd ( uint32_t arep, pnet_result_t * p_result) +{ + return 0; +} + +int Profinet::callbackDcontrolInd ( uint32_t arep, + pnet_control_command_t control_command, + pnet_result_t * p_result) +{ + return 0; +} + +int Profinet::callbackCcontrolInd ( uint32_t arep, pnet_result_t * p_result) +{ + return 0; +} + +int Profinet::callbackReadInd ( uint32_t arep, + uint16_t slot_nbr, + uint16_t subslot_nbr, + uint16_t idx, + uint16_t sequence_number, + uint8_t ** pp_read_data, + uint16_t * p_read_length, + pnet_result_t * p_result) +{ + return 0; +} + +int Profinet::callbackWriteInd ( uint32_t arep, + uint16_t slot_nbr, + uint16_t subslot_nbr, + uint16_t idx, + uint16_t sequence_number, + uint16_t write_length, + const uint8_t * p_write_data, + pnet_result_t * p_result) +{ + return 0; +} + + + +int Profinet::callbackExpModuleInd ( uint16_t slot, uint32_t module_ident) +{ + ProfinetSlot * const slot_ptr = getSlotPtr(slot, module_ident); + /** + * @brief Проверка, что слот slot добавлен в конфигурацию и что + * идентификатор модуля m_module_id совпадает с module_ident + * + */ + if (slot_ptr == nullptr) + { + return -1; + } + + /// Подключить модуль в слот + if (!slot_ptr->plugModule(m_pnet_data)) + { + return -1; + } + + return 0; +} + +int Profinet::callbackExpSubmoduleInd ( uint16_t slot, + uint16_t subslot, + uint32_t module_id, + uint32_t submodule_id, + const pnet_data_cfg_t * p_exp_data) +{ + ProfinetSlot * const slot_ptr = getSlotPtr(slot, module_id); + /** + * @brief Проверка, что слот slot добавлен в конфигурацию и что + * идентификатор модуля m_module_id совпадает с module_ident + * + */ + if (slot_ptr == nullptr) + { + return -1; + } + + /// Проверка, что модуль подключен к слоту + if (!slot_ptr->isModulePlugged()) + { + return -1; + } + + ProfinetSubslot * const subslot_ptr = slot_ptr->getSubslotPtr(subslot, submodule_id, p_exp_data); + + /** + * Проверка того, что: + * - подслот subslot добавлен в конфигурацию слота, + * - идентификатор модуля подслота m_module_id совпадает с submodule_id + * - конфигурация данных слота совпадает с p_exp_data + */ + if (subslot_ptr == nullptr) + { + return -1; + } + + /// Подключить подмодуль submodule_id к подслоту subslot + if (!subslot_ptr->plugSubmodule(m_pnet_data)) + { + return -1; + } + + return 0; +} + +int Profinet::callbackNewDataStatusInd ( uint32_t arep, + uint32_t crep, + uint8_t changes, + uint8_t data_status) +{ + return 0; +} + +int Profinet::callbackAlarmInd ( uint32_t arep, + const pnet_alarm_argument_t * p_alarm_arg, + uint16_t data_len, + uint16_t data_usi, + const uint8_t * p_data) +{ + return 0; +} + +int Profinet::callbackAlarmCnf ( uint32_t arep, const pnet_pnio_status_t * p_pnio_status) +{ + return 0; +} + +int Profinet::callbackAlarmAckCnf ( uint32_t arep, int res) +{ + return 0; +} + +int Profinet::callbackResetInd ( bool should_reset_application, uint16_t reset_mode) +{ + return 0; +} + +int Profinet::callbackSignalLedInd (bool led_state) +{ + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet.hpp b/src/profinet/profinet.hpp index e5a8a67..370fed3 100644 --- a/src/profinet/profinet.hpp +++ b/src/profinet/profinet.hpp @@ -1,12 +1,13 @@ #pragma once -#include "../libs/include/pnet_api.h" +#include "../../libs/include/pnet_api.h" #include "profinet_settings.hpp" #include #include #include #include "profinet_slot.hpp" #include "profinet_serv_data.hpp" +#include "profinet_iface.hpp" class Profinet { public: @@ -27,13 +28,44 @@ private: std::map> m_slots; private: - + /** + * @brief Геттер указателя на слот. Проверяет в конфигурации наличие слота slot_nbr + * с правильным module_id + * + * @param slot_nbr номер слота + * @param module_id идентификатор модуля + * @return ProfinetSlot* указатель на слот + */ + ProfinetSlot * getSlotPtr(uint16_t slot_nbr, uint32_t module_id); public: - /// AREP Application Relationship End Point /** - * @brief This application call-back function is called by the Profinet stack on - * specific state transitions within the Profinet stack. + * @brief + * AREP - Application Relationship End Point (uint32), + * pretty much an index into an array of AR. + * AR - Application Relation. Consists of several communication relations (CR). + * Typically an IO AR, which is a connection to a PLC, but can also be an + * Supervisor AR. + */ + + /** + * + * Indication to the application that a module is requested by the controller in + * a specific slot. + * + * This application call-back function is called by the Profinet stack to + * indicate that the controller has requested the presence of a specific module, + * ident number \a module_ident, in the slot number \a slot. + * + * The application must react to this by configuring itself accordingly (if + * possible) and call function pnet_plug_module() to configure the stack for + * this module. + * + * If the wrong module ident number is plugged then the stack will accept this, + * but signal to the controller that a substitute module is fitted. + * + * This function should return 0 (zero) if a valid module was plugged. Or return + * -1 if the application cannot handle this request. * * @param arep In: The AREP. * @param event In: The state transition event. See pnet_event_values_t @@ -50,9 +82,7 @@ public: * @return 0 on success. * -1 if an error occurred. */ - int callbackConnectInd ( - uint32_t arep, - pnet_result_t * p_result); + int callbackConnectInd ( uint32_t arep, pnet_result_t * p_result); /** * @brief This application call-back function is called by the Profinet stack on every @@ -63,39 +93,31 @@ public: * @return 0 on success. * -1 if an error occurred. */ - int callbackReleaseInd ( - uint32_t arep, - pnet_result_t * p_result); + int callbackReleaseInd ( uint32_t arep, pnet_result_t * p_result); /** * @brief This application call-back function is called by the Profinet stack on every * DControl request from the Profinet controller. * - * @param net InOut: The p-net stack instance - * @param arg InOut: User-defined data (not used by p-net) * @param arep In: The AREP. * @param control_command In: The DControl command code. * @param p_result Out: Detailed error information if return != 0. * @return 0 on success. * -1 if an error occurred. */ - int callbackDcontrolInd ( - uint32_t arep, - pnet_control_command_t control_command, - pnet_result_t * p_result); + int callbackDcontrolInd ( uint32_t arep, + pnet_control_command_t control_command, + pnet_result_t * p_result); /** * @brief * This application call-back function is called by the Profinet stack on every * CControl confirmation from the Profinet controller. - * - * @param arg InOut: User-defined data (not used by p-net) * @param arep In: The AREP. * @param p_result Out: Detailed error information. * @return 0 on success. Other values are ignored. */ - int callbackCcontrolCnf ( - uint32_t arep, - pnet_result_t * p_result); + int callbackCcontrolInd ( uint32_t arep, pnet_result_t * p_result); + /** * @brief This application call-back function is called by the Profinet stack on every * IODRead request from the Profinet controller which specify an @@ -159,9 +181,7 @@ public: * @param module_ident * @return int */ - int callbackExpModuleInd ( - uint16_t slot, - uint32_t module_ident); + int callbackExpModuleInd ( uint16_t slot, uint32_t module_ident); /** * @brief This application call-back function is called by the Profinet stack to @@ -179,9 +199,6 @@ public: * -1 if an error occurred. */ int callbackExpSubmoduleInd ( - pnet_t * net, - void * arg, - uint32_t api, uint16_t slot, uint16_t subslot, uint32_t module_id, @@ -232,11 +249,7 @@ public: * @param p_pnio_status In: Detailed ACK information. * @return 0 on success. Other values are ignored. */ - int callbackAlarmCnf ( - pnet_t * net, - void * arg, - uint32_t arep, - const pnet_pnio_status_t * p_pnio_status); + int callbackAlarmCnf ( uint32_t arep, const pnet_pnio_status_t * p_pnio_status); /** * @brief This functionality is used for alarms triggered by the IO-controller. @@ -248,9 +261,7 @@ public: * side. This is cnf(-). * @return 0 on success. Other values are ignored. */ - int callbackAlarmAckCnf ( - uint32_t arep, - int res); + int callbackAlarmAckCnf ( uint32_t arep, int res); /** * @brief This application call-back function is called by the Profinet stack on every * reset request (via the DCP "Set" command) from the Profinet controller. @@ -260,9 +271,7 @@ public: * @param reset_mode In: Detailed reset information. * @return 0 on success. Other values are ignored. */ - int callbackResetInd ( - bool should_reset_application, - uint16_t reset_mode); + int callbackResetInd ( bool should_reset_application, uint16_t reset_mode); /** * @brief Use this callback to implement control of the LED. diff --git a/src/profinet/profinet_cb_alarm_cnf.cpp b/src/profinet/profinet_cb_alarm_cnf.cpp index b3c595e..1ea0b76 100644 --- a/src/profinet/profinet_cb_alarm_cnf.cpp +++ b/src/profinet/profinet_cb_alarm_cnf.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_alarm_cnf.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_alarm_cnf ( pnet_t * net, @@ -6,5 +7,9 @@ int profinet_cb_alarm_cnf ( uint32_t arep, const pnet_pnio_status_t * p_pnio_status) { + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackAlarmCnf(arep, p_pnio_status); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_alarm_ind.cpp b/src/profinet/profinet_cb_alarm_ind.cpp index 26e90ff..c7d6a07 100644 --- a/src/profinet/profinet_cb_alarm_ind.cpp +++ b/src/profinet/profinet_cb_alarm_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_alarm_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_alarm_ind ( pnet_t * net, @@ -9,6 +10,9 @@ int profinet_cb_alarm_ind ( uint16_t data_usi, const uint8_t * p_data) { - + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackAlarmInd(arep, p_alarm_arg, data_len, data_usi, p_data); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_ccontrol_ind.cpp b/src/profinet/profinet_cb_ccontrol_ind.cpp index 2c8e72c..e652186 100644 --- a/src/profinet/profinet_cb_ccontrol_ind.cpp +++ b/src/profinet/profinet_cb_ccontrol_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_ccontrol_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_ccontrol_ind ( pnet_t * net, @@ -6,6 +7,9 @@ int profinet_cb_ccontrol_ind ( uint32_t arep, pnet_result_t * p_result) { + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackCcontrolInd(arep, p_result); return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_connect_ind.cpp b/src/profinet/profinet_cb_connect_ind.cpp index 348e59a..c9a6e55 100644 --- a/src/profinet/profinet_cb_connect_ind.cpp +++ b/src/profinet/profinet_cb_connect_ind.cpp @@ -1,5 +1,5 @@ #include "./profinet/profinet_cb_connect_ind.hpp" - +#include "./profinet/profinet.hpp" #include using namespace std; @@ -9,11 +9,9 @@ int profinet_cb_connect_ind( pnet_t * net, uint32_t arep, pnet_result_t * p_result) { - cout << "profinet_cb_connect_ind: PLC connect indication. AREP:" << arep << endl; - /* - * Handle the request on an application level. - * This is a very simple application which does not need to handle anything. - * All the needed information is in the AR data structure. - */ + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackConnectInd(arep, p_result); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_dcontrol_ind.cpp b/src/profinet/profinet_cb_dcontrol_ind.cpp index a0554de..d4f114c 100644 --- a/src/profinet/profinet_cb_dcontrol_ind.cpp +++ b/src/profinet/profinet_cb_dcontrol_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_dcontrol_ind ( pnet_t * net, @@ -7,6 +8,9 @@ int profinet_cb_dcontrol_ind ( pnet_control_command_t control_command, pnet_result_t * p_result) { - + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackDcontrolInd(arep, control_command, p_result); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_exp_module_ind.cpp b/src/profinet/profinet_cb_exp_module_ind.cpp index ba63779..2801e11 100644 --- a/src/profinet/profinet_cb_exp_module_ind.cpp +++ b/src/profinet/profinet_cb_exp_module_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_exp_module_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_exp_module_ind ( pnet_t * net, @@ -7,5 +8,9 @@ int profinet_cb_exp_module_ind ( uint16_t slot, uint32_t module_ident) { + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackExpModuleInd(slot, module_ident); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_exp_submodule_ind.cpp b/src/profinet/profinet_cb_exp_submodule_ind.cpp index 6416c55..deebaa7 100644 --- a/src/profinet/profinet_cb_exp_submodule_ind.cpp +++ b/src/profinet/profinet_cb_exp_submodule_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_exp_submodule_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_exp_submodule_ind ( pnet_t * net, @@ -10,6 +11,9 @@ int profinet_cb_exp_submodule_ind ( uint32_t submodule_id, const pnet_data_cfg_t * p_exp_data) { + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackExpSubmoduleInd(slot, subslot, module_id, submodule_id, p_exp_data); return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_new_data_status_ind.cpp b/src/profinet/profinet_cb_new_data_status_ind.cpp index 560fc56..a60499a 100644 --- a/src/profinet/profinet_cb_new_data_status_ind.cpp +++ b/src/profinet/profinet_cb_new_data_status_ind.cpp @@ -1,4 +1,6 @@ #include "./profinet/profinet_cb_new_data_status_ind.hpp" +#include "./profinet/profinet.hpp" + int profinet_cb_new_data_status_ind ( pnet_t * net, @@ -8,6 +10,9 @@ int profinet_cb_new_data_status_ind ( uint8_t changes, uint8_t data_status) { - + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackNewDataStatusInd(arep, crep, changes, data_status); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_read_ind.cpp b/src/profinet/profinet_cb_read_ind.cpp index b841093..bf1ce9d 100644 --- a/src/profinet/profinet_cb_read_ind.cpp +++ b/src/profinet/profinet_cb_read_ind.cpp @@ -1,5 +1,5 @@ #include "./profinet/profinet_cb_read_ind.hpp" - +#include "./profinet/profinet.hpp" int profinet_cb_read_ind ( pnet_t * net, @@ -14,6 +14,16 @@ int profinet_cb_read_ind ( uint16_t * p_read_length, pnet_result_t * p_result) { - + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackReadInd( arep, + slot_nbr, + subslot_nbr, + idx, + sequence_number, + pp_read_data, + p_read_length, + p_result); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_release_ind.cpp b/src/profinet/profinet_cb_release_ind.cpp index 7f8bf98..5b40dad 100644 --- a/src/profinet/profinet_cb_release_ind.cpp +++ b/src/profinet/profinet_cb_release_ind.cpp @@ -1,5 +1,5 @@ #include "./profinet/profinet_cb_release_ind.hpp" - +#include "./profinet/profinet.hpp" #include using namespace std; @@ -9,7 +9,9 @@ int profinet_cb_release_ind( pnet_t * net, uint32_t arep, pnet_result_t * p_result) { - cout << "profinet_cb_release_ind: PLC release (disconnect) indication. AREP: " << arep << endl; - /// По идее погасить светодиод наличия связи + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackReleaseInd(arep, p_result); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_reset_ind.cpp b/src/profinet/profinet_cb_reset_ind.cpp index 0ad4e28..e4eb1eb 100644 --- a/src/profinet/profinet_cb_reset_ind.cpp +++ b/src/profinet/profinet_cb_reset_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_reset_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_reset_ind ( pnet_t * net, @@ -6,6 +7,9 @@ int profinet_cb_reset_ind ( bool should_reset_application, uint16_t reset_mode) { + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackResetInd(should_reset_application, reset_mode); return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_signal_led_ind.cpp b/src/profinet/profinet_cb_signal_led_ind.cpp index 9467a20..3ec3bb4 100644 --- a/src/profinet/profinet_cb_signal_led_ind.cpp +++ b/src/profinet/profinet_cb_signal_led_ind.cpp @@ -1,7 +1,11 @@ #include "./profinet/profinet_cb_signal_led_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_signal_led_ind (pnet_t * net, void * arg, bool led_state) { + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackSignalLedInd(led_state); return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_state_ind.cpp b/src/profinet/profinet_cb_state_ind.cpp index bf34849..97dd174 100644 --- a/src/profinet/profinet_cb_state_ind.cpp +++ b/src/profinet/profinet_cb_state_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_state_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_state_ind ( pnet_t * net, @@ -6,6 +7,9 @@ int profinet_cb_state_ind ( uint32_t arep, pnet_event_values_t event) { - + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackStateInd(arep, event); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_cb_write_ind.cpp b/src/profinet/profinet_cb_write_ind.cpp index 8ea3aea..1850858 100644 --- a/src/profinet/profinet_cb_write_ind.cpp +++ b/src/profinet/profinet_cb_write_ind.cpp @@ -1,4 +1,5 @@ #include "./profinet/profinet_cb_write_ind.hpp" +#include "./profinet/profinet.hpp" int profinet_cb_write_ind ( pnet_t * net, @@ -13,6 +14,16 @@ int profinet_cb_write_ind ( const uint8_t * p_write_data, pnet_result_t * p_result) { - + Profinet * const profinet_ptr = static_cast(arg); + + profinet_ptr->callbackWriteInd( arep, + slot_nbr, + subslot_nbr, + idx, + sequence_number, + write_length, + p_write_data, + p_result); + return 0; } \ No newline at end of file diff --git a/src/profinet/profinet_slot.cpp b/src/profinet/profinet_slot.cpp index aee6435..b62b1e5 100644 --- a/src/profinet/profinet_slot.cpp +++ b/src/profinet/profinet_slot.cpp @@ -57,3 +57,28 @@ bool ProfinetSlot::addSubslotAndPlugSubmodule(ProfinetServiceData& pnet_data, st return true; } +ProfinetSubslot * ProfinetSlot::getSubslotPtr(uint16_t subslot_nbr, uint32_t submodule_id, const pnet_data_cfg_t * const p_data_cfg) +{ + /// Проверка наличия подслота в конфигурации + if (!m_subslots.count(subslot_nbr)) + { + return nullptr; + } + + ProfinetSubslot * const subslot_ptr = m_subslots[subslot_nbr].get(); + /// Проверка совпадения идентификатора подмодуля + if (subslot_ptr->m_submodule_id != submodule_id) + { + return nullptr; + } + /// Проверка совпадения конфигурации данных + if ( (subslot_ptr->m_data_cfg.data_dir != p_data_cfg->data_dir) || + (subslot_ptr->m_data_cfg.insize != p_data_cfg->insize) || + (subslot_ptr->m_data_cfg.outsize != p_data_cfg->outsize) + ) + { + return nullptr; + } + + return subslot_ptr; +} diff --git a/src/profinet/profinet_slot.hpp b/src/profinet/profinet_slot.hpp index 3cd151d..d08e269 100644 --- a/src/profinet/profinet_slot.hpp +++ b/src/profinet/profinet_slot.hpp @@ -44,6 +44,10 @@ public: bool addSubslotAndPlugSubmodule(ProfinetServiceData& pnet_data, std::shared_ptr& subslot_ptr); + bool isModulePlugged() { return m_module_plugged; } + + ProfinetSubslot * getSubslotPtr(uint16_t subslot_nbr, uint32_t submodule_id, const pnet_data_cfg_t * const p_data_cfg); + public: /// Номер слота const uint16_t m_slot_nbr; diff --git a/src/profinet/profinet_subslot.hpp b/src/profinet/profinet_subslot.hpp index 3869101..6f932a3 100644 --- a/src/profinet/profinet_subslot.hpp +++ b/src/profinet/profinet_subslot.hpp @@ -12,7 +12,7 @@ * @param subslot InOut: Subslot structure * @param tag InOut: Typically a handle to a submodule */ -typedef void (*ProfinetSubslotCallback) (ProfinetSubslot * subslot, void * tag); +typedef void (*ProfinetSubslotCallback) (void * subslot, void * tag); class ProfinetSubslot { diff --git a/src/utils/utils.c b/src/utils/utils.c index 6902485..8be9dcd 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -1,4 +1,6 @@ #include "utils.h" +#include "string.h" +#include "pnal.h" static void utils_copy_ip_to_struct ( pnet_cfg_ip_addr_t * destination_struct, @@ -120,7 +122,7 @@ int utils_pnet_cfg_init_netifs ( uint32_t netmask; uint32_t gateway; - ret = app_utils_get_netif_namelist ( + ret = utils_get_netif_namelist ( netif_list_str, PNET_MAX_PHYSICAL_PORTS, if_list,