add to stellarium daemon debug port @10001

This commit is contained in:
Edward Emelianov 2020-03-02 08:28:53 +03:00
parent bd09ecef90
commit 33185e174a
11 changed files with 226 additions and 109 deletions

View File

@ -35,6 +35,7 @@ glob_pars G;
#define DEFAULT_COMDEV "/dev/ttyUSB0"
// port for connections
#define DEFAULT_PORT "10000"
#define DEFAULT_DBGPORT "10001"
// accept only local connections
//#define ACCEPT_IP "192.168.3.225"
// default PID filename:
@ -47,6 +48,7 @@ glob_pars G;
glob_pars const Gdefault = {
.device = DEFAULT_COMDEV,
.port = DEFAULT_PORT,
.dbgport = DEFAULT_DBGPORT,
.pidfile = DEFAULT_PIDFILE,
.crdsfile = DEFAULT_FITSHDR,
.emulation = 0,
@ -67,6 +69,7 @@ myoption cmdlnopts[] = {
{"hdrfile", NEED_ARG, NULL, 'o', arg_string, APTR(&G.crdsfile), _("file to save FITS-header with coordinates and time")},
{"pidfile", NEED_ARG, NULL, 'P', arg_string, APTR(&G.pidfile), _("pidfile (default: " DEFAULT_PIDFILE ")")},
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("port to connect (default: " DEFAULT_PORT ")")},
{"dbgport", NEED_ARG, NULL, 'D', arg_string, APTR(&G.dbgport), _("port to connect for debug console (default: " DEFAULT_DBGPORT ")")},
end_option
};

View File

