Beispiel #1
0
def deal_assign_slave_router(req: bytearray, *args) -> (bytearray, bool):
    """处理分配从机帧.返回值是应答数据和应答标志.应答标志为false表示不需要应答"""
    if len(req) == 0:
        lagan.warn(config.TAG, "deal apply failed.payload len is wrong:%d",
                   len(req))
        return None, False

    j = 0
    if req[j] != 0:
        lagan.warn(config.TAG, "deal apply failed.error code:%d", req[j])
        return None, False
    j += 1

    if len(req) != 16:
        lagan.warn(config.TAG, "deal apply failed.payload len is wrong:%d",
                   len(req))
        return None, False

    param.parent.ia = utz.bytes_to_ia(req[j:j + utz.IA_LEN])
    j += utz.IA_LEN

    ip = socket.inet_ntoa(req[j:j + 4])
    j += 4
    port = (req[j] << 8) + req[j + 1]
    j += 2
    param.parent.pipe = dcom.addr_to_pipe(ip, port)

    lagan.info(config.TAG,
               "apply success.parent ia:0x%x ip:%s port:%d cost:%d",
               param.parent.ia, ip, port, req[j])
    return None, False
Beispiel #2
0
def config_core_param(ia: int, ip: str, port: int):
    """配置核心网参数"""
    global core_ia, core_ip, core_port, core_pipe
    core_ia = ia
    core_ip = ip
    core_port = port
    core_pipe = dcom.addr_to_pipe(ip, port)
Beispiel #3
0
def _socket_rx():
    global _socket
    while True:
        data, address = _socket.recvfrom(config.FRAME_MAX_LEN)
        if len(data) == 0:
            continue
        lagan.info(config.TAG, 'udp rx:%r len:%d', address, len(data))
        lagan.print_hex(config.TAG, lagan.LEVEL_DEBUG, bytearray(data))
        pipe_receive(dcom.addr_to_pipe(address[0], address[1]), data)
Beispiel #4
0
def _socket_rx():
    global _socket, _item
    while True:
        data, address = _socket.recvfrom(config.FRAME_MAX_LEN)
        if len(data) == 0:
            continue
        lagan.info(config.TAG, 'udp rx:%r len:%d', address, len(data))
        lagan.print_hex(config.TAG, lagan.LEVEL_DEBUG, bytearray(data))

        if _item.is_rx:
            lagan.warn(config.TAG, 'udp rx:%r len:%d.deal is too slow!!!',
                       address, len(data))
            continue
        _item.pipe = dcom.addr_to_pipe(address[0], address[1])
        _item.data = data
        _item.is_rx = True
Beispiel #5
0
def init():
    global core_pipe
    core_pipe = dcom.addr_to_pipe(core_ip, core_port)