Skip to content

Commit 4c5ef53

Browse files
author
Wang DeYou
committed
Optimize code
1 parent 034637b commit 4c5ef53

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

app/custom_baudrate/main.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,15 @@ void print_usage(int argc, const char* argv[])
6666
" %s <com port> [baudrate]\n"
6767
" The baudrate can be ANY possible values between 115200 to 512000.\n"
6868

69-
, "SL_LIDAR_SDK_VERSION", argv[0], argv[0]);
69+
, "SL_LIDAR_SDK_VERSION", argv[0]);
7070
}
7171

7272

7373
int main(int argc, const char* argv[]) {
7474

7575
const char* opt_port_dev;
76-
sl_u32 opt_required_baudrate = 460000;
77-
sl_result op_result;
78-
79-
80-
bool useArgcBaudrate = false;
76+
sl_u32 opt_required_baudrate = 460000;
77+
sl_result op_result;
8178

8279
IChannel* _channel;
8380

@@ -116,12 +113,10 @@ int main(int argc, const char* argv[]) {
116113

117114
_channel = (*createSerialPortChannel(opt_port_dev, opt_required_baudrate));
118115

119-
int result = 0;
120116
do {
121117

122118
if (SL_IS_FAIL((drv)->connect(_channel))) {
123119
fprintf(stderr, "Error, failed to bind to the serial port.\n");
124-
result = -2;
125120
break;
126121
}
127122

@@ -131,7 +126,6 @@ int main(int argc, const char* argv[]) {
131126
if (SL_IS_FAIL((drv)->negotiateSerialBaudRate(opt_required_baudrate, &baudrateDetected)))
132127
{
133128
fprintf(stderr, "Error, cannot perform baudrate negotiation.\n");
134-
result = -3;
135129
break;
136130
}
137131

@@ -146,7 +140,6 @@ int main(int argc, const char* argv[]) {
146140

147141
if (SL_IS_FAIL((drv)->connect(_channel))) { //reconnect, otherwise, corrupted data will be retrieved.
148142
fprintf(stderr, "Error, failed to bind to the serial port.\n");
149-
result = -2;
150143
break;
151144
}
152145

@@ -158,7 +151,6 @@ int main(int argc, const char* argv[]) {
158151

159152
if (SL_IS_FAIL(op_result)) {
160153
fprintf(stderr, "Neogiation failure, the new baudrate cannot be used.\n");
161-
result = -4;
162154
break;
163155
}
164156

app/simple_grabber/main.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ void print_usage(int argc, const char * argv[])
5858
"Version: %s \n"
5959
"Usage:\n"
6060
" For serial channel %s --channel --serial <com port> [baudrate]\n"
61-
"The baudrate is 115200(for A2) , 256000(for A3 and S1), 1000000(for S2).\n"
61+
" The baudrate used by different models is as follows:\n"
62+
" A1(115200),A2M7(256000),A2M8(115200),A2M12(256000),"
63+
"A3(256000),S1(256000),S2(1000000),S3(1000000)\n"
6264
" For udp channel %s --channel --udp <ipaddr> [port NO.]\n"
6365
"The LPX default ipaddr is 192.168.11.2,and the port NO.is 8089. Please refer to the datasheet for details.\n"
6466
, "SL_LIDAR_SDK_VERSION", argv[0], argv[0]);
@@ -69,7 +71,7 @@ void plot_histogram(sl_lidar_response_measurement_node_hq_t * nodes, size_t coun
6971
{
7072
const int BARCOUNT = 75;
7173
const int MAXBARHEIGHT = 20;
72-
const float ANGLESCALE = 360.0f/BARCOUNT;
74+
// const float ANGLESCALE = 360.0f/BARCOUNT;
7375

7476
float histogram[BARCOUNT];
7577
for (int pos = 0; pos < _countof(histogram); ++pos) {
@@ -140,11 +142,11 @@ sl_result capture_and_display(ILidarDriver * drv)
140142
}
141143

142144
int main(int argc, const char * argv[]) {
143-
const char * opt_channel = NULL;
144-
const char * opt_channel_param_first = NULL;
145-
sl_u32 opt_channel_param_second = 0;
146-
sl_result op_result;
147-
int opt_channel_type = CHANNEL_TYPE_SERIALPORT;
145+
const char *opt_channel = NULL;
146+
const char *opt_channel_param_first = NULL;
147+
sl_u32 opt_channel_param_second = 0;
148+
sl_result op_result;
149+
int opt_channel_type = CHANNEL_TYPE_SERIALPORT;
148150

149151
IChannel* _channel;
150152

@@ -206,7 +208,7 @@ int main(int argc, const char * argv[]) {
206208
, opt_channel_param_first);
207209
break;
208210
case CHANNEL_TYPE_UDP:
209-
fprintf(stderr, "Error, cannot connect to the ip addr %s with the udp port %s.\n"
211+
fprintf(stderr, "Error, cannot connect to the ip addr %s with the udp port %u.\n"
210212
, opt_channel_param_first, opt_channel_param_second);
211213
break;
212214
}

app/ultra_simple/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ using namespace sl;
5454

5555
void print_usage(int argc, const char * argv[])
5656
{
57-
printf("Simple LIDAR data grabber for SLAMTEC LIDAR.\n"
58-
"Version: %s \n"
59-
"Usage:\n"
60-
" For serial channel %s --channel --serial <com port> [baudrate]\n"
61-
"The baudrate is 115200(for A2) or 256000(for A3).\n"
62-
" For udp channel %s --channel --udp <ipaddr> [port NO.]\n"
63-
"The LPX default ipaddr is 192.168.11.2,and the port NO.is 8089. Please refer to the datasheet for details.\n"
64-
, "SL_LIDAR_SDK_VERSION", argv[0], argv[0]);
57+
printf("Usage:\n"
58+
" For serial channel\n %s --channel --serial <com port> [baudrate]\n"
59+
" The baudrate used by different models is as follows:\n"
60+
" A1(115200),A2M7(256000),A2M8(115200),A2M12(256000),"
61+
"A3(256000),S1(256000),S2(1000000),S3(1000000)\n"
62+
" For udp channel\n %s --channel --udp <ipaddr> [port NO.]\n"
63+
" The T1 default ipaddr is 192.168.11.2,and the port NO.is 8089. Please refer to the datasheet for details.\n"
64+
, argv[0], argv[0]);
6565
}
6666

6767
bool checkSLAMTECLIDARHealth(ILidarDriver * drv)

0 commit comments

Comments
 (0)