Exemple #1
0
    def modDataPortScript(self):
        '''
        modify LnK data port script template to update downloadable data file
        '''
        if not os.path.isfile(self.output_path + self.sys_xml_template_file):
            raise BellagioError(
                "Could not find LnK DP DL script file for sys config! {0}".
                format(self.output_path + self.sys_xml_template_file))
        '''
        ###convert binary to DP DL file
        '''
        self.bin2Dat()

        ###replace sys_config txt in DP download script template
        with open(self.output_path +
                  self.sys_xml_template_file) as infile, open(
                      self.output_path + self.sys_xml_file, 'w') as outfile:
            for line in infile:
                if re.search(self.sys_txt_replace, line):
                    #update DP DL txt file
                    line = line.replace(self.sys_txt_replace,
                                        self.output_path + self.sys_txt_file)
                elif re.search('_DATE_', line):
                    #update date
                    line = line.replace(
                        "_DATE_",
                        datetime.datetime.now().strftime("%m/%d/%Y"))
                outfile.write(line)

        infile.close()
        outfile.close()

        ###replace bosko_fw txt in DP download script template
        if not os.path.isfile(self.output_path + self.fw_xml_template_file):
            raise BellagioError(
                "Could not find LnK script xml file for bosko fw!")

        with open(self.output_path +
                  self.fw_xml_template_file) as infile, open(
                      self.output_path + self.fw_xml_file, 'w') as outfile:
            for line in infile:
                if re.search(self.fw_txt_replace, line):
                    #update DP DL txt file
                    line = line.replace(self.fw_txt_replace,
                                        self.output_path + self.fw_txt_file)
                elif re.search('_DATE_', line):
                    #update date
                    line = line.replace(
                        "_DATE_",
                        datetime.datetime.now().strftime("%m/%d/%Y"))
                outfile.write(line)

        infile.close()
        outfile.close()

        tblog.infoLog("LnkScriptMod: LnK script xml file revised!")
        return self.sys_xml_file, self.fw_xml_file
Exemple #2
0
    def genCtrlPortScript(self):
        if not os.path.isfile(self.output_path + self.sys_file):
            raise BellagioError("Could not find sys config bin!")
        self.bin2CtrlPort(self.output_path + self.sys_file,
                          self.output_path + self.cp_dl_sys_file)

        if not os.path.isfile(self.output_path + self.fw_file):
            raise BellagioError("Could not find Bosko FW bin!")
        self.bin2CtrlPort(self.output_path + self.fw_file,
                          self.output_path + self.cp_dl_fw_file)

        return self.cp_dl_sys_file, self.cp_dl_fw_file
    def bin2txt(self, bin_file, txt_file):
        '''
        convert binary to txt file and pad it to 4-byte aligned
            bin_file:   binary file
            txt_file:   swire txt file
        '''
        if not os.path.isfile(bin_file):
            raise BellagioError("bin2lnk could not find binary input!")

        with open(bin_file, "rb") as bin_input, open(txt_file,
                                                     'w') as txt_output:
            byte = bin_input.read(1)
            tblog.infoLog("bin2txt {0:02X}".format(ord(byte)))
            count = 0
            while byte != "":
                line = "{0:02X}".format(ord(byte))
                txt_output.write(line)
                byte = bin_input.read(1)
                count += 1

            tblog.infoLog("bin2txt size {0}".format(count))
            if count & 0x3:
                for i in range(4 - (count & 0x3)):
                    txt_output.write("00")

        bin_input.close()
        txt_output.close()
        tblog.infoLog("binary to txt done!")
