예제 #1
0
 def start(self):
     bot = FBot(listen_socks=[900, 1100], listen_accpet_callback=self.listen_accept_callback, report_status=True,
                comment="任务大脑调度")
     bot.add_listen_callbacks(901, self.protocol_state_B)
     bot.add_listen_callbacks(903, self.protocol_state_D)
     bot.add_listen_callbacks(1101, self.protocol_state_B2)
     bot.add_listen_callbacks(1103, self.protocol_state_D2)
     bot.add_listen_callbacks(1105, self.protocol_state_E2)
     bot.run()
예제 #2
0
    def protocol_state_E2(self, value, param1, param2, is_last_package):
        print("[*]Protocol State E2:Value={0},Param1={1},Param2={2}".format(
            value, param1, param2))

        sendCTUnit = FBot.make_package(1105, "自定义协议哦", "是的", "没错")
        retCTUnitArray = [sendCTUnit]
        return retCTUnitArray
예제 #3
0
    def protocol_state_C2(self, value, param1, param2, is_last_package):
        print("[*]Protocol State C2:Value={0},Param1={1},Param2={2}".format(
            value, param1, param2))

        strNowTime = time.strftime("%y-%m-%d %H:%M:%S", time.localtime())
        sendCTUnit = FBot.make_package(
            1103, "", "", "插件2模块计算结果为:{0} [{1}]".format(value, strNowTime))
        retCTUnitArray = [sendCTUnit]
        return retCTUnitArray
예제 #4
0
파일: brain_side.py 프로젝트: afcentry/Test
def listen_request_exec_callback(peerName, value, param1, param2,
                                 is_last_package):
    print(
        "[*]Listen Request Exec Callback:PeerName={0},Value={1},Param1={2},Param2={3}"
        .format(peerName, value, param1, param2))
    sendCTUnit = FBot.make_package(OP_ACTION_BRAIN_SUB_CMD_REPLY_REQUEST_EXEC,
                                   "Do Add Task", "100", "200")
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray
예제 #5
0
def connect_request_exec_callback(value, param1, param2, is_last_package):
    print("[*]Connect Request Callback:Value={0},Param1={1},Param2={2}".format(
        value, param1, param2))
    if "Add" in value:
        c = int(param1) + int(param2)
    else:
        c = -99999
    strNowTime = time.strftime("%y-%m-%d %H:%M:%S", time.localtime())
    sendCTUnit = FBot.make_package(OP_ACTION_BRAIN_SUB_CMD_REPLY_EXEC_RESULT,
                                   "", "",
                                   "插件模块计算结果为:{0} [{1}]".format(c, strNowTime))
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray
예제 #6
0
파일: brain_side.py 프로젝트: afcentry/Test
def protocol_state_B(peerName, value, param1, param2, is_last_package):
    '''
    回调处理函数
    :param peerName: 回调任务远端节点名称
    :param value: 参数Value,内容由用户根据协议自定义
    :param param1: 参数Value,内容由用户根据协议自定义
    :param param2: 参数Value,内容由用户根据协议自定义
    :param is_last_package: 是否是最后一个数据包(处理的数据包可能是一批,也可能是单个)
    :return: 处理完成后需要发送应答的数据包或数据包List集合
    '''
    #print("[*]Protocol State B:PeerName={0},Value={1},Param1={2},Param2={3}".format(peerName, value,param1, param2))
    sendCTUnit = FBot.make_package(902, str(time.time()), "", "")
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray
예제 #7
0
from TYBotSDK2.FBot.fbotV2 import FBot
from TYBotSDK2.FBot.global_define import *
import time


#实现关于OP_ACTION_BRAIN_SUB_CMD_REPLY_EXEC_RESULT指令结果的回调
def connect_request_exec_callback(value, param1, param2, is_last_package):
    print("[*]Connect Request Callback:Value={0},Param1={1},Param2={2}".format(
        value, param1, param2))
    if "Add" in value:
        c = int(param1) + int(param2)
    else:
        c = -99999
    strNowTime = time.strftime("%y-%m-%d %H:%M:%S", time.localtime())
    sendCTUnit = FBot.make_package(OP_ACTION_BRAIN_SUB_CMD_REPLY_EXEC_RESULT,
                                   "", "",
                                   "插件模块计算结果为:{0} [{1}]".format(c, strNowTime))
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray


if __name__ == "__main__":
    bot = FBot(
        name="FBotA",
        connect_to_socks={"BrainA": LISTEN_SOCK_FBOT_ACTION_BRAIN_OPERATE})
    bot.add_connect_to_callbacks("BrainA", connect_request_exec_callback)
    bot.run()
예제 #8
0
파일: brain_side.py 프로젝트: afcentry/Test
def protocol_state_E2(peerName, value, param1, param2, is_last_package):
    print("[*]Protocol State E2:PeerName={0},Value={1},Param1={2},Param2={3}".
          format(peerName, value, param1, param2))
    sendCTUnit = FBot.make_package(1106, "", "", "")
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray
예제 #9
0
파일: brain_side.py 프로젝트: afcentry/Test
    print("[*]Protocol State D2:PeerName={0},Value={1},Param1={2},Param2={3}".
          format(peerName, value, param1, param2))
    sendCTUnit = FBot.make_package(1104, "", "", "")
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray


def protocol_state_E2(peerName, value, param1, param2, is_last_package):
    print("[*]Protocol State E2:PeerName={0},Value={1},Param1={2},Param2={3}".
          format(peerName, value, param1, param2))
    sendCTUnit = FBot.make_package(1106, "", "", "")
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray


def listen_accept_callback(**kwargs):
    for key in kwargs:
        print(key, kwargs[key])


if __name__ == "__main__":
    bot = FBot(listen_socks=[900, 1100],
               listen_accpet_callback=listen_accept_callback,
               report_status=True,
               comment="任务大脑调度")
    bot.add_listen_callbacks(901, protocol_state_B)
    bot.add_listen_callbacks(903, protocol_state_D)
    bot.add_listen_callbacks(1101, protocol_state_B2)
    bot.add_listen_callbacks(1103, protocol_state_D2)
    bot.add_listen_callbacks(1105, protocol_state_E2)
    bot.run()
예제 #10
0
 def protocol_state_B2(self, peerName, value, param1, param2, is_last_package):
     # print("[*]Protocol State B2:PeerName={0},Value={1},Param1={2},Param2={3}".format(peerName, value,param1, param2))
     sendCTUnit = FBot.make_package(1102, str(time.time()), "", "")
     retCTUnitArray = [sendCTUnit]
     return retCTUnitArray
예제 #11
0
    def start(self):
        bot = FBot(connect_to_socks={"BrainA": [900, 1100]},
                   report_status=True,
                   comment="执行加法计算")
        bot.add_connect_to_callbacks("BrainA", 900, 901, self.protocol_state_A,
                                     True)
        bot.add_connect_to_callbacks("BrainA", 900, 902, self.protocol_state_C,
                                     False)

        bot.add_connect_to_callbacks("BrainA", 1100, 1101,
                                     self.protocol_state_A2, True)
        bot.add_connect_to_callbacks("BrainA", 1100, 1102,
                                     self.protocol_state_C2, False)
        bot.add_connect_to_callbacks("BrainA", 1100, 1104,
                                     self.protocol_state_E2, False)
        bot.run()
예제 #12
0
    def protocol_state_A2(self, value, param1, param2, is_last_package):
        # print("[*]Protocol State A2:Value={0},Param1={1},Param2={2}".format(value,param1,param2))

        sendCTUnit = FBot.make_package(1101, "", "", "")
        retCTUnitArray = [sendCTUnit]
        return retCTUnitArray
예제 #13
0
파일: brain_side.py 프로젝트: afcentry/Test
                                 is_last_package):
    print(
        "[*]Listen Request Exec Callback:PeerName={0},Value={1},Param1={2},Param2={3}"
        .format(peerName, value, param1, param2))
    sendCTUnit = FBot.make_package(OP_ACTION_BRAIN_SUB_CMD_REPLY_REQUEST_EXEC,
                                   "Do Add Task", "100", "200")
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray


#实现关于OP_ACTION_BRAIN_SUB_CMD_REPLY_EXEC_RESULT指令的回调
def listen_reply_request_exec_callback(peerName, value, param1, param2,
                                       is_last_package):
    print(
        "[*]Listen Reply Request Exec Callback:PeerName={0},Value={1},Param1={2},Param2={3}"
        .format(peerName, value, param1, param2))
    sendCTUnit = FBot.make_package(
        OP_ACTION_BRAIN_SUB_CMD_REPLY_REPLY_EXEC_RESULT, "", "", "")
    retCTUnitArray = [sendCTUnit]
    return retCTUnitArray


if __name__ == "__main__":
    bot = FBot(name="BrainA",
               listen_mode=True,
               listen_operate_id=LISTEN_SOCK_FBOT_ACTION_BRAIN_OPERATE)
    bot.add_listen_callbacks(str(OP_ACTION_BRAIN_SUB_CMD_REQUEST_EXEC),
                             listen_request_exec_callback)
    bot.add_listen_callbacks(str(OP_ACTION_BRAIN_SUB_CMD_REPLY_EXEC_RESULT),
                             listen_reply_request_exec_callback)
    bot.run()