X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fcommand.cpp;h=dd1cdbc5d97b1137a30f162da4db7e6d438b832b;hb=3df8cb5c78fbb0b919bcb79677c6c788b8028482;hp=f953cbdb77770ba5fb462ad8567251bdd2b9615d;hpb=1d735b80482317fd930eb47ca255ab9f1f120a7d;p=r2c2.git diff --git a/source/libmarklin/command.cpp b/source/libmarklin/command.cpp index f953cbd..dd1cdbc 100644 --- a/source/libmarklin/command.cpp +++ b/source/libmarklin/command.cpp @@ -1,17 +1,45 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +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::set_sent(bool s) +void Command::send(int fd) { - sent=s; + write(fd, data, len); + sent=true; +} + +ostream &operator<<(ostream &out, const Command &cmd) +{ + out<(cmd.data[i])); + + return out; } } // namespace Marklin