码迷,mamicode.com
首页 > 编程语言 > 详细

函数指针数组工程实例

时间:2015-03-11 14:47:10      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:c   linux   

在这以前曾经写过一篇关于函数指针数组文章,今天又看到了通信工程的应用,拷贝下来,作为参考!

http://blog.csdn.net/eliot_shao/article/details/8609259

1、数据结构的定义

typedef int (*IO_DETECT_FUCTION)(void);
typedef struct __IO_DETECT
{
	int id;
	IO_DETECT_FUCTION fun;
	
}IO_DETECT;

2、类型实体

IO_DETECT s_IO_Detect[]=
{
    {0x01, InputPowerDetect},        
    {0x02, InputPowerDetect1},      
    {0x03, InputPowerDetect2},       
    {0x04, InputPowerDetect3},       
    {0x05, DownBrokenDectect},      
    {0x06, UpBrokenDetect},          
    {0x07, UpBrokenDetect1},         
    {0x08, OpticalTransDetect},      
    {0x09, UpOutputDetect},         
    {0x0A, SlaveDCAlarm},           
    {0x0B, SlaveACAlarm},           
    {0x0C, SolarEnergyDetect},       
    {0x0D, MainInputPowerDetect1},
    {0x0E, MainInputPowerDetect2},
    {0x0F, BackupInputPowerDetect1},
    {0x10, BackupInputPowerDetect2},
    {0x11, GZDTInputPowerDetect},
    {0x12, GZDTOpeicalAlarmDect},
    {0x13, BJDTSlaveDCAlarm},
    {0x14, BJDTUpOutputDetect},  
    {0x15, BJDTSlaveACAlarm},
    {0x16, DCAlarm},
    {0x17, ACAlarm},
    {0x18, GSMCTDownInputPowerDetect},  
    {0x19, CMMBInputPowerDetect},
    {0x1A, BeiJingInputPowerDetect},
    {0x1B, BeiJingOutputPowerDetect},
    {0x1C, CDMAInputPowerDetect1},
    {0x1D, DCAlarm1V},                 
    {0x1E, ACAlarm1V},
    {0x1F, BAT13VDect},                
    {0x20, BAT48VDect},
    {0x21, ReportKey},                  
    {0x22, InputPowerDetect4},
    {0x23, OutputPowerDetect1},
    {0x24, RePowerDetect1},
    {0x25, ACLow_Alarm}
};

3、函数调用

int IO_DetectFunction(int Id)
{
    int  i = 0;
    int ret = 0;
    for(i=0; i < sizeof(s_IO_Detect)/sizeof(IO_DETECT); i++)
    {
        if( s_IO_Detect[i].id == Id )
        {

            ret = s_IO_Detect[i].fun();
            break;
        }
    }
    return ret;
}



函数指针数组工程实例

标签:c   linux   

原文地址:http://blog.csdn.net/eliot_shao/article/details/44198205

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!