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

Function OD_write_1280

301/CO_SDOclient.c:155–211  ·  view source on GitHub ↗

* Custom function for writing OD object _SDO client parameter_ * * For more information see file CO_ODinterface.h, OD_IO_t. */

Source from the content-addressed store, hash-verified

153 * For more information see file CO_ODinterface.h, OD_IO_t.
154 */
155static ODR_t
156OD_write_1280(OD_stream_t* stream, const void* buf, OD_size_t count, OD_size_t* countWritten) {
157 /* "count" is already verified in *_init() function */
158 if ((stream == NULL) || (buf == NULL) || (countWritten == NULL)) {
159 return ODR_DEV_INCOMPAT;
160 }
161
162 CO_SDOclient_t* SDO_C = (CO_SDOclient_t*)stream->object;
163
164 switch (stream->subIndex) {
165 case 0: /* Highest sub-index supported */ return ODR_READONLY; break;
166
167 case 1: { /* COB-ID client -> server */
168 uint32_t COB_ID = CO_getUint32(buf);
169 uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
170 uint16_t CAN_ID_cur = (uint16_t)(SDO_C->COB_IDClientToServer & 0x7FFU);
171 bool_t valid = (COB_ID & 0x80000000U) == 0U;
172
173 /* SDO client must not be valid when changing COB_ID */
174 if (((COB_ID & 0x3FFFF800U) != 0U) || (valid && SDO_C->valid && (CAN_ID != CAN_ID_cur))
175 || (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))) {
176 return ODR_INVALID_VALUE;
177 }
178 (void)CO_SDOclient_setup(SDO_C, COB_ID, SDO_C->COB_IDServerToClient, SDO_C->nodeIDOfTheSDOServer);
179 break;
180 }
181
182 case 2: { /* COB-ID server -> client */
183 uint32_t COB_ID = CO_getUint32(buf);
184 uint16_t CAN_ID = (uint16_t)(COB_ID & 0x7FFU);
185 uint16_t CAN_ID_cur = (uint16_t)(SDO_C->COB_IDServerToClient & 0x7FFU);
186 bool_t valid = (COB_ID & 0x80000000U) == 0U;
187
188 /* SDO client must not be valid when changing COB_ID */
189 if (((COB_ID & 0x3FFFF800U) != 0U) || (valid && SDO_C->valid && (CAN_ID != CAN_ID_cur))
190 || (valid && CO_IS_RESTRICTED_CAN_ID(CAN_ID))) {
191 return ODR_INVALID_VALUE;
192 }
193 (void)CO_SDOclient_setup(SDO_C, SDO_C->COB_IDClientToServer, COB_ID, SDO_C->nodeIDOfTheSDOServer);
194 break;
195 }
196
197 case 3: { /* Node-ID of the SDO server */
198 uint8_t nodeId = CO_getUint8(buf);
199 if (nodeId > 127U) {
200 return ODR_INVALID_VALUE;
201 }
202 SDO_C->nodeIDOfTheSDOServer = nodeId;
203 break;
204 }
205
206 default: return ODR_SUB_NOT_EXIST; break;
207 }
208
209 /* write value to the original location in the Object Dictionary */
210 return OD_writeOriginal(stream, buf, count, countWritten);
211}
212#endif /* (CO_CONFIG_SDO_CLI) & CO_CONFIG_FLAG_OD_DYNAMIC */

Callers

nothing calls this directly

Calls 4

CO_getUint32Function · 0.85
CO_SDOclient_setupFunction · 0.85
CO_getUint8Function · 0.85
OD_writeOriginalFunction · 0.85

Tested by

no test coverage detected