/* Function: ProcessSelectTriggerSignalPkt =========================================== * Receive and process the EXT_SELECT_TRIGGER or EXT_SELECT_SIGNALS packet. */ PRIVATE boolean_T ProcessSelectTriggerSignalPkt(const ExtModeAction ACTION_ID, RTWExtModeInfo *ei, const int pktSize, int_T numSampTimes, char* errMsg) { const char *pkt; int32_T upInfoIdx; boolean_T error = EXT_NO_ERROR; printf("Inside ProcessSelectTriggerSignalPkt \n"); //DAREN :added this here pkt = GetPkt(pktSize); if (pkt == NULL) { SendResponseStatus(ACTION_ID, NOT_ENOUGH_MEMORY, -1); return(EXT_ERROR); } (void)memcpy(&upInfoIdx, pkt, sizeof(int32_T)); /* Extract upInfoIdx */ switch(ACTION_ID) { case EXT_SELECT_TRIGGER_RESPONSE: #ifndef EXTMODE_DISABLEPRINTF PRINT_VERBOSE( ("got EXT_SELECT_TRIGGER packet for upInfoIdx : %d\n", upInfoIdx)); #endif error = UploadInitTrigger(ei, pkt+sizeof(int32_T), upInfoIdx); break; case EXT_SELECT_SIGNALS_RESPONSE: #ifndef EXTMODE_DISABLEPRINTF PRINT_VERBOSE( ("got EXT_SELECT_SIGNALS packet for upInfoIdx : %d\n", upInfoIdx)); #endif error = UploadLogInfoInit(ei, numSampTimes, pkt+sizeof(int32_T), upInfoIdx); break; default: break; } if (error != EXT_NO_ERROR) { SendResponseStatus(ACTION_ID, NOT_ENOUGH_MEMORY, upInfoIdx); #ifndef EXTMODE_DISABLEPRINTF printf("%s\n", errMsg); #endif return(error); } error = SendResponseStatus(ACTION_ID, STATUS_OK, upInfoIdx); return(error); /* Can be EXT_NO_ERROR */ } /* end ProcessSelectTriggerSignalPkt */
/* Function: ProcessSelectSignalsPkt =========================================== * Receive and process the EXT_SELECT_SIGNALS packet. */ PRIVATE boolean_T ProcessSelectSignalsPkt(RTWExtModeInfo *ei, int_T numSampTimes, const int pktSize) { const char *pkt; int32_T upInfoIdx; boolean_T error = EXT_NO_ERROR; pkt = GetPkt(pktSize); if (pkt == NULL) { SendResponseStatus(EXT_SELECT_SIGNALS_RESPONSE, NOT_ENOUGH_MEMORY, -1); error = EXT_ERROR; goto EXIT_POINT; } /* Extract upInfoIdx */ (void)memcpy(&upInfoIdx, pkt, sizeof(int32_T)); PRINT_VERBOSE( ("got EXT_SELECT_SIGNALS packet for upInfoIdx : %d\n", upInfoIdx)); error = UploadLogInfoInit(ei, numSampTimes, pkt+sizeof(int32_T), upInfoIdx); if (error != NO_ERR) { SendResponseStatus(EXT_SELECT_SIGNALS_RESPONSE, NOT_ENOUGH_MEMORY, upInfoIdx); printf( "\nError in UploadLogInfoInit(). Most likely a memory\n" "allocation error or an attempt to re-initialize the\n" "signal selection during the data logging process\n" "(i.e., multiple EXT_SELECT_SIGNAL packets were received\n" "before the logging session terminated or an\n" "EXT_CANCEL_LOGGING packet was received)\n"); goto EXIT_POINT; } error = SendResponseStatus(EXT_SELECT_SIGNALS_RESPONSE, STATUS_OK, upInfoIdx); if (error != EXT_NO_ERROR) goto EXIT_POINT; EXIT_POINT: return(error); } /* end ProcessSelectSignalsPkt */
/* Function: rt_MsgServerWork ================================================== * Abstract: * If not connected, establish communication of the message line and the * data upload line. If connected, send/receive messages and parameters * on the message line. */ PUBLIC boolean_T rt_MsgServerWork(SimStruct *S) { MsgHeader msgHdr; boolean_T hdrAvail; boolean_T error = EXT_NO_ERROR; boolean_T disconnectOnError = FALSE; /* * If not connected, attempt to make connection to host. */ if (!connected) { 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 do do */ /* * Process messages. */ /* Wait for a message. */ error = GetMsgHdr(&msgHdr, &hdrAvail); if (error != EXT_NO_ERROR) { printf("\nError occured getting message header.\n"); disconnectOnError = TRUE; goto EXIT_POINT; } if (!hdrAvail) goto EXIT_POINT; /* nothing to do */ /* * This is the first message. 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) { msgHdr.type = EXT_CONNECT; } /* * At this point we know that we have a message: process it. */ switch(msgHdr.type) { case EXT_GET_TIME: { time_T t = ssGetT(S); /* Skip verbosity print out - we get too many of these */ /*PRINT_VERBOSE(("got EXT_GET_TIME message.\n"));*/ error = SendMsgToHost( EXT_GET_TIME_RESPONSE,sizeof(time_T),(char_T *)&t); if (error != EXT_NO_ERROR) goto EXIT_POINT; break; } case EXT_ARM_TRIGGER: { PRINT_VERBOSE(("got EXT_ARM_TRIGGER message.\n")); UploadArmTrigger(); break; } case EXT_SELECT_SIGNALS: { const char *msg; PRINT_VERBOSE(("got EXT_SELECT_SIGNALS message.\n")); msg = GetMsg(msgHdr.size); if (msg == NULL) { error = EXT_ERROR; goto EXIT_POINT; } error = UploadLogInfoInit(S, msg); if (error != NO_ERR) { printf( "\nError in UploadLogInfoInit(). Most likely a memory\n" "allocation error or an attempt to re-initialize the\n" "signal selection during the data logging process\n" "(i.e., multiple EXT_SELECT_SIGNAL messages were received\n" "before the logging session terminated or an\n" "EXT_CANCEL_LOGGING message was received)"); goto EXIT_POINT; } break; } case EXT_SELECT_TRIGGER: { const char *msg; PRINT_VERBOSE(("got EXT_SELECT_TRIGGER message.\n")); msg = GetMsg(msgHdr.size); if (msg == NULL) { error = EXT_ERROR; goto EXIT_POINT; } error = UploadInitTrigger(S, msg); if (error != EXT_NO_ERROR) { printf("\nError in UploadInitTrigger\n"); goto EXIT_POINT; } break; } case EXT_CONNECT: { PRINT_VERBOSE(("got EXT_CONNECT message.\n")); error = ProcessConnectMsg(S); if (error != EXT_NO_ERROR) goto EXIT_POINT; break; } case EXT_SETPARAM: { PRINT_VERBOSE(("got EXT_SETPARAM message.\n")); error = ProcessSetParamMsg(S, msgHdr.size); if (error != EXT_NO_ERROR) goto EXIT_POINT; break; } case EXT_GETPARAMS: { PRINT_VERBOSE(("got EXT_GETPARAMS message.\n")); error = ProcessGetParamsMsg(S); if (error != EXT_NO_ERROR) goto EXIT_POINT; break; } case EXT_DISCONNECT_REQUEST: { PRINT_VERBOSE(("got EXT_DISCONNECT_REQUEST message.\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 = SendMsgToHost(EXT_DISCONNECT_REQUEST_RESPONSE, 0, NULL); if (error != EXT_NO_ERROR) goto EXIT_POINT; DisconnectFromHost(S); break; } case EXT_MODEL_START: PRINT_VERBOSE(("got EXT_MODEL_START message.\n")); #ifdef VXWORKS { extern SEM_ID startStopSem; semGive(startStopSem); } #endif startModel = TRUE; error = SendMsgToHost(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 message.\n")); ssSetStopRequested(S, TRUE); break; case EXT_MODEL_PAUSE: PRINT_VERBOSE(("got EXT_MODEL_PAUSE message.\n")); modelStatus = TARGET_STATUS_PAUSED; startModel = FALSE; error = SendMsgToHost(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 message.\n")); if ((modelStatus == TARGET_STATUS_PAUSED) && !startModel) { startModel = TRUE; } error = SendMsgToHost(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 message.\n")); if (modelStatus == TARGET_STATUS_PAUSED) { modelStatus = TARGET_STATUS_RUNNING; startModel = FALSE; } error = SendMsgToHost(EXT_MODEL_CONTINUE_RESPONSE, 0, NULL); if (error != EXT_NO_ERROR) goto EXIT_POINT; break; case EXT_CANCEL_LOGGING: PRINT_VERBOSE(("got EXT_CANCEL_LOGGING message.\n")); UploadCancelLogging(); break; default: fprintf(stderr,"received invalid message.\n"); break; } /* end switch */ EXIT_POINT: if (error != EXT_NO_ERROR) { if (disconnectOnError) { fprintf(stderr, "Error occured in rt_MsgServerWork.\n" "Disconnecting from host!\n"); DisconnectFromHost(S); /* * Patch by Gopal Santhanam 5/25/2002 (for VXWORKS) * If there there was a problem and we have already disconnected * from the host, there is no point in returning that error * back to rt_MsgServer. That would cause the task servicing * external messages to quit. Once disconnected, we could * just as easily resume by waiting for a new connection. */ #ifdef VXWORKS error = EXT_NO_ERROR; #endif } } return(error); } /* end rt_MsgServerWork */