Beispiel #1
0
def replyACK(ackToSend, sock):
    replyToWorld = wa.ACommands()
    replyToWorld.acks.append(ackToSend)
    reply = replyToWorld.SerializeToString()
    _EncodeVarint(sock.send, len(reply), None)
    sock.send(reply)
    return
def send_to_world(msg):
    print('msg you send is')
    print('-----')
    print(msg)
    print('-----')
    _EncodeVarint(world_fd.send, len(msg.SerializeToString()), None)
    world_fd.sendall(msg.SerializeToString())
Beispiel #3
0
def Send(sock, msg):
    print('sending out the following: ')
    print(msg)
    req = msg.SerializeToString()
    _EncodeVarint(sock.send, len(req), None)
    sock.send(req)
    print('send finish')
Beispiel #4
0
def waitACK(seqnum, message, sock):
    global WAIT_ACK_QUEUE

    while True:
        # receive from world
        wait = select.select([sock], [], [], 10)
        if wait[0]:
            world_response = responseFromWorld(sock)
            if not world_response.acks:
                print("no acks")
                print(world_response)
                break
            else:
                for ack in world_response.acks:
                    print(f"receive ack: {ack}")
                    WAIT_ACK_QUEUE.remove(ack)
                    if ack == seqnum:
                        # return
                        return world_response

                    # check WAIT_ACK_QUEUE every 10 seconds
        if seqnum in WAIT_ACK_QUEUE:
            # send again
            print("resend")
            _EncodeVarint(sock.send, len(message), None)
            sock.send(message)
Beispiel #5
0
 def write_output(self, message):
     serialized = message.SerializeToString()
     self.__lock.acquire()        
     encoder._EncodeVarint(self.__file.write, len(serialized))
     self.__file.write(serialized)
     self.__file.flush()
     self.__lock.release()
def send_to_amazon(msg):
    print('msg you send is')
    print('-----')
    print(msg)
    print('-----')
    _EncodeVarint(amazon_fd.send, len(msg.SerializeToString()), None)
    amazon_fd.sendall(msg.SerializeToString())
Beispiel #7
0
def WriteArticle(article, fileobj):
    """
    Writes the given Article protocol buffer to the given file-like object.
    """
    msg = article.SerializeToString()
    _EncodeVarint(fileobj.write, len(msg))
    fileobj.write(msg)
Beispiel #8
0
def sendMsg(s, protoType):
    if protoType is not None:
        msg = protoType.SerializeToString()
        _EncodeVarint(s.sendall, len(msg), None)
        try:
            s.sendall(msg)
        except:
            raise SocketDisconnectedException
Beispiel #9
0
def sendMsg(socket, msg):
    print("============")
    print("send:", msg)
    print("============")

    msgstr = msg.SerializeToString()
    _EncodeVarint(socket.send, len(msgstr), None)
    socket.send(msgstr)
def send(sock, msg, des):
    print("send : ")
    print(msg)
    print(des)
    req = msg.SerializeToString()
    _EncodeVarint(sock.send, len(req), None)
    sock.send(req)
    print('send finish')
Beispiel #11
0
def encode_uvarint(value):
    """Encode a long or int into a bytearray."""
    if not isinstance(value, int):
        raise TypeError("UVarInt encode requires a int type")

    output = bytearray()
    encoder._EncodeVarint(output.extend, value)
    return output
Beispiel #12
0
def my_send(s, message):
    print("------------------ Send Message ---------------")
    print(message)
    hdr = []
    _EncodeVarint(hdr.append, len(message.SerializeToString()), None)
    s.sendall(b"".join(hdr))
    s.sendall(message.SerializeToString())
    print("-----------------------------------------------")
Beispiel #13
0
def send_request(sock, request):
    """Send protocol buffer over connected socket

    Args:
        request -- a protocol buffer
    """
    message = request.SerializeToString()
    _EncodeVarint(sock.send, len(message), None)
    sock.sendall(message)
Beispiel #14
0
    def stop_recording(self):
        """ Stop recording. Always call this function or the :py:func:`blickfeld_scanner.stream.point_cloud.point_cloud.close` function before deleting a point_cloud object.
        """
        if self._ofile:
            self._stream_data.footer.CopyFrom(self._metadata.footer)
            _EncodeVarint(self._ofile.write, self._stream_data.ByteSize())
            self._ofile.write(self._stream_data.SerializeToString())

            self._ofile.close()
            self._ofile = None
