Exemplo n.º 1
0
/* Function: ProcessSetParamPkt ================================================
 * Receive and process the EXT_SETPARAM packet.
 */
PRIVATE boolean_T ProcessSetParamPkt(RTWExtModeInfo *ei,
                                     const int pktSize)
{
    int32_T    msg;
    const char *pkt;
    boolean_T  error = EXT_NO_ERROR;

    /*
     * Receive packet and set parameters.
     */
    pkt = GetPkt(pktSize);
    if (pkt == NULL) {
        msg = (int32_T)NOT_ENOUGH_MEMORY;
        SendPktToHost(EXT_SETPARAM_RESPONSE,sizeof(int32_T),(char_T *)&msg);
        error = EXT_ERROR;
        goto EXIT_POINT;
    }
    SetParam(ei, pkt);
   
    msg = (int32_T)STATUS_OK;
    
    error = SendPktToHost(EXT_SETPARAM_RESPONSE,sizeof(int32_T),(char_T *)&msg);
  
        
    if (error != EXT_NO_ERROR) goto EXIT_POINT;

EXIT_POINT:
   
    return(error);
} /* end ProcessSetParamPkt */
Exemplo n.º 2
0
/* Function: rt_ExtModeShutdown ================================================
 * Abstract:
 *  Called when target program terminates to enable cleanup of external 
 *  mode.
 */
PUBLIC boolean_T rt_ExtModeShutdown(int_T numSampTimes)
{
    int i;
    boolean_T error = EXT_NO_ERROR;

    for (i=0; i<NUM_UPINFOS; i++) {
        ExtModeShutdown(i, numSampTimes);
    }

    if (commInitialized) {
        error = SendPktToHost(EXT_MODEL_SHUTDOWN, 0, NULL);
        if (error != EXT_NO_ERROR) {
            fprintf(stderr,
                "\nError sending EXT_MODEL_SHUTDOWN packet to host.\n");
        }
        commInitialized = FALSE;
    }
    if (connected) {
        connected = FALSE;
        modelStatus = TARGET_STATUS_WAITING_TO_START;        
    }

    ExtShutDown(extUD);
    ExtUserDataDestroy(extUD);
    
    rtExtModeTestingRemoveBatMarker();
    
    return(error);
} /* end rt_ExtModeShutdown */
PRIVATE boolean_T AcknowledgeSetParamPkt(const int pktSize)
{
    int32_T    msg;
    const char *pkt;
    boolean_T  error = EXT_NO_ERROR;
    printf("Inside AcknowledgeSetParamPkt \n");  //DAREN :added this here
    pkt = GetPkt(pktSize);
    msg = (int32_T)STATUS_OK;
    error = SendPktToHost(EXT_SETPARAM_RESPONSE, sizeof(int32_T), (char_T *)&msg);
    return(error);
}
Exemplo n.º 4
0
/* Function:  SendResponseStatus ===============================================
 *  
 */
PRIVATE boolean_T SendResponseStatus(const ExtModeAction  response,
                                     const ResponseStatus status,
                                     int32_T upInfoIdx)
{
    int32_T   msg[2];
    boolean_T error = EXT_NO_ERROR;

    msg[0] = (int32_T)status;
    msg[1] = upInfoIdx;

    error = SendPktToHost(response,2*sizeof(int32_T),(char_T *)&msg);
    return(error);

} /* end SendResponseStatus */
Exemplo n.º 5
0
/* Function: rt_PktServerWork ==================================================
 * Abstract:
 *  If not connected, establish communication of the packet line and the
 *  data upload line.  If connected, send/receive packets and parameters
 *  on the packet line.
 */
