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

📄 dvb_log.c

📁 DVB软件,基于CT216软件的开发源程序.
💻 C
📖 第 1 页 / 共 2 页
字号:
					}
				}
				
			} /* if(b8OpenFile == FALSE) */						
		}
		
	}
}

bool8 DVB_Log_Suspend(void)
{
	if(_b8Log_Suspend == FALSE)
	{
		DVB_LogDebugSuspend();
		
		if(EN_CTOS_SUCCESS != CT_OS_SuspendTask(&stLogTaskCtrlBlk))
		{
			return FALSE;
		}

		_b8Log_Suspend = TRUE;

	}

	return TRUE;
}

bool8 DVB_Log_Resume(void)
{
	if(_b8Log_Suspend == TRUE)
	{
		if(EN_CTOS_SUCCESS != CT_OS_ResumeTask(&stLogTaskCtrlBlk))
		{
			return FALSE;
		}

		_b8Log_Suspend = FALSE;
	}
	
	return TRUE;
}

void DVB_LogPowerOn(void)
{
	b8SetDevice = FALSE;
	b8OpenFile = FALSE;
	
	if(DVB_Log_Resume() == FALSE)
	{
		LOG_PRINT(("\n>> [USRDLOG] Log task resume fail <<\n"));
	}		
}

void DVB_LogStandby(void)
{
	if(b8FileExist == TRUE)
	{	
		if(b8ChangeToBuff2 == TRUE)
		{
			if(u32Buff2Idx != 0)
			{
				LOG_PRINT(("\n>> FileWrite BUFF_2 <<\n"));
				DVB_DEVCTRL_HoldFs(TRUE, _enLogMediaType);
				DVB_FILECTRL_FileWrite(_enDeviceType, _u32LogFileHandle, u32Buff2Idx, au8Buff2);
				DVB_DEVCTRL_HoldFs(FALSE, _enLogMediaType);
				memset(au8Buff2, 0, (sizeof(au8Buff2)));
				u32Buff2Idx = 0;
			}	
		}
		else
		{
			if(u32Buff1Idx != 0)
			{
				LOG_PRINT(("\n>> FileWrite BUFF_1 <<\n"));
				DVB_DEVCTRL_HoldFs(TRUE, _enLogMediaType);
				DVB_FILECTRL_FileWrite(_enDeviceType, _u32LogFileHandle, u32Buff1Idx, au8Buff1);
				DVB_DEVCTRL_HoldFs(FALSE, _enLogMediaType);
				memset(au8Buff1, 0, (sizeof(au8Buff1)));
				u32Buff1Idx = 0;
			}	
		}

		DVB_DEVCTRL_HoldFs(TRUE, _enLogMediaType);
		DVB_FILECTRL_FileClose(_enDeviceType, _u32CmdFileHandle);
		DVB_FILECTRL_FileClose(_enDeviceType, _u32LogFileHandle);
		DVB_FILECTRL_Flush_FS(_enDeviceType);
		DVB_DEVCTRL_HoldFs(FALSE, _enLogMediaType);
		LOG_PRINT(("\n>> DVB_FILECTRL_FileClose: %ld <<\n", _u32CmdFileHandle));
		LOG_PRINT(("\n>> DVB_FILECTRL_FileClose: %ld <<\n", _u32LogFileHandle));
	}	
		
	if(DVB_Log_Suspend() == FALSE)
	{
		LOG_PRINT(("\n>> [USRDLOG] Log task suspend fail <<\n"));
	}			
}

bool8 DVB_LogGetStatus(void)
{
	return b8OpenFile;
}

/************************************************************************
 * UserLogDebug task function.
 ************************************************************************/
