예제 #1
0
void main()
{
	FCPartitionDesc dbl("dbl","dbl");
	FCPartitionDesc lng("lng","lng");
	FCPartitionDesc charp("charp","charp");
	FCPartitionDesc date("date","date");
	FCPartitionDesc dblx("dblx","dblx");
	FCPartitionDesc lngx("lngx","lngx");
	FCPartitionDesc charpx("charpx","charpx");
	FCPartitionDesc datex("datex","datex");

   PDFriend::MakeADouble(dbl);
	PDFriend::MakeACharPtr(charp);
	PDFriend::MakeALong(lng);
	PDFriend::MakeAColDate(date);


	// test copy constructor..
	FCPartitionDesc dbl2(dbl);
	FCPartitionDesc lng2(lng);
	FCPartitionDesc charp2(charp);
	FCPartitionDesc date2(date);

	dblx = dbl;
	lngx = lng;
	charpx = charp;
	datex = date;


   cout << "dbl----" << endl << dbl ;
   cout << "lng----" << endl << lng ;
   cout << "charp--" << endl << charp ;
   cout << "date---" << endl << date << endl;
   cout << "dbl2----" << endl << dbl2 ;
   cout << "lng2----" << endl << lng2 ;
   cout << "charp2--" << endl << charp2 ;
   cout << "date2---" << endl << date2 << endl;
   cout << "dblx----" << endl << dblx ;
   cout << "lngx----" << endl << lngx ;
   cout << "charpx--" << endl << charpx ;
   cout << "date2x--" << endl << datex << endl;


   cout << dbl.GetDouble() << endl;
   cout << charp.GetCharPtr() << endl;
   cout << lng.GetLong() << endl;
   cout  << date.GetColDate().nMonth   << "/" 
         << date.GetColDate().nDay     << "/"
         << date.GetColDate().nYear    << endl;

}
예제 #2
0
/* wcmd

function fills the datastructure rw

*/
char *
wcmd (struct cmd *pcmd, struct wthio *rw) {
  int ndat = 0;                   /* length of array containing the 
                                     data frame */
  int err;                        /* return value of functions, 
                                     useful for errorhandling */
  int retval = 0;                 
  long snum = 0;                   /* current dataset number */
  int command;
  int argcm;
  unsigned char data[MAXBUFF];    /* data array to store the raw dataframe 
                                     and the message datagram */
  char *clk;                      /* display time in reasonable format */
  char *rbuf;                     /* return buffer */
  

  syslog(LOG_DEBUG, "wcmd: called for command request: %d\n",pcmd->command);  
  rw->wstat.ndats = 0;
  command = pcmd->command; 
  argcm   = pcmd->argcmd; 

  /* first get status of weatherstation 
     needed to fill sens.status
  */
  pcmd->command = 5;
  if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
    rbuf = mkmsg("wcmd: error data reception\n");
    return (rbuf);
  }
  pcmd->command = command;
  syslog(LOG_DEBUG, "wcmd : check status OK\n");

  /* status weatherstation */
  if ( ( rbuf = wstat(data, ndat, rw)) == NULL) {
    rbuf = mkmsg("wcmd: error in subroutine wstat\n");
    return (rbuf);
  }
  
  /* command 0 : poll DCF time */
  if (command == 0) {
    tzset();
	
    /* write command and retrieve data */
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }

    /* calculate seconds since EPOCH if DCF synchronized */
    rw->DCF.time  = dcftime(data, ndat);
    if (rw->DCF.time == -1) {
      rbuf = mkmsg("DCF not synchronized\n");
    }
    else {
      clk = ctime(&rw->DCF.time);
      rbuf = mkmsg("%s", clk);
    }
  }

  /* command 1 : Request Dataset */
  else if (command == 1)  {
    /* first get DCF time if possible */
    pcmd->command = 0;
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }
    pcmd->command = command;

    /* calculate seconds since EPOCH if DCF synchronized */
    rw->DCF.time  = dcftime(data, ndat);

    /* write command and retrieve data */
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }

    /* weather station response : no data available: <DLE> */
    if ( ( ndat == 1 ) && ( data[0] == DLE ) ) {
      rbuf = mkmsg("no data available (<DLE> received)\n");
    }
    /* fill data structure sens */
    else {
      /* get one dataset */
      err = datex(data, ndat, rw);
      syslog(LOG_DEBUG, "wcmd : returncode datex : %d\n", err);
      rw->wstat.ndats = rw->wstat.ndats + 1;
      snum++;
    }

    /* echo sensor data */
    if ( rw->wstat.ndats > 0 )
      rbuf = pdata(rw);
  } 


  /* command 2 : Select next dataset */
  else if (command == 2) {
    /* write the command word to the weather station */ 
    /* extract message datagram */
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }


    /* if DLE no data available */
    if ( ( ndat == 1 ) && ( data[0] == DLE ) ) {
      rbuf = mkmsg("no data available(<DLE> received)\n");
      retval = 16; 
    } else if ( ( ndat == 1 ) && ( data[0] == ACK ) )  {
      /* if ACK next dataset is available */
      rbuf = mkmsg("next dataset available (<ACK> received)\n");
      retval = 6;
    }
    /* exit if unknown response */
    else {
      rbuf = mkmsg("error next dataset : \"unknown response\"\n");
      retval = -1;
    }
  }


  /* command 3 : Activate 8 temperature sensors */
  else if (command == 3) {

    /* write the command word to the weather station */ 
    /* extract message datagram */
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }

    /* weather station response : <ACK> */
    if ( ( ndat == 1 ) && ( data[0] == ACK ) ) {
      rbuf = mkmsg("set 9 temperature sensors (<ACK> received)\n");
    }

    /* update status */
    pcmd->command = 5;
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }
    if ( ( wstat(data, ndat, rw)) == NULL) {
      rbuf = mkmsg("wcmd: error in subroutine wstat\n");
      return (rbuf);
    }	  
  } 


  /* command 4 : Activate 16 temperature sensors */
  else if (command == 4) {

    /* write the command word to the weather station */ 
    /* extract message datagram */
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }

    /* weather station response : <ACK> */
    if ( ( ndat == 1 ) && ( data[0] == ACK ) ) {
      rbuf = mkmsg("set 16 temperature sensors(<ACK> received)\n");
    }

    /* update status */
    pcmd->command = 5;
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }
    if ( ( wstat(data, ndat, rw)) == NULL) {
      rbuf = mkmsg("wcmd: error in subroutine wstat\n");
      return (rbuf);
    }	  
  } 


  /* command 5 : Request status of weatherstation */
  else if ( command == 5 ) {
    ; /* status known, drive thru */
  } 


  /* command 6 : Set logging intervall of weatherstation */
  else if (command == 6) {
    /* write the command word to the weather station */ 
    /* extract message datagram */
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }

    /* weather station response : <ACK> */
    if ( ( ndat == 1 ) && ( data[0] == ACK ) ) {
      rbuf = mkmsg("set logging interval to %d [min] (<ACK> received)\n",
		   pcmd->argcmd);
    }

    /* update status */
    pcmd->command = 5;
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }

    if ( ( wstat( data, ndat, rw)) == NULL) {
      rbuf = mkmsg("wcmd: error in subroutine wstat\n");
      return (rbuf);
    }
  } 


  /* command 12 : 
     Recursively, request dataset and select next dataset, 
     recursive combination of command 1 and 2 
  */
  else if ( ( command == 12) || ( command == 7) )  {      
    /* first get DCF time if possible */
    pcmd->command = 0;
    if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
      rbuf = mkmsg("wcmd: error data reception\n");
      return (rbuf);
    }
    pcmd->command = command;

    /* calculate seconds since EPOCH if DCF synchronized */
    rw->DCF.time  = dcftime(data, ndat);

	  
    while (retval != 16) {
      /* write command and retrieve data */
      pcmd->command = 1;
      if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
	rbuf = mkmsg("wcmd: error data reception\n");
	return (rbuf);
      }

      /* extract dataset from raw dataframe */
      /* weather station response : no data available: <DLE> */
      if ( ( ndat == 1 ) && ( data[0] == DLE ) ) {
	rbuf = mkmsg("no data available (<DLE> received)\n");
	retval = 16;
      }
      /* do extraction */
      else {
	if ( ( err = datex(data, ndat, rw)) == -1) {
	  rbuf = mkmsg("wcmd: error extracting data frame");
	  return (rbuf);
	}
	rw->wstat.ndats = rw->wstat.ndats + 1;
      }
 
      /* write the command word to select next dataset and 
	 retrieve response*/ 
      pcmd->command = 2;
      if ( ( err = getcd( data, &ndat, pcmd)) == -1) {
	rbuf = mkmsg("wcmd: error data reception\n");
	return (rbuf);
      }

      /* stop if DLE no data available, */
      if ( ( ndat == 1 ) && ( data[0] == DLE ) ) {
	/* rbuf = mkmsg(
	   "<DLE> received :\"no data available\"!"); */
	retval = 16; 
      }
      /* if ACK next dataset is available */
      else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) {
	syslog(LOG_DEBUG, \
	       "wcmd: next dataset available (<ACK> received)!\n");
	retval = 6;
      }
      /* return if unknown response */
      /* no data is returned, maybe too strict? */
      else {
	rbuf = mkmsg(
		     "wcmd: error request next dataset : unknown response\n");
	return (rbuf);
      }
      syslog(LOG_DEBUG, "wcmd: retval : %d\n", retval);
    }

    /* echo sensor data */
    if ( rw->wstat.ndats > 0 ) {
      rbuf = pdata(rw);
#if defined POSTGRES
      if ( command == 7 ) {
	if ( ( err = pg_data(rw)) == -1 ) {
	  rbuf = mkmsg("wmcd: postgres error\n") ;
	  return (rbuf);
	}
      }
#endif
    }

  }//command 12 || command 7

  else {
    rbuf = mkmsg("unknown command\n");
  }
  syslog(LOG_DEBUG, "wcmd: exit OK\n");
  return(rbuf);
}//wcmd()