Skip to content

Commit

Permalink
修改GS2自动重连异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanyiaini committed Mar 14, 2023
1 parent a99d815 commit 14b1578
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 148 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(ydlidar_sdk C CXX)
# version
set(YDLIDAR_SDK_VERSION_MAJOR 1)
set(YDLIDAR_SDK_VERSION_MINOR 1)
set(YDLIDAR_SDK_VERSION_PATCH 4)
set(YDLIDAR_SDK_VERSION_PATCH 5)
set(YDLIDAR_SDK_VERSION ${YDLIDAR_SDK_VERSION_MAJOR}.${YDLIDAR_SDK_VERSION_MINOR}.${YDLIDAR_SDK_VERSION_PATCH})

##########################################################
Expand Down
17 changes: 7 additions & 10 deletions core/base/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ class Thread {
return _param;
}
int join(unsigned long timeout = -1) {
if (!this->_handle) {
if (!_handle) {
return 0;
}

#if defined(_WIN32)

switch (WaitForSingleObject(reinterpret_cast<HANDLE>(this->_handle), timeout)) {
case WAIT_OBJECT_0:
CloseHandle(reinterpret_cast<HANDLE>(this->_handle));
Expand All @@ -101,24 +100,22 @@ class Thread {
case WAIT_TIMEOUT:
return -1;
}

#else
UNUSED(timeout);
void *res;
int s = -1;
s = pthread_cancel((pthread_t)(this->_handle));
s = pthread_cancel((pthread_t)(_handle));
if (s != 0) {
}

s = pthread_join((pthread_t)(this->_handle), &res);
s = pthread_join((pthread_t)(_handle), &res);
if (s != 0) {
}

if (res == PTHREAD_CANCELED) {
printf("0x%X thread has been canceled\n", this->_handle);
printf("[YDLIDAR] Thread 0x%X has been canceled\n", _handle);
_handle = 0; //强制置空线程句柄,以免再次调用该函数时出现异常
} else {
fprintf(stderr, "[YDLIDAR] An error occurred while thread[0x%X] cancelled!\n", _handle);
}
this->_handle = 0; //强制置空线程句柄,以免再次调用该函数时出现异常

#endif
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions core/common/DriverInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@ class DriverInterface {
bool m_isConnected = false;
/// Scan Data Event
Event _dataEvent;
/// Data Locker
/// Data Locker(不支持嵌套)
Locker _lock;
/// Parse Data thread
Thread _thread;
/// command locker
/// command locker(不支持嵌套)
Locker _cmd_lock;
/// driver error locker
/// driver error locker(不支持嵌套)
Locker _error_lock;

/// LiDAR com port or IP Address
Expand Down
4 changes: 2 additions & 2 deletions samples/gs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main(int argc, char *argv[])
printf("Baudrate:\n");
for (std::map<int, int>::iterator it = baudrateList.begin();
it != baudrateList.end(); it++) {
printf("%d. %d\n", it->first, it->second);
printf("[%d] %d\n", it->first, it->second);
}

while (ydlidar::os_isOk())
Expand Down Expand Up @@ -153,7 +153,7 @@ int main(int argc, char *argv[])
/// lidar baudrate
laser.setlidaropt(LidarPropSerialBaudrate, &baudrate, sizeof(int));
/// gs lidar
int optval = TYPE_GS1;
int optval = TYPE_GS;
laser.setlidaropt(LidarPropLidarType, &optval, sizeof(int));
/// device type
optval = YDLIDAR_TYPE_SERIAL;
Expand Down
10 changes: 5 additions & 5 deletions samples/tri_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, char *argv[])

for (it = ports.begin(); it != ports.end(); it++)
{
printf("%d. %s\n", id, it->first.c_str());
printf("[%d] %s\n", id, it->first.c_str());
id++;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ int main(int argc, char *argv[])
for (std::map<int, int>::iterator it = baudrateList.begin();
it != baudrateList.end(); it++)
{
printf("%d. %d\n", it->first, it->second);
printf("[%d] %d\n", it->first, it->second);
}

while (ydlidar::os_isOk())
Expand All @@ -163,7 +163,7 @@ int main(int argc, char *argv[])

bool isSingleChannel = false;
std::string input_channel;
printf("Whether the Lidar is one-way communication[yes/no]:");
printf("Whether the Lidar is one-way communication [yes/no]:");
std::cin >> input_channel;
std::transform(input_channel.begin(), input_channel.end(),
input_channel.begin(),
Expand Down Expand Up @@ -197,8 +197,8 @@ int main(int argc, char *argv[])
break;
}

fprintf(stderr,
"Invalid scan frequency,The scanning frequency range is 5 to 12 HZ, Please re-enter.\n");
fprintf(stderr, "Invalid scan frequency,"
"The scanning frequency range is 5 to 12 HZ, Please re-enter.\n");
}

if (!ydlidar::os_isOk())
Expand Down
Loading

0 comments on commit 14b1578

Please sign in to comment.