-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBGT24LTR11.h
145 lines (126 loc) · 5.68 KB
/
BGT24LTR11.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
135
136
137
138
139
140
141
142
143
144
145
#ifndef __BGT24LTR11__
#define __BGT24LTR11__
#include "Arduino.h"
//address code
#define BGT24LTR11_MESSAGE_HEAD 0x55
#define BGT24LTR11_RECEIVE_ADDRESS 0x2A
#define BGT24LTR11_SEND_ADDRESS 0xA2
//command code
#define BGT24LTR11_COMMAND_GET_TARGET 0xC1
#define BGT24LTR11_COMMAND_GET_IQADC 0xC2
#define BGT24LTR11_COMMAND_SET_SPEED_SCOPE 0xC3
#define BGT24LTR11_COMMAND_GET_SPEED_SCOPE 0xC4
#define BGT24LTR11_COMMAND_SET_MODE 0xC5
#define BGT24LTR11_COMMAND_GET_MODE 0xC6
#define BGT24LTR11_COMMAND_SET_THRESHOLD 0xC7
#define BGT24LTR11_COMMAND_GET_THRESHOLD 0xC8
// target state
#define BGT24LTR11_TARGET_APPROACH 0x02
#define BGT24LTR11_TARGET_LEAVE 0x01
#define BGT24LTR11_TARGET_NONE 0x00
//mode
#define BGT24LTR11_MODE_TARGET 0x00
#define BGT24LTR11_MODE_IQADC 0x01
template <class T>
class BGT24LTR11 {
private:
T* _serial;
unsigned char commandC1[7] = {BGT24LTR11_MESSAGE_HEAD, BGT24LTR11_RECEIVE_ADDRESS,
BGT24LTR11_COMMAND_GET_TARGET,
0x00, 0x02, 0x01, 0x42
};
/* data */
public:
/****************************************************************
Function Name: init
Description: hand over serial port where module is connected to
Parameters: serialPort
Return: void
****************************************************************/
void init(T& serialPort);
/****************************************************************
Function Name: getInfo
Description: Get target state and speed in one call
Parameters: targetState, speed
Return: 1:success 0:fail
****************************************************************/
uint8_t getInfo(uint16_t* target_tate, uint16_t* speed);
/****************************************************************
Function Name: getSpeed
Description: Target acquisition speed
Parameters: None
Return: >0:success speed -1:fail
****************************************************************/
uint16_t getSpeed();
/****************************************************************
Function Name: getTargetState
Description: Get target state
Parameters: None
Return: 2:target approach 1:target leave 0:Not Found target or error
****************************************************************/
uint16_t getTargetState();
/****************************************************************
Function Name: getIQADC
Description: Gets the I/Q information ADC value.
Parameters: I_d,Q_d,Store an array of I/Q information. len,The length of the array.
Return: 1:success 0:fail
****************************************************************/
uint8_t getIQADC(uint16_t I_d[], uint16_t Q_d[], uint16_t* len);
/****************************************************************
Function Name: setSpeedScope
Description: Set the detection speed range.
Parameters: maxspeed,minspeed 0-65535
Return: 1:success 0:fail
****************************************************************/
uint8_t setSpeedScope(uint16_t maxspeed, uint16_t minspeed);
/****************************************************************
Function Name: getSpeedScope
Description: Get the detection speed range.
Parameters: maxspeed,minspeed
Return: 1:success 0:fail
****************************************************************/
uint8_t getSpeedScope(uint16_t* maxspeed, uint16_t* minspeed);
/****************************************************************
Function Name: setMode
Description: Set module mode.
Parameters: 1:Gets the I/Q information ADC value mode. 0:To detect the target mode.
Return: 1:success 0:fail
****************************************************************/
uint8_t setMode(uint16_t mode);
/****************************************************************
Function Name: getMode
Description: Get module mode.
Parameters: none.
Return: 1:detect the target mode 2:Reported I/Q ADC 0:fail
****************************************************************/
uint8_t getMode();
/****************************************************************
Function Name: setThreshold
Description: Set threshold which determines detection range.
Parameters: threshold.
Return: 1:success 0:fail
****************************************************************/
uint8_t setThreshold(uint16_t threshold);
/****************************************************************
Function Name: getThreshold
Description: Get threshold which determines detection range.
Parameters: None.
Return: 1:success 0:fail
****************************************************************/
uint16_t getThreshold();
/****************************************************************
Function Name: calculateChecksum
Description: Calculate checksum from data bytes
Parameters: data, pointer to uint16_t data array. data_length, length of array to calculate checksum over
Return: uint16_t value of checksum
****************************************************************/
uint16_t calculateChecksum(uint16_t *data, uint16_t data_length);
/****************************************************************
Function Name: messageChecksum
Description: Transform checksum from message to single value
Parameters: high_order, low_order, last two checksum bytes from the message
Return: uint16_t value of checksum
****************************************************************/
uint16_t messageChecksum(uint16_t high_order, uint16_t low_order);
};
#endif