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

📄 flashwriterdlg.cpp

📁 将XLS文件的内容下载到LED显示屏上显示
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// FlashWriterDlg.cpp : implementation file
//

#include <time.h>
#include "stdafx.h"
#include <process.h>
#include "Command.h"
#include "FlashWriterDlg.h"
#include "string.h"

#include "ExcelRW.h"

#include "Flash.cpp"

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

/////////////////////////////////////////////////////////////////////////////
// CFlashWriterDlg dialog

CFlashWriterDlg::CFlashWriterDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFlashWriterDlg::IDD, pParent)
{
	m_NFlashSpace = " 0 ";

	//Jack Add 2007.06.29
	m_Status.Empty();
	//End Add

	//Jack Dele 2007.06.29
	//m_Status = "Link OK";
	//End Dele

	m_TotalFiles = 0;
	USB_Special_Patten = 0x00;
	m_CS=0;
	m_Debug=DebugMachine;//0;//1;
	m_SourceFile="";
	USBReadyFlag=false;
	CSFlag=false;
}

void CFlashWriterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFlashWriterDlg)
	DDX_Text(pDX, IDC_SOURCEFILE, m_SourceFile);
	DDX_Text(pDX, IDC_Status_FLASH_WRITER, m_Status);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFlashWriterDlg, CDialog)
	//{{AFX_MSG_MAP(CFlashWriterDlg)
	ON_BN_CLICKED(IDC_Erase_FLASH_WRITER, OnEraseFlash)
	ON_BN_CLICKED(IDC_Program_FLASH_WRITER, OnProgramFlash)
	ON_BN_CLICKED(IDC_PlayFile_FLASH_WRITER, OnPlayFile)
	ON_BN_CLICKED(IDC_ReFlash_FLASH_WRITER, OnReFlash)
	ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
	ON_WM_CLOSE()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_NOTIFY(NM_OUTOFMEMORY, IDC_PROGRESS1, OnOutofmemoryProgress1)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFlashWriterDlg message handlers

BOOL CFlashWriterDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

//	if ( ! Initial_NFlashWriter() )
//	{
//		EndDialog(0);
//		return 0;
//	}

	CWnd *pWnd = GetDlgItem(IDC_STATIC_USB);

	if ( ! Initial_NFlashWriter() )
	{
		USBReadyFlag=false;
		pWnd->SetWindowText("USB Status:No USB Device!");
		Close_USB();
		GetDlgItem(IDC_Program_FLASH_WRITER)->EnableWindow(FALSE);
	}
	else
	{
		USBReadyFlag=true;
		pWnd->SetWindowText("USB is Ready!");
		GetDlgItem(IDC_Program_FLASH_WRITER)->EnableWindow(TRUE);
	}

	m_FileInformation =  new FileInformation[USE_BLOCK0_SIZE/8];
	m_FileInforCount = 0;

	SetTimer(1,500,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}


MonthDate CFlashWriterDlg::GetMonthDate(CString stDateMonth)
{
	MonthDate DMonth;

	DMonth.Month = 0xff;
	DMonth.Date = 0xff;

	int len = stDateMonth.GetLength();
	if (len <= 0)
	{
		return  DMonth;
	}

	int first = 0;
	int last = 0;
	char c;
	// 取月份
	c = stDateMonth.GetAt(first);
	while (c > '9' || c < '0')
	{
		first ++;
		
		if (first >= len)
		{
			return DMonth;
		}
		c = stDateMonth.GetAt(first);
	}
	last = first;
	c = stDateMonth.GetAt(last);
	while (c <= '9' && c >= '0')
	{
		last ++;
		
		if (last >= len)
		{
			return DMonth;
		}
		c = stDateMonth.GetAt(last);
	}

	CString str = stDateMonth.Mid(first, last - first);
	DMonth.Month = atoi(str.GetBuffer(0));

	// 取日期
	first = last + 1; 
	c = stDateMonth.GetAt(first);
	while (c > '9' || c < '0')
	{
		first ++;
		
		if (first >= len)
		{
			break;
		}
		c = stDateMonth.GetAt(first);
	}
	last = first;
	c = stDateMonth.GetAt(last);
	while (c <= '9' && c >= '0')
	{
		last ++;
		
		if (last >= len)
		{
			break;
		}
		c = stDateMonth.GetAt(last);
	}

	str = stDateMonth.Mid(first, last - first);
	DMonth.Date = atoi(str.GetBuffer(0));

	return DMonth;

}

HourMin CFlashWriterDlg::GetHourMin(CString stHorMin)
{
	HourMin DHour;

	DHour.Hour = 0xff;
	DHour.Minute = 0xff;

	int len = stHorMin.GetLength();
	if (len <= 0)
	{
		return  DHour;
	}

	int first = 0;
	int last = 0;
	char c;
	// 取小时
	c = stHorMin.GetAt(first);
	while (c > '9' || c < '0')
	{
		first ++;
		
		if (first >= len)
		{
			return DHour;
		}
		c = stHorMin.GetAt(first);
	}
	DHour.Hour = atoi(&c);
	last = first;
	c = stHorMin.GetAt(last);
	while (c <= '9' && c >= '0')
	{
		last ++;
		
		if (last >= len)
		{
			return DHour;
		}
		c = stHorMin.GetAt(last);
		if(c=='0')
		{
			DHour.Hour = DHour.Hour<<4 | atoi(&c) ;
			break;
		}
		if(atoi(&c))
		{
			DHour.Hour = DHour.Hour<<4 | atoi(&c) ;
			break;
		}
	}

//	CString str = stDateMonth.Mid(first, last - first);
//	DHour.Hour = atoi(str.GetBuffer(0));

	// 取分钟
	first = last + 1; 
	c = stHorMin.GetAt(first);
	while (c > '9' || c < '0')
	{
		first ++;
		
		if (first >= len)
		{
			break;
		}
		c = stHorMin.GetAt(first);
	}
	DHour.Minute = atoi(&c);
	last = first;
	c = stHorMin.GetAt(last);
	while (c <= '9' && c >= '0')
	{
		last ++;
		
		if (last >= len)
		{
			break;
		}
		c = stHorMin.GetAt(last);
		DHour.Minute = DHour.Minute<<4 | atoi(&c) ;
	}

//	str = stDateMonth.Mid(first, last - first);
//	DHour.Minute = atoi(str.GetBuffer(0));

	return DHour;
}




