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

📄 parse.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 3 页
字号:
				{
					if (++un32Adapter <= TB640_FSK_MAX_SUPPORTED_ADAPTERS)
					{
						fAdapterGroup = TBX_TRUE;
						g_AppContext->un32NbAdapter++;
						strcpy (g_AppContext->ahAdapterInfo [un32Adapter].szAdapterName, pszArgument);
					}
					else
					{
						TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, (pszToken-pszLine), pszLine, "Too many adapter group");
						TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
					}
				}
				else
				{
					TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, (pszToken-pszLine), pszLine, "Unexpected .ADAPTER group start");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				break;

			case TB640_FSK_PARSING_TOKEN_GW_PORT:
			{
				int iGwPort;
				sscanf( pszArgument, "%d", &iGwPort );
				g_AppContext->un16GwPort = iGwPort;
			}	break;

			/* Param group start flag processing */
			case TB640_FSK_PARSING_TOKEN_PARAMS_GROUP_START:
				if ((fParamGroup == TBX_FALSE) && (fAdapterGroup == TBX_FALSE))
					fParamGroup = TBX_TRUE;
				else
				{
					TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, (pszToken-pszLine), pszLine, "Unexpected .PARAMS group start");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				break;

			/* Group end flag processing */
			case TB640_FSK_PARSING_TOKEN_GROUP_END:
				if (fParamGroup != TBX_FALSE)
					fParamGroup = TBX_FALSE;
				else if (fAdapterGroup != TBX_FALSE)
					fAdapterGroup = TBX_FALSE;
				else
				{
					TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, (pszToken-pszLine), pszLine, "Unexpected .END");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				break;

			/* Trunk configuration line processing */
			case TB640_FSK_PARSING_TOKEN_TRUNK_CONFIG:
			{
				TBX_UINT32 un32TrunkNb;

				TB640_FSK_PARSE_TRUNK_LINE_VALIDATE (TB640_FSK_PARSING_TOKEN_TRUNK_CONFIG);

				/* Process the trunk configuration */
				result = TB640FskParseTrunkConfigurationLine
				(
					pszArgument,
					pszLine,
					un32Line,
					(pszArgument-pszLine),
					un32Adapter,
					&un32TrunkNb
				);
				if (TBX_RESULT_FAILURE (result))
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
			} break;

			/* "Log filename" line processing */
			case TB640_FSK_PARSING_TOKEN_LOG_FILENAME:
			{
				TBX_CHAR		szNewFilename [128];
				time_t			tTime;
				struct tm *		pTime;


				TB640_FSK_PARSE_PARAMS_LINE_VALIDATE();

				/* Open the log file */
				TB640FskToLower (pszArgument);

				strncpy (g_AppContext->szFilename, pszArgument, sizeof (g_AppContext->szFilename));
				g_AppContext->szFilename[ sizeof (g_AppContext->szFilename) - 1 ] = '\0';

				/* Keep space for _%d at the end of filename */
				g_AppContext->szFilename [sizeof (g_AppContext->szFilename)-8] = '\0';

				sprintf (szNewFilename, "%s_%d", g_AppContext->szFilename, g_AppContext->un32LogNumber++ );

				g_AppContext->pLogFile = fopen (szNewFilename, "w+");
				if (NULL == g_AppContext->pLogFile)
				{
					TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to open log file");
				}

				/* Get the time of day */
				time (&tTime);
				pTime = localtime( &tTime );

				/* Print a string to the log file... */
				TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "FSK sample application\n");
				TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Copyright (c)2003 by Telcobridges inc.\n");
				TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Application instance run on %s", asctime(pTime));
				TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "----------------------------------------------------------------\n\n");
			}
			break;

			/* Log file level processing */
			case TB640_FSK_PARSING_TOKEN_LOG_FILE_LEVEL:
				g_AppContext->un32FileLogLevel = atoi (pszArgument);
				fLogFileLevelPresent = TBX_TRUE;
				break;

			/* Log display level processing */
			case TB640_FSK_PARSING_TOKEN_LOG_DISPLAY_LEVEL:
				g_AppContext->un32DisplayLogLevel = atoi (pszArgument);
				fLogDisplayLevelPresent = TBX_TRUE;
				break;

			/* Minimum refresh rate */
			case TB640_FSK_PARSING_TOKEN_MIN_REFRESH:
				g_AppContext->un32MinRefreshDelayMsec = atoi (pszArgument);
				fRefreshRateConfigured = TBX_TRUE;
				break;


			case TB640_FSK_PARSING_TOKEN_UNKNOWN:
			default:
				TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, 0, pszLine, "Syntax error (unknown token)");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}
		}

		/* Check for mandatory token */
		if (!fLogFileLevelPresent)
		{
			TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, 0, pszLine, "Missing LOG_FILE_LEVEL token");
			TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
		}
		if (!fLogDisplayLevelPresent)
		{
			TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, 0, pszLine, "Missing LOG_DISPLAY_LEVEL token");
			TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
		}
		if (!fRefreshRateConfigured)
		{
			TB640_FSK_PARSE_ERROR_DISPLAY (un32Line, 0, pszLine, "No MIN_REFRESH token found.  Defaulting to 10 msec refresh!");
			g_AppContext->un32MinRefreshDelayMsec = 10;
			fRefreshRateConfigured = TBX_TRUE;
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		/* Close open file */
		if (pFileIn != NULL)
		{
			fclose (pFileIn);
			pFileIn = NULL;
		}
	}

	RETURN;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskParseTrunkConfigurationLine:	Parses the content of a trunk configuration line and stores them into our structure
 |
 |  in_pszLine		:	Pointer to the text line
 |  in_pszOriginalLine:	Pointer to the original text line
 |	in_un32Line		:	Line number in the configuration file
 |	in_un32Index	:	Index of the argument in the original string
 |	in_un32Adapter	:	Adapter index in our internal array
 |	out_pun32TrunkNb:	Pointer to a variable that will contain the trunk number
 |
 |  Note			:	Line must be converted in CAPS
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskParseTrunkConfigurationLine(
  IN		const PTBX_CHAR				in_pszLine,
  IN		const PTBX_CHAR				in_pszOriginalLine,
  IN		TBX_UINT32					in_un32Line,
  IN		TBX_UINT32					in_un32Index,
  IN		TBX_UINT32					in_un32Adapter,
  OUT		PTBX_UINT32					out_pun32TrunkNb)
{
	TBX_CHAR					szLine [TB640_FSK_MAX_CONFIGURATION_LINE_LENGTH];
	TBX_UINT32					un32IdleValue;
	TBX_UINT32					un32Setting;
	TBX_UINT32					un32TrunkNb;
	TBX_UINT32					un32SizeOfEntry;
	PTBX_CHAR					pArg;
	PTB640_FSK_ADAPTER_INFO		pAdapterInfo;
	PTB640_FSK_TRUNK_INFO		pTrunkInfo;
	PTB640_TRUNK_CFG			pTrunkCfg;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		strcpy (szLine, in_pszLine);
		un32Setting = 0;
		un32TrunkNb = 0;
		pTrunkInfo = NULL;
		pTrunkCfg = NULL;

		/* Begin parsing */
		pArg = strtok (szLine, TB640_FSK_LINE_PARSING_DELIMITERS);
		while (NULL != pArg)
		{
			switch (un32Setting)
			{
			/* First argument is the trunk number */
			case 0:
				/* Within range ? */
				un32TrunkNb = atoi (pArg);
				if (un32TrunkNb >= TB640_FSK_MAX_SUPPORTED_TRUNKS_PER_ADAPTER)
				{
					TB640_FSK_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Numbers from 0 to 63 only");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				*out_pun32TrunkNb = un32TrunkNb;
				pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_un32Adapter]);
				pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32TrunkNb]);
				pTrunkCfg = &(pTrunkInfo->TrunkConfiguration);

				/* Trunk already configured ? */
				if (pTrunkCfg->Type != 0)
				{
					TB640_FSK_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Trunk already configured");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}

				/* Initialize parameters not in the configuration file */
				pTrunkCfg->un32StructVersion = 1;
				pTrunkInfo->FskType = TB640_VP_FSK_TYPE_V23;

				break;

			/* Second argument is the trunk type */
			case 1:
				/* Get the trunk type */
				TB640_FSK_PARSE_GET_PARAMETER (g_aParseTrunkTypes, &(pTrunkCfg->Type), "Invalid value. Expecting trunk type [E1/T1/J1]");
				break;

			/* Third argument is the trunk framing */
			case 2:
				TB640_FSK_PARSE_GET_TRUNK_PARAMETER (Framing,												\
				  g_aParseTrunkE1Framing, 		"Invalid value. Expecting framing [DFRAME/MFRAME/AUTO]",	\
				  g_aParseTrunkT1Framing, 		"Invalid value. Expecting framing [SF/ESF/SLC96]",			\
				  g_aParseTrunkJ1Framing,		"Invalid value. Expecting framing [SF/ESF/SLC96]");
				break;

			/* Fourth argument is the trunk encoding */
			case 3:
				TB640_FSK_PARSE_GET_TRUNK_PARAMETER (Encoding,											\
				  g_aParseTrunkE1Encoding, 		"Invalid value. Expecting encoding [HDB3/AMI]",			\
				  g_aParseTrunkT1Encoding, 		"Invalid value. Expecting encoding [B8ZS/AMI/CLEAR]",	\
				  g_aParseTrunkJ1Encoding,		"Invalid value. Expecting encoding [B8ZS/AMI/CLEAR]");
				break;

			/* Fifth argument is the trunk line termination */
			case 4:
				TB640_FSK_PARSE_GET_TRUNK_PARAMETER (Termination,										\
				  g_aParseTrunkE1Termination, 	"Invalid value. Expecting termination [SHORT/LONG]",	\
				  g_aParseTrunkT1Termination, 	"Invalid value. Expecting termination [SHORT/LONG]",	\
				  g_aParseTrunkJ1Termination,	"Invalid value. Expecting termination [SHORT/LONG]");
				break;

			/* Sixth argument is the trunk loop-time setting */
			case 5:
				TB640_FSK_PARSE_GET_TRUNK_PARAMETER (fLoopTime,									\
				  g_aParseBoolean, 				"Invalid value. Expecting loop-time [TRUE/FALSE]",	\
				  g_aParseBoolean, 				"Invalid value. Expecting loop-time [TRUE/FALSE]",	\
				  g_aParseBoolean,				"Invalid value. Expecting loop-time [TRUE/FALSE]");
				break;

			/* Seventh argument is the trunk idle code setting */
			case 6:
				un32IdleValue = atoi (pArg);
				if (un32TrunkNb > TB640_FSK_MAX_IDLE_CODE_VALUE)
				{
					TB640_FSK_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Invalid value. Expecting idle code [0...127]");
					TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				}
				if (pTrunkCfg->Type == TB640_TRUNK_TYPE_E1)
					pTrunkCfg->Cfg.E1.byIdleCode = (TBX_UINT8)un32IdleValue;
				else if (pTrunkCfg->Type == TB640_TRUNK_TYPE_T1)
					pTrunkCfg->Cfg.T1.byIdleCode = (TBX_UINT8)un32IdleValue;
				else
					pTrunkCfg->Cfg.J1.byIdleCode = (TBX_UINT8)un32IdleValue;
				break;

			/* Fsk Type */
			case 7:
				TB640_FSK_PARSE_GET_PARAMETER (g_aParseFskType, &pTrunkInfo->FskType, "Invalid value. Expecting Fsk Type [FSK|B202]");
				break;

			default:
				/* Too many argument found */
				TB640_FSK_PARSE_ERROR_DISPLAY (in_un32Line, (pArg-szLine+in_un32Index), in_pszOriginalLine, "Too many arguments");
				TBX_EXIT_SUCCESS(TBX_RESULT_FAIL);
				break;
			}

			/* Process the next argument */
			un32Setting++;

			/* Get the next token */
			pArg = strtok (NULL, TB640_FSK_LINE_PARSING_DELIMITERS);
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
}




⌨️ 快捷键说明

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