A messenger application for Raspberry Pi Zerofor A.U.TH (Real time Embedded systems).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.c 3.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*!
  2. * \file main.c
  3. * This is the main file of the RTES final task.
  4. *
  5. * \author Christos Choutouridis AEM:8997 <cchoutou@ece.auth.gr>
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <getopt.h>
  10. #include<signal.h>
  11. #include <unistd.h>
  12. #include <pthread.h>
  13. #include "listener.h"
  14. #include "client.h"
  15. /*!
  16. * Global data
  17. */
  18. //! @{
  19. settings_t settings_init (settings); //!< Application settings
  20. devList_t devList[AEMLIST_SIZE]; //!< Device list
  21. stats_t stats; //!< Statistical data
  22. //! @}
  23. /*!
  24. * CLI short options
  25. */
  26. const char *short_opt = "v:i:p:s:w:th";
  27. /*!
  28. * CLI long options
  29. */
  30. const struct option long_opt[] = {
  31. {"outlevel", required_argument, NULL, 'v'},
  32. {"interval", required_argument, NULL, 'i'},
  33. {"pingtimeout",required_argument, NULL, 'p'},
  34. {"sendtimeout",required_argument, NULL, 's'},
  35. {"who", required_argument, NULL, 'w'},
  36. {"tracktime", no_argument, NULL, 't'},
  37. {"help", no_argument, NULL, 'h'},
  38. {NULL, 0, NULL, 0}
  39. };
  40. /*!
  41. * \brief
  42. * Parse input argument and fill the kcli_input_t struct
  43. * \param s Pointer to settings_t data to fill
  44. * \param argc The argument count as passed to the main()
  45. * \param argv Argument array as passed to the main()
  46. * \return The status of the operation
  47. * \arg 0 Success
  48. * \arg 1 Fail
  49. */
  50. int parse_args (settings_t *s, int argc, char const *argv[]) {
  51. int c;
  52. while ((c = getopt_long (argc, (char *const *)argv, short_opt, long_opt, NULL)) != -1) {
  53. switch (c) {
  54. case -1: /* no more arguments */
  55. case 0: /* long options toggles */
  56. break;
  57. case 'v':
  58. s->outLevel = atoi (optarg);
  59. if (s->outLevel >= OUTLEVEL_2) s->outLevel = OUTLEVEL_2;
  60. if (s->outLevel < OUTLEVEL_0) s->outLevel = OUTLEVEL_0;
  61. break;
  62. case 'i': s->seekerInterval = atoi (optarg); break;
  63. case 'p': s->pingTimeout = atoi (optarg); break;
  64. case 's': s->sendTimeout.tv_sec = atoi (optarg); break;
  65. case 'w': s->me = atoi (optarg); break;
  66. case 't': s->trackTime = true; break;
  67. case 'h': printf ("This will be the help text\n"); break;
  68. case ':':
  69. default:
  70. case '?':
  71. fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c);
  72. fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
  73. exit(1);
  74. }
  75. }
  76. return 0;
  77. }
  78. int main (int argc, char const *argv[]) {
  79. // get command line arguments
  80. parse_args (&settings, argc, argv);
  81. // Initialize all subsystems
  82. log_init ();
  83. stats_init (&stats);
  84. devList_init (devList);
  85. msgList_init (&msgList);
  86. // Create threads
  87. pthread_t ptL, ptS, ptC;
  88. pthread_create (&ptL, NULL, pthListener, NULL);
  89. pthread_create (&ptS, NULL, pthSeeker, NULL);
  90. pthread_create (&ptC, NULL, pthClient, NULL);
  91. // block here
  92. pthread_join (ptL, NULL);
  93. pthread_join (ptS, NULL);
  94. pthread_join (ptC, NULL);
  95. return 0;
  96. }