diff --git a/Daemons/weather_proxy/Makefile b/Daemons/weather_proxy/Makefile index 5463b8f..a7d1b84 100644 --- a/Daemons/weather_proxy/Makefile +++ b/Daemons/weather_proxy/Makefile @@ -2,7 +2,7 @@ CC = gcc CFLAGS = -Wall -Wextra -fPIC -DEBUG LDFLAGS = -lrt -pthread -lusefull_macros -all: weather_daemon libweather.so weather_clt_example +all: weather_daemon libweather.so weather_clt_example chkweather weather_daemon: weather_daemon.o $(CC) -o $@ $^ $(LDFLAGS) @@ -10,6 +10,9 @@ weather_daemon: weather_daemon.o weather_clt_example: weather_clt_example.o $(CC) -o $@ $^ $(LDFLAGS) -l weather -L. +chkweather: chkweather.o + $(CC) -o $@ $^ $(LDFLAGS) -l weather -L. + weather_daemon.o: weather_daemon.c weather_data.h $(CC) $(CFLAGS) -c $< @@ -25,9 +28,12 @@ weather_client.o: weather_client.c weather_data.h weather_clt_example.o: weather_clt_example.c libweather.so $(CC) $(CFLAGS) -c $< +chkweather.o: chkweather.c libweather.so + $(CC) $(CFLAGS) -c $< + clean: rm -f *.o weather_daemon libweather.so libweather.a weather_clt_example install: cp libweather.so /usr/local/lib/ - cp weather_data.h /usr/local/include/ \ No newline at end of file + cp weather_data.h /usr/local/include/ diff --git a/Daemons/weather_proxy/chkweather.c b/Daemons/weather_proxy/chkweather.c new file mode 100644 index 0000000..0449b1f --- /dev/null +++ b/Daemons/weather_proxy/chkweather.c @@ -0,0 +1,40 @@ +/* + * This file is part of the weather_proxy project. + * Copyright 2026 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "weather_data.h" +#include + +int main() { + weather_data_t wd; + int errcode = 3; + if(get_weather_data(&wd) == 0){ + char strt[64]; + struct tm *T = localtime(&wd.last_update); + strftime(strt, 63, "%F %T", T); + printf("Windmax=%.1f\nRain=%d\nClouds=%.1f\nWind=%.1f\nExttemp=%.1f\n" + "Pres=%.1f\nHumid=%.1f\nMeteo=local\nForceOFF=%d\n", + wd.windmax, wd.rain, wd.clouds, wd.wind, wd.exttemp, + wd.pressure, wd.humidity, wd.forceoff); + if(!wd.forceoff) errcode = wd.weather; + }else{ + fprintf(stderr, "Failed to get weather data\n"); + } + return errcode; +} + +// echo -e "Rain=$Rain\nClouds=$Clouds\nWind=$Wind\nExttemp=$Exttemp\nPres=$Pres\nHumid=$Humid\nMeteo=$Meteo" diff --git a/Daemons/weather_proxy/weather_clt_example.c b/Daemons/weather_proxy/weather_clt_example.c index e2be913..2bf51b6 100644 --- a/Daemons/weather_proxy/weather_clt_example.c +++ b/Daemons/weather_proxy/weather_clt_example.c @@ -25,8 +25,8 @@ int main() { char strt[64]; struct tm *T = localtime(&wd.last_update); strftime(strt, 63, "%F %T", T); - printf("Prohibited: %d\nWeather: %d\nMax wind: %.1f\nWind: %.1f\nTemp: %.1f\nPressure: %.1f\nHumidity: %.1f\nupdated @%zd (%s)\n", - wd.prohibited, wd.weather, wd.windmax, wd.wind, wd.exttemp, wd.pressure, wd.humidity, + printf("ForceOFF: %d\nWeather: %d\nMax wind: %.1f\nWind: %.1f\nTemp: %.1f\nPressure: %.1f\nHumidity: %.1f\nupdated @%zd (%s)\n", + wd.forceoff, wd.weather, wd.windmax, wd.wind, wd.exttemp, wd.pressure, wd.humidity, wd.last_update, strt); }else{ fprintf(stderr, "Failed to get weather data\n"); diff --git a/Daemons/weather_proxy/weather_daemon.c b/Daemons/weather_proxy/weather_daemon.c index 629b986..94cd996 100644 --- a/Daemons/weather_proxy/weather_daemon.c +++ b/Daemons/weather_proxy/weather_daemon.c @@ -165,7 +165,7 @@ static void FITS_update(const char *line, int finish){ static FILE *tmp = NULL; static char templ[32]; // temporary file name if(!tmp){ // try to create new temporary file - sprintf(templ, "/tmp/fitshdrXXXXXX"); + sprintf(templ, "%sXXXXXX", G.fitsheader); int fd = mkstemp(templ); if(fd < 0){ WARN("mkstemp()"); @@ -232,16 +232,15 @@ static void parse_line(const char *line, weather_data_t *data) { }else if (strcmp(key, "HUMIDITY") == 0){ data->humidity = atof(value); printf("got humidity: %g\n", data->humidity); - }else if (strcmp(key, "PROHIBIT") == 0){ - data->prohibited = atoi(value); - }else if (strcmp(key, "TMEAS") == 0){ // last line in message -> update + }else if (strcmp(key, "FORCEOFF") == 0){ + data->forceoff = atoi(value); + }else if (strcmp(key, "TWEATH") == 0){ // last line in message -> update data->last_update = atof(value); - if(data->weather == WEATHER_PROHIBITED || forbidden) data->prohibited = 1; - else if(data->weather < WEATHER_PROHIBITED) data->prohibited = 0; + if(forbidden) data->weather = WEATHER_PROHIBITED; // update all update_shm(data); update = 1; - }else update = -1; + }//else update = -1; if(update > -1 && G.fitsheader){ FITS_update(line, update); } diff --git a/Daemons/weather_proxy/weather_data.h b/Daemons/weather_proxy/weather_data.h index 87e0875..df8ec16 100644 --- a/Daemons/weather_proxy/weather_data.h +++ b/Daemons/weather_proxy/weather_data.h @@ -7,10 +7,10 @@ #define SEM_NAME "/weather_sem" typedef enum { - WEATHER_GOOD = 0, // may start observations - WEATHER_BAD = 1, // cannot start but can continue if want - WEATHER_TERRIBLE = 2, // close & park: wind, precipitation, humidity etc. - WEATHER_PROHIBITED = 3, // force closing & parking; power off equipment, ready to power off computer + WEATHER_GOOD = 0, // may start observations + WEATHER_BAD = 1, // cannot start but can continue if want + WEATHER_TERRIBLE = 2, // close & park: wind, precipitation, humidity etc. + WEATHER_PROHIBITED = 3, // force closing & parking; power off equipment, ready to power off computer } weather_condition_t; typedef struct { @@ -22,7 +22,7 @@ typedef struct { float pressure; // atm. pressure, mmHg: "PRESSURE" float humidity; // humidity, percents: "HUMIDITY" int rain; // ==1 when rainy: "PRECIP" - int prohibited; // ==1 if "weather == prohibited" or got `prohibited` signal -> ready to power off + int forceoff; // force power off (AC power lost or lightning) time_t last_update; // value of "TMEAS" } weather_data_t;