-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a3cf9a
commit 1e7db63
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright (C) 2023 Dmitry Ponomarev <[email protected]> | ||
# Distributed under the terms of the GPL v3 license, available in the file LICENSE. | ||
|
||
list(APPEND APPLICATION_SOURCES | ||
${CMAKE_CURRENT_LIST_DIR}/canopen.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* This program is free software under the GNU General Public License v3. | ||
* See <https://www.gnu.org/licenses/> for details. | ||
* Author: Dmitry Ponomarev <[email protected]> | ||
*/ | ||
|
||
#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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* This program is free software under the GNU General Public License v3. | ||
* See <https://www.gnu.org/licenses/> for details. | ||
* Author: Dmitry Ponomarev <[email protected]> | ||
*/ | ||
|
||
#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_ |