McpBool _MCP_CONFIG_PARSER_IsSection (McpU8 *pLine)
{
    McpU32      uIndex, uLen;

    uLen = MCP_HAL_STRING_StrLen ((const char *)pLine);

    /* trim starting white spaces */
    uIndex = 0;
    while ((uIndex < uLen) && (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uIndex ])))
    {
        uIndex++;
    }

    /* check if first character is an opening square bracket */
    if ('[' != pLine[ uIndex ])
    {
        return MCP_FALSE;
    }

    /* trim ending white spaces */
    uIndex = uLen - 1;
    while ((uIndex > 0) && (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uIndex ])))
    {
        uIndex--;
    }

    /* check if last character is a closing square bracket */
    if (']' != pLine[ uIndex ])
    {
        return MCP_FALSE;
    }

    return MCP_TRUE;
}
void _MCP_CONFIG_PARSER_GetSectionName (McpU8* pLine, McpU8* pName)
{
    McpU32 uStartIndex, uCloseIndex, uIndex;

    /* find starting index: trim heading white spaces */
    uStartIndex = 0;
    uCloseIndex = MCP_HAL_STRING_StrLen ((const char *)pLine) - 1;
    while ((uStartIndex <= uCloseIndex) && 
           (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uStartIndex ])))
    {
        uStartIndex++;
    }

    /* than opening square bracket */
    uStartIndex++;

    /* and again trim white space */
    while ((uStartIndex <= uCloseIndex) && 
           (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uStartIndex ])))
    {
        uStartIndex++;
    }

    /* find finishing index: trim trailing white spaces */
    while ((uCloseIndex > 0) && 
           (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uCloseIndex ])))
    {
        uCloseIndex--;
    }

    /* than closing square bracket */
    uCloseIndex--;

    /* and again trim white space */
    while ((uCloseIndex > 0) && 
           (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uCloseIndex ])))
    {
        uCloseIndex--;
    }

    /* now copy from starting index to finishing index */
    uIndex = uStartIndex;
    while (uIndex <= uCloseIndex)
    {
        pName[ uIndex - uStartIndex ] = pLine[ uIndex ];
        uIndex++;
    }
    pName[ uIndex - uStartIndex ] = '\0';
}
/*
    Utility function that formats a number as a string

    [ToDo] - Duplicate of a function in FMC_Utils - Consider making an infrastructure utility function
*/
const char *_MCP_BTS_SP_FormatNumber(const char *formatMsg, McpUint number, char *tempStr,McpUint maxTempStrSize)
{
    McpU16 formatMsgLen;
    formatMsgLen=MCP_HAL_STRING_StrLen(formatMsg);

    /*Verfiy that the tempStr allocation is enough  */
    if ((McpU16)(formatMsgLen+MAX_MCP_UINT_SIZE_IN_ASCII)>maxTempStrSize)
        {            
            return invalidMcpempStr;
        }    

    MCP_HAL_STRING_Sprintf(tempStr, formatMsg, number);

    return tempStr;
}
Example #4
0
const char * FMC_UTILS_FormatNumber(const char *formatMsg, FMC_UINT number, char *tempStr,FMC_UINT maxTempStrSize)
{
    FMC_U16 formatMsgLen;
    formatMsgLen=MCP_HAL_STRING_StrLen(formatMsg);

    /*Verify that the tempStr allocation is enough  */
    if ((FMC_U16)(formatMsgLen+MAX_FMC_UINT_SIZE_IN_ASCII)>maxTempStrSize)
        {            
            return invalidFmcTempStr;
        }
    

    MCP_HAL_STRING_Sprintf (tempStr, formatMsg, number);

    return tempStr;
}
McpBool _MCP_CONFIG_PARSER_IsEmptyLine (McpU8 *pLine)
{
    McpU32      uIndex, uLen;

    uLen = MCP_HAL_STRING_StrLen ((const char *)pLine);

    /* trim starting white spaces */
    uIndex = 0;
    while ((uIndex < uLen) && (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uIndex ])))
    {
        uIndex++;
    }

    if (uIndex == uLen)
    {
        return MCP_TRUE;
    }
    else
    {
        return MCP_FALSE;
    }
}
void _MCP_CONFIG_PARSER_GetKeyValue (McpU8 *pLine, McpU8 *pValue)
{
    McpU32 uStartIndex, uCloseIndex, uIndex;

    uStartIndex = 0;
    uCloseIndex = MCP_HAL_STRING_StrLen ((const char *)pLine) - 1;

    /* find finishing index: find equation sign */
    while ((uStartIndex <= uCloseIndex) && ('=' != pLine[ uStartIndex ]))
    {
        uStartIndex++;
    }
    uStartIndex++;

    /* and than trim leading white spaces */
    while ((uStartIndex <= uCloseIndex) && 
           (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uStartIndex ])))
    {
        uStartIndex++;
    }

    /* find finishing index: trim trailing white spaces */
    while ((uCloseIndex > 0) && 
           (MCP_TRUE == _MCP_CONFIG_PARSER_IsWhiteSpace (pLine[ uCloseIndex ])))
    {
        uCloseIndex--;
    }

    /* now copy key name */
    uIndex = uStartIndex;
    while (uIndex <= uCloseIndex)
    {
        pValue[ uIndex - uStartIndex ] = pLine[ uIndex ];
        uIndex++;
    }
    pValue[ uIndex - uStartIndex ] = '\0';
}
/**
 * \fn     HAL_ST_Init
 * \brief  HAL ST object initialization
 *
 * Initiate state of HAL ST object
 *
 */
