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

📄 appcore.cpp

📁 基于Nuleus操作系统和s3c4510的编写的EFC。已经包含了该EFC的设计说明。这是个实际产品的代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		//Added bella yu 2005/01/25
		pos = strLine.Find('*');
		if (pos != -1)
		{
			bAppFile = TRUE;
			break;
		}
*/		
		// read a line of text
		pos = strLine.Find(';');
		if (pos != -1) 
		{// the string after the ';' is comment
			strLine = strLine.Left(pos) + "\r\n";
		}
		strLine.TrimLeft();
		if (strLine.IsEmpty())
			continue;
		
		if (strLine[0] == '[')
		{// section
			strUnit = strLine.Mid('[', ']');
			if (!strUnit.IsEmpty())
			{
				pSection = FindProfileSection(strUnit);
				if (pSection == NULL) 
				{// create new section
					pSection = new CProfileSection();
					ASSERT(pSection);
					pSection->strSection = strUnit;
					pSection->pNext = m_pSectionHeader;
					m_pSectionHeader = pSection;
				}
			}
		}
		else if (pSection && pSection->nWriteRights >= nRights)
		{// entry
			strUnit = strLine.Mid("", "=");
			strUnit.TrimRight(); // remove blank spaces
			if (!strUnit.IsEmpty()) 
			{
				pEntry = FindProfileEntry(pSection, strUnit);
				if (pEntry == NULL) 
				{// create new profile entry
					pEntry = new CProfileEntry();
					ASSERT(pEntry);
					pEntry->strEntry = strUnit;
					pEntry->pNext = pSection->pEntryHeader;
					pSection->pEntryHeader = pEntry;
				}
				if (pEntry->nWriteRights >= nRights) 
				{// has rights to write value
					pEntry->strValue = strLine.Mid("=", "\r\n");
					pEntry->strValue.TrimLeft();
				}
			}
		}
	}
#ifdef __EFC_MASTER // Added by xbz	
/*
	// Added by bella yu in 2005/01/25
	if (bAppFile)
	{
		if (!m_pcmMessage->CombinationFileToAppConfire(file))
			return FALSE;
		if (!m_pcmMessage->OnFileTransferToApp(m_pcmMessage->OnGetAppInfoToFile(),m_pcmMessage->OnGetInfoToFileLen()))
			return FALSE;
	}
*/	
	if (m_pcuUser)
		m_pcuUser->OnLoadData();	
	if (m_pcmMessage)
		m_pcmMessage->OnLoadData();
#endif
	
	if (m_pcdDevice)
		m_pcdDevice->OnLoadData();

	SetModifiedFlag(FALSE);
	return TRUE;
}

// store all the section-entry link table data to a file
void CRTApp::SaveToFile(CFile &file, int nRights) const
{
	if (nRights == 0)
		return; // no rights to save

	// update sections and entries link table
#ifdef __EFC_MASTER // Added by xbz	
	if (m_pcuUser)
		m_pcuUser->OnSaveData();	
	
	if (m_pcmMessage)
		m_pcmMessage->OnSaveData();
#endif
	if (m_pcdDevice)
		m_pcdDevice->OnSaveData();

	// add comments
	file.WriteLine("; System.ini\r\n; ==========\r\n;");
	file.WriteLine("; This INI file contains information that is necessary for");
	file.WriteLine("; firmware to support a device. The firmware reads this file");
	file.WriteLine("; on startup and when the device changes. The format of the");
	file.WriteLine("; contents may change at any time when the EFC updates.\r\n;");
	file.WriteLine("; The entries have the following format, spaces can be added");
	file.WriteLine("; before or after the equal sign:\r\n;\r\n; <Entry> = <Value>\r\n;");
	file.WriteLine("; The [Device] section contains parameters of the whole device.");
	file.WriteLine("; The [Message] section contains parameters of the communication.");
	file.WriteLine("; The [Users] section contains parameters of system users.");
	file.WriteLine("; Version and built time information:\r\n; ===================================");

	CString strLine;
	strLine.Format("; EFC version: %x.%02x, built time: %s, %s",
		HIBYTE(GetEfcVersion()), LOBYTE(GetEfcVersion()), __TIME__, __DATE__);
	file.WriteLine(strLine);
	strLine.Format("; APP version: %x.%02x, built time: %s, %s", HIBYTE(GetVersion()), 
		LOBYTE(GetVersion()), GetBuiltTime(), GetBuiltDate());
	file.WriteLine(strLine);
#ifdef __EFC_MASTER // Added by xbz	
	if (m_pcmMessage)
	{
		strLine.Format("; MSG version: %x.%02x\r\n", 
			HIBYTE(m_pcmMessage->GetVersion()), LOBYTE(m_pcmMessage->GetVersion()));
		file.WriteLine(strLine);
	}
#endif	
	CProfileSection *pSection = m_pSectionHeader;
	CProfileEntry *pEntry = NULL;
	while (pSection != NULL) 
	{
		if (pSection->nReadRights >= nRights) 
		{// has read rights of this section
			strLine.Format("[%s]", (LPCSTR)pSection->strSection);
			file.WriteLine(strLine); // write section
			pEntry = pSection->pEntryHeader;
			while (pEntry != NULL) 
			{
				if (pEntry->nReadRights >= nRights) 
				{// has read rights of this entry (Modified from Format to FormatW by Bozhong xu in 2006.11.15)
					strLine.FormatW(pEntry->strValue.GetLength() + pEntry->strValue.GetLength() + 10, 
						"%s = %s",
						(LPCSTR)pEntry->strEntry, (LPCSTR)pEntry->strValue);
					file.WriteLine(strLine); // write entry
				}
				pEntry = pEntry->pNext;
			}
			file.WriteLine(""); // "\r\n"
		}
		pSection = pSection->pNext;
	}
	file.WriteLine("; End");
#ifdef __EFC_MASTER // Added by xbz	
	if (m_pcmMessage)
		m_pcmMessage->ReportConsole(m_pcdDevice->GetFlagLoaddef());
#endif
}

