Skip to main content

a8mini_camera_rs/
constants.rs

1use std::time::Duration;
2pub const RECV_BUFF_SIZE: usize = 64;
3pub const RECV_TIMEOUT: Duration = Duration::from_millis(500);
4
5pub const CAMERA_IP: &str = "192.168.144.25";
6pub const CAMERA_COMMAND_PORT: &str = "37260";
7pub const CAMERA_HTTP_PORT: &str = "82";
8
9pub const API_BASE_URL: &str = "//cgi-bin/media.cgi";
10
11// ### SDK PROTOCOL FORMAT
12// +-----------+-------+---------+---------------------------------------------------+
13// | Field     | Index | Bytes   | Description                                       |
14// +-----------+-------+---------+---------------------------------------------------+
15// | STX       | 0     | 2       | 0x6655: starting mark.                            |
16// |           |       |         | Low byte in the front                             |
17// +-----------+-------+---------+---------------------------------------------------+
18// | CTRL      | 2     | 1       | 0: need_ack (if the current data pack needs ack)  |
19// |           |       |         | 1: ack_pack (if the current data pack is an ack)  |
20// |           |       |         | 2-7: reserved                                     |
21// +-----------+-------+---------+---------------------------------------------------+
22// | DATALEN   | 3     | 2       | Data field byte length                            |
23// |           |       |         | Low byte in the front                             |
24// +-----------+-------+---------+---------------------------------------------------+
25// | SEQ       | 5     | 2       | Frame sequence (0 ~ 65535)                        |
26// |           |       |         | Low byte in the front                             |
27// +-----------+-------+---------+---------------------------------------------------+
28// | CMD_ID    | 7     | 1       | Command ID                                        |
29// +-----------+-------+---------+---------------------------------------------------+
30// | DATA      | 8     | DATALEN | Data                                              |
31// +-----------+-------+---------+---------------------------------------------------+
32// | CRC16     |       | 2       | CRC16 check to the complete data package.         |
33// |           |       |         | Low byte in the front                             |
34// +-----------+-------+---------+---------------------------------------------------+
35//
36//
37// +---------+----+---------+---------+----+------- ... --+---------+
38// |   STX   |CTRL| DATALEN |   SEQ   | CMD|  DATA  ...   |  CRC16  |
39// +---------+----+---------+---------+----+------- ... --+---------+
40pub const NUM_COMMANDS: usize = 32; // update this if more commands are added
41pub const HARDCODED_COMMANDS: [&[u8]; NUM_COMMANDS] = [
42    &[
43        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0xd1, 0x12,
44    ], // Auto Center
45    &[
46        0x55, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x2D, 0x3e, 0xd1,
47    ], // Rotate Up
48    &[
49        0x55,
50        0x66,
51        0x01,
52        0x02,
53        0x00,
54        0x00,
55        0x00,
56        0x07,
57        0x00,
58        0u8.wrapping_sub(0x2D),
59        0xef,
60        0xdf,
61    ], // Rotate Down
62    &[
63        0x55,
64        0x66,
65        0x01,
66        0x02,
67        0x00,
68        0x00,
69        0x00,
70        0x07,
71        0u8.wrapping_sub(0x2D),
72        0x00,
73        0x85,
74        0x64,
75    ], // Rotate Right
76    &[
77        0x55, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0x07, 0x2D, 0x00, 0x4b, 0x54,
78    ], // Rotate Left
79    &[
80        0x55, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0xf1, 0x24,
81    ], // Stop Rotation
82    &[
83        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x05, 0x01, 0x8d, 0x64,
84    ], // Zoom +1
85    &[
86        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x05, 0xFF, 0x5c, 0x6a,
87    ], // Zoom -1
88    &[
89        0x55, 0x66, 0x01, 0x02, 0x00, 0x01, 0x00, 0x0F, 0x04, 0x05, 0x60, 0xBB,
90    ], // Absolute Zoom (4.5x)
91    &[0x55, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x16, 0xB2, 0xA6], // Acquire the Max Zoom Value
92    &[
93        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x01, 0xde, 0x31,
94    ], // Manual Focus +1
95    &[
96        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0xff, 0x0f, 0x3f,
97    ], // Manual Focus -1
98    &[
99        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x34, 0xce,
100    ], // Take Pictures
101    &[
102        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x76, 0xee,
103    ], // Record Video
104    &[
105        0x55, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0x07, 0x64, 0x64, 0x3d, 0xcf,
106    ], // Rotate 100 100
107    &[0x55, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0f, 0x75], // Camera Status Information
108    &[
109        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x04, 0x01, 0xbc, 0x57,
110    ], // Auto Focus
111    &[0x55, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x07, 0xf4], // Acquire Hardware ID
112    &[0x55, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0xc4], // Acquire Firmware Version
113    &[
114        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x57, 0xfe,
115    ], // Lock Mode
116    &[
117        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x04, 0xb0, 0x8e,
118    ], // Follow Mode
119    &[
120        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x05, 0x91, 0x9e,
121    ], // FPV Mode
122    &[0x55, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xe8, 0x05], // Acquire Attitude Data
123    &[
124        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x06, 0xf2, 0xae,
125    ], // Set Video Output as HDMI
126    &[
127        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x07, 0xd3, 0xbe,
128    ], // Set Video Output as CVBS
129    &[
130        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x08, 0x3c, 0x4f,
131    ], // Turn Off both CVBS and HDMI Output
132    &[0x55, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x15, 0xD1, 0x96], // Read Range from Laser Rangefinder
133    &[
134        0x55, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0a, 0xa9,
135    ], // Reboot Camera
136    &[
137        0x55, 0x66, 0x01, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x01, 0x1a, 0x8a,
138    ], // Reboot Gimbal
139    &[
140        0x55, 0x66, 0x01, 0x09, 0x00, 0x00, 0x00, 0x21, 0x00, 0x02, 0x00, 0x0f, 0x70, 0x08, 0x98,
141        0x3a, 0x00, 0x70, 0xbe,
142    ], // Resolution 4k
143    &[
144        0x55, 0x66, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x8B,
145    ], // Heartbeat
146    &[
147        0x55, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0f, 0x75,
148    ], // Get gimbal status
149];
150
151pub const CRC16_TAB: [u16; 256] = [
152    0x0, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b,
153    0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
154    0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x420, 0x1401,
155    0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
156    0x3653, 0x2672, 0x1611, 0x630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738,
157    0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x840, 0x1861, 0x2802, 0x3823,
158    0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96,
159    0x1a71, 0xa50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
160    0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0xc60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd,
161    0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0xe70,
162    0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb,
163    0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0xa1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
164    0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x2b1, 0x1290, 0x22f3, 0x32d2,
165    0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
166    0x34e2, 0x24c3, 0x14a0, 0x481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8,
167    0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
168    0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827,
169    0x18c0, 0x8e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
170    0x4a75, 0x5a54, 0x6a37, 0x7a16, 0xaf1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d,
171    0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0xcc1,
172    0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74,
173    0x2e93, 0x3eb2, 0xed1, 0x1ef0,
174];