帮我优化这段代码 val = get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i]); if( DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE) { displayString(isDraw,gcszOnOff[(int)val],(i%LISTOFFSET)+1,20); } else if(DBData[i] == RT1064KZZ_MODE) { displayString(isDraw,ModeName[(int)val],(i%LISTOFFSET)+1,20); } else if (DBData[i] == RT1064KZZ_FBS || DBData[i] == RT1064KZZ_FBS_MODE ) { displayString(isDraw,(DBData[i] == RT1064KZZ_FBS ?FBS_NAME[(int)val] :FBS_MODE_NAME[(int)val]),(i%LISTOFFSET)+1,20); } else if(DBData[i] == RT1064KZZ_UAB_CH || DBData[i] == RT1064KZZ_UBC_CH || DBData[i] == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f" , val); LCD_DisString((i%LISTOFFSET)+1, 19 , szVal); if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%LISTOFFSET)+1, 24, (char *)"次"); if (isDraw == 1) len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); } else { sprintf(szVal, "%0.3f" , get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])); LCD_DisString((i%LISTOFFSET)+1, 19, szVal); if (DBData[i] >= RT1064_YS_GL1 && DBData[i] <= RT1064_YS_FBS_JY) LCD_DisString((i%9)+1, 25, (char *)"S"); else if ((DBData[i] >= RT1064_DZ_GL1 && DBData[i] <= RT1064_DZ_I02) || ((DBData[i] >= RT1064_DZ_PHASE_I && DBData[i] <= RT1064_DZ_I0DLT) && DBData[i] != RT1064_DZ_YL_HAR && DBData[i] != RT1064_DZ_LMJ) || DBData[i] == RT1064_DZ_SD || DBData[i] == RT1064_DZ_I0HJS || DBData[i] == RT1064_DZ_FC_CHZ || (DBData[i] >= RT1064_DZ_I03 && DBData[i] <= RT1064_DZ_FBS_I0)|| DBData[i] == RT1064_DZ_FBS_OL) { LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"A"); } else if (DBData[i] == RT1064_DZ_LMJ || DBData[i] == RT1064_DZ_JC || DBData[i] == RT1064_DZ_GYJC) { LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"°"); } else if (DBData[i] == RT1064_DZ_YL_HAR) LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"%"); else if (DBData[i] == RT1064_DZ_IDS ||DBData[i] == RT1064_DZ_OPENCS || (DBData[i] >= RT1064_DZ_I03 && DBData[i] <= RT1064_DZ_FBS_I0)) { LCD_DisString((i%LISTOFFSET)+1, 24, (char *)"次"); } else if (DBData[i] == RT1064_DZ_DP || DBData[i] == RT1064_DZ_GP) { LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"HZ"); } else LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"V"); if (isDraw == 1)len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); }

时间: 2024-03-03 22:47:46 浏览: 19
首先,可以看到在代码中有很多重复的部分,比如调用`get_ActionDZInfo_val`函数、调用`sprintf`函数、调用`LCD_DisString`函数等。我们可以将这些重复的部分抽象成一个函数,减少代码的冗余。 其次,可以将一些常量和字符串存储到数组中,这样可以减少代码中的硬编码,提高可读性和可维护性。 最后,可以使用条件语句合并一些相似的逻辑,减少代码重复。 以下是重构后的代码: ``` const char* UNIT_NAME[] = {"V", "A", "S", "°", "%", "次", "HZ"}; const char* FBS_NAME[] = {"常开", "常闭"}; const char* FBS_MODE_NAME[] = {"标准", "反向"}; const char* ModeName[] = {"单相", "三相"}; void displayData(int isDraw, float val, int data, int i, int gapid, int bit) { char szVal[16]; int x = (i % LISTOFFSET) + 1; if (data >= RT1064KZZ_GL1_ALM && data <= RT1064KZZ_KZHL && data != RT1064KZZ_MODE && data != RT1064KZZ_UAB_CH && data != RT1064KZZ_UBC_CH && data != RT1064KZZ_FBS && data != RT1064KZZ_FBS_MODE) { displayString(isDraw, UNIT_NAME[(int)val], x, 20); } else if (data == RT1064KZZ_MODE) { displayString(isDraw, ModeName[(int)val], x, 20); } else if (data == RT1064KZZ_FBS || data == RT1064KZZ_FBS_MODE) { displayString(isDraw, (data == RT1064KZZ_FBS ? FBS_NAME[(int)val] : FBS_MODE_NAME[(int)val]), x, 20); } else if (data == RT1064KZZ_UAB_CH || data == RT1064KZZ_UBC_CH || data == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f", val); LCD_DisString(x, 19, szVal); if (data == RT1064_DZ_CHZCS) { LCD_DisString(x, 24, "次"); } if (isDraw == 1) { len = LCD_BitNot(UNIT_PROTECT, UNIT_GAP_RT1064, gapid, data, i, bit); } } else { sprintf(szVal, "%0.3f", get_ActionDZInfo_val(UNIT_GAP_RT1064, gapid, data)); LCD_DisString(x, 19, szVal); int index = -1; if (data >= RT1064_YS_GL1 && data <= RT1064_YS_FBS_JY) { index = 2; } else if ((data >= RT1064_DZ_GL1 && data <= RT1064_DZ_I02) || ((data >= RT1064_DZ_PHASE_I && data <= RT1064_DZ_I0DLT) && data != RT1064_DZ_YL_HAR && data != RT1064_DZ_LMJ) || data == RT1064_DZ_SD || data == RT1064_DZ_I0HJS || data == RT1064_DZ_FC_CHZ || (data >= RT1064_DZ_I03 && data <= RT1064_DZ_FBS_I0) || data == RT1064_DZ_FBS_OL) { index = 1; } else if (data == RT1064_DZ_LMJ || data == RT1064_DZ_JC || data == RT1064_DZ_GYJC) { index = 3; } else if (data == RT1064_DZ_YL_HAR) { index = 4; } else if (data == RT1064_DZ_IDS || data == RT1064_DZ_OPENCS || (data >= RT1064_DZ_I03 && data <= RT1064_DZ_FBS_I0)) { LCD_DisString(x, 24, "次"); } else if (data == RT1064_DZ_DP || data == RT1064_DZ_GP) { index = 6; } if (index != -1) { LCD_DisString(x, 25, UNIT_NAME[index]); } if (isDraw == 1) { len = LCD_BitNot(UNIT_PROTECT, UNIT_GAP_RT1064, gapid, data, i, bit); } } } for (int i = 0; i < DBData.size(); i++) { float val = get_ActionDZInfo_val(UNIT_GAP_RT1064, gapid, DBData[i]); displayData(isDraw, val, DBData[i], i, gapid, bit); } ```

相关推荐

优化这段代码 if( DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE) { LCD_DisString((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if(DBData[i] == RT1064KZZ_MODE) { LCD_DisString((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if (DBData[i] == RT1064KZZ_FBS || DBData[i] == RT1064KZZ_FBS_MODE ) { if (DBData[i] == RT1064KZZ_FBS) { LCD_DisString((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if(DBData[i] == RT1064KZZ_FBS_MODE ) { LCD_DisString((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } } else if(DBData[i] == RT1064KZZ_UAB_CH || DBData[i] == RT1064KZZ_UBC_CH || DBData[i] == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f" , get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])); LCD_DisString((i%9)+1, 19 , szVal); if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%9)+1, 24, (char *)"次"); if (not == 2) { if(draw == (i+1)) { len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); } } }

优化这段代码 if( DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE) { LCD_DisString((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)gcszOnOff[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if(DBData[i] == RT1064KZZ_MODE) { LCD_DisString((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)ModeName[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if (DBData[i] == RT1064KZZ_FBS || DBData[i] == RT1064KZZ_FBS_MODE ) { if (DBData[i] == RT1064KZZ_FBS) { LCD_DisString((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)FBS_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } else if(DBData[i] == RT1064KZZ_FBS_MODE ) { LCD_DisString((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); if (not == 2) { if(draw == (i+1)) { LCD_DisString_Not((i%9)+1, 20, (char *)FBS_MODE_NAME[(int)get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])]); } } } } else if(DBData[i] == RT1064KZZ_UAB_CH || DBData[i] == RT1064KZZ_UBC_CH || DBData[i] == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f" , get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])); LCD_DisString((i%9)+1, 19 , szVal); if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%9)+1, 24, (char *)"次"); if (not == 2) { if(draw == (i+1)) { len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); } } }

优化这段代码 if(i > num - 1) break; isDraw = (not == 2 && (draw == i+1)); if (DBData[i] != RT1064_YS_YYDD && DBData[i] != RT1064KZZ_FC_CHZ ) LCD_DisString((i%LISTOFFSET)+1, 0, gRunPara.gap_ActionDZInfo[gapid][DBData[i]].szName); if (DBData[i] == RT1064KZZ_FC_CHZ) LCD_DisString((i%LISTOFFSET)+1, 0, (char *)"大电流闭锁重合闸"); if (DBData[i] == RT1064_YS_YYDD) LCD_DisString((i%LISTOFFSET)+1, 0, (char *)"重合闸检有压时间"); val = get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i]); if( DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)val]) ); } else if(DBData[i] == RT1064KZZ_MODE) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)val]) ); } else if (DBData[i] == RT1064KZZ_FBS || DBData[i] == RT1064KZZ_FBS_MODE ) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)val]) ); } else if(DBData[i] == RT1064KZZ_UAB_CH || DBData[i] == RT1064KZZ_UBC_CH || DBData[i] == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f" , val); LCD_DisString((i%LISTOFFSET)+1, 19 , szVal); if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%LISTOFFSET)+1, 24, (char *)"次"); if (isDraw == 1) len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); }

优化这段代码 if( DBData[i] >= RT1064KZZ_GL1_ALM && DBData[i] <= RT1064KZZ_KZHL && DBData[i] != RT1064KZZ_MODE && DBData[i] != RT1064KZZ_UAB_CH && DBData[i] != RT1064KZZ_UBC_CH && DBData[i] != RT1064KZZ_FBS && DBData[i] != RT1064KZZ_FBS_MODE) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)gcszOnOff[(int)val]) ); } else if(DBData[i] == RT1064KZZ_MODE) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)ModeName[(int)val]) ); } else if (DBData[i] == RT1064KZZ_FBS || DBData[i] == RT1064KZZ_FBS_MODE ) { (isDraw ? LCD_DisString_Not((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)val]) : LCD_DisString((i%LISTOFFSET)+1, 20,(char *)FBS_NAME[(int)val]) ); } else if(DBData[i] == RT1064KZZ_UAB_CH || DBData[i] == RT1064KZZ_UBC_CH || DBData[i] == RT1064_DZ_CHZCS) { sprintf(szVal, "%0.f" , val); LCD_DisString((i%LISTOFFSET)+1, 19 , szVal); if(DBData[i] == RT1064_DZ_CHZCS) LCD_DisString((i%LISTOFFSET)+1, 24, (char *)"次"); if (isDraw == 1) len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); } else { sprintf(szVal, "%0.3f" , get_ActionDZInfo_val(UNIT_GAP_RT1064,gapid,DBData[i])); LCD_DisString((i%LISTOFFSET)+1, 19, szVal); if (DBData[i] >= RT1064_YS_GL1 && DBData[i] <= RT1064_YS_FBS_JY) LCD_DisString((i%9)+1, 25, (char *)"S"); else if ((DBData[i] >= RT1064_DZ_GL1 && DBData[i] <= RT1064_DZ_I02) || ((DBData[i] >= RT1064_DZ_PHASE_I && DBData[i] <= RT1064_DZ_I0DLT) && DBData[i] != RT1064_DZ_YL_HAR && DBData[i] != RT1064_DZ_LMJ) || DBData[i] == RT1064_DZ_SD || DBData[i] == RT1064_DZ_I0HJS || DBData[i] == RT1064_DZ_FC_CHZ || (DBData[i] >= RT1064_DZ_I03 && DBData[i] <= RT1064_DZ_FBS_I0)|| DBData[i] == RT1064_DZ_FBS_OL) { LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"A"); } else if (DBData[i] == RT1064_DZ_LMJ || DBData[i] == RT1064_DZ_JC || DBData[i] == RT1064_DZ_GYJC) { LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"°"); } else if (DBData[i] == RT1064_DZ_YL_HAR) LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"%"); else if (DBData[i] == RT1064_DZ_IDS ||DBData[i] == RT1064_DZ_OPENCS || (DBData[i] >= RT1064_DZ_I03 && DBData[i] <= RT1064_DZ_FBS_I0)) { LCD_DisString((i%LISTOFFSET)+1, 24, (char *)"次"); } else if (DBData[i] == RT1064_DZ_DP || DBData[i] == RT1064_DZ_GP) { LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"HZ"); } else LCD_DisString((i%LISTOFFSET)+1, 25, (char *)"V"); if (isDraw == 1)len = LCD_BitNot(UNIT_PROTECT,UNIT_GAP_RT1064,gapid,DBData[i],i,bit); }