Exemple #4
0
    def bin2Dat(self):
        '''
        convert config/fw binary file to LnK data port downloadable file
        '''
        bin2lnk = Bin2Lnk()

        if not os.path.isfile(self.output_path + self.sys_file):
            raise BellagioError("Could not find sys config bin!")
        bin2lnk.bin2Dp(self.output_path + self.sys_file,
                       self.output_path + self.sys_txt_file)

        if not os.path.isfile(self.output_path + self.fw_file):
            raise BellagioError("Could not find Bosko FW bin!")
        bin2lnk.bin2Dp(self.output_path + self.fw_file,
                       self.output_path + self.fw_txt_file)

        tblog.infoLog("LnkScriptMod: converted bin to data port data file!")
    def bin2Dp(self, bin_file, dp_file):
        '''
        convert binary to swire dp downloading file
            bin_file:   binary file
            dp_file:   swire dp file
        '''
        tblog.infoLog("bin2Dp: input-{0} output-{1}".format(bin_file, dp_file))

        if not os.path.isfile(bin_file):
            raise BellagioError("bin2lnk could not find binary input!")

        self.bin2txt(bin_file, self.tmp_txt)
        #convert binary to txt first

        if not os.path.isfile(self.tmp_txt):
            raise BellagioError("bin2lnk failed to generate tmp txt!")

        with open(self.tmp_txt, "r") as txt_input, open(dp_file,
                                                        'w') as dp_output:
            '''
            ###8-byte 00 header, no need after v103
            '''
            if self.version < 103:
                for i in range(2):
                    dp_output.write("00000000\n")

            dword = txt_input.read(
                self.dp_line_size)  #read 4-char per line for DP format
            tblog.infoLog("bin2Dp: {0}".format(dword))
            count = 0
            while dword != "":
                l = list(dword)
                '''
                ###use big-endian
                '''
                line = "{0}{1}{2}{3}\n".format(l[6] + l[7], l[4] + l[5],
                                               l[2] + l[3], l[0] + l[1])
                dp_output.write(line)
                dword = txt_input.read(self.dp_line_size)
                count += 1
            tblog.infoLog("bin2txt size {0}".format(count))

        txt_input.close()
        dp_output.close()
        #os.remove(self.tmp_txt)
        tblog.infoLog("binary to dp done!")
