Changeset 143


Ignore:
Timestamp:
01/18/10 07:51:43 (15 years ago)
Author:
ogrimm
Message:
Updates to DIM paths
Location:
tools/SkyQualityMonitor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tools/SkyQualityMonitor/Makefile

    r134 r143  
    22
    33PROG=sqm
    4 CPPFLAGS += -I../../Evidence/DIM/
    5 LDLIBS += -lpthread
     4CPPFLAGS += -I../../Evidence -I$(DIMDIR)/dim
     5LDLIBS += -lpthread $(DIMDIR)/linux/libdim.a
    66
    7 $(PROG): $(PROG).o ../../Evidence/Evidence.o ../../Evidence/DIM/libdim.a
     7$(PROG): $(PROG).o ../../Evidence/Evidence.o
    88
    99clean:
  • tools/SkyQualityMonitor/sqm.cpp

    r130 r143  
    1717
    1818#define SERVER_NAME "SQM"       // Name to use in DIM
    19 #include "../Evidence.h"
     19#include "Evidence.h"
    2020
    2121#define READ_CMD "rx"           // Command to read from device
     
    3030  fd_set ReadFileDescriptor;
    3131  time_t Time;
     32  unsigned int Period;
    3233 
    3334  // Start server and request configuration data
     
    3536  char *Address = Srv.GetConfig(SERVER_NAME " address");
    3637  unsigned int Port = atoi(Srv.GetConfig(SERVER_NAME " port"));
    37   unsigned int Period = atoi(Srv.GetConfig(SERVER_NAME " period"));
    3838   
    3939  // Open socket descriptor
    4040  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));
    4242  }
    4343   
     
    4545  struct hostent *hostent = gethostbyname(Address);
    4646  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));
    4848  }
    4949
     
    5454 
    5555  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));
    5757  }
    5858
    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);
    6060  signal(SIGPIPE,SIG_IGN);  // Do not kill process if writing to closed socket
    6161
     
    6363  double sqm_reading=0.0;
    6464  char Buffer[BUF_SIZE];
     65 
    6566  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);
    6768
    6869  while(!EvidenceServer::ExitRequest) {
     70        // Request measurement period 
     71    Period = atoi(Srv.GetConfig(SERVER_NAME " period"));
     72
    6973    // Write read command to socket
    7074    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);
    7276    }
    7377   
    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);   
    7881    FD_SET(SocketDescriptor, &ReadFileDescriptor);
    7982    struct timeval WaitTime = {Period, 0};
    8083    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));
    8285    }
    8386
    8487    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);
    8689      continue;
    8790    }
     
    8992    memset(Buffer, 0, BUF_SIZE);
    9093    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");
    9295    }
    9396
     
    9598    for (int i=0; i<strlen(Buffer); i++) if (Buffer[i] == '\n') Buffer[i] = '\0';
    9699    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
    100104    Time = time(NULL);
    101105    printf("%s\n %s CTRL-c to exit.\r", Buffer, asctime(localtime(&Time)));
    102106    fflush(stdout);
    103     sleep(Period/2); // Wait second half period here
    104  
     107       
     108    sleep(Period);
    105109  } // while()
    106110
Note: See TracChangeset for help on using the changeset viewer.