-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDevice.h
More file actions
203 lines (179 loc) · 3.43 KB
/
Copy pathDevice.h
File metadata and controls
203 lines (179 loc) · 3.43 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
* File: Device.h
* Author: tomko
*
* Created on 26 marzec 2012, 23:24
*/
#ifndef DEVICE_H
#define DEVICE_H
#include <string>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <ostream>
#include <istream>
/**
* Klasa Device odpowiada urządzeniu bluetooth. Pozwala na wysyłanie i odbieranie informacji z urządzeniem zdalnym.
*/
class Device
{
public:
class ConnectionError
{
public:
ConnectionError(std::string n, std::string m, std::string a) : name(n), MAC(m), action(a)
{
};
std::string GetMAC() const
{
return MAC;
}
std::string GetName() const
{
return name;
}
std::string GetAction() const
{
return action;
}
private:
std::string MAC;
std::string name;
std::string action;
};
Device();
/**
* Kontruktor kopiujący. Kopiuje tylko dane urządzenia, połączenie trzeba tworzyć od nowa.
* @param c Urządzenie do skopiowania.
*/
Device(const Device & c);
Device(std::string M, std::string n) : MAC(M), name(n)
{
my_socket = 0;
}
virtual ~Device();
std::string getMAC() const
{
return MAC;
}
void setMAC(std::string MAC)
{
this->MAC = MAC;
}
std::string getName() const
{
return name;
}
void setName(std::string name)
{
this->name = name;
}
uint8_t getPort() const
{
return port;
}
/**
* Funkcja ustawiająca port, z którym chcemy się połączyć.
* @param to_send Numer portu.
*/
void setPort(uint8_t port)
{
this->port = port;
}
/**
* Funkcja wysyłająca int na dane urządzenie.
* @param to_send int do wysłania.
*/
void sendInt(int to_send) throw (Device::ConnectionError);
/**
* Funkcja wysyłająca jeden znak.
* @param to_send Znak, który chcemy wysłać
*/
virtual void sendChar(char to_send) throw (Device::ConnectionError);
/**
* Funkcja odbierająca 4 bajty z urządzenia zdalnego traktowane jako 4-bajtowa liczba bez znaku z kolejnością bajtów "little endian"
* @return Liczba bez znaku.
*/
virtual u_int32_t receiveUInt4() throw (Device::ConnectionError);
/**
* Funkcja odbierająca jeden bajt z urządzenia zdalnego traktowany jako char.
* @return Odebrany bajt jako char.
*/
char receiveUChar() throw (Device::ConnectionError);
/**
* Funkcja łącząca z urządzeniem.
*/
virtual void startConnection();
/**
* Funkcja zamykająca połączenie, a co z tym idzie i połączenie.
*/
virtual void stopConnection();
private:
std::string MAC;
std::string name;
uint8_t port;
struct sockaddr_rc sock_addr_send;
struct sockaddr_rc sock_addr_rec;
int my_socket;
void createSockAddrSend();
void createSockAddrSend(uint8_t port);
void createSockAddrRec();
void clearSockRec();
};
/**
* Funkcja zapisująca Device (nazwę, MAC i port) do std::ostream.
* @param o std::ostream do którego jest zapis.
* @param d Device, który jest zapisywany.
* @return std::ostrema do którego jest zapis.
*/
std::ostream& operator<<(std::ostream& o, Device &d);
/**
* Funkcja wczytująca Device (nazwę, MAC i port) z std::istream.
* @param i std::istream z którego jest odczyt.
* @param d Device, który jest wczytywany.
* @return std::istream z którego jest zapis.
*/
std::istream& operator>>(std::istream& i, Device &d);
#endif /* DEVICE_H */
/*
wyjście
153
0
0
0
0
0
0
0
0
0
0
0
156
0
0
0
0
0
0
0
0
0
0
0
155
0
0
0
0
0
0
0
0
0
0
0
152
0
0
0
*/