testing.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /**
  40. * @brief Тестирование
  41. */
  42. // TODO Убрать заглушки
  43. void vTaskTesting(void *params)
  44. {
  45. uint8_t len;
  46. for (;;)
  47. {
  48. //printf("Start testing task\r\n");
  49. memset(ID, 0, 33);
  50. /* Читаем ID */
  51. GetSTM32IDStr(ID, &len);
  52. /* Отправляем запрос */
  53. TEST_SendData();
  54. /* Ждем timeout и высылаем ответ на тестер */
  55. vTaskDelay(2000);
  56. /* Если все прошло хорошо*/
  57. if (fServer)
  58. {
  59. LED_On(LED_INIT_R);
  60. /* Устанавливаем статус тестирования "T2OK" и сохраняем настройки */
  61. SETTINGS_SetT2OK();
  62. LED_Off(LED_INIT_R);
  63. fServer = false;
  64. vTaskDelay(2000);
  65. Reboot();
  66. vTaskDelete(NULL);
  67. }
  68. vTaskDelay(100);
  69. }
  70. }
  71. /**
  72. * @brief Отправляет строку данных по UDP
  73. */
  74. void TEST_SendData(void)
  75. {
  76. struct netconn *conn;
  77. struct netbuf *buf;
  78. char *data;
  79. char msg[MSG_LEN];
  80. err_t err;
  81. /* Отправляем сообщение на сервер по UDP */
  82. memset(msg, 0, MSG_LEN);
  83. conn = netconn_new( NETCONN_UDP );
  84. if (conn!= NULL)
  85. {
  86. err = netconn_bind(conn, IP_ADDR_ANY, UDP_PORT);
  87. if (err == ERR_OK)
  88. {
  89. netconn_connect(conn, IP_ADDR_BROADCAST, UDP_PORT);
  90. strcpy(msg, sSettings.sSnmp.sysName);
  91. strcat(msg, ";");
  92. /* Заглушка */
  93. //strcat(msg, "KN-03-00001;EC-4C-4D-00-90-01;0.8_DEMO;;;");
  94. strcat(msg, sSettings.sInfo.serialNumber);
  95. strcat(msg, ";");
  96. strcat(msg, sSettings.sInfo.mac);
  97. strcat(msg, ";");
  98. strcat(msg, VERSION);
  99. strcat(msg, ";;;");
  100. // for (uint8_t i = 0; i < 12; i++)
  101. {
  102. strcat(msg, ID);
  103. }
  104. strcat(msg, ";;;");
  105. strcat(msg, sSettings.sFlags.testState);
  106. strcat(msg, ";;");
  107. buf = netbuf_new();
  108. data = netbuf_alloc(buf, strlen(msg));
  109. memcpy(data, msg, strlen(msg));
  110. netconn_send(conn, buf);
  111. netbuf_delete(buf);
  112. netconn_delete(conn);
  113. }
  114. else
  115. netconn_delete(conn);
  116. }
  117. }
  118. /**
  119. * @brief
  120. */
  121. void TEST_SetServerFlag(void)
  122. {
  123. fServer = true;
  124. }
  125. /********************************* (C) РОТЕК **********************************/