]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/control.cpp
Use Msp::IO::print instead of std::cout
[r2c2.git] / source / libmarklin / control.cpp
index 30e99e6e4f5266cfa1878735bf3a4a21ded55920..fa1117ccd0fa319dd6c15bf5c735092e8fe27ada 100644 (file)
@@ -8,8 +8,8 @@ Distributed under the GPL
 #include <fcntl.h>
 #include <termios.h>
 #include <sys/poll.h>
-#include <iostream>
 #include <msp/core/except.h>
+#include <msp/io/print.h>
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
 #include "command.h"
@@ -72,7 +72,7 @@ void Control::open(const string &dev)
                pollfd pfd = { serial_fd, POLLIN, 0 };
                if(poll(&pfd, 1, 500)>0)
                {
-                       cout<<"IB detected at "<<baud[i]<<" bits/s\n";
+                       IO::print("IB detected at %d bits/s\n", baud[i]);
                        char buf[2];
                        p50 = (read(serial_fd, buf, 2)==2);
                        ok = true;
@@ -199,7 +199,7 @@ void Control::tick()
                {
                        Reply reply = Reply::read(serial_fd, queue.front().get_command());
                        if(debug)
-                               cout<<"R: "<<reply<<'\n';
+                               IO::print("R: %s\n", reply);
 
                        queue.front().signal_done.emit(reply);
                        queue.erase(queue.begin());
@@ -211,7 +211,7 @@ void Control::tick()
        if(!queue.empty())
        {
                if(debug)
-                       cout<<"W: "<<queue.front()<<'\n';
+                       IO::print("W: %s\n", queue.front());
 
                if(serial_fd>=0)
                        queue.front().send(serial_fd);
@@ -256,7 +256,7 @@ void Control::turnout_event_done(const Reply &reply)
        {
                unsigned addr = (data[i*2+1])+((data[i*2+2]&7)<<8);
                bool status = !(data[i*2+2]&0x80);
-               cout<<"Turnout "<<addr<<", status "<<status<<'\n';
+               IO::print("Turnout %d, status %d\n", addr, status);
                signal_turnout_event.emit(addr, status);
        }
 }
@@ -268,10 +268,7 @@ void Control::sensor_event_done(const Reply &reply)
        {
                unsigned module = data[i];
 
-               cout<<"S88 module "<<module<<", status ";
-               for(unsigned j=0; j<16; ++j)
-                       cout<<((data[i+1+j/8]>>(7-j%8))&1);
-               cout<<'\n';
+               IO::print("S88 module %d, status %08b%08b\n", module, data[1], data[2]);
 
                for(unsigned j=0; j<16; ++j)
                        signal_sensor_event.emit(module*16+j-15, (data[i+1+j/8]>>(7-j%8))&1);