最新推荐

recommend-type

解决keras,val_categorical_accuracy:,0.0000e+00问题

主要介绍了解决keras,val_categorical_accuracy:,0.0000e+00问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

浅谈keras使用中val_acc和acc值不同步的思考

主要介绍了浅谈keras使用中val_acc和acc值不同步的思考,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

基于SpringBoot框架仿stackOverflow网站后台开发.zip

基于springboot的java毕业&课程设计
recommend-type

基于SpringBoot洗衣店管理系统.zip

基于springboot的java毕业&课程设计
recommend-type

【优化覆盖】算术算法求解传感器覆盖优化问题【含Matlab源码 2436期】.zip

【优化覆盖】算术算法求解传感器覆盖优化问题【含Matlab源码 2436期】.zip
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SQL怎么实现 数据透视表

SQL可以通过使用聚合函数和GROUP BY子句来实现数据透视表。 例如,假设有一个销售记录表,其中包含产品名称、销售日期、销售数量和销售额等信息。要创建一个按照产品名称、销售日期和销售额进行汇总的数据透视表,可以使用以下SQL语句: ``` SELECT ProductName, SaleDate, SUM(SaleQuantity) AS TotalQuantity, SUM(SaleAmount) AS TotalAmount FROM Sales GROUP BY ProductName, SaleDate; ``` 该语句将Sales表按照ProductName和SaleDat
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。