main.c 1.7 KB

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