加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
handlecommand.py 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
Xvar 提交于 2021-11-27 16:32 . finish network recv send
import timer
import network
import pickle
import time
class CHandleCommand(object):
def __init__(self):
self.m_NextSecond = int(time.time()*100)
self.m_FrameCommandList = []
timer.Call_Out_Per_Second(self.SendMsg, 1)
def OnHandle(self, lstPackage):
for iFileNo, packageInfo in lstPackage:
self.OnCommand(iFileNo, packageInfo)
def OnCommand(self, iFileNo, PackageInfo):
print("OnCommand", iFileNo, PackageInfo)
sMsg = PackageInfo.get("msg", "")
sPackage = pickle.dumps({"msg":sMsg, "no":iFileNo})
self.m_FrameCommandList.append(sPackage)
def SendMsg(self):
self.m_NextSecond = int(time.time()*100)
sAllMsg = pickle.dumps(self.m_FrameCommandList)
if self.m_FrameCommandList:
print("SendMsg")
network.SendAll(sAllMsg)
self.m_FrameCommandList = []
timer.Call_Out_Per_Second(self.SendMsg, 1)
def Init():
global g_HandleCommand
g_HandleCommand = CHandleCommand()
def GetHandleCommand():
global g_HandleCommand
return g_HandleCommand
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化