Преглед изворни кода

Merge branch 'master' of http://jiecheng2024.tpddns.cn:3000/liyuezong/SmartPDCode

guohui пре 1 година
родитељ
комит
ecf890a60a

+ 1 - 1
control/STS/HARDWARE/Electricity/Electricity.c

@@ -199,7 +199,7 @@ static void check_freq_min(uint8_t channel)
 	sts_data_t *data = get_sts();
 	if(channel != CH448_CHANNEL_1)
 	{
-		uint8_t chn = channel -1;
+		uint8_t chn = channel - 1;
 		if(chn > CH448_CHANNEL_3)
 			return;
 		if(IS_FREQ_MIN_EN(data->input_wanning_en[chn])) {

+ 4 - 2
control/STS/HARDWARE/Exti/Exti.c

@@ -135,13 +135,15 @@ void EXTI4_15_IRQHandler(void)
 		{
 			if(data->m_data.input_status.input_status[INPUT_CHANNEL_1])
 			{
-				data->choise_input(INPUT_CHANNEL_1);
+				if(data->m_data.md_choise.choise_ch != INPUT_CHANNEL_1)
+					data->choise_input(INPUT_CHANNEL_1);
 			}
 		}else														//falling
 		{
 			if(data->m_data.input_status.input_status[INPUT_CHANNEL_2])
 			{
-				data->choise_input(INPUT_CHANNEL_2);
+				if(data->m_data.md_choise.choise_ch != INPUT_CHANNEL_2)
+					data->choise_input(INPUT_CHANNEL_2);
 			}
 		}
 		exti_interrupt_flag_clear(SWITCH_EXTI);

+ 3 - 0
control/STS/HARDWARE/Fan/Fan.c

@@ -26,12 +26,15 @@ void fans_init(void)
 
 void fans_on_off(unsigned char status)
 {
+	sts_data_t *data = get_sts();
 	if(status == FANS_OFF)
 	{
 		gpio_bit_reset(GPIOB, GPIO_PIN_6); 
+		data->m_data.fans_status = FANS_OFF;
 	}else if(status == FANS_ON)
 	{
 		gpio_bit_set(GPIOB, GPIO_PIN_6); 
+		data->m_data.fans_status = FANS_ON;
 	}else{
 	
 	}

+ 2 - 2
control/STS/HARDWARE/Fan/Fan.h

@@ -11,8 +11,8 @@
 #define __FANS_H
 
 enum{
-	FANS_ON = 0,
-	FANS_OFF,
+	FANS_OFF = 0,
+	FANS_ON,
 };
 
 void fans_init(void);

+ 4 - 0
control/STS/HARDWARE/Relay/Relay.c

@@ -76,16 +76,20 @@ void choise_input(uint8_t channel)
 
 void out_open()
 {
+		sts_data_t *data = get_sts();
 		unlock();
 		gpio_bit_set(GPIOB, RELAY_2);
 		lock();
 		out_r_led(0);
+		data->m_data.out_status = OUT_OPEN;
 }
 
 void out_close()
 {
+		sts_data_t *data = get_sts();
 		unlock();
 		gpio_bit_reset(GPIOB, RELAY_2);
 		lock();
 		out_r_led(1);
+		data->m_data.out_status = OUT_CLOSE;
 }

+ 5 - 0
control/STS/HARDWARE/Relay/Relay.h

@@ -17,6 +17,11 @@ enum{
 	RELAY_CHANNEL_2,
 };
 
+enum{
+	OUT_CLOSE = 0,
+	OUT_OPEN,
+};
+
 
 void InitRelay(void);                   
 void out_open();

+ 57 - 6
control/STS/HARDWARE/Temprature/Temprature.c

@@ -10,16 +10,67 @@
 #include "Temprature.h"
 #include "Adc.h"
 #include "main.h"
+#include "math.h"
+/****************************************************************
+*
+*     NXFT15XH103
+*
+*     T(K) = (662.666 -45.389*ln(R)+0.069*(ln(R))^3)
+*     T(C) = T(K) - 273.15
+*
+*****************************************************************/
+static float get_temp(void);
 
-static void get_temp(void);
+#define GATHER_MAX  200
+#define VREF        33
 
-static void get_temp(void)
+#define V_HOT(ad) (((ad * 1000)>>12) * VREF / 10.0 /1000.0) 
+
+#define R_HOT(ad) ((V_HOT(ad)*10000.0) / ((VREF/10.0)-(2.0*V_HOT(ad))))
+
+#define T_TEMP(res) ((662.666 - (45.389 * log10(res)) + (0.069 * log10(res)*log10(res)*log10(res))) - 273.15)
+
+static uint32_t gather_count = 0;
+
+static uint32_t all_get_ad = 0;
+
+static float get_temp(void)
 {
 	sts_data_t *data = get_sts();
-	float a = 0.0;
-	
-	
-	data->temprature = a;
+	uint32_t all_get_ad = 0;	
+	float temprature = 0.0;
+	if(gather_count < GATHER_MAX)
+	{
+		
+		all_get_ad += get_adc();
+		gather_count++;
+	}else
+	{
+		all_get_ad /= GATHER_MAX;
+		
+		float v_hot = V_HOT(all_get_ad);
+		if((uint32_t)((v_hot)*100) < 165)
+		{
+			float res = ((v_hot)*10000) / (3.3 - 2 * v_hot);
+			if(res>=598 && res <= 197000)
+			{
+				temprature = T_TEMP(res);
+				data->temp_online_flag = TEMP_ONLINE;
+			}else
+			{
+				data->temp_online_flag = TEMP_INLINE;
+			}
+		}else
+		{
+			temprature = 0.0;
+			data->temp_online_flag = TEMP_INLINE;
+		}
+		
+		gather_count = 0;
+		all_get_ad = 0;
+	}
+	data->temprature = temprature;
+	return temprature;
 }
 
 

+ 4 - 1
control/STS/HARDWARE/Temprature/Temprature.h

@@ -11,7 +11,10 @@
 #define __TEMPRATURE_H
 
 
-
+enum{
+	TEMP_INLINE = 0,
+	TEMP_ONLINE 
+};
 
 
 

+ 12 - 11
control/STS/HARDWARE/Timer/Timer.c

@@ -97,25 +97,26 @@ static void ConfigTimer16(unsigned short arr,unsigned short psc)
 void TIMER14_IRQHandler(void)
 {  
   //static  unsigned short s_iCnt2 = 0;                            
-	static  uint16_t  led_cnt = 0;
-	static  uint16_t  read_ele_cnt = 0;
+	static  uint16_t  cnt_1000 = 0;
+	static  uint8_t   cnt_100 = 0;
+	static 	uint8_t   cnt_5 = 0;
   if(timer_interrupt_flag_get(TIMER14, TIMER_INT_FLAG_UP) == SET) 
   {
     timer_interrupt_flag_clear(TIMER14, TIMER_INT_FLAG_UP);       
   }
-	led_cnt++;
-	read_ele_cnt++;
-	
-	if(led_cnt >=1000)
+	cnt_1000++;
+	cnt_100++;
+	if(cnt_1000 >=1000)
 	{
-		data->led_flag = 1;
-		led_cnt = 0;
+		data->flag_1000ms = 1;
+		cnt_1000 = 0;
 	}
-	if(read_ele_cnt >= 100)
+	if(cnt_100 >= 100)
 	{
-		data->read_ele_flag = 1;
-		read_ele_cnt = 0;
+		data->flag_100ms = 1;
+		cnt_100 = 0;
 	}
+
 }
 
 

+ 57 - 4
control/STS/MODBUS/BARE/port/port.c

@@ -23,16 +23,17 @@
 #include "mb.h"
 #include "mbport.h"
 #include "string.h"
+#include "main.h"
 
 
 /* ----------------------- Defines ------------------------------------------*/
 //输入寄存器
 #define REG_INPUT_START  3000
-#define REG_INPUT_NREGS  4
+#define REG_INPUT_NREGS  1
 
 //保持寄存器
-#define REG_HOLD_START   4000
-#define REG_HOLD_NREGS   1500
+#define REG_HOLD_START   STS_R_START
+#define REG_HOLD_NREGS   500
 
 //线圈
 #define REG_COILS_START  0
@@ -109,6 +110,9 @@ eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
             iRegIndex++;
             usNRegs--;
         }
+				{
+					
+				}
     }
     else
     {
@@ -143,6 +147,9 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
     eMBErrorCode    eStatus = MB_ENOERR;
     uint16_t             iRegIndex;
 		usAddress = usAddress - 1;
+		
+		sts_data_t *t_data = get_sts();
+		md_data_t *data = &t_data->m_data;
     if((usAddress >= REG_HOLD_START) && ((usAddress+usNRegs) <= (REG_HOLD_START + REG_HOLD_NREGS)))
     {
         iRegIndex = (uint16_t)(usAddress - usRegHoldStart);
@@ -150,7 +157,10 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
         switch(eMode)
         {
         case MB_REG_READ://读寄存器
-
+						{
+							uint16_t *start = &data->dev;
+							memcpy(&usRegHoldBuf[iRegIndex],start+iRegIndex,usNRegs*2);
+						}
             while(usNRegs > 0)
             {
                 *pucRegBuffer++ = (uint8_t)(usRegHoldBuf[iRegIndex] >> 8);
@@ -158,6 +168,7 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
                 iRegIndex++;
                 usNRegs--;
             }
+						
             break;
         case MB_REG_WRITE://写寄存器
 						WusNRegs = usNRegs;
@@ -168,6 +179,48 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
                 iRegIndex++;
                 usNRegs--;
             }
+						{
+							if(usAddress == STS_OUTPUT_STATUS)
+							{
+								uint16_t recive = 0;
+								memcpy(&recive,&usRegHoldBuf[WiRegIndex],WusNRegs*2);
+								if(recive > 0)
+								{
+									t_data->open_output();
+								}else
+								{
+									t_data->close_output();
+								}
+								t_data->write_at24(IIC_OUT_CHANNEL,recive,sizeof(recive));
+							}else if(usAddress == STS_CHOISE_INPUT)
+							{
+								uint16_t recive = 0;
+								memcpy(&recive,&usRegHoldBuf[WiRegIndex],WusNRegs*2);
+								if(recive == 0)
+								{
+									t_data->choise_input(INPUT_CHANNEL_1);
+								}else
+								{
+									t_data->choise_input(INPUT_CHANNEL_2);
+								}
+							}else if(usAddress >= STS_INPUT_THRESHOLD && usAddress < STS_OUTPUT_THRESHOLD)
+							{
+								WeeiRegIndex = (uint16_t)(usAddress - STS_INPUT_THRESHOLD);
+								uint16_t *p_start = &(data->input_th[0].voltage_max);
+								memcpy(p_start+WeeiRegIndex,&usRegHoldBuf[WiRegIndex],WusNRegs*2);
+								t_data->write_at24(IIC_INPUT_THRESHOLD_START+(WeeiRegIndex*2),&usRegHoldBuf[WiRegIndex],WusNRegs*2);
+								
+							}else if(usAddress >= STS_OUTPUT_THRESHOLD  && usAddress < STS_TEMP_THRESHOLD)
+							{
+							}else if(usAddress >= STS_TEMP_THRESHOLD && usAddress < STS_OVER_FUNC)
+							{
+							}else if(usAddress == STS_OVER_FUNC)
+							{
+							}else
+							{
+								eStatus = MB_ENOREG;
+							}
+						}
 						
         }
     }

Разлика између датотеке није приказан због своје велике величине
+ 62 - 89
control/STS/PRJ/sts.uvguix.Gowon


+ 53 - 0
control/STS/PRJ/test.py

@@ -0,0 +1,53 @@
+import numpy as np
+from scipy.optimize import curve_fit
+# NXFT15XH103
+data = np.array([
+[-40,197338],
+[-35,149395],
+[-30,114345],
+[-25,88381],
+[-20,68915],
+[-15,54166],
+[-10,42889],
+[-5,34196],
+[0,27445],
+[5,22165],
+[10,18010],
+[15,14720],
+[20,12099],
+[25,10000],
+[30,8309],
+[35,6939],
+[40,5824],
+[45,4911],
+[50,4160],
+[55,3539],
+[60,3024],
+[65,2593],
+[70,2233],
+[75,1929],
+[80,1673],
+[85,1455],
+[90,1270],
+[95,1112],
+[100,976],
+[105,860],
+[110,759],
+[115,673],
+[120,598],
+[125,532],
+])
+
+T_K = data[:, 0] + 273.15
+R = data[:, 1]
+
+def steinhart_hart(R, A, B, C):
+    return 1 / (A + B * np.log(R) + C * (np.log(R))*(np.log(R))*(np.log(R)))
+
+
+
+params, _ = curve_fit(steinhart_hart, R, 1/T_K)
+
+A, B, C = params
+print(f"A: {A}, B: {B}, C: {C}")
+

+ 32 - 8
control/STS/USER/main.c

@@ -72,19 +72,20 @@ int main()
 	while(1){
 		Fwdgt_reload();
 		eMBPoll();
+		sts_data.read_temp();
 		// read consumer
-		if(sts_data.led_flag)
+		if(sts_data.flag_1000ms)
 		{
-			sts_data.led_flag = 0;
+			sts_data.flag_1000ms = 0;
 			sts_data.led_flash();
 			if(sts_data.beep_flag)
 			{
 				sts_data.beep();
 			}
 		}
-		if(sts_data.read_ele_flag)
+		if(sts_data.flag_100ms)
 		{
-			sts_data.read_ele_flag = 0;
+			sts_data.flag_100ms = 0;
 			sts_data.read_ele(channel);
 			//
 			sts_data.check_wanning(channel);
@@ -104,7 +105,7 @@ int main()
 					{
 							if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_2]))
 							{
-								sts_data.close_output();
+								if(sts_data.m_data.out_status == OUT_OPEN) sts_data.close_output();
 							}else
 							{
 								sts_data.choise_input(INPUT_CHANNEL_2);
@@ -114,7 +115,7 @@ int main()
 				{
 					if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_1]))
 					{
-							sts_data.close_output();
+						if(sts_data.m_data.out_status == OUT_OPEN) sts_data.close_output();
 					}else {
 							sts_data.choise_input(INPUT_CHANNEL_1);
 					}