Exemple #6
0
 def __init__(self):
     if self.dev is None:
         try:
             from uiautomator import device as d
         except Exception as e:
             raise BellagioError(
                 "Uiautomator Python wrapper not found: {0}".format(e))
         self.dev = d
     '''
Exemple #7
0
    def calculate_logcat_interval(self, start_time, end_time):
        '''
        calculate logcat style(h:m:s.ms) time interval
        '''
        tblog.traceLog(self.calculate_logcat_interval, start_time, end_time)
        try:
            start_hr = int(start_time.split(":", 1)[0])
            start_min = int((start_time.split(":", 1)[1]).split(":")[0])
            start_sec = int((start_time.split(":", 2)[2]).split(".")[0])
            start_ms = int(start_time.split(".")[1])
            print(start_hr, start_min, start_sec, start_ms)

            end_hr = int(end_time.split(":", 1)[0])
            end_min = int((end_time.split(":", 1)[1]).split(":")[0])
            end_sec = int((end_time.split(":", 2)[2]).split(".")[0])
            end_ms = int(end_time.split(".")[1])
            print(end_hr, end_min, end_sec, end_ms)
        except LookupError as e:
            print("Failed to find time pattern: {0}".format(e))
            raise BellagioError("Failed to find time pattern: {0}".format(e))
            return -1

        if end_ms < start_ms:
            end_ms += 1000
            end_sec -= 1
        interval_ms = end_ms - start_ms
        if end_sec < start_sec:
            end_sec += 60
            end_min -= 1
        interval_sec = end_sec - start_sec
        if end_min < start_min:
            end_min += 60
            end_hr -= 1
        interval_min = end_min - start_min
        if end_hr < start_hr:
            print("Time error {}/{}!".format(start_time, end_time))
            raise BellagioError("Time error {}/{}!".format(
                start_time, end_time))
            return -1
        interval_hr = end_hr - start_hr
        return interval_hr, interval_min, interval_sec, interval_ms
Exemple #8
0
    def setupRouteScript(self, route_num, output_dir, rx_samplerate,
                         rx_wordlength, tx_samplerate, tx_wordlength,
                         frame_size):
        '''
        Setup route script from template
        '''
        template = output_dir + self.route_template
        if not os.path.isfile(template):
            tblog.infoLog(
                "Could not find route template file {0}!".format(template))
            raise BellagioError("Could not find route template file!")

        #get route definition: channel num/rx port/tx port
        self.channel_num = swire_route_def[route_num][
            swire_route_def_index['channel_num']]
        self.dp_rx = swire_route_def[route_num][
            swire_route_def_index['rx_port']]
        self.dp_tx = swire_route_def[route_num][
            swire_route_def_index['tx_port']]

        self.rx_samplerate = rx_samplerate
        self.rx_wordlength = rx_wordlength - 1  #number: length - 1
        self.tx_samplerate = tx_samplerate
        self.tx_wordlength = tx_wordlength - 1  #number: length - 1
        '''
        Form frame shape based on PCM stream sample rate
            if rx is PCM, use rx
            else if tx is PCM, use tx 
        '''
        if self.dp_rx == 3:
            self.input_pcm = 1
            self.swire_framerate = self.rx_samplerate
        elif self.dp_rx == 4:
            self.input_pcm = 0
            if self.dp_tx == 1:
                self.swire_framerate = self.tx_samplerate
            else:
                #FIXME: for PDM pass-through, set framerate=16KHz?
                self.swire_framerate = 16

        tblog.infoLog(
            "Route{0} def: channel {1}, RX port {2} TX port {3}!".format(
                route_num, self.channel_num, self.dp_rx, self.dp_tx))

        self.updateSwireSetting()
        tblog.infoLog("SWIRE route updated")

        #gen route script name
        route_script = output_dir + os.path.splitext(
            self.route_script)[0] + str(route_num) + '_' + str(
                rx_samplerate) + 'K_' + str(rx_wordlength) + 'bit_' + str(
                    tx_samplerate) + 'K_' + str(tx_wordlength) + 'bit_' + str(
                        frame_size) + 'ms.xml'

        #when frame_size = 0.5ms, set shapiro 0x8035 = 0
        if frame_size < 1:
            frame_size = 0

        with open(template) as route_in, open(route_script, 'w') as route_out:
            for line in route_in:
                '''
                Gen script for shaprio route setup
                '''
                if re.search('start shapiro setup', line):
                    route_out.write(line)
                    self.genShapiroRouteSetting(route_out, route_num,
                                                frame_size)
                    continue
                '''
                gen script for swire route setup
                '''
                if re.search('start swire channel setup', line):
                    route_out.write(line)
                    self.genSwireRouteSetting(route_out)
                    self.genSwireFrameShapeSetting(route_out)
                    continue
                '''
                gen script for swire data stream transfer and close 
                '''
                if re.search('start data stream', line):
                    #start stream only when input is swire
                    if self.dp_rx != 0:
                        self.genSwireStreamStart(
                            route_out, self.swire_rows, self.swire_cols,
                            swire_route_properties['_DPRX_CHANNEL_EN_']
                            [swire_reg_val])
                    #loop for data transfer
                    self.genSwireStreamLoop(route_out, self.swire_rows,
                                            self.swire_cols)

                    #disable swire channel
                    if self.dp_rx != 0:
                        self.writeReadSwireReg(
                            route_out, 1,
                            swire_route_properties['_DPRX_CHANNEL_EN_']
                            [swire_reg_addr], 0, 1, self.swire_rows,
                            self.swire_cols)
                    self.writeReadSwireReg(
                        route_out, 1,
                        swire_route_properties['_DPTX_CHANNEL_EN_']
                        [swire_reg_addr], 0, 1, self.swire_rows,
                        self.swire_cols)

                    #delay 2 ms
                    self.genSwirePing(route_out, self.calTimeInFrames(2), 0,
                                      self.swire_rows, self.swire_cols)

                    #stop shapiro route
                    self.writeShapiroReg(route_out, 0x8033, 0, 1,
                                         self.swire_rows, self.swire_cols)
                    continue
                '''
                gen script for swire data stream def
                '''
                if re.search('start stream define', line):
                    route_out.write(line)
                    #only when input is swire
                    if self.dp_rx != 0:
                        self.genSwireStream(route_out)
                    continue

                if re.search('_DATE_', line):
                    #update date
                    line = line.replace(
                        "_DATE_",
                        datetime.datetime.now().strftime("%m/%d/%Y"))
                    tblog.infoLog(
                        "route setup script updated: {0}".format(line))

                route_out.write(line)

        route_in.close()
        route_out.close()
        return route_script
Exemple #9
0
    def bin2CtrlPort(self, bin_file, cp_dl_script):
        '''
        convert config/fw binary file to LnK data control port script file
            bin_file: binary_file name(config or FW)
            cp_dl_script: output CP DL script file name
        '''
        if not os.path.isfile(self.output_path + self.cp_header_file):
            tblog.infoLog("LnkScriptMod: failed to find CP header script!")
            raise BellagioError(
                "LnkScriptMod: failed to find CP header script!")

        if not os.path.isfile(self.output_path + self.cp_content_file):
            tblog.infoLog("LnkScriptMod: failed to find CP content script!")
            raise BellagioError(
                "LnkScriptMod: failed to find CP content script!")
        '''
        ###convert binary to txt and align to 4-byte
        '''
        bin2lnk = Bin2Lnk()
        bin2lnk.bin2txt(bin_file, self.tmp_txt)
        '''
        ###generate CP DL script from header, content and input data
        '''
        with open(self.output_path + self.cp_header_file) as cp_header, open(
                cp_dl_script,
                'w') as cp_dl_out, open(self.tmp_txt) as input_data:
            event_str = "0"
            for header_line in cp_header:
                '''
                ###write header file to output till last line
                '''
                if not re.search('Command', header_line):
                    '''
                    #1. write header to output
                    #2. scan event number
                    #3. update current date
                    '''
                    found = re.search('(?<=Event #)\w+', header_line)
                    if found:
                        event_str = found.group(0)
                        #tblog.infoLog("event number: {0}" .format(event_str))
                    if re.search('_DATE_', header_line):
                        #update date
                        header_line = header_line.replace(
                            "_DATE_",
                            datetime.datetime.now().strftime("%m/%d/%Y"))
                    #tblog.infoLog("{0}" .format(header_line))
                    cp_dl_out.write(header_line)
                else:
                    '''
                    ###loop input data into content script and insert
                    '''
                    event_num = int(
                        event_str
                    ) + 2  #Event # LHDEBUG...original # start from "+2"
                    tblog.infoLog(
                        "start event number in int: {0}".format(event_num))

                    dword = input_data.read(self.dword_size)
                    #tblog.infoLog("dword read: {0}" .format(dword))

                    while dword != "":
                        '''
                        ###reset data count and addr
                        '''
                        data_count = 0
                        reg_addr = 2000
                        l = list(dword)

                        with open(self.output_path +
                                  self.cp_content_file) as cp_content:
                            for line in cp_content:
                                if re.search('event_num', line):
                                    '''
                                    ###update event
                                    '''
                                    new_line = line.replace(
                                        "event_num", str(event_num))
                                    event_num += 1
                                elif re.search('reg_addr', line) and re.search(
                                        'data', line):
                                    '''
                                    ###update register address and data
                                    '''
                                    new_line1 = line.replace(
                                        "reg_addr", str(reg_addr))
                                    new_line = new_line1.replace(
                                        "data", l[data_count * 2] +
                                        l[data_count * 2 + 1])
                                    #tblog.infoLog("reg_addr: {0} data: {1}" .format(reg_addr, l[data_count*2] + l[data_count*2+1]))
                                    data_count += 1
                                    reg_addr += 1
                                else:
                                    '''
                                    ###do nothing
                                    '''
                                    if re.search('Delay of about 2 us', line):
                                        ###add one frame delay?
                                        event_num += 1
                                    new_line = line
                                cp_dl_out.write(new_line)
                        cp_content.close()
                        '''
                        ###loop data file
                        '''
                        dword = input_data.read(self.dword_size)
                        #tblog.infoLog("dword read: {0}" .format(dword))
                        #break   ###debug...
                    ###write "<Command>" line
                    cp_dl_out.write(header_line)

        cp_header.close()
        cp_dl_out.close()
        input_data.close()
        os.remove(self.tmp_txt)
        tblog.infoLog(
            "LnkScriptMod: converted bin to control port script file{0}!".
            format(cp_dl_script))