/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : uType.h
  * @brief          : Header for remote.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __UTYPE_H
#define __UTYPE_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32l4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
#include <string.h> //memset
#include <stdio.h>	//printf
#include <stdbool.h> // bool

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

#define SENSOR_TEMPERATURE (0)
#define SENSOR_PRESSURE    (1)
#define SENSOR_H2          (2)
#define SENSOR_CO          (3)

#define SENSOR_TEMP_FIRST_THRESHOLD (4)
#define SENSOR_TEMP_SECOND_THRESHOLD (5)
#define MAINBOARD_UPLOAD_FREQUENCY (6)
#define SMALLBOARD_UPLOAD_FREQUENCY (7)
#define OBJECT_EMISSIVITY (8)
#define Terminal_ID (9)
#define Terminal_phone (10)
/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

#define MAX_NODE_NUM (32)
#define MAX_SLICES_PER_SECOND (2)
#define SLICE_DATA_SIZE (8)
#define MAX_TEMP_NODE_NUM  (30)
#define MAX_PRESSURE_NODE_NUM  (3)
#define MAX_H2_NODE_NUM  (3)
#define MAX_CO_NODE_NUM  (3)
#define MAX_SLICE_NUM  (2)

typedef struct {
    uint8_t ssid[20];
    uint8_t password[20];
} WIFI_Config_t;
extern WIFI_Config_t wifi_config;


typedef enum {
    Cloud_4G_MODE,		// 4G模式
    Cloud_WIFI_MODE,	// WIFI模式
} SYSTEM_Cloud_MODE;
extern SYSTEM_Cloud_MODE system_cloud_mode;
 typedef  struct _Uart2Rx_msg
 {
	uint8_t data[40];
 }Uart2Rx_msg;
 
 typedef  struct _Uart3Rx_msg
 {
	uint8_t data[80];
	uint16_t length;
 }Uart3Rx_msg; 
/**
  * @breaf CAN 接收队列结构体
  */
 typedef  struct _CanRx_msg
 {
	uint32_t ExtId;
	uint8_t data[SLICE_DATA_SIZE];
 }CanRx_msg;

/**
  * @breaf 迪文屏发送结构体
  */
 typedef  struct _Dwin_msg
 {
	uint8_t SensorType;
	uint8_t SensorId; // 从0 开始 
	uint8_t data[4];
 }Dwin_msg;
 
 /**
  * @breaf 云平台 发送结构体
  */
 typedef  struct _Remote_msg
 {
	uint8_t SensorType;
	uint8_t SensorId; // 从0 开始 
	uint8_t data[SLICE_DATA_SIZE*MAX_SLICE_NUM];
 }Remote_msg;
 /**
  * @breaf gas 结构体
  */
 typedef  struct _gas_msg
 {
	uint8_t SensorType;
	uint8_t SensorId; // 从0 开始 
	uint8_t data[SLICE_DATA_SIZE*MAX_SLICE_NUM];
 }gas_msg;
 
 typedef struct { 
	uint8_t controltransmit_flag;
	uint8_t temp_first_threshold;
	uint8_t temp_second_threshold;
	uint8_t pressure_threshold;
	uint8_t co_threshold;
	uint8_t h2_threshold;
	uint8_t smallboard_upload_frequency;
	uint8_t heart_upload_frequency;
	uint8_t mainboard_upload_frequency;
	uint8_t sensoronline_upload_frequency;
	uint8_t object_emissivity;
	uint8_t version;
} FlashData;
extern FlashData flash_data;

 /**
  * @breaf 迪文屏发送阈值结构体
//  */
// typedef  struct _Dwinthreshold_msg
// {
//	uint8_t 	SensorType;
//	 
//	uint16_t  TEMP_FIRST_Sensoraddress; 
//	uint16_t  TEMP_SECOND_Sensoraddress; 
//	uint16_t  MAINBOARD_UPLOAD_Sensoraddress; 
//	uint16_t  SMALLBOARD_UPLOAD_Sensoraddress; 
//	uint16_t  OBJECT_EMISSIVITY_Sensoraddress; 
//	uint16_t  PRESSURE_Sensoraddress; 
//	uint16_t  SENSOR_CO_Sensoraddress; 
//	uint16_t  SENSOR_H2_Sensoraddress; 