@@ -127,17 +128,40 @@ int main()
 				sts_data.beep_flag = 1;
 				if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_1]))
 				{
-					sts_data.close_output();
+					if(sts_data.m_data.out_status == OUT_OPEN) sts_data.close_output();
 				}
 			}else if((sts_data.m_data.input_status.input_status[INPUT_CHANNEL_2]) ){
 				sts_data.beep_flag = 1;
 				if(STS_INPUT_HAS_WANNING(sts_data.m_data.input_wanning.waning[INPUT_CHANNEL_2]))
 				{
-					sts_data.close_output();
+					if(sts_data.m_data.out_status == OUT_OPEN) sts_data.close_output();
 				}
 			}
 			channel = CH448_CHANNEL_1;
 		}
+		if(sts_data.temp_online_flag == TEMP_ONLINE)
+		{
+			sts_data.m_data.temprature = sts_data.temprature * 100;
+			if(sts_data.m_data.temprature_th.fans_max_temp != 0 && sts_data.m_data.temprature_th.fans_min_temp != 0)
+			{
+				if(sts_data.m_data.temprature_th.fans_max_temp > sts_data.m_data.temprature_th.fans_min_temp)
+				{
+					if((uint16_t)(sts_data.temprature*100) >= sts_data.m_data.temprature_th.fans_max_temp)
+					{
+						if(sts_data.m_data.fans_status != FANS_ON)
+						{
+							sts_data.fans(FANS_ON);
+						}
+					}else if((uint16_t)(sts_data.temprature*100) <= sts_data.m_data.temprature_th.fans_min_temp)
+					{
+						if(sts_data.m_data.fans_status != FANS_OFF)
+						{
+							sts_data.fans(FANS_OFF);
+						}
+					}
+				}
+			}
+		}
 	}
 	return 0;
 }

