| 91 | } |
| 92 | |
| 93 | CO_ReturnError_t |
| 94 | CO_nodeGuardingSlave_init(CO_nodeGuardingSlave_t* ngs, OD_entry_t* OD_100C_GuardTime, |
| 95 | OD_entry_t* OD_100D_LifeTimeFactor, CO_EM_t* em, uint16_t CANidNodeGuarding, |
| 96 | CO_CANmodule_t* CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t* CANdevTx, |
| 97 | uint16_t CANdevTxIdx, uint32_t* errInfo) { |
| 98 | CO_ReturnError_t ret = CO_ERROR_NO; |
| 99 | |
| 100 | /* verify arguments */ |
| 101 | if ((ngs == NULL) || (em == NULL) || (CANdevRx == NULL) || (CANdevTx == NULL) || (OD_100C_GuardTime == NULL) |
| 102 | || (OD_100D_LifeTimeFactor == NULL)) { |
| 103 | return CO_ERROR_ILLEGAL_ARGUMENT; |
| 104 | } |
| 105 | |
| 106 | /* clear the object */ |
| 107 | (void)memset(ngs, 0, sizeof(CO_nodeGuardingSlave_t)); |
| 108 | |
| 109 | /* Configure object variables */ |
| 110 | ngs->em = em; |
| 111 | |
| 112 | /* get and verify required "Guard time" from the Object Dictionary */ |
| 113 | uint16_t guardTime_ms; |
| 114 | ODR_t odRet = OD_get_u16(OD_100C_GuardTime, 0, &guardTime_ms, true); |
| 115 | if (odRet != ODR_OK) { |
| 116 | if (errInfo != NULL) { |
| 117 | *errInfo = OD_getIndex(OD_100C_GuardTime); |
| 118 | } |
| 119 | return CO_ERROR_OD_PARAMETERS; |
| 120 | } |
| 121 | ngs->guardTime_us = (uint32_t)guardTime_ms * 1000U; |
| 122 | |
| 123 | ngs->OD_100C_extension.object = ngs; |
| 124 | ngs->OD_100C_extension.read = OD_readOriginal; |
| 125 | ngs->OD_100C_extension.write = OD_write_100C; |
| 126 | odRet = OD_extension_init(OD_100C_GuardTime, &ngs->OD_100C_extension); |
| 127 | if (odRet != ODR_OK) { |
| 128 | if (errInfo != NULL) { |
| 129 | *errInfo = OD_getIndex(OD_100C_GuardTime); |
| 130 | } |
| 131 | return CO_ERROR_OD_PARAMETERS; |
| 132 | } |
| 133 | |
| 134 | /* get and verify required "Life time factor" from the Object Dictionary */ |
| 135 | uint8_t lifeTimeFactor; |
| 136 | odRet = OD_get_u8(OD_100D_LifeTimeFactor, 0, &lifeTimeFactor, true); |
| 137 | if (odRet != ODR_OK) { |
| 138 | if (errInfo != NULL) { |
| 139 | *errInfo = OD_getIndex(OD_100D_LifeTimeFactor); |
| 140 | } |
| 141 | return CO_ERROR_OD_PARAMETERS; |
| 142 | } |
| 143 | ngs->lifeTimeFactor = lifeTimeFactor; |
| 144 | ngs->lifeTime_us = ngs->guardTime_us * ngs->lifeTimeFactor; |
| 145 | |
| 146 | ngs->OD_100D_extension.object = ngs; |
| 147 | ngs->OD_100D_extension.read = OD_readOriginal; |
| 148 | ngs->OD_100D_extension.write = OD_write_100D; |
| 149 | odRet = OD_extension_init(OD_100D_LifeTimeFactor, &ngs->OD_100D_extension); |
| 150 | if (odRet != ODR_OK) { |
no test coverage detected