1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
float myData;
std::array<QString,25> Inputs{"real","double","double","double","double","double","double","double","double","double"
,"real","real","real","real","real","real","real","real","double","double","boolean","double"
,"uint32","boolean","boolean"};
QByteArray payloadupload= QByteArray::fromHex("F504");
QByteArray payloadupload8byte= QByteArray::fromHex("F508");
QByteArray Testsend= QByteArray::fromHex("FF"); // réponse static
QByteArray payloadrpm= QByteArray::fromHex("F600000000180010"); // Rpm @
QString ID = "101";
const uint frameId = ID.toUInt(nullptr, 16);
QCanBusFrame firstframetosend;
QCanBusFrame frameupload;
QCanBusDevice *device = QCanBus::instance()->createDevice(
QStringLiteral("socketcan"), QStringLiteral("can0"));
if(device->connectDevice()){ //changer avant la validation
//Récuperation de Rpm
//Envoie de l'@ Rpm
firstframetosend.setFrameId(frameId);
firstframetosend.setPayload(payloadrpm);
device->writeFrame(firstframetosend);
// fin @Rpm
device->waitForFramesReceived(3000);
QCanBusFrame rpmreponse= device->readFrame();
QByteArray Testreponse = rpmreponse.payload();
if(Testreponse==Testsend){ //test de la reponse
for(size_t i=0;i<Inputs.size();i++){
//Envoie de la commande upload
qDebug() << "Input type" << Inputs[i];
if(Inputs[i]=="double") {
frameupload.setFrameId(frameId);
frameupload.setPayload(payloadupload8byte);
qDebug() << "type is double : upload commande is" << payloadupload8byte;
device->writeFrame(frameupload);
}
else{
frameupload.setFrameId(frameId);
frameupload.setPayload(payloadupload);
qDebug() << "type is not double : upload commande is" << payloadupload;
device->writeFrame(frameupload);
}
// fin de la commande upload
device->waitForFramesReceived(3000);
QCanBusFrame framereceived = device->readFrame(); // Reception 1ére données
QByteArray data = QByteArray::fromHex(framereceived.payload());
qDebug() << QByteArray::fromHex(framereceived.payload()) << " Data Data&size" << QByteArray::fromHex(framereceived.payload()).size();
// QByteArray data = QByteArray::fromHex("FF42480000");
QDataStream stream(data);
qDebug() << data.size() << " Data Data&size" ;
if (data.size()== 5){
stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
}else {
stream.setFloatingPointPrecision(QDataStream::DoublePrecision);
}
quint8 byte;
stream >> byte; // skip first byte
stream >> myData; // read data
qDebug() << "this is data"<< myData ;
QString DatatoString =QString::number(myData);
Outputs[i]=DatatoString;
qDebug() << "In outputs data" << Outputs[i];
//fin récuperation
}
m_Valuespeed=Outputs[0].toDouble();
m_ValueId=Outputs[1].toFloat();
m_ValueIQ=Outputs[2].toFloat();
m_ValueIdRef=Outputs[3].toFloat();
m_ValueIQRef=Outputs[4].toFloat();
m_ValueVD=Outputs[5].toFloat();
m_ValueVQ=Outputs[6].toFloat();
m_ValueVDRef=Outputs[7].toFloat();
m_ValueVQRef=Outputs[8].toFloat();
m_valueDCvolt=Outputs[9].toFloat();
m_ValueCPU1=Outputs[10].toFloat();
m_ValueCPU2=Outputs[11].toFloat();
m_ValueCPU3=Outputs[12].toFloat();
m_ValueCPU4=Outputs[13].toFloat();
m_ValueCPU5=Outputs[14].toFloat();
m_ValueCPU6=Outputs[15].toFloat();
m_ValueCPU7=Outputs[16].toFloat();
m_ValueCPU8=Outputs[17].toFloat();
m_ValueTorque=Outputs[18].toFloat();
m_ValueTorqueMax=Outputs[19].toFloat();
m_directiontext=Outputs[20];
m_motiontext=Outputs[21];
m_nbrevoltext=Outputs[22];
m_degradedtext=Outputs[23];
m_dischtext=Outputs[24];
}
}
}
| |