Merge pull request #3 from fmederos/master
Some minor updates to runsched
This commit is contained in:
commit
fa8d90f0f9
37
runsched.c
37
runsched.c
|
@ -13,6 +13,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#define PORT 7264
|
#define PORT 7264
|
||||||
|
#define MAXPORT 7274
|
||||||
#define IP "127.0.0.1"
|
#define IP "127.0.0.1"
|
||||||
#define LIM 2048
|
#define LIM 2048
|
||||||
#define NMAX 128
|
#define NMAX 128
|
||||||
|
@ -57,12 +58,19 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// Get local time
|
// Get local time
|
||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
rawtime-=3600;
|
//rawtime-=3600;
|
||||||
|
|
||||||
|
|
||||||
// Print UTC time
|
// Print UTC time
|
||||||
ptm=gmtime(&rawtime);
|
ptm=gmtime(&rawtime);
|
||||||
strftime(buf,20,"%Y-%m-%dT%H:%M:%S",ptm);
|
strftime(buf,20,"%Y-%m-%dT%H:%M:%S",ptm);
|
||||||
|
|
||||||
|
// Make raw time UTC to compare with scheduled time
|
||||||
|
rawtime=mktime(ptm);
|
||||||
|
|
||||||
|
// Show current raw time, just to check
|
||||||
|
// printf("%s\n",ctime(&rawtime));
|
||||||
|
|
||||||
// Compute time differences
|
// Compute time differences
|
||||||
for (i=0;i<nobs;i++)
|
for (i=0;i<nobs;i++)
|
||||||
obs[i].dt=difftime(obs[i].ptime,rawtime);
|
obs[i].dt=difftime(obs[i].ptime,rawtime);
|
||||||
|
@ -101,7 +109,7 @@ int fgetline(FILE *file,char *s,int lim)
|
||||||
// Send new position to telescope
|
// Send new position to telescope
|
||||||
void send_position(char *sra,char *sde)
|
void send_position(char *sra,char *sde)
|
||||||
{
|
{
|
||||||
int skt;
|
int skt, port;
|
||||||
struct hostent *he;
|
struct hostent *he;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
char packet[LIM];
|
char packet[LIM];
|
||||||
|
@ -118,25 +126,38 @@ void send_position(char *sra,char *sde)
|
||||||
// Send TCP packet
|
// Send TCP packet
|
||||||
skt=socket(AF_INET,SOCK_STREAM,0);
|
skt=socket(AF_INET,SOCK_STREAM,0);
|
||||||
addr.sin_family=AF_INET;
|
addr.sin_family=AF_INET;
|
||||||
addr.sin_port=htons(PORT);
|
port=PORT;
|
||||||
|
addr.sin_port=htons(port);
|
||||||
he=gethostbyname(IP);
|
he=gethostbyname(IP);
|
||||||
bcopy(he->h_addr,(struct in_addr *) &addr.sin_addr,he->h_length);
|
bcopy(he->h_addr,(struct in_addr *) &addr.sin_addr,he->h_length);
|
||||||
if(connect(skt,(struct sockaddr *) &addr,sizeof(addr))<0) {
|
while((connect(skt,(struct sockaddr *) &addr,sizeof(addr))<0) && (port < MAXPORT)) {
|
||||||
fprintf(stderr,"Connection refused by remote host.\n");
|
fprintf(stderr,"Connection refused by remote host on port %04d.\n",port);
|
||||||
return;
|
port++;
|
||||||
|
// Skip port 7265... used by some other service?
|
||||||
|
if(port==7265) port++;
|
||||||
|
fprintf(stderr,"Trying port %04d.\n",port);
|
||||||
|
|
||||||
|
addr.sin_port=htons(port);
|
||||||
|
he=gethostbyname(IP);
|
||||||
|
bcopy(he->h_addr,(struct in_addr *) &addr.sin_addr,he->h_length);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(port>=MAXPORT) return;
|
||||||
|
|
||||||
|
fprintf(stderr,"Connected on port %04d.\n",port);
|
||||||
|
|
||||||
write(skt,packet,strlen(packet));
|
write(skt,packet,strlen(packet));
|
||||||
close(skt);
|
close(skt);
|
||||||
|
|
||||||
// Set restart
|
// Set restart
|
||||||
file=fopen("/data2/satobs/control/state.txt","w");
|
file=fopen("/data1/satobs/control/state.txt","w");
|
||||||
if (file!=NULL) {
|
if (file!=NULL) {
|
||||||
fprintf(file,"restart");
|
fprintf(file,"restart");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set position
|
// Set position
|
||||||
file=fopen("/data2/satobs/control/position.txt","w");
|
file=fopen("/data1/satobs/control/position.txt","w");
|
||||||
if (file!=NULL) {
|
if (file!=NULL) {
|
||||||
fprintf(file,"%s %s\n",sra,sde);
|
fprintf(file,"%s %s\n",sra,sde);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
Loading…
Reference in a new issue