UniSet  2.6.0
ComPort485F.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
17 #ifndef COMPORT_485F_H_
18 #define COMPORT_485F_H_
19 // --------------------------------------------------------------------------
20 #include <queue>
21 #include "ComPort.h"
22 #include "PassiveTimer.h"
23 // --------------------------------------------------------------------------
24 namespace uniset
25 {
37  class ComPort485F:
38  public ComPort
39  {
40  public:
41 
42  ComPort485F( const std::string& comDevice, int gpio_num, bool tmit_ctrl = false );
43 
44  virtual void sendByte( unsigned char x ) override;
45  virtual void setTimeout( timeout_t timeout ) override;
46  virtual size_t sendBlock( unsigned char* msg, size_t len ) override;
47 
48  virtual void cleanupChannel() override;
49  virtual void reopen() override;
50 
51  protected:
52 
53  virtual unsigned char m_receiveByte( bool wait ) override;
54  void save2queue(unsigned char* msg, size_t len, size_t bnum );
55  bool remove_echo( unsigned char tb[], size_t len );
56  void m_read( timeout_t tmsec );
57 
59  unsigned char tbuf[ComPort::BufSize];
60 
61  std::queue<unsigned char> wq;
62  std::queue<unsigned char> rq;
64  int gpio_num;
65  bool tmit_ctrl_on;
66  PassiveTimer ptRecv;
67  timeout_t tout_msec = { 2000 };
68  };
69  // -------------------------------------------------------------------------
70 } // end of uniset namespace
71 // --------------------------------------------------------------------------
72 #endif // COMPORT_485F_H_
73 // --------------------------------------------------------------------------