testing.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /********************************* (C) РОТЕК ***********************************
  2. * @module testing
  3. * @file testing.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief Template
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "testing.h"
  14. #include "settings_api.h"
  15. #include "common_config.h"
  16. #include "stm32_uid.h"
  17. #include "led.h"
  18. #include "hal.h"
  19. #include "FreeRTOS.h"
  20. #include "task.h"
  21. #include "lwip/opt.h"
  22. #include "lwip/arch.h"
  23. #include "lwip/api.h"
  24. #include "lwip/tcp.h"
  25. #ifdef PRINTF_STDLIB
  26. #include <stdio.h>
  27. #endif
  28. #ifdef PRINTF_CUSTOM
  29. #include "tinystdio.h"
  30. #endif
  31. #include <stdbool.h>
  32. #include <string.h>
  33. #define UDP_PORT 49049
  34. bool fTesting = false;
  35. bool fServer = false;
  36. #define MSG_LEN 300
  37. char ID[33];
  38. extern SETTINGS_t sSettings; // Общая структура настроек
  39. extern bool isIpReceived;
  40. /**
  41. * @brief Тестирование
  42. */
  43. // TODO Убрать заглушки
  44. void vTaskTesting(void *params)
  45. {
  46. uint8_t len;
  47. while (!isIpReceived) {
  48. vTaskDelay(100);
  49. }
  50. for (;;)
  51. {
  52. //printf("Start testing task\r\n");
  53. memset(ID, 0, 33);
  54. /* Читаем ID */
  55. GetSTM32IDStr(ID, &len);
  56. /* Отправляем запрос */
  57. vTaskDelay(3000);
  58. TEST_SendData();
  59. /* Ждем timeout и высылаем ответ на тестер */
  60. vTaskDelay(2000);
  61. /* Если все прошло хорошо*/
  62. if (fServer)
  63. {
  64. LED_On(LED_INIT_R);
  65. /* Устанавливаем статус тестирования "T2OK" и сохраняем настройки */
  66. SETTINGS_SetT2OK();
  67. LED_Off(LED_INIT_R);
  68. fServer = false;
  69. vTaskDelay(2000);
  70. Reboot();
  71. vTaskDelete(NULL);
  72. }
  73. vTaskDelay(100);
  74. }
  75. }
  76. /**
  77. * @brief Отправляет строку данных по UDP
  78. */
  79. void TEST_SendData(void)
  80. {
  81. struct netconn *conn;
  82. struct netbuf *buf;
  83. char *data;
  84. char msg[MSG_LEN];
  85. err_t err;
  86. /* Отправляем сообщение на сервер по UDP */
  87. memset(msg, 0, MSG_LEN);
  88. conn = netconn_new( NETCONN_UDP );
  89. if (conn!= NULL)
  90. {
  91. err = netconn_bind(conn, IP_ADDR_ANY, UDP_PORT);
  92. if (err == ERR_OK)
  93. {
  94. netconn_connect(conn, IP_ADDR_BROADCAST, UDP_PORT);
  95. strcpy(msg, sSettings.sSnmp.sysName);
  96. strcat(msg, ";");
  97. /* Заглушка */
  98. //strcat(msg, "KN-03-00001;EC-4C-4D-00-90-01;0.8_DEMO;;;");
  99. strcat(msg, sSettings.sInfo.serialNumber);
  100. strcat(msg, ";");
  101. strcat(msg, sSettings.sInfo.mac);
  102. strcat(msg, ";");
  103. strcat(msg, VERSION);
  104. strcat(msg, ";;;");
  105. // for (uint8_t i = 0; i < 12; i++)
  106. {
  107. strcat(msg, ID);
  108. }
  109. strcat(msg, ";;;");
  110. strcat(msg, sSettings.sFlags.testState);
  111. strcat(msg, ";;");
  112. buf = netbuf_new();
  113. data = netbuf_alloc(buf, strlen(msg));
  114. memcpy(data, msg, strlen(msg));
  115. netconn_send(conn, buf);
  116. netbuf_delete(buf);
  117. netconn_delete(conn);
  118. }
  119. else
  120. netconn_delete(conn);
  121. }
  122. }
  123. /**
  124. * @brief
  125. */
  126. void TEST_SetServerFlag(void)
  127. {
  128. fServer = true;
  129. }
  130. /********************************* (C) РОТЕК **********************************/