Chinaunix首页 | 论坛 | 博客
  • 博客访问: 515406
  • 博文数量: 77
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 689
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-12 08:40
文章分类

全部博文(77)

文章存档

2018年(1)

2016年(3)

2015年(24)

2014年(49)

我的朋友

分类: C/C++

2015-03-13 14:22:40


点击(此处)折叠或打开

  1. #include <stdio.h>

  2. void procd_rec(int n, void *cmd);
  3. void procd_ntrip(int n, void *cmd);
  4. void procd_init(int n, void *cmd);
  5. void procd_memory(int n, void *cmd);
  6. void procd_monitorPower(int n, void *cmd);
  7. void procd_monitorGPS(int n, void *cmd);
  8. void procd_monitorRunTime(int n, void *cmd);

  9. void procd_rec(int n, void *cmd)
  10. {
  11.     printf("procd_rec\n");
  12. }
  13. void procd_ntrip(int n, void *cmd)
  14. {
  15.     printf("procd_ntrip\n");
  16. }
  17. void procd_init(int n, void *cmd)
  18. {
  19.     printf("procd_init,%d,%s\n",n,(char *)cmd);
  20. }
  21. void procd_memory(int n, void *cmd)
  22. {
  23.     printf("procd_memory\n");
  24. }
  25. void procd_monitorPower(int n, void *cmd)
  26. {
  27.     printf("procd_monitorPower\n");
  28. }
  29. void procd_monitorGPS(int n, void *cmd)
  30. {
  31.     printf("procd_monitorGPS\n");
  32. }
  33. void procd_monitorRunTime(int n, void *cmd)
  34. {
  35.     printf("procd_monitorRunTime\n");
  36. }

  37. int main(int argc, const char *argv[])
  38. {
  39.     unsigned int i,Func_Num;
  40.     unsigned int count=0;
  41.     
  42.     typedef struct _PROCD_FUNC{
  43.         int interval;//sec
  44.         unsigned int nexttick;
  45.         int options;
  46.         unsigned int reserve1;
  47.         unsigned int reserve2;
  48.         void (*Function)(int ,void *);
  49.     }PROCD_FUNC;

  50.     PROCD_FUNC Func[]={
  51.         {3,0,0,0,0,procd_rec},
  52.         {2,0,0,0,0,procd_ntrip},
  53.         {2,0,0,0,0,procd_init},
  54.         {30,0,0,0,0,procd_memory},
  55.         {5,0,0,0,0,procd_monitorPower},
  56.         {10,0,0,0,0,procd_monitorGPS},
  57.         {60,0,0,0,0,procd_monitorRunTime},
  58.     };

  59.     printf("Func[]: %d\n",sizeof(Func));
  60.     printf("PROCD_FUNC:%d\n",sizeof(PROCD_FUNC));
  61.     printf("Func_Num: %d\n",Func_Num=(sizeof(Func)/sizeof(PROCD_FUNC)));
  62.     
  63.     while(1)
  64.     {
  65.         for(i=0;i<Func_Num;i++)
  66.         {
  67.             if(count>=Func[i].nexttick)
  68.             {
  69.                 Func[i].Function(i,"333");
  70.                 Func[i].nexttick=count+Func[i].interval;
  71.             }
  72.             /*
  73.             * count=0 ; count:0>=nexttick:0 nexttick=count:0+interval(3、2、2、30...)
  74.             * count=1 ; count:1<nexttick:(3、2、2、30...)
  75.             * count=2 ; count:2>=nexttick:2、2(3、30...) nexttick=count:2+interval(2、2)
  76.             * count=3 ; count:3>=nexttick:3(4、4、30...) nexttick=count:3+interval(3)
  77.             * count=4 ; count:4>=nexttick:4、4(6、30...) nexttick=count:4+interval(4、4)
  78.             */
  79.         }
  80.         count++;
  81.         sleep(1);
  82.         printf("========%d=======\n",count);
  83.     }
  84.     return 0;
  85. }
执行结果:
Func[]:    168
PROCD_FUNC:24
Func_Num:  7
procd_rec
procd_ntrip
procd_init,2,333
procd_memory
procd_monitorPower
procd_monitorGPS
procd_monitorRunTime
========1=======
========2=======
procd_ntrip
procd_init,2,333
========3=======
procd_rec
========4=======
procd_ntrip
procd_init,2,333
========5=======
procd_monitorPower
========6=======
procd_rec
procd_ntrip
procd_init,2,333
========7=======
========8=======
procd_ntrip
procd_init,2,333
========9=======
procd_rec
========10=======
procd_ntrip
procd_init,2,333
procd_monitorPower
procd_monitorGPS

阅读(1757) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~