Exemple #1
0
 def _custparamget(self, index, name):
     value = None
     cmd = "custparamget %s" % index
     resp = self.sendcmd(cmd)
     if "OK" in resp:
         lines = resp.split("\n")
         data = lines[0]
         match = re.search("%s=(.*)" % name, data)
         if match:
             value = match.group(1)
             value = value.rstrip("\r\n")
         else:
             raise DeviceAdapterError("Can't get the param value with index '%s' and name '%s'" % (index, name))
     else:
         raise DeviceAdapterError("'%s' failed" % cmd)
     return value
Exemple #2
0
 def getHRLinkQuality(self):
     value = None
     cmd = "get_hr_link_quality"
     resp = self.sendcmd(cmd)
     if "OK" in resp:
         lines = resp.split("\n")
         data = lines[0]
         match = re.search("HR_LINK_QUALITY=(.*)", data)
         if match:
             value = match.group(1)
             value = int(value.strip())
         else:
             raise DeviceAdapterError("Can't get hr link quality")
     else:
         raise DeviceAdapterError("'%s' failed" % cmd)
     return value
Exemple #3
0
 def set_ss_server_logname(self, newname):
     resp = self.sendcmd("ss_server logfilename=%s" % newname)
     if resp == "OK":
         logger.info("change ss_server log path done")
         self.logname = newname
     else:
         raise DeviceAdapterError("change ss_server log path failed")
Exemple #4
0
    def __init_and_get_interrupt_for_ever(self):
        # if not SiiHalAardvarkCreate()
        if not SiiPlatformCreate(self.devport):
            raise DeviceAdapterError("ERROR: I2c not available")

        config = Sii9777Config_t()
        config.pNameStr = "9777-Rx"
        config.bDeviceReset = bool_t(True)

        func = Sii9777EventCallbackFunc_t(self.evt_subject.event_callback)
        self.drv_instance = Sii9777Create(self.devport, func,
                                          ctypes.byref(config))
        if not self.drv_instance:
            raise DeviceAdapterError(
                "Call driver api SiiDrvAdaptCreate failed!!!")

        while True:
            status = Sii9777BootStat_t()
            with self.lock:
                Sii9777BootStatusQuery(self.drv_instance, ctypes.byref(status))
            if status.value == SII9777_BOOT_STAT__IN_PROGRESS:
                time.sleep(0.1)
                continue
            elif status.value == SII9777_BOOT_STAT__FAILURE:
                raise ValueError(
                    "Sii9777BootStatus: SII9777_BOOT_STAT__FAILURE")
            elif status.value == SII9777_BOOT_STAT__SUCCESS:
                break
            else:
                raise ValueError("Sii9777BootStatus not in (0, 1, 2)")

        mask = Sii9777EventFlags_t(SII9777_EVENT_FLAGS__ALL)
        with self.lock:
            Sii9777EventFlagsMaskSet(self.drv_instance, ctypes.byref(mask))

        while not self.__should_stop.is_set():
            with self.lock:
                #logger.debug("Call SiiHalAardvarkInterruptQuery")
                #if SiiHalAardvarkInterruptQuery():
                if SiiPlatformInterruptQuery(self.devport):
                    Sii9777Handle(self.drv_instance)
            time.sleep(0.1)

        with self.lock:
            Sii9777Delete(self.drv_instance)
            #SiiHalAardvarkDelete()
            SiiPlatformDelete(self.devport)
Exemple #5
0
 def run(self, cmd):
     if self._android_serial:
         cmd = 'adb -s %s shell "%s"' % (self._android_serial, cmd)
     logger.debug("run: cmd=%s", cmd)
     proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
     stdout = proc.communicate()[0]
     logger.debug("run: retcode=%s, output=\n%s", proc.returncode, stdout)
     if proc.returncode != 0:
         raise DeviceAdapterError("command '%s' error" % cmd)
     return proc.returncode, stdout
Exemple #6
0
 def read_block(self, page, offset, length):
     self.run("echo %d > %s/reg_access/page" % (page, self.DEVPATH))
     self.run("echo %d > %s/reg_access/offset" % (offset, self.DEVPATH))
     self.run("echo %d > %s/reg_access/length" % (length, self.DEVPATH))
     retcode, data = self.run("cat %s/reg_access/data" % self.DEVPATH)
     actual_key, value = data.split(":")
     expect_key = "0x%02x'0x%02x" % (page, offset)
     if actual_key != expect_key:
         raise DeviceAdapterError("%s != %s" % (actual_key, expect_key))
     return [int(s, 16) for s in value.strip().split(" ")]
Exemple #7
0
    def __init_flash(self, operation, target):
        logger.debug("Sii9777FlashInit: operation=%s, target=%s", operation,
                     target)
        with self.lock:
            Sii9777FlashInit(self.drv_instance, operation, target)

        while True:
            pStatus = Sii9777FileStatus_t()
            with self.lock:
                Sii9777FlashStatusQuery(self.drv_instance,
                                        ctypes.byref(pStatus))
            if pStatus.value == SII9777_FILE_STATUS__READY:
                break
            elif pStatus.value == SII9777_FILE_STATUS__IN_PROGRESS:
                time.sleep(0.5)
                continue
            elif pStatus.value == SII9777_FILE_STATUS__FAILURE:
                raise DeviceAdapterError("Sii9777FlashInit failed.")
            else:
                raise DeviceAdapterError("Unsupported status value %s" %
                                         pStatus.value)
