| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 | /********************************* (C) РОТЕК *********************************** * @module  testing * @file    testing.c * @version 1.0.0 * @date    XX.XX.XXXX * $brief   Template ******************************************************************************* * @history     Version  Author         Comment * XX.XX.XXXX   1.0.0    Telenkov D.A.  First release. ******************************************************************************* */   #include "stm32f4xx.h"#include "testing.h"#include "settings_api.h"#include "common_config.h"#include "stm32_uid.h"#include "led.h"#include "hal.h"#include "FreeRTOS.h"#include "task.h"#include "lwip/opt.h"#include "lwip/arch.h"#include "lwip/api.h"#include "lwip/tcp.h"#ifdef PRINTF_STDLIB#include <stdio.h>#endif#ifdef PRINTF_CUSTOM#include "tinystdio.h"#endif#include <stdbool.h>#include <string.h>#define UDP_PORT 49049bool fTesting = false;bool fServer = false;#define MSG_LEN   300char ID[33];extern SETTINGS_t   sSettings;       // Общая структура настроекextern bool isIpReceived;/**  * @brief  Тестирование  */// TODO Убрать заглушкиvoid vTaskTesting(void *params){  uint8_t len;    while (!isIpReceived) {    vTaskDelay(100);  }        for (;;)  {    	  //printf("Start testing task\r\n");	  memset(ID, 0, 33);	  /* Читаем ID */	  GetSTM32IDStr(ID, &len);	  	  /* Отправляем запрос */      vTaskDelay(3000);	  TEST_SendData();	  	  /* Ждем timeout и высылаем ответ на тестер */	  vTaskDelay(2000);	  	  /* Если все прошло хорошо*/	  if (fServer)	  {		  SETTINGS_SetAllDefault();		  SETTINGS_Save();        LED_On(LED_INIT_R);		/* Устанавливаем статус тестирования "T2OK" и сохраняем настройки */		SETTINGS_SetT2OK();        LED_Off(LED_INIT_R);	    fServer = false;	    vTaskDelay(2000);	  //  Reboot();	    vTaskDelete(NULL);      }            vTaskDelay(100);	  }}/**  * @brief  Отправляет строку данных по UDP  */void TEST_SendData(void){  struct netconn *conn;  struct netbuf *buf;  char *data;  char msg[MSG_LEN];  err_t err;     /* Отправляем сообщение на сервер по UDP */  memset(msg, 0, MSG_LEN);   conn = netconn_new( NETCONN_UDP );    if (conn!= NULL)  {    err = netconn_bind(conn, IP_ADDR_ANY, UDP_PORT);         if (err == ERR_OK)    {      netconn_connect(conn, IP_ADDR_BROADCAST, UDP_PORT);      	  strcpy(msg, HW_REV);	  strcat(msg, ";");			  /* Заглушка */	  //strcat(msg, "KN-03-00001;EC-4C-4D-00-90-01;0.8_DEMO;;;");	  strcat(msg, sSettings.sInfo.serialNumber);	  strcat(msg, ";");	  	  strcat(msg, sSettings.sInfo.mac);	  strcat(msg, ";");       	  strcat(msg, VERSION);	  strcat(msg, ";;;");      	//  for (uint8_t i = 0; i < 12; i++)	  {		 strcat(msg, ID);	  }		        strcat(msg, ";;;");      	  strcat(msg, sSettings.sFlags.testState);	  	  strcat(msg, ";;");	  	  buf = netbuf_new();      data = netbuf_alloc(buf, strlen(msg));      memcpy(data, msg, strlen(msg));      netconn_send(conn, buf);      netbuf_delete(buf); 	  	  netconn_delete(conn);	}	else      netconn_delete(conn);  }	}/**  * @brief    */void TEST_SetServerFlag(void){  fServer = true;}/********************************* (C) РОТЕК **********************************/
 |