/* 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 */
/* Function: ProcessGetParamsMsg =============================================== * Respond to the hosts request for the parameters by gathering up all the * params and sending them to the host. */ PRIVATE boolean_T ProcessGetParamsMsg(SimStruct *S) { int_T i; int_T nBytesTotal; boolean_T error = EXT_NO_ERROR; const DataTypeTransInfo *dtInfo = ssGetModelMappingInfo(S); 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++) { boolean_T tranIsComplex = dtTransGetComplexFlag(dtTable, i); int_T dt = dtTransGetDataType(dtTable, i); int_T dtSize = dtSizes[dt]; int_T elSize = dtSize * (tranIsComplex ? 2 : 1); int_T nEls = dtTransNEls(dtTable, i); int_T nBytes = elSize * nEls; nBytesTotal += nBytes; } /* * Send the message header. */ error = SendMsgHdrToHost(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); boolean_T tranIsComplex = dtTransGetComplexFlag(dtTable, i); int_T dt = dtTransGetDataType(dtTable, i); int_T dtSize = dtSizes[dt]; int_T elSize = dtSize * (tranIsComplex ? 2 : 1); int_T nEls = dtTransNEls(dtTable, i); int_T nBytes = elSize * nEls; error = SendMsgDataToHost(tranAddress, nBytes); if (error != EXT_NO_ERROR) goto EXIT_POINT; } } else { /* * We've got no params in the model. */ error = SendMsgHdrToHost(EXT_GETPARAMS_RESPONSE,0); if (error != EXT_NO_ERROR) goto EXIT_POINT; } EXIT_POINT: return(error); } /* end ProcessGetParamsMsg */
/* Function: ProcessConnectPkt ================================================= * Abstract: * Process the EXT_CONNECT packet and send response to host. */ PRIVATE boolean_T ProcessConnectPkt(RTWExtModeInfo *ei) { int_T nSet; PktHeader pktHdr; int_T tmpBufSize; uint32_T *tmpBuf = NULL; boolean_T error = EXT_NO_ERROR; const DataTypeTransInfo *dtInfo = (DataTypeTransInfo *) rteiGetModelMappingInfo(ei); uint_T *dtSizes = dtGetDataTypeSizes(dtInfo); int_T nDataTypes = dtGetNumDataTypes(dtInfo); assert(connected); assert(!comminitialized); /* * Send the 1st of two EXT_CONNECT_RESPONSE packets to the host. * The packet consists purely of the pktHeader. In this special * case the pktSize actually contains the number of bits per byte * (not always 8 - see TI compiler for C30 and C40). */ pktHdr.type = (uint32_T)EXT_CONNECT_RESPONSE; pktHdr.size = (uint32_T)8; /* 8 bits per byte */ error = ExtSetHostPkt(extUD,sizeof(pktHdr),(char_T *)&pktHdr,&nSet); if (error || (nSet != sizeof(pktHdr))) { fprintf(stderr, "ExtSetHostPkt() failed for 1st EXT_CONNECT_RESPONSE.\n"); goto EXIT_POINT; } /* Send 2nd EXT_CONNECT_RESPONSE packet containing the following * fields: * * CS1 - checksum 1 (uint32_T) * CS2 - checksum 2 (uint32_T) * CS3 - checksum 3 (uint32_T) * CS4 - checksum 4 (uint32_T) * * intCodeOnly - flag indicating if target is integer only (uint32_T) * * MWChunkSize - multiword data type chunk size on target (uint32_T) * * targetStatus - the status of the target (uint32_T) * * nDataTypes - # of data types (uint32_T) * dataTypeSizes - 1 per nDataTypes (uint32_T[]) */ { int nPktEls = 4 + /* checkSums */ 1 + /* intCodeOnly */ 1 + /* MW chunk size */ 1 + /* targetStatus */ 1 + /* nDataTypes */ dtGetNumDataTypes(dtInfo); /* data type sizes */ tmpBufSize = nPktEls * sizeof(uint32_T); tmpBuf = (uint32_T *)malloc(tmpBufSize); if (tmpBuf == NULL) { error = EXT_ERROR; goto EXIT_POINT; } } /* Send packet header. */ pktHdr.type = EXT_CONNECT_RESPONSE; pktHdr.size = tmpBufSize; error = ExtSetHostPkt(extUD,sizeof(pktHdr),(char_T *)&pktHdr,&nSet); if (error || (nSet != sizeof(pktHdr))) { fprintf(stderr, "ExtSetHostPkt() failed for 2nd EXT_CONNECT_RESPONSE.\n"); goto EXIT_POINT; } /* Checksums, target status & SL_DOUBLESize. */ tmpBuf[0] = rteiGetChecksum0(ei); tmpBuf[1] = rteiGetChecksum1(ei); tmpBuf[2] = rteiGetChecksum2(ei); tmpBuf[3] = rteiGetChecksum3(ei); #if INTEGER_CODE == 0 tmpBuf[4] = (uint32_T)0; #else tmpBuf[4] = (uint32_T)1; #endif tmpBuf[5] = (uint32_T)sizeof(uchunk_T); tmpBuf[6] = (uint32_T)modelStatus; /* nDataTypes and dataTypeSizes */ tmpBuf[7] = (uint32_T)nDataTypes; (void)memcpy(&tmpBuf[8], dtSizes, sizeof(uint32_T)*nDataTypes); /* Send the packet. */ error = ExtSetHostPkt(extUD,tmpBufSize,(char_T *)tmpBuf,&nSet); if (error || (nSet != tmpBufSize)) { fprintf(stderr, "ExtSetHostPkt() failed.\n"); goto EXIT_POINT; } commInitialized = TRUE; EXIT_POINT: free(tmpBuf); return(error); } /* end ProcessConnectPkt */
/* Function: ProcessConnectMsg ================================================= * Abstract: * Process the EXT_CONNECT message and send response to host. */ PRIVATE boolean_T ProcessConnectMsg(SimStruct *S) { int_T nSet; MsgHeader msgHdr; int_T tmpBufSize; uint32_T *tmpBuf = NULL; boolean_T error = EXT_NO_ERROR; const DataTypeTransInfo *dtInfo = ssGetModelMappingInfo(S); uint_T *dtSizes = dtGetDataTypeSizes(dtInfo); int_T nDataTypes = dtGetNumDataTypes(dtInfo); assert(connected); assert(!comminitialized); /* * Send the 1st of two EXT_CONNECT_RESPONSE messages to the host. * The message consists purely of the msgHeader. In this special * case the msgSize actually contains the number of bits per byte * (not always 8 - see TI compiler for C30 and C40). */ msgHdr.type = (uint32_T)EXT_CONNECT_RESPONSE; msgHdr.size = (uint32_T)8; /* 8 bits per byte */ error = ExtSetHostMsg(extUD,sizeof(msgHdr),(char_T *)&msgHdr,&nSet); if (error || (nSet != sizeof(msgHdr))) { fprintf(stderr, "ExtSetHostMsg() failed for 1st EXT_CONNECT_RESPONSE.\n"); goto EXIT_POINT; } /* Send 2nd EXT_CONNECT_RESPONSE message containing the following * fields: * * CS1 - checksum 1 (uint32_T) * CS2 - checksum 2 (uint32_T) * CS3 - checksum 3 (uint32_T) * CS4 - checksum 4 (uint32_T) * * targetStatus - the status of the target (uint32_T) * * nDataTypes - # of data types (uint32_T) * dataTypeSizes - 1 per nDataTypes (uint32_T[]) */ { int nMsgEls = 4 + /* checkSums */ 1 + /* targetStatus */ 1 + /* nDataTypes */ dtGetNumDataTypes(dtInfo); /* data type sizes */ tmpBufSize = nMsgEls * sizeof(uint32_T); tmpBuf = (uint32_T *)malloc(tmpBufSize); if (tmpBuf == NULL) { error = EXT_ERROR; goto EXIT_POINT; } } /* Send message header. */ msgHdr.type = EXT_CONNECT_RESPONSE; msgHdr.size = tmpBufSize; error = ExtSetHostMsg(extUD,sizeof(msgHdr),(char_T *)&msgHdr,&nSet); if (error || (nSet != sizeof(msgHdr))) { fprintf(stderr, "ExtSetHostMsg() failed for 2nd EXT_CONNECT_RESPONSE.\n"); goto EXIT_POINT; } /* Checksums, target status & SL_DOUBLESize. */ tmpBuf[0] = ssGetChecksum0(S); tmpBuf[1] = ssGetChecksum1(S); tmpBuf[2] = ssGetChecksum2(S); tmpBuf[3] = ssGetChecksum3(S); tmpBuf[4] = (uint32_T)modelStatus; /* nDataTypes and dataTypeSizes */ tmpBuf[5] = (uint32_T)nDataTypes; (void)memcpy(&tmpBuf[6], dtSizes, sizeof(uint32_T)*nDataTypes); /* Send the message. */ error = ExtSetHostMsg(extUD,tmpBufSize,(char_T *)tmpBuf,&nSet); if (error || (nSet != tmpBufSize)) { fprintf(stderr, "ExtSetHostMsg() failed.\n"); goto EXIT_POINT; } commInitialized = TRUE; EXIT_POINT: free(tmpBuf); return(error); } /* end ProcessConnectMsg */