Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2015-11-04 16:00:37 +0300
committerAlessandro Ranellucci <aar@cpan.org>2015-11-04 16:00:37 +0300
commitc34430c6c478a47120b9f451c4530102334e3fe3 (patch)
treee2ca2a999a7efbd19a889e3db11b5743637f29fb /xs/src/libslic3r/GCodeSender.cpp
parent1d10e463a3745d5513132e5c45aa6890ea97066f (diff)
Fix G-code checksum
Diffstat (limited to 'xs/src/libslic3r/GCodeSender.cpp')
-rw-r--r--xs/src/libslic3r/GCodeSender.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/xs/src/libslic3r/GCodeSender.cpp b/xs/src/libslic3r/GCodeSender.cpp
index 8dfd6673c..727b31e5b 100644
--- a/xs/src/libslic3r/GCodeSender.cpp
+++ b/xs/src/libslic3r/GCodeSender.cpp
@@ -299,6 +299,7 @@ GCodeSender::on_read(const boost::system::error_code& error,
{
boost::lock_guard<boost::mutex> l(this->queue_mutex);
this->priqueue.push(this->last_sent);
+ this->sent--; // resend it with the same line number
this->can_send = true;
}
this->send();
@@ -400,18 +401,22 @@ GCodeSender::send()
void
GCodeSender::do_send(const std::string &line)
{
+ // compute full line
+ this->sent++;
+ std::string full_line = "N" + boost::lexical_cast<std::string>(this->sent) + " " + line;
+
// calculate checksum
int cs = 0;
- for (std::string::const_iterator it = line.begin(); it != line.end(); ++it)
+ for (std::string::const_iterator it = full_line.begin(); it != full_line.end(); ++it)
cs = cs ^ *it;
- this->sent++;
- this->last_sent = line;
+ // write line to device
asio::streambuf b;
std::ostream os(&b);
- os << "N" << sent << " " << line
- << "*" << cs << "\n";
+ os << full_line << "*" << cs << "\n";
asio::write(this->serial, b);
+
+ this->last_sent = line;
this->can_send = false;
}