FrelonSerialLine.h 1.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef FRELONSERIALLINE_H
#define FRELONSERIALLINE_H

#include "Frelon.h"

namespace lima
{

namespace Frelon
{

class SerialLine : public HwSerialLine
{
 public:
	enum MsgPart {
		MsgSync, MsgCmd, MsgVal, MsgReq, MsgTerm, 
	};
	
19
20
21
22
23
24
25
26
	enum AnsPart {
		AnsResp, AnsWarn, AnsErr,
	};
	
	enum {
		MaxReadLen = 10000,
	};

ahoms's avatar
ahoms committed
27
28
	typedef std::map<MsgPart, std::string> MsgPartStrMapType;

29
	static const double TimeoutSingle, TimeoutNormal, TimeoutMultiLine, 
30
31
32
33
			    TimeoutReset;
	
	SerialLine(Espia::SerialLine& espia_ser_line);
	
34
35
	Espia::SerialLine& getEspiaSerialLine();

36
37
	virtual void write(const std::string& buffer, 
			   bool no_wait = false);
38
39
	virtual void read(std::string& buffer, 
			  int max_len = MaxReadLen, 
40
			  double timeout = TimeoutDefault);
41
42
	virtual void readStr(std::string& buffer, int max_len, 
			     const std::string& term, 
43
			     double timeout = TimeoutDefault);
44
45
	virtual void readLine(std::string& buffer, 
			      int max_len = MaxReadLen, 
46
			      double timeout = TimeoutDefault);
47
48
	virtual void readSingleLine(std::string& buffer, 
				    int max_len = MaxReadLen, 
49
				    double timeout = TimeoutDefault);
50
51
	virtual void readMultiLine(std::string& buffer, 
				   int max_len = MaxReadLen);
52
	
53
54
	virtual void flush();

55
	virtual void getNbAvailBytes(int &avail);
56
	
57
58
59
	virtual void setTimeout(double timeout);
	virtual void getTimeout(double& timeout) const;

60
	void splitMsg(const std::string& msg, 
ahoms's avatar
ahoms committed
61
		      MsgPartStrMapType& msg_parts) const;
62
63
64
65
66
	void decodeFmtResp(const std::string& ans, std::string& fmt_resp);

	void sendFmtCmd(const std::string& cmd, std::string& resp);

	int getLastWarning();
67
68
69
70

 private:
	Espia::SerialLine& m_espia_ser_line;
	bool m_multi_line_cmd;
71
	bool m_reset_cmd;
72
	int m_last_warn;
73
74
75
76
77
78
79
80
81
82
83
};


} // namespace Frelon



} // namespace lima


#endif // FRELONSERIALLINE_H