+ 37 - 16
control/STS/USER/main.h

@@ -13,6 +13,22 @@
 #include "stdint.h"
 
 
+#define STS_TYPE    							0x07
+#define STS_R_START        				4000
+
+#define STS_RW_START       				4161
+
+#define STS_OUTPUT_STATUS   			(STS_RW_START)
+#define STS_CHOISE_INPUT    			(STS_OUTPUT_STATUS + 1)
+
+#define STS_INPUT_THRESHOLD   		(STS_CHOISE_INPUT + 1)
+
+#define STS_OUTPUT_THRESHOLD     	(STS_INPUT_THRESHOLD + 10)
+
+#define STS_TEMP_THRESHOLD        (STS_OUTPUT_THRESHOLD + 2)
+
+#define STS_OVER_FUNC             (STS_TEMP_THRESHOLD +1)
+
 
 
 #define IIC_INPUT_THRESHOLD_START          (10)
@@ -128,7 +144,7 @@ enum {
 																			|| (IS_WANNING_FREQ_MAX(reg)) || (IS_WANNING_FREQ_MIN(reg)) )
 
 
-//#pragma pack (2)
+#pragma pack (2)
 
 typedef struct {
 		uint32_t uniq_ID_64_95;
@@ -207,32 +223,37 @@ typedef struct{
 typedef uint16_t iic_over_func;
 
 typedef struct{
-	uint16_t                      dev;
-	md_information_t 				     info;
-	md_input_info 			     input[2];
-	md_chiose_ch            md_choise;
-	md_input_status      input_status;
-	md_in_wanning       input_wanning;
-	md_out_wanning      output_waning;
-	md_out_power_info   		out_power;
-	uint16_t               out_status;
-	iic_in_threshold_t    input_th[2];
+	uint16_t                      dev;														//4000
+	md_information_t 				     info;														//4001 - 4030
+	md_input_info 			     input[2];														//4031 - 4038
+	md_input_status      input_status;														//4039 - 4040
+	md_in_wanning       input_wanning;														//4041
+	md_out_wanning      output_waning;														//4042
+	md_out_power_info   		out_power;														//4043 - 4057
+	int16_t                temprature;														//4058
+	uint16_t               temprature_flag;												//4059
+	uint16_t               fans_status;														//4060
+	uint16_t               resurved[100];													//
+	uint16_t               out_status;                          //r_w   //4061
+	md_chiose_ch            md_choise;																	//4062
+	iic_in_threshold_t    input_th[2];																	
 	iic_out_threshold_t     output_th;
 	iic_temp_threshold_t   temprature_th;
 	iic_over_func               over_func;
 }md_data_t;
 
-
+#pragma pack ()
 typedef struct sts_data sts_data_t;
 
 
 
 typedef struct sts_data{
-	uint8_t     led_flag;
+	uint8_t     flag_1000ms;
+	uint8_t     flag_100ms;
+	uint8_t     temp_online_flag;
 	uint8_t     count_start_flag;
 	uint8_t     switch_flag;
 	uint8_t     over_func_flag;
-	uint8_t     read_ele_flag;
 	uint8_t     beep_flag;
 	uint8_t       switch_status;
 	md_data_t 						m_data;
@@ -252,11 +273,11 @@ typedef struct sts_data{
 	void (*read_eeprom)();
 	void (*read_at24)(uint16_t start,uint8_t *buff,uint16_t lenth);
 	void (*write_at24)(uint16_t start,uint8_t *buff,uint16_t lenth);
-	void (*read_temp)();
+	float (*read_temp)();
 	void (*check_wanning)(uint8_t channel);
 }sts_data_t;
 
-//#pragma pack ()
+
 
 
 sts_data_t *get_sts(void);