Guest User

Untitled

a guest
Mar 30th, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. void ChtEgtWorker::doWork()
  2. {
  3.     //qDebug() << Q_FUNC_INFO << " on thread: " << QThread::currentThread();
  4.     QMutexLocker locker(m_mutex);
  5.  
  6.     // This prints...
  7.     qDebug() << "FOO1";
  8.  
  9.     const size_t COUNT = 2;
  10.  
  11.     // drefs =
  12.     //      "sim/cockpit2/engine/indicators/CHT_CYL_deg_cel",
  13.     //      "sim/cockpit2/engine/indicators/EGT_CYL_deg_cel"
  14.     const char* drefs[COUNT] = { DATAREFS::CHT_ALL_CYLS , DATAREFS::EGT_ALL_CYLS };
  15.  
  16.     // This prints...
  17.     qDebug() << "FOO2";
  18.  
  19.     float* chtEgtValues[COUNT];
  20.  
  21.     // For each row in the array, we need 4 * 4 = 16 bytes
  22.     chtEgtValues[0] = (float*)(malloc(4 * sizeof(float)));  // cht values
  23.     chtEgtValues[1] = (float*)(malloc(4 * sizeof(float)));  // egt values
  24.  
  25.     // This prints...
  26.     qDebug() << "FOO3";
  27.  
  28.     // Allocated size of each element in the egtValues array
  29.     int sizes[COUNT] = { 4, 4 };
  30.  
  31.  
  32.     if (getDREFs(m_socket, drefs, chtEgtValues, COUNT, sizes) < 0)
  33.     {
  34.         qDebug() << "An error occurred";
  35.         return;
  36.     }
  37.     // This DOES NOT print: We get an invalid pointer error (munmap_chunk(): invalid pointer)
  38.     qDebug() << "FOO4";
  39.  
  40.     float cht1 = chtEgtValues[0][0];
  41.     float cht1F = convertCtoF(cht1);
  42.     float mappedCht1F = mapValueToNewRange(cht1F, 0, 500, 0, 90);
  43.     m_engine->setChtCyl1(static_cast<int>(mappedCht1F));
  44.     qDebug() << "cht1: " << cht1;
  45.     qDebug() << "cht1F: " << cht1F;
  46.     //qDebug() << "mappedCht1F: " << mappedCht1F;
  47.  
  48.     float cht2 = chtEgtValues[0][1];
  49.     float cht2F = convertCtoF(cht2);
  50.     float mappedCht2F = mapValueToNewRange(cht2F, 0, 500, 0, 90);
  51.     m_engine->setChtCyl2(static_cast<int>(mappedCht2F));
  52.     qDebug() << "cht2F: " << cht2F;
  53.  
  54.     float cht3 = chtEgtValues[0][2];
  55.     float cht3F = convertCtoF(cht3);
  56.     float mappedCht3F = mapValueToNewRange(cht3F, 0, 500, 0, 90);
  57.     m_engine->setChtCyl3(static_cast<int>(mappedCht3F));
  58.     qDebug() << "cht3F: " << cht3F;
  59.  
  60.     float cht4 = chtEgtValues[0][3];
  61.     float cht4F = convertCtoF(cht4);
  62.     float mappedCht4F = mapValueToNewRange(cht4F, 0, 500, 0, 90);
  63.     m_engine->setChtCyl4(static_cast<int>(mappedCht4F));
  64.     qDebug() << "cht4F: " << cht4F;
  65.  
  66.     float egt1 = chtEgtValues[1][0];
  67.     float egt1F = convertCtoF(egt1);
  68.     float mappedEgt1F = mapValueToNewRange(egt1F, 0, 1600, 0, 90);
  69.     m_engine->setEgtCyl1(static_cast<int>(mappedEgt1F));
  70.     qDebug() << "egt1: " << egt1;
  71.     qDebug() << "egt1F: " << egt1F;
  72.     //qDebug() << "mappedEgt1F: " << mappedEgt1F;
  73.  
  74.     float egt2 = chtEgtValues[1][1];
  75.     float egt2F = convertCtoF(egt2);
  76.     float mappedEgt2F = mapValueToNewRange(egt2F, 0, 1600, 0, 90);
  77.     m_engine->setEgtCyl2(static_cast<int>(mappedEgt2F));
  78.     qDebug() << "egt2F: " << egt2F;
  79.  
  80.     float egt3 = chtEgtValues[1][2];
  81.     float egt3F = convertCtoF(egt3);
  82.     float mappedEgt3F = mapValueToNewRange(egt3F, 0, 1600, 0, 90);
  83.     m_engine->setEgtCyl3(static_cast<int>(mappedEgt3F));
  84.     qDebug() << "egt3F: " << egt3F;
  85.  
  86.     float egt4 = chtEgtValues[1][3];
  87.     float egt4F = convertCtoF(egt4);
  88.     float mappedEgt4F = mapValueToNewRange(egt4F, 0, 1600, 0, 90);
  89.     m_engine->setEgtCyl4(static_cast<int>(mappedEgt4F));
  90.     qDebug() << "egt4F: " << egt4F;
  91.  
  92.     for (size_t i = 0; i < COUNT; i++)
  93.     {
  94.         delete [] chtEgtValues[i];
  95.     }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment