/*=====================================================================================================*/ int main( void ) { s16 i = 0; u8 TrData[4][16] = {0}; SystemInit(); System_SetVectorTable(IAP_FLASH_SIZE); GPIO_Config(); RS232_Config(); while(1) { PAO(1) = LED_R; PAO(2) = LED_R; PAO(3) = LED_R; PAO(4) = LED_R; PAO(5) = LED_R; PAO(6) = LED_R; PAO(7) = LED_R; PAO(8) = LED_R; PAO(11) = LED_R; PAO(12) = LED_R; PAO(15) = LED_R; PBO(0) = LED_R; PBO(1) = LED_R; PBO(3) = LED_R; PBO(4) = LED_R; PBO(5) = LED_R; PBO(6) = LED_R; PBO(7) = LED_R; PBO(8) = LED_R; PBO(9) = LED_R; PBO(10) = LED_R; PBO(11) = LED_R; PBO(12) = LED_R; PBO(13) = LED_R; PBO(14) = LED_R; PBO(15) = LED_R; LED_R = ~LED_R; Delay_10ms(10); if(KEY_BO == 1) { LED_G = ~LED_G; Delay_10ms(10); } if(KEY_WU == 1) { LED_B = ~LED_B; Delay_10ms(10); } i++; if(i == 1024) i = -1024; NumToChar(Type_I, 5, TrData[0], i); RS232_Print(USART1, (u8*)"CH1,"); RS232_Print(USART1, TrData[0]); RS232_Print(USART1, (u8*)"\r\n"); } }
void xml_create_by_vm2vm(char *xmlfilename) { int i; xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL, node = NULL, node1 = NULL; //建立根节点 doc = xmlNewDoc(BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "DATA"); xmlNewProp(root_node,BAD_CAST"VERSION",BAD_CAST"0.1"); xmlDocSetRootElement(doc, root_node); /*对没一条亲和性关系输出到XML*/ for(i=0;i<_xpthis->sd->v2v_total;i++){ /*生成主节点*/ node = xmlNewNode(NULL, BAD_CAST "AFFINITY"); /*生成AT属性*/ xmlNewProp(node,BAD_CAST"AT",BAD_CAST _xpthis->sd->v2vlist[i].at); /*生成TYPE属性*/ xmlNewProp(node,BAD_CAST"TYPE",BAD_CAST NumToChar (_xpthis->sd->v2vlist[i].affinity)); /*生成TRAFFIC属性*/ if(_xpthis->sd->v2vlist[i].traffic>0) xmlNewProp(node,BAD_CAST"TRAFFIC",BAD_CAST DoubleToChar (_xpthis->sd->v2vlist[i].traffic,0)); else xmlNewProp(node,BAD_CAST"TRAFFIC",BAD_CAST " "); /*生成DELAY属性*/ xmlNewProp(node,BAD_CAST"DELAY",BAD_CAST DoubleToChar (_xpthis->sd->v2vlist[i].delay,0)); /*生成VMIDS属性*/ xmlNewProp(node,BAD_CAST"VMIDS",BAD_CAST _xpthis->sd->v2vlist[i].vmids); /* xmlNewProp(node,BAD_CAST"DSTID",BAD_CAST NumToChar(_xpthis->sd->v2vlist[i].p_dst_vm->host.id)); xmlNewProp(node,BAD_CAST"SRCID",BAD_CAST NumToChar(_xpthis->sd->v2vlist[i].p_src_vm->host.id)); */ xmlAddChild(root_node, node); } /*生成文件*/ xmlSaveFormatFileEnc(xmlfilename, doc, "UTF-8", 1); /*释放*/ xmlFreeDoc(doc); xmlCleanupParser(); xmlMemoryDump(); }
/* * 函数名 : void xml_create_by_pms_vms() * 功能 : 将物理机及虚拟机信息生成xml文档:xml2.xml * 传入参数 : xmlfilename 为生成的文件名 * 返回值 :无 * @created by 贾俊伟 in 2013.5.12 * @Modified by Jianhai in 2013-05-13 */ void xml1_create(char *xmlfilename) { int i,j; char strBuf[30]; xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL, node = NULL, node1 = NULL; /*建立根节点*/ doc = xmlNewDoc(BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "DATA"); xmlNewProp(root_node,BAD_CAST"VERSION",BAD_CAST"0.3"); xmlDocSetRootElement(doc, root_node); ///////////////////////////////////////////////////////////////// /*生成框FRAME信息*/ for(i=0;i<_xpthis->sd->fr_total;i++){ /*生成FRAME元素*/ node = xmlNewNode(NULL, BAD_CAST "FRAME"); /*加入FRAME的PMIDS属性*/ xmlNewProp(node,BAD_CAST"PMIDS",BAD_CAST _xpthis->sd->framelist[i].pmids); /*加入FRAME的ID属性*/ xmlNewProp(node,BAD_CAST"ID",BAD_CAST _xpthis->sd->framelist[i].sid); xmlAddChild(root_node, node); } /*组GROUPxin*/ for(i=0;i<_xpthis->sd->gr_total;i++){ /*生成GROUP元素*/ node = xmlNewNode(NULL, BAD_CAST "GROUP"); /*加入GROUP的PMIDS属性*/ xmlNewProp(node,BAD_CAST"PMIDS",BAD_CAST _xpthis->sd->pmglist[i].pmids); /*加入GROUP的ID属性*/ xmlNewProp(node,BAD_CAST"ID",BAD_CAST _xpthis->sd->pmglist[i].sid); xmlAddChild(root_node, node); } ///////////////////////////////////////////////////////////////// /*物理机输出*/ for(i=0;i<_xpthis->sd->pm_total;i++){ /*生成PM元素*/ node = xmlNewNode(NULL, BAD_CAST "PM"); /*加入PM的STAT属性*/ sprintf(strBuf,"%d",(int)_xpthis->sd->pmlist[i].host.stat); xmlNewProp(node,BAD_CAST"STAT",BAD_CAST strBuf); /*所在GROUP*/ //sprintf(strBuf,"%d",(int)_xpthis->sd->pmlist[i].group_id); xmlNewProp(node,BAD_CAST"GR",BAD_CAST _xpthis->sd->pmlist[i].at_gr_ids); /*所在FRAME*/ //sprintf(strBuf,"%d",(int)_xpthis->sd->pmlist[i].frame_id); xmlNewProp(node,BAD_CAST"FR",BAD_CAST _xpthis->sd->pmlist[i].at_fr_sid); /*加入PM的IP属性*/ xmlNewProp(node,BAD_CAST"IP",BAD_CAST _xpthis->sd->pmlist[i].host.ip); /*加入PM的ID属性*/ //itoa(_xpthis->sd->pmlist[i].host.id,strBuf,10); //sprintf(strBuf,"%d",(int)_xpthis->sd->pmlist[i].host.id); xmlNewProp(node,BAD_CAST"ID",BAD_CAST _xpthis->sd->pmlist[i].host.sid); xmlAddChild(root_node, node); /*生成METRIC元素*/ for(j=0;j<DIM;j++){ node1 = xmlNewNode(NULL,BAD_CAST"METRIC"); /*指标值 预留*/ xmlNewProp (node1,BAD_CAST"RESERVED",BAD_CAST DoubleToChar(_xpthis->sd->pmlist[i].host.load[j].reserved,2)); /*指标值 总量*/ xmlNewProp (node1,BAD_CAST"TOTAL",BAD_CAST DoubleToChar(_xpthis->sd->pmlist[i].host.load[j].total,2)); /*指标值 已用量*/ xmlNewProp (node1,BAD_CAST"USED",BAD_CAST DoubleToChar(_xpthis->sd->pmlist[i].host.load[j].used,2)); /*新增METRIC属性enum MetricName {CPU = 0, MEM, DISKIO, FPGA, ETH0, ETH1, ETH2, ETH3, SUM, MAX, MIN};*/ switch(j){ case CPU: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"cpu"); break; case MEM: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"mem"); break; case DISKIO: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"diskio"); break; case FPGA: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"fpga"); break; case ETH0: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth0"); break; case ETH1: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth1"); break; case ETH2: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth2"); break; case ETH3: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth3"); break; } xmlAddChild(node,node1); } } ///////////////////////////////////////////////////////////////// /*虚拟机输出*/ for(i=0;i<_xpthis->sd->vm_total;i++){ node = xmlNewNode(NULL, BAD_CAST "VM"); // xmlNewProp(node,BAD_CAST"STAT",BAD_CAST NumToChar(g_vmlist[i].stat)); 没有stat的值 /*所在PM*/ xmlNewProp(node,BAD_CAST"AT",BAD_CAST _xpthis->sd->pmlist[_xpthis->sd->vmlist[i].at].host.sid); /*加入VM的STAT属性*/ xmlNewProp(node,BAD_CAST"STAT",BAD_CAST NumToChar(_xpthis->sd->vmlist[i].host.stat)); /*IP*/ xmlNewProp(node,BAD_CAST"IP",BAD_CAST _xpthis->sd->vmlist[i].host.ip); /*加入ID属性*/ xmlNewProp(node,BAD_CAST"ID",BAD_CAST _xpthis->sd->vmlist[i].host.sid); xmlAddChild(root_node, node); for(j=0;j<DIM;j++){ /*METRIC*/ node1=xmlNewNode(NULL,BAD_CAST"METRIC"); /*TOTAL属性*/ xmlNewProp(node1,BAD_CAST"TOTAL",BAD_CAST DoubleToChar(_xpthis->sd->vmlist[i].host.load[j].total,2)); /*USED属性*/ xmlNewProp(node1,BAD_CAST"USED",BAD_CAST DoubleToChar(_xpthis->sd->vmlist[i].host.load[j].used,2)); /*新增METRIC属性enum MetricName {CPU = 0, MEM, DISKIO, FPGA, ETH0, ETH1, ETH2, ETH3, SUM, MAX, MIN};*/ switch(j){ case CPU: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"cpu"); break; case MEM: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"mem"); break; case DISKIO: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"diskio"); break; case FPGA: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"fpga"); break; case ETH0: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth0"); break; case ETH1: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth1"); break; case ETH2: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth2"); break; case ETH3: xmlNewProp(node1,BAD_CAST"NAME",BAD_CAST"eth3"); break; } xmlAddChild(node,node1); } } /*保存输出到文件*/ xmlSaveFormatFileEnc(xmlfilename, doc, "UTF-8", 1); /*释放*/ xmlFreeDoc(doc); xmlCleanupParser(); xmlMemoryDump(); }
/*生成网络拓扑XML21 cjh add 7.28*/ void xml_create_by_pm2pm_treetopo(char *xmlfilename) { int i; pm2swPtr p_ps; sw2swPtr p_ss; swPtr p_sw; xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL, node = NULL, node1 = NULL; //建立根节点 doc = xmlNewDoc(BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "DATA"); xmlNewProp(root_node,BAD_CAST"VERSION",BAD_CAST"0.1"); xmlDocSetRootElement(doc, root_node); /*---1.生成SWITCH列表---------------*/ /*对每一个SWITHC输出到XML21*/ for(i=0;i<_xpthis->sd->sw_total;i++){ p_sw=&_xpthis->sd->swlist[i]; /*生成id属性*/ xmlNewProp(node,BAD_CAST"ID",BAD_CAST p_sw->sid); //printf(" ---%s ---\n",p_sw->sid); /*生成主节点*/ node = xmlNewNode(NULL, BAD_CAST "SW"); /*生成LEVEL属性*/ xmlNewProp(node,BAD_CAST"LEV",BAD_CAST NumToChar(p_sw->level)); /*端口个数属性*/ xmlNewProp(node,BAD_CAST"PORTNUM",BAD_CAST "24"); xmlAddChild(root_node, node); } /*对每一个PM2SW连接关系输出到XML21*/ for(i=0;i<_xpthis->sd->p2s_total;i++){ p_ps=&_xpthis->sd->p2slist[i]; /*生成主节点*/ node = xmlNewNode(NULL, BAD_CAST "P2S"); /*生成delay属性*/ xmlNewProp(node,BAD_CAST"DELAY",BAD_CAST DoubleToChar(p_ps->delay,0)); /*生成BANDWIDTH属性*/ if(_xpthis->sd->p2slist[i].bandwidth>0) xmlNewProp(node,BAD_CAST"BW",BAD_CAST DoubleToChar (p_ps->bandwidth,0)); else xmlNewProp(node,BAD_CAST"BW",BAD_CAST ""); /*生成DST: SWITCH SID属性*/ xmlNewProp(node,BAD_CAST"DPORT",BAD_CAST NumToChar(p_ps->swithch_port)); /*生成DST: SWITCH SID属性*/ xmlNewProp(node,BAD_CAST"DST",BAD_CAST p_ps->switch_sid); /*生成SRC: PMSID属性*/ xmlNewProp(node,BAD_CAST"SPORT",BAD_CAST NumToChar( p_ps->port_id)); /*生成SRC: PMSID属性*/ xmlNewProp(node,BAD_CAST"SRC",BAD_CAST p_ps->pm_sid); /*生成ID属性:PS(pm2sw), SS(sw2sw)*/ xmlNewProp(node,BAD_CAST"ID",BAD_CAST NumToChar( p_ps->id)); xmlAddChild(root_node, node); } /*对每一个SW2SW连接关系输出到XML21*/ for(i=0;i<_xpthis->sd->s2s_total;i++){ p_ss=&_xpthis->sd->s2slist[i]; /*生成主节点*/ node = xmlNewNode(NULL, BAD_CAST "S2S"); /*生成delay属性*/ xmlNewProp(node,BAD_CAST"DELAY",BAD_CAST DoubleToChar(p_ss->delay,0)); /*生成BANDWIDTH属性*/ if(_xpthis->sd->s2slist[i].bandwidth>0) xmlNewProp(node,BAD_CAST"BW",BAD_CAST DoubleToChar (p_ss->bandwidth,0)); else xmlNewProp(node,BAD_CAST"BW",BAD_CAST ""); /*生成DST: SWITCH SID属性*/ xmlNewProp(node,BAD_CAST"DST",BAD_CAST p_ss->p_dst_sw->sid); /*生成SRC: PMSID属性*/ xmlNewProp(node,BAD_CAST"SRC",BAD_CAST p_ss->sw_src_sid); /*生成ID属性:PS(pm2sw), SS(sw2sw)*/ xmlNewProp(node,BAD_CAST"ID",BAD_CAST NumToChar(p_ss->id)); xmlAddChild(root_node, node); } /*生成文件*/ xmlSaveFormatFileEnc(xmlfilename, doc, "UTF-8", 1); /*释放*/ xmlFreeDoc(doc); xmlCleanupParser(); xmlMemoryDump(); }
int main( void ) { u32 i = 0; u8 ReadBuf[128] = {0}; u8 TrData[8][32] = {0}; u8 WriteData[50] = "ABCDEFG"; SystemInit(); GPIO_Config(); RS232_Config(); LED_R = 1; LED_G = 1; // SD Card Init Info RS232_SendStr(USART3, (u8*)" \r\n"); RS232_SendStr(USART3, (u8*)"----------------------\r\n"); RS232_SendStr(USART3, (u8*)"----------------------\r\n"); RS232_SendStr(USART3, (u8*)" SDIO SD FatFs demo\r\n"); RS232_SendStr(USART3, (u8*)"----------------------\r\n"); RS232_SendStr(USART3, (u8*)"----------------------\r\n\r\n"); RS232_SendStr(USART3, (u8*)" SD Init ... "); while(SD_Init() != SD_OK) { RS232_SendStr(USART3, (u8*)"Failed!!\r\n"); while(1) { LED_R = ~LED_R; Delay_100ms(2); } } RS232_SendStr(USART3, (u8*)"OK!!\r\n\r\n"); RS232_SendStr(USART3, (u8*)"-----SD Init Info-----\r\n"); RS232_SendStr(USART3, (u8*)" Capacity : "); NumToChar(Type_D, 5, TrData[0], SDCardInfo.CardCapacity>>20); RS232_SendStr(USART3, TrData[0]); RS232_SendStr(USART3, (u8*)" MB\r\n"); RS232_SendStr(USART3, (u8*)" CardBlockSize : "); NumToChar(Type_D, 5, TrData[1], SDCardInfo.CardBlockSize); RS232_SendStr(USART3, TrData[1]); RS232_SendStr(USART3, (u8*)"\r\n"); RS232_SendStr(USART3, (u8*)" CardType : "); NumToChar(Type_D, 5, TrData[2], SDCardInfo.CardType); RS232_SendStr(USART3, TrData[2]); RS232_SendStr(USART3, (u8*)"\r\n"); RS232_SendStr(USART3, (u8*)" RCA : "); NumToChar(Type_D, 5, TrData[3], SDCardInfo.RCA); RS232_SendStr(USART3, TrData[3]); RS232_SendStr(USART3, (u8*)"\r\n"); RS232_SendStr(USART3, (u8*)"----------------------\r\n"); RS232_SendStr(USART3, (u8*)"\r\n"); // Wait while(KEY != 1){ LED_G = ~LED_G; Delay_100ms(2); } // Read Directory File RS232_SendStr(USART3, (u8*)"----------------------\r\n"); RS232_SendStr(USART3, (u8*)" SD_Card Read Directory File\r\n"); RS232_SendStr(USART3, (u8*)"----------------------\r\n\r\n"); res = f_mount(&FatFs, "", 1); res = f_opendir(&dirs, "0:/"); res = f_readdir(&dirs, &finfo); while(res!= FR_OK) { RS232_SendStr(USART3, (u8*)" FatFs failed!!\r\n"); while(1) { LED_R = ~LED_R; Delay_100ms(2); } } RS232_SendStr(USART3, (u8*)" File name : \r\n"); while(finfo.fname[0]) { f_readdir(&dirs, &finfo); if(!finfo.fname[0]) break; RS232_SendStr(USART3, (u8*)" ... "); RS232_SendStr(USART3, (u8*)finfo.fname); RS232_SendStr(USART3, (u8*)"\r\n"); } // Wait while(KEY != 1){ LED_G = ~LED_G; Delay_100ms(2); } // Write File RS232_SendStr(USART3, (u8*)" f_open ... "); res = f_open(&file,"SDCard_K.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE); if(res==FR_OK) RS232_SendStr(USART3, (u8*)"OK!!\r\n"); else RS232_SendStr(USART3, (u8*)"failed!!\r\n"); RS232_SendStr(USART3, (u8*)" f_write ... "); res = f_write(&file, WriteData, 20, (UINT *)&i); if(res==FR_OK) RS232_SendStr(USART3, (u8*)"OK!!\r\n"); else RS232_SendStr(USART3, (u8*)"failed!!\r\n"); file.fptr = 0; RS232_SendStr(USART3, (u8*)" f_read ... "); res = f_read(&file, ReadBuf, 100, (UINT *)&i); if(res==FR_OK) RS232_SendStr(USART3, (u8*)"OK!!\r\n"); else RS232_SendStr(USART3, (u8*)"failed!!\r\n"); f_close(&file); RS232_SendStr(USART3, ReadBuf); while(1) { LED_G = ~LED_G; Delay_100ms(2); } }