DIY编程器网
标题:
uuprog开发教程:芯片支持库加载2-加载函数
[打印本页]
作者:
liyf
时间:
2014-12-12 06:28
标题:
uuprog开发教程:芯片支持库加载2-加载函数
前一节我们已经说道支持库的结构体,这是构建该文件的基本,通过结构体我们可以很方便的加载文件信息到内存,而且不用处理就可以用。
这部分的处理相当复杂,读取的顺序,结构大小,芯片的数量等等必须非常清楚,不然读出的数据100%错的,而且这里基本肯定要用调试功能,每修改一次必须过一次调试跟踪,切记。
QQ图片20141210084017.png
(49.03 KB, 下载次数: 106)
下载附件
保存到相册
2014-12-10 08:45 上传
这个函数可以说在整个软件设计中花时最多的,十几天的功夫基本都是耗在这上面,光修改和调试都超多10天,可想而知。对于那些说三道四,软件设计怎么怎么不值钱之类的人整改让他折腾下这个,设计软件的艰辛在哪。
这个函数的主要功能就是解析支持库,然后分类加载到内存中的变量中,因此必须要定义一些全局变量
public:
void GetUpdate();
CString GetMacAddress();
CString GetCpuID();
CString GetGuid();
CString GetOSName();
int VerCompare(CString ver1,CString ver2);
DWORD m_dDeviceSize;
CArray<TypeStruct,TypeStruct> m_arTypeList;
CArray<TypeStruct,TypeStruct> m_arOperationList;
CArray<TypeStruct,TypeStruct> m_arSizeList;
CArray<TypeStruct,TypeStruct> m_arPinList;
CArray<TypeStruct,TypeStruct> m_arDataWidthList;
CArray<TypeStruct,TypeStruct> m_arPackageList;
CArray<TypeStruct1,TypeStruct1> m_arVCCList;
CArray<TypeStruct1,TypeStruct1> m_arVPPList;
CArray<TypeStruct,TypeStruct> m_arAdapterList;
CArray<DeviceListFileStruct,DeviceListFileStruct> m_arDeviceList;
DeviceListFileStruct m_stDFile;
DeviceListFileHeadStruct m_stDFileHead;
ProjectFileHeadStruct m_stPFileHead;
ProjectFileStruct m_stPFile;
BYTE* pProgBuff;
CString m_sAppPath;
CString m_sAppVer;
/* CString m_sDeviceNote;
int m_iDevicePinCount;
int m_iDeviceDataWidth;
DWORD m_dDeviceID;
float m_fDeviceVPP;
DWORD m_dDeviceCheckCRC;
CString m_sDevicePackage;
float m_fDeviceVCC;
int m_iDeviceSize;
DWORD m_dDeviceManuID;
CString m_sDeviceAdapter;
CString m_sDeviceName;
*/
DWORD m_dBuffCheckCRC;
DWORD m_dProjectFileCRC;
CString m_sFilename;
复制代码
而且必须在程序启动时就要初始化
CUUProgDlg::CUUProgDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUUProgDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUUProgDlg)
m_AppLog = _T("");
m_sDeviceAdapter = _T("");
m_sDeviceCheckCRC = _T("");
m_sDeviceID = _T("");
m_sDeviceManuID = _T("");
m_sDeviceName = _T("");
m_sDeviceNote = _T("");
m_sDevicePackage = _T("");
m_sDeviceSize = _T("");
m_sDeviceType = _T("");
m_sDeviceVCC = _T("");
m_sDeviceVPP = _T("");
m_sDeviceDatasheet = _T("");
m_sLoadFileName = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bProgLink = false;
m_bOneKeyMode = true;
m_iAppLogLine = 0;
m_dBuffCheckCRC = 0;
m_dProjectFileCRC = 0;
m_dDeviceSize = 0;
m_sAppPath = "";
m_sUUProgSN = "------";
m_sUUProgHWVer = "----";
m_sUUProgFWVer = "----";
m_sUUProgFWDate = "--------";
m_sUUProgType = "------";
ZeroMemory(&m_stPFile, sizeof(ProjectFileStruct));
ZeroMemory(&m_stPFileHead, sizeof(ProjectFileHeadStruct));
ZeroMemory(&m_stDFile, sizeof(DeviceListFileStruct));
ZeroMemory(&m_stDFileHead, sizeof(DeviceListFileHeadStruct));
// pProgBuff=(BYTE*)GlobalAlloc(GMEM_FIXED,0x10000);//½¨Á¢»º³å1
// memset(pProgBuff,0xff,0x10000);
}
复制代码
然后就是指定函数什么时候加载了,这里我们用到了定时器,其实这个的处理比较蛋疼的,想要实现加载信息实时显示,用多线程该是最好的方案,但是我们这里只用到了定时器延时启动,避免程序启动时就一闪而过,看不到加载的效果。
void CUUProgDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
SetAppLog("欢迎使用UUProg编程器应用程序");
SetAppLog("设计开发:Liyf");
SetAppLog("支持网站:http://www.diybcq.com");
// SetAppLog(" http://kitebee.gnway.net");
SetAppLog("QQ群:41210778");
SetAppLog("<----------------------------------------------");
SetAppLog("");
//初始化程序
SetAppLog("程序初始化...");
GetAppVer();
GetAppPath();
SetAppLog("加载配置...");
LoadConfig();
SetAppLog("设置计数器...");
SetCount();
SetAppLog("加载芯片列表...");
LoadDeviceList();
SetAppLog("加载最近编程芯片...");
if(!m_sDeviceName.IsEmpty())//加载最近编程芯片
{
CString temp;
for (int i=0; i<m_arDeviceList.GetSize(); i++)
{
temp = m_arDeviceList.GetAt(i).DeviceName;
if(m_sDeviceName == temp)
{
SetDeviceInfo(i);
break;
}
}
}
SetAppLog("初始化完成!");
SetAppLog("<----------------------------------------------");
SetAppLog("");
SetAppLog("操作系统:"+GetOSName());
SetAppLog("CID:"+GetCpuID()+"-"+GetMacAddress());
SetAppLog("UID:"+GetGuid());
SetAppLog("<----------------------------------------------");
SetAppLog("");
m_bProgLink = FindUUProg();
SetAppLog("<----------------------------------------------");
SetAppLog("");
SetAppLog("检测是否有软件更新...");
GetUpdate();
SetAppLog("<----------------------------------------------");
KillTimer(1);
CDialog::OnTimer(nIDEvent);
}
复制代码
下面就是LoadDeviceList()函数了,非常复杂的,慢慢看
void CUUProgDlg::LoadDeviceList()
{
CFile ldfile;
if(ldfile.Open(m_sAppPath+"device.pdl",CFile::shareCompat|CFile::modeRead,NULL))
{
int BufSize=ldfile.GetLength();
int StartAddr;
BYTE* fileBuf=new BYTE[BufSize];
ldfile.Read(fileBuf,BufSize);
memcpy(&m_stDFileHead,fileBuf,sizeof(DeviceListFileHeadStruct));
int result = VerCompare(m_sAppVer,m_stDFileHead.DeviceListFileVer);
if(result != 0)
{
AfxMessageBox("芯片支持库版本不匹配,请从新安装软件!");
GlobalFree(fileBuf);
ldfile.Close();
}
//Type List
StartAddr = sizeof(DeviceListFileHeadStruct);
TypeStruct* pType=(TypeStruct*)&fileBuf[StartAddr];
for(int n=0;n<=m_stDFileHead.TypeListCount-1;n++)
{
m_arTypeList.Add(pType[n]);
}
//Operation List
StartAddr += m_stDFileHead.TypeListCount*sizeof(TypeStruct);
pType=(TypeStruct*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.OperationListCount-1;n++)
{
m_arOperationList.Add(pType[n]);
}
//Size List
StartAddr += m_stDFileHead.OperationListCount*sizeof(TypeStruct);
pType=(TypeStruct*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.SizeListCount-1;n++)
{
m_arSizeList.Add(pType[n]);
}
//Pin List
StartAddr += m_stDFileHead.SizeListCount*sizeof(TypeStruct);
pType=(TypeStruct*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.PinListCount-1;n++)
{
m_arPinList.Add(pType[n]);
}
//DataWidth List
StartAddr += m_stDFileHead.PinListCount*sizeof(TypeStruct);
pType=(TypeStruct*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.DataWidthListCount-1;n++)
{
m_arDataWidthList.Add(pType[n]);
}
//Package List
StartAddr += m_stDFileHead.DataWidthListCount*sizeof(TypeStruct);
pType=(TypeStruct*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.PackageListCount-1;n++)
{
m_arPackageList.Add(pType[n]);
}
//VCC List
StartAddr += m_stDFileHead.PackageListCount*sizeof(TypeStruct);
TypeStruct1* pType1=(TypeStruct1*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.VCCListCount-1;n++)
{
m_arVCCList.Add(pType1[n]);
}
//VPP List
StartAddr += m_stDFileHead.VCCListCount*sizeof(TypeStruct1);
pType1=(TypeStruct1*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.VPPListCount-1;n++)
{
m_arVPPList.Add(pType1[n]);
}
//Adapter List
StartAddr += m_stDFileHead.VPPListCount*sizeof(TypeStruct1);
pType=(TypeStruct*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.AdapterListCount-1;n++)
{
m_arAdapterList.Add(pType[n]);
}
//Device List
// memcpy(&m_stDFileHead,fileBuf,sizeof(DeviceListFileHeadStruct));
StartAddr += m_stDFileHead.AdapterListCount*sizeof(TypeStruct);
DeviceListFileStruct* pDevice=(DeviceListFileStruct*)&fileBuf[StartAddr];
for(n=0;n<=m_stDFileHead.DeviceCount-1;n++)
{
m_arDeviceList.Add(pDevice[n]);
}
GlobalFree(fileBuf);
ldfile.Close();
}
else
{
TypeStruct stType;
TypeStruct1 stType1;
ZeroMemory(&stType, sizeof(TypeStruct));
ZeroMemory(&stType1, sizeof(TypeStruct1));
strcpy(stType.TypeName,"EPROM");
stType.TypeVal = 1;
m_arTypeList.Add(stType);
strcpy(stType.TypeName,"MPU");
stType.TypeVal = 2;
m_arTypeList.Add(stType);
strcpy(stType.TypeName,"PLD");
stType.TypeVal = 3;
m_arTypeList.Add(stType);
strcpy(stType.TypeName,"PROM");
stType.TypeVal = 4;
m_arTypeList.Add(stType);
strcpy(stType.TypeName,"AT24(AT24xxx)");
stType.TypeVal = 1;
m_arOperationList.Add(stType);
strcpy(stType.TypeName,"AT51(AT89x5x)");
stType.TypeVal = 2;
m_arOperationList.Add(stType);
strcpy(stType.TypeName,"AT93(AT93xxx)");
stType.TypeVal = 3;
m_arOperationList.Add(stType);
strcpy(stType.TypeName,"EN25(EN25xxx)");
stType.TypeVal = 4;
m_arOperationList.Add(stType);
strcpy(stType.TypeName,"1k");
stType.TypeVal = 1024;
m_arSizeList.Add(stType);
strcpy(stType.TypeName,"2k");
stType.TypeVal = 2048;
m_arSizeList.Add(stType);
strcpy(stType.TypeName,"4k");
stType.TypeVal = 4096;
m_arSizeList.Add(stType);
strcpy(stType.TypeName,"8k");
stType.TypeVal = 8192;
m_arSizeList.Add(stType);
strcpy(stType.TypeName,"8 Pin");
stType.TypeVal = 8;
m_arPinList.Add(stType);
strcpy(stType.TypeName,"16 Pin");
stType.TypeVal = 16;
m_arPinList.Add(stType);
strcpy(stType.TypeName,"28 Pin");
stType.TypeVal = 28;
m_arPinList.Add(stType);
strcpy(stType.TypeName,"32 Pin");
stType.TypeVal = 32;
m_arPinList.Add(stType);
strcpy(stType.TypeName,"40 Pin");
stType.TypeVal = 40;
m_arPinList.Add(stType);
strcpy(stType.TypeName,"8 bit");
stType.TypeVal = 8;
m_arDataWidthList.Add(stType);
strcpy(stType.TypeName,"16 bit");
stType.TypeVal = 16;
m_arDataWidthList.Add(stType);
strcpy(stType.TypeName,"32 bit");
stType.TypeVal = 32;
m_arDataWidthList.Add(stType);
strcpy(stType.TypeName,"DIP");
stType.TypeVal = 1;
m_arPackageList.Add(stType);
strcpy(stType.TypeName,"SOP");
stType.TypeVal = 2;
m_arPackageList.Add(stType);
strcpy(stType.TypeName,"SSOP");
stType.TypeVal = 3;
m_arPackageList.Add(stType);
strcpy(stType.TypeName,"TSSOP");
stType.TypeVal = 4;
m_arPackageList.Add(stType);
strcpy(stType1.TypeName,"5.00V");
stType1.TypeVal = 5.00;
m_arVCCList.Add(stType1);
strcpy(stType1.TypeName,"3.30V");
stType1.TypeVal = 3.30;
m_arVCCList.Add(stType1);
strcpy(stType1.TypeName,"0.00V");
stType1.TypeVal = 0.00;
m_arVPPList.Add(stType1);
strcpy(stType1.TypeName,"12.00V");
stType1.TypeVal = 12.00;
m_arVPPList.Add(stType1);
strcpy(stType1.TypeName,"14.00V");
stType1.TypeVal = 14.00;
m_arVPPList.Add(stType1);
strcpy(stType.TypeName,"NONE");
stType.TypeVal = 1;
m_arAdapterList.Add(stType);
strcpy(stType.TypeName,"SOP8toDIP8");
stType.TypeVal = 2;
m_arAdapterList.Add(stType);
strcpy(stType.TypeName,"SOP16toDIP8");
stType.TypeVal = 3;
m_arAdapterList.Add(stType);
strcpy(stType.TypeName,"TSSOP14toDIP8");
stType.TypeVal = 4;
m_arAdapterList.Add(stType);
}
}
复制代码
今天先到这里,又得忙了,欢迎有兴趣的加入,详细的请下载源代码,篇幅有限不一定讲解清楚。下节更精彩。
欢迎光临 DIY编程器网 (http://diybcq.com./)
Powered by Discuz! X3.2