-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvi_ex_ter.h
78 lines (59 loc) · 1.73 KB
/
vi_ex_ter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef VI_EX_TER_H
#define VI_EX_TER_H
#include <fstream>
#include <iostream>
#include <ios>
#include "vi_ex_cell.h"
/*!
\class vi_ex_cell
\brief high level function for autoconnect & human terminal
merge of vi_ex_cell & hi_ex_hid
*/
class vi_ex_ter : public vi_ex_hid, public vi_ex_cell
{
private:
std::string cmd;
std::istream *hi; /*!< human terminal enter for text commands*/
protected:
/*! \brief high level callback (only for relevant packet, omits intrenal control packet) */
virtual void callback_rx_new(t_vi_exch_dgram *){;}
public:
/*! \brief text command
\return text response
response is explicitly expecting; timeout in another case
*/
std::string command(const std::string &ord){
char rcv[VIEX_HID_SP];
if(vi_ex_hid::submit(ord.c_str()) == vi_ex_io::VI_IO_OK) //translate to binary
if(vi_ex_hid::receive(rcv, VIEX_HID_SP) == vi_ex_io::VI_IO_OK) //wait for reply & translate to text
return std::string(rcv); //return
return std::string(); //fail
}
/*! \brief command line refresh & execution
*/
void refreshcmdln(){
if(NULL == hi) return;
hi->sync();
int c;
while(EOF != (c = hi->get())){
if((c != '\n') && (c != '\r')){
cmd.push_back(c);
} else {
vi_ex_hid::submit(cmd.c_str()); //execute
cmd.clear();
}
}
}
/*! \brief contructor
*/
vi_ex_ter(p_vi_io_mn _name, std::istream *_hi, std::ostream *_p_trace = &std::cout):
vi_ex_cell(_name, _p_trace), hi(_hi)
{
}
/*! \brief destructor
*/
virtual ~vi_ex_ter(void)
{
}
};
#endif // VI_EX_TER_H