Commit d5ed0bb5 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

compiles with class definition

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 2668
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 538697f8
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: DL1direct.cc,v 1.2 2008-11-24 17:04:59 tforb Exp $
* $Id: DL1direct.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $
* \author Thomas Forbriger
* \date 24/11/2008
*
......@@ -36,12 +36,13 @@
#define DL1DIRECT_VERSION \
"DL1DIRECT V1.0 directly send command to DL1 and receive the response"
#define DL1DIRECT_CVSID \
"$Id: DL1direct.cc,v 1.2 2008-11-24 17:04:59 tforb Exp $"
"$Id: DL1direct.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $"
#include <iostream>
#include <string>
#include <tfxx/commandline.h>
#include <serialxx/serialport.h>
#include "thiesdl1.h"
using std::cout;
using std::cerr;
......@@ -136,30 +137,15 @@ int main(int iargc, char* argv[])
opt.timestring=cmdline.string_arg(4);
if (opt.verbose) { cout << "open port " << opt.device << endl; }
serialport::SerialPort port(opt.device);
if (opt.verbose) { cout << "enable xon/xoff flow control" << endl; }
port.flowxon();
if (opt.verbose) { cout << "set mode 7E1" << endl; }
port.mode7E1();
// activate DL1
if (opt.verbose) { cout << "activate DL1" << endl; }
port.write("0");
::sleep(1);
dl1::DL1 port(opt.device);
// send command
if (opt.verbose) { cout << "send command " << opt.command << endl; }
std::string commandsequence;
commandsequence.append("\x02");
commandsequence.append(opt.command);
commandsequence.append("\x03\r");
port.write(commandsequence);
port.sendcommand(opt.command);
// receive response
std::string response;
if (opt.verbose) { cout << "read response " << endl; }
response=port.read("END");
cout << response << endl;
const int timeout=2;
while (true) { cout << port.getline(timeout) << endl; }
}
/* ----- END OF DL1direct.cc ----- */
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.2 2008-11-25 08:30:54 tforb Exp $
# $Id: Makefile,v 1.3 2008-11-25 09:46:15 tforb Exp $
#
# Copyright (c) 2008 by Thomas Forbriger (BFO Schiltach)
#
......@@ -32,7 +32,7 @@
HEADERS=$(wildcard *.h)
SUBSRC=error.cc dataline.cc record.cc thiesdl1.cc
SUBOBS=$(patsubst %.cc,%.o,$(SUBSERC))
SUBOBS=$(patsubst %.cc,%.o,$(SUBSRC))
all:
......@@ -87,9 +87,9 @@ doxyview: doxyfullview
#======================================================================
DL1direct: %: %.o
$(CXX) $(FLAGS) -o $@ $< -I$(LOCINCLUDEDIR) \
-lserialxx -ltfxx \
DL1direct: %: %.o $(SUBOBS)
$(CXX) $(FLAGS) -o $@ $^ -I$(LOCINCLUDEDIR) \
-lserialxx -ltime++ -ltfxx \
-L$(LOCLIBDIR)
/bin/mv -fv $@ $(LOCBINDIR)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: dataline.cc,v 1.2 2008-11-25 08:37:03 tforb Exp $
* $Id: dataline.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -36,9 +36,9 @@
#define TF_DATALINE_CC_VERSION \
"TF_DATALINE_CC V1.0 "
#define TF_DATALINE_CC_CVSID \
"$Id: dataline.cc,v 1.2 2008-11-25 08:37:03 tforb Exp $"
"$Id: dataline.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $"
#include <dataline.h>
#include "dataline.h"
namespace dl1 {
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: error.cc,v 1.2 2008-11-25 08:37:03 tforb Exp $
* $Id: error.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -36,9 +36,9 @@
#define TF_ERROR_CC_VERSION \
"TF_ERROR_CC V1.0 "
#define TF_ERROR_CC_CVSID \
"$Id: error.cc,v 1.2 2008-11-25 08:37:03 tforb Exp $"
"$Id: error.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $"
#include <error.h>
#include "error.h"
#include <iostream>
using std::cerr;
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: error.h,v 1.2 2008-11-25 08:37:03 tforb Exp $
* $Id: error.h,v 1.3 2008-11-25 09:46:15 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -40,8 +40,7 @@
#define TF_ERROR_H_VERSION \
"TF_ERROR_H V1.0 "
#define TF_ERROR_H_CVSID \
"$Id: error.h,v 1.2 2008-11-25 08:37:03 tforb Exp $"
"$Id: error.h,v 1.3 2008-11-25 09:46:15 tforb Exp $"
namespace dl1 {
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: record.cc,v 1.2 2008-11-25 08:37:04 tforb Exp $
* $Id: record.cc,v 1.3 2008-11-25 09:46:16 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -36,9 +36,9 @@
#define TF_RECORD_CC_VERSION \
"TF_RECORD_CC V1.0 "
#define TF_RECORD_CC_CVSID \
"$Id: record.cc,v 1.2 2008-11-25 08:37:04 tforb Exp $"
"$Id: record.cc,v 1.3 2008-11-25 09:46:16 tforb Exp $"
#include <record.h>
#include "record.h"
namespace dl1 {
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: thiesdl1.cc,v 1.2 2008-11-25 08:37:04 tforb Exp $
* $Id: thiesdl1.cc,v 1.3 2008-11-25 09:46:16 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -36,12 +36,95 @@
#define TF_THIESDL1_CC_VERSION \
"TF_THIESDL1_CC V1.0 "
#define TF_THIESDL1_CC_CVSID \
"$Id: thiesdl1.cc,v 1.2 2008-11-25 08:37:04 tforb Exp $"
"$Id: thiesdl1.cc,v 1.3 2008-11-25 09:46:16 tforb Exp $"
#include <thiesdl1.h>
#include "thiesdl1.h"
#include<iostream>
using std::cout;
using std::endl;
namespace dl1 {
const char* const DL1::EOL="\r\n";
const char* const DL1::STX="\x02";
const char* const DL1::ETX="\x03";
/*----------------------------------------------------------------------*/
DL1::DL1(const std::string& device, const bool& debug):
Mport(device), Mdebug(debug)
{
if (Mdebug) { cout << "DL1 (DEBUG): opened port " << device << endl; }
this->init();
}
/*----------------------------------------------------------------------*/
void DL1::init()
{
if (Mdebug) { cout << "DL1 (DEBUG): enable xon/xoff flow control" << endl; }
Mport.flowxon();
if (Mdebug) { cout << "DL1 (DEBUG): set mode 7E1" << endl; }
Mport.mode7E1();
}
/*----------------------------------------------------------------------*/
void DL1::activate() const
{
if (Mdebug) { cout << "DL1 (DEBUG): activate data logger" << endl; }
Mport.write("0");
::sleep(1);
}
/*----------------------------------------------------------------------*/
void DL1::sendcommand(const std::string& command,
const bool& activate) const
{
if (activate) this->activate();
std::string commandsequence;
commandsequence.append(this->STX);
commandsequence.append(command);
commandsequence.append(this->ETX);
commandsequence.append(this->EOL);
Mport.write(commandsequence);
}
/*----------------------------------------------------------------------*/
std::string DL1::getline(const int& timeout) const
{
std::string retval;
libtime::TAbsoluteTime now=libtime::utc();
const int nbuf=255;
char buffer[nbuf];
bool hot=true;
bool timeisout=false;
Mport.sendxon();
while (hot)
{
int nbytes=Mport.read(buffer, nbuf);
if (Mdebug)
{
std::cout << "DL1 (DEBUG): " << std::endl
<< "read " << nbytes << " characters" << std::endl;
}
if (nbytes>0) { retval.append(buffer, nbytes); }
if (retval.find(DL1::EOL)!=std::string::npos) { hot=false; }
if (timeout>0)
{
libtime::TRelativeTime passed=libtime::utc()-now;
int seconds=int(libtime::time2double(passed));
if (seconds>timeout) { timeisout=true; hot=false; }
}
}
Mport.sendxoff();
if (timeisout) { throw dl1::TimeOut(); }
return(retval);
}
} // namespace dl1
/* ----- END OF thiesdl1.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: thiesdl1.h,v 1.2 2008-11-25 08:37:04 tforb Exp $
* $Id: thiesdl1.h,v 1.3 2008-11-25 09:46:16 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -40,10 +40,79 @@
#define TF_THIESDL1_H_VERSION \
"TF_THIESDL1_H V1.0 "
#define TF_THIESDL1_H_CVSID \
"$Id: thiesdl1.h,v 1.2 2008-11-25 08:37:04 tforb Exp $"
"$Id: thiesdl1.h,v 1.3 2008-11-25 09:46:16 tforb Exp $"
#include<serialxx/serialport.h>
#include<libtime++.h>
namespace dl1 {
/*! timeout exception class
*/
class TimeOut {
}; // class TimeOut
/*! access DL1 data logger via serial port
*/
class DL1 {
public:
//! open device to DL1 logger
DL1(const std::string& device, const bool& debug=false);
//! activate DL1
void activate() const;
/*! read one line of data
* throw TimeOut if time spent is larger than timeout seconds
* and timeout > 0
*/
std::string getline(const int& timeout=0) const;
//! send command string
void sendcommand(const std::string& command,
const bool& activate=true) const;
//! command HH
void sendHH() const { this->sendcommand("HH"); }
//! command PD
void sendPD() const { this->sendcommand("PD"); }
//! command SS
void sendSS() const { this->sendcommand("SS"); }
//! command LL
void sendLL() const { this->sendcommand("LL"); }
//! command MM
void sendMM() const { this->sendcommand("MM"); }
//! command ZZ
void sendZZ() const { this->sendcommand("ZZ"); }
//! command XX
void sendXX() const { this->sendcommand("XX"); }
//! command ts
void sendts(const libtime::TAbsoluteTime& time) const;
//! command ds
void sendds(const libtime::TAbsoluteTime& time) const;
//! command DT
void sendDT(const int& day) const;
//! command DM
void sendDM(const int& month) const;
//! command DJ
void sendDJ(const int& year) const;
//! command ZH
void sendZH(const int& hour) const;
//! command ZM
void sendZM(const int& minute) const;
//! sequence terminating DL1 data lines
static const char* const EOL;
//! character to initiate command
static const char* const STX;
//! character that terminates a command
static const char* const ETX;
private:
//! initialize communication
void init();
//! my serial port that is attached to the DL1
serialport::SerialPort Mport;
//! debug mode
bool Mdebug;
}; // class DL1
} // namespace dl1
#endif // TF_THIESDL1_H_VERSION (includeguard)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment