-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisca.hpp
139 lines (115 loc) · 2.77 KB
/
Visca.hpp
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
#ifndef VISCA
#define VISCA
#include <SPI.h>
#include <EthernetUdp.h>
namespace Visca
{
enum PayloadType
{
VISCACommand = 0x01,
VISCAInquiry = 0x09,
VISCAReply = 0x50
};
enum VISCAType
{
Command = 0x01,
Inquiry = 0x09,
Camera = 0x04,
Position = 0x06
};
enum VISCAError
{
SyntaxError = 0x01,
BufferFullError = 0x03,
MessageLengthError = 0x02
};
enum ControlCommand
{
Reset = 0x01,
ErrorSequence = 0x0F01,
ErrorMessage = 0x0F02
};
enum VISCAPositionCommand
{
NormalPosition = 0x01,
AbsolutePosition = 0x02,
RelativePosition = 0x03,
Home = 0x04,
ResetPosition = 0x05,
Limit = 0x07,
LimitSet = 0x00,
LimitClear = 0x01,
PositionLess = 0x02,
PositionMore = 0x01,
PositionStop = 0x03,
SlowMode = 0x44
};
enum VISCAPositionInquiry
{
PositionInq = 0x12,
SlowModeInq = 0x44,
MaxSpeed = 0x11
};
enum VISCACameraCommand
{
Power = 0x00,
Zoom = 0x07,
Focus = 0x08,
Iris = 0x0B,
Direct = 0x40,
Stop = 0x00,
MoreStandard = 0x02,
LessStandard = 0x03,
MoreVariable = 0x20,
LessVariable = 0x30,
AutoFocus = 0x38
};
enum VISCACameraInquiry
{
PowerInq = 0x00,
ZoomInq = 0x47,
FocusInq = 0x48,
FocusModeInq = 0x38,
IrisInq = 0x4B
};
enum VISCABoolean
{
ON = 0x02,
OFF = 0x03,
Toggle = 0x10
};
struct ViscaCommand
{
bool inquiry;
unsigned char message[12];
int messageLength;
VISCAType type;
};
class ViscaProtocol
{
public:
ViscaProtocol(unsigned int udpPort = 52381) : _udpPort(udpPort){};
~ViscaProtocol();
void begin();
void loop();
bool hasCommand() { return _hasCommand; }
ViscaCommand getCommand();
void sendInquiryResult(unsigned char *value, int size);
void sendError(VISCAError error);
void sendCompletion();
private:
unsigned int _udpPort;
unsigned char _packetBuffer[UDP_TX_PACKET_MAX_SIZE];
unsigned char _commandBuffer[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
bool parseCommand(unsigned int size);
bool parseVISCA(VISCAType type);
EthernetUDP Udp;
unsigned int _payloadType = 0;
unsigned int _payloadLength = 0;
unsigned int _commandType = 0;
bool _hasCommand = false;
unsigned char _replyBuffer[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void sendAck();
};
} // namespace Visca
#endif //VISCA