g0b1vetx-board/Application/simuflow.c
2584532475@qq.com 0f40dd8b17 网络自适应
2024-09-10 11:51:07 +08:00

177 lines
5.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "data.h"
#include "math.h"
#include "easyflash.h"
#include "stdlib.h"
#include "cjson.h"
#include "rtthread.h"
#include "user_config.h"
#if !defined(LOG_TAG)
#define LOG_TAG "simu"
#endif
#include <elog.h>
static const ParShallInfo_t ParShallTale[] =
{
{.w = 0, .c = 0, .m = 0},
{.w = 0.152, .c = 0.381, .m = 1.58 , .minLeve = 0.03, .maxLeve = 0.45, .minFlow = 1.5 / 1000, .maxFlow = 100 / 1000},
{.w = 0.25, .c = 0.561, .m = 1.513 , .minLeve = 0.03, .maxLeve = 0.60, .minFlow = 3.0 / 1000, .maxFlow = 250 / 1000},
{.w = 0.30, .c = 0.679, .m = 1.521 , .minLeve = 0.03, .maxLeve = 0.75, .minFlow = 3.5 / 1000, .maxFlow = 400 / 1000},
{.w = 0.45, .c = 1.038, .m = 1.537 , .minLeve = 0.03, .maxLeve = 0.75, .minFlow = 4.5 / 1000, .maxFlow = 630 / 1000},
{.w = 0.60, .c = 1.403, .m = 1.548 , .minLeve = 0.05, .maxLeve = 0.75, .minFlow = 12.5 / 1000, .maxFlow = 850 / 1000},
{.w = 0.75, .c = 1.772, .m = 1.557 , .minLeve = 0.06, .maxLeve = 0.75, .minFlow = 25.0 / 1000, .maxFlow = 1100 / 1000},
{.w = 0.90, .c = 2.147, .m = 1.565 , .minLeve = 0.06, .maxLeve = 0.75, .minFlow = 30.0 / 1000, .maxFlow = 1250 / 1000},
{.w = 1.00, .c = 2.397, .m = 1.569 , .minLeve = 0.06, .maxLeve = 0.80, .minFlow = 30.0 / 1000, .maxFlow = 1500 / 1000},
{.w = 1.20, .c = 2.904, .m = 1.577 , .minLeve = 0.06, .maxLeve = 0.80, .minFlow = 35.0 / 1000, .maxFlow = 2000 / 1000},
{.w = 1.50, .c = 3.668, .m = 1.586 , .minLeve = 0.06, .maxLeve = 0.80, .minFlow = 45.0 / 1000, .maxFlow = 2500 / 1000},
{.w = 1.80, .c = 4.440, .m = 1.593 , .minLeve = 0.08, .maxLeve = 0.80, .minFlow = 80.0 / 1000, .maxFlow = 3000 / 1000},
{.w = 2.10, .c = 5.222, .m = 1.599 , .minLeve = 0.08, .maxLeve = 0.80, .minFlow = 95.0 / 1000, .maxFlow = 3600 / 1000},
{.w = 2.40, .c = 6.004, .m = 1.605 , .minLeve = 0.08, .maxLeve = 0.80, .minFlow = 100.0 / 1000,.maxFlow = 4000 / 1000},
{.w = 3.05, .c = 7.463, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.07, .minFlow = 0.16, .maxFlow = 8.28},
{.w = 3.66, .c = 8.859, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.37, .minFlow = 0.19, .maxFlow = 14.68},
{.w = 4.57, .c = 10.96, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.67, .minFlow = 0.23, .maxFlow = 25.04},
{.w = 6.10, .c = 14.45, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.83, .minFlow = 0.31, .maxFlow = 37.97},
{.w = 7.62, .c = 17.94, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.83, .minFlow = 0.38, .maxFlow = 47.16},
{.w = 9.14, .c = 21.44, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.83, .minFlow = 0.46, .maxFlow = 56.33},
{.w = 12.19, .c = 28.43, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.83, .minFlow = 0.60, .maxFlow = 74.70},
{.w = 15.24, .c = 35.41, .m = 1.6 , .minLeve = 0.09, .maxLeve = 1.83, .minFlow = 0.75, .maxFlow = 93.04},
} ;
// <20><><EFBFBD><EFBFBD><E3B7A8><EFBFBD><EFBFBD>k<EFBFBD><6B>b
double math_k(double x0,double y0,double x1,double y1)
{
double k;
k = (y1-y0)/(x1-x0);
return k;
}
double math_b(double k,double x,double y)
{
double b;
b = y - (k*x);
return b;
}
//WaterLeveInfo_t Info = {
// .Y[0] = 2,
//};
// k=(y2-y1)/(x2-x1)
typedef struct SimflowPara_t
{
double leve[11];
double flow[11];
int pallid ;
}SimflowPara_t;
// ˮλ<CBAE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
static SimflowPara_t g_para = {
.leve = {0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1},
.flow = {0,0.036,0.105,0.200,0.317,0.454,0.713,0.897,0.955,1.015,1.025},
.pallid = 7
};
// ˮλ<CBAE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
void SimuFlowInit(void)
{
char *p ;
p = ef_get_env ("parshall");
g_para.pallid = atoi (p); // <20><>Ъ<EFBFBD><D0AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋۺ<C6B2>
rt_kprintf("parshall:%d\r\n",g_para.pallid);
#ifdef SYK_06_18_SM
ef_set_env ("simu_flow","1");
ef_set_env("level","[0.1,0.18,0.26,0.34,0.42,0.5,0.58,0.66,0.74,0.8]");
ef_set_env("flow","[0.031,0.081,0.149,0.233,0.33,0.44,0.562,0.695,0.84,0.955]");
#endif
#ifdef SYK_08_18_SM
ef_set_env ("simu_flow","1");
ef_set_env("level","[0.1,0.18,0.26,0.34,0.42,0.5,0.58,0.66,0.74,0.8]");
ef_set_env("flow","[0.043,0.113,0.206,0.32,0.453,0.603,0.769,0.951,1.147,1.304]");
#endif
#ifdef SYK_10_18_SM
ef_set_env ("simu_flow","1");
ef_set_env("level","[0.1,0.18,0.26,0.34,0.42,0.5,0.58,0.66,0.74,0.8]");
ef_set_env("flow","[0.058,0.146,0.261,0.397,0.553,0.728,0.918,1.125,1.346,1.522]");
#endif
cJSON *root = NULL;
// ˮλ<CBAE><CEBB>
p = ef_get_env ("level") ;
root = cJSON_Parse (p);
int size = cJSON_GetArraySize (root);
if(size != 10)
{
cJSON_Delete (root);
return ;
}
for (int i = 1; i < 11; i++)
{
g_para.leve[i] = cJSON_GetNumberValue (cJSON_GetArrayItem (root, i-1)); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
p = ef_get_env ("flow") ;
root = cJSON_Parse (p);
size = cJSON_GetArraySize (root);
if(size != 10)
{
cJSON_Delete (root);
return ;
}
for (int i = 1; i < 11; i++)
{
g_para.flow[i] = cJSON_GetNumberValue (cJSON_GetArrayItem (root, i-1)); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
}
cJSON_Delete (root);
rt_kprintf("leve( mm):");
for (int i =0; i< 11;i++)
{
rt_kprintf("%6d,",(int)(g_para.leve[i] * 1000));
}
rt_kprintf("\r\nflow(dm3):");
for (int i =0; i< 11;i++)
{
rt_kprintf("%6d,",(int)(g_para.flow[i]*1000));
}
rt_kprintf("\r\n");
}
// ˮλ<CBAE><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5> <20><>λcm
int32_t WaterLeveCalc(double leve)
{
double k,b;
double flow;
if((leve == 0) ||(leve >= g_para.leve[10]) )
return 0;
for (int i =0;i< 11;i++)
{
if (leve < g_para.leve[i])
{
k = math_k((double)g_para.leve[i-1],(double)g_para.flow[i-1],(double)g_para.leve[i],(double)g_para.flow[i]) ;
b = math_b(k,(double)g_para.leve[i],(double)g_para.flow[i]);
flow = k *leve +b;
break;
}
}
return (int32_t )(flow *1000);
}
int32_t ParShallCalc(double leve)
{
char * p;
double flow = 0;
flow = ParShallTale[g_para.pallid].c * pow(leve,ParShallTale[g_para.pallid].m);
return (int32_t )(flow *1000);
}