]> git.tdb.fi Git - r2c2.git/commitdiff
Get the initial state of s88 modules
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 May 2011 20:54:48 +0000 (20:54 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 May 2011 20:54:48 +0000 (20:54 +0000)
Get all functions of locomotives

source/libr2c2/centralstation.cpp
source/libr2c2/centralstation.h

index dd0cbcf58ef13709cd25989324090cd19a0cf5db..2e605ba3500d92b7ce91cfd594d997789ee93d17 100644 (file)
@@ -107,6 +107,10 @@ void CentralStation::add_loco(unsigned addr, const string &proto_name, const Veh
                loco.protocol = proto;
                loco.address = addr;
 
+               const VehicleType::FunctionMap &type_funcs = type.get_functions();
+               for(VehicleType::FunctionMap::const_iterator i=type_funcs.begin(); i!=type_funcs.end(); ++i)
+                       loco.func_mask |= 1<<i->first;
+
                if(locos_synced && proto!=MFX)
                        command("create(10)");
        }
@@ -343,7 +347,12 @@ void CentralStation::process_reply(const Message &msg)
                                        if(j!=locos.end())
                                        {
                                                command(format("request(%d, view, control, force)", i->first));
-                                               command(format("get(%d, dir, func[0])", i->first));
+                                               string cmd = format("get(%d, dir", i->first);
+                                               for(unsigned l=0; j->second.func_mask>>l; ++l)
+                                                       if((j->second.func_mask>>l)&1)
+                                                               cmd += format(", func[%d]", l);
+                                               cmd += ')';
+                                               command(cmd);
 
                                                locos.insert(LocoMap::value_type(i->first, j->second));
                                                locos.erase(j);
@@ -410,6 +419,7 @@ void CentralStation::process_reply(const Message &msg)
                {
                        s88.push_back(i->first);
                        command(format("request(%d, view)", i->first));
+                       command(format("get(%d, state)", i->first));
                }
 
                sensors_synced = true;
@@ -706,10 +716,12 @@ CentralStation::Message CentralStation::parse_message(string::iterator &iter, co
                        if(open_bracket!=string::npos)
                        {
                                string::size_type close_bracket = attr.rfind(']');
-                               attribs[attr.substr(0, open_bracket)] = attr.substr(open_bracket+1, close_bracket-open_bracket-1);
+                               string attr_name = attr.substr(0, open_bracket);
+                               string attr_value = attr.substr(open_bracket+1, close_bracket-open_bracket-1);
+                               attribs.insert(Message::AttribMap::value_type(attr_name, attr_value));
                        }
                        else
-                               attribs[attr];
+                               attribs.insert(Message::AttribMap::value_type(attr, string()));
                }
        }
 
@@ -741,6 +753,7 @@ CentralStation::Locomotive::Locomotive():
        address(0),
        speed(0),
        reverse(false),
+       func_mask(0),
        funcs(0),
        control(false)
 { }
index fea882be1011230fa9d6f8c86fc77a7dfbc6288d..90f44715a70da64298d2e0e5af2296867788fcbb 100644 (file)
@@ -30,7 +30,7 @@ private:
 
        struct Message
        {
-               typedef std::map<std::string, std::string> AttribMap;
+               typedef std::multimap<std::string, std::string> AttribMap;
                typedef std::map<unsigned, AttribMap> ObjectMap;
        
                Tag header;
@@ -68,6 +68,7 @@ private:
                unsigned address;
                unsigned speed;
                bool reverse;
+               unsigned func_mask;
                unsigned funcs;
                bool control;