⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 routelink_cmn.c

📁 本程序的功能是对导航数据中的道路情况数据进行整理
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		S_LNKDATA_DSP*		:	Route link info data file[IN]			   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯RET_SUCCESS					   */
/*								乮Error乯 RET_FAILED					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Convert route link data to string, return the address of the	   */
/*		string buffer .	(The buffer for string saving will be allocated,   */
/*		so please make sure that the free function will be called after	   */
/*		finishing using the string buffer.)								   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
BYTE* routelink_linkdata2dspstr(
	S_LNKDATA_DSP*		pstRsltData		/* I/ Route link info data file	   */
	)
{
	int					iDspStrLen	= 0;
						/* The lenth of the string displayed			   */
	BYTE*				pbDspStr	= NULL;
						/* Buffer for displayed string					   */
	BYTE				abDspStrBuf[RL_DSPSTR_MAXLEN];
						/* Temporary area for getting string			   */


	/* Exception prevention						*/
	if( NULL == pstRsltData )
	{
		return (BYTE*)NULL;
	}

	/* Display string buffer initialization		*/
	memset( abDspStrBuf, 0, sizeof(abDspStrBuf) );

	/* Cat the string for displaying			*/
	if( NULL != pstRsltData->pstRoadName )
	{
		/* Road name exist						*/
		sprintf( abDspStrBuf, 
			"#linkid=%d;roadnameflag=%d;brunch=%d;dispclass=%d;roadname=%s#",
			pstRsltData->udwLinkID,
			pstRsltData->bRoadNameFlg,
			pstRsltData->bBranchNum,
			pstRsltData->bDspClass,
			pstRsltData->pstRoadName->pbStr
			);
	}
	else
	{
		/* Road name does not exist				*/
		sprintf( abDspStrBuf, 
			"#linkid=%d;roadnameflag=%d;brunch=%d;dispclass=%d#",
			pstRsltData->udwLinkID,
			pstRsltData->bRoadNameFlg,
			pstRsltData->bBranchNum,
			pstRsltData->bDspClass
			);
	}

	/* End character appended(Only for ensuring)*/
	abDspStrBuf[RL_DSPSTR_MAXLEN - 1] = '\0';
	iDspStrLen = strlen( abDspStrBuf ) + 1;

	/* Display buffer area allocation			*/
	pbDspStr = (BYTE*)malloc( iDspStrLen );
	if( NULL != pbDspStr )
	{
		memset( pbDspStr, 0, iDspStrLen );
		strncpy( pbDspStr, abDspStrBuf, iDspStrLen );
	}

	return pbDspStr;
}

