当前位置: 首页>>代码示例>>Python>>正文


Python Connector.recvCommand方法代码示例

本文整理汇总了Python中connector.Connector.recvCommand方法的典型用法代码示例。如果您正苦于以下问题:Python Connector.recvCommand方法的具体用法?Python Connector.recvCommand怎么用?Python Connector.recvCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在connector.Connector的用法示例。


在下文中一共展示了Connector.recvCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Modem

# 需要导入模块: from connector import Connector [as 别名]
# 或者: from connector.Connector import recvCommand [as 别名]
class Modem(object):
    """Class modem to control the node via TCP"""

    class Status:
        """Internal class where the status sens_ts are defined"""
        IDLE, BUSY2REQ, BUSY2DATA, BUSY2RECV, BUSY2REQ2DATA, KILL = range(6)

    class ErrorDict:
        """Internal class to map the error sens_ts to their error message"""
        NONE, SYNT_ERR, WRONG_SETTING, NOT_RESPONDING, FILE_NOT_FOUND, \
        TX_WHILE_RX, RX_WHILE_TX = range(7)
        error_dict = {
            NONE : 'none',
            SYNT_ERR : 'command syntax error',
            WRONG_SETTING : 'wrong setting, value not allowed',
            NOT_RESPONDING : 'device not responding, check the status',
            FILE_NOT_FOUND : 'file not found error',
            TX_WHILE_RX : 'you attempt to transmit while receiving, if \
                you really want, set the force flag to 1',
            RX_WHILE_TX : 'you attempt to receive while transmitting if \
                you really want set the force flag to 1'
         }

    def __init__(self, ip, port, automatic = True, control_buf_size = 32, data_buf_size = 128, \
        m_to = 0.01, socket_to = 0.005):
        """
        Constructor, initialize the modem and the connector. Connect the
        modem to the submerged node
        @param self pointer to the class object
        @param ip string cointaining the IP address of the TCP server
        @param port string with the port of the TCP server socket
        @param control_buf_size: int with the control buffer size, in bytes
        @param data_buf_size: int with the data buffer size, in bytes
        @param m_to: float value time out of the cycle, in [s]
        @param socket_to: time out of the socket checking operation, [s]
        """
        self.conn = Connector(ip, port, control_buf_size, data_buf_size, socket_to)
        self.conn.connect()
        self.m_to = m_to
        self.status = Modem.Status.IDLE
        self.node_status = 0
        self.automatic = automatic
        self.interpreter = Interpreter()
        self.mainPID = os.getpid()
        self.error_status = Modem.ErrorDict.NONE
        self.commands_queue = "".split(Interpreter.END_COMMAND)
        if automatic:
            thread.start_new_thread(self.run,())

    def run(self):
        """
        Run cycle, checks if data available
        @param self pointer to the class object
        """
        threadPID = os.getpid()
        index = 0
        while True:
            index += 1
            if ((index * self.m_to) > 1):
                #self.check4kill(threadPID)
                index = 1
            if(self.status == Modem.Status.IDLE or self.status == Modem.Status.BUSY2REQ):
                r, e = self.conn.dataAvailable()
                if(e):
                    break
                if(r):
                    rx = self.recvCommand()
                    if (len(rx) == 0):
                        break
            elif(self.status == Modem.Status.KILL):
                break
            sleep(self.m_to)
        self.close()
        print >>sys.stderr, 'Closing'

    def check4kill(self,threadPID = -1):
        """
        Check if the process has to be killed
        @param self pointer to the class object
        """
        #TODO: check in the kill log if my main or my thred PID are there.
        #      In case True, kill all. /var/log/check_status/check_kills.log
        # kill $TOPPID
        # /var/log/check_status/check_off.log
        off_log = "/var/log/check_status/check_off.log"
        kill_log = "/var/log/check_status/check_kills.log"
        try:
            f = open (off_log, "r")
            l = f.read(self.conn.data_buf_size)
            while (l or self.status != Modem.Status.KILL):
                if l == "poweroff":
                    self.status = Modem.Status.KILL
                l = f.read(self.conn.data_buf_size)
            f.close()
        except IOError:
            print off_log + " not found"
        try:
            f = open (kill_log, "r")
            l = f.read(self.conn.data_buf_size)
            while (l or self.status != Modem.Status.KILL):
#.........这里部分代码省略.........
开发者ID:marinetech,项目名称:Udoo,代码行数:103,代码来源:modem.py


注:本文中的connector.Connector.recvCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。