代码拉取完成,页面将自动刷新
#include "command.h"
Command::DataType Command::stringToDataType(const QString &dataTypeStr) const {
if (dataTypeStr == "uint" || dataTypeStr == "Uint" || dataTypeStr == "UINT") {
return UINT;
} else if (dataTypeStr == "int" || dataTypeStr == "Int" || dataTypeStr == "INT") {
return INT;
} else if (dataTypeStr == "float" || dataTypeStr == "Float" || dataTypeStr == "FLOAT") {
return FLOAT;
} else if (dataTypeStr == "bool" || dataTypeStr == "Bool" || dataTypeStr == "BOOL") {
return BOOL;
} else {
return UNKNOWN;
}
}
QByteArray Command::generateCommandBytes() {
QByteArray byteArray;
QDataStream stream(&byteArray, QDataStream::WriteOnly);
stream.setByteOrder(QDataStream::ByteOrder::LittleEndian);
// MagicNum
uint8_t magicNum = 0xAB;
stream << magicNum;
// ChunkNum
uint8_t chunkNum = 1;
stream << chunkNum;
// CMD number
stream << m_number;
// data
switch (m_dataType) {
case UINT: {
uint32_t value = m_data.toUInt();
stream << value;
break;
}
case INT: {
int32_t value = m_data.toInt();
stream << value;
break;
}
case FLOAT: {
float value = m_data.toFloat();
stream.writeRawData(reinterpret_cast<const char*>(&value), sizeof(float));
break;
}
case BOOL: {
uint32_t boolValue = m_data.toUInt() ? 1 : 0;
stream << boolValue;
break;
}
case UNKNOWN:
default:
qDebug() << "wrong data type: ";
// Handle unknown data type if necessary
break;
}
return byteArray;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。