trypost.cpp

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

CPP
74
字号
#ifndef TRY_POST#define TRY_POSTbool ttTryPost(char* mailbox, void* msg) {  MailboxNode* mbn;  Mailbox* m;  mbn = (MailboxNode*) rtsys->mailboxList->getFirst();  while (mbn != NULL) {    if (mbn->getMailbox()->name != NULL) {      if (strcmp(mbn->getMailbox()->name, mailbox) == 0)	break;    }    mbn = (MailboxNode*) mbn->getNext();  }      if (mbn == NULL) {    char buf[200];    sprintf(buf, "ttTryPost: Non-existent mailbox '%s'!", mailbox);    MEX_ERROR(buf);    return false;  }  m = mbn->getMailbox();  if (m->count == m->maxSize) {    printf("ttTryPost: Mailbox '%s' is full\n", mailbox);    return false;  } else {    m->buffer[m->inP] = msg;    m->count++;    m->inP = (m->inP + 1) % m->maxSize;    return true;  }  }int ttTryPostMATLAB(char* mailbox) {  MailboxNode* mbn;  Mailbox* m;  int value;  mbn = (MailboxNode*) rtsys->mailboxList->getFirst();  while (mbn != NULL) {    if (mbn->getMailbox()->name != NULL) {      if (strcmp(mbn->getMailbox()->name, mailbox) == 0)	break;    }    mbn = (MailboxNode*) mbn->getNext();  }      if (mbn == NULL) {    // Mailbox does not exist     char buf[200];    sprintf(buf, "ttTryPost: Non-existent mailbox '%s'\n", mailbox);    MEX_ERROR(buf);    return 0;  }  m = mbn->getMailbox();  if (m->count == m->maxSize) {    printf("ttTryPost: Mailbox '%s' is full\n", mailbox);    value = 0;  } else {    m->count++;    value = m->inP + 1;    m->inP = (m->inP + 1) % m->maxSize;  }      return value;}#endif

⌨️ 快捷键说明

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