Skip to content
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

FWT-146 Start Drinking On (SDO) company time #112

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

DiegoLHendrix
Copy link
Contributor

No description provided.

@DiegoLHendrix DiegoLHendrix changed the title Start Drinking On (SDO) company time FWT-146 Start Drinking On (SDO) company time Dec 5, 2024
Copy link
Contributor

@mjh9585 mjh9585 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few changes, mostly should make a method to register a callback that is used by the sdo.

Copy link
Contributor

@mjmagee991 mjmagee991 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good start

* @param node[in] The SDO node
* @param sampleDataArray[in] The value to set sample data to
*/
CO_ERR SDOTransfer(CO_NODE &node, uint8_t *data, uint8_t size, uint32_t entry);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjh9585 Do you think it's worth converting the error to a different type? That's what we do for the HAL and ThreadX

Comment on lines +113 to +135
{
/* Communication Object SDO Server */
.Key = CO_KEY(0x1280, 0x00, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED32,
.Data = (CO_DATA) 0x03,
},
{
/* SDO Server Request COBID */
.Key = CO_KEY(0x1280, 0x01, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED32,
.Data = (CO_DATA) CO_COBID_SDO_REQUEST(),
},
{
/* SDO Server Response COBID */
.Key = CO_KEY(0x1280, 0x02, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED32,
.Data = (CO_DATA) CO_COBID_SDO_RESPONSE(),
},
{
/* Node ID of Server */
.Key = CO_KEY(0x1280, 0x03, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED8,
.Data = (CO_DATA) 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have macros for these


while (1) {
if ((HAL_GetTick() - lastUpdate1) >= 1000) { // If 1000ms have passed receive CAN message.
testCanNode.receiveData(canNode); // Receive data from server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really do not like that you have to pass the CO_NODE in every time you call this function. I think it might be better to store the CO_NODE in SDOCanNode, but I'm not sure because you'd have to make a function to get a pointer to pass into io::processCANopenNode. @mjh9585 what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine as you still have to pass it into io::processCANopenNode and an extra method to access CO_NODE from SDOCanNode would make it harder to follow. Perhaps a better approach would be to pass a pointer to CO_NODE into the constructor instead.

Copy link
Contributor

@mjh9585 mjh9585 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of changes. Make sure to clean up leftover code from the unresolved comments.

uint8_t* data = message.getPayload();
for (int i = 0; i < message.getDataLength(); i++) {
uart.printf("%X ", *data);
log::LOGGER.log(log::Logger::LogLevel::INFO, "%X ", *data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of logging each byte, build a string of the data and print 1 log message.

*/
CO_CSDO* csdo = COCSdoFind(&(node), 0);

core::io::registerCallBack(AppCallback, reinterpret_cast<void*>(csdo)); // Register callback function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are registering a global callback you should probably not be registering it in this method.

void registerCallBack(void (*AppCallback)(CO_CSDO* csdo, uint16_t index, uint8_t sub, uint32_t code),
void* AppContext) {
callback = AppCallback;
context = AppContext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you passing this context into the callback? You need some other method to apply the context to your callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants