dio  130
API Documentation
dino.hxx
Go to the documentation of this file.
1 #ifndef _DINO_DINO_HXX_
2 #define _DINO_DINO_HXX_
3 
4 #include <map>
5 #include <sstream>
6 #include <vector>
7 #include "umi/umi_task.hxx"
8 #include "dino/umipro_dino.hxx"
9 #include "cplRaw/sm.hxx"
10 
15 namespace INdepUmi100 {
16  class RunIo ;
17  class UseIo {
18  RunIo* _pur;
19  public:
20 
21  RunIo* pur() { return _pur; }
22  UseIo(RunIo *pur):_pur(pur) { }
23  ~UseIo() { }
24  };
25  class RunIo {
26  UseIo *_pui;
27  class Chan:public SmM {
28  ChanUser *_pcu;
29  public:
30  ChanUser *pcu() { return _pcu; }
31  Chan(ChanUser *pcu=0):_pcu(pcu) {}
32  ~Chan() {}
33  };
34  std::vector<Chan> _vccn;
35  typedef std::vector<Chan>::iterator ItCn;
36  enum { sIdle, sSend, sRecv };
37  public:
38  ChanUser *pucIo() { return _vccn.at(0).pcu() ; }
39 
40  int run();
41  void init(UseIo *pui) { _pui=pui; }
42  void add(ChanUser *pucIo) {
43  _vccn.push_back(Chan(pucIo));
44  }
45  RunIo():_pui(0) { }
46  };
47 }
48 
50 namespace INdepDino100 {
51  namespace Umi=INdepUmi100 ;
52  const Dino_dino_Proto theDino_dino_Proto ;
53 
57  typedef int BitHandle;
58  inline BitHandle bitHandle(int iBits, int iIndex, int f) { return ((iBits << 24) | (iIndex << 16) | f); }
59  inline int ibits(BitHandle bh) { return bh >> 24; }
60  inline int index(BitHandle bh) { return (bh >> 16) & 0xff; }
61  inline unsigned char flag(BitHandle bh) { return bh & 0xff; }
62  enum { bhNil = 0 }; /* not a BitHandle */
63 
64  /*
65  * Multiple named channel client plexer
66  */
67  class MultiPlex : protected std::vector<Umi::TaskFunc> , public Umi::Plexer, public Umi::TaskUser {
68  const Umi::Proto *_pup;
69  std::map<std::string, unsigned> _mpsi;
70  typedef std::map<std::string, unsigned>::iterator ItSi;
71 
72  /*
73  * find port, nonzero if unknown
74  */
75  protected:
76  int findPort(std::string *psgPort, const std::string &sgPath);
77  Umi::TaskFunc *pta(int i) { return &at(i); }
78 
79  /* implement Plexer */
80  void sigDown(int iCtx, Channel *pcn, int hChan) { pta(hChan)->sigDown(iCtx, pcn); }
81  void sigUp(int iCtx, Channel *pcn, int hChan) { pta(hChan)->sigUp(iCtx, pcn); }
82 
83 
84  public:
85  int init(const std::string &sg, Umi::Channel *pcn);
86  MultiPlex(const UmiProto *pup);
87  ~MultiPlex();
88  };
89 
93  class DinoPlex:public MultiPlex, public Failable {
94  struct Bits {
95  unsigned char _mpucOut[16]; /* IO bits */
96  unsigned char _mpucIn[16];
97  size_t _sIn, _sOut;
98  Bits(): _sIn(4), _sOut(4) {
99  memset(_mpucOut, 0, sizeof(_mpucOut));
100  memset(_mpucIn, 0, sizeof(_mpucIn));
101  }
102  ~Bits() { }
103  };
104  std::vector<Bits> _vcbi;
105  typedef std::vector<Bits>::const_iterator IcBi;
106  friend class DinoSyncClientFunc;
107 
108  public:
109  bool getBit(BitHandle bh) { return _vcbi[ibits(bh)]._mpucOut[index(bh)] & flag(bh); }
110  void setBit(BitHandle bh) { _vcbi[ibits(bh)]._mpucOut[index(bh)] |= flag(bh); }
111  void clrBit(BitHandle bh) { _vcbi[ibits(bh)]._mpucOut[index(bh)] &= ~flag(bh); }
112  void setBit(BitHandle bh, bool b) { return b ? setBit(bh) : clrBit(bh); }
113 
114  bool isBit(BitHandle bh) { return _vcbi[ibits(bh)]._mpucIn[index(bh)] & flag(bh); }
115 
116  std::ostream &print(std::ostream &os);
117 
118  int startOpen(const std::string &sgPort);
119  BitHandle doneOpen(int i);
120  void startSync();
121  int doneSync();
122 
123  int init(const std::string &sg, Umi::Channel *pcn);
124 
125 
126  DinoPlex():MultiPlex(&theDino_dino_Proto) {
127  }
128  };
129 
130 
131 
135  class DinoPlexSync:public DinoPlex, public Umi::UseIo {
136  bool _fRun;
137 
138  void done(Umi::Task *pta) ;
139 
140  public:
148  BitHandle callOpen(const std::string &sgPort);
149 
155  int callSync();
156 
157 
158  DinoPlexSync( Umi::RunIo *pur );
159  ~DinoPlexSync( );
160  };
161 }
162 #endif
163 
int BitHandle
A BitHandle is a compact (integer-type) representation of a bit at a port.
Definition: dino.hxx:57
Dino Protocol Plexer.
Definition: dino.hxx:93
Definition: dino.hxx:17
Dino Protocol Plexer with blocking functions.
Definition: dino.hxx:135
namespace for the ines Digital I/O (Dino) interface
Definition: dino.hxx:50
base class for something that does have a failed/good state.
Definition: failable.hxx:13
Definition: dino.hxx:15