Exemple #8
0
 def get_local_devcap(self):
     pData = (uint8_t * 16)()
     offset = uint8_t(0)
     length = uint8_t(16)
     with self.lock:
         retcode = Sii9777CbusLocalDevcapGet(self.drv_instance, pData,
                                             offset, length)
     if retcode != 0:
         raise DeviceAdapterError(
             "call API Sii9777CbusLocalDevcapGet failed.")
     devcap = [pData[index] for index in range(16)]
     logger.debug("%s get local devcap: %s", self, devcap)
     return devcap
Exemple #9
0
 def _get_umac_sm_show(self):
     resp = self.sendcmd("umac_sm_show", interval=1, timeout=10)
     data = resp.split("\n")[1]
     match = re.search("Cfg:.*HR=(\d{1}), LR=(\d{1}), Dev=(\w+), WVAN_ID=(\d+)", data)
     if match:
         hr = match.group(1)
         lr = match.group(2)
         dev = match.group(3)
         wvan_id = match.group(4)
         ret = (int(hr), int(lr), dev, int(wvan_id))
         return ret
     else:
         raise DeviceAdapterError("umac_sm_show failed")
Exemple #10
0
 def set_local_x_devcap(self, data):
     logger.debug("%s set local x devcap: %s", self, data)
     pData = (uint8_t * 4)()
     for index in range(4):
         pData[index] = data[index]
     offset = uint8_t(0)
     length = uint8_t(4)
     with self.lock:
         retcode = Sii9777CbusLocalXDevcapSet(self.drv_instance, pData,
                                              offset, length)
     if retcode != 0:
         raise DeviceAdapterError(
             "call API Sii9777CbusLocalXDevcapSet failed.")
Exemple #11
0
    def open(self):
        if self.comport is not None:
            self.log_subject.open()

        self.__should_stop.clear()
        if self.devport is not None:
            self.__thread = threading.Thread(
                target=self.__init_and_get_interrupt_for_ever)
            self.__thread.name = threading.current_thread().name
            self.__thread.start()
            time.sleep(5.0)

            if self.drv_instance is None:
                raise DeviceAdapterError("Create Sii9777 instance failed")
Exemple #12
0
    def __write_flash_block(self, data):
        logger.debug("write flash block: %r", data)
        length = len(data)
        buff = (uint8_t * length)()
        for i in range(length):
            buff[i] = uint8_t(ord(data[i]))

        with self.evt_subject.listen(
                SII9777_EVENT_FLAGS__FLASH_DONE) as listener:
            with self.lock:
                Sii9777FlashUpdate(self.drv_instance, buff, length)
            event = listener.get(timeout=3.0)
            if event is None:
                raise DeviceAdapterError("Sii9777FlashUpdate failed.")
Exemple #13
0
 def __check_ss_server_available(self):
     logger.debug("check ss_server is available with cmd: show_version ")
     conn = SWAM3Connection(addr=("127.0.0.1", self._tcpport))
     while True:
         try:
             conn.open()
         except socket.error:
             time.sleep(1)
             continue
         else:
             cmd = "show_version 1" if self._srvtype == "server_jax" else "show_version"
             if not conn.sendcmd(cmd):
                 conn.sendcmd("ss_server exit", timeout=1.0)
                 raise DeviceAdapterError("startup ss_server failed")
             break
         finally:
             conn.close()
Exemple #14
0
    def upgradeFirmware(self, filename):
        """
        ERROR: AP port not opened<EOF>
        ERROR: Module not supported<EOF>
        ERROR: File not exists<EOF>
        ERROR: Open file failed<EOF>
        ERROR: Upgrade firmware failed<EOF>
        OK: Upgrade firmware succeeded<EOF>
        """
        if not os.path.exists(filename):
            raise OSError(errno.ENOENT, "Firmware '%s' not exists" % filename)

        resp = self.sendcmd("svr_apcommand full_upgrade=%s" % filename, timeout=120.0)
        try:
            match = re.search(r"ERROR: (.*)", resp)
            if match:
                raise DeviceAdapterError(match.group(1))
        finally:
            self.reset()
Exemple #15
0
    def update_flash_full_device(self, filename):
        self.__init_flash(SII9777_FILE_OPERATION__WRITE,
                          SII9777_FILE_TARGET__FULL_DEVICE)

        with open(filename, "rb") as f:
            flash = f.read()
        logger.debug("set RX0-RX3 HPD to True and update flash checksum")
        l = list(flash)
        l[0x0000DEBB] = '\x01'
        l[0x0000DEBC] = '\x01'
        l[0x0000DEBD] = '\x01'
        l[0x0000DEBE] = '\x01'
        flash = l
        self.update_flash_checksum(flash)

        logger.debug("programing start")

        index = 0
        total_length = len(flash)
        slice_length = 256
        process = None
        for i in range(total_length / slice_length):
            self.__write_flash_block(flash[index:(i + 1) * slice_length])
            index += slice_length

            prev_process = process
            process = int(round(float(index) / float(total_length), 2) * 100)
            if (process % 5) == 0 and process != prev_process:
                logger.debug("programing process: %s%%", process)
        if total_length % slice_length > 0:
            self.__write_flash_block(flash[index:-1], )
        logger.debug("programing done")

        with self.lock:
            Sii9777FirmwareRestart(self.drv_instance)
        time.sleep(1.0)

        while self.__query_boot_status() == SII9777_BOOT_STAT__IN_PROGRESS:
            time.sleep(0.5)

        if self.__query_boot_status() == SII9777_BOOT_STAT__FAILURE:
            raise DeviceAdapterError("upgrade firmware failed")
        logger.info("upgrade firmware successfully")
Exemple #16
0
 def setMacAddress(self, macaddr):
     resp = self.sendcmd("custparamset 0 %s" % sstring.trimMacAddress(macaddr))
     if "OK" not in resp:
         raise DeviceAdapterError("set mac address failed with value: %s" % macaddr)
Exemple #17
0
    def __init_rogue_and_get_interrupt_for_ever(self):
        """
        must put rogue initinalize and get interrupt in same thread, otherwise, it will cause access violation reading
        """
        ADAPT_DEFAULT_I2C_DEVICE_ID = 0x70
        SPI_ERASE_COMMAND = 0xD8
        SPI_WRITE_ENABLE_COMMAND = 0x06
        SPI_PAGE_WRITE_COMMAND = 0x02

        if not Platform_Create():
            raise DeviceAdapterError("Init BlackBox Failed!!!!")

        SiiPlatformInit()
        time.sleep(0.5)

        while not SiiHalGetInt1Flag():
            time.sleep(0.1)

        func = SiiLibEvtCbFunc_t(self.evt_subject.event_callback)
        self.sii_instance = SiiDrvAdaptCreate(0, 1, func)
        if not self.sii_instance:
            raise DeviceAdapterError(
                "Call driver api SiiDrvAdaptCreate failed!!!")

        adapt_config = SiiDrvAdaptConfig_t()
        if self.id == 0x9678:
            adapt_config.platformId = SII_DRV_ADAPT_PLATFORM__SII9678
            ADAPT_DEFAULT_I2C_DEVICE_ID = 0x60
        elif self.id == 0x9679:
            adapt_config.platformId = SII_DRV_ADAPT_PLATFORM__SII9679
        elif self.id == 0x9394:
            adapt_config.platformId = SII_DRV_ADAPT_PLATFORM__AVR
        else:
            raise ValueError("Unsupported platform %s" % hex(self.id))
        adapt_config.i2cSlaveAddr = ADAPT_DEFAULT_I2C_DEVICE_ID
        adapt_config.i2cSlaveAddrBase = SII_DRV_ADAPT_DEFAULT_I2C_DEVICE_ID_BASE
        adapt_config.i2cSlaveAddrF0 = 0
        adapt_config.i2cSlaveAddrAA = 0
        adapt_config.interruptPinType = SII_DRV_ADAPTER_INT__OPENDRAIN
        adapt_config.interruptPolarity = SII_DRV_ADAPTER_INT__POL_LOW
        adapt_config.spiConfig.eraseCmd = SPI_ERASE_COMMAND
        adapt_config.spiConfig.writeEnCmd = SPI_WRITE_ENABLE_COMMAND
        adapt_config.spiConfig.pageWrCmd = SPI_PAGE_WRITE_COMMAND

        SiiDrvAdaptConfigure(self.sii_instance, ctypes.byref(adapt_config))

        if self.id == 0x9678:
            state = SiiDrvAdaptHdcpProtect_t(SII_DRV_ADAPTER_HDCP_PROTECT__ON)
            SiiDrvAdaptTxHdcpProtectionSet(self.sii_instance, state)
            content_type = SiiDrvAdaptHdcpContenrType_t(
                SII_DRV_ADAPTER_HDCP_CONTENT__TYPE0)
            SiiDrvAdaptTxHdcpContentTypeSet(self.sii_instance, content_type)

        SiiDrvAdaptStart(self.sii_instance)

        while not self.__should_stop.is_set():
            if SiiHalGetInt1Flag():
                if SiiHalGetInterrupt1:
                    SiiDrvAdaptTaskExecute(self.sii_instance)
                else:
                    SiiHalSetInt1Flag(bool_t(False))

        SiiDrvAdaptStop(self.sii_instance)
        SiiDrvAdaptDelete(self.sii_instance)

        time.sleep(0.5)
        SiiPlatformDestroy()
        Platform_Destroy()
Exemple #18
0
 def send_devcap_change_command(self):
     with self.lock:
         retcode = Sii9777CbusDcapChgSend(self.drv_instance)
     if retcode != 0:
         raise DeviceAdapterError("call API Sii9777CbusDcapChgSend failed.")