load capi
This commit is contained in:
+102
-1
@@ -3,6 +3,104 @@
|
||||
#include <QLibrary>
|
||||
#include <QHostAddress>
|
||||
|
||||
|
||||
void MainWindow::setup_param(const QVector<QString> &head, const QVector<double> &onecase)
|
||||
{
|
||||
const rtwCAPI_ModelMappingStaticInfo *sm = (*getmap_func)();
|
||||
if (sm)
|
||||
{
|
||||
//unsigned int n = rtwCAPI_GetNumBlockParametersFromStaticMap(sm);
|
||||
unsigned int m = rtwCAPI_GetNumModelParametersFromStaticMap(sm);
|
||||
rtwCAPI_ModelParameters const *prm = rtwCAPI_GetModelParametersFromStaticMap(sm);
|
||||
rtwCAPI_DataTypeMap const *dtm = rtwCAPI_GetDataTypeMapFromStaticMap(sm);
|
||||
rtwCAPI_DimensionMap const *dmm = rtwCAPI_GetDimensionMapFromStaticMap(sm);
|
||||
uint_T const *dam = rtwCAPI_GetDimensionArrayFromStaticMap(sm);
|
||||
rtwCAPI_ModelMappingInfo *MMI = &(rtmGetDataMapInfo(this->m).mmi);
|
||||
void **da = rtwCAPI_GetDataAddressMap(MMI);
|
||||
for (unsigned int i = 0; i < m; ++i)
|
||||
{
|
||||
const char *name = rtwCAPI_GetModelParameterName(prm, i);
|
||||
int idx = rtwCAPI_GetModelParameterAddrIdx(prm, i);
|
||||
uint16_t dti = rtwCAPI_GetModelParameterDataTypeIdx(prm, i);
|
||||
uint16_t dmi = rtwCAPI_GetModelParameterDimensionIdx(prm, i);
|
||||
uint8_t ss = rtwCAPI_GetDataTypeSLId(dtm, dti);
|
||||
uint16_t dai = rtwCAPI_GetDimArrayIndex(dmm, dmi);
|
||||
uint8_t nd = rtwCAPI_GetNumDims(dmm, dmi);
|
||||
uint16_t n = 1;
|
||||
for (int j = 0; j < nd; ++j)
|
||||
{
|
||||
n *= dam[dai + j];
|
||||
}
|
||||
int j = 0;
|
||||
for (auto i = head.begin(); i != head.end(); ++i, ++j)
|
||||
{
|
||||
if (i->contains(name))
|
||||
{
|
||||
int target_idx = 0;
|
||||
double target_value = onecase[j];
|
||||
QStringList s = i->split(QRegExp("[()]"));
|
||||
if (s.size() >= 2)
|
||||
{
|
||||
target_idx = s.value(1).toInt() - 1;
|
||||
}
|
||||
switch (ss)
|
||||
{
|
||||
case SS_DOUBLE:
|
||||
{
|
||||
double *d = (double *)da[idx];
|
||||
d[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
case SS_SINGLE:
|
||||
{
|
||||
float *s = (float *)da[idx];
|
||||
s[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
case SS_INT8:
|
||||
{
|
||||
int8_T *c = (int8_T *)da[idx];
|
||||
c[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
case SS_INT16:
|
||||
{
|
||||
int16_T *h = (int16_T *)da[idx];
|
||||
h[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
case SS_INT32:
|
||||
{
|
||||
int32_T *I = (int32_T *)da[idx];
|
||||
I[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
case SS_UINT8:
|
||||
{
|
||||
uint8_T *c = (uint8_T *)da[idx];
|
||||
c[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
case SS_UINT16:
|
||||
{
|
||||
uint16_T *h = (uint16_T *)da[idx];
|
||||
h[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
case SS_UINT32:
|
||||
{
|
||||
uint32_T *I = (uint32_T *)da[idx];
|
||||
I[target_idx] = target_value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow)
|
||||
{
|
||||
@@ -13,18 +111,21 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
{
|
||||
init_func = static_cast<SIL_initialize_ptr>(mdl->resolve("SIL_initialize"));
|
||||
step_func = static_cast<SIL_step_ptr>(mdl->resolve("SIL_step"));
|
||||
getmap_func = (SIL_GetCAPIStaticMap_ptr)(mdl->resolve("SIL_GetCAPIStaticMap"));
|
||||
u = (ExtU_SIL_T *)mdl->resolve("SIL_U");
|
||||
y = (ExtY_SIL_T *)mdl->resolve("SIL_Y");
|
||||
m = (RT_MODEL_SIL_T *)mdl->resolve("SIL_M_");
|
||||
}
|
||||
else
|
||||
{
|
||||
init_func = &SIL_initialize;
|
||||
step_func = &SIL_step;
|
||||
getmap_func = &SIL_GetCAPIStaticMap;
|
||||
u = &SIL_U;
|
||||
y = &SIL_Y;
|
||||
}
|
||||
|
||||
if (init_func && step_func && u && y)
|
||||
if (init_func && step_func && u && y && getmap_func)
|
||||
{
|
||||
qgc_sock = new QUdpSocket(this);
|
||||
if (qgc_sock->bind(QHostAddress::LocalHost, 6061))
|
||||
|
||||
@@ -6,6 +6,7 @@ extern "C"
|
||||
#include "SIL.h"
|
||||
typedef void (*SIL_initialize_ptr)(void);
|
||||
typedef void (*SIL_step_ptr)(void);
|
||||
typedef const rtwCAPI_ModelMappingStaticInfo *(*SIL_GetCAPIStaticMap_ptr)(void);
|
||||
}
|
||||
|
||||
#include <QMainWindow>
|
||||
@@ -37,8 +38,12 @@ private:
|
||||
|
||||
SIL_initialize_ptr init_func;
|
||||
SIL_step_ptr step_func;
|
||||
SIL_GetCAPIStaticMap_ptr getmap_func;
|
||||
ExtU_SIL_T *u;
|
||||
ExtY_SIL_T *y;
|
||||
RT_MODEL_SIL_T *m;
|
||||
|
||||
void setup_param(const QVector<QString> &head, const QVector<double> &onecase);
|
||||
|
||||
uint8_t seq;
|
||||
|
||||
|
||||
+105
-61
@@ -1,65 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>311</width>
|
||||
<height>187</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Proj41 HIL</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,1">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Latitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEditLat"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Longitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEditLon"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>altitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEditAlt"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>heading</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEditHdg"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Proj41 HIL</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>100</x>
|
||||
<y>100</y>
|
||||
<width>200</width>
|
||||
<height>100</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fire</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButton</sender>
|
||||
<signal>pressed()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>onFire()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>155</x>
|
||||
<y>153</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>255</x>
|
||||
<y>181</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>onFire()</slot>
|
||||
</slots>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>311</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButton</sender>
|
||||
<signal>pressed()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>onFire()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>155</x>
|
||||
<y>153</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>255</x>
|
||||
<y>181</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>onFire()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user