add new meteostation support

This commit is contained in:
Edward Emelianov 2023-05-22 17:31:13 +03:00
parent f07d63c970
commit 61acba7e17
19 changed files with 1336 additions and 0 deletions

View File

@ -0,0 +1,42 @@
# run `make DEF=...` to add extra defines
PROGRAM := weatherdaemon
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all -pthread
LDFLAGS += -flto `pkg-config --libs usefull_macros` -lm
SRCS := $(wildcard *.c)
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
#DEFINES += -DEBUG
OBJDIR := mk
CFLAGS += `pkg-config --cflags usefull_macros` -O3 -Wall -Werror -Wextra -Wno-trampolines -flto
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
DEPS := $(OBJS:.o=.d)
CC = gcc
all : $(OBJDIR) $(PROGRAM)
$(PROGRAM) : $(OBJS)
@echo -e "\t\tLD $(PROGRAM)"
$(CC) $(OBJS) $(LDFLAGS) -o $(PROGRAM)
$(OBJDIR):
mkdir $(OBJDIR)
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
$(OBJDIR)/%.o: %.c
@echo -e "\t\tCC $<"
$(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $<
clean:
@echo -e "\t\tCLEAN"
@rm -f $(OBJS) $(DEPS)
@rmdir $(OBJDIR) 2>/dev/null || true
xclean: clean
@rm -f $(PROGRAM)
gentags:
CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null
.PHONY: gentags clean xclean

View File

@ -0,0 +1,22 @@
Weather daemon
==================
Weather daemon for new meteostation.
Open a socket at given port (default: 12345)
Parse weather data and send it to client
```
Usage: weatherdaemon [args]
Where args are:
-P, --pidfile=arg pidfile name (default: /tmp/weatherdaemon.pid)
-b, --baudrate=arg serial terminal baudrate (default: 9600)
-d, --device=arg serial device name (default: none)
-e, --emulation emulate serial device
-h, --help show this help
-l, --logfile=arg save logs to file (default: none)
-p, --port=arg network port to connect (default: 12345)
-v, --verb logfile verbocity level (each -v increase it)
```

View File

@ -0,0 +1,92 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2021 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 <assert.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <math.h>
#include <usefull_macros.h>
#include "cmdlnopts.h"
/*
* here are global parameters initialisation
*/
int help;
static glob_pars G;
// default values for Gdefault & help
#define DEFAULT_PORT "12345"
#define DEFAULT_PID "/tmp/weatherdaemon.pid"
// DEFAULTS
// default global parameters
glob_pars const Gdefault = {
.device = NULL,
.port = DEFAULT_PORT,
.logfile = NULL,
.verb = 0,
.tty_speed = 9600,
.rest_pars = NULL,
.rest_pars_num = 0,
.emul = 0,
.pidfile = DEFAULT_PID
};
/*
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
myoption cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"device", NEED_ARG, NULL, 'd', arg_string, APTR(&G.device), _("serial device name (default: none)")},
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("network port to connect (default: " DEFAULT_PORT ")")},
{"logfile", NEED_ARG, NULL, 'l', arg_string, APTR(&G.logfile), _("save logs to file (default: none)")},
{"verb", NO_ARGS, NULL, 'v', arg_none, APTR(&G.verb), _("logfile verbocity level (each -v increase it)")},
{"baudrate",NEED_ARG, NULL, 'b', arg_int, APTR(&G.tty_speed), _("serial terminal baudrate (default: 9600)")},
{"emulation",NO_ARGS, NULL, 'e', arg_int, APTR(&G.emul), _("emulate serial device")},
{"pidfile", NEED_ARG, NULL, 'P', arg_string, APTR(&G.pidfile), _("pidfile name (default: " DEFAULT_PID ")")},
end_option
};
/**
* Parse command line options and return dynamically allocated structure
* to global parameters
* @param argc - copy of argc from main
* @param argv - copy of argv from main
* @return allocated structure with global parameters
*/
glob_pars *parse_args(int argc, char **argv){
int i;
void *ptr;
ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
// format of help: "Usage: progname [args]\n"
change_helpstring("Usage: %s [args]\n\n\tWhere args are:\n");
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
if(argc > 0){
G.rest_pars_num = argc;
G.rest_pars = calloc(argc, sizeof(char*));
for (i = 0; i < argc; i++)
G.rest_pars[i] = strdup(argv[i]);
}
return &G;
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2021 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/>.
*/
#pragma once
#ifndef __CMDLNOPTS_H__
#define __CMDLNOPTS_H__
/*
* here are some typedef's for global data
*/
typedef struct{
char *device; // serial device name
char *port; // port to connect
char *logfile; // logfile name
int terminal; // run as terminal
int echo; // echo user commands back
int verb; // verbocity level
int tty_speed; // serial terminal baudrate
int emul; // emulation of serial device
char *pidfile; // pidfile name
int rest_pars_num; // number of rest parameters
char** rest_pars; // the rest parameters: array of char* (path to logfile and thrash)
} glob_pars;
glob_pars *parse_args(int argc, char **argv);
#endif // __CMDLNOPTS_H__

View File

@ -0,0 +1,88 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2021 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 <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h> // wait
#include <sys/prctl.h> //prctl
#include <usefull_macros.h>
#include "cmdlnopts.h"
#include "socket.h"
#include "term.h"
glob_pars *GP;
void signals(int signo){
restore_console();
stop_tty();
LOGERR("exit with status %d", signo);
exit(signo);
}
int main(int argc, char **argv){
initial_setup();
signal(SIGTERM, signals); // kill (-15) - quit
signal(SIGHUP, SIG_IGN); // hup - ignore
signal(SIGINT, signals); // ctrl+C - quit
signal(SIGQUIT, signals); // ctrl+\ - quit
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
#ifndef EBUG
char *self = strdup(argv[0]);
#endif
GP = parse_args(argc, argv);
if(GP->logfile){
sl_loglevel lvl = LOGLEVEL_ERR;
for(; GP->verb && lvl < LOGLEVEL_ANY; --GP->verb) ++lvl;
DBG("Loglevel: %d", lvl);
if(!OPENLOG(GP->logfile, lvl, 1)) ERRX("Can't open log file");
LOGERR("Started");
}
#ifndef EBUG
if(daemon(1, 0)){
ERR("daemon()");
}
check4running(self, GP->pidfile);
while(1){ // guard for dead processes
pid_t childpid = fork();
if(childpid){
LOGDBG("create child with PID %d\n", childpid);
DBG("Created child with PID %d\n", childpid);
wait(NULL);
WARNX("Child %d died\n", childpid);
LOGWARN("Child %d died\n", childpid);
sleep(1);
}else{
prctl(PR_SET_PDEATHSIG, SIGTERM); // send SIGTERM to child when parent dies
break; // go out to normal functional
}
}
#endif
if(GP->device) if(!try_connect(GP->device, GP->tty_speed)){
LOGERR("Can't connect to device");
ERRX("Can't connect to device");
}
if(!GP->device && !GP->emul){
LOGERR("Need serial device name or emulation flag");
ERRX("Need serial device name or emulation flag");
}
daemonize(GP->port);
return 0;
}

View File

@ -0,0 +1,340 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2021 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 <netdb.h> // addrinfo
#include <arpa/inet.h> // inet_ntop
#include <limits.h> // INT_xxx
#include <poll.h> // poll
#include <pthread.h>
#include <signal.h> // pthread_kill
#include <stdio.h>
#include <string.h>
#include <sys/syscall.h> // syscall
#include <unistd.h> // daemon
#include <usefull_macros.h>
#include "cmdlnopts.h" // glob_pars
#include "socket.h"
#include "stat.h"
#include "term.h"
// temporary buffers
#define BUFLEN (1024)
// Max amount of connections
#define BACKLOG (30)
extern glob_pars *GP;
static weather_t lastweather = {0};
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
/**************** SERVER FUNCTIONS ****************/
/**
* Send data over socket
* @param sock - socket fd
* @param webquery - ==1 if this is web query
* @param format - 1 - full (param=value), 0 - simple (comma-separated)
* @return 1 if all OK
*/
static int send_data(int sock, int webquery, int format){
char tbuf[BUFSIZ]; // buffer to send
char databuf[BUFSIZ]; // buffer with data
ssize_t Len = 0;
const char *eol = webquery ? "\r\n" : "\n";
// fill buffer with data
pthread_mutex_lock(&mutex);
if(format){ // full format
Len = snprintf(databuf, BUFSIZ,
"Wind=%.1f%sDir=%.1f%sPressure=%.1f%sTemperature=%.1f%sHumidity=%.1f%s"
"Rain=%.1f%sTime=%.3f%s",
lastweather.windspeed, eol, lastweather.winddir, eol, lastweather.pressure, eol,
lastweather.temperature, eol, lastweather.humidity, eol, lastweather.rainfall, eol,
lastweather.tmeasure, eol
);
}else{ // short format
Len = snprintf(databuf, BUFSIZ,
"%.3f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f%s",
lastweather.tmeasure, lastweather.windspeed, lastweather.winddir,
lastweather.pressure, lastweather.temperature, lastweather.humidity,
lastweather.rainfall, eol
);
}
pthread_mutex_unlock(&mutex);
// OK buffer ready, prepare to send it
if(webquery){
ssize_t L = snprintf(tbuf, BUFSIZ,
"HTTP/2.0 200 OK\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Methods: GET, POST\r\n"
"Access-Control-Allow-Credentials: true\r\n"
"Content-type: text/plain\r\nContent-Length: %zd\r\n\r\n", Len);
if(L < 0){
WARN("sprintf()");
LOGWARN("sprintf()");
return 0;
}
if(L != write(sock, tbuf, L)){
LOGWARN("Can't write header");
WARN("write");
return 0;
}
}
if(Len != write(sock, databuf, Len)){
WARN("write()");
LOGERR("send_data(): write() failed");
return 0;
}
//LOGDBG("fd %d, write %s", sock, textbuf);
return 1;
}
// search a first word after needle without spaces
static char* stringscan(char *str, char *needle){
char *a;//, *e;
char *end = str + strlen(str);
a = strstr(str, needle);
if(!a) return NULL;
a += strlen(needle);
while (a < end && (*a == ' ' || *a == '\r' || *a == '\t' || *a == '\r')) a++;
if(a >= end) return NULL;
return a;
}
/**
* @brief handle_socket - read information from socket
* @param sock - socket fd
* @param chkheader - ==1 on first run
* @return 1 if socket closed
*/
static int handle_socket(int sock){
FNAME();
int webquery = 0; // whether query is web or regular
char buff[BUFLEN];
ssize_t rd;
if(!(rd = read(sock, buff, BUFLEN-1))){
//LOGMSG("Client %d closed", sock);
return 1;
}
//LOG("client send %zd bytes", rd);
DBG("Got %zd bytes", rd);
if(rd <= 0){ // error
LOGWARN("Client %d close socket on error", sock);
DBG("Nothing to read from fd %d (ret: %zd)", sock, rd);
return 1;
}
// add trailing zero to be on the safe side
buff[rd] = 0;
// now we should check what do user want
char *found = buff;
DBG("user send: %s", buff);
int format = 1; // text format - default for web-queries
if(0 == strncmp(buff, "GET", 3)){
DBG("GET");
// GET web query have format GET /some.resource
webquery = 1;
char *slash = strchr(buff, '/');
if(slash){
found = slash + 1;
char *eol = strstr(found, "HTTP");
if(eol) *eol = 0;
}
}else if(0 == strncmp(buff, "POST", 4)){
DBG("POST");
webquery = 1;
// search content length of POST query
char *cl = stringscan(buff, "Content-Length:");
if(cl){
int contlen = atoi(cl);
int l = strlen(buff);
if(contlen && l > contlen) found = &buff[l - contlen];
}
}else if(0 == strncmp(buff, "simple", 6)) format = 0; // simple format
else if(0 == strncmp(buff, "stat", 4)){ // show stat
stat_for(90.);
return 0;
}
// here we can process user data
DBG("found=%s", found);
LOGDBG("sockfd=%d, got %s", sock, buff);
DBG("format=%d", format);
send_data(sock, webquery, format);
if(webquery) return 1; // close web query after message processing
return 0;
}
// main socket server
static void *server(void *asock){
LOGMSG("server()");
int sock = *((int*)asock);
if(listen(sock, BACKLOG) == -1){
LOGERR("listen() failed");
WARN("listen");
return NULL;
}
int nfd = 1; // current fd amount in poll_set
struct pollfd poll_set[MAX_FDS];
memset(poll_set, 0, sizeof(poll_set));
poll_set[0].fd = sock;
poll_set[0].events = POLLIN;
while(1){
poll(poll_set, nfd, 1); // poll for 1ms
for(int fdidx = 0; fdidx < nfd; ++fdidx){ // poll opened FDs
if((poll_set[fdidx].revents & POLLIN) == 0) continue;
poll_set[fdidx].revents = 0;
if(fdidx){ // client
int fd = poll_set[fdidx].fd;
if(handle_socket(fd)){ // socket closed - remove it from list
close(fd);
DBG("Client with fd %d closed", fd);
LOGMSG("Client %d disconnected", fd);
// move last to free space
poll_set[fdidx] = poll_set[nfd - 1];
--nfd;
}
}else{ // server
socklen_t size = sizeof(struct sockaddr_in);
struct sockaddr_in their_addr;
int newsock = accept(sock, (struct sockaddr*)&their_addr, &size);
if(newsock <= 0){
LOGERR("server(): accept() failed");
WARN("accept()");
continue;
}
struct in_addr ipAddr = their_addr.sin_addr;
char str[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &ipAddr, str, INET_ADDRSTRLEN);
DBG("Connection from %s, give fd=%d", str, newsock);
LOGMSG("Got connection from %s, fd=%d", str, newsock);
if(nfd == MAX_FDS){
LOGWARN("Max amount of connections: disconnect %s (%d)", str, newsock);
int _U_ x = write(newsock, "Max amount of connections reached!\n", 35);
WARNX("Limit of connections reached");
close(newsock);
}else{
memset(&poll_set[nfd], 0, sizeof(struct pollfd));
poll_set[nfd].fd = newsock;
poll_set[nfd].events = POLLIN;
++nfd;
}
}
} // endfor
} // endwhile(1)
LOGERR("server(): UNREACHABLE CODE REACHED!");
}
// poll last weather data
static void *weatherpolling(_U_ void *notused){
while(1){
weather_t w;
if(getlastweather(&w) && 0 == pthread_mutex_lock(&mutex)){
memcpy(&lastweather, &w, sizeof(weather_t));
addtobuf(&w);
pthread_mutex_unlock(&mutex);
}
}
return NULL;
}
// data gathering & socket management
static void daemon_(int sock){
if(sock < 0) return;
pthread_t sock_thread, parser_thread;
if(pthread_create(&sock_thread, NULL, server, (void*) &sock)){
LOGERR("daemon_(): pthread_create(sock_thread) failed");
ERR("pthread_create()");
}
if(pthread_create(&parser_thread, NULL, weatherpolling, NULL)){
LOGERR("daemon_(): pthread_create(parser_thread) failed");
ERR("pthread_create()");
}
do{
if(pthread_kill(sock_thread, 0) == ESRCH){ // died
WARNX("Sockets thread died");
LOGWARN("Sockets thread died");
pthread_join(sock_thread, NULL);
if(pthread_create(&sock_thread, NULL, server, (void*) &sock)){
LOGERR("daemon_(): new pthread_create() failed");
ERR("pthread_create()");
}
}
if(pthread_kill(parser_thread, 0) == ESRCH){ // died
WARNX("TTY thread died");
LOGWARN("TTY thread died");
pthread_join(parser_thread, NULL);
if(pthread_create(&parser_thread, NULL, weatherpolling, NULL)){
LOGERR("daemon_(): new pthread_create(parser_thread) failed");
ERR("pthread_create()");
}
}
usleep(1000); // sleep a little
}while(1);
LOGERR("daemon_(): UNREACHABLE CODE REACHED!");
}
/**
* Run daemon service
*/
void daemonize(char *port){
FNAME();
int sock = -1;
struct addrinfo hints, *res, *p;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
// To accept only local sockets replace NULL with "127.0.0.1" and remove AI_PASSIVE
if(getaddrinfo(NULL, port, &hints, &res) != 0){
LOGERR("getaddrinfo");
ERR("getaddrinfo");
}
struct sockaddr_in *ia = (struct sockaddr_in*)res->ai_addr;
char str[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(ia->sin_addr), str, INET_ADDRSTRLEN);
// loop through all the results and bind to the first we can
for(p = res; p != NULL; p = p->ai_next){
if((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1){
WARN("socket");
continue;
}
int reuseaddr = 1;
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)) == -1){
LOGERR("setsockopt() error");
ERR("setsockopt");
}
if(bind(sock, p->ai_addr, p->ai_addrlen) == -1){
close(sock);
WARN("bind");
LOGWARN("bind() error");
continue;
}
break; // if we get here, we have a successfull connection
}
if(p == NULL){
LOGERR("daemonize(): failed to bind socket, exit");
// looped off the end of the list with no successful bind
ERRX("failed to bind socket");
}
freeaddrinfo(res);
daemon_(sock);
close(sock);
LOGERR("daemonize(): UNREACHABLE CODE REACHED!");
signals(0);
}

