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
3925d5dd
Commit
3925d5dd
authored
Jul 08, 2021
by
Pierre NARVOR
Browse files
[driver] Successful checksum handling (still work to do on parser)
parent
65891edd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/SeatracDriver.cpp
View file @
3925d5dd
...
...
@@ -22,9 +22,11 @@ SeatracDriver::SeatracDriver(const IoServicePtr& ioService,
void
SeatracDriver
::
on_read
(
ReadBuffer
&
buffer
,
size_t
byteCount
)
{
std
::
cout
<<
"Received "
<<
byteCount
<<
" bytes."
<<
std
::
endl
;
std
::
istream
is
(
&
buffer
);
char
start
=
is
.
get
();
std
::
cout
<<
start
<<
std
::
endl
;
if
(
start
!=
'$'
)
{
std
::
ostringstream
oss
;
oss
<<
"Invalid data line (no starting character) :
\n
"
...
...
@@ -32,17 +34,29 @@ void SeatracDriver::on_read(ReadBuffer& buffer, size_t byteCount)
for
(
int
i
=
0
;
i
<
byteCount
-
1
;
i
++
)
{
oss
<<
(
char
)
is
.
get
();
}
throw
std
::
runtime_error
(
oss
.
str
());
//throw std::runtime_error(oss.str());
std
::
cerr
<<
oss
.
str
()
<<
std
::
endl
;
}
// conversion from pair of ascii character to a 8bit value
auto
fromAscii
=
[](
char
c
)
{
return
(
uint8_t
)(
c
>=
'A'
)
?
(
c
-
'A'
+
10
)
:
(
c
-
'0'
);
};
data_
.
resize
((
byteCount
-
7
)
/
2
);
uint16_t
checksum
=
0
;
data_
.
resize
(
byteCount
-
7
);
for
(
auto
&
v
:
data_
)
{
v
=
is
.
get
();
crc16_update
(
checksum
,
v
);
v
=
fromAscii
(
is
.
get
())
<<
4
;
v
+=
fromAscii
(
is
.
get
());
crc16_update
(
checksum
,
v
);
}
//cout << "Checksum
uint16_t
c
=
0
;
c
=
fromAscii
(
is
.
get
())
<<
4
;
c
+=
fromAscii
(
is
.
get
());
c
+=
fromAscii
(
is
.
get
())
<<
12
;
c
+=
fromAscii
(
is
.
get
())
<<
8
;
std
::
cout
<<
std
::
hex
<<
checksum
<<
std
::
dec
<<
std
::
endl
;
std
::
cout
<<
std
::
hex
<<
c
<<
std
::
dec
<<
std
::
endl
;
std
::
cout
<<
(
int
)
is
.
get
()
<<
" "
<<
(
int
)
is
.
get
()
<<
std
::
endl
;
}
};
//namespace seatrac
...
...
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