• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1988 (tree)
日時2012-05-15 16:04:56
作者satofumi

ログメッセージ

changed source code LF.

変更サマリ

差分

--- trunk/widgets/EthernetConnectionWidget/EthernetConnectionWidget.cpp (revision 1987)
+++ trunk/widgets/EthernetConnectionWidget/EthernetConnectionWidget.cpp (revision 1988)
@@ -1,174 +1,174 @@
1-
2-/*!
3- \file
4- \brief Ethernet 接続用 Widget
5-
6- \author Satofumi KAMIMURA
7-
8- $Id$
9-*/
10-
11-#include "EthernetConnectionWidget.h"
12-#include <QFile>
13-#include <QTextStream>
14-#include <QCompleter>
15-
16-using namespace qrk;
17-using namespace std;
18-
19-
20-namespace
21-{
22- const char CompleterFile[] = "ethernet_address.txt";
23-}
24-
25-
26-struct EthernetConnectionWidget::pImpl
27-{
28- EthernetConnectionWidget* widget_;
29- QStringList completer_address_;
30-
31-
32- pImpl(EthernetConnectionWidget* widget) : widget_(widget)
33- {
34- }
35-
36-
37- void initializeForm(void)
38- {
39- connect(widget_->connect_button_, SIGNAL(clicked(bool)),
40- widget_, SLOT(connectPressed(bool)));
41-
42- loadCompleteAddress();
43- }
44-
45-
46- bool loadCompleteAddress(void)
47- {
48- // 入力候補を保存したファイルがあれば、読み出して入力候補として使う
49- QFile file(CompleterFile);
50- if (! file.open(QFile::ReadOnly)) {
51- return false;
52- }
53-
54- QTextStream fin(&file);
55- while (true) {
56- QString line = fin.readLine();
57- if (line.isNull()) {
58- break;
59- }
60- completer_address_ << line;
61- }
62-
63- QCompleter* completer = new QCompleter(completer_address_, widget_);
64- widget_->address_lineedit_->setCompleter(completer);
65-
66- return true;
67- }
68-
69-
70- bool saveCompleteAddress(void)
71- {
72- QFile file(CompleterFile);
73- if (! file.open(QFile::WriteOnly | QFile::Truncate)) {
74- return false;
75- }
76-
77- QTextStream fout(&file);
78- size_t n = completer_address_.size();
79- for (size_t i = 0; i < n; ++i) {
80- fout << completer_address_.at(i);
81- }
82-
83- return true;
84- }
85-};
86-
87-
88-EthernetConnectionWidget::EthernetConnectionWidget(QWidget* parent)
89- : QWidget(parent), pimpl(new pImpl(this))
90-{
91- setupUi(this);
92- pimpl->initializeForm();
93-}
94-
95-
96-EthernetConnectionWidget::~EthernetConnectionWidget(void)
97-{
98-}
99-
100-
101-void EthernetConnectionWidget::setConnected(bool connected)
102-{
103- connect_button_->setEnabled(true);
104- connect_button_->setChecked(connected);
105-
106- if (connected) {
107- // 今までにない接続アドレスの場合、追加して保存する
108- QString connected_address = address().c_str();
109- if (! pimpl->completer_address_.contains(connected_address)) {
110- pimpl->completer_address_ << connected_address;
111- pimpl->saveCompleteAddress();
112- }
113- connect_button_->setText(tr("Disconnect"));
114- } else {
115- connect_button_->setText(tr("Connect"));
116- }
117- address_lineedit_->setEnabled(! connected);
118- port_spinbox_->setEnabled(! connected);
119-
120- connect_button_->setFocus();
121-}
122-
123-
124-bool EthernetConnectionWidget::isConnected(void) const
125-{
126- return (connect_button_->isEnabled() && connect_button_->isChecked())
127- ? true : false;
128-}
129-
130-
131-void EthernetConnectionWidget::setAddress(const std::string& address)
132-{
133- address_lineedit_->setText(address.c_str());
134-}
135-
136-
137-std::string EthernetConnectionWidget::address(void) const
138-{
139- return address_lineedit_->text().toStdString();
140-}
141-
142-
143-void EthernetConnectionWidget::setPort(unsigned short port)
144-{
145- port_spinbox_->setValue(port);
146-}
147-
148-
149-unsigned EthernetConnectionWidget::port(void) const
150-{
151- return port_spinbox_->value();
152-}
153-
154-
155-void EthernetConnectionWidget::setEnabled(bool enable)
156-{
157- QWidget::setEnabled(enable);
158-}
159-
160-
161-void EthernetConnectionWidget::setFocus(void)
162-{
163- connect_button_->setFocus();
164-}
165-
166-
167-void EthernetConnectionWidget::connectPressed(bool checked)
168-{
169- // 接続ボタンが押下されたとき、setConnected() が呼ばれるまでボタンを無効にする
170- connect_button_->setEnabled(false);
171- string address = address_lineedit_->text().toStdString();
172- unsigned short port = port_spinbox_->value();
173- emit connectRequest(checked, address, port);
174-}
1+
2+/*!
3+ \file
4+ \brief Ethernet 接続用 Widget
5+
6+ \author Satofumi KAMIMURA
7+
8+ $Id$
9+*/
10+
11+#include "EthernetConnectionWidget.h"
12+#include <QFile>
13+#include <QTextStream>
14+#include <QCompleter>
15+
16+using namespace qrk;
17+using namespace std;
18+
19+
20+namespace
21+{
22+ const char CompleterFile[] = "ethernet_address.txt";
23+}
24+
25+
26+struct EthernetConnectionWidget::pImpl
27+{
28+ EthernetConnectionWidget* widget_;
29+ QStringList completer_address_;
30+
31+
32+ pImpl(EthernetConnectionWidget* widget) : widget_(widget)
33+ {
34+ }
35+
36+
37+ void initializeForm(void)
38+ {
39+ connect(widget_->connect_button_, SIGNAL(clicked(bool)),
40+ widget_, SLOT(connectPressed(bool)));
41+
42+ loadCompleteAddress();
43+ }
44+
45+
46+ bool loadCompleteAddress(void)
47+ {
48+ // 入力候補を保存したファイルがあれば、読み出して入力候補として使う
49+ QFile file(CompleterFile);
50+ if (! file.open(QFile::ReadOnly)) {
51+ return false;
52+ }
53+
54+ QTextStream fin(&file);
55+ while (true) {
56+ QString line = fin.readLine();
57+ if (line.isNull()) {
58+ break;
59+ }
60+ completer_address_ << line;
61+ }
62+
63+ QCompleter* completer = new QCompleter(completer_address_, widget_);
64+ widget_->address_lineedit_->setCompleter(completer);
65+
66+ return true;
67+ }
68+
69+
70+ bool saveCompleteAddress(void)
71+ {
72+ QFile file(CompleterFile);
73+ if (! file.open(QFile::WriteOnly | QFile::Truncate)) {
74+ return false;
75+ }
76+
77+ QTextStream fout(&file);
78+ size_t n = completer_address_.size();
79+ for (size_t i = 0; i < n; ++i) {
80+ fout << completer_address_.at(i);
81+ }
82+
83+ return true;
84+ }
85+};
86+
87+
88+EthernetConnectionWidget::EthernetConnectionWidget(QWidget* parent)
89+ : QWidget(parent), pimpl(new pImpl(this))
90+{
91+ setupUi(this);
92+ pimpl->initializeForm();
93+}
94+
95+
96+EthernetConnectionWidget::~EthernetConnectionWidget(void)
97+{
98+}
99+
100+
101+void EthernetConnectionWidget::setConnected(bool connected)
102+{
103+ connect_button_->setEnabled(true);
104+ connect_button_->setChecked(connected);
105+
106+ if (connected) {
107+ // 今までにない接続アドレスの場合、追加して保存する
108+ QString connected_address = address().c_str();
109+ if (! pimpl->completer_address_.contains(connected_address)) {
110+ pimpl->completer_address_ << connected_address;
111+ pimpl->saveCompleteAddress();
112+ }
113+ connect_button_->setText(tr("Disconnect"));
114+ } else {
115+ connect_button_->setText(tr("Connect"));
116+ }
117+ address_lineedit_->setEnabled(! connected);
118+ port_spinbox_->setEnabled(! connected);
119+
120+ connect_button_->setFocus();
121+}
122+
123+
124+bool EthernetConnectionWidget::isConnected(void) const
125+{
126+ return (connect_button_->isEnabled() && connect_button_->isChecked())
127+ ? true : false;
128+}
129+
130+
131+void EthernetConnectionWidget::setAddress(const std::string& address)
132+{
133+ address_lineedit_->setText(address.c_str());
134+}
135+
136+
137+std::string EthernetConnectionWidget::address(void) const
138+{
139+ return address_lineedit_->text().toStdString();
140+}
141+
142+
143+void EthernetConnectionWidget::setPort(unsigned short port)
144+{
145+ port_spinbox_->setValue(port);
146+}
147+
148+
149+unsigned EthernetConnectionWidget::port(void) const
150+{
151+ return port_spinbox_->value();
152+}
153+
154+
155+void EthernetConnectionWidget::setEnabled(bool enable)
156+{
157+ QWidget::setEnabled(enable);
158+}
159+
160+
161+void EthernetConnectionWidget::setFocus(void)
162+{
163+ connect_button_->setFocus();
164+}
165+
166+
167+void EthernetConnectionWidget::connectPressed(bool checked)
168+{
169+ // 接続ボタンが押下されたとき、setConnected() が呼ばれるまでボタンを無効にする
170+ connect_button_->setEnabled(false);
171+ string address = address_lineedit_->text().toStdString();
172+ unsigned short port = port_spinbox_->value();
173+ emit connectRequest(checked, address, port);
174+}
--- trunk/libs/range_sensor/capture_sample/capture_sample.cpp (revision 1987)
+++ trunk/libs/range_sensor/capture_sample/capture_sample.cpp (revision 1988)
@@ -629,7 +629,7 @@
629629 {
630630 // COM ポート設定
631631 // !!! 各自の環境に合わせて COM 設定を変更すること
632- const char com_port[] = "COM3";
632+ const char com_port[] = "COM5";
633633 const long com_baudrate = 115200;
634634
635635 // URG に接続
--- trunk/libs/connection/qt/TcpipSocket.cpp (revision 1987)
+++ trunk/libs/connection/qt/TcpipSocket.cpp (revision 1988)
@@ -1,160 +1,160 @@
1-/*!
2- \file
3- \brief TCP/IP 通信
4-
5- \author Satofumi KAMIMURA
6-
7- $Id$
8-
9- \todo テストを実装して動作確認を行う
10-*/
11-
12-#include "TcpipSocket.h"
13-#include <QTcpSocket>
14-
15-using namespace qrk;
16-
17-
18-struct TcpipSocket::pImpl
19-{
20- QTcpSocket* socket_;
21- long baudrate_;
22-
23-
24- pImpl(QTcpSocket* socket) : socket_(socket), baudrate_(0)
25- {
26- }
27-
28-
29- ~pImpl(void)
30- {
31- //delete socket_;
32- }
33-};
34-
35-
36-TcpipSocket::TcpipSocket(void) : pimpl(new pImpl(new QTcpSocket))
37-{
38-}
39-
40-
41-TcpipSocket::TcpipSocket(void* socket)
42- : pimpl(new pImpl(static_cast<QTcpSocket*>(socket)))
43-{
44-}
45-
46-
47-
48-TcpipSocket::~TcpipSocket(void)
49-{
50- disconnect();
51-}
52-
53-
54-const char* TcpipSocket::what(void) const
55-{
56- return pimpl->socket_->errorString().toStdString().c_str();
57-}
58-
59-
60-bool TcpipSocket::connect(const char* host, long port)
61-{
62- pimpl->socket_->connectToHost(host, port);
63-
64- enum { ConnectionTimeout = 3000 };
65- bool ret = pimpl->socket_->waitForConnected(ConnectionTimeout);
66-
67- return ret;
68-}
69-
70-
71-void TcpipSocket::disconnect(void)
72-{
73- if (pimpl->socket_->isValid()) {
74- pimpl->socket_->disconnectFromHost();
75- pimpl->socket_->waitForDisconnected();
76- }
77-}
78-
79-
80-bool TcpipSocket::setBaudrate(long baudrate)
81-{
82- // 実装しない
83- pimpl->baudrate_ = baudrate;
84- return true;
85-}
86-
87-
88-long TcpipSocket::baudrate(void) const
89-{
90- // 実装しない
91- return pimpl->baudrate_;
92-}
93-
94-
95-bool TcpipSocket::isConnected(void) const
96-{
97- return pimpl->socket_->isValid();
98-}
99-
100-
101-int TcpipSocket::send(const char* data, size_t count)
102-{
103- return pimpl->socket_->write(data, count);
104-}
105-
106-
107-int TcpipSocket::receive(char* data, size_t count, int timeout)
108-{
109- if (count == 0) {
110- return 0;
111- }
112-
113- // !!! 制御構造を見直す
114- size_t filled = 0;
115- do {
116- int n = pimpl->socket_->read(&data[filled], count - filled);
117- if (n < 0) {
118- return n;
119- }
120- if (n > 0) {
121- filled += n;
122- }
123-
124- if ((filled < count) && (! pimpl->socket_->waitForReadyRead(timeout))) {
125- break;
126- }
127- } while (filled < count);
128-
129- return filled;
130-}
131-
132-
133-size_t TcpipSocket::size(void) const
134-{
135- return pimpl->socket_->bytesAvailable();
136-}
137-
138-
139-void TcpipSocket::flush(void)
140-{
141- pimpl->socket_->flush();
142-}
143-
144-
145-void TcpipSocket::clear(void)
146-{
147- // 受信バッファの内容を読み捨てる
148- enum { BufferSize = 256 };
149- char buffer[BufferSize];
150-
151- while (receive(buffer, BufferSize, 0) == BufferSize) {
152- ;
153- }
154-}
155-
156-
157-void TcpipSocket::ungetc(const char ch)
158-{
159- pimpl->socket_->ungetChar(ch);
160-}
1+/*!
2+ \file
3+ \brief TCP/IP 通信
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+
9+ \todo テストを実装して動作確認を行う
10+*/
11+
12+#include "TcpipSocket.h"
13+#include <QTcpSocket>
14+
15+using namespace qrk;
16+
17+
18+struct TcpipSocket::pImpl
19+{
20+ QTcpSocket* socket_;
21+ long baudrate_;
22+
23+
24+ pImpl(QTcpSocket* socket) : socket_(socket), baudrate_(0)
25+ {
26+ }
27+
28+
29+ ~pImpl(void)
30+ {
31+ //delete socket_;
32+ }
33+};
34+
35+
36+TcpipSocket::TcpipSocket(void) : pimpl(new pImpl(new QTcpSocket))
37+{
38+}
39+
40+
41+TcpipSocket::TcpipSocket(void* socket)
42+ : pimpl(new pImpl(static_cast<QTcpSocket*>(socket)))
43+{
44+}
45+
46+
47+
48+TcpipSocket::~TcpipSocket(void)
49+{
50+ disconnect();
51+}
52+
53+
54+const char* TcpipSocket::what(void) const
55+{
56+ return pimpl->socket_->errorString().toStdString().c_str();
57+}
58+
59+
60+bool TcpipSocket::connect(const char* host, long port)
61+{
62+ pimpl->socket_->connectToHost(host, port);
63+
64+ enum { ConnectionTimeout = 3000 };
65+ bool ret = pimpl->socket_->waitForConnected(ConnectionTimeout);
66+
67+ return ret;
68+}
69+
70+
71+void TcpipSocket::disconnect(void)
72+{
73+ if (pimpl->socket_->isValid()) {
74+ pimpl->socket_->disconnectFromHost();
75+ pimpl->socket_->waitForDisconnected();
76+ }
77+}
78+
79+
80+bool TcpipSocket::setBaudrate(long baudrate)
81+{
82+ // 実装しない
83+ pimpl->baudrate_ = baudrate;
84+ return true;
85+}
86+
87+
88+long TcpipSocket::baudrate(void) const
89+{
90+ // 実装しない
91+ return pimpl->baudrate_;
92+}
93+
94+
95+bool TcpipSocket::isConnected(void) const
96+{
97+ return pimpl->socket_->isValid();
98+}
99+
100+
101+int TcpipSocket::send(const char* data, size_t count)
102+{
103+ return pimpl->socket_->write(data, count);
104+}
105+
106+
107+int TcpipSocket::receive(char* data, size_t count, int timeout)
108+{
109+ if (count == 0) {
110+ return 0;
111+ }
112+
113+ // !!! 制御構造を見直す
114+ size_t filled = 0;
115+ do {
116+ int n = pimpl->socket_->read(&data[filled], count - filled);
117+ if (n < 0) {
118+ return n;
119+ }
120+ if (n > 0) {
121+ filled += n;
122+ }
123+
124+ if ((filled < count) && (! pimpl->socket_->waitForReadyRead(timeout))) {
125+ break;
126+ }
127+ } while (filled < count);
128+
129+ return filled;
130+}
131+
132+
133+size_t TcpipSocket::size(void) const
134+{
135+ return pimpl->socket_->bytesAvailable();
136+}
137+
138+
139+void TcpipSocket::flush(void)
140+{
141+ pimpl->socket_->flush();
142+}
143+
144+
145+void TcpipSocket::clear(void)
146+{
147+ // 受信バッファの内容を読み捨てる
148+ enum { BufferSize = 256 };
149+ char buffer[BufferSize];
150+
151+ while (receive(buffer, BufferSize, 0) == BufferSize) {
152+ ;
153+ }
154+}
155+
156+
157+void TcpipSocket::ungetc(const char ch)
158+{
159+ pimpl->socket_->ungetChar(ch);
160+}
--- trunk/libs/connection/Connection.h (revision 1987)
+++ trunk/libs/connection/Connection.h (revision 1988)
@@ -1,139 +1,139 @@
1-#ifndef QRK_CONNECTION_H
2-#define QRK_CONNECTION_H
3-
4-/*!
5- \file
6- \brief 通信インターフェース
7-
8- \author Satofumi KAMIMURA
9-
10- $Id$
11-*/
12-
13-#include <cstddef>
14-
15-
16-namespace qrk
17-{
18- enum {
19- ReceiveTimeout = -1,
20- ErrorLastIndex = -2,
21- };
22-
23-
24- //! 通信インターフェース
25- class Connection
26- {
27- public:
28- virtual ~Connection(void) {}
29-
30-
31- /*!
32- \brief 内部状態を返す
33-
34- \return 内部状態を示す文字列
35- */
36- virtual const char* what(void) const = 0;
37-
38-
39- /*!
40- \brief デバイスへの接続
41-
42- \param[in] device 接続デバイス名
43- \param[in] baudrate 接続ボーレート
44-
45- \retval true 成功
46- \retval false 失敗
47- */
48- virtual bool connect(const char* device, long baudrate) = 0;
49-
50-
51- /*!
52- \brief 切断
53- */
54- virtual void disconnect(void) = 0;
55-
56-
57- /*!
58- \brief ボーレートの変更
59-
60- \param[in] baudrate ボーレート
61-
62- \retval 0 正常
63- \retval < 0 エラー
64- */
65- virtual bool setBaudrate(long baudrate) = 0;
66-
67-
68- /*!
69- \brief ボーレートを返す
70-
71- \retval ボーレート
72-
73- \attention SerialDevice でのみ有効
74- */
75- virtual long baudrate(void) const = 0;
76-
77-
78- /*!
79- \brief 接続状態を返す
80-
81- \retval true 接続中
82- \retval false 切断中
83- */
84- virtual bool isConnected(void) const = 0;
85-
86-
87- /*!
88- \brief 送信
89-
90- \param[in] data 送信データ
91- \param[in] count 送信バイト数
92-
93- \return 送信したバイト数
94- */
95- virtual int send(const char* data, size_t count) = 0;
96-
97-
98- /*!
99- \brief 受信
100-
101- \param[out] data 受信用バッファ
102- \param[in] count 受信バッファの最大サイズ
103- \param[in] timeout タイムアウト時間 [msec]
104- */
105- virtual int receive(char* data, size_t count, int timeout) = 0;
106-
107-
108- /*!
109- \brief 受信済みデータのバイト数を返す
110-
111- \return 受信済みデータのバイト数
112- */
113- virtual size_t size(void) const = 0;
114-
115-
116- /*!
117- \brief バッファの内容を強制的に出力する
118- */
119- virtual void flush(void) = 0;
120-
121-
122- /*!
123- \brief 送受信データのクリア
124-
125- 送信バッファ、受信済みデータをクリアする
126- */
127- virtual void clear(void) = 0;
128-
129-
130- /*!
131- \brief 1文字書き戻す
132-
133- \param[in] ch 書き戻す文字
134- */
135- virtual void ungetc(const char ch) = 0;
136- };
137-}
138-
139-#endif /* !QRK_CONNECTION_H */
1+#ifndef QRK_CONNECTION_H
2+#define QRK_CONNECTION_H
3+
4+/*!
5+ \file
6+ \brief 通信インターフェース
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include <cstddef>
14+
15+
16+namespace qrk
17+{
18+ enum {
19+ ReceiveTimeout = -1,
20+ ErrorLastIndex = -2,
21+ };
22+
23+
24+ //! 通信インターフェース
25+ class Connection
26+ {
27+ public:
28+ virtual ~Connection(void) {}
29+
30+
31+ /*!
32+ \brief 内部状態を返す
33+
34+ \return 内部状態を示す文字列
35+ */
36+ virtual const char* what(void) const = 0;
37+
38+
39+ /*!
40+ \brief デバイスへの接続
41+
42+ \param[in] device 接続デバイス名
43+ \param[in] baudrate 接続ボーレート
44+
45+ \retval true 成功
46+ \retval false 失敗
47+ */
48+ virtual bool connect(const char* device, long baudrate) = 0;
49+
50+
51+ /*!
52+ \brief 切断
53+ */
54+ virtual void disconnect(void) = 0;
55+
56+
57+ /*!
58+ \brief ボーレートの変更
59+
60+ \param[in] baudrate ボーレート
61+
62+ \retval 0 正常
63+ \retval < 0 エラー
64+ */
65+ virtual bool setBaudrate(long baudrate) = 0;
66+
67+
68+ /*!
69+ \brief ボーレートを返す
70+
71+ \retval ボーレート
72+
73+ \attention SerialDevice でのみ有効
74+ */
75+ virtual long baudrate(void) const = 0;
76+
77+
78+ /*!
79+ \brief 接続状態を返す
80+
81+ \retval true 接続中
82+ \retval false 切断中
83+ */
84+ virtual bool isConnected(void) const = 0;
85+
86+
87+ /*!
88+ \brief 送信
89+
90+ \param[in] data 送信データ
91+ \param[in] count 送信バイト数
92+
93+ \return 送信したバイト数
94+ */
95+ virtual int send(const char* data, size_t count) = 0;
96+
97+
98+ /*!
99+ \brief 受信
100+
101+ \param[out] data 受信用バッファ
102+ \param[in] count 受信バッファの最大サイズ
103+ \param[in] timeout タイムアウト時間 [msec]
104+ */
105+ virtual int receive(char* data, size_t count, int timeout) = 0;
106+
107+
108+ /*!
109+ \brief 受信済みデータのバイト数を返す
110+
111+ \return 受信済みデータのバイト数
112+ */
113+ virtual size_t size(void) const = 0;
114+
115+
116+ /*!
117+ \brief バッファの内容を強制的に出力する
118+ */
119+ virtual void flush(void) = 0;
120+
121+
122+ /*!
123+ \brief 送受信データのクリア
124+
125+ 送信バッファ、受信済みデータをクリアする
126+ */
127+ virtual void clear(void) = 0;
128+
129+
130+ /*!
131+ \brief 1文字書き戻す
132+
133+ \param[in] ch 書き戻す文字
134+ */
135+ virtual void ungetc(const char ch) = 0;
136+ };
137+}
138+
139+#endif /* !QRK_CONNECTION_H */
--- trunk/programs/UrgViewer/UrgViewerWindow.cpp (revision 1987)
+++ trunk/programs/UrgViewer/UrgViewerWindow.cpp (revision 1988)
@@ -291,6 +291,7 @@
291291 serial_connection_widget_.setConnected(connected);
292292 ethernet_connection_widget_.setConnected(connected);
293293 capture_setting_widget_.setConnected(connected);
294+#if 1
294295 if (! connected) {
295296 // エラーメッセージのポップアップ表示
296297 QString error_message = localedToUnicode(urg_.what());
@@ -298,6 +299,7 @@
298299 tr("Connection error"), error_message);
299300 return;
300301 }
302+#endif
301303
302304 // パラメータ情報が与えられていない場合、センサ情報を反映させる
303305 parameter_ = urg_.parameter();
--- trunk/programs/UrgRecorder/UrgRecorderWidget.cpp (revision 1987)
+++ trunk/programs/UrgRecorder/UrgRecorderWidget.cpp (revision 1988)
@@ -1,500 +1,500 @@
1-/*!
2- \file
3- \brief URG データの記録ウィジット
4-
5- \author Satofumi KAMIMURA
6-
7- $Id$
8-*/
9-
10-#include "UrgRecorderWidget.h"
11-#include "SerialConnectionWidget.h"
12-#include "EthernetConnectionWidget.h"
13-#include "RecordConnection.h"
14-#include "UrgDevice.h"
15-#include "UrgUsbCom.h"
16-#include "FindComPorts.h"
17-#include "DetectOS.h"
18-#include "TcpipSocket.h"
19-#include <QTimer>
20-#include <QDateTime>
21-#include <QDir>
22-#include <QTextStream>
23-#include <QMessageBox>
24-#include <QShortcut>
25-#include <QSettings>
26-
27-using namespace qrk;
28-using namespace std;
29-
30-#if defined(MSC)
31-#define snprintf _snprintf
32-#endif
33-
34-
35-namespace
36-{
37- const char* Organization = "Hokuyo LTD.";
38- const char* Application = "URG Recorder";
39- const char* UrgDefaultAddress = "192.168.0.10";
40-
41- enum {
42- UrgDefaultPort = 10940,
43- DefaultCaptureTimes = 10,
44- };
45-}
46-
47-
48-struct UrgRecorderWidget::pImpl
49-{
50- UrgRecorderWidget* widget_;
51- SerialConnectionWidget serial_connection_widget_;
52- EthernetConnectionWidget ethernet_connection_widget_;
53-
54- UrgUsbCom urg_usb_;
55- FindComPorts urg_finder_;
56- UrgDevice urg_;
57- Connection* serial_connection_;
58- TcpipSocket ethernet_connection_;
59-
60- QTimer capture_timer_;
61- QString save_directory_;
62- size_t capture_max_;
63- size_t total_times_;
64- bool is_raw_record_;
65-
66- bool intensity_mode_;
67- bool is_using_serial_;
68-
69-
70- pImpl(UrgRecorderWidget* widget)
71- : widget_(widget), serial_connection_(NULL),
72- capture_max_(1), total_times_(0), is_raw_record_(false),
73- intensity_mode_(false), is_using_serial_(true)
74- {
75- urg_finder_.addBaseName("/dev/ttyACM");
76- urg_finder_.addBaseName("/dev/tty.usbmodem");
77- urg_finder_.addDriverName("URG Series USB Device Driver");
78- urg_finder_.addDriverName("URG-X002 USB Device Driver");
79-
80- ethernet_connection_widget_.setPort(UrgDefaultPort);
81- }
82-
83-
84- void initializeForm(void)
85- {
86- // 位置と大きさを読み出す
87- loadSettings();
88-
89- // ConnectionWidget の配置
90- widget_->connection_layout_->addWidget(&serial_connection_widget_);
91- widget_->connection_layout_->addWidget(&ethernet_connection_widget_);
92- widget_->connection_dummy_label_->hide();
93-
94- // イベントの接続
95- connect(&serial_connection_widget_, SIGNAL(rescanRequest()),
96- widget_, SLOT(rescanPressed()));
97- connect(&serial_connection_widget_,
98- SIGNAL(connectRequest(bool, const std::string&)),
99- widget_, SLOT(connectPressed(bool, const std::string&)));
100-
101- connect(&ethernet_connection_widget_,
102- SIGNAL(connectRequest(bool, const std::string&,
103- unsigned short)),
104- widget_, SLOT(connectPressed(bool, const std::string&,
105- unsigned short)));
106-
107- connect(widget_->times_spinbox_, SIGNAL(valueChanged(int)),
108- widget_, SLOT(timesChanged(int)));
109-
110- connect(widget_->record_button_, SIGNAL(clicked()),
111- widget_, SLOT(recordPressed()));
112- connect(widget_->cancel_button_, SIGNAL(clicked()),
113- widget_, SLOT(cancelPressed()));
114-
115- connect(widget_->raw_button_, SIGNAL(toggled(bool)),
116- widget_, SLOT(rawButtonChanged(bool)));
117-
118- connect(&capture_timer_, SIGNAL(timeout()),
119- widget_, SLOT(recordData()));
120-
121- connect(widget_->change_button_, SIGNAL(clicked()),
122- widget_, SLOT(changeButtonPressed()));
123- }
124-
125-
126- void loadSettings(void)
127- {
128- QSettings settings(Organization, Application);
129- widget_->restoreGeometry(settings.value("geometry").toByteArray());
130- int capture_times =
131- settings.value("capture_times", DefaultCaptureTimes).toInt();
132- widget_->times_spinbox_->setValue(capture_times);
133- widget_->times_progress_->setMaximum(capture_times);
134-
135- is_raw_record_ = settings.value("raw_button_checked", false).toBool();
136- widget_->raw_button_->setChecked(is_raw_record_);
137- rawButtonChanged(is_raw_record_);
138-
139- is_using_serial_ = settings.value("serial_connection", true).toBool();
140- if (is_using_serial_) {
141- selectSerial();
142- } else {
143- selectEthernet();
144- }
145-
146- string address =
147- settings.value("address",
148- UrgDefaultAddress).toString().toStdString();
149- ethernet_connection_widget_.setAddress(address);
150- unsigned short port = settings.value("port", UrgDefaultPort).toInt();
151- ethernet_connection_widget_.setPort(port);
152- }
153-
154-
155- void saveSettings(void)
156- {
157- QSettings settings(Organization, Application);
158- settings.setValue("geometry", widget_->saveGeometry());
159- settings.setValue("capture_times", widget_->times_spinbox_->value());
160- settings.setValue("raw_button_checked",
161- widget_->raw_button_->isChecked());
162-
163- settings.setValue("serial_connection", is_using_serial_);
164- settings.setValue("address",
165- ethernet_connection_widget_.address().c_str());
166- settings.setValue("port", ethernet_connection_widget_.port());
167- }
168-
169-
170- void setRecording(bool recording)
171- {
172- widget_->record_button_->setEnabled(! recording);
173- widget_->cancel_button_->setEnabled(recording);
174- widget_->output_group_->setEnabled(! recording);
175- widget_->times_group_->setEnabled(! recording);
176- }
177-
178-
179- void recordPressed(void)
180- {
181- setRecording(true);
182-
183- // 出力先ディレクトリの作成
184- save_directory_ =
185- QDateTime::currentDateTime().toString("yyyy-MM-dd_hh_mm_ss");
186- QDir dir;
187- dir.mkdir(save_directory_);
188-
189- // 取得モードの設定
190- is_raw_record_ = widget_->raw_button_->isChecked();
191- if (is_raw_record_) {
192- is_raw_record_ = true;
193- serial_connection_ = urg_.connection();
194- string send_file = save_directory_.toStdString() + "/send.txt";
195- string receive_file =
196- save_directory_.toStdString() + "/receive.txt";
197- urg_.setConnection(new RecordConnection(serial_connection_,
198- send_file.c_str(),
199- receive_file.c_str()));
200-
201- // ログに URG の情報を含めるための呼び出し
202- urg_.loadParameter();
203- }
204-
205- // データ取得の開始
206- capture_max_ = widget_->times_spinbox_->value();
207- total_times_ = 0;
208- if (intensity_mode_) {
209- urg_.setCaptureMode(IntensityCapture);
210- } else {
211- urg_.setCaptureMode(AutoCapture);
212- }
213- capture_timer_.setInterval(urg_.scanMsec() / 2);
214- capture_timer_.start();
215- }
216-
217-
218- void recordData(void)
219- {
220- vector<long> data;
221- vector<long> intensity_data;
222-
223- int n;
224- if (intensity_mode_) {
225- n = urg_.captureWithIntensity(data, intensity_data);
226- } else {
227- n = urg_.capture(data);
228- }
229-
230- if (n <= 0) {
231- return;
232- }
233- ++total_times_;
234-
235- if (! is_raw_record_) {
236-
237- // ファイルへのデータ書き出し
238- char buffer[] = "/data_xxxxxxxxxx.csv";
239- snprintf(buffer, sizeof(buffer), "/data_%09d.csv", total_times_);
240- QFile file(save_directory_ + QString(buffer));
241- if (! file.open(QIODevice::WriteOnly)) {
242- // !!! エラー表示
243- return;
244- }
245-
246- QTextStream fout(&file);
247- saveFile(fout, data, intensity_data);
248- }
249-
250- widget_->times_progress_->setValue(total_times_);
251- if (total_times_ >= capture_max_) {
252- stopRecording();
253- }
254- }
255-
256-
257- void stopRecording(void)
258- {
259- setRecording(false);
260- capture_timer_.stop();
261- widget_->times_progress_->setValue(0);
262-
263- urg_.stop();
264-
265- if (is_raw_record_) {
266- Connection* connection = urg_.connection();
267- if (connection != serial_connection_) {
268- delete connection;
269- urg_.setConnection(serial_connection_);
270- }
271- }
272- }
273-
274-
275- void saveFile(QTextStream& fout, const vector<long>& data,
276- vector<long>& intensity_data)
277- {
278- size_t n = data.size();
279- for (size_t i = 0; i < n; ++i) {
280- long length = data[i];
281- double radian = urg_.index2rad(i);
282- double x = length * cos(radian);
283- double y = length * sin(radian);
284- fout << i << ',' << length << ','
285- << radian << ',' << x << ',' << y;
286-
287- if (intensity_mode_) {
288- fout << ',' << intensity_data[i];
289- }
290-
291- fout << endl;
292- }
293- }
294-
295-
296- void rawButtonChanged(bool checked)
297- {
298- if (checked) {
299- widget_->sample_text_->clear();
300- widget_->sample_text_->
301- insertPlainText("# receive data sample\n"
302- "MD0044072501000\n"
303- "99b\n"
304- "...");
305- } else {
306- widget_->sample_text_->clear();
307- widget_->sample_text_->
308- insertPlainText("# index, length, radian, x, y\n"
309- "0,669,-2.08621,-329.749,-582.088\n"
310- "1,667,-2.08008,-325.196,-582.354\n"
311- "...");
312- }
313- }
314-
315-
316- void selectSerial(void)
317- {
318- widget_->change_button_->setText(tr("Change to Ethernet"));
319- ethernet_connection_widget_.hide();
320- serial_connection_widget_.show();
321-
322- if (serial_connection_) {
323- urg_.setConnection(serial_connection_);
324- }
325-
326- is_using_serial_ = true;
327- }
328-
329-
330- void selectEthernet(void)
331- {
332- widget_->change_button_->setText(tr("Change to Serial"));
333- serial_connection_widget_.hide();
334- ethernet_connection_widget_.show();
335-
336- urg_.setConnection(&ethernet_connection_);
337-
338- is_using_serial_ = false;
339- }
340-
341-
342- void set_enables(bool connected)
343- {
344- widget_->record_group_->setEnabled(connected);
345- widget_->cancel_button_->setEnabled(false);
346-
347- serial_connection_widget_.setConnected(connected);
348- ethernet_connection_widget_.setConnected(connected);
349-
350- if (connected) {
351- // フォーカスを Record ボタンに移動させる
352- widget_->record_button_->setFocus();
353- }
354- }
355-};
356-
357-
358-UrgRecorderWidget::UrgRecorderWidget(QWidget* parent)
359- : QWidget(parent), pimpl(new pImpl(this))
360-{
361- setupUi(this);
362-
363- // フォームを初期化し、最初の表示を行う
364- pimpl->initializeForm();
365- rescanPressed();
366-
367- pimpl->serial_connection_widget_.setFocus();
368-
369- // Ctrl-q, Alt-F4 で終了させる
370- (void) new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close()));
371- (void) new QShortcut(Qt::ALT + Qt::Key_F4, this, SLOT(close()));
372-}
373-
374-
375-UrgRecorderWidget::~UrgRecorderWidget(void)
376-{
377-}
378-
379-
380-void UrgRecorderWidget::setIntensityMode(void)
381-{
382- if (! pimpl->intensity_mode_) {
383- pimpl->intensity_mode_ = true;
384- if (pimpl->intensity_mode_) {
385- setWindowTitle(windowTitle() + " " + tr("[intensity]"));
386- }
387- }
388-}
389-
390-
391-void UrgRecorderWidget::closeEvent(QCloseEvent* event)
392-{
393- static_cast<void>(event);
394-
395- pimpl->urg_.stop();
396- pimpl->saveSettings();
397-}
398-
399-
400-void UrgRecorderWidget::rescanPressed(void)
401-{
402- vector<string> devices;
403- pimpl->urg_finder_.find(devices);
404- for (vector<string>::iterator it = devices.begin();
405- it != devices.end(); ++it) {
406- if (pimpl->urg_usb_.isUsbCom(it->c_str())) {
407- *it = *it + " [URG]";
408- }
409- }
410- pimpl->serial_connection_widget_.setDevices(devices);
411-}
412-
413-
414-void UrgRecorderWidget::connectPressed(bool connection,
415- const string& device)
416-{
417- // !!! 接続処理をスレッドで行うように調整する
418- bool connected = connection;
419-
420- if (connection) {
421- if (! pimpl->urg_.connect(device.c_str())) {
422- QMessageBox::warning(this, tr("Connection error"),
423- pimpl->urg_.what());
424- connected = false;
425- }
426- } else {
427- pimpl->stopRecording();
428- }
429-
430- pimpl->set_enables(connected);
431-}
432-
433-
434-void UrgRecorderWidget::connectPressed(bool connection,
435- const std::string& address,
436- unsigned short port)
437-{
438- // !!! 接続処理をスレッドで行うように調整する
439- bool connected = connection;
440-
441- fprintf(stderr, "%p, %p\n", &pimpl->ethernet_connection_, pimpl->urg_.connection());
442- if (connection) {
443- if (! pimpl->urg_.connect(address.c_str(), port)) {
444- QMessageBox::warning(this, tr("Connection error"),
445- pimpl->urg_.what());
446- connected = false;
447- }
448- } else {
449- pimpl->stopRecording();
450- }
451-
452- pimpl->set_enables(connected);
453-}
454-
455-
456-void UrgRecorderWidget::recordPressed(void)
457-{
458- if (pimpl->capture_timer_.isActive()) {
459- return;
460- }
461- pimpl->recordPressed();
462-}
463-
464-
465-void UrgRecorderWidget::cancelPressed(void)
466-{
467- pimpl->stopRecording();
468-}
469-
470-
471-void UrgRecorderWidget::timesChanged(int times)
472-{
473- times_progress_->setMaximum(times);
474-
475- // 再描画が行われるように、2回ほど値をセットしている
476- times_progress_->setValue(1);
477- times_progress_->setValue(0);
478-}
479-
480-
481-void UrgRecorderWidget::recordData(void)
482-{
483- pimpl->recordData();
484-}
485-
486-
487-void UrgRecorderWidget::rawButtonChanged(bool checked)
488-{
489- pimpl->rawButtonChanged(checked);
490-}
491-
492-
493-void UrgRecorderWidget::changeButtonPressed(void)
494-{
495- if (pimpl->is_using_serial_) {
496- pimpl->selectEthernet();
497- } else {
498- pimpl->selectSerial();
499- }
500-}
1+/*!
2+ \file
3+ \brief URG データの記録ウィジット
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "UrgRecorderWidget.h"
11+#include "SerialConnectionWidget.h"
12+#include "EthernetConnectionWidget.h"
13+#include "RecordConnection.h"
14+#include "UrgDevice.h"
15+#include "UrgUsbCom.h"
16+#include "FindComPorts.h"
17+#include "DetectOS.h"
18+#include "TcpipSocket.h"
19+#include <QTimer>
20+#include <QDateTime>
21+#include <QDir>
22+#include <QTextStream>
23+#include <QMessageBox>
24+#include <QShortcut>
25+#include <QSettings>
26+
27+using namespace qrk;
28+using namespace std;
29+
30+#if defined(MSC)
31+#define snprintf _snprintf
32+#endif
33+
34+
35+namespace
36+{
37+ const char* Organization = "Hokuyo LTD.";
38+ const char* Application = "URG Recorder";
39+ const char* UrgDefaultAddress = "192.168.0.10";
40+
41+ enum {
42+ UrgDefaultPort = 10940,
43+ DefaultCaptureTimes = 10,
44+ };
45+}
46+
47+
48+struct UrgRecorderWidget::pImpl
49+{
50+ UrgRecorderWidget* widget_;
51+ SerialConnectionWidget serial_connection_widget_;
52+ EthernetConnectionWidget ethernet_connection_widget_;
53+
54+ UrgUsbCom urg_usb_;
55+ FindComPorts urg_finder_;
56+ UrgDevice urg_;
57+ Connection* serial_connection_;
58+ TcpipSocket ethernet_connection_;
59+
60+ QTimer capture_timer_;
61+ QString save_directory_;
62+ size_t capture_max_;
63+ size_t total_times_;
64+ bool is_raw_record_;
65+
66+ bool intensity_mode_;
67+ bool is_using_serial_;
68+
69+
70+ pImpl(UrgRecorderWidget* widget)
71+ : widget_(widget), serial_connection_(NULL),
72+ capture_max_(1), total_times_(0), is_raw_record_(false),
73+ intensity_mode_(false), is_using_serial_(true)
74+ {
75+ urg_finder_.addBaseName("/dev/ttyACM");
76+ urg_finder_.addBaseName("/dev/tty.usbmodem");
77+ urg_finder_.addDriverName("URG Series USB Device Driver");
78+ urg_finder_.addDriverName("URG-X002 USB Device Driver");
79+
80+ ethernet_connection_widget_.setPort(UrgDefaultPort);
81+ }
82+
83+
84+ void initializeForm(void)
85+ {
86+ // 位置と大きさを読み出す
87+ loadSettings();
88+
89+ // ConnectionWidget の配置
90+ widget_->connection_layout_->addWidget(&serial_connection_widget_);
91+ widget_->connection_layout_->addWidget(&ethernet_connection_widget_);
92+ widget_->connection_dummy_label_->hide();
93+
94+ // イベントの接続
95+ connect(&serial_connection_widget_, SIGNAL(rescanRequest()),
96+ widget_, SLOT(rescanPressed()));
97+ connect(&serial_connection_widget_,
98+ SIGNAL(connectRequest(bool, const std::string&)),
99+ widget_, SLOT(connectPressed(bool, const std::string&)));
100+
101+ connect(&ethernet_connection_widget_,
102+ SIGNAL(connectRequest(bool, const std::string&,
103+ unsigned short)),
104+ widget_, SLOT(connectPressed(bool, const std::string&,
105+ unsigned short)));
106+
107+ connect(widget_->times_spinbox_, SIGNAL(valueChanged(int)),
108+ widget_, SLOT(timesChanged(int)));
109+
110+ connect(widget_->record_button_, SIGNAL(clicked()),
111+ widget_, SLOT(recordPressed()));
112+ connect(widget_->cancel_button_, SIGNAL(clicked()),
113+ widget_, SLOT(cancelPressed()));
114+
115+ connect(widget_->raw_button_, SIGNAL(toggled(bool)),
116+ widget_, SLOT(rawButtonChanged(bool)));
117+
118+ connect(&capture_timer_, SIGNAL(timeout()),
119+ widget_, SLOT(recordData()));
120+
121+ connect(widget_->change_button_, SIGNAL(clicked()),
122+ widget_, SLOT(changeButtonPressed()));
123+ }
124+
125+
126+ void loadSettings(void)
127+ {
128+ QSettings settings(Organization, Application);
129+ widget_->restoreGeometry(settings.value("geometry").toByteArray());
130+ int capture_times =
131+ settings.value("capture_times", DefaultCaptureTimes).toInt();
132+ widget_->times_spinbox_->setValue(capture_times);
133+ widget_->times_progress_->setMaximum(capture_times);
134+
135+ is_raw_record_ = settings.value("raw_button_checked", false).toBool();
136+ widget_->raw_button_->setChecked(is_raw_record_);
137+ rawButtonChanged(is_raw_record_);
138+
139+ is_using_serial_ = settings.value("serial_connection", true).toBool();
140+ if (is_using_serial_) {
141+ selectSerial();
142+ } else {
143+ selectEthernet();
144+ }
145+
146+ string address =
147+ settings.value("address",
148+ UrgDefaultAddress).toString().toStdString();
149+ ethernet_connection_widget_.setAddress(address);
150+ unsigned short port = settings.value("port", UrgDefaultPort).toInt();
151+ ethernet_connection_widget_.setPort(port);
152+ }
153+
154+
155+ void saveSettings(void)
156+ {
157+ QSettings settings(Organization, Application);
158+ settings.setValue("geometry", widget_->saveGeometry());
159+ settings.setValue("capture_times", widget_->times_spinbox_->value());
160+ settings.setValue("raw_button_checked",
161+ widget_->raw_button_->isChecked());
162+
163+ settings.setValue("serial_connection", is_using_serial_);
164+ settings.setValue("address",
165+ ethernet_connection_widget_.address().c_str());
166+ settings.setValue("port", ethernet_connection_widget_.port());
167+ }
168+
169+
170+ void setRecording(bool recording)
171+ {
172+ widget_->record_button_->setEnabled(! recording);
173+ widget_->cancel_button_->setEnabled(recording);
174+ widget_->output_group_->setEnabled(! recording);
175+ widget_->times_group_->setEnabled(! recording);
176+ }
177+
178+
179+ void recordPressed(void)
180+ {
181+ setRecording(true);
182+
183+ // 出力先ディレクトリの作成
184+ save_directory_ =
185+ QDateTime::currentDateTime().toString("yyyy-MM-dd_hh_mm_ss");
186+ QDir dir;
187+ dir.mkdir(save_directory_);
188+
189+ // 取得モードの設定
190+ is_raw_record_ = widget_->raw_button_->isChecked();
191+ if (is_raw_record_) {
192+ is_raw_record_ = true;
193+ serial_connection_ = urg_.connection();
194+ string send_file = save_directory_.toStdString() + "/send.txt";
195+ string receive_file =
196+ save_directory_.toStdString() + "/receive.txt";
197+ urg_.setConnection(new RecordConnection(serial_connection_,
198+ send_file.c_str(),
199+ receive_file.c_str()));
200+
201+ // ログに URG の情報を含めるための呼び出し
202+ urg_.loadParameter();
203+ }
204+
205+ // データ取得の開始
206+ capture_max_ = widget_->times_spinbox_->value();
207+ total_times_ = 0;
208+ if (intensity_mode_) {
209+ urg_.setCaptureMode(IntensityCapture);
210+ } else {
211+ urg_.setCaptureMode(AutoCapture);
212+ }
213+ capture_timer_.setInterval(urg_.scanMsec() / 2);
214+ capture_timer_.start();
215+ }
216+
217+
218+ void recordData(void)
219+ {
220+ vector<long> data;
221+ vector<long> intensity_data;
222+
223+ int n;
224+ if (intensity_mode_) {
225+ n = urg_.captureWithIntensity(data, intensity_data);
226+ } else {
227+ n = urg_.capture(data);
228+ }
229+
230+ if (n <= 0) {
231+ return;
232+ }
233+ ++total_times_;
234+
235+ if (! is_raw_record_) {
236+
237+ // ファイルへのデータ書き出し
238+ char buffer[] = "/data_xxxxxxxxxx.csv";
239+ snprintf(buffer, sizeof(buffer), "/data_%09d.csv", total_times_);
240+ QFile file(save_directory_ + QString(buffer));
241+ if (! file.open(QIODevice::WriteOnly)) {
242+ // !!! エラー表示
243+ return;
244+ }
245+
246+ QTextStream fout(&file);
247+ saveFile(fout, data, intensity_data);
248+ }
249+
250+ widget_->times_progress_->setValue(total_times_);
251+ if (total_times_ >= capture_max_) {
252+ stopRecording();
253+ }
254+ }
255+
256+
257+ void stopRecording(void)
258+ {
259+ setRecording(false);
260+ capture_timer_.stop();
261+ widget_->times_progress_->setValue(0);
262+
263+ urg_.stop();
264+
265+ if (is_raw_record_) {
266+ Connection* connection = urg_.connection();
267+ if (connection != serial_connection_) {
268+ delete connection;
269+ urg_.setConnection(serial_connection_);
270+ }
271+ }
272+ }
273+
274+
275+ void saveFile(QTextStream& fout, const vector<long>& data,
276+ vector<long>& intensity_data)
277+ {
278+ size_t n = data.size();
279+ for (size_t i = 0; i < n; ++i) {
280+ long length = data[i];
281+ double radian = urg_.index2rad(i);
282+ double x = length * cos(radian);
283+ double y = length * sin(radian);
284+ fout << i << ',' << length << ','
285+ << radian << ',' << x << ',' << y;
286+
287+ if (intensity_mode_) {
288+ fout << ',' << intensity_data[i];
289+ }
290+
291+ fout << endl;
292+ }
293+ }
294+
295+
296+ void rawButtonChanged(bool checked)
297+ {
298+ if (checked) {
299+ widget_->sample_text_->clear();
300+ widget_->sample_text_->
301+ insertPlainText("# receive data sample\n"
302+ "MD0044072501000\n"
303+ "99b\n"
304+ "...");
305+ } else {
306+ widget_->sample_text_->clear();
307+ widget_->sample_text_->
308+ insertPlainText("# index, length, radian, x, y\n"
309+ "0,669,-2.08621,-329.749,-582.088\n"
310+ "1,667,-2.08008,-325.196,-582.354\n"
311+ "...");
312+ }
313+ }
314+
315+
316+ void selectSerial(void)
317+ {
318+ widget_->change_button_->setText(tr("Change to Ethernet"));
319+ ethernet_connection_widget_.hide();
320+ serial_connection_widget_.show();
321+
322+ if (serial_connection_) {
323+ urg_.setConnection(serial_connection_);
324+ }
325+
326+ is_using_serial_ = true;
327+ }
328+
329+
330+ void selectEthernet(void)
331+ {
332+ widget_->change_button_->setText(tr("Change to Serial"));
333+ serial_connection_widget_.hide();
334+ ethernet_connection_widget_.show();
335+
336+ urg_.setConnection(&ethernet_connection_);
337+
338+ is_using_serial_ = false;
339+ }
340+
341+
342+ void set_enables(bool connected)
343+ {
344+ widget_->record_group_->setEnabled(connected);
345+ widget_->cancel_button_->setEnabled(false);
346+
347+ serial_connection_widget_.setConnected(connected);
348+ ethernet_connection_widget_.setConnected(connected);
349+
350+ if (connected) {
351+ // フォーカスを Record ボタンに移動させる
352+ widget_->record_button_->setFocus();
353+ }
354+ }
355+};
356+
357+
358+UrgRecorderWidget::UrgRecorderWidget(QWidget* parent)
359+ : QWidget(parent), pimpl(new pImpl(this))
360+{
361+ setupUi(this);
362+
363+ // フォームを初期化し、最初の表示を行う
364+ pimpl->initializeForm();
365+ rescanPressed();
366+
367+ pimpl->serial_connection_widget_.setFocus();
368+
369+ // Ctrl-q, Alt-F4 で終了させる
370+ (void) new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close()));
371+ (void) new QShortcut(Qt::ALT + Qt::Key_F4, this, SLOT(close()));
372+}
373+
374+
375+UrgRecorderWidget::~UrgRecorderWidget(void)
376+{
377+}
378+
379+
380+void UrgRecorderWidget::setIntensityMode(void)
381+{
382+ if (! pimpl->intensity_mode_) {
383+ pimpl->intensity_mode_ = true;
384+ if (pimpl->intensity_mode_) {
385+ setWindowTitle(windowTitle() + " " + tr("[intensity]"));
386+ }
387+ }
388+}
389+
390+
391+void UrgRecorderWidget::closeEvent(QCloseEvent* event)
392+{
393+ static_cast<void>(event);
394+
395+ pimpl->urg_.stop();
396+ pimpl->saveSettings();
397+}
398+
399+
400+void UrgRecorderWidget::rescanPressed(void)
401+{
402+ vector<string> devices;
403+ pimpl->urg_finder_.find(devices);
404+ for (vector<string>::iterator it = devices.begin();
405+ it != devices.end(); ++it) {
406+ if (pimpl->urg_usb_.isUsbCom(it->c_str())) {
407+ *it = *it + " [URG]";
408+ }
409+ }
410+ pimpl->serial_connection_widget_.setDevices(devices);
411+}
412+
413+
414+void UrgRecorderWidget::connectPressed(bool connection,
415+ const string& device)
416+{
417+ // !!! 接続処理をスレッドで行うように調整する
418+ bool connected = connection;
419+
420+ if (connection) {
421+ if (! pimpl->urg_.connect(device.c_str())) {
422+ QMessageBox::warning(this, tr("Connection error"),
423+ pimpl->urg_.what());
424+ connected = false;
425+ }
426+ } else {
427+ pimpl->stopRecording();
428+ }
429+
430+ pimpl->set_enables(connected);
431+}
432+
433+
434+void UrgRecorderWidget::connectPressed(bool connection,
435+ const std::string& address,
436+ unsigned short port)
437+{
438+ // !!! 接続処理をスレッドで行うように調整する
439+ bool connected = connection;
440+
441+ fprintf(stderr, "%p, %p\n", &pimpl->ethernet_connection_, pimpl->urg_.connection());
442+ if (connection) {
443+ if (! pimpl->urg_.connect(address.c_str(), port)) {
444+ QMessageBox::warning(this, tr("Connection error"),
445+ pimpl->urg_.what());
446+ connected = false;
447+ }
448+ } else {
449+ pimpl->stopRecording();
450+ }
451+
452+ pimpl->set_enables(connected);
453+}
454+
455+
456+void UrgRecorderWidget::recordPressed(void)
457+{
458+ if (pimpl->capture_timer_.isActive()) {
459+ return;
460+ }
461+ pimpl->recordPressed();
462+}
463+
464+
465+void UrgRecorderWidget::cancelPressed(void)
466+{
467+ pimpl->stopRecording();
468+}
469+
470+
471+void UrgRecorderWidget::timesChanged(int times)
472+{
473+ times_progress_->setMaximum(times);
474+
475+ // 再描画が行われるように、2回ほど値をセットしている
476+ times_progress_->setValue(1);
477+ times_progress_->setValue(0);
478+}
479+
480+
481+void UrgRecorderWidget::recordData(void)
482+{
483+ pimpl->recordData();
484+}
485+
486+
487+void UrgRecorderWidget::rawButtonChanged(bool checked)
488+{
489+ pimpl->rawButtonChanged(checked);
490+}
491+
492+
493+void UrgRecorderWidget::changeButtonPressed(void)
494+{
495+ if (pimpl->is_using_serial_) {
496+ pimpl->selectEthernet();
497+ } else {
498+ pimpl->selectSerial();
499+ }
500+}
旧リポジトリブラウザで表示