FrelonSerialLine.h 1.73 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
34
35
			    TimeoutReset;
	
	SerialLine(Espia::SerialLine& espia_ser_line);
	
	virtual void write(const std::string& buffer, 
			   bool no_wait = false);
36
37
	virtual void read(std::string& buffer, 
			  int max_len = MaxReadLen, 
38
			  double timeout = TimeoutDefault);
39
40
	virtual void readStr(std::string& buffer, int max_len, 
			     const std::string& term, 
41
			     double timeout = TimeoutDefault);
42
43
	virtual void readLine(std::string& buffer, 
			      int max_len = MaxReadLen, 
44
			      double timeout = TimeoutDefault);
45
46
	virtual void readSingleLine(std::string& buffer, 
				    int max_len = MaxReadLen, 
47
				    double timeout = TimeoutDefault);
48
49
	virtual void readMultiLine(std::string& buffer, 
				   int max_len = MaxReadLen);
50
	
51
52
	virtual void flush();

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

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

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

	int getLastWarning();
65
66
67
68

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


} // namespace Frelon



} // namespace lima


#endif // FRELONSERIALLINE_H