def SendVoiceFile(self, request_iterator, context):
     '''
     description: this function is the response function when
     the AR site send voice file to the robot site.
     param {*} self
     param {VoiceFile} request: the bytes of voice file, which is str
     param {*} context
     return {Response} feedback response
     TODO: post the custom message of getting voice file
     '''
     # The following code save the voice file
     '''
     filename = "example.wav"
     with open(filename, "wb+") as file:
         for bytestr in request_iterator:
             file.write(bytestr)
             print(bytestr)
     '''
     # according to protocol buffer document, bytestr is a string.
     # bytestr need convert to byte buffer and then write into the files.
     # TODO: please implement the convert method.
     for bytestr in request_iterator:
         print(bytestr.file)
     # if the reqeust message goes wrong, please modify the status to 1
     if self.receiveVoice is not None:
         # The Callback function
         return msg_pb2.Response(
             status=self.receiveVoice(request_iterator, context))
     else:
         return msg_pb2.Response(status=0)
    def ConfigMap(self, request, context):
        '''
        description: this function is the response function when
        the control site sends config map message to robot.
        param {*} self
        param {Map} request: the config map message
        param {*} context
        return {Response} feedback response
        TODO: post the custom message of getting config map
        '''
        # The following code prints the received message
        width = request.roomwidth
        height = request.roomheight
        blocks = request.blocks
        print("Room Width: {}".format(width))
        print("Room Heigth: {}".format(height))
        for block in blocks:
            print("Type: {}, W: {}, H: {}, Pos x: {}, Pos y: {}".format(
                block.type, block.w, block.h, block.pos.posx, block.pos.posy))

        # if the reqeust message goes wrong, please modify the status to 1
        if self.receiveMap is not None:
            # The Callback function
            return msg_pb2.Response(status=self.receiveMap(request, context))
        else:
            return msg_pb2.Response(status=0)
 def ControlCommand(self, request, context):
     '''
     description: this function is the response function when
     the control site send control command suck as start experiment
     or stop experiment.
     param {*} self
     param {ControlCmd} request: the ControlCmd message
     param {*} context
     return {Response} feedback response
     TODO: post the custom message of getting Control Command
     '''
     # The following code prints the received message
     # if the reqeust message goes wrong, please modify the status to 1
     if self.receiveCommand is not None:
         # The Callback function
         return msg_pb2.Response(
             status=self.receiveCommand(request, context))
     else:
         return msg_pb2.Response(status=0)
 def DriveRobot(self, response, context):
     '''
     description: this function is the response function when the control server site sends drive robot message
     param {*} self
     param {Drive} response
     param {*} context
     return {Response}
     '''
     return msg_pb2.Response(
         status=self.receiveDriveCommand(response, context))
Пример #5
0
def sendResponseMsg(receiver, status):
    '''
    description: this function send the robot finished message to the receiver.
    param {str} receiver: the message's receiver
    return {int} feedback response status
    '''
    address = getAddr(receiver)
    print("send response to " + receiver + ": " + address)
    channel = grpc.insecure_channel(address)
    stub = msg_pb2_grpc.MsgServicesStub(channel)
    resultmsg = msg_pb2.Response(status=status)
    response = stub.RobotFinished(resultmsg)
    print("Send Robot Finished Feedback" + "{}".format(response.status))
    return response.status
Пример #6
0
    def response(self, flow: mitmproxy.http.HTTPFlow):
        # 每分钟储存一次记录
        now = datetime.now()
        if now.minute != self._minute and len(self._viewer) > 0:
            with open(self._filename, "a", encoding="utf-8") as f:
                json.dump({
                    "viewer": int(sum(self._viewer) / len(self._viewer)),
                    "comment": self._comment,
                    "time": now.strftime("%d %H%M")
                }, f)
                f.write("\n")
            self._minute = now.minute
            self._viewer = list()
            self._comment = 0
            print("存储记录啦")
        if flow.request.host == "webcast.amemv.com" \
                and re.match("^/webcast/im/fetch.*$", flow.request.path):
            msg = msg_pb2.Response()
            msg.ParseFromString(flow.response.content)
            for x in msg.messages:
                # print(x.method)
                if x.method == "WebcastChatMessage":
                    payload = payload_pb2.Detail()
                    payload.ParseFromString(x.payload)
                    user = payload.info
                    t1 = threading.Thread(target=save_comment, args=(user.username, user.userId1, payload.chatMessage))
                    t1.start()
                    print("%s(%s | %s) : %s" % (user.username, user.userId1, user.userId2, payload.chatMessage))
                    self._comment += 1

                # 点赞真不真?
                elif x.method == "WebcastLikeMessage":
                    pass
                # 到底有几个人?
                elif x.method == "WebcastRoomUserSeqMessage":
                    user_info = userinfo_pb2.userResponse()
                    user_info.ParseFromString(x.payload)
                    self._viewer.append(user_info.total)
                    print("直播间人数 %d" % user_info.total)