Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pierre NARVOR
seatrac_driver
Commits
9dbb1617
Commit
9dbb1617
authored
Jul 12, 2021
by
Pierre NARVOR
Browse files
[driver] Renamed SerialHandler in SeatracSerial
parent
3925d5dd
Changes
8
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
9dbb1617
...
...
@@ -6,12 +6,12 @@ message(STATUS "Boost version : ${Boost_VERSION}")
message
(
STATUS
"Boost location :
${
Boost_INCLUDE_DIRS
}
"
)
list
(
APPEND seatrac_driver_headers
include/seatrac_driver/Se
rialHandler
.h
include/seatrac_driver/Se
atracSerial
.h
include/seatrac_driver/SeatracDriver.h
)
add_library
(
seatrac_driver SHARED
src/Se
rialHandler
.cpp
src/Se
atracSerial
.cpp
src/SeatracDriver.cpp
)
set_target_properties
(
seatrac_driver PROPERTIES
...
...
include/seatrac_driver/SeatracDriver.h
View file @
9dbb1617
#ifndef _DEF_SEATRAC_DRIVER_SEATRAC_DRIVER_H_
#define _DEF_SEATRAC_DRIVER_SEATRAC_DRIVER_H_
#include <seatrac_driver/Se
rialHandler
.h>
#include <seatrac_driver/Se
atracSerial
.h>
namespace
narval
{
namespace
seatrac
{
class
SeatracDriver
:
Se
rialHandler
class
SeatracDriver
:
Se
atracSerial
{
public:
...
...
include/seatrac_driver/Se
rialHandler
.h
→
include/seatrac_driver/Se
atracSerial
.h
View file @
9dbb1617
#ifndef _DEF_SEATRAC_DRIVER_SE
RIAL_HANDLE
_H_
#define _DEF_SEATRAC_DRIVER_SE
RIAL_HANDLE
_H_
#ifndef _DEF_SEATRAC_DRIVER_SE
ATRAC_SERIAL
_H_
#define _DEF_SEATRAC_DRIVER_SE
ATRAC_SERIAL
_H_
#include <iostream>
#include <sstream>
...
...
@@ -12,7 +12,7 @@
namespace
narval
{
namespace
seatrac
{
class
Se
rialHandler
class
Se
atracSerial
{
public:
...
...
@@ -46,11 +46,11 @@ class SerialHandler
public:
Se
rialHandler
(
const
IoServicePtr
&
ioService
,
Se
atracSerial
(
const
IoServicePtr
&
ioService
,
const
std
::
string
&
port
=
"/dev/narval_usbl"
);
};
};
//namespace seatrac
};
//namespace narval
#endif //_DEF_SEATRAC_DRIVER_SE
RIAL_HANDLE
_H_
#endif //_DEF_SEATRAC_DRIVER_SE
ATRAC_SERIAL
_H_
src/SeatracDriver.cpp
View file @
9dbb1617
...
...
@@ -17,7 +17,7 @@ void SeatracDriver::crc16_update(uint16_t& checksum, uint8_t v)
SeatracDriver
::
SeatracDriver
(
const
IoServicePtr
&
ioService
,
const
std
::
string
&
port
)
:
Se
rialHandler
(
ioService
,
port
)
Se
atracSerial
(
ioService
,
port
)
{}
void
SeatracDriver
::
on_read
(
ReadBuffer
&
buffer
,
size_t
byteCount
)
...
...
src/Se
rialHandler
.cpp
→
src/Se
atracSerial
.cpp
View file @
9dbb1617
#include <seatrac_driver/Se
rialHandler
.h>
#include <seatrac_driver/Se
atracSerial
.h>
namespace
narval
{
namespace
seatrac
{
Se
rialHandler
::
SerialHandler
(
const
IoServicePtr
&
ioService
,
Se
atracSerial
::
SeatracSerial
(
const
IoServicePtr
&
ioService
,
const
std
::
string
&
port
)
:
ioService_
(
ioService
),
serial_
(
*
ioService
,
port
)
...
...
@@ -10,7 +10,7 @@ SerialHandler::SerialHandler(const IoServicePtr& ioService,
this
->
initiate_read
();
}
void
Se
rialHandler
::
reset_serial
()
void
Se
atracSerial
::
reset_serial
()
{
SerialPort
::
baud_rate
baudRate
(
115200
);
SerialPort
::
character_size
cSize
(
8
);
...
...
@@ -27,7 +27,7 @@ void SerialHandler::reset_serial()
this
->
flush
();
}
boost
::
system
::
error_code
Se
rialHandler
::
flush
(
FlushType
flushType
)
boost
::
system
::
error_code
Se
atracSerial
::
flush
(
FlushType
flushType
)
{
if
(
::
tcflush
(
serial_
.
lowest_layer
().
native_handle
(),
flushType
)
==
0
)
{
return
boost
::
system
::
error_code
();
...
...
@@ -38,18 +38,18 @@ boost::system::error_code SerialHandler::flush(FlushType flushType)
}
}
void
Se
rialHandler
::
initiate_read
()
void
Se
atracSerial
::
initiate_read
()
{
this
->
reset_serial
();
boost
::
asio
::
async_read_until
(
serial_
,
readBuffer_
,
Delimiter
,
boost
::
bind
(
&
Se
rialHandler
::
on_first_read
,
this
,
_1
,
_2
));
boost
::
bind
(
&
Se
atracSerial
::
on_first_read
,
this
,
_1
,
_2
));
}
/**
* Grab and discard a first (probably incomplete) chunk of data.
*/
void
Se
rialHandler
::
on_first_read
(
const
boost
::
system
::
error_code
&
err
,
size_t
byteCount
)
void
Se
atracSerial
::
on_first_read
(
const
boost
::
system
::
error_code
&
err
,
size_t
byteCount
)
{
if
(
err
)
{
std
::
ostringstream
oss
;
...
...
@@ -60,10 +60,10 @@ void SerialHandler::on_first_read(const boost::system::error_code& err, size_t b
// entering reading loop
boost
::
asio
::
async_read_until
(
serial_
,
readBuffer_
,
Delimiter
,
boost
::
bind
(
&
Se
rialHandler
::
read_callback
,
this
,
_1
,
_2
));
boost
::
bind
(
&
Se
atracSerial
::
read_callback
,
this
,
_1
,
_2
));
}
void
Se
rialHandler
::
read_callback
(
const
boost
::
system
::
error_code
&
err
,
size_t
byteCount
)
void
Se
atracSerial
::
read_callback
(
const
boost
::
system
::
error_code
&
err
,
size_t
byteCount
)
{
if
(
err
)
{
std
::
ostringstream
oss
;
...
...
@@ -76,10 +76,10 @@ void SerialHandler::read_callback(const boost::system::error_code& err, size_t b
// looping
boost
::
asio
::
async_read_until
(
serial_
,
readBuffer_
,
Delimiter
,
boost
::
bind
(
&
Se
rialHandler
::
read_callback
,
this
,
_1
,
_2
));
boost
::
bind
(
&
Se
atracSerial
::
read_callback
,
this
,
_1
,
_2
));
}
void
Se
rialHandler
::
on_read
(
ReadBuffer
&
buffer
,
size_t
byteCount
)
void
Se
atracSerial
::
on_read
(
ReadBuffer
&
buffer
,
size_t
byteCount
)
{
std
::
cout
<<
"Read : "
<<
byteCount
<<
" bytes"
<<
std
::
endl
;
...
...
tests/CMakeLists.txt
View file @
9dbb1617
...
...
@@ -3,8 +3,8 @@ list(APPEND test_names
hello_test.cpp
dump_test.cpp
serial_test.cpp
driver_test.cpp
checksum_test.cpp
# driver_test.cpp
)
list
(
APPEND test_deps
...
...
tests/src/driver_test.cpp
View file @
9dbb1617
...
...
@@ -6,7 +6,7 @@ using namespace narval::seatrac;
int
main
()
{
auto
service
=
std
::
make_shared
<
Se
rialHandler
::
IoService
>
();
auto
service
=
std
::
make_shared
<
Se
atracSerial
::
IoService
>
();
SeatracDriver
serial
(
service
);
service
->
run
();
...
...
tests/src/serial_test.cpp
View file @
9dbb1617
#include <iostream>
using
namespace
std
;
#include <seatrac_driver/Se
rialHandler
.h>
#include <seatrac_driver/Se
atracSerial
.h>
using
namespace
narval
::
seatrac
;
int
main
()
{
auto
service
=
std
::
make_shared
<
Se
rialHandler
::
IoService
>
();
Se
rialHandler
serial
(
service
);
auto
service
=
std
::
make_shared
<
Se
atracSerial
::
IoService
>
();
Se
atracSerial
serial
(
service
);
service
->
run
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment