return protocol_info[map_protocol(proto_name)].max_speed;
}
+const Driver::DetectedLocomotive *ArduControl::enumerate_detected_locos(unsigned i) const
+{
+ if(i>=mfx_info.size())
+ return 0;
+
+ return &mfx_info[i];
+}
+
unsigned ArduControl::add_loco(unsigned addr, const string &proto_name, const VehicleType &)
{
if(!addr)
if(power.commit(tag.serial))
signal_power.emit(power.current);
}
+ else if(tag.command==NEW_LOCO)
+ {
+ MfxInfo info;
+ if(mfx_search.pop_info(info))
+ {
+ MfxInfoArray::iterator i;
+ for(i=mfx_info.begin(); (i!=mfx_info.end() && i->id!=info.id); ++i) ;
+ if(i==mfx_info.end())
+ {
+ mfx_info.push_back(info);
+ i = --mfx_info.end();
+ }
+ else
+ *i = info;
+ signal_locomotive_detected.emit(*i);
+ }
+ }
}
else if(tag.type==Tag::LOCOMOTIVE)
{
if(control.debug>=1)
IO::print("Assigning MFX address %d to decoder %08X\n", next_address, bits);
+ MfxInfo info;
+ info.protocol = "MFX";
+ info.address = next_address;
+ info.name = format("%08X", bits);
+ info.id = bits;
+ push_info(info);
+
cmd.command[0] = MFX_ASSIGN_ADDRESS;
cmd.command[1] = next_address>>8;
cmd.command[2] = next_address;
cmd.command[3+i] = bits>>(24-i*8);
cmd.length = 7;
+ cmd.tag.type = Tag::GENERAL;
+ cmd.tag.command = NEW_LOCO;
+ cmd.tag.id = bits;
+
size = 0;
bits = 0;
++next_address;
}
}
+void ArduControl::MfxSearchTask::push_info(const MfxInfo &info)
+{
+ MutexLock lock(mutex);
+ queue.push_back(info);
+}
+
+bool ArduControl::MfxSearchTask::pop_info(MfxInfo &info)
+{
+ MutexLock lock(mutex);
+ if(queue.empty())
+ return false;
+ info = queue.back();
+ queue.pop_back();
+ return true;
+}
+
ArduControl::ControlThread::ControlThread(ArduControl &c):
control(c),
enum GeneralCommand
{
- POWER
+ POWER,
+ NEW_LOCO
};
enum Protocol
unsigned create_speed_func_command(unsigned, char *) const;
};
+ struct MfxInfo: public DetectedLocomotive
+ {
+ unsigned id;
+ };
+
struct Accessory
{
enum Kind
unsigned size;
unsigned bits;
unsigned misses;
+ std::list<MfxInfo> queue;
+ Msp::Mutex mutex;
public:
MfxSearchTask(ArduControl &);
virtual bool get_work(PendingCommand &);
virtual void process_reply(const char *, unsigned);
+
+ private:
+ void push_info(const MfxInfo &);
+ public:
+ bool pop_info(MfxInfo &);
};
class ControlThread: public Msp::Thread
};
typedef std::map<unsigned, Locomotive> LocomotiveMap;
+ typedef std::vector<MfxInfo> MfxInfoArray;
typedef std::map<unsigned, Accessory> AccessoryMap;
typedef std::list<Accessory *> AccessoryPtrList;
typedef std::map<unsigned, Sensor> SensorMap;
ControlledVariable<bool> power;
LocomotiveMap locomotives;
+ MfxInfoArray mfx_info;
AccessoryMap accessories;
AccessoryPtrList accessory_queue;
Accessory *active_accessory;
public:
virtual unsigned get_protocol_speed_steps(const std::string &) const;
- virtual const DetectedLocomotive *enumerate_detected_locos(unsigned) const { return 0; }
+ virtual const DetectedLocomotive *enumerate_detected_locos(unsigned) const;
virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &);
virtual void remove_loco(unsigned);
virtual void set_loco_speed(unsigned, unsigned);