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

📄 typecmd.cpp

📁 M16C Flash Starter Software Ver.2.0.0.46 Source Files.zip是瑞萨的M16C系列单片机的flash烧写程序。
💻 CPP
字号:
// TypeCmd.cpp: CTypeCmd Implementation.
//
// This software can be offered for free and used as necessary to aid 
// in your program developments.
//
// RENESAS TECHNOLOGY CORPORATION, RENESAS SOLUTIONS CORPORATION,
// and related original software developers assume no responsibility 
// for any damage or infringement of any third-party's rights, originating 
// in the use of the following software.
// Please use this software under the agreement and acceptance of these conditions. 
//
// Copyright(C)1998(2003) RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION
// ALL RIGHTS RESERVED
//
//////////////////////////////////////////////////////////////////////
#include <ctype.h>

#include "stdafx.h"
#include "M16Cflsh.h"
#include "TypeCmd.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction.
//////////////////////////////////////////////////////////////////////

CTypeCmd::CTypeCmd()
{

}

CTypeCmd::~CTypeCmd()
{

}

	// String to integer.
int CTypeCmd::aToHex(char* chHex)
{
	int nRet = 0;			// result.

	// is chHex hex code?
	if(isxdigit(*chHex))
	{
		if(isdigit(*chHex))
		{
			nRet = (*chHex - '0');
		}
		else
		{
			if(islower(*chHex))
			{
				nRet = (*chHex - 'a' + 0x0a);
			}
			else
			{
				nRet = (*chHex - 'A' + 0x0a);
			}
		}
	}
	else
	{
		nRet = 0;
		*chHex = '0';
	}
	return nRet;
}


	// Send input value.
BOOL CTypeCmd::exec(CString* strSend)
{
	BOOL	bResult = FALSE;				// result

	// Get Comm object.
	CSerialComm& comObj = GetSerialComm();

	// make send data.
	int nStrLength = strSend->GetLength();	// input data length.
	BYTE send[MAXBYTE];						// send data buffer.
	int nIndex = 0, nStrIndex = 0;			// buffer counter.
	TCHAR chHex = 0;						// string element.
	for(nIndex = 0, nStrIndex = 0; nIndex < nStrLength / 2; nIndex++, nStrIndex = nStrIndex + 2)
	{
		chHex = strSend->GetAt(nStrIndex);
		send[nIndex] = aToHex(&chHex) * 0x10;
		strSend->SetAt(nStrIndex, chHex);
		chHex = strSend->GetAt(nStrIndex + 1);
		send[nIndex] += aToHex(&chHex);
		strSend->SetAt(nStrIndex + 1, chHex);
	}
	if(nStrLength % 2)
	{
		chHex = strSend->GetAt(nStrIndex);
		send[nIndex] = aToHex(&chHex) * 0x10;
		strSend->SetAt(nStrIndex, chHex);
		*strSend += "0";
	}

	// Send command.
	bResult = comObj.Write(send, (nStrLength / 2) + (nStrLength % 2));

	Sleep(SLEEP_IN);

	return	bResult;
}
	

⌨️ 快捷键说明

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