-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEZB.h
134 lines (112 loc) · 2.66 KB
/
EZB.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
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef _EZ_CONN_H
#define _EZ_CONN_H
#include <stdlib.h>
#include <stdio.h>
#include <stdexcept>
#include <errno.h>
#ifdef _WINDOWS
#include "windows_ports.h"
#else
#include <unistd.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <sys/socket.h>
#include <pthread.h>
#endif
#include "ADC.h"
#include "Configuration.h"
#include "Digital.h"
#include "HC_SR04.h"
#include "I2C.h"
#include "Movement.h"
#include "PWM.h"
#include "Servo.h"
#include "SureDualAxisCompass.h"
#include "Tone.h"
#include "Uart.h"
#define KEEP_ALIVE_INTERVAL 2000
class EZB{
private:
long m_socket;
bool m_exit;
bool m_connected;
bool m_verbose;
double m_firmware;
char m_firmware_str[20];
char* m_mac_address;
unsigned char m_keepalive[1];
#ifdef _WINDOWS
_SOCKADDR_BTH m_addr;
CRITICAL_SECTION m_send_mutex;
HANDLE m_keepalive_thread;
#else
struct sockaddr_rc m_addr;
pthread_t m_keepalive_thread;
pthread_mutex_t m_send_mutex;
#endif
long m_lastcommand_time;
void CreateObjects();
bool KeepAlive();
public:
enum CommandEnum{
Unknown = 0,
ReleaseAllServos = 1,
SetSerialMacro = 2,
SetI2CMacro = 3,
WriteConfiguration = 4,
ReadConfiguration = 5,
StatusLED = 6,
I2CStart = 7,
I2CRestart = 8,
I2CStop = 9,
I2CWrite = 10,
I2CRead = 11,
I2CReadAutoAck = 12,
I2CPoll = 13,
BootLoader = 14,
SetPWMSpeed = 15,
BV4113_Cmd = 35,
SetServoSpeed = 40,
Ping = 85,
SetDigitalPortOn = 100,
SetDigitalPortOff = 120,
GetDigitalPort = 140,
SetServoPosition = 160,
GetADCValue = 180,
SendSerial = 190,
HC_SR04 = 210,
PlayNote = 230,
};
ADCClass* ADC;
ConfigurationClass* Configuration;
DigitalClass* Digital;
HC_SR04Class* HCSR04;
I2CClass* I2C;
MovementClass* Movement;
PWMClass* PWM;
ServoClass* Servo;
SureDualAxisCompassClass* SureDualAxisCompass;
ToneClass* Tone;
UartClass* Uart;
EZB();
~EZB();
void Connect(char* mac_address);
void Disconnect();
bool IsConnected();
void SetVerboseLogging(bool verbose);
time_t LastCommandTime();
void SendCommand(unsigned char command);
void SendCommand(unsigned char command, unsigned char* args, int num_args);
unsigned char* SendCommand(unsigned char command, unsigned char* args, int num_args, int expected_ret_bytes);
unsigned char* SendCommand(unsigned char command, int expected_ret_bytes);
void SetLEDStatus(bool status);
char* GetFirmwareVersion();
double GetFirmwareVersionRaw();
void ConnectionCheck();
static const char* VersionNumber();
};
void* ConnectionCheckStub(void* lParam);
#ifdef _WINDOWS
int str2ba(const char* straddr, BTH_ADDR* btaddr);
#endif
#endif