fixed some small bugs

This commit is contained in:
Edward Emelianov 2023-05-23 16:03:45 +03:00
parent a7c53df2e7
commit c70ce5216a
5 changed files with 54 additions and 41 deletions

View File

@ -4,7 +4,7 @@ LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-a
LDFLAGS += -flto `pkg-config --libs usefull_macros` -lm
SRCS := $(wildcard *.c)
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
DEFINES += -DEBUG
#DEFINES += -DEBUG
OBJDIR := mk
CFLAGS += `pkg-config --cflags usefull_macros` -O3 -Wall -Werror -Wextra -Wno-trampolines -flto
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))

View File

@ -200,12 +200,18 @@ static int handle_socket(int sock){
format_t format = FORMAT_CURDFULL; // text format - default for web-queries
if(0 == strncmp(buff, "GET", 3)){
DBG("GET");
DBG("GET, buff=%s", buff);
// GET web query have format GET /some.resource
webquery = 1;
char *slash = strchr(buff, '/');
if(slash){
found = slash + 1;
if(strncmp(found, "stat", 4) == 0){
format = FORMAT_STATFULL;
double dt = getpar(found + 4);
if(dt < 1.) dt = 900.;
if(stat_for(dt, &wstat) < 1.) format = FORMAT_ERROR;
}
char *eol = strstr(found, "HTTP");
if(eol) *eol = 0;
}
@ -308,6 +314,7 @@ static void *weatherpolling(_U_ void *notused){
addtobuf(&w);
pthread_mutex_unlock(&mutex);
}
usleep(100000); // not more than 10 messages per second
}
return NULL;
}

View File

@ -77,13 +77,15 @@ double stat_for(double Tsec, weatherstat_t *wstat){
double dt = 0., tlast = buf[lastidx].tmeasure;
size_t startfrom = lastidx;
pthread_mutex_lock(&mutex);
if(tdiffmax <= Tsec) startfrom = firstidx; // use all data
else while(dt < Tsec && startfrom != firstidx){ // search from which index we should start
if(tdiffmax <= Tsec){ // use all data
startfrom = firstidx;
dt = tdiffmax;
}else while(dt < Tsec && startfrom != firstidx){ // search from which index we should start
if(startfrom == 0) startfrom = buflen - 1;
else --startfrom;
dt = tlast - buf[startfrom].tmeasure;
}
dt = tlast - buf[startfrom].tmeasure;
// DBG("got indexes: start=%zd, end=%zd, dt=%.2f", startfrom, lastidx, dt);
DBG("got indexes: start=%zd, end=%zd, dt=%.2f (dtiffmax=%.1f)", startfrom, lastidx, dt, tdiffmax);
weather_t min = {0}, max = {0}, sum = {0}, sum2 = {0};
size_t amount = 0;
memcpy(&min, &buf[lastidx], sizeof(weather_t));
@ -100,18 +102,20 @@ double stat_for(double Tsec, weatherstat_t *wstat){
else ++south;
if(++st == buflen) st = 0;
}
double wminus = 0.;
if(north > 2*south) wminus = 360.;
int minus = 0;
if(north > 2*south) minus = 1;
while(startfrom != lastidx){
weather_t *curw = &buf[startfrom];
#define CHK(field) do{register double d = curw->field; if(d > max.field) max.field = d; if(d < min.field) min.field = d; \
sum.field += d; sum2.field += d*d;}while(0)
CHK(windspeed);
register double s = curw->windspeed, sd = (curw->winddir - wminus) * s;
if(s > max.winddir) max.winddir = s;
if(s < min.winddir) min.winddir = s;
register double dir = curw->winddir, s = curw->windspeed;
if(minus && dir > 180.) dir -= 360.;
register double sd = dir * s; // weighted sum
if(dir > max.winddir) max.winddir = dir;
if(dir < min.winddir) min.winddir = dir;
sum.winddir += sd;
sum2.winddir += sd * s; // v * dir^2
sum2.winddir += sd * dir; // v * dir^2
CHK(pressure);
CHK(temperature);
CHK(humidity);

View File

@ -42,7 +42,6 @@ static const char *emultemplate = "0R0,S=1.9,D=217.2,P=787.7,T=10.8,H=69.0,R=31.
static char *read_string(){
//static int done = 0;
if(GP->emul){
usleep(100000);
strncpy(buf, emultemplate, BUFLEN);
return buf;
}
@ -55,14 +54,14 @@ static char *read_string(){
if((l = read_tty(ttydescr))){
strncpy(ptr, ttydescr->buf, LL);
r += l; LL -= l; ptr += l;
DBG("l=%zd, r=%zd, LL=%d", l, r, LL);
//DBG("l=%zd, r=%zd, LL=%d", l, r, LL);
d0 = dtime();
if(r > 2 && ptr[-1] == '\n') break;
}
}while(dtime() - d0 < WAIT_TMOUT && LL);
if(r){
//buf[r] = 0;
DBG("buf: %s", buf);
//DBG("buf: %s", buf);
return buf;
}
return NULL;

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.12.3, 2021-06-09T21:11:29. -->
<!-- Written by QtCreator 8.0.2, 2023-05-23T16:02:23. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -37,45 +37,57 @@
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">2</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
<valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">4</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{65a14f9e-e008-4c1b-89df-4eaa4774b6e3}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Big/Data/00__Small_tel/C-sources/netdaemon</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/10micron/C-sources/weatherdaemon_newmeteo</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
<value type="QString">all</value>
</valuelist>
<value type="bool" key="GenericProjectManager.GenericMakeStep.Clean">false</value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeArguments"></value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand"></value>
<value type="bool" key="GenericProjectManager.GenericMakeStep.OverrideMakeflags">false</value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
@ -89,10 +101,6 @@
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
<value type="QString">clean</value>
</valuelist>
<value type="bool" key="GenericProjectManager.GenericMakeStep.Clean">false</value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeArguments"></value>
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand"></value>
<value type="bool" key="GenericProjectManager.GenericMakeStep.OverrideMakeflags">false</value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
@ -103,6 +111,8 @@
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
@ -121,23 +131,16 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="QString" key="RunConfiguration.Arguments"></value>
<value type="bool" key="RunConfiguration.Arguments.multi">false</value>
<value type="QString" key="RunConfiguration.OverrideDebuggerStartup"></value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>