/* 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 */