📄 generalpage.cpp
字号:
strcpy(g_config_source,filename);
// Sets the variaous member variable values.
//
LoadGeneralHeaderData(cfg_load_header);
g_pIP->LoadIPHeaderData(cfg_load_header);
g_pTCP->LoadTCPHeaderData(cfg_load_header);
g_pMEMORY->LoadMemoryHeaderData(cfg_load_header);
g_pDEBUG->LoadDebugHeaderData(cfg_load_header);
g_pNP0->LoadNIfce0SourceData(&cfg_source->nw_ifces[0]);
g_pNP1->LoadNIfce1SourceData(&cfg_source->nw_ifces[1]);
// Show them in UI
PopulateGeneralPageSettings();
}
static void GenerateSourceFile(char *filename,ConfigSourceStruct *cfg_source,int num_networks)
{
FILE *fp = NULL;
char tmpbuffer[512],tmac[32];
int in=0,ic,il;
fp = fopen(filename,"w+");
if(fp != NULL)
{
fprintf(fp,"%s\n","/////////////////////////////////////////////////");
fprintf(fp,"%s\n","// Generated file Do not Modify");
fprintf(fp,"%s\n","/////////////////////////////////////////////////");
fprintf(fp,"typedef struct net_config_info\n");
fprintf(fp," {\n");
fprintf(fp," int imask;\n");
fprintf(fp," short rx_buffs;\n");
fprintf(fp," short tx_buffs;\n");
fprintf(fp," short rx_buff_datalen;\n");
fprintf(fp," short tx_buff_datalen;\n");
fprintf(fp," short buff_area;\n");
fprintf(fp," short buff_area_size;\n");
fprintf(fp," short use_dhcp;\n");
fprintf(fp," unsigned char mac_addr[6];\n");
fprintf(fp," int ipaddr;\n");
fprintf(fp," int netmask;\n");
fprintf(fp," int gateway;\n");
fprintf(fp," }net_config_info;\n");
fprintf(fp,"extern struct net_config_info user_net_config_info[];\n");
fprintf(fp,"%\n");
fprintf(fp,"%s\n","struct net_config_info user_net_config_info[]= {");
for (in=0;in<num_networks;in++) {
fprintf(fp,"%s\n"," {");
sprintf(tmpbuffer,"%d,",0x0);
fprintf(fp," %s\n",tmpbuffer);
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"%d,",cfg_source->nw_ifces[in].rx_bufs);
fprintf(fp," %s\n",tmpbuffer);
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"%d,",cfg_source->nw_ifces[in].tx_bufs);
fprintf(fp," %s\n",tmpbuffer);
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"%d,",cfg_source->nw_ifces[in].rx_buf_sz);
fprintf(fp," %s\n",tmpbuffer);
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"%d,",cfg_source->nw_ifces[in].tx_buf_sz);
fprintf(fp," %s\n",tmpbuffer);
sprintf(tmpbuffer,"%d,",0x0);
fprintf(fp," %s\n",tmpbuffer);
sprintf(tmpbuffer,"%d,",0x0);
fprintf(fp," %s\n",tmpbuffer);
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"%d,",cfg_source->nw_ifces[in].use_dhcp);
fprintf(fp," %s\n",tmpbuffer);
fprintf(fp," %s","{");
ConvertBinaryMacToText(cfg_source->nw_ifces[in].mac_addr,tmac);
il = 0; /* il points to first hex pair */
for (ic=0;ic<6;ic++) {
fprintf(fp,"0x%c%c",tmac[il],tmac[il+1]);
il += 2;
if (ic<5) fprintf(fp,",");
}
fprintf(fp,"},\n");
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"0x%x,",cfg_source->nw_ifces[in].ip_addr);
fprintf(fp,"\n %s\n",tmpbuffer);
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"0x%x,",cfg_source->nw_ifces[in].subnet_mask);
fprintf(fp," %s\n",tmpbuffer);
memset(tmpbuffer,0,sizeof(tmpbuffer));
sprintf(tmpbuffer,"0x%x,",cfg_source->nw_ifces[in].default_gateway);
fprintf(fp," %s\n",tmpbuffer);
fprintf(fp," %s\n","},");
}
fprintf(fp," %s\n","};");
fprintf(fp,"%s","int user_net_num_ifces = sizeof(user_net_config_info)/sizeof(net_config_info);");
fprintf(fp,"%s\n","");
fflush(fp);
fclose(fp);
}
}
static WriteInt(FILE *fp, unsigned int inValue, char *inKeyString, V_TYPE inType)
{
char tmpbuffer[512];
char wbuffer[512];
char macro_protect[80];
switch(inType)
{
case T_MACRO :
sprintf(wbuffer,"%d",inValue);
strcpy(tmpbuffer,"#define ");
strcat(tmpbuffer,inKeyString);
strcat(tmpbuffer," ");
strcat(tmpbuffer,wbuffer);
fprintf(fp," %s\n\n",tmpbuffer);
break;
case T_MACRO_PROTECT :
// put the macro protection
strcpy(macro_protect,"#ifndef ");
strcat(macro_protect,inKeyString);
fprintf(fp," %s\n",macro_protect);
// Write the actual value
sprintf(wbuffer,"%d",inValue);
strcpy(tmpbuffer,"#define ");
strcat(tmpbuffer,inKeyString);
strcat(tmpbuffer," ");
strcat(tmpbuffer,wbuffer);
fprintf(fp," %s\n",tmpbuffer);
strcpy(macro_protect,"#endif");
fprintf(fp," %s\n\n",macro_protect);
break;
case T_STRING:
fprintf(fp," %s\n",inKeyString);
break;
case T_NULL :
strcpy(tmpbuffer,"#define ");
strcat(tmpbuffer,inKeyString);
fprintf(fp," %s\n\n",tmpbuffer);
break;
default:
break;
}
}
static void GenerateFileHeader(FILE *fp,char *filename)
{
char drive[3];
char directory[120];
char basename[20];
char ext[20];
char tmpbuffer[128];
_splitpath(filename,drive,directory,basename,ext);
// save off for the #ifndef
strcpy(tmpbuffer,"_");
strcat(tmpbuffer,basename);
strcat(tmpbuffer,"_H_");
// add extension.
strcat(basename,ext);
fprintf(fp,"%s\n","/////////////////////////////////////////////////");
fprintf(fp,"%s\n","// Generated file Do Not Modify");
fprintf(fp,"%s","// ");
fprintf(fp,"FileName: %s\n",basename);
fprintf(fp,"%s\n","/////////////////////////////////////////////////");
fprintf(fp,"\n\n#define _LWIPOPTS_H_\n\n");
fprintf(fp,"%s","#ifndef ");
fprintf(fp,"%s\n",tmpbuffer);
fprintf(fp,"%s","#define ");
fprintf(fp,"%s\n\n",tmpbuffer);
}
////////////////////////////////////////////////////////////////////////
const int MEMP_NUM_PBUF=32;
const int MEMP_NUM_SYS_TIMEOUT=12;
const int TCP_TTL = 255;
const int TCP_QUEUE_OOSEQ=1;
const int TCP_MAXRTX = 12;
const int TCP_SYNMAXRTX=4;
static void GenerateHeaderFile(char *filename,ConfigHeaderStruct *cfg_header,ConfigSourceStruct *cfg_source)
{
FILE *fp = NULL;
int tempval;
fp = fopen(filename,"w+");
if(fp != NULL)
{
GenerateFileHeader(fp,filename);
WriteInt(fp,0,"NO_SYS",T_MACRO);
WriteInt(fp,cfg_header->mem_alignment,"MEM_ALIGNMENT",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->ram_size,"MEM_SIZE",T_MACRO_PROTECT);
WriteInt(fp,MEMP_NUM_PBUF,"MEMP_NUM_PBUF",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->no_udp_conn,"MEMP_NUM_UDP_PCB",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->no_tcp_conn,"MEMP_NUM_TCP_PCB",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->no_listen_conn,"MEMP_NUM_TCP_PCB_LISTEN",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->no_tcp_conn*2,"MEMP_NUM_TCP_SEG",T_MACRO_PROTECT);
WriteInt(fp,MEMP_NUM_SYS_TIMEOUT,"MEMP_NUM_SYS_TIMEOUT",T_MACRO_PROTECT);
tempval = (cfg_header->no_tcp_conn*2 + cfg_header->no_udp_conn) / 2;
WriteInt(fp,tempval,"MEMP_NUM_NETBUF",T_MACRO_PROTECT);
tempval = (cfg_header->no_tcp_conn*2 + cfg_header->no_udp_conn) / 2 + 4;
WriteInt(fp,tempval,"MEMP_NUM_NETCONN",T_MACRO_PROTECT);
tempval = (cfg_header->no_tcp_conn*2 + cfg_header->no_udp_conn);
WriteInt(fp,tempval,"MEMP_NUM_API_MSG",T_MACRO_PROTECT);
tempval = (cfg_header->no_tcp_conn*2);
WriteInt(fp,tempval,"MEMP_NUM_TCPIP_MSG",T_MACRO_PROTECT);
tempval =1;
WriteInt(fp,tempval,"MEM_RECLAIM",T_MACRO);
WriteInt(fp,tempval,"MEMP_RECLAIM",T_MACRO);
// pool_start_addr is actually the number of buffers in the pool
//
WriteInt(fp,cfg_header->pool_start_addr,"PBUF_POOL_SIZE",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->pool_size,"PBUF_POOL_BUFSIZE",T_MACRO_PROTECT);
// PBUF header length
WriteInt(fp,16,"PBUF_LINK_HLEN",T_MACRO_PROTECT);
// Stat options
if( (cfg_source->nw_ifces[0].use_dhcp == 1) || ((cfg_header->num_networks > 1) && (cfg_source->nw_ifces[1].use_dhcp == 1)))
{
WriteInt(fp,M_ON,"LWIP_DHCP",T_MACRO);
WriteInt(fp,M_ON,"DHCP_DOES_ARP_CHECK",T_MACRO);
}
if( (cfg_header->stats_all == true) || (cfg_header->stats_icmp == true) ||
(cfg_header->stats_ip == true) || (cfg_header->stats_udp == true) ||
(cfg_header->stats_tcp == true) || (cfg_header->stats_link == true) )
WriteInt(fp,1,"LWIP_STATS",T_MACRO);
if(cfg_header->stats_ip == true)
WriteInt(fp,M_ON,"IP_STATS",T_MACRO);
if(cfg_header->stats_icmp == true)
WriteInt(fp,M_ON,"ICMP_STATS",T_MACRO);
if(cfg_header->stats_udp == true)
WriteInt(fp,M_ON,"UDP_STATS",T_MACRO);
if(cfg_header->stats_tcp == true)
WriteInt(fp,M_ON,"TCP_STATS",T_MACRO);
// Debug options
if(cfg_header->debug_ip == true)
{
WriteInt(fp,1,"IP_DEBUG",T_MACRO);
WriteInt(fp,1,"INET_DEBUG",T_MACRO);
}
if(cfg_header->debug_tcp == true)
{
WriteInt(fp,M_ON,"TCP_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_INPUT_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_FR_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_RTO_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_REXMIT_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_CWND_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_WND_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_OUTPUT_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_RST_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCP_QLEN_DEBUG",T_MACRO);
WriteInt(fp,M_ON,"TCPIP_DEBUG",T_MACRO);
}
if(cfg_header->debug_udp == true)
{
WriteInt(fp,M_ON,"UDP_DEBUG",T_MACRO);
}
if(cfg_header->debug_sockets == true)
{
WriteInt(fp,M_ON,"SOCKETS_DEBUG",T_MACRO);
}
if(cfg_header->debug_apilib == true)
{
WriteInt(fp,M_ON,"API_LIB_DEBUG",T_MACRO);
}
if(cfg_header->debug_mem == true)
{
WriteInt(fp,M_ON,"MEM_DEBUG",T_MACRO);
}
if(cfg_header->debug_memp == true)
{
WriteInt(fp,M_ON,"MEMP_DEBUG",T_MACRO);
}
if((cfg_header->proto_all == true) || (cfg_header->proto_tcp == true))
{
WriteInt(fp,M_ON,"LWIP_TCP",T_MACRO);
WriteInt(fp,TCP_TTL,"TCP_TTL",T_MACRO_PROTECT);
WriteInt(fp,TCP_QUEUE_OOSEQ,"TCP_QUEUE_OOSEQ",T_MACRO);
WriteInt(fp,cfg_header->tcp_mss,"TCP_MSS",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->tcp_mss*4,"TCP_SND_BUFF",T_MACRO_PROTECT);
tempval = cfg_header->tcp_mss*4;
WriteInt(fp,(4* tempval / cfg_header->tcp_mss),"TCP_SND_QUEUELEN",T_MACRO_PROTECT);
WriteInt(fp,cfg_header->tcp_wndsz,"TCP_WND",T_MACRO_PROTECT);
WriteInt(fp,TCP_MAXRTX,"TCP_MAXRTX",T_MACRO_PROTECT);
WriteInt(fp,TCP_SYNMAXRTX,"TCP_SYNMAXRTX",T_MACRO_PROTECT);
WriteInt(fp,(cfg_header->tcp_mss*4)/2,"TCP_SNDLOWAT",T_MACRO_PROTECT);
}
// Arp options
//
WriteInt(fp,cfg_header->arp_tbsz,"ARP_TABLE_SIZE",T_MACRO_PROTECT);
WriteInt(fp,M_ON,"ARP_QUEUEING",T_MACRO);
WriteInt(fp,M_ON,"ETHARP_ALWAYS_INSERT",T_MACRO);
// IP options
WriteInt(fp,cfg_header->ip_forward,"IP_FORWARD",T_MACRO);
WriteInt(fp,cfg_header->ip_options,"IP_OPTIONS",T_MACRO);
WriteInt(fp,cfg_header->ip_reassembly,"IP_REASSEMBLY",T_MACRO);
WriteInt(fp,cfg_header->ip_fragmentation,"IP_FRAG",T_MACRO);
// ICMP
WriteInt(fp,TCP_TTL,"ICMP_TTL",T_MACRO);
// UDP
if(cfg_header->proto_udp == true)
{
WriteInt(fp,M_ON,"LWIP_UDP",T_MACRO);
WriteInt(fp,TCP_TTL,"UDP_TTL",T_MACRO);
}
// System
WriteInt(fp,M_ON,"SYS_LEIGHTWEIGHT_PROTO",T_MACRO);
WriteInt(fp,M_ON,"LWIP_COMPAT_SOCKETS",T_MACRO);
WriteInt(fp,M_ON,"LWIP_PROVIDE_ERRNO",T_MACRO);
WriteInt(fp,5,"TCPIP_THREAD_PRIO",T_MACRO_PROTECT);
WriteInt(fp,10,"DEFAULT_THREAD_PRIO",T_MACRO_PROTECT);
WriteInt(fp,29,"LOW_THREAD_PRIO",T_MACRO_PROTECT);
// Write an #endif to end the file
WriteInt(fp,0,"#endif",T_STRING);
fflush(fp);
fclose(fp);
}
}
void GeneralPage::OnButtonAddproject()
{
ConfigHeaderStruct *cfg_header = (ConfigHeaderStruct*)malloc(sizeof(ConfigHeaderStruct));
ConfigSourceStruct *cfg_source = (ConfigSourceStruct*)malloc(sizeof(ConfigSourceStruct));
long inter;
StoreGeneralHeaderData(cfg_header);
g_pIP->StoreIPHeaderData(cfg_header);
g_pTCP->StoreTCPHeaderData(cfg_header);
g_pNP0->StoreNIfce0SourceData(&cfg_source->nw_ifces[0]);
g_pNP1->StoreNIfce1SourceData(&cfg_source->nw_ifces[1]);
g_pDEBUG->StoreDebugHeaderData(cfg_header);
g_pMEMORY->StoreMemoryHeaderData(cfg_header);
char drive[3];
char directory[512];
char basename[512];
char ext[512];
char source_file[512],osource_file[512];
char header_file[512],oheader_file[512];
char szBuffer[2048];
strcpy(directory,"");
strcpy(drive,"");
strcpy(basename,"");
strcpy(ext,"");
if(stricmp(g_config_source,""))
{
_splitpath(g_config_source,drive,directory,basename,ext);
strcpy(source_file,drive);
if(!stricmp(directory,""))
strcat(source_file,"/");
else
strcat(source_file,directory);
strcat(source_file,basename);
strcat(source_file,".c");
strcpy(header_file,drive);
if(!stricmp(directory,""))
strcat(header_file,"/");
else
strcat(header_file,directory);
strcat(header_file,basename);
strcat(header_file,".h");
#if 0
FILE *srcFP = fopen(source_file,"r");
FILE *headerFP = fopen(header_file,"r");
if(srcFP != NULL && headerFP != NULL)
{
char message[1024];
strcpy(message,"OverWrite Generated Files: ");
strcat(message,basename);
strcat(message,"(.c/.h) ");
int res = AfxMessageBox(message,MB_ICONEXCLAMATION | MB_ICONWARNING | MB_YESNO);
if(srcFP != NULL) fclose(srcFP);
if(headerFP != NULL) fclose(headerFP);
if(res == IDNO)
return;
}
if(srcFP != NULL) fclose(srcFP);
if(headerFP != NULL) fclose(headerFP);
#endif
GenerateSourceFile(source_file,cfg_source,cfg_header->num_networks);
GenerateHeaderFile(header_file,cfg_header,cfg_source);
}
IADspApplicationPtr pApp;
pApp.CreateInstance( "VisualDSP.ADspApplication" );
inter = pApp->Interactive;
pApp->Interactive = 0;
IADspProjectListPtr pProjectList = pApp->ProjectList;
IADspProjectPtr pProject;
pProject = pProjectList->GetActiveProject();
// try adding the TCP Configuration folder
try {
pProject->AddFolder("TCP/IP Configuration",".tcp");
}
catch(_com_error err)
{
}
// remove previous files if they exist
if (stricmp(g_config_source,m_OriginalFile)!=0) {
// remove original files
_splitpath(m_OriginalFile,drive,directory,basename,ext);
strcpy(osource_file,drive);
if(!stricmp(directory,""))
strcat(osource_file,"/");
else
strcat(osource_file,directory);
strcat(osource_file,basename);
strcat(osource_file,".c");
strcpy(oheader_file,drive);
if(!stricmp(directory,""))
strcat(oheader_file,"/");
else
strcat(oheader_file,directory);
strcat(oheader_file,basename);
strcat(oheader_file,".h");
try
{
char tmp[512];
strcpy(tmp,m_OriginalFile);
pProject->RemoveFile(osource_file);
pProject->RemoveFile(header_file);
pProject->RemoveFile(tmp);
}
catch(_com_error err)
{
}
IADspToolListPtr pToolList = pProject->ToolList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -