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);
cmd.length = 6;
next = t+200*Time::msec;
- pending = true;
if(control.debug>=1)
IO::print("Search %08X/%d\n", bits, size);
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;
}
}
}
INPUT_VOLTAGE = 0xC1,
POWER_STATE = 0xC2,
S88_DATA = 0xD0,
- MFX_FEEDBACK = 0xD1
+ MFX_SEARCH_FEEDBACK = 0xD1,
+ MFX_PING_FEEDBACK = 0xD2
};
struct Tag
Msp::Time::TimeStamp next;
unsigned size;
unsigned bits;
- bool pending;
+ unsigned misses;
public:
MfxSearchTask(ArduControl &);