/* Function: SendPktDataToHost ================================================= * Abstract: * Send packet data to host. You are responsible for sending a header * prior to sending the header. */ PRIVATE boolean_T SendPktDataToHost(const char *data, const int size) { int_T nSet; boolean_T error = EXT_NO_ERROR; error = ExtSetHostPkt(extUD,size,data,&nSet); if (error || (nSet != size)) { error = EXT_ERROR; fprintf(stderr,"ExtSetHostPkt() failed.\n"); goto EXIT_POINT; } EXIT_POINT: return(error); } /* end SendPktDataToHost */
/* Function: SendPktHdrToHost ================================================== * Abstract: * Send a packet header to the host. */ PRIVATE boolean_T SendPktHdrToHost( const ExtModeAction action, const int size) /* # of bytes to follow pkt header */ { int_T nSet; PktHeader pktHdr; boolean_T error = EXT_NO_ERROR; pktHdr.type = (uint32_T)action; pktHdr.size = size; error = ExtSetHostPkt(extUD,sizeof(pktHdr),(char_T *)&pktHdr,&nSet); if (error || (nSet != sizeof(pktHdr))) { error = EXT_ERROR; fprintf(stderr,"ExtSetHostPkt() failed.\n"); goto EXIT_POINT; } EXIT_POINT: return(error); } /* end SendPktHdrToHost */
/* 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 */