diff --git a/Src/modules/canopen/CMakeLists.txt b/Src/modules/canopen/CMakeLists.txt new file mode 100644 index 0000000..142e5ed --- /dev/null +++ b/Src/modules/canopen/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (C) 2023 Dmitry Ponomarev +# Distributed under the terms of the GPL v3 license, available in the file LICENSE. + +list(APPEND APPLICATION_SOURCES + ${CMAKE_CURRENT_LIST_DIR}/canopen.cpp +) diff --git a/Src/modules/canopen/canopen.cpp b/Src/modules/canopen/canopen.cpp new file mode 100644 index 0000000..58f7e9d --- /dev/null +++ b/Src/modules/canopen/canopen.cpp @@ -0,0 +1,30 @@ +/** + * This program is free software under the GNU General Public License v3. + * See for details. + * Author: Dmitry Ponomarev + */ + +#include "canopen.hpp" +#include "can_driver.h" + +REGISTER_MODULE(CanopenModule) + +void CanopenModule::init() { + int8_t res = canDriverInit(1000000, CAN_DRIVER_SECOND); + health = (res < 0) ? Status::FATAL_MALFANCTION : Status::OK; + + mode = Module::Mode::OPERATIONAL; +} + +void CanopenModule::spin_once() { + if (health == Status::FATAL_MALFANCTION) { + return; + } + + CanardCANFrame frame; + frame.id = 100; + frame.data_len = 4; + + int8_t res = canDriverTransmit(&frame, CAN_DRIVER_SECOND); + health = (res > 0) ? Status::OK : Status::MINOR_FAILURE; +} diff --git a/Src/modules/canopen/canopen.hpp b/Src/modules/canopen/canopen.hpp new file mode 100644 index 0000000..ec12102 --- /dev/null +++ b/Src/modules/canopen/canopen.hpp @@ -0,0 +1,29 @@ +/** + * This program is free software under the GNU General Public License v3. + * See for details. + * Author: Dmitry Ponomarev + */ + +#ifndef SRC_MODULES_CANOPEN_HPP_ +#define SRC_MODULES_CANOPEN_HPP_ + +#include "module.hpp" + +#ifdef __cplusplus +extern "C" { +#endif + +class CanopenModule : public Module { +public: + CanopenModule() : Module(10.0) {} + void init() override; + +protected: + void spin_once() override; +}; + +#ifdef __cplusplus +} +#endif + +#endif // SRC_MODULES_CANOPEN_HPP_