/* $Id$
-This file is part of the MSP Märklin suite
+This file is part of R²C²
Copyright © 2009-2010 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <msp/net/inet.h>
-#include "libmarklin/route.h"
-#include "libmarklin/train.h"
-#include "libmarklin/vehicletype.h"
+#include "libr2c2/route.h"
+#include "libr2c2/train.h"
+#include "libr2c2/vehicletype.h"
#include "server.h"
using namespace std;
using namespace Msp;
-namespace Marklin {
+namespace R2C2 {
Server::Server(Layout &l):
layout(l),
TrainInfoPacket pkt;
pkt.address = train.get_address();
- pkt.loco_type = train.get_locomotive_type().get_article_number();
+ pkt.loco_type = train.get_locomotive_type().get_article_number().str();
pkt.name = train.get_name();
send(pkt);
}
void Server::Connection::handshake_done()
{
- const map<string, Route *> &routes = server.layout.get_routes();
- for(map<string, Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
+ const set<Route *> &routes = server.layout.get_routes();
+ for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
{
RouteInfoPacket pkt;
- pkt.name = i->first;
+ pkt.name = (*i)->get_name();
comm.send(pkt);
}
{
TrainInfoPacket pkt;
pkt.address = train.get_address();
- pkt.loco_type = train.get_locomotive_type().get_article_number();
+ pkt.loco_type = train.get_locomotive_type().get_article_number().str();
pkt.name = train.get_name();
comm.send(pkt);
}
- // XXX Need control enumeration to send control packets
+ for(unsigned j=0;; ++j)
+ {
+ const char *name = train.get_controller().enumerate_controls(j);
+ if(!name)
+ break;
+
+ TrainControlPacket pkt;
+ pkt.address = train.get_address();
+ pkt.control = name;
+ pkt.value = train.get_control(name);
+ comm.send(pkt);
+ }
{
TrainFunctionPacket pkt;
pkt.address = train.get_address();
comm.send(pkt);
}
-} // namespace Marklin
+} // namespace R2C2