From 955999ece91912c49a96534fdf50aef42c6c916f Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Thu, 16 Jan 2025 15:42:22 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=84=E5=AD=98?= =?UTF-8?q?=E5=99=A8=E5=9C=B0=E5=9D=80=E4=B8=8E=E5=AF=8C=E5=A5=A5=E9=80=9A?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Inc/frt_protocol.h | 33 +++++++++++++++++---------------- App/Src/frt_protocol.c | 10 ++++++---- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/App/Inc/frt_protocol.h b/App/Inc/frt_protocol.h index 961e9fb..a0f6a57 100644 --- a/App/Inc/frt_protocol.h +++ b/App/Inc/frt_protocol.h @@ -23,22 +23,23 @@ typedef enum typedef enum { FRT_REGISTER_MIN_WIND_DIRECTION = 0, /* 最小风向 */ - FRT_REGISTER_THROUGH_WIND_DIRECTION = 1, /* 极小风向 */ - FRT_REGISTER_AVERAGE_WIND_DIRECTION = 2, /* 平均风向 */ - FRT_REGISTER_INSTANTANEOUS_WIND_DIRECTION = 3, /* 瞬时风向 */ - FRT_REGISTER_PEAK_WIND_DIRECTION = 4, /* 极大风向 */ - FRT_REGISTER_MAX_WIND_DIRECTION = 5, /* 最大风向 */ - FRT_REGISTER_MIN_WIND_SPEED = 6, /* 最小风速 */ - FRT_REGISTER_THROUGH_WIND_SPEED = 7, /* 极小风速 */ - FRT_REGISTER_AVERAGE_WIND_SPEED = 8, /* 平均风速 */ - FRT_REGISTER_INSTANTANEOUS_WIND_SPEED = 9, /* 瞬时风速 */ - FRT_REGISTER_PEAK_WIND_SPEED = 10, /* 极大风速 */ - FRT_REGISTER_MAX_WIND_SPEED = 11, /* 最大风速 */ - FRT_REGISTER_TEMPERATURE = 12, /* 大气温度 */ - FRT_REGISTER_HUMIDITY = 13, /* 大气湿度 */ - FRT_REGISTER_PRESSURE = 14, /* 大气压 */ - FRT_REGISTER_RAIN = 15, /* 雨量 */ - FRT_REGISTER_PRECIPITATION_INTENSITY = 16, /* 总辐射 */ + FRT_REGISTER_AVERAGE_WIND_DIRECTION = 1, /* 平均风向 */ + FRT_REGISTER_MAX_WIND_DIRECTION = 2, /* 最大风向 */ + FRT_REGISTER_MIN_WIND_SPEED = 3, /* 最小风速 */ + FRT_REGISTER_AVERAGE_WIND_SPEED = 4, /* 平均风速 */ + FRT_REGISTER_MAX_WIND_SPEED = 5, /* 最大风速 */ + FRT_REGISTER_TEMPERATURE = 6, /* 大气温度 */ + FRT_REGISTER_HUMIDITY = 7, /* 大气湿度 */ + FRT_REGISTER_PRESSURE = 8, /* 大气压 */ + FRT_REGISTER_RAIN = 9, /* 雨量 */ + FRT_REGISTER_PRECIPITATION_INTENSITY = 10, /* 总辐射 */ + FRT_REGISTER_UV_INTENSITY = 11, /* 紫外强度 */ + FRT_REGISTER_THROUGH_WIND_DIRECTION = 12, /* 极小风向 */ + FRT_REGISTER_INSTANTANEOUS_WIND_DIRECTION = 13, /* 瞬时风向 */ + FRT_REGISTER_PEAK_WIND_DIRECTION = 14, /* 极大风向 */ + FRT_REGISTER_THROUGH_WIND_SPEED = 15, /* 极小风速 */ + FRT_REGISTER_INSTANTANEOUS_WIND_SPEED = 16, /* 瞬时风速 */ + FRT_REGISTER_PEAK_WIND_SPEED = 17, /* 极大风速 */ FRT_REGISTER_DEVICE_ADDR = 20, /* 设备地址 */ FRT_REGISTER_COMMU_BAUDRATE = 21, /* 波特率 */ diff --git a/App/Src/frt_protocol.c b/App/Src/frt_protocol.c index f406543..238bd93 100644 --- a/App/Src/frt_protocol.c +++ b/App/Src/frt_protocol.c @@ -1298,9 +1298,10 @@ void FRT_MsgProc_ReadRegister(device_handle device, void *pMsg) u_int16_t reg_num= (data[4] << 8)| data[5]; if ( \ start_reg_addr < 0x00 ||\ - (start_reg_addr > FRT_REGISTER_PRESSURE && start_reg_addr < FRT_REGISTER_DEVICE_ADDR) ||\ + (start_reg_addr > FRT_REGISTER_PRESSURE && start_reg_addr < FRT_REGISTER_THROUGH_WIND_DIRECTION) ||\ + (start_reg_addr > FRT_REGISTER_PEAK_WIND_SPEED && start_reg_addr < FRT_REGISTER_DEVICE_ADDR) ||\ (start_reg_addr > FRT_REGISTER_TEMPHUM_UPDATE_TIME && start_reg_addr < FRT_REGISTER_TRANSDUCER_CFG_1R5) ||\ - start_reg_addr > FRT_REGISTER_ID_4 \ + start_reg_addr > FRT_REGISTER_ID_4 \ ) { @@ -1310,9 +1311,10 @@ void FRT_MsgProc_ReadRegister(device_handle device, void *pMsg) if ( \ reg_num < 0x01 ||\ - (((reg_num + start_reg_addr - 1) > FRT_REGISTER_PRESSURE) && ((reg_num + start_reg_addr - 1) < FRT_REGISTER_DEVICE_ADDR)) ||\ + (((reg_num + start_reg_addr - 1) > FRT_REGISTER_PRESSURE) && ((reg_num + start_reg_addr - 1) < FRT_REGISTER_THROUGH_WIND_DIRECTION)) ||\ + (((reg_num + start_reg_addr - 1) > FRT_REGISTER_PEAK_WIND_SPEED) && ((reg_num + start_reg_addr - 1) < FRT_REGISTER_DEVICE_ADDR)) ||\ (((reg_num + start_reg_addr -1) > FRT_REGISTER_TEMPHUM_UPDATE_TIME) && ((reg_num + start_reg_addr -1) < FRT_REGISTER_TRANSDUCER_CFG_1R5)) ||\ - ((reg_num + start_reg_addr -1) > FRT_REGISTER_ID_4) \ + ((reg_num + start_reg_addr -1) > FRT_REGISTER_ID_4) \ ) { From 117777c09298630c98391b01a64dc1c427b824ee Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Sat, 18 Jan 2025 08:52:38 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=9C=A8=E4=B8=80=E9=98=B6=E4=BD=8E?= =?UTF-8?q?=E9=80=9A=E6=BB=A4=E6=B3=A2=E5=99=A8=E5=90=8E=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E6=B3=A2=E5=8A=A8=E8=BE=83=E5=A4=A7=E7=9A=84=E6=B3=A2?= =?UTF-8?q?=E5=8A=A8=E5=80=BC=EF=BC=8C=E8=A7=A3=E5=86=B3=E4=BA=86=E6=9C=89?= =?UTF-8?q?=E6=B0=B4=E6=97=B6=E8=A7=A6=E6=91=B8=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=A3=8E=E9=80=9F=E7=AA=81=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Drivers/Filter/LowPassFilter.c | 38 ++++++++++++++++++++++++++++++---- Drivers/Filter/LowPassFilter.h | 2 ++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Drivers/Filter/LowPassFilter.c b/Drivers/Filter/LowPassFilter.c index 49c4da5..f4879c8 100644 --- a/Drivers/Filter/LowPassFilter.c +++ b/Drivers/Filter/LowPassFilter.c @@ -10,14 +10,44 @@ void initLowPassFilter(SL_LowPassFilter* filter, float alpha) filter->alpha = alpha; // 初始化上一次的输出值为0 filter->previous = 0.0f; + + filter->x = 0; + filter->times = 0; } // 更新滤波器输出值 float updateFilter(SL_LowPassFilter* filter, float new_input) { - // 更新滤波后的值 - float output = (1.0f - filter->alpha) * filter->previous + filter->alpha * new_input; + // 滤波新值 + float filtedData = (1.0f - filter->alpha) * filter->previous + filter->alpha * new_input; + + //差值大于一定值认为有问题,暂定4 + if((filter->x) - filtedData > 4 || (filtedData) - filter->x > 4 ) + { +// 将有问题的值存起来 + (filter->x) = filtedData; +// 使用上一次的正确值当结果 + filtedData = filter->previous; +// 清空计数 + filter->times = 0; + }else + { +// 差值在允许范围内 +// 差值合理一定时间后认为数据没问题 + if(filter->times < 3) + { + filter->times++; +// 没满足次数,使用旧值 + filtedData = filter->previous; + } + else + { +// 将值存起来,直接使用滤波后的值 + (filter->x) = filtedData; + } + } + // 更新上一次的输出值 - filter->previous = output; - return output; + filter->previous = filtedData; + return filtedData; } \ No newline at end of file diff --git a/Drivers/Filter/LowPassFilter.h b/Drivers/Filter/LowPassFilter.h index 53fa63b..00d2d91 100644 --- a/Drivers/Filter/LowPassFilter.h +++ b/Drivers/Filter/LowPassFilter.h @@ -9,6 +9,8 @@ typedef struct { float alpha; // 滤波器系数 float previous; // 上一次的输出值 + float x; // 上一次的输入值 + uint8_t times; // 次数 } SL_LowPassFilter; extern SL_LowPassFilter low_pass_filter_x; From 980d3a242978580d1c49df2bcb955c284035de52 Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Sat, 18 Jan 2025 10:26:13 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E6=9C=89=E9=9A=9C=E7=A2=8D=E7=89=A9?= =?UTF-8?q?=E9=81=AE=E6=8C=A1=E6=8E=A2=E5=A4=B4=E6=97=B6=EF=BC=8C=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E5=B9=B3=E5=9D=87=E6=95=B0=E7=BB=84=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E4=B8=8E=E8=AE=A1=E6=95=B0=E5=BD=92=E9=9B=B6=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E9=87=8F=E5=A2=9E=E5=80=BC=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E6=BA=A2=E5=87=BA=EF=BC=9B=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=85=8D=E7=BD=AE=E5=8C=BA=E5=9F=9F=E4=B8=8E=E5=87=BA?= =?UTF-8?q?=E5=8E=82=E9=85=8D=E7=BD=AE=E5=8C=BA=E5=9F=9F=E9=83=BD=E9=A2=84?= =?UTF-8?q?=E7=95=9920=E4=B8=AA=E5=AD=97=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Inc/inflash.h | 2 ++ App/Src/anemometer_dev.c | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/App/Inc/inflash.h b/App/Inc/inflash.h index 40f9d99..db3c976 100644 --- a/App/Inc/inflash.h +++ b/App/Inc/inflash.h @@ -39,6 +39,8 @@ typedef struct _usr_config_info{ u_int16_t temp5; /* 鍗犱綅鐣欏緟鍗囩骇 */ u_int16_t temp6; /* 鍗犱綅鐣欏緟鍗囩骇 */ u_int16_t temp7; /* 鍗犱綅鐣欏緟鍗囩骇 */ + u_int16_t temp8; /* 鍗犱綅鐣欏緟鍗囩骇 */ + u_int16_t temp9; /* 鍗犱綅鐣欏緟鍗囩骇 */ u_int8_t flag_end; }usr_config_info; diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c index cb63dd5..2a45d42 100644 --- a/App/Src/anemometer_dev.c +++ b/App/Src/anemometer_dev.c @@ -460,6 +460,7 @@ char str[100]; //} +SlidingWindow_10min win_10min = {0}; void wind_task(void const * argument) { //杞欢鍔犲瘑鏍¢獙 @@ -527,7 +528,6 @@ void wind_task(void const * argument) // 鎺ュ彈淇″彿寰堝皬 if(tofx<0||tofy<0) { - tof_error_log_NS ++; // 鏀惧純鏈閲囨牱锛屽彲浠ユ湁鏁堢瓫閫夐洦婊寸瓑瀵艰嚧鐨勫紓甯稿ぇ鐨勯閫熸暟鎹 // 浣嗘槸鎸佺画鐨勯伄鎸′細瀵艰嚧椋庨熸暟鎹繚鎸佷笉鍙樸 // 杩炵画10娆¢噰鏍锋湁闂鍒ゅ畾涓烘湁閬尅锛岀疆閿欒鏍囧織浣嶏紝灏嗗0閫熶笌椋庨熷垎閲忕疆0 @@ -540,6 +540,7 @@ void wind_task(void const * argument) } else { + tof_error_log_NS ++; continue; } // 鎵嬪姩璁剧疆娓¤秺鏃堕棿宸负0锛屼細鍦ㄦ帰澶村彈閬尅鐨勬椂鍊欒緭鍑0锛屾寔缁伄鎸$殑鏃跺欎篃杈撳嚭0锛屼絾鏄绠楀嚭澹伴熷皢鍙樺緱寰堝ぇ @@ -594,7 +595,6 @@ void wind_task(void const * argument) // 濡傛灉娴嬮噺鐨勪俊鍙峰箙鍊艰繃灏忋 if(tofx<0||tofy<0) { - tof_error_log_WE ++; // 鏀惧純鏈閲囨牱锛屽彲浠ユ湁鏁堢瓫閫夐洦婊寸瓑瀵艰嚧鐨勫紓甯稿ぇ鐨勯閫熸暟鎹 // 浣嗘槸鎸佺画鐨勯伄鎸′細瀵艰嚧椋庨熸暟鎹繚鎸佷笉鍙樸 // 杩炵画10娆¢噰鏍锋湁闂鍒ゅ畾涓烘湁閬尅锛岀疆閿欒鏍囧織浣嶏紝灏嗗0閫熶笌椋庨熷垎閲忕疆0 @@ -607,6 +607,7 @@ void wind_task(void const * argument) } else { + tof_error_log_WE ++; continue; } // 鎵嬪姩璁剧疆娓¤秺鏃堕棿宸负0锛屼細鍦ㄦ帰澶村彈閬尅鐨勬椂鍊欒緭鍑0锛屾寔缁伄鎸$殑鏃跺欎篃杈撳嚭0锛屼絾鏄绠楀嚭澹伴熷皢鍙樺緱寰堝ぇ @@ -663,6 +664,9 @@ void wind_task(void const * argument) { av_speed = 0; av_angle = 0; + //婊戝姩骞冲潎鍊肩储寮曞綊闆 + win_10min.count = 0; + win_10min.index = 0; } // 360涓鍦 if(av_speedy<0) @@ -844,7 +848,6 @@ void update_mcs_param(float new_wind_speed, float new_wind_dirction) } } -SlidingWindow_10min win_10min = {0}; SlidingWindow_3s win_3s = {0}; //姹傚拰鍑芥暟 float sum(float arr[], int n) From d49f35ffeba891332ea07b3f478886ebae0a980d Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Mon, 20 Jan 2025 15:06:07 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Src/anemometer_dev.c | 8 -------- Core/Src/freertos.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c index 2a45d42..33f66d8 100644 --- a/App/Src/anemometer_dev.c +++ b/App/Src/anemometer_dev.c @@ -1069,7 +1069,6 @@ void tem_hum_update_task(void const * argument) uint8_t tem_hun_check_flag = JudgeEncrypt(); uint16_t time_s_temp_humi = 0;//1绉掕鏃讹紝娓╂箍搴︽洿鏂 - uint32_t time_s_1Day = 0;//1澶╃殑绉掓暟 float backupTemperature; uint8_t hp203_ret; @@ -1100,7 +1099,6 @@ void tem_hum_update_task(void const * argument) osDelay(1000); if(!tem_hun_check_flag)continue; time_s_temp_humi ++; - time_s_1Day ++; // 娓╂箍搴﹀ぇ姘斿帇鏇存柊 if (time_s_temp_humi >= g_usrConfigInfo.temp_hum_update_time) { @@ -1132,12 +1130,6 @@ void tem_hum_update_task(void const * argument) // 璁℃椂閲嶇疆 time_s_temp_humi = 0; } -// 涓澶╅噸鍚 - if (time_s_1Day >= 86400) - { - __iar_builtin_set_FAULTMASK(1); - NVIC_SystemReset(); - } // 椋庨熼鍚戞洿鏂 my_update_mcs_param(weather_info.instantaneous_wind_speed, weather_info.instantaneous_wind_direction); } diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index b37fcd7..7f57e69 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -188,6 +188,8 @@ void SensorTask(void const * argument) } /* USER CODE END Application */ + uint16_t time_s_1Hour = 0;//1小时的秒数 + uint8_t time_h_1Day = 0;//1天的小时 void LEDTask(void const * argument) { /* USER CODE BEGIN StartDefaultTask */ @@ -196,9 +198,22 @@ void LEDTask(void const * argument) for(;;) { osDelay(1000); + time_s_1Hour ++; if(LED_Check_flag) { HAL_GPIO_TogglePin(GPIOC,GPIO_LED_CTRL_Pin); + // 一天重启 + if (time_s_1Hour >= 3600) + { + time_s_1Hour = 0; + time_h_1Day++; + } + if (time_h_1Day >= 24) + { + time_h_1Day = 0; + __iar_builtin_set_FAULTMASK(1); + NVIC_SystemReset(); + } } } /* USER CODE END StartDefaultTask */ From afe80d069530e3dfea8c3e4aa079394fd340b6d4 Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Wed, 22 Jan 2025 15:42:33 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E6=BB=A4=E9=99=A4=E8=BE=83=E5=A4=A7?= =?UTF-8?q?=E6=B3=A2=E5=8A=A8=E6=9C=89BUG=EF=BC=8C=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Drivers/Filter/LowPassFilter.c | 50 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Drivers/Filter/LowPassFilter.c b/Drivers/Filter/LowPassFilter.c index f4879c8..50a3052 100644 --- a/Drivers/Filter/LowPassFilter.c +++ b/Drivers/Filter/LowPassFilter.c @@ -21,31 +21,31 @@ float updateFilter(SL_LowPassFilter* filter, float new_input) // 滤波新值 float filtedData = (1.0f - filter->alpha) * filter->previous + filter->alpha * new_input; - //差值大于一定值认为有问题,暂定4 - if((filter->x) - filtedData > 4 || (filtedData) - filter->x > 4 ) - { -// 将有问题的值存起来 - (filter->x) = filtedData; -// 使用上一次的正确值当结果 - filtedData = filter->previous; -// 清空计数 - filter->times = 0; - }else - { -// 差值在允许范围内 -// 差值合理一定时间后认为数据没问题 - if(filter->times < 3) - { - filter->times++; -// 没满足次数,使用旧值 - filtedData = filter->previous; - } - else - { -// 将值存起来,直接使用滤波后的值 - (filter->x) = filtedData; - } - } +// //差值大于一定值认为有问题,暂定4 +// if((filter->x) - filtedData > 4 || (filtedData) - filter->x > 4 ) +// { +//// 将有问题的值存起来 +// (filter->x) = filtedData; +//// 使用上一次的正确值当结果 +// filtedData = filter->previous; +//// 清空计数 +// filter->times = 0; +// }else +// { +//// 差值在允许范围内 +//// 差值合理一定时间后认为数据没问题 +// if(filter->times < 3) +// { +// filter->times++; +//// 没满足次数,使用旧值 +// filtedData = filter->previous; +// } +// else +// { +//// 将值存起来,直接使用滤波后的值 +// (filter->x) = filtedData; +// } +// } // 更新上一次的输出值 filter->previous = filtedData; From 075d2931735e06ea051ba7bb4f2e59d94d9871f0 Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Thu, 20 Feb 2025 13:32:40 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E8=AF=BB=E8=B6=85=E8=BF=87=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E7=9A=84=E5=AF=84=E5=AD=98=E5=99=A8=E8=BF=94=E5=9B=9E?= =?UTF-8?q?0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Src/frt_protocol.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/App/Src/frt_protocol.c b/App/Src/frt_protocol.c index 238bd93..79dfe98 100644 --- a/App/Src/frt_protocol.c +++ b/App/Src/frt_protocol.c @@ -31,8 +31,9 @@ static u_int16_t FRT_ReadRegTemperature(void *pMsg); static u_int16_t FRT_ReadRegHumidity(void *pMsg); static u_int16_t FRT_ReadRegPressure(void *pMsg); static u_int16_t FRT_ReadRegRain(void *pMsg); -/* 璇 */ static u_int16_t FRT_ReadRegPrecipitationIntensity(void *pMsg); +static u_int16_t FRT_ReadRegUVIntensity(void *pMsg); +/* 璇 */ static u_int16_t FRT_ReadRegDeviceAddr(void *pMsg); static u_int16_t FRT_ReadRegCommuBaudRate(void *pMsg); static u_int16_t FRT_ReadRegSpeedAverageTime(void *pMsg); @@ -126,6 +127,8 @@ FRT_RegProcTable_s g_RegTbl[] = { FRT_REGISTER_PRESSURE, FRT_ReadRegPressure }, /* 澶ф皵鍘 */ { FRT_REGISTER_RAIN, FRT_ReadRegRain }, /* 闆ㄩ噺 */ { FRT_REGISTER_PRECIPITATION_INTENSITY, FRT_ReadRegPrecipitationIntensity }, /* 鎬昏緪灏 */ + { FRT_REGISTER_UV_INTENSITY, FRT_ReadRegUVIntensity }, /* 绱寮哄害 */ + { FRT_REGISTER_DEVICE_ADDR, FRT_ReadRegDeviceAddr }, /* 璁惧鍦板潃 */ { FRT_REGISTER_COMMU_BAUDRATE, FRT_ReadRegCommuBaudRate }, /* 娉㈢壒鐜 */ { FRT_REGISTER_SPEED_AVERAGE_TIME, FRT_ReadRegSpeedAverageTime }, /* 椋庨熷钩鍧囨椂闂 */ @@ -396,7 +399,7 @@ static u_int16_t FRT_ReadRegPressure(void *pMsg) */ static u_int16_t FRT_ReadRegRain(void *pMsg) { - u_int16_t value=9; + u_int16_t value=0; return FRT_swap_endian_16(value); } @@ -407,7 +410,18 @@ static u_int16_t FRT_ReadRegRain(void *pMsg) */ static u_int16_t FRT_ReadRegPrecipitationIntensity(void *pMsg) { - u_int16_t value=10; + u_int16_t value=0; + return FRT_swap_endian_16(value); +} + +/** + * @brief 璇荤传澶栧己搴﹀瘎瀛樺櫒鍊 + * @param + * @retval + */ +static u_int16_t FRT_ReadRegUVIntensity(void *pMsg) +{ + u_int16_t value=0; return FRT_swap_endian_16(value); } @@ -1298,7 +1312,7 @@ void FRT_MsgProc_ReadRegister(device_handle device, void *pMsg) u_int16_t reg_num= (data[4] << 8)| data[5]; if ( \ start_reg_addr < 0x00 ||\ - (start_reg_addr > FRT_REGISTER_PRESSURE && start_reg_addr < FRT_REGISTER_THROUGH_WIND_DIRECTION) ||\ +/* (start_reg_addr > FRT_REGISTER_PRESSURE && start_reg_addr < FRT_REGISTER_THROUGH_WIND_DIRECTION) ||\ */ (start_reg_addr > FRT_REGISTER_PEAK_WIND_SPEED && start_reg_addr < FRT_REGISTER_DEVICE_ADDR) ||\ (start_reg_addr > FRT_REGISTER_TEMPHUM_UPDATE_TIME && start_reg_addr < FRT_REGISTER_TRANSDUCER_CFG_1R5) ||\ start_reg_addr > FRT_REGISTER_ID_4 \ @@ -1311,7 +1325,7 @@ void FRT_MsgProc_ReadRegister(device_handle device, void *pMsg) if ( \ reg_num < 0x01 ||\ - (((reg_num + start_reg_addr - 1) > FRT_REGISTER_PRESSURE) && ((reg_num + start_reg_addr - 1) < FRT_REGISTER_THROUGH_WIND_DIRECTION)) ||\ +/* (((reg_num + start_reg_addr - 1) > FRT_REGISTER_PRESSURE) && ((reg_num + start_reg_addr - 1) < FRT_REGISTER_THROUGH_WIND_DIRECTION)) ||\ */ (((reg_num + start_reg_addr - 1) > FRT_REGISTER_PEAK_WIND_SPEED) && ((reg_num + start_reg_addr - 1) < FRT_REGISTER_DEVICE_ADDR)) ||\ (((reg_num + start_reg_addr -1) > FRT_REGISTER_TEMPHUM_UPDATE_TIME) && ((reg_num + start_reg_addr -1) < FRT_REGISTER_TRANSDUCER_CFG_1R5)) ||\ ((reg_num + start_reg_addr -1) > FRT_REGISTER_ID_4) \ From 34c91c30992658ecf15a7c40f669dbdb1cabcba8 Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Fri, 21 Feb 2025 14:49:15 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E6=B8=A9=E5=BA=A6=E6=8E=A2=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Inc/anemometer_dev.h | 8 ++- App/Src/anemometer_dev.c | 108 +++++++++++++++++++++++---------------- Core/Src/freertos.c | 3 +- Core/Src/main.c | 2 + Drivers/Tmp117/tmp117.c | 45 ++++++++++++++++ Drivers/Tmp117/tmp117.h | 27 ++++++++++ EWARM/micro_climate.ewp | 11 ++++ EWARM/micro_climate.ewt | 9 ++++ 8 files changed, 165 insertions(+), 48 deletions(-) create mode 100644 Drivers/Tmp117/tmp117.c create mode 100644 Drivers/Tmp117/tmp117.h diff --git a/App/Inc/anemometer_dev.h b/App/Inc/anemometer_dev.h index b66fd56..dd40f8f 100644 --- a/App/Inc/anemometer_dev.h +++ b/App/Inc/anemometer_dev.h @@ -35,9 +35,13 @@ #define DRIVE_FREQ_MHz ((float32_t)0.2) // 椹卞姩鏂规尝涓暟 瀹為檯涓暟 DRIVE_NUM+1 - #define DRIVE_NUM 2 +// 娓╁害鎺㈠ご鐗堟湰锛孲HT30=1锛孴MP117=2 +#define SHT30_SENSOR 1 +#define TMP117_SENSOR 2 +#define TEMP_SENSOR TMP117_SENSOR + ///宸插皢DISTANCE鍐欏叆閰嶇疆鏂囦欢锛屽湪缁撴瀯浣揼_stConfigInfo.transducer_distace涓 // 浼犳挱璺濈 椋庨熻绠楀叕寮忎腑鐨凩鍙傛暟 @@ -140,7 +144,7 @@ typedef struct _error_log{ uint16_t tof_error_WE:1; /* 鎺ュ彈涓滆タ淇″彿锛坱ofy锛宼ofx<0锛夊緢灏 */ uint16_t temp_error_SHT30:1; /* SHT30閿欒鏃ュ織锛堟俯婀垮害锛 */ uint16_t temp_error_HP203B:1; /* HP203B閿欒鏃ュ織锛堝ぇ姘斿帇锛 */ - uint16_t error_4:1; /* 淇濈暀 */ + uint16_t temp_error_TMP117:1; /* TMP117閿欒鏃ュ織锛堟俯搴) */ uint16_t error_5:1; /* 淇濈暀 */ uint16_t error_6:1; /* 淇濈暀 */ uint16_t error_7:1; /* 淇濈暀 */ diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c index 33f66d8..f5259f2 100644 --- a/App/Src/anemometer_dev.c +++ b/App/Src/anemometer_dev.c @@ -6,6 +6,7 @@ #include "fdacoefs.h" #include "sht30.h" #include "hp203b.h" +#include "tmp117.h" #include "FIR.h" #include "LowPassFilter.h" #include "encrypt.h" @@ -1063,35 +1064,76 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction) win_10min.index = (win_10min.index + 1) % g_usrConfigInfo.speed_average_time;//鏇存柊绱㈠紩 } +//閲囬泦娓╁害锛屾箍搴︼紝澶ф皵鍘 +static void getTempHumiPress(void) +{ + //閲囬泦澶囩敤娓╁害涓庡ぇ姘斿帇 + float backupTemperature1; + float backupTemperature2; + uint8_t hp203_ret = get_HP203_data(&backupTemperature1, &g_stMcs_Para.pressure); + uint8_t sht30_ret = get_temp_humi_data(&backupTemperature2, &g_stMcs_Para.humidity); +#if TEMP_SENSOR == SHT30_SENSOR + g_stMcs_Para.temperature = backupTemperature2; +#endif /*TEMP_SENSOR == SHT30_SENSOR*/ + +#if TEMP_SENSOR == TMP117_SENSOR + uint8_t tmp117_ret = TMP117_Get_Temp(&g_stMcs_Para.temperature); + +// TMP117鍑洪棶棰 + if(tmp117_ret != HAL_OK) + { + //缃敊璇爣蹇椾綅 + g_error_log.temp_error_TMP117 = 1; + //浣跨敤澶囩敤娓╁害 + g_stMcs_Para.temperature = backupTemperature1; + } + else + { + //鎭㈠閿欒鏍囧織浣 + g_error_log.temp_error_TMP117 = 0; + } +#endif /*TEMP_SENSOR == TMP117_SENSOR*/ + + // SHT30鍑洪棶棰 + if(sht30_ret == FALSE) + { + //缃敊璇爣蹇椾綅 + g_error_log.temp_error_SHT30 = 1; + //閿欒澶勭悊 +#if TEMP_SENSOR == SHT30_SENSOR + g_stMcs_Para.temperature = backupTemperature1; +#endif /*TEMP_SENSOR == SHT30_SENSOR*/ + } + else + { + //鎭㈠閿欒鏍囧織浣 + g_error_log.temp_error_SHT30 = 0; + } + + //HP203B鍑洪棶棰 + if(hp203_ret == FALSE) + { + //缃敊璇爣蹇椾綅 + g_error_log.temp_error_HP203B = 1; + //閿欒澶勭悊 + } + else + { + //鎭㈠閿欒鏍囧織浣 + g_error_log.temp_error_HP203B = 0; + } +} void tem_hum_update_task(void const * argument) { uint8_t tem_hun_check_flag = JudgeEncrypt(); uint16_t time_s_temp_humi = 0;//1绉掕鏃讹紝娓╂箍搴︽洿鏂 - - float backupTemperature; - uint8_t hp203_ret; - uint8_t sht30_ret; // 寮鏈哄厛閲囬泦涓娆″ぇ姘斿帇娓╂箍搴 if(tem_hun_check_flag) { - uint8_t hp203_ret = get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure); - uint8_t sht30_ret = get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity); - } - -// 閲囬泦HP203B浼犳劅鍣ㄦ暟鎹紙澶ф皵鍘嬶級 - if(hp203_ret == FALSE) - { - g_error_log.temp_error_HP203B = 1; -/// 閿欒澶勭悊 - } -// 閲囬泦SHT30浼犳劅鍣ㄦ暟鎹紙娓╂箍搴︼級 - if(sht30_ret == FALSE) - { - g_error_log.temp_error_SHT30 = 1; -/// 閿欒澶勭悊 - g_stMcs_Para.temperature = backupTemperature; + //閲囬泦娓╂箍搴︿笌澶ф皵鍘 + getTempHumiPress(); } while(1) @@ -1102,31 +1144,7 @@ void tem_hum_update_task(void const * argument) // 娓╂箍搴﹀ぇ姘斿帇鏇存柊 if (time_s_temp_humi >= g_usrConfigInfo.temp_hum_update_time) { - hp203_ret = get_HP203_data(&backupTemperature, &g_stMcs_Para.pressure); - sht30_ret = get_temp_humi_data(&g_stMcs_Para.temperature, &g_stMcs_Para.humidity); -// 閲囬泦HP203B浼犳劅鍣ㄦ暟鎹紙澶ф皵鍘嬶級 - if(hp203_ret == FALSE) - { - g_error_log.temp_error_HP203B = 1; -/// 閿欒澶勭悊 - } - else - { - // 娌″嚭闂娓呴櫎閿欒鏃ュ織 - g_error_log.temp_error_HP203B = 0; - } -// 閲囬泦SHT30浼犳劅鍣ㄦ暟鎹紙娓╂箍搴︼級 - if(sht30_ret == FALSE) - { - g_error_log.temp_error_SHT30 = 1; -/// 閿欒澶勭悊 - g_stMcs_Para.temperature = backupTemperature; - } - else - { - // 娌″嚭闂娓呴櫎閿欒鏃ュ織 - g_error_log.temp_error_SHT30 = 0; - } + getTempHumiPress(); // 璁℃椂閲嶇疆 time_s_temp_humi = 0; } diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 7f57e69..5ee9e32 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -32,6 +32,7 @@ void task_shell_term_main_loop(void const * argument); #include "frt_protocol.h" #include "inflash.h" #include "hp203b.h" +#include "tmp117.h" #include "encrypt.h" /* USER CODE END Includes */ @@ -201,7 +202,7 @@ void LEDTask(void const * argument) time_s_1Hour ++; if(LED_Check_flag) { - HAL_GPIO_TogglePin(GPIOC,GPIO_LED_CTRL_Pin); + HAL_GPIO_TogglePin(GPIOC,GPIO_LED_CTRL_Pin); // 一天重启 if (time_s_1Hour >= 3600) { diff --git a/Core/Src/main.c b/Core/Src/main.c index 3c1f1cd..956ae80 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -43,6 +43,7 @@ #include "uart_dev.h" #include "sht30.h" #include "hp203b.h" +#include "tmp117.h" #include "inflash.h" /* USER CODE END Includes */ @@ -172,6 +173,7 @@ void Flash_EnableReadProtection(void) term_printf("Version 1.0.0 Build: %s %s\r\n",__DATE__,__TIME__); HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED); sht30_init(); + TMP117_Init(); /* USER CODE END 2 */ /* Call init function for freertos objects (in cmsis_os2.c) */ diff --git a/Drivers/Tmp117/tmp117.c b/Drivers/Tmp117/tmp117.c new file mode 100644 index 0000000..55e0969 --- /dev/null +++ b/Drivers/Tmp117/tmp117.c @@ -0,0 +1,45 @@ +#include "tmp117.h" +#include "i2c.h" + + +// 初始化温度传感器(连续转换模式,64次平均) +HAL_StatusTypeDef TMP117_Init(void) +{ + // 配置值:连续转换模式 + AVG=64 (0x00A0) + uint8_t config_data[2] = {0x00, 0xA0}; // 高字节在前 + return HAL_I2C_Mem_Write(&hi2c1, TMP117_ADDR << 1, TMP117_CONFIG_REG, + I2C_MEMADD_SIZE_8BIT, config_data, 2, 100); +} + +// 从寄存器读取双字节数据 +HAL_StatusTypeDef TMP117_Read(uint8_t reg, uint8_t *buffer) { + return HAL_I2C_Mem_Read(&hi2c1, TMP117_ADDR << 1, reg, + I2C_MEMADD_SIZE_8BIT, buffer, 2, 100); +} + +// 获取温度值(单位:℃) +HAL_StatusTypeDef TMP117_Get_Temp(float *temp) +{ + uint8_t raw_data[2] = {0}; + int16_t temp_raw; + + if (HAL_OK == TMP117_Read(TMP117_TEMP_REG, raw_data)) { + temp_raw = (raw_data[0] << 8) | raw_data[1]; + *temp = temp_raw * 0.0078125f; + } + else + { + *temp = 0; + return HAL_ERROR; + } + if(*temp <= -60) + { + *temp = -60; + } + if(*temp >= 150) + { + *temp = 150; + } + return HAL_OK; +} + diff --git a/Drivers/Tmp117/tmp117.h b/Drivers/Tmp117/tmp117.h new file mode 100644 index 0000000..7111240 --- /dev/null +++ b/Drivers/Tmp117/tmp117.h @@ -0,0 +1,27 @@ +#ifndef __TMP117_H_ +#define __TMP117_H_ + +#include "comm_types.h" +#include "main.h" + +#define TMP117_ADDR 0x48 //A0接GND +//#define TMP117_ADDR 0x49 //A0接V+ +//#define TMP117_ADDR 0x4A //A0接SDA +//#define TMP117_ADDR 0x4B //A0接SCL + +#define TMP117_TEMP_REG 0x00 //温度寄存器 +#define TMP117_CONFIG_REG 0x01 //配置寄存器 +#define TMP117_TLOW_REG 0x02 //温度高报警寄存器 +#define TMP117_THIGH_REG 0x03 //温度低报警寄存器 + + + +HAL_StatusTypeDef TMP117_Init(void); +HAL_StatusTypeDef TMP117_Read(uint8_t reg, uint8_t *buffer); +HAL_StatusTypeDef TMP117_Get_Temp(float *temp); + +#endif __TMP117_H_ + + + + diff --git a/EWARM/micro_climate.ewp b/EWARM/micro_climate.ewp index 4e95e6e..6518386 100644 --- a/EWARM/micro_climate.ewp +++ b/EWARM/micro_climate.ewp @@ -374,6 +374,7 @@ $PROJ_DIR$\..\tools $PROJ_DIR$\..\App\Inc $PROJ_DIR$\..\Drivers\HP203B + $PROJ_DIR$\..\Drivers\Tmp117