Skip to content

Commit

Permalink
Merge pull request #20 from UrgNetworks/Add_VS2019_etc
Browse files Browse the repository at this point in the history
Add vs2019 project.
Add the feature which can change to ignore check sum error.
Fixed the feature which ignores SIGPIPE when executed send function.
  • Loading branch information
ShimizuRyousuke123456 authored Sep 2, 2022
2 parents 3f8f2f3 + c1b39ec commit c7c5528
Show file tree
Hide file tree
Showing 34 changed files with 3,704 additions and 22 deletions.
6 changes: 5 additions & 1 deletion current/include/c/urg_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ extern "C" {

urg_error_handler error_handler;

int ignore_checkSumError;

char return_buffer[80];
} urg_t;

Expand Down Expand Up @@ -318,6 +320,7 @@ extern "C" {
\param[in] type データ・タイプ
\param[in] scan_times データの取得回数
\param[in] skip_scan データの取得間隔
\param[in] ignore_checkSumError 0以外:チェックサムエラーを無視し、計測継続 0:チェックサムエラーで計測停止
\retval 0 正常
\retval <0 エラー
Expand Down Expand Up @@ -347,6 +350,7 @@ extern "C" {
\param[in] type Measurement type
\param[in] scan_times Number of scans to request
\param[in] skip_scan Interval between scans
\param[in] ignore_checkSumError non-0:continue measurement 0: stop measurement
\retval 0 Successful
\retval <0 Error
Expand Down Expand Up @@ -389,7 +393,7 @@ extern "C" {
\see urg_get_distance(), urg_get_distance_intensity(), urg_get_multiecho(), urg_get_multiecho_intensity(), urg_stop_measurement()
*/
extern int urg_start_measurement(urg_t *urg, urg_measurement_type_t type,
int scan_times, int skip_scan);
int scan_times, int skip_scan, int ignore_checkSumError);


/*!
Expand Down
4 changes: 3 additions & 1 deletion current/include/cpp/Urg_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace qrk
int scan_times = Infinity_times,
int skip_scan = 0);

void set_ignore_checkSumError(bool ignore = true);

//! \~japanese 受信データの受け取り \~english Receives measurement data
bool get_distance(std::vector<long>& data, long *time_stamp = NULL);
bool get_distance_intensity(std::vector<long>& data,
Expand Down Expand Up @@ -128,7 +130,7 @@ namespace qrk
Urg_driver& operator = (const Urg_driver& rhs);

struct pImpl;
std::auto_ptr<pImpl> pimpl;
std::unique_ptr<pImpl> pimpl;
};
}

Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/calculate_xy.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char *argv[])

// \~japanese データ取得
// \~english Gets measurement data
urg_start_measurement(&urg, URG_DISTANCE, 1, 0);
urg_start_measurement(&urg, URG_DISTANCE, 1, 0, 1);
n = urg_get_distance(&urg, data, &time_stamp);
if (n < 0) {
printf("urg_get_distance: %s\n", urg_error(&urg));
Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/get_distance.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(int argc, char *argv[])
urg_deg2step(&urg, +90), 0);
#endif

urg_start_measurement(&urg, URG_DISTANCE, URG_SCAN_INFINITY, 0);
urg_start_measurement(&urg, URG_DISTANCE, URG_SCAN_INFINITY, 0, 1);
for (i = 0; i < CAPTURE_TIMES; ++i) {
n = urg_get_distance(&urg, data, &time_stamp);
if (n <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/get_distance_handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int main(int argc, char *argv[])
#endif

for (i = 0; i < CAPTURE_TIMES; ++i) {
urg_start_measurement(&urg, URG_DISTANCE, 1, 0);
urg_start_measurement(&urg, URG_DISTANCE, 1, 0 ,1);
n = urg_get_distance(&urg, data, &time_stamp);
if (n <= 0) {
printf("urg_get_distance: %s\n", urg_error(&urg));
Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/get_distance_intensity.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main(int argc, char *argv[])

// \~japanese データ取得
// \~english Gets measurement data
urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, URG_SCAN_INFINITY, 0);
urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, URG_SCAN_INFINITY, 0 , 1);
for (i = 0; i < CAPTURE_TIMES; ++i) {
n = urg_get_distance_intensity(&urg, data, intensity, &time_stamp);
if (n <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/get_multiecho.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char *argv[])

// \~japanese データ取得
// \~english Gets measurement data
urg_start_measurement(&urg, URG_MULTIECHO, URG_SCAN_INFINITY, 0);
urg_start_measurement(&urg, URG_MULTIECHO, URG_SCAN_INFINITY, 0, 1);
for (i = 0; i < CAPTURE_TIMES; ++i) {
n = urg_get_multiecho(&urg, data, &time_stamp);
if (n <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/get_multiecho_intensity.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main(int argc, char *argv[])

// \~japanese データ取得
// \~english Gets measurement data
urg_start_measurement(&urg, URG_MULTIECHO_INTENSITY, URG_SCAN_INFINITY, 0);
urg_start_measurement(&urg, URG_MULTIECHO_INTENSITY, URG_SCAN_INFINITY, 0, 1);
for (i = 0; i < CAPTURE_TIMES; ++i) {
n = urg_get_multiecho_intensity(&urg, data, intensity, &time_stamp);
if (n <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion current/samples/cpp/Connection_information.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace qrk
private:
Connection_information(void);
struct pImpl;
std::auto_ptr<pImpl> pimpl;
std::unique_ptr<pImpl> pimpl;
};
}

Expand Down
8 changes: 5 additions & 3 deletions current/src/Urg_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ bool Urg_driver::start_measurement(measurement_type_t type,
type_table_t type_table[] = {
{ URG_DISTANCE, Distance },
{ URG_DISTANCE_INTENSITY, Distance_intensity },
{ URG_MULTIECHO, Multiecho },
{ URG_MULTIECHO, Multiecho },
{ URG_MULTIECHO_INTENSITY, Multiecho_intensity},
{ URG_DISTANCE_IO, Distance_io },
{ URG_DISTANCE_INTENSITY_IO, Distance_intensity_io },
};
Expand All @@ -188,8 +189,8 @@ bool Urg_driver::start_measurement(measurement_type_t type,
for (size_t i = 0; i < n; ++i) {
const type_table_t* p = &type_table[i];
if (type == p->type) {
int ret = urg_start_measurement(&pimpl->urg_,
p->c_type, scan_times, skip_scan);
int ret =
urg_start_measurement(&pimpl->urg_, p->c_type, scan_times, skip_scan,pimpl->urg_.ignore_checkSumError);
if (ret == URG_NO_ERROR) {
pimpl->last_measure_type_ = type;
}
Expand All @@ -200,6 +201,7 @@ bool Urg_driver::start_measurement(measurement_type_t type,
return false;
}

void Urg_driver::set_ignore_checkSumError(bool ignore) { pimpl->urg_.ignore_checkSumError = ignore ? 1 : 0; }

bool Urg_driver::get_distance(std::vector<long>& data, long* time_stamp)
{
Expand Down
21 changes: 12 additions & 9 deletions current/src/urg_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void ignore_receive_data_with_qt(urg_t *urg, int timeout)
if ((urg->is_sending == URG_FALSE) && (urg->is_laser_on == URG_FALSE)) {
return;
}

connection_write(&urg->connection, "QT\n", 3);
urg->is_laser_on = URG_FALSE;
ignore_receive_data(urg, timeout);
Expand Down Expand Up @@ -548,13 +548,13 @@ static int receive_length_data(urg_t *urg, long length[],
if (n > 0) {
// \~japanese チェックサムの評価
// \~english Validates the checksum
if (buffer[line_filled + n - 1] !=
scip_checksum(&buffer[line_filled], n - 1)) {
if (buffer[line_filled + n - 1] != scip_checksum(&buffer[line_filled], n - 1) &&
(urg->ignore_checkSumError == 0)) {
ignore_receive_data_with_qt(urg, urg->timeout);
return set_errno_and_return(urg, URG_CHECKSUM_ERROR);
}
}

if (n > 0) {
line_filled += n - 1;
}
Expand Down Expand Up @@ -670,10 +670,11 @@ static int receive_data(urg_t *urg, long data[], unsigned short intensity[], lon
return set_errno_and_return(urg, URG_INVALID_RESPONSE);
}

if (buffer[n - 1] != scip_checksum(buffer, n - 1)) {
if (buffer[n - 1] != scip_checksum(buffer, n - 1) && (urg->ignore_checkSumError == 0)) {
// \~japanese チェックサムの評価
// \~english Validates the checksum
ignore_receive_data_with_qt(urg, urg->timeout);
*time_stamp = 0;
return set_errno_and_return(urg, URG_CHECKSUM_ERROR);
}

Expand Down Expand Up @@ -795,6 +796,7 @@ void urg_t_initialize(urg_t *urg)
urg->timeout = MAX_TIMEOUT;
urg->scanning_skip_scan = 0;
urg->error_handler = NULL;
urg->ignore_checkSumError = 1;
}

int urg_open(urg_t *urg, urg_connection_type_t connection_type,
Expand Down Expand Up @@ -997,21 +999,22 @@ static int send_distance_command(urg_t *urg, int scan_times, int skip_scan,
}


int urg_start_measurement(urg_t *urg, urg_measurement_type_t type,
int scan_times, int skip_scan)
{
int urg_start_measurement(urg_t *urg, urg_measurement_type_t type, int scan_times, int skip_scan,
int ignore_checkSumError) {
char range_byte_ch;
int ret = 0;

if (!urg->is_active) {
return set_errno_and_return(urg, URG_NOT_CONNECTED);
}

if ((skip_scan < 0) || (skip_scan > 9)) {
if (((skip_scan < 0) || (skip_scan > 9)) || ((ignore_checkSumError < 0) || (ignore_checkSumError > 2))) {
ignore_receive_data_with_qt(urg, urg->timeout);
return set_errno_and_return(urg, URG_INVALID_PARAMETER);
}

urg->ignore_checkSumError = ignore_checkSumError;

// \~japanese !!! Mx 系, Nx 系の計測中のときは、QT を発行してから
// \~japanese !!! 計測開始コマンドを送信するようにする
// \~japanese !!! ただし、MD 計測中に MD を発行するように、同じコマンドの場合は
Expand Down
9 changes: 8 additions & 1 deletion current/src/urg_tcpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,14 @@ int tcpclient_read(urg_tcpclient_t* cli,
int tcpclient_write(urg_tcpclient_t* cli, const char* buf, int size)
{
// blocking if data size is larger than system's buffer.
return send(cli->sock_desc, buf, size, 0); //4th arg 0: no flag
#if defined(URG_WINDOWS_OS)
// blocking if data size is larger than system's buffer.
return send(cli->sock_desc, buf, size, 0); // 4th arg 0: no flag
#elif defined(URG_LINUX_OS)
return send(cli->sock_desc, buf, size, MSG_NOSIGNAL);
#else
return send(cli->sock_desc, buf, size, SO_NOSIGPIPE);
#endif
}


Expand Down
Loading

0 comments on commit c7c5528

Please sign in to comment.