// Initialize the application
BOOL CRTApp::InitInstance()
{
		

	return TRUE;
}

///////////////////////////////////////////////////
// The following defined by Bozhong Xu ////////////
// Distributed system
BOOL CRTApp::IsDistributedSystem() const
{
	return m_bDistributed;
}

void CRTApp::SetDistributedSystem(BOOL bDistr)
{
	m_bDistributed = bDistr;
}

// Sub system (Added by Bozhong Xu)
BOOL CRTApp::IsSubSystem() const
{
	return m_bSubsystem;
}

void CRTApp::SetSubSystem(BOOL bSubsys)
{
	m_bSubsystem = bSubsys;
}

// Watchdog
BOOL CRTApp::BeWatchdog() const
{
	return m_bWatchdog;
}

void CRTApp::EnableWatchdog(BOOL bEnable)
{
	m_bWatchdog = bEnable;
}

// RTC (Added by Bozhong Xu)
BOOL CRTApp::BeRTC() const
{
	return m_bRTC;
}

void CRTApp::EnableRTC(BOOL bEnable)
{
	m_bRTC = bEnable;
}
#ifdef __EFC_MASTER // Added by xbz	
// Add event 
void CRTApp::AddEvent(BYTE uType, const void* pBuf, UINT nCount)
{
	if (m_pceEventLog)
	{
		m_pceEventLog->Add(uType, pBuf, nCount);		
	}
}
#endif
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Return Value:
//		Version of the application. High byte is the major version and low byte 
//		is the minor version. The version number is in BCD format.
// Remarks:
//		Retrieves the version of the application
WORD CRTApp::GetVersion() const
{// default version: V1.03
	return 0x0100;
}


///////////////////////////////////////////////////////////////////////////////
// Return Value:
//		A pointer to the string that contains the default system config string.
// Remarks:
//		Gets the default system config string. (default system.ini file)
LPCSTR CRTApp::GetDefaultConfig() const
{
	return s_pszSystem;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszSection		Points to a null-terminated string that specifies the 
//						section containing the entry.
//		lpszEntry		Points to a null-terminated string that contains the 
//						entry whose string is to be retrieved. This value must
//						not be NULL.
//		lpszDefault		Points to the default string value for the given entry 
//						if the entry cannot be found in the initialization file.
// Return Value:
//		The return value is the string from the application's .INI file or 
//		lpszDefault if the string cannot be found. 
// Remarks:
//		Call this member function to retrieve the string associated with an 
//		entry within the specified section in the application's .INI file.
CString CRTApp::GetProfileString(LPCSTR lpszSection, LPCSTR lpszEntry, 
								 LPCSTR lpszDefault) const
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);

	CProfileEntry *pEntry = FindProfileEntry(lpszSection, lpszEntry);
	return (pEntry != NULL) ? pEntry->strValue : CString(lpszDefault);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszSection		Points to a null-terminated string that specifies the 
//						section containing the entry. If the section does not 
//						exist, it is created. The name of the section is case 
//						sensitive;  the string may be any combination of 
//						uppercase and lowercase letters.
//		lpszEntry		Points to a null-terminated string that contains the 
//						entry into which the value is to be written. If the 
//						entry does not exist in the specified section, it is 
//						created.
//		lpszValue		Points to the string to be written. If this parameter 
//						is NULL, the entry specified by the lpszEntry parameter
//						is deleted. 

