def manage_aldb_record(self, control_code, control_flags, group, address,
                           data1, data2, data3):
        """Update an IM All-Link record.

        Control Code values:
        - 0x00 Find First Starting at the top of the ALDB, search for the
        first ALL-Link Record matching the <ALL-Link Group> and <ID> in bytes
        5 – 8. The search ignores byte 4, <ALL-Link Record Flags>. You will
        receive an ACK at the end of the returned message if such an ALL-Link
        Record exists, or else a NAK if it doesn’t.  If the record exists, the
        IM will return it in an ALL-Link Record Response (0x51) message.

        - 0x01 Find Next Search for the next ALL-Link Record following the one
        found using <Control Code> 0x00 above.  This allows you to find both
        Controller and Responder records for a given <ALL-Link Group> and
        <ID>. Be sure to use the same <ALL-Link Group> and <ID> (bytes 5 – 8)
        as you used for <Control Code> 0x00. You will receive an ACK at the
        end of the returned message if another matching ALL-Link Record
        exists, or else a NAK if it doesn’t.  If the record exists, the IM
        will return it in an ALL-Link Record Response (0x51) message.

        - 0x20 Modify First Found or Add Modify an existing or else add a new
        ALL-Link Record for either a Controller or Responder. Starting at the
        top of the ALDB, search for the first ALL-Link Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  The search ignores byte 4,
        <ALL-Link Record Flags>. If such an ALL-Link Record exists, overwrite
        it with the data in bytes 4 – 11; otherwise, create a new ALL-Link
        Record using bytes 4 – 11. Note that the IM will copy
        <ALL-Link Record Flags> you supplied in byte 4 below directly into the
        <ALL-Link Record Flags> byte of the ALL-Link Record in an ALDB-L
        (linear) database.  Use caution, because you can damage an ALDB-L if
        you misuse this Command.  For instance, if you zero the
        <ALL-Link Record Flags> byte in the first ALL-Link Record, the IM’s
        ALDB-L database will then appear empty.

        - 0x40 Modify First Controller Found or Add Modify an existing or else
        add a new Controller (master) ALL-Link Record. Starting at the top of
        the ALDB, search for the first ALL-Link Controller Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  An ALL-Link Controller
        Record has bit 6 of its <ALL-Link Record Flags> byte set to 1. If such
        a Controller ALL-Link Record exists, overwrite it with the data in
        bytes 5 – 11; otherwise, create a new ALL-Link Record using bytes
        5 – 11.  In either case, the IM will set bit 6 of the
        <ALL-Link Record Flags> byte in the ALL-Link Record to 1 to indicate
        that the record is for a Controller.

        - 0x41 Modify First Responder Found or Add Modify an existing or else
        add a new Responder (slave) ALLLink Record. Starting at the top of the
        ALDB, search for the first ALL-Link Responder Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  An ALL-Link Responder
        Record has bit 6 of its <ALL-Link Record Flags> byte cleared to 0. If
        such a Responder ALL-Link Record exists, overwrite it with the data in
        bytes 5 – 11; otherwise, create a new ALL-Link Record using bytes
        5 – 11.  In either case, The IM will clear bit 6 of the
        <ALL-Link Record Flags> byte in the ALL-Link Record to 0 to indicate
        that the record is for a Responder.

        - 0x80 Delete First Found Delete an ALL-Link Record. Starting at the
        top of the ALDB, search for the first ALL-Link Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  The search ignores byte 4,
        <ALL-Link Record Flags>. You will receive an ACK at the end of the
        returned message if such an ALL-Link Record existed and was deleted,
        or else a NAK no such record exists.
        """
        found_first = False
        for memaddr in self.aldb:
            found = False
            rec = self.aldb[memaddr]
            found = Address(address) == rec.address
            found = found & int(group) == rec.group
            if control_code == 0x00:
                if found:
                    return (True, rec)
                if rec.control_flags.is_high_water_mark:
                    return (False, None)
            if control_code == 0x01:
                if found & found_first:
                    return (True, rec)
                if rec.control_flags.is_high_water_mark:
                    return (False, None)
                if found:
                    found_first = True
            elif control_code == 0x20:
                if found or rec.control_flags.is_high_water_mark:
                    new_rec = self._write_new_aldb_rec(
                        rec.mem_addr, control_flags, group, address,
                        data1, data2, data3)
                    return (found, new_rec)
            elif control_code == 0x40:
                found = found & rec.control_flags.is_controller
                if found or rec.control_flags.is_high_water_mark:
                    new_rec = self._write_new_aldb_rec(
                        rec.mem_addr, control_flags, group, address,
                        data1, data2, data3)
                    return (found, new_rec)
            elif control_code == 0x41:
                found = found & rec.control_flags.is_responder
                if found or rec.control_flags.is_high_water_mark:
                    new_rec = self._write_new_aldb_rec(
                        rec.mem_addr, control_flags, group, address,
                        data1, data2, data3)
                    return (found, new_rec)
            elif control_code == 0x80:
                if found:
                    cf = rec.control_flags
                    new_control_flags = ControlFlags(False, cf.is_controller,
                                                     cf.is_high_water_mark,
                                                     False, False)
                    new_rec = self._write_new_aldb_rec(
                        rec.mem_addr, new_control_flags, rec.group,
                        rec.address, rec.data1, rec.data2, rec.data3)
                    return (found, new_rec)
            return (False, rec)
