-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSP.h
121 lines (86 loc) · 1.76 KB
/
RSP.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//RSP: Remote Serial Protocol
#ifndef __RSP__h__
#define __RSP__h__
#include "Port.h"
#include "Socket.h"
#define RSP_DEFAULT_BUFFER_SIZE (4096)
#define HEXVAL(ch) \
((ch) >= '0' && (ch) <= '9'? ch - '0': \
(ch) >= 'a' && (ch) <= 'f'? ch - 'a' + 10: \
(ch) >= 'A' && (ch) <= 'F'? ch - 'A' + 10: -1)
#define HEXCHAR(val) \
(((val & 0xf) <= 9)? (val & 0xf) + '0': (val & 0xf) - 10 + 'a')
namespace gdb {
enum {
STATE_INIT,
STATE_CMD,
STATE_CHECKSUM1,
STATE_CHECKSUM2,
STATE_VERIFIED
};
class RSP
{
class Buffer
{
Socket* s;
size_t len;
size_t size;
char* buf;
char* cur;
int ch;
void
dump(const char* name, const char* ptr, size_t n);
public:
Buffer(Socket* s, size_t size);
~Buffer();
int
peek();
int
getc();
void
ungetc(int ch);
int
putc(int ch);
int
read(void* buf, size_t len);
int
write(const void* buf, size_t len);
int
flush();
};
bool noAckMode;
Buffer recv_buffer;
Buffer send_buffer;
public:
RSP(Socket* s, size_t size = RSP_DEFAULT_BUFFER_SIZE);
~RSP();
enum {
DISCONNECTED = -1,
INTERRUPTED = -2,
OVERFLOWED = -3
};
bool
isInterrupted();
void
setNoAckMode(bool noAckMode);
bool
isNoAckMode() const;
int
receivePacket(char* packet, size_t packet_size);
int
sendPacket(const char* buffer, size_t len = 0);
int
sendPacketFormat(const char* fmt, ...);
int
sendPacketFormatV(const char* fmt, va_list args);
static string
unhexify(const string& str);
static string
hexify(const string& str);
static bool
getNextParamStr(const char* &ptr, string& param);
static bool
getNextParamInt(const char* &ptr, int ¶m, int base = 10);
};
}; // endof namespace gdb
#endif/*__RSP__h__*/