namespace R2C2 {
+ArduControl::ProtocolInfo ArduControl::protocol_info[2] =
+{
+ { 79, 14, 4 } // MM
+};
+
ArduControl::ArduControl(const string &dev):
serial(dev),
debug(true),
{
if(proto_name=="MM")
return MM;
+ else if(proto_name=="MFX")
+ return MFX;
else
throw invalid_argument("ArduControl::map_protocol");
}
unsigned ArduControl::get_protocol_speed_steps(const string &proto_name) const
{
- Protocol proto = map_protocol(proto_name);
- if(proto==MM)
- return 14;
- else
- return 0;
+ return protocol_info[map_protocol(proto_name)].max_speed;
}
unsigned ArduControl::add_loco(unsigned addr, const string &proto_name, const VehicleType &)
throw invalid_argument("ArduControl::add_loco");
Protocol proto = map_protocol(proto_name);
-
- if(proto==MM)
- {
- if(addr>=80)
- throw invalid_argument("ArduControl::add_loco");
- }
+ if(addr>protocol_info[proto].max_address)
+ throw invalid_argument("ArduControl::add_loco");
Locomotive loco(proto, addr);
insert_unique(locomotives, loco.id, loco);
void ArduControl::set_loco_speed(unsigned id, unsigned speed)
{
Locomotive &loco = get_item(locomotives, id);
+ if(speed>protocol_info[loco.proto].max_speed)
+ throw invalid_argument("ArduControl::set_loco_speed");
+
if(loco.speed.set(speed))
{
QueuedCommand cmd(loco, Locomotive::SPEED);
void ArduControl::set_loco_function(unsigned id, unsigned func, bool state)
{
Locomotive &loco = get_item(locomotives, id);
+ if(func>protocol_info[loco.proto].max_func)
+ throw invalid_argument("ArduControl::set_loco_function");
+
unsigned mask = 1<<func;
if(loco.funcs.set((loco.funcs&~mask)|(mask*state)))
{