1 #include <msp/core/maputils.h>
2 #include <msp/datafile/writer.h>
3 #include <msp/fs/redirectedpath.h>
4 #include <msp/fs/stat.h>
5 #include <msp/io/print.h>
6 #include <msp/time/utils.h>
7 #include "arducontrol.h"
15 ArduControl::ProtocolInfo ArduControl::protocol_info[2] =
18 { 0x3FFF, 126, 15 } // MFX
21 ArduControl::ArduControl(const Options &opts):
22 serial(opts.get<string>(string(), "ttyUSB0")),
23 debug(opts.get<unsigned>("debug")),
24 state_file("arducontrol.state"),
32 if(FS::exists(state_file))
33 DataFile::load(*this, state_file.str());
35 unsigned max_address = 0;
36 for(MfxInfoArray::const_iterator i=mfx_info.begin(); i!=mfx_info.end(); ++i)
37 max_address = max(max_address, i->address);
38 mfx_search.set_next_address(max_address+1);
41 cmd.command[0] = READ_POWER_STATE;
43 command_queue.push(cmd);
45 cmd.command[0] = MFX_SET_STATION_ID;
51 command_queue.push(cmd);
54 ArduControl::~ArduControl()
59 void ArduControl::set_power(bool p)
63 PendingCommand cmd(POWER);
64 cmd.tag.serial = power.serial;
65 cmd.command[0] = (p ? POWER_ON : POWER_OFF);
67 command_queue.push(cmd);
71 void ArduControl::halt(bool h)
79 for(LocomotiveMap::const_iterator i=locomotives.begin(); i!=locomotives.end(); ++i)
80 set_loco_speed(i->first, 0);
83 signal_halt.emit(halted);
86 const char *ArduControl::enumerate_protocols(unsigned i) const
96 ArduControl::Protocol ArduControl::map_protocol(const string &proto_name)
100 else if(proto_name=="MFX")
103 throw invalid_argument("ArduControl::map_protocol");
106 unsigned ArduControl::get_protocol_speed_steps(const string &proto_name) const
108 return protocol_info[map_protocol(proto_name)].max_speed;
111 const Driver::DetectedLocomotive *ArduControl::enumerate_detected_locos(unsigned i) const
113 if(i>=mfx_info.size())
119 unsigned ArduControl::add_loco(unsigned addr, const string &proto_name, const VehicleType &)
122 throw invalid_argument("ArduControl::add_loco");
124 Protocol proto = map_protocol(proto_name);
125 if(addr>protocol_info[proto].max_address)
126 throw invalid_argument("ArduControl::add_loco");
128 Locomotive loco(proto, addr);
129 insert_unique(locomotives, loco.id, loco);
134 ArduControl::MfxInfoArray::iterator ArduControl::add_mfx_info(const MfxInfo &info)
136 MfxInfoArray::iterator i;
137 for(i=mfx_info.begin(); (i!=mfx_info.end() && i->id!=info.id); ++i) ;
138 if(i==mfx_info.end())
140 mfx_info.push_back(info);
141 i = --mfx_info.end();
148 void ArduControl::remove_loco(unsigned id)
150 Locomotive &loco = get_item(locomotives, id);
151 refresh.remove_loco(loco);
152 locomotives.erase(id);
155 void ArduControl::set_loco_speed(unsigned id, unsigned speed)
157 Locomotive &loco = get_item(locomotives, id);
158 if(speed>protocol_info[loco.proto].max_speed)
159 throw invalid_argument("ArduControl::set_loco_speed");
164 if(loco.speed.set(speed))
166 PendingCommand cmd(loco, Locomotive::SPEED);
167 command_queue.push(cmd);
169 refresh.add_loco(loco);
173 void ArduControl::set_loco_reverse(unsigned id, bool rev)
175 Locomotive &loco = get_item(locomotives, id);
176 if(loco.reverse.set(rev))
178 PendingCommand cmd(loco, Locomotive::REVERSE);
179 command_queue.push(cmd);
181 refresh.add_loco(loco);
185 void ArduControl::set_loco_function(unsigned id, unsigned func, bool state)
187 Locomotive &loco = get_item(locomotives, id);
188 if(func>protocol_info[loco.proto].max_func)
189 throw invalid_argument("ArduControl::set_loco_function");
191 unsigned mask = 1<<func;
192 if(loco.funcs.set((loco.funcs&~mask)|(mask*state)))
194 if(func>0 || loco.proto!=MM)
196 PendingCommand cmd(loco, Locomotive::FUNCTIONS, func);
197 command_queue.push(cmd);
200 refresh.add_loco(loco);
204 unsigned ArduControl::add_turnout(unsigned addr, const TrackType &type)
206 if(!addr || !type.is_turnout())
207 throw invalid_argument("ArduControl::add_turnout");
209 return add_accessory(Accessory::TURNOUT, addr, type.get_state_bits());
212 void ArduControl::remove_turnout(unsigned addr)
214 remove_accessory(Accessory::TURNOUT, addr);
217 void ArduControl::set_turnout(unsigned addr, unsigned state)
219 set_accessory(Accessory::TURNOUT, addr, state);
222 unsigned ArduControl::get_turnout(unsigned addr) const
224 return get_accessory(Accessory::TURNOUT, addr);
227 unsigned ArduControl::add_signal(unsigned addr, const SignalType &)
229 return add_accessory(Accessory::SIGNAL, addr, 1);
232 void ArduControl::remove_signal(unsigned addr)
234 remove_accessory(Accessory::SIGNAL, addr);
237 void ArduControl::set_signal(unsigned addr, unsigned state)
239 set_accessory(Accessory::SIGNAL, addr, state);
242 unsigned ArduControl::get_signal(unsigned addr) const
244 return get_accessory(Accessory::SIGNAL, addr);
247 unsigned ArduControl::add_accessory(Accessory::Kind kind, unsigned addr, unsigned bits)
249 AccessoryMap::iterator i = accessories.lower_bound(addr);
250 AccessoryMap::iterator j = accessories.upper_bound(addr+bits-1);
252 throw key_error(addr);
253 if(i!=accessories.begin())
256 if(i->first+i->second.bits>addr)
257 throw key_error(addr);
260 insert_unique(accessories, addr, Accessory(kind, addr, bits));
264 void ArduControl::remove_accessory(Accessory::Kind kind, unsigned addr)
266 Accessory &acc = get_item(accessories, addr);
268 throw key_error(addr);
269 accessories.erase(addr);
272 void ArduControl::set_accessory(Accessory::Kind kind, unsigned addr, unsigned state)
274 Accessory &acc = get_item(accessories, addr);
276 throw key_error(addr);
278 if(state!=acc.target)
281 accessory_queue.push_back(&acc);
285 unsigned ArduControl::get_accessory(Accessory::Kind kind, unsigned addr) const
287 const Accessory &acc = get_item(accessories, addr);
289 throw key_error(addr);
293 unsigned ArduControl::add_sensor(unsigned addr)
296 throw invalid_argument("ArduControl::add_sensor");
298 insert_unique(sensors, addr, Sensor(addr));
299 s88.grow_n_octets((addr+7)/8);
304 void ArduControl::remove_sensor(unsigned addr)
306 remove_existing(sensors, addr);
307 // TODO update s88.n_octets
310 bool ArduControl::get_sensor(unsigned addr) const
312 return get_item(sensors, addr).state;
315 void ArduControl::tick()
318 while(completed_commands.pop(tag))
320 if(tag.type==Tag::GENERAL)
322 if(tag.command==POWER)
324 if(power.commit(tag.serial))
325 signal_power.emit(power.current);
327 else if(tag.command==NEW_LOCO)
330 if(mfx_search.pop_info(info))
332 MfxInfoArray::iterator i = add_mfx_info(info);
334 signal_locomotive_detected.emit(*i);
338 else if(tag.type==Tag::LOCOMOTIVE)
340 LocomotiveMap::iterator i = locomotives.find(tag.id);
341 if(i==locomotives.end())
344 Locomotive &loco = i->second;
345 if(tag.command==Locomotive::SPEED)
347 if(loco.speed.commit(tag.serial))
348 signal_loco_speed.emit(loco.id, loco.speed, loco.reverse);
350 else if(tag.command==Locomotive::REVERSE)
352 if(loco.reverse.commit(tag.serial))
353 signal_loco_speed.emit(loco.id, loco.speed, loco.reverse);
355 else if(tag.command==Locomotive::FUNCTIONS)
357 unsigned old = loco.funcs;
358 if(loco.funcs.commit(tag.serial))
360 unsigned changed = old^loco.funcs;
361 for(unsigned j=0; changed>>j; ++j)
363 signal_loco_function.emit(loco.id, j, (loco.funcs>>j)&1);
367 else if(tag.type==Tag::ACCESSORY)
369 AccessoryMap::iterator i = accessories.find(tag.id);
370 if(i==accessories.end())
373 Accessory &acc = i->second;
374 if(tag.command==Accessory::ACTIVATE)
375 off_timeout = Time::now()+acc.active_time;
376 else if(tag.command==Accessory::DEACTIVATE)
378 if(acc.state.commit(tag.serial))
380 if(acc.state==acc.target)
382 if(acc.kind==Accessory::TURNOUT)
383 signal_turnout.emit(acc.address, acc.state);
384 else if(acc.kind==Accessory::SIGNAL)
385 signal_signal.emit(acc.address, acc.state);
387 if(&acc==active_accessory)
388 active_accessory = 0;
392 else if(tag.type==Tag::SENSOR)
394 SensorMap::iterator i = sensors.find(tag.id);
398 Sensor &sensor = i->second;
399 if(tag.command==Sensor::STATE)
401 if(sensor.state.commit(tag.serial))
402 signal_sensor.emit(sensor.address, sensor.state);
407 while(power && !active_accessory && !accessory_queue.empty())
409 Accessory &acc = *accessory_queue.front();
411 if(acc.state!=acc.target)
413 active_accessory = &acc;
415 unsigned changes = acc.state^acc.target;
416 unsigned lowest_bit = changes&~(changes-1);
418 for(i=0; (lowest_bit>>i)>1; ++i) ;
420 acc.state.set(acc.state^lowest_bit);
421 PendingCommand cmd(acc, Accessory::ACTIVATE, i);
422 command_queue.push(cmd);
424 monitor.reset_peak();
427 accessory_queue.pop_front();
430 if(active_accessory && off_timeout)
432 Time::TimeStamp t = Time::now();
435 Accessory &acc = *active_accessory;
437 if(acc.kind==Accessory::TURNOUT && monitor.get_peak()<0.5f)
439 unsigned bit = 1<<active_index;
440 if(acc.uncertain&bit)
441 acc.uncertain &= ~bit;
444 signal_turnout_failed.emit(acc.address);
445 acc.state.rollback();
450 off_timeout = Time::TimeStamp();
451 PendingCommand cmd(acc, Accessory::DEACTIVATE, active_index);
452 command_queue.push(cmd);
457 void ArduControl::flush()
461 void ArduControl::save_state() const
463 FS::RedirectedPath tmp_file(state_file);
464 IO::BufferedFile out(tmp_file.str(), IO::M_WRITE);
465 DataFile::Writer writer(out);
467 writer.write((DataFile::Statement("mfx_announce_serial"), mfx_announce.get_serial()));
468 for(MfxInfoArray::const_iterator i=mfx_info.begin(); i!=mfx_info.end(); ++i)
470 DataFile::Statement st("mfx_locomotive");
472 st.sub.push_back((DataFile::Statement("address"), i->address));
473 st.sub.push_back((DataFile::Statement("name"), i->name));
479 ArduControl::Tag::Tag():
487 ArduControl::Locomotive::Locomotive(Protocol p, unsigned a):
497 unsigned ArduControl::Locomotive::create_speed_dir_command(char *buffer) const
501 buffer[0] = MOTOROLA_SPEED_DIRECTION;
503 buffer[2] = funcs.pending&1;
504 buffer[3] = speed.pending+reverse.pending*0x80;
509 buffer[0] = MFX_SPEED;
510 buffer[1] = address>>8;
512 buffer[3] = speed.pending+reverse.pending*0x80;
519 unsigned ArduControl::Locomotive::create_speed_func_command(unsigned f, char *buffer) const
524 throw invalid_argument("Locomotive::create_speed_func_command");
526 buffer[0] = MOTOROLA_SPEED_FUNCTION;
528 buffer[2] = (f<<4)|(((funcs.pending>>f)&1)<<1)|(funcs.pending&1);
529 buffer[3] = speed.pending;
534 bool f16 = (funcs.pending>0xFF);
535 buffer[0] = (f16 ? MFX_SPEED_FUNCS16 : MFX_SPEED_FUNCS8);
536 buffer[1] = address>>8;
538 buffer[3] = speed.pending+reverse.pending*0x80;
541 buffer[4] = funcs.pending>>8;
542 buffer[5] = funcs.pending;
547 buffer[4] = funcs.pending;
556 ArduControl::Accessory::Accessory(Kind k, unsigned a, unsigned b):
561 uncertain((1<<bits)-1),
563 active_time(500*Time::msec)
566 unsigned ArduControl::Accessory::create_state_command(unsigned b, bool c, char *buffer) const
569 throw invalid_argument("Accessory::create_state_command");
571 unsigned a = (address+b+3)*2;
572 if(!((state.pending>>b)&1))
574 buffer[0] = MOTOROLA_SOLENOID;
576 buffer[2] = ((a&7)<<4)|c;
581 ArduControl::Sensor::Sensor(unsigned a):
587 ArduControl::PendingCommand::PendingCommand():
592 ArduControl::PendingCommand::PendingCommand(GeneralCommand cmd):
596 tag.type = Tag::GENERAL;
600 ArduControl::PendingCommand::PendingCommand(Locomotive &loco, Locomotive::Command cmd, unsigned index):
603 tag.type = Tag::LOCOMOTIVE;
606 if(cmd==Locomotive::SPEED)
608 tag.serial = loco.speed.serial;
609 length = loco.create_speed_dir_command(command);
611 else if(cmd==Locomotive::REVERSE)
613 tag.serial = loco.reverse.serial;
614 length = loco.create_speed_dir_command(command);
616 else if(cmd==Locomotive::FUNCTIONS)
618 tag.serial = loco.funcs.serial;
619 length = loco.create_speed_func_command(index, command);
622 throw invalid_argument("PendingCommand");
625 ArduControl::PendingCommand::PendingCommand(Accessory &acc, Accessory::Command cmd, unsigned index):
628 tag.type = Tag::ACCESSORY;
630 tag.id = acc.address;
631 if(cmd==Accessory::ACTIVATE || cmd==Accessory::DEACTIVATE)
633 tag.serial = acc.state.serial;
634 length = acc.create_state_command(index, (cmd==Accessory::ACTIVATE), command);
637 throw invalid_argument("PendingCommand");
642 void ArduControl::Queue<T>::push(const T &item)
644 MutexLock lock(mutex);
645 items.push_back(item);
649 bool ArduControl::Queue<T>::pop(T &item)
651 MutexLock lock(mutex);
655 item = items.front();
661 ArduControl::RefreshTask::RefreshTask():
668 bool ArduControl::RefreshTask::get_work(PendingCommand &cmd)
670 if(loco && loco->proto==MM && phase==0)
672 cmd.length = loco->create_speed_func_command(round%4+1, cmd.command);
673 cmd.repeat_count = 2;
678 loco = get_next_loco();
685 cmd.length = loco->create_speed_dir_command(cmd.command);
686 cmd.repeat_count = 2;
688 else if(loco->proto==MFX)
689 cmd.length = loco->create_speed_func_command(0, cmd.command);
696 void ArduControl::RefreshTask::add_loco(Locomotive &l)
698 MutexLock lock(mutex);
702 LocomotivePtrList::iterator oldest = cycle.begin();
703 for(LocomotivePtrList::iterator i=cycle.begin(); ++i!=cycle.end(); )
704 if((*i)->last_change_age>(*oldest)->last_change_age)
710 if(next==cycle.end())
711 next = cycle.begin();
714 void ArduControl::RefreshTask::remove_loco(Locomotive &l)
716 MutexLock lock(mutex);
717 for(LocomotivePtrList::iterator i=cycle.begin(); i!=cycle.end(); ++i)
732 ArduControl::Locomotive *ArduControl::RefreshTask::get_next_loco()
734 MutexLock lock(mutex);
738 Locomotive *l = *next;
743 void ArduControl::RefreshTask::advance()
746 if(next==cycle.end())
754 ArduControl::S88Task::S88Task(ArduControl &c):
761 bool ArduControl::S88Task::get_work(PendingCommand &cmd)
768 if(octets_remaining || !n_octets)
771 octets_remaining = n_octets;
772 cmd.command[0] = S88_READ;
773 cmd.command[1] = octets_remaining;
781 void ArduControl::S88Task::process_reply(const char *reply, unsigned length)
783 unsigned char type = reply[0];
784 if(type==S88_DATA && length>2)
786 unsigned offset = static_cast<unsigned char>(reply[1]);
787 unsigned count = length-2;
789 SensorMap::iterator begin = control.sensors.lower_bound(offset*8+1);
790 SensorMap::iterator end = control.sensors.upper_bound((offset+count)*8);
791 for(SensorMap::iterator i=begin; i!=end; ++i)
793 unsigned bit_index = i->first-1-offset*8;
794 bool state = (reply[2+bit_index/8]>>(7-bit_index%8))&1;
795 i->second.state.set(state);
798 tag.type = Tag::SENSOR;
799 tag.command = Sensor::STATE;
800 tag.serial = i->second.state.serial;
802 control.completed_commands.push(tag);
805 if(count>octets_remaining)
806 octets_remaining = 0;
808 octets_remaining -= count;
812 void ArduControl::S88Task::set_n_octets(unsigned n)
817 void ArduControl::S88Task::grow_n_octets(unsigned n)
824 ArduControl::MfxAnnounceTask::MfxAnnounceTask():
828 bool ArduControl::MfxAnnounceTask::get_work(PendingCommand &cmd)
830 Time::TimeStamp t = Time::now();
834 cmd.command[0] = MFX_ANNOUNCE;
835 cmd.command[1] = serial>>8;
836 cmd.command[2] = serial;
838 next = t+400*Time::msec;
843 void ArduControl::MfxAnnounceTask::set_serial(unsigned s)
849 ArduControl::MfxSearchTask::MfxSearchTask(ArduControl &c):
857 bool ArduControl::MfxSearchTask::get_work(PendingCommand &cmd)
862 IO::print("Assigning MFX address %d to decoder %08X\n", next_address, bits);
865 info.protocol = "MFX";
866 info.address = next_address;
867 info.name = format("%08X", bits);
871 cmd.command[0] = MFX_ASSIGN_ADDRESS;
872 cmd.command[1] = next_address>>8;
873 cmd.command[2] = next_address;
874 for(unsigned i=0; i<4; ++i)
875 cmd.command[3+i] = bits>>(24-i*8);
878 cmd.tag.type = Tag::GENERAL;
879 cmd.tag.command = NEW_LOCO;
889 Time::TimeStamp t = Time::now();
893 cmd.command[0] = MFX_SEARCH;
894 for(unsigned i=0; i<4; ++i)
895 cmd.command[1+i] = bits>>(24-i*8);
896 cmd.command[5] = size;
899 next = t+200*Time::msec;
902 IO::print("Search %08X/%d\n", bits, size);
907 void ArduControl::MfxSearchTask::process_reply(const char *reply, unsigned length)
909 unsigned char type = reply[0];
910 if(type==MFX_SEARCH_FEEDBACK && length==2)
917 else if(size>0 && misses<6)
920 bits ^= 1<<(32-size);
924 next = Time::now()+2*Time::sec;
932 void ArduControl::MfxSearchTask::set_next_address(unsigned a)
937 bool ArduControl::MfxSearchTask::pop_info(MfxInfo &info)
939 return queue.pop(info);
943 ArduControl::MonitorTask::MonitorTask():
951 bool ArduControl::MonitorTask::get_work(PendingCommand &cmd)
953 Time::TimeStamp t = Time::now();
958 cmd.command[0] = READ_INPUT_VOLTAGE;
960 cmd.command[0] = READ_TRACK_CURRENT;
963 next_poll = t+200*Time::msec;
964 next_type = (next_type+1)%5;
969 void ArduControl::MonitorTask::process_reply(const char *reply, unsigned length)
971 unsigned char type = reply[0];
972 if(type==INPUT_VOLTAGE && length==3)
973 voltage = ((static_cast<unsigned char>(reply[1])<<8) | static_cast<unsigned char>(reply[2]))/1000.0f;
974 else if(type==TRACK_CURRENT && length==5)
976 current = ((static_cast<unsigned char>(reply[1])<<8) | static_cast<unsigned char>(reply[2]))/1000.0f;
977 float peak = ((static_cast<unsigned char>(reply[3])<<8) | static_cast<unsigned char>(reply[4]))/1000.0f;
978 peak_level = max(peak_level, peak);
979 base_level = min(base_level, current);
983 void ArduControl::MonitorTask::reset_peak()
985 base_level = current;
986 peak_level = current;
990 ArduControl::ControlThread::ControlThread(ArduControl &c):
994 tasks.push_back(&control.monitor);
995 tasks.push_back(&control.mfx_announce);
996 tasks.push_back(&control.mfx_search);
997 tasks.push_back(&control.s88);
998 tasks.push_back(&control.refresh);
1003 void ArduControl::ControlThread::exit()
1009 void ArduControl::ControlThread::main()
1018 bool success = true;
1019 for(unsigned i=0; (success && i<cmd.repeat_count); ++i)
1020 success = (do_command(cmd)==COMMAND_OK);
1021 if(success && cmd.tag)
1022 control.completed_commands.push(cmd.tag);
1025 Time::sleep(10*Time::msec);
1029 void ArduControl::ControlThread::init_baud_rate()
1031 static unsigned rates[] = { 57600, 9600, 19200, 38400, 0 };
1033 control.serial.set_data_bits(8);
1034 control.serial.set_parity(IO::Serial::NONE);
1035 control.serial.set_stop_bits(1);
1036 for(unsigned i=0; rates[i]; ++i)
1038 control.serial.set_baud_rate(rates[i]);
1039 control.serial.put('\xFF');
1040 if(IO::poll(control.serial, IO::P_INPUT, 500*Time::msec))
1042 int c = control.serial.get();
1053 if(control.debug>=1)
1054 IO::print("ArduControl detection failed\n");
1059 if(control.debug>=1)
1060 IO::print("ArduControl detected at %d bits/s\n", rate);
1065 cmd.command[0] = SET_BAUD_RATE;
1066 cmd.command[1] = rates[0]>>8;
1067 cmd.command[2] = rates[0];
1069 if(do_command(cmd)==COMMAND_OK)
1071 control.serial.set_baud_rate(rates[0]);
1072 Time::sleep(Time::sec);
1073 if(do_command(cmd)==COMMAND_OK)
1075 if(control.debug>=1)
1076 IO::print("Rate changed to %d bits/s\n", rates[0]);
1082 bool ArduControl::ControlThread::get_work(PendingCommand &cmd)
1084 if(control.command_queue.pop(cmd))
1087 for(vector<Task *>::iterator i=tasks.begin(); i!=tasks.end(); ++i)
1088 if((*i)->get_work(cmd))
1091 // As fallback, send an idle packet for the MM protocol
1092 cmd.command[0] = MOTOROLA_SPEED;
1093 cmd.command[1] = 80;
1101 unsigned ArduControl::ControlThread::do_command(const PendingCommand &cmd)
1103 if(control.debug>=2)
1106 for(unsigned i=0; i<cmd.length; ++i)
1107 cmd_hex += format(" %02X", static_cast<unsigned char>(cmd.command[i]));
1108 IO::print("< %02X%s\n", cmd.length^0xFF, cmd_hex);
1111 control.serial.put(cmd.length^0xFF);
1112 control.serial.write(cmd.command, cmd.length);
1114 unsigned result = 0;
1119 got_data = IO::poll(control.serial, IO::P_INPUT, Time::zero);
1121 got_data = IO::poll(control.serial, IO::P_INPUT);
1126 unsigned rlength = control.serial.get()^0xFF;
1129 IO::print("Invalid length %02X\n", rlength);
1136 pos += control.serial.read(reply+pos, rlength-pos);
1138 if(control.debug>=2)
1141 for(unsigned i=0; i<rlength; ++i)
1142 reply_hex += format(" %02X", static_cast<unsigned char>(reply[i]));
1143 IO::print("> %02X%s\n", rlength^0xFF, reply_hex);
1146 unsigned r = process_reply(reply, rlength);
1154 unsigned ArduControl::ControlThread::process_reply(const char *reply, unsigned rlength)
1156 unsigned char type = reply[0];
1157 if((type&0xE0)==0x80)
1159 if(type!=COMMAND_OK)
1160 IO::print("Error %02X\n", type);
1163 else if(type==POWER_STATE && rlength==2)
1165 control.power.set(reply[1]);
1168 tag.type = Tag::GENERAL;
1169 tag.command = POWER;
1170 tag.serial = control.power.serial;
1171 control.completed_commands.push(tag);
1175 for(vector<Task *>::iterator i=tasks.begin(); i!=tasks.end(); ++i)
1176 (*i)->process_reply(reply, rlength);
1183 ArduControl::Loader::Loader(ArduControl &c):
1184 DataFile::ObjectLoader<ArduControl>(c)
1186 add("mfx_announce_serial", &Loader::mfx_announce_serial);
1187 add("mfx_locomotive", &Loader::mfx_locomotive);
1190 void ArduControl::Loader::mfx_announce_serial(unsigned s)
1192 obj.mfx_announce.set_serial(s);
1195 void ArduControl::Loader::mfx_locomotive(unsigned id)
1199 info.protocol = "MFX";
1201 obj.add_mfx_info(info);
1205 ArduControl::MfxInfo::Loader::Loader(MfxInfo &i):
1206 DataFile::ObjectLoader<MfxInfo>(i)
1208 add("address", static_cast<unsigned MfxInfo::*>(&MfxInfo::address));
1209 add("name", static_cast<string MfxInfo::*>(&MfxInfo::name));