/***************************************************************************/
/*	routelink_dspstr2linkdata()											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		S_LNKDATA_DSP*		:	Route link info data file[IN]			   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	乮Normal乯RET_SUCCESS					   */
/*								乮Error乯 RET_FAILED					   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Convert displaying string to route link data, return the address   */
/*		of the Link data buffer.										   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
BYTE* routelink_dspstr2linkdata(
	BYTE*				pbDspStr			/* I/ Displayed string		   */
	)
{
	UWORD				uwRecSize	= 0;	/* Record size				   */
	UWORD				uwRNameSize	= 0;	/* Road name size			   */
	UDWORD				udwNodeInfo	= 0;	/* Start node info			   */

	int					iDspStrLen	= 0;	/* Displayed string lenth	   */
	int					iLoop		= 0;	/* Loop counter				   */
	int					iField		= 0;	/* Current field			   */
	int					iNextField	= 0;	/* Next field				   */
	int					iBufScript	= 0;	/* Subscript of array		   */
	int					iLinkID		= 0;	/* Link ID					   */
	int					iNameFlg	= 0;	/* Name flag				   */
	int					iBranchNum	= 0;	/* Branch number			   */
	int					iDspClassNo	= 0;	/* Display class No.		   */

	BYTE*				pbLinkData	= NULL;	/* Link data buffer			   */
	UWORD*				puwPntr		= NULL;	/* UWORD type data buffer	   */
	UDWORD*				pudwPntr	= NULL;	/* UDWORD type data buffer	   */
	BYTE				abBuffer[RL_DSPSTR_MAXLEN];	/* Buffer for string   */



	/* Exception prevention					*/
	if( NULL == pbDspStr )
	{
		return (BYTE*)NULL;
	}

	/* Get the lenth of displayed string	*/
	iDspStrLen = strlen( pbDspStr );

	/* Buffer initialization				*/
	iNextField	= 0;
	memset( abBuffer, 0, sizeof(abBuffer) );

	/* Record size calculating				*/
	for( iLoop = 0; iLoop < iDspStrLen; iLoop++ )
	{
		/* "=" means the begin of a new field	*/
		if( '=' == pbDspStr[iLoop] )
		{
			iField++;
			iBufScript = 0;
			continue;
		}

		switch( iField )
		{
		case 1:		/* Link ID					*/
			if( iNextField > iField )
			{
				break;
			}

			if( ';' != pbDspStr[iLoop] )
			{
				abBuffer[iBufScript] = pbDspStr[iLoop];
				iBufScript++;
			}
			else
			{
				iLinkID = routelink_cmn_str2num( abBuffer );
				memset( abBuffer, 0, sizeof(abBuffer) );
				iNextField = iField + 1;
			}
			break;

		case 2:		/* Road name exist flag		*/
			if( iNextField > iField )
			{
				break;
			}

			if( ';' != pbDspStr[iLoop] )
			{
				abBuffer[iBufScript] = pbDspStr[iLoop];
				iBufScript++;
			}
			else
			{
				iNameFlg = routelink_cmn_str2num( abBuffer );
				memset( abBuffer, 0, sizeof(abBuffer) );
				iNextField = iField + 1;
			}
			break;

		case 3:		/* Branch number			*/
			if( iNextField > iField )
			{
				break;
			}

			if( ';' != pbDspStr[iLoop] )
			{
				abBuffer[iBufScript] = pbDspStr[iLoop];
				iBufScript++;
			}
			else
			{
				iBranchNum = routelink_cmn_str2num( abBuffer );
				memset( abBuffer, 0, sizeof(abBuffer) );
				iNextField = iField + 1;
			}
			break;

		case 4:		/* Displayed class No.		*/
			if( iNextField > iField )
			{
				break;
			}

			if( ';' != pbDspStr[iLoop] )
			{
				abBuffer[iBufScript] = pbDspStr[iLoop];
				iBufScript++;
			}
			else
			{
				iDspClassNo = routelink_cmn_str2num( abBuffer );
				memset( abBuffer, 0, sizeof(abBuffer) );
				iNextField = iField + 1;
			}
			break;

		case 5:		/* Road Name				*/
			if( iNextField > iField )
			{
				break;
			}

			if( 1 == iNameFlg )
			{
				strncpy( abBuffer, &pbDspStr[iLoop], sizeof(abBuffer) );
				if( '#' == abBuffer[strlen(abBuffer)] )
				{
					abBuffer[strlen(abBuffer)] = '0';
				}
				uwRNameSize = (UWORD)strlen(abBuffer);
			}
			iNextField = iField + 1;
			break;

		default:	/* Char before Link ID		*/
			break;
		}
	}

	/* Record size get								*/
	uwRecSize = (UWORD)(RL_OFFSET_ROADNAME + uwRNameSize);

	/* Node info get								*/
	udwNodeInfo = ( (iNameFlg & 0x0000000f) << 7 )   |
				  ( (iBranchNum & 0x0000000f) << 4 ) |
				  ( iDspClassNo & 0x0000000f );

	/* LinkData area allocation						*/
	pbLinkData	= (BYTE*)malloc( uwRecSize );
	if( NULL != pbLinkData )
	{
		/* Record size set							*/
		puwPntr	= (UWORD*)pbLinkData;
		*puwPntr = (UWORD)( (( uwRecSize & 0xff00 ) >> 8) | 
					 (( uwRecSize & 0x00ff ) << 8) );


		/* Link ID set								*/
		pudwPntr	= (UDWORD*)(pbLinkData + RL_OFFSET_LNKID);
		*pudwPntr	= ( ((iLinkID & 0x000000ff) << 24) |
						((iLinkID & 0x0000ff00) << 8)  |
						((iLinkID & 0x00ff0000) >> 8)  |
						((iLinkID & 0xff000000) >> 24) );

		/* Name size set							*/
		puwPntr		= (UWORD*)(pbLinkData + RL_OFFSET_NAMESIZE);
		*puwPntr	= (UWORD)( ((uwRNameSize & 0x00ff) << 8) |
						((uwRNameSize & 0xff00) >> 8) );

		/* Node info set							*/
		pudwPntr	= (UDWORD*)(pbLinkData + RL_OFFSET_NODEINF);
		*pudwPntr	= (udwNodeInfo & 0x000000ff) << 24;

		/* Road name set							*/
		strncpy( (pbLinkData + RL_OFFSET_ROADNAME), abBuffer, uwRNameSize );
	}


	return pbLinkData;
}

/***************************************************************************/
/*	routelink_linkdatafree()											   */
/*	-----------------------------------------------------------------------*/
/*	Input:																   */
/*		BYTE**				:	Route link data area[IN]				   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Output:																   */
/*		RETURN				:	RET_SUCCESS								   */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Outline:															   */
/*		Free the area for link data created from display string.		   */
/*		This if the free function for function routelink_linkdata2dspstr.  */
/*																		   */
/*	-----------------------------------------------------------------------*/
/*	Others:																   */
/*																		   */
/***************************************************************************/
int routelink_linkdatafree(
	BYTE**				pbLinkData		/* I/ Link data area			   */
	)
{
	/* Exception prevention				*/
	if( NULL == pbLinkData )
	{
		return RET_SUCCESS;
	}

	/* LinkData area free				*/
	free( *pbLinkData );
	*pbLinkData = NULL;

	return RET_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -