feat: 添加命令行运行版本用于批量运行

update gencode
This commit is contained in:
matt
2021-02-27 12:57:31 +08:00
parent 55e0dca74b
commit d4495ecaff
15 changed files with 324 additions and 43 deletions
+11 -2
View File
@@ -24,7 +24,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# endif()
#endif()
find_package(Qt5 COMPONENTS Widgets Network REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets Network REQUIRED)
include_directories( SIL/work/SIL_ert_shrlib_rtw
SIL/work/slprj
@@ -150,12 +150,21 @@ else()
)
endif()
add_executable(kb3_batsil
mainc.cpp
task.h
task.cpp
${SIL_SRC}
)
target_link_libraries(kb3_batsil PRIVATE Qt5::Core)
target_link_libraries(kb3_sil PRIVATE Qt5::Widgets Qt5::Network)
include(GNUInstallDirs)
message("CMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR}")
install(TARGETS kb3_sil RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS kb3_sil kb3_batsil RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES SIL/work/SIL_win64.dll DESTINATION "${CMAKE_INSTALL_BINDIR}")
set(CPACK_GENERATOR ZIP)
+1 -1
View File
@@ -49,7 +49,7 @@ typedef struct rtwCAPI_ModelMappingStaticInfo_tag rtwCAPI_ModelMappingStaticInfo
struct rtwCAPI_ModelMappingStaticInfo_tag {
/* signals */
struct {
rtwCAPI_Signals const *signals; /* Signals Array */
rtwCAPI_Signals const *Signals; /* Signals Array */
uint_T numSignals; /* Num Signals */
rtwCAPI_Signals const *rootInputs; /* Root Inputs array */
uint_T numRootInputs; /* Num Root Inputs */
+6 -20
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
@@ -10208,7 +10208,6 @@ void SIL_step(void)
real32_T u0;
ENUM_operational_level2 tmp_2;
ENUM_auto_level3 tmp_3;
ENUM_mission_level4 tmp_4;
int32_T rtb_Product2_k0_tmp;
int32_T rtb_Product2_k0_tmp_0;
real32_T tan_elv3_tmp;
@@ -16262,7 +16261,7 @@ void SIL_step(void)
* UnitDelay: '<S628>/Unit Delay'
*/
rtb_BusAssignment = SIL_DW.CC;
rtb_BusAssignment.linked = false;
rtb_BusAssignment.linked = true;
rtb_BusAssignment.boot_time = SIL_DW.UnitDelay_DSTATE_gx;
rtb_BusAssignment.rc.connected = false;
rtb_BusAssignment.ccm_ch = 0U;
@@ -18935,25 +18934,11 @@ void SIL_step(void)
SIL_B.mission_mode;
SIL_B.BusAssignment_g.autocont = SIL_B.ac;
/* SwitchCase: '<S768>/Switch Case' */
s370_iter = SIL_DW.SwitchCase_ActiveSubsystem_gz;
/* Switch: '<S768>/Switch' incorporates:
* Constant: '<S768>/Constant'
* Constant: '<S768>/Constant2'
*/
if (SIL_P.force_sysauto_level) {
tmp_4 = ENUM_mission_level4_TAKEOFF;
} else {
tmp_4 = SIL_B.BusAssignment_g.level4_lgx;
}
/* End of Switch: '<S768>/Switch' */
/* SwitchCase: '<S768>/Switch Case' incorporates:
* Inport: '<S770>/C2_in'
*/
switch (tmp_4) {
s370_iter = SIL_DW.SwitchCase_ActiveSubsystem_gz;
switch (SIL_B.BusAssignment_g.level4_lgx) {
case ENUM_mission_level4_TAKEOFF:
SIL_DW.SwitchCase_ActiveSubsystem_gz = 0;
break;
@@ -19246,6 +19231,7 @@ void SIL_step(void)
break;
}
/* End of SwitchCase: '<S768>/Switch Case' */
/* End of Outputs for SubSystem: '<S762>/mission' */
break;
}
+2 -3
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
@@ -2568,7 +2568,6 @@ struct P_SIL_T_ {
* '<S750>/Constant1'
* '<S756>/Constant2'
* '<S762>/Constant2'
* '<S768>/Constant2'
*/
boolean_T use_ext_ins; /* Variable: use_ext_ins
* Referenced by: '<S2>/Constant2'
+6 -6
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
@@ -596,10 +596,10 @@ static rtwCAPI_ModelMappingStaticInfo mmiStatic = {
rtElementMap, rtSampleTimeMap, rtDimensionArray },
"float",
{ 3697272899U,
839490183U,
2694341262U,
2171168554U },
{ 2143802087U,
183506615U,
1113919586U,
4200277077U },
(NULL), 0,
0
};
+2 -2
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
+2 -3
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
@@ -660,7 +660,6 @@ P_SIL_T SIL_P = {
* '<S750>/Constant1'
* '<S756>/Constant2'
* '<S762>/Constant2'
* '<S768>/Constant2'
*/
1,
+2 -2
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
+2 -2
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
Binary file not shown.
+2 -2
View File
@@ -3,9 +3,9 @@
*
* Code generated for Simulink model 'SIL'.
*
* Model version : 1.607
* Model version : 1.609
* Simulink Coder version : 9.0 (R2018b) 24-May-2018
* C/C++ source code generated on : Fri Feb 26 21:06:18 2021
* C/C++ source code generated on : Sat Feb 27 10:13:12 2021
*
* Target selection: ert_shrlib.tlc
* Embedded hardware selection: Intel->x86-64 (Windows64)
Binary file not shown.
+47
View File
@@ -0,0 +1,47 @@
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QTimer>
#include "task.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("batsil");
QCoreApplication::setApplicationVersion("1.0");
QCommandLineParser parser;
parser.setApplicationDescription("Batch SIL App");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("param", "parameter file.");
// An option with a value
QCommandLineOption idxOption(QStringList() << "i" << "idx",
"index in file.", "idx","1");
parser.addOption(idxOption);
// Process the actual command line arguments given by the user
parser.process(a);
const QStringList args = parser.positionalArguments();
QString fn;
if (args.count() > 0)
{
fn = args.at(0);
}
int idx = parser.value(idxOption).toInt();
// Task parented to the application so that it
// will be deleted by the application.
Task *task = new Task(&a, fn, idx);
// This will cause the application to exit when
// the task signals finished.
QObject::connect(task, SIGNAL(finished()), &a, SLOT(quit()));
// This will run the task from the application event loop.
QTimer::singleShot(0, task, SLOT(run()));
return a.exec();
}
+197
View File
@@ -0,0 +1,197 @@
#include "task.h"
#include <qlogging.h>
#include <QLibrary>
#include <QDateTime>
#include <QTextStream>
extern "C"{
#include "SIL_capi.h"
}
void Task::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)
{
QStringList s = i->split(QRegExp("[()]"));
if (*i == name || ((s.size() >= 2) && (s.value(0) == name)))
{
int target_idx = 0;
double target_value = onecase[j];
if (s.size() >= 2)
{
target_idx = s.value(1).toInt();
}
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;
}
}
}
}
}
}
Task::Task(QObject *parent, QString fn, int index) : QObject(parent),filename(fn),idx(index)
{
if (idx < 1)
{
idx = 1;
}
}
void Task::run()
{
QLibrary *mdl = new QLibrary("SIL_win64.dll");
if (mdl->isLoaded())
{
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;
m = (RT_MODEL_SIL_T *)SIL_M;
}
if (init_func && step_func && u && y && getmap_func)
{
SIL_InitializeDataMapInfo();
QFile data(filename);
if (data.open(QFile::ReadOnly)) {
QVector<QString> head;
QVector<double> onecase;
QTextStream stream(&data);
QString line;
while (stream.readLineInto(&line)) {
QStringList items = line.split(QString(","));
head.push_back(items[0]);
onecase.push_back(items[idx].toDouble());
}
setup_param(head, onecase);
}
(*init_func)();
QString filename = QString("sil")
+QDateTime::currentDateTime().toString("yyyyMMddhhmmss")
+".DAT";
rec_file = new QFile(filename, this);
rec_file->open(QFile::WriteOnly);
u->launch_trigger = 0.0;
u->fault = 0x0;
uint8_t seq_rec = 0;
int ticks = 0;
for (float t=0;;t+=0.005f)
{
u->data_len = 0u;
if (t > 30 && u->launch_trigger < 1)
{
u->launch_trigger = 1;
}
if (t > 35 && y->C2out.recovery > 1)
{
break;
}
for (int i = 0; i < 2; ++i)
{
(*step_func)();
}
if (y->rec_seq != seq_rec)
{
seq_rec = y->rec_seq;
rec_file->write((const char *)y->rec_buff, y->rec_len);
}
if (++ticks >= 1000)
{
qInfo("%.0f ", t);
ticks = 0;
}
}
}
emit finished();
}
+44
View File
@@ -0,0 +1,44 @@
#ifndef TASK_H
#define TASK_H
#include <QObject>
#include <QVector>
#include <QString>
#include <QFile>
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);
}
class Task : public QObject
{
Q_OBJECT
public:
explicit Task(QObject *parent, QString filename, int index=1);
protected:
void setup_param(const QVector<QString> &head, const QVector<double> &onecase);
QString filename;
int idx;
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;
QFile *rec_file;
public slots:
void run();
signals:
void finished();
};
#endif // TASK_H