Skip to content

c-open: Fix cached status. Fix SDO 7B last packet. Add cb_notify event. #56

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions include/co_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,19 @@ typedef enum co_dtype
/** Access function event */
typedef enum od_event
{
OD_EVENT_READ, /**< Read subindex */
OD_EVENT_WRITE, /**< Write subindex */
OD_EVENT_RESTORE, /**< Restore default value */
OD_EVENT_READ, /**< Read subindex */
OD_EVENT_WRITE, /**< Write subindex */
OD_EVENT_RESTORE, /**< Restore default value */
} od_event_t;

/** Notify event */
typedef enum od_notify_event
{
OD_NOTIFY_ACCESSED,
OD_NOTIFY_VALUE_SET,
OD_NOTIFY_SDO_RECEIVED,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are both ACCESSED and VALUE_SET required? They are both called from co_od_set_value and it seems that the only difference is whether the user has specified that the object has an accessor function or not.

SDO_RECEIVED seems to be used when an object larger than 64 bits is being downloaded and will be called for every partial update with the size received so far. So the value in this case is a size. This should be documented. There should also be a test that verifies the functionality.

} od_notify_event_t;

struct co_obj;
struct co_entry;

Expand Down Expand Up @@ -317,7 +325,7 @@ typedef struct co_cfg
uint8_t msef[5]);

/** Notify callback */
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex);
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value);

/** Function to open dictionary store */
void * (*open) (co_store_t store, co_mode_t mode);
Expand Down
2 changes: 1 addition & 1 deletion src/co_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ struct co_net
uint8_t msef[5]);

/** Notify callback */
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex);
void (*cb_notify) (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value);

/** Function to open dictionary store */
void * (*open) (co_store_t store, co_mode_t mode);
Expand Down
12 changes: 7 additions & 5 deletions src/co_od.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ static int co_subindex_equals (
return entry->subindex == subindex;
}

static void co_od_notify (
void co_od_notify (
co_net_t * net,
const co_obj_t * obj,
const co_entry_t * entry,
uint8_t subindex)
uint8_t subindex,
od_notify_event_t event,
uint32_t value)
{
if (entry->flags & OD_NOTIFY)
{
if (net->cb_notify)
net->cb_notify (net, obj->index, subindex);
net->cb_notify (net, obj->index, subindex, event, value);
}
}

Expand Down Expand Up @@ -221,7 +223,7 @@ uint32_t co_od_set_value (
uint32_t v = value;

result = obj->access (net, OD_EVENT_WRITE, obj, entry, subindex, &v);
co_od_notify (net, obj, entry, subindex);
co_od_notify (net, obj, entry, subindex, OD_NOTIFY_ACCESSED, 0);
return result;
}

Expand Down Expand Up @@ -262,7 +264,7 @@ uint32_t co_od_set_value (
return CO_SDO_ABORT_GENERAL;
}

co_od_notify (net, obj, entry, subindex);
co_od_notify (net, obj, entry, subindex, OD_NOTIFY_VALUE_SET, 0);
return 0;
}

Expand Down
21 changes: 21 additions & 0 deletions src/co_od.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ uint32_t co_od_set_value (
uint8_t subindex,
uint64_t value);

/**
* Trigger notification callback
*
* This functions triggers the notification callback of the subindex,
* if any.
*
* @param net network handle
* @param obj object descriptor
* @param entry entry descriptor
* @param subindex subindex
* @param event event type
* @param value optional value
*/
void co_od_notify (
co_net_t * net,
const co_obj_t * obj,
const co_entry_t * entry,
uint8_t subindex,
od_notify_event_t event,
uint32_t value);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/mocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void cb_sync (co_net_t * net)
unsigned int cb_notify_calls;
uint16_t cb_notify_index;
uint16_t cb_notify_subindex;
void cb_notify (co_net_t * net, uint16_t index, uint8_t subindex)
void cb_notify (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value)
{
cb_notify_calls++;
cb_notify_index = index;
Expand Down
2 changes: 1 addition & 1 deletion test/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void cb_sync (co_net_t * net);
extern unsigned int cb_notify_calls;
extern uint16_t cb_notify_index;
extern uint16_t cb_notify_subindex;
void cb_notify (co_net_t * net, uint16_t index, uint8_t subindex);
void cb_notify (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value);

void store_init (void);
extern unsigned int store_open_calls;
Expand Down
1 change: 1 addition & 0 deletions test/test_sdo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ TEST_F (SdoServerTest, SegmentedDownload)
}

EXPECT_STREQ ("new slave name", name1009);
EXPECT_EQ (1u, cb_notify_calls);
}

TEST_F (SdoServerTest, SegmentedDownloadCached)
Expand Down
2 changes: 1 addition & 1 deletion test/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TestBase : public ::testing::Test

char name1009[20] = {0};
co_entry_t OD1009[1] = {
{0, OD_RW, DTYPE_VISIBLE_STRING, 8 * sizeof (name1009), 0, name1009},
{0, OD_NOTIFY | OD_RW, DTYPE_VISIBLE_STRING, 8 * sizeof (name1009), 0, name1009},
};

char name100A[20];
Expand Down
2 changes: 1 addition & 1 deletion util/slave/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void cb_sync (co_net_t * net)
}

/* Called when RPDO is received (if OD_NOTIFY is set) */
static void cb_notify (co_net_t * net, uint16_t index, uint8_t subindex)
static void cb_notify (co_net_t * net, uint16_t index, uint8_t subindex, od_notify_event_t event, uint32_t value)
{
}

Expand Down