Closed nattgris closed 2 years ago
Loading an enabled COB-ID fails the check that the PDO is disabled before updating the value. This check should be disabled in INIT state, as we do for the mapping parameters. Something like this:
diff --git a/src/co_pdo.c b/src/co_pdo.c
index 8be412e..582a5ce 100644
--- a/src/co_pdo.c
+++ b/src/co_pdo.c
@@ -184,7 +184,7 @@ static uint32_t co_pdo_comm_set (
{
if (!co_validate_cob_id (*value))
return CO_SDO_ABORT_VALUE;
- if (((pdo->cobid | *value) & CO_COBID_INVALID) == 0)
+ if (((pdo->cobid | *value) & CO_COBID_INVALID) == 0 && net->state != STATE_INIT)
return CO_SDO_ABORT_VALUE;
pdo->cobid = *value;
pdo->sync_counter = 0;
@@ -197,7 +197,7 @@ static uint32_t co_pdo_comm_set (
pdo->transmission_type = *value & 0xFF;
break;
case 3:
- if ((pdo->cobid & CO_COBID_INVALID) == 0)
+ if ((pdo->cobid & CO_COBID_INVALID) == 0 && net->state != STATE_INIT)
return CO_SDO_ABORT_VALUE;
pdo->inhibit_time = *value & 0xFFFF;
break;
@@ -207,7 +207,7 @@ static uint32_t co_pdo_comm_set (
case 6:
if (is_rx)
return CO_SDO_ABORT_BAD_SUBINDEX;
- if ((pdo->cobid & CO_COBID_INVALID) == 0)
+ if ((pdo->cobid & CO_COBID_INVALID) == 0 && net->state != STATE_INIT)
return CO_SDO_ABORT_VALUE;
pdo->sync_start = *value & 0xFF;
break;
Although this still doesn't help with the issue in #48?
No this is a separate but mildly related issue, which if it would work could be used as part of a workaround for that problem. But other things would still be needed for that workaround, such as a way of triggering a store parameters locally. I have performed another trick to get around the #48 for now.
Also, the application I'm working on doesn't have a need for customizing PDO COB-IDs, so this report is more of a heads-up and nothing I'm blocked by.
Ok, the above diff should fix this problem. I'll add a testcase also.
An updated CAN-ID for a PDO that is setup in the defaults array does not stick even if the communication parameters are stored. This can be demonstrated using the example slave, with the addition of a long delay before exiting main, and the following test script:
candump
shows the following output:The last line shows that the TPDO COB-ID reverted to the default after an NMT reset. However, the updated mapping was correctly remembered.