mirror of
https://github.com/eddyem/BTA_utils.git
synced 2025-12-06 02:35:13 +03:00
Tested, beta-stage
This commit is contained in:
parent
d0d0f4dfc1
commit
31aeba1507
@ -2,7 +2,7 @@ PROGRAM = stellariumdaemon
|
|||||||
LDFLAGS = -lcrypt -lm -lsla
|
LDFLAGS = -lcrypt -lm -lsla
|
||||||
SRCS = $(wildcard *.c)
|
SRCS = $(wildcard *.c)
|
||||||
CC = gcc
|
CC = gcc
|
||||||
DEFINES = -D_GNU_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=1111 -DEBUG
|
DEFINES = -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=1111 -DEBUG
|
||||||
CXX = gcc
|
CXX = gcc
|
||||||
CFLAGS = -Wall -Werror -Wextra $(DEFINES)
|
CFLAGS = -Wall -Werror -Wextra $(DEFINES)
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|||||||
@ -141,3 +141,5 @@ void calc_AD(double az, double zd, double stime, double *alpha, double *delta){
|
|||||||
*alpha += 86400.; // +24h
|
*alpha += 86400.; // +24h
|
||||||
DBG("A: %g, Z: %g, alp: %g, del: %g", az, zd, *alpha, *delta);
|
DBG("A: %g, Z: %g, alp: %g, del: %g", az, zd, *alpha, *delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -50,9 +50,9 @@ extern void check4running(char **argv, char *pidfilename, void (*iffound)(pid_t
|
|||||||
// Max amount of connections
|
// Max amount of connections
|
||||||
#define BACKLOG (1)
|
#define BACKLOG (1)
|
||||||
// port for connections
|
// port for connections
|
||||||
#define PORT (10000)
|
#define PORT "10000"
|
||||||
// accept only local connections
|
// accept only local connections
|
||||||
#define ACCEPT_IP "127.0.0.1"
|
#define ACCEPT_IP "192.168.3.225"
|
||||||
#define BUFLEN (1024)
|
#define BUFLEN (1024)
|
||||||
|
|
||||||
static uint8_t buff[BUFLEN+1];
|
static uint8_t buff[BUFLEN+1];
|
||||||
@ -154,7 +154,7 @@ typedef struct __attribute__((__packed__)){
|
|||||||
int32_t status;
|
int32_t status;
|
||||||
} outdata;
|
} outdata;
|
||||||
|
|
||||||
#define ACS_CMD(a) do{green(#a); printf("\n");}while(0)
|
#define ACS_CMD(a) do{green(#a); printf("\n"); a; }while(0)
|
||||||
/**
|
/**
|
||||||
* send input RA/Decl (j2000!) coordinates to tel
|
* send input RA/Decl (j2000!) coordinates to tel
|
||||||
* both coords are in seconds (ra in time, dec in angular)
|
* both coords are in seconds (ra in time, dec in angular)
|
||||||
@ -223,9 +223,10 @@ void handle_socket(int sock){
|
|||||||
dout.type = 0;
|
dout.type = 0;
|
||||||
dout.status = 0;
|
dout.status = 0;
|
||||||
while(!global_quit){
|
while(!global_quit){
|
||||||
double r, d, ca, cd;
|
double r, d;//, ca, cd;
|
||||||
calc_AD(val_A, val_Z, S_time, &ca, &cd); // calculate current telescope polar coordinates
|
//calc_AD(val_A, val_Z, S_time, &ca, &cd); // calculate current telescope polar coordinates
|
||||||
calc_mean(ca, cd, &r, &d);
|
//calc_mean(ca, cd, &r, &d);
|
||||||
|
calc_mean(val_Alp, val_Del, &r, &d);
|
||||||
dout.ra = htole32(HRS2RA(r));
|
dout.ra = htole32(HRS2RA(r));
|
||||||
dout.dec = (int32_t)htole32(DEG2DEC(d));
|
dout.dec = (int32_t)htole32(DEG2DEC(d));
|
||||||
if(!send_data((uint8_t*)&dout, sizeof(outdata), sock)) break;
|
if(!send_data((uint8_t*)&dout, sizeof(outdata), sock)) break;
|
||||||
@ -298,20 +299,32 @@ static inline void main_proc(){
|
|||||||
int sock;
|
int sock;
|
||||||
int reuseaddr = 1;
|
int reuseaddr = 1;
|
||||||
// open socket
|
// open socket
|
||||||
struct sockaddr_in myaddr;
|
struct addrinfo hints, *res, *p;
|
||||||
myaddr.sin_family = AF_INET;
|
memset(&hints, 0, sizeof(hints));
|
||||||
myaddr.sin_port = htons(PORT);
|
hints.ai_family = AF_INET;
|
||||||
if(!inet_aton(ACCEPT_IP, (struct in_addr*)&myaddr.sin_addr.s_addr))
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
ERR("inet_aton");
|
hints.ai_flags = AI_PASSIVE;
|
||||||
if((sock = socket(PF_INET, SOCK_STREAM, 0)) == -1){
|
if(getaddrinfo(NULL, PORT, &hints, &res) != 0){
|
||||||
ERR("socket");
|
ERR("getaddrinfo");
|
||||||
}
|
}
|
||||||
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)) == -1){
|
struct sockaddr_in *ia = (struct sockaddr_in*)res->ai_addr;
|
||||||
ERR("setsockopt");
|
char str[INET_ADDRSTRLEN];
|
||||||
}
|
inet_ntop(AF_INET, &(ia->sin_addr), str, INET_ADDRSTRLEN);
|
||||||
if(-1 == bind(sock, (struct sockaddr*)&myaddr, sizeof(myaddr))){
|
// loop through all the results and bind to the first we can
|
||||||
close(sock);
|
for(p = res; p != NULL; p = p->ai_next){
|
||||||
ERR("bind");
|
if((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1){
|
||||||
|
WARN("socket");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)) == -1){
|
||||||
|
ERR("setsockopt");
|
||||||
|
}
|
||||||
|
if(bind(sock, p->ai_addr, p->ai_addrlen) == -1){
|
||||||
|
close(sock);
|
||||||
|
WARN("bind");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break; // if we get here, we must have connected successfully
|
||||||
}
|
}
|
||||||
// Listen
|
// Listen
|
||||||
if(listen(sock, BACKLOG) == -1){
|
if(listen(sock, BACKLOG) == -1){
|
||||||
@ -328,6 +341,20 @@ static inline void main_proc(){
|
|||||||
WARN("accept()");
|
WARN("accept()");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
struct sockaddr_in peer;
|
||||||
|
socklen_t peer_len = sizeof(peer);
|
||||||
|
if (getpeername(newsock, &peer, &peer_len) == -1) {
|
||||||
|
WARN("getpeername()");
|
||||||
|
close(newsock);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
char *peerIP = inet_ntoa(peer.sin_addr);
|
||||||
|
DBG("Peer's IP address is: %s\n", peerIP);
|
||||||
|
if(strcmp(peerIP, ACCEPT_IP) && strcmp(peerIP, "127.0.0.1")){
|
||||||
|
WARNX("Wrong IP");
|
||||||
|
close(newsock);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
handle_socket(newsock);
|
handle_socket(newsock);
|
||||||
}
|
}
|
||||||
close(sock);
|
close(sock);
|
||||||
@ -359,21 +386,18 @@ int main(_U_ int argc, char **argv){
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
if(fabs(M_time - last) < 0.02)
|
if(fabs(M_time - last) < 0.02)
|
||||||
ERRX(_("Data stale!"));
|
ERRX(_("Data stale!"));
|
||||||
//get_cmd_queue(&ucmd, ClientSide);
|
get_cmd_queue(&ucmd, ClientSide);
|
||||||
//passhash pass = {0,0};
|
passhash pass = {0,0};
|
||||||
//get_passhash(&pass);
|
get_passhash(&pass);
|
||||||
printf(_("All OK, start socket\n"));
|
printf(_("All OK, start socket\n"));
|
||||||
|
|
||||||
/*
|
|
||||||
#ifndef EBUG // daemonize only in release mode
|
#ifndef EBUG // daemonize only in release mode
|
||||||
if(!Global_parameters->nodaemon){
|
if(daemon(1, 0)){
|
||||||
if(daemon(1, 0)){
|
ERR("daemon()");
|
||||||
perror("daemon()");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // EBUG
|
#endif // EBUG
|
||||||
*/
|
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
pid_t childpid = fork();
|
pid_t childpid = fork();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user