CFlashWriterDlg::~CFlashWriterDlg()
{
	delete [] m_FileInformation;
	::FreeLibrary(hWNDLL);
}

void CFlashWriterDlg::OnEraseFlash()
{

	m_Status = "Erasing...";
	UpdateData(false);
	EraseNFlash(FlashAddress);
	m_Status = "Erase OK!";
	UpdateData(false);
}

void CFlashWriterDlg::OnProgramFlash()
{

	if ( !USBReadyFlag )
	{
		MessageBox("USB is not ready.Please plug it and try again!!");
		return;
	}
	UpdateData(TRUE);
	m_CS = 0;
	if(0==m_CS)
	{
		FlashAddress=0x400040;
		if (CSFlag)
		{
			SwitchToCS1();
			CSFlag=false;
		}
	}
	else if(1==m_CS)
	{
		FlashAddress=0x400080;
		if (!CSFlag)
		{
			SwitchToCS2();
			CSFlag=true;
		}
	}
	else if(2==m_CS)
	{
		FlashAddress=0x4000c0;
	}

	int MonthDateTable[14] = {0,0,31,60,91,121,152,182,213,244,274,305,335,366};
	CString FileName;
	//unsigned char	*FileDataPtr;
	//BYTE data[64];
	//int	Status;
	//int Temp_Counter;
	CExcelRW rwxls;
	if (!m_SourceFile.IsEmpty())
	{
		CString sCell = "";


		if(rwxls.Open(m_SourceFile, "sheet1"))
		{
			//bool efg;
			for( int i=1; i<8; i++ )
			{
				//pbstrVal
				sCell = rwxls.ReadStr(2, i);
				//sCell = (rwxls.Read(2, i)).pbstrVal;
				//sCell = (BSTR)rwxls.Read(2, i);
			}
			if( sCell == "" || sCell == "~" )
			{
				MessageBox("file empty!!");
				return;
			}
			else
			{
				unsigned short *TimeTable = new unsigned short[TableDataLength];
				unsigned short DayPrayTime[7];
				int MonthDateLine;
				int MonthDateLineEnd;
				if( NFlashRead((BYTE *)TimeTable, NFStartAddress, TableDataLength, m_Debug) )
				{
					for( i=2; i<MaxLine; i++)
					{
						sCell = rwxls.ReadStr(i, 1);
						if(sCell == "")
							{
							break;
							}

						if(sCell == "~")
							{
							sCell = rwxls.ReadStr(i+1, 1);
								if(sCell == "")
								{
								break;
								}
								MonthDate Month_Date;
								Month_Date = GetMonthDate(sCell);
								MonthDateLineEnd = MonthDateTable[Month_Date.Month] + Month_Date.Date - 1;
								for( MonthDateLine++; MonthDateLine<MonthDateLineEnd; MonthDateLine++ )
								{
									for(int j=2; j<MaxRow; j++ )
									{
										TimeTable[MonthDateLine*6+j-2] = DayPrayTime[j-2];
									}
								}
							}

						MonthDate Month_Date;

						Month_Date = GetMonthDate(sCell);
						MonthDateLine = MonthDateTable[Month_Date.Month] + Month_Date.Date - 1;

						for(int j=2; j<MaxRow; j++ )
						{
							sCell = rwxls.ReadStr(i, j);
							if(sCell == "")
							{
								DayPrayTime[j-2] = TimeTable[MonthDateLine*6+j-2];
							}
							HourMin Hour_Min = GetHourMin(sCell);
							TimeTable[MonthDateLine*6+j-2] = ((Hour_Min.Hour&0x0ff)<<8) | (Hour_Min.Minute&0x0ff);
							DayPrayTime[j-2] = TimeTable[MonthDateLine*6+j-2];
						}
					}
					rwxls.Close();
					int FlashClrAddr = 0x478000;
					if( EraseNFlashSector(FlashClrAddr) )	//擦除flash,注意这里只擦除一个扇区,如果要擦除多个扇区,则需要修改这段代码
					{
						/*if( NFlashWrite((BYTE *)TimeTable, NFStartAddress, TableDataLength) )
						{
							MessageBox("NF write ok!");
							return;
						}
						else
						{
							MessageBox("NF write erro!!");
							return;
						}*/
						//NFStartAddress=&ProgramData[0];
						
						int     Status;
						int		Temp_Counter;
						UINT StartAddress = 0x078000;	//NFStartAddress;

						unsigned short *ProgramData;
						ProgramData = &TimeTable[0];
						BYTE	data[64];
						Temp_Counter = 0;
						ProgressPrg(0);
						do//for (i=0,i<DownloadLength,i+=512
							{
								if ( ! NFlashWrite((BYTE *)ProgramData,StartAddress,512) )

⌨️ 快捷键说明

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