def numpy_u32_encoder(write, value):
    value_bytes = value.tobytes()
    value_len = len(value_bytes)
    tag1 = (3 << 3) | 2
    tag2 = (1 << 3) | 2
    write(bytes([tag1]))
    _EncodeVarint(write, 1 + _VarintSize(value_len) + value_len)
    write(bytes([tag2]))
    _EncodeVarint(write, value_len)
    return write(value_bytes)
Beispiel #16
0
 def send_request(self):
     message = self.acommunicate.SerializeToString()
     _EncodeVarint(self.sock.send, len(message), None)
     while True:
         try:
             self.sock.sendall(message)
         except socket.error as e:           # broken connection
             self.sock.connect(self.addr)
             continue
         else:
             break
Beispiel #17
0
def encode_uvarint(value):
    """Encode a long or int into a bytearray."""
    output = bytearray()
    if value < 0:
        raise EncoderException(
            "Error encoding %d as uvarint. Value must be positive" % value)
    try:
        encoder._EncodeVarint(_gen_append_bytearray(output), value)
    except (struct.error, ValueError) as exc:
        six.raise_from(
            EncoderException("Error encoding %d as uvarint." % value), exc)

    return output
Beispiel #18
0
def writeToDelimitedString(obj, stream=None):
    """
    Stanford CoreNLP uses the Java "writeDelimitedTo" function, which
    writes the size (and offset) of the buffer before writing the object.
    This function handles parsing this message starting from offset 0.

    @returns how many bytes of @buf were consumed.
    """
    if stream is None:
        stream = BytesIO()

    _EncodeVarint(stream.write, obj.ByteSize(), True)
    stream.write(obj.SerializeToString())
    return stream
Beispiel #19
0
def connect_world_simulator():
    # UConnect message to world simulator
    uconnect = world_ups_pb2.UConnect()
    uconnect.trucks.extend([truck1, truck2])
    uconnect.isAmazon = False
    conn_world_req = uconnect.SerializeToString()
    _EncodeVarint(conn_world.sendall, len(conn_world_req))
    conn_world.sendall(conn_world_req)

    # UConnected from world simulator
    uconnected = world_ups_pb2.UConnected()
    data = recv_world_id()
    uconnected.ParseFromString(data)
    print("world simulator status: ", uconnected.result)
    return uconnected.worldid
Beispiel #20
0
    def build_cmd(self, cmd_type, cmd):
        msg = cmd.SerializeToString()
        cmd = CommandMsg()
        cmd.type = cmd_type
        cmd.content = msg
        msg = cmd.SerializeToString()
        
        class PrefixWriter(object):
            def __init__(self):
                self.msg = ''
            def write(self, onechr):
                self.msg = onechr + self.msg


        writer = PrefixWriter()
        encoder._EncodeVarint(writer.write, len(msg))
        return writer.msg + msg
def send_unack_msg_to_amazon(amazon_fd):
    db_conn = psycopg2.connect(
        "dbname='postgres' user='******' password = '******'"
        "host='" + db_host + "' port='" + db_port + "'")
    db_cur = db_conn.cursor()
    while True:
        """
        get all message that haven't receive ack
        """
        db_cur.execute("""select message from  amazon_ack""")
        """send them all again"""
        msgs_json = db_cur.fetchall()
        for msg_json in msgs_json:
            """restore it back to Message and send again"""
            msg = ups_amazon_pb2.UCommunicate()
            msg = json2pb(msg, msg_json, useFieldNumber=False)
            _EncodeVarint(amazon_fd.send, len(msg.SerializeToString()), None)
            amazon_fd.sendall(msg.SerializeToString())
        sleep(60)
Beispiel #22
0
    def _save_frame_to_file(self, frame):
        """ Save a pointcloud frame to a file. Write Metadata into the footer
        """
        self._stream_data.frame.CopyFrom(frame)
        # Add events for changed scan pattern to footer
        scan_pattern_str = self._stream_data.frame.scan_pattern.SerializeToString(
        )
        if self._prev_scan_pattern_str != scan_pattern_str:
            event = self._metadata.footer.events.add()
            event.from_frame_id = self._stream_data.frame.id
            event.scan_pattern.CopyFrom(self._stream_data.frame.scan_pattern)

            self._prev_scan_pattern_str = scan_pattern_str

        # Update stats in footer
        counter = self._metadata.footer.stats.counter
        counter.frames = counter.frames + 1
        counter.points = counter.points + self._stream_data.frame.total_number_of_points
        counter.returns = counter.returns + self._stream_data.frame.total_number_of_returns

        _EncodeVarint(self._ofile.write, self._stream_data.ByteSize())
        self._ofile.write(self._stream_data.SerializeToString())