View File

@ -0,0 +1,32 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2021 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/>.
*/
#pragma once
#ifndef __SOCKET_H__
#define __SOCKET_H__
// time interval for data polling (seconds)
#define T_INTERVAL (10.)
// max amount of opened fd (+1 for server socket)
#define MAX_FDS (11)
// no data timeout
#define NODATA_TMOUT (90.)
void daemonize(char *port);
#endif // __SOCKET_H__

View File

@ -0,0 +1,105 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2023 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 <math.h>
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <usefull_macros.h>
#include "stat.h"
// add BUFSZ_INCR records to buffer each time when no free space left
#define BUFSZ_INCR (2048)
static weather_t *buf = NULL;
// current size of `buf`
static size_t buflen = 0;
// indexes of first and last element in buffer
static size_t firstidx = 0, lastidx = 0;
// maximal current time delta between last and first items of `buf`
static double tdiffmax = 0.;
// mutex for working with buffer
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
double get_tmax(){
return tdiffmax;
}
// add new record to buffer
void addtobuf(weather_t *record){
if(!record) return;
pthread_mutex_lock(&mutex);
if(!buf){ // first run
buf = MALLOC(weather_t, BUFSZ_INCR);
buflen = BUFSZ_INCR;
memcpy(&buf[0], record, sizeof(weather_t));
//DBG("init buff to %zd", buflen);
pthread_mutex_unlock(&mutex);
return;
}
if(++lastidx == buflen){ // end of buffer reached: decide wether to increase buffer or not
if(tdiffmax < STATMAXT){
buflen += BUFSZ_INCR;
buf = realloc(buf, sizeof(weather_t)*buflen);
DBG("realloc buf to %zd", buflen);
}else lastidx = 0;
}
if(lastidx == firstidx){
if(++firstidx == buflen) firstidx = 0;
}
memcpy(&buf[lastidx], record, sizeof(weather_t));
tdiffmax = buf[lastidx].tmeasure - buf[firstidx].tmeasure;
//DBG("add record, last=%zd, first=%zd, dT=%.3f", lastidx, firstidx, tdiffmax);
pthread_mutex_unlock(&mutex);
}
// get statistics for last `Tsec` seconds; @return real dT for given interval
double stat_for(double Tsec/*, weather_t *w*/){
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(startfrom == 0) startfrom = buflen - 1;
else --startfrom;
}
dt = tlast - buf[startfrom].tmeasure;
DBG("got indexes: start=%zd, end=%zd, dt=%.2f", startfrom, lastidx, dt);
weather_t min = {0}, max = {0}, sum = {0}, sum2 = {0};
size_t amount = 0;
memcpy(&min, &buf[lastidx], sizeof(weather_t));
while(startfrom != lastidx){
weather_t *curw = &buf[startfrom];
#define CHK(field) do{register double d = curw->field; if(d > max.field) max.field = d; else if(d < min.field) min.field = d; \
sum.field += d; sum2.field += d*d;}while(0)
CHK(windspeed);
CHK(pressure);
CHK(temperature);
CHK(humidity);
CHK(rainfall);
++amount;
if(++startfrom == buflen) startfrom = 0;
}
DBG("Got %zd records", amount);
double wmean = sum.windspeed/amount;
DBG("wind min/max/mean/rms=%.1f/%.1f/%.1f/%.1f", min.windspeed, max.windspeed,
wmean, sqrt(sum2.windspeed/amount - wmean*wmean));
pthread_mutex_unlock(&mutex);
return dt;
}