PUBLIC void rt_PktServerWork( RTWExtModeInfo *ei, int_T numSampTimes,  boolean_T      *stopReq)
{
    PktHeader  pktHdr;
    boolean_T  hdrAvail;
    boolean_T  error             = EXT_NO_ERROR;
    boolean_T  disconnectOnError = FALSE;
    pktServerArgT  *pktServerArg;
   
     
    /*
     * If not connected, attempt to make connection to host.
     */
    if (!connected) {
        rtExtModeTestingKillIfOrphaned(FALSE);

        error = ExtOpenConnection(extUD,&connected);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
    }

    /*
     * If ExtOpenConnection is not blocking and there are no pending
     * requests to open a connection, we'll still be unconnected.
     */
    if (!connected) goto EXIT_POINT; /* nothing to do */
    
    /*
     * Process packets.
     */

    /* Wait for a packet. */
    error = GetPktHdr(&pktHdr, &hdrAvail);
    if (error != EXT_NO_ERROR) {
        fprintf(stderr, "\nError occurred getting packet header.\n");
        disconnectOnError = TRUE;
        goto EXIT_POINT;
    }
    rtExtModeTestingKillIfOrphaned(hdrAvail);
    
    if (!hdrAvail) goto EXIT_POINT; /* nothing to do */

    /*
     * This is the first packet.  Should contain the string:
     * 'ext-mode'.  Its contents are not important to us.
     * It is used as a flag to start the handshaking process.
     */
    if (!commInitialized) {
        pktHdr.type = EXT_CONNECT;
    }

    /* 
     * At this point we know that we have a packet: process it.
     */
#ifdef QNX_OS
    //taskSafe();
#endif
    switch(pktHdr.type) {

    case EXT_GET_TIME:
    {
        /* Skip verbosity print out - we get too many of these */
        /*PRINT_VERBOSE(("got EXT_GET_TIME packet.\n"));*/
        time_T t = rteiGetT(ei);
        
        error = SendPktToHost(
            EXT_GET_TIME_RESPONSE,sizeof(time_T),
            (char_T *)&t);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    case EXT_ARM_TRIGGER:
    {
        error = ProcessArmTriggerPkt(pktHdr.size,numSampTimes);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    case EXT_SELECT_SIGNALS:
    {
        error = ProcessSelectSignalsPkt(ei,numSampTimes,pktHdr.size);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    case EXT_SELECT_TRIGGER: 
    {
        error = ProcessSelectTriggerPkt(ei,pktHdr.size);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    case EXT_CONNECT:
    {
        PRINT_VERBOSE(("got EXT_CONNECT packet.\n"));
        error = ProcessConnectPkt(ei);
 
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    case EXT_SETPARAM:
    {
        PRINT_VERBOSE(("got EXT_SETPARAM packet.\n"));
        error = ProcessSetParamPkt(ei, pktHdr.size);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    case EXT_GETPARAMS:
    {
        PRINT_VERBOSE(("got EXT_GETPARAMS packet.\n"));
        error = ProcessGetParamsPkt(ei);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    case EXT_DISCONNECT_REQUEST:
    {
        PRINT_VERBOSE(("got EXT_DISCONNECT_REQUEST packet.\n"));
        
        /*
         * Note that from the target's point of view this is
         * more a "notify" than a "request".  The host needs to
         * have this acknowledged before it can begin closing
         * the connection.
         */
        error = SendPktToHost(EXT_DISCONNECT_REQUEST_RESPONSE, 0, NULL);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;

        DisconnectFromHost(numSampTimes);

        break;
    }

    case EXT_DISCONNECT_REQUEST_NO_FINAL_UPLOAD:
    {
        PRINT_VERBOSE(("got EXT_DISCONNECT_REQUEST_NO_FINAL_UPLOAD packet.\n"));
        
        /*
         * The target receives this packet when the host is
         * immediately terminating the extmode communication due
         * to some error.  The target should not send back a
         * response or a final upload of data because the host is
         * expecting neither.  The target must be disconnected and
         * returned to a state where it is running and can be
         * re-connected to by the host.
         */
        ForceDisconnectFromHost(numSampTimes);

        break;
    }

    case EXT_MODEL_START:
        PRINT_VERBOSE(("got EXT_MODEL_START packet.\n"));
#ifdef QNX_OS
        {
            extern sem_t* startStopSem;
    
            sem_post(startStopSem);
        }
#endif
        startModel = TRUE;
        error = SendPktToHost(EXT_MODEL_START_RESPONSE, 0, NULL);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;

    case EXT_MODEL_STOP:
        PRINT_VERBOSE(("got EXT_MODEL_STOP packet.\n"));
        *stopReq = TRUE;
        break;

    case EXT_MODEL_PAUSE:
        PRINT_VERBOSE(("got EXT_MODEL_PAUSE packet.\n"));
        modelStatus = TARGET_STATUS_PAUSED;
        startModel  = FALSE;

        error = SendPktToHost(EXT_MODEL_PAUSE_RESPONSE, 0, NULL);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;

        break;

    case EXT_MODEL_STEP:
        PRINT_VERBOSE(("got EXT_MODEL_STEP packet.\n"));
        if ((modelStatus == TARGET_STATUS_PAUSED) && !startModel) {
            startModel = TRUE;
        }
        
        error = SendPktToHost(EXT_MODEL_STEP_RESPONSE, 0, NULL);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;

        break;

    case EXT_MODEL_CONTINUE:
        PRINT_VERBOSE(("got EXT_MODEL_CONTINUE packet.\n"));
        if (modelStatus == TARGET_STATUS_PAUSED) {
            modelStatus = TARGET_STATUS_RUNNING;
            startModel  = FALSE;
        }
        
        error = SendPktToHost(EXT_MODEL_CONTINUE_RESPONSE, 0, NULL);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;

        break;

    case EXT_CANCEL_LOGGING:
    {
        error = ProcessCancelLoggingPkt(pktHdr.size);
        if (error != EXT_NO_ERROR) goto EXIT_POINT;
        break;
    }

    default:
        fprintf(stderr,"received invalid packet.\n");
        break;
    } /* end switch */

EXIT_POINT:
    if (error != EXT_NO_ERROR) {
        if (disconnectOnError) {
            fprintf(stderr,
                "Error occurred in rt_PktServerWork.\n"
                "Disconnecting from host!\n");

            /* An error in this function which causes disconnectOnError to be
             * set to true is caused by a physical failure in the external mode
             * connection.  We assume this failure caused the host to disconnect.
             * The target must be disconnected and returned to a state
             * where it is running and can be re-connected to by the host.
             */
            ForceDisconnectFromHost(numSampTimes);
        }
    }
#ifdef VXWORKS
    //taskUnsafe();
#endif
} /* end rt_PktServerWork */