@ -31,6 +31,7 @@
typedef struct{
char *device; // serial device name
char *port; // port to connect
char *dbgport; // port for debug console
char *pidfile; // name of PID file
char *logfile; // logging to this file
char *crdsfile; // file where FITS-header should be written

View File

@ -62,8 +62,8 @@ int getPlace(placeData *p){
int getWeath(placeWeather *w){
if(!w) return 0;
w->relhum = 0.7;
w->tc = 0.;
w->php = 780.;
w->tc = 1.;
w->php = 78.; // temporary, to fix bug of firmware
return 0;
}
int getDUT(almDut *a){

View File

@ -40,31 +40,30 @@
extern void check4running(char *self, char *pidfilename, void (*iffound)(pid_t pid));
// Max amount of connections
#define BACKLOG (1)
#define BACKLOG (10)
#define BUFLEN (1024)
// pause for incoming message waiting (out coordinates sent after that timeout)
#define SOCK_TMOUT (1)
static uint8_t buff[BUFLEN+1];
// global parameters
static glob_pars *GP = NULL;
static pid_t childpid = 1; // PID of child process
static volatile int global_quit = 0;
volatile int global_quit = 0;
// quit by signal
void signals(int sig){
signal(sig, SIG_IGN);
unlink(GP->crdsfile); // remove header file
unlink(GP->pidfile); // and remove pidfile
if(childpid){ // parent process
restore_console();
restore_tty();
unlink(GP->pidfile); // and remove pidfile
}
DBG("Get signal %d, quit.\n", sig);
global_quit = 1;
sleep(1);
if(childpid) putlog("PID %d exit with status %d after child's %d death", getpid(), sig, childpid);
else WARN("Child %d died with %d", getpid(), sig);
else WARNX("Child %d died with %d", getpid(), sig);
exit(sig);
}
@ -260,7 +259,6 @@ int proc_data(uint8_t *data, ssize_t len){
void *handle_socket(void *sockd){
FNAME();
if(global_quit) return NULL;
ssize_t rd;
outdata dout;
int sock = *(int*)sockd;
dout.len = htole16(sizeof(outdata));
@ -294,7 +292,8 @@ void *handle_socket(void *sockd){
}
if(!(FD_ISSET(sock, &readfds))) continue;
// fill incoming buffer
rd = read(sock, buff, BUFLEN);
uint8_t buff[BUFLEN+1];
ssize_t rd = read(sock, buff, BUFLEN);
buff[rd] = 0;
DBG("read %zd (%s)", rd, buff);
if(rd <= 0){ // error or disconnect
@ -311,64 +310,74 @@ void *handle_socket(void *sockd){
return NULL;
}
// thread writing FITS-header file
static void *hdrthread(_U_ void *buf){
// write FITS-header at most once per second
do{
while(!global_quit){
wrhdr();
usleep(1000); // give a chanse to write/read for others
}while(1);
}
return NULL;
}
static inline void main_proc(){
int sock;
/**
* @brief opensocket - open socket to port `port`
* @return socket fd or <0 if failed
*/
static int opensocket(char *port){
if(!port) return -1;
int reuseaddr = 1;
pthread_t hthrd;
// connect to telescope
if(!GP->emulation){
if(!connect_telescope(GP->device, GP->crdsfile)){
ERRX(_("Can't connect to telescope device"));
}
if(pthread_create(&hthrd, NULL, hdrthread, NULL))
ERR(_("Can't create writing thread"));
}
// open socket
int sock;
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;
DBG("try to open port %s", GP->port);
if(getaddrinfo(NULL, GP->port, &hints, &res) != 0){
ERR("getaddrinfo");
DBG("try to open port %s", port);
if(getaddrinfo(NULL, port, &hints, &res) != 0){
WARN("getaddrinfo()");
return 0;
}
/*
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");
WARN("socket()");
continue;
}
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)) == -1){
ERR("setsockopt");
WARN("setsockopt()");
close(sock);
continue;
}
if(bind(sock, p->ai_addr, p->ai_addrlen) == -1){
WARN("bind()");
close(sock);
WARN("bind");
continue;
}
break; // if we get here, we must have connected successfully
}
freeaddrinfo(res);
// Listen
if(listen(sock, BACKLOG) == -1){
WARN("listen");
putlog("listen() error");
ERR("listen");
}
DBG("listen at %s", GP->port);
putlog("listen at %s", GP->port);
//freeaddrinfo(res);
DBG("listen at %s", port);
putlog("listen at %s", port);
return sock;
}
/**
* @brief waitconn
* @param sock - socket fd to accept()
* @param connthread - thread which to run when connection accepted (it's parameter - socket fd)
*/
static void waitconn(int sock, void *(*connthread)(void*)){
// Main loop
while(!global_quit){
socklen_t size = sizeof(struct sockaddr_in);
@ -377,45 +386,81 @@ static inline void main_proc(){
newsock = accept(sock, (struct sockaddr*)&myaddr, &size);
if(newsock <= 0){
WARN("accept()");
sleep(1);
continue;
}
struct sockaddr_in peer;
socklen_t peer_len = sizeof(peer);
if (getpeername(newsock, &peer, &peer_len) == -1) {
if(getpeername(newsock, (struct sockaddr*)&peer, &peer_len) == -1){
WARN("getpeername()");
close(newsock);
continue;
}
int sockport = -1;
if(getsockname(newsock, (struct sockaddr*)&peer, &peer_len) == 0){
sockport = ntohs(peer.sin_port);
}
char *peerIP = inet_ntoa(peer.sin_addr);
putlog("Got connection from %s", peerIP);
DBG("Peer's IP address is: %s\n", peerIP);
putlog("Got connection from %s @ %d", peerIP, sockport);
DBG("Peer's IP address is: %s (@port %d)\n", peerIP, sockport);
/*if(strcmp(peerIP, ACCEPT_IP) && strcmp(peerIP, "127.0.0.1")){
WARNX("Wrong IP");
close(newsock);
continue;
}*/
//handle_socket(newsock);
pthread_t rthrd;
if(pthread_create(&rthrd, NULL, handle_socket, (void*)&newsock)){
if(pthread_create(&rthrd, NULL, connthread, (void*)&newsock)){
putlog("Error creating listen thread");
ERR(_("Can't create socket thread"));
}else{
DBG("Thread created, detouch");
pthread_detach(rthrd); // don't care about thread state
}
}
pthread_cancel(hthrd); // cancel reading thread
pthread_join(hthrd, NULL);
close(sock);
}
// thread working with terminal
static void *termthread(_U_ void *buf){
int sock = opensocket(GP->dbgport);
if(sock < 0){
putlog("Can't open debugging socket @ port %s", GP->dbgport);
ERRX("Can't open debug socket");
}
waitconn(sock, term_thread);
return NULL;
}
static inline void main_proc(){
pthread_t hthrd, termthrd;
// connect to telescope
if(!GP->emulation){
if(!connect_telescope(GP->device, GP->crdsfile)){
ERRX(_("Can't connect to telescope device"));
}
if(pthread_create(&hthrd, NULL, hdrthread, NULL))
ERR(_("Can't create writing thread"));
if(pthread_create(&termthrd, NULL, termthread, NULL))
ERR(_("Can't create terminal thread"));
}
// open socket
int sock = opensocket(GP->port);
if(sock < 0){
putlog("Can't open socket @ port %s", GP->port);
ERRX("Can't open stellarium socket");
}
waitconn(sock, handle_socket);
usleep(10000);
pthread_cancel(hthrd); // cancel reading thread
pthread_cancel(termthrd);
pthread_join(hthrd, NULL);
pthread_join(termthrd, NULL);
}
int main(int argc, char **argv){
char *self = strdup(argv[0]);
GP = parse_args(argc, argv);
initial_setup();
check4running(self, GP->pidfile, NULL);
if(GP->logfile) openlogfile(GP->logfile);
signal(SIGTERM, signals); // kill (-15) - quit
signal(SIGKILL, signals); // kill (-9) - quit
@ -429,14 +474,16 @@ int main(int argc, char **argv){
ERR(_("Can't open %s for writing"), GP->crdsfile);
close(fd);
printf(_("Start socket\n"));
putlog("Starting, master PID=%d", getpid());
printf("Daemonize\n");
#ifndef EBUG // daemonize only in release mode
if(daemon(1, 0)){
putlog("Err: daemon()");
ERR("daemon()");
}
#endif // EBUG
check4running(self, GP->pidfile, NULL);
if(GP->logfile) openlogfile(GP->logfile);
putlog("Starting, master PID=%d", getpid());
while(1){
childpid = fork();

View File

@ -38,5 +38,6 @@
// global parameters
extern glob_pars *Global_parameters;
// global quit flag
extern volatile int global_quit;
#endif // __MAIN_H__

View File

@ -20,9 +20,13 @@
* MA 02110-1301, USA.
*
*/
#include <arpa/inet.h> // ntoa
#include <netinet/in.h> // ntoa
#include <pthread.h>
#include <sys/socket.h> // getpeername
#include "libsofa.h"
#include "main.h" // global_quit
#include "telescope.h"
#include "usefull_macros.h"
@ -35,7 +39,6 @@
#define WAIT_TMOUT (0.01)
#endif
#define BUFLEN 80
static char *hdname = NULL;
@ -45,6 +48,7 @@ static int Target = 0; // target coordinates entered
/**
* read strings from terminal (ending with '\n') with timeout
* @return NULL if nothing was read or pointer to static buffer
* THREAD UNSAFE!
*/
static char *read_string(){
static char buf[BUFLEN];
@ -78,20 +82,25 @@ static char *read_string(){
/**
* write command, thread-safe
* @param cmd (i) - command to write
* @param buff (o) - buffer (WHICH SIZE = BUFLEN!!!) to which write data (or NULL if don't need)
* @return answer or NULL if error occured (or no answer)
* WARNING!!! data returned is allocated by strdup! You MUST free it when don't need
*/
static char *write_cmd(const char *cmd){
static char *write_cmd(const char *cmd, char *buff){
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&mutex);
//DBG("Write %s", cmd);
if(write_tty(cmd, strlen(cmd))) return NULL;
double t0 = dtime();
static char *ans;
char *ans;
while(dtime() - t0 < T_POLLING_TMOUT){ // read answer
if((ans = read_string())){ // parse new data
// DBG("got answer: %s", ans);
pthread_mutex_unlock(&mutex);
return ans;
if(!buff) return NULL;
strncpy(buff, ans, BUFLEN-1);
return buff;
}
}
pthread_mutex_unlock(&mutex);
@ -99,48 +108,60 @@ static char *write_cmd(const char *cmd){
}
// write to telescope mount corrections: datetime, pressure and temperature
static void makecorr(){
// @return 1 if time was corrected
static int makecorr(){
int ret = 0;
// write current date&time
char buf[64], *ans;
DBG("curtime: %s", write_cmd(":GUDT#"));
write_cmd(":gT#"); // correct time by GPS
ans = write_cmd(":gtg#");
if(!ans || *ans != '1'){
WARNX("mount don't synchronized with GPS! Refresh datetime");
time_t t = time(NULL);
struct tm *stm = localtime(&t);
struct timeval tv;
gettimeofday(&tv,NULL);
snprintf(buf, 64, ":SLDT%04d-%02d-%02d,%02d:%02d:%02d.%02ld#", 1900+stm->tm_year, stm->tm_mon+1, stm->tm_mday,
stm->tm_hour, stm->tm_min, stm->tm_sec, tv.tv_usec/10000);
DBG("write: %s", buf);
ans = write_cmd(buf);
if(!ans || *ans != '1'){
WARNX("Can't write current date/time");
putlog("Can't set system time");
}else putlog("Set system time by command %s", buf);
DBG("curtime: %s", write_cmd(":GUDT#"));
char buf[64], ibuff[BUFLEN], *ans;
DBG("curtime: %s", write_cmd(":GUDT#", ibuff));
ans = write_cmd(":Gstat#", ibuff);
/*
* there's no GPS on this mount and there's no need for it!
write_cmd(":gT#", NULL); // correct time by GPS
ans = write_cmd(":gtg#", ibuff);
*/
if(!ans || *ans == '0'){ // system is in tracking or unknown state - don't update data!
return 0;
}
WARNX("Refresh datetime");
time_t t = time(NULL);
struct tm *stm = localtime(&t);
struct timeval tv;
gettimeofday(&tv,NULL);
snprintf(buf, 64, ":SLDT%04d-%02d-%02d,%02d:%02d:%02d.%02ld#", 1900+stm->tm_year, stm->tm_mon+1, stm->tm_mday,
stm->tm_hour, stm->tm_min, stm->tm_sec, tv.tv_usec/10000);
DBG("write: %s", buf);
ans = write_cmd(buf, ibuff);
if(!ans || *ans != '1'){
WARNX("Can't write current date/time");
putlog("Can't set system time");
}else{
putlog("Set system time by command %s", buf);
ret = 1;
}
DBG("curtime: %s", write_cmd(":GUDT#", ibuff));
placeWeather w;
if(getWeath(&w)) putlog("Can't determine weather data");
else{ // set refraction model data
snprintf(buf, 64, ":SRPRS%.1f#", w.php);
ans = write_cmd(buf);
ans = write_cmd(buf, ibuff);
if(!ans || *ans != '1') putlog("Can't set pressure data of refraction model");
else putlog("Correct pressure to %g", w.php);
snprintf(buf, 64, ":SRTMP%.1f#", w.tc);
ans = write_cmd(buf);
ans = write_cmd(buf, ibuff);
if(!ans || *ans != '1') putlog("Can't set temperature data of refraction model");
else putlog("Correct temperature to %g", w.tc);
}
return ret;
}
int chkconn(){
char tmpbuf[4096];
read_tty(tmpbuf, 4096); // clear rbuf
write_cmd("#"); // clear cmd buffer
if(!write_cmd(":SB0#")) return 0; // 115200
write_cmd("#", NULL); // clear cmd buffer
if(!write_cmd(":SB0#", tmpbuf)) return 0; // 115200
//if(!write_cmd(":GR#")) return 0;
return 1;
}
@ -167,14 +188,16 @@ int connect_telescope(char *dev, char *hdrname){
tty_init(dev, B115200);
if(!chkconn()) return 0;
}
write_cmd(":U2#");
write_cmd(":U2#"); // set high precision
write_cmd(":So10#"); // set minimum altitude to 10 degrees
write_cmd("#", NULL); // clear previous buffer
write_cmd(":STOP#", NULL); // stop tracking after poweron
write_cmd(":U2#", NULL); // set high precision
write_cmd(":So10#", NULL); // set minimum altitude to 10 degrees
putlog("Connected to %s@115200, will write FITS-header into %s", dev, hdrname);
FREE(hdname);
hdname = strdup(hdrname);
DBG("connected");
Target = 0;
write_cmd(":gT#"); // correct time by GPS
write_cmd(":gT#", NULL); // correct time by GPS
return 1;
}
@ -195,7 +218,7 @@ int point_telescope(double ra, double dec){
ptDECdeg = dec;
Target = 0;
int err = 0;
static char buf[80];
char buf[80], ibuff[BUFLEN];
char sign = '+';
if(dec < 0){
sign = '-';
@ -212,19 +235,19 @@ int point_telescope(double ra, double dec){
int dm = (int)dec;
dec -= dm; dec *= 60.;
snprintf(buf, 80, ":Sr%d:%d:%.2f#", h,m,ra);
char *ans = write_cmd(buf);
char *ans = write_cmd(buf, ibuff);
if(!ans || *ans != '1'){
err = 1;
goto ret;
}
snprintf(buf, 80, ":Sd%c%d:%d:%.1f#", sign,d,dm,dec);
ans = write_cmd(buf);
ans = write_cmd(buf, ibuff);
if(!ans || *ans != '1'){
err = 2;
goto ret;
}
DBG("Move");
ans = write_cmd(":MS#");
ans = write_cmd(":MS#", ibuff);
if(!ans || *ans != '0'){
putlog("move error, answer: %s", ans);
err = 3;
@ -314,8 +337,9 @@ int get_telescope_coords(double *ra, double *decl){
}
void stop_telescope(){
write_cmd(":RT9#"); // stop tracking
write_cmd(":STOP#"); // halt moving
write_cmd(":RT9#", NULL); // stop tracking
write_cmd(":AL#", NULL); // stop tracking
write_cmd(":STOP#", NULL); // halt moving
Target = 0;
}
@ -347,24 +371,24 @@ static char *dups(const char *buf, int astr){
}
static void getplace(){
char *ans;
char *ans, ibuff[BUFLEN];
if(!elevation){
ans = write_cmd(":Gev#");
ans = write_cmd(":Gev#", ibuff);
elevation = dups(ans, 0);
}
if(!longitude){
ans = write_cmd(":Gg#");
ans = write_cmd(":Gg#", ibuff);
longitude = dups(ans, 1);
}
if(!latitude){
ans = write_cmd(":Gt#");
ans = write_cmd(":Gt#", ibuff);
latitude = dups(ans, 1);
}
}
static const char *statuses[12] = {
[0] = "'Tracking'",
[1] = "'Going to stop'",
[1] = "'Stoped or homing'",
[2] = "'Slewing to park'",
[3] = "'Unparking'",
[4] = "'Slewing to home'",
@ -396,12 +420,13 @@ void wrhdr(){
static int failcounter = 0;
static time_t lastcorr = 0; // last time of corrections made
if(time(NULL) - lastcorr > CORRECTIONS_TIMEDIFF){
lastcorr = time(NULL);
makecorr();
if(makecorr()) lastcorr = time(NULL);
else lastcorr += 30; // failed -> check 30s later
}
char *ans = NULL, *jd = NULL, *lst = NULL, *date = NULL, *pS = NULL;
char ibuff[BUFLEN];
// get coordinates for writing to file & sending to stellarium client
ans = write_cmd(":GR#");
ans = write_cmd(":GR#", ibuff);
if(!str2coord(ans, &r)){
if(++failcounter == 10){
putlog("Lost connection with mount");
@ -410,7 +435,7 @@ void wrhdr(){
}
return;
}
ans = write_cmd(":GD#");
ans = write_cmd(":GD#", ibuff);
if(!str2coord(ans, &d)){
if(++failcounter == 10){
putlog("Lost connection with mount");
@ -421,11 +446,14 @@ void wrhdr(){
}
failcounter = 0;
tlast = time(NULL);
if(!hdname) return;
if(!hdname){
DBG("hdname not given!");
return;
}
if(!elevation || !longitude || !latitude) getplace();
ans = write_cmd(":GJD1#"); jd = dups(ans, 0);
ans = write_cmd(":GS#"); lst = dups(ans, 1);
ans = write_cmd(":GUDT#");
ans = write_cmd(":GJD1#", ibuff); jd = dups(ans, 0);
ans = write_cmd(":GS#", ibuff); lst = dups(ans, 1);
ans = write_cmd(":GUDT#", ibuff);
if(ans){
char *comma = strchr(ans, ',');
if(comma){
@ -433,15 +461,15 @@ void wrhdr(){
date = dups(ans, 1);
}
}
ans = write_cmd(":pS#"); pS = dups(ans, 1);
ans = write_cmd(":Gstat#");
ans = write_cmd(":pS#", ibuff); pS = dups(ans, 1);
ans = write_cmd(":Gstat#", ibuff);
if(ans){
mountstatus = atoi(ans);
//DBG("Status: %d", mountstatus);
}
#define WRHDR(k, v, c) do{if(printhdr(hdrfd, k, v, c)){close(hdrfd); return;}}while(0)
char val[22];
if(unlink(hdname)){
if(unlink(hdname) && errno != ENOENT){ // can't unlink existng file
WARN("unlink(%s)", hdname);
FREE(jd); FREE(lst); FREE(date); FREE(pS);
return;
@ -486,4 +514,42 @@ void wrhdr(){
close(hdrfd);
}
// terminal thread: allows to work with terminal through socket
void *term_thread(void *sockd){
int sock = *(int*)sockd;
char buff[BUFLEN+1], ibuff[BUFLEN+2];
// get client IP from socket fd - for logging
struct sockaddr_in peer;
socklen_t peer_len = sizeof(peer);
char *peerIP = NULL;
if(getpeername(sock, (struct sockaddr*)&peer, &peer_len) == 0){
peerIP = inet_ntoa(peer.sin_addr);
}
while(!global_quit){ // blocking read
ssize_t rd = read(sock, buff, BUFLEN);
if(rd <= 0){ // error or disconnect
DBG("Nothing to read from fd %d (ret: %zd)", sock, rd);
break;
}
buff[rd] = 0;
char *ch = strchr(buff, '\n');
if(ch) *ch = 0;
if(!buff[0]) continue; // empty string
char *ans = write_cmd(buff, ibuff);
putlog("%s COMMAND %s ANSWER %s", peerIP, buff, ibuff);
DBG("%s COMMAND: %s ANSWER: %s", peerIP, buff, ibuff);
if(ans){
ssize_t l = (ssize_t)strlen(ans);
if(l++){
ans[l-1] = '\n';
ans[l] = 0;
if(l != write(sock, ans, l)){
WARN("term_thread, write()");
break;
}
}
}
}
close(sock);
return NULL;
}

View File

@ -34,5 +34,6 @@ int point_telescope(double ra, double decl);
int get_telescope_coords(double *ra, double *decl);
void stop_telescope();
void wrhdr();
void *term_thread(void *sockd);
#endif // __TELESCOPE_H__

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.2, 2020-02-25T17:15:24. -->
<!-- Written by QtCreator 4.8.2, 2020-02-27T16:44:16. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -38,7 +38,6 @@ static glob_pars G;
// DEFAULTS
// default global parameters
static glob_pars const Gdefault = {
.pidfile = DEFAULT_PIDFILE,
.port = DEFAULT_PORT,
.host = DEFAULT_HOST,
};
@ -50,7 +49,6 @@ static glob_pars const Gdefault = {
static myoption cmdlnopts[] = {
// common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"pidfile", NEED_ARG, NULL, 'p', arg_string, APTR(&G.pidfile), _("pidfile (default: " DEFAULT_PIDFILE ")")},
{"port", NEED_ARG, NULL, 'P', arg_string, APTR(&G.port), _("port to connect (default: " DEFAULT_PORT ")")},
{"host", NEED_ARG, NULL, 'H', arg_string, APTR(&G.host), _("host to connect (default: " DEFAULT_HOST ")")},
{"ra", NEED_ARG, NULL, 'r', arg_string, APTR(&G.ra), _("target RA: HH:MM:SS.SS")},

View File

@ -25,7 +25,6 @@
* here are some typedef's for global data
*/
typedef struct{
char *pidfile; // name of PID file
char *port; // port to connect
char *host; // hostname
char *ra; // RA in string form

View File

@ -36,9 +36,6 @@ void signals(int sig){
signal(sig, SIG_IGN);
DBG("Get signal %d, quit.\n", sig);
}
WARNX("Exit with status %d", sig);
if(GP->pidfile) // remove unnesessary PID file
unlink(GP->pidfile);
restore_console();
exit(sig);
}
@ -51,20 +48,24 @@ int main(int argc, char *argv[]){
initial_setup();
char *self = strdup(argv[0]);
GP = parse_args(argc, argv);
DBG("here");
if(GP->rest_pars_num){
printf("%d extra options:\n", GP->rest_pars_num);
for(int i = 0; i < GP->rest_pars_num; ++i)
printf("%s\n", GP->rest_pars[i]);
}
DBG("here");
if((GP->ra && !GP->dec) || (!GP->ra && GP->dec))
ERRX("You should point both coordinates");
check4running(self, GP->pidfile);
DBG("here");
free(self);
DBG("here");
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
DBG("here");
setup_con();
/*
if(GP->rest_pars_num){