3 This file is part of the MSP Märklin suite
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
15 NetTrain::NetTrain(Client &c, const TrainInfoPacket &pkt):
17 loco_type(client.get_catalogue().get_locomotive(pkt.loco_type)),
25 void NetTrain::set_speed(unsigned s)
31 pkt.address = address;
33 pkt.reverse = reverse;
37 void NetTrain::set_reverse(bool r)
43 pkt.address = address;
49 void NetTrain::set_function(unsigned i, bool set)
51 TrainFunctionPacket pkt;
52 pkt.address = address;
53 pkt.functions = functions;
55 pkt.functions |= 1<<i;
57 pkt.functions &= ~(1<<i);
61 void NetTrain::set_route(const string &r)
67 pkt.address = address;
72 void NetTrain::process_packet(const TrainSpeedPacket &pkt)
77 signal_speed_changed.emit(speed);
79 if(pkt.reverse!=reverse)
81 reverse = pkt.reverse;
82 signal_reverse_changed.emit(reverse);
86 void NetTrain::process_packet(const TrainFunctionPacket &pkt)
88 unsigned old_funcs = functions;
89 functions = pkt.functions;
90 for(unsigned i=0; i<9; ++i)
91 if(((functions^old_funcs)>>i)&1)
92 signal_function_changed.emit(i, (functions>>i)&1);
95 void NetTrain::process_packet(const TrainStatusPacket &pkt)
98 signal_status_changed.emit(status);
101 void NetTrain::process_packet(const TrainRoutePacket &pkt)
104 signal_route_changed.emit(route);
107 } // namespace Marklin