]> git.tdb.fi Git - r2c2.git/commitdiff
Fix and improve logic in MfxSearchTask
authorMikko Rasa <tdb@tdb.fi>
Fri, 8 Nov 2013 19:39:26 +0000 (21:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 8 Nov 2013 19:39:26 +0000 (21:39 +0200)
source/libr2c2/arducontrol.cpp
source/libr2c2/arducontrol.h

index 201d9a2ebdd73e7871527c2f09c87b3a7f29cba2..8c17234051752e2527295016e197d2b8d8e5237c 100644 (file)
@@ -760,12 +760,12 @@ ArduControl::MfxSearchTask::MfxSearchTask(ArduControl &c):
        next_address(1),
        size(0),
        bits(0),
-       pending(false)
+       misses(0)
 { }
 
 bool ArduControl::MfxSearchTask::get_work(PendingCommand &cmd)
 {
-       if(size==32)
+       if(size>32)
        {
                if(control.debug>=1)
                        IO::print("Assigning MFX address %d to decoder %08X\n", next_address, bits);
@@ -795,7 +795,6 @@ bool ArduControl::MfxSearchTask::get_work(PendingCommand &cmd)
        cmd.length = 6;
 
        next = t+200*Time::msec;
-       pending = true;
 
        if(control.debug>=1)
                IO::print("Search %08X/%d\n", bits, size);
@@ -806,31 +805,24 @@ bool ArduControl::MfxSearchTask::get_work(PendingCommand &cmd)
 void ArduControl::MfxSearchTask::process_reply(const char *reply, unsigned length)
 {
        unsigned char type = reply[0];
-       if(type==MFX_FEEDBACK && length==2 && pending)
+       if(type==MFX_SEARCH_FEEDBACK && length==2)
        {
-               pending = false;
-               bool finished = true;
                if(reply[1])
                {
-                       if(size<32)
-                               ++size;
-                       finished = false;
+                       misses = 0;
+                       ++size;
                }
-               else if(size>0)
+               else if(size>0 && misses<6)
                {
-                       unsigned mask = 1<<(32-size);
-                       if(!(bits&mask))
-                       {
-                               bits |= mask;
-                               finished = false;
-                       }
+                       ++misses;
+                       bits ^= 1<<(32-size);
                }
-
-               if(finished)
+               else
                {
                        next = Time::now()+2*Time::sec;
                        bits = 0;
                        size = 0;
+                       misses = 0;
                }
        }
 }
index e354ecf0fed0c6f88824167ee8b7138399475863..46af9238af3fe845e5e19af05ea285b27987361d 100644 (file)
@@ -46,7 +46,8 @@ private:
                INPUT_VOLTAGE = 0xC1,
                POWER_STATE = 0xC2,
                S88_DATA = 0xD0,
-               MFX_FEEDBACK = 0xD1
+               MFX_SEARCH_FEEDBACK = 0xD1,
+               MFX_PING_FEEDBACK = 0xD2
        };
 
        struct Tag
@@ -253,7 +254,7 @@ private:
                Msp::Time::TimeStamp next;
                unsigned size;
                unsigned bits;
-               bool pending;
+               unsigned misses;
 
        public:
                MfxSearchTask(ArduControl &);