Example #1
0
/******************************************************************************
  Function Name    :  bFormSigNameAndLength

  Input(s)         :  UINT* punLength : Signal length
                      UINT* punStartBit : Signal start bit
                      CStringArray& omStrArraySigName : Signal array
                      list<FRAME_STRUCT>::iterator itrFrame : Frame structure

  Output           :  BOOL : Return value
******************************************************************************/
BOOL Cluster::bFormSigNameAndLength(UINT* punLength,
                                    UINT* punStartBit,
                                    CStringArray& omStrArraySigName,
                                    list<FRAME_STRUCT>::iterator itrFrame)
{
    BOOL bReturn    = FALSE;
    int unSigCount = 0;
    itrFrame->GetSignalCount(unSigCount);//m_psMessages[nIndex].m_unNumberOfSignals;;
    //sSIGNALS* pSg = m_psMessages[nIndex].m_psSignals;

    list<SIGNAL_STRUCT> sigList;
    itrFrame->GetSignalList(sigList);
    //sSIGNALS* pSg = m_psMessages[unMsgIndex].m_psSignals;
    list<SIGNAL_STRUCT>::iterator itrSig = sigList.begin();

    UINT unStartBit = 0;
    UINT unUnused   = 0;
    UINT unCount    = 0;

    //rmdup(punStartBit, unSigCount);
    UINT* p = (UINT*)std::unique(punStartBit, punStartBit+unSigCount);
    unSigCount = (p-punStartBit);
    if( itrSig != sigList.end() && punLength != NULL && punStartBit != NULL )
    {
        //unSigCount = m_psMessages[nIndex].m_unNumberOfSignals;
        CString omFormatString;
        for(UINT i = 0 ; i < unSigCount ; i++ )
        {
            SIGNAL_STRUCT itrSig = psGetSigPtr(punStartBit[i],
                                               sigList);
            if(itrSig.m_unStartbit >= 0)
            {
                UINT unSigLen = itrSig.m_nLength /** 8*/;

                // if first signal is not defined from first bit in first
                // byte
                if(punStartBit[i] > 0  && i == 0)
                {
                    // If more then first 32 bits are not having
                    // any signal defined, add two signal without
                    // any name one with size 32 bit and other
                    // with size of rest of bits.
                    INT nTempBitLen = static_cast<INT> (punStartBit[i]);
                    while (nTempBitLen > defBITS_IN_FOUR_BYTE )
                    {
                        omFormatString.Format(defUNION_FORMAT_STRING,
                                              defUNSIGNED_INT,
                                              STR_EMPTY,
                                              defUINT_LENGTH);
                        omStrArraySigName.Add(omFormatString);
                        nTempBitLen -= defBITS_IN_FOUR_BYTE;
                    }


                    omFormatString.Format(defUNION_FORMAT_STRING,
                                          defUNSIGNED_INT,
                                          STR_EMPTY,
                                          nTempBitLen);
                    omStrArraySigName.Add(omFormatString);
                }

                // For signals > 32 bits
                if( unSigLen > defBITS_IN_FOUR_BYTE)
                {
                    omFormatString.Format(defUNION_FORMAT_STRING,
                                          defINTEGER64,
                                          itrSig.m_strSignalName.c_str(),
                                          unSigLen);
                }
                // For < 32 bits use signed int
                else
                {
                    // Check for the Sign of the signal
                    if( itrSig.m_bDataType == CHAR_INT )
                    {
                        omFormatString.Format(defUNION_FORMAT_STRING,
                                              defSIGNED_INTEGER,
                                              itrSig.m_strSignalName.c_str(),
                                              unSigLen);
                    }
                    else
                    {
                        omFormatString.Format(defUNION_FORMAT_STRING,
                                              defUNSIGNED_INTEGER,
                                              itrSig.m_strSignalName.c_str(),
                                              unSigLen);
                    }
                }
                omStrArraySigName.Add(omFormatString);
                // check if there is some unsed in between two signal
                // defined

                if( ( (punStartBit[i] + unSigLen) <
                        ( punStartBit[i + 1] ) )
                        && (unSigCount != i + 1 )
                  )
                {
                    INT nLengthTemp = static_cast<INT>(punStartBit[i + 1])
                                      - static_cast<INT>(punStartBit[i] + unSigLen);
                    while (nLengthTemp > defBITS_IN_FOUR_BYTE)
                    {
                        omFormatString.Format(defUNION_FORMAT_STRING,
                                              defUNSIGNED_INT,
                                              STR_EMPTY,
                                              defUINT_LENGTH);
                        omStrArraySigName.Add(omFormatString);
                        nLengthTemp -= defBITS_IN_FOUR_BYTE;
                    }
                    omFormatString.Format(defUNION_FORMAT_STRING,
                                          defUNSIGNED_INT,
                                          STR_EMPTY,
                                          nLengthTemp);
                    omStrArraySigName.Add(omFormatString);
                }
                else if (i == (unSigCount -1))// if last signal, check if unsed bits at the end

                {

                    INT nLastBitLength = 0;
                    nLastBitLength = static_cast<INT>
                                     ((itrFrame->m_nLength) *
                                      defBITS_IN_BYTE ) ;
                    nLastBitLength -= static_cast<INT> (punStartBit[i]);
                    nLastBitLength -= static_cast<INT> (unSigLen);
                    // If there is unsed bits at the end add bit wise definition
                    // without giving any name.
                    if(nLastBitLength >0 )
                    {
                        // If last unsed signal is more then 32 bit
                        // add two signal with no name and first
                        // having length of
                        INT nTempLastBitLen = nLastBitLength;
                        nTempLastBitLen = 32; // To be commented
                        while (nTempLastBitLen > defBITS_IN_FOUR_BYTE)
                        {
                            omFormatString.Format(defUNION_FORMAT_STRING,
                                                  defUNSIGNED_INT,
                                                  STR_EMPTY,
                                                  defUINT_LENGTH);
                            omStrArraySigName.Add(omFormatString);
                            nTempLastBitLen -= defBITS_IN_FOUR_BYTE;
                        }
                        omFormatString.Format(defUNION_FORMAT_STRING,
                                              defUNSIGNED_INT,
                                              STR_EMPTY,
                                              nTempLastBitLen);
                        omStrArraySigName.Add(omFormatString);
                    }
                }
            }
        }
        bReturn = TRUE;
    }
    return bReturn;
}