// Return Value:
//		TRUE if successful; otherwise FALSE.
// Remarks:
//		Call this member function to write the specified string into the 
//		specified section of the application's .INI file.
BOOL CRTApp::WriteProfileString(LPCSTR lpszSection, LPCSTR lpszEntry, 
								LPCSTR lpszValue)
{
	ASSERT(lpszSection != NULL && *lpszSection != '\0');
	ASSERT(lpszEntry != NULL && *lpszEntry != '\0');

	if (lpszValue == NULL)
		return DeleteProfileEntry(lpszSection, lpszEntry);

	CProfileSection *pSection = FindProfileSection(lpszSection);
	if (pSection == NULL)
	{// create new section
		pSection = new CProfileSection();
		ASSERT(pSection);
		pSection->strSection = lpszSection;
		// Add to header
		pSection->pNext = m_pSectionHeader;
		m_pSectionHeader = pSection;
	}

	CProfileEntry *pEntry = FindProfileEntry(pSection, lpszEntry);
	if (pEntry == NULL)
	{// create new entry
		pEntry = new CProfileEntry();
		ASSERT(pEntry);
		pEntry->strEntry = lpszEntry;
		// Add to header
		pEntry->pNext = pSection->pEntryHeader;
		pSection->pEntryHeader = pEntry;
	}

	pEntry->strValue = lpszValue;
	return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszSection		Points to a null-terminated string that specifies the 
//						section containing the entry. If the section does not 
//						exist, it is created. The name of the section is case 
//						sensitive;  the string may be any combination of 
//						uppercase and lowercase letters.
//		lpszEntry		Points to a null-terminated string that contains the 
//						entry into which the value is to be written. If the 
//						entry does not exist in the specified section, it is 
//						created.
//		nValue			Contains the value to be written.
// Return Value:
//		TRUE if successful; otherwise FALSE.
// Remarks:
//		Call this member function to write the specified value into the 
//		specified section of the application's .INI file.
BOOL CRTApp::WriteProfileInt(LPCSTR lpszSection, LPCSTR lpszEntry, int nValue)
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);

	CString strValue;
	strValue.Format("%d", nValue);
	return WriteProfileString(lpszSection, lpszEntry, strValue);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszSection		Points to a null-terminated string that specifies the 
//						section containing the entry.
//		lpszEntry		Points to a null-terminated string that contains the 
//						entry whose value is to be retrieved.
//		nDefault		Specifies the default value to return if the framework 
//						cannot find the entry. This value can be an unsigned 
//						value in the range 0 through 65,535 or a signed value 
//						in the range –32,768 through 32,767.
// Return Value:
//		The integer value of the string that follows the specified entry if the
//		function is successful. The return value is the value of the nDefault 
//		parameter if the function does not find the entry. The return value is
//		0 if the value that corresponds to the specified entry is not an integer.
//		This member function supports hexadecimal notation for the value in the
//		.INI file. When you retrieve a signed integer, you should cast the value
//		into an int.
// Remarks:
//		Call this member function to retrieve the value of an integer from an 
//		entry within a specified section of the application's .INI file.
UINT CRTApp::GetProfileInt(LPCSTR lpszSection, LPCSTR lpszEntry, int nDefault) const
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);

	CString strDefault;
	strDefault.Format("%d", nDefault);
	CString strValue = GetProfileString(lpszSection, lpszEntry, strDefault);
	strValue.TrimLeft();
	if (strValue.Find("0x") == 0 || strValue.Find("0X") == 0)
		return (UINT)strValue.Tohex();
	else
		return (UINT)strValue.Tolong();
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpszSection		Points to a null-terminated string that specifies the 
//						section containing the entry.
//		lpszEntry		Points to a null-terminated string that contains the 
//						entry whose value is to be retrieved.
//		dbDefault		Specifies the default value to return if the framework 
//						cannot find the entry. 
// Return Value:
//		The double value of the string that follows the specified entry if the
//		function is successful. The return value is the value of the dbDefault 
//		parameter if the function does not find the entry. The return value is
//		0.0 if the value that corresponds to the specified entry is not a number.
// Remarks:
//		Call this member function to retrieve the value of a double from an 
//		entry within a specified section of the application's .INI file.
double CRTApp::GetProfileFloat(LPCSTR lpszSection, LPCSTR lpszEntry,
							   double dbDefault) const
{
	ASSERT(lpszSection != NULL);
	ASSERT(lpszEntry != NULL);
	
	CString strDefault;
	strDefault.Format("%f", dbDefault);
	CString strValue = GetProfileString(lpszSection, lpszEntry, strDefault);

⌨️ 快捷键说明

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