コード例 #1
0
ファイル: rtiostream_interface.c プロジェクト: epffpe/Matlab
/* Function: ExtProcessArgs ====================================================
 * Abstract:
 *  Process the arguments specified by the user when invoking the target
 *  program.  In the case of this TCPIP example the args handled by external
 *  mode are:
 *      o -port #
 *          specify tcpip port number
 *      
 *      o -w
 *          wait for a start packet from the target before starting to execute
 *          the real-time model code
 *
 *  If any unrecognized options are encountered, ignore them.
 *
 * NOTES:
 *  o An error string is returned on failure, NULL is returned on success.
 *
 *  o IMPORTANT!!!
 *    As the arguments are processed, their strings must be NULL'd out in
 *    the argv array.  ext_svr will search argv when this function returns,
 *    and if any non-NULL entries are encountered an "unrecognized option" 
 *    packet will be displayed.
 */
PUBLIC const char_T *ExtProcessArgs(
    ExtUserData   *UD,
    const int_T   argc,
    const char_T  *argv[])
{
    const char_T *error          = NULL;
    int_T        count           = 1;

#if defined(ON_TARGET_WAIT_FOR_START) && ON_TARGET_WAIT_FOR_START == 1
    boolean_T    waitForStartPkt = TRUE;
#else
    boolean_T    waitForStartPkt = FALSE;
#endif

    while(count < argc) {
        const char_T *option = argv[count++];
        
        if (option == NULL) continue;

        if (strcmp(option, "-w") == 0) {
            /* 
             * -w (wait for packet from host) option
             */
            waitForStartPkt = TRUE;
            
            argv[count-1] = NULL;
        } else if (strcmp(option, "-ignore-arg") == 0 && (count != argc)) {
            /*
             * Special argument used by sbruntests to mark an executable
             * with a particular ID allowing the executable to be killed
             * when the sbruntests session is killed.
             *
             * -ignore-arg SBRUNTESTS_SESSION_ID#
             */
            count++;     
            argv[count-2] = NULL;
            argv[count-1] = NULL;
        }
    }

    assert(UD != NULL);
    UD->waitForStartPkt = waitForStartPkt;

#ifdef VXWORKS
    /* Store argv and argc for processing in ExtUserDataSetPort. 
     * rtIOStreamOpen will be called in ExtUserDataSetPort */
    UD->processArgsArgc = argc;
    UD->processArgsArgv = (const char_T **) argv;
#else
    /* rtIOStreamOpen combines argument processing and opening the stream */
    UD->streamID = rtIOStreamOpen(argc, (void *) argv);
#endif    
    return(error);
} /* end ExtProcessArgs */
コード例 #2
0
int main(void)
{

  /* Initialize rtiostream channel */
  rtIOStreamOpen(0,NULL);

  while (1) {
      serial_simple_step();
  }

}
コード例 #3
0
ファイル: rtiostream_interface.c プロジェクト: epffpe/Matlab
PUBLIC void ExtUserDataSetPort(ExtUserData *UD, const int_T port)
{
#define PORT_NUM_STR_DEFAULT "00255\0"
#define PORT_NUM_STR_LEN 6 /* allocates extra space for sprintf below */
#define PORT_ARG_STR "-port"
    /* create an extended argc and argv that includes -port */    
    const int_T argc = UD->processArgsArgc + 2;
    const char_T * portArgStr = PORT_ARG_STR;
    char_T portNumStr[PORT_NUM_STR_LEN] = PORT_NUM_STR_DEFAULT;
    const char_T ** argv = (const char_T **) calloc(argc, sizeof(char_T *));
    int_T count;
    if (argv == NULL) {
#ifndef EXTMODE_DISABLEPRINTF        
       (void)fprintf(stderr,
                "ExtUserDataSetPort: Memory allocation error.\n");
#endif
       /* any unprocessed args in the original argv will be caught by caller */
       return;
    }
    /* set a non-default port if valid */ 
    if ( (port >=255) && (port <= 65535)) {
        sprintf(portNumStr, "%5d", port);
    }
    /* copy original argv */
    for (count = 0; count < UD->processArgsArgc; count++) {
      argv[count] = UD->processArgsArgv[count];
    }
    /* add port */
    argv[argc-2] = portArgStr;
    argv[argc-1] = (const char_T *) portNumStr;
        
    /* rtIOStreamOpen combines argument processing and opening the stream */
    UD->streamID = rtIOStreamOpen(argc, (void *) argv);

    /* We assume -port argument has been processed by rtIOStream.
     * Copy back other elements of processed argv which should have been set to NULL. */
    for (count = 0; count < UD->processArgsArgc; count++) {
       UD->processArgsArgv[count] = argv[count];
    }
    free(argv);
} /* end ExtUserDataSetPort */