mirror of
https://github.com/eddyem/small_tel.git
synced 2026-06-19 10:26:25 +03:00
some fixes; added chkweather
This commit is contained in:
@@ -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,6 +28,9 @@ 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
|
||||
|
||||
|
||||
40
Daemons/weather_proxy/chkweather.c
Normal file
40
Daemons/weather_proxy/chkweather.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of the weather_proxy project.
|
||||
* Copyright 2026 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "weather_data.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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"
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user