Skip to content

Commit

Permalink
[MTM-31190][fix]mbbase.cc: Add comments after review
Browse files Browse the repository at this point in the history
  • Loading branch information
rina23q committed Mar 12, 2020
1 parent e4e11a7 commit c45d6d5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/modbus/mbbase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ void ModbusModel::addAddress(uint8_t type, uint16_t addr)
return;
}

// Make a pair (start addr, end addr) to queue
for(auto itr = pm->begin(); itr != pm->end(); ++itr) {
if (itr->first <= addr && addr <= itr->second){
// addr is within the pair's address range
return;
} else if (itr->second + 1 == itr->first + limit) {
// The pair's address range is already limit
continue;
} else if (itr->second + 2 == itr->first + limit) {
// The pair's address range will be limit after extension
if (addr + 1 == itr->first) {
itr->first = addr;
return;
Expand All @@ -130,6 +134,7 @@ void ModbusModel::addAddress(uint8_t type, uint16_t addr)
} else if (addr + 1 == itr->first) {
itr->first = addr;
for(auto i = pm->begin(); i != pm->end(); ++i) {
// Extend the pair's address range with another consecutive pair
if (addr == i->second + 1) {
itr->first = i->first;
pm->erase(i);
Expand Down

0 comments on commit c45d6d5

Please sign in to comment.