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

Function OD_readOriginal

301/CO_ODinterface.c:24–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#include "301/CO_ODinterface.h"
23
24ODR_t
25OD_readOriginal(OD_stream_t* stream, void* buf, OD_size_t count, OD_size_t* countRead) {
26 if ((stream == NULL) || (buf == NULL) || (countRead == NULL)) {
27 return ODR_DEV_INCOMPAT;
28 }
29
30 OD_size_t dataLenToCopy = stream->dataLength; /* length of OD variable */
31 const uint8_t* dataOrig = stream->dataOrig;
32
33 if (dataOrig == NULL) {
34 return ODR_SUB_NOT_EXIST;
35 }
36
37 ODR_t returnCode = ODR_OK;
38
39 /* If previous read was partial or OD variable length is larger than
40 * current buffer size, then data was (will be) read in several segments */
41 if ((stream->dataOffset > 0U) || (dataLenToCopy > count)) {
42 if (stream->dataOffset >= dataLenToCopy) {
43 return ODR_DEV_INCOMPAT;
44 }
45 /* Reduce for already copied data */
46 dataLenToCopy -= stream->dataOffset;
47 dataOrig += stream->dataOffset;
48
49 if (dataLenToCopy > count) {
50 /* Not enough space in destination buffer */
51 dataLenToCopy = count;
52 stream->dataOffset += dataLenToCopy;
53 returnCode = ODR_PARTIAL;
54 } else {
55 stream->dataOffset = 0; /* copy finished, reset offset */
56 }
57 }
58
59 (void)memcpy((void*)buf, (const void*)dataOrig, dataLenToCopy);
60
61 *countRead = dataLenToCopy;
62 return returnCode;
63}
64
65ODR_t
66OD_writeOriginal(OD_stream_t* stream, const void* buf, OD_size_t count, OD_size_t* countWritten) {

Callers 3

OD_not_write_same_valueFunction · 0.85
OD_read_PDO_commParamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected