/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
*
© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "SIM_STM32.h"
#include "FLASH_STM32.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "stdbool.h"
#include "wizchip_conf.h"
#include "w5500.h"
#include "socket.h"
#include "dhcp.h"
#include "ftpc.h"
#include "math.h"
#include "dns.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define LCD_UART huart1
/*---DEFINE---*/
#define TINH "GL"
#define COSO "KDPU"
#define TRAM "NUO001"
/*SIM*/
#define HTTPREQ "http://testdogio.tapit.vn/dienphu.html"
/*Sensor IN*/
#define SSHIGH_IN_MAX 101.16F //Unit: m
#define SSHIGH_IN_MIN 0.0F //Unit: m
#define WFHIGH_MAX SSHIGH_IN_MAX //Unit: m
/*Sensor OUT*/
#define SSHIGH_OUT_MAX 0.75F //Unit: m
#define SSHIGH_OUT_MIN 0.21F //Unit: m
#define CALCULATEH20FLOW(x) 1372*(pow(x,1.580)) //Mang pascal
#define MAXINDEX 10
/*------*/
#define WAIT4DATA 20000
#define WAIT4CONNECT 3000
#define DATA_BUF_SIZE 4000
#define MY_MAX_DHCP_RETRY 3
/*Socket*/
#define SOCK_DNS 4
#define SOCK_DHCP 2
#define SOCK_TCPS 0
#define SOCK_TCPS_SERVER_PORT 80
#define SOCK_TCPS_FTP_PORT 21
/*ADC*/
#define VOLPOWER 3.32
#define THRESHOLD_MIN_VALUE 0.05
#define THRESHOLD_MAX_VALUE 1.00
#define NSAMPLE 50
#define ADC_1 0
#define ADC_2 1
#define ADC_3 2
#define FLOW_IN ADC_1
#define FLOW_OUT ADC_2
/*FLASH*/
#define MIN_PAGE_ADDR 0x0800B7F0 //End of page 22
#define MAX_PAGE_ADDR 0x0800EFF0 //End of page 30
#define MIN_DATA_ADDR 0x0800B000 //Page 22
#define RD_ADDR 0x0800F800 //Page 31
#define WR_ADDR 0x0800F810 //Page 31
#define PG_ADDR 0x0800F820 //Page 31
/*TIME*/
#define UTC_0 0x0
#define UTC_7 0x7
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
IWDG_HandleTypeDef hiwdg;
RTC_HandleTypeDef hrtc;
SPI_HandleTypeDef hspi1;
TIM_HandleTypeDef htim4;
UART_HandleTypeDef huart5;
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart3;
/* USER CODE BEGIN PV */
/*=====SIM=====*/
extern uint8_t Sim_Rxbyte[1];
extern uint8_t Sim_Rxdata[MAX_RECVBUF_LEN];
char Sim_FTPServer[20] = {0};
/*========RTC==========*/
RTC_TimeTypeDef TimeToUpdate = {0};
RTC_DateTypeDef DateToUpdate = {0};
RTC_AlarmTypeDef sAlarm = {0};
volatile bool isOnTimeToSendFile = false;
volatile bool startCountingTime = false;
bool isUpdateTimezone = false;
extern uint8_t RTC_ALARM;
volatile struct time {
char sec[6];
char min[6];
char hour[6];
char date[6];
char day[6];
char mon[6];
char year[7];
char timezone[31];
int8_t UTC;
} TimeZone;
/*========ETHERNET==========*/
uint16_t SOCK_TCPS_MY_PORT = 16894;
/*========IP FTP Server==========*/
uint8_t FTP_IP_1[5] = {103, 255, 236, 68}; //
uint8_t FTP_IP_2[5] = {0}; //
uint8_t FTP_IP_3[5] = {0}; //
uint8_t FTP_IP_4[5] = {0}; //
/*========Path FTP Server==========*/
uint8_t FTP_PATH_1[30] = "TTQTMT1"; //
uint8_t FTP_PATH_2[30] = {0}; //
uint8_t FTP_PATH_3[30] = {0}; //
uint8_t FTP_PATH_4[30] = {0}; //
/*========USER FTP Server==========*/
uint8_t FTP_USER_1[30] = "testdogio"; //
uint8_t FTP_USER_2[30] = {0}; //
uint8_t FTP_USER_3[30] = {0}; //
uint8_t FTP_USER_4[30] = {0}; //
/*========P@$$ FTP Server==========*/
uint8_t FTP_PASS_1[30] = "123456"; //
uint8_t FTP_PASS_2[30] = {0}; //
uint8_t FTP_PASS_3[30] = {0}; //
uint8_t FTP_PASS_4[30] = {0}; //
/*========IP HTTP Server & Request String==========*/
uint8_t HTTP_ServerIP[4] = {103, 255, 236, 68};
char HTTP_Format[]={
"GET /dienphu.html HTTP/1.0\r\n"
"Host: testdogio.tapit.vn\r\n"
"Connection: close\r\n"
"\r\n"
};
/*========IP HTTP & Request Change Server String==========*/
uint8_t HTTP_TapitIP[4] = {103, 255, 236, 68};
char HTTP_ChangeServerFormat[]={
"GET /quantracmoitruong/dienphu/checkserver.php?checksv=1 HTTP/1.0\r\n"
"Host: testdogio.tapit.vn\r\n"
"Connection: close\r\n"
"\r\n"
};
/*========INTERNET==========*/
char FTP_ServerIP[5] = {0};
char FTP_UserName[30]= {0};
char FTP_Password[30]= {0};
char FTP_Path[30]= {0};
bool isRunServer = true;
bool isReqChangeServer = true;
bool isFTPready = true;
uint8_t gDATABUF[DATA_BUF_SIZE];
wiz_NetInfo netInfo,netinfo; //netInfo: network infor before get DHCP; netinfo: after get DHCP
bool isDHCPsuccess = false;
bool isNoEthernet = false;
bool isNoInternet = false;
uint8_t bufSize[] = {8, 2, 2, 2, 2, 0, 0, 0}; //Size of each socket (8 sockets)
char DataToSend[300]={0};
extern struct ftpsocket ftpsock;
/*========SENSOR==========*/
typedef struct sensor {
char MVAL[8];
char MPARA[8];
char SVAL[8];
char INFO[8];
} Sensor;
Sensor sensor[7] = {0};
char TSSval[10] = {0};
char CODval[10] = {0};
char PHval[10] = {0};
char Tempval[10] = {0};
char Flowval_in[10] = {0};
char Flowval_out[10] = {0};
char NH4val[10] = {0};
uint8_t quantity, quantityE, quantityO = 0;
char mval[8], munit[8], mpara[8], sval[8], info[8] = {0};
/*========ADC==========*/
float Current_Max = 0;
uint16_t ADCvalue[3] = {0};
float adc_vol, adc_avg, current = 0;
uint8_t count;
float FinalCurrent;
int ADCarray[NSAMPLE+1] = {0};
/*========FILE=========*/
char FTP_FileName[50] = {0};
char temp_filename[50] = {0};
/*========FLASH==========*/
uint32_t WRITE_DATA_ADDR = MIN_DATA_ADDR;
uint32_t READ_DATA_ADDR = MIN_DATA_ADDR;
uint32_t PAGE_ADDR = MAX_PAGE_ADDR;
uint16_t Flash_Counter = 0;
char DataFromFlash[300] = {0};
uint16_t DataFlashSize = 0;
/*========DNS=========*/
uint8_t DNS_2nd[5] = {192,168,1,0}; // Secondary DNS server IP
//uint8_t DNS_2nd[5] = {123,23,23,23}; // Secondary DNS server IP - Test
uint8_t Domain_name[MAX_DOMAIN_NAME] = "qtmt.tapit.vn";
uint8_t Domain_IP[4] = {0, }; // Translated IP address by DNS
//========OTHERS=========//
RTC_TimeTypeDef TimeToDisplay = {0};
uint16_t msTicks = 0;
#ifdef _IWDG_
uint32_t currentTick = 0;
#endif
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_UART5_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_RTC_Init(void);
static void MX_IWDG_Init(void);
static void MX_ADC1_Init(void);
static void MX_SPI1_Init(void);
static void MX_TIM4_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
void insertionSort(int arr[], int n);
void resetStruct(struct sensor *s);
void getData(char *res, char* des, char* id);
int indexoffrom(const char *str, const char* sub, int from);
int indexof(const char *str, const char* sub);
void substr(char* str, char* sub, int pos, int len);
int hexadecimalToDecimal(char hexVal[]);
void dhcp_routine(void);
void my_ip_conflict(void);
void my_ip_assign(void);
void network_init(void);
void spi_wb(uint8_t b);
uint8_t spi_rb(void);
void cs_desel(void);
void cs_sel(void);
STATUS HTTP_sendRequest(uint16_t MyPort, uint8_t* ServerIP, uint32_t ServerPort, uint8_t * DataToSend);
STATUS HTTP_recvResponse(uint8_t* recvData);
void HTTP_extractData(char* data);
STATUS HTTP_extractIP(char* data);
STATUS FTP_sendFileToServer(uint8_t* serverIP, char* data);
void FTP_sendFileToMultiServer(uint8_t* serverIP, uint8_t* serverPath, uint8_t* User,
uint8_t* Pass, uint8_t UTC, char* filename, char* data);
void FTP_combineMultiData(char* filename, char* data);
STATUS FTP_loginProcess(char* server,uint16_t port,char* path,char* user,char* pass);
void Sim_reset(void);
STATUS Sim_getFileModificationTime(char* filename, char* datetime);
void Flash_extractData(char* data);
void Flash_init(void);
float Sensor_getADCValue(uint8_t channel);
void Sensor_convertToString(uint8_t* data, uint8_t channel);
float ADC_map(float x, float in_min, float in_max, float out_min, float out_max);
void classificateSensors(Sensor* ss);
uint8_t findOccurrenceOfSubStr(char* substr, char* str);
void Ethernet_init(void);
void Ethernet_reset(void);
void Flash_init(void);
void Flash_writeData(char* serverip, char* filename, char* data);
void Flash_extractData(char* data);
#ifdef _IWDG_
void refreshIWDG(uint16_t ms);
#endif
void LCD_sendCmd(char* data);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void HAL_SYSTICK_Callback(void)
{
msTicks++;
if(msTicks % 1000 == 0)
{
DNS_time_handler();
DHCP_time_handler();
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_UART5_Init();
MX_USART3_UART_Init();
MX_RTC_Init();
#ifdef _IWDG_
MX_IWDG_Init();
#endif
MX_ADC1_Init();
MX_SPI1_Init();
MX_TIM4_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED);
char cmd_time[20] = {0}, cmd_date[30] = {0};
LCD_sendCmd("page 0"); //page welcome
HAL_RTC_GetTime(&hrtc, &TimeToDisplay, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN);
sprintf(cmd_time,"t1.txt=\"%02u:%02u\"",TimeToDisplay.Hours,TimeToDisplay.Minutes);
sprintf(cmd_date,"t2.txt=\"%02u/%02u/20%02u\"",DateToUpdate.Date,DateToUpdate.Month,DateToUpdate.Year);
LCD_sendCmd(cmd_time);
LCD_sendCmd(cmd_date);
//========INIT========//
// Ethernet_reset();
// Ethernet_init();
HAL_UART_Receive_IT(&SIM_UART, Sim_Rxbyte, 1);
Sim_reset();
Flash_init();
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
char HTTP_GetRequest[4000] = {0};
LCD_sendCmd("page 1"); //page data
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Configure LSE Drive Capability
*/
HAL_PWR_EnableBkUpAccess();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI
|RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART3
|RCC_PERIPHCLK_UART5|RCC_PERIPHCLK_RTC
|RCC_PERIPHCLK_ADC12;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
PeriphClkInit.Uart5ClockSelection = RCC_UART5CLKSOURCE_PCLK1;
PeriphClkInit.Adc12ClockSelection = RCC_ADC12PLLCLK_DIV1;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 2;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_601CYCLES_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_2;
sConfig.Rank = ADC_REGULAR_RANK_2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
/**
* @brief IWDG Initialization Function
* @param None
* @retval None
*/
static void MX_IWDG_Init(void)
{
/* USER CODE BEGIN IWDG_Init 0 */
/* USER CODE END IWDG_Init 0 */
/* USER CODE BEGIN IWDG_Init 1 */
/* USER CODE END IWDG_Init 1 */
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
hiwdg.Init.Window = 4095;
hiwdg.Init.Reload = 4095;
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN IWDG_Init 2 */
/* USER CODE END IWDG_Init 2 */
}
/**
* @brief RTC Initialization Function
* @param None
* @retval None
*/
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Check_RTC_BKUP */
if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0x32F2)
{
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date
*/
sTime.Hours = 8;
sTime.Minutes = 0;
sTime.Seconds = 0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
{
Error_Handler();
}
sDate.WeekDay = RTC_WEEKDAY_THURSDAY;
sDate.Month = RTC_MONTH_DECEMBER;
sDate.Date = 10;
sDate.Year = 20;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
{
Error_Handler();
}
/** Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 8;
sAlarm.AlarmTime.Minutes = 2;
sAlarm.AlarmTime.Seconds = 0;
sAlarm.AlarmTime.SubSeconds = 0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 1;
sAlarm.Alarm = RTC_ALARM_A;
if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BIN) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN RTC_Init 2 */
HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1,0x32F2);
TimeToUpdate = sTime;
DateToUpdate = sDate;
}
else
{
HAL_RTC_GetTime(&hrtc, &TimeToUpdate, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN);
/**Enable the Alarm A */
sAlarm.AlarmTime.Hours = TimeToUpdate.Hours;
sAlarm.AlarmTime.Minutes = TimeToUpdate.Minutes;
sAlarm.AlarmTime.Seconds = 0;
sAlarm.AlarmTime.SubSeconds = 0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 1;
sAlarm.Alarm = RTC_ALARM_A;
sAlarm.Alarm = RTC_ALARM_A;
User_InitAlarm(sAlarm.AlarmTime.Hours,sAlarm.AlarmTime.Minutes,sAlarm.AlarmTime.Seconds);
}
/* USER CODE END RTC_Init 2 */
}
/**
* @brief SPI1 Initialization Function
* @param None
* @retval None
*/
static void MX_SPI1_Init(void)
{
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
/* USER CODE BEGIN SPI1_Init 1 */
/* USER CODE END SPI1_Init 1 */
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
/**
* @brief TIM4 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM4_Init(void)
{
/* USER CODE BEGIN TIM4_Init 0 */
/* USER CODE END TIM4_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM4_Init 1 */
/* USER CODE END TIM4_Init 1 */
htim4.Instance = TIM4;
htim4.Init.Prescaler = 799;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 9999;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM4_Init 2 */
/* USER CODE END TIM4_Init 2 */
}
/**
* @brief UART5 Initialization Function
* @param None
* @retval None
*/
static void MX_UART5_Init(void)
{
/* USER CODE BEGIN UART5_Init 0 */
/* USER CODE END UART5_Init 0 */
/* USER CODE BEGIN UART5_Init 1 */
/* USER CODE END UART5_Init 1 */
huart5.Instance = UART5;
huart5.Init.BaudRate = 115200;
huart5.Init.WordLength = UART_WORDLENGTH_8B;
huart5.Init.StopBits = UART_STOPBITS_1;
huart5.Init.Parity = UART_PARITY_NONE;
huart5.Init.Mode = UART_MODE_TX_RX;
huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart5.Init.OverSampling = UART_OVERSAMPLING_16;
huart5.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart5.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart5) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN UART5_Init 2 */
/* USER CODE END UART5_Init 2 */
}
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/**
* @brief USART3 Initialization Function
* @param None
* @retval None
*/
static void MX_USART3_UART_Init(void)
{
/* USER CODE BEGIN USART3_Init 0 */
/* USER CODE END USART3_Init 0 */
/* USER CODE BEGIN USART3_Init 1 */
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART3_Init 2 */
/* USER CODE END USART3_Init 2 */
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_STATUS_GPIO_Port, LED_STATUS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, SPI1_RST_Pin|SPI1_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, PWR_CTRL_Pin|SIM_DTR_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(SIM_PWR_GPIO_Port, SIM_PWR_Pin, GPIO_PIN_SET);
/*Configure GPIO pin : LED_STATUS_Pin */
GPIO_InitStruct.Pin = LED_STATUS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_STATUS_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : SPI1_RST_Pin SPI1_CS_Pin */
GPIO_InitStruct.Pin = SPI1_RST_Pin|SPI1_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : PWR_CTRL_Pin SIM_DTR_Pin SIM_PWR_Pin */
GPIO_InitStruct.Pin = PWR_CTRL_Pin|SIM_DTR_Pin|SIM_PWR_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : SIM_RI_Pin */
GPIO_InitStruct.Pin = SIM_RI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(SIM_RI_GPIO_Port, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
/*SPI*/
void cs_sel() {
HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET); //CS LOW
}
void cs_desel() {
HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_SET); //CS HIGH
}
uint8_t spi_rb(void) {
uint8_t rbuf;
HAL_SPI_Receive(&hspi1, &rbuf, 1, 0xFFFFFFFF);
return rbuf;
}
void spi_wb(uint8_t b) {
HAL_SPI_Transmit(&hspi1, &b, 1, 0xFFFFFFFF);
}
/*DHCP*/
void network_init(void)
{
uint8_t tmpstr[6] = {0,};
//Set Network information from netinfo structure
ctlnetwork(CN_SET_NETINFO, (void*)&netInfo);
// Get Network information
ctlnetwork(CN_GET_NETINFO, (void*)&netinfo);
// Display Network Information
ctlwizchip(CW_GET_ID,(void*)tmpstr);
#if (_DEBUG_ == 1)
printf("===================================");
#endif
if(netinfo.dhcp == NETINFO_DHCP) printf("\r\n=== %s NET CONF : DHCP ===\r\n",(char*)tmpstr);
else printf("\r\n=== %s NET CONF : Static ===\r\n",(char*)tmpstr);
printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n",netinfo.mac[0],netinfo.mac[1],netinfo.mac[2], netinfo.mac[3],netinfo.mac[4],netinfo.mac[5]);
printf("SIP: %d.%d.%d.%d\r\n", netinfo.ip[0],netinfo.ip[1],netinfo.ip[2],netinfo.ip[3]);
printf("GAR: %d.%d.%d.%d\r\n", netinfo.gw[0],netinfo.gw[1],netinfo.gw[2],netinfo.gw[3]);
printf("SUB: %d.%d.%d.%d\r\n", netinfo.sn[0],netinfo.sn[1],netinfo.sn[2],netinfo.sn[3]);
printf("DNS: %d.%d.%d.%d\r\n", netinfo.dns[0],netinfo.dns[1],netinfo.dns[2],netinfo.dns[3]);
}
void my_ip_assign(void)
{
getIPfromDHCP(netInfo.ip);
getGWfromDHCP(netInfo.gw);
getSNfromDHCP(netInfo.sn);
getDNSfromDHCP(netInfo.dns);
netInfo.dhcp = NETINFO_DHCP;
/* Network initialization */
network_init(); // apply from dhcp
#if (_DEBUG_ == 1)
printf("DHCP LEASED TIME : %ld Sec.\r\n", (long)getDHCPLeasetime());
#endif
isDHCPsuccess = true;
}
void my_ip_conflict()
{
#if (_DEBUG_ == 1)
printf("CONFLICT IP from DHCP\r\n");
#endif
}
void dhcp_routine()
{
uint8_t my_dhcp_retry = 0;
switch(DHCP_run())
{
case DHCP_IP_ASSIGN:
break;
case DHCP_IP_CHANGED:
break;
case DHCP_IP_LEASED:
break;
case DHCP_FAILED:
my_dhcp_retry++;
if(my_dhcp_retry > MY_MAX_DHCP_RETRY)
{
#if (_DEBUG_ == 1)
printf(">> DHCP %d Failed\r\n", my_dhcp_retry);
#endif
my_dhcp_retry = 0;
DHCP_stop(); // if restart, recall DHCP_init()
network_init();
}
break;
case DHCP_RUNNING:
break;
case DHCP_STOPPED:
break;
default:
break;
}
}
void Ethernet_reset(void)
{
HAL_GPIO_WritePin(SPI1_RST_GPIO_Port, SPI1_RST_Pin, GPIO_PIN_RESET);
HAL_Delay(1);
HAL_GPIO_WritePin(SPI1_RST_GPIO_Port, SPI1_RST_Pin, GPIO_PIN_SET);
HAL_Delay(5);
}
void Ethernet_init(void)
{
int8_t ret;
#if (_DEBUG_ == 1)
printf("W5500 init\r\n");
HAL_RTC_GetTime(&hrtc, &TimeToDisplay, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN);
printf("-->Time: %02d:%02d:%02d\r\n",TimeToDisplay.Hours,TimeToDisplay.Minutes,TimeToDisplay.Seconds);
#endif
netInfo.mac[0] = 0x00;netInfo.mac[1] = 0x08;netInfo.mac[2] = 0xed;
netInfo.mac[3] = 0xab;netInfo.mac[4] = 0xbc;netInfo.mac[5] = 0xab;
netInfo.ip[0] = 192;netInfo.ip[1] = 168;netInfo.ip[2] = 2;netInfo.ip[3] = 60;
netInfo.sn[0] = 255;netInfo.sn[1] = 255;netInfo.sn[2] = 255;netInfo.sn[3] = 0;
netInfo.gw[0] = 192;netInfo.gw[1] = 168;netInfo.gw[2] = 1;netInfo.gw[3] = 1;
netInfo.dns[0] = 192;netInfo.dns[1] = 168;netInfo.dns[2] = 1;netInfo.dns[3] = 1;
// netInfo.gw[0] = 192;netInfo.gw[1] = 168;netInfo.gw[2] = 23;netInfo.gw[3] = 1; //test
// netInfo.dns[0] = 123;netInfo.dns[1] = 26;netInfo.dns[2] = 26;netInfo.dns[3] = 26; //test
netInfo.dhcp = NETINFO_DHCP;
cs_desel();
reg_wizchip_spi_cbfunc(spi_rb, spi_wb);
reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
wizchip_init(bufSize, bufSize);
wizchip_setnetinfo(&netInfo);
wizchip_getnetinfo(&netInfo);
uint8_t temp;
//========ETHERNET=========//
// #ifdef _IWDG_
// HAL_IWDG_Refresh(&hiwdg);
// #endif
// uint8_t cnt = 0;
// do
// {
// HAL_Delay(1000);
// cnt++;
// if(cnt == 10)
// {
// #if (_DEBUG_ == 1)
// printf("No Ethernet\r\n");
// #endif
// isNoEthernet = true;
// break;
// }
// if (ctlwizchip(CW_GET_PHYLINK, (void*)&temp) == -1)
// {
// #if (_DEBUG_ == 1)
// printf("Unknown PHY link status.\r\n");
// #endif
// }
// } while (temp == PHY_LINK_OFF);
// HAL_Delay(1000);
// #ifdef _IWDG_
// HAL_IWDG_Refresh(&hiwdg);
// #endif
//=======DNS=======//
// #if (_DEBUG_ == 1)
// printf("\r\n================ DNS ===============\r\n");
// printf("> DNS 1st : %d.%d.%d.%d\r\n", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
// printf("> DNS 2nd : %d.%d.%d.%d\r\n", DNS_2nd[0], DNS_2nd[1], DNS_2nd[2], DNS_2nd[3]);
// printf("> Domain Name : %s\r\n", Domain_name);
// printf("====================================\r\n");
// #endif
/* DNS client initialization */
// DNS_init(SOCK_DNS, gDATABUF);
// /* DNS procssing */
// if((ret = DNS_run(netInfo.dns, Domain_name, Domain_IP)) > 0) // try to 1st DNS
// {
// #if (_DEBUG_ == 1)
// printf("> 1st DNS Reponsed\r\n");
// #endif
// }
// else if((ret != -1) && ((ret = DNS_run(DNS_2nd, Domain_name, Domain_IP))>0)) // retry to 2nd DNS
// {
// #if (_DEBUG_ == 1)
// printf("> 2nd DNS Reponsed\r\n");
// #endif
// }
// else if(ret == -1)
// {
// #if (_DEBUG_ == 1)
// printf("> MAX_DOMAIN_NAME is too small.\r\n");
// #endif
// }
// else
// {
// #if (_DEBUG_ == 1)
// printf("> DNS Failed\r\n");
// #endif
// }
// if(ret > 0)
// {
// #if (_DEBUG_ == 1)
// printf("> Translated %s to %d.%d.%d.%d\r\n",Domain_name,Domain_IP[0],\
// Domain_IP[1],Domain_IP[2],Domain_IP[3]);
// #endif
// strcpy((char*)FTP_IP_1,(char*)Domain_IP);
// strcpy((char*)HTTP_TapitIP,(char*)Domain_IP);
// }
// memset(gDATABUF,0,strlen((char*)gDATABUF));
// //=======DHCP=======//
// #if (_DEBUG_ == 1)
// printf("DHCP init\r\n");
// #endif
// DHCP_init(SOCK_DHCP, gDATABUF);
// reg_dhcp_cbfunc(my_ip_assign, my_ip_assign, my_ip_conflict);
// #ifdef _IWDG_
// HAL_IWDG_Refresh(&hiwdg);
// #endif
}
//TCP
STATUS HTTP_sendRequest(uint16_t MyPort, uint8_t* ServerIP, uint32_t ServerPort, uint8_t * DataToSend)
{
#if (_DEBUG_ == 1)
printf("HTTP_sendRequest() running\r\n");
#endif
int8_t check = 0;
check = socket(SOCK_TCPS,Sn_MR_TCP,MyPort,0); //open socket
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
if(check == SOCK_TCPS)
{
#if (_DEBUG_ == 1)
printf("Open socket success at port %d\r\n",getSn_PORT(SOCK_TCPS));
#endif
check = connect(SOCK_TCPS, ServerIP, ServerPort);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
if(check == SOCK_OK)
{
#if (_DEBUG_ == 1)
printf("Connect success\r\n");
#endif
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
check = send(SOCK_TCPS, DataToSend, strlen((char*)DataToSend));
#if (_DEBUG_ == 1)
printf("Send %s \r\n",DataToSend);
#endif
if(check < 1)
{
isNoEthernet = true;
#if (_DEBUG_ == 1)
printf("Send error\r\n");
printf("Close & Disconnect socket\r\n");
#endif
close(SOCK_TCPS);
return RET_ERROR;
}
else
{
isNoEthernet = false;
return RET_OK;
}
} else {
#if (_DEBUG_ == 1)
printf("Connect fail\r\n");
printf("Close & Disconnect socket\r\n");
#endif
close(SOCK_TCPS);
isNoEthernet = true;
return RET_ERROR;
}
} else {
#if (_DEBUG_ == 1)
printf("Open socket failed!\r\n");
printf("Disconnect socket\r\n");
#endif
close(SOCK_TCPS);
isNoEthernet = true;
return RET_ERROR;
}
}
STATUS HTTP_recvResponse(uint8_t* recvData)
{
#if (_DEBUG_ == 1)
printf("HTTP_recvResponse() runing\r\n");
#endif
uint32_t timeout = HAL_GetTick();
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
while(getSn_RX_RSR(SOCK_TCPS)==0)
{
if(HAL_GetTick() - timeout > WAIT4DATA)
{
#if (_DEBUG_ == 1)
printf("Error: Timeout\r\n");
printf("Close & Disconnect socket\r\n");
#endif
close(SOCK_TCPS);
return RET_TIMEOUT;
}
}
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
if(getSn_RX_RSR(SOCK_TCPS)>0) //if data come
{
recv(SOCK_TCPS, recvData, DATA_BUF_SIZE);
#if (_DEBUG_ == 1)
printf("HTTP data came\r\n");
#endif
}
#if (_DEBUG_ == 1)
printf("Close & Disconnect socket\r\n");
#endif
disconnect(SOCK_TCPS);
close(SOCK_TCPS);
return RET_OK;
}
void HTTP_extractData(char* data)
{
#if (_DEBUG_ == 1)
printf("HTTP_extractData() running\r\n");
#endif
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
quantityE = findOccurrenceOfSubStr("EvenRow", data);
quantityO = findOccurrenceOfSubStr("OddRow", data) - 1;
if(quantityE > quantityO) quantity = quantityE*2 - 1;
else quantity = quantityE*2;
for(uint8_t i = 0; i < quantity; i++)
{
resetStruct(&sensor[i]);
}
uint8_t cnt = 0;
for(uint8_t i = 0; i < MAXINDEX; i++)
{
sprintf(mval, "MVAL%hu", i+1);
if(strstr(data, mval) != NULL)
{
sprintf(munit, "MUNIT%hu", i+1);
sprintf(mpara, "MPARA%hu", i+1);
sprintf(sval, "SVAL%hu", i+1);
sprintf(info, "INFO%hu", i+1);
getData((char*)data, sensor[i].MVAL, mval);
getData((char*)data, sensor[i].SVAL, sval);
getData((char*)data, sensor[i].MPARA, mpara);
getData((char*)data, sensor[i].INFO, info);
classificateSensors(&sensor[i]);
cnt++;
if(cnt > quantity) break;
}
}
deleteBuffer(mval, 6);
deleteBuffer(munit, 7);
deleteBuffer(mpara, 7);
deleteBuffer(sval, 6);
deleteBuffer(info, 6);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
}
STATUS HTTP_extractIP(char* data)
{
char* tok = strtok(data,"|");
tok = strtok(NULL,"|"); //|on/off
if(tok != NULL)
{
if((strstr(tok,"on") != NULL) || (strstr(tok,"off") != NULL))
{
if(strstr(tok,"off") != NULL)
{
isRunServer = false;
}
uint8_t buf1[30], buf2[30] = {0};
deleteBuffer((char*)FTP_IP_1,5);
deleteBuffer((char*)FTP_PATH_1,30);
deleteBuffer((char*)FTP_USER_1,30);
deleteBuffer((char*)FTP_PASS_1,30);
deleteBuffer((char*)FTP_IP_2,5);
deleteBuffer((char*)FTP_PATH_2,30);
deleteBuffer((char*)FTP_USER_2,30);
deleteBuffer((char*)FTP_PASS_2,30);
tok = strtok(NULL,"|"); //|ip
strcpy((char*)buf1,tok);
tok = strtok(NULL,"|"); //path
strcpy((char*)FTP_PATH_2,tok);
tok = strtok(NULL,"|"); //user
strcpy((char*)FTP_USER_2,tok);
tok = strtok(NULL,"|"); //pass
strcpy((char*)FTP_PASS_2,tok);
tok = strtok(NULL,"|"); //|ip TAPIT
strcpy((char*)buf2,tok);
tok = strtok(NULL,"|"); //path TAPIT
strcpy((char*)FTP_PATH_1,tok);
tok = strtok(NULL,"|"); //user TAPIT
strcpy((char*)FTP_USER_1,tok);
tok = strtok(NULL,"|"); //pass TAPIT
strcpy((char*)FTP_PASS_1,tok);
char* ptr = strtok((char*)buf1,".");
FTP_IP_2[0] = atoi(ptr);
ptr = strtok(NULL,".");
FTP_IP_2[1] = atoi(ptr);
ptr = strtok(NULL,".");
FTP_IP_2[2] = atoi(ptr);
ptr = strtok(NULL,".");
FTP_IP_2[3] = atoi(ptr);
ptr = strtok((char*)buf2,".");
FTP_IP_1[0] = atoi(ptr);
ptr = strtok(NULL,".");
FTP_IP_1[1] = atoi(ptr);
ptr = strtok(NULL,".");
FTP_IP_1[2] = atoi(ptr);
ptr = strtok(NULL,".");
FTP_IP_1[3] = atoi(ptr);
}
return RET_OK;
}
return RET_FAIL;
}
void FTP_combineMultiData(char* filename, char* data)
{
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
memset(data,0,strlen(data));
memset(filename,0,50);
memset(temp_filename,0,50);
sprintf(data, "TSS\t%s\t%s\t%s\t%s\r\n",TSSval,"mg/l",TimeZone.timezone,"00");
sprintf(data, "%sCOD\t%s\t%s\t%s\t%s\r\n",data,CODval,"mg/l",TimeZone.timezone,"00");
sprintf(data, "%spH\t%s\t%s\t%s\t%s\r\n",data,PHval,"",TimeZone.timezone,"00");
sprintf(data,"%sTemp\t%s\t%s\t%s\t%s\r\n",data,Tempval,"oC",TimeZone.timezone,"00");
sprintf(data,"%sNH4+\t%s\t%s\t%s\t%s\r\n",data,NH4val,"mg/l",TimeZone.timezone,"00");
sprintf(data,"%sIn_Flow\t%s\t%s\t%s\t%s\r\n",data,Flowval_in,"m3/h",TimeZone.timezone,"00");
sprintf(data,"%sOut_Flow\t%s\t%s\t%s\t%s\r\n",data,Flowval_out,"m3/h",TimeZone.timezone,"00");
sprintf(filename,"%s_%s_%s_%s.txt",TINH,COSO,TRAM,TimeZone.timezone);
strcpy((char*)temp_filename, filename);
#if (_DEBUG_ == 1)
printf("FTP_combineMultiData() running\r\n");
#endif
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
}
STATUS FTP_sendFileToServer(uint8_t* serverIP, char* data)
{
#if (_DEBUG_ == 1)
printf("FTP_sendFileToServer() running\r\n");
printf("===========================\r\n");
printf("IP: %d.%d.%d.%d\r\n",serverIP[0],serverIP[1],serverIP[2],serverIP[3]);
printf("USER: %s\r\n",FTP_UserName);
printf("PASS: %s\r\n",FTP_Password);
printf("PATH: %s\r\n",FTP_Path);
printf("===========================\r\n");
HAL_RTC_GetTime(&hrtc, &TimeToDisplay, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN);
printf("-->Time: %02d:%02d:%02d\r\n",TimeToDisplay.Hours,TimeToDisplay.Minutes,TimeToDisplay.Seconds);
#endif
uint32_t waittime = HAL_GetTick();
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
while(isFTPready)
{
FTPClient_Instruction(serverIP);
FTPClient_Data(serverIP,data);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
if((HAL_GetTick() - waittime) > 20000)
{
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
if(ftpsock.control == SOCK_ESTABLISHED)
{
#if (_DEBUG_ == 1)
printf("control socket = SOCK_ESTABLISHED\r\n");
#endif
disconnect(CTRL_SOCK);
HAL_Delay(5);
}
if(ftpsock.data == SOCK_ESTABLISHED)
{
#if (_DEBUG_ == 1)
printf("data socket = SOCK_ESTABLISHED\r\n");
#endif
disconnect(DATA_SOCK);
HAL_Delay(5);
}
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
if(ftpsock.control != SOCK_CLOSED)
{
#if (_DEBUG_ == 1)
printf("control socket = SOCK_CLOSED\r\n");
#endif
close(CTRL_SOCK);
HAL_Delay(5);
}
if(ftpsock.data != SOCK_CLOSED)
{
#if (_DEBUG_ == 1)
printf("data socket = SOCK_CLOSED\r\n");
#endif
close(DATA_SOCK);
HAL_Delay(5);
}
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
return RET_TIMEOUT;
}
}
isFTPready = true;
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
return RET_OK;
}
void FTP_sendFileToMultiServer(uint8_t* serverIP, uint8_t* serverPath, uint8_t* User,
uint8_t* Pass, uint8_t UTC, char* filename, char* data)
{
isUpdateTimezone = false;
if(strstr((char*)serverIP,(char*)FTP_IP_1)!=NULL)
{
isUpdateTimezone = true;
TimeZone.UTC = UTC;
}
memset(filename,0,strlen((char*)filename));
memset(FTP_ServerIP,0,strlen((char*)FTP_ServerIP));
memset(FTP_Path,0,strlen((char*)FTP_Path));
memset(FTP_UserName,0,strlen((char*)FTP_UserName));
memset(FTP_Password,0,strlen((char*)FTP_Password));
strcpy(filename,temp_filename);
strcpy(FTP_ServerIP,(char*)serverIP);
strcpy(FTP_Path,(char*)serverPath);
strcpy(FTP_UserName,(char*)User);
strcpy(FTP_Password,(char*)Pass);
#if (_DEBUG_ == 1)
printf("File name: %s\r\n",filename);
#endif
if(FTP_sendFileToServer((uint8_t*)FTP_ServerIP, data) == RET_TIMEOUT) //if send file fail
{
isNoEthernet = true;
}
else //if success
{
isNoEthernet = false;
}
}
STATUS FTP_loginProcess(char* server,uint16_t port,char* path,char* user,char* pass)
{
if(FTP_configParams() == RET_OK)
{
if(FTP_setUserAndPass(user, pass) == RET_OK)
{
if(FTP_setFileType(binary) == RET_OK)
{
if(FTP_setTransmode(passive) == RET_OK)
{
if(FTP_setRspTimeout(90) == RET_OK)
{
if(FTPS_configuration() == RET_OK)
{
if(FTP_loginServer(server,port) == RET_OK)
{
if(FTP_setPath(path) == RET_OK)
{
return RET_OK;
}
}
}
}
}
}
}
}
return RET_FAIL;
}
void Sim_reset(void)
{
HAL_GPIO_WritePin(SIM_PWR_GPIO_Port, SIM_PWR_Pin, GPIO_PIN_SET);
HAL_Delay(3000);
HAL_GPIO_WritePin(SIM_PWR_GPIO_Port, SIM_PWR_Pin, GPIO_PIN_RESET);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
__NOP();
if(Sim_checkOK() != RET_OK)
{
HAL_GPIO_WritePin(SIM_PWR_GPIO_Port, SIM_PWR_Pin, GPIO_PIN_SET);
HAL_Delay(3000);
HAL_GPIO_WritePin(SIM_PWR_GPIO_Port, SIM_PWR_Pin, GPIO_PIN_RESET);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
HAL_Delay(5000);
#ifdef _IWDG_
HAL_IWDG_Refresh(&hiwdg);
#endif
if(Sim_checkOK() != RET_OK)
{
__NOP();
}
else
{
__NOP();
}
}
}
STATUS Sim_getFileModificationTime(char* filename, char* datetime)
{
char cmd[50] = {0};
sprintf(cmd,"AT+QFTPMDTM=\"%s\"\r",filename);
Sim_send(cmd, strlen(cmd));
if(Sim_checkResponseWith("+QFTPMDTM", 2, 5000) == RET_OK) //“YYYYMMDDHHMMSS�?
{
char* ptr = NULL;
uint8_t index = 0;
ptr = strstr((char*)Sim_Rxdata,"+QFTPMDTM:");
index = ptr - (char*)Sim_Rxdata + 14; //YYYY
deleteBuffer(datetime, 14);
strncpy(datetime,(char*)Sim_Rxdata+index,14);
__NOP();
return RET_OK;
}
__NOP();
return RET_FAIL;
}
void Flash_init(void)
{
#if _STM32CHIP_ == F3
Flash_Unlock();
if(Flash_ReadIntType(WR_ADDR) == 0xFFFFFFFF)
{
Flash_Erase(WR_ADDR);
Flash_WriteIntType(WR_ADDR, WRITE_DATA_ADDR, FLASH_TYPEPROGRAM_WORD);
Flash_WriteIntType(RD_ADDR, READ_DATA_ADDR, FLASH_TYPEPROGRAM_WORD);
Flash_WriteIntType(PG_ADDR, PAGE_ADDR, FLASH_TYPEPROGRAM_WORD);
}
// if(Flash_ReadIntType(RD_ADDR) == 0xFFFFFFFF)
// {
// Flash_Erase(RD_ADDR);
// Flash_WriteIntType(RD_ADDR, READ_DATA_ADDR, FLASH_TYPEPROGRAM_WORD);
// }
// if(Flash_ReadIntType(PG_ADDR) == 0xFFFFFFFF)
// {
// Flash_Erase(PG_ADDR);
// Flash_WriteIntType(PG_ADDR, PAGE_ADDR, FLASH_TYPEPROGRAM_WORD);
// }
Flash_Lock();
#endif
#if (_DEBUG_ == 1)
printf("FLASH init\r\n");
#endif
WRITE_DATA_ADDR = Flash_ReadIntType(WR_ADDR);
READ_DATA_ADDR = Flash_ReadIntType(RD_ADDR);
PAGE_ADDR = Flash_ReadIntType(PG_ADDR);
#if (_DEBUG_ == 1)
printf("-> Index of write flash: %lx\r\n",WRITE_DATA_ADDR);
printf("-> Index of read flash: %lx\r\n",READ_DATA_ADDR);
printf("-> Index of page flash: %lx\r\n",PAGE_ADDR);
#endif
}
void Flash_writeData(char* serverip, char* filename, char* data)
{
//write file to flash
sprintf(DataFromFlash,"%d|%d|%d|%d|%s|%s", serverip[0], serverip[1], serverip[2],
serverip[3], filename, data);
DataFlashSize = strlen(DataFromFlash);
WRITE_DATA_ADDR = Flash_ReadIntType(WR_ADDR);
READ_DATA_ADDR = Flash_ReadIntType(RD_ADDR);
PAGE_ADDR = Flash_ReadIntType(PG_ADDR);
Flash_Unlock();
if((WRITE_DATA_ADDR + DataFlashSize*2) >= PAGE_ADDR)
{
if(PAGE_ADDR == MAX_PAGE_ADDR)
{
PAGE_ADDR = MIN_PAGE_ADDR;
WRITE_DATA_ADDR = MIN_DATA_ADDR;
Flash_Erase(WRITE_DATA_ADDR);
}
else
{
PAGE_ADDR += 0x800;
}
if(READ_DATA_ADDR > WRITE_DATA_ADDR)
{
READ_DATA_ADDR = PAGE_ADDR + 0x10 - 0x800;
}
}
#if _STM32CHIP_ == F3
Flash_WriteCharType(WRITE_DATA_ADDR, DataFromFlash, FLASH_TYPEPROGRAM_HALFWORD);
WRITE_DATA_ADDR += DataFlashSize*2+2;
Flash_Erase(WR_ADDR);
Flash_WriteIntType(WR_ADDR, WRITE_DATA_ADDR,FLASH_TYPEPROGRAM_WORD);
Flash_WriteIntType(RD_ADDR,READ_DATA_ADDR,FLASH_TYPEPROGRAM_WORD);
Flash_WriteIntType(PG_ADDR,PAGE_ADDR,FLASH_TYPEPROGRAM_WORD);
#endif
#if (_DEBUG_ == 1)
printf("---Write data to Flash...---\r\n");
printf("%s\r\n",DataFromFlash);
printf("Write index: %lx\r\n",WRITE_DATA_ADDR);
printf("Read index: %lx\r\n",READ_DATA_ADDR);
printf("Page index: %lx\r\n",PAGE_ADDR);
#endif
memset(DataFromFlash,0,strlen(DataFromFlash));
Flash_Lock();
}
void Flash_extractData(char* data)
{
#if (_DEBUG_ == 1)
printf("Flash_extractData() running\r\n");
#endif
memset(FTP_ServerIP,0,strlen(FTP_ServerIP));
char* token;
token = strtok(data,"|");
FTP_ServerIP[0] = atoi(token);
token = strtok(NULL,"|");
FTP_ServerIP[1] = atoi(token);
token = strtok(NULL,"|");
FTP_ServerIP[2] = atoi(token);
token = strtok(NULL,"|");
FTP_ServerIP[3] = atoi(token);
token = strtok(NULL,"|");
memset(FTP_FileName,0,strlen(FTP_FileName));
strcpy(FTP_FileName,token);
token = strtok(NULL,"|");
memset(DataToSend,0,strlen(DataToSend));
strcpy(DataToSend,token);
if((FTP_ServerIP[0] == FTP_IP_1[0])&&(FTP_ServerIP[1] == FTP_IP_1[1])
&&(FTP_ServerIP[2] == FTP_IP_1[2])&&(FTP_ServerIP[3] == FTP_IP_1[3]))
{
memset(FTP_UserName,0,strlen(FTP_UserName));
memset(FTP_Password,0,strlen(FTP_Password));
memset(FTP_Path,0,strlen(FTP_Path));
strcpy(FTP_UserName,(char*)FTP_USER_1);
strcpy(FTP_Password,(char*)FTP_PASS_1);
strcpy(FTP_Path,(char*)FTP_PATH_1);
}
else if((FTP_ServerIP[0] == FTP_IP_2[0])&&(FTP_ServerIP[1] == FTP_IP_2[1])
&&(FTP_ServerIP[2] == FTP_IP_2[2])&&(FTP_ServerIP[3] == FTP_IP_2[3]))
{
memset(FTP_UserName,0,strlen(FTP_UserName));
memset(FTP_Password,0,strlen(FTP_Password));
memset(FTP_Path,0,strlen(FTP_Path));
strcpy(FTP_UserName,(char*)FTP_USER_2);
strcpy(FTP_Password,(char*)FTP_PASS_2);
strcpy(FTP_Path,(char*)FTP_PATH_2);
}
else if((FTP_ServerIP[0] == FTP_IP_3[0])&&(FTP_ServerIP[1] == FTP_IP_3[1])
&&(FTP_ServerIP[2] == FTP_IP_3[2])&&(FTP_ServerIP[3] == FTP_IP_3[3]))
{
memset(FTP_UserName,0,strlen(FTP_UserName));
memset(FTP_Password,0,strlen(FTP_Password));
memset(FTP_Path,0,strlen(FTP_Path));
strcpy(FTP_UserName,(char*)FTP_USER_3);
strcpy(FTP_Password,(char*)FTP_PASS_3);
strcpy(FTP_Path,(char*)FTP_PATH_3);
}
else if((FTP_ServerIP[0] == FTP_IP_4[0])&&(FTP_ServerIP[1] == FTP_IP_4[1])
&&(FTP_ServerIP[2] == FTP_IP_4[2])&&(FTP_ServerIP[3] == FTP_IP_4[3]))
{
memset(FTP_UserName,0,strlen(FTP_UserName));
memset(FTP_Password,0,strlen(FTP_Password));
memset(FTP_Path,0,strlen(FTP_Path));
strcpy(FTP_UserName,(char*)FTP_USER_4);
strcpy(FTP_Password,(char*)FTP_PASS_4);
strcpy(FTP_Path,(char*)FTP_PATH_4);
}
else{};
}
#ifdef _IWDG_
void refreshIWDG(uint16_t ms)
{
if(HAL_GetTick() - currentTick > ms)
{
HAL_IWDG_Refresh(&hiwdg);
currentTick = HAL_GetTick();
}
}
#endif
void LCD_sendCmd(char* data)
{
HAL_UART_Transmit(&huart1, (uint8_t*)data, strlen(data), 1000);
HAL_UART_Transmit(&huart1, (uint8_t*)"\xFF\xFF\xFF", 3, 1000);
}
//XU LY DU LIEU
//Pos from 0
void substr(char* str, char* sub, int pos, int len) {
int i;
for (i = 0 ; i < len ; i++)
{
*(sub + i) = *(str + pos);
str++;
}
*(sub + i) = '\0';
}
int indexof(const char *str, const char* sub) {
char *p = strstr(str, sub);
if (p != NULL) {
return (p - str);
}
return -1;
}
int indexoffrom(const char *str, const char* sub, int from) {
char *p = strstr(str + from, sub);
if (p != NULL) {
return (p - str);
}
return -1;
}
int hexadecimalToDecimal(char hexVal[])
{
substr(hexVal, hexVal, 2, strlen(hexVal));
int len = strlen(hexVal);
// Initializing base value to 1, i.e 16^0
int base = 1;
int dec_val = 0;
// Extracting characters as digits from last character
for (int i=len-1; i>=0; i--)
{
// if character lies in '0'-'9', converting
// it to integral 0-9 by subtracting 48 from
// ASCII value.
if (hexVal[i]>='0' && hexVal[i]<='9')
{
dec_val += (hexVal[i] - 48)*base;
// incrementing base by power
base = base * 16;
}
// if character lies in 'A'-'F' , converting
// it to integral 10 - 15 by subtracting 55
// from ASCII value
else if (hexVal[i]>='A' && hexVal[i]<='F')
{
dec_val += (hexVal[i] - 55)*base;
// incrementing base by power
base = base*16;
}
}
return dec_val;
}
void getData(char *res, char* des, char* id) {
int dataStart;
int dataEnd;
dataStart = indexof(res, id) + strlen(id) + 2;
dataEnd = indexoffrom(res, "<", dataStart) - 1;
substr(res, des, dataStart, dataEnd - dataStart + 1);
if(strstr(id,"INFO") != NULL)
{
int val = hexadecimalToDecimal(des);
memset(des,0,strlen(des));
sprintf(des,"%02d",val);
}
}
void resetStruct(struct sensor *s) {
*s = sensor[6];
}
void classificateSensors(Sensor* ss)
{
if(strstr(ss->MPARA,"pH") != NULL)
{
memset(PHval,0,strlen(PHval));
memset(Tempval,0,strlen(Tempval));
strcpy(PHval,ss->MVAL);
strcpy(Tempval,ss->SVAL);
}
else if(strstr(ss->MPARA,"TSS") != NULL)
{
memset(TSSval,0,strlen(TSSval));
strcpy(TSSval,ss->MVAL);
}
else if(strstr(ss->MPARA,"COD") != NULL)
{
memset(CODval,0,strlen(CODval));
strcpy(CODval,ss->MVAL);
}
else if(strstr(ss->MPARA,"NH4") != NULL)
{
memset(NH4val,0,strlen(NH4val));
strcpy(NH4val,ss->MVAL);
}
}
uint8_t findOccurrenceOfSubStr(char* substr, char* str)
{
int dem=0,l=strlen(substr);
char *p= strstr(str,substr);
while(p!=NULL)
{
dem++;
p=strstr(p+l,substr);
}
return dem;
}
void insertionSort(int arr[], int n)
{
int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
/* Move elements of arr[0..i-1], that are
greater than key, to one position ahead
of their current position */
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
float ADC_map(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float Sensor_getADCValue(uint8_t channel)
{
for(uint8_t i=0; i Current_Max)
{
Current_Max = val;
}
val = Current_Max;
}
if(channel == FLOW_OUT)
{
if((val > 3.95) && (val < 4.00)) val = 4.0;
else if((val > 20.0) && (val < 20.05)) val = 20.0;
sensor_val = ADC_map(val, 4.00, 20.00, SSHIGH_IN_MIN, SSHIGH_IN_MAX);
#if (_DEBUG_ == 1)
printf("ADC_1 val: %f\r\n",val);
#endif
}
else if(channel == FLOW_IN)
{
if((val < 4.00) || (val > 20.00))
{
sensor_val = WFHIGH_MAX;
}
else
{
sensor_val = ADC_map(val, 4.00, 20.00, SSHIGH_OUT_MIN, SSHIGH_OUT_MAX);
}
sensor_val = SSHIGH_OUT_MAX - sensor_val;
if(sensor_val < 0) sensor_val = 0;
sensor_val = CALCULATEH20FLOW(sensor_val);
#if (_DEBUG_ == 1)
printf("ADC_2 val: %f\r\n",val);
#endif
}
memset(data,0,strlen((char*)data));
sprintf((char*)data,"%.02f",sensor_val);
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/