Commit a822ca23 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Ensure variable-length string as well-supported as SDO write server

parent 8a7680b7
......@@ -103,9 +103,13 @@ CanOpenSdoTransfer::CanOpenSdoTransfer (void)
{ }
void CanOpenSdoTransfer::createBuffer (const CanOpenDataLen len) {
buffer.clear ();
buffer.resize (int (len));
memset (buffer.data (), 0x00, len);
buffer = QByteArray (int (len), '\0');
}
void CanOpenSdoTransfer::adjustBuffer (const CanOpenDataLen len) {
if (buffer.size () != len) {
buffer = buffer.leftJustified (int (len), '\0', true);
}
}
/*** CAN OPEN SDO TRANSFERS QUEUE ***/
......
......@@ -655,6 +655,7 @@ struct QTCAN_CANOPEN_EXPORT CanOpenSdoTransfer {
QByteArray buffer;
void createBuffer (const CanOpenDataLen len);
void adjustBuffer (const CanOpenDataLen len);
};
class QTCAN_CANOPEN_EXPORT CanOpenSdoTransferQueue : public QObject {
......
This diff is collapsed.
......@@ -115,16 +115,16 @@ QVariant CanOpenSubEntry::readToQtVariant (void) const {
return QVariant::fromValue (double (* reinterpret_cast<double *> (m_dataPtr)));
}
case CanOpenDataTypes::VisibleStr: {
return QVariant::fromValue (QString::fromLatin1 (reinterpret_cast<char *> (m_dataPtr)).left (int (m_dataLen)));
return QVariant::fromValue (QString::fromLatin1 (reinterpret_cast<const char *> (m_dataPtr), int (m_dataLen)));
}
case CanOpenDataTypes::OctetStr: {
return QVariant::fromValue (QString::fromLocal8Bit (reinterpret_cast<char *> (m_dataPtr)).left (int (m_dataLen)));
return QVariant::fromValue (QString::fromLocal8Bit (reinterpret_cast<const char *> (m_dataPtr), int (m_dataLen)));
}
case CanOpenDataTypes::UnicodeStr: {
return QVariant::fromValue (QString::fromUtf8 (reinterpret_cast<char *> (m_dataPtr)).left (int (m_dataLen)));
return QVariant::fromValue (QString::fromUtf8 (reinterpret_cast<const char *> (m_dataPtr), int (m_dataLen)));
}
case CanOpenDataTypes::Domain: {
return QVariant::fromValue (QString::fromLatin1 (QByteArray (reinterpret_cast<char *> (m_dataPtr), int (m_dataLen)).toHex ()));
return QVariant::fromValue (QString::fromLatin1 (QByteArray (reinterpret_cast<const char *> (m_dataPtr), int (m_dataLen)).toHex ()));
}
case CanOpenDataTypes::Int24:
case CanOpenDataTypes::Int40:
......@@ -225,7 +225,7 @@ void CanOpenSubEntry::writeFromQtVariant (const QVariant & var) {
break;
}
case CanOpenDataTypes::Domain: {
const QByteArray tmp = QByteArray::fromHex (var.value<QString> ().toLatin1 ()).leftJustified (int (m_dataLen) * 2, '\0', true);
const QByteArray tmp = QByteArray::fromHex (var.value<QString> ().toLatin1 ()).leftJustified (int (m_dataLen) * 2, '0', true);
write (tmp.data (), quint (tmp.size ()));
break;
}
......
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