Changeset 143
- Timestamp:
- 01/18/10 07:51:43 (15 years ago)
- Location:
- tools/SkyQualityMonitor
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/SkyQualityMonitor/Makefile
r134 r143 2 2 3 3 PROG=sqm 4 CPPFLAGS += -I../../Evidence /DIM/5 LDLIBS += -lpthread 4 CPPFLAGS += -I../../Evidence -I$(DIMDIR)/dim 5 LDLIBS += -lpthread $(DIMDIR)/linux/libdim.a 6 6 7 $(PROG): $(PROG).o ../../Evidence/Evidence.o ../../Evidence/DIM/libdim.a7 $(PROG): $(PROG).o ../../Evidence/Evidence.o 8 8 9 9 clean: -
tools/SkyQualityMonitor/sqm.cpp
r130 r143 17 17 18 18 #define SERVER_NAME "SQM" // Name to use in DIM 19 #include " ../Evidence.h"19 #include "Evidence.h" 20 20 21 21 #define READ_CMD "rx" // Command to read from device … … 30 30 fd_set ReadFileDescriptor; 31 31 time_t Time; 32 unsigned int Period; 32 33 33 34 // Start server and request configuration data … … 35 36 char *Address = Srv.GetConfig(SERVER_NAME " address"); 36 37 unsigned int Port = atoi(Srv.GetConfig(SERVER_NAME " port")); 37 unsigned int Period = atoi(Srv.GetConfig(SERVER_NAME " period"));38 38 39 39 // Open socket descriptor 40 40 if ((SocketDescriptor = socket(PF_INET, SOCK_STREAM, 0)) == -1) { 41 Srv. Msg(Srv.FATAL, "Could not open socket (%s)", strerror(errno));41 Srv.State(Srv.FATAL, "Could not open socket (%s)", strerror(errno)); 42 42 } 43 43 … … 45 45 struct hostent *hostent = gethostbyname(Address); 46 46 if (hostent==0) { 47 Srv. Msg(Srv.FATAL, "Could not resolve host name '%s' (%s)", Address, hstrerror(h_errno));47 Srv.State(Srv.FATAL, "Could not resolve host name '%s' (%s)", Address, hstrerror(h_errno)); 48 48 } 49 49 … … 54 54 55 55 if (connect(SocketDescriptor, (struct sockaddr *) &SocketAddress, sizeof(SocketAddress))==-1) { 56 Srv. Msg(Srv.FATAL, "Could not connect to server '%s' on port %d (%s)", Address, Port, strerror(errno));56 Srv.State(Srv.FATAL, "Could not connect to server '%s' on port %d (%s)", Address, Port, strerror(errno)); 57 57 } 58 58 59 Srv. Msg(Srv.INFO, "Connected to server '%s' on port %d", Address, Port);59 Srv.State(Srv.INFO, "Connected to server '%s' on port %d", Address, Port); 60 60 signal(SIGPIPE,SIG_IGN); // Do not kill process if writing to closed socket 61 61 … … 63 63 double sqm_reading=0.0; 64 64 char Buffer[BUF_SIZE]; 65 65 66 DimService SQM_Brightness(SERVER_NAME"/NSB", sqm_reading); 66 DimService SQM_Response(SERVER_NAME"/Response", Buffer);67 DimService SQM_Response(SERVER_NAME"/Response", NO_LINK); 67 68 68 69 while(!EvidenceServer::ExitRequest) { 70 // Request measurement period 71 Period = atoi(Srv.GetConfig(SERVER_NAME " period")); 72 69 73 // Write read command to socket 70 74 if ((write(SocketDescriptor, READ_CMD, strlen(READ_CMD)))<1) { 71 Srv. Msg(Srv.ERROR, "Could not write read command '%s' to socket.", READ_CMD);75 Srv.State(Srv.ERROR, "Could not write read command '%s' to socket.", READ_CMD); 72 76 } 73 77 74 // Wait for data from socket with time-out 75 sleep(Period/2); // Wait half period to allow for response 76 77 FD_ZERO(&ReadFileDescriptor); 78 // Wait for response (minimum 100 ms) 79 usleep(100000); 80 FD_ZERO(&ReadFileDescriptor); 78 81 FD_SET(SocketDescriptor, &ReadFileDescriptor); 79 82 struct timeval WaitTime = {Period, 0}; 80 83 if (select(((int) SocketDescriptor)+1, &ReadFileDescriptor, NULL, NULL, &WaitTime)==-1) { 81 Srv. Msg(Srv.FATAL, "Error with select() (%s)", strerror(errno));84 Srv.State(Srv.FATAL, "Error with select() (%s)", strerror(errno)); 82 85 } 83 86 84 87 if (!FD_ISSET(SocketDescriptor, &ReadFileDescriptor)) { 85 Srv. Msg(Srv.WARN, "Time-out of %d seconds expired before receiving response from socket", Period);88 Srv.State(Srv.WARN, "Time-out of %d seconds expired before receiving response from socket", Period); 86 89 continue; 87 90 } … … 89 92 memset(Buffer, 0, BUF_SIZE); 90 93 if(read(SocketDescriptor, Buffer, BUF_SIZE) == 0) { 91 Srv. Msg(Srv.FATAL, "Server not existing anymore, exiting...\n");94 Srv.State(Srv.FATAL, "Server not existing anymore, exiting...\n"); 92 95 } 93 96 … … 95 98 for (int i=0; i<strlen(Buffer); i++) if (Buffer[i] == '\n') Buffer[i] = '\0'; 96 99 sqm_reading = strtod(Buffer+2 ,NULL); 97 SQM_Brightness.updateService(); 98 SQM_Response.updateService(); 99 100 101 SQM_Brightness.updateService(sqm_reading); 102 SQM_Response.updateService(Buffer); 103 100 104 Time = time(NULL); 101 105 printf("%s\n %s CTRL-c to exit.\r", Buffer, asctime(localtime(&Time))); 102 106 fflush(stdout); 103 sleep(Period/2); // Wait second half period here 104 107 108 sleep(Period); 105 109 } // while() 106 110
Note:
See TracChangeset
for help on using the changeset viewer.