Skip to content

Commit

Permalink
fix 2nd address scanning bug, add some comments
Browse files Browse the repository at this point in the history
code merge from arska/libmbus without debug
  • Loading branch information
Aarno Aukia authored and Stefan Wahren committed Nov 7, 2013
1 parent 0d9f83b commit f42c56f
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions mbus/mbus-protocol-aux.c
Expand Up @@ -2414,51 +2414,58 @@ mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask)

if (mask[pos] == 'f' || mask[pos] == 'F')
{
// mask[pos] is a wildcard -> enumerate all 0..9 at this position
i_start = 0;
i_end = 9;
}
else
{
if (pos < 15)
{
// mask[pos] is not a wildcard -> don't iterate, recursively check pos+1
mbus_scan_2nd_address_range(handle, pos+1, mask);
}
else
{
// .. except if we're at the last pos (==15) and this isn't a wildcard we still need to send the probe
i_start = (int)(mask[pos] - '0');
i_end = (int)(mask[pos] - '0');
}
}

for (i = 0; i <= 9; i++)
// skip the scanning if we're returning from the (pos < 15) case above
if (mask[pos] == 'f' || mask[pos] == 'F' || pos == 15)
{
mask[pos] = '0'+i;
for (i = i_start; i <= i_end; i++)
{
mask[pos] = '0'+i;

if (handle->scan_progress)
handle->scan_progress(handle,mask);
if (handle->scan_progress)
handle->scan_progress(handle,mask);

probe_ret = mbus_probe_secondary_address(handle, mask, matching_mask);
probe_ret = mbus_probe_secondary_address(handle, mask, matching_mask);

if (probe_ret == MBUS_PROBE_SINGLE)
{
if (!handle->found_event)
if (probe_ret == MBUS_PROBE_SINGLE)
{
printf("Found a device on secondary address %s [using address mask %s]\n", matching_mask, mask);
if (!handle->found_event)
{
printf("Found a device on secondary address %s [using address mask %s]\n", matching_mask, mask);
}
}
else if (probe_ret == MBUS_PROBE_COLLISION)
{
// collision, more than one device matching, restrict the search mask further
mbus_scan_2nd_address_range(handle, pos+1, mask);
}
else if (probe_ret == MBUS_PROBE_NOTHING)
{
// nothing... move on to next address mask
}
else // MBUS_PROBE_ERROR
{
MBUS_ERROR("%s: Failed to probe secondary address [%s].\n", __PRETTY_FUNCTION__, mask);
return -1;
}
}
else if (probe_ret == MBUS_PROBE_COLLISION)
{
// collision, more than one device matching, restrict the search mask further
mbus_scan_2nd_address_range(handle, pos+1, mask);
}
else if (probe_ret == MBUS_PROBE_NOTHING)
{
// nothing... move on to next address mask
}
else // MBUS_PROBE_ERROR
{
MBUS_ERROR("%s: Failed to probe secondary address [%s].\n", __PRETTY_FUNCTION__, mask);
return -1;
}
}

Expand Down

0 comments on commit f42c56f

Please sign in to comment.