-
Notifications
You must be signed in to change notification settings - Fork 1
FWT-146 Start Drinking On (SDO) company time #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 28 commits
dfad85a
35424c8
dd1dd90
c00d790
fbeb922
4451a8b
ae64dc7
028f030
9169c95
4c750e4
580dbfa
fff86b4
ffc8495
f85675a
6319675
9301881
8a9b880
53d5b88
ff17043
359df66
0563097
7ee46da
92d8cc7
df47e01
a651e26
f4aca03
83b893b
0c37b58
d4f9389
04e4cfd
ff7c199
ad442dc
221c07c
ea7e8b2
3587bce
59806c1
9cf8008
d0dc51b
5c1b840
9532b47
0a003be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| add_subdirectory(canopen_rpdo) | ||
| add_subdirectory(canopen_sample) | ||
| add_subdirectory(canopen_sdo) | ||
| add_subdirectory(canopen_tpdo) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| include(../../../cmake/evt-core_build.cmake) | ||
|
|
||
| set( SAMPLE_SOURCES main.cpp SDOCanNode.cpp) | ||
| make_exe(canopen_sdo "${SAMPLE_SOURCES}") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #include "SDOCanNode.hpp" | ||
| #include <core/io/CANopen.hpp> | ||
| #include <cstdio> | ||
|
|
||
| SDOCanNode::SDOCanNode(CO_NODE& canNode) : node(canNode) { | ||
| sampleDataA = 0; | ||
| sampleDataB = 0; | ||
| transferBuffArray[0] = 0; | ||
| transferBuffArray[1] = 0; | ||
DiegoLHendrix marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void SDOCanNode::transferData() { | ||
| /* Increment the first element of transferBuffArray by 1. */ | ||
| transferBuffArray[0]++; | ||
| /* Set the second element of transferBuffArray to twice the new value of the first element. */ | ||
| transferBuffArray[1] = transferBuffArray[0] * 2; | ||
|
|
||
| /* | ||
| * Initiates an SDO transfer for the specified node using the provided | ||
| * transfer buffer array. Targets the object dictionary entry at index 0x2100, | ||
| * sub-index 0x02. Registers and executes the SDOTransferCallback function upon completion. | ||
DiegoLHendrix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| CO_ERR err = core::io::SDOTransfer(node, transferBuffArray, 2, CO_DEV(0x2100, 0x02)); | ||
|
|
||
| /* Check if the SDO transfer was successfully started. */ | ||
| if (err == CO_ERR_NONE) { | ||
| /* Transfer is started successfully */ | ||
| log::LOGGER.log(log::Logger::LogLevel::INFO, "SDOTransfer Sent Request"); | ||
|
|
||
| /* Note: don't use the 'readValue' until transfer is finished! */ | ||
DiegoLHendrix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| /* Unable to start the SDO transfer */ | ||
| log::LOGGER.log(log::Logger::LogLevel::ERROR, "SDOTransfer Request Error"); | ||
| } | ||
| } | ||
|
|
||
| void SDOCanNode::receiveData() { | ||
| static uint8_t receiveBuffArray[1]; | ||
DiegoLHendrix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /* | ||
| * Initiates an SDO receive operation for the specified node, reading data into | ||
| * the provided receive buffer array. Targets the object dictionary entry at | ||
| * index 0x2100, sub-index 0x01. Registers and executes the SDOReceiveCallback function upon completion. | ||
| */ | ||
| CO_ERR err = core::io::SDOReceive(node, receiveBuffArray, 1, CO_DEV(0x2100, 0x01)); | ||
|
|
||
| /* Check if the SDO receive operation was successfully started. */ | ||
| if (err == CO_ERR_NONE) { | ||
| /* Transfer is started successfully */ | ||
| log::LOGGER.log(log::Logger::LogLevel::INFO, "SDOReceive Sent Request"); | ||
|
|
||
| /* Note: don't use the 'readValue' until transfer is finished! */ | ||
DiegoLHendrix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| /* Unable to start the SDO transfer */ | ||
| log::LOGGER.log(log::Logger::LogLevel::ERROR, "SDOReceive Request Error"); | ||
| } | ||
| } | ||
|
|
||
| CO_OBJ_T* SDOCanNode::getObjectDictionary() { | ||
| return &objectDictionary[0]; | ||
| } | ||
|
|
||
| uint8_t SDOCanNode::getNumElements() { | ||
| return OBJECT_DICTIONARY_SIZE; | ||
| } | ||
|
|
||
| uint8_t SDOCanNode::getNodeID() { | ||
| return NODE_ID; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #include <core/utils/log.hpp> | ||
DiegoLHendrix marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <cstdint> | ||
|
|
||
| #include <co_core.h> | ||
| #include <core/io/CANDevice.hpp> | ||
| #include <core/io/CANOpenMacros.hpp> | ||
|
|
||
| /** | ||
| * Representation of the CAN node. Handles constructing the object | ||
| * dictionary and other baseline settings. The idea is that each "board" | ||
| * will have a specific object dictionary associated with it. The object | ||
| * dictionary itself will also need to have information on "data of interest". | ||
| * For example, a temperature management system may to expose water pump | ||
| * flow rate in the object dictionary. | ||
| */ | ||
|
|
||
| namespace log = core::log; | ||
|
|
||
| class SDOCanNode : public CANDevice { | ||
DiegoLHendrix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public: | ||
| SDOCanNode(CO_NODE& canNode); | ||
|
|
||
| /** | ||
| * Update Object Dictionary entry | ||
| * | ||
| * @param node[in] The canopen node to write to | ||
| */ | ||
| void transferData(); | ||
|
|
||
| /** | ||
| * Read Object Dictionary entry | ||
| * | ||
| * @param node[in] The canopen node to read from | ||
| */ | ||
| void receiveData(); | ||
|
|
||
| /** | ||
| * Get a pointer to the start of the object dictionary | ||
| * | ||
| * @return Pointer to the start of the object dictionary | ||
| */ | ||
| CO_OBJ_T* getObjectDictionary() override; | ||
|
|
||
| /** | ||
| * Get the number of elements in the object dictionary. | ||
| * | ||
| * @return The number of elements in the object dictionary | ||
| */ | ||
| uint8_t getNumElements() override; | ||
|
|
||
| /** | ||
| * Get the device's node ID | ||
| * | ||
| * @return The node ID of the can device. | ||
| */ | ||
| uint8_t getNodeID() override; | ||
|
|
||
| /** | ||
| * Get the device's node ID | ||
| * | ||
| * @return The node ID of the can device. | ||
| */ | ||
| static constexpr uint8_t NODE_ID = 2; | ||
|
|
||
| private: | ||
| /** | ||
| * This sample data will be exposed over CAN through the object | ||
| * dictionary. The address of the variable will be included in the | ||
| * object dictionary and can be updated via SDO via a CANopen client. | ||
| * This device will then broadcast the value via a triggered PDO. | ||
| */ | ||
| uint8_t sampleDataA; | ||
| uint16_t sampleDataB; | ||
|
Comment on lines
+73
to
+74
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are not really using these values in your sample, are you able to use them for your transfer and receive somehow instead of a raw array? |
||
|
|
||
| uint8_t transferBuffArray[2]{}; | ||
DiegoLHendrix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| CO_NODE& node; | ||
|
|
||
| /** | ||
| * Have to know the size of the object dictionary for initialization | ||
| * process. | ||
| */ | ||
| static constexpr uint8_t OBJECT_DICTIONARY_SIZE = 24; | ||
|
|
||
| /** | ||
| * The object dictionary itself. Will be populated by this object during | ||
| * construction. | ||
| * | ||
| * The plus one is for the special "end of dictionary" marker. | ||
| */ | ||
| CO_OBJ_T objectDictionary[OBJECT_DICTIONARY_SIZE + 1] = { | ||
| MANDATORY_IDENTIFICATION_ENTRIES_1000_1014, | ||
| HEARTBEAT_PRODUCER_1017(2000), | ||
| IDENTITY_OBJECT_1018, | ||
| SDO_CONFIGURATION_1200, | ||
| SDO_CONFIGURATION_1280, | ||
|
|
||
| // User defined data, this will be where we put elements that can be | ||
| // accessed via SDO and depending on configuration PDO | ||
| DATA_LINK_START_KEY_21XX(0, 0x02), | ||
| DATA_LINK_21XX(0x00, 0x01, CO_TUNSIGNED8, &sampleDataA), | ||
| DATA_LINK_21XX(0x00, 0x02, CO_TUNSIGNED16, &sampleDataB), | ||
|
Comment on lines
+100
to
+104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you using these entries? |
||
|
|
||
| // End of dictionary marker | ||
| CO_OBJ_DICT_ENDMARK, | ||
| }; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.