main.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #include <syslog.h>
  6. #include <unistd.h>
  7. #include "appl.h"
  8. #include "tool.h"
  9. static void sim_init( void )
  10. {
  11. STA.uab = 400.1;
  12. STA.ubc = 400.2;
  13. STA.uca = 400.3;
  14. }
  15. int DAEMON = 0;
  16. int RUNTYPE = -1;
  17. int VERSION[3] = {2, 0, 5}; /* ONLY VERSION[0] is used */
  18. static char* s_optstr = "a:b:cdep:s:t:";
  19. int main(int argc, char *argv[])
  20. {
  21. int ret = 0;
  22. int i = 0;
  23. int ch;
  24. opterr = 0;
  25. openlog(argv[0], LOG_CONS | LOG_PID, 0);
  26. syslog(LOG_INFO, "%s,++",__func__);
  27. for( i = 0; i < argc; i++ ){
  28. syslog(LOG_INFO, "%s,arg list,argv[%d]:%s",__func__,i,argv[i]);
  29. }
  30. strcpy(STA.szdev,"Enjoy-100kW");
  31. while ((ch = getopt(argc,argv,s_optstr))!=-1){
  32. switch(ch){
  33. case 'a':
  34. STA.adr = atoi(optarg);
  35. syslog(LOG_INFO, "option a: %s \n",optarg);
  36. break;
  37. case 'b':
  38. strcpy(STA.szser, optarg);
  39. syslog(LOG_INFO,"option b: %s\n", optarg);
  40. break;
  41. case 'd':
  42. DAEMON = 1;
  43. syslog(LOG_INFO,"option d\n");
  44. break;
  45. case 'p':
  46. STA.mqtt_servport= atoi(optarg);
  47. syslog(LOG_INFO,"option p : %s\n", optarg);
  48. break;
  49. case 's':
  50. strcpy(STA.szmqtt_servip, optarg);
  51. syslog(LOG_INFO,"option s : %s\n", optarg);
  52. break;
  53. case 't':
  54. if(strcmp("appl", optarg)==0){
  55. RUNTYPE = 0;
  56. }else if(strcmp("tool", optarg)==0){
  57. RUNTYPE = 2;
  58. }else{
  59. RUNTYPE = -1;
  60. }
  61. break;
  62. default:
  63. syslog(LOG_INFO, "other option :%c\n",ch);
  64. }
  65. }
  66. sim_init();
  67. if( RUNTYPE == 0 ){
  68. appl_main();
  69. }else if( RUNTYPE == 2 ){
  70. tool_main();
  71. }else{
  72. syslog(LOG_INFO, "%s, unknown runtype:%d",__func__, RUNTYPE);
  73. }
  74. syslog(LOG_INFO, "%s, --",__func__);
  75. closelog();
  76. return 0;
  77. }