-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spykee.h
83 lines (65 loc) · 1.88 KB
/
Spykee.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
// ARDrone Controller in C++
// by Pongsak Suvanpong [email protected] or [email protected]
#include <string>
#include <commonc++/StreamSocket.h++>
#include <commonc++/Mutex.h++>
#include <commonc++/Thread.h++>
#include <commonc++/Common.h++>
#include <commonc++/Lock.h++>
#include <commonc++/String.h++>
#include <commonc++/ScopedLock.h++>
#include "../Common/MemoryLibrary.h"
namespace Spykee
{
enum DockState
{
eDontKnow,
eDocked,
eUnDocked,
eDocking
};
struct TelemetryData
{
std::string name;
std::string firmwareVersion;
DockState dockState;
int batteryLevel;
MemoryLibrary::DynamicBuffer image;
MemoryLibrary::DynamicBuffer audio;
void CopyTo(TelemetryData& data)
{
data.name = name;
data.firmwareVersion = firmwareVersion;
data.dockState = dockState;
data.batteryLevel = batteryLevel;
data.image.Allocate(image.size());
image.CopyTo(data.image);
data.audio.Allocate(audio.size());
audio.CopyTo(data.audio);
}
};
class Controller :public ccxx::Runnable
{
public:
Controller();
~Controller();
bool connect(const char* strSpykeeHostName,
const char* strLoginName,
const char* strPassword);
void disconnect();
bool isConnected() {return myStreamSocket != NULL;}
void copyTelemetryDataTo(TelemetryData& data);
void copyImage(MemoryLibrary::DynamicBuffer& buffer);
protected:
void login(const char* strLoginName, const char* strPassword);
size_t readData(MemoryLibrary::Buffer* buffer, int offset, int len);
private:
void run();
void readOnBoardData(bool& bRequestStop);
ccxx::Mutex myMutex;
bool myRequestStop;
TelemetryData myTelemetryData;
ccxx::StreamSocket* myStreamSocket;
ccxx::Thread* myThread;
};
} //namespace Spykee