View File

@ -0,0 +1,28 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2023 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/>.
*/
#pragma once
#include "term.h"
// maximal time difference for records in statbuf - one hour
#define STATMAXT (3600.)
double stat_for(double Tsec/*, weather_t *w*/);
void addtobuf(weather_t *record);
double get_tmax();

View File

@ -0,0 +1,156 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2021 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 <ctype.h> // isspace
#include <stdio.h>
#include <string.h>
#include <strings.h> // strncasecmp
#include <time.h> // time(NULL)
#include <limits.h> // INT_MAX, INT_MIN
#include <pthread.h>
#include "cmdlnopts.h"
#include "term.h"
#define BUFLEN (4096)
static TTY_descr *ttydescr = NULL;
extern glob_pars *GP;
static char buf[BUFLEN];
static const char *emultemplate = "0R0,S=1.9,D=217.2,P=787.7,T=10.8,H=69.0,R=31.0,Ri=0.0,Rs=Y";
/**
* read strings from terminal (ending with '\n') with timeout
* @return NULL if nothing was read or pointer to static buffer
*/
static char *read_string(){
//static int done = 0;
if(GP->emul){
usleep(100000);
strncpy(buf, emultemplate, BUFLEN);
return buf;
}
if(!ttydescr) ERRX("Serial device not initialized");
size_t r = 0, l;
int LL = BUFLEN - 1;
char *ptr = buf;
double d0 = dtime();
do{
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);
d0 = dtime();
if(r > 2 && ptr[-1] == '\n') break;
}
}while(dtime() - d0 < WAIT_TMOUT && LL);
if(r){
//buf[r] = 0;
DBG("buf: %s", buf);
return buf;
}
return NULL;
}
/**
* Try to connect to `device` at baudrate speed
* @return 1 if OK
*/
int try_connect(char *device, int baudrate){
if(!device) return 0;
fflush(stdout);
ttydescr = new_tty(device, baudrate, 1024);
if(ttydescr) ttydescr = tty_open(ttydescr, 1); // exclusive open
if(!ttydescr) return 0;
while(read_tty(ttydescr)); // clear rbuf
LOGMSG("Connected to %s", device);
return 1;
}
// stop polling thread and close tty
void stop_tty(){
if(ttydescr) close_tty(&ttydescr);
}
static weather_t lastweather;
typedef struct{
const char *parname;
int parlen;
double *weatherpar;
} wpair_t;
static const wpair_t wpairs[] = {
{"S=", 2, &lastweather.windspeed},
{"D=", 2, &lastweather.winddir},
{"P=", 2, &lastweather.pressure},
{"T=", 2, &lastweather.temperature},
{"H=", 2, &lastweather.humidity},
{"R=", 2, &lastweather.rainfall},
{NULL, 0, NULL}
};
static int parseans(char *str, weather_t *w){
if(strncmp(str, "0R0,", 4)){
WARNX("Wrong answer");
LOGWARN("poll_device() get wrong answer: %s", str);
return FALSE;
}
str += 3;
do{
++str;
//DBG("start=%s", str);
const wpair_t *el = wpairs;
while(el->parname){
if(strncmp(str, el->parname, el->parlen) == 0){ // found next parameter
str += el->parlen;
char *endptr;
*el->weatherpar = strtod(str, &endptr);
//DBG("found par: %s, val=%g", el->parname, *el->weatherpar);
if(endptr == str){
DBG("Wrong double value");
return FALSE;
}
break;
}
++el;
}
str = strchr(str, ',');
//DBG("next=%s", str);
}while(str && *str);
lastweather.tmeasure = dtime();
if(w) memcpy(w, &lastweather, sizeof(weather_t));
return TRUE;
}
// get weather measurements; return FALSE if something failed
int getlastweather(weather_t *w){
if(!GP->emul){
if(write_tty(ttydescr->comfd, "!0R0\r\n", 6))
return FALSE;
}
double t0 = dtime();
while(dtime() - t0 < T_POLLING_TMOUT){
char *r = NULL;
if((r = read_string())){ // parse new data
//DBG("got %s", r);
if(parseans(r, w)) return TRUE;
}
}
return FALSE;
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of the weatherdaemon project.
* Copyright 2021 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/>.
*/
#pragma once
#ifndef __TERM_H__
#define __TERM_H__
#include <usefull_macros.h>
#define FRAME_MAX_LENGTH (300)
#define MAX_MEMORY_DUMP_SIZE (0x800 * 4)
// Terminal timeout (seconds)
#define WAIT_TMOUT (0.5)
// Terminal polling timeout - 1 second
#define T_POLLING_TMOUT (1.0)
typedef struct{
double windspeed; // speed in m/s
double winddir; // direction from north
double pressure; // pressure in hPa
double temperature; // outern temperature in degC
double humidity; // humidity in percents
double rainfall; // cumulative rain level (mm)
double tmeasure; // UNIX-time of last measure
} weather_t;
int try_connect(char *device, int baudrate);
int getlastweather(weather_t *w);
void stop_tty();
#endif // __TERM_H__

View File

@ -0,0 +1 @@
-std=c17

View File

@ -0,0 +1,4 @@
#define EBUG 1
#define _GNU_SOURCE
#define _XOPEN_SOURCE 1111
#define _POSIX_C_SOURCE 200000

View File

@ -0,0 +1 @@
[General]

View File

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.12.3, 2021-06-09T21:11:29. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<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.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</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.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<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="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>
<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>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<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>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</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.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<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">
<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>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>

View File

@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.2, 2020-08-27T15:02:35. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<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.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</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.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">false</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<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="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>
<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.DefaultDisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<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.DefaultDisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</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.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">По умолчанию</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Установка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Конфигурация установки</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<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">
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<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.DefaultDisplayName">Особая программа</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="RunConfiguration.Arguments"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</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>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">20</value>
</data>
<data>
<variable>Version</variable>
<value type="int">20</value>
</data>
</qtcreator>

View File

@ -0,0 +1 @@
-std=c++17

View File

@ -0,0 +1,9 @@
cmdlnopts.c
cmdlnopts.h
main.c
socket.c
socket.h
stat.c
stat.h
term.c
term.h

View File

@ -0,0 +1 @@
.