testing.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. SETTINGS_SetAllDefault();
  65. SETTINGS_Save();
  66. LED_On(LED_INIT_R);
  67. /* Устанавливаем статус тестирования "T2OK" и сохраняем настройки */
  68. SETTINGS_SetT2OK();
  69. LED_Off(LED_INIT_R);
  70. fServer = false;
  71. vTaskDelay(2000);
  72. // Reboot();
  73. vTaskDelete(NULL);
  74. }
  75. vTaskDelay(100);
  76. }
  77. }
  78. /**
  79. * @brief Отправляет строку данных по UDP
  80. */
  81. void TEST_SendData(void)
  82. {
  83. struct netconn *conn;
  84. struct netbuf *buf;
  85. char *data;
  86. char msg[MSG_LEN];
  87. err_t err;
  88. /* Отправляем сообщение на сервер по UDP */
  89. memset(msg, 0, MSG_LEN);
  90. conn = netconn_new( NETCONN_UDP );
  91. if (conn!= NULL)
  92. {
  93. err = netconn_bind(conn, IP_ADDR_ANY, UDP_PORT);
  94. if (err == ERR_OK)
  95. {
  96. netconn_connect(conn, IP_ADDR_BROADCAST, UDP_PORT);
  97. strcpy(msg, HW_REV);
  98. strcat(msg, ";");
  99. /* Заглушка */
  100. //strcat(msg, "KN-03-00001;EC-4C-4D-00-90-01;0.8_DEMO;;;");
  101. strcat(msg, sSettings.sInfo.serialNumber);
  102. strcat(msg, ";");
  103. strcat(msg, sSettings.sInfo.mac);
  104. strcat(msg, ";");
  105. strcat(msg, VERSION);
  106. strcat(msg, ";;;");
  107. // for (uint8_t i = 0; i < 12; i++)
  108. {
  109. strcat(msg, ID);
  110. }
  111. strcat(msg, ";;;");
  112. strcat(msg, sSettings.sFlags.testState);
  113. strcat(msg, ";;");
  114. buf = netbuf_new();
  115. data = netbuf_alloc(buf, strlen(msg));
  116. memcpy(data, msg, strlen(msg));
  117. netconn_send(conn, buf);
  118. netbuf_delete(buf);
  119. netconn_delete(conn);
  120. }
  121. else
  122. netconn_delete(conn);
  123. }
  124. }
  125. /**
  126. * @brief
  127. */
  128. void TEST_SetServerFlag(void)
  129. {
  130. fServer = true;
  131. }
  132. /********************************* (C) РОТЕК **********************************/