Ejemplo n.º 1
0
/**
 * @brief Destroyes the log stream
 *
 **/
ParserLogger::LogStream::~LogStream()
{
	if(!value.str().empty())
	{
		logger->logToStream(category, logvalue());
	}
}
Ejemplo n.º 2
0
void father(char *svname, int loop)
{
  pid_t p_id;
  int killed = 0;

  p_id = fork();
  if (p_id < 0)
  {
    printf("Fork failed in svwatch.\n");
    exit (-1);
  }
  if (p_id > 0)
  {
    printf("Luke, I'm your father.\n");
    while (loop && !killed)
    {
      if (waitpid(p_id, NULL, WNOHANG) > 0)
      {
	killed = 1;
	logvalue(p_id, svname);
	father(svname, loop);
      }
    }
  }
  if (p_id == 0)
    child(svname);
}
Ejemplo n.º 3
0
int main()
     
{
  
  struct hostent *hp; /* = gethostbyname(argv[1]);*/
  char record[60];
  modbus_t *mb;

  
  uint16_t tab_secondi[50];
  int nregs_secondi=48; /* 0..47 num. registri da leggere*/
  int addr_secondi=151; /* indirizzo primo registro da leggere */

  uint16_t tab_scatti[50];
  int nregs_scatti=48;
  int addr_scatti=100;

  uint16_t tab_oraplc[10];
  int nregs_oraplc=1;
  int addr_oraplc=150;

  int i;
  
  date_string(dat);
  set_logname();
  
  /*************************************/
  hp=gethostbyname(HOST); /* lo ricalcolo sempre perche' l'ip del GH potrebbe cambiare */
  mb = modbus_new_tcp( (char*)inet_ntoa( *( struct in_addr*)( hp -> h_addr_list[0])), PORT);      

  if ( modbus_connect(mb) == -1) {
    /*Errore di comunicazione*/
    printf("ERRORE1\n");
    date_string(dat); /* imposto il timestamp per il log */
    snprintf(record,(size_t)60,"%s-%s-%s;%s;%s",dat[GIORNO],dat[MESE],dat[ANNO],dat[ORA],"Communication error");
    logvalue(LOG_FILE,record); /* scrivo su file di log l'errore */
    modbus_free(mb); /* ripulisco il context */
    exit(1);
  } else { /* connessione OK, vado a leggere i registri */
    
    /***********************************************/
    /* Reads nregs registers from the address addr */
    /***********************************************/
    if ( (modbus_read_registers(mb, addr_secondi, nregs_secondi, tab_secondi) == -1) ||
	 (modbus_read_registers(mb, addr_scatti,  nregs_scatti,  tab_scatti)  == -1) ||
	 (modbus_read_registers(mb, addr_oraplc,  nregs_oraplc,  tab_oraplc)  == -1) ) {
      /* Errore di lettura */
      printf("ERRORE2\n");
      date_string(dat); /* imposto il timestamp per il log */
      snprintf(record,(size_t)60,"%s-%s-%s;%s;%s",dat[GIORNO],dat[MESE],dat[ANNO],dat[ORA],"Communication error");
      logvalue(LOG_FILE,record); /* scrivo su file di log l'errore */
      modbus_close(mb);
      modbus_free(mb); /* ripulisco il context */
      exit(1);
    } else { /* non ci sono stati errori di comunicazione e di lettura */
      /***********************************************/
      /* stampo i registri letti                     */
      /***********************************************/
      /*ora;secondi_utoclave;secondi_pozzo;scatti_autoclave;scatti_pozzo */
      for (i=0;i<=tab_oraplc[0];i++) {
	printf("%d.30;%d;%d;%d;%d",i,tab_secondi[i],tab_secondi[i+24],tab_scatti[i],tab_scatti[i+24]);
	printf("\n");
      }
#ifdef _DB_

      /* 
	 record ora contiene la data in formato yyyymmdd e anche l'ora nel formato ora:30
      */
      
      strftime(record,sizeof(record),"%Y%m%d",date_string(dat));
      
      /*
	update("secondi", record, tab_oraplc[0], tab_secondi);
	update("scatti",  record, tab_oraplc[0], tab_scatti);
      */
      
      update("ss", record, tab_oraplc[0], tab_secondi, tab_scatti);

#endif        
      modbus_close(mb);
      modbus_free(mb);  
    }
    
  }
  return 0; 
}