Beispiel #23
0
    def record_to_file(self, file_name, compresslevel=1):
        """ Record point cloud stream to file

        :param file_name: Path to the file where it should be dumped
        :param compresslevel: The compresslevel argument is an integer from 0 to 9 controlling the level of compression; 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression. 0 is no compression. The default is 1. If frames are lost during the recording decrease the compression level.

        .. deprecated:: 2.13.0
            Since BSL v2.13.0 this function is deprecated, because of performance issues. Please use :py:func:`blickfeld_scanner.scanner.scanner.record_point_cloud_stream` for a performance improved recording.
        """
        warnings.warn(
            "This function is deprecated, because of performance issues. Please use scanner.record_point_cloud_stream for a performance improved recording.",
            DeprecationWarning,
            stacklevel=2)

        if self._ofile:
            raise Exception(
                "The output file has already been opened. To open another file, please call 'stop_recording' first to close the current output file."
            )
        self._prev_scan_pattern_str = b""
        self._metadata.ClearField("footer")
        self._ofile = gzip.open(file_name, 'wb', compresslevel=compresslevel)
        _EncodeVarint(self._ofile.write, self._metadata.header.ByteSize())
        self._ofile.write(self._metadata.header.SerializeToString())
Beispiel #24
0
 def write_long_no_tag(self, val):
     _EncodeVarint(self._write, wire_format.ZigZagEncode(val))
Beispiel #25
0
def encode(i):
    buf = []
	# Note: The signed variant is named "_EncodeSignedVarint".
    _EncodeVarint(buf.append, i)
    return "".join(buf)
Beispiel #26
0
def _encode_varint(i):
    """Encode integer as varint
    """
    buff = bytearray()
    _EncodeVarint(buff.append, i)
    return buff
Beispiel #27
0
def send_msg(socket,msg):
    to_send = msg.SerializeToString()
    _EncodeVarint(socket.sendall,len(to_send))
    socket.sendall(to_send)
Beispiel #28
0
def Send(sock, msg):
    req = msg.SerializeToString()
    _EncodeVarint(sock.send, len(req), None)
    sock.send(req)
    print('send finish')
Beispiel #29
0
def write_delimited(f, message):
    msg_string = message.SerializeToString()
    msg_size = len(msg_string)
    _EncodeVarint(f.write, msg_size)
    f.write(msg_string)
Beispiel #30
0
def send_message(response, msg, s):
    response.messageId = msg.messageId
    s_response = response.SerializeToString()
    _EncodeVarint(s.sendall, len(s_response), False)
    s.sendall(s_response)
Beispiel #31
0
 def encode_varint(self, value):
     """ Encode an int as a protobuf varint """
     data = []
     _EncodeVarint()(data.append, value, None)
     return b''.join(data)
Beispiel #32
0
 def send_data_amazon(self, message):
     data = message.SerializeToString()
     _EncodeVarint(self.amazon_sock.send, len(data), None)
     self.amazon_sock.send(data)
Beispiel #33
0
def send_message(response, msg, s):
    response.messageId = msg.messageId
    s_response = response.SerializeToString()
    _EncodeVarint(s.sendall, len(s_response))
    s.sendall(s_response)
Beispiel #34
0
 def sendString(self, string):
     #print "sending %d bytes" % len(string)
     out = StringIO()
     encoder._EncodeVarint(out.write, len(string))
     out.write(string)
     self.transport.write(out.getvalue())
Beispiel #35
0
def encode_varint(v):
    out = StringIO()
    _EncodeVarint(out.write, v)
    return out.getvalue()
 def encode_and_send(self, socket):
     _EncodeVarint(socket.send, len(self._message), None)
     socket.send(self._message)
Beispiel #37
0
def encode_varint(value):
    bio = BytesIO()
    encoder._EncodeVarint(bio.write, value)
    bio.seek(0)
    return bio.read()
Beispiel #38
0
def send_msg(s, msg):
    hdr = []
    _EncodeVarint(hdr.append, len(msg.SerializeToString()), None)
    s.send(b"".join(hdr))
    s.send(msg.SerializeToString())
Beispiel #39
0
 def sendString(self, addr, string):
     out = StringIO()
     encoder._EncodeVarint(out.write, len(string))
     out.write(string)
     self.transport.write(out.getvalue(), addr)