ttcreatetask.cpp
来自「一个很棒的网络控制系统仿真软件」· C++ 代码 · 共 92 行
CPP
92 行
#define KERNEL_MATLAB#include "../ttkernel.h" RTsys *rtsys;#include "../createtask.cpp"#include "getrtsys.cpp"void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ){ rtsys = getrtsys() ; // Get pointer to rtsys // Check number and type of arguments. if (nrhs < 4 || nrhs > 5) { mexErrMsgTxt("ttCreateTask: Wrong number of input arguments! \nUsage: ttCreateTask(name, deadline, priority, codefcn)\n ttCreateTask(name, deadline, priority, codefcn, data)"); } if (mxIsChar(prhs[0]) != 1) { mexErrMsgTxt("ttCreateTask: name must be a string"); } if (!mxIsDoubleScalar(prhs[1])) { mexErrMsgTxt("ttCreateTask: deadline must be a double scalar"); } if (!mxIsDoubleScalar(prhs[2])) { mexErrMsgTxt("ttCreateTask: priority must be a double scalar"); } if (mxIsChar(prhs[3]) != 1 || mxGetM(prhs[3]) != 1) { mexErrMsgTxt("ttCreateTask: codeFcn must be a non-empty string"); } char name[100]; mxGetString(prhs[0], name, 100); double deadline = *mxGetPr(prhs[1]); if (deadline < -EPS) { deadline = 0.0; mexWarnMsgTxt("ttCreateTask: negative deadline changed to zero"); } double priority = *mxGetPr(prhs[2]); char codeFcn[100]; mxGetString(prhs[3], codeFcn, 100); // Make sure that the code function exists in Matlab path // and that the code function is syntactically correct. mxArray *lhs[1]; mxArray *rhs[1]; rhs[0] = mxDuplicateArray(prhs[3]); mexCallMATLAB(1, lhs, 1, rhs, "exist"); int number = (int) *mxGetPr(lhs[0]); if (number == 0) { char buf[200]; sprintf(buf, "ttCreateTask: codeFcn %s not in path! Task '%s' not created!", codeFcn),name; mexErrMsgTxt(buf); } if (ttCreateTask(name, deadline, priority, NULL)) { // Add name of code function (m-file) and data variable TaskNode *n = (TaskNode*) rtsys->taskList->getLast(); n->getTask()->codeFcnMATLAB = new char[strlen(codeFcn)+1]; strcpy(n->getTask()->codeFcnMATLAB, codeFcn); char dataname[100]; char blockhandle[16]; mxArray* data; if (nrhs == 4) { // no data specified data = mxCreateDoubleMatrix(0, 0, mxREAL); } else { data = mxDuplicateArray(prhs[4]); } // Create globally unique name for data: gcbh + taskname + "_task_" mexCallMATLAB(1, lhs, 0, NULL, "gcbh"); // Get block handle sprintf(blockhandle, "%f", *(mxGetPr(lhs[0]))); strcpy(dataname, blockhandle); strcat(dataname, name); strcat(dataname, "_task_"); // Write data structure to global workspace mexPutVariable("global", dataname, data); mxDestroyArray(data); n->getTask()->dataMATLAB = new char[strlen(dataname)+1]; strcpy(n->getTask()->dataMATLAB, dataname); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?