fujikininterface.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #ifndef FUJIKININTERFACE_H_
15 #define FUJIKININTERFACE_H_
16 
17 #include "charinterface.h"
18 #include "chardevicedriver.h"
19 
21 public:
22  XFujikinInterface(const char *name, bool runtime, const shared_ptr<XDriver> &driver);
23  virtual ~XFujikinInterface();
24 
25  template <typename T>
26  void send(uint8_t classid, uint8_t instanceid, uint8_t attributeid, T data);
27  template <typename T>
28  T query(uint8_t classid, uint8_t instanceid, uint8_t attributeid);
29 protected:
30  virtual void open() throw (XInterfaceError &);
31  //! This can be called even if has already closed.
32  virtual void close() throw (XInterfaceError &);
33 
34  virtual bool isOpened() const {return !!m_openedPort;}
35 private:
36  void communicate_once(uint8_t classid, uint8_t instanceid, uint8_t attributeid,
37  const std::vector<uint8_t> &data, std::vector<uint8_t> *response);
38  void communicate(uint8_t classid, uint8_t instanceid, uint8_t attributeid,
39  const std::vector<uint8_t> &data, std::vector<uint8_t> *response = 0);
40 
41  shared_ptr<XPort> m_openedPort;
42  static XMutex s_lock;
43  static std::deque<weak_ptr<XPort> > s_openedPorts; //guarded by s_lock.
44 
45  enum {STX = 0x02, ACK = 0x06, NAK = 0x16};
46 };
47 
48 template <class T>
49 class XFujikinProtocolDriver : public XCharDeviceDriver<T, XFujikinInterface> {
50 public:
51  XFujikinProtocolDriver(const char *name, bool runtime,
52  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
53  XCharDeviceDriver<T, XFujikinInterface>(name, runtime, ref(tr_meas), meas) {}
54  virtual ~XFujikinProtocolDriver() {};
55 };
56 
57 #endif /*FUJIKININTERFACE_H_*/

Generated for KAME4 by  doxygen 1.8.3