X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fcommand.cpp;h=dd1cdbc5d97b1137a30f162da4db7e6d438b832b;hb=f42183985c65e1e12f19e9246dee90b8e7e44a34;hp=9530cbabe78f22f40b3332bfbfe45053905445b4;hpb=3e9c210ddc036cd015228504cc0803c909e27f84;p=r2c2.git diff --git a/source/libmarklin/command.cpp b/source/libmarklin/command.cpp index 9530cba..dd1cdbc 100644 --- a/source/libmarklin/command.cpp +++ b/source/libmarklin/command.cpp @@ -5,20 +5,41 @@ Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ +#include +#include #include "command.h" using namespace std; +using namespace Msp; namespace Marklin { -Command::Command(const string &c): +Command::Command(Cmd c, const unsigned char *d, unsigned l): cmd(c), + len(1), sent(false) -{ } +{ + data[0]=cmd; + if(d) + { + memcpy(data+1, d, min(l, 127U)); + len+=min(l, 127U); + } +} + +void Command::send(int fd) +{ + write(fd, data, len); + sent=true; +} -void Command::set_sent(bool s) +ostream &operator<<(ostream &out, const Command &cmd) { - sent=s; + out<(cmd.data[i])); + + return out; } } // namespace Marklin