EMcpfRes HAL_ST_Init ( 	handle_t                    			hHalSt,
                      			const HalST_EventHandlerCb 	fEventHandlerCb,
                          			const handle_t            			hHandleCb,
                          			const THalSt_PortCfg          		*pConf,
                          			const char					*pDevName,
                          			McpU8                     			*pBuf,
                          			const McpU16              			len,
                          			McpBool						bIsBlockOnWrite)
{
    THalStObj  *pHalSt = (THalStObj *) hHalSt;
    EMcpfRes      status;

    /** Used when ST input buffer has to be flushed
      * McpU8 *pBuffer;
      * McpU16 lengthToBeRead = 1; */

    pHalSt->fEventHandlerCb = fEventHandlerCb;
    pHalSt->hHandleCb = hHandleCb;
    /* Data will be read into this buffer */
    pHalSt->pInData = pBuf;
    pHalSt->iRxReadNum  = len;
    pHalSt->bIsBlockOnWrite = bIsBlockOnWrite;

    if(pConf)
		mcpf_mem_copy(pHalSt->hMcpf, &pHalSt->tPortCfg, (void *)pConf, sizeof(THalSt_PortCfg));

    if(pDevName)
		mcpf_mem_copy(pHalSt->hMcpf, pHalSt->devFileName, (void *)pDevName, 
						MCP_HAL_STRING_StrLen(pDevName));
    else
    {
    		MCPF_REPORT_ERROR(pHalSt->hMcpf, HAL_ST_MODULE_LOG, ("HAL_ST_Init: Missing device Name to open\n") );
		return RES_ERROR;
    }
    status = stPortInit (pHalSt);

    if (status != RES_OK)
    {
        MCPF_REPORT_DEBUG_CONTROL(pHalSt->hMcpf, HAL_ST_MODULE_LOG, ("stPortInit failed!\n") );
        if (pHalSt->hOsPort)
        {
            close(pHalSt->hOsPort);
        }
        halStDestroy (pHalSt);
        return RES_ERROR;
    }

    /* Flush the com port buffer.
     * Ideally not required as this is done in stPortInit()*/
    /* stPortRxReset (pHalSt, pBuffer, lengthToBeRead); */

    MCPF_REPORT_DEBUG_CONTROL(pHalSt->hMcpf, HAL_ST_MODULE_LOG, ("HAL_ST_Init: create thread, hHalSt=%p \n", hHalSt));

    /* Used for exiting from ST thread */
    pHalSt->terminationFlag = MCP_FALSE;

    /* If recevied 'bIsBlockOnWrite' is TRUE --> no need for RX thread (will be working in Block on Write Mode) */
    if(pHalSt->bIsBlockOnWrite == MCP_FALSE)
    {
	    if(pthread_create( &pHalSt->hOsThread,           /* Thread handle */
	                       NULL,                           /* Default attributes */
	                       stThreadFun,                  /* Function */
	                       pHalSt) != NUMBER_ZERO)    /* Thread function parameter */
	    {
	          MCPF_REPORT_ERROR (pHalSt->hMcpf, HAL_ST_MODULE_LOG, ("pthread_create failed!\n"));
	          if (pHalSt->hOsPort)
	          {
	            close(pHalSt->hOsPort);
	          }

	          halStDestroy (pHalSt);
	          return RES_ERROR;
	    }

	    MCPF_REPORT_DEBUG_CONTROL(pHalSt->hMcpf, HAL_ST_MODULE_LOG, ("HAL_ST_Init: waiting for ST thread initialization completion ...\n"));
	    /* wait for completion of thread initialization */
	    waitForSem (pHalSt->hMcpf, &pHalSt->tSem);
	    MCPF_REPORT_DEBUG_CONTROL(pHalSt->hMcpf, HAL_ST_MODULE_LOG, ("HAL_ST_Init: ST thread initialization is completed\n"));
    }

    return status;
}