def manage_aldb_record ( self , control_code , control_flags , group , address , data1 , data2 , data3 ) : found_first = False for memaddr in self . aldb : found = False rec = self . aldb [ memaddr ] found = Address ( address ) == rec . address found = found & int ( group ) == rec . group if control_code == 0x00 : if found : return ( True , rec ) if rec . control_flags . is_high_water_mark : return ( False , None ) if control_code == 0x01 : if found & found_first : return ( True , rec ) if rec . control_flags . is_high_water_mark : return ( False , None ) if found : found_first = True elif control_code == 0x20 : if found or rec . control_flags . is_high_water_mark : new_rec = self . _write_new_aldb_rec ( rec . mem_addr , control_flags , group , address , data1 , data2 , data3 ) return ( found , new_rec ) elif control_code == 0x40 : found = found & rec . control_flags . is_controller if found or rec . control_flags . is_high_water_mark : new_rec = self . _write_new_aldb_rec ( rec . mem_addr , control_flags , group , address , data1 , data2 , data3 ) return ( found , new_rec ) elif control_code == 0x41 : found = found & rec . control_flags . is_responder if found or rec . control_flags . is_high_water_mark : new_rec = self . _write_new_aldb_rec ( rec . mem_addr , control_flags , group , address , data1 , data2 , data3 ) return ( found , new_rec ) elif control_code == 0x80 : if found : cf = rec . control_flags new_control_flags = ControlFlags ( False , cf . is_controller , cf . is_high_water_mark , False , False ) new_rec = self . _write_new_aldb_rec ( rec . mem_addr , new_control_flags , rec . group , rec . address , rec . data1 , rec . data2 , rec . data3 ) return ( found , new_rec ) return ( False , rec )
Update an IM All-Link record.

        Control Code values:
        - 0x00 Find First Starting at the top of the ALDB, search for the
        first ALL-Link Record matching the <ALL-Link Group> and <ID> in bytes
        5 – 8. The search ignores byte 4, <ALL-Link Record Flags>. You will
        receive an ACK at the end of the returned message if such an ALL-Link
        Record exists, or else a NAK if it doesn’t.  If the record exists, the
        IM will return it in an ALL-Link Record Response (0x51) message.

        - 0x01 Find Next Search for the next ALL-Link Record following the one
        found using <Control Code> 0x00 above.  This allows you to find both
        Controller and Responder records for a given <ALL-Link Group> and
        <ID>. Be sure to use the same <ALL-Link Group> and <ID> (bytes 5 – 8)
        as you used for <Control Code> 0x00. You will receive an ACK at the
        end of the returned message if another matching ALL-Link Record
        exists, or else a NAK if it doesn’t.  If the record exists, the IM
        will return it in an ALL-Link Record Response (0x51) message.

        - 0x20 Modify First Found or Add Modify an existing or else add a new
        ALL-Link Record for either a Controller or Responder. Starting at the
        top of the ALDB, search for the first ALL-Link Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  The search ignores byte 4,
        <ALL-Link Record Flags>. If such an ALL-Link Record exists, overwrite
        it with the data in bytes 4 – 11; otherwise, create a new ALL-Link
        Record using bytes 4 – 11. Note that the IM will copy
        <ALL-Link Record Flags> you supplied in byte 4 below directly into the
        <ALL-Link Record Flags> byte of the ALL-Link Record in an ALDB-L
        (linear) database.  Use caution, because you can damage an ALDB-L if
        you misuse this Command.  For instance, if you zero the
        <ALL-Link Record Flags> byte in the first ALL-Link Record, the IM’s
        ALDB-L database will then appear empty.

        - 0x40 Modify First Controller Found or Add Modify an existing or else
        add a new Controller (master) ALL-Link Record. Starting at the top of
        the ALDB, search for the first ALL-Link Controller Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  An ALL-Link Controller
        Record has bit 6 of its <ALL-Link Record Flags> byte set to 1. If such
        a Controller ALL-Link Record exists, overwrite it with the data in
        bytes 5 – 11; otherwise, create a new ALL-Link Record using bytes
        5 – 11.  In either case, the IM will set bit 6 of the
        <ALL-Link Record Flags> byte in the ALL-Link Record to 1 to indicate
        that the record is for a Controller.

        - 0x41 Modify First Responder Found or Add Modify an existing or else
        add a new Responder (slave) ALLLink Record. Starting at the top of the
        ALDB, search for the first ALL-Link Responder Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  An ALL-Link Responder
        Record has bit 6 of its <ALL-Link Record Flags> byte cleared to 0. If
        such a Responder ALL-Link Record exists, overwrite it with the data in
        bytes 5 – 11; otherwise, create a new ALL-Link Record using bytes
        5 – 11.  In either case, The IM will clear bit 6 of the
        <ALL-Link Record Flags> byte in the ALL-Link Record to 0 to indicate
        that the record is for a Responder.

        - 0x80 Delete First Found Delete an ALL-Link Record. Starting at the
        top of the ALDB, search for the first ALL-Link Record matching the
        <ALL-Link Group> and <ID> in bytes 5 – 8.  The search ignores byte 4,
        <ALL-Link Record Flags>. You will receive an ACK at the end of the
        returned message if such an ALL-Link Record existed and was deleted,
        or else a NAK no such record exists.