initnetwork2.cpp

来自「一个很棒的网络控制系统仿真软件」· C++ 代码 · 共 75 行

CPP
75
字号
#ifndef INIT_NETWORK2#define INIT_NETWORK2// returns 0 if successful, -1 otherwiseint ttInitNetwork2(){  int i;  char buf[100];  mxArray *lhs1[1];  mxArray *lhs2[1];  mxArray *rhs[9];  void *nwsysp;  NetworkNode *nn;  Network* network;  RTnetwork* tmp_network;    mexCallMATLAB(1, lhs1, 0, NULL, "bdroot"); // Get model name  // find an S-function block with the specified name  rhs[0] = lhs1[0];  rhs[1] = mxCreateString("LookUnderMasks");  rhs[2] = mxCreateString("all");  rhs[3] = mxCreateString("FollowLinks");  rhs[4] = mxCreateString("on");  rhs[5] = mxCreateString("Name");    rhs[6] = mxCreateString("ttnetwork");  rhs[7] = mxCreateString("BlockType");  rhs[8] = mxCreateString("S-Function");  mexCallMATLAB(1, lhs1, 9, rhs, "find_system");    if (mxIsEmpty(lhs1[0])) {    MEX_ERROR("ttInitNetwork: Can't find any network blocks!");    return -1;  }  nn = (NetworkNode*) rtsys->networkList->getFirst();  while (nn!=NULL) {    network = nn->getNetwork();    // Assign TrueTime network pointer     i = 0;    bool found = false;    while (!found) {      // Go through the network blocks      rhs[0] = mxGetCell(lhs1[0], i);      rhs[1] = mxCreateString("UserData");      mexCallMATLAB(1, lhs2, 2, rhs, "get_param");      if (mxIsChar(lhs2[0]) != 1 || mxGetM(lhs2[0]) != 1) {	MEX_ERROR("UserData is not a string.");	return -1;      }      mxGetString(lhs2[0], buf, 100);      sscanf(buf, "%p", &nwsysp);            if (nwsysp == NULL) {	MEX_ERROR("ttInitNetwork: UserData of network block is not a pointer\n");	return -1;      }            RTnetwork *tt_network = (RTnetwork*) nwsysp;      if (tt_network->networkNbr == network->networkNbr) {	network->nwsys = tt_network;	found = true;      }      i++; // next network string    }        nn = (NetworkNode*) nn->getNext();  }  return 0; // Everything is OK}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?