Compare commits

...

2 Commits

Author SHA1 Message Date
09642743a6 add some bash scripts 2026-01-26 17:16:49 +03:00
a80347643f fixed for new vesrion of usefull_macros 2026-01-26 16:54:50 +03:00
31 changed files with 471 additions and 103 deletions

3
.gitignore vendored
View File

@ -23,3 +23,6 @@
*.so
*.so.*
# build dirs
mk/
build/

View File

@ -49,7 +49,7 @@ static glob_pars const Gdefault = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
static myoption cmdlnopts[] = {
static sl_option_t 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: )" DEFAULT_DEV ")")},
@ -75,10 +75,10 @@ glob_pars *parse_args(int argc, char **argv){
char helpstring[1024], *hptr = helpstring;
snprintf(hptr, hlen, "Usage: %%s [args]\n\n\tWhere args are:\n");
// format of help: "Usage: progname [args]\n"
change_helpstring(helpstring);
sl_helpstring(helpstring);
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
sl_parseargs(&argc, &argv, cmdlnopts);
if(help) sl_showhelp(-1, cmdlnopts);
if(argc > 0){
WARNX("Ignore %d unknown parameters: ");
for (i = 0; i < argc; i++)

View File

@ -57,7 +57,7 @@ static void dumpRchanges(rg11 *new, rg11 *old){
int start = 1;
for(int i = 0; i < RREGNUM; ++i){
if(o[i] != n[i]){
sl_putlogt(start, globlog, LOGLEVEL_MSG, "%s=%d", regname(i), n[i]);
sl_putlogt(start, sl_globlog, LOGLEVEL_MSG, "%s=%d", regname(i), n[i]);
DBG("%s=%d", regname(i), n[i]);
if(start) start = 0;
}
@ -68,7 +68,7 @@ static void dumpRchanges(rg11 *new, rg11 *old){
uint8_t f = 1;
for(int i = 0; i < RGBITNUM; ++i, f <<= 1){
if(xOr & f){
sl_putlogt(start, globlog, LOGLEVEL_MSG, "%s=%d", rgbitname(i), (new->RGBits & f) ? 1 : 0);
sl_putlogt(start, sl_globlog, LOGLEVEL_MSG, "%s=%d", rgbitname(i), (new->RGBits & f) ? 1 : 0);
DBG("%s=%d", rgbitname(i), (new->RGBits & f) ? 1 : 0);
if(start) start = 0;
}
@ -82,7 +82,7 @@ static void dumpSchanges(slowregs *new, slowregs *old){
int start = 1;
for(int i = 0; i < SREGNUM; ++i){
if(o[i] != n[i]){
sl_putlogt(start, globlog, LOGLEVEL_MSG, "%s=%d", slowname(i), n[i]);
sl_putlogt(start, sl_globlog, LOGLEVEL_MSG, "%s=%d", slowname(i), n[i]);
DBG("%s=%d", slowname(i), n[i]);
if(start) start = 0;
}
@ -147,12 +147,12 @@ static void puttotable(rg11 *R, slowregs *S){
}
int main(int argc, char **argv){
initial_setup();
sl_init();
char *self = strdup(argv[0]);
G = parse_args(argc, argv);
if(G->timeout < 5) ERRX("Timeout should be not less than 5 seconds");
if(!G->logfile && !G->outfile) ERRX("Point at least log or output file name");
check4running(self, G->pidfile);
sl_check4running(self, G->pidfile);
if(!hydreon_open(G->device)) return 1;
if(G->logfile) OPENLOG(G->logfile, LOGLEVEL_ANY, 0);
if(G->outfile){
@ -166,9 +166,9 @@ int main(int argc, char **argv){
signal(SIGINT, signals); // ctrl+C - quit
signal(SIGQUIT, signals); // ctrl+\ - quit
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
double t0 = dtime();
double t0 = sl_dtime();
puttotable(NULL, NULL);
while(dtime() - t0 < (double)G->timeout){ // dump only changes
while(sl_dtime() - t0 < (double)G->timeout){ // dump only changes
if(!hydreon_getpacket(&Rregs, &Sregs)) continue;
int changes = FALSE;
if(memcmp(&Rregs, &oRregs, RREGNUM + 1)){ // Rregs changed -> log changes
@ -182,7 +182,7 @@ int main(int argc, char **argv){
changes = TRUE;
}
if(changes) puttotable(&Rregs, &Sregs);
t0 = dtime();
t0 = sl_dtime();
}
signals(-1); // never reached
return 0;

View File

@ -20,7 +20,7 @@
#include "hydreon.h"
static TTY_descr *dev = NULL;
static sl_tty_t *dev = NULL;
// regular registers names
static const char* rregnames[RREGNUM] = {
@ -121,7 +121,7 @@ int hydreon_getpacket(rg11 *Rregs, slowregs *Sregs){
if(!dev) return 0;
static int buflen = 0;
static char strbuf[BUFLEN];
int l = read_tty(dev);
int l = sl_tty_read(dev);
if(l < 1) return FALSE;
char s = dev->buf[0];
if(s == 's'){ // start of new packet -> encode old
@ -146,13 +146,13 @@ int hydreon_getpacket(rg11 *Rregs, slowregs *Sregs){
* @return TRUE or FALSE if failed
*/
int hydreon_open(const char *devname){
dev = new_tty((char*)devname, 1200, 1);
dev = sl_tty_new((char*)devname, 1200, 1);
if(!dev) return FALSE;
dev = tty_open(dev, 1);
dev = sl_tty_open(dev, 1);
if(!dev) return FALSE;
return TRUE;
}
void hydreon_close(){
if(dev) close_tty(&dev);
if(dev) sl_tty_close(&dev);
}

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.30)
set(PROJ PCS_create)
set(MINOR_VERSION "0")
set(MID_VERSION "1")

View File

@ -321,7 +321,7 @@ static void printheader(){
}
int main(int argc, char **argv) {
initial_setup();
sl_init();
G = parse_args(argc, argv);
if(G->pressure < 0.) ERRX("Pressure should be greater than zero");
if(G->temperature < -100. || G->temperature > 100.) ERRX("Temperature over the range -100..+100");

View File

@ -40,7 +40,7 @@ glob_pars const Gdefault = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
static myoption cmdlnopts[] = {
static sl_option_t cmdlnopts[] = {
// set 1 to param despite of its repeating number:
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"10m", NO_ARGS, NULL, 't', arg_int, APTR(&G.for10m), _("make output suitable for 10-micron mount")},
@ -68,10 +68,10 @@ static myoption cmdlnopts[] = {
glob_pars *parse_args(int argc, char **argv){
void *ptr = memcpy(&G, &Gdefault, sizeof(G)); assert(ptr);
// format of help: "Usage: progname [args]\n"
change_helpstring(_("Version: " PACKAGE_VERSION "\nUsage: %s [args] FITS_files\nMake PCS list for equatorial mount\n\tWhere args are:\n"));
sl_helpstring(_("Version: " PACKAGE_VERSION "\nUsage: %s [args] FITS_files\nMake PCS list for equatorial mount\n\tWhere args are:\n"));
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
sl_parseargs(&argc, &argv, cmdlnopts);
if(help) sl_showhelp(-1, cmdlnopts);
G.nfiles = argc;
G.infiles = MALLOC(char*, argc);
for(int i = 0; i < argc; i++){

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.30)
set(PROJ chkweather)
set(MINOR_VERSION "1")
set(MID_VERSION "0")

View File

@ -40,7 +40,7 @@ glob_pars const Gdefault = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
static myoption cmdlnopts[] = {
static sl_option_t cmdlnopts[] = {
// set 1 to param despite of its repeating number:
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"speed", NEED_ARG, NULL, 's', arg_int, APTR(&G.speed), _("baudrate (default: 9600)")},
@ -59,10 +59,10 @@ static myoption cmdlnopts[] = {
glob_pars *parse_args(int argc, char **argv){
void *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"));
sl_helpstring(_("Usage: %s [args]\n\n\tWhere args are:\n"));
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
sl_parseargs(&argc, &argv, cmdlnopts);
if(help) sl_showhelp(-1, cmdlnopts);
if(argc > 0){
WARNX("Wrong arguments:\n");
for(int i = 0; i < argc; i++)

View File

@ -51,28 +51,28 @@ static int getpar(char *string, double *Val, char *Name){
int main(int argc, char **argv){
glob_pars *G = NULL; // default parameters see in cmdlnopts.c
initial_setup();
sl_init();
G = parse_args(argc, argv);
TTY_descr *dev = new_tty(G->ttyname, G->speed, 64);
sl_tty_t *dev = sl_tty_new(G->ttyname, G->speed, 64);
if(!dev) return 1;
size_t got, L = 0;
char buff[BUFLEN], *ptr = buff;
int errctr = 0;
for(; errctr < ERRCTR_MAX; ++errctr){
if(!tty_open(dev, 1)){
if(!sl_tty_open(dev, 1)){
sleep(1);
continue;
}
while(read_tty(dev)); // clear buffer
if(write_tty(dev->comfd, "?U\r\n", 3)){
while(sl_tty_read(dev)); // clear buffer
if(sl_tty_write(dev->comfd, "?U\r\n", 3)){
WARNX("write_tty()");
continue;
}
double t0 = dtime();
while(dtime() - t0 < 10.){ // timeout - 10s
got = read_tty(dev);
double t0 = sl_dtime();
while(sl_dtime() - t0 < 10.){ // timeout - 10s
got = sl_tty_read(dev);
if(got == 0) continue;
t0 = dtime();
t0 = sl_dtime();
if(L + got > BUFLEN - 1) break;
L += got;
buff[L] = 0;
@ -92,8 +92,8 @@ int main(int argc, char **argv){
continue;
}else break;
}
while(read_tty(dev));
close_tty(&dev);
while(sl_tty_read(dev));
sl_tty_close(&dev);
if(errctr == ERRCTR_MAX){
ERRX("No connection to meteostation");
}

View File

@ -4,7 +4,7 @@ A="90:00:00"
H="45:00:00"
function sendcmd(){
echo $1 | nc 192.168.70.33 10001 -q10
echo $1 | nc localhost 10001 -q10
}
sendcmd ":Sz${A}#"

View File

@ -0,0 +1,20 @@
#!/bin/bash
#
# $1 - scaling factor (in percents) of the image
#
scale=50
if [ $# -gt 0 ]; then
scale=$1
fi
unset http_proxy
clear
while [[ 1 ]]; do
tput cup 0 0
curl -s http://zarch.sao.ru/webcam/mirat_allsky.cgi | magick - -colors 256 +dither -normalize -resize $scale% sixel:-
# sleep 30s
sleep 5s
done

View File

@ -0,0 +1,114 @@
#!/bin/bash
#
# $1 - scaling factor (in percents) of the image
#
function get_val {
echo $(echo $1 | cut -d "=" -f 2 | cut -d "." -f 1)
}
white_col="\e[97m"
red_col="\e[1m\e[31m"
end_col="\e[0m"
last_row=0
scale=50
if [ $# -gt 0 ]; then
scale=$1
fi
unset http_proxy
im_sleep=20 # in secs
info_sleep=180 # in secs
n_info=$((info_sleep/im_sleep))
clear
while [[ 1 ]]; do
# weather info
m_old=($(curl 192.168.70.33:12345 2>/dev/null)// / )
rain=${m_old[0]}
clouds=${m_old[1]}
temp=${m_old[2]}
m_new=($(curl localhost:3333/stat3600 2>/dev/null | sed 's/[\x01-\x1F\x7F]//g')// / )
windmax=${m_new[0]}
m_new=($(curl localhost:3333 2>/dev/null | sed 's/[\x01-\x1F\x7F]//g')// / )
wind=${m_new[0]}
humi=${m_new[4]}
rain_col=$white_col
clouds_col=$white_col
humi_col=$white_col
wind_col=$white_col
wind_max_col=$white_col
let rain_flag=$(get_val $rain)
if [[ $rain_flag -eq 1 ]]; then
rain_col=$red_col
fi
let clouds_val=$(get_val $clouds)
if [[ $clouds_val -le 1500 ]]; then
clouds_col=$red_col
fi
let humi_val=$(get_val $humi)
if [[ $humi_val -ge 90 ]]; then
humi_col=$red_col
fi
let wind_val=$(get_val $wind)
if [[ $wind_val -ge 10 ]]; then
wind_col=$red_col
fi
let wind_max_val=$(get_val $windmax)
if [[ $wind_max_val -ge 10 ]]; then
wind_max_col=$red_col
fi
ncols=`tput cols`
start_col=$((ncols-25))
tput cup $last_row $start_col
# echo -e "\e[4m`date`:\e[0m"
echo -e "\e[4m`date +'%F %T'`:\e[0m"
((++last_row))
tput cup $last_row $start_col
echo -e "$clouds_col$clouds $rain_col($rain)$end_col"
((++last_row))
tput cup $last_row $start_col
# echo -e "$temp $humi_col($humi)$end_col"
temp_val=`printf "%.1f" ${temp#*=}`
echo -e "Temp=$temp_val, ${humi_col}Hum=$humi_val%$end_col"
((++last_row))
tput cup $last_row $start_col
# echo -e "$wind_col$wind $wind_max_col($windmax @hour)$end_col\n"
wind_max_val=`printf "%.1f" ${windmax#*=}`
echo -e "$wind_col$wind $wind_max_col(Max=$wind_max_val/hour)$end_col\n"
IFS='[;' read -p $'\e[6n' -d R -rs _ last_row col _
# allsky image
for i in `seq $n_info`; do
tput cup 0 0
curl -s http://zarch.sao.ru/webcam/omea_allsky.cgi | magick - -colors 256 -normalize +dither -resize $scale% sixel:-
# curl -s http://zarch.sao.ru/webcam/mirat_allsky.cgi | magick - -colors 256 -resize $scale% sixel:-
sleep ${im_sleep}s
done
done

View File

@ -0,0 +1,18 @@
#!/bin/bash
#
# $1 - directory to be copied
#
RDIR="/home/obs/robotel1_2025"
# copy non-FITS files
tar c --exclude='*.fit' --exclude='*shit*' $1 | ssh obs@roboserv "tar x -C $RDIR"
#tar c --exclude='*.fit' --exclude='*shit*' $1 | ssh obs@roboserv "tar x -C /home/obs/robotel1_2023"
# copy FITS files and XZ-ing it on remote server
CMD='sh -c "xz -6e -T0 - > $TAR_FILENAME.xz"'
tar c $1/*.fit | ssh obs@roboserv "cd $RDIR; tar x --to-command='$CMD'"
#tar c $1/*.fit | ssh obs@roboserv "cd /home/obs/robotel1_2023; tar x --to-command='$CMD'"
ssh obs@roboserv "cd $RDIR; tar c $1 | ssh data@robostorage 'tar x -C /mnt/ARCHIVE/ROBOTEL1/'"

View File

@ -0,0 +1,165 @@
#!/bin/bash
RA="17:17:08.86"
DEC="+67:57:11.4"
OBJ="GALEX171708.5"
EXPTIME=31000
FLATTIME=40000
OBS="Fatkhullin T.A."
BADWEATHER=1300
DATEEND=$(sunrise 14)
# focus each N seconds
FOCUST=7200
FNO=1
FDATE=0
#
# NOTE: THIS IS A NEW VERSION OF THE OBSERVATION SCRIPT!
# CHAGLELOG:
# Oct 2024: replace focussing algorithm (T. Fatkhullin)
# At the night start the first focussing run
# uses of two-step algorithm:
# 1) rough focus astimation along full season-to-season
# focus range (as it was implemented in the old obs. script)
# 2) precise focussing along narrow range computed from
# previous rough estimation
# Next focussing runs compute range from the current focus value.
# (new function 'focustel_new')
#
# May 2025: rewrite detection of running this script process (T. Fatkhullin)
# (use of '-c' commandline option for 'pgrep' command)
function focustel_new(){
rm focus*.fit 2>/dev/null
echo "Focussing..."
let fno=$1
if [[ $fno -gt 1 ]]; then
let curr_foc=`fli_control | tail -n 5 | head -n 1 | cut -d "=" -f 2`
let lowf=$curr_foc-1500
let highf=$curr_foc+1500
focus_seq_FLI.py -v -c focus$(printf "%02d" $1).jpg $lowf $highf 500
if [[ $? -ne 0 ]]; then
echo -e "\nFOCUSSING SCRIPT RETURNED: $?"
echo -e "SOMETHING WAS WRONG IN FOCUSSING SEQUENCE!!! SET FOCUS TO PREVIOUS VALUE!!\n"
fli_control -g $curr_foc
fi
else
focus_seq_FLI.py --guess -v -N 7 -c focus$(printf "%02d" $1).jpg 47000 60000 500
fi
FDATE=$(date +%s)
}
function sendcmd(){
echo $1 | nc 192.168.70.33 10001 -q10
}
function point_tel(){
touch lastpointing
send_coords -r $1 -d $2
}
#c=$(pgrep run_full | wc -l)
# $ will run another run_full, so c=2 for single run
#if [[ $c -gt 1 ]]; then
# echo "Another process is running; exiting"
# exit 1
#fi
if [[ $(pgrep -c run_full) -gt 1 ]]; then
echo "Another process is running! Exit!"
exit 1
fi
export http_proxy=""
# set lower limit to 5degr
send_command2mount ":So5#"
echo "Time diff: $(($DATEEND-$(date +%s)))"
if [ $(($DATEEND-$(date +%s))) -lt 3600 ]; then
echo "There's less an hour for observation!"
exit 2
fi
if [ $(($DATEEND-$(date +%s))) -gt 53200 ]; then
echo "There's more than 12 hours till closing, check script data!"
exit 3
fi
#STARTobs
#send_coords
#echo "Wait a little"
#sleep 10
echo "GoTo object: ${RA} ${DEC}"
send_coords -r${RA} -d${DEC}
echo "Start taking object"
badweather=0
while true; do
now=$(date +%s)
ANS=$(curl localhost:55555/status 2>/dev/null)
echo "Dome status: $ANS"
if [ $ANS != "opened" ]; then
echo "Closed"
curl localhost:55555/weather 2>/dev/null > DomeClosed
break;
fi
chkweather ${BADWEATHER} > lastweather && badweather=0 || badweather=$((badweather+1))
[ $badweather -gt 5 ] && break
[ -f stopobs ] && break
[ -f exitjob ] && exit 0
if [ "$now" -lt "$DATEEND" ]; then
est=$(sendcmd ":Gmte#"|sed -e 's/^0*//' -e 's/#//')
echo -e "\n\n\n\n\nEstimated time to flip: $est minutes"
if [[ ("x$est" == "x") || ($est -lt 3) ]]; then
point_tel "${RA}" "${DEC}"
continue
fi
ST=$(send_coords | awk '{print $4}')
[ "x$ST" == "x" ] && break
if [ $ST -ne "0" ]; then
point_tel "${RA}" "${DEC}"
continue
else
[ $(($(date +%s) - $FDATE)) -gt $FOCUST ] && focustel_new $((FNO++))
# [ $(($(date +%s) - $FDATE)) -gt $FOCUST ] && focustel $((FNO++))
preflash
fli_control -r /tmp/10micron.fitsheader -x $EXPTIME -N "${OBS}" -O "${OBJ}" "$OBJ"
fi
else
break
fi
done
echo "Dome closed @ $(date)" >> closed
curl localhost:55555/close
relay_manage -s1
park_telescope
for x in $(seq 1 10); do
preflash
fli_control -r /tmp/10micron.fitsheader -x1 -N "${OBS}" -O "bias" -d bias
preflash
fli_control -r /tmp/10micron.fitsheader -x $EXPTIME -N "${OBS}" -O "dark" -d dark
preflash
fli_control -r /tmp/10micron.fitsheader -n3 -x $FLATTIME -N "${OBS}" -O "flat" flat
done
relay_manage -r1
echo "Closed @ $(date)" >> closed
STOPobs || true
DIR=$(basename $PWD)
echo "TAR: $DIR"
cd ..
./copy_and_xz.sh $DIR
echo "Archived, end"
echo "$DIR archived @ $(date)" >> archived

View File

@ -0,0 +1,44 @@
#!/bin/bash
#
# The script creates working directory,
# copies 'run' script into it and
# edits observer name according to
# the its argument
#
# Working directory name is formed from
# date of the script running and is computed
# as follows:
# now - 12hours
# i.e. the day starts from 12h not from 0h!
#
# $1 - observer name
#
if [[ $# -eq 0 ]]; then
obs_name="Fatkhullin T.A."
else
obs_name=$1
fi
# now - 12h
let now12=`date +%s`-12*3600
# working directory
wdir=/DATA/FITS/`date -d @$now12 +%y.%m.%d`
echo -n "Creating working directory: $wdir ..."
if [[ -d $wdir ]]; then
echo -e "\tFAILED! The directory already exists! Exit!"
exit 1
else
echo -e "\tOK!"
mkdir $wdir
cd $wdir
fi
cp ../run_full.new_foc .
# replace observer name
sed -i "0,/^OBS=\".*\"/ s//OBS=\"${obs_name}\"/" run_full.new_foc
#sed -i "0,/^OBS=\"[a-zA-Z \.]*\"/ s//OBS=\"${obs_name}\"/" run_full.new_foc

View File

@ -0,0 +1,3 @@
#!/bin/bash
mpv -vo sixel --really-quiet=yes "rtsp://viewer:view25@192.168.70.25:554/axis-media/media.amp?videocodec=h264&resolution=640x480"

View File

@ -41,7 +41,7 @@ static glob_pars G = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
static myoption cmdlnopts[] = {
static sl_option_t cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), "show this help"},
{"delimeter",NEED_ARG, NULL, 'd', arg_string, APTR(&G.delimeter), "coordinates delimeter string (default: ':')"},
@ -71,10 +71,10 @@ glob_pars *parse_args(int argc, char **argv){
char helpstring[1024], *hptr = helpstring;
snprintf(hptr, hlen, "Usage: %%s [args]\n\n\tWhere args are:\n");
// format of help: "Usage: progname [args]\n"
change_helpstring(helpstring);
sl_helpstring(helpstring);
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
sl_parseargs(&argc, &argv, cmdlnopts);
if(help) sl_showhelp(-1, cmdlnopts);
if(argc > 0){
G.rest_pars_num = argc;
G.rest_pars = MALLOC(char *, argc);

View File

@ -100,7 +100,7 @@ static void savepoints(FILE *f, point *pts, int N, char *delim, int mask){
}
int main(int argc, char **argv){
initial_setup();
sl_init();
glob_pars *G = parse_args(argc, argv);
FILE *f = NULL;
if(G->outfile){

View File

@ -32,7 +32,7 @@ typedef struct{
static glob_pars G = {.tolerance = 10.};
static myoption cmdlnopts[] = {
static sl_option_t cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_none, APTR(&G.help), _("show this help")},
{"infile", NEED_ARG, NULL, 'i', arg_string, APTR(&G.input), _("input file name")},
@ -158,11 +158,11 @@ static double calcfocus(double coeffs[3]){
int main(int argc, char **argv){
char helpstring[256];
initial_setup();
sl_init();
snprintf(helpstring, 255, "Usage: `cat file | %%s` or with args; file format \"x y\\n..\"\n\tArgs:\n");
change_helpstring(helpstring);
parseargs(&argc, &argv, cmdlnopts);
if(G.help) showhelp(-1, cmdlnopts);
sl_helpstring(helpstring);
sl_parseargs(&argc, &argv, cmdlnopts);
if(G.help) sl_showhelp(-1, cmdlnopts);
if(G.tolerance <= 0.) ERRX("Tolerance should be > 0");
FILE *f = stdin;
if(G.input){

View File

@ -36,7 +36,7 @@ static const char *radtodeg(double r){
int main(){
initial_setup();
sl_init();
at_MJD_t mjd;
if(!at_get_MJDu(time(NULL), &mjd)) ERRX("at_get_MJDu");
printf("MJD=%g; TAI=%g/%g, TT=%g/%g, UTC=%g/%g\n", mjd.MJD, mjd.tai1, mjd.tai2, mjd.tt1, mjd.tt2, mjd.utc1, mjd.utc2);

View File

@ -56,7 +56,7 @@ static parameters G = {
.py = -10000.
};
static myoption cmdlnopts[] = {
static sl_option_t cmdlnopts[] = {
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
{"obsplace", NO_ARGS, NULL, 'O', arg_int, APTR(&G.obsplace), "input RA/Dec is observed place"},
{"JD", NEED_ARG, NULL, 'J', arg_double, APTR(&G.JD), "Julian date"},
@ -77,9 +77,9 @@ static myoption cmdlnopts[] = {
int main(int argc, char **argv){
initial_setup();
parseargs(&argc, &argv, cmdlnopts);
if(G.help) showhelp(-1, cmdlnopts);
sl_init();
sl_parseargs(&argc, &argv, cmdlnopts);
if(G.help) sl_showhelp(-1, cmdlnopts);
at_MJD_t MJD;
G.ra *= ERFA_DD2R;
G.dec *= ERFA_DD2R;

View File

@ -180,9 +180,10 @@ static void toomuch(int fd){
LOGWARN("Client fd=%d tried to connect after MAX reached", fd);
}
// new connections handler
static void connected(sl_sock_t *c){
static int connected(sl_sock_t *c){
if(c->type == SOCKT_UNIX) LOGMSG("New client fd=%d connected", c->fd);
else LOGMSG("New client fd=%d, IP=%s connected", c->fd, c->IP);
return TRUE;
}
// disconnected handler
static void disconnected(sl_sock_t *c){
@ -196,12 +197,12 @@ void server_run(sl_socktype_e type, const char *node, sl_tty_t *serial){
ERRX("server_run(): wrong parameters");
}
dome_serialdev(serial);
sl_sock_changemaxclients(5);
sl_sock_maxclhandler(toomuch);
sl_sock_connhandler(connected);
sl_sock_dischandler(disconnected);
s = sl_sock_run_server(type, node, -1, handlers);
if(!s) ERRX("Can't create socket and/or run threads");
sl_sock_changemaxclients(s, 5);
sl_sock_maxclhandler(s, toomuch);
sl_sock_connhandler(s, connected);
sl_sock_dischandler(s, disconnected);
while(s && s->connected){
if(!s->rthread){
LOGERR("Server handlers thread is dead");

View File

@ -54,7 +54,7 @@ glob_pars const Gdefault = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
myoption cmdlnopts[] = {
sl_option_t cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"device", NEED_ARG, NULL, 'i', arg_string, APTR(&G.device), _("serial device name (default: none)")},
@ -79,10 +79,10 @@ glob_pars *parse_args(int argc, char **argv){
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");
sl_helpstring("Usage: %s [args]\n\n\tWhere args are:\n");
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
sl_parseargs(&argc, &argv, cmdlnopts);
if(help) sl_showhelp(-1, cmdlnopts);
if(argc > 0){
G.rest_pars_num = argc;
G.rest_pars = calloc(argc, sizeof(char*));

View File

@ -30,14 +30,14 @@
glob_pars *GP;
void signals(int signo){
restore_console();
if(ttydescr) close_tty(&ttydescr);
sl_restore_con();
if(ttydescr) sl_tty_close(&ttydescr);
LOGERR("exit with status %d", signo);
exit(signo);
}
int main(int argc, char **argv){
initial_setup();
sl_init();
signal(SIGTERM, signals); // kill (-15) - quit
signal(SIGHUP, SIG_IGN); // hup - ignore
signal(SIGINT, signals); // ctrl+C - quit
@ -52,7 +52,7 @@ int main(int argc, char **argv){
signals(0); // never reached!
}
if(GP->logfile){
sl_loglevel lvl = LOGLEVEL_ERR;
sl_loglevel_e 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");

View File

@ -28,7 +28,7 @@
#define BUFLEN 1024
TTY_descr *ttydescr = NULL;
sl_tty_t *ttydescr = NULL;
static char buf[BUFLEN];
@ -50,14 +50,14 @@ static char *read_string(){
return ptr;
}
ptr = buf;
double d0 = dtime();
double d0 = sl_dtime();
do{
if((l = read_tty(ttydescr))){
if((l = sl_tty_read(ttydescr))){
r += l; LL -= l; ptr += l;
if(ptr[-1] == '\n') break;
d0 = dtime();
d0 = sl_dtime();
}
}while(dtime() - d0 < WAIT_TMOUT && LL);
}while(sl_dtime() - d0 < WAIT_TMOUT && LL);
if(r){
buf[r] = 0;
//DBG("r=%zd, got string: %s", r, buf);
@ -75,10 +75,10 @@ static char *read_string(){
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
ttydescr = sl_tty_new(device, baudrate, 1024);
if(ttydescr) ttydescr = sl_tty_open(ttydescr, 1); // exclusive open
if(!ttydescr) return 0;
while(read_tty(ttydescr)); // clear rbuf
while(sl_tty_read(ttydescr)); // clear rbuf
LOGMSG("Connected to %s", device);
return 1;
}
@ -91,14 +91,14 @@ void run_terminal(){
green(_("Work in terminal mode without echo\n"));
int rb;
size_t l;
setup_con();
sl_setup_con();
while(1){
if((l = read_tty(ttydescr))){
if((l = sl_tty_read(ttydescr))){
printf("%s", ttydescr->buf);
}
if((rb = read_console())){
if((rb = sl_read_con())){
char c = (char) rb;
write_tty(ttydescr->comfd, &c, 1);
sl_tty_write(ttydescr->comfd, &c, 1);
}
}
}
@ -109,8 +109,8 @@ void run_terminal(){
*/
char *poll_device(){
char *ans;
double t0 = dtime();
while(dtime() - t0 < T_POLLING_TMOUT){
double t0 = sl_dtime();
while(sl_dtime() - t0 < T_POLLING_TMOUT){
if((ans = read_string())){ // parse new data
DBG("got %s", ans);
/*

View File

@ -31,7 +31,7 @@
// Terminal polling timeout - 1 second
#define T_POLLING_TMOUT (1.0)
extern TTY_descr *ttydescr;
extern sl_tty_t *ttydescr;
void run_terminal();
int try_connect(char *device, int baudrate);
char *poll_device();

View File

@ -46,7 +46,7 @@ static glob_pars const Gdefault = {
* Define command line options by filling structure:
* name has_arg flag val type argptr help
*/
static myoption cmdlnopts[] = {
static sl_option_t cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"port", NEED_ARG, NULL, 'P', arg_string, APTR(&G.port), _("port to connect (default: " DEFAULT_PORT ")")},
@ -73,13 +73,13 @@ glob_pars *parse_args(int argc, char **argv){
char helpstring[1024], *hptr = helpstring;
snprintf(hptr, hlen, "Usage: %%s [args]\n\n\tWhere args are:\n");
// format of help: "Usage: progname [args]\n"
change_helpstring(helpstring);
sl_helpstring(helpstring);
// parse arguments
parseargs(&argc, &argv, cmdlnopts);
if(help) showhelp(-1, cmdlnopts);
sl_parseargs(&argc, &argv, cmdlnopts);
if(help) sl_showhelp(-1, cmdlnopts);
if(argc > 0){
fprintf(stderr, "Undefined extra parameters!\n");
showhelp(-1, cmdlnopts);
sl_showhelp(-1, cmdlnopts);
G.rest_pars_num = argc;
G.rest_pars = MALLOC(char *, argc);
for (i = 0; i < argc; i++)

View File

@ -36,7 +36,7 @@ void signals(int sig){
signal(sig, SIG_IGN);
DBG("Get signal %d, quit.\n", sig);
}
restore_console();
sl_restore_con();
exit(sig);
}
@ -45,7 +45,7 @@ void iffound_default(pid_t pid){
}
int main(int argc, char *argv[]){
initial_setup();
sl_init();
char *self = strdup(argv[0]);
GP = parse_args(argc, argv);
DBG("here");
@ -66,7 +66,7 @@ int main(int argc, char *argv[]){
signal(SIGQUIT, signals); // ctrl+\ - quit
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
DBG("here");
setup_con();
sl_setup_con();
/*
if(GP->rest_pars_num){
for(int i = 0; i < GP->rest_pars_num; ++i)

View File

@ -56,7 +56,7 @@ void signals(int signo){
exit(signo);
}
static myoption cmdlnopts[] = {
static sl_option_t cmdlnopts[] = {
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"},
{"address", NEED_ARG, NULL, 'a', arg_string, APTR(&G.server), "server name or IP"},
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), "server port"},
@ -68,19 +68,19 @@ static myoption cmdlnopts[] = {
int main(int argc, char **argv){
char *self = strdup(argv[0]);
initial_setup();
parseargs(&argc, &argv, cmdlnopts);
if(G.help) showhelp(-1, cmdlnopts);
sl_init();
sl_parseargs(&argc, &argv, cmdlnopts);
if(G.help) sl_showhelp(-1, cmdlnopts);
if(argc > 0) WARNX("Got %d unused keys", argc);
if(!G.dbname) ERRX("Point database file name");
if(!G.server) ERRX("Point server IP or name");
if(!G.port) ERRX("Point server port");
sl_loglevel lvl = LOGLEVEL_ERR + G.v;
sl_loglevel_e lvl = LOGLEVEL_ERR + G.v;
if(lvl > LOGLEVEL_ANY) lvl = LOGLEVEL_ANY;
if(G.logfile) OPENLOG(G.logfile, lvl, 1);
LOGMSG("hello, start");
LOGDBG("SQLite version: %s", sqlite3_libversion());
check4running(self, G.pidfile);
sl_check4running(self, G.pidfile);
// signal reactions:
signal(SIGTERM, signals); // kill (-15) - quit
signal(SIGHUP, SIG_IGN); // hup - ignore
@ -93,11 +93,11 @@ int main(int argc, char **argv){
while(1){
childpid = fork();
if(childpid){ // master
double t0 = dtime();
double t0 = sl_dtime();
LOGMSG("Created child with pid %d", childpid);
wait(NULL);
LOGWARN("Child %d died", childpid);
if(dtime() - t0 < 1.) pause += 5;
if(sl_dtime() - t0 < 1.) pause += 5;
else pause = 1;
if(pause > 900) pause = 900;
sleep(pause); // wait a little before respawn

View File

@ -78,7 +78,7 @@ static void sendmessage(int fd, const char *msg, int l){
LOGWARN("write()");
WARN("write()");
}else{
if(globlog){ // logging turned ON
if(sl_globlog){ // logging turned ON
tmpbuf[l-1] = 0; // remove trailing '\n' for logging
LOGMSG("SEND to fd %d: %s", fd, tmpbuf);
}
@ -125,10 +125,10 @@ static int canberead(int fd){
// collect data and write into database
// @return FALSE if can't get full data string
static int getdata(int fd){
double t0 = dtime();
double t0 = sl_dtime();
char buf[BUFSIZ];
int len = 0, leave = BUFSIZ, got = 0;
while(dtime() - t0 < ANS_TIMEOUT){
while(sl_dtime() - t0 < ANS_TIMEOUT){
int r = canberead(fd);
if(r == 0) continue;
r = read(fd, buf + len, leave);
@ -169,7 +169,7 @@ static int getdata(int fd){
void run_socket(int fd){
double t0 = 0.;
while(1){
double tlast = dtime();
double tlast = sl_dtime();
if(tlast - t0 >= POLLING_INTERVAL){
sendstrmessage(fd, SERVER_COMMAND);
if(getdata(fd)) t0 = tlast;