//	uint16_t  TEMP_FIRST_data;
//	uint16_t  TEMP_SECOND_data;
//	uint16_t  MAINBOARD_UPLOAD_data;
//	uint16_t  SMALLBOARD_UPLOAD_data;
//	uint16_t  OBJECT_EMISSIVITY_data;
//	uint16_t  PRESSURE_data;
//	uint16_t  SENSOR_CO_data;
//	uint16_t  SENSOR_H2_data;
//	 
// }Dwinthreshold_msg;

 /**
 * @breaf 迪文屏发送终端ID和手机号结构体
  */
 typedef  struct _Dwinterminal_msg
 {
	uint8_t  Sensoraddress; 
	uint8_t  data[8];
 }Dwinterminal_msg;
 /**
  * @breaf 用于发送平台的温度压力COH2数据缓存结构体
  */
 typedef struct {
		
		uint8_t temp_data[MAX_TEMP_NODE_NUM][12]; // 存储温度数据
    uint8_t pressure_data[MAX_PRESSURE_NODE_NUM][2]; // 存储压力数据
    uint8_t co_data[MAX_CO_NODE_NUM][4];  // 存储 CO 数据
    uint8_t h2_data[MAX_H2_NODE_NUM][4];  // 存储 H2 数据
		
		uint8_t temp_valid[MAX_TEMP_NODE_NUM]; // 标记该编号是否有新数据
    uint8_t pressure_valid[MAX_PRESSURE_NODE_NUM]; // 标记该编号是否有新数据
    uint8_t co_valid[MAX_CO_NODE_NUM]; // 标记 CO 是否有新数据
    uint8_t h2_valid[MAX_H2_NODE_NUM]; // 标记 H2 是否有新数据
	 
} SensorDataBuffer;
//SensorDataBuffer sensor_data = {0};
 /**
  * @breaf 用于发送DWIN的温度压力COH2数据缓存结构体
  */
 typedef struct {
		
		uint8_t temp_data[MAX_TEMP_NODE_NUM][3]; // 存储温度数据
    uint8_t pressure_data[MAX_PRESSURE_NODE_NUM][2]; // 存储压力数据
    uint8_t co_data[MAX_CO_NODE_NUM][4];  // 存储 CO 数据
    uint8_t h2_data[MAX_H2_NODE_NUM][4];  // 存储 H2 数据
		
		uint8_t temp_valid[MAX_TEMP_NODE_NUM]; // 标记该编号是否有新数据
    uint8_t pressure_valid[MAX_PRESSURE_NODE_NUM]; // 标记该编号是否有新数据
    uint8_t co_valid[MAX_CO_NODE_NUM]; // 标记 CO 是否有新数据
    uint8_t h2_valid[MAX_H2_NODE_NUM]; // 标记 H2 是否有新数据
	 
} SensorDWINDataBuffer;


typedef enum {
    dwin_power_closed,	
    dwin_power_opened,
		dwin_power_reserve,
} DWIN_power_t;

typedef enum {
    dwin_Init_closed,	
    dwin_Init_opened,	
} DWIN_Init_t;

typedef enum {
    dwin_show_closed,	
    dwin_show_opened,	
} DWIN_Show_t;

typedef enum {
    actuator_opened,	// 电推杆已开启
    actuator_closed,	// 电推杆已关闭
} actuator_t;

/**
  * @breaf 系统状态等级
  */
typedef enum {
    SYSTEM_LEVEL_0,	// 正常状态
    SYSTEM_LEVEL_1,	// 一级预警
    SYSTEM_LEVEL_2,	// 二级报警
		SYSTEM_LEVEL_3	// 备用
} SystemLevel_t;


extern volatile DWIN_power_t dwin_power_state;
extern volatile DWIN_Init_t dwin_init_state;
extern volatile DWIN_Show_t dwin_show_state;
extern volatile actuator_t actuator_powered_state;
extern volatile SystemLevel_t system_level;

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/


/* USER CODE BEGIN EFP */
void CAN_Send_Parameter(uint32_t node_id, FlashData *flash_data, uint8_t len);

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __UTYPE_H */
 
