def read_register_and_xml(self, settingsfile, xmlfile): if xmlfile is not None: try: with open(xmlfile) as infile: xml = infile.read() except IOError: print("can't read {}".format(xmlfile)) sys.exit(1) else: xml = self.dsptk.generic_request(COMMAND_XML, COMMAND_XML_RESPONSE).decode() if xml is None or len(xml) == 0: print("server did not provide XML file") sys.exit(1) xmlprofile = XmlProfile() try: xmlprofile.read_from_text(xml) except: print("can't parse XML profile") sys.exit(1) try: registerfile = SettingsFile(settingsfile, xmlprofile.samplerate()) except: print("can't parse settings file") sys.exit(1) return (registerfile, xmlprofile)
def store_attributes(self, attributes): ''' Store specific attributes from RAM into DSP EEPROM ''' xml = self.dsptk.generic_request(COMMAND_XML, COMMAND_XML_RESPONSE) if len(xml) == 0: print("can't retrieve XML file from server") sys.exit(1) xmlprofile = XmlProfile() xmlprofile.read_from_text(xml.decode("utf-8", errors="replace")) replace = {} for attribute in attributes: (addr, length) = xmlprofile.get_addr_length(attribute) if addr is None: continue while length > 0: data = self.dsptk.sigmatcp.read_data( addr, self.dsptk.dsp.WORD_LENGTH) replace[addr] = data addr += 1 length -= 1 xmlprofile.replace_eeprom_cells(replace) xmlprofile.replace_ram_cells(replace) self.write_back_xml(xmlprofile)
def store_attributes(self, attributes=None): ''' Store specific attributes from RAM into DSP EEPROM ''' xml = self.dsptk.generic_request(COMMAND_XML, COMMAND_XML_RESPONSE) if len(xml) == 0: print("can't retrieve XML file from server") sys.exit(1) xmlprofile = XmlProfile() xmlprofile.read_from_text(xml.decode("utf-8", errors="replace")) replace = {} if attributes is None: print("checking attribute tags from XML profile") attributes = xmlprofile.get_storable_registers() if len(attributes) == 0: print("no storable attributes found in XML, using default set") attributes = REGISTER_ATTRIBUTES for attribute in attributes: (addr, length) = xmlprofile.get_addr_length(attribute) if addr is None: continue while length > 0: data = self.dsptk.sigmatcp.read_data(addr, self.dsptk.dsp.WORD_LENGTH) replace[addr] = data addr += 1 length -= 1 print("storing {}".format(attribute)) xmlprofile.replace_eeprom_cells(replace) xmlprofile.replace_ram_cells(replace) self.write_back_xml(xmlprofile)