def commit_callback(self, mac, cmd_data): log.info('Got Commit response from %s' % print_mac(mac)) log.debug('Data: ' + ' '.join(['%02X' % ord(b) for b in cmd_data])) oc_resp = parse_obj(OtapCommitResp, cmd_data) log.debug(str(oc_resp)) if not self.state == 'Commit': return if mac in self.commit_motes: self.commit_motes.remove(mac) if oc_resp.otapResult == 0: fcs = self.files[self.current_file].fcs msg = '%s committed %s [FCS=0x%04x]' % (print_mac(mac), self.current_file, fcs) print msg log.info(msg) else: msg = 'Commit error (%s) on %s' % (otap_error_string( oc_resp.otapResult), print_mac(mac)) print msg log.error(msg) self.complete_motes.remove(mac) self.failure_motes.append(mac) # detect when all motes have responded to the commit if not len(self.commit_motes): self.commit_complete()
def parse(self, data, index=0): self.header = parse_obj(OtapStatusRespHeader, data, index) index = OtapStatusRespHeader.serialized_length while index < len(data): (lost_block, ) = struct.unpack('!H', data[index:index + 2]) self.missing_blocks.append(lost_block) index = index + 2
def handshake_callback(self, mac, cmd_data): log.info('Got Handshake response from %s' % print_mac(mac)) log.debug('Data: ' + ' '.join(['%02X' % ord(b) for b in cmd_data])) oh_resp = parse_obj(OtapHandshakeResp, cmd_data) log.debug(str(oh_resp)) if not self.state == 'Handshake': return if not mac in self.handshake_motes: log.info('Duplicate handshake response for %s: %d', print_mac(mac), oh_resp.otapResult) return # add a mote that accepts the handshake to the list of motes to send to if oh_resp.otapResult == 0: # validate mac is in the handshake list if mac in self.handshake_motes and not mac in self.incomplete_motes: self.incomplete_motes.append(mac) else: otap_err = otap_error_string(oh_resp.otapResult) msg = "Handshake rejected (%s) by %s" % (otap_err, print_mac(mac)) print msg log.warning(msg) # TODO: handle the delay field # remove this mote from the list of expected handshakers self.handshake_motes.remove(mac) # once the list of expected handshakers is empty, we're ready to move on if not len(self.handshake_motes): self.handshake_complete()
def commit_callback(self, mac, cmd_data): log.info('Got Commit response from %s' % print_mac(mac)) log.debug('Data: ' + ' '.join(['%02X' % ord(b) for b in cmd_data])) oc_resp = parse_obj(OtapCommitResp, cmd_data) log.debug(str(oc_resp)) if not self.state == 'Commit': return if mac in self.commit_motes: self.commit_motes.remove(mac) if oc_resp.otapResult == 0: fcs = self.files[self.current_file].fcs msg = '%s committed %s [FCS=0x%04x]' % (print_mac(mac), self.current_file, fcs) print msg log.info(msg) else: msg = 'Commit error (%s) on %s' % (otap_error_string(oc_resp.otapResult), print_mac(mac)) print msg log.error(msg) self.complete_motes.remove(mac) self.failure_motes.append(mac) # detect when all motes have responded to the commit if not len(self.commit_motes): self.commit_complete()
def parse(self, data, index = 0): self.header = parse_obj(OtapStatusRespHeader, data, index) index = OtapStatusRespHeader.serialized_length while index < len(data): (lost_block,) = struct.unpack('!H', data[index:index+2]) self.missing_blocks.append(lost_block) index = index + 2
def parse_otap_file(filename): header_data = '' with open(filename, 'rb') as f: header_data = f.read(FileHeader.serialized_length) return parse_obj(FileHeader, header_data)