MCPcopy Create free account
hub / github.com/CANopenNode/CANopenNode / OD_getSub

Function OD_getSub

301/CO_ODinterface.c:176–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176ODR_t
177OD_getSub(const OD_entry_t* entry, uint8_t subIndex, OD_IO_t* io, bool_t odOrig) {
178 if ((entry == NULL) || (entry->odObject == NULL)) {
179 return ODR_IDX_NOT_EXIST;
180 }
181 if (io == NULL) {
182 return ODR_DEV_INCOMPAT;
183 }
184
185 ODR_t ret = ODR_OK;
186 OD_stream_t* stream = &io->stream;
187
188 /* attribute, dataOrig and dataLength, depends on object type */
189 switch (entry->odObjectType & (uint8_t)ODT_TYPE_MASK) {
190 case ODT_VAR: {
191 if (subIndex > 0U) {
192 ret = ODR_SUB_NOT_EXIST;
193 break;
194 }
195 CO_PROGMEM OD_obj_var_t* odo = entry->odObject;
196
197 stream->attribute = odo->attribute;
198 stream->dataOrig = odo->dataOrig;
199 stream->dataLength = odo->dataLength;
200 break;
201 }
202 case ODT_ARR: {
203 if (subIndex >= entry->subEntriesCount) {
204 ret = ODR_SUB_NOT_EXIST;
205 break;
206 }
207 CO_PROGMEM OD_obj_array_t* odo = entry->odObject;
208
209 if (subIndex == 0U) {
210 stream->attribute = odo->attribute0;
211 stream->dataOrig = odo->dataOrig0;
212 stream->dataLength = 1;
213 } else {
214 stream->attribute = odo->attribute;
215 uint8_t* ptr = odo->dataOrig;
216 stream->dataOrig = (ptr == NULL) ? ptr : (ptr + (odo->dataElementSizeof * (uint8_t)(subIndex - 1U)));
217 stream->dataLength = odo->dataElementLength;
218 }
219 break;
220 }
221 case ODT_REC: {
222 CO_PROGMEM OD_obj_record_t* odoArr = entry->odObject;
223 CO_PROGMEM OD_obj_record_t* odo = NULL;
224 for (uint8_t i = 0; i < entry->subEntriesCount; i++) {
225 if (odoArr[i].subIndex == subIndex) {
226 odo = &odoArr[i];
227 break;
228 }
229 }
230 if (odo == NULL) {
231 ret = ODR_SUB_NOT_EXIST;
232 break;
233 }

Callers 9

CO_SRDOGuard_initFunction · 0.85
CO_SRDO_configFunction · 0.85
CO_SDOserver_processFunction · 0.85
CO_PDO.cFile · 0.85
PDO_initMappingFunction · 0.85
OD_get_valueFunction · 0.85
OD_set_valueFunction · 0.85
OD_getPtrFunction · 0.85
ifFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected