Commit 2280fcb2 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Cleanup implementation of read/write in CanOpenSubEntry

(better support for different src/dst sizes)
parent 239153a7
......@@ -51,11 +51,9 @@ CanOpenAccessMode CanOpenSubEntry::getAttributes (void) const {
void CanOpenSubEntry::read (qvoidptr dstPtr, const quint dstSize) const {
if (dstPtr != Q_NULLPTR && m_dataPtr != Q_NULLPTR) {
qbyteptr dstBytes = qbyteptr (dstPtr);
const qbyteptr ownBytes = qbyteptr (m_dataPtr);
const quint ownSize = m_dataLen;
for (quint pos = 0; pos < dstSize && pos < ownSize; ++pos) {
dstBytes [pos] = ownBytes [pos];
for (quint pos = 0; pos < dstSize; ++pos) {
const qbyte byte = (pos < m_dataLen ? m_dataPtr [pos] : 0x00);
(qbyteptr (dstPtr)) [pos] = m_dataPtr [pos];
}
}
}
......@@ -63,16 +61,14 @@ void CanOpenSubEntry::read (qvoidptr dstPtr, const quint dstSize) const {
bool CanOpenSubEntry::write (const qvoidptr srcPtr, const quint srcSize) {
bool changed = false;
if (srcPtr != Q_NULLPTR && m_dataPtr != Q_NULLPTR) {
m_haveBeenWritten = true;
const qbyteptr srcBytes = qbyteptr (srcPtr);
qbyteptr ownBytes = qbyteptr (m_dataPtr);
const quint ownSize = m_dataLen;
for (quint pos = 0; pos < srcSize && pos < ownSize; ++pos) {
if (ownBytes [pos] != srcBytes [pos]) {
ownBytes [pos] = srcBytes [pos];
for (quint pos = 0; pos < m_dataLen; ++pos) {
const qbyte byte = (pos < srcSize ? (qbyteptr (srcPtr)) [pos] : 0x00);
if (m_dataPtr [pos] != byte) {
m_dataPtr [pos] = byte;
changed = true;
}
}
m_haveBeenWritten = true;
}
if (changed) {
emit dataChanged ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment