/* Function: SendPktToHost ===================================================== * Abstract: * Send a packet to the host. Packets can be of two forms: * o packet header only * the type is used as a flag to notify Simulink of an event * that has taken place on the target (event == action == type) * o pkt header, followed by data */ PUBLIC boolean_T SendPktToHost( const ExtModeAction action, const int size, /* # of bytes to follow pkt header */ const char *data) { boolean_T error = EXT_NO_ERROR; sched_yield(); #ifdef QNX_OS sem_wait(pktSem); #endif error = SendPktHdrToHost(action,size); if (error != EXT_NO_ERROR) goto EXIT_POINT; if (data != NULL) { error = SendPktDataToHost(data, size); if (error != EXT_NO_ERROR) goto EXIT_POINT; } else { assert(size == 0); } EXIT_POINT: #ifdef QNX_OS sem_post(pktSem); #endif return(error); } /* end SendPktToHost */
/* Function: SendPktToHost ===================================================== * Abstract: * Send a packet to the host. Packets can be of two forms: * o packet header only * the type is used as a flag to notify Simulink of an event * that has taken place on the target (event == action == type) * o pkt header, followed by data */ PUBLIC boolean_T SendPktToHost( const ExtModeAction action, const int size, /* # of bytes to follow pkt header */ const char *data) { boolean_T error = EXT_NO_ERROR; #ifdef VXWORKS semTake(pktSem, WAIT_FOREVER); #endif error = SendPktHdrToHost(action,size); if (error != EXT_NO_ERROR) goto EXIT_POINT; if (data != NULL) { error = SendPktDataToHost(data, size); if (error != EXT_NO_ERROR) goto EXIT_POINT; } else { assert(size == 0); } EXIT_POINT: #ifdef VXWORKS semGive(pktSem); #endif return(error); } /* end SendPktToHost */
/* Function: SendPktToHost ===================================================== * Abstract: * Send a packet to the host. Packets can be of two forms: * o packet header only * the type is used as a flag to notify Simulink of an event * that has taken place on the target (event == action == type) * o pkt header, followed by data */ PUBLIC boolean_T SendPktToHost( const ExtModeAction action, const int size, /* # of bytes to follow pkt header */ const char *data) { boolean_T error = EXT_NO_ERROR; error = SendPktHdrToHost(action,size); if (error != EXT_NO_ERROR) goto EXIT_POINT; if (data != NULL) { error = SendPktDataToHost(data, size); if (error != EXT_NO_ERROR) goto EXIT_POINT; } else { assert(size == 0); } EXIT_POINT: return(error); } /* end SendPktToHost */
/* Function: ProcessGetParamsPkt =============================================== * Respond to the hosts request for the parameters by gathering up all the * params and sending them to the host. */ PRIVATE boolean_T ProcessGetParamsPkt(RTWExtModeInfo *ei) { int_T i; int_T nBytesTotal; boolean_T error = EXT_NO_ERROR; const DataTypeTransInfo *dtInfo = (DataTypeTransInfo *) rteiGetModelMappingInfo(ei); const DataTypeTransitionTable *dtTable = dtGetParamDataTypeTrans(dtInfo); if (dtTable != NULL) { /* * We've got some params in the model. Send their values to the * host. */ int_T nTrans = dtGetNumTransitions(dtTable); const uint_T *dtSizes = dtGetDataTypeSizes(dtInfo); #ifdef VERBOSE printf("\nUploading initial parameters....\n"); #endif /* * Take pass 1 through the transitions to figure out how many * bytes we're going to send. */ nBytesTotal = 0; for (i=0; i<nTrans; i++) { int_T dt = dtTransGetDataType(dtTable, i); int_T dtSize = dtSizes[dt]; int_T nEls = dtTransNEls(dtTable, i); /* complexity accounted for in trans tbl num of els */ int_T nBytes = dtSize * nEls; nBytesTotal += nBytes; } /* * Send the packet header. */ error = SendPktHdrToHost(EXT_GETPARAMS_RESPONSE,nBytesTotal); if (error != EXT_NO_ERROR) goto EXIT_POINT; /* * Take pass 2 through the transitions and send the parameters. */ for (i=0; i<nTrans; i++) { char_T *tranAddress = dtTransGetAddress(dtTable, i); int_T dt = dtTransGetDataType(dtTable, i); int_T dtSize = dtSizes[dt]; int_T nEls = dtTransNEls(dtTable, i); /* complexity accounted for in trans tbl num of els */ int_T nBytes = dtSize * nEls; error = SendPktDataToHost(tranAddress, nBytes); if (error != EXT_NO_ERROR) goto EXIT_POINT; } } else { /* * We've got no params in the model. */ error = SendPktHdrToHost(EXT_GETPARAMS_RESPONSE,0); if (error != EXT_NO_ERROR) goto EXIT_POINT; } EXIT_POINT: return(error); } /* end ProcessGetParamsPkt */