void DVB_LogDebugInitialStart(void)
{
	u32LoopIndex = 0;
	u8LoopTimes = 0;
	u8StartIndex = LOGMEMSIZE;
	enParserState = EN_STATE_INT;
	memset(au8size, 0, LOGMEMSIZE+1);
}
void DVB_LogDebugSuspend(void)
{
	enParserState = EN_STATE_OTHER;
}
void DVB_LogDebugTask (u32 u32Argc, void * pArgv)
{
	u32 i;
	
	while(TRUE)
	{
		if(EN_CTOS_SUCCESS==CT_OS_WaitOnSemaphore(&LogDebugSemore,CTOS_WAIT))
		{
			while(	enParserState != EN_STATE_OTHER)
			{
				//  Parser the format code   Format is " (Time(s)):(Command)"
				DVB_DEVCTRL_HoldFs(TRUE, _enLogMediaType);
				if( !(u32size = DVB_FILECTRL_FileRead (_enDeviceType, _u32CmdFileHandle, u8StartIndex, &au8size[LOGMEMSIZE-u8StartIndex]) ))
				{
					enParserState = EN_STATE_OTHER;
					DVB_DEVCTRL_HoldFs(FALSE, _enLogMediaType);
					LOG_PRINT((">>>Read Cmd file error at[%d] u8StartIndex %d\n",__LINE__,u8StartIndex));
					continue;
				}
				DVB_DEVCTRL_HoldFs(FALSE, _enLogMediaType);
				au8size[LOGMEMSIZE-u8StartIndex+u32size]='\0';

				// STATE        INT          CMDSTR     CMDOVR
				// 	         Wait Time  :  Command Code
				for(u8Index=0,u8StartIndex=0;u8Index<LOGMEMSIZE;u8Index++)
				{
					switch(au8size[u8Index])
					{
						default:
							if(enParserState == EN_STATE_CMDOVR)
								enParserState = EN_STATE_INT;
							break;
						case '?':		//randon Time
							if(enParserState == EN_STATE_INT)
							{
								au8size[u8Index]='\0';
								u32waittime = DVB_Random()%(_atoi(&au8size[u8StartIndex])+1);
								u8StartIndex = u8Index+1;
								enParserState = EN_STATE_CMDSTR;
							}
							break;
						case ':':
							if(enParserState == EN_STATE_INT)
							{
								au8size[u8Index]='\0';
								u32waittime = _atoi(&au8size[u8StartIndex]);
							}
							u8StartIndex = u8Index+1;
							enParserState = EN_STATE_CMDSTR;
							break;	
						case '{':		//for loop start
							if(enParserState == EN_STATE_INT)
							{
								DVB_DEVCTRL_HoldFs(TRUE, _enLogMediaType);
								u32LoopIndex = DVB_FILECTRL_GetCurrentReadPosition(_enDeviceType, _u32CmdFileHandle)-u32size+u8Index+1;
								DVB_DEVCTRL_HoldFs(FALSE, _enLogMediaType);
								au8size[u8Index]='\0';
								u8LoopTimes = _atoi(&au8size[u8StartIndex]);
							}
							break;
						case '}':		//for loop back
							if( 0 != u8LoopTimes)
							{
								u8LoopTimes--;
								LOG_PRINT(("\n[%4d]%s",u8LoopTimes,__FILE__));
								DVB_DEVCTRL_HoldFs(TRUE, _enLogMediaType);
								DVB_FILECTRL_FileSeek(_enDeviceType, _u32CmdFileHandle, u32LoopIndex, EN_FILE_START);
								DVB_DEVCTRL_HoldFs(FALSE, _enLogMediaType);
								u8StartIndex = LOGMEMSIZE;
								memset(&au8size[0],0x20,LOGMEMSIZE);
							}
							break;
						case '\n':
						case '\r':
							if(enParserState == EN_STATE_CMDSTR)
							{
								au8size[u8Index]='\0';
								strcpy(au8command,&au8size[u8StartIndex]);
								GetCommand = TRUE;
							}
							u8StartIndex = u8Index+1;
							enParserState = EN_STATE_CMDOVR;
							break;
						case '\0':		//end
							if(enParserState == EN_STATE_CMDSTR)
							{
								strcpy(au8command,&au8size[u8StartIndex]);
								GetCommand = TRUE;
							}
							enParserState = EN_STATE_OTHER;
							break;	
					}
					if(TRUE == GetCommand)
					{	

						EN_SWITCH_DEBUG enSaveSwitchDebug=0;
						u8 j,k;
						GetCommand = FALSE;

						// Switch Debug Mode
						enSaveSwitchDebug = DVB_GetUserDebugMode();
						DVB_SetUserDebugMode(EN_SYSTEM_DEBUG);

						// set command and wait
						CT_UART_PutString("\n\rCDAT !!");
						CT_UART_PutString(au8command);
						CT_UART_PutString("\n\rCDAT >>");
						if (Usrdebug_ParseCommand(&au8command[0], &u8ArgcLOG, (u8 *)au8ArgvLOG) == DRV_OK)
						{
							if (Usrdebug_ExecuteCommand((u8 *)au8ArgvLOG) == DRV_OK)
							{
								LOG_PRINT(("\n\r[LOGLOGDEBUG]%s OK", au8ArgvLOG[0]));
								//				LOG_PRINT(("\n\rCDAT >>"));
							}else
							{
								LOG_PRINT(("\n\r[LOGLOGDEBUG] no command %s", au8ArgvLOG[0]));
							}
							/*
							 * Clean argv and argc.
							 */
							for (j = 0; j < u8ArgcLOG; j++)
							{
								for (k = 0; k < DEBUG_MAX_ARGV_LENGTH; k++)
								{
									au8ArgvLOG[j][k] = 0;
								}
							}
							u8ArgcLOG = 0;
						}
						DVB_SetUserDebugMode(enSaveSwitchDebug);
						
#if 0
						CT_OS_Delay(u32waittime*100);
#else
						/*
						 * Wait u32waittime seconds, but check the state per second.
						 * For example, if the wait time is 30s, after calling DVB_LogStandby(), 
						 * task is still in CT_OS_Delay(), but we want the task stops the job.
						 * So check the state per second to break the loop.
						 */
						for (i = 0; i < u32waittime; i++)
						{
							CT_OS_Delay(100);
							if(enParserState == EN_STATE_OTHER)
							{
								break;
							}
						}
#endif
					}
					if(enParserState == EN_STATE_OTHER)
					{
						CT_UART_PutString("\n\rReadFileOver");
						break;
					}
				}
				memcpy(&au8size[0],&au8size[u8StartIndex],LOGMEMSIZE-u8StartIndex);
			}
		}
	}
}

/************************************************************************
 * UserLog initialized function.
 ************************************************************************/
EN_DRV_RESULT DVB_LOG_Initial(void)
{
	EN_CTOS_STATUS enOsResult = EN_CTOS_SUCCESS;
	
	u32Buff1Idx = 0;
	u32Buff2Idx = 0;
	memset(au8Buff1, 0, (sizeof(au8Buff1)));
	memset(au8Buff2, 0, (sizeof(au8Buff2)));
		
    if(EN_CTOS_SUCCESS != CT_OS_CreateMsgQueue(&LOG_Request_MsgQueue, 
        "LOGQ", &u32LOGRequestQueueMsg[0], LOG_QUEUE_SIZE, EN_CTOS_SUSPEND_FIFO))
	{
		LOG_PRINT(("    [ERROR]: %s - CreateRequestMsgQueue error\n", __FUNCTION__));
		return (DRVERR_NOTOK);
	}	
	
	if (b8LogTaskCreated == FALSE)
	{
		enOsResult = CT_OS_CreateTask(& stLogTaskCtrlBlk,
										"DVBLOG",
										DVB_LogTask,
										& au8LogTaskStack[0],
										DVB_LOG_TASK_STACK_SIZE,
										DVB_LOG_TASK_PRIORITY,
										DVB_LOG_TASK_TIMESLICE);

		if (enOsResult == EN_CTOS_SUCCESS)
		{
			b8LogTaskCreated = TRUE;
		}
		else
		{
			CT_OS_DeleteMsgQueue(&LOG_Request_MsgQueue);
			LOG_PRINT((">> [USRDLOG] Log Task Create Fail \n"));
			return (DRVERR_NOTOK);
		}	
	}
	
	if (EN_CTOS_SUCCESS != CT_OS_ResumeTask(&stLogTaskCtrlBlk))
	{
		CT_OS_DeleteMsgQueue(&LOG_Request_MsgQueue);
		LOG_PRINT(("\n>> [USRDLOG] Log Task Resume Fail \n"));
		return (DRVERR_NOTOK);
	}
	
	if(DRV_OK != RegisterEventFunc(fnDeviceLogCallback))
	{
		LOG_PRINT(("\n>> [USRDLOG] LOG_RegisterEventFunc Error \n"));
	}

	if(EN_CTOS_SUCCESS!=CT_OS_CreateSemaphore(&LogDebugSemore,"LogDebug",0, EN_CTOS_SUSPEND_FIFO))
	{
		LOG_PRINT(("\n\r>>Error, CT_OS_CreateSemaphore"));
        return (DRVERR_NOTOK);                      
	}

	if (b8LogDebugTaskCreated == FALSE)
	{
		enOsResult = CT_OS_CreateTask(& stLogDebugTaskCtrlBlk,
										"DVBLOGDebug",
										DVB_LogDebugTask,
										& au8LogDebugTaskStack[0],
										DVB_LOGDEBUG_TASK_STACK_SIZE,
										DVB_LOGDEBUG_TASK_PRIORITY,
										DVB_LOGDEBUG_TASK_TIMESLICE);

		if (enOsResult == EN_CTOS_SUCCESS)
		{
			b8LogDebugTaskCreated = TRUE;
		}
		else
		{
			LOG_PRINT((">> [USRDLOG] LogDebug Task Create Fail \n"));
			return (DRVERR_NOTOK);
		}
	}
	if (EN_CTOS_SUCCESS != CT_OS_ResumeTask(&stLogDebugTaskCtrlBlk))
	{
		return (DRVERR_NOTOK);
	}
		
	LOG_PRINT(("\n>> [USRDLOG] DVB_LogInitial success \n"));
	return (DRV_OK);
} /* end DVB_LogInitial */

⌨️ 快捷键说明

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