]> git.tdb.fi Git - r2c2.git/commitdiff
Simulate commands if no serial device is set to make turnouts work
authorMikko Rasa <tdb@tdb.fi>
Fri, 18 Dec 2009 23:07:25 +0000 (23:07 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 18 Dec 2009 23:07:25 +0000 (23:07 +0000)
source/libmarklin/control.cpp
source/libmarklin/reply.cpp
source/libmarklin/reply.h

index 4f63cc20be086e90e4c56c7e2d768665444a2044..30e99e6e4f5266cfa1878735bf3a4a21ded55920 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2007-2008  Mikkosoft Productions, Mikko Rasa
+Copyright © 2007-2009  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -216,7 +216,11 @@ void Control::tick()
                if(serial_fd>=0)
                        queue.front().send(serial_fd);
                else
+               {
+                       Reply reply = Reply::simulate(queue.front().get_command());
+                       queue.front().signal_done.emit(reply);
                        queue.erase(queue.begin());
+               }
        }
 }
 
@@ -240,7 +244,7 @@ void Control::event_query_done(const Reply &reply)
                command(CMD_EVENT_TURNOUT).signal_done.connect(sigc::mem_fun(this, &Control::turnout_event_done));
        if(data[0]&0x04)
                command(CMD_EVENT_SENSOR).signal_done.connect(sigc::mem_fun(this, &Control::sensor_event_done));
-       if(data[1]&0x40)
+       if((data[0]&0x80) && (data[1]&0x40))
                command(CMD_STATUS).signal_done.connect(sigc::mem_fun(this, &Control::status_done));
 }
 
index 5a02df212897c4efd36a2261d4747d94da41617b..1d7d536ba1dbb506c94289e23499b138bba44f86 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-200 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -108,6 +108,45 @@ Reply Reply::read(int fd, Cmd cmd)
        return result;
 }
 
+Reply Reply::simulate(Cmd cmd)
+{
+       Reply result;
+
+       if(cmd==CMD_STATUS)
+       {
+               result.data[0] = 0x80;
+               result.len = 1;
+       }
+       if(cmd==CMD_EVENT)
+               result.len = 1;
+       else if(cmd==CMD_TURNOUT)
+               ;
+       else if(cmd==CMD_TURNOUT_STATUS)
+       {
+               result.data[0] = 0x04;
+               result.len = 1;
+       }
+       else if(cmd==CMD_LOK)
+               ;
+       else if(cmd==CMD_LOK_STATUS)
+       {
+               result.data[1] = 0x20;
+               result.len = 3;
+       }
+       else if(cmd==CMD_SENSOR_PARAM_SET)
+               ;
+       else if(cmd==CMD_SENSOR_REPORT)
+               ;
+       else if(cmd==CMD_POWER_ON)
+               ;
+       else if(cmd==CMD_POWER_OFF)
+               ;
+       else
+               result.err = ERR_SYS_ERROR;
+
+       return result;
+}
+
 ostream &operator<<(ostream &out, const Reply &reply)
 {
        out<<reply.err;
index d075b9be977824a78ae023fc5db35eb399e16a0f..1666490b2ef9aa9aa27d732861c5080471c45314 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-200 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -25,6 +25,7 @@ public:
        const unsigned char *get_data() const { return data; }
 
        static Reply read(int, Cmd);
+       static Reply simulate(Cmd);
 
        friend std::ostream &operator<<(std::ostream &, const Reply &);
 };