diff --git a/App/Inc/frt_protocol.h b/App/Inc/frt_protocol.h index 160fbce..87b2e65 100644 --- a/App/Inc/frt_protocol.h +++ b/App/Inc/frt_protocol.h @@ -44,12 +44,23 @@ typedef enum FRT_REGISTER_REST_DEFAULT_SETTING = 27, /* 恢复出厂设置 */ FRT_REGISTER_PROTOCOL_SETTING = 28, /* 设置协议:0-ASCII;1-MODBUS协议 */ - FRT_REGISTER_TRANSDUCER_CFG_1R5 = 30, /* 换能器参数 */ - FRT_REGISTER_TRANSDUCER_CFG_4R5 = 31, /* 换能器参数 */ - FRT_REGISTER_TRANSDUCER_CFG_8R0 = 32, /* 换能器参数 */ - FRT_REGISTER_RSSI_RANGE = 33, /* RSSI有效范围 */ - FRT_REGISTER_WAVE_DATA = 34, /* 波形数据 */ - FRT_REGISTER_ERROR_LOG = 35, /* 错误日志 */ + FRT_REGISTER_TRANSDUCER_CFG_1R5 = 30, /* 换能器参数 */ + FRT_REGISTER_TRANSDUCER_CFG_4R5 = 31, /* 换能器参数 */ + FRT_REGISTER_TRANSDUCER_CFG_8R0 = 32, /* 换能器参数 */ + FRT_REGISTER_RSSI_RANGE = 33, /* RSSI有效范围 */ + FRT_REGISTER_WAVE_DATA = 34, /* 波形数据 */ + FRT_REGISTER_ERROR_LOG = 35, /* 错误日志 */ + FRT_REGISTER_LINEAR_POINT_X_1 = 36, /* 线性插值原始点1 */ + FRT_REGISTER_LINEAR_POINT_X_2 = 37, /* 线性插值原始点2 */ + FRT_REGISTER_LINEAR_POINT_X_3 = 38, /* 线性插值原始点3 */ + FRT_REGISTER_LINEAR_POINT_X_4 = 39, /* 线性插值原始点4 */ + FRT_REGISTER_LINEAR_POINT_X_5 = 40, /* 线性插值原始点5 */ + FRT_REGISTER_LINEAR_POINT_Y_1 = 41, /* 线性插值校准点1 */ + FRT_REGISTER_LINEAR_POINT_Y_2 = 42, /* 线性插值校准点2 */ + FRT_REGISTER_LINEAR_POINT_Y_3 = 43, /* 线性插值校准点3 */ + FRT_REGISTER_LINEAR_POINT_Y_4 = 44, /* 线性插值校准点4 */ + FRT_REGISTER_LINEAR_POINT_Y_5 = 45, /* 线性插值校准点5 */ + FRT_REGISTER_LINEAR_ENABLE = 46, /* 线性插值使能 */ }FRT_MsgRegister; #pragma pack(push,1) diff --git a/App/Inc/inflash.h b/App/Inc/inflash.h index d03b681..d374096 100644 --- a/App/Inc/inflash.h +++ b/App/Inc/inflash.h @@ -27,6 +27,17 @@ typedef struct _config_info{ u_int16_t transducer_cfg_4R5; /* 鎹㈣兘鍣ㄥ弬鏁 */ u_int16_t transducer_cfg_8R0; /* 鎹㈣兘鍣ㄥ弬鏁 */ u_int16_t RSSI_range; /* RSSI鏈夋晥鑼冨洿 */ + u_int16_t linear_point_1_x; /* 绾挎ф彃鍊肩偣1X */ + u_int16_t linear_point_1_y; /* 绾挎ф彃鍊肩偣1Y */ + u_int16_t linear_point_2_x; /* 绾挎ф彃鍊肩偣2X */ + u_int16_t linear_point_2_y; /* 绾挎ф彃鍊肩偣2Y */ + u_int16_t linear_point_3_x; /* 绾挎ф彃鍊肩偣3X */ + u_int16_t linear_point_3_y; /* 绾挎ф彃鍊肩偣3Y */ + u_int16_t linear_point_4_x; /* 绾挎ф彃鍊肩偣4X */ + u_int16_t linear_point_4_y; /* 绾挎ф彃鍊肩偣4Y */ + u_int16_t linear_point_5_x; /* 绾挎ф彃鍊肩偣5X */ + u_int16_t linear_point_5_y; /* 绾挎ф彃鍊肩偣5Y */ + u_int16_t linear_enable; /* 绾挎ф彃鍊间娇鑳 */ u_int8_t flag_end; }config_info; #pragma pack(pop) diff --git a/App/Src/anemometer_dev.c b/App/Src/anemometer_dev.c index b8b4d87..59744c2 100644 --- a/App/Src/anemometer_dev.c +++ b/App/Src/anemometer_dev.c @@ -526,7 +526,7 @@ void wind_task(void const * argument) av_speed = 0; av_angle = 0; } -// term_printf("x:%.2f y:%.2f win_speed %.2f m/s angle %.2f \r\n",av_speedx,av_speedy,av_speed,av_angle); +/// term_printf("x:%.2f y:%.2f win_speed %.2f m/s angle %.2f \r\n",av_speedx,av_speedy,av_speed,av_angle); } ///term_printf("win_speed %.2f \r\n",weather_info.wind_velocity); @@ -704,8 +704,59 @@ float sum(float arr[], int n) return total; } -int times_1s_3sec = 0; -int times_1s_1min = 0; +//int times_1s_3sec = 0; +//int times_1s_1min = 0; + +// 绾挎ф彃鍊煎嚱鏁 +//float linear_interpolation(float x0, float y0, float x1, float y1, float x) { +float linear_interpolation(float x) { + float y; + //寮濮嬫彃鍊 + uint16_t x1 = g_stConfigInfo.linear_point_1_x; + uint16_t y1 = g_stConfigInfo.linear_point_1_y; + uint16_t x2 = g_stConfigInfo.linear_point_2_x; + uint16_t y2 = g_stConfigInfo.linear_point_2_y; + uint16_t x3 = g_stConfigInfo.linear_point_3_x; + uint16_t y3 = g_stConfigInfo.linear_point_3_y; + uint16_t x4 = g_stConfigInfo.linear_point_4_x; + uint16_t y4 = g_stConfigInfo.linear_point_4_y; + uint16_t x5 = g_stConfigInfo.linear_point_5_x; + uint16_t y5 = g_stConfigInfo.linear_point_5_y; + if(g_stConfigInfo.linear_enable == 0x01) + { + if (x1 == x2 || x2 == x3 || x3 == x4 || x4 == x5) + { +// 鏈夐棶棰樺氨杩斿洖鍒濆鍊 + return x; + } + if(x>=0&&x=x1&&x=x2&&x=x3&&x=x4&&x=x4) + { + y = y4 + (x - x4) * (y5 - y4) / (x5 - x4); + } + return y; + } + else + { + return x; + } +} void my_update_mcs_param(float new_wind_speed, float new_wind_dirction) { @@ -718,8 +769,7 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction) win_10min.count++; } - if(win_10min.count > g_stConfigInfo.speed_average_time/*AVE_TIME*/){win_10min.count = /*AVE_TIME*/g_stConfigInfo.speed_average_time;} - + if(win_10min.count > g_stConfigInfo.speed_average_time/*AVE_TIME*/){win_10min.count = /*AVE_TIME*/g_stConfigInfo.speed_average_time;} //璁$畻10min椋庨熸粦鍔ㄥ钩鍧囧 win_10min.ave_speed_data[win_10min.index] = sum(win_10min.speed_data, win_10min.count) / win_10min.count; //璁$畻10min椋庡悜婊戝姩骞冲潎鍊硷紝椋庡悜婊戝姩骞冲潎鍊奸渶瑕佽繃闆剁畻娉 @@ -744,6 +794,13 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction) win_10min.ave_direction_data[win_10min.index] += 360; } + /** 绾挎ф彃鍊 **/ + /** win_10min.ave_speed_data[win_10min.index]涓洪閫 **/ + /** win_10min.ave_direction_data[win_10min.index]涓洪鍚 **/ + /** 椋庡悜涓嶈鎻掑 **/ + win_10min.ave_speed_data[win_10min.index] = linear_interpolation(win_10min.ave_speed_data[win_10min.index]); + /** 绾挎ф彃鍊 **/ + //榛樿绗竴涓暟鎹负鏈澶ф垨鑰呮渶灏 float temp_min_direction = win_10min.ave_direction_data[0]; float temp_max_direction = win_10min.ave_direction_data[0]; @@ -763,7 +820,7 @@ void my_update_mcs_param(float new_wind_speed, float new_wind_dirction) if (win_10min.ave_speed_data[i] > temp_max_speed) { temp_max_speed = win_10min.ave_speed_data[i]; // 鏇存柊椋庨熸渶澶у } - } + } g_stMcs_Para.min_wind_direction = temp_min_direction; g_stMcs_Para.average_wind_direction = win_10min.ave_direction_data[win_10min.index]; diff --git a/App/Src/frt_protocol.c b/App/Src/frt_protocol.c index a416689..178ee0a 100644 --- a/App/Src/frt_protocol.c +++ b/App/Src/frt_protocol.c @@ -46,11 +46,28 @@ static u_int16_t FRT_ReadRegTransducerCFG8R0(void *pMsg); static u_int16_t FRT_ReadRegRSSIRange(void *pMsg); static u_int16_t FRT_ReadRegWaveData(void *pMsg); static u_int16_t FRT_ReadRegErrorData(void *pMsg); +static u_int16_t FRT_ReadRegPoint_1X(void *pMsg); +static u_int16_t FRT_ReadRegPoint_2X(void *pMsg); +static u_int16_t FRT_ReadRegPoint_3X(void *pMsg); +static u_int16_t FRT_ReadRegPoint_4X(void *pMsg); +static u_int16_t FRT_ReadRegPoint_5X(void *pMsg); +static u_int16_t FRT_ReadRegPoint_1Y(void *pMsg); +static u_int16_t FRT_ReadRegPoint_2Y(void *pMsg); +static u_int16_t FRT_ReadRegPoint_3Y(void *pMsg); +static u_int16_t FRT_ReadRegPoint_4Y(void *pMsg); +static u_int16_t FRT_ReadRegPoint_5Y(void *pMsg); +static u_int16_t FRT_ReadRegLinearEnable(void *pMsg); /* 鍐欓厤缃 */ static u_int16_t FRT_WriteRegTransducerCFG1R5(void *pMsg); static u_int16_t FRT_WriteRegTransducerCFG4R5(void *pMsg); static u_int16_t FRT_WriteRegTransducerCFG8R0(void *pMsg); static u_int16_t FRT_WriteRegRSSIRange(void *pMsg); +static u_int16_t FRT_WriteRegPoint_1Y(void *pMsg); +static u_int16_t FRT_WriteRegPoint_2Y(void *pMsg); +static u_int16_t FRT_WriteRegPoint_3Y(void *pMsg); +static u_int16_t FRT_WriteRegPoint_4Y(void *pMsg); +static u_int16_t FRT_WriteRegPoint_5Y(void *pMsg); +static u_int16_t FRT_WriteRegLinearEnable(void *pMsg); static void pdebug_mcs_info(); @@ -85,6 +102,17 @@ FRT_RegProcTable_s g_RegTbl[] = { FRT_REGISTER_TRANSDUCER_CFG_8R0, FRT_ReadRegTransducerCFG8R0 }, /* 璇绘崲鑳藉櫒鍙傛暟瀵勫瓨鍣ㄥ8R0 */ { FRT_REGISTER_RSSI_RANGE, FRT_ReadRegRSSIRange }, /* 璇籖SSI鏈夋晥鑼冨洿 */ { FRT_REGISTER_ERROR_LOG, FRT_ReadRegErrorData }, /* 璇婚敊璇棩蹇 */ + { FRT_REGISTER_LINEAR_POINT_X_1, FRT_ReadRegPoint_1X }, /* 绾挎ф彃鍊煎師濮嬬偣1 */ + { FRT_REGISTER_LINEAR_POINT_X_2, FRT_ReadRegPoint_2X }, /* 绾挎ф彃鍊煎師濮嬬偣2 */ + { FRT_REGISTER_LINEAR_POINT_X_3, FRT_ReadRegPoint_3X }, /* 绾挎ф彃鍊煎師濮嬬偣3 */ + { FRT_REGISTER_LINEAR_POINT_X_4, FRT_ReadRegPoint_4X }, /* 绾挎ф彃鍊煎師濮嬬偣4 */ + { FRT_REGISTER_LINEAR_POINT_X_5, FRT_ReadRegPoint_5X }, /* 绾挎ф彃鍊煎師濮嬬偣5 */ + { FRT_REGISTER_LINEAR_POINT_Y_1, FRT_ReadRegPoint_1Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣1 */ + { FRT_REGISTER_LINEAR_POINT_Y_2, FRT_ReadRegPoint_2Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣2 */ + { FRT_REGISTER_LINEAR_POINT_Y_3, FRT_ReadRegPoint_3Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣3 */ + { FRT_REGISTER_LINEAR_POINT_Y_4, FRT_ReadRegPoint_4Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣4 */ + { FRT_REGISTER_LINEAR_POINT_Y_5, FRT_ReadRegPoint_5Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣5 */ + { FRT_REGISTER_LINEAR_ENABLE, FRT_ReadRegLinearEnable }, /* 绾挎ф彃鍊间娇鑳 */ }; /* 鍐欏瘎瀛樺櫒澶勭悊琛 */ @@ -100,6 +128,12 @@ FRT_RegProcTable_s g_Write_RegTbl[] = { FRT_REGISTER_TRANSDUCER_CFG_4R5, FRT_WriteRegTransducerCFG4R5 }, /* 鍐欐崲鑳藉櫒鍙傛暟瀵勫瓨鍣ㄥ4R5 */ { FRT_REGISTER_TRANSDUCER_CFG_8R0, FRT_WriteRegTransducerCFG8R0 }, /* 鍐欐崲鑳藉櫒鍙傛暟瀵勫瓨鍣ㄥ8R0 */ { FRT_REGISTER_RSSI_RANGE, FRT_WriteRegRSSIRange }, /* 鍐橰SSI鏈夋晥鑼冨洿 */ + { FRT_REGISTER_LINEAR_POINT_Y_1, FRT_WriteRegPoint_1Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣1 */ + { FRT_REGISTER_LINEAR_POINT_Y_2, FRT_WriteRegPoint_2Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣2 */ + { FRT_REGISTER_LINEAR_POINT_Y_3, FRT_WriteRegPoint_3Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣3 */ + { FRT_REGISTER_LINEAR_POINT_Y_4, FRT_WriteRegPoint_4Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣4 */ + { FRT_REGISTER_LINEAR_POINT_Y_5, FRT_WriteRegPoint_5Y }, /* 绾挎ф彃鍊兼牎鍑嗙偣5 */ + { FRT_REGISTER_LINEAR_ENABLE, FRT_WriteRegLinearEnable }, /* 绾挎ф彃鍊间娇鑳 */ }; /** @@ -480,6 +514,40 @@ static u_int16_t FRT_ReadRegErrorData(void *pMsg) return FRT_swap_endian_16(value); } +static u_int16_t FRT_ReadRegPoint_1X(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_2X(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_3X(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_4X(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_5X(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_1Y(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_2Y(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_3Y(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_4Y(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegPoint_5Y(void *pMsg) +{ +} +static u_int16_t FRT_ReadRegLinearEnable(void *pMsg) +{ +} + /** * @brief 鍐欐崲鑳藉櫒鍙傛暟瀵勫瓨鍣ㄥ1R5 * @param @@ -544,6 +612,25 @@ static u_int16_t FRT_WriteRegRSSIRange(void *pMsg) return 0; } +static u_int16_t FRT_WriteRegPoint_1Y(void *pMsg) +{ +} +static u_int16_t FRT_WriteRegPoint_2Y(void *pMsg) +{ +} +static u_int16_t FRT_WriteRegPoint_3Y(void *pMsg) +{ +} +static u_int16_t FRT_WriteRegPoint_4Y(void *pMsg) +{ +} +static u_int16_t FRT_WriteRegPoint_5Y(void *pMsg) +{ +} +static u_int16_t FRT_WriteRegLinearEnable(void *pMsg) +{ +} + /** * @brief 灏佽鍗忚鍙戦 diff --git a/App/Src/inflash.c b/App/Src/inflash.c index 8386237..a2c6f51 100644 --- a/App/Src/inflash.c +++ b/App/Src/inflash.c @@ -10,7 +10,7 @@ * 65 * 无锡电声换能器参数 */ - +/* 默认参数 */ config_info g_stConfigInfo={ .flag_head = FLAG_SAVE_INFLASH_HEAD, .addr = 0x30, /* 默认地址 */ @@ -25,6 +25,18 @@ config_info g_stConfigInfo={ .transducer_cfg_4R5 = 35, /* 无锡电声换能器参数 */ .transducer_cfg_8R0 = 65, /* 无锡电声换能器参数 */ .RSSI_range = 20, /* RSSI大于0.2有效 */ + + .linear_point_1_x = 0, /* 线性插值点1 */ + .linear_point_1_y = 0, /* 线性插值点1 */ + .linear_point_2_x = 0, /* 线性插值点2 */ + .linear_point_2_y = 0, /* 线性插值点2 */ + .linear_point_3_x = 0, /* 线性插值点3 */ + .linear_point_3_y = 0, /* 线性插值点3 */ + .linear_point_4_x = 0, /* 线性插值点4 */ + .linear_point_4_y = 0, /* 线性插值点4 */ + .linear_point_5_x = 0, /* 线性插值点5 */ + .linear_point_5_y = 0, /* 线性插值点5 */ + .linear_enable = 0, /* 线性插值使能 */ .flag_end = FLAG